python3 compatibility for the BGE api, this only works with scons when WITH_BF_NOBLENDER is enabled.
Mathutils, Geometry and BGL modules are currently disabled with python3
This commit is contained in:
@@ -33,6 +33,11 @@
|
||||
#include <eval.h>
|
||||
#endif
|
||||
|
||||
/* TODO, support python3.x */
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
#define DISABLE_PYTHON 1
|
||||
#endif
|
||||
|
||||
#include "DNA_text_types.h"
|
||||
#include "BKE_text.h"
|
||||
#include "BKE_utildefines.h"
|
||||
|
||||
@@ -30,4 +30,6 @@ if env['WITH_BF_FFMPEG']:
|
||||
if env['BF_BUILDINFO']:
|
||||
defs.append('NAN_BUILDINFO')
|
||||
|
||||
env.BlenderLib ( libname='blender_python', sources = Split(sources), includes = Split(incs), defines = defs, libtype=['core','game2'], priority = [60,115] )
|
||||
# A bit dodgy but disable building with python3
|
||||
if not env['BF_PYTHON_VERSION'].startswith('3'):
|
||||
env.BlenderLib ( libname='blender_python', sources = Split(sources), includes = Split(incs), defines = defs, libtype=['core','game2'], priority = [60,115] )
|
||||
|
||||
@@ -43,6 +43,23 @@
|
||||
* Python defines
|
||||
------------------------------*/
|
||||
|
||||
|
||||
|
||||
#if PY_VERSION_HEX > 0x03000000
|
||||
#define PyString_FromString PyUnicode_FromString
|
||||
#define PyString_FromFormat PyUnicode_FromFormat
|
||||
#define PyString_Check PyUnicode_Check
|
||||
#define PyString_Size PyUnicode_GetSize
|
||||
|
||||
#define PyInt_FromLong PyLong_FromSsize_t
|
||||
#define PyInt_AsLong PyLong_AsSsize_t
|
||||
#define PyString_AsString _PyUnicode_AsString
|
||||
#define PyInt_Check PyLong_Check
|
||||
#define PyInt_AS_LONG PyLong_AsLong // TODO - check this one
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Py_RETURN_NONE
|
||||
Python 2.4 macro.
|
||||
|
||||
@@ -88,10 +88,12 @@
|
||||
#include "BKE_main.h"
|
||||
|
||||
extern "C" {
|
||||
#include "bpy_internal_import.h" /* from the blender python api, but we want to import text too! */
|
||||
#if PY_VERSION_HEX < 0x03000000
|
||||
#include "Mathutils.h" // Blender.Mathutils module copied here so the blenderlayer can use.
|
||||
#include "Geometry.h" // Blender.Geometry module copied here so the blenderlayer can use.
|
||||
#include "bpy_internal_import.h" /* from the blender python api, but we want to import text too! */
|
||||
#include "BGL.h"
|
||||
#endif
|
||||
}
|
||||
|
||||
#include "marshal.h" /* python header for loading/saving dicts */
|
||||
@@ -1770,7 +1772,7 @@ static void clearGameModules()
|
||||
clearModule(modules, "GameLogic");
|
||||
clearModule(modules, "Rasterizer");
|
||||
clearModule(modules, "GameKeys");
|
||||
clearModule(modules, "VideoTexture");
|
||||
clearModule(modules, "VideoTexture");
|
||||
clearModule(modules, "Mathutils");
|
||||
clearModule(modules, "Geometry");
|
||||
clearModule(modules, "BGL");
|
||||
@@ -2095,6 +2097,7 @@ PyObject* initGameKeys()
|
||||
return d;
|
||||
}
|
||||
|
||||
#if PY_VERSION_HEX < 0x03000000
|
||||
PyObject* initMathutils()
|
||||
{
|
||||
return Mathutils_Init("Mathutils"); // Use as a top level module in BGE
|
||||
@@ -2109,6 +2112,11 @@ PyObject* initBGL()
|
||||
{
|
||||
return BGL_Init("BGL"); // Use as a top level module in BGE
|
||||
}
|
||||
#else // TODO Py3k conversion
|
||||
PyObject* initMathutils() {Py_INCREF(Py_None);return Py_None;}
|
||||
PyObject* initGeometry() {Py_INCREF(Py_None);return Py_None;}
|
||||
PyObject* initBGL() {Py_INCREF(Py_None);return Py_None;}
|
||||
#endif
|
||||
|
||||
void KX_SetActiveScene(class KX_Scene* scene)
|
||||
{
|
||||
|
||||
@@ -312,32 +312,9 @@ PyObject* KX_VehicleWrapper::py_getattro_dict() {
|
||||
py_getattro_dict_up(PyObjectPlus);
|
||||
}
|
||||
|
||||
int KX_VehicleWrapper::py_setattro(PyObject *attr,PyObject* pyobj)
|
||||
int KX_VehicleWrapper::py_setattro(PyObject *attr,PyObject* value)
|
||||
{
|
||||
/* TODO - strange setattr, needs updating */
|
||||
PyTypeObject* type = pyobj->ob_type;
|
||||
int result = 1;
|
||||
|
||||
if (type == &PyList_Type)
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
if (type == &PyFloat_Type)
|
||||
{
|
||||
result = 0;
|
||||
|
||||
}
|
||||
if (type == &PyInt_Type)
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
if (type == &PyString_Type)
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
if (result)
|
||||
result = PyObjectPlus::py_setattro(attr,pyobj);
|
||||
return result;
|
||||
py_setattro_up(PyObjectPlus);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -7,25 +7,27 @@ sources = env.Glob('*.cpp')
|
||||
defs = ''
|
||||
|
||||
# Mathutils C files.
|
||||
sources.extend([\
|
||||
'#source/blender/python/api2_2x/Mathutils.c',\
|
||||
'#source/blender/python/api2_2x/Geometry.c',\
|
||||
'#source/blender/python/api2_2x/constant.c',\
|
||||
'#source/blender/python/api2_2x/euler.c',\
|
||||
'#source/blender/python/api2_2x/matrix.c',\
|
||||
'#source/blender/python/api2_2x/quat.c',\
|
||||
'#source/blender/python/api2_2x/vector.c',\
|
||||
])
|
||||
if not env['BF_PYTHON_VERSION'].startswith('3'):
|
||||
# TODO - py3 support
|
||||
sources.extend([\
|
||||
'#source/blender/python/api2_2x/Mathutils.c',\
|
||||
'#source/blender/python/api2_2x/Geometry.c',\
|
||||
'#source/blender/python/api2_2x/euler.c',\
|
||||
'#source/blender/python/api2_2x/matrix.c',\
|
||||
'#source/blender/python/api2_2x/quat.c',\
|
||||
'#source/blender/python/api2_2x/vector.c',\
|
||||
'#source/blender/python/api2_2x/constant.c',\
|
||||
])
|
||||
|
||||
sources.extend([\
|
||||
'#source/blender/python/api2_2x/BGL.c'
|
||||
])
|
||||
|
||||
sources.extend([\
|
||||
'#source/blender/python/api2_2x/bpy_internal_import.c'
|
||||
])
|
||||
|
||||
|
||||
sources.extend([\
|
||||
'#source/blender/python/api2_2x/BGL.c'
|
||||
])
|
||||
|
||||
incs = '. #source/blender/python/api2_2x' # Only for Mathutils! and bpy_internal_import.h, be very careful
|
||||
|
||||
incs += ' #source/kernel/gen_system #intern/string #intern/guardedalloc'
|
||||
|
||||
@@ -168,7 +168,7 @@ void Texture_dealloc (Texture * self)
|
||||
// release scaled image buffer
|
||||
delete [] self->m_scaledImg;
|
||||
// release object
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
((PyObject *)self)->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user