diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-05-07 09:23:15 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-05-07 09:23:15 +0400 |
commit | 779bf435ef2ba87fbcee6a28b053d97a551b8eb5 (patch) | |
tree | 484cf248d2cce408dc9e90d989a003534035c818 | |
parent | c46fa2745a98fe0b4545743751ad1e96802e330d (diff) |
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
-rw-r--r-- | source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c | 5 | ||||
-rw-r--r-- | source/blender/python/SConscript | 4 | ||||
-rw-r--r-- | source/gameengine/Expressions/PyObjectPlus.h | 17 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 12 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_VehicleWrapper.cpp | 27 | ||||
-rw-r--r-- | source/gameengine/Ketsji/SConscript | 28 | ||||
-rw-r--r-- | source/gameengine/VideoTexture/Texture.cpp | 2 |
7 files changed, 53 insertions, 42 deletions
diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c b/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c index 9a8f2f13d65..4b20ca9da21 100644 --- a/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c +++ b/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c @@ -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" diff --git a/source/blender/python/SConscript b/source/blender/python/SConscript index e869cfba556..e06cf1840c5 100644 --- a/source/blender/python/SConscript +++ b/source/blender/python/SConscript @@ -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] ) diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 449ece535c1..c21dc3a6e57 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -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. diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 8eb8956cfe2..1a571633b15 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -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) { diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp index e43a5caa50a..8146d04a878 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp @@ -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); }; diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript index dd7297080e5..2c87c7dd78a 100644 --- a/source/gameengine/Ketsji/SConscript +++ b/source/gameengine/Ketsji/SConscript @@ -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' diff --git a/source/gameengine/VideoTexture/Texture.cpp b/source/gameengine/VideoTexture/Texture.cpp index f1fcbee3041..a8ece4bc17e 100644 --- a/source/gameengine/VideoTexture/Texture.cpp +++ b/source/gameengine/VideoTexture/Texture.cpp @@ -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); } |