From 024b4b3dda2c6e4acb3fb111fdee4de82215d6ea Mon Sep 17 00:00:00 2001 From: Chris Want Date: Mon, 15 Dec 2008 20:53:45 +0000 Subject: B Linking of blenderplayer was failing with unresolved symbols (initVideoTexture) when building without FFMPEG. Needs testing with SCons and Makefiles. --- source/gameengine/GamePlayer/ghost/CMakeLists.txt | 4 ++++ source/gameengine/GamePlayer/ghost/GPG_Application.cpp | 3 ++- source/gameengine/GamePlayer/ghost/Makefile | 3 +++ source/gameengine/GamePlayer/ghost/SConscript | 2 ++ 4 files changed, 11 insertions(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GamePlayer/ghost/CMakeLists.txt b/source/gameengine/GamePlayer/ghost/CMakeLists.txt index 5e0ca93ac06..a3cd8296da3 100644 --- a/source/gameengine/GamePlayer/ghost/CMakeLists.txt +++ b/source/gameengine/GamePlayer/ghost/CMakeLists.txt @@ -70,5 +70,9 @@ SET(INC ${PYTHON_INC} ) +IF(WITH_FFMPEG) + ADD_DEFINITIONS(-DWITH_FFMPEG) +ENDIF(WITH_FFMPEG) + BLENDERLIB_NOLIST(gp_ghost "${SRC}" "${INC}") #env.BlenderLib (libname='gp_ghost', sources=source_files, includes = incs, defines = [], libtype='player',priority=0, compileflags=cflags) diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index aa5e5835cdc..d0a2d0b05f2 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -686,8 +686,9 @@ bool GPG_Application::startEngine(void) initGameKeys(); initPythonConstraintBinding(); initMathutils(); +#ifdef WITH_FFMPEG initVideoTexture(); - +#endif // Set the GameLogic.globalDict from marshal'd data, so we can // load new blend files and keep data in GameLogic.globalDict loadGamePythonConfig(m_pyGlobalDictString, m_pyGlobalDictString_Length); diff --git a/source/gameengine/GamePlayer/ghost/Makefile b/source/gameengine/GamePlayer/ghost/Makefile index 52e219db8f2..5f90d804611 100644 --- a/source/gameengine/GamePlayer/ghost/Makefile +++ b/source/gameengine/GamePlayer/ghost/Makefile @@ -82,3 +82,6 @@ CPPFLAGS += -I$(NAN_STRING)/include CPPFLAGS += -I$(NAN_GHOST)/include CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION) +ifeq ($(WITH_FFMPEG), true) + CPPFLAGS += -DWITH_FFMPEG +endif diff --git a/source/gameengine/GamePlayer/ghost/SConscript b/source/gameengine/GamePlayer/ghost/SConscript index 33cf07b6211..c1559f6e1fc 100644 --- a/source/gameengine/GamePlayer/ghost/SConscript +++ b/source/gameengine/GamePlayer/ghost/SConscript @@ -49,5 +49,7 @@ cflags = [] if env['OURPLATFORM']=='win32-vc': cflags = ['/GR'] +if env['WITH_BF_FFMPEG']: + defs += ' WITH_FFMPEG' env.BlenderLib (libname='gp_ghost', sources=source_files, includes = incs, defines = [], libtype='player',priority=0, compileflags=cflags) -- cgit v1.2.3 From 4da3c4b9d5ede4369467165cb9f31eee4385a353 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 16 Dec 2008 11:26:55 +0000 Subject: fix for [bf-blender-Bug Tracker][18089] scons compiling bug and removed unused vars --- source/gameengine/GamePlayer/ghost/SConscript | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GamePlayer/ghost/SConscript b/source/gameengine/GamePlayer/ghost/SConscript index c1559f6e1fc..4f1324b3938 100644 --- a/source/gameengine/GamePlayer/ghost/SConscript +++ b/source/gameengine/GamePlayer/ghost/SConscript @@ -49,7 +49,8 @@ cflags = [] if env['OURPLATFORM']=='win32-vc': cflags = ['/GR'] +defs = '' if env['WITH_BF_FFMPEG']: defs += ' WITH_FFMPEG' -env.BlenderLib (libname='gp_ghost', sources=source_files, includes = incs, defines = [], libtype='player',priority=0, compileflags=cflags) +env.BlenderLib (libname='gp_ghost', sources=source_files, includes = incs, defines = Split(defs), libtype='player',priority=0, compileflags=cflags) -- cgit v1.2.3 From 3c9ae035fbe81f0b6397a27ec3489bbdb430b2ef Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 19 Dec 2008 03:26:41 +0000 Subject: Typo was making actuator.getExecutePriority() crash --- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index abd049e9d64..515b485061d 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -247,7 +247,7 @@ PyParentObject SCA_ILogicBrick::Parents[] = { PyMethodDef SCA_ILogicBrick::Methods[] = { {"getOwner", (PyCFunction) SCA_ILogicBrick::sPyGetOwner, METH_NOARGS}, - {"getExecutePriority", (PyCFunction) SCA_ILogicBrick::sPySetExecutePriority, METH_NOARGS}, + {"getExecutePriority", (PyCFunction) SCA_ILogicBrick::sPyGetExecutePriority, METH_NOARGS}, {"setExecutePriority", (PyCFunction) SCA_ILogicBrick::sPySetExecutePriority, METH_VARARGS}, {NULL,NULL} //Sentinel }; -- cgit v1.2.3 From 630c16feb7c8c5e8f128e4e56507c3afceaf9c6f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 20 Dec 2008 07:12:38 +0000 Subject: patch [#18110] [patch] Update blenderplayer.exe -h text from Mitchell Stokes (moguri) --- source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 0bf0317d8f2..70272d57357 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -162,11 +162,10 @@ void usage(const char* program) consoleoption = ""; #endif - printf("usage: %s [-w [-p l t w h]] %s[-g gamengineoptions] " + printf("usage: %s [-w l t w h] %s[-g gamengineoptions] " "[-s stereomode] filename.blend\n", program, consoleoption); printf(" -h: Prints this command summary\n"); printf(" -w: display in a window\n"); - printf(" -p: specify window position\n"); printf(" l = window left coordinate\n"); printf(" t = window top coordinate\n"); printf(" w = window width\n"); @@ -190,17 +189,18 @@ void usage(const char* program) printf(" -c: keep console window open\n"); #endif printf(" -d: turn debugging on\n"); - printf(" -g: game engine options:\n"); - printf(" Name Default Description\n"); - printf(" ----------------------------------------\n"); - printf(" fixedtime 0 Do the same timestep each frame \"Enable all frames\"\n"); - printf(" nomipmap 0 Disable mipmaps\n"); - printf(" show_framerate 0 Show the frame rate\n"); - printf(" show_properties 0 Show debug properties\n"); - printf(" show_profile 0 Show profiling information\n"); - printf(" blender_material 0 Enable material settings\n"); + printf(" -g: game engine options:\n\n"); + printf(" Name Default Description\n"); + printf(" ------------------------------------------------------------------------\n"); + printf(" fixedtime 0 \"Enable all frames\"\n"); + printf(" nomipmap 0 Disable mipmaps\n"); + printf(" show_framerate 0 Show the frame rate\n"); + printf(" show_properties 0 Show debug properties\n"); + printf(" show_profile 0 Show profiling information\n"); + printf(" blender_material 0 Enable material settings\n"); + printf(" ignore_deprecation_warnings 0 Ignore deprecation warnings\n"); printf("\n"); - printf("example: %s -p 10 10 320 200 -g noaudio c:\\loadtest.blend\n", program); + printf("example: %s -w 10 10 320 200 -g noaudio c:\\loadtest.blend\n", program); printf("example: %s -g show_framerate = 0 c:\\loadtest.blend\n", program); } -- cgit v1.2.3 From aa56346b1264f1a37992834b37f47ab48fd97380 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 24 Dec 2008 21:53:15 +0000 Subject: * disable back buffer selection drawing while projection painting (was redoing for every update while painting) * remove unneeded return from game engines py api - ConvertPythonToGameObject --- source/gameengine/Ketsji/KX_GameObject.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index e4a37b589a8..f2a554c6b2a 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -2082,7 +2082,6 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py PyErr_SetString(PyExc_TypeError, "Expected KX_GameObject or a string for a name of a KX_GameObject, None is invalid"); return false; } - return (py_none_ok ? true : false); } if (PyString_Check(value)) { -- cgit v1.2.3 From 1c663bbc7e53cda1fe35579302574b0d98aa8db3 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Mon, 29 Dec 2008 16:36:58 +0000 Subject: First batch of GE API cleanup. The principle is to replace most get/set methods of logic bricks by direct property access. To make porting of game code easier, the properties have usually the same type and use than the return values/parameters of the get/set methods. More details on http://wiki.blender.org/index.php/GameEngineDev/Python_API_Clean_Up Old methods are still available but will produce deprecation warnings on the console: " is deprecated, use the property instead" You can avoid these messages by turning on the "Ignore deprecation warnings" option in Game menu. PyDoc is updated to include the new properties and display a deprecation warning for the get/set methods that are being deprecated. --- .../BlenderRoutines/BL_KetsjiEmbedStart.cpp | 4 + source/gameengine/Expressions/PyObjectPlus.h | 15 +- source/gameengine/Expressions/Value.cpp | 12 ++ source/gameengine/Expressions/Value.h | 5 + source/gameengine/GameLogic/SCA_ActuatorSensor.cpp | 24 +++ source/gameengine/GameLogic/SCA_ActuatorSensor.h | 1 + source/gameengine/GameLogic/SCA_DelaySensor.cpp | 45 ++++ source/gameengine/GameLogic/SCA_DelaySensor.h | 1 + source/gameengine/GameLogic/SCA_ISensor.cpp | 222 ++++++++++++++------ source/gameengine/GameLogic/SCA_ISensor.h | 12 +- source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 161 +++++++++++++- source/gameengine/GameLogic/SCA_JoystickSensor.h | 3 + source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 179 ++++++++++++---- source/gameengine/GameLogic/SCA_KeyboardSensor.h | 16 +- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 233 +++++++++++++-------- source/gameengine/GameLogic/SCA_MouseSensor.h | 10 +- .../gameengine/GameLogic/SCA_PropertyActuator.cpp | 35 ++++ source/gameengine/GameLogic/SCA_PropertyActuator.h | 1 + source/gameengine/GameLogic/SCA_PropertySensor.cpp | 52 +++++ source/gameengine/GameLogic/SCA_PropertySensor.h | 1 + .../gameengine/GameLogic/SCA_PythonController.cpp | 24 ++- source/gameengine/GameLogic/SCA_PythonController.h | 1 + source/gameengine/GameLogic/SCA_RandomActuator.cpp | 64 +++++- source/gameengine/GameLogic/SCA_RandomActuator.h | 1 + .../GamePlayer/ghost/GPG_Application.cpp | 3 + source/gameengine/Ketsji/KX_PolyProxy.cpp | 32 +-- source/gameengine/PyDoc/KX_ActuatorSensor.py | 7 + source/gameengine/PyDoc/SCA_DelaySensor.py | 17 ++ source/gameengine/PyDoc/SCA_ILogicBrick.py | 9 + source/gameengine/PyDoc/SCA_ISensor.py | 34 ++- source/gameengine/PyDoc/SCA_JoystickSensor.py | 59 +++++- source/gameengine/PyDoc/SCA_KeyboardSensor.py | 65 +++++- source/gameengine/PyDoc/SCA_MouseSensor.py | 11 + source/gameengine/PyDoc/SCA_PropertyActuator.py | 11 + source/gameengine/PyDoc/SCA_PropertySensor.py | 17 ++ source/gameengine/PyDoc/SCA_PythonController.py | 10 + source/gameengine/PyDoc/SCA_RandomActuator.py | 32 +++ 37 files changed, 1182 insertions(+), 247 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 4410763ec53..f046942af75 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -81,6 +81,7 @@ /***/ #include "GPU_extensions.h" +#include "Value.h" #ifdef __cplusplus extern "C" { @@ -139,6 +140,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0); bool game2ipo = (SYS_GetCommandLineInt(syshandle, "game2ipo", 0) != 0); bool displaylists = (SYS_GetCommandLineInt(syshandle, "displaylists", 0) != 0); + bool nodepwarnings = (SYS_GetCommandLineInt(syshandle, "ignore_deprecation_warnings", 0) != 0); // create the canvas, rasterizer and rendertools RAS_ICanvas* canvas = new KX_BlenderCanvas(area); @@ -195,6 +197,8 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, ketsjiengine->SetUseFixedTime(usefixed); ketsjiengine->SetTimingDisplay(frameRate, profile, properties); + CValue::SetDeprecationWarnings(nodepwarnings); + //lock frame and camera enabled - storing global values int tmp_lay= G.scene->lay; diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 3a054454a0b..55998ce1c97 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -185,7 +185,10 @@ static inline void Py_Fatal(const char *M) { #define KX_PYMETHODTABLE(class_name, method_name) \ {#method_name , (PyCFunction) class_name::sPy##method_name, METH_VARARGS, (PY_METHODCHAR)class_name::method_name##_doc} -#define KX_PYMETHODTABLE_NOARG(class_name, method_name) \ +#define KX_PYMETHODTABLE_O(class_name, method_name) \ + {#method_name , (PyCFunction) class_name::sPy##method_name, METH_O, (PY_METHODCHAR)class_name::method_name##_doc} + +#define KX_PYMETHODTABLE_NOARGS(class_name, method_name) \ {#method_name , (PyCFunction) class_name::sPy##method_name, METH_NOARGS, (PY_METHODCHAR)class_name::method_name##_doc} /** @@ -195,7 +198,15 @@ static inline void Py_Fatal(const char *M) { const char class_name::method_name##_doc[] = doc_string; \ PyObject* class_name::Py##method_name(PyObject*, PyObject* args, PyObject*) -#define KX_PYMETHODDEF_DOC_NOARG(class_name, method_name, doc_string) \ +#define KX_PYMETHODDEF_DOC_VARARGS(class_name, method_name, doc_string) \ +const char class_name::method_name##_doc[] = doc_string; \ +PyObject* class_name::Py##method_name(PyObject*, PyObject* args) + +#define KX_PYMETHODDEF_DOC_O(class_name, method_name, doc_string) \ +const char class_name::method_name##_doc[] = doc_string; \ +PyObject* class_name::Py##method_name(PyObject*, PyObject* value) + +#define KX_PYMETHODDEF_DOC_NOARGS(class_name, method_name, doc_string) \ const char class_name::method_name##_doc[] = doc_string; \ PyObject* class_name::Py##method_name(PyObject*) diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index 7296dfbec10..f2b5569c76e 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -32,6 +32,7 @@ ////////////////////////////////////////////////////////////////////// double CValue::m_sZeroVec[3] = {0.0,0.0,0.0}; +bool CValue::m_ignore_deprecation_warnings(false); #ifndef NO_EXP_PYTHON_EMBEDDING @@ -849,4 +850,15 @@ void CValue::SetValue(CValue* newval) } /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// +/* deprecation warning management */ +void CValue::SetDeprecationWarnings(bool ignoreDeprecationWarnings) +{ + m_ignore_deprecation_warnings = ignoreDeprecationWarnings; +} + +void CValue::ShowDeprecationWarning(const char* old_way,const char* new_way) +{ + if (!m_ignore_deprecation_warnings) + printf("Method %s is deprecated, please use %s instead.\n", old_way, new_way); +} diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h index 74fcdae5756..56a4991af27 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/Value.h @@ -318,6 +318,10 @@ public: STR_String op2str(VALUE_OPERATOR op); + /** enable/disable display of deprecation warnings */ + static void SetDeprecationWarnings(bool ignoreDeprecationWarnings); + /** Shows a deprecation warning */ + static void ShowDeprecationWarning(const char* method,const char* prop); // setting / getting flags inline void SetSelected(bool bSelected) { m_ValFlags.Selected = bSelected; } @@ -349,6 +353,7 @@ private: ValueFlags m_ValFlags; // Frequently used flags in a bitfield (low memoryusage) int m_refcount; // Reference Counter static double m_sZeroVec[3]; + static bool m_ignore_deprecation_warnings; }; diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp index 7c37b237d60..5ad28dbf329 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp @@ -149,21 +149,44 @@ PyParentObject SCA_ActuatorSensor::Parents[] = { }; PyMethodDef SCA_ActuatorSensor::Methods[] = { + //Deprecated functions ------> {"getActuator", (PyCFunction) SCA_ActuatorSensor::sPyGetActuator, METH_NOARGS, (PY_METHODCHAR)GetActuator_doc}, {"setActuator", (PyCFunction) SCA_ActuatorSensor::sPySetActuator, METH_VARARGS, (PY_METHODCHAR)SetActuator_doc}, + //<----- Deprecated {NULL,NULL} //Sentinel }; PyObject* SCA_ActuatorSensor::_getattr(const STR_String& attr) { + if (attr == "actuator") { + return PyString_FromString(m_checkactname); + } _getattr_up(SCA_ISensor); /* implicit return! */ } +int SCA_ActuatorSensor::_setattr(const STR_String& attr, PyObject *value) { + if (PyString_Check(value)) { + char* sval = PyString_AsString(value); + if (attr == "actuator") { + SCA_IActuator* act = GetParent()->FindActuator(STR_String(sval)); + if (act) { + m_checkactname = sval; + m_actuator = act; + return 0; + } + PyErr_SetString(PyExc_AttributeError, "string does not correspond to an actuator"); + return 1; + } + } + return SCA_ISensor::_setattr(attr, value); +} + /* 3. getActuator */ const char SCA_ActuatorSensor::GetActuator_doc[] = "getActuator()\n" "\tReturn the Actuator with which the sensor operates.\n"; PyObject* SCA_ActuatorSensor::PyGetActuator(PyObject* self) { + ShowDeprecationWarning("getActuator()", "the actuator property"); return PyString_FromString(m_checkactname); } @@ -175,6 +198,7 @@ const char SCA_ActuatorSensor::SetActuator_doc[] = "\tof this name, the call is ignored.\n"; PyObject* SCA_ActuatorSensor::PySetActuator(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setActuator()", "the actuator property"); /* We should query whether the name exists. Or should we create a prop */ /* on the fly? */ char *actNameArg = NULL; diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.h b/source/gameengine/GameLogic/SCA_ActuatorSensor.h index a71145f6852..4fe4700602c 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.h +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.h @@ -62,6 +62,7 @@ public: /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject *value); /* 3. setProperty */ KX_PYMETHOD_DOC(SCA_ActuatorSensor,SetActuator); diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp index f15d4c7249f..362483b58a2 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp +++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp @@ -158,6 +158,7 @@ PyParentObject SCA_DelaySensor::Parents[] = { }; PyMethodDef SCA_DelaySensor::Methods[] = { + //Deprecated functions ------> /* setProperty */ {"setDelay", (PyCFunction) SCA_DelaySensor::sPySetDelay, METH_VARARGS, (PY_METHODCHAR)SetDelay_doc}, {"setDuration", (PyCFunction) SCA_DelaySensor::sPySetDuration, METH_VARARGS, (PY_METHODCHAR)SetDuration_doc}, @@ -166,13 +167,51 @@ PyMethodDef SCA_DelaySensor::Methods[] = { {"getDelay", (PyCFunction) SCA_DelaySensor::sPyGetDelay, METH_NOARGS, (PY_METHODCHAR)GetDelay_doc}, {"getDuration", (PyCFunction) SCA_DelaySensor::sPyGetDuration, METH_NOARGS, (PY_METHODCHAR)GetDuration_doc}, {"getRepeat", (PyCFunction) SCA_DelaySensor::sPyGetRepeat, METH_NOARGS, (PY_METHODCHAR)GetRepeat_doc}, + //<----- Deprecated {NULL,NULL} //Sentinel }; PyObject* SCA_DelaySensor::_getattr(const STR_String& attr) { + if (attr == "delay") { + return PyInt_FromLong(m_delay); + } + if (attr == "duration") { + return PyInt_FromLong(m_duration); + } + if (attr == "repeat") { + return PyInt_FromLong(m_repeat); + } _getattr_up(SCA_ISensor); } +int SCA_DelaySensor::_setattr(const STR_String& attr, PyObject *value) { + if (PyInt_Check(value)) { + int ival = PyInt_AsLong(value); + if (attr == "delay") { + if (ival < 0) { + PyErr_SetString(PyExc_ValueError, "Delay cannot be negative"); + return 1; + } + m_delay = ival; + return 0; + } + if (attr == "duration") { + if (ival < 0) { + PyErr_SetString(PyExc_ValueError, "Duration cannot be negative"); + return 1; + } + m_duration = ival; + return 0; + } + if (attr == "repeat") { + m_repeat = (ival != 0); + return 0; + } + } + return SCA_ISensor::_setattr(attr, value); +} + + const char SCA_DelaySensor::SetDelay_doc[] = "setDelay(delay)\n" "\t- delay: length of the initial OFF period as number of frame\n" @@ -180,6 +219,7 @@ const char SCA_DelaySensor::SetDelay_doc[] = "\tSet the initial delay before the positive trigger\n"; PyObject* SCA_DelaySensor::PySetDelay(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setDelay()", "the delay property"); int delay; if(!PyArg_ParseTuple(args, "i", &delay)) { @@ -201,6 +241,7 @@ const char SCA_DelaySensor::SetDuration_doc[] = "\tIf > 0, a negative trigger is fired at the end of the ON pulse.\n"; PyObject* SCA_DelaySensor::PySetDuration(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setDuration()", "the duration property"); int duration; if(!PyArg_ParseTuple(args, "i", &duration)) { @@ -221,6 +262,7 @@ const char SCA_DelaySensor::SetRepeat_doc[] = "\tSet the sensor repeat mode\n"; PyObject* SCA_DelaySensor::PySetRepeat(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setRepeat()", "the repeat property"); int repeat; if(!PyArg_ParseTuple(args, "i", &repeat)) { @@ -235,6 +277,7 @@ const char SCA_DelaySensor::GetDelay_doc[] = "\tReturn the delay parameter value\n"; PyObject* SCA_DelaySensor::PyGetDelay(PyObject* self) { + ShowDeprecationWarning("getDelay()", "the delay property"); return PyInt_FromLong(m_delay); } @@ -243,6 +286,7 @@ const char SCA_DelaySensor::GetDuration_doc[] = "\tReturn the duration parameter value\n"; PyObject* SCA_DelaySensor::PyGetDuration(PyObject* self) { + ShowDeprecationWarning("getDuration()", "the duration property"); return PyInt_FromLong(m_duration); } @@ -251,6 +295,7 @@ const char SCA_DelaySensor::GetRepeat_doc[] = "\tReturn the repeat parameter value\n"; PyObject* SCA_DelaySensor::PyGetRepeat(PyObject* self) { + ShowDeprecationWarning("getRepeat()", "the repeat property"); return BoolToPyArg(m_repeat); } diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.h b/source/gameengine/GameLogic/SCA_DelaySensor.h index a997fabe3cd..ff3afe16542 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.h +++ b/source/gameengine/GameLogic/SCA_DelaySensor.h @@ -61,6 +61,7 @@ public: /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject *value); /* setProperty */ KX_PYMETHOD_DOC(SCA_DelaySensor,SetDelay); diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index b10ac676464..6e46c8504bb 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -139,71 +139,6 @@ void SCA_ISensor::DecLink() { } } -/* python integration */ - -PyTypeObject SCA_ISensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) - 0, - "SCA_ISensor", - sizeof(SCA_ISensor), - 0, - PyDestructor, - 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, - 0, - 0, - 0 -}; - -PyParentObject SCA_ISensor::Parents[] = { - &SCA_ISensor::Type, - &SCA_ILogicBrick::Type, - &CValue::Type, - NULL -}; -PyMethodDef SCA_ISensor::Methods[] = { - {"isPositive", (PyCFunction) SCA_ISensor::sPyIsPositive, - METH_NOARGS, (PY_METHODCHAR)IsPositive_doc}, - {"isTriggered", (PyCFunction) SCA_ISensor::sPyIsTriggered, - METH_VARARGS, (PY_METHODCHAR)IsTriggered_doc}, - {"getUsePosPulseMode", (PyCFunction) SCA_ISensor::sPyGetUsePosPulseMode, - METH_NOARGS, (PY_METHODCHAR)GetUsePosPulseMode_doc}, - {"setUsePosPulseMode", (PyCFunction) SCA_ISensor::sPySetUsePosPulseMode, - METH_VARARGS, (PY_METHODCHAR)SetUsePosPulseMode_doc}, - {"getFrequency", (PyCFunction) SCA_ISensor::sPyGetFrequency, - METH_NOARGS, (PY_METHODCHAR)GetFrequency_doc}, - {"setFrequency", (PyCFunction) SCA_ISensor::sPySetFrequency, - METH_VARARGS, (PY_METHODCHAR)SetFrequency_doc}, - {"getUseNegPulseMode", (PyCFunction) SCA_ISensor::sPyGetUseNegPulseMode, - METH_NOARGS, (PY_METHODCHAR)GetUseNegPulseMode_doc}, - {"setUseNegPulseMode", (PyCFunction) SCA_ISensor::sPySetUseNegPulseMode, - METH_VARARGS, (PY_METHODCHAR)SetUseNegPulseMode_doc}, - {"getInvert", (PyCFunction) SCA_ISensor::sPyGetInvert, - METH_NOARGS, (PY_METHODCHAR)GetInvert_doc}, - {"setInvert", (PyCFunction) SCA_ISensor::sPySetInvert, - METH_VARARGS, (PY_METHODCHAR)SetInvert_doc}, - {"getLevel", (PyCFunction) SCA_ISensor::sPyGetLevel, - METH_NOARGS, (PY_METHODCHAR)GetLevel_doc}, - {"setLevel", (PyCFunction) SCA_ISensor::sPySetLevel, - METH_VARARGS, (PY_METHODCHAR)SetLevel_doc}, - {"reset", (PyCFunction) SCA_ISensor::sPyReset, - METH_NOARGS, (PY_METHODCHAR)Reset_doc}, - {NULL,NULL} //Sentinel -}; - - -PyObject* -SCA_ISensor::_getattr(const STR_String& attr) -{ - _getattr_up(SCA_ILogicBrick); -} - - void SCA_ISensor::RegisterToManager() { // sensor is just activated, initialize it @@ -275,13 +210,17 @@ void SCA_ISensor::Activate(class SCA_LogicManager* logicmgr, CValue* event) } } } +/* ----------------------------------------------- */ +/* Python Functions */ +/* ----------------------------------------------- */ -/* Python functions: */ +//Deprecated Functions ------> const char SCA_ISensor::IsPositive_doc[] = "isPositive()\n" "\tReturns whether the sensor is in an active state.\n"; PyObject* SCA_ISensor::PyIsPositive(PyObject* self) { + ShowDeprecationWarning("isPositive()", "the read-only positive property"); int retval = IsPositiveTrigger(); return PyInt_FromLong(retval); } @@ -291,6 +230,7 @@ const char SCA_ISensor::IsTriggered_doc[] = "\tReturns whether the sensor has triggered the current controller.\n"; PyObject* SCA_ISensor::PyIsTriggered(PyObject* self) { + ShowDeprecationWarning("isTriggered()", "the read-only triggered property"); // check with the current controller int retval = 0; if (SCA_PythonController::m_sCurrentController) @@ -306,6 +246,7 @@ const char SCA_ISensor::GetUsePosPulseMode_doc[] = "\tReturns whether positive pulse mode is active.\n"; PyObject* SCA_ISensor::PyGetUsePosPulseMode(PyObject* self) { + ShowDeprecationWarning("getUsePosPulseMode()", "the usePosPulseMode property"); return BoolToPyArg(m_pos_pulsemode); } @@ -319,6 +260,7 @@ const char SCA_ISensor::SetUsePosPulseMode_doc[] = "\tSet whether to do pulsing when positive pulses occur.\n"; PyObject* SCA_ISensor::PySetUsePosPulseMode(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setUsePosPulseMode()", "the usePosPulseMode property"); int pyarg = 0; if(!PyArg_ParseTuple(args, "i", &pyarg)) { return NULL; } m_pos_pulsemode = PyArgToBool(pyarg); @@ -333,6 +275,7 @@ const char SCA_ISensor::GetFrequency_doc[] = "\tReturns the frequency of the updates in pulse mode.\n" ; PyObject* SCA_ISensor::PyGetFrequency(PyObject* self) { + ShowDeprecationWarning("getFrequency()", "the frequency property"); return PyInt_FromLong(m_pulse_frequency); } @@ -346,6 +289,7 @@ const char SCA_ISensor::SetFrequency_doc[] = "\tIf the frequency is negative, it is set to 0.\n" ; PyObject* SCA_ISensor::PySetFrequency(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setFrequency()", "the frequency property"); int pulse_frequencyArg = 0; if(!PyArg_ParseTuple(args, "i", &pulse_frequencyArg)) { @@ -368,6 +312,7 @@ const char SCA_ISensor::GetInvert_doc[] = "\tReturns whether or not pulses from this sensor are inverted.\n" ; PyObject* SCA_ISensor::PyGetInvert(PyObject* self) { + ShowDeprecationWarning("getInvert()", "the invert property"); return BoolToPyArg(m_invert); } @@ -377,6 +322,7 @@ const char SCA_ISensor::SetInvert_doc[] = "\tSet whether to invert pulses.\n"; PyObject* SCA_ISensor::PySetInvert(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setInvert()", "the invert property"); int pyarg = 0; if(!PyArg_ParseTuple(args, "i", &pyarg)) { return NULL; } m_invert = PyArgToBool(pyarg); @@ -392,6 +338,7 @@ const char SCA_ISensor::GetLevel_doc[] = "\tA edge detector will wait for a state change before generating a pulse.\n"; PyObject* SCA_ISensor::PyGetLevel(PyObject* self) { + ShowDeprecationWarning("getLevel()", "the level property"); return BoolToPyArg(m_level); } @@ -401,6 +348,7 @@ const char SCA_ISensor::SetLevel_doc[] = "\tSet whether to detect level or edge transition when entering a state.\n"; PyObject* SCA_ISensor::PySetLevel(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setLevel()", "the level property"); int pyarg = 0; if(!PyArg_ParseTuple(args, "i", &pyarg)) { return NULL; } m_level = PyArgToBool(pyarg); @@ -412,6 +360,7 @@ const char SCA_ISensor::GetUseNegPulseMode_doc[] = "\tReturns whether negative pulse mode is active.\n"; PyObject* SCA_ISensor::PyGetUseNegPulseMode(PyObject* self) { + ShowDeprecationWarning("getUseNegPulseMode()", "the useNegPulseMode property"); return BoolToPyArg(m_neg_pulsemode); } @@ -422,21 +371,156 @@ const char SCA_ISensor::SetUseNegPulseMode_doc[] = "\tSet whether to do pulsing when negative pulses occur.\n"; PyObject* SCA_ISensor::PySetUseNegPulseMode(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setUseNegPulseMode()", "the useNegPulseMode property"); int pyarg = 0; if(!PyArg_ParseTuple(args, "i", &pyarg)) { return NULL; } m_neg_pulsemode = PyArgToBool(pyarg); Py_Return; } +//<------Deprecated -const char SCA_ISensor::Reset_doc[] = +KX_PYMETHODDEF_DOC_NOARGS(SCA_ISensor, reset, "reset()\n" "\tReset sensor internal state, effect depends on the type of sensor and settings.\n" -"\tThe sensor is put in its initial state as if it was just activated.\n"; -PyObject* SCA_ISensor::PyReset(PyObject* self) +"\tThe sensor is put in its initial state as if it was just activated.\n") { Init(); Py_Return; } +/* ----------------------------------------------- */ +/* Python Integration Hooks */ +/* ----------------------------------------------- */ + +PyTypeObject SCA_ISensor::Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, + "SCA_ISensor", + sizeof(SCA_ISensor), + 0, + PyDestructor, + 0, + __getattr, + __setattr, + 0, //&MyPyCompare, + __repr, + 0, //&cvalue_as_number, + 0, + 0, + 0, + 0 +}; + +PyParentObject SCA_ISensor::Parents[] = { + &SCA_ISensor::Type, + &SCA_ILogicBrick::Type, + &CValue::Type, + NULL +}; +PyMethodDef SCA_ISensor::Methods[] = { + //Deprecated functions -----> + {"isPositive", (PyCFunction) SCA_ISensor::sPyIsPositive, + METH_NOARGS, (PY_METHODCHAR)IsPositive_doc}, + {"isTriggered", (PyCFunction) SCA_ISensor::sPyIsTriggered, + METH_VARARGS, (PY_METHODCHAR)IsTriggered_doc}, + {"getUsePosPulseMode", (PyCFunction) SCA_ISensor::sPyGetUsePosPulseMode, + METH_NOARGS, (PY_METHODCHAR)GetUsePosPulseMode_doc}, + {"setUsePosPulseMode", (PyCFunction) SCA_ISensor::sPySetUsePosPulseMode, + METH_VARARGS, (PY_METHODCHAR)SetUsePosPulseMode_doc}, + {"getFrequency", (PyCFunction) SCA_ISensor::sPyGetFrequency, + METH_NOARGS, (PY_METHODCHAR)GetFrequency_doc}, + {"setFrequency", (PyCFunction) SCA_ISensor::sPySetFrequency, + METH_VARARGS, (PY_METHODCHAR)SetFrequency_doc}, + {"getUseNegPulseMode", (PyCFunction) SCA_ISensor::sPyGetUseNegPulseMode, + METH_NOARGS, (PY_METHODCHAR)GetUseNegPulseMode_doc}, + {"setUseNegPulseMode", (PyCFunction) SCA_ISensor::sPySetUseNegPulseMode, + METH_VARARGS, (PY_METHODCHAR)SetUseNegPulseMode_doc}, + {"getInvert", (PyCFunction) SCA_ISensor::sPyGetInvert, + METH_NOARGS, (PY_METHODCHAR)GetInvert_doc}, + {"setInvert", (PyCFunction) SCA_ISensor::sPySetInvert, + METH_VARARGS, (PY_METHODCHAR)SetInvert_doc}, + {"getLevel", (PyCFunction) SCA_ISensor::sPyGetLevel, + METH_NOARGS, (PY_METHODCHAR)GetLevel_doc}, + {"setLevel", (PyCFunction) SCA_ISensor::sPySetLevel, + METH_VARARGS, (PY_METHODCHAR)SetLevel_doc}, + //<----- Deprecated + KX_PYMETHODTABLE_NOARGS(SCA_ISensor, reset), + {NULL,NULL} //Sentinel +}; + +PyObject* +SCA_ISensor::_getattr(const STR_String& attr) +{ + if (attr == "usePosPulseMode") + return PyInt_FromLong(m_pos_pulsemode); + if (attr == "useNegPulseMode") + return PyInt_FromLong(m_neg_pulsemode); + if (attr == "frequency") + return PyInt_FromLong(m_pulse_frequency); + if (attr == "invert") + return PyInt_FromLong(m_invert); + if (attr == "level") + return PyInt_FromLong(m_level); + if (attr == "triggered") + { + int retval = 0; + if (SCA_PythonController::m_sCurrentController) + retval = SCA_PythonController::m_sCurrentController->IsTriggered(this); + return PyInt_FromLong(retval); + } + if (attr == "positive") + { + int retval = IsPositiveTrigger(); + return PyInt_FromLong(retval); + } + + _getattr_up(SCA_ILogicBrick); +} + +int SCA_ISensor::_setattr(const STR_String& attr, PyObject *value) +{ + if (attr == "triggered") + PyErr_SetString(PyExc_AttributeError, "attribute \"triggered\" is read only"); + if (attr == "positive") + PyErr_SetString(PyExc_AttributeError, "attribute \"positive\" is read only"); + + if (PyInt_Check(value)) + { + int val = PyInt_AsLong(value); + + if (attr == "usePosPulseMode") + { + m_pos_pulsemode = (val != 0); + return 0; + } + + if (attr == "useNegPulseMode") + { + m_neg_pulsemode = (val != 0); + return 0; + } + + if (attr == "invert") + { + m_invert = (val != 0); + return 0; + } + if (attr == "level") + { + m_level = (val != 0); + return 0; + } + + if (attr == "frequency") + { + if (val < 0) + val = 0; + m_pulse_frequency = val; + return 0; + } + } + + return SCA_ILogicBrick::_setattr(attr, value); +} /* eof */ diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h index d1872009291..1b57c4621e4 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.h +++ b/source/gameengine/GameLogic/SCA_ISensor.h @@ -93,8 +93,7 @@ public: virtual bool Evaluate(CValue* event) = 0; virtual bool IsPositiveTrigger(); virtual void Init(); - - virtual PyObject* _getattr(const STR_String& attr); + virtual CValue* GetReplica()=0; /** Set parameters for the pulsing behaviour. @@ -141,6 +140,11 @@ public: { return !m_links; } /* Python functions: */ + + virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject *value); + + //Deprecated functions -----> KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,IsPositive); KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,IsTriggered); KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetUsePosPulseMode); @@ -153,8 +157,8 @@ public: KX_PYMETHOD_DOC(SCA_ISensor,SetInvert); KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetLevel); KX_PYMETHOD_DOC(SCA_ISensor,SetLevel); - KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,Reset); - + //<------ + KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,reset); }; #endif //__SCA_ISENSOR diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 8b96840b149..ec5921bad85 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -304,6 +304,7 @@ PyParentObject SCA_JoystickSensor::Parents[] = { PyMethodDef SCA_JoystickSensor::Methods[] = { + //Deprecated functions ------> {"getIndex", (PyCFunction) SCA_JoystickSensor::sPyGetIndex, METH_NOARGS, (PY_METHODCHAR)GetIndex_doc}, {"setIndex", (PyCFunction) SCA_JoystickSensor::sPySetIndex, METH_O, (PY_METHODCHAR)SetIndex_doc}, {"getAxis", (PyCFunction) SCA_JoystickSensor::sPyGetAxis, METH_NOARGS, (PY_METHODCHAR)GetAxis_doc}, @@ -313,27 +314,144 @@ PyMethodDef SCA_JoystickSensor::Methods[] = { {"setThreshold", (PyCFunction) SCA_JoystickSensor::sPySetThreshold, METH_VARARGS, (PY_METHODCHAR)SetThreshold_doc}, {"getButton", (PyCFunction) SCA_JoystickSensor::sPyGetButton, METH_NOARGS, (PY_METHODCHAR)GetButton_doc}, {"setButton", (PyCFunction) SCA_JoystickSensor::sPySetButton, METH_O, (PY_METHODCHAR)SetButton_doc}, - {"getButtonValue",(PyCFunction) SCA_JoystickSensor::sPyGetButtonValue, METH_NOARGS,(PY_METHODCHAR)GetButtonValue_doc}, {"getHat", (PyCFunction) SCA_JoystickSensor::sPyGetHat, METH_NOARGS, (PY_METHODCHAR)GetHat_doc}, {"setHat", (PyCFunction) SCA_JoystickSensor::sPySetHat, METH_VARARGS, (PY_METHODCHAR)SetHat_doc}, {"getNumAxes", (PyCFunction) SCA_JoystickSensor::sPyNumberOfAxes, METH_NOARGS, (PY_METHODCHAR)NumberOfAxes_doc}, {"getNumButtons",(PyCFunction) SCA_JoystickSensor::sPyNumberOfButtons,METH_NOARGS, (PY_METHODCHAR)NumberOfButtons_doc}, {"getNumHats", (PyCFunction) SCA_JoystickSensor::sPyNumberOfHats, METH_NOARGS, (PY_METHODCHAR)NumberOfHats_doc}, {"isConnected", (PyCFunction) SCA_JoystickSensor::sPyConnected, METH_NOARGS, (PY_METHODCHAR)Connected_doc}, + {"getButtonValue",(PyCFunction) SCA_JoystickSensor::sPyGetButtonValue, METH_NOARGS,(PY_METHODCHAR)GetButtonValue_doc}, + //<----- Deprecated + {"getButtonActiveList",(PyCFunction) SCA_JoystickSensor::sPyGetButtonActiveList, METH_NOARGS,(PY_METHODCHAR)GetButtonActiveList_doc}, + {"getButtonStatus",(PyCFunction) SCA_JoystickSensor::sPyGetButtonStatus, METH_VARARGS,(PY_METHODCHAR)GetButtonStatus_doc}, {NULL,NULL} //Sentinel }; PyObject* SCA_JoystickSensor::_getattr(const STR_String& attr) { + SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); + if (attr == "axisPosition") { + if(joy) + return Py_BuildValue("[iiii]", joy->GetAxis10(), joy->GetAxis11(), joy->GetAxis20(), joy->GetAxis21()); + else + return Py_BuildValue("[iiii]", 0, 0, 0, 0); + } + if (attr == "numAxis") { + return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 ); + } + if (attr == "numButtons") { + return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 ); + } + if (attr == "numHats") { + return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 ); + } + if (attr == "connected") { + return PyBool_FromLong( joy ? joy->Connected() : 0 ); + } + if (attr == "index") { + return PyInt_FromLong(m_joyindex); + } + if (attr == "threshold") { + return PyInt_FromLong(m_precision); + } + if (attr == "button") { + return PyInt_FromLong(m_button); + } + if (attr == "axis") { + return Py_BuildValue("[ii]",m_axis, m_axisf); + } + if (attr == "hat") { + return Py_BuildValue("[ii]",m_hat, m_hatf); + } _getattr_up(SCA_ISensor); } +int SCA_JoystickSensor::_setattr(const STR_String& attr, PyObject *value) { + if (attr == "axisPosition") { + PyErr_SetString(PyExc_AttributeError, "axisPosition is read only"); + return 1; + } + if (attr == "numAxis") { + PyErr_SetString(PyExc_AttributeError, "numaxis is read only"); + return 1; + } + if (attr == "numButtons") { + PyErr_SetString(PyExc_AttributeError, "numbuttons is read only"); + return 1; + } + if (attr == "numHats") { + PyErr_SetString(PyExc_AttributeError, "numhats is read only"); + return 1; + } + if (attr == "connected") { + PyErr_SetString(PyExc_AttributeError, "connected is read only"); + return 1; + } + if (PyInt_Check(value)) { + int ival = PyInt_AsLong(value); + if (attr == "index") { + if (ival < 0 || ival >= JOYINDEX_MAX) { + PyErr_SetString(PyExc_ValueError, "joystick index out of range"); + return 1; + } + m_joyindex = ival; + } else if (attr == "threshold") { + m_precision = ival; + } else if (attr == "button") { + if (ival < 0) { + PyErr_SetString(PyExc_ValueError, "button out of range"); + return 1; + } + m_button = ival; + } + return 0; + } + if (PySequence_Check(value)) { + if (attr == "axis" || attr == "hat") { + if (PySequence_Size(value) != 2) { + PyErr_SetString(PyExc_ValueError, "value must be sequence of 2 integers"); + return 1; + } + int ival = -1; + int ivalf = -1; + PyObject *item = PySequence_GetItem(value, 0); /* new ref */ + ival = PyInt_AsLong(item); + Py_DECREF(item); + item = PySequence_GetItem(value, 1); /* new ref */ + ivalf = PyInt_AsLong(item); + Py_DECREF(item); + if (PyErr_Occurred()) { + PyErr_SetString(PyExc_ValueError, "one or more of the items in the sequence was not an integer"); + return 1; + } + if (attr == "axis") { + if (ival < 1 || ival > 2 || ivalf < 0 || ivalf > 3) { + PyErr_SetString(PyExc_ValueError, "items in the sequence are out of range"); + return 1; + } + m_axis = ival; + m_axisf = ivalf; + } else { + if (ival < 1 || ival > 2) { + PyErr_SetString(PyExc_ValueError, "items in the sequence are out of range"); + return 1; + } + m_hat = ival; + m_hatf = ivalf; + } + } + return 0; + } + return SCA_ISensor::_setattr(attr, value); +} + /* get index ---------------------------------------------------------- */ const char SCA_JoystickSensor::GetIndex_doc[] = "getIndex\n" "\tReturns the joystick index to use.\n"; PyObject* SCA_JoystickSensor::PyGetIndex( PyObject* self ) { + ShowDeprecationWarning("getIndex()", "the index property"); return PyInt_FromLong(m_joyindex); } @@ -343,6 +461,7 @@ const char SCA_JoystickSensor::SetIndex_doc[] = "setIndex\n" "\tSets the joystick index to use.\n"; PyObject* SCA_JoystickSensor::PySetIndex( PyObject* self, PyObject* value ) { + ShowDeprecationWarning("setIndex()", "the index property"); int index = PyInt_AsLong( value ); /* -1 on error, will raise an error in this case */ if (index < 0 || index >= JOYINDEX_MAX) { PyErr_SetString(PyExc_ValueError, "joystick index out of range or not an int"); @@ -358,6 +477,7 @@ const char SCA_JoystickSensor::GetAxis_doc[] = "getAxis\n" "\tReturns the current axis this sensor reacts to.\n"; PyObject* SCA_JoystickSensor::PyGetAxis( PyObject* self) { + ShowDeprecationWarning("getAxis()", "the axis property"); return Py_BuildValue("[ii]",m_axis, m_axisf); } @@ -367,6 +487,7 @@ const char SCA_JoystickSensor::SetAxis_doc[] = "setAxis\n" "\tSets the current axis this sensor reacts to.\n"; PyObject* SCA_JoystickSensor::PySetAxis( PyObject* self, PyObject* args ) { + ShowDeprecationWarning("setAxis()", "the axis property"); int axis,axisflag; if(!PyArg_ParseTuple(args, "ii", &axis, &axisflag)){ @@ -383,6 +504,7 @@ const char SCA_JoystickSensor::GetAxisValue_doc[] = "getAxisValue\n" "\tReturns a list of the values for the current state of each axis.\n"; PyObject* SCA_JoystickSensor::PyGetAxisValue( PyObject* self) { + ShowDeprecationWarning("getAxisValue()", "the axisPosition property"); SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); if(joy) return Py_BuildValue("[iiii]", joy->GetAxis10(), joy->GetAxis11(), joy->GetAxis20(), joy->GetAxis21()); @@ -396,6 +518,7 @@ const char SCA_JoystickSensor::GetThreshold_doc[] = "getThreshold\n" "\tReturns the threshold of the axis.\n"; PyObject* SCA_JoystickSensor::PyGetThreshold( PyObject* self) { + ShowDeprecationWarning("getThreshold()", "the threshold property"); return PyInt_FromLong(m_precision); } @@ -405,6 +528,7 @@ const char SCA_JoystickSensor::SetThreshold_doc[] = "setThreshold\n" "\tSets the threshold of the axis.\n"; PyObject* SCA_JoystickSensor::PySetThreshold( PyObject* self, PyObject* args ) { + ShowDeprecationWarning("setThreshold()", "the threshold property"); int thresh; if(!PyArg_ParseTuple(args, "i", &thresh)){ return NULL; @@ -418,6 +542,7 @@ const char SCA_JoystickSensor::GetButton_doc[] = "getButton\n" "\tReturns the current button this sensor is checking.\n"; PyObject* SCA_JoystickSensor::PyGetButton( PyObject* self) { + ShowDeprecationWarning("getButton()", "the button property"); return PyInt_FromLong(m_button); } @@ -426,6 +551,7 @@ const char SCA_JoystickSensor::SetButton_doc[] = "setButton\n" "\tSets the button the sensor reacts to.\n"; PyObject* SCA_JoystickSensor::PySetButton( PyObject* self, PyObject* value ) { + ShowDeprecationWarning("setButton()", "the button property"); int button = PyInt_AsLong(value); if(button==-1 && PyErr_Occurred()) { PyErr_SetString(PyExc_ValueError, "expected an int"); @@ -440,6 +566,15 @@ const char SCA_JoystickSensor::GetButtonValue_doc[] = "getButtonValue\n" "\tReturns a list containing the indicies of the current pressed state of each button.\n"; PyObject* SCA_JoystickSensor::PyGetButtonValue( PyObject* self) { + ShowDeprecationWarning("getButtonValue()", "getButtonActiveList"); + return PyGetButtonActiveList(self); +} + +/* get button active list -------------------------------------------------- */ +const char SCA_JoystickSensor::GetButtonActiveList_doc[] = +"getButtonActiveList\n" +"\tReturns a list containing the indicies of the button currently pressed.\n"; +PyObject* SCA_JoystickSensor::PyGetButtonActiveList( PyObject* self) { SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); PyObject *ls = PyList_New(0); PyObject *value; @@ -457,11 +592,30 @@ PyObject* SCA_JoystickSensor::PyGetButtonValue( PyObject* self) { return ls; } +/* get button status -------------------------------------------------- */ +const char SCA_JoystickSensor::GetButtonStatus_doc[] = +"getButtonStatus(buttonIndex)\n" +"\tReturns a bool of the current pressed state of the specified button.\n"; +PyObject* SCA_JoystickSensor::PyGetButtonStatus( PyObject* self, PyObject* args ) { + SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); + PyObject *value; + int index; + + if(!PyArg_ParseTuple(args, "i", &index)){ + return NULL; + } + if(joy && index >= 0 && index < joy->GetNumberOfButtons()) { + return PyBool_FromLong(joy->aButtonPressIsPositive(index) ? 1 : 0); + } + return PyBool_FromLong(0); +} + /* get hat ----------------------------------------------------------- */ const char SCA_JoystickSensor::GetHat_doc[] = "getHat\n" "\tReturns the current direction of the hat.\n"; PyObject* SCA_JoystickSensor::PyGetHat( PyObject* self ) { + ShowDeprecationWarning("getHat()", "the hat property"); return Py_BuildValue("[ii]",m_hat, m_hatf); } @@ -471,6 +625,7 @@ const char SCA_JoystickSensor::SetHat_doc[] = "setHat\n" "\tSets the hat the sensor reacts to.\n"; PyObject* SCA_JoystickSensor::PySetHat( PyObject* self, PyObject* args ) { + ShowDeprecationWarning("setHat()", "the hat property"); int hat,hatflag; if(!PyArg_ParseTuple(args, "ii", &hat, &hatflag)){ return NULL; @@ -486,6 +641,7 @@ const char SCA_JoystickSensor::NumberOfAxes_doc[] = "getNumAxes\n" "\tReturns the number of axes .\n"; PyObject* SCA_JoystickSensor::PyNumberOfAxes( PyObject* self ) { + ShowDeprecationWarning("getNumAxes()", "the numAxis property"); SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); // when the joystick is null their is 0 exis still. dumb but scripters should use isConnected() return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 ); @@ -496,6 +652,7 @@ const char SCA_JoystickSensor::NumberOfButtons_doc[] = "getNumButtons\n" "\tReturns the number of buttons .\n"; PyObject* SCA_JoystickSensor::PyNumberOfButtons( PyObject* self ) { + ShowDeprecationWarning("getNumButtons()", "the numButtons property"); SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 ); } @@ -505,6 +662,7 @@ const char SCA_JoystickSensor::NumberOfHats_doc[] = "getNumHats\n" "\tReturns the number of hats .\n"; PyObject* SCA_JoystickSensor::PyNumberOfHats( PyObject* self ) { + ShowDeprecationWarning("getNumHats()", "the numHats property"); SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 ); } @@ -513,6 +671,7 @@ const char SCA_JoystickSensor::Connected_doc[] = "getConnected\n" "\tReturns True if a joystick is connected at this joysticks index.\n"; PyObject* SCA_JoystickSensor::PyConnected( PyObject* self ) { + ShowDeprecationWarning("getConnected()", "the connected property"); SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); return PyBool_FromLong( joy ? joy->Connected() : 0 ); } diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.h b/source/gameengine/GameLogic/SCA_JoystickSensor.h index d316ad1119c..03653070db7 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.h +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.h @@ -122,6 +122,7 @@ public: /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject *value); /* Joystick Index */ KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetIndex); @@ -136,6 +137,8 @@ public: KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetButton); KX_PYMETHOD_DOC_O(SCA_JoystickSensor,SetButton); KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetButtonValue); + KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetButtonActiveList); + KX_PYMETHOD_DOC_VARARGS(SCA_JoystickSensor,GetButtonStatus); /* Hats */ KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetHat); KX_PYMETHOD_DOC_VARARGS(SCA_JoystickSensor,SetHat); diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index fa39a13679f..f880cd7768e 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -545,42 +545,17 @@ void SCA_KeyboardSensor::LogKeystrokes(void) /* ------------------------------------------------------------------------- */ -/* Python functions : specific */ +/* Python Functions */ /* ------------------------------------------------------------------------- */ - -PyObject* SCA_KeyboardSensor::PySetAllMode(PyObject* self, - PyObject* args, - PyObject* kwds) -{ - bool allkeys; - - if (!PyArg_ParseTuple(args, "i", &allkeys)) - { - return NULL; - } - - m_bAllKeys = allkeys; - Py_Return -} - - - -PyObject* SCA_KeyboardSensor::sPySetAllMode(PyObject* self, - PyObject* args, - PyObject* kwds) -{ -// printf("sPyIsPositive\n"); - return ((SCA_KeyboardSensor*) self)->PyIsPositive(self); -} - - +//Deprecated -----> /** 1. GetKey : check which key this sensor looks at */ const char SCA_KeyboardSensor::GetKey_doc[] = "getKey()\n" "\tReturn the code of the key this sensor is listening to.\n" ; PyObject* SCA_KeyboardSensor::PyGetKey(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getKey()", "the key property"); return PyInt_FromLong(m_hotkey); } @@ -591,6 +566,7 @@ const char SCA_KeyboardSensor::SetKey_doc[] = "\tSet the key this sensor should listen to.\n" ; PyObject* SCA_KeyboardSensor::PySetKey(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setKey()", "the key property"); int keyCode; if(!PyArg_ParseTuple(args, "i", &keyCode)) { @@ -611,6 +587,7 @@ const char SCA_KeyboardSensor::GetHold1_doc[] = "\tsensor is listening to.\n" ; PyObject* SCA_KeyboardSensor::PyGetHold1(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getHold1()", "the hold1 property"); return PyInt_FromLong(m_qual); } @@ -621,6 +598,7 @@ const char SCA_KeyboardSensor::SetHold1_doc[] = "\tSet the first modifier to the key this sensor should listen to.\n" ; PyObject* SCA_KeyboardSensor::PySetHold1(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setHold1()", "the hold1 property"); int keyCode; if(!PyArg_ParseTuple(args, "i", &keyCode)) { @@ -641,6 +619,7 @@ const char SCA_KeyboardSensor::GetHold2_doc[] = "\tsensor is listening to.\n" ; PyObject* SCA_KeyboardSensor::PyGetHold2(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getHold2()", "the hold2 property"); return PyInt_FromLong(m_qual2); } @@ -651,6 +630,7 @@ const char SCA_KeyboardSensor::SetHold2_doc[] = "\tSet the first modifier to the key this sensor should listen to.\n" ; PyObject* SCA_KeyboardSensor::PySetHold2(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setHold2()", "the hold2 property"); int keyCode; if(!PyArg_ParseTuple(args, "i", &keyCode)) { @@ -671,6 +651,8 @@ const char SCA_KeyboardSensor::GetPressedKeys_doc[] = PyObject* SCA_KeyboardSensor::PyGetPressedKeys(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getPressedKeys()", "getEventList()"); + SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); int num = inputdev->GetNumJustEvents(); @@ -711,6 +693,8 @@ const char SCA_KeyboardSensor::GetCurrentlyPressedKeys_doc[] = PyObject* SCA_KeyboardSensor::PyGetCurrentlyPressedKeys(PyObject* self, PyObject* args, PyObject* kwds) { +ShowDeprecationWarning("getCurrentlyPressedKeys()", "getEventList()"); + SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); int num = inputdev->GetNumActiveEvents(); @@ -743,9 +727,54 @@ SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); Py_Return; } +//<---- Deprecated + +KX_PYMETHODDEF_DOC_NOARGS(SCA_KeyboardSensor, getEventList, +"getEventList()\n" +"\tGet the list of the keyboard events in this frame.\n") +{ + SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); + + PyObject* resultlist = PyList_New(0); + + for (int i=SCA_IInputDevice::KX_BEGINKEY ; i< SCA_IInputDevice::KX_ENDKEY;i++) + { + const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) i); + if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS) + { + PyObject* keypair = PyList_New(2); + PyList_SetItem(keypair,0,PyInt_FromLong(i)); + PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status)); + PyList_Append(resultlist,keypair); + } + } + return resultlist; +} + +KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus, +"getKeyStatus(keycode)\n" +"\tGet the given key's status (KX_NO_INPUTSTATUS, KX_JUSTACTIVATED, KX_ACTIVE or KX_JUSTRELEASED).\n") +{ + if (PyInt_Check(value)) + { + int keycode = PyInt_AsLong(value); + + if ((keycode < SCA_IInputDevice::KX_BEGINKEY) + || (keycode > SCA_IInputDevice::KX_ENDKEY)){ + PyErr_SetString(PyExc_AttributeError, "invalid keycode specified!"); + return NULL; + } + + SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); + const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) keycode); + return PyInt_FromLong(inevent.m_status); + } + + Py_Return; +} /* ------------------------------------------------------------------------- */ -/* Python functions : integration hooks */ +/* Python Integration Hooks */ /* ------------------------------------------------------------------------- */ PyTypeObject SCA_KeyboardSensor::Type = { @@ -776,23 +805,91 @@ PyParentObject SCA_KeyboardSensor::Parents[] = { }; PyMethodDef SCA_KeyboardSensor::Methods[] = { - {"getKey", (PyCFunction) SCA_KeyboardSensor::sPyGetKey, METH_VARARGS, (PY_METHODCHAR)GetKey_doc}, - {"setKey", (PyCFunction) SCA_KeyboardSensor::sPySetKey, METH_VARARGS, (PY_METHODCHAR)SetKey_doc}, - {"getHold1", (PyCFunction) SCA_KeyboardSensor::sPyGetHold1, METH_VARARGS, (PY_METHODCHAR)GetHold1_doc}, - {"setHold1", (PyCFunction) SCA_KeyboardSensor::sPySetHold1, METH_VARARGS, (PY_METHODCHAR)SetHold1_doc}, - {"getHold2", (PyCFunction) SCA_KeyboardSensor::sPyGetHold2, METH_VARARGS, (PY_METHODCHAR)GetHold2_doc}, - {"setHold2", (PyCFunction) SCA_KeyboardSensor::sPySetHold2, METH_VARARGS, (PY_METHODCHAR)SetHold2_doc}, -// {"getUseAllKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetUseAllKeys, METH_VARARGS, (PY_METHODCHAR)GetUseAllKeys_doc}, -// {"setUseAllKeys", (PyCFunction) SCA_KeyboardSensor::sPySetUseAllKeys, METH_VARARGS, (PY_METHODCHAR)SetUseAllKeys_doc}, - {"getPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetPressedKeys, METH_VARARGS, (PY_METHODCHAR)GetPressedKeys_doc}, - {"getCurrentlyPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetCurrentlyPressedKeys, METH_VARARGS, (PY_METHODCHAR)GetCurrentlyPressedKeys_doc}, -// {"getKeyEvents", (PyCFunction) SCA_KeyboardSensor::sPyGetKeyEvents, METH_VARARGS, (PY_METHODCHAR)GetKeyEvents_doc}, - {NULL,NULL} //Sentinel + //Deprecated functions ------> + {"getKey", (PyCFunction) SCA_KeyboardSensor::sPyGetKey, METH_VARARGS, (PY_METHODCHAR)GetKey_doc}, + {"setKey", (PyCFunction) SCA_KeyboardSensor::sPySetKey, METH_VARARGS, (PY_METHODCHAR)SetKey_doc}, + {"getHold1", (PyCFunction) SCA_KeyboardSensor::sPyGetHold1, METH_VARARGS, (PY_METHODCHAR)GetHold1_doc}, + {"setHold1", (PyCFunction) SCA_KeyboardSensor::sPySetHold1, METH_VARARGS, (PY_METHODCHAR)SetHold1_doc}, + {"getHold2", (PyCFunction) SCA_KeyboardSensor::sPyGetHold2, METH_VARARGS, (PY_METHODCHAR)GetHold2_doc}, + {"setHold2", (PyCFunction) SCA_KeyboardSensor::sPySetHold2, METH_VARARGS, (PY_METHODCHAR)SetHold2_doc}, + {"getPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetPressedKeys, METH_VARARGS, (PY_METHODCHAR)GetPressedKeys_doc}, + {"getCurrentlyPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetCurrentlyPressedKeys, METH_VARARGS, (PY_METHODCHAR)GetCurrentlyPressedKeys_doc}, + //<----- Deprecated + KX_PYMETHODTABLE_NOARGS(SCA_KeyboardSensor, getEventList), + KX_PYMETHODTABLE_O(SCA_KeyboardSensor, getKeyStatus), + {NULL,NULL} //Sentinel }; PyObject* SCA_KeyboardSensor::_getattr(const STR_String& attr) { + if (attr == "key") + return PyInt_FromLong(m_hotkey); + + if (attr == "hold1") + return PyInt_FromLong(m_qual); + + if (attr == "hold2") + return PyInt_FromLong(m_qual2); + + if (attr == "toggleProperty") + return PyString_FromString(m_toggleprop); + + if (attr == "targetProperty") + return PyString_FromString(m_targetprop); + + if (attr == "useAllKeys") + return PyInt_FromLong(m_bAllKeys); + _getattr_up(SCA_ISensor); } +int SCA_KeyboardSensor::_setattr(const STR_String& attr, PyObject *value) +{ + if (PyInt_Check(value)) + { + int val = PyInt_AsLong(value); + + if (attr == "key") + { + m_hotkey = val; + return 0; + } + + if (attr == "hold1") + { + m_qual = val; + return 0; + } + + if (attr == "hold2") + { + m_qual2 = val; + return 0; + } + + if (attr == "useAllKeys") + { + m_bAllKeys = (val != 0); + return 0; + } + } + + if (PyString_Check(value)) + { + STR_String val = PyString_AsString(value); + if (attr == "logToggleProperty") + { + m_toggleprop = val; + return 0; + } + + if (attr == "logTargetProperty") + { + m_targetprop = val; + return 0; + } + } + + return SCA_ISensor::_setattr(attr, value); +} diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.h b/source/gameengine/GameLogic/SCA_KeyboardSensor.h index b86f6931d27..4efbe9366cc 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.h +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.h @@ -127,15 +127,9 @@ public: /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject *value); - - PyObject* PySetAllMode(PyObject* self, - PyObject* args, - PyObject* kwds); - static PyObject* sPySetAllMode(PyObject* self, - PyObject* args, - PyObject* kwds); - + //Deprecated functions -----> /** 1. GetKey : check which key this sensor looks at */ KX_PYMETHOD_DOC(SCA_KeyboardSensor,GetKey); /** 2. SetKey: change the key to look at */ @@ -152,6 +146,12 @@ public: KX_PYMETHOD_DOC(SCA_KeyboardSensor,GetPressedKeys); /** 9. GetCurrrentlyPressedKeys: */ KX_PYMETHOD_DOC(SCA_KeyboardSensor,GetCurrentlyPressedKeys); + // <------ + + // KeyEvents: + KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,getEventList); + // KeyStatus: + KX_PYMETHOD_DOC_O(SCA_KeyboardSensor,getKeyStatus); }; #endif //__KX_KEYBOARDSENSOR diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index d4952ce4777..9562003aec0 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -25,7 +25,7 @@ * * The Original Code is: all of this file. * - * Contributor(s): none yet. + * Contributor(s): José I. Romero (cleanup and fixes) * * ***** END GPL LICENSE BLOCK ***** */ @@ -59,6 +59,29 @@ SCA_MouseSensor::SCA_MouseSensor(SCA_MouseManager* eventmgr, m_mousemode = mousemode; m_triggermode = true; + UpdateHotkey(); + Init(); +} + +void SCA_MouseSensor::Init() +{ + m_val = (m_invert)?1:0; /* stores the latest attribute */ + m_reset = true; +} + +SCA_MouseSensor::~SCA_MouseSensor() +{ + /* Nothing to be done here. */ +} + +void SCA_MouseSensor::UpdateHotkey() +{ + // gosh, this function is so damn stupid + // its here because of a design mistake in the mouse sensor, it should only + // have 3 trigger modes (button, wheel, move), and let the user set the + // hotkey separately, like the other sensors. but instead it has a mode for + // each friggin key and i have to update the hotkey based on it... genius! + switch (m_mousemode) { case KX_MOUSESENSORMODE_LEFTBUTTON: m_hotkey = SCA_IInputDevice::KX_LEFTMOUSE; @@ -78,22 +101,8 @@ SCA_MouseSensor::SCA_MouseSensor(SCA_MouseManager* eventmgr, default: ; /* ignore, no hotkey */ } - Init(); -} - -void SCA_MouseSensor::Init() -{ - m_val = (m_invert)?1:0; /* stores the latest attribute */ - m_reset = true; } -SCA_MouseSensor::~SCA_MouseSensor() -{ - /* Nothing to be done here. */ -} - - - CValue* SCA_MouseSensor::GetReplica() { SCA_MouseSensor* replica = new SCA_MouseSensor(*this); @@ -137,15 +146,6 @@ bool SCA_MouseSensor::Evaluate(CValue* event) bool reset = m_reset && m_level; SCA_IInputDevice* mousedev = m_pMouseMgr->GetInputDevice(); - - -// SCA_ILogicBrick::RegisterEvent(event); -// if (m_mousemode == KX_MOUSESENSORMODE_MOVEMENT) cout << "\nChecking for movement..."; -//CValue* val = event->GetProperty("val"); - - /* both MOUSEX and MOUSEY. Treat all of these as key-presses. */ - /* So, treat KX_MOUSESENSORMODE_POSITION as */ - /* KX_MOUSESENSORMODE_POSITIONX || KX_MOUSESENSORMODE_POSITIONY */ m_reset = false; switch (m_mousemode) { case KX_MOUSESENSORMODE_LEFTBUTTON: @@ -155,42 +155,34 @@ bool SCA_MouseSensor::Evaluate(CValue* event) case KX_MOUSESENSORMODE_WHEELDOWN: { const SCA_InputEvent& event = mousedev->GetEventValue(m_hotkey); - if (event.m_status == SCA_InputEvent::KX_JUSTACTIVATED) - { + switch (event.m_status){ + case SCA_InputEvent::KX_JUSTACTIVATED: m_val = 1; result = true; - } else - { - if (event.m_status == SCA_InputEvent::KX_JUSTRELEASED) + break; + case SCA_InputEvent::KX_JUSTRELEASED: + m_val = 0; + result = true; + break; + case SCA_InputEvent::KX_ACTIVE: + if (m_val == 0) + { + m_val = 1; + if (m_level) + result = true; + } + break; + default: + if (m_val == 1) { m_val = 0; result = true; - } else - { - if (event.m_status == SCA_InputEvent::KX_ACTIVE) - { - if (m_val == 0) - { - m_val = 1; - if (m_level) - { - result = true; - } - } - } else - { - if (m_val == 1) - { - m_val = 0; - result = true; - } - } } + break; } break; } case KX_MOUSESENSORMODE_MOVEMENT: - { const SCA_InputEvent& eventX = mousedev->GetEventValue(SCA_IInputDevice::KX_MOUSEX); const SCA_InputEvent& eventY = mousedev->GetEventValue(SCA_IInputDevice::KX_MOUSEY); @@ -198,27 +190,26 @@ bool SCA_MouseSensor::Evaluate(CValue* event) if (eventX.m_status == SCA_InputEvent::KX_JUSTACTIVATED || eventY.m_status == SCA_InputEvent::KX_JUSTACTIVATED || eventX.m_status == SCA_InputEvent::KX_ACTIVE || - eventY.m_status == SCA_InputEvent::KX_ACTIVE) - + eventY.m_status == SCA_InputEvent::KX_ACTIVE) { m_val = 1; result = true; - } else - { - if (eventX.m_status == SCA_InputEvent::KX_JUSTRELEASED || + } + else if (eventX.m_status == SCA_InputEvent::KX_JUSTRELEASED || eventY.m_status == SCA_InputEvent::KX_JUSTRELEASED ) + { + m_val = 0; + result = true; + } + else //KX_NO_IMPUTSTATUS + { + if (m_val == 1) { m_val = 0; result = true; - } else - { - if (m_val == 1) - { - m_val = 0; - result = true; - } } } + break; } default: @@ -243,18 +234,67 @@ void SCA_MouseSensor::setY(short y) bool SCA_MouseSensor::isValid(SCA_MouseSensor::KX_MOUSESENSORMODE m) { - bool res = false; + return ((m > KX_MOUSESENSORMODE_NODEF) && (m < KX_MOUSESENSORMODE_MAX)); +} + +/* ------------------------------------------------------------------------- */ +/* Python functions */ +/* ------------------------------------------------------------------------- */ - res = ((m > KX_MOUSESENSORMODE_NODEF) && (m < KX_MOUSESENSORMODE_MAX)); +//Deprecated functions ------> +/* get x position ---------------------------------------------------------- */ +const char SCA_MouseSensor::GetXPosition_doc[] = +"getXPosition\n" +"\tReturns the x-coordinate of the mouse sensor, in frame coordinates.\n" +"\tThe lower-left corner is the origin. The coordinate is given in\n" +"\tpixels\n"; +PyObject* SCA_MouseSensor::PyGetXPosition(PyObject* self, + PyObject* args, + PyObject* kwds) { + ShowDeprecationWarning("getXPosition()", "the position property"); + return PyInt_FromLong(m_x); +} + +/* get y position ---------------------------------------------------------- */ +const char SCA_MouseSensor::GetYPosition_doc[] = +"getYPosition\n" +"\tReturns the y-coordinate of the mouse sensor, in frame coordinates.\n" +"\tThe lower-left corner is the origin. The coordinate is given in\n" +"\tpixels\n"; +PyObject* SCA_MouseSensor::PyGetYPosition(PyObject* self, + PyObject* args, + PyObject* kwds) { + ShowDeprecationWarning("getYPosition()", "the position property"); + return PyInt_FromLong(m_y); +} +//<----- Deprecated + +KX_PYMETHODDEF_DOC_O(SCA_MouseSensor, getButtonStatus, +"getButtonStatus(button)\n" +"\tGet the given button's status (KX_NO_INPUTSTATUS, KX_JUSTACTIVATED, KX_ACTIVE or KX_JUSTRELEASED).\n") +{ + if (PyInt_Check(value)) + { + int button = PyInt_AsLong(value); + + if ((button < SCA_IInputDevice::KX_LEFTMOUSE) + || (button > SCA_IInputDevice::KX_MIDDLEMOUSE)){ + PyErr_SetString(PyExc_ValueError, "invalid button specified!"); + return NULL; + } + + SCA_IInputDevice* mousedev = m_pMouseMgr->GetInputDevice(); + const SCA_InputEvent& event = mousedev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) button); + return PyInt_FromLong(event.m_status); + } - return res; + Py_Return; } /* ------------------------------------------------------------------------- */ -/* Python functions */ +/* Python Integration Hooks */ /* ------------------------------------------------------------------------- */ -/* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_MouseSensor::Type = { PyObject_HEAD_INIT(&PyType_Type) 0, @@ -283,37 +323,54 @@ PyParentObject SCA_MouseSensor::Parents[] = { }; PyMethodDef SCA_MouseSensor::Methods[] = { + //Deprecated functions ------> {"getXPosition", (PyCFunction) SCA_MouseSensor::sPyGetXPosition, METH_VARARGS, (PY_METHODCHAR)GetXPosition_doc}, {"getYPosition", (PyCFunction) SCA_MouseSensor::sPyGetYPosition, METH_VARARGS, (PY_METHODCHAR)GetYPosition_doc}, + //<----- Deprecated + KX_PYMETHODTABLE_O(SCA_MouseSensor, getButtonStatus), {NULL,NULL} //Sentinel }; PyObject* SCA_MouseSensor::_getattr(const STR_String& attr) { + if (attr == "position") + return Py_BuildValue("[ii]", m_x, m_y); + + if (attr == "mode") + return PyInt_FromLong(m_mousemode); + _getattr_up(SCA_ISensor); } -/* get x position ---------------------------------------------------------- */ -const char SCA_MouseSensor::GetXPosition_doc[] = -"getXPosition\n" -"\tReturns the x-coordinate of the mouse sensor, in frame coordinates.\n" -"\tThe lower-left corner is the origin. The coordinate is given in\n" -"\tpixels\n"; -PyObject* SCA_MouseSensor::PyGetXPosition(PyObject* self, - PyObject* args, - PyObject* kwds) { - return PyInt_FromLong(m_x); -} +int SCA_MouseSensor::_setattr(const STR_String& attr, PyObject *value) +{ + if (PyInt_Check(value)) + { + int val = PyInt_AsLong(value); -/* get y position ---------------------------------------------------------- */ -const char SCA_MouseSensor::GetYPosition_doc[] = -"getYPosition\n" -"\tReturns the y-coordinate of the mouse sensor, in frame coordinates.\n" -"\tThe lower-left corner is the origin. The coordinate is given in\n" -"\tpixels\n"; -PyObject* SCA_MouseSensor::PyGetYPosition(PyObject* self, - PyObject* args, - PyObject* kwds) { - return PyInt_FromLong(m_y); + if (attr == "mode") + { + if ((val < KX_MOUSESENSORMODE_NODEF) + || (val > KX_MOUSESENSORMODE_MAX)){ + + PyErr_SetString(PyExc_ValueError, "invalid mode specified!"); + return NULL; + } + + m_mousemode = val; + UpdateHotkey(); + return 0; + } + } + else + { + if (attr == "position") + { + PyErr_SetString(PyExc_AttributeError, "read-only property!"); + return NULL; + } + } + + return SCA_ISensor::_setattr(attr, value); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.h b/source/gameengine/GameLogic/SCA_MouseSensor.h index 26a1c5e3fd2..6d6e641c798 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.h +++ b/source/gameengine/GameLogic/SCA_MouseSensor.h @@ -24,7 +24,7 @@ * * The Original Code is: all of this file. * - * Contributor(s): none yet. + * Contributor(s): José I. Romero (cleanup and fixes) * * ***** END GPL LICENSE BLOCK ***** */ @@ -87,6 +87,8 @@ class SCA_MouseSensor : public SCA_ISensor bool isValid(KX_MOUSESENSORMODE); + void UpdateHotkey(); + SCA_MouseSensor(class SCA_MouseManager* keybdmgr, int startx,int starty, short int mousemode, @@ -108,11 +110,17 @@ class SCA_MouseSensor : public SCA_ISensor /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject *value); + //Deprecated functions -----> /* read x-coordinate */ KX_PYMETHOD_DOC(SCA_MouseSensor,GetXPosition); /* read y-coordinate */ KX_PYMETHOD_DOC(SCA_MouseSensor,GetYPosition); + //<----- deprecated + + // get button status + KX_PYMETHOD_DOC_O(SCA_MouseSensor,getButtonStatus); }; diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index 3b541e87f02..f8509fe380e 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -245,17 +245,48 @@ PyParentObject SCA_PropertyActuator::Parents[] = { }; PyMethodDef SCA_PropertyActuator::Methods[] = { + //Deprecated functions ------> {"setProperty", (PyCFunction) SCA_PropertyActuator::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc}, {"getProperty", (PyCFunction) SCA_PropertyActuator::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc}, {"setValue", (PyCFunction) SCA_PropertyActuator::sPySetValue, METH_VARARGS, (PY_METHODCHAR)SetValue_doc}, {"getValue", (PyCFunction) SCA_PropertyActuator::sPyGetValue, METH_VARARGS, (PY_METHODCHAR)GetValue_doc}, + //<----- Deprecated {NULL,NULL} //Sentinel }; PyObject* SCA_PropertyActuator::_getattr(const STR_String& attr) { + if (attr == "property") { + return PyString_FromString(m_propname); + } + if (attr == "value") { + return PyString_FromString(m_exprtxt); + } _getattr_up(SCA_IActuator); } +int SCA_PropertyActuator::_setattr(const STR_String& attr, PyObject *value) { + if (PyString_Check(value)) { + char* sval = PyString_AsString(value); + if (attr == "property") { + CValue* prop = GetParent()->FindIdentifier(sval); + bool error = prop->IsError(); + prop->Release(); + if (!prop->IsError()) { + m_propname = sval; + return 0; + } else { + PyErr_SetString(PyExc_ValueError, "string does not correspond to a property"); + return 1; + } + } + if (attr == "value") { + m_exprtxt = sval; + return 0; + } + } + return SCA_IActuator::_setattr(attr, value); +} + /* 1. setProperty */ const char SCA_PropertyActuator::SetProperty_doc[] = "setProperty(name)\n" @@ -264,6 +295,7 @@ const char SCA_PropertyActuator::SetProperty_doc[] = "\tof this name, the call is ignored.\n"; PyObject* SCA_PropertyActuator::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setProperty()", "the 'property' property"); /* Check whether the name exists first ! */ char *nameArg; if (!PyArg_ParseTuple(args, "s", &nameArg)) { @@ -288,6 +320,7 @@ const char SCA_PropertyActuator::GetProperty_doc[] = "\tReturn the property on which the actuator operates.\n"; PyObject* SCA_PropertyActuator::PyGetProperty(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getProperty()", "the 'property' property"); return PyString_FromString(m_propname); } @@ -300,6 +333,7 @@ const char SCA_PropertyActuator::SetValue_doc[] = "\t action is ignored.\n"; PyObject* SCA_PropertyActuator::PySetValue(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setValue()", "the value property"); char *valArg; if(!PyArg_ParseTuple(args, "s", &valArg)) { return NULL; @@ -316,6 +350,7 @@ const char SCA_PropertyActuator::GetValue_doc[] = "\tReturns the value with which the actuator operates.\n"; PyObject* SCA_PropertyActuator::PyGetValue(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getValue()", "the value property"); return PyString_FromString(m_exprtxt); } diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.h b/source/gameengine/GameLogic/SCA_PropertyActuator.h index 1e435684572..cdfeee4c67d 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.h +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.h @@ -86,6 +86,7 @@ public: /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject *value); // python wrapped methods KX_PYMETHOD_DOC(SCA_PropertyActuator,SetProperty); diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp index 64e3d49c6cb..19ee85207bb 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp +++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp @@ -333,25 +333,72 @@ PyParentObject SCA_PropertySensor::Parents[] = { }; PyMethodDef SCA_PropertySensor::Methods[] = { + //Deprecated functions ------> {"getType", (PyCFunction) SCA_PropertySensor::sPyGetType, METH_VARARGS, (PY_METHODCHAR)GetType_doc}, {"setType", (PyCFunction) SCA_PropertySensor::sPySetType, METH_VARARGS, (PY_METHODCHAR)SetType_doc}, {"getProperty", (PyCFunction) SCA_PropertySensor::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc}, {"setProperty", (PyCFunction) SCA_PropertySensor::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc}, {"getValue", (PyCFunction) SCA_PropertySensor::sPyGetValue, METH_VARARGS, (PY_METHODCHAR)GetValue_doc}, {"setValue", (PyCFunction) SCA_PropertySensor::sPySetValue, METH_VARARGS, (PY_METHODCHAR)SetValue_doc}, + //<----- Deprecated {NULL,NULL} //Sentinel }; PyObject* SCA_PropertySensor::_getattr(const STR_String& attr) { + if (attr == "type") { + return PyInt_FromLong(m_checktype); + } + if (attr == "property") { + return PyString_FromString(m_checkpropname); + } + if (attr == "value") { + return PyString_FromString(m_checkpropval); + } _getattr_up(SCA_ISensor); /* implicit return! */ } +int SCA_PropertySensor::_setattr(const STR_String& attr, PyObject *value) { + if (PyInt_Check(value)) { + int ival = PyInt_AsLong(value); + if (attr == "type") { + if ((ival <= KX_PROPSENSOR_NODEF) || (ival >= KX_PROPSENSOR_MAX)) { + PyErr_SetString(PyExc_ValueError, "type out of range"); + return 1; + } + m_checktype = ival; + } + return 0; + } + if (PyString_Check(value)) { + char* sval = PyString_AsString(value); + if (attr == "property") { + CValue *prop = FindIdentifier(STR_String(sval)); + bool error = prop->IsError(); + prop->Release(); + if (error) { + PyErr_SetString(PyExc_ValueError, "string does not correspond to a property"); + return 1; + } + m_checkpropname = sval; + } else if (attr == "value") { + if (!validValueForProperty(sval, m_checkpropname)) { + PyErr_SetString(PyExc_ValueError, "string does not represent a suitable value for the property"); + return 1; + } + m_checkpropval = sval; + } + return 0; + } + return SCA_ISensor::_setattr(attr, value); +} + /* 1. getType */ const char SCA_PropertySensor::GetType_doc[] = "getType()\n" "\tReturns the type of check this sensor performs.\n"; PyObject* SCA_PropertySensor::PyGetType(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getType()", "the type property"); return PyInt_FromLong(m_checktype); } @@ -364,6 +411,7 @@ const char SCA_PropertySensor::SetType_doc[] = "\tSet the type of check to perform.\n"; PyObject* SCA_PropertySensor::PySetType(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setType()", "the type property"); int typeArg; if (!PyArg_ParseTuple(args, "i", &typeArg)) { @@ -384,6 +432,7 @@ const char SCA_PropertySensor::GetProperty_doc[] = "\tReturn the property with which the sensor operates.\n"; PyObject* SCA_PropertySensor::PyGetProperty(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getProperty()", "the 'property' property"); return PyString_FromString(m_checkpropname); } @@ -395,6 +444,7 @@ const char SCA_PropertySensor::SetProperty_doc[] = "\tof this name, the call is ignored.\n"; PyObject* SCA_PropertySensor::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setProperty()", "the 'property' property"); /* We should query whether the name exists. Or should we create a prop */ /* on the fly? */ char *propNameArg = NULL; @@ -419,6 +469,7 @@ const char SCA_PropertySensor::GetValue_doc[] = "\tReturns the value with which the sensor operates.\n"; PyObject* SCA_PropertySensor::PyGetValue(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getValue()", "the value property"); return PyString_FromString(m_checkpropval); } @@ -431,6 +482,7 @@ const char SCA_PropertySensor::SetValue_doc[] = "\t action is ignored.\n"; PyObject* SCA_PropertySensor::PySetValue(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setValue()", "the value property"); /* Here, we need to check whether the value is 'valid' for this property.*/ /* We know that the property exists, or is NULL. */ char *propValArg = NULL; diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.h b/source/gameengine/GameLogic/SCA_PropertySensor.h index 6871cb3afdc..81203c78f9d 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.h +++ b/source/gameengine/GameLogic/SCA_PropertySensor.h @@ -90,6 +90,7 @@ public: /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject *value); /* 1. getType */ KX_PYMETHOD_DOC(SCA_PropertySensor,GetType); diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index c354ab39747..e879481a444 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -233,9 +233,11 @@ PyMethodDef SCA_PythonController::Methods[] = { {"getActuator", (PyCFunction) SCA_PythonController::sPyGetActuator, METH_O, (PY_METHODCHAR)SCA_PythonController::GetActuator_doc}, {"getSensors", (PyCFunction) SCA_PythonController::sPyGetSensors, METH_NOARGS, (PY_METHODCHAR)SCA_PythonController::GetSensors_doc}, {"getSensor", (PyCFunction) SCA_PythonController::sPyGetSensor, METH_O, (PY_METHODCHAR)SCA_PythonController::GetSensor_doc}, - {"getScript", (PyCFunction) SCA_PythonController::sPyGetScript, METH_NOARGS}, {"setScript", (PyCFunction) SCA_PythonController::sPySetScript, METH_O}, + //Deprecated functions ------> + {"getScript", (PyCFunction) SCA_PythonController::sPyGetScript, METH_NOARGS}, {"getState", (PyCFunction) SCA_PythonController::sPyGetState, METH_NOARGS}, + //<----- Deprecated {NULL,NULL} //Sentinel }; @@ -329,9 +331,27 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) PyObject* SCA_PythonController::_getattr(const STR_String& attr) { + if (attr == "script") { + return PyString_FromString(m_scriptText); + } + if (attr == "state") { + return PyInt_FromLong(m_statemask); + } _getattr_up(SCA_IController); } +int SCA_PythonController::_setattr(const STR_String& attr, PyObject *value) +{ + if (attr == "script") { + PyErr_SetString(PyExc_AttributeError, "script is read only, use setScript() to update the script"); + return 1; + } + if (attr == "state") { + PyErr_SetString(PyExc_AttributeError, "state is read only"); + return 1; + } + return SCA_IController::_setattr(attr, value); +} PyObject* SCA_PythonController::PyGetActuators(PyObject* self) @@ -420,6 +440,7 @@ SCA_PythonController::PyGetSensors(PyObject* self) /* 1. getScript */ PyObject* SCA_PythonController::PyGetScript(PyObject* self) { + ShowDeprecationWarning("getScript()", "the script property"); return PyString_FromString(m_scriptText); } @@ -443,6 +464,7 @@ PyObject* SCA_PythonController::PySetScript(PyObject* self, PyObject* value) /* 1. getScript */ PyObject* SCA_PythonController::PyGetState(PyObject* self) { + ShowDeprecationWarning("getState()", "the state property"); return PyInt_FromLong(m_statemask); } diff --git a/source/gameengine/GameLogic/SCA_PythonController.h b/source/gameengine/GameLogic/SCA_PythonController.h index d9b2e242bea..1918cc488d8 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.h +++ b/source/gameengine/GameLogic/SCA_PythonController.h @@ -77,6 +77,7 @@ class SCA_PythonController : public SCA_IController static PyObject* sPyAddActiveActuator(PyObject* self, PyObject* args); virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject *value); KX_PYMETHOD_DOC_NOARGS(SCA_PythonController,GetSensors); KX_PYMETHOD_DOC_NOARGS(SCA_PythonController,GetActuators); diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp index 7b50a483cd8..8dd405c3d82 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp +++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp @@ -339,6 +339,7 @@ PyParentObject SCA_RandomActuator::Parents[] = { }; PyMethodDef SCA_RandomActuator::Methods[] = { + //Deprecated functions ------> {"setSeed", (PyCFunction) SCA_RandomActuator::sPySetSeed, METH_VARARGS, (PY_METHODCHAR)SetSeed_doc}, {"getSeed", (PyCFunction) SCA_RandomActuator::sPyGetSeed, METH_VARARGS, (PY_METHODCHAR)GetSeed_doc}, {"getPara1", (PyCFunction) SCA_RandomActuator::sPyGetPara1, METH_VARARGS, (PY_METHODCHAR)GetPara1_doc}, @@ -346,6 +347,7 @@ PyMethodDef SCA_RandomActuator::Methods[] = { {"getDistribution", (PyCFunction) SCA_RandomActuator::sPyGetDistribution, METH_VARARGS, (PY_METHODCHAR)GetDistribution_doc}, {"setProperty", (PyCFunction) SCA_RandomActuator::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc}, {"getProperty", (PyCFunction) SCA_RandomActuator::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc}, + //<----- Deprecated {"setBoolConst", (PyCFunction) SCA_RandomActuator::sPySetBoolConst, METH_VARARGS, (PY_METHODCHAR)SetBoolConst_doc}, {"setBoolUniform", (PyCFunction) SCA_RandomActuator::sPySetBoolUniform, METH_VARARGS, (PY_METHODCHAR)SetBoolUniform_doc}, {"setBoolBernouilli",(PyCFunction) SCA_RandomActuator::sPySetBoolBernouilli, METH_VARARGS, (PY_METHODCHAR)SetBoolBernouilli_doc}, @@ -360,9 +362,60 @@ PyMethodDef SCA_RandomActuator::Methods[] = { }; PyObject* SCA_RandomActuator::_getattr(const STR_String& attr) { + if (attr == "seed") { + return PyInt_FromLong(m_base->GetSeed()); + } + if (attr == "para1") { + return PyFloat_FromDouble(m_parameter1); + } + if (attr == "para2") { + return PyFloat_FromDouble(m_parameter2); + } + if (attr == "distribution") { + return PyInt_FromLong(m_distribution); + } + if (attr == "property") { + return PyString_FromString(m_propname); + } _getattr_up(SCA_IActuator); } +int SCA_RandomActuator::_setattr(const STR_String& attr, PyObject *value) +{ + if (attr == "para1") { + PyErr_SetString(PyExc_AttributeError, "para1 is read only"); + } + if (attr == "para2") { + PyErr_SetString(PyExc_AttributeError, "para2 is read only"); + } + if (attr == "distribution") { + PyErr_SetString(PyExc_AttributeError, "distribution is read only"); + } + if (PyInt_Check(value)) { + int ival = PyInt_AsLong(value); + if (attr == "seed") { + m_base->SetSeed(ival); + } + return 0; + } + if (PyString_Check(value)) { + char* sval = PyString_AsString(value); + if (attr == "property") { + CValue* prop = GetParent()->FindIdentifier(sval); + bool error = prop->IsError(); + prop->Release(); + if (!prop->IsError()) { + m_propname = sval; + return 0; + } else { + PyErr_SetString(PyExc_ValueError, "string does not correspond to a property"); + return 1; + } + } + } + return SCA_IActuator::_setattr(attr, value); +} + /* 1. setSeed */ const char SCA_RandomActuator::SetSeed_doc[] = "setSeed(seed)\n" @@ -371,6 +424,7 @@ const char SCA_RandomActuator::SetSeed_doc[] = "\tequal series. If the seed is 0, the generator will produce\n" "\tthe same value on every call.\n"; PyObject* SCA_RandomActuator::PySetSeed(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setSeed()", "the seed property"); long seedArg; if(!PyArg_ParseTuple(args, "i", &seedArg)) { return NULL; @@ -386,6 +440,7 @@ const char SCA_RandomActuator::GetSeed_doc[] = "\tReturns the initial seed of the generator. Equal seeds produce\n" "\tequal series.\n"; PyObject* SCA_RandomActuator::PyGetSeed(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getSeed()", "the seed property"); return PyInt_FromLong(m_base->GetSeed()); } @@ -396,6 +451,7 @@ const char SCA_RandomActuator::GetPara1_doc[] = "\tto the documentation of the generator types for the meaning\n" "\tof this value."; PyObject* SCA_RandomActuator::PyGetPara1(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getPara1()", "the para1 property"); return PyFloat_FromDouble(m_parameter1); } @@ -406,6 +462,7 @@ const char SCA_RandomActuator::GetPara2_doc[] = "\tto the documentation of the generator types for the meaning\n" "\tof this value."; PyObject* SCA_RandomActuator::PyGetPara2(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getPara2()", "the para2 property"); return PyFloat_FromDouble(m_parameter2); } @@ -414,6 +471,7 @@ const char SCA_RandomActuator::GetDistribution_doc[] = "getDistribution()\n" "\tReturns the type of the active distribution.\n"; PyObject* SCA_RandomActuator::PyGetDistribution(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getDistribution()", "the distribution property"); return PyInt_FromLong(m_distribution); } @@ -424,6 +482,7 @@ const char SCA_RandomActuator::SetProperty_doc[] = "\tSet the property to which the random value is assigned. If the \n" "\tgenerator and property types do not match, the assignment is ignored.\n"; PyObject* SCA_RandomActuator::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setProperty()", "the 'property' property"); char *nameArg; if (!PyArg_ParseTuple(args, "s", &nameArg)) { return NULL; @@ -446,6 +505,7 @@ const char SCA_RandomActuator::GetProperty_doc[] = "\tReturn the property to which the random value is assigned. If the \n" "\tgenerator and property types do not match, the assignment is ignored.\n"; PyObject* SCA_RandomActuator::PyGetProperty(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getProperty()", "the 'property' property"); return PyString_FromString(m_propname); } @@ -463,9 +523,7 @@ PyObject* SCA_RandomActuator::PySetBoolConst(PyObject* self, } m_distribution = KX_RANDOMACT_BOOL_CONST; - if (paraArg) { - m_parameter1 = 1; - } + m_parameter1 = (paraArg) ? 1.0 : 0.0; Py_Return; } diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.h b/source/gameengine/GameLogic/SCA_RandomActuator.h index f6da0595d1a..2fc14f9a0b7 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.h +++ b/source/gameengine/GameLogic/SCA_RandomActuator.h @@ -97,6 +97,7 @@ class SCA_RandomActuator : public SCA_IActuator /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject *value); /* 1. setSeed */ KX_PYMETHOD_DOC(SCA_RandomActuator,SetSeed); diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index d0a2d0b05f2..e858c852b70 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -530,6 +530,7 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode) bool fixed_framerate= (SYS_GetCommandLineInt(syshandle, "fixed_framerate", fixedFr) != 0); bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0); bool useLists = (SYS_GetCommandLineInt(syshandle, "displaylists", G.fileflags & G_FILE_DISPLAY_LISTS) != 0); + bool nodepwarnings = (SYS_GetCommandLineInt(syshandle, "ignore_deprecation_warnings", 0) != 0); if(GLEW_ARB_multitexture && GLEW_VERSION_1_1) m_blendermat = (SYS_GetCommandLineInt(syshandle, "blender_material", 1) != 0); @@ -604,6 +605,8 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode) m_ketsjiengine->SetAudioDevice(m_audiodevice); m_ketsjiengine->SetTimingDisplay(frameRate, false, false); + CValue::SetDeprecationWarnings(nodepwarnings); + m_ketsjiengine->SetUseFixedTime(fixed_framerate); m_ketsjiengine->SetTimingDisplay(frameRate, profile, properties); diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp index c6f6bc2db01..bb9072b34dc 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.cpp +++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp @@ -65,15 +65,15 @@ PyParentObject KX_PolyProxy::Parents[] = { }; PyMethodDef KX_PolyProxy::Methods[] = { - KX_PYMETHODTABLE_NOARG(KX_PolyProxy,getMaterialIndex), - KX_PYMETHODTABLE_NOARG(KX_PolyProxy,getNumVertex), - KX_PYMETHODTABLE_NOARG(KX_PolyProxy,isVisible), - KX_PYMETHODTABLE_NOARG(KX_PolyProxy,isCollider), - KX_PYMETHODTABLE_NOARG(KX_PolyProxy,getMaterialName), - KX_PYMETHODTABLE_NOARG(KX_PolyProxy,getTextureName), + KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,getMaterialIndex), + KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,getNumVertex), + KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,isVisible), + KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,isCollider), + KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,getMaterialName), + KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,getTextureName), KX_PYMETHODTABLE(KX_PolyProxy,getVertexIndex), - KX_PYMETHODTABLE_NOARG(KX_PolyProxy,getMesh), - KX_PYMETHODTABLE_NOARG(KX_PolyProxy,getMaterial), + KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,getMesh), + KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,getMaterial), {NULL,NULL} //Sentinel }; @@ -171,7 +171,7 @@ void KX_PolyProxy::ReplicaSetName(STR_String) {}; // stuff for python integration -KX_PYMETHODDEF_DOC_NOARG(KX_PolyProxy, getMaterialIndex, +KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getMaterialIndex, "getMaterialIndex() : return the material index of the polygon in the mesh\n") { RAS_MaterialBucket* polyBucket = m_polygon->GetMaterial(); @@ -186,31 +186,31 @@ KX_PYMETHODDEF_DOC_NOARG(KX_PolyProxy, getMaterialIndex, return PyInt_FromLong(matid); } -KX_PYMETHODDEF_DOC_NOARG(KX_PolyProxy, getNumVertex, +KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getNumVertex, "getNumVertex() : returns the number of vertex of the polygon, 3 or 4\n") { return PyInt_FromLong(m_polygon->VertexCount()); } -KX_PYMETHODDEF_DOC_NOARG(KX_PolyProxy, isVisible, +KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, isVisible, "isVisible() : returns whether the polygon is visible or not\n") { return PyInt_FromLong(m_polygon->IsVisible()); } -KX_PYMETHODDEF_DOC_NOARG(KX_PolyProxy, isCollider, +KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, isCollider, "isCollider() : returns whether the polygon is receives collision or not\n") { return PyInt_FromLong(m_polygon->IsCollider()); } -KX_PYMETHODDEF_DOC_NOARG(KX_PolyProxy, getMaterialName, +KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getMaterialName, "getMaterialName() : returns the polygon material name, \"NoMaterial\" if no material\n") { return PyString_FromString(m_polygon->GetMaterial()->GetPolyMaterial()->GetMaterialName()); } -KX_PYMETHODDEF_DOC_NOARG(KX_PolyProxy, getTextureName, +KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getTextureName, "getTexturelName() : returns the polygon texture name, \"NULL\" if no texture\n") { return PyString_FromString(m_polygon->GetMaterial()->GetPolyMaterial()->GetTextureName()); @@ -239,14 +239,14 @@ KX_PYMETHODDEF_DOC(KX_PolyProxy, getVertexIndex, return PyInt_FromLong(0); } -KX_PYMETHODDEF_DOC_NOARG(KX_PolyProxy, getMesh, +KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getMesh, "getMesh() : returns a mesh proxy\n") { KX_MeshProxy* meshproxy = new KX_MeshProxy((RAS_MeshObject*)m_mesh); return meshproxy; } -KX_PYMETHODDEF_DOC_NOARG(KX_PolyProxy, getMaterial, +KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getMaterial, "getMaterial() : returns a material\n") { RAS_IPolyMaterial *polymat = m_polygon->GetMaterial()->GetPolyMaterial(); diff --git a/source/gameengine/PyDoc/KX_ActuatorSensor.py b/source/gameengine/PyDoc/KX_ActuatorSensor.py index cdfbf27576e..b0e138a8009 100644 --- a/source/gameengine/PyDoc/KX_ActuatorSensor.py +++ b/source/gameengine/PyDoc/KX_ActuatorSensor.py @@ -8,15 +8,22 @@ class KX_ActuatorSensor(SCA_ISensor): Actuator sensor detect change in actuator state of the parent object. It generates a positive pulse if the corresponding actuator is activated and a negative pulse if the actuator is deactivated. + + Properties: + + @ivar actuator: the name of the actuator that the sensor is monitoring. + @type actuator: string """ def getActuator(): """ + DEPRECATED: use the actuator property Return the Actuator with which the sensor operates. @rtype: string """ def setActuator(name): """ + DEPRECATED: use the actuator property Sets the Actuator with which to operate. If there is no Actuator of this name, the function has no effect. diff --git a/source/gameengine/PyDoc/SCA_DelaySensor.py b/source/gameengine/PyDoc/SCA_DelaySensor.py index 19df589ea7b..b99ed08bed5 100644 --- a/source/gameengine/PyDoc/SCA_DelaySensor.py +++ b/source/gameengine/PyDoc/SCA_DelaySensor.py @@ -13,9 +13,21 @@ class SCA_DelaySensor(SCA_ISensor): The sensor runs the OFF-ON cycle once unless the repeat option is set: the OFF-ON cycle repeats indefinately (or the OFF cycle if duration is 0). Use SCA_ISensor::reset() at any time to restart sensor. + + Properties: + + @ivar delay: length of the initial OFF period as number of frame, 0 for immediate trigger. + @type delay: integer. + @ivar duration: length of the ON period in number of frame after the initial OFF period. + If duration is greater than 0, a negative trigger is sent at the end of the ON pulse. + @type duration: integer + @ivar repeat: 1 if the OFF-ON cycle should be repeated indefinately, 0 if it should run once. + @type repeat: integer + """ def setDelay(delay): """ + DEPRECATED: use the delay property Set the initial delay before the positive trigger. @param delay: length of the initial OFF period as number of frame, 0 for immediate trigger @@ -23,6 +35,7 @@ class SCA_DelaySensor(SCA_ISensor): """ def setDuration(duration): """ + DEPRECATED: use the duration property Set the duration of the ON pulse after initial delay and the generation of the positive trigger. If duration is greater than 0, a negative trigger is sent at the end of the ON pulse. @@ -31,6 +44,7 @@ class SCA_DelaySensor(SCA_ISensor): """ def setRepeat(repeat): """ + DEPRECATED: use the repeat property Set if the sensor repeat mode. @param repeat: 1 if the OFF-ON cycle should be repeated indefinately, 0 if it should run once. @@ -38,18 +52,21 @@ class SCA_DelaySensor(SCA_ISensor): """ def getDelay(): """ + DEPRECATED: use the delay property Return the delay parameter value. @rtype: integer """ def getDuration(): """ + DEPRECATED: use the duration property Return the duration parameter value @rtype: integer """ def getRepeat(): """ + DEPRECATED: use the repeat property Return the repeat parameter value @rtype: KX_TRUE or KX_FALSE diff --git a/source/gameengine/PyDoc/SCA_ILogicBrick.py b/source/gameengine/PyDoc/SCA_ILogicBrick.py index ea09fcaea37..18cb900f28d 100644 --- a/source/gameengine/PyDoc/SCA_ILogicBrick.py +++ b/source/gameengine/PyDoc/SCA_ILogicBrick.py @@ -5,6 +5,9 @@ from KX_GameObject import * class SCA_ILogicBrick: """ Base class for all logic bricks. + + @ivar executePriority: This determines the order controllers are evaluated, and actuators are activated (lower priority is executed first). + @type executePriority: int """ def getOwner(): @@ -13,6 +16,8 @@ class SCA_ILogicBrick: @rtype: L{KX_GameObject} """ + + #--The following methods are deprecated-- def setExecutePriority(priority): """ Sets the priority of this logic brick. @@ -20,6 +25,8 @@ class SCA_ILogicBrick: This determines the order controllers are evaluated, and actuators are activated. Bricks with lower priority will be executed first. + Deprecated: Use the "executePriority" property instead. + @type priority: integer @param priority: the priority of this logic brick. """ @@ -27,6 +34,8 @@ class SCA_ILogicBrick: """ Gets the execution priority of this logic brick. + Deprecated: Use the "executePriority" property instead. + @rtype: integer @return: this logic bricks current priority. """ diff --git a/source/gameengine/PyDoc/SCA_ISensor.py b/source/gameengine/PyDoc/SCA_ISensor.py index 14858505e24..ab35996aa50 100644 --- a/source/gameengine/PyDoc/SCA_ISensor.py +++ b/source/gameengine/PyDoc/SCA_ISensor.py @@ -5,8 +5,35 @@ from SCA_ILogicBrick import * class SCA_ISensor(SCA_ILogicBrick): """ Base class for all sensor logic bricks. + + @ivar usePosPulseMode: Flag to turn positive pulse mode on and off. + @type usePosPulseMode: boolean + @ivar useNegPulseMode: Flag to turn negative pulse mode on and off. + @type useNegPulseMode: boolean + @ivar frequency: The frequency for pulse mode sensors. + @type frequency: int + @ivar level: Flag to set whether to detect level or edge transition when entering a state. + It makes a difference only in case of logic state transition (state actuator). + A level detector will immediately generate a pulse, negative or positive + depending on the sensor condition, as soon as the state is activated. + A edge detector will wait for a state change before generating a pulse. + @type level: boolean + @ivar invert: Flag to set if this sensor activates on positive or negative events. + @type invert: boolean + @ivar triggered: True if this sensor brick is in a positive state. (Read only) + @type triggered: boolean + @ivar positive: True if this sensor brick is in a positive state. (Read only) + @type positive: boolean """ + def reset(): + """ + Reset sensor internal state, effect depends on the type of sensor and settings. + + The sensor is put in its initial state as if it was just activated. + """ + + #--The following methods are deprecated-- def isPositive(): """ True if this sensor brick is in a positive state. @@ -82,10 +109,3 @@ class SCA_ISensor(SCA_ILogicBrick): @param level: Detect level instead of edge? (KX_TRUE, KX_FALSE) @type level: boolean """ - def reset(): - """ - Reset sensor internal state, effect depends on the type of sensor and settings. - - The sensor is put in its initial state as if it was just activated. - """ - diff --git a/source/gameengine/PyDoc/SCA_JoystickSensor.py b/source/gameengine/PyDoc/SCA_JoystickSensor.py index d1dab9afcaf..111ee7f4cfa 100644 --- a/source/gameengine/PyDoc/SCA_JoystickSensor.py +++ b/source/gameengine/PyDoc/SCA_JoystickSensor.py @@ -5,15 +5,58 @@ from SCA_ISensor import * class SCA_JoystickSensor(SCA_ISensor): """ This sensor detects player joystick events. + + Properties: + + @ivar axisPosition: (read-only) The state of the joysticks axis as a list of 4 values, each spesifying the value of an axis between -32767 and 32767 depending on how far the axis is pushed, 0 for nothing. + The first 2 values are used by most joysticks and gamepads for directional control. 3rd and 4th values are only on some joysticks and can be used for arbitary controls. + left:[-32767, 0, ...], right:[32767, 0, ...], up:[0, -32767, ...], down:[0, 32767, ...] + @type axisPosition: [integer, integer, integer, integer] + @ivar numAxis: (read-only) The number of axes for the joystick at this index. + @type numAxis: integer + @ivar numButtons: (read-only) The number of buttons for the joystick at this index. + @type numButtons: integer + @ivar numHats: (read-only) The number of hats for the joystick at this index. + @type numHats: integer + @ivar connected: (read-only) True if a joystick is connected at this joysticks index. + @type connected: boolean + @ivar index: The joystick index to use (from 0 to 7). The first joystick is always 0. + @type index: integer + @ivar threshold: Axis threshold. Joystick axis motion below this threshold wont trigger an event. Use values between (0 and 32767), lower values are more sensitive. + @type threshold: integer + @ivar button: The button index the sensor reacts to (first button = 0). When the "All Events" toggle is set, this option has no effect. + @type button: integer + @ivar axis: The axis this sensor reacts to, as a list of two values [axisIndex, axisDirection] + axisIndex: the axis index to use when detecting axis movement, 1=primary directional control, 2=secondary directional control. + axisDirection: 0=right, 1=up, 2=left, 3=down + @type axis: [integer, integer] + @ivar hat: The hat the sensor reacts to, as a list of two values: [hatIndex, hatDirection] + hatIndex: the hat index to use when detecting hat movement, 1=primary hat, 2=secondary hat. + hatDirection: 0-11 + @type hat: [integer, integer] """ + def getButtonActiveList(): + """ + Returns a list containing the indicies of the currently pressed buttons. + @rtype: list + """ + def getButtonStatus(buttonIndex): + """ + Returns a bool of the current pressed state of the specified button. + @param buttonIndex: the button index, 0=first button + @type buttonIndex: integer + @rtype: bool + """ def getIndex(): """ + DEPRECATED: use the 'index' property. Returns the joystick index to use (from 1 to 8). @rtype: integer """ def setIndex(index): """ + DEPRECATED: use the 'index' property. Sets the joystick index to use. @param index: The index of this joystick sensor, Clamped between 1 and 8. @type index: integer @@ -21,6 +64,7 @@ class SCA_JoystickSensor(SCA_ISensor): """ def getAxis(): """ + DEPRECATED: use the 'axis' property. Returns the current axis this sensor reacts to. See L{getAxisValue()} for the current axis state. @rtype: list @return: 2 values returned are [axisIndex, axisDirection] - see L{setAxis()} for their purpose. @@ -28,6 +72,7 @@ class SCA_JoystickSensor(SCA_ISensor): """ def setAxis(axisIndex, axisDirection): """ + DEPRECATED: use the 'axis' property. @param axisIndex: Set the axis index to use when detecting axis movement. @type axisIndex: integer from 1 to 2 @param axisDirection: Set the axis direction used for detecting motion. 0:right, 1:up, 2:left, 3:down. @@ -36,6 +81,7 @@ class SCA_JoystickSensor(SCA_ISensor): """ def getAxisValue(): """ + DEPRECATED: use the 'axisPosition' property. Returns the state of the joysticks axis. See differs to L{getAxis()} returning the current state of the joystick. @rtype: list @return: 4 values, each spesifying the value of an axis between -32767 and 32767 depending on how far the axis is pushed, 0 for nothing. @@ -47,60 +93,71 @@ class SCA_JoystickSensor(SCA_ISensor): """ def getThreshold(): """ + DEPRECATED: use the 'threshold' property. Get the axis threshold. See L{setThreshold()} for details. @rtype: integer """ def setThreshold(threshold): """ + DEPRECATED: use the 'threshold' property. Set the axis threshold. @param threshold: Joystick axis motion below this threshold wont trigger an event. Use values between (0 and 32767), lower values are more sensitive. @type threshold: integer """ def getButton(): """ + DEPRECATED: use the 'button' property. Returns the button index the sensor reacts to. See L{getButtonValue()} for a list of pressed buttons. @rtype: integer @note: When the "All Events" toggle is set, this option has no effect. """ def setButton(index): """ + DEPRECATED: use the 'button' property. Sets the button index the sensor reacts to when the "All Events" option is not set. @note: When the "All Events" toggle is set, this option has no effect. """ def getButtonValue(): """ + DEPRECATED: use the 'getButtonActiveList' method. Returns a list containing the indicies of the currently pressed buttons. @rtype: list """ def getHat(): """ + DEPRECATED: use the 'hat' property. Returns the current hat direction this sensor is set to. [hatNumber, hatDirection]. @rtype: list @note: When the "All Events" toggle is set, this option has no effect. """ - def setHat(index): + def setHat(index,direction): """ + DEPRECATED: use the 'hat' property. Sets the hat index the sensor reacts to when the "All Events" option is not set. @type index: integer """ def getNumAxes(): """ + DEPRECATED: use the 'numAxis' property. Returns the number of axes for the joystick at this index. @rtype: integer """ def getNumButtons(): """ + DEPRECATED: use the 'numButtons' property. Returns the number of buttons for the joystick at this index. @rtype: integer """ def getNumHats(): """ + DEPRECATED: use the 'numHats' property. Returns the number of hats for the joystick at this index. @rtype: integer """ def isConnected(): """ + DEPRECATED: use the 'connected' property. Returns True if a joystick is detected at this joysticks index. @rtype: bool """ diff --git a/source/gameengine/PyDoc/SCA_KeyboardSensor.py b/source/gameengine/PyDoc/SCA_KeyboardSensor.py index 2f741f7d6a2..f6a7a7d8a97 100644 --- a/source/gameengine/PyDoc/SCA_KeyboardSensor.py +++ b/source/gameengine/PyDoc/SCA_KeyboardSensor.py @@ -7,44 +7,99 @@ class SCA_KeyboardSensor(SCA_ISensor): A keyboard sensor detects player key presses. See module L{GameKeys} for keycode values. + + @ivar key: The key code this sensor is looking for. + @type key: keycode from L{GameKeys} module + @ivar hold1: The key code for the first modifier this sensor is looking for. + @type hold1: keycode from L{GameKeys} module + @ivar hold2: The key code for the second modifier this sensor is looking for. + @type hold2: keycode from L{GameKeys} module + @ivar toggleProperty: The name of the property that indicates whether or not to log keystrokes as a string. + @type toggleProperty: string + @ivar targetProperty: The name of the property that receives keystrokes in case in case a string is logged. + @type targetProperty: string + @ivar useAllKeys: Flag to determine whether or not to accept all keys. + @type useAllKeys: boolean """ + def getEventList(): + """ + Get a list of pressed keys that have either been pressed, or just released, or are active this frame. + + @rtype: list of key status. [[keycode, status]] + @return: A list of keyboard events + """ + + def getKeyStatus(keycode): + """ + Get the status of a key. + + @rtype: key state (KX_NO_INPUTSTATUS, KX_JUSTACTIVATED, KX_ACTIVE or KX_JUSTRELEASED) + @return: The state of the given key + @type keycode: integer + @param keycode: The code that represents the key you want to get the state of + """ + #--The following methods are deprecated-- def getKey(): """ Returns the key code this sensor is looking for. + + Deprecated: Use the "key" property instead. + + @rtype: keycode from L{GameKeys} module """ def setKey(keycode): """ Set the key this sensor should listen for. + Deprecated: Use the "key" property instead. + @type keycode: keycode from L{GameKeys} module """ def getHold1(): """ Returns the key code for the first modifier this sensor is looking for. + + Deprecated: Use the "hold1" property instead. + + @rtype: keycode from L{GameKeys} module """ - def setHold1(): + def setHold1(keycode): """ Sets the key code for the first modifier this sensor should look for. + + Deprecated: Use the "hold1" property instead. + + @type keycode: keycode from L{GameKeys} module """ def getHold2(): """ Returns the key code for the second modifier this sensor is looking for. + + Deprecated: Use the "hold2" property instead. + + @rtype: keycode from L{GameKeys} module """ - def setHold2(): + def setHold2(keycode): """ Sets the key code for the second modifier this sensor should look for. + + Deprecated: Use the "hold2" property instead. + + @type keycode: keycode from L{GameKeys} module """ def getPressedKeys(): """ Get a list of keys that have either been pressed, or just released this frame. + Deprecated: Use getEventList() instead. + @rtype: list of key status. [[keycode, status]] """ @@ -52,7 +107,7 @@ class SCA_KeyboardSensor(SCA_ISensor): """ Get a list of currently pressed keys that have either been pressed, or just released + Deprecated: Use getEventList() instead. + @rtype: list of key status. [[keycode, status]] - """ - - + """ \ No newline at end of file diff --git a/source/gameengine/PyDoc/SCA_MouseSensor.py b/source/gameengine/PyDoc/SCA_MouseSensor.py index 06b261f67fa..9550cbb4105 100644 --- a/source/gameengine/PyDoc/SCA_MouseSensor.py +++ b/source/gameengine/PyDoc/SCA_MouseSensor.py @@ -5,10 +5,20 @@ from SCA_ISensor import * class SCA_MouseSensor(SCA_ISensor): """ Mouse Sensor logic brick. + + Properties: + + @ivar position: current [x,y] coordinates of the mouse, in frame coordinates (pixels) + @type position: [integer,interger] + @ivar mode: sensor mode: 1=KX_MOUSESENSORMODE_LEFTBUTTON 2=KX_MOUSESENSORMODE_MIDDLEBUTTON + 3=KX_MOUSESENSORMODE_RIGHTBUTTON 4=KX_MOUSESENSORMODE_WHEELUP + 5=KX_MOUSESENSORMODE_WHEELDOWN 9=KX_MOUSESENSORMODE_MOVEMENT + @type mode: integer """ def getXPosition(): """ + DEPRECATED: use the position property Gets the x coordinate of the mouse. @rtype: integer @@ -16,6 +26,7 @@ class SCA_MouseSensor(SCA_ISensor): """ def getYPosition(): """ + DEPRECATED: use the position property Gets the y coordinate of the mouse. @rtype: integer diff --git a/source/gameengine/PyDoc/SCA_PropertyActuator.py b/source/gameengine/PyDoc/SCA_PropertyActuator.py index dc1233ddfb7..52aefcae651 100644 --- a/source/gameengine/PyDoc/SCA_PropertyActuator.py +++ b/source/gameengine/PyDoc/SCA_PropertyActuator.py @@ -5,9 +5,17 @@ from SCA_IActuator import * class SCA_PropertyActuator(SCA_IActuator): """ Property Actuator + + Properties: + + @ivar property: the property on which to operate. + @type property: string + @ivar value: the value with which the actuator operates. + @type value: string """ def setProperty(prop): """ + DEPRECATED: use the 'property' property Set the property on which to operate. If there is no property of this name, the call is ignored. @@ -17,12 +25,14 @@ class SCA_PropertyActuator(SCA_IActuator): """ def getProperty(): """ + DEPRECATED: use the 'property' property Returns the name of the property on which to operate. @rtype: string """ def setValue(value): """ + DEPRECATED: use the 'value' property Set the value with which the actuator operates. If the value is not compatible with the type of the @@ -32,6 +42,7 @@ class SCA_PropertyActuator(SCA_IActuator): """ def getValue(): """ + DEPRECATED: use the 'value' property Gets the value with which this actuator operates. @rtype: string diff --git a/source/gameengine/PyDoc/SCA_PropertySensor.py b/source/gameengine/PyDoc/SCA_PropertySensor.py index 22de8d8b986..949ffd3b703 100644 --- a/source/gameengine/PyDoc/SCA_PropertySensor.py +++ b/source/gameengine/PyDoc/SCA_PropertySensor.py @@ -5,10 +5,22 @@ from SCA_ISensor import * class SCA_PropertySensor(SCA_ISensor): """ Activates when the game object property matches. + + Properties: + + @ivar type: type of check on the property: + KX_PROPSENSOR_EQUAL(1), KX_PROPSENSOR_NOTEQUAL(2), KX_PROPSENSOR_INTERVAL(3), + KX_PROPSENSOR_CHANGED(4), KX_PROPSENSOR_EXPRESSION(5) + @type type: integer + @ivar property: the property with which the sensor operates. + @type property: string + @ivar value: the value with which the sensor compares to the value of the property. + @type value: string """ def getType(): """ + DEPRECATED: use the type property Gets when to activate this sensor. @return: KX_PROPSENSOR_EQUAL, KX_PROPSENSOR_NOTEQUAL, @@ -18,6 +30,7 @@ class SCA_PropertySensor(SCA_ISensor): def setType(checktype): """ + DEPRECATED: use the type property Set the type of check to perform. @type checktype: KX_PROPSENSOR_EQUAL, KX_PROPSENSOR_NOTEQUAL, @@ -27,6 +40,7 @@ class SCA_PropertySensor(SCA_ISensor): def getProperty(): """ + DEPRECATED: use the property property Return the property with which the sensor operates. @rtype: string @@ -34,6 +48,7 @@ class SCA_PropertySensor(SCA_ISensor): """ def setProperty(name): """ + DEPRECATED: use the property property Sets the property with which to operate. If there is no property of that name, this call is ignored. @@ -41,6 +56,7 @@ class SCA_PropertySensor(SCA_ISensor): """ def getValue(): """ + DEPRECATED: use the value property Return the value with which the sensor compares to the value of the property. @rtype: string @@ -48,6 +64,7 @@ class SCA_PropertySensor(SCA_ISensor): """ def setValue(value): """ + DEPRECATED: use the value property Set the value with which the sensor operates. If the value is not compatible with the type of the property, the subsequent action is ignored. diff --git a/source/gameengine/PyDoc/SCA_PythonController.py b/source/gameengine/PyDoc/SCA_PythonController.py index 6d91736d636..06f2b7e9d1d 100644 --- a/source/gameengine/PyDoc/SCA_PythonController.py +++ b/source/gameengine/PyDoc/SCA_PythonController.py @@ -6,6 +6,14 @@ class SCA_PythonController(SCA_IController): """ A Python controller uses a Python script to activate it's actuators, based on it's sensors. + + Properties: + + @ivar script: the Python script this controller executes + @type script: string, read-only + @ivar state: the controllers state bitmask. + This can be used with the GameObject's state to test if the controller is active. + @type state: integer """ def getSensors(): @@ -36,6 +44,7 @@ class SCA_PythonController(SCA_IController): """ def getScript(): """ + DEPRECATED: use the script property Gets the Python script this controller executes. @rtype: string @@ -48,6 +57,7 @@ class SCA_PythonController(SCA_IController): """ def getState(): """ + DEPRECATED: use the state property Get the controllers state bitmask, this can be used with the GameObject's state to test if the the controller is active. This for instance will always be true however you could compare with a previous state to see when the state was activated. GameLogic.getCurrentController().getState() & GameLogic.getCurrentController().getOwner().getState() diff --git a/source/gameengine/PyDoc/SCA_RandomActuator.py b/source/gameengine/PyDoc/SCA_RandomActuator.py index 353b398b1ff..000a1af7846 100644 --- a/source/gameengine/PyDoc/SCA_RandomActuator.py +++ b/source/gameengine/PyDoc/SCA_RandomActuator.py @@ -5,9 +5,35 @@ from SCA_IActuator import * class SCA_RandomActuator(SCA_IActuator): """ Random Actuator + + Properties: + + @ivar seed: Seed of the random number generator. + Equal seeds produce equal series. If the seed is 0, + the generator will produce the same value on every call. + @type seed: integer + @ivar para1: the first parameter of the active distribution. + Refer to the documentation of the generator types for the meaning + of this value. + @type para1: float, read-only + @ivar para2: the second parameter of the active distribution. + Refer to the documentation of the generator types for the meaning + of this value. + @type para2: float, read-only + @ivar distribution: distribution type: + KX_RANDOMACT_BOOL_CONST, KX_RANDOMACT_BOOL_UNIFORM, KX_RANDOMACT_BOOL_BERNOUILLI, + KX_RANDOMACT_INT_CONST, KX_RANDOMACT_INT_UNIFORM, KX_RANDOMACT_INT_POISSON, + KX_RANDOMACT_FLOAT_CONST, KX_RANDOMACT_FLOAT_UNIFORM, KX_RANDOMACT_FLOAT_NORMAL, + KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL + @type distribution: integer, read-only + @ivar property: the name of the property to set with the random value. + If the generator and property types do not match, the assignment is ignored. + @type property: string + """ def setSeed(seed): """ + DEPRECATED: use the seed property Sets the seed of the random number generator. Equal seeds produce equal series. If the seed is 0, @@ -17,12 +43,14 @@ class SCA_RandomActuator(SCA_IActuator): """ def getSeed(): """ + DEPRECATED: use the seed property Returns the initial seed of the generator. @rtype: integer """ def getPara1(): """ + DEPRECATED: use the para1 property Returns the first parameter of the active distribution. Refer to the documentation of the generator types for the meaning @@ -32,6 +60,7 @@ class SCA_RandomActuator(SCA_IActuator): """ def getPara2(): """ + DEPRECATED: use the para2 property Returns the second parameter of the active distribution. Refer to the documentation of the generator types for the meaning @@ -41,6 +70,7 @@ class SCA_RandomActuator(SCA_IActuator): """ def getDistribution(): """ + DEPRECATED: use the distribution property Returns the type of random distribution. @rtype: distribution type @@ -51,6 +81,7 @@ class SCA_RandomActuator(SCA_IActuator): """ def setProperty(property): """ + DEPRECATED: use the property property Set the property to which the random value is assigned. If the generator and property types do not match, the assignment is ignored. @@ -60,6 +91,7 @@ class SCA_RandomActuator(SCA_IActuator): """ def getProperty(): """ + DEPRECATED: use the property property Returns the name of the property to set. @rtype: string -- cgit v1.2.3 From cbceb6c8b2806587a45e05946cb591bd119cc801 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Tue, 30 Dec 2008 16:44:34 +0000 Subject: BGE API cleanup: more consistent type check on set attribute (mouse and keyboard so far). Check type after name so that the user get a type error when assigning a wrong type to a built-in attribute. --- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 77 +++++++++++++--------- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 39 ++++++----- 2 files changed, 65 insertions(+), 51 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index f880cd7768e..0e014628ac7 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -846,49 +846,64 @@ SCA_KeyboardSensor::_getattr(const STR_String& attr) int SCA_KeyboardSensor::_setattr(const STR_String& attr, PyObject *value) { - if (PyInt_Check(value)) + if (attr == "key") { - int val = PyInt_AsLong(value); - - if (attr == "key") - { - m_hotkey = val; - return 0; + if (!PyInt_Check(value)){ + PyErr_SetString(PyExc_TypeError, "expected an integer"); + return 1; } + m_hotkey = PyInt_AsLong(value); + return 0; + } - if (attr == "hold1") - { - m_qual = val; - return 0; + if (attr == "hold1") + { + if (!PyInt_Check(value)){ + PyErr_SetString(PyExc_TypeError, "expected an integer"); + return 1; } - - if (attr == "hold2") - { - m_qual2 = val; - return 0; + m_qual = PyInt_AsLong(value); + return 0; + } + + if (attr == "hold2") + { + if (!PyInt_Check(value)){ + PyErr_SetString(PyExc_TypeError, "expected an integer"); + return 1; } + m_qual2 = PyInt_AsLong(value); + return 0; + } - if (attr == "useAllKeys") - { - m_bAllKeys = (val != 0); - return 0; + if (attr == "useAllKeys") + { + if (!PyInt_Check(value)){ + PyErr_SetString(PyExc_TypeError, "expected an integer"); + return 1; } + m_bAllKeys = (PyInt_AsLong(value) != 0); + return 0; } - - if (PyString_Check(value)) + + if (attr == "logToggleProperty") { - STR_String val = PyString_AsString(value); - if (attr == "logToggleProperty") - { - m_toggleprop = val; - return 0; + if (!PyString_Check(value)){ + PyErr_SetString(PyExc_TypeError, "expected a string"); + return 1; } + m_toggleprop = PyString_AsString(value); + return 0; + } - if (attr == "logTargetProperty") - { - m_targetprop = val; - return 0; + if (attr == "logTargetProperty") + { + if (!PyString_Check(value)){ + PyErr_SetString(PyExc_TypeError, "expected a string"); + return 1; } + m_targetprop = PyString_AsString(value); + return 0; } return SCA_ISensor::_setattr(attr, value); diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index 9562003aec0..8281eed47bc 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -343,31 +343,30 @@ PyObject* SCA_MouseSensor::_getattr(const STR_String& attr) { int SCA_MouseSensor::_setattr(const STR_String& attr, PyObject *value) { - if (PyInt_Check(value)) + if (attr == "mode") { + if (!PyInt_Check(value)){ + PyErr_SetString(PyExc_TypeError, "expected an integer"); + return 1; + } + int val = PyInt_AsLong(value); - - if (attr == "mode") - { - if ((val < KX_MOUSESENSORMODE_NODEF) - || (val > KX_MOUSESENSORMODE_MAX)){ - - PyErr_SetString(PyExc_ValueError, "invalid mode specified!"); - return NULL; - } - - m_mousemode = val; - UpdateHotkey(); - return 0; + + if ((val < KX_MOUSESENSORMODE_NODEF) + || (val > KX_MOUSESENSORMODE_MAX)){ + PyErr_SetString(PyExc_ValueError, "invalid mode specified!"); + return 1; } + + m_mousemode = val; + UpdateHotkey(); + return 0; } - else + + if (attr == "position") { - if (attr == "position") - { - PyErr_SetString(PyExc_AttributeError, "read-only property!"); - return NULL; - } + PyErr_SetString(PyExc_AttributeError, "'position' is a read-only property!"); + return 1; } return SCA_ISensor::_setattr(attr, value); -- cgit v1.2.3 From 2dfd34994fb2a5d7d8ca57a7ce1fa18e7047463e Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 31 Dec 2008 20:35:20 +0000 Subject: BGE API cleanup: introduction of a generic framework to link Python attributes to logic brick class member. See KX_PYATTRIBUTE macros in PyObjectPlus.h. --- source/gameengine/Expressions/PyObjectPlus.cpp | 443 +++++++++++++++++++++ source/gameengine/Expressions/PyObjectPlus.h | 101 +++++ source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 114 ++---- source/gameengine/GameLogic/SCA_JoystickSensor.h | 30 +- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 94 +---- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 69 ++-- source/gameengine/GameLogic/SCA_MouseSensor.h | 4 +- 7 files changed, 638 insertions(+), 217 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 1eca527151a..c31587628b0 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -131,6 +131,449 @@ int PyObjectPlus::_setattr(const STR_String& attr, PyObject *value) return 1; } +PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *self, const STR_String &attr) +{ + const PyAttributeDef *attrdef; + for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++) + { + if (attr == attrdef->m_name) + { + if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY) + { + // fake attribute, ignore + return NULL; + } + char *ptr = reinterpret_cast(self)+attrdef->m_offset; + if (attrdef->m_length > 1) + { + PyObject* resultlist = PyList_New(attrdef->m_length); + for (int i=0; im_length; i++) + { + switch (attrdef->m_type) { + case KX_PYATTRIBUTE_TYPE_BOOL: + { + bool *val = reinterpret_cast(ptr); + ptr += sizeof(bool); + PyList_SetItem(resultlist,i,PyInt_FromLong(*val)); + break; + } + case KX_PYATTRIBUTE_TYPE_SHORT: + { + short int *val = reinterpret_cast(ptr); + ptr += sizeof(short int); + PyList_SetItem(resultlist,i,PyInt_FromLong(*val)); + break; + } + case KX_PYATTRIBUTE_TYPE_INT: + { + int *val = reinterpret_cast(ptr); + ptr += sizeof(int); + PyList_SetItem(resultlist,i,PyInt_FromLong(*val)); + break; + } + case KX_PYATTRIBUTE_TYPE_FLOAT: + { + float *val = reinterpret_cast(ptr); + ptr += sizeof(float); + PyList_SetItem(resultlist,i,PyFloat_FromDouble(*val)); + break; + } + default: + // no support for array of complex data + return NULL; + } + } + return resultlist; + } + else + { + switch (attrdef->m_type) { + case KX_PYATTRIBUTE_TYPE_BOOL: + { + bool *val = reinterpret_cast(ptr); + return PyInt_FromLong(*val); + } + case KX_PYATTRIBUTE_TYPE_SHORT: + { + short int *val = reinterpret_cast(ptr); + return PyInt_FromLong(*val); + } + case KX_PYATTRIBUTE_TYPE_INT: + { + int *val = reinterpret_cast(ptr); + return PyInt_FromLong(*val); + } + case KX_PYATTRIBUTE_TYPE_FLOAT: + { + float *val = reinterpret_cast(ptr); + return PyFloat_FromDouble(*val); + } + case KX_PYATTRIBUTE_TYPE_STRING: + { + STR_String *val = reinterpret_cast(ptr); + return PyString_FromString(*val); + } + default: + return NULL; + } + } + } + } + return NULL; +} + +int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, const STR_String &attr, PyObject *value) +{ + const PyAttributeDef *attrdef; + void *undoBuffer = NULL; + void *sourceBuffer = NULL; + size_t bufferSize = 0; + + for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++) + { + if (attr == attrdef->m_name) + { + if (attrdef->m_access == KX_PYATTRIBUTE_RO || + attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY) + { + PyErr_SetString(PyExc_AttributeError, "property is read-only"); + return 1; + } + char *ptr = reinterpret_cast(self)+attrdef->m_offset; + if (attrdef->m_length > 1) + { + if (!PySequence_Check(value)) + { + PyErr_SetString(PyExc_TypeError, "expected a sequence"); + return 1; + } + if (PySequence_Size(value) != attrdef->m_length) + { + PyErr_SetString(PyExc_TypeError, "incorrect number of elements in sequence"); + return 1; + } + switch (attrdef->m_type) + { + case KX_PYATTRIBUTE_TYPE_BOOL: + bufferSize = sizeof(bool); + break; + case KX_PYATTRIBUTE_TYPE_SHORT: + bufferSize = sizeof(short int); + break; + case KX_PYATTRIBUTE_TYPE_INT: + bufferSize = sizeof(int); + break; + case KX_PYATTRIBUTE_TYPE_FLOAT: + bufferSize = sizeof(float); + break; + default: + // should not happen + PyErr_SetString(PyExc_AttributeError, "Unsupported attribute type, report to blender.org"); + return 1; + } + // let's implement a smart undo method + bufferSize *= attrdef->m_length; + undoBuffer = malloc(bufferSize); + sourceBuffer = ptr; + if (undoBuffer) + { + memcpy(undoBuffer, sourceBuffer, bufferSize); + } + for (int i=0; im_length; i++) + { + PyObject *item = PySequence_GetItem(value, i); /* new ref */ + // we can decrement the reference immediately, the reference count + // is at least 1 because the item is part of an array + Py_DECREF(item); + switch (attrdef->m_type) + { + case KX_PYATTRIBUTE_TYPE_BOOL: + { + bool *var = reinterpret_cast(ptr); + ptr += sizeof(bool); + if (PyInt_Check(item)) + { + *var = (PyInt_AsLong(item) != 0); + } + else if (PyBool_Check(item)) + { + *var = (item == Py_True); + } + else + { + PyErr_SetString(PyExc_TypeError, "expected an integer or a bool"); + goto UNDO_AND_ERROR; + } + break; + } + case KX_PYATTRIBUTE_TYPE_SHORT: + { + short int *var = reinterpret_cast(ptr); + ptr += sizeof(short int); + if (PyInt_Check(item)) + { + long val = PyInt_AsLong(item); + if (val < attrdef->m_imin || val > attrdef->m_imax) + { + PyErr_SetString(PyExc_ValueError, "item value out of range"); + goto UNDO_AND_ERROR; + } + *var = (short int)val; + } + else + { + PyErr_SetString(PyExc_TypeError, "expected an integer"); + goto UNDO_AND_ERROR; + } + break; + } + case KX_PYATTRIBUTE_TYPE_INT: + { + int *var = reinterpret_cast(ptr); + ptr += sizeof(int); + if (PyInt_Check(item)) + { + long val = PyInt_AsLong(item); + if (val < attrdef->m_imin || val > attrdef->m_imax) + { + PyErr_SetString(PyExc_ValueError, "item value out of range"); + goto UNDO_AND_ERROR; + } + *var = (int)val; + } + else + { + PyErr_SetString(PyExc_TypeError, "expected an integer"); + goto UNDO_AND_ERROR; + } + break; + } + case KX_PYATTRIBUTE_TYPE_FLOAT: + { + float *var = reinterpret_cast(ptr); + ptr += sizeof(float); + if (PyFloat_Check(item)) + { + double val = PyFloat_AsDouble(item); + if (val < attrdef->m_fmin || val > attrdef->m_fmax) + { + PyErr_SetString(PyExc_ValueError, "item value out of range"); + goto UNDO_AND_ERROR; + } + *var = (float)val; + } + else + { + PyErr_SetString(PyExc_TypeError, "expected a float"); + goto UNDO_AND_ERROR; + } + break; + } + default: + // should not happen + PyErr_SetString(PyExc_AttributeError, "attribute type check error, report to blender.org"); + goto UNDO_AND_ERROR; + } + } + // no error, call check function if any + if (attrdef->m_function != NULL) + { + if ((*attrdef->m_function)(self) != 0) + { + // post check returned an error, restore values + UNDO_AND_ERROR: + if (undoBuffer) + { + memcpy(sourceBuffer, undoBuffer, bufferSize); + free(undoBuffer); + } + return 1; + } + } + if (undoBuffer) + free(undoBuffer); + return 0; + } + else // simple attribute value + { + + if (attrdef->m_function != NULL) + { + // post check function is provided, prepare undo buffer + sourceBuffer = ptr; + switch (attrdef->m_type) + { + case KX_PYATTRIBUTE_TYPE_BOOL: + bufferSize = sizeof(bool); + break; + case KX_PYATTRIBUTE_TYPE_SHORT: + bufferSize = sizeof(short); + break; + case KX_PYATTRIBUTE_TYPE_INT: + bufferSize = sizeof(int); + break; + case KX_PYATTRIBUTE_TYPE_FLOAT: + bufferSize = sizeof(float); + break; + case KX_PYATTRIBUTE_TYPE_STRING: + sourceBuffer = reinterpret_cast(ptr)->Ptr(); + if (sourceBuffer) + bufferSize = strlen(reinterpret_cast(sourceBuffer))+1; + break; + default: + PyErr_SetString(PyExc_AttributeError, "unknown attribute type, report to blender.org"); + return 1; + } + if (bufferSize) + { + undoBuffer = malloc(bufferSize); + if (undoBuffer) + { + memcpy(undoBuffer, sourceBuffer, bufferSize); + } + } + } + + switch (attrdef->m_type) + { + case KX_PYATTRIBUTE_TYPE_BOOL: + { + bool *var = reinterpret_cast(ptr); + if (PyInt_Check(value)) + { + *var = (PyInt_AsLong(value) != 0); + } + else if (PyBool_Check(value)) + { + *var = (value == Py_True); + } + else + { + PyErr_SetString(PyExc_TypeError, "expected an integer or a bool"); + goto FREE_AND_ERROR; + } + break; + } + case KX_PYATTRIBUTE_TYPE_SHORT: + { + short int *var = reinterpret_cast(ptr); + if (PyInt_Check(value)) + { + long val = PyInt_AsLong(value); + if (val < attrdef->m_imin || val > attrdef->m_imax) + { + PyErr_SetString(PyExc_ValueError, "value out of range"); + goto FREE_AND_ERROR; + } + *var = (short int)val; + } + else + { + PyErr_SetString(PyExc_TypeError, "expected an integer"); + goto FREE_AND_ERROR; + } + break; + } + case KX_PYATTRIBUTE_TYPE_INT: + { + int *var = reinterpret_cast(ptr); + if (PyInt_Check(value)) + { + long val = PyInt_AsLong(value); + if (val < attrdef->m_imin || val > attrdef->m_imax) + { + PyErr_SetString(PyExc_ValueError, "value out of range"); + goto FREE_AND_ERROR; + } + *var = (int)val; + } + else + { + PyErr_SetString(PyExc_TypeError, "expected an integer"); + goto FREE_AND_ERROR; + } + break; + } + case KX_PYATTRIBUTE_TYPE_FLOAT: + { + float *var = reinterpret_cast(ptr); + if (PyFloat_Check(value)) + { + double val = PyFloat_AsDouble(value); + if (val < attrdef->m_fmin || val > attrdef->m_fmax) + { + PyErr_SetString(PyExc_ValueError, "value out of range"); + goto FREE_AND_ERROR; + } + *var = (float)val; + } + else + { + PyErr_SetString(PyExc_TypeError, "expected a float"); + goto FREE_AND_ERROR; + } + break; + } + case KX_PYATTRIBUTE_TYPE_STRING: + { + STR_String *var = reinterpret_cast(ptr); + if (PyString_Check(value)) + { + char *val = PyString_AsString(value); + if (strlen(val) < attrdef->m_imin || strlen(val) > attrdef->m_imax) + { + PyErr_SetString(PyExc_ValueError, "string length out of range"); + goto FREE_AND_ERROR; + } + *var = val; + } + else + { + PyErr_SetString(PyExc_TypeError, "expected a string"); + goto FREE_AND_ERROR; + } + break; + } + default: + // should not happen + PyErr_SetString(PyExc_AttributeError, "unknown attribute type, report to blender.org"); + goto FREE_AND_ERROR; + } + } + // check if post processing is needed + if (attrdef->m_function != NULL) + { + if ((*attrdef->m_function)(self) != 0) + { + // restore value + if (undoBuffer) + { + if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_STRING) + { + // special case for STR_String: restore the string + STR_String *var = reinterpret_cast(ptr); + *var = reinterpret_cast(undoBuffer); + } + else + { + // other field type have direct values + memcpy(ptr, undoBuffer, bufferSize); + } + } + FREE_AND_ERROR: + if (undoBuffer) + free(undoBuffer); + return 1; + } + } + if (undoBuffer) + free(undoBuffer); + return 0; + } + } + return -1; +} + /*------------------------------ * PyObjectPlus repr -- representations ------------------------------*/ diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 55998ce1c97..016fa293d73 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -86,6 +86,7 @@ static inline void Py_Fatal(const char *M) { public: \ static PyTypeObject Type; \ static PyMethodDef Methods[]; \ + static PyAttributeDef Attributes[]; \ static PyParentObject Parents[]; \ virtual PyTypeObject *GetType(void) {return &Type;}; \ virtual PyParentObject *GetParents(void) {return Parents;} @@ -210,6 +211,104 @@ PyObject* class_name::Py##method_name(PyObject*, PyObject* value) const char class_name::method_name##_doc[] = doc_string; \ PyObject* class_name::Py##method_name(PyObject*) +/** + * Attribute management + */ +enum KX_PYATTRIBUTE_TYPE { + KX_PYATTRIBUTE_TYPE_BOOL, + KX_PYATTRIBUTE_TYPE_SHORT, + KX_PYATTRIBUTE_TYPE_INT, + KX_PYATTRIBUTE_TYPE_FLOAT, + KX_PYATTRIBUTE_TYPE_STRING, + KX_PYATTRIBUTE_TYPE_DUMMY, +}; + +enum KX_PYATTRIBUTE_ACCESS { + KX_PYATTRIBUTE_RW, + KX_PYATTRIBUTE_RO +}; + +typedef int (*KX_PYATTRIBUTE_FUNCTION)(void *self); + +typedef struct KX_PYATTRIBUTE_DEF { + const char *m_name; // name of the python attribute + KX_PYATTRIBUTE_TYPE m_type; // type of value + KX_PYATTRIBUTE_ACCESS m_access; // read/write access or read-only + int m_imin; // minimum value in case of integer attributes + int m_imax; // maximum value in case of integer attributes + float m_fmin; // minimum value in case of float attributes + float m_fmax; // maximum value in case of float attributes + size_t m_offset; // position of field in structure + size_t m_length; // length of array, 1=simple attribute + KX_PYATTRIBUTE_FUNCTION m_function; // static function to check the assignment, returns 0 if no error + // The following pointers are just used to have compile time check for attribute type. + // It would have been good to use a union but that would require C99 compatibility + // to initialize specific union fields through designated initializers. + struct { + bool *m_boolPtr; + short int *m_shortPtr; + int *m_intPtr; + float *m_floatPtr; + STR_String *m_stringPtr; + } m_typeCheck; +} PyAttributeDef; + +#define KX_PYATTRIBUTE_DUMMY(name) \ + { name, KX_PYATTRIBUTE_TYPE_DUMMY, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, 0, 1, NULL, {NULL, NULL, NULL, NULL, NULL} } + +#define KX_PYATTRIBUTE_BOOL_RW(name,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, offsetof(object,field), 1, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_BOOL_RW_CHECK(name,object,field,function) \ + { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, offsetof(object,field), 1, &object::function, {&((object *)0)->field, NULL, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_BOOL_RO(name,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RO, 0, 1, 0.f, 0.f, offsetof(object,field), 1, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL} } + +#define KX_PYATTRIBUTE_SHORT_RW(name,min,max,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), 1, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_SHORT_RW_CHECK(name,min,max,object,field,function) \ + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), 1, &object::function, {NULL, &((object *)0)->field, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_SHORT_RO(name,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, offsetof(object,field), 1, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_SHORT_ARRAY_RW(name,min,max,object,field,length) \ + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), length, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_SHORT_ARRAY_RW_CHECK(name,min,max,object,field,length,function) \ + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), length, &object::function, {NULL, &((object *)0)->field, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_SHORT_ARRAY_RO(name,object,field,length) \ + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, offsetof(object,field), length, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } + +#define KX_PYATTRIBUTE_INT_RW(name,min,max,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), 1, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } +#define KX_PYATTRIBUTE_INT_RW_CHECK(name,min,max,object,field,function) \ + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), 1, &object::function, {NULL, NULL, &((object *)0)->field, NULL, NULL} } +#define KX_PYATTRIBUTE_INT_RO(name,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, offsetof(object,field), 1, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } +#define KX_PYATTRIBUTE_INT_ARRAY_RW(name,min,max,object,field,length) \ + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), length, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } +#define KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK(name,min,max,object,field,length,function) \ + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), length, &object::function, {NULL, NULL, &((object *)0)->field, NULL, NULL} } +#define KX_PYATTRIBUTE_INT_ARRAY_RO(name,object,field,length) \ + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, offsetof(object,field), length, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } + +#define KX_PYATTRIBUTE_FLOAT_RW(name,min,max,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, offsetof(object,field), 1, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } +#define KX_PYATTRIBUTE_FLOAT_RW_CHECK(name,min,max,object,field,function) \ + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, offsetof(object,field), 1, &object::function, {NULL, NULL, NULL, &((object *)0)->field, NULL} } +#define KX_PYATTRIBUTE_FLOAT_RO(name,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, offsetof(object,field), 1, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } +#define KX_PYATTRIBUTE_FLOAT_ARRAY_RW(name,min,max,object,field,length) \ + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, offsetof(object,field), length, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } +#define KX_PYATTRIBUTE_FLOAT_ARRAY_RW_CHECK(name,min,max,object,field,length,function) \ + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, offsetof(object,field), length, &object::function, {NULL, NULL, NULL, &((object *)0)->field, NULL} } +#define KX_PYATTRIBUTE_FLOAT_ARRAY_RO(name,object,field,length) \ + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, offsetof(object,field), length, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } + +#define KX_PYATTRIBUTE_STRING_RW(name,min,max,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), 1, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field} } +#define KX_PYATTRIBUTE_STRING_RW_CHECK(name,min,max,object,field,function) \ + { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), 1, &object::function, {NULL, NULL, NULL, NULL, &((object *)0)->field} } +#define KX_PYATTRIBUTE_STRING_RO(name,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, offsetof(object,field), 1 , NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field} } + /*------------------------------ * PyObjectPlus ------------------------------*/ @@ -240,6 +339,8 @@ public: { return ((PyObjectPlus*) PyObj)->_getattr(STR_String(attr)); } + static PyObject *_getattr_self(const PyAttributeDef attrlist[], void *self, const STR_String &attr); + static int _setattr_self(const PyAttributeDef attrlist[], void *self, const STR_String &attr, PyObject *value); virtual int _delattr(const STR_String& attr); virtual int _setattr(const STR_String& attr, PyObject *value); // _setattr method diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index ec5921bad85..ce9058448ac 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -327,6 +327,21 @@ PyMethodDef SCA_JoystickSensor::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_JoystickSensor::Attributes[] = { + KX_PYATTRIBUTE_SHORT_RW("index",0,JOYINDEX_MAX-1,SCA_JoystickSensor,m_joyindex), + KX_PYATTRIBUTE_INT_RW("threshold",0,32768,SCA_JoystickSensor,m_precision), + KX_PYATTRIBUTE_INT_RW("button",0,100,SCA_JoystickSensor,m_button), + KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK("axis",0,3,SCA_JoystickSensor,m_axis,2,CheckAxis), + KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK("hat",0,12,SCA_JoystickSensor,m_hat,2,CheckHat), + // dummy attributes will just be read-only in _setattr + // you still need to defined them in _getattr + KX_PYATTRIBUTE_DUMMY("axisPosition"), + KX_PYATTRIBUTE_DUMMY("numAxis"), + KX_PYATTRIBUTE_DUMMY("numButtons"), + KX_PYATTRIBUTE_DUMMY("numHats"), + KX_PYATTRIBUTE_DUMMY("connected"), + { NULL } //Sentinel +}; PyObject* SCA_JoystickSensor::_getattr(const STR_String& attr) { SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); @@ -348,100 +363,17 @@ PyObject* SCA_JoystickSensor::_getattr(const STR_String& attr) { if (attr == "connected") { return PyBool_FromLong( joy ? joy->Connected() : 0 ); } - if (attr == "index") { - return PyInt_FromLong(m_joyindex); - } - if (attr == "threshold") { - return PyInt_FromLong(m_precision); - } - if (attr == "button") { - return PyInt_FromLong(m_button); - } - if (attr == "axis") { - return Py_BuildValue("[ii]",m_axis, m_axisf); - } - if (attr == "hat") { - return Py_BuildValue("[ii]",m_hat, m_hatf); - } + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_ISensor); } -int SCA_JoystickSensor::_setattr(const STR_String& attr, PyObject *value) { - if (attr == "axisPosition") { - PyErr_SetString(PyExc_AttributeError, "axisPosition is read only"); - return 1; - } - if (attr == "numAxis") { - PyErr_SetString(PyExc_AttributeError, "numaxis is read only"); - return 1; - } - if (attr == "numButtons") { - PyErr_SetString(PyExc_AttributeError, "numbuttons is read only"); - return 1; - } - if (attr == "numHats") { - PyErr_SetString(PyExc_AttributeError, "numhats is read only"); - return 1; - } - if (attr == "connected") { - PyErr_SetString(PyExc_AttributeError, "connected is read only"); - return 1; - } - if (PyInt_Check(value)) { - int ival = PyInt_AsLong(value); - if (attr == "index") { - if (ival < 0 || ival >= JOYINDEX_MAX) { - PyErr_SetString(PyExc_ValueError, "joystick index out of range"); - return 1; - } - m_joyindex = ival; - } else if (attr == "threshold") { - m_precision = ival; - } else if (attr == "button") { - if (ival < 0) { - PyErr_SetString(PyExc_ValueError, "button out of range"); - return 1; - } - m_button = ival; - } - return 0; - } - if (PySequence_Check(value)) { - if (attr == "axis" || attr == "hat") { - if (PySequence_Size(value) != 2) { - PyErr_SetString(PyExc_ValueError, "value must be sequence of 2 integers"); - return 1; - } - int ival = -1; - int ivalf = -1; - PyObject *item = PySequence_GetItem(value, 0); /* new ref */ - ival = PyInt_AsLong(item); - Py_DECREF(item); - item = PySequence_GetItem(value, 1); /* new ref */ - ivalf = PyInt_AsLong(item); - Py_DECREF(item); - if (PyErr_Occurred()) { - PyErr_SetString(PyExc_ValueError, "one or more of the items in the sequence was not an integer"); - return 1; - } - if (attr == "axis") { - if (ival < 1 || ival > 2 || ivalf < 0 || ivalf > 3) { - PyErr_SetString(PyExc_ValueError, "items in the sequence are out of range"); - return 1; - } - m_axis = ival; - m_axisf = ivalf; - } else { - if (ival < 1 || ival > 2) { - PyErr_SetString(PyExc_ValueError, "items in the sequence are out of range"); - return 1; - } - m_hat = ival; - m_hatf = ivalf; - } - } - return 0; - } +int SCA_JoystickSensor::_setattr(const STR_String& attr, PyObject *value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; return SCA_ISensor::_setattr(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.h b/source/gameengine/GameLogic/SCA_JoystickSensor.h index 03653070db7..25103b3c6bc 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.h +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.h @@ -37,11 +37,11 @@ class SCA_JoystickSensor :public SCA_ISensor class SCA_JoystickManager* m_pJoystickMgr; /** - * Axis 1-or-2 + * Axis 1-or-2, MUST be followed by m_axisf */ int m_axis; /** - * Axis flag to find direction + * Axis flag to find direction, MUST be an int */ int m_axisf; /** @@ -53,11 +53,11 @@ class SCA_JoystickSensor :public SCA_ISensor */ int m_buttonf; /** - * The actual hat + * The actual hat. MUST be followed by m_hatf */ int m_hat; /** - * Flag to find direction 1-12 + * Flag to find direction 0-11, MUST be an int */ int m_hatf; /** @@ -147,6 +147,28 @@ public: KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,NumberOfButtons); KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,NumberOfHats); KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,Connected); + + /* attribute check */ + static int CheckAxis(void *self) + { + SCA_JoystickSensor* sensor = reinterpret_cast(self); + if (sensor->m_axis < 1 || sensor->m_axis > 2) + { + PyErr_SetString(PyExc_ValueError, "axis number must be 1 or 2"); + return 1; + } + return 0; + } + static int CheckHat(void *self) + { + SCA_JoystickSensor* sensor = reinterpret_cast(self); + if (sensor->m_hat < 1 || sensor->m_hat > 2) + { + PyErr_SetString(PyExc_ValueError, "hat number must be 1 or 2"); + return 1; + } + return 0; + } }; diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index 0e014628ac7..a05f9ae9879 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -820,91 +820,29 @@ PyMethodDef SCA_KeyboardSensor::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_KeyboardSensor::Attributes[] = { + KX_PYATTRIBUTE_BOOL_RW("useAllKeys",SCA_KeyboardSensor,m_bAllKeys), + KX_PYATTRIBUTE_INT_RW("key",0,1000,SCA_KeyboardSensor,m_hotkey), + KX_PYATTRIBUTE_SHORT_RW("hold1",0,1000,SCA_KeyboardSensor,m_qual), + KX_PYATTRIBUTE_SHORT_RW("hold2",0,1000,SCA_KeyboardSensor,m_qual2), + KX_PYATTRIBUTE_STRING_RW("toggleProperty",0,100,SCA_KeyboardSensor,m_toggleprop), + KX_PYATTRIBUTE_STRING_RW("targetProperty",0,100,SCA_KeyboardSensor,m_targetprop), + { NULL } //Sentinel +}; + PyObject* SCA_KeyboardSensor::_getattr(const STR_String& attr) { - if (attr == "key") - return PyInt_FromLong(m_hotkey); - - if (attr == "hold1") - return PyInt_FromLong(m_qual); - - if (attr == "hold2") - return PyInt_FromLong(m_qual2); - - if (attr == "toggleProperty") - return PyString_FromString(m_toggleprop); - - if (attr == "targetProperty") - return PyString_FromString(m_targetprop); - - if (attr == "useAllKeys") - return PyInt_FromLong(m_bAllKeys); - + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_ISensor); } int SCA_KeyboardSensor::_setattr(const STR_String& attr, PyObject *value) { - if (attr == "key") - { - if (!PyInt_Check(value)){ - PyErr_SetString(PyExc_TypeError, "expected an integer"); - return 1; - } - m_hotkey = PyInt_AsLong(value); - return 0; - } - - if (attr == "hold1") - { - if (!PyInt_Check(value)){ - PyErr_SetString(PyExc_TypeError, "expected an integer"); - return 1; - } - m_qual = PyInt_AsLong(value); - return 0; - } - - if (attr == "hold2") - { - if (!PyInt_Check(value)){ - PyErr_SetString(PyExc_TypeError, "expected an integer"); - return 1; - } - m_qual2 = PyInt_AsLong(value); - return 0; - } - - if (attr == "useAllKeys") - { - if (!PyInt_Check(value)){ - PyErr_SetString(PyExc_TypeError, "expected an integer"); - return 1; - } - m_bAllKeys = (PyInt_AsLong(value) != 0); - return 0; - } - - if (attr == "logToggleProperty") - { - if (!PyString_Check(value)){ - PyErr_SetString(PyExc_TypeError, "expected a string"); - return 1; - } - m_toggleprop = PyString_AsString(value); - return 0; - } - - if (attr == "logTargetProperty") - { - if (!PyString_Check(value)){ - PyErr_SetString(PyExc_TypeError, "expected a string"); - return 1; - } - m_targetprop = PyString_AsString(value); - return 0; - } - + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; return SCA_ISensor::_setattr(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index 8281eed47bc..14d9c898980 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -59,7 +59,7 @@ SCA_MouseSensor::SCA_MouseSensor(SCA_MouseManager* eventmgr, m_mousemode = mousemode; m_triggermode = true; - UpdateHotkey(); + UpdateHotkey(this); Init(); } @@ -74,33 +74,37 @@ SCA_MouseSensor::~SCA_MouseSensor() /* Nothing to be done here. */ } -void SCA_MouseSensor::UpdateHotkey() +int SCA_MouseSensor::UpdateHotkey(void *self) { // gosh, this function is so damn stupid // its here because of a design mistake in the mouse sensor, it should only // have 3 trigger modes (button, wheel, move), and let the user set the // hotkey separately, like the other sensors. but instead it has a mode for // each friggin key and i have to update the hotkey based on it... genius! - - switch (m_mousemode) { + SCA_MouseSensor* sensor = reinterpret_cast(self); + + switch (sensor->m_mousemode) { case KX_MOUSESENSORMODE_LEFTBUTTON: - m_hotkey = SCA_IInputDevice::KX_LEFTMOUSE; + sensor->m_hotkey = SCA_IInputDevice::KX_LEFTMOUSE; break; case KX_MOUSESENSORMODE_MIDDLEBUTTON: - m_hotkey = SCA_IInputDevice::KX_MIDDLEMOUSE; + sensor->m_hotkey = SCA_IInputDevice::KX_MIDDLEMOUSE; break; case KX_MOUSESENSORMODE_RIGHTBUTTON: - m_hotkey = SCA_IInputDevice::KX_RIGHTMOUSE; + sensor->m_hotkey = SCA_IInputDevice::KX_RIGHTMOUSE; break; case KX_MOUSESENSORMODE_WHEELUP: - m_hotkey = SCA_IInputDevice::KX_WHEELUPMOUSE; + sensor->m_hotkey = SCA_IInputDevice::KX_WHEELUPMOUSE; break; case KX_MOUSESENSORMODE_WHEELDOWN: - m_hotkey = SCA_IInputDevice::KX_WHEELDOWNMOUSE; + sensor->m_hotkey = SCA_IInputDevice::KX_WHEELDOWNMOUSE; break; default: ; /* ignore, no hotkey */ } + // return value is used in _setattr(), + // 0=attribute checked ok (see Attributes array definition) + return 0; } CValue* SCA_MouseSensor::GetReplica() @@ -331,44 +335,25 @@ PyMethodDef SCA_MouseSensor::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* SCA_MouseSensor::_getattr(const STR_String& attr) { - if (attr == "position") - return Py_BuildValue("[ii]", m_x, m_y); - - if (attr == "mode") - return PyInt_FromLong(m_mousemode); - +PyAttributeDef SCA_MouseSensor::Attributes[] = { + KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",KX_MOUSESENSORMODE_NODEF,KX_MOUSESENSORMODE_MAX-1,SCA_MouseSensor,m_mousemode,UpdateHotkey), + KX_PYATTRIBUTE_SHORT_ARRAY_RO("position",SCA_MouseSensor,m_x,2), + { NULL } //Sentinel +}; + +PyObject* SCA_MouseSensor::_getattr(const STR_String& attr) +{ + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_ISensor); } int SCA_MouseSensor::_setattr(const STR_String& attr, PyObject *value) { - if (attr == "mode") - { - if (!PyInt_Check(value)){ - PyErr_SetString(PyExc_TypeError, "expected an integer"); - return 1; - } - - int val = PyInt_AsLong(value); - - if ((val < KX_MOUSESENSORMODE_NODEF) - || (val > KX_MOUSESENSORMODE_MAX)){ - PyErr_SetString(PyExc_ValueError, "invalid mode specified!"); - return 1; - } - - m_mousemode = val; - UpdateHotkey(); - return 0; - } - - if (attr == "position") - { - PyErr_SetString(PyExc_AttributeError, "'position' is a read-only property!"); - return 1; - } - + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; return SCA_ISensor::_setattr(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.h b/source/gameengine/GameLogic/SCA_MouseSensor.h index 6d6e641c798..58ee96c8856 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.h +++ b/source/gameengine/GameLogic/SCA_MouseSensor.h @@ -58,7 +58,7 @@ class SCA_MouseSensor : public SCA_ISensor SCA_IInputDevice::KX_EnumInputs m_hotkey; /** - * valid x coordinate + * valid x coordinate, MUST be followed by y coordinate */ short m_x; @@ -87,7 +87,7 @@ class SCA_MouseSensor : public SCA_ISensor bool isValid(KX_MOUSESENSORMODE); - void UpdateHotkey(); + static int UpdateHotkey(void *self); SCA_MouseSensor(class SCA_MouseManager* keybdmgr, int startx,int starty, -- cgit v1.2.3 From cc569504d0468ec19a1018ea804aa418c134cb0f Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Fri, 2 Jan 2009 17:43:56 +0000 Subject: BGE API Cleanup: update the python attribute definition framework. * Value clamping to min/max is now supported as an option for integer, float and string attribute (for string clamping=trim to max length) * Post check function now take PyAttributeDef parameter so that more generic function can be written. * Definition of SCA_ILogicBrick::CheckProperty() function to check that a string attribute contains a valid property name of the parent game object. * Definition of enum attribute vi KX_PYATTRIBUTE_ENUM... macros. Enum are handled just like integer but to be totally paranoid, the sizeof() of the enum member is check at run time to match integer size. * More bricks updated to use the framework. --- source/gameengine/Expressions/PyObjectPlus.cpp | 142 +++++++++++++++++---- source/gameengine/Expressions/PyObjectPlus.h | 92 +++++++------ source/gameengine/GameLogic/SCA_ActuatorSensor.cpp | 39 +++--- source/gameengine/GameLogic/SCA_ActuatorSensor.h | 1 + source/gameengine/GameLogic/SCA_DelaySensor.cpp | 45 ++----- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 18 ++- source/gameengine/GameLogic/SCA_ILogicBrick.h | 3 + source/gameengine/GameLogic/SCA_ISensor.cpp | 73 +++-------- source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 10 +- source/gameengine/GameLogic/SCA_JoystickSensor.h | 22 ++-- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 10 +- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 6 +- source/gameengine/GameLogic/SCA_MouseSensor.h | 2 +- .../gameengine/GameLogic/SCA_PropertyActuator.cpp | 37 ++---- source/gameengine/GameLogic/SCA_PropertySensor.cpp | 65 +++------- source/gameengine/GameLogic/SCA_PropertySensor.h | 9 +- source/gameengine/GameLogic/SCA_RandomActuator.cpp | 61 +++------ source/gameengine/GameLogic/SCA_RandomActuator.h | 1 - 18 files changed, 325 insertions(+), 311 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index c31587628b0..8fd99c8d267 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -164,6 +164,14 @@ PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *sel PyList_SetItem(resultlist,i,PyInt_FromLong(*val)); break; } + case KX_PYATTRIBUTE_TYPE_ENUM: + // enum are like int, just make sure the field size is the same + if (sizeof(int) != attrdef->m_size) + { + Py_DECREF(resultlist); + return NULL; + } + // walkthrough case KX_PYATTRIBUTE_TYPE_INT: { int *val = reinterpret_cast(ptr); @@ -180,6 +188,7 @@ PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *sel } default: // no support for array of complex data + Py_DECREF(resultlist); return NULL; } } @@ -198,6 +207,13 @@ PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *sel short int *val = reinterpret_cast(ptr); return PyInt_FromLong(*val); } + case KX_PYATTRIBUTE_TYPE_ENUM: + // enum are like int, just make sure the field size is the same + if (sizeof(int) != attrdef->m_size) + { + return NULL; + } + // walkthrough case KX_PYATTRIBUTE_TYPE_INT: { int *val = reinterpret_cast(ptr); @@ -260,6 +276,7 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con case KX_PYATTRIBUTE_TYPE_SHORT: bufferSize = sizeof(short int); break; + case KX_PYATTRIBUTE_TYPE_ENUM: case KX_PYATTRIBUTE_TYPE_INT: bufferSize = sizeof(int); break; @@ -313,7 +330,14 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con if (PyInt_Check(item)) { long val = PyInt_AsLong(item); - if (val < attrdef->m_imin || val > attrdef->m_imax) + if (attrdef->m_clamp) + { + if (val < attrdef->m_imin) + val = attrdef->m_imin; + else if (val > attrdef->m_imax) + val = attrdef->m_imax; + } + else if (val < attrdef->m_imin || val > attrdef->m_imax) { PyErr_SetString(PyExc_ValueError, "item value out of range"); goto UNDO_AND_ERROR; @@ -327,6 +351,14 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con } break; } + case KX_PYATTRIBUTE_TYPE_ENUM: + // enum are equivalent to int, just make sure that the field size matches: + if (sizeof(int) != attrdef->m_size) + { + PyErr_SetString(PyExc_AttributeError, "attribute size check error, report to blender.org"); + goto UNDO_AND_ERROR; + } + // walkthrough case KX_PYATTRIBUTE_TYPE_INT: { int *var = reinterpret_cast(ptr); @@ -334,7 +366,14 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con if (PyInt_Check(item)) { long val = PyInt_AsLong(item); - if (val < attrdef->m_imin || val > attrdef->m_imax) + if (attrdef->m_clamp) + { + if (val < attrdef->m_imin) + val = attrdef->m_imin; + else if (val > attrdef->m_imax) + val = attrdef->m_imax; + } + else if (val < attrdef->m_imin || val > attrdef->m_imax) { PyErr_SetString(PyExc_ValueError, "item value out of range"); goto UNDO_AND_ERROR; @@ -352,21 +391,25 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con { float *var = reinterpret_cast(ptr); ptr += sizeof(float); - if (PyFloat_Check(item)) + double val = PyFloat_AsDouble(item); + if (val == -1.0 && PyErr_Occurred()) { - double val = PyFloat_AsDouble(item); - if (val < attrdef->m_fmin || val > attrdef->m_fmax) - { - PyErr_SetString(PyExc_ValueError, "item value out of range"); - goto UNDO_AND_ERROR; - } - *var = (float)val; + PyErr_SetString(PyExc_TypeError, "expected a float"); + goto UNDO_AND_ERROR; } - else + else if (attrdef->m_clamp) { - PyErr_SetString(PyExc_TypeError, "expected a float"); + if (val < attrdef->m_fmin) + val = attrdef->m_fmin; + else if (val > attrdef->m_fmax) + val = attrdef->m_fmax; + } + else if (val < attrdef->m_fmin || val > attrdef->m_fmax) + { + PyErr_SetString(PyExc_ValueError, "item value out of range"); goto UNDO_AND_ERROR; } + *var = (float)val; break; } default: @@ -378,7 +421,7 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con // no error, call check function if any if (attrdef->m_function != NULL) { - if ((*attrdef->m_function)(self) != 0) + if ((*attrdef->m_function)(self, attrdef) != 0) { // post check returned an error, restore values UNDO_AND_ERROR: @@ -409,6 +452,7 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con case KX_PYATTRIBUTE_TYPE_SHORT: bufferSize = sizeof(short); break; + case KX_PYATTRIBUTE_TYPE_ENUM: case KX_PYATTRIBUTE_TYPE_INT: bufferSize = sizeof(int); break; @@ -460,7 +504,14 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con if (PyInt_Check(value)) { long val = PyInt_AsLong(value); - if (val < attrdef->m_imin || val > attrdef->m_imax) + if (attrdef->m_clamp) + { + if (val < attrdef->m_imin) + val = attrdef->m_imin; + else if (val > attrdef->m_imax) + val = attrdef->m_imax; + } + else if (val < attrdef->m_imin || val > attrdef->m_imax) { PyErr_SetString(PyExc_ValueError, "value out of range"); goto FREE_AND_ERROR; @@ -474,13 +525,28 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con } break; } + case KX_PYATTRIBUTE_TYPE_ENUM: + // enum are equivalent to int, just make sure that the field size matches: + if (sizeof(int) != attrdef->m_size) + { + PyErr_SetString(PyExc_AttributeError, "attribute size check error, report to blender.org"); + goto FREE_AND_ERROR; + } + // walkthrough case KX_PYATTRIBUTE_TYPE_INT: { int *var = reinterpret_cast(ptr); if (PyInt_Check(value)) { long val = PyInt_AsLong(value); - if (val < attrdef->m_imin || val > attrdef->m_imax) + if (attrdef->m_clamp) + { + if (val < attrdef->m_imin) + val = attrdef->m_imin; + else if (val > attrdef->m_imax) + val = attrdef->m_imax; + } + else if (val < attrdef->m_imin || val > attrdef->m_imax) { PyErr_SetString(PyExc_ValueError, "value out of range"); goto FREE_AND_ERROR; @@ -497,21 +563,25 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con case KX_PYATTRIBUTE_TYPE_FLOAT: { float *var = reinterpret_cast(ptr); - if (PyFloat_Check(value)) + double val = PyFloat_AsDouble(value); + if (val == -1.0 && PyErr_Occurred()) { - double val = PyFloat_AsDouble(value); - if (val < attrdef->m_fmin || val > attrdef->m_fmax) - { - PyErr_SetString(PyExc_ValueError, "value out of range"); - goto FREE_AND_ERROR; - } - *var = (float)val; + PyErr_SetString(PyExc_TypeError, "expected a float"); + goto FREE_AND_ERROR; } - else + else if (attrdef->m_clamp) { - PyErr_SetString(PyExc_TypeError, "expected a float"); + if (val < attrdef->m_fmin) + val = attrdef->m_fmin; + else if (val > attrdef->m_fmax) + val = attrdef->m_fmax; + } + else if (val < attrdef->m_fmin || val > attrdef->m_fmax) + { + PyErr_SetString(PyExc_ValueError, "value out of range"); goto FREE_AND_ERROR; } + *var = (float)val; break; } case KX_PYATTRIBUTE_TYPE_STRING: @@ -520,7 +590,24 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con if (PyString_Check(value)) { char *val = PyString_AsString(value); - if (strlen(val) < attrdef->m_imin || strlen(val) > attrdef->m_imax) + if (attrdef->m_clamp) + { + if (strlen(val) < attrdef->m_imin) + { + // can't increase the length of the string + PyErr_SetString(PyExc_ValueError, "string length too short"); + goto FREE_AND_ERROR; + } + else if (strlen(val) > attrdef->m_imax) + { + // trim the string + char c = val[attrdef->m_imax]; + val[attrdef->m_imax] = 0; + *var = val; + val[attrdef->m_imax] = c; + break; + } + } else if (strlen(val) < attrdef->m_imin || strlen(val) > attrdef->m_imax) { PyErr_SetString(PyExc_ValueError, "string length out of range"); goto FREE_AND_ERROR; @@ -543,9 +630,10 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con // check if post processing is needed if (attrdef->m_function != NULL) { - if ((*attrdef->m_function)(self) != 0) + if ((*attrdef->m_function)(self, attrdef) != 0) { // restore value + RESTORE_AND_ERROR: if (undoBuffer) { if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_STRING) diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 016fa293d73..e0e2213d984 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -216,6 +216,7 @@ PyObject* class_name::Py##method_name(PyObject*) */ enum KX_PYATTRIBUTE_TYPE { KX_PYATTRIBUTE_TYPE_BOOL, + KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_TYPE_FLOAT, @@ -228,17 +229,20 @@ enum KX_PYATTRIBUTE_ACCESS { KX_PYATTRIBUTE_RO }; -typedef int (*KX_PYATTRIBUTE_FUNCTION)(void *self); +struct KX_PYATTRIBUTE_DEF; +typedef int (*KX_PYATTRIBUTE_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); typedef struct KX_PYATTRIBUTE_DEF { const char *m_name; // name of the python attribute KX_PYATTRIBUTE_TYPE m_type; // type of value KX_PYATTRIBUTE_ACCESS m_access; // read/write access or read-only - int m_imin; // minimum value in case of integer attributes - int m_imax; // maximum value in case of integer attributes + int m_imin; // minimum value in case of integer attributes (for string: minimum string length) + int m_imax; // maximum value in case of integer attributes (for string: maximum string length) float m_fmin; // minimum value in case of float attributes float m_fmax; // maximum value in case of float attributes + bool m_clamp; // enforce min/max value by clamping size_t m_offset; // position of field in structure + size_t m_size; // size of field for runtime verification (enum only) size_t m_length; // length of array, 1=simple attribute KX_PYATTRIBUTE_FUNCTION m_function; // static function to check the assignment, returns 0 if no error // The following pointers are just used to have compile time check for attribute type. @@ -254,60 +258,70 @@ typedef struct KX_PYATTRIBUTE_DEF { } PyAttributeDef; #define KX_PYATTRIBUTE_DUMMY(name) \ - { name, KX_PYATTRIBUTE_TYPE_DUMMY, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, 0, 1, NULL, {NULL, NULL, NULL, NULL, NULL} } + { name, KX_PYATTRIBUTE_TYPE_DUMMY, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, 0, 0, 1, NULL, {NULL, NULL, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_BOOL_RW(name,object,field) \ - { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, offsetof(object,field), 1, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL} } + { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_BOOL_RW_CHECK(name,object,field,function) \ - { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, offsetof(object,field), 1, &object::function, {&((object *)0)->field, NULL, NULL, NULL, NULL} } + { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, false, offsetof(object,field), 0, 1, &object::function, {&((object *)0)->field, NULL, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_BOOL_RO(name,object,field) \ - { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RO, 0, 1, 0.f, 0.f, offsetof(object,field), 1, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL} } - -#define KX_PYATTRIBUTE_SHORT_RW(name,min,max,object,field) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), 1, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_SHORT_RW_CHECK(name,min,max,object,field,function) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), 1, &object::function, {NULL, &((object *)0)->field, NULL, NULL, NULL} } + { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RO, 0, 1, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL} } + +// enum field cannot be mapped to pointer (because we would need a pointer for each enum) +// use field size to verify mapping at runtime only, assuming enum size is equal to int size. +#define KX_PYATTRIBUTE_ENUM_RW(name,min,max,clamp,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, {NULL, NULL, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_ENUM_RW_CHECK(name,min,max,clamp,object,field,function) \ + { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), sizeof(((object *)0)->field), 1, &object::function, {NULL, NULL, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_ENUM_RO(name,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), sizeof(((object *)0)->field), 1, NULL, {NULL, NULL, NULL, NULL, NULL} } + +#define KX_PYATTRIBUTE_SHORT_RW(name,min,max,clamp,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_SHORT_RW_CHECK(name,min,max,clamp,object,field,function) \ + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, &object::function, {NULL, &((object *)0)->field, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_SHORT_RO(name,object,field) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, offsetof(object,field), 1, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_SHORT_ARRAY_RW(name,min,max,object,field,length) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), length, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_SHORT_ARRAY_RW_CHECK(name,min,max,object,field,length,function) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), length, &object::function, {NULL, &((object *)0)->field, NULL, NULL, NULL} } + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_SHORT_ARRAY_RW(name,min,max,clamp,object,field,length) \ + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_SHORT_ARRAY_RW_CHECK(name,min,max,clamp,object,field,length,function) \ + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, {NULL, &((object *)0)->field, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_SHORT_ARRAY_RO(name,object,field,length) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, offsetof(object,field), length, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_INT_RW(name,min,max,object,field) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), 1, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } -#define KX_PYATTRIBUTE_INT_RW_CHECK(name,min,max,object,field,function) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), 1, &object::function, {NULL, NULL, &((object *)0)->field, NULL, NULL} } +#define KX_PYATTRIBUTE_INT_RW(name,min,max,clamp,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } +#define KX_PYATTRIBUTE_INT_RW_CHECK(name,min,max,clamp,object,field,function) \ + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, &object::function, {NULL, NULL, &((object *)0)->field, NULL, NULL} } #define KX_PYATTRIBUTE_INT_RO(name,object,field) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, offsetof(object,field), 1, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } -#define KX_PYATTRIBUTE_INT_ARRAY_RW(name,min,max,object,field,length) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), length, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } -#define KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK(name,min,max,object,field,length,function) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), length, &object::function, {NULL, NULL, &((object *)0)->field, NULL, NULL} } + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } +#define KX_PYATTRIBUTE_INT_ARRAY_RW(name,min,max,clamp,object,field,length) \ + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } +#define KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK(name,min,max,clamp,object,field,length,function) \ + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, {NULL, NULL, &((object *)0)->field, NULL, NULL} } #define KX_PYATTRIBUTE_INT_ARRAY_RO(name,object,field,length) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, offsetof(object,field), length, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } +// always clamp for float #define KX_PYATTRIBUTE_FLOAT_RW(name,min,max,object,field) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, offsetof(object,field), 1, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, offsetof(object,field), 0, 1, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } #define KX_PYATTRIBUTE_FLOAT_RW_CHECK(name,min,max,object,field,function) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, offsetof(object,field), 1, &object::function, {NULL, NULL, NULL, &((object *)0)->field, NULL} } + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, offsetof(object,field), 0, 1, &object::function, {NULL, NULL, NULL, &((object *)0)->field, NULL} } #define KX_PYATTRIBUTE_FLOAT_RO(name,object,field) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, offsetof(object,field), 1, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } #define KX_PYATTRIBUTE_FLOAT_ARRAY_RW(name,min,max,object,field,length) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, offsetof(object,field), length, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, offsetof(object,field), 0, length, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } #define KX_PYATTRIBUTE_FLOAT_ARRAY_RW_CHECK(name,min,max,object,field,length,function) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, offsetof(object,field), length, &object::function, {NULL, NULL, NULL, &((object *)0)->field, NULL} } + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, offsetof(object,field), 0, length, &object::function, {NULL, NULL, NULL, &((object *)0)->field, NULL} } #define KX_PYATTRIBUTE_FLOAT_ARRAY_RO(name,object,field,length) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, offsetof(object,field), length, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } -#define KX_PYATTRIBUTE_STRING_RW(name,min,max,object,field) \ - { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), 1, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field} } -#define KX_PYATTRIBUTE_STRING_RW_CHECK(name,min,max,object,field,function) \ - { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, offsetof(object,field), 1, &object::function, {NULL, NULL, NULL, NULL, &((object *)0)->field} } +#define KX_PYATTRIBUTE_STRING_RW(name,min,max,clamp,object,field) \ + { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field} } +#define KX_PYATTRIBUTE_STRING_RW_CHECK(name,min,max,clamp,object,field,function) \ + { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, &object::function, {NULL, NULL, NULL, NULL, &((object *)0)->field} } #define KX_PYATTRIBUTE_STRING_RO(name,object,field) \ - { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, offsetof(object,field), 1 , NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field} } + { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, 1 , NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field} } /*------------------------------ * PyObjectPlus diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp index 5ad28dbf329..fae8d2ba5a7 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp @@ -156,27 +156,34 @@ PyMethodDef SCA_ActuatorSensor::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_ActuatorSensor::Attributes[] = { + KX_PYATTRIBUTE_STRING_RW_CHECK("actuator",0,100,false,SCA_ActuatorSensor,m_checkactname,CheckActuator), + { NULL } //Sentinel +}; + PyObject* SCA_ActuatorSensor::_getattr(const STR_String& attr) { - if (attr == "actuator") { - return PyString_FromString(m_checkactname); - } + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_ISensor); /* implicit return! */ } -int SCA_ActuatorSensor::_setattr(const STR_String& attr, PyObject *value) { - if (PyString_Check(value)) { - char* sval = PyString_AsString(value); - if (attr == "actuator") { - SCA_IActuator* act = GetParent()->FindActuator(STR_String(sval)); - if (act) { - m_checkactname = sval; - m_actuator = act; - return 0; - } - PyErr_SetString(PyExc_AttributeError, "string does not correspond to an actuator"); - return 1; - } +int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*) +{ + SCA_ActuatorSensor* sensor = reinterpret_cast(self); + SCA_IActuator* act = sensor->GetParent()->FindActuator(sensor->m_checkactname); + if (act) { + sensor->m_actuator = act; + return 0; } + PyErr_SetString(PyExc_AttributeError, "string does not correspond to an actuator"); + return 1; +} + +int SCA_ActuatorSensor::_setattr(const STR_String& attr, PyObject *value) { + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; return SCA_ISensor::_setattr(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.h b/source/gameengine/GameLogic/SCA_ActuatorSensor.h index 4fe4700602c..3d64247461c 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.h +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.h @@ -69,6 +69,7 @@ public: /* 4. getProperty */ KX_PYMETHOD_DOC_NOARGS(SCA_ActuatorSensor,GetActuator); + static int CheckActuator(void *self, const PyAttributeDef*); }; #endif diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp index 362483b58a2..4c97ca98d72 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp +++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp @@ -171,43 +171,24 @@ PyMethodDef SCA_DelaySensor::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_DelaySensor::Attributes[] = { + KX_PYATTRIBUTE_INT_RW("delay",0,100000,true,SCA_DelaySensor,m_delay), + KX_PYATTRIBUTE_INT_RW("duration",0,100000,true,SCA_DelaySensor,m_duration), + KX_PYATTRIBUTE_BOOL_RW("repeat",SCA_DelaySensor,m_repeat), + { NULL } //Sentinel +}; + PyObject* SCA_DelaySensor::_getattr(const STR_String& attr) { - if (attr == "delay") { - return PyInt_FromLong(m_delay); - } - if (attr == "duration") { - return PyInt_FromLong(m_duration); - } - if (attr == "repeat") { - return PyInt_FromLong(m_repeat); - } + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_ISensor); } int SCA_DelaySensor::_setattr(const STR_String& attr, PyObject *value) { - if (PyInt_Check(value)) { - int ival = PyInt_AsLong(value); - if (attr == "delay") { - if (ival < 0) { - PyErr_SetString(PyExc_ValueError, "Delay cannot be negative"); - return 1; - } - m_delay = ival; - return 0; - } - if (attr == "duration") { - if (ival < 0) { - PyErr_SetString(PyExc_ValueError, "Duration cannot be negative"); - return 1; - } - m_duration = ival; - return 0; - } - if (attr == "repeat") { - m_repeat = (ival != 0); - return 0; - } - } + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; return SCA_ISensor::_setattr(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index 515b485061d..37658480c05 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -252,7 +252,23 @@ PyMethodDef SCA_ILogicBrick::Methods[] = { {NULL,NULL} //Sentinel }; - +int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef) +{ + if (attrdef->m_type != KX_PYATTRIBUTE_TYPE_STRING || attrdef->m_length != 1) { + PyErr_SetString(PyExc_AttributeError, "inconsistent check function for attribute type, report to blender.org"); + return 1; + } + SCA_ILogicBrick* brick = reinterpret_cast(self); + STR_String* var = reinterpret_cast((char*)self+attrdef->m_offset); + CValue* prop = brick->GetParent()->FindIdentifier(*var); + bool error = prop->IsError(); + prop->Release(); + if (error) { + PyErr_SetString(PyExc_ValueError, "string does not correspond to a property"); + return 1; + } + return 0; +} PyObject* SCA_ILogicBrick::_getattr(const STR_String& attr) diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h index c28711ac0f6..38ec80d4096 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.h +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h @@ -89,6 +89,9 @@ public: KX_PYMETHOD(SCA_ILogicBrick,SetExecutePriority); KX_PYMETHOD_NOARGS(SCA_ILogicBrick,GetExecutePriority); + // check that attribute is a property + static int CheckProperty(void *self, const PyAttributeDef *attrdef); + enum KX_BOOL_TYPE { KX_BOOL_NODEF = 0, KX_TRUE, diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index 6e46c8504bb..68a3a93eab0 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -448,19 +448,24 @@ PyMethodDef SCA_ISensor::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_ISensor::Attributes[] = { + KX_PYATTRIBUTE_BOOL_RW("usePosPulseMode",SCA_ISensor,m_pos_pulsemode), + KX_PYATTRIBUTE_BOOL_RW("useNegPulseMode",SCA_ISensor,m_neg_pulsemode), + KX_PYATTRIBUTE_INT_RW("frequency",0,100000,true,SCA_ISensor,m_pulse_frequency), + KX_PYATTRIBUTE_BOOL_RW("invert",SCA_ISensor,m_invert), + KX_PYATTRIBUTE_BOOL_RW("level",SCA_ISensor,m_level), + // make these properties read-only in _setaddr, must still implement them in _getattr + KX_PYATTRIBUTE_DUMMY("triggered"), + KX_PYATTRIBUTE_DUMMY("positive"), + { NULL } //Sentinel +}; + PyObject* SCA_ISensor::_getattr(const STR_String& attr) { - if (attr == "usePosPulseMode") - return PyInt_FromLong(m_pos_pulsemode); - if (attr == "useNegPulseMode") - return PyInt_FromLong(m_neg_pulsemode); - if (attr == "frequency") - return PyInt_FromLong(m_pulse_frequency); - if (attr == "invert") - return PyInt_FromLong(m_invert); - if (attr == "level") - return PyInt_FromLong(m_level); + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; if (attr == "triggered") { int retval = 0; @@ -473,54 +478,14 @@ SCA_ISensor::_getattr(const STR_String& attr) int retval = IsPositiveTrigger(); return PyInt_FromLong(retval); } - - _getattr_up(SCA_ILogicBrick); + _getattr_up(SCA_ILogicBrick); } int SCA_ISensor::_setattr(const STR_String& attr, PyObject *value) { - if (attr == "triggered") - PyErr_SetString(PyExc_AttributeError, "attribute \"triggered\" is read only"); - if (attr == "positive") - PyErr_SetString(PyExc_AttributeError, "attribute \"positive\" is read only"); - - if (PyInt_Check(value)) - { - int val = PyInt_AsLong(value); - - if (attr == "usePosPulseMode") - { - m_pos_pulsemode = (val != 0); - return 0; - } - - if (attr == "useNegPulseMode") - { - m_neg_pulsemode = (val != 0); - return 0; - } - - if (attr == "invert") - { - m_invert = (val != 0); - return 0; - } - - if (attr == "level") - { - m_level = (val != 0); - return 0; - } - - if (attr == "frequency") - { - if (val < 0) - val = 0; - m_pulse_frequency = val; - return 0; - } - } - + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; return SCA_ILogicBrick::_setattr(attr, value); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index ce9058448ac..694bca9bac5 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -328,11 +328,11 @@ PyMethodDef SCA_JoystickSensor::Methods[] = { }; PyAttributeDef SCA_JoystickSensor::Attributes[] = { - KX_PYATTRIBUTE_SHORT_RW("index",0,JOYINDEX_MAX-1,SCA_JoystickSensor,m_joyindex), - KX_PYATTRIBUTE_INT_RW("threshold",0,32768,SCA_JoystickSensor,m_precision), - KX_PYATTRIBUTE_INT_RW("button",0,100,SCA_JoystickSensor,m_button), - KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK("axis",0,3,SCA_JoystickSensor,m_axis,2,CheckAxis), - KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK("hat",0,12,SCA_JoystickSensor,m_hat,2,CheckHat), + KX_PYATTRIBUTE_SHORT_RW("index",0,JOYINDEX_MAX-1,true,SCA_JoystickSensor,m_joyindex), + KX_PYATTRIBUTE_INT_RW("threshold",0,32768,true,SCA_JoystickSensor,m_precision), + KX_PYATTRIBUTE_INT_RW("button",0,100,false,SCA_JoystickSensor,m_button), + KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK("axis",0,3,true,SCA_JoystickSensor,m_axis,2,CheckAxis), + KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK("hat",0,12,true,SCA_JoystickSensor,m_hat,2,CheckHat), // dummy attributes will just be read-only in _setattr // you still need to defined them in _getattr KX_PYATTRIBUTE_DUMMY("axisPosition"), diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.h b/source/gameengine/GameLogic/SCA_JoystickSensor.h index 25103b3c6bc..fa11f1cc3d0 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.h +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.h @@ -149,24 +149,22 @@ public: KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,Connected); /* attribute check */ - static int CheckAxis(void *self) + static int CheckAxis(void *self, const PyAttributeDef*) { SCA_JoystickSensor* sensor = reinterpret_cast(self); - if (sensor->m_axis < 1 || sensor->m_axis > 2) - { - PyErr_SetString(PyExc_ValueError, "axis number must be 1 or 2"); - return 1; - } + if (sensor->m_axis < 1) + sensor->m_axis = 1; + else if (sensor->m_axis > 2) + sensor->m_axis = 2; return 0; } - static int CheckHat(void *self) + static int CheckHat(void *self, const PyAttributeDef*) { SCA_JoystickSensor* sensor = reinterpret_cast(self); - if (sensor->m_hat < 1 || sensor->m_hat > 2) - { - PyErr_SetString(PyExc_ValueError, "hat number must be 1 or 2"); - return 1; - } + if (sensor->m_hat < 1) + sensor->m_hat = 1; + else if (sensor->m_hat > 2) + sensor->m_hat = 2; return 0; } diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index a05f9ae9879..981d165287b 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -822,11 +822,11 @@ PyMethodDef SCA_KeyboardSensor::Methods[] = { PyAttributeDef SCA_KeyboardSensor::Attributes[] = { KX_PYATTRIBUTE_BOOL_RW("useAllKeys",SCA_KeyboardSensor,m_bAllKeys), - KX_PYATTRIBUTE_INT_RW("key",0,1000,SCA_KeyboardSensor,m_hotkey), - KX_PYATTRIBUTE_SHORT_RW("hold1",0,1000,SCA_KeyboardSensor,m_qual), - KX_PYATTRIBUTE_SHORT_RW("hold2",0,1000,SCA_KeyboardSensor,m_qual2), - KX_PYATTRIBUTE_STRING_RW("toggleProperty",0,100,SCA_KeyboardSensor,m_toggleprop), - KX_PYATTRIBUTE_STRING_RW("targetProperty",0,100,SCA_KeyboardSensor,m_targetprop), + KX_PYATTRIBUTE_INT_RW("key",0,SCA_IInputDevice::KX_ENDKEY,true,SCA_KeyboardSensor,m_hotkey), + KX_PYATTRIBUTE_SHORT_RW("hold1",0,SCA_IInputDevice::KX_ENDKEY,true,SCA_KeyboardSensor,m_qual), + KX_PYATTRIBUTE_SHORT_RW("hold2",0,SCA_IInputDevice::KX_ENDKEY,true,SCA_KeyboardSensor,m_qual2), + KX_PYATTRIBUTE_STRING_RW("toggleProperty",0,100,false,SCA_KeyboardSensor,m_toggleprop), + KX_PYATTRIBUTE_STRING_RW("targetProperty",0,100,false,SCA_KeyboardSensor,m_targetprop), { NULL } //Sentinel }; diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index 14d9c898980..09b46e6443e 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -59,7 +59,7 @@ SCA_MouseSensor::SCA_MouseSensor(SCA_MouseManager* eventmgr, m_mousemode = mousemode; m_triggermode = true; - UpdateHotkey(this); + UpdateHotkey(this, NULL); Init(); } @@ -74,7 +74,7 @@ SCA_MouseSensor::~SCA_MouseSensor() /* Nothing to be done here. */ } -int SCA_MouseSensor::UpdateHotkey(void *self) +int SCA_MouseSensor::UpdateHotkey(void *self, const PyAttributeDef*) { // gosh, this function is so damn stupid // its here because of a design mistake in the mouse sensor, it should only @@ -336,7 +336,7 @@ PyMethodDef SCA_MouseSensor::Methods[] = { }; PyAttributeDef SCA_MouseSensor::Attributes[] = { - KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",KX_MOUSESENSORMODE_NODEF,KX_MOUSESENSORMODE_MAX-1,SCA_MouseSensor,m_mousemode,UpdateHotkey), + KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",KX_MOUSESENSORMODE_NODEF,KX_MOUSESENSORMODE_MAX-1,true,SCA_MouseSensor,m_mousemode,UpdateHotkey), KX_PYATTRIBUTE_SHORT_ARRAY_RO("position",SCA_MouseSensor,m_x,2), { NULL } //Sentinel }; diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.h b/source/gameengine/GameLogic/SCA_MouseSensor.h index 58ee96c8856..82af2ce9c04 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.h +++ b/source/gameengine/GameLogic/SCA_MouseSensor.h @@ -87,7 +87,7 @@ class SCA_MouseSensor : public SCA_ISensor bool isValid(KX_MOUSESENSORMODE); - static int UpdateHotkey(void *self); + static int UpdateHotkey(void *self, const PyAttributeDef*); SCA_MouseSensor(class SCA_MouseManager* keybdmgr, int startx,int starty, diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index f8509fe380e..566d3b63487 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -254,36 +254,23 @@ PyMethodDef SCA_PropertyActuator::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_PropertyActuator::Attributes[] = { + KX_PYATTRIBUTE_STRING_RW_CHECK("property",0,100,false,SCA_PropertyActuator,m_propname,CheckProperty), + KX_PYATTRIBUTE_STRING_RW("value",0,100,false,SCA_PropertyActuator,m_exprtxt), + { NULL } //Sentinel +}; + PyObject* SCA_PropertyActuator::_getattr(const STR_String& attr) { - if (attr == "property") { - return PyString_FromString(m_propname); - } - if (attr == "value") { - return PyString_FromString(m_exprtxt); - } + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_IActuator); } int SCA_PropertyActuator::_setattr(const STR_String& attr, PyObject *value) { - if (PyString_Check(value)) { - char* sval = PyString_AsString(value); - if (attr == "property") { - CValue* prop = GetParent()->FindIdentifier(sval); - bool error = prop->IsError(); - prop->Release(); - if (!prop->IsError()) { - m_propname = sval; - return 0; - } else { - PyErr_SetString(PyExc_ValueError, "string does not correspond to a property"); - return 1; - } - } - if (attr == "value") { - m_exprtxt = sval; - return 0; - } - } + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; return SCA_IActuator::_setattr(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp index 19ee85207bb..a6f7a9cd82b 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp +++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp @@ -293,7 +293,7 @@ CValue* SCA_PropertySensor::FindIdentifier(const STR_String& identifiername) return GetParent()->FindIdentifier(identifiername); } -bool SCA_PropertySensor::validValueForProperty(char *val, STR_String &prop) +int SCA_PropertySensor::validValueForProperty(void *self, const PyAttributeDef*) { bool result = true; /* There is no type checking at this moment, unfortunately... */ @@ -344,51 +344,25 @@ PyMethodDef SCA_PropertySensor::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_PropertySensor::Attributes[] = { + KX_PYATTRIBUTE_INT_RW("type",KX_PROPSENSOR_NODEF,KX_PROPSENSOR_MAX-1,false,SCA_PropertySensor,m_checktype), + KX_PYATTRIBUTE_STRING_RW_CHECK("property",0,100,false,SCA_PropertySensor,m_checkpropname,CheckProperty), + KX_PYATTRIBUTE_STRING_RW_CHECK("value",0,100,false,SCA_PropertySensor,m_checkpropval,validValueForProperty), + { NULL } //Sentinel +}; + + PyObject* SCA_PropertySensor::_getattr(const STR_String& attr) { - if (attr == "type") { - return PyInt_FromLong(m_checktype); - } - if (attr == "property") { - return PyString_FromString(m_checkpropname); - } - if (attr == "value") { - return PyString_FromString(m_checkpropval); - } + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_ISensor); /* implicit return! */ } int SCA_PropertySensor::_setattr(const STR_String& attr, PyObject *value) { - if (PyInt_Check(value)) { - int ival = PyInt_AsLong(value); - if (attr == "type") { - if ((ival <= KX_PROPSENSOR_NODEF) || (ival >= KX_PROPSENSOR_MAX)) { - PyErr_SetString(PyExc_ValueError, "type out of range"); - return 1; - } - m_checktype = ival; - } - return 0; - } - if (PyString_Check(value)) { - char* sval = PyString_AsString(value); - if (attr == "property") { - CValue *prop = FindIdentifier(STR_String(sval)); - bool error = prop->IsError(); - prop->Release(); - if (error) { - PyErr_SetString(PyExc_ValueError, "string does not correspond to a property"); - return 1; - } - m_checkpropname = sval; - } else if (attr == "value") { - if (!validValueForProperty(sval, m_checkpropname)) { - PyErr_SetString(PyExc_ValueError, "string does not represent a suitable value for the property"); - return 1; - } - m_checkpropval = sval; - } - return 0; - } + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; return SCA_ISensor::_setattr(attr, value); } @@ -490,11 +464,12 @@ PyObject* SCA_PropertySensor::PySetValue(PyObject* self, PyObject* args, PyObjec if(!PyArg_ParseTuple(args, "s", &propValArg)) { return NULL; } - - if (validValueForProperty(propValArg, m_checkpropname)) { - m_checkpropval = propValArg; + STR_String oldval = m_checkpropval; + m_checkpropval = propValArg; + if (validValueForProperty(self, NULL)) { + m_checkpropval = oldval; + return NULL; } - Py_Return; } diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.h b/source/gameengine/GameLogic/SCA_PropertySensor.h index 81203c78f9d..e625e84a36f 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.h +++ b/source/gameengine/GameLogic/SCA_PropertySensor.h @@ -47,10 +47,6 @@ class SCA_PropertySensor : public SCA_ISensor bool m_recentresult; CExpression* m_range_expr; - /** - * Test whether this is a sensible value (type check) - */ - bool validValueForProperty(char *val, STR_String &prop); protected: public: @@ -104,7 +100,10 @@ public: KX_PYMETHOD_DOC(SCA_PropertySensor,GetValue); /* 6. setValue */ KX_PYMETHOD_DOC(SCA_PropertySensor,SetValue); - + /** + * Test whether this is a sensible value (type check) + */ + static int validValueForProperty(void* self, const PyAttributeDef*); }; #endif diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp index 8dd405c3d82..840b95d559a 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp +++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp @@ -361,57 +361,38 @@ PyMethodDef SCA_RandomActuator::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_RandomActuator::Attributes[] = { + KX_PYATTRIBUTE_FLOAT_RO("para1",SCA_RandomActuator,m_parameter1), + KX_PYATTRIBUTE_FLOAT_RO("para2",SCA_RandomActuator,m_parameter2), + KX_PYATTRIBUTE_ENUM_RO("distribution",SCA_RandomActuator,m_distribution), + KX_PYATTRIBUTE_STRING_RW_CHECK("property",0,100,false,SCA_RandomActuator,m_propname,CheckProperty), + { NULL } //Sentinel +}; + PyObject* SCA_RandomActuator::_getattr(const STR_String& attr) { + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; if (attr == "seed") { return PyInt_FromLong(m_base->GetSeed()); } - if (attr == "para1") { - return PyFloat_FromDouble(m_parameter1); - } - if (attr == "para2") { - return PyFloat_FromDouble(m_parameter2); - } - if (attr == "distribution") { - return PyInt_FromLong(m_distribution); - } - if (attr == "property") { - return PyString_FromString(m_propname); - } _getattr_up(SCA_IActuator); } int SCA_RandomActuator::_setattr(const STR_String& attr, PyObject *value) { - if (attr == "para1") { - PyErr_SetString(PyExc_AttributeError, "para1 is read only"); - } - if (attr == "para2") { - PyErr_SetString(PyExc_AttributeError, "para2 is read only"); - } - if (attr == "distribution") { - PyErr_SetString(PyExc_AttributeError, "distribution is read only"); - } - if (PyInt_Check(value)) { - int ival = PyInt_AsLong(value); - if (attr == "seed") { + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + if (attr == "seed") { + if (PyInt_Check(value)) { + int ival = PyInt_AsLong(value); m_base->SetSeed(ival); + return 0; + } else { + PyErr_SetString(PyExc_TypeError, "expected an integer"); + return 1; } - return 0; - } - if (PyString_Check(value)) { - char* sval = PyString_AsString(value); - if (attr == "property") { - CValue* prop = GetParent()->FindIdentifier(sval); - bool error = prop->IsError(); - prop->Release(); - if (!prop->IsError()) { - m_propname = sval; - return 0; - } else { - PyErr_SetString(PyExc_ValueError, "string does not correspond to a property"); - return 1; - } - } } return SCA_IActuator::_setattr(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.h b/source/gameengine/GameLogic/SCA_RandomActuator.h index 2fc14f9a0b7..de8faaf9c72 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.h +++ b/source/gameengine/GameLogic/SCA_RandomActuator.h @@ -136,7 +136,6 @@ class SCA_RandomActuator : public SCA_IActuator KX_PYMETHOD_DOC(SCA_RandomActuator,SetFloatNormal); /* 20. setFloatNegativeExponential, */ KX_PYMETHOD_DOC(SCA_RandomActuator,SetFloatNegativeExponential); - }; /* end of class KX_EditObjectActuator : public SCA_PropertyActuator */ #endif -- cgit v1.2.3 From 10702bf93f14441066ceba3204f932a5ba099c2e Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Fri, 2 Jan 2009 22:09:57 +0000 Subject: BGE API cleanup: more bricks converted to attributes. --- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 19 ++++++++++++++ source/gameengine/GameLogic/SCA_ILogicBrick.h | 1 + source/gameengine/GameLogic/SCA_RandomSensor.cpp | 32 ++++++++++++++++++++++++ source/gameengine/GameLogic/SCA_RandomSensor.h | 1 + 4 files changed, 53 insertions(+) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index 37658480c05..8286c0829a7 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -247,11 +247,18 @@ PyParentObject SCA_ILogicBrick::Parents[] = { PyMethodDef SCA_ILogicBrick::Methods[] = { {"getOwner", (PyCFunction) SCA_ILogicBrick::sPyGetOwner, METH_NOARGS}, + // --> Deprecated {"getExecutePriority", (PyCFunction) SCA_ILogicBrick::sPyGetExecutePriority, METH_NOARGS}, {"setExecutePriority", (PyCFunction) SCA_ILogicBrick::sPySetExecutePriority, METH_VARARGS}, + // <-- Deprecated {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_ILogicBrick::Attributes[] = { + KX_PYATTRIBUTE_INT_RW("executePriority",0,100000,false,SCA_ILogicBrick,m_Execute_Ueber_Priority), + {NULL} //Sentinel +}; + int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef) { if (attrdef->m_type != KX_PYATTRIBUTE_TYPE_STRING || attrdef->m_length != 1) { @@ -273,9 +280,19 @@ int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef) PyObject* SCA_ILogicBrick::_getattr(const STR_String& attr) { + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(CValue); } +int SCA_ILogicBrick::_setattr(const STR_String& attr, PyObject *value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return CValue::_setattr(attr, value); +} PyObject* SCA_ILogicBrick::PyGetOwner(PyObject* self) @@ -297,6 +314,7 @@ PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setExecutePriority()", "the executePriority property"); int priority=0; @@ -313,6 +331,7 @@ PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* self, PyObject* SCA_ILogicBrick::PyGetExecutePriority(PyObject* self) { + ShowDeprecationWarning("getExecutePriority()", "the executePriority property"); return PyInt_FromLong(m_Execute_Ueber_Priority); } diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h index 38ec80d4096..772bd65d577 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.h +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h @@ -79,6 +79,7 @@ public: virtual bool LessComparedTo(SCA_ILogicBrick* other); virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject *value); static class SCA_LogicManager* m_sCurrentLogicManager; diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp index 202fd6382e6..8fae0bbeaba 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp +++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp @@ -160,10 +160,39 @@ PyMethodDef SCA_RandomSensor::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_RandomSensor::Attributes[] = { + KX_PYATTRIBUTE_BOOL_RO("lastDraw",SCA_RandomSensor,m_lastdraw), + {NULL} //Sentinel +}; + PyObject* SCA_RandomSensor::_getattr(const STR_String& attr) { + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + if (attr == "seed") { + return PyInt_FromLong(m_basegenerator->GetSeed()); + } _getattr_up(SCA_ISensor); } +int SCA_RandomSensor::_setattr(const STR_String& attr, PyObject *value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + if (attr == "seed") { + if (PyInt_Check(value)) { + int ival = PyInt_AsLong(value); + m_basegenerator->SetSeed(ival); + return 0; + } else { + PyErr_SetString(PyExc_TypeError, "expected an integer"); + return 1; + } + } + return SCA_ISensor::_setattr(attr, value); +} + /* 1. setSeed */ const char SCA_RandomSensor::SetSeed_doc[] = "setSeed(seed)\n" @@ -172,6 +201,7 @@ const char SCA_RandomSensor::SetSeed_doc[] = "\tequal series. If the seed is 0, the generator will produce\n" "\tthe same value on every call.\n"; PyObject* SCA_RandomSensor::PySetSeed(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setSeed()", "the seed property"); long seedArg; if(!PyArg_ParseTuple(args, "i", &seedArg)) { return NULL; @@ -188,6 +218,7 @@ const char SCA_RandomSensor::GetSeed_doc[] = "\tReturns the initial seed of the generator. Equal seeds produce\n" "\tequal series.\n"; PyObject* SCA_RandomSensor::PyGetSeed(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getSeed()", "the seed property"); return PyInt_FromLong(m_basegenerator->GetSeed()); } @@ -196,6 +227,7 @@ const char SCA_RandomSensor::GetLastDraw_doc[] = "getLastDraw()\n" "\tReturn the last value that was drawn.\n"; PyObject* SCA_RandomSensor::PyGetLastDraw(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getLastDraw()", "the lastDraw property"); return PyInt_FromLong(m_lastdraw); } diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.h b/source/gameengine/GameLogic/SCA_RandomSensor.h index d29bfb6837a..009efc32aac 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.h +++ b/source/gameengine/GameLogic/SCA_RandomSensor.h @@ -61,6 +61,7 @@ public: /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject *value); /* 1. setSeed */ KX_PYMETHOD_DOC(SCA_RandomSensor,SetSeed); -- cgit v1.2.3 From 9ce30005debab6837d8f44443620c570391a0cb8 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Fri, 2 Jan 2009 22:15:05 +0000 Subject: BGE bug #18070 fixed: 2dFilter actuator is always pulsed. --- source/gameengine/GameLogic/SCA_2DFilterActuator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp index 9ec4ea00337..a70830193db 100644 --- a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp +++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp @@ -74,7 +74,8 @@ bool SCA_2DFilterActuator::Update() { m_rendertools->Update2DFilter(m_propNames, m_gameObj, m_type, m_int_arg, m_shaderText); } - return true; + // once the filter is in place, no need to update it again => disable the actuator + return false; } -- cgit v1.2.3 From 00c12e09066c551e3ae8ee6da3cb85fb3bcf90f8 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Tue, 13 Jan 2009 22:59:18 +0000 Subject: BGE patch: dynamically update the coumpound parent shape when parenting to a compound object. This patch modifies the way the setParent actuator and KX_GameObject::setParent() function works when parenting to a compound object: the collision shape of the object being parented is dynamically added to the coumpound shape. Similarly, unparenting an object from a compound object will cause the child collision shape to be dynamically removed from the parent shape provided that is was previously added with setParent. Note: * This also works if the object is parented to a child of a compound object: the collision shape is added to the compound shape of the top parent. * The collision shape is added with the transformation (position, scale and orientation) it had at the time of the parenting. * The child shape is rigidly attached to the compound shape, the transformation is not affected by any further change in position/scale/orientation of the child object. * While the child shape is added to the compound shape, the child object is removed from the dynamic world to avoid superposition of shapes (one for the object itself and one for the compound child shape). This means that collision sensors on the child object are disabled while the child object is parent to a compound object. * There is no difference when setParent is used on a non-compound object: the child object is automatically changed to a static ghost object to avoid bad interaction with the parent shape; collision sensors on the child object continue to be active while the object is parented. * The child shape dynamically added to a compound shape modifies the inertia of the compound object but not the mass. It participates to collision detection as any other "static" child shape. --- .../Ketsji/KX_BulletPhysicsController.cpp | 135 ++++++++++++++++++++- .../gameengine/Ketsji/KX_BulletPhysicsController.h | 5 +- .../gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp | 2 +- source/gameengine/Ketsji/KX_GameObject.cpp | 23 ++++ source/gameengine/Ketsji/KX_IPhysicsController.cpp | 3 +- source/gameengine/Ketsji/KX_IPhysicsController.h | 10 +- .../gameengine/Ketsji/KX_OdePhysicsController.cpp | 2 +- source/gameengine/Ketsji/KX_OdePhysicsController.h | 2 + .../gameengine/Ketsji/KX_SumoPhysicsController.h | 5 +- .../Physics/Bullet/CcdPhysicsController.cpp | 22 +++- .../Physics/Bullet/CcdPhysicsController.h | 44 ++++++- .../Physics/Bullet/CcdPhysicsEnvironment.cpp | 14 ++- .../Physics/Bullet/CcdPhysicsEnvironment.h | 2 + .../gameengine/Physics/common/PHY_DynamicTypes.h | 3 +- 14 files changed, 257 insertions(+), 15 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp index 3a20bbfbb11..a67f4a54b3f 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp @@ -17,10 +17,11 @@ #include "BulletSoftBody/btSoftBody.h" -KX_BulletPhysicsController::KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna) -: KX_IPhysicsController(dyna,(PHY_IPhysicsController*)this), +KX_BulletPhysicsController::KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna, bool compound) +: KX_IPhysicsController(dyna,compound,(PHY_IPhysicsController*)this), CcdPhysicsController(ci), -m_savedCollisionFlags(0) +m_savedCollisionFlags(0), +m_bulletChildShape(NULL) { } @@ -175,6 +176,133 @@ void KX_BulletPhysicsController::setRigidBody(bool rigid) { } +/* This function dynamically adds the collision shape of another controller to + the current controller shape provided it is a compound shape. + The idea is that dynamic parenting on a compound object will dynamically extend the shape +*/ +void KX_BulletPhysicsController::AddCompoundChild(KX_IPhysicsController* child) +{ + if (child == NULL || !IsCompound()) + return; + // other controller must be a bullet controller too + // verify that body and shape exist and match + KX_BulletPhysicsController* childCtrl = dynamic_cast(child); + btRigidBody* rootBody = GetRigidBody(); + btRigidBody* childBody = childCtrl->GetRigidBody(); + if (!rootBody || !childBody) + return; + const btCollisionShape* rootShape = rootBody->getCollisionShape(); + const btCollisionShape* childShape = childBody->getCollisionShape(); + if (!rootShape || + !childShape || + rootShape->getShapeType() != COMPOUND_SHAPE_PROXYTYPE || + childShape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE) + return; + btCompoundShape* compoundShape = (btCompoundShape*)rootShape; + // compute relative transformation between parent and child + btTransform rootTrans; + btTransform childTrans; + rootBody->getMotionState()->getWorldTransform(rootTrans); + childBody->getMotionState()->getWorldTransform(childTrans); + btVector3 rootScale = rootShape->getLocalScaling(); + rootScale[0] = 1.0/rootScale[0]; + rootScale[1] = 1.0/rootScale[1]; + rootScale[2] = 1.0/rootScale[2]; + // relative scale = child_scale/parent_scale + btVector3 relativeScale = childShape->getLocalScaling()*rootScale; + btMatrix3x3 rootRotInverse = rootTrans.getBasis().transpose(); + // relative pos = parent_rot^-1 * ((parent_pos-child_pos)/parent_scale) + btVector3 relativePos = rootRotInverse*((childTrans.getOrigin()-rootTrans.getOrigin())*rootScale); + // relative rot = parent_rot^-1 * child_rot + btMatrix3x3 relativeRot = rootRotInverse*childTrans.getBasis(); + // create a proxy shape info to store the transformation + CcdShapeConstructionInfo* proxyShapeInfo = new CcdShapeConstructionInfo(); + // store the transformation to this object shapeinfo + proxyShapeInfo->m_childTrans.setOrigin(relativePos); + proxyShapeInfo->m_childTrans.setBasis(relativeRot); + proxyShapeInfo->m_childScale.setValue(relativeScale[0], relativeScale[1], relativeScale[2]); + // we will need this to make sure that we remove the right proxy later when unparenting + proxyShapeInfo->m_userData = childCtrl; + proxyShapeInfo->SetProxy(childCtrl->GetShapeInfo()->AddRef()); + // add to parent compound shapeinfo + GetShapeInfo()->AddShape(proxyShapeInfo); + // create new bullet collision shape from the object shapeinfo and set scaling + btCollisionShape* newChildShape = proxyShapeInfo->CreateBulletShape(); + newChildShape->setLocalScaling(relativeScale); + // add bullet collision shape to parent compound collision shape + compoundShape->addChildShape(proxyShapeInfo->m_childTrans,newChildShape); + // remember we created this shape + childCtrl->m_bulletChildShape = newChildShape; + // recompute inertia of parent + if (!rootBody->isStaticOrKinematicObject()) + { + btVector3 localInertia; + float mass = 1.f/rootBody->getInvMass(); + compoundShape->calculateLocalInertia(mass,localInertia); + rootBody->setMassProps(mass,localInertia); + } + // must update the broadphase cache, + GetPhysicsEnvironment()->refreshCcdPhysicsController(this); + // remove the children + GetPhysicsEnvironment()->disableCcdPhysicsController(childCtrl); +} + +/* Reverse function of the above, it will remove a shape from a compound shape + provided that the former was added to the later using AddCompoundChild() +*/ +void KX_BulletPhysicsController::RemoveCompoundChild(KX_IPhysicsController* child) +{ + if (child == NULL || !IsCompound()) + return; + // other controller must be a bullet controller too + // verify that body and shape exist and match + KX_BulletPhysicsController* childCtrl = dynamic_cast(child); + btRigidBody* rootBody = GetRigidBody(); + btRigidBody* childBody = childCtrl->GetRigidBody(); + if (!rootBody || !childBody) + return; + const btCollisionShape* rootShape = rootBody->getCollisionShape(); + if (!rootShape || + rootShape->getShapeType() != COMPOUND_SHAPE_PROXYTYPE) + return; + btCompoundShape* compoundShape = (btCompoundShape*)rootShape; + // retrieve the shapeInfo + CcdShapeConstructionInfo* childShapeInfo = childCtrl->GetShapeInfo(); + CcdShapeConstructionInfo* rootShapeInfo = GetShapeInfo(); + // and verify that the child is part of the parent + int i = rootShapeInfo->FindChildShape(childShapeInfo, childCtrl); + if (i < 0) + return; + rootShapeInfo->RemoveChildShape(i); + if (childCtrl->m_bulletChildShape) + { + int numChildren = compoundShape->getNumChildShapes(); + for (i=0; igetChildShape(i) == childCtrl->m_bulletChildShape) + { + compoundShape->removeChildShapeByIndex(i); + compoundShape->recalculateLocalAabb(); + break; + } + } + delete childCtrl->m_bulletChildShape; + childCtrl->m_bulletChildShape = NULL; + } + // recompute inertia of parent + if (!rootBody->isStaticOrKinematicObject()) + { + btVector3 localInertia; + float mass = 1.f/rootBody->getInvMass(); + compoundShape->calculateLocalInertia(mass,localInertia); + rootBody->setMassProps(mass,localInertia); + } + // must update the broadphase cache, + GetPhysicsEnvironment()->refreshCcdPhysicsController(this); + // reactivate the children + GetPhysicsEnvironment()->enableCcdPhysicsController(childCtrl); +} + void KX_BulletPhysicsController::SuspendDynamics(bool ghost) { btRigidBody *body = GetRigidBody(); @@ -251,6 +379,7 @@ SG_Controller* KX_BulletPhysicsController::GetReplica(class SG_Node* destnode) physicsreplica->setParentCtrl(ccdParent); physicsreplica->PostProcessReplica(motionstate,parentctrl); physicsreplica->m_userdata = (PHY_IPhysicsController*)physicsreplica; + physicsreplica->m_bulletChildShape = NULL; return physicsreplica; } diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.h b/source/gameengine/Ketsji/KX_BulletPhysicsController.h index d5fca4ec6d3..a50af2699bf 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.h +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.h @@ -13,10 +13,11 @@ private: short int m_savedCollisionFilterGroup; short int m_savedCollisionFilterMask; MT_Scalar m_savedMass; + btCollisionShape* m_bulletChildShape; public: - KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna); + KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna, bool compound); virtual ~KX_BulletPhysicsController (); /////////////////////////////////// @@ -42,6 +43,8 @@ public: virtual MT_Scalar GetMass(); virtual MT_Vector3 getReactionForce(); virtual void setRigidBody(bool rigid); + virtual void AddCompoundChild(KX_IPhysicsController* child); + virtual void RemoveCompoundChild(KX_IPhysicsController* child); virtual void resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ); diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 0e7a6d92ec1..46e46b014b5 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -1084,7 +1084,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, ci.m_bSoft = objprop->m_softbody; MT_Vector3 scaling = gameobj->NodeGetWorldScaling(); ci.m_scaling.setValue(scaling[0], scaling[1], scaling[2]); - KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,isbulletdyna); + KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,isbulletdyna,objprop->m_hasCompoundChildren); // shapeInfo is reference counted, decrement now as we don't use it anymore if (shapeInfo) shapeInfo->Release(); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index f2a554c6b2a..706b80a1fab 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -252,6 +252,20 @@ void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj) if (rootlist->RemoveValue(this)) // the object was in parent list, decrement ref count as it's now removed Release(); + // if the new parent is a compound object, add this object shape to the compound shape. + // step 0: verify this object has physical controller + if (m_pPhysicsController1) + { + // step 1: find the top parent (not necessarily obj) + KX_GameObject* rootobj = (KX_GameObject*)obj->GetSGNode()->GetRootSGParent()->GetSGClientObject(); + // step 2: verify it has a physical controller and compound shape + if (rootobj != NULL && + rootobj->m_pPhysicsController1 != NULL && + rootobj->m_pPhysicsController1->IsCompound()) + { + rootobj->m_pPhysicsController1->AddCompoundChild(m_pPhysicsController1); + } + } } } @@ -260,6 +274,8 @@ void KX_GameObject::RemoveParent(KX_Scene *scene) // check on valid node in case a python controller holds a reference to a deleted object if (GetSGNode() && GetSGNode()->GetSGParent()) { + // get the root object to remove us from compound object if needed + KX_GameObject* rootobj = (KX_GameObject*)GetSGNode()->GetRootSGParent()->GetSGClientObject(); // Set us to the right spot GetSGNode()->SetLocalScale(GetSGNode()->GetWorldScaling()); GetSGNode()->SetLocalOrientation(GetSGNode()->GetWorldOrientation()); @@ -275,6 +291,13 @@ void KX_GameObject::RemoveParent(KX_Scene *scene) rootlist->Add(AddRef()); if (m_pPhysicsController1) { + // in case this controller was added as a child shape to the parent + if (rootobj != NULL && + rootobj->m_pPhysicsController1 != NULL && + rootobj->m_pPhysicsController1->IsCompound()) + { + rootobj->m_pPhysicsController1->RemoveCompoundChild(m_pPhysicsController1); + } m_pPhysicsController1->RestoreDynamics(); } } diff --git a/source/gameengine/Ketsji/KX_IPhysicsController.cpp b/source/gameengine/Ketsji/KX_IPhysicsController.cpp index 5cd66efd965..a38222c5f7e 100644 --- a/source/gameengine/Ketsji/KX_IPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_IPhysicsController.cpp @@ -35,9 +35,10 @@ #include "PHY_DynamicTypes.h" -KX_IPhysicsController::KX_IPhysicsController(bool dyna,void* userdata) +KX_IPhysicsController::KX_IPhysicsController(bool dyna, bool compound, void* userdata) : m_bDyna(dyna), + m_bCompound(compound), m_suspendDynamics(false), m_userdata(userdata) { diff --git a/source/gameengine/Ketsji/KX_IPhysicsController.h b/source/gameengine/Ketsji/KX_IPhysicsController.h index 4ea283e9f98..fed71735bec 100644 --- a/source/gameengine/Ketsji/KX_IPhysicsController.h +++ b/source/gameengine/Ketsji/KX_IPhysicsController.h @@ -32,6 +32,7 @@ #include "SG_Controller.h" #include "MT_Vector3.h" #include "MT_Point3.h" +#include "MT_Transform.h" #include "MT_Matrix3x3.h" struct KX_ClientObjectInfo; @@ -48,10 +49,11 @@ class KX_IPhysicsController : public SG_Controller { protected: bool m_bDyna; + bool m_bCompound; bool m_suspendDynamics; void* m_userdata; public: - KX_IPhysicsController(bool dyna,void* userdata); + KX_IPhysicsController(bool dyna,bool compound, void* userdata); virtual ~KX_IPhysicsController(); @@ -78,6 +80,8 @@ public: virtual MT_Scalar GetMass()=0; virtual MT_Vector3 getReactionForce()=0; virtual void setRigidBody(bool rigid)=0; + virtual void AddCompoundChild(KX_IPhysicsController* child) = 0; + virtual void RemoveCompoundChild(KX_IPhysicsController* child) = 0; virtual void SuspendDynamics(bool ghost=false)=0; virtual void RestoreDynamics()=0; @@ -92,6 +96,10 @@ public: return m_bDyna; } + bool IsCompound(void) { + return m_bCompound; + } + virtual MT_Scalar GetRadius()=0; virtual void SetSumoTransform(bool nondynaonly)=0; // todo: remove next line ! diff --git a/source/gameengine/Ketsji/KX_OdePhysicsController.cpp b/source/gameengine/Ketsji/KX_OdePhysicsController.cpp index 6a701a5f25b..dc6990267d4 100644 --- a/source/gameengine/Ketsji/KX_OdePhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_OdePhysicsController.cpp @@ -50,7 +50,7 @@ KX_OdePhysicsController::KX_OdePhysicsController( float extends[3], float radius ) -: KX_IPhysicsController(dyna,(PHY_IPhysicsController*)this), +: KX_IPhysicsController(dyna,false,(PHY_IPhysicsController*)this), ODEPhysicsController( dyna,fullRigidBody,phantom,motionstate, space,world,mass,friction,restitution, diff --git a/source/gameengine/Ketsji/KX_OdePhysicsController.h b/source/gameengine/Ketsji/KX_OdePhysicsController.h index 53050f6ce3e..e3b5336c0b5 100644 --- a/source/gameengine/Ketsji/KX_OdePhysicsController.h +++ b/source/gameengine/Ketsji/KX_OdePhysicsController.h @@ -73,6 +73,8 @@ public: virtual MT_Scalar GetMass(); virtual MT_Vector3 getReactionForce(); virtual void setRigidBody(bool rigid); + virtual void AddCompoundChild(KX_IPhysicsController* child) { } + virtual void RemoveCompoundChild(KX_IPhysicsController* child) { } virtual void SuspendDynamics(bool); virtual void RestoreDynamics(); diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.h b/source/gameengine/Ketsji/KX_SumoPhysicsController.h index abe48d99043..a684b637894 100644 --- a/source/gameengine/Ketsji/KX_SumoPhysicsController.h +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.h @@ -53,7 +53,7 @@ public: class SM_Object* sumoObj, class PHY_IMotionState* motionstate ,bool dyna) - : KX_IPhysicsController(dyna,NULL) , + : KX_IPhysicsController(dyna,false,NULL) , SumoPhysicsController(sumoScene,/*solidscene,*/sumoObj,motionstate,dyna) { }; @@ -78,6 +78,9 @@ public: void SuspendDynamics(bool); void RestoreDynamics(); + virtual void AddCompoundChild(KX_IPhysicsController* child) { } + virtual void RemoveCompoundChild(KX_IPhysicsController* child) { } + virtual void getOrientation(MT_Quaternion& orn); virtual void setOrientation(const MT_Matrix3x3& orn); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index c9c30c1b450..fafce5cf5cc 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -1276,7 +1276,7 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo // assume no shape information // no support for dynamic change of shape yet - assert(m_meshObject == NULL); + assert(IsUnused()); m_shapeType = PHY_SHAPE_NONE; m_vertexArray.clear(); m_polygonIndexArray.clear(); @@ -1398,6 +1398,17 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo return true; } +bool CcdShapeConstructionInfo::SetProxy(CcdShapeConstructionInfo* shapeInfo) +{ + if (shapeInfo == NULL) + return false; + // no support for dynamic change + assert(IsUnused()); + m_shapeType = PHY_SHAPE_PROXY; + m_shapeProxy = shapeInfo; + return true; +} + btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape() { btCollisionShape* collisionShape = 0; @@ -1406,9 +1417,12 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape() btCompoundShape* compoundShape = 0; CcdShapeConstructionInfo* nextShapeInfo; + if (m_shapeType == PHY_SHAPE_PROXY && m_shapeProxy != NULL) + return m_shapeProxy->CreateBulletShape(); + switch (m_shapeType) { - case PHY_SHAPE_NONE: + default: break; case PHY_SHAPE_BOX: @@ -1522,6 +1536,10 @@ CcdShapeConstructionInfo::~CcdShapeConstructionInfo() m_meshShapeMap.erase(mit); } } + if (m_shapeType == PHY_SHAPE_PROXY && m_shapeProxy != NULL) + { + m_shapeProxy->Release(); + } } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index 054ec91122a..c771aa2624b 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -67,11 +67,13 @@ public: m_height(1.0), m_halfExtend(0.f,0.f,0.f), m_childScale(1.0f,1.0f,1.0f), + m_userData(NULL), m_refCount(1), m_meshObject(NULL), m_unscaledShape(NULL), m_useGimpact(false), - m_weldingThreshold(0.f) + m_weldingThreshold(0.f), + m_shapeProxy(NULL) { m_childTrans.setIdentity(); } @@ -92,6 +94,11 @@ public: return 0; } + bool IsUnused(void) + { + return (m_meshObject==NULL && m_shapeArray.size() == 0 && m_shapeProxy == NULL); + } + void AddShape(CcdShapeConstructionInfo* shapeInfo); btTriangleMeshShape* GetMeshShape(void) @@ -105,6 +112,32 @@ public: return m_shapeArray.at(i); } + int FindChildShape(CcdShapeConstructionInfo* shapeInfo, void* userData) + { + if (shapeInfo == NULL) + return -1; + for (int i=0; im_userData) && + (childInfo == shapeInfo || + (childInfo->m_shapeType == PHY_SHAPE_PROXY && + childInfo->m_shapeProxy == shapeInfo))) + return i; + } + return -1; + } + + bool RemoveChildShape(int i) + { + if (i < 0 || i >= m_shapeArray.size()) + return false; + m_shapeArray.at(i)->Release(); + if (i < m_shapeArray.size()-1) + m_shapeArray[i] = m_shapeArray.back(); + m_shapeArray.pop_back(); + return true; + } bool SetMesh(RAS_MeshObject* mesh, bool polytope,bool useGimpact); RAS_MeshObject* GetMesh(void) @@ -112,6 +145,12 @@ public: return m_meshObject; } + bool SetProxy(CcdShapeConstructionInfo* shapeInfo); + CcdShapeConstructionInfo* GetProxy(void) + { + return m_shapeProxy; + } + btCollisionShape* CreateBulletShape(); // member variables @@ -121,6 +160,7 @@ public: btVector3 m_halfExtend; btTransform m_childTrans; btVector3 m_childScale; + void* m_userData; std::vector m_vertexArray; // Contains both vertex array for polytope shape and // triangle array for concave mesh shape. // In this case a triangle is made of 3 consecutive points @@ -146,7 +186,7 @@ protected: std::vector m_shapeArray; // for compound shapes bool m_useGimpact; //use gimpact for concave dynamic/moving collision detection float m_weldingThreshold; //welding closeby vertices together can improve softbody stability etc. - + CcdShapeConstructionInfo* m_shapeProxy; // only used for PHY_SHAPE_PROXY, pointer to actual shape info }; struct CcdConstructionInfo diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 4fe35630784..d2274c1e8d6 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -536,12 +536,24 @@ void CcdPhysicsEnvironment::disableCcdPhysicsController(CcdPhysicsController* ct { } else { - m_dynamicsWorld->removeCollisionObject(body); + m_dynamicsWorld->removeCollisionObject(ctrl->GetCollisionObject()); } } } } +void CcdPhysicsEnvironment::refreshCcdPhysicsController(CcdPhysicsController* ctrl) +{ + btCollisionObject* obj = ctrl->GetCollisionObject(); + if (obj) + { + btBroadphaseProxy* proxy = obj->getBroadphaseHandle(); + if (proxy) + { + m_dynamicsWorld->getPairCache()->cleanProxyFromPairs(proxy,m_dynamicsWorld->getDispatcher()); + } + } +} void CcdPhysicsEnvironment::beginFrame() { diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h index 74384dd8cf2..4b28d3fddfc 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h @@ -196,6 +196,8 @@ protected: void enableCcdPhysicsController(CcdPhysicsController* ctrl); + void refreshCcdPhysicsController(CcdPhysicsController* ctrl); + btBroadphaseInterface* getBroadphase(); btDispatcher* getDispatcher(); diff --git a/source/gameengine/Physics/common/PHY_DynamicTypes.h b/source/gameengine/Physics/common/PHY_DynamicTypes.h index 3b3e42c38d2..09126264dcc 100644 --- a/source/gameengine/Physics/common/PHY_DynamicTypes.h +++ b/source/gameengine/Physics/common/PHY_DynamicTypes.h @@ -95,7 +95,8 @@ typedef enum PHY_ShapeType { PHY_SHAPE_CONE, PHY_SHAPE_MESH, PHY_SHAPE_POLYTOPE, - PHY_SHAPE_COMPOUND + PHY_SHAPE_COMPOUND, + PHY_SHAPE_PROXY } PHY_ShapeType; -- cgit v1.2.3 From 509ca83ef1d10fab4903981714cfab3719280e04 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 14 Jan 2009 22:33:39 +0000 Subject: BGE patch 18065: gameobj mass writeable + setmass actuator. This patch allows to change the mass of a dynamic or rigid body object during the game. Two methods are available: in a Python script by setting the mass attribute of the game object; by logic brick with the Edit Object->Dynamics->Set Mass actuator. The mass can only be set on dynamic objects and must be a positive floating point value. --- source/gameengine/Converter/KX_ConvertActuators.cpp | 3 ++- .../Ketsji/KX_BulletPhysicsController.cpp | 21 ++++++++++++++++++++- .../gameengine/Ketsji/KX_BulletPhysicsController.h | 1 + source/gameengine/Ketsji/KX_GameObject.cpp | 11 ++++++----- source/gameengine/Ketsji/KX_IPhysicsController.h | 1 + source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp | 7 ++++++- source/gameengine/Ketsji/KX_SCA_DynamicActuator.h | 2 ++ .../gameengine/Ketsji/KX_SumoPhysicsController.cpp | 4 ++++ source/gameengine/Ketsji/KX_SumoPhysicsController.h | 1 + .../Physics/Bullet/CcdPhysicsController.cpp | 4 ++-- 10 files changed, 45 insertions(+), 10 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index 4f152acc918..3a6122e6608 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -661,7 +661,8 @@ void BL_ConvertActuators(char* maggiename, { KX_SCA_DynamicActuator* tmpdynact = new KX_SCA_DynamicActuator(gameobj, - editobact->dyn_operation + editobact->dyn_operation, + editobact->mass ); baseact = tmpdynact; } diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp index a67f4a54b3f..534c48661b7 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp @@ -303,6 +303,25 @@ void KX_BulletPhysicsController::RemoveCompoundChild(KX_IPhysicsController* c GetPhysicsEnvironment()->enableCcdPhysicsController(childCtrl); } +void KX_BulletPhysicsController::SetMass(MT_Scalar newmass) +{ + btRigidBody *body = GetRigidBody(); + if (body && body->getActivationState() != DISABLE_SIMULATION && + newmass>MT_EPSILON && GetMass()>MT_EPSILON) + { + btVector3 grav = body->getGravity(); + btVector3 accel = grav / GetMass(); + + btBroadphaseProxy* handle = body->getBroadphaseHandle(); + GetPhysicsEnvironment()->updateCcdPhysicsController(this, + newmass, + body->getCollisionFlags(), + handle->m_collisionFilterGroup, + handle->m_collisionFilterMask); + body->setGravity(accel); + } +} + void KX_BulletPhysicsController::SuspendDynamics(bool ghost) { btRigidBody *body = GetRigidBody(); @@ -333,7 +352,7 @@ void KX_BulletPhysicsController::RestoreDynamics() m_savedCollisionFlags, m_savedCollisionFilterGroup, m_savedCollisionFilterMask); - GetRigidBody()->forceActivationState(m_savedActivationState); + body->forceActivationState(m_savedActivationState); } } diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.h b/source/gameengine/Ketsji/KX_BulletPhysicsController.h index a50af2699bf..44fbde7054e 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.h +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.h @@ -41,6 +41,7 @@ public: virtual void setPosition(const MT_Point3& pos); virtual void setScaling(const MT_Vector3& scaling); virtual MT_Scalar GetMass(); + virtual void SetMass(MT_Scalar newmass); virtual MT_Vector3 getReactionForce(); virtual void setRigidBody(bool rigid); virtual void AddCompoundChild(KX_IPhysicsController* child); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 706b80a1fab..42316c6c873 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1129,7 +1129,7 @@ PyObject* KX_GameObject::_getattr(const STR_String& attr) if (m_pPhysicsController1) { if (attr == "mass") - return PyFloat_FromDouble(GetPhysicsController()->GetMass()); + return PyFloat_FromDouble(m_pPhysicsController1->GetMass()); } if (attr == "parent") @@ -1171,10 +1171,6 @@ PyObject* KX_GameObject::_getattr(const STR_String& attr) int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr method { - if (attr == "mass") { - PyErr_SetString(PyExc_AttributeError, "attribute \"mass\" is read only"); - return 1; - } if (attr == "parent") { PyErr_SetString(PyExc_AttributeError, "attribute \"mass\" is read only\nUse setParent()"); @@ -1203,6 +1199,11 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr return 0; } } + if (attr == "mass") { + if (m_pPhysicsController1) + m_pPhysicsController1->SetMass(val); + return 0; + } } if (PySequence_Check(value)) diff --git a/source/gameengine/Ketsji/KX_IPhysicsController.h b/source/gameengine/Ketsji/KX_IPhysicsController.h index fed71735bec..13501f1fbbd 100644 --- a/source/gameengine/Ketsji/KX_IPhysicsController.h +++ b/source/gameengine/Ketsji/KX_IPhysicsController.h @@ -78,6 +78,7 @@ public: virtual void setPosition(const MT_Point3& pos)=0; virtual void setScaling(const MT_Vector3& scaling)=0; virtual MT_Scalar GetMass()=0; + virtual void SetMass(MT_Scalar newmass)=0; virtual MT_Vector3 getReactionForce()=0; virtual void setRigidBody(bool rigid)=0; virtual void AddCompoundChild(KX_IPhysicsController* child) = 0; diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp index d44ab477749..176ccf1a84a 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp @@ -133,10 +133,12 @@ KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, getOperation, KX_SCA_DynamicActuator::KX_SCA_DynamicActuator(SCA_IObject *gameobj, short dyn_operation, + float setmass, PyTypeObject* T) : SCA_IActuator(gameobj, T), - m_dyn_operation(dyn_operation) + m_dyn_operation(dyn_operation), + m_setmass(setmass) { } /* End of constructor */ @@ -179,6 +181,9 @@ bool KX_SCA_DynamicActuator::Update() case 3: controller->setRigidBody(false); break; + case 4: + controller->SetMass(m_setmass); + break; } return false; diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h index b47c3a511d9..de2fab68d15 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h @@ -45,10 +45,12 @@ class KX_SCA_DynamicActuator : public SCA_IActuator // dynamics operation to apply to the game object short m_dyn_operation; + float m_setmass; public: KX_SCA_DynamicActuator( SCA_IObject* gameobj, short dyn_operation, + float setmass, PyTypeObject* T=&Type ); diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp index c842ca1ee14..7631ee05b0b 100644 --- a/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp @@ -205,6 +205,10 @@ MT_Scalar KX_SumoPhysicsController::GetMass() return SumoPhysicsController::getMass(); } +void KX_SumoPhysicsController::SetMass(MT_Scalar newmass) +{ +} + MT_Scalar KX_SumoPhysicsController::GetRadius() { return SumoPhysicsController::GetRadius(); diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.h b/source/gameengine/Ketsji/KX_SumoPhysicsController.h index a684b637894..46c8ba6df45 100644 --- a/source/gameengine/Ketsji/KX_SumoPhysicsController.h +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.h @@ -87,6 +87,7 @@ public: virtual void setPosition(const MT_Point3& pos); virtual void setScaling(const MT_Vector3& scaling); virtual MT_Scalar GetMass(); + virtual void SetMass(MT_Scalar newmass); virtual MT_Scalar GetRadius(); virtual MT_Vector3 getReactionForce(); virtual void setRigidBody(bool rigid); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index fafce5cf5cc..d09ad58fe3b 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -74,10 +74,10 @@ CcdPhysicsController::CcdPhysicsController (const CcdConstructionInfo& ci) ///??? -#ifdef WIN32 +/*#ifdef WIN32 if (GetRigidBody() && !GetRigidBody()->isStaticObject()) GetRigidBody()->setLinearVelocity(startVel); -#endif +#endif*/ } -- cgit v1.2.3 From 8bd7aa0a01ee53172bb4fd1bd2de1b318c4ea80c Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 21 Jan 2009 13:54:53 +0000 Subject: BGE API cleanup: action actuator. --- source/gameengine/Converter/BL_ActionActuator.cpp | 339 ++++++++++++++-------- source/gameengine/Converter/BL_ActionActuator.h | 48 ++- source/gameengine/PyDoc/BL_ActionActuator.py | 52 +++- 3 files changed, 308 insertions(+), 131 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 4d748948c27..c05f763cacb 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -52,6 +52,8 @@ #include "FloatValue.h" #include "PyObjectPlus.h" +#include "blendef.h" + #ifdef HAVE_CONFIG_H #include #endif @@ -418,67 +420,6 @@ bool BL_ActionActuator::Update(double curtime, bool frame) /* Python functions */ /* ------------------------------------------------------------------------- */ -/* Integration hooks ------------------------------------------------------- */ - -PyTypeObject BL_ActionActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) - 0, - "BL_ActionActuator", - sizeof(BL_ActionActuator), - 0, - PyDestructor, - 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, - 0, - 0, - 0 -}; - -PyParentObject BL_ActionActuator::Parents[] = { - &BL_ActionActuator::Type, - &SCA_IActuator::Type, - &SCA_ILogicBrick::Type, - &CValue::Type, - NULL -}; - -PyMethodDef BL_ActionActuator::Methods[] = { - {"setAction", (PyCFunction) BL_ActionActuator::sPySetAction, METH_VARARGS, (PY_METHODCHAR)SetAction_doc}, - {"setStart", (PyCFunction) BL_ActionActuator::sPySetStart, METH_VARARGS, (PY_METHODCHAR)SetStart_doc}, - {"setEnd", (PyCFunction) BL_ActionActuator::sPySetEnd, METH_VARARGS, (PY_METHODCHAR)SetEnd_doc}, - {"setBlendin", (PyCFunction) BL_ActionActuator::sPySetBlendin, METH_VARARGS, (PY_METHODCHAR)SetBlendin_doc}, - {"setPriority", (PyCFunction) BL_ActionActuator::sPySetPriority, METH_VARARGS, (PY_METHODCHAR)SetPriority_doc}, - {"setFrame", (PyCFunction) BL_ActionActuator::sPySetFrame, METH_VARARGS, (PY_METHODCHAR)SetFrame_doc}, - {"setProperty", (PyCFunction) BL_ActionActuator::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc}, - {"setFrameProperty", (PyCFunction) BL_ActionActuator::sPySetFrameProperty, METH_VARARGS, (PY_METHODCHAR)SetFrameProperty_doc}, - {"setBlendtime", (PyCFunction) BL_ActionActuator::sPySetBlendtime, METH_VARARGS, (PY_METHODCHAR)SetBlendtime_doc}, - - {"getAction", (PyCFunction) BL_ActionActuator::sPyGetAction, METH_VARARGS, (PY_METHODCHAR)GetAction_doc}, - {"getStart", (PyCFunction) BL_ActionActuator::sPyGetStart, METH_VARARGS, (PY_METHODCHAR)GetStart_doc}, - {"getEnd", (PyCFunction) BL_ActionActuator::sPyGetEnd, METH_VARARGS, (PY_METHODCHAR)GetEnd_doc}, - {"getBlendin", (PyCFunction) BL_ActionActuator::sPyGetBlendin, METH_VARARGS, (PY_METHODCHAR)GetBlendin_doc}, - {"getPriority", (PyCFunction) BL_ActionActuator::sPyGetPriority, METH_VARARGS, (PY_METHODCHAR)GetPriority_doc}, - {"getFrame", (PyCFunction) BL_ActionActuator::sPyGetFrame, METH_VARARGS, (PY_METHODCHAR)GetFrame_doc}, - {"getProperty", (PyCFunction) BL_ActionActuator::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc}, - {"getFrameProperty", (PyCFunction) BL_ActionActuator::sPyGetFrameProperty, METH_VARARGS, (PY_METHODCHAR)GetFrameProperty_doc}, - {"setChannel", (PyCFunction) BL_ActionActuator::sPySetChannel, METH_VARARGS, (PY_METHODCHAR)SetChannel_doc}, -// {"getChannel", (PyCFunction) BL_ActionActuator::sPyGetChannel, METH_VARARGS}, - {"getType", (PyCFunction) BL_ActionActuator::sPyGetType, METH_VARARGS, (PY_METHODCHAR)GetType_doc}, - {"setType", (PyCFunction) BL_ActionActuator::sPySetType, METH_VARARGS, (PY_METHODCHAR)SetType_doc}, - {"getContinue", (PyCFunction) BL_ActionActuator::sPyGetContinue, METH_NOARGS, 0}, - {"setContinue", (PyCFunction) BL_ActionActuator::sPySetContinue, METH_O, 0}, - {NULL,NULL} //Sentinel -}; - -PyObject* BL_ActionActuator::_getattr(const STR_String& attr) { - _getattr_up(SCA_IActuator); -} - /* setStart */ const char BL_ActionActuator::GetAction_doc[] = "getAction()\n" @@ -487,6 +428,8 @@ const char BL_ActionActuator::GetAction_doc[] = PyObject* BL_ActionActuator::PyGetAction(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getAction()", "the action property"); + if (m_action){ return PyString_FromString(m_action->id.name+2); } @@ -501,6 +444,8 @@ const char BL_ActionActuator::GetProperty_doc[] = PyObject* BL_ActionActuator::PyGetProperty(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getProperty()", "the property property"); + PyObject *result; result = Py_BuildValue("s", (const char *)m_propname); @@ -516,6 +461,8 @@ const char BL_ActionActuator::GetFrameProperty_doc[] = PyObject* BL_ActionActuator::PyGetFrameProperty(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getFrameProperty()", "the frameProperty property"); + PyObject *result; result = Py_BuildValue("s", (const char *)m_framepropname); @@ -531,6 +478,8 @@ const char BL_ActionActuator::GetFrame_doc[] = PyObject* BL_ActionActuator::PyGetFrame(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getFrame()", "the frame property"); + PyObject *result; result = Py_BuildValue("f", m_localtime); @@ -546,6 +495,8 @@ const char BL_ActionActuator::GetEnd_doc[] = PyObject* BL_ActionActuator::PyGetEnd(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getEnd()", "the end property"); + PyObject *result; result = Py_BuildValue("f", m_endframe); @@ -561,6 +512,8 @@ const char BL_ActionActuator::GetStart_doc[] = PyObject* BL_ActionActuator::PyGetStart(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getStart()", "the start property"); + PyObject *result; result = Py_BuildValue("f", m_startframe); @@ -577,6 +530,8 @@ const char BL_ActionActuator::GetBlendin_doc[] = PyObject* BL_ActionActuator::PyGetBlendin(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getBlendin()", "the blendin property"); + PyObject *result; result = Py_BuildValue("f", m_blendin); @@ -593,6 +548,8 @@ const char BL_ActionActuator::GetPriority_doc[] = PyObject* BL_ActionActuator::PyGetPriority(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getPriority()", "the priority property"); + PyObject *result; result = Py_BuildValue("i", m_priority); @@ -613,6 +570,8 @@ const char BL_ActionActuator::SetAction_doc[] = PyObject* BL_ActionActuator::PySetAction(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setAction()", "the action property"); + char *string; int reset = 1; @@ -647,6 +606,8 @@ const char BL_ActionActuator::SetStart_doc[] = PyObject* BL_ActionActuator::PySetStart(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setStart()", "the start property"); + float start; if (PyArg_ParseTuple(args,"f",&start)) @@ -668,6 +629,8 @@ const char BL_ActionActuator::SetEnd_doc[] = PyObject* BL_ActionActuator::PySetEnd(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setEnd()", "the end property"); + float end; if (PyArg_ParseTuple(args,"f",&end)) @@ -690,6 +653,8 @@ const char BL_ActionActuator::SetBlendin_doc[] = PyObject* BL_ActionActuator::PySetBlendin(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setBlendin()", "the blendin property"); + float blendin; if (PyArg_ParseTuple(args,"f",&blendin)) @@ -713,6 +678,8 @@ const char BL_ActionActuator::SetBlendtime_doc[] = PyObject* BL_ActionActuator::PySetBlendtime(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setBlendtime()", "the blendtime property"); + float blendframe; if (PyArg_ParseTuple(args,"f",&blendframe)) @@ -740,6 +707,8 @@ const char BL_ActionActuator::SetPriority_doc[] = PyObject* BL_ActionActuator::PySetPriority(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setPriority()", "the priority property"); + int priority; if (PyArg_ParseTuple(args,"i",&priority)) @@ -761,6 +730,8 @@ const char BL_ActionActuator::SetFrame_doc[] = PyObject* BL_ActionActuator::PySetFrame(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setFrame()", "the frame property"); + float frame; if (PyArg_ParseTuple(args,"f",&frame)) @@ -787,6 +758,8 @@ const char BL_ActionActuator::SetProperty_doc[] = PyObject* BL_ActionActuator::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setProperty()", "the property property"); + char *string; if (PyArg_ParseTuple(args,"s",&string)) @@ -808,6 +781,8 @@ const char BL_ActionActuator::SetFrameProperty_doc[] = PyObject* BL_ActionActuator::PySetFrameProperty(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setFrameProperty()", "the frameProperty property"); + char *string; if (PyArg_ParseTuple(args,"s",&string)) @@ -839,16 +814,80 @@ PyObject* BL_ActionActuator::PyGetChannel(PyObject* self, } */ -/* setChannel */ -const char BL_ActionActuator::SetChannel_doc[] = +/* getType */ +const char BL_ActionActuator::GetType_doc[] = +"getType()\n" +"\tReturns the operation mode of the actuator.\n"; +PyObject* BL_ActionActuator::PyGetType(PyObject* self, + PyObject* args, + PyObject* kwds) { + ShowDeprecationWarning("getType()", "the type property"); + + return Py_BuildValue("h", m_playtype); +} + +/* setType */ +const char BL_ActionActuator::SetType_doc[] = +"setType(mode)\n" +"\t - mode: Play (0), Flipper (2), LoopStop (3), LoopEnd (4) or Property (6)\n" +"\tSet the operation mode of the actuator.\n"; +PyObject* BL_ActionActuator::PySetType(PyObject* self, + PyObject* args, + PyObject* kwds) { + ShowDeprecationWarning("setType()", "the type property"); + + short typeArg; + + if (!PyArg_ParseTuple(args, "h", &typeArg)) { + return NULL; + } + + switch (typeArg) { + case KX_ACT_ACTION_PLAY: + case KX_ACT_ACTION_FLIPPER: + case KX_ACT_ACTION_LOOPSTOP: + case KX_ACT_ACTION_LOOPEND: + case KX_ACT_ACTION_PROPERTY: + m_playtype = typeArg; + break; + default: + printf("Invalid type for action actuator: %d\n", typeArg); /* error */ + } + Py_RETURN_NONE; +} + +PyObject* BL_ActionActuator::PyGetContinue(PyObject* self) { + ShowDeprecationWarning("getContinue()", "the continue property"); + + return PyInt_FromLong((long)(m_end_reset==0)); +} + +PyObject* BL_ActionActuator::PySetContinue(PyObject* self, PyObject* value) { + ShowDeprecationWarning("setContinue()", "the continue property"); + + int param = PyObject_IsTrue( value ); + + if( param == -1 ) { + PyErr_SetString( PyExc_TypeError, "expected True/False or 0/1" ); + return NULL; + } + + if (param) { + m_end_reset = 0; + } else { + m_end_reset = 1; + } + Py_RETURN_NONE; +} + +//<-----Deprecated + +/* setChannel */ +KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel, "setChannel(channel, matrix)\n" "\t - channel : A string specifying the name of the bone channel.\n" "\t - matrix : A 4x4 matrix specifying the overriding transformation\n" -"\t as an offset from the bone's rest position.\n"; - -PyObject* BL_ActionActuator::PySetChannel(PyObject* self, - PyObject* args, - PyObject* kwds) +"\t as an offset from the bone's rest position.\n") { float matrix[4][4]; char *string; @@ -923,61 +962,123 @@ PyObject* BL_ActionActuator::PySetChannel(PyObject* self, Py_RETURN_NONE; } -/* getType */ -const char BL_ActionActuator::GetType_doc[] = -"getType()\n" -"\tReturns the operation mode of the actuator.\n"; -PyObject* BL_ActionActuator::PyGetType(PyObject* self, - PyObject* args, - PyObject* kwds) { - return Py_BuildValue("h", m_playtype); -} +/* ------------------------------------------------------------------------- */ +/* Python Integration Hooks */ +/* ------------------------------------------------------------------------- */ -/* setType */ -const char BL_ActionActuator::SetType_doc[] = -"setType(mode)\n" -"\t - mode: Play (0), Flipper (2), LoopStop (3), LoopEnd (4) or Property (6)\n" -"\tSet the operation mode of the actuator.\n"; -PyObject* BL_ActionActuator::PySetType(PyObject* self, - PyObject* args, - PyObject* kwds) { - short typeArg; - - if (!PyArg_ParseTuple(args, "h", &typeArg)) { - return NULL; - } +PyTypeObject BL_ActionActuator::Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, + "BL_ActionActuator", + sizeof(BL_ActionActuator), + 0, + PyDestructor, + 0, + __getattr, + __setattr, + 0, //&MyPyCompare, + __repr, + 0, //&cvalue_as_number, + 0, + 0, + 0, + 0 +}; - switch (typeArg) { - case KX_ACT_ACTION_PLAY: - case KX_ACT_ACTION_FLIPPER: - case KX_ACT_ACTION_LOOPSTOP: - case KX_ACT_ACTION_LOOPEND: - case KX_ACT_ACTION_PROPERTY: - m_playtype = typeArg; - break; - default: - printf("Invalid type for action actuator: %d\n", typeArg); /* error */ - } - Py_RETURN_NONE; -} +PyParentObject BL_ActionActuator::Parents[] = { + &BL_ActionActuator::Type, + &SCA_IActuator::Type, + &SCA_ILogicBrick::Type, + &CValue::Type, + NULL +}; -PyObject* BL_ActionActuator::PyGetContinue(PyObject* self) { - return PyInt_FromLong((long)(m_end_reset==0)); -} +PyMethodDef BL_ActionActuator::Methods[] = { + //Deprecated -----> + {"setAction", (PyCFunction) BL_ActionActuator::sPySetAction, METH_VARARGS, (PY_METHODCHAR)SetAction_doc}, + {"setStart", (PyCFunction) BL_ActionActuator::sPySetStart, METH_VARARGS, (PY_METHODCHAR)SetStart_doc}, + {"setEnd", (PyCFunction) BL_ActionActuator::sPySetEnd, METH_VARARGS, (PY_METHODCHAR)SetEnd_doc}, + {"setBlendin", (PyCFunction) BL_ActionActuator::sPySetBlendin, METH_VARARGS, (PY_METHODCHAR)SetBlendin_doc}, + {"setPriority", (PyCFunction) BL_ActionActuator::sPySetPriority, METH_VARARGS, (PY_METHODCHAR)SetPriority_doc}, + {"setFrame", (PyCFunction) BL_ActionActuator::sPySetFrame, METH_VARARGS, (PY_METHODCHAR)SetFrame_doc}, + {"setProperty", (PyCFunction) BL_ActionActuator::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc}, + {"setFrameProperty", (PyCFunction) BL_ActionActuator::sPySetFrameProperty, METH_VARARGS, (PY_METHODCHAR)SetFrameProperty_doc}, + {"setBlendtime", (PyCFunction) BL_ActionActuator::sPySetBlendtime, METH_VARARGS, (PY_METHODCHAR)SetBlendtime_doc}, -PyObject* BL_ActionActuator::PySetContinue(PyObject* self, PyObject* value) { - int param = PyObject_IsTrue( value ); - - if( param == -1 ) { - PyErr_SetString( PyExc_TypeError, "expected True/False or 0/1" ); - return NULL; - } + {"getAction", (PyCFunction) BL_ActionActuator::sPyGetAction, METH_VARARGS, (PY_METHODCHAR)GetAction_doc}, + {"getStart", (PyCFunction) BL_ActionActuator::sPyGetStart, METH_VARARGS, (PY_METHODCHAR)GetStart_doc}, + {"getEnd", (PyCFunction) BL_ActionActuator::sPyGetEnd, METH_VARARGS, (PY_METHODCHAR)GetEnd_doc}, + {"getBlendin", (PyCFunction) BL_ActionActuator::sPyGetBlendin, METH_VARARGS, (PY_METHODCHAR)GetBlendin_doc}, + {"getPriority", (PyCFunction) BL_ActionActuator::sPyGetPriority, METH_VARARGS, (PY_METHODCHAR)GetPriority_doc}, + {"getFrame", (PyCFunction) BL_ActionActuator::sPyGetFrame, METH_VARARGS, (PY_METHODCHAR)GetFrame_doc}, + {"getProperty", (PyCFunction) BL_ActionActuator::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc}, + {"getFrameProperty", (PyCFunction) BL_ActionActuator::sPyGetFrameProperty, METH_VARARGS, (PY_METHODCHAR)GetFrameProperty_doc}, +// {"getChannel", (PyCFunction) BL_ActionActuator::sPyGetChannel, METH_VARARGS}, + {"getType", (PyCFunction) BL_ActionActuator::sPyGetType, METH_VARARGS, (PY_METHODCHAR)GetType_doc}, + {"setType", (PyCFunction) BL_ActionActuator::sPySetType, METH_VARARGS, (PY_METHODCHAR)SetType_doc}, + {"getContinue", (PyCFunction) BL_ActionActuator::sPyGetContinue, METH_NOARGS, 0}, + {"setContinue", (PyCFunction) BL_ActionActuator::sPySetContinue, METH_O, 0}, + //<------ + KX_PYMETHODTABLE(BL_ActionActuator, setChannel), + {NULL,NULL} //Sentinel +}; - if (param) { - m_end_reset = 0; - } else { - m_end_reset = 1; - } - Py_RETURN_NONE; +PyAttributeDef BL_ActionActuator::Attributes[] = { + KX_PYATTRIBUTE_FLOAT_RW("start", 0, MAXFRAMEF, BL_ActionActuator, m_startframe), + KX_PYATTRIBUTE_FLOAT_RW("end", 0, MAXFRAMEF, BL_ActionActuator, m_endframe), + KX_PYATTRIBUTE_FLOAT_RW("blendin", 0, MAXFRAMEF, BL_ActionActuator, m_blendin), + KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ActionActuator, m_priority), + KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ActionActuator, m_localtime, CheckFrame), + KX_PYATTRIBUTE_STRING_RW("property", 0, 31, false, BL_ActionActuator, m_propname), + KX_PYATTRIBUTE_STRING_RW("frameProperty", 0, 31, false, BL_ActionActuator, m_framepropname), + KX_PYATTRIBUTE_BOOL_RW("continue", BL_ActionActuator, m_end_reset), + KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ActionActuator, m_blendframe, CheckBlendTime), + KX_PYATTRIBUTE_ENUM_RW_CHECK("type",0,100,false,BL_ActionActuator,m_playtype,CheckType), + { NULL } //Sentinel +}; + +PyObject* BL_ActionActuator::_getattr(const STR_String& attr) { + if (attr == "action") + return PyString_FromString(m_action->id.name+2); + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + _getattr_up(SCA_IActuator); } +int BL_ActionActuator::_setattr(const STR_String& attr, PyObject* value) { + if (attr == "action") + { + if (!PyString_Check(value)) + { + PyErr_SetString(PyExc_ValueError, "expected a string"); + return 1; + } + + STR_String val = PyString_AsString(value); + + if (val == "") + { + m_action = NULL; + return 0; + } + + bAction *action; + + action = (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); + + + if (!action) + { + PyErr_SetString(PyExc_ValueError, "action not found!"); + return 1; + } + + m_action = action; + return 0; + } + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_IActuator::_setattr(attr, value); +} \ No newline at end of file diff --git a/source/gameengine/Converter/BL_ActionActuator.h b/source/gameengine/Converter/BL_ActionActuator.h index a67b6d29b74..04bd9c803c5 100644 --- a/source/gameengine/Converter/BL_ActionActuator.h +++ b/source/gameengine/Converter/BL_ActionActuator.h @@ -81,6 +81,7 @@ public: void SetBlendTime (float newtime); + //Deprecated -----> KX_PYMETHOD_DOC(BL_ActionActuator,SetAction); KX_PYMETHOD_DOC(BL_ActionActuator,SetBlendin); KX_PYMETHOD_DOC(BL_ActionActuator,SetPriority); @@ -90,7 +91,6 @@ public: KX_PYMETHOD_DOC(BL_ActionActuator,SetProperty); KX_PYMETHOD_DOC(BL_ActionActuator,SetFrameProperty); KX_PYMETHOD_DOC(BL_ActionActuator,SetBlendtime); - KX_PYMETHOD_DOC(BL_ActionActuator,SetChannel); KX_PYMETHOD_DOC(BL_ActionActuator,GetAction); KX_PYMETHOD_DOC(BL_ActionActuator,GetBlendin); @@ -105,8 +105,12 @@ public: KX_PYMETHOD_DOC(BL_ActionActuator,SetType); KX_PYMETHOD_NOARGS(BL_ActionActuator,GetContinue); KX_PYMETHOD_O(BL_ActionActuator,SetContinue); + //<----- + + KX_PYMETHOD_DOC(BL_ActionActuator,setChannel); virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject* value); enum ActionActType { @@ -117,6 +121,46 @@ public: KX_ACT_ACTION_PROPERTY = 6 }; + /* attribute check */ + static int CheckFrame(void *self, const PyAttributeDef*) + { + BL_ActionActuator* act = reinterpret_cast(self); + + if (act->m_localtime < act->m_startframe) + act->m_localtime = act->m_startframe; + else if (act->m_localtime > act->m_endframe) + act->m_localtime = act->m_endframe; + + return 0; + } + + static int CheckBlendTime(void *self, const PyAttributeDef*) + { + BL_ActionActuator* act = reinterpret_cast(self); + + if (act->m_blendframe < act->m_blendin) + act->m_blendframe = act->m_blendin; + + return 0; + } + + static int CheckType(void *self, const PyAttributeDef*) + { + BL_ActionActuator* act = reinterpret_cast(self); + + switch (act->m_playtype) { + case KX_ACT_ACTION_PLAY: + case KX_ACT_ACTION_FLIPPER: + case KX_ACT_ACTION_LOOPSTOP: + case KX_ACT_ACTION_LOOPEND: + case KX_ACT_ACTION_PROPERTY: + return 0; + default: + PyErr_SetString(PyExc_ValueError, "invalid type supplied"); + return 1; + } + + } protected: void SetStartTime(float curtime); @@ -141,7 +185,7 @@ protected: float m_stridelength; short m_playtype; short m_priority; - short m_end_reset; + bool m_end_reset; struct bPose* m_pose; struct bPose* m_blendpose; struct bPose* m_userpose; diff --git a/source/gameengine/PyDoc/BL_ActionActuator.py b/source/gameengine/PyDoc/BL_ActionActuator.py index b68d3014115..5d6ea51060b 100644 --- a/source/gameengine/PyDoc/BL_ActionActuator.py +++ b/source/gameengine/PyDoc/BL_ActionActuator.py @@ -5,7 +5,49 @@ from SCA_IActuator import * class BL_ActionActuator(SCA_IActuator): """ Action Actuators apply an action to an actor. + + @ivar action: The name of the action to set as the current action. + @type action: string + @ivar start: Specifies the starting frame of the animation. + @type start: float + @type end: Specifies the ending frame of the animation. + @type end: float + @ivar blendin: Specifies the number of frames of animation to generate when making transitions between actions. + @type blendin: float + @ivar priority: Sets the priority of this actuator. Actuators will lower + priority numbers will override actuators with higher + numbers. + @type priority: integer + @ivar frame: Sets the current frame for the animation. + @type frame: float + @ivar property: Sets the property to be used in FromProp playback mode. + @type property: string + @ivar blendTime: Sets the internal frame timer. This property must be in + the range from 0.0 to 1.0. + @type blendTime: float + @ivar type: The operation mode of the actuator. + KX_ACTIONACT_PLAY, KX_ACTIONACT_PROPERTY, KX_ACTIONACT_FLIPPER, + KX_ACTIONACT_LOOPSTOP, KX_ACTIONACT_LOOPEND + @type type: integer + @ivar continue: The actions continue option, True or False. + When True, the action will always play from where last left off, + otherwise negative events to this actuator will reset it to its start frame. + @type: boolean + @ivar frameProperty: The name of the property that is set to the current frame number. + @type frameProperty: string """ + def setChannel(channel, matrix, mode = False): + """ + @param channel: A string specifying the name of the bone channel. + @type channel: string + @param matrix: A 4x4 matrix specifying the overriding transformation + as an offset from the bone's rest position. + @type matrix: list [[float]] + @param mode: True for armature/world space, False for bone space + @type mode: boolean + """ + + #--The following methods are deprecated-- def setAction(action, reset = True): """ Sets the current action. @@ -154,16 +196,6 @@ class BL_ActionActuator(SCA_IActuator): @rtype: string """ - def setChannel(channel, matrix, mode = False): - """ - @param channel: A string specifying the name of the bone channel. - @type channel: string - @param matrix: A 4x4 matrix specifying the overriding transformation - as an offset from the bone's rest position. - @type matrix: list [[float]] - @param mode: True for armature/world space, False for bone space - @type mode: boolean - """ def setFrameProperty(prop): """ @param prop: A string specifying the property of the object that will be updated with the action frame number. -- cgit v1.2.3 From 8a95c67a50918a928f45fffd53e084428fcff9d8 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Thu, 22 Jan 2009 17:40:47 +0000 Subject: BGE API cleanup: shape action actuator. --- source/gameengine/Converter/BL_ActionActuator.cpp | 16 ++--- source/gameengine/Converter/BL_ActionActuator.h | 22 ++---- .../Converter/BL_ShapeActionActuator.cpp | 80 +++++++++++++++++++++- .../gameengine/Converter/BL_ShapeActionActuator.h | 40 +++++++++++ source/gameengine/Ketsji/KX_PythonInit.cpp | 10 +-- source/gameengine/PyDoc/BL_ActionActuator.py | 23 ++++++- source/gameengine/PyDoc/BL_ShapeActionActuator.py | 63 ++++++++++++----- 7 files changed, 205 insertions(+), 49 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index c05f763cacb..65d6892fa6d 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -39,10 +39,9 @@ #include "BL_SkinDeformer.h" #include "KX_GameObject.h" #include "STR_HashedString.h" -#include "DNA_action_types.h" #include "DNA_nla_types.h" -#include "DNA_actuator_types.h" #include "BKE_action.h" +#include "DNA_action_types.h" #include "DNA_armature_types.h" #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" @@ -51,7 +50,6 @@ #include "BKE_utildefines.h" #include "FloatValue.h" #include "PyObjectPlus.h" - #include "blendef.h" #ifdef HAVE_CONFIG_H @@ -843,11 +841,11 @@ PyObject* BL_ActionActuator::PySetType(PyObject* self, } switch (typeArg) { - case KX_ACT_ACTION_PLAY: - case KX_ACT_ACTION_FLIPPER: - case KX_ACT_ACTION_LOOPSTOP: - case KX_ACT_ACTION_LOOPEND: - case KX_ACT_ACTION_PROPERTY: + case ACT_ACTION_PLAY: + case ACT_ACTION_FLIPPER: + case ACT_ACTION_LOOP_STOP: + case ACT_ACTION_LOOP_END: + case ACT_ACTION_FROM_PROP: m_playtype = typeArg; break; default: @@ -1033,7 +1031,7 @@ PyAttributeDef BL_ActionActuator::Attributes[] = { KX_PYATTRIBUTE_STRING_RW("frameProperty", 0, 31, false, BL_ActionActuator, m_framepropname), KX_PYATTRIBUTE_BOOL_RW("continue", BL_ActionActuator, m_end_reset), KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ActionActuator, m_blendframe, CheckBlendTime), - KX_PYATTRIBUTE_ENUM_RW_CHECK("type",0,100,false,BL_ActionActuator,m_playtype,CheckType), + KX_PYATTRIBUTE_SHORT_RW_CHECK("type",0,100,false,BL_ActionActuator,m_playtype,CheckType), { NULL } //Sentinel }; diff --git a/source/gameengine/Converter/BL_ActionActuator.h b/source/gameengine/Converter/BL_ActionActuator.h index 04bd9c803c5..6e291106553 100644 --- a/source/gameengine/Converter/BL_ActionActuator.h +++ b/source/gameengine/Converter/BL_ActionActuator.h @@ -32,6 +32,7 @@ #include "GEN_HashedPtr.h" #include "SCA_IActuator.h" +#include "DNA_actuator_types.h" #include "MT_Point3.h" class BL_ActionActuator : public SCA_IActuator @@ -112,15 +113,6 @@ public: virtual PyObject* _getattr(const STR_String& attr); virtual int _setattr(const STR_String& attr, PyObject* value); - enum ActionActType - { - KX_ACT_ACTION_PLAY = 0, - KX_ACT_ACTION_FLIPPER = 2, - KX_ACT_ACTION_LOOPSTOP, - KX_ACT_ACTION_LOOPEND, - KX_ACT_ACTION_PROPERTY = 6 - }; - /* attribute check */ static int CheckFrame(void *self, const PyAttributeDef*) { @@ -138,7 +130,7 @@ public: { BL_ActionActuator* act = reinterpret_cast(self); - if (act->m_blendframe < act->m_blendin) + if (act->m_blendframe > act->m_blendin) act->m_blendframe = act->m_blendin; return 0; @@ -149,11 +141,11 @@ public: BL_ActionActuator* act = reinterpret_cast(self); switch (act->m_playtype) { - case KX_ACT_ACTION_PLAY: - case KX_ACT_ACTION_FLIPPER: - case KX_ACT_ACTION_LOOPSTOP: - case KX_ACT_ACTION_LOOPEND: - case KX_ACT_ACTION_PROPERTY: + case ACT_ACTION_PLAY: + case ACT_ACTION_FLIPPER: + case ACT_ACTION_LOOP_STOP: + case ACT_ACTION_LOOP_END: + case ACT_ACTION_FROM_PROP: return 0; default: PyErr_SetString(PyExc_ValueError, "invalid type supplied"); diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index 46f3141be29..df0a8c4f25e 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -35,13 +35,11 @@ #include "SCA_LogicManager.h" #include "BL_ShapeActionActuator.h" -#include "BL_ActionActuator.h" #include "BL_ShapeDeformer.h" #include "KX_GameObject.h" #include "STR_HashedString.h" -#include "DNA_action_types.h" #include "DNA_nla_types.h" -#include "DNA_actuator_types.h" +#include "DNA_action_types.h" #include "BKE_action.h" #include "DNA_armature_types.h" #include "MEM_guardedalloc.h" @@ -51,6 +49,7 @@ #include "BKE_utildefines.h" #include "FloatValue.h" #include "PyObjectPlus.h" +#include "blendef.h" #ifdef HAVE_CONFIG_H #include @@ -471,16 +470,73 @@ PyMethodDef BL_ShapeActionActuator::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef BL_ShapeActionActuator::Attributes[] = { + KX_PYATTRIBUTE_FLOAT_RW("start", 0, MAXFRAMEF, BL_ShapeActionActuator, m_startframe), + KX_PYATTRIBUTE_FLOAT_RW("end", 0, MAXFRAMEF, BL_ShapeActionActuator, m_endframe), + KX_PYATTRIBUTE_FLOAT_RW("blendin", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendin), + KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ShapeActionActuator, m_priority), + KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ShapeActionActuator, m_localtime, CheckFrame), + KX_PYATTRIBUTE_STRING_RW("property", 0, 31, false, BL_ShapeActionActuator, m_propname), + KX_PYATTRIBUTE_STRING_RW("frameProperty", 0, 31, false, BL_ShapeActionActuator, m_framepropname), + KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendframe, CheckBlendTime), + KX_PYATTRIBUTE_SHORT_RW_CHECK("type",0,100,false,BL_ShapeActionActuator,m_playtype,CheckType), + { NULL } //Sentinel +}; + + PyObject* BL_ShapeActionActuator::_getattr(const STR_String& attr) { + if (attr == "action") + return PyString_FromString(m_action->id.name+2); + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_IActuator); } +int BL_ShapeActionActuator::_setattr(const STR_String& attr, PyObject* value) { + if (attr == "action") + { + if (!PyString_Check(value)) + { + PyErr_SetString(PyExc_ValueError, "expected a string"); + return 1; + } + + STR_String val = PyString_AsString(value); + + if (val == "") + { + m_action = NULL; + return 0; + } + + bAction *action; + + action = (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); + + + if (!action) + { + PyErr_SetString(PyExc_ValueError, "action not found!"); + return 1; + } + + m_action = action; + return 0; + } + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_IActuator::_setattr(attr, value); +} + /* setStart */ const char BL_ShapeActionActuator::GetAction_doc[] = "getAction()\n" "\tReturns a string containing the name of the current action.\n"; PyObject* BL_ShapeActionActuator::PyGetAction(PyObject* self) { + ShowDeprecationWarning("getAction()", "the action property"); if (m_action){ return PyString_FromString(m_action->id.name+2); } @@ -493,6 +549,7 @@ const char BL_ShapeActionActuator::GetProperty_doc[] = "\tReturns the name of the property to be used in FromProp mode.\n"; PyObject* BL_ShapeActionActuator::PyGetProperty(PyObject* self) { + ShowDeprecationWarning("getProperty()", "the property property"); PyObject *result; result = Py_BuildValue("s", (const char *)m_propname); @@ -506,6 +563,7 @@ const char BL_ShapeActionActuator::GetFrame_doc[] = "\tReturns the current frame number.\n"; PyObject* BL_ShapeActionActuator::PyGetFrame(PyObject* self) { + ShowDeprecationWarning("getFrame()", "the frame property"); PyObject *result; result = Py_BuildValue("f", m_localtime); @@ -519,6 +577,7 @@ const char BL_ShapeActionActuator::GetEnd_doc[] = "\tReturns the last frame of the action.\n"; PyObject* BL_ShapeActionActuator::PyGetEnd(PyObject* self) { + ShowDeprecationWarning("getEnd()", "the end property"); PyObject *result; result = Py_BuildValue("f", m_endframe); @@ -532,6 +591,7 @@ const char BL_ShapeActionActuator::GetStart_doc[] = "\tReturns the starting frame of the action.\n"; PyObject* BL_ShapeActionActuator::PyGetStart(PyObject* self) { + ShowDeprecationWarning("getStart()", "the start property"); PyObject *result; result = Py_BuildValue("f", m_startframe); @@ -546,6 +606,7 @@ const char BL_ShapeActionActuator::GetBlendin_doc[] = "\tgenerated when this actuator is triggered.\n"; PyObject* BL_ShapeActionActuator::PyGetBlendin(PyObject* self) { + ShowDeprecationWarning("getBlendin()", "the blendin property"); PyObject *result; result = Py_BuildValue("f", m_blendin); @@ -560,6 +621,7 @@ const char BL_ShapeActionActuator::GetPriority_doc[] = "\tPriority numbers will override actuators with higher numbers.\n"; PyObject* BL_ShapeActionActuator::PyGetPriority(PyObject* self) { + ShowDeprecationWarning("getPriority()", "the priority property"); PyObject *result; result = Py_BuildValue("i", m_priority); @@ -581,6 +643,7 @@ const char BL_ShapeActionActuator::SetAction_doc[] = PyObject* BL_ShapeActionActuator::PySetAction(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setAction()", "the action property"); char *string; int reset = 1; @@ -615,6 +678,7 @@ const char BL_ShapeActionActuator::SetStart_doc[] = PyObject* BL_ShapeActionActuator::PySetStart(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setStart()", "the start property"); float start; if (PyArg_ParseTuple(args,"f",&start)) @@ -636,6 +700,7 @@ const char BL_ShapeActionActuator::SetEnd_doc[] = PyObject* BL_ShapeActionActuator::PySetEnd(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setEnd()", "the end property"); float end; if (PyArg_ParseTuple(args,"f",&end)) @@ -658,6 +723,7 @@ const char BL_ShapeActionActuator::SetBlendin_doc[] = PyObject* BL_ShapeActionActuator::PySetBlendin(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setBlendin()", "the blendin property"); float blendin; if (PyArg_ParseTuple(args,"f",&blendin)) @@ -681,6 +747,7 @@ const char BL_ShapeActionActuator::SetBlendtime_doc[] = PyObject* BL_ShapeActionActuator::PySetBlendtime(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setBlendtime()", "the blendTime property"); float blendframe; if (PyArg_ParseTuple(args,"f",&blendframe)) @@ -708,6 +775,7 @@ const char BL_ShapeActionActuator::SetPriority_doc[] = PyObject* BL_ShapeActionActuator::PySetPriority(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setPriority()", "the priority property"); int priority; if (PyArg_ParseTuple(args,"i",&priority)) @@ -727,6 +795,7 @@ const char BL_ShapeActionActuator::GetFrameProperty_doc[] = "\tReturns the name of the property, that is set to the current frame number.\n"; PyObject* BL_ShapeActionActuator::PyGetFrameProperty(PyObject* self) { + ShowDeprecationWarning("getFrameProperty()", "the frameProperty property"); PyObject *result; result = Py_BuildValue("s", (const char *)m_framepropname); @@ -743,6 +812,7 @@ const char BL_ShapeActionActuator::SetFrame_doc[] = PyObject* BL_ShapeActionActuator::PySetFrame(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setFrame()", "the frame property"); float frame; if (PyArg_ParseTuple(args,"f",&frame)) @@ -769,6 +839,7 @@ const char BL_ShapeActionActuator::SetProperty_doc[] = PyObject* BL_ShapeActionActuator::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setProperty()", "the property property"); char *string; if (PyArg_ParseTuple(args,"s",&string)) @@ -790,6 +861,7 @@ const char BL_ShapeActionActuator::SetFrameProperty_doc[] = PyObject* BL_ShapeActionActuator::PySetFrameProperty(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setFrameProperty()", "the frameProperty property"); char *string; if (PyArg_ParseTuple(args,"s",&string)) @@ -808,6 +880,7 @@ const char BL_ShapeActionActuator::GetType_doc[] = "getType()\n" "\tReturns the operation mode of the actuator.\n"; PyObject* BL_ShapeActionActuator::PyGetType(PyObject* self) { + ShowDeprecationWarning("getType()", "the type property"); return Py_BuildValue("h", m_playtype); } @@ -819,6 +892,7 @@ const char BL_ShapeActionActuator::SetType_doc[] = PyObject* BL_ShapeActionActuator::PySetType(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setType()", "the type property"); short typeArg; if (!PyArg_ParseTuple(args, "h", &typeArg)) { diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.h b/source/gameengine/Converter/BL_ShapeActionActuator.h index 30b2d41fc67..b521c0d98a6 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.h +++ b/source/gameengine/Converter/BL_ShapeActionActuator.h @@ -32,6 +32,7 @@ #include "GEN_HashedPtr.h" #include "SCA_IActuator.h" +#include "BL_ActionActuator.h" #include "MT_Point3.h" #include @@ -103,6 +104,45 @@ public: KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetType); virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject* value); + + static int CheckBlendTime(void *self, const PyAttributeDef*) + { + BL_ShapeActionActuator* act = reinterpret_cast(self); + + if (act->m_blendframe > act->m_blendin) + act->m_blendframe = act->m_blendin; + + return 0; + } + static int CheckFrame(void *self, const PyAttributeDef*) + { + BL_ShapeActionActuator* act = reinterpret_cast(self); + + if (act->m_localtime < act->m_startframe) + act->m_localtime = act->m_startframe; + else if (act->m_localtime > act->m_endframe) + act->m_localtime = act->m_endframe; + + return 0; + } + static int CheckType(void *self, const PyAttributeDef*) + { + BL_ShapeActionActuator* act = reinterpret_cast(self); + + switch (act->m_playtype) { + case ACT_ACTION_PLAY: + case ACT_ACTION_FLIPPER: + case ACT_ACTION_LOOP_STOP: + case ACT_ACTION_LOOP_END: + case ACT_ACTION_FROM_PROP: + return 0; + default: + PyErr_SetString(PyExc_ValueError, "invalid type supplied"); + return 1; + } + + } protected: diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 0032d83c2ff..13f141dec13 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -963,11 +963,11 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP); /* 7. Action actuator */ - KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PLAY, BL_ActionActuator::KX_ACT_ACTION_PLAY); - KX_MACRO_addTypesToDict(d, KX_ACTIONACT_FLIPPER, BL_ActionActuator::KX_ACT_ACTION_FLIPPER); - KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPSTOP, BL_ActionActuator::KX_ACT_ACTION_LOOPSTOP); - KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPEND, BL_ActionActuator::KX_ACT_ACTION_LOOPEND); - KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PROPERTY, BL_ActionActuator::KX_ACT_ACTION_PROPERTY); + KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PLAY, ACT_ACTION_PLAY); + KX_MACRO_addTypesToDict(d, KX_ACTIONACT_FLIPPER, ACT_ACTION_FLIPPER); + KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPSTOP, ACT_ACTION_LOOP_STOP); + KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPEND, ACT_ACTION_LOOP_END); + KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PROPERTY, ACT_ACTION_FROM_PROP); /*8. GL_BlendFunc */ KX_MACRO_addTypesToDict(d, BL_ZERO, GL_ZERO); diff --git a/source/gameengine/PyDoc/BL_ActionActuator.py b/source/gameengine/PyDoc/BL_ActionActuator.py index 5d6ea51060b..3e95befe16b 100644 --- a/source/gameengine/PyDoc/BL_ActionActuator.py +++ b/source/gameengine/PyDoc/BL_ActionActuator.py @@ -23,7 +23,7 @@ class BL_ActionActuator(SCA_IActuator): @ivar property: Sets the property to be used in FromProp playback mode. @type property: string @ivar blendTime: Sets the internal frame timer. This property must be in - the range from 0.0 to 1.0. + the range from 0.0 to blendin. @type blendTime: float @ivar type: The operation mode of the actuator. KX_ACTIONACT_PLAY, KX_ACTIONACT_PROPERTY, KX_ACTIONACT_FLIPPER, @@ -50,6 +50,7 @@ class BL_ActionActuator(SCA_IActuator): #--The following methods are deprecated-- def setAction(action, reset = True): """ + DEPRECATED: use the 'action' property Sets the current action. @param action: The name of the action to set as the current action. @@ -63,6 +64,7 @@ class BL_ActionActuator(SCA_IActuator): def setStart(start): """ + DEPRECATED: use the 'start' property Specifies the starting frame of the animation. @param start: the starting frame of the animation @@ -71,6 +73,7 @@ class BL_ActionActuator(SCA_IActuator): def setEnd(end): """ + DEPRECATED: use the 'end' property Specifies the ending frame of the animation. @param end: the ending frame of the animation @@ -78,6 +81,7 @@ class BL_ActionActuator(SCA_IActuator): """ def setBlendin(blendin): """ + DEPRECATED: use the 'blendin' property Specifies the number of frames of animation to generate when making transitions between actions. @@ -87,6 +91,7 @@ class BL_ActionActuator(SCA_IActuator): def setPriority(priority): """ + DEPRECATED: use the 'priority' property Sets the priority of this actuator. @param priority: Specifies the new priority. Actuators will lower @@ -96,6 +101,7 @@ class BL_ActionActuator(SCA_IActuator): """ def setFrame(frame): """ + DEPRECATED: use the 'frame' property Sets the current frame for the animation. @param frame: Specifies the new current frame for the animation @@ -104,6 +110,7 @@ class BL_ActionActuator(SCA_IActuator): def setProperty(prop): """ + DEPRECATED: use the 'property' property Sets the property to be used in FromProp playback mode. @param prop: the name of the property to use. @@ -112,6 +119,7 @@ class BL_ActionActuator(SCA_IActuator): def setBlendtime(blendtime): """ + DEPRECATED: use the 'blendTime' property Sets the internal frame timer. Allows the script to directly modify the internal timer @@ -123,6 +131,7 @@ class BL_ActionActuator(SCA_IActuator): def setType(mode): """ + DEPRECATED: use the 'type' property Sets the operation mode of the actuator @param mode: KX_ACTIONACT_PLAY, KX_ACTIONACT_PROPERTY, KX_ACTIONACT_FLIPPER, KX_ACTIONACT_LOOPSTOP, KX_ACTIONACT_LOOPEND @@ -131,6 +140,7 @@ class BL_ActionActuator(SCA_IActuator): def setContinue(cont): """ + DEPRECATED: use the 'continue' property Set the actions continue option True or False. see getContinue. @param cont: The continue option. @@ -139,6 +149,7 @@ class BL_ActionActuator(SCA_IActuator): def getType(): """ + DEPRECATED: use the 'type' property Returns the operation mode of the actuator @rtype: integer @@ -147,6 +158,7 @@ class BL_ActionActuator(SCA_IActuator): def getContinue(): """ + DEPRECATED: use the 'continue' property When True, the action will always play from where last left off, otherwise negative events to this actuator will reset it to its start frame. @rtype: bool @@ -154,6 +166,7 @@ class BL_ActionActuator(SCA_IActuator): def getAction(): """ + DEPRECATED: use the 'action' property getAction() returns the name of the action associated with this actuator. @rtype: string @@ -161,24 +174,28 @@ class BL_ActionActuator(SCA_IActuator): def getStart(): """ + DEPRECATED: use the 'start' property Returns the starting frame of the action. @rtype: float """ def getEnd(): """ + DEPRECATED: use the 'end' property Returns the last frame of the action. @rtype: float """ def getBlendin(): """ + DEPRECATED: use the 'blendin' property Returns the number of interpolation animation frames to be generated when this actuator is triggered. @rtype: float """ def getPriority(): """ + DEPRECATED: use the 'priority' property Returns the priority for this actuator. Actuators with lower Priority numbers will override actuators with higher numbers. @@ -186,23 +203,27 @@ class BL_ActionActuator(SCA_IActuator): """ def getFrame(): """ + DEPRECATED: use the 'frame' property Returns the current frame number. @rtype: float """ def getProperty(): """ + DEPRECATED: use the 'property' property Returns the name of the property to be used in FromProp mode. @rtype: string """ def setFrameProperty(prop): """ + DEPRECATED: use the 'frameProperty' property @param prop: A string specifying the property of the object that will be updated with the action frame number. @type prop: string """ def getFrameProperty(): """ + DEPRECATED: use the 'frameProperty' property Returns the name of the property that is set to the current frame number. @rtype: string diff --git a/source/gameengine/PyDoc/BL_ShapeActionActuator.py b/source/gameengine/PyDoc/BL_ShapeActionActuator.py index a26b276a2da..209ff4e5580 100644 --- a/source/gameengine/PyDoc/BL_ShapeActionActuator.py +++ b/source/gameengine/PyDoc/BL_ShapeActionActuator.py @@ -4,10 +4,38 @@ from SCA_IActuator import * class BL_ShapeActionActuator(SCA_IActuator): """ - ShapeAction Actuators apply an shape action to an mesh object. + ShapeAction Actuators apply an shape action to an mesh object.\ + + @ivar action: The name of the action to set as the current shape action. + @type action: string + @ivar start: Specifies the starting frame of the shape animation. + @type start: float + @type end: Specifies the ending frame of the shape animation. + @type end: float + @ivar blendin: Specifies the number of frames of animation to generate when making transitions between actions. + @type blendin: float + @ivar priority: Sets the priority of this actuator. Actuators will lower + priority numbers will override actuators with higher + numbers. + @type priority: integer + @ivar frame: Sets the current frame for the animation. + @type frame: float + @ivar property: Sets the property to be used in FromProp playback mode. + @type property: string + @ivar blendTime: Sets the internal frame timer. This property must be in + the range from 0.0 to blendin. + @type blendTime: float + @ivar type: The operation mode of the actuator. + KX_ACTIONACT_PLAY, KX_ACTIONACT_PROPERTY, KX_ACTIONACT_FLIPPER, + KX_ACTIONACT_LOOPSTOP, KX_ACTIONACT_LOOPEND + @type type: integer + @ivar frameProperty: The name of the property that is set to the current frame number. + @type frameProperty: string + """ def setAction(action, reset = True): """ + DEPRECATED: use the 'action' property Sets the current action. @param action: The name of the action to set as the current action. @@ -21,6 +49,7 @@ class BL_ShapeActionActuator(SCA_IActuator): def setStart(start): """ + DEPRECATED: use the 'start' property Specifies the starting frame of the animation. @param start: the starting frame of the animation @@ -29,6 +58,7 @@ class BL_ShapeActionActuator(SCA_IActuator): def setEnd(end): """ + DEPRECATED: use the 'end' property Specifies the ending frame of the animation. @param end: the ending frame of the animation @@ -36,6 +66,7 @@ class BL_ShapeActionActuator(SCA_IActuator): """ def setBlendin(blendin): """ + DEPRECATED: use the 'blendin' property Specifies the number of frames of animation to generate when making transitions between actions. @@ -45,6 +76,7 @@ class BL_ShapeActionActuator(SCA_IActuator): def setPriority(priority): """ + DEPRECATED: use the 'priority' property Sets the priority of this actuator. @param priority: Specifies the new priority. Actuators will lower @@ -54,6 +86,7 @@ class BL_ShapeActionActuator(SCA_IActuator): """ def setFrame(frame): """ + DEPRECATED: use the 'frame' property Sets the current frame for the animation. @param frame: Specifies the new current frame for the animation @@ -62,6 +95,7 @@ class BL_ShapeActionActuator(SCA_IActuator): def setProperty(prop): """ + DEPRECATED: use the 'property' property Sets the property to be used in FromProp playback mode. @param prop: the name of the property to use. @@ -70,6 +104,7 @@ class BL_ShapeActionActuator(SCA_IActuator): def setBlendtime(blendtime): """ + DEPRECATED: use the 'blendTime' property Sets the internal frame timer. Allows the script to directly modify the internal timer @@ -81,37 +116,25 @@ class BL_ShapeActionActuator(SCA_IActuator): def setType(mode): """ + DEPRECATED: use the 'type' property Sets the operation mode of the actuator @param mode: KX_ACTIONACT_PLAY, KX_ACTIONACT_PROPERTY, KX_ACTIONACT_FLIPPER, KX_ACTIONACT_LOOPSTOP, KX_ACTIONACT_LOOPEND @type mode: integer """ - def setContinue(cont): - """ - Set the actions continue option True or False. see getContinue. - - @param cont: The continue option. - @type cont: bool - """ - def getType(): """ + DEPRECATED: use the 'type' property Returns the operation mode of the actuator @rtype: integer @return: KX_ACTIONACT_PLAY, KX_ACTIONACT_PROPERTY, KX_ACTIONACT_FLIPPER, KX_ACTIONACT_LOOPSTOP, KX_ACTIONACT_LOOPEND """ - def getContinue(): - """ - When True, the action will always play from where last left off, otherwise negative events to this actuator will reset it to its start frame. - - @rtype: bool - """ - def getAction(): """ + DEPRECATED: use the 'action' property getAction() returns the name of the action associated with this actuator. @rtype: string @@ -119,24 +142,28 @@ class BL_ShapeActionActuator(SCA_IActuator): def getStart(): """ + DEPRECATED: use the 'start' property Returns the starting frame of the action. @rtype: float """ def getEnd(): """ + DEPRECATED: use the 'end' property Returns the last frame of the action. @rtype: float """ def getBlendin(): """ + DEPRECATED: use the 'blendin' property Returns the number of interpolation animation frames to be generated when this actuator is triggered. @rtype: float """ def getPriority(): """ + DEPRECATED: use the 'priority' property Returns the priority for this actuator. Actuators with lower Priority numbers will override actuators with higher numbers. @@ -144,23 +171,27 @@ class BL_ShapeActionActuator(SCA_IActuator): """ def getFrame(): """ + DEPRECATED: use the 'frame' property Returns the current frame number. @rtype: float """ def getProperty(): """ + DEPRECATED: use the 'property' property Returns the name of the property to be used in FromProp mode. @rtype: string """ def setFrameProperty(prop): """ + DEPRECATED: use the 'frameProperty' property @param prop: A string specifying the property of the object that will be updated with the action frame number. @type prop: string """ def getFrameProperty(): """ + DEPRECATED: use the 'frameProperty' property Returns the name of the property that is set to the current frame number. @rtype: string -- cgit v1.2.3 From f1948b363d6cd01ec6cfcd2d69101fdb9407aff6 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sat, 24 Jan 2009 21:19:35 +0000 Subject: BGE patch 18211: Bug Fix for: [#18175] error on anaglyph view of a splitted viewport. --- source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 8bcda4479e1..1271474802c 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -732,6 +732,26 @@ void KX_KetsjiEngine::Render() // do the rendering //RenderFrame(scene); RenderFrame(scene, cam); + + list* cameras = scene->GetCameras(); + + // Draw the scene once for each camera with an enabled viewport + list::iterator it = cameras->begin(); + while(it != cameras->end()) + { + if((*it)->GetViewport()) + { + if (scene->IsClearingZBuffer()) + m_rasterizer->ClearDepthBuffer(); + + m_rendertools->SetAuxilaryClientInfo(scene); + + // do the rendering + RenderFrame(scene, (*it)); + } + + it++; + } } } // if(m_rasterizer->Stereo()) -- cgit v1.2.3 From 9146687ffcc7ac78d0bd75339f351baf630b07e3 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Mon, 26 Jan 2009 06:31:06 +0000 Subject: let the game engine compile, if WITH_FFPEG is not defined (so we don't have video textures in that case) --- source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index f046942af75..67bec97ea32 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -368,7 +368,9 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, initGameKeys(); initPythonConstraintBinding(); initMathutils(); +#ifdef WITH_FFMPEG initVideoTexture(); +#endif if (sceneconverter) { @@ -660,7 +662,9 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, initGameKeys(); initPythonConstraintBinding(); initMathutils(); - initVideoTexture(); +#ifdef WITH_FFMPEG + initVideoTexture(); +#endif if (sceneconverter) { -- cgit v1.2.3 From e40803a5b3ac860f895c2180fe90f0040f3583d5 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 6 Feb 2009 19:21:24 +0000 Subject: Fix for bug #18228: OpenGL specular did not get the correct view vector in perspective mode. This is default OpenGL behavior, but by now this optimization is really insignificant. Works in both the 3d view and game engine. --- source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp | 9 +++++---- source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h | 4 ++-- source/gameengine/GamePlayer/common/GPC_RenderTools.cpp | 9 +++++---- source/gameengine/GamePlayer/common/GPC_RenderTools.h | 4 ++-- source/gameengine/Rasterizer/RAS_IRasterizer.h | 2 ++ source/gameengine/Rasterizer/RAS_IRenderTools.h | 1 + source/gameengine/Rasterizer/RAS_MaterialBucket.cpp | 4 ++-- .../Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp | 11 ++++++++++- .../Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h | 2 ++ 9 files changed, 31 insertions(+), 15 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp index 1797d6c1a0f..42ad7769cbd 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp @@ -80,7 +80,7 @@ void KX_BlenderRenderTools::EndFrame(RAS_IRasterizer* rasty) * has a maximum of 8 lights (simultaneous), so 20 * 8 lights are possible in * a scene. */ -void KX_BlenderRenderTools::ProcessLighting(int layer, const MT_Transform& viewmat) +void KX_BlenderRenderTools::ProcessLighting(RAS_IRasterizer *rasty, int layer, const MT_Transform& viewmat) { if(m_lastlightlayer == layer) return; @@ -101,12 +101,12 @@ void KX_BlenderRenderTools::ProcessLighting(int layer, const MT_Transform& viewm } if(enable) - EnableOpenGLLights(); + EnableOpenGLLights(rasty); else DisableOpenGLLights(); } -void KX_BlenderRenderTools::EnableOpenGLLights() +void KX_BlenderRenderTools::EnableOpenGLLights(RAS_IRasterizer *rasty) { if(m_lastlighting == true) return; @@ -115,7 +115,8 @@ void KX_BlenderRenderTools::EnableOpenGLLights() glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, true); + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); + glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, (rasty->GetCameraOrtho())? GL_FALSE: GL_TRUE); if (GLEW_EXT_separate_specular_color || GLEW_VERSION_1_2) glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h index a7618462c9b..ebf7562503f 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h @@ -60,9 +60,9 @@ public: void EndFrame(RAS_IRasterizer* rasty); void BeginFrame(RAS_IRasterizer* rasty); - void EnableOpenGLLights(); + void EnableOpenGLLights(RAS_IRasterizer *rasty); void DisableOpenGLLights(); - void ProcessLighting(int layer, const MT_Transform& viewmat); + void ProcessLighting(RAS_IRasterizer *rasty, int layer, const MT_Transform& viewmat); void RenderText2D(RAS_TEXT_RENDER_MODE mode, const char* text, diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp index 78d8eaf2aa3..c0d6248a3ca 100644 --- a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp +++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp @@ -85,7 +85,7 @@ void GPC_RenderTools::EndFrame(RAS_IRasterizer* rasty) * has a maximum of 8 lights (simultaneous), so 20 * 8 lights are possible in * a scene. */ -void GPC_RenderTools::ProcessLighting(int layer, const MT_Transform& viewmat) +void GPC_RenderTools::ProcessLighting(RAS_IRasterizer *rasty, int layer, const MT_Transform& viewmat) { if(m_lastlightlayer == layer) return; @@ -106,12 +106,12 @@ void GPC_RenderTools::ProcessLighting(int layer, const MT_Transform& viewmat) } if(enable) - EnableOpenGLLights(); + EnableOpenGLLights(rasty); else DisableOpenGLLights(); } -void GPC_RenderTools::EnableOpenGLLights() +void GPC_RenderTools::EnableOpenGLLights(RAS_IRasterizer *rasty) { if(m_lastlighting == true) return; @@ -120,7 +120,8 @@ void GPC_RenderTools::EnableOpenGLLights() glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, true); + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); + glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, (rasty->GetCameraOrtho())? GL_FALSE: GL_TRUE); if (GLEW_EXT_separate_specular_color || GLEW_VERSION_1_2) glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.h b/source/gameengine/GamePlayer/common/GPC_RenderTools.h index 382956e73ea..2a1b66a3aa9 100644 --- a/source/gameengine/GamePlayer/common/GPC_RenderTools.h +++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.h @@ -65,9 +65,9 @@ public: void EndFrame(RAS_IRasterizer* rasty); void BeginFrame(RAS_IRasterizer* rasty); - void EnableOpenGLLights(); + void EnableOpenGLLights(RAS_IRasterizer *rasty); void DisableOpenGLLights(); - void ProcessLighting(int layer, const MT_Transform& viewmat); + void ProcessLighting(RAS_IRasterizer *rasty, int layer, const MT_Transform& viewmat); /* @attention mode is ignored here */ void RenderText2D(RAS_TEXT_RENDER_MODE mode, diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h index b4b90c3608b..d529ca8973a 100644 --- a/source/gameengine/Rasterizer/RAS_IRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h @@ -255,6 +255,8 @@ public: /** */ virtual const MT_Point3& GetCameraPosition()=0; + virtual bool GetCameraOrtho()=0; + /** */ virtual void SetFog(float start, diff --git a/source/gameengine/Rasterizer/RAS_IRenderTools.h b/source/gameengine/Rasterizer/RAS_IRenderTools.h index 57f331e64cb..a289ffed492 100644 --- a/source/gameengine/Rasterizer/RAS_IRenderTools.h +++ b/source/gameengine/Rasterizer/RAS_IRenderTools.h @@ -134,6 +134,7 @@ public: virtual void ProcessLighting( + RAS_IRasterizer *rasty, int layer, const MT_Transform& trans )=0; diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp index ad8d7ebd5b0..d8631c1edf6 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp @@ -517,9 +517,9 @@ bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_I return false; if (m_material->UsesLighting(rasty)) - rendertools->ProcessLighting(RAS_IRenderTools::RAS_LIGHT_OBJECT_LAYER, cameratrans); + rendertools->ProcessLighting(rasty, RAS_IRenderTools::RAS_LIGHT_OBJECT_LAYER, cameratrans); else - rendertools->ProcessLighting(-1, cameratrans); + rendertools->ProcessLighting(rasty, -1, cameratrans); return true; } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 3cad5fe74f2..08c600e7682 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -59,6 +59,8 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas) m_2DCanvas(canvas), m_fogenabled(false), m_time(0.0), + m_campos(0.0f, 0.0f, 0.0f), + m_camortho(false), m_stereomode(RAS_STEREO_NOSTEREO), m_curreye(RAS_STEREO_LEFTEYE), m_eyeseparation(0.0), @@ -756,8 +758,9 @@ void RAS_OpenGLRasterizer::SetProjectionMatrix(MT_CmMatrix4x4 &mat) glMatrixMode(GL_PROJECTION); double* matrix = &mat(0,0); glLoadMatrixd(matrix); -} + m_camortho= (mat(3, 3) != 0.0f); +} void RAS_OpenGLRasterizer::SetProjectionMatrix(const MT_Matrix4x4 & mat) { @@ -767,6 +770,8 @@ void RAS_OpenGLRasterizer::SetProjectionMatrix(const MT_Matrix4x4 & mat) mat.getValue(matrix); /* Internally, MT_Matrix4x4 uses doubles (MT_Scalar). */ glLoadMatrixd(matrix); + + m_camortho= (mat[3][3] != 0.0f); } MT_Matrix4x4 RAS_OpenGLRasterizer::GetFrustumMatrix( @@ -883,6 +888,10 @@ const MT_Point3& RAS_OpenGLRasterizer::GetCameraPosition() return m_campos; } +bool RAS_OpenGLRasterizer::GetCameraOrtho() +{ + return m_camortho; +} void RAS_OpenGLRasterizer::SetCullFace(bool enable) { diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h index d39fd642f86..c72d4880437 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h @@ -80,6 +80,7 @@ class RAS_OpenGLRasterizer : public RAS_IRasterizer MT_Matrix4x4 m_viewmatrix; MT_Matrix4x4 m_viewinvmatrix; MT_Point3 m_campos; + bool m_camortho; StereoMode m_stereomode; StereoEye m_curreye; @@ -168,6 +169,7 @@ public: ); virtual const MT_Point3& GetCameraPosition(); + virtual bool GetCameraOrtho(); virtual void SetFog( float start, -- cgit v1.2.3 From 59e96a2831ef52bff36f900bb4bb31fffe072f7d Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sat, 7 Feb 2009 20:35:16 +0000 Subject: BGE Py API cleanup: Camera Actuator. --- source/gameengine/Ketsji/KX_CameraActuator.cpp | 35 +++++++++++++++++++++++--- source/gameengine/Ketsji/KX_CameraActuator.h | 15 +++++------ source/gameengine/PyDoc/KX_CameraActuator.py | 9 +++++++ 3 files changed, 49 insertions(+), 10 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 4d24e83843e..98dd9ab3e68 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -36,6 +36,7 @@ #include "KX_GameObject.h" #include "PyObjectPlus.h" +#include "blendef.h" STR_String KX_CameraActuator::X_AXIS_STRING = "x"; STR_String KX_CameraActuator::Y_AXIS_STRING = "y"; @@ -52,9 +53,9 @@ STR_String KX_CameraActuator::Y_AXIS_STRING = "y"; KX_CameraActuator::KX_CameraActuator( SCA_IObject* gameobj, SCA_IObject *obj, - MT_Scalar hght, - MT_Scalar minhght, - MT_Scalar maxhght, + float hght, + float minhght, + float maxhght, bool xytog, PyTypeObject* T ): @@ -399,6 +400,7 @@ PyParentObject KX_CameraActuator::Parents[] = { PyMethodDef KX_CameraActuator::Methods[] = { {"setObject",(PyCFunction) KX_CameraActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc}, {"getObject",(PyCFunction) KX_CameraActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc}, + // ---> deprecated {"setMin" ,(PyCFunction) KX_CameraActuator::sPySetMin, METH_VARARGS, (PY_METHODCHAR)SetMin_doc}, {"getMin" ,(PyCFunction) KX_CameraActuator::sPyGetMin, METH_NOARGS, (PY_METHODCHAR)GetMin_doc}, {"setMax" ,(PyCFunction) KX_CameraActuator::sPySetMax, METH_VARARGS, (PY_METHODCHAR)SetMax_doc}, @@ -410,9 +412,28 @@ PyMethodDef KX_CameraActuator::Methods[] = { {NULL,NULL,NULL,NULL} //Sentinel }; +PyAttributeDef KX_CameraActuator::Attributes[] = { + KX_PYATTRIBUTE_FLOAT_RW("min",-MAXFLOAT,MAXFLOAT,KX_CameraActuator,m_minHeight), + KX_PYATTRIBUTE_FLOAT_RW("max",-MAXFLOAT,MAXFLOAT,KX_CameraActuator,m_maxHeight), + KX_PYATTRIBUTE_FLOAT_RW("height",-MAXFLOAT,MAXFLOAT,KX_CameraActuator,m_height), + KX_PYATTRIBUTE_BOOL_RW("xy",KX_CameraActuator,m_x), + {NULL} +}; + PyObject* KX_CameraActuator::_getattr(const STR_String& attr) { + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_IActuator); } + +int KX_CameraActuator::_setattr(const STR_String& attr, PyObject* value) { + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_IActuator::_setattr(attr, value); +} + /* get obj ---------------------------------------------------------- */ const char KX_CameraActuator::GetObject_doc[] = "getObject(name_only = 1)\n" @@ -462,6 +483,7 @@ PyObject* KX_CameraActuator::PyGetMin(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getMin()", "the min property"); return PyFloat_FromDouble(m_minHeight); } /* set min ---------------------------------------------------------- */ @@ -472,6 +494,7 @@ PyObject* KX_CameraActuator::PySetMin(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setMin()", "the min property"); float min; if(PyArg_ParseTuple(args,"f", &min)) { @@ -488,6 +511,7 @@ PyObject* KX_CameraActuator::PyGetMax(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getMax()", "the max property"); return PyFloat_FromDouble(m_maxHeight); } /* set min ---------------------------------------------------------- */ @@ -498,6 +522,7 @@ PyObject* KX_CameraActuator::PySetMax(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getMax()", "the max property"); float max; if(PyArg_ParseTuple(args,"f", &max)) { @@ -514,6 +539,7 @@ PyObject* KX_CameraActuator::PyGetHeight(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getHeight()", "the height property"); return PyFloat_FromDouble(m_height); } /* set height ---------------------------------------------------------- */ @@ -524,6 +550,7 @@ PyObject* KX_CameraActuator::PySetHeight(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getHeight()", "the height property"); float height; if(PyArg_ParseTuple(args,"f", &height)) { @@ -541,6 +568,7 @@ PyObject* KX_CameraActuator::PySetXY(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setXY()", "the xy property"); int value; if(PyArg_ParseTuple(args,"i", &value)) { @@ -559,6 +587,7 @@ PyObject* KX_CameraActuator::PyGetXY(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getXY()", "the xy property"); return PyInt_FromLong(m_x); } diff --git a/source/gameengine/Ketsji/KX_CameraActuator.h b/source/gameengine/Ketsji/KX_CameraActuator.h index d53d12b3b82..4acca12833c 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.h +++ b/source/gameengine/Ketsji/KX_CameraActuator.h @@ -59,13 +59,13 @@ private : //const MT_Scalar m_maxHeight; /** height (float), */ - MT_Scalar m_height; + float m_height; /** min (float), */ - MT_Scalar m_minHeight; + float m_minHeight; /** max (float), */ - MT_Scalar m_maxHeight; + float m_maxHeight; /** xy toggle (pick one): true == x, false == y */ bool m_x; @@ -88,9 +88,9 @@ private : SCA_IObject *gameobj, //const CValue *ob, SCA_IObject *ob, - MT_Scalar hght, - MT_Scalar minhght, - MT_Scalar maxhght, + float hght, + float minhght, + float maxhght, bool xytog, PyTypeObject* T=&Type @@ -121,7 +121,8 @@ private : /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const STR_String& attr); - + virtual int _setattr(const STR_String& attr, PyObject* value); + /* set object to look at */ KX_PYMETHOD_DOC_O(KX_CameraActuator,SetObject); /* get current object */ diff --git a/source/gameengine/PyDoc/KX_CameraActuator.py b/source/gameengine/PyDoc/KX_CameraActuator.py index 9a9abaf3d57..c4d5c9bcbfc 100644 --- a/source/gameengine/PyDoc/KX_CameraActuator.py +++ b/source/gameengine/PyDoc/KX_CameraActuator.py @@ -6,6 +6,15 @@ class KX_CameraActuator(SCA_IActuator): """ Applies changes to a camera. + @ivar min: minimum distance to the target object maintained by the actuator + @type min: float + @ivar max: maximum distance to stay from the target object + @type max: float + @ivar height: height to stay above the target object + @type height: float + @ivar xy: axis this actuator is tracking, true=X, false=Y + @type xy: boolean + @author: snail """ def getObject(name_only = 1): -- cgit v1.2.3 From 915baae622233e89ae721ef2562732564e58fb27 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sun, 15 Feb 2009 19:07:27 +0000 Subject: BGE bug #18137 fixed: When two actors collide in this blend file the blender crashes. --- source/gameengine/Ketsji/KX_TouchSensor.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 1935a0bde39..849972955af 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -100,8 +100,8 @@ m_eventmgr(eventmgr) m_colliders = new CListValue(); KX_ClientObjectInfo *client_info = gameobj->getClientInfo(); - client_info->m_gameobject = gameobj; - client_info->m_auxilary_info = NULL; + //client_info->m_gameobject = gameobj; + //client_info->m_auxilary_info = NULL; client_info->m_sensors.push_back(this); m_physCtrl = dynamic_cast(gameobj->GetPhysicsController()); @@ -143,8 +143,8 @@ void KX_TouchSensor::ReParent(SCA_IObject* parent) // m_solidHandle = m_sumoObj->getObjectHandle(); KX_ClientObjectInfo *client_info = gameobj->getClientInfo(); - client_info->m_gameobject = gameobj; - client_info->m_auxilary_info = NULL; + //client_info->m_gameobject = gameobj; + //client_info->m_auxilary_info = NULL; client_info->m_sensors.push_back(this); SCA_ISensor::ReParent(parent); @@ -354,7 +354,7 @@ PyObject* KX_TouchSensor::PyGetHitObjectList(PyObject* self, if (spc) { KX_ClientObjectInfo* cl_inf = static_cast(spc->getNewClientInfo()); - if (m_touchedpropname == ((char*)cl_inf->m_auxilary_info)) { + if (NULL != cl_inf->m_auxilary_info && m_touchedpropname == ((char*)cl_inf->m_auxilary_info)) { newList->Add(m_colliders->GetValue(i)->AddRef()); } } -- cgit v1.2.3 From c3d74547befb549cb3104d39797519a32afb2f35 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Sun, 15 Feb 2009 23:26:00 +0000 Subject: SCons: * giving compileflags, cc_compileflags and cxx_compileflags to BlenderLib() now actually overrides any other setting (so there's no unclarity when ie. conflicting options are being specified in REL_CFLAGS et al). These are set after either release or debug flags, but before any *_WARN flags (so those stay maintained). * add cxx_compileflags for GE parts on win32-vc to have better performance. * NOTE: if platform maintainers (OSX and Linux) could check and do the same for their systems. Not vital, but probably very, very much welcomed by GE users. --- source/gameengine/BlenderRoutines/SConscript | 3 ++- source/gameengine/Expressions/SConscript | 7 ++++++- source/gameengine/GameLogic/SConscript | 7 ++++++- source/gameengine/GamePlayer/common/SConscript | 7 ++++--- source/gameengine/GamePlayer/ghost/SConscript | 8 +++++--- source/gameengine/Ketsji/KXNetwork/SConscript | 8 +++++++- source/gameengine/Ketsji/SConscript | 12 ++++++------ source/gameengine/Physics/Bullet/SConscript | 8 ++++---- source/gameengine/Physics/common/SConscript | 7 ++++++- source/gameengine/Rasterizer/RAS_OpenGLRasterizer/SConscript | 7 ++++++- source/gameengine/Rasterizer/SConscript | 10 +++++----- source/gameengine/SceneGraph/SConscript | 7 ++++++- source/gameengine/VideoTexture/SConscript | 11 ++++++----- 13 files changed, 69 insertions(+), 33 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/SConscript b/source/gameengine/BlenderRoutines/SConscript index 78adbc83d9b..7a1bf4d9ad6 100644 --- a/source/gameengine/BlenderRoutines/SConscript +++ b/source/gameengine/BlenderRoutines/SConscript @@ -25,5 +25,6 @@ incs += ' ' + env['BF_OPENGL_INC'] cxxflags = [] if env['OURPLATFORM']=='win32-vc': cxxflags.append ('/GR') + cxxflags.append ('/O2') -env.BlenderLib ( 'bf_bloutines', sources, Split(incs), [], libtype=['game', 'game2', 'player'], priority=[0, 0, 55] , compileflags=cxxflags) +env.BlenderLib ( 'bf_bloutines', sources, Split(incs), [], libtype=['game', 'game2', 'player'], priority=[0, 0, 55] , cxx_compileflags=cxxflags) diff --git a/source/gameengine/Expressions/SConscript b/source/gameengine/Expressions/SConscript index 809ac31371e..3d855d40623 100644 --- a/source/gameengine/Expressions/SConscript +++ b/source/gameengine/Expressions/SConscript @@ -6,4 +6,9 @@ sources = env.Glob('*.cpp') incs ='. #source/kernel/gen_system #intern/string #intern/moto/include' incs += ' ' + env['BF_PYTHON_INC'] -env.BlenderLib ( 'bf_expressions', sources, Split(incs), [], libtype=['game','player'], priority = [45,125] ) +cxxflags = [] +if env['OURPLATFORM']=='win32-vc': + cxxflags.append ('/GR') + cxxflags.append ('/O2') + +env.BlenderLib ( 'bf_expressions', sources, Split(incs), [], libtype=['game','player'], priority = [45,125], cxx_compileflags=cxxflags) diff --git a/source/gameengine/GameLogic/SConscript b/source/gameengine/GameLogic/SConscript index b4e2159dc22..ebf225f728f 100644 --- a/source/gameengine/GameLogic/SConscript +++ b/source/gameengine/GameLogic/SConscript @@ -17,4 +17,9 @@ if env['WITH_BF_SDL']: else: defs += ' DISABLE_SDL' -env.BlenderLib ( 'bf_logic', sources, Split(incs), Split(defs), libtype=['game','player'], priority=[30, 110] ) +cxxflags = [] +if env['OURPLATFORM']=='win32-vc': + cxxflags.append ('/GR') + cxxflags.append ('/O2') + +env.BlenderLib ( 'bf_logic', sources, Split(incs), Split(defs), libtype=['game','player'], priority=[30, 110], cxx_compileflags=cxxflags ) diff --git a/source/gameengine/GamePlayer/common/SConscript b/source/gameengine/GamePlayer/common/SConscript index 30f20a670d3..c9bda78d905 100644 --- a/source/gameengine/GamePlayer/common/SConscript +++ b/source/gameengine/GamePlayer/common/SConscript @@ -67,8 +67,9 @@ incs += Split(env['BF_SOLID_INC']) incs += Split(env['BF_PNG_INC']) incs += Split(env['BF_ZLIB_INC']) -cflags=[] +cxxflags = [] if env['OURPLATFORM']=='win32-vc': - cflags = ['/GR'] + cxxflags.append ('/GR') + cxxflags.append ('/O2') -env.BlenderLib (libname='gp_common', sources=source_files, includes=incs, defines = [], libtype='player', priority=5, compileflags=cflags) +env.BlenderLib (libname='gp_common', sources=source_files, includes=incs, defines = [], libtype='player', priority=5, cxx_compileflags=cxxflags) diff --git a/source/gameengine/GamePlayer/ghost/SConscript b/source/gameengine/GamePlayer/ghost/SConscript index 4f1324b3938..0785ce4bd0d 100644 --- a/source/gameengine/GamePlayer/ghost/SConscript +++ b/source/gameengine/GamePlayer/ghost/SConscript @@ -45,12 +45,14 @@ incs = ['.', incs += Split(env['BF_PYTHON_INC']) incs += Split(env['BF_SOLID_INC']) -cflags = [] + +cxxflags = [] if env['OURPLATFORM']=='win32-vc': - cflags = ['/GR'] + cxxflags.append ('/GR') + cxxflags.append ('/O2') defs = '' if env['WITH_BF_FFMPEG']: defs += ' WITH_FFMPEG' -env.BlenderLib (libname='gp_ghost', sources=source_files, includes = incs, defines = Split(defs), libtype='player',priority=0, compileflags=cflags) +env.BlenderLib (libname='gp_ghost', sources=source_files, includes = incs, defines = Split(defs), libtype='player',priority=0, cxx_compileflags=cxxflags) diff --git a/source/gameengine/Ketsji/KXNetwork/SConscript b/source/gameengine/Ketsji/KXNetwork/SConscript index 2297b96c19e..2476ed1f275 100644 --- a/source/gameengine/Ketsji/KXNetwork/SConscript +++ b/source/gameengine/Ketsji/KXNetwork/SConscript @@ -9,4 +9,10 @@ incs += ' #source/gameengine/Network' incs += ' ' + env['BF_PYTHON_INC'] -env.BlenderLib ( 'kx_network', Split(sources), Split(incs), defines=[],libtype=['game2', 'player'], priority=[5, 155] ) +cxxflags = [] +if env['OURPLATFORM']=='win32-vc': + cxxflags.append ('/GR') + cxxflags.append ('/O2') + + +env.BlenderLib ( 'kx_network', Split(sources), Split(incs), defines=[],libtype=['game2', 'player'], priority=[5, 155], cxx_compileflags=cxxflags ) diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript index f5c620b583f..e9e68f14df8 100644 --- a/source/gameengine/Ketsji/SConscript +++ b/source/gameengine/Ketsji/SConscript @@ -34,11 +34,6 @@ incs += ' #source/gameengine/Physics/Sumo #source/gameengine/Physics/Sumo/includ incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork' incs += ' #source/blender/misc #source/blender/blenloader #extern/glew/include #source/blender/gpu' -cflags = [] -if env['OURPLATFORM'] == 'win32-vc': - cflags.append('/GR') - cflags.append('/Ox') - incs += ' ' + env['BF_SOLID_INC'] incs += ' ' + env['BF_PYTHON_INC'] incs += ' ' + env['BF_BULLET_INC'] @@ -47,4 +42,9 @@ incs += ' ' + env['BF_OPENGL_INC'] if env['WITH_BF_SDL']: incs += ' ' + env['BF_SDL_INC'] -env.BlenderLib ( 'bf_ketsji', sources, Split(incs), [], libtype=['game','player'], priority=[25, 72], compileflags = cflags ) +cxxflags = [] +if env['OURPLATFORM']=='win32-vc': + cxxflags.append ('/GR') + cxxflags.append ('/O2') + +env.BlenderLib ( 'bf_ketsji', sources, Split(incs), [], libtype=['game','player'], priority=[25, 72], cxx_compileflags = cxxflags ) diff --git a/source/gameengine/Physics/Bullet/SConscript b/source/gameengine/Physics/Bullet/SConscript index 0936d45197a..0d5bf4933d8 100644 --- a/source/gameengine/Physics/Bullet/SConscript +++ b/source/gameengine/Physics/Bullet/SConscript @@ -7,9 +7,9 @@ incs = '. ../common #source/kernel/gen_system #intern/string #intern/moto/includ incs += ' ' + env['BF_BULLET_INC'] -cflags = [] +cxxflags = [] if env['OURPLATFORM']=='win32-vc': - cflags.append('/GR') - cflags.append('/O2') + cxxflags.append ('/GR') + cxxflags.append ('/O2') -env.BlenderLib ( 'bf_bullet', Split(sources), Split(incs), [], libtype=['game','player'], priority=[15,90] ) +env.BlenderLib ( 'bf_bullet', Split(sources), Split(incs), [], libtype=['game','player'], priority=[15,90], cxx_compileflags=cxxflags ) diff --git a/source/gameengine/Physics/common/SConscript b/source/gameengine/Physics/common/SConscript index 91c5101675e..474536e1f76 100644 --- a/source/gameengine/Physics/common/SConscript +++ b/source/gameengine/Physics/common/SConscript @@ -5,4 +5,9 @@ sources = 'PHY_IMotionState.cpp PHY_IPhysicsController.cpp PHY_IPhysicsEnvironme incs = '. ../Dummy #intern/moto/include' -env.BlenderLib ( 'bf_common', Split(sources), Split(incs), [], libtype=['game', 'game2','player'], priority=[20, 35, 95] ) +cxxflags = [] +if env['OURPLATFORM']=='win32-vc': + cxxflags.append ('/GR') + cxxflags.append ('/O2') + +env.BlenderLib ( 'bf_common', Split(sources), Split(incs), [], libtype=['game', 'game2','player'], priority=[20, 35, 95], cxx_compileflags = cxxflags ) diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/SConscript b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/SConscript index 8d46528f7f0..6731da9a776 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/SConscript +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/SConscript @@ -6,4 +6,9 @@ sources = env.Glob('*.cpp') incs = '. #source/kernel/gen_system #intern/string #intern/moto/include #source/gameengine/Rasterizer #source/gameengine/BlenderRoutines ' incs += ' #source/blender/gpu #extern/glew/include ' + env['BF_OPENGL_INC'] -env.BlenderLib ( 'bf_oglrasterizer', Split(sources), Split(incs), [], libtype=['game','player'], priority=[40, 120] ) +cxxflags = [] +if env['OURPLATFORM']=='win32-vc': + cxxflags.append ('/GR') + cxxflags.append ('/O2') + +env.BlenderLib ( 'bf_oglrasterizer', Split(sources), Split(incs), [], libtype=['game','player'], priority=[40, 120], cxx_compileflags = cxxflags ) diff --git a/source/gameengine/Rasterizer/SConscript b/source/gameengine/Rasterizer/SConscript index a024f7e0ee6..a16a04b8514 100644 --- a/source/gameengine/Rasterizer/SConscript +++ b/source/gameengine/Rasterizer/SConscript @@ -7,9 +7,9 @@ sources = env.Glob('*.cpp') incs = '. #source/kernel/gen_system #intern/string #intern/moto/include #source/gameengine/BlenderRoutines #extern/glew/include #source/gameengine/Expressions #source/blender/blenkernel #source/blender/makesdna' incs += ' ' + env['BF_PYTHON_INC'] +cxxflags = [] if env['OURPLATFORM']=='win32-vc': - cflags = [] - cflags.append('/Ox') - env.BlenderLib ( 'bf_rasterizer', sources, Split(incs), [], libtype=['game','player'], priority=[35,115], compileflags = cflags ) -else: - env.BlenderLib ( 'bf_rasterizer', sources, Split(incs), [], libtype=['game','player'], priority=[35,115] ) + cxxflags.append ('/GR') + cxxflags.append ('/O2') + +env.BlenderLib ( 'bf_rasterizer', sources, Split(incs), [], libtype=['game','player'], priority=[35,115], cxx_compileflags = cxxflags ) diff --git a/source/gameengine/SceneGraph/SConscript b/source/gameengine/SceneGraph/SConscript index 23c1c24c297..8ebf9c0b850 100644 --- a/source/gameengine/SceneGraph/SConscript +++ b/source/gameengine/SceneGraph/SConscript @@ -6,4 +6,9 @@ sources = env.Glob('*.cpp') #'SG_BBox.cpp SG_Controller.cpp SG_IObject.cpp SG_No incs = '. #intern/moto/include' -env.BlenderLib ( 'bf_scenegraph', sources, Split(incs), [], libtype=['game','player'], priority=[50,130] ) +cxxflags = [] +if env['OURPLATFORM']=='win32-vc': + cxxflags.append ('/GR') + cxxflags.append ('/O2') + +env.BlenderLib ( 'bf_scenegraph', sources, Split(incs), [], libtype=['game','player'], priority=[50,130], cxx_compileflags = cxxflags ) diff --git a/source/gameengine/VideoTexture/SConscript b/source/gameengine/VideoTexture/SConscript index f3fe0dab6ad..28737ed06e5 100644 --- a/source/gameengine/VideoTexture/SConscript +++ b/source/gameengine/VideoTexture/SConscript @@ -15,11 +15,12 @@ incs += ' #source/blender/gpu #source/kernel/gen_system #intern/string #intern/m incs += ' #intern/guardedalloc #intern/SoundSystem' incs += ' #extern/glew/include' -cflags = [] defs = '' -if env['OURPLATFORM'] == 'win32-vc': - cflags.append('/GR') - cflags.append('/Ox') +cxxflags = [] +if env['OURPLATFORM']=='win32-vc': + cxxflags.append ('/GR') + cxxflags.append ('/O2') + incs += ' ' + env['BF_PYTHON_INC'] #incs += ' ' + env['BF_OPENGL_INC'] @@ -29,4 +30,4 @@ if env['WITH_BF_FFMPEG']: incs += ' ' + env['BF_FFMPEG_INC'] defs += ' __STDC_CONSTANT_MACROS' -env.BlenderLib ( 'bf_videotex', sources, Split(incs), Split(defs), libtype=['game','player'], priority=[25, 72], compileflags = cflags ) +env.BlenderLib ( 'bf_videotex', sources, Split(incs), Split(defs), libtype=['game','player'], priority=[25, 72], cxx_compileflags = cxxflags ) -- cgit v1.2.3 From 92d4ef0939c82e5654f899fe8e55e7a2cccbf6a0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 19 Feb 2009 07:01:49 +0000 Subject: Accept negative indices's for ListValues scene.getObjectList()[-1] works like a python sequence. removed some STR_String creation that was only used to do comparisons, in a simple expressions benchmark this made logic use 4% less overall. --- source/gameengine/Expressions/InputParser.cpp | 19 ++++++++----------- source/gameengine/Expressions/ListValue.cpp | 10 +++++++--- source/gameengine/Expressions/PyObjectPlus.cpp | 12 +++++++----- source/gameengine/Ketsji/KX_TouchSensor.cpp | 2 +- 4 files changed, 23 insertions(+), 20 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/InputParser.cpp b/source/gameengine/Expressions/InputParser.cpp index 32a9de32e21..c3869d8f89b 100644 --- a/source/gameengine/Expressions/InputParser.cpp +++ b/source/gameengine/Expressions/InputParser.cpp @@ -272,32 +272,29 @@ void CParser::NextSym() || ((ch >= 'A') && (ch <= 'Z'))) { // reserved word? int start; - STR_String funstr; start = chcount; CharRep(); GrabString(start); - funstr = const_as_string; - funstr.Upper(); - if (funstr == STR_String("SUM")) { + if (!strcasecmp(const_as_string, "SUM")) { sym = sumsym; } - else if (funstr == STR_String("NOT")) { + else if (!strcasecmp(const_as_string, "NOT")) { sym = opsym; opkind = OPnot; } - else if (funstr == STR_String("AND")) { + else if (!strcasecmp(const_as_string, "AND")) { sym = opsym; opkind = OPand; } - else if (funstr == STR_String("OR")) { + else if (!strcasecmp(const_as_string, "OR")) { sym = opsym; opkind = OPor; } - else if (funstr == STR_String("IF")) { + else if (!strcasecmp(const_as_string, "IF")) sym = ifsym; - } else if (funstr == STR_String("WHOMADE")) { + else if (!strcasecmp(const_as_string, "WHOMADE")) sym = whocodedsym; - } else if (funstr == STR_String("FALSE")) { + else if (!strcasecmp(const_as_string, "FALSE")) { sym = constsym; constkind = booltype; boolvalue = false; - } else if (funstr == STR_String("TRUE")) { + } else if (!strcasecmp(const_as_string, "TRUE")) { sym = constsym; constkind = booltype; boolvalue = true; } else { sym = idsym; diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 9ffdbb1223c..b7236afdee4 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -34,7 +34,12 @@ Py_ssize_t listvalue_bufferlen(PyObject* list) PyObject* listvalue_buffer_item(PyObject* list,Py_ssize_t index) { - if (index >= 0 && index < ((CListValue*) list)->GetCount()) + int count = ((CListValue*) list)->GetCount(); + + if (index < 0) + index = count+index; + + if (index >= 0 && index < count) { PyObject* pyobj = ((CListValue*) list)->GetValue(index)->ConvertValueToPython(); if (pyobj) @@ -64,8 +69,7 @@ PyObject* listvalue_mapping_subscript(PyObject* list,PyObject* pyindex) } PyObject *pyindex_str = PyObject_Repr(pyindex); /* new ref */ - STR_String index_str(PyString_AsString(pyindex_str)); - PyErr_Format(PyExc_KeyError, "'%s' not in list", index_str.Ptr()); + PyErr_Format(PyExc_KeyError, "'%s' not in list", PyString_AsString(pyindex_str)); Py_DECREF(pyindex_str); return NULL; } diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 8fd99c8d267..19f458b69a6 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -94,7 +94,7 @@ PyObjectPlus::PyObjectPlus(PyTypeObject *T) // constructor * PyObjectPlus Methods -- Every class, even the abstract one should have a Methods ------------------------------*/ PyMethodDef PyObjectPlus::Methods[] = { - {"isA", (PyCFunction) sPy_isA, METH_VARARGS}, + {"isA", (PyCFunction) sPy_isA, METH_O}, {NULL, NULL} /* Sentinel */ }; @@ -688,19 +688,21 @@ bool PyObjectPlus::isA(const char *mytypename) // check typename of each parent for (P = Ps[i=0]; P != NULL; P = Ps[i++]) { - if (STR_String(P->tp_name) == STR_String(mytypename) ) + if (strcmp(P->tp_name, mytypename)==0) return true; } return false; } -PyObject *PyObjectPlus::Py_isA(PyObject *args) // Python wrapper for isA +PyObject *PyObjectPlus::Py_isA(PyObject *value) // Python wrapper for isA { char *mytypename; - if (!PyArg_ParseTuple(args, "s", &mytypename)) + if (!PyString_Check(value)) { + PyErr_SetString(PyExc_TypeError, "expected a string"); return NULL; - if(isA(mytypename)) + } + if(isA(PyString_AsString(value))) Py_RETURN_TRUE; else Py_RETURN_FALSE; diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 849972955af..0000d5793b6 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -199,7 +199,7 @@ bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll { if (client_info->m_auxilary_info) { - found = (m_touchedpropname == STR_String((char*)client_info->m_auxilary_info)); + found = (!strcmp(m_touchedpropname.Ptr(), (char*)client_info->m_auxilary_info)); } } else { -- cgit v1.2.3 From c597863783e1001dca599e6dcbc28048f0ef4ce1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 19 Feb 2009 10:34:51 +0000 Subject: "object" and "objectLastCreated" attribute for actuators, deprecates getObject/setObject() & getLastCreatedObject() also removed some warnings --- .../gameengine/Converter/BL_ShapeActionActuator.h | 2 +- source/gameengine/Ketsji/KX_CameraActuator.cpp | 37 +++++++++++++++++-- source/gameengine/Ketsji/KX_ParentActuator.cpp | 36 ++++++++++++++++++- source/gameengine/Ketsji/KX_ParentActuator.h | 1 + .../gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp | 42 ++++++++++++++++++++-- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.h | 15 ++++---- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 38 ++++++++++++++++++-- source/gameengine/Ketsji/KX_TrackToActuator.h | 1 + source/gameengine/PyDoc/KX_CameraActuator.py | 3 +- source/gameengine/PyDoc/KX_ParentActuator.py | 3 ++ .../gameengine/PyDoc/KX_SCA_AddObjectActuator.py | 4 +++ source/gameengine/PyDoc/KX_TrackToActuator.py | 2 ++ 12 files changed, 167 insertions(+), 17 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.h b/source/gameengine/Converter/BL_ShapeActionActuator.h index b521c0d98a6..47ceb9aa995 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.h +++ b/source/gameengine/Converter/BL_ShapeActionActuator.h @@ -169,8 +169,8 @@ protected: short m_playtype; short m_priority; struct bAction *m_action; - STR_String m_propname; STR_String m_framepropname; + STR_String m_propname; vector m_blendshape; }; diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 98dd9ab3e68..4ac097eb575 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -398,9 +398,9 @@ PyParentObject KX_CameraActuator::Parents[] = { }; PyMethodDef KX_CameraActuator::Methods[] = { + // ---> deprecated (all) {"setObject",(PyCFunction) KX_CameraActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc}, {"getObject",(PyCFunction) KX_CameraActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc}, - // ---> deprecated {"setMin" ,(PyCFunction) KX_CameraActuator::sPySetMin, METH_VARARGS, (PY_METHODCHAR)SetMin_doc}, {"getMin" ,(PyCFunction) KX_CameraActuator::sPyGetMin, METH_NOARGS, (PY_METHODCHAR)GetMin_doc}, {"setMax" ,(PyCFunction) KX_CameraActuator::sPySetMax, METH_VARARGS, (PY_METHODCHAR)SetMax_doc}, @@ -421,14 +421,40 @@ PyAttributeDef KX_CameraActuator::Attributes[] = { }; PyObject* KX_CameraActuator::_getattr(const STR_String& attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object; + + if (attr == "object") { + if (!m_ob) Py_RETURN_NONE; + else return m_ob->AddRef(); + } + + object = _getattr_self(Attributes, this, attr); if (object != NULL) return object; _getattr_up(SCA_IActuator); } int KX_CameraActuator::_setattr(const STR_String& attr, PyObject* value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret; + + if (attr == "object") { + KX_GameObject *gameobj; + + if (!ConvertPythonToGameObject(value, &gameobj, true)) + return 1; // ConvertPythonToGameObject sets the error + + if (m_ob != NULL) + m_ob->UnregisterActuator(this); + + m_ob = (SCA_IObject*)gameobj; + + if (m_ob) + m_ob->RegisterActuator(this); + + return 0; + } + + ret = _setattr_self(Attributes, this, attr, value); if (ret >= 0) return ret; return SCA_IActuator::_setattr(attr, value); @@ -442,6 +468,9 @@ const char KX_CameraActuator::GetObject_doc[] = PyObject* KX_CameraActuator::PyGetObject(PyObject* self, PyObject* args) { int ret_name_only = 1; + + ShowDeprecationWarning("getObject()", "the object property"); + if (!PyArg_ParseTuple(args, "|i", &ret_name_only)) return NULL; @@ -462,6 +491,8 @@ PyObject* KX_CameraActuator::PySetObject(PyObject* self, PyObject* value) { KX_GameObject *gameobj; + ShowDeprecationWarning("setObject()", "the object property"); + if (!ConvertPythonToGameObject(value, &gameobj, true)) return NULL; // ConvertPythonToGameObject sets the error diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index 89549ca6b57..c7ac52e571a 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -166,15 +166,44 @@ PyParentObject KX_ParentActuator::Parents[] = { }; PyMethodDef KX_ParentActuator::Methods[] = { + // ---> deprecated (all) {"setObject", (PyCFunction) KX_ParentActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc}, {"getObject", (PyCFunction) KX_ParentActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc}, {NULL,NULL} //Sentinel }; -PyObject* KX_ParentActuator::_getattr(const STR_String& attr) { +PyObject* KX_ParentActuator::_getattr(const STR_String& attr) { + + if (attr == "object") { + if (!m_ob) Py_RETURN_NONE; + else return m_ob->AddRef(); + } + _getattr_up(SCA_IActuator); } +int KX_ParentActuator::_setattr(const STR_String& attr, PyObject* value) { + + if (attr == "object") { + KX_GameObject *gameobj; + + if (!ConvertPythonToGameObject(value, &gameobj, true)) + return 1; // ConvertPythonToGameObject sets the error + + if (m_ob != NULL) + m_ob->UnregisterActuator(this); + + m_ob = (SCA_IObject*)gameobj; + + if (m_ob) + m_ob->RegisterActuator(this); + + return 0; + } + + return SCA_IActuator::_setattr(attr, value); +} + /* 1. setObject */ const char KX_ParentActuator::SetObject_doc[] = "setObject(object)\n" @@ -183,6 +212,8 @@ const char KX_ParentActuator::SetObject_doc[] = PyObject* KX_ParentActuator::PySetObject(PyObject* self, PyObject* value) { KX_GameObject *gameobj; + ShowDeprecationWarning("setObject()", "the object property"); + if (!ConvertPythonToGameObject(value, &gameobj, true)) return NULL; // ConvertPythonToGameObject sets the error @@ -206,6 +237,9 @@ const char KX_ParentActuator::GetObject_doc[] = PyObject* KX_ParentActuator::PyGetObject(PyObject* self, PyObject* args) { int ret_name_only = 1; + + ShowDeprecationWarning("getObject()", "the object property"); + if (!PyArg_ParseTuple(args, "|i", &ret_name_only)) return NULL; diff --git a/source/gameengine/Ketsji/KX_ParentActuator.h b/source/gameengine/Ketsji/KX_ParentActuator.h index e2b30ba2d0f..e082b4fc209 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.h +++ b/source/gameengine/Ketsji/KX_ParentActuator.h @@ -77,6 +77,7 @@ class KX_ParentActuator : public SCA_IActuator /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject* value); /* 1. setObject */ KX_PYMETHOD_DOC_O(KX_ParentActuator,SetObject); diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index 5777f54b799..ab65c93529e 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -188,9 +188,7 @@ PyParentObject KX_SCA_AddObjectActuator::Parents[] = { NULL }; PyMethodDef KX_SCA_AddObjectActuator::Methods[] = { - {"setObject", (PyCFunction) KX_SCA_AddObjectActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc}, {"setTime", (PyCFunction) KX_SCA_AddObjectActuator::sPySetTime, METH_O, (PY_METHODCHAR)SetTime_doc}, - {"getObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc}, {"getTime", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetTime, METH_NOARGS, (PY_METHODCHAR)GetTime_doc}, {"getLinearVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLinearVelocity, METH_NOARGS, (PY_METHODCHAR)GetLinearVelocity_doc}, {"setLinearVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPySetLinearVelocity, METH_VARARGS, (PY_METHODCHAR)SetLinearVelocity_doc}, @@ -199,15 +197,50 @@ PyMethodDef KX_SCA_AddObjectActuator::Methods[] = { {"getLastCreatedObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetLastCreatedObject, METH_NOARGS,"getLastCreatedObject() : get the object handle to the last created object\n"}, {"instantAddObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyInstantAddObject, METH_NOARGS,"instantAddObject() : immediately add object without delay\n"}, + // ---> deprecated + {"setObject", (PyCFunction) KX_SCA_AddObjectActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc}, + {"getObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc}, + {NULL,NULL} //Sentinel }; PyObject* KX_SCA_AddObjectActuator::_getattr(const STR_String& attr) { + if (attr == "object") { + if (!m_OriginalObject) Py_RETURN_NONE; + else return m_OriginalObject->AddRef(); + } + else if (attr == "objectLastCreated") { + if (!m_OriginalObject) Py_RETURN_NONE; + else return m_lastCreatedObject->AddRef(); + } + _getattr_up(SCA_IActuator); } +int KX_SCA_AddObjectActuator::_setattr(const STR_String& attr, PyObject* value) { + + if (attr == "object") { + KX_GameObject *gameobj; + + if (!ConvertPythonToGameObject(value, &gameobj, true)) + return 1; // ConvertPythonToGameObject sets the error + + if (m_OriginalObject != NULL) + m_OriginalObject->UnregisterActuator(this); + + m_OriginalObject = (SCA_IObject*)gameobj; + + if (m_OriginalObject) + m_OriginalObject->RegisterActuator(this); + + return 0; + } + + return SCA_IActuator::_setattr(attr, value); +} + /* 1. setObject */ const char KX_SCA_AddObjectActuator::SetObject_doc[] = "setObject(object)\n" @@ -218,6 +251,8 @@ PyObject* KX_SCA_AddObjectActuator::PySetObject(PyObject* self, PyObject* value) { KX_GameObject *gameobj; + ShowDeprecationWarning("setObject()", "the object property"); + if (!ConvertPythonToGameObject(value, &gameobj, true)) return NULL; // ConvertPythonToGameObject sets the error @@ -277,6 +312,9 @@ const char KX_SCA_AddObjectActuator::GetObject_doc[] = PyObject* KX_SCA_AddObjectActuator::PyGetObject(PyObject* self, PyObject* args) { int ret_name_only = 1; + + ShowDeprecationWarning("getObject()", "the object property"); + if (!PyArg_ParseTuple(args, "|i", &ret_name_only)) return NULL; diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h index 278d4180284..035f44f16c9 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h @@ -60,13 +60,16 @@ class KX_SCA_AddObjectActuator : public SCA_IActuator /// Linear velocity upon creation of the object. MT_Vector3 m_linear_velocity; + /// Apply the velocity locally + bool m_localLinvFlag; /// Angular velocity upon creation of the object. MT_Vector3 m_angular_velocity; - /// Apply the velocity locally - bool m_localLinvFlag; - bool m_localAngvFlag; + bool m_localAngvFlag; + + + SCA_IObject* m_lastCreatedObject; @@ -107,10 +110,8 @@ public: virtual bool Update(); - virtual PyObject* - _getattr( - const STR_String& attr - ); + virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject* value); SCA_IObject* GetLastCreatedObject( diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index acc4a6ab5d7..515349fbba8 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -456,12 +456,15 @@ PyParentObject KX_TrackToActuator::Parents[] = { PyMethodDef KX_TrackToActuator::Methods[] = { - {"setObject", (PyCFunction) KX_TrackToActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc}, - {"getObject", (PyCFunction) KX_TrackToActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc}, {"setTime", (PyCFunction) KX_TrackToActuator::sPySetTime, METH_VARARGS, (PY_METHODCHAR)SetTime_doc}, {"getTime", (PyCFunction) KX_TrackToActuator::sPyGetTime, METH_VARARGS, (PY_METHODCHAR)GetTime_doc}, {"setUse3D", (PyCFunction) KX_TrackToActuator::sPySetUse3D, METH_VARARGS, (PY_METHODCHAR)SetUse3D_doc}, {"getUse3D", (PyCFunction) KX_TrackToActuator::sPyGetUse3D, METH_VARARGS, (PY_METHODCHAR)GetUse3D_doc}, + + // ---> deprecated + {"setObject", (PyCFunction) KX_TrackToActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc}, + {"getObject", (PyCFunction) KX_TrackToActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc}, + {NULL,NULL} //Sentinel }; @@ -469,10 +472,36 @@ PyMethodDef KX_TrackToActuator::Methods[] = { PyObject* KX_TrackToActuator::_getattr(const STR_String& attr) { + if (attr == "object") { + if (!m_object) Py_RETURN_NONE; + else return m_object->AddRef(); + } + _getattr_up(SCA_IActuator); } +int KX_TrackToActuator::_setattr(const STR_String& attr, PyObject* value) { + int ret; + + if (attr == "object") { + KX_GameObject *gameobj; + + if (!ConvertPythonToGameObject(value, &gameobj, true)) + return 1; // ConvertPythonToGameObject sets the error + + if (m_object != NULL) + m_object->UnregisterActuator(this); + m_object = (SCA_IObject*)gameobj; + + if (m_object) + m_object->RegisterActuator(this); + + return 0; + } + + return SCA_IActuator::_setattr(attr, value); +} /* 1. setObject */ const char KX_TrackToActuator::SetObject_doc[] = @@ -483,6 +512,8 @@ PyObject* KX_TrackToActuator::PySetObject(PyObject* self, PyObject* value) { KX_GameObject *gameobj; + ShowDeprecationWarning("setObject()", "the object property"); + if (!ConvertPythonToGameObject(value, &gameobj, true)) return NULL; // ConvertPythonToGameObject sets the error @@ -506,6 +537,9 @@ const char KX_TrackToActuator::GetObject_doc[] = PyObject* KX_TrackToActuator::PyGetObject(PyObject* self, PyObject* args) { int ret_name_only = 1; + + ShowDeprecationWarning("getObject()", "the object property"); + if (!PyArg_ParseTuple(args, "|i", &ret_name_only)) return NULL; diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.h b/source/gameengine/Ketsji/KX_TrackToActuator.h index 445132a6094..c9cae905240 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.h +++ b/source/gameengine/Ketsji/KX_TrackToActuator.h @@ -73,6 +73,7 @@ class KX_TrackToActuator : public SCA_IActuator /* Python part */ virtual PyObject* _getattr(const STR_String& attr); + virtual int _setattr(const STR_String& attr, PyObject* value); /* 1. setObject */ KX_PYMETHOD_DOC_O(KX_TrackToActuator,SetObject); diff --git a/source/gameengine/PyDoc/KX_CameraActuator.py b/source/gameengine/PyDoc/KX_CameraActuator.py index c4d5c9bcbfc..6ffc55a5854 100644 --- a/source/gameengine/PyDoc/KX_CameraActuator.py +++ b/source/gameengine/PyDoc/KX_CameraActuator.py @@ -14,7 +14,8 @@ class KX_CameraActuator(SCA_IActuator): @type height: float @ivar xy: axis this actuator is tracking, true=X, false=Y @type xy: boolean - + @ivar object: the object this actuator tracks. + @type object: KX_GameObject or None @author: snail """ def getObject(name_only = 1): diff --git a/source/gameengine/PyDoc/KX_ParentActuator.py b/source/gameengine/PyDoc/KX_ParentActuator.py index 6d6e0937257..7b5625ec82d 100644 --- a/source/gameengine/PyDoc/KX_ParentActuator.py +++ b/source/gameengine/PyDoc/KX_ParentActuator.py @@ -5,6 +5,9 @@ from SCA_IActuator import * class KX_ParentActuator(SCA_IActuator): """ The parent actuator can set or remove an objects parent object. + + @ivar object: the object this actuator sets the parent too. + @type object: KX_GameObject or None """ def setObject(object): """ diff --git a/source/gameengine/PyDoc/KX_SCA_AddObjectActuator.py b/source/gameengine/PyDoc/KX_SCA_AddObjectActuator.py index c3b2e947ddb..56068fa641a 100644 --- a/source/gameengine/PyDoc/KX_SCA_AddObjectActuator.py +++ b/source/gameengine/PyDoc/KX_SCA_AddObjectActuator.py @@ -5,6 +5,10 @@ from SCA_IActuator import * class KX_SCA_AddObjectActuator(SCA_IActuator): """ Edit Object Actuator (in Add Object Mode) + @ivar object: the object this actuator adds. + @type object: KX_GameObject or None + @ivar objectLastCreated: the last added object from this actuator (read only). + @type objectLastCreated: KX_GameObject or None @warning: An Add Object actuator will be ignored if at game start, the linked object doesn't exist (or is empty) or the linked object is in an active layer. diff --git a/source/gameengine/PyDoc/KX_TrackToActuator.py b/source/gameengine/PyDoc/KX_TrackToActuator.py index 948302991b7..730ab21166b 100644 --- a/source/gameengine/PyDoc/KX_TrackToActuator.py +++ b/source/gameengine/PyDoc/KX_TrackToActuator.py @@ -13,6 +13,8 @@ class KX_TrackToActuator(SCA_IActuator): C{ERROR: GameObject I{OBName} no object in EditObjectActuator I{ActuatorName}} + @ivar object: the object this actuator tracks. + @type object: KX_GameObject or None """ def setObject(object): """ -- cgit v1.2.3 From cdec2b3d15ab0448e4df70496285ed95681e5972 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 19 Feb 2009 13:42:07 +0000 Subject: BGE Python API Use 'const char *' rather then the C++ 'STR_String' type for the attribute identifier of python attributes. Each attribute and method access from python was allocating and freeing the string. A simple test with getting an attribute a loop shows this speeds up attribute lookups a bit over 2x. --- source/gameengine/Converter/BL_ActionActuator.cpp | 8 +- source/gameengine/Converter/BL_ActionActuator.h | 4 +- .../Converter/BL_BlenderDataConversion.cpp | 2 +- .../Converter/BL_ShapeActionActuator.cpp | 8 +- .../gameengine/Converter/BL_ShapeActionActuator.h | 4 +- source/gameengine/Expressions/ListValue.cpp | 2 +- source/gameengine/Expressions/ListValue.h | 2 +- source/gameengine/Expressions/PyObjectPlus.cpp | 18 ++-- source/gameengine/Expressions/PyObjectPlus.h | 18 ++-- source/gameengine/Expressions/Value.cpp | 15 ++-- source/gameengine/Expressions/Value.h | 6 +- .../gameengine/GameLogic/SCA_2DFilterActuator.cpp | 2 +- source/gameengine/GameLogic/SCA_2DFilterActuator.h | 2 +- source/gameengine/GameLogic/SCA_ANDController.cpp | 2 +- source/gameengine/GameLogic/SCA_ANDController.h | 2 +- source/gameengine/GameLogic/SCA_ActuatorSensor.cpp | 4 +- source/gameengine/GameLogic/SCA_ActuatorSensor.h | 4 +- source/gameengine/GameLogic/SCA_AlwaysSensor.cpp | 2 +- source/gameengine/GameLogic/SCA_AlwaysSensor.h | 2 +- source/gameengine/GameLogic/SCA_DelaySensor.cpp | 4 +- source/gameengine/GameLogic/SCA_DelaySensor.h | 4 +- .../GameLogic/SCA_ExpressionController.h | 2 +- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 4 +- source/gameengine/GameLogic/SCA_ILogicBrick.h | 4 +- source/gameengine/GameLogic/SCA_IObject.cpp | 2 +- source/gameengine/GameLogic/SCA_IObject.h | 2 +- source/gameengine/GameLogic/SCA_ISensor.cpp | 8 +- source/gameengine/GameLogic/SCA_ISensor.h | 4 +- source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 14 ++-- source/gameengine/GameLogic/SCA_JoystickSensor.h | 4 +- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 4 +- source/gameengine/GameLogic/SCA_KeyboardSensor.h | 4 +- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 4 +- source/gameengine/GameLogic/SCA_MouseSensor.h | 4 +- source/gameengine/GameLogic/SCA_NANDController.cpp | 2 +- source/gameengine/GameLogic/SCA_NANDController.h | 2 +- source/gameengine/GameLogic/SCA_NORController.cpp | 2 +- source/gameengine/GameLogic/SCA_NORController.h | 2 +- source/gameengine/GameLogic/SCA_ORController.cpp | 2 +- source/gameengine/GameLogic/SCA_ORController.h | 2 +- .../gameengine/GameLogic/SCA_PropertyActuator.cpp | 4 +- source/gameengine/GameLogic/SCA_PropertyActuator.h | 4 +- source/gameengine/GameLogic/SCA_PropertySensor.cpp | 4 +- source/gameengine/GameLogic/SCA_PropertySensor.h | 4 +- .../gameengine/GameLogic/SCA_PythonController.cpp | 35 +++++--- source/gameengine/GameLogic/SCA_PythonController.h | 4 +- source/gameengine/GameLogic/SCA_RandomActuator.cpp | 8 +- source/gameengine/GameLogic/SCA_RandomActuator.h | 4 +- source/gameengine/GameLogic/SCA_RandomSensor.cpp | 8 +- source/gameengine/GameLogic/SCA_RandomSensor.h | 4 +- source/gameengine/GameLogic/SCA_XNORController.cpp | 2 +- source/gameengine/GameLogic/SCA_XNORController.h | 2 +- source/gameengine/GameLogic/SCA_XORController.cpp | 2 +- source/gameengine/GameLogic/SCA_XORController.h | 2 +- source/gameengine/Ketsji/BL_Shader.cpp | 2 +- source/gameengine/Ketsji/BL_Shader.h | 2 +- source/gameengine/Ketsji/BL_Texture.cpp | 2 +- .../Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp | 2 +- .../Ketsji/KXNetwork/KX_NetworkMessageActuator.h | 2 +- .../Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp | 2 +- .../Ketsji/KXNetwork/KX_NetworkMessageSensor.h | 2 +- source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 4 +- source/gameengine/Ketsji/KX_BlenderMaterial.h | 4 +- source/gameengine/Ketsji/KX_CDActuator.cpp | 2 +- source/gameengine/Ketsji/KX_CDActuator.h | 2 +- source/gameengine/Ketsji/KX_Camera.cpp | 40 ++++----- source/gameengine/Ketsji/KX_Camera.h | 4 +- source/gameengine/Ketsji/KX_CameraActuator.cpp | 8 +- source/gameengine/Ketsji/KX_CameraActuator.h | 4 +- source/gameengine/Ketsji/KX_ConstraintActuator.cpp | 2 +- source/gameengine/Ketsji/KX_ConstraintActuator.h | 2 +- source/gameengine/Ketsji/KX_ConstraintWrapper.cpp | 14 ++-- source/gameengine/Ketsji/KX_ConstraintWrapper.h | 4 +- source/gameengine/Ketsji/KX_GameActuator.cpp | 2 +- source/gameengine/Ketsji/KX_GameActuator.h | 2 +- source/gameengine/Ketsji/KX_GameObject.cpp | 38 +++++---- source/gameengine/Ketsji/KX_GameObject.h | 14 +--- source/gameengine/Ketsji/KX_IpoActuator.cpp | 2 +- source/gameengine/Ketsji/KX_IpoActuator.h | 2 +- source/gameengine/Ketsji/KX_Light.cpp | 60 +++++++------- source/gameengine/Ketsji/KX_Light.h | 4 +- source/gameengine/Ketsji/KX_MeshProxy.cpp | 4 +- source/gameengine/Ketsji/KX_MeshProxy.h | 2 +- source/gameengine/Ketsji/KX_MouseFocusSensor.cpp | 2 +- source/gameengine/Ketsji/KX_MouseFocusSensor.h | 2 +- source/gameengine/Ketsji/KX_NearSensor.cpp | 2 +- source/gameengine/Ketsji/KX_NearSensor.h | 2 +- source/gameengine/Ketsji/KX_ObjectActuator.cpp | 2 +- source/gameengine/Ketsji/KX_ObjectActuator.h | 2 +- source/gameengine/Ketsji/KX_ParentActuator.cpp | 8 +- source/gameengine/Ketsji/KX_ParentActuator.h | 4 +- .../gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp | 10 +-- source/gameengine/Ketsji/KX_PhysicsObjectWrapper.h | 4 +- source/gameengine/Ketsji/KX_PolyProxy.cpp | 23 +++--- source/gameengine/Ketsji/KX_PolyProxy.h | 2 +- source/gameengine/Ketsji/KX_PolygonMaterial.cpp | 4 +- source/gameengine/Ketsji/KX_PolygonMaterial.h | 4 +- source/gameengine/Ketsji/KX_RadarSensor.cpp | 2 +- source/gameengine/Ketsji/KX_RadarSensor.h | 2 +- source/gameengine/Ketsji/KX_RaySensor.cpp | 2 +- source/gameengine/Ketsji/KX_RaySensor.h | 2 +- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp | 8 +- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.h | 4 +- .../gameengine/Ketsji/KX_SCA_DynamicActuator.cpp | 2 +- source/gameengine/Ketsji/KX_SCA_DynamicActuator.h | 5 +- .../gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp | 2 +- .../gameengine/Ketsji/KX_SCA_EndObjectActuator.h | 5 +- .../Ketsji/KX_SCA_ReplaceMeshActuator.cpp | 2 +- .../gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h | 5 +- source/gameengine/Ketsji/KX_Scene.cpp | 23 +++--- source/gameengine/Ketsji/KX_Scene.h | 6 +- source/gameengine/Ketsji/KX_SceneActuator.cpp | 2 +- source/gameengine/Ketsji/KX_SceneActuator.h | 2 +- source/gameengine/Ketsji/KX_SoundActuator.cpp | 2 +- source/gameengine/Ketsji/KX_SoundActuator.h | 2 +- source/gameengine/Ketsji/KX_StateActuator.cpp | 5 +- source/gameengine/Ketsji/KX_StateActuator.h | 2 +- source/gameengine/Ketsji/KX_TouchSensor.cpp | 2 +- source/gameengine/Ketsji/KX_TouchSensor.h | 2 +- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 8 +- source/gameengine/Ketsji/KX_TrackToActuator.h | 4 +- source/gameengine/Ketsji/KX_VehicleWrapper.cpp | 4 +- source/gameengine/Ketsji/KX_VehicleWrapper.h | 4 +- source/gameengine/Ketsji/KX_VertexProxy.cpp | 96 +++++++++++----------- source/gameengine/Ketsji/KX_VertexProxy.h | 4 +- source/gameengine/Ketsji/KX_VisibilityActuator.cpp | 5 +- source/gameengine/Ketsji/KX_VisibilityActuator.h | 2 +- 127 files changed, 392 insertions(+), 403 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 65d6892fa6d..22c6c95b158 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -1035,8 +1035,8 @@ PyAttributeDef BL_ActionActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* BL_ActionActuator::_getattr(const STR_String& attr) { - if (attr == "action") +PyObject* BL_ActionActuator::_getattr(const char *attr) { + if (!strcmp(attr, "action")) return PyString_FromString(m_action->id.name+2); PyObject* object = _getattr_self(Attributes, this, attr); if (object != NULL) @@ -1044,8 +1044,8 @@ PyObject* BL_ActionActuator::_getattr(const STR_String& attr) { _getattr_up(SCA_IActuator); } -int BL_ActionActuator::_setattr(const STR_String& attr, PyObject* value) { - if (attr == "action") +int BL_ActionActuator::_setattr(const char *attr, PyObject* value) { + if (!strcmp(attr, "action")) { if (!PyString_Check(value)) { diff --git a/source/gameengine/Converter/BL_ActionActuator.h b/source/gameengine/Converter/BL_ActionActuator.h index 6e291106553..6161048afb8 100644 --- a/source/gameengine/Converter/BL_ActionActuator.h +++ b/source/gameengine/Converter/BL_ActionActuator.h @@ -110,8 +110,8 @@ public: KX_PYMETHOD_DOC(BL_ActionActuator,setChannel); - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject* value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject* value); /* attribute check */ static int CheckFrame(void *self, const PyAttributeDef*) diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 9c699b67b28..2fa3e192179 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -361,7 +361,7 @@ BL_Material* ConvertMaterial( facetex = true; if(validface && mat->mtex[0]) { MTex *tmp = mat->mtex[0]; - if(!tmp->tex || tmp->tex && !tmp->tex->ima ) + if(!tmp->tex || (tmp->tex && !tmp->tex->ima)) facetex = true; } numchan = numchan>MAXTEX?MAXTEX:numchan; diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index df0a8c4f25e..7cba6b01e1a 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -484,8 +484,8 @@ PyAttributeDef BL_ShapeActionActuator::Attributes[] = { }; -PyObject* BL_ShapeActionActuator::_getattr(const STR_String& attr) { - if (attr == "action") +PyObject* BL_ShapeActionActuator::_getattr(const char *attr) { + if (!strcmp(attr, "action")) return PyString_FromString(m_action->id.name+2); PyObject* object = _getattr_self(Attributes, this, attr); if (object != NULL) @@ -493,8 +493,8 @@ PyObject* BL_ShapeActionActuator::_getattr(const STR_String& attr) { _getattr_up(SCA_IActuator); } -int BL_ShapeActionActuator::_setattr(const STR_String& attr, PyObject* value) { - if (attr == "action") +int BL_ShapeActionActuator::_setattr(const char *attr, PyObject* value) { + if (!strcmp(attr, "action")) { if (!PyString_Check(value)) { diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.h b/source/gameengine/Converter/BL_ShapeActionActuator.h index 47ceb9aa995..7f2431bcfa5 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.h +++ b/source/gameengine/Converter/BL_ShapeActionActuator.h @@ -103,8 +103,8 @@ public: KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetType); KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetType); - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject* value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject* value); static int CheckBlendTime(void *self, const PyAttributeDef*) { diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index b7236afdee4..3cf22bdc9bd 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -234,7 +234,7 @@ PyMethodDef CListValue::Methods[] = { -PyObject* CListValue::_getattr(const STR_String& attr) { +PyObject* CListValue::_getattr(const char *attr) { _getattr_up(CValue); } diff --git a/source/gameengine/Expressions/ListValue.h b/source/gameengine/Expressions/ListValue.h index 431f8f558a9..8c0bd767938 100644 --- a/source/gameengine/Expressions/ListValue.h +++ b/source/gameengine/Expressions/ListValue.h @@ -59,7 +59,7 @@ public: bool CheckEqual(CValue* first,CValue* second); - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); KX_PYMETHOD(CListValue,append); KX_PYMETHOD(CListValue,reverse); diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 19f458b69a6..16184b7c5f2 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -106,24 +106,24 @@ PyParentObject PyObjectPlus::Parents[] = {&PyObjectPlus::Type, NULL}; /*------------------------------ * PyObjectPlus attributes -- attributes ------------------------------*/ -PyObject *PyObjectPlus::_getattr(const STR_String& attr) +PyObject *PyObjectPlus::_getattr(const char *attr) { - if (attr == "__doc__" && GetType()->tp_doc) + if (!strcmp(attr, "__doc__") && GetType()->tp_doc) return PyString_FromString(GetType()->tp_doc); //if (streq(attr, "type")) // return Py_BuildValue("s", (*(GetParents()))->tp_name); - return Py_FindMethod(Methods, this, const_cast(attr.ReadPtr())); + return Py_FindMethod(Methods, this, attr); } -int PyObjectPlus::_delattr(const STR_String& attr) +int PyObjectPlus::_delattr(const char *attr) { PyErr_SetString(PyExc_AttributeError, "attribute cant be deleted"); return 1; } -int PyObjectPlus::_setattr(const STR_String& attr, PyObject *value) +int PyObjectPlus::_setattr(const char *attr, PyObject *value) { //return PyObject::_setattr(attr,value); //cerr << "Unknown attribute" << endl; @@ -131,12 +131,12 @@ int PyObjectPlus::_setattr(const STR_String& attr, PyObject *value) return 1; } -PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *self, const STR_String &attr) +PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *self, const char *attr) { const PyAttributeDef *attrdef; for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++) { - if (attr == attrdef->m_name) + if (!strcmp(attr, attrdef->m_name)) { if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY) { @@ -238,7 +238,7 @@ PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *sel return NULL; } -int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, const STR_String &attr, PyObject *value) +int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, const char *attr, PyObject *value) { const PyAttributeDef *attrdef; void *undoBuffer = NULL; @@ -247,7 +247,7 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++) { - if (attr == attrdef->m_name) + if (!strcmp(attr, attrdef->m_name)) { if (attrdef->m_access == KX_PYATTRIBUTE_RO || attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY) diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index e0e2213d984..5092c8106ec 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -97,7 +97,7 @@ static inline void Py_Fatal(const char *M) { // to be properly passed up the hierarchy. #define _getattr_up(Parent) \ PyObject *rvalue = NULL; \ - if (attr=="__methods__") { \ + if (!strcmp(attr, "__methods__")) { \ PyObject *_attr_string = NULL; \ PyMethodDef *meth = Methods; \ rvalue = Parent::_getattr(attr); \ @@ -113,7 +113,7 @@ static inline void Py_Fatal(const char *M) { } \ } \ } else { \ - rvalue = Py_FindMethod(Methods, this, const_cast(attr.ReadPtr())); \ + rvalue = Py_FindMethod(Methods, this, attr); \ if (rvalue == NULL) { \ PyErr_Clear(); \ rvalue = Parent::_getattr(attr); \ @@ -348,23 +348,23 @@ public: // Py_DECREF(this); // }; // decref method - virtual PyObject *_getattr(const STR_String& attr); // _getattr method + virtual PyObject *_getattr(const char *attr); // _getattr method static PyObject *__getattr(PyObject * PyObj, char *attr) // This should be the entry in Type. { - return ((PyObjectPlus*) PyObj)->_getattr(STR_String(attr)); + return ((PyObjectPlus*) PyObj)->_getattr(attr); } - static PyObject *_getattr_self(const PyAttributeDef attrlist[], void *self, const STR_String &attr); - static int _setattr_self(const PyAttributeDef attrlist[], void *self, const STR_String &attr, PyObject *value); + static PyObject *_getattr_self(const PyAttributeDef attrlist[], void *self, const char *attr); + static int _setattr_self(const PyAttributeDef attrlist[], void *self, const char *attr, PyObject *value); - virtual int _delattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); // _setattr method + virtual int _delattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); // _setattr method static int __setattr(PyObject *PyObj, // This should be the entry in Type. char *attr, PyObject *value) { if (!value) return ((PyObjectPlus*) PyObj)->_delattr(attr); - return ((PyObjectPlus*) PyObj)->_setattr(STR_String(attr), value); + return ((PyObjectPlus*) PyObj)->_setattr(attr, value); } virtual PyObject *_repr(void); // _repr method diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index f2b5569c76e..f30dd1a71ed 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -674,9 +674,9 @@ static PyMethodDef CValueMethods[] = }; -PyObject* CValue::_getattr(const STR_String& attr) +PyObject* CValue::_getattr(const char *attr) { - CValue* resultattr = FindIdentifier(attr); + CValue* resultattr = FindIdentifier(STR_String(attr)); STR_String text; if (resultattr) { @@ -761,26 +761,27 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj) } -int CValue::_delattr(const STR_String& attr) +int CValue::_delattr(const char *attr) { - if (!RemoveProperty(attr)) /* sets error */ + if (!RemoveProperty(STR_String(attr))) /* sets error */ return 1; return 0; } -int CValue::_setattr(const STR_String& attr,PyObject* pyobj) +int CValue::_setattr(const char *attr,PyObject* pyobj) { CValue* vallie = ConvertPythonToValue(pyobj); if (vallie) { - CValue* oldprop = GetProperty(attr); + STR_String attr_str = attr; + CValue* oldprop = GetProperty(attr_str); if (oldprop) { oldprop->SetValue(vallie); } else { - SetProperty(attr,vallie); + SetProperty(attr_str, vallie); } vallie->Release(); } else diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h index 56a4991af27..854334b892b 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/Value.h @@ -223,7 +223,7 @@ public: - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); void SpecialRelease() { @@ -250,8 +250,8 @@ public: virtual CValue* ConvertPythonToValue(PyObject* pyobj); - virtual int _delattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr,PyObject* value); + virtual int _delattr(const char *attr); + virtual int _setattr(const char *attr, PyObject* value); virtual PyObject* ConvertKeysToPython( void ); diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp index a70830193db..6fcb1be654c 100644 --- a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp +++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp @@ -114,6 +114,6 @@ PyMethodDef SCA_2DFilterActuator::Methods[] = { }; -PyObject* SCA_2DFilterActuator::_getattr(const STR_String& attr) { +PyObject* SCA_2DFilterActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); } diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.h b/source/gameengine/GameLogic/SCA_2DFilterActuator.h index 7ec07cf5b19..9da0500afff 100644 --- a/source/gameengine/GameLogic/SCA_2DFilterActuator.h +++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.h @@ -38,7 +38,7 @@ public: virtual bool Update(); virtual CValue* GetReplica(); - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); }; #endif diff --git a/source/gameengine/GameLogic/SCA_ANDController.cpp b/source/gameengine/GameLogic/SCA_ANDController.cpp index cfc2d25e0ae..98a3c2e96cd 100644 --- a/source/gameengine/GameLogic/SCA_ANDController.cpp +++ b/source/gameengine/GameLogic/SCA_ANDController.cpp @@ -137,7 +137,7 @@ PyMethodDef SCA_ANDController::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* SCA_ANDController::_getattr(const STR_String& attr) { +PyObject* SCA_ANDController::_getattr(const char *attr) { _getattr_up(SCA_IController); } diff --git a/source/gameengine/GameLogic/SCA_ANDController.h b/source/gameengine/GameLogic/SCA_ANDController.h index 376f4a9a876..eba7e1b545a 100644 --- a/source/gameengine/GameLogic/SCA_ANDController.h +++ b/source/gameengine/GameLogic/SCA_ANDController.h @@ -48,7 +48,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); }; diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp index fae8d2ba5a7..dcdd7df50d4 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp @@ -161,7 +161,7 @@ PyAttributeDef SCA_ActuatorSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_ActuatorSensor::_getattr(const STR_String& attr) { +PyObject* SCA_ActuatorSensor::_getattr(const char *attr) { PyObject* object = _getattr_self(Attributes, this, attr); if (object != NULL) return object; @@ -180,7 +180,7 @@ int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*) return 1; } -int SCA_ActuatorSensor::_setattr(const STR_String& attr, PyObject *value) { +int SCA_ActuatorSensor::_setattr(const char *attr, PyObject *value) { int ret = _setattr_self(Attributes, this, attr, value); if (ret >= 0) return ret; diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.h b/source/gameengine/GameLogic/SCA_ActuatorSensor.h index 3d64247461c..75ee08f42d6 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.h +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.h @@ -61,8 +61,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); /* 3. setProperty */ KX_PYMETHOD_DOC(SCA_ActuatorSensor,SetActuator); diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp index f9fbf2387c4..76aa328aa48 100644 --- a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp +++ b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp @@ -135,7 +135,7 @@ PyMethodDef SCA_AlwaysSensor::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* SCA_AlwaysSensor::_getattr(const STR_String& attr) { +PyObject* SCA_AlwaysSensor::_getattr(const char *attr) { _getattr_up(SCA_ISensor); } diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.h b/source/gameengine/GameLogic/SCA_AlwaysSensor.h index 8bf2a8aa98e..ebe6ba80208 100644 --- a/source/gameengine/GameLogic/SCA_AlwaysSensor.h +++ b/source/gameengine/GameLogic/SCA_AlwaysSensor.h @@ -52,7 +52,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); }; diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp index 4c97ca98d72..802edc4b6cf 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp +++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp @@ -178,14 +178,14 @@ PyAttributeDef SCA_DelaySensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_DelaySensor::_getattr(const STR_String& attr) { +PyObject* SCA_DelaySensor::_getattr(const char *attr) { PyObject* object = _getattr_self(Attributes, this, attr); if (object != NULL) return object; _getattr_up(SCA_ISensor); } -int SCA_DelaySensor::_setattr(const STR_String& attr, PyObject *value) { +int SCA_DelaySensor::_setattr(const char *attr, PyObject *value) { int ret = _setattr_self(Attributes, this, attr, value); if (ret >= 0) return ret; diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.h b/source/gameengine/GameLogic/SCA_DelaySensor.h index ff3afe16542..491eee61da8 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.h +++ b/source/gameengine/GameLogic/SCA_DelaySensor.h @@ -60,8 +60,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); /* setProperty */ KX_PYMETHOD_DOC(SCA_DelaySensor,SetDelay); diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.h b/source/gameengine/GameLogic/SCA_ExpressionController.h index f1db45a19e0..20e1eb77771 100644 --- a/source/gameengine/GameLogic/SCA_ExpressionController.h +++ b/source/gameengine/GameLogic/SCA_ExpressionController.h @@ -53,7 +53,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ -// virtual PyObject* _getattr(const STR_String& attr); +// virtual PyObject* _getattr(const char *attr); }; diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index 8286c0829a7..70938db7c3d 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -278,7 +278,7 @@ int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef) } PyObject* -SCA_ILogicBrick::_getattr(const STR_String& attr) +SCA_ILogicBrick::_getattr(const char *attr) { PyObject* object = _getattr_self(Attributes, this, attr); if (object != NULL) @@ -286,7 +286,7 @@ SCA_ILogicBrick::_getattr(const STR_String& attr) _getattr_up(CValue); } -int SCA_ILogicBrick::_setattr(const STR_String& attr, PyObject *value) +int SCA_ILogicBrick::_setattr(const char *attr, PyObject *value) { int ret = _setattr_self(Attributes, this, attr, value); if (ret >= 0) diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h index 772bd65d577..cde1353275b 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.h +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h @@ -78,8 +78,8 @@ public: virtual bool LessComparedTo(SCA_ILogicBrick* other); - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); static class SCA_LogicManager* m_sCurrentLogicManager; diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp index b0f8decee26..3afc48b719c 100644 --- a/source/gameengine/GameLogic/SCA_IObject.cpp +++ b/source/gameengine/GameLogic/SCA_IObject.cpp @@ -409,7 +409,7 @@ PyMethodDef SCA_IObject::Methods[] = { -PyObject* SCA_IObject::_getattr(const STR_String& attr) { +PyObject* SCA_IObject::_getattr(const char *attr) { _getattr_up(CValue); } diff --git a/source/gameengine/GameLogic/SCA_IObject.h b/source/gameengine/GameLogic/SCA_IObject.h index 38a7ed29dca..d47353b1ac0 100644 --- a/source/gameengine/GameLogic/SCA_IObject.h +++ b/source/gameengine/GameLogic/SCA_IObject.h @@ -145,7 +145,7 @@ public: // const class MT_Point3& ConvertPythonPylist(PyObject* pylist); // here come the python forwarded methods - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); virtual int GetGameObjectType() {return -1;} diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index 68a3a93eab0..73475b018fc 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -461,19 +461,19 @@ PyAttributeDef SCA_ISensor::Attributes[] = { }; PyObject* -SCA_ISensor::_getattr(const STR_String& attr) +SCA_ISensor::_getattr(const char *attr) { PyObject* object = _getattr_self(Attributes, this, attr); if (object != NULL) return object; - if (attr == "triggered") + if (!strcmp(attr, "triggered")) { int retval = 0; if (SCA_PythonController::m_sCurrentController) retval = SCA_PythonController::m_sCurrentController->IsTriggered(this); return PyInt_FromLong(retval); } - if (attr == "positive") + if (!strcmp(attr, "positive")) { int retval = IsPositiveTrigger(); return PyInt_FromLong(retval); @@ -481,7 +481,7 @@ SCA_ISensor::_getattr(const STR_String& attr) _getattr_up(SCA_ILogicBrick); } -int SCA_ISensor::_setattr(const STR_String& attr, PyObject *value) +int SCA_ISensor::_setattr(const char *attr, PyObject *value) { int ret = _setattr_self(Attributes, this, attr, value); if (ret >= 0) diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h index 1b57c4621e4..5ae7ced2a2a 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.h +++ b/source/gameengine/GameLogic/SCA_ISensor.h @@ -141,8 +141,8 @@ public: /* Python functions: */ - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); //Deprecated functions -----> KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,IsPositive); diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 694bca9bac5..17a8710ed48 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -343,24 +343,24 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_JoystickSensor::_getattr(const STR_String& attr) { +PyObject* SCA_JoystickSensor::_getattr(const char *attr) { SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); - if (attr == "axisPosition") { + if (!strcmp(attr, "axisPosition")) { if(joy) return Py_BuildValue("[iiii]", joy->GetAxis10(), joy->GetAxis11(), joy->GetAxis20(), joy->GetAxis21()); else return Py_BuildValue("[iiii]", 0, 0, 0, 0); } - if (attr == "numAxis") { + if (!strcmp(attr, "numAxis")) { return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 ); } - if (attr == "numButtons") { + if (!strcmp(attr, "numButtons")) { return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 ); } - if (attr == "numHats") { + if (!strcmp(attr, "numHats")) { return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 ); } - if (attr == "connected") { + if (!strcmp(attr, "connected")) { return PyBool_FromLong( joy ? joy->Connected() : 0 ); } PyObject* object = _getattr_self(Attributes, this, attr); @@ -369,7 +369,7 @@ PyObject* SCA_JoystickSensor::_getattr(const STR_String& attr) { _getattr_up(SCA_ISensor); } -int SCA_JoystickSensor::_setattr(const STR_String& attr, PyObject *value) +int SCA_JoystickSensor::_setattr(const char *attr, PyObject *value) { int ret = _setattr_self(Attributes, this, attr, value); if (ret >= 0) diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.h b/source/gameengine/GameLogic/SCA_JoystickSensor.h index fa11f1cc3d0..49d220c056d 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.h +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.h @@ -121,8 +121,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); /* Joystick Index */ KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetIndex); diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index 981d165287b..0edc41bef7b 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -831,7 +831,7 @@ PyAttributeDef SCA_KeyboardSensor::Attributes[] = { }; PyObject* -SCA_KeyboardSensor::_getattr(const STR_String& attr) +SCA_KeyboardSensor::_getattr(const char *attr) { PyObject* object = _getattr_self(Attributes, this, attr); if (object != NULL) @@ -839,7 +839,7 @@ SCA_KeyboardSensor::_getattr(const STR_String& attr) _getattr_up(SCA_ISensor); } -int SCA_KeyboardSensor::_setattr(const STR_String& attr, PyObject *value) +int SCA_KeyboardSensor::_setattr(const char *attr, PyObject *value) { int ret = _setattr_self(Attributes, this, attr, value); if (ret >= 0) diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.h b/source/gameengine/GameLogic/SCA_KeyboardSensor.h index 4efbe9366cc..bc2f86327a5 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.h +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.h @@ -126,8 +126,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); //Deprecated functions -----> /** 1. GetKey : check which key this sensor looks at */ diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index 09b46e6443e..a96d3758d3c 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -341,7 +341,7 @@ PyAttributeDef SCA_MouseSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_MouseSensor::_getattr(const STR_String& attr) +PyObject* SCA_MouseSensor::_getattr(const char *attr) { PyObject* object = _getattr_self(Attributes, this, attr); if (object != NULL) @@ -349,7 +349,7 @@ PyObject* SCA_MouseSensor::_getattr(const STR_String& attr) _getattr_up(SCA_ISensor); } -int SCA_MouseSensor::_setattr(const STR_String& attr, PyObject *value) +int SCA_MouseSensor::_setattr(const char *attr, PyObject *value) { int ret = _setattr_self(Attributes, this, attr, value); if (ret >= 0) diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.h b/source/gameengine/GameLogic/SCA_MouseSensor.h index 82af2ce9c04..30b43fe53cc 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.h +++ b/source/gameengine/GameLogic/SCA_MouseSensor.h @@ -109,8 +109,8 @@ class SCA_MouseSensor : public SCA_ISensor /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); //Deprecated functions -----> /* read x-coordinate */ diff --git a/source/gameengine/GameLogic/SCA_NANDController.cpp b/source/gameengine/GameLogic/SCA_NANDController.cpp index 5b869ee8298..0efa8da153a 100644 --- a/source/gameengine/GameLogic/SCA_NANDController.cpp +++ b/source/gameengine/GameLogic/SCA_NANDController.cpp @@ -137,7 +137,7 @@ PyMethodDef SCA_NANDController::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* SCA_NANDController::_getattr(const STR_String& attr) { +PyObject* SCA_NANDController::_getattr(const char *attr) { _getattr_up(SCA_IController); } diff --git a/source/gameengine/GameLogic/SCA_NANDController.h b/source/gameengine/GameLogic/SCA_NANDController.h index 1193ff64f07..d88504cfc0d 100644 --- a/source/gameengine/GameLogic/SCA_NANDController.h +++ b/source/gameengine/GameLogic/SCA_NANDController.h @@ -48,7 +48,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); }; diff --git a/source/gameengine/GameLogic/SCA_NORController.cpp b/source/gameengine/GameLogic/SCA_NORController.cpp index 2866dec0b74..fa24be9ebce 100644 --- a/source/gameengine/GameLogic/SCA_NORController.cpp +++ b/source/gameengine/GameLogic/SCA_NORController.cpp @@ -137,7 +137,7 @@ PyMethodDef SCA_NORController::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* SCA_NORController::_getattr(const STR_String& attr) { +PyObject* SCA_NORController::_getattr(const char *attr) { _getattr_up(SCA_IController); } diff --git a/source/gameengine/GameLogic/SCA_NORController.h b/source/gameengine/GameLogic/SCA_NORController.h index aab59e3d46c..45b639f3f3f 100644 --- a/source/gameengine/GameLogic/SCA_NORController.h +++ b/source/gameengine/GameLogic/SCA_NORController.h @@ -48,7 +48,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); }; diff --git a/source/gameengine/GameLogic/SCA_ORController.cpp b/source/gameengine/GameLogic/SCA_ORController.cpp index 2d4eb31f241..42a29e1959b 100644 --- a/source/gameengine/GameLogic/SCA_ORController.cpp +++ b/source/gameengine/GameLogic/SCA_ORController.cpp @@ -129,7 +129,7 @@ PyMethodDef SCA_ORController::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* SCA_ORController::_getattr(const STR_String& attr) { +PyObject* SCA_ORController::_getattr(const char *attr) { _getattr_up(SCA_IController); } diff --git a/source/gameengine/GameLogic/SCA_ORController.h b/source/gameengine/GameLogic/SCA_ORController.h index beb69aa2af9..9a6e9e75022 100644 --- a/source/gameengine/GameLogic/SCA_ORController.h +++ b/source/gameengine/GameLogic/SCA_ORController.h @@ -49,7 +49,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); }; #endif //__KX_ORCONTROLLER diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index 566d3b63487..644b82a92bf 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -260,14 +260,14 @@ PyAttributeDef SCA_PropertyActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_PropertyActuator::_getattr(const STR_String& attr) { +PyObject* SCA_PropertyActuator::_getattr(const char *attr) { PyObject* object = _getattr_self(Attributes, this, attr); if (object != NULL) return object; _getattr_up(SCA_IActuator); } -int SCA_PropertyActuator::_setattr(const STR_String& attr, PyObject *value) { +int SCA_PropertyActuator::_setattr(const char *attr, PyObject *value) { int ret = _setattr_self(Attributes, this, attr, value); if (ret >= 0) return ret; diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.h b/source/gameengine/GameLogic/SCA_PropertyActuator.h index cdfeee4c67d..444d9285796 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.h +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.h @@ -85,8 +85,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); // python wrapped methods KX_PYMETHOD_DOC(SCA_PropertyActuator,SetProperty); diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp index a6f7a9cd82b..10d49769162 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp +++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp @@ -352,14 +352,14 @@ PyAttributeDef SCA_PropertySensor::Attributes[] = { }; -PyObject* SCA_PropertySensor::_getattr(const STR_String& attr) { +PyObject* SCA_PropertySensor::_getattr(const char *attr) { PyObject* object = _getattr_self(Attributes, this, attr); if (object != NULL) return object; _getattr_up(SCA_ISensor); /* implicit return! */ } -int SCA_PropertySensor::_setattr(const STR_String& attr, PyObject *value) { +int SCA_PropertySensor::_setattr(const char *attr, PyObject *value) { int ret = _setattr_self(Attributes, this, attr, value); if (ret >= 0) return ret; diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.h b/source/gameengine/GameLogic/SCA_PropertySensor.h index e625e84a36f..933de49de18 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.h +++ b/source/gameengine/GameLogic/SCA_PropertySensor.h @@ -85,8 +85,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); /* 1. getType */ KX_PYMETHOD_DOC(SCA_PropertySensor,GetType); diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index e879481a444..2fff21f22fb 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -233,8 +233,8 @@ PyMethodDef SCA_PythonController::Methods[] = { {"getActuator", (PyCFunction) SCA_PythonController::sPyGetActuator, METH_O, (PY_METHODCHAR)SCA_PythonController::GetActuator_doc}, {"getSensors", (PyCFunction) SCA_PythonController::sPyGetSensors, METH_NOARGS, (PY_METHODCHAR)SCA_PythonController::GetSensors_doc}, {"getSensor", (PyCFunction) SCA_PythonController::sPyGetSensor, METH_O, (PY_METHODCHAR)SCA_PythonController::GetSensor_doc}, - {"setScript", (PyCFunction) SCA_PythonController::sPySetScript, METH_O}, //Deprecated functions ------> + {"setScript", (PyCFunction) SCA_PythonController::sPySetScript, METH_O}, {"getScript", (PyCFunction) SCA_PythonController::sPyGetScript, METH_NOARGS}, {"getState", (PyCFunction) SCA_PythonController::sPyGetState, METH_NOARGS}, //<----- Deprecated @@ -329,25 +329,35 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) -PyObject* SCA_PythonController::_getattr(const STR_String& attr) +PyObject* SCA_PythonController::_getattr(const char *attr) { - if (attr == "script") { - return PyString_FromString(m_scriptText); - } - if (attr == "state") { + if (!strcmp(attr,"state")) { return PyInt_FromLong(m_statemask); } + if (!strcmp(attr,"script")) { + return PyString_FromString(m_scriptText); + } _getattr_up(SCA_IController); } -int SCA_PythonController::_setattr(const STR_String& attr, PyObject *value) +int SCA_PythonController::_setattr(const char *attr, PyObject *value) { - if (attr == "script") { - PyErr_SetString(PyExc_AttributeError, "script is read only, use setScript() to update the script"); + if (!strcmp(attr,"state")) { + PyErr_SetString(PyExc_AttributeError, "state is read only"); return 1; } - if (attr == "state") { - PyErr_SetString(PyExc_AttributeError, "state is read only"); + if (!strcmp(attr,"script")) { + char *scriptArg = PyString_AsString(value); + + if (scriptArg==NULL) { + PyErr_SetString(PyExc_TypeError, "expected a string (script name)"); + return -1; + } + + /* set scripttext sets m_bModified to true, + so next time the script is needed, a reparse into byte code is done */ + this->SetScriptText(scriptArg); + return 1; } return SCA_IController::_setattr(attr, value); @@ -448,6 +458,9 @@ PyObject* SCA_PythonController::PyGetScript(PyObject* self) PyObject* SCA_PythonController::PySetScript(PyObject* self, PyObject* value) { char *scriptArg = PyString_AsString(value); + + ShowDeprecationWarning("setScript()", "the script property"); + if (scriptArg==NULL) { PyErr_SetString(PyExc_TypeError, "expected a string (script name)"); return NULL; diff --git a/source/gameengine/GameLogic/SCA_PythonController.h b/source/gameengine/GameLogic/SCA_PythonController.h index 1918cc488d8..00c30d7f3d5 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.h +++ b/source/gameengine/GameLogic/SCA_PythonController.h @@ -76,8 +76,8 @@ class SCA_PythonController : public SCA_IController static const char* sPyAddActiveActuator__doc__; static PyObject* sPyAddActiveActuator(PyObject* self, PyObject* args); - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); KX_PYMETHOD_DOC_NOARGS(SCA_PythonController,GetSensors); KX_PYMETHOD_DOC_NOARGS(SCA_PythonController,GetActuators); diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp index 840b95d559a..7aa25d22b3f 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp +++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp @@ -369,22 +369,22 @@ PyAttributeDef SCA_RandomActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_RandomActuator::_getattr(const STR_String& attr) { +PyObject* SCA_RandomActuator::_getattr(const char *attr) { PyObject* object = _getattr_self(Attributes, this, attr); if (object != NULL) return object; - if (attr == "seed") { + if (!strcmp(attr, "seed")) { return PyInt_FromLong(m_base->GetSeed()); } _getattr_up(SCA_IActuator); } -int SCA_RandomActuator::_setattr(const STR_String& attr, PyObject *value) +int SCA_RandomActuator::_setattr(const char *attr, PyObject *value) { int ret = _setattr_self(Attributes, this, attr, value); if (ret >= 0) return ret; - if (attr == "seed") { + if (!strcmp(attr, "seed")) { if (PyInt_Check(value)) { int ival = PyInt_AsLong(value); m_base->SetSeed(ival); diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.h b/source/gameengine/GameLogic/SCA_RandomActuator.h index de8faaf9c72..0d404fa8a9f 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.h +++ b/source/gameengine/GameLogic/SCA_RandomActuator.h @@ -96,8 +96,8 @@ class SCA_RandomActuator : public SCA_IActuator /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); /* 1. setSeed */ KX_PYMETHOD_DOC(SCA_RandomActuator,SetSeed); diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp index 8fae0bbeaba..5a1bd10e044 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp +++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp @@ -165,22 +165,22 @@ PyAttributeDef SCA_RandomSensor::Attributes[] = { {NULL} //Sentinel }; -PyObject* SCA_RandomSensor::_getattr(const STR_String& attr) { +PyObject* SCA_RandomSensor::_getattr(const char *attr) { PyObject* object = _getattr_self(Attributes, this, attr); if (object != NULL) return object; - if (attr == "seed") { + if (!strcmp(attr,"seed")) { return PyInt_FromLong(m_basegenerator->GetSeed()); } _getattr_up(SCA_ISensor); } -int SCA_RandomSensor::_setattr(const STR_String& attr, PyObject *value) +int SCA_RandomSensor::_setattr(const char *attr, PyObject *value) { int ret = _setattr_self(Attributes, this, attr, value); if (ret >= 0) return ret; - if (attr == "seed") { + if (!strcmp(attr,"seed")) { if (PyInt_Check(value)) { int ival = PyInt_AsLong(value); m_basegenerator->SetSeed(ival); diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.h b/source/gameengine/GameLogic/SCA_RandomSensor.h index 009efc32aac..d808db07536 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.h +++ b/source/gameengine/GameLogic/SCA_RandomSensor.h @@ -60,8 +60,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); /* 1. setSeed */ KX_PYMETHOD_DOC(SCA_RandomSensor,SetSeed); diff --git a/source/gameengine/GameLogic/SCA_XNORController.cpp b/source/gameengine/GameLogic/SCA_XNORController.cpp index 3ef7c07fe0a..b019aedc93d 100644 --- a/source/gameengine/GameLogic/SCA_XNORController.cpp +++ b/source/gameengine/GameLogic/SCA_XNORController.cpp @@ -141,7 +141,7 @@ PyMethodDef SCA_XNORController::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* SCA_XNORController::_getattr(const STR_String& attr) { +PyObject* SCA_XNORController::_getattr(const char *attr) { _getattr_up(SCA_IController); } diff --git a/source/gameengine/GameLogic/SCA_XNORController.h b/source/gameengine/GameLogic/SCA_XNORController.h index 4b1eaee95d8..a431a72c177 100644 --- a/source/gameengine/GameLogic/SCA_XNORController.h +++ b/source/gameengine/GameLogic/SCA_XNORController.h @@ -48,7 +48,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); }; diff --git a/source/gameengine/GameLogic/SCA_XORController.cpp b/source/gameengine/GameLogic/SCA_XORController.cpp index 6499c62f5f2..11ffa19b8f1 100644 --- a/source/gameengine/GameLogic/SCA_XORController.cpp +++ b/source/gameengine/GameLogic/SCA_XORController.cpp @@ -141,7 +141,7 @@ PyMethodDef SCA_XORController::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* SCA_XORController::_getattr(const STR_String& attr) { +PyObject* SCA_XORController::_getattr(const char *attr) { _getattr_up(SCA_IController); } diff --git a/source/gameengine/GameLogic/SCA_XORController.h b/source/gameengine/GameLogic/SCA_XORController.h index f50cd33c125..2fbc7866ecf 100644 --- a/source/gameengine/GameLogic/SCA_XORController.h +++ b/source/gameengine/GameLogic/SCA_XORController.h @@ -48,7 +48,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); }; diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index 80892764089..0c57b2d03a5 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -729,7 +729,7 @@ void BL_Shader::SetUniform(int uniform, const int* val, int len) } -PyObject* BL_Shader::_getattr(const STR_String& attr) +PyObject* BL_Shader::_getattr(const char *attr) { _getattr_up(PyObjectPlus); } diff --git a/source/gameengine/Ketsji/BL_Shader.h b/source/gameengine/Ketsji/BL_Shader.h index 18ca8f8b4f8..52cbd0cda51 100644 --- a/source/gameengine/Ketsji/BL_Shader.h +++ b/source/gameengine/Ketsji/BL_Shader.h @@ -202,7 +202,7 @@ public: void SetUniform(int uniform, const int val); // Python interface - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); // ----------------------------------- KX_PYMETHOD_DOC( BL_Shader, setSource ); diff --git a/source/gameengine/Ketsji/BL_Texture.cpp b/source/gameengine/Ketsji/BL_Texture.cpp index f0ef84032f7..5d40ba7d75c 100644 --- a/source/gameengine/Ketsji/BL_Texture.cpp +++ b/source/gameengine/Ketsji/BL_Texture.cpp @@ -609,7 +609,7 @@ int BL_Texture::GetPow2(int n) void BL_Texture::SplitEnvMap(EnvMap *map) { - if (!map || !map->ima || map->ima && !map->ima->ok) return; + if (!map || !map->ima || (map->ima && !map->ima->ok)) return; ImBuf *ibuf= BKE_image_get_ibuf(map->ima, NULL); if (ibuf) my_envmap_split_ima(map, ibuf); diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp index 85921ae75ca..a332295ad72 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp @@ -143,7 +143,7 @@ PyMethodDef KX_NetworkMessageActuator::Methods[] = { {NULL,NULL} // Sentinel }; -PyObject* KX_NetworkMessageActuator::_getattr(const STR_String& attr) { +PyObject* KX_NetworkMessageActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h index 653107699c7..96b55ef839b 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h @@ -61,7 +61,7 @@ public: /* Python interface ------------------------------------------- */ /* ------------------------------------------------------------ */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); KX_PYMETHOD(KX_NetworkMessageActuator, SetToPropName); KX_PYMETHOD(KX_NetworkMessageActuator, SetSubject); diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp index 8956df9c96b..cb9956d4616 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp @@ -213,7 +213,7 @@ PyMethodDef KX_NetworkMessageSensor::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* KX_NetworkMessageSensor::_getattr(const STR_String& attr) { +PyObject* KX_NetworkMessageSensor::_getattr(const char *attr) { _getattr_up(SCA_ISensor); // implicit return! } diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h index 8cdfd6cdb5a..26adbc9945a 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h @@ -72,7 +72,7 @@ public: /* Python interface -------------------------------------------- */ /* ------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); KX_PYMETHOD_DOC_O(KX_NetworkMessageSensor, SetSubjectFilterText); KX_PYMETHOD_DOC_NOARGS(KX_NetworkMessageSensor, GetFrameMessageCount); diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index f92200780d5..83148ea9a2b 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -772,12 +772,12 @@ PyParentObject KX_BlenderMaterial::Parents[] = { }; -PyObject* KX_BlenderMaterial::_getattr(const STR_String& attr) +PyObject* KX_BlenderMaterial::_getattr(const char *attr) { _getattr_up(PyObjectPlus); } -int KX_BlenderMaterial::_setattr(const STR_String& attr, PyObject *pyvalue) +int KX_BlenderMaterial::_setattr(const char *attr, PyObject *pyvalue) { return PyObjectPlus::_setattr(attr, pyvalue); } diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.h b/source/gameengine/Ketsji/KX_BlenderMaterial.h index 6e5db1b56c1..2cf623dbd85 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.h +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.h @@ -82,8 +82,8 @@ public: ); // -------------------------------- - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *pyvalue); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *pyvalue); KX_PYMETHOD_DOC( KX_BlenderMaterial, getShader ); KX_PYMETHOD_DOC( KX_BlenderMaterial, getMaterialIndex ); diff --git a/source/gameengine/Ketsji/KX_CDActuator.cpp b/source/gameengine/Ketsji/KX_CDActuator.cpp index a5d7f6d799a..44d073193b1 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.cpp +++ b/source/gameengine/Ketsji/KX_CDActuator.cpp @@ -199,7 +199,7 @@ PyMethodDef KX_CDActuator::Methods[] = { -PyObject* KX_CDActuator::_getattr(const STR_String& attr) +PyObject* KX_CDActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_CDActuator.h b/source/gameengine/Ketsji/KX_CDActuator.h index f46dd99b6dc..393c49083f9 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.h +++ b/source/gameengine/Ketsji/KX_CDActuator.h @@ -81,7 +81,7 @@ public: /* Python interface --------------------------------------------------- */ /* -------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); KX_PYMETHOD(KX_CDActuator,StartCD); KX_PYMETHOD(KX_CDActuator,PauseCD); diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index fb91c793765..809bcdba8c9 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -538,48 +538,48 @@ PyParentObject KX_Camera::Parents[] = { NULL }; -PyObject* KX_Camera::_getattr(const STR_String& attr) +PyObject* KX_Camera::_getattr(const char *attr) { - if (attr == "INSIDE") + if (!strcmp(attr, "INSIDE")) return PyInt_FromLong(INSIDE); /* new ref */ - if (attr == "OUTSIDE") + if (!strcmp(attr, "OUTSIDE")) return PyInt_FromLong(OUTSIDE); /* new ref */ - if (attr == "INTERSECT") + if (!strcmp(attr, "INTERSECT")) return PyInt_FromLong(INTERSECT); /* new ref */ - if (attr == "lens") + if (!strcmp(attr, "lens")) return PyFloat_FromDouble(GetLens()); /* new ref */ - if (attr == "near") + if (!strcmp(attr, "near")) return PyFloat_FromDouble(GetCameraNear()); /* new ref */ - if (attr == "far") + if (!strcmp(attr, "far")) return PyFloat_FromDouble(GetCameraFar()); /* new ref */ - if (attr == "frustum_culling") + if (!strcmp(attr, "frustum_culling")) return PyInt_FromLong(m_frustum_culling); /* new ref */ - if (attr == "perspective") + if (!strcmp(attr, "perspective")) return PyInt_FromLong(m_camdata.m_perspective); /* new ref */ - if (attr == "projection_matrix") + if (!strcmp(attr, "projection_matrix")) return PyObjectFrom(GetProjectionMatrix()); /* new ref */ - if (attr == "modelview_matrix") + if (!strcmp(attr, "modelview_matrix")) return PyObjectFrom(GetModelviewMatrix()); /* new ref */ - if (attr == "camera_to_world") + if (!strcmp(attr, "camera_to_world")) return PyObjectFrom(GetCameraToWorld()); /* new ref */ - if (attr == "world_to_camera") + if (!strcmp(attr, "world_to_camera")) return PyObjectFrom(GetWorldToCamera()); /* new ref */ _getattr_up(KX_GameObject); } -int KX_Camera::_setattr(const STR_String &attr, PyObject *pyvalue) +int KX_Camera::_setattr(const char *attr, PyObject *pyvalue) { if (PyInt_Check(pyvalue)) { - if (attr == "frustum_culling") + if (!strcmp(attr, "frustum_culling")) { m_frustum_culling = PyInt_AsLong(pyvalue); return 0; } - if (attr == "perspective") + if (!strcmp(attr, "perspective")) { m_camdata.m_perspective = PyInt_AsLong(pyvalue); return 0; @@ -588,19 +588,19 @@ int KX_Camera::_setattr(const STR_String &attr, PyObject *pyvalue) if (PyFloat_Check(pyvalue)) { - if (attr == "lens") + if (!strcmp(attr, "lens")) { m_camdata.m_lens = PyFloat_AsDouble(pyvalue); m_set_projection_matrix = false; return 0; } - if (attr == "near") + if (!strcmp(attr, "near")) { m_camdata.m_clipstart = PyFloat_AsDouble(pyvalue); m_set_projection_matrix = false; return 0; } - if (attr == "far") + if (!strcmp(attr, "far")) { m_camdata.m_clipend = PyFloat_AsDouble(pyvalue); m_set_projection_matrix = false; @@ -610,7 +610,7 @@ int KX_Camera::_setattr(const STR_String &attr, PyObject *pyvalue) if (PyObject_IsMT_Matrix(pyvalue, 4)) { - if (attr == "projection_matrix") + if (!strcmp(attr, "projection_matrix")) { MT_Matrix4x4 mat; if (PyMatTo(pyvalue, mat)) diff --git a/source/gameengine/Ketsji/KX_Camera.h b/source/gameengine/Ketsji/KX_Camera.h index 75d574cd697..9ff9c545f2c 100644 --- a/source/gameengine/Ketsji/KX_Camera.h +++ b/source/gameengine/Ketsji/KX_Camera.h @@ -270,8 +270,8 @@ public: KX_PYMETHOD_DOC(KX_Camera, setViewport); KX_PYMETHOD_DOC(KX_Camera, setOnTop); - virtual PyObject* _getattr(const STR_String& attr); /* lens, near, far, projection_matrix */ - virtual int _setattr(const STR_String& attr, PyObject *pyvalue); + virtual PyObject* _getattr(const char *attr); /* lens, near, far, projection_matrix */ + virtual int _setattr(const char *attr, PyObject *pyvalue); }; diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 4ac097eb575..dc2c4c4b414 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -420,10 +420,10 @@ PyAttributeDef KX_CameraActuator::Attributes[] = { {NULL} }; -PyObject* KX_CameraActuator::_getattr(const STR_String& attr) { +PyObject* KX_CameraActuator::_getattr(const char *attr) { PyObject* object; - if (attr == "object") { + if (!strcmp(attr, "object")) { if (!m_ob) Py_RETURN_NONE; else return m_ob->AddRef(); } @@ -434,10 +434,10 @@ PyObject* KX_CameraActuator::_getattr(const STR_String& attr) { _getattr_up(SCA_IActuator); } -int KX_CameraActuator::_setattr(const STR_String& attr, PyObject* value) { +int KX_CameraActuator::_setattr(const char *attr, PyObject* value) { int ret; - if (attr == "object") { + if (!strcmp(attr, "object")) { KX_GameObject *gameobj; if (!ConvertPythonToGameObject(value, &gameobj, true)) diff --git a/source/gameengine/Ketsji/KX_CameraActuator.h b/source/gameengine/Ketsji/KX_CameraActuator.h index 4acca12833c..3b08536fc21 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.h +++ b/source/gameengine/Ketsji/KX_CameraActuator.h @@ -120,8 +120,8 @@ private : /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject* value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject* value); /* set object to look at */ KX_PYMETHOD_DOC_O(KX_CameraActuator,SetObject); diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index 76357e9c58f..5c08bdc94a3 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -612,7 +612,7 @@ PyMethodDef KX_ConstraintActuator::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* KX_ConstraintActuator::_getattr(const STR_String& attr) { +PyObject* KX_ConstraintActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.h b/source/gameengine/Ketsji/KX_ConstraintActuator.h index 28b9b1e6a0b..132b8a7328a 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.h +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.h @@ -142,7 +142,7 @@ protected: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); KX_PYMETHOD_DOC(KX_ConstraintActuator,SetDamp); KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetDamp); diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp index c9095ff34f6..9ceb4a05b06 100644 --- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp @@ -92,32 +92,30 @@ PyParentObject KX_ConstraintWrapper::Parents[] = { NULL }; -PyObject* KX_ConstraintWrapper::_getattr(const STR_String& attr) +PyObject* KX_ConstraintWrapper::_getattr(const char *attr) { //here you can search for existing data members (like mass,friction etc.) _getattr_up(PyObjectPlus); } -int KX_ConstraintWrapper::_setattr(const STR_String& attr,PyObject* pyobj) +int KX_ConstraintWrapper::_setattr(const char *attr,PyObject* pyobj) { - - PyTypeObject* type = pyobj->ob_type; int result = 1; - if (type == &PyList_Type) + if (PyList_Check(pyobj)) { result = 0; } - if (type == &PyFloat_Type) + if (PyFloat_Check(pyobj)) { result = 0; } - if (type == &PyInt_Type) + if (PyInt_Check(pyobj)) { result = 0; } - if (type == &PyString_Type) + if (PyString_Check(pyobj)) { result = 0; } diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.h b/source/gameengine/Ketsji/KX_ConstraintWrapper.h index 79fb3dc21aa..36606d2d67b 100644 --- a/source/gameengine/Ketsji/KX_ConstraintWrapper.h +++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.h @@ -35,8 +35,8 @@ class KX_ConstraintWrapper : public PyObjectPlus { Py_Header; - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); public: KX_ConstraintWrapper(PHY_ConstraintType ctype,int constraintId,class PHY_IPhysicsEnvironment* physenv,PyTypeObject *T = &Type); virtual ~KX_ConstraintWrapper (); diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp index 76459e46731..a8b4e0d7d2c 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.cpp +++ b/source/gameengine/Ketsji/KX_GameActuator.cpp @@ -276,7 +276,7 @@ PyObject* KX_GameActuator::PySetFile(PyObject* self, PyObject* args, PyObject* k -PyObject* KX_GameActuator::_getattr(const STR_String& attr) +PyObject* KX_GameActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_GameActuator.h b/source/gameengine/Ketsji/KX_GameActuator.h index bb3448995dc..856fa0c24e9 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.h +++ b/source/gameengine/Ketsji/KX_GameActuator.h @@ -77,7 +77,7 @@ protected: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); KX_PYMETHOD_DOC(KX_GameActuator,GetFile); KX_PYMETHOD_DOC(KX_GameActuator,SetFile); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 42316c6c873..521fd317305 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1124,15 +1124,15 @@ PyParentObject KX_GameObject::Parents[] = { -PyObject* KX_GameObject::_getattr(const STR_String& attr) +PyObject* KX_GameObject::_getattr(const char *attr) { if (m_pPhysicsController1) { - if (attr == "mass") + if (!strcmp(attr, "mass")) return PyFloat_FromDouble(m_pPhysicsController1->GetMass()); } - if (attr == "parent") + if (!strcmp(attr, "parent")) { KX_GameObject* parent = GetParent(); if (parent) @@ -1143,21 +1143,23 @@ PyObject* KX_GameObject::_getattr(const STR_String& attr) Py_RETURN_NONE; } - if (attr == "visible") + if (!strcmp(attr, "visible")) return PyInt_FromLong(m_bVisible); - if (attr == "position") + if (!strcmp(attr, "position")) return PyObjectFrom(NodeGetWorldPosition()); - if (attr == "orientation") + if (!strcmp(attr, "orientation")) return PyObjectFrom(NodeGetWorldOrientation()); - if (attr == "scaling") + if (!strcmp(attr, "scaling")) return PyObjectFrom(NodeGetWorldScaling()); - if (attr == "name") + if (!strcmp(attr, "name")) return PyString_FromString(m_name.ReadPtr()); - if (attr == "timeOffset") { + + if (!strcmp(attr, "timeOffset")) + { if (m_pSGNode->GetSGParent()->IsSlowParent()) { return PyFloat_FromDouble(static_cast(m_pSGNode->GetSGParent()->GetParentRelation())->GetTimeOffset()); } else { @@ -1169,10 +1171,10 @@ PyObject* KX_GameObject::_getattr(const STR_String& attr) _getattr_up(SCA_IObject); } -int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr method +int KX_GameObject::_setattr(const char *attr, PyObject *value) // _setattr method { - if (attr == "parent") { + if (!strcmp(attr, "parent")) { PyErr_SetString(PyExc_AttributeError, "attribute \"mass\" is read only\nUse setParent()"); return 1; } @@ -1180,7 +1182,7 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr if (PyInt_Check(value)) { int val = PyInt_AsLong(value); - if (attr == "visible") + if (!strcmp(attr, "visible")) { SetVisible(val != 0, false); UpdateBuckets(false); @@ -1191,7 +1193,7 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr if (PyFloat_Check(value)) { MT_Scalar val = PyFloat_AsDouble(value); - if (attr == "timeOffset") { + if (!strcmp(attr, "timeOffset")) { if (m_pSGNode->GetSGParent() && m_pSGNode->GetSGParent()->IsSlowParent()) { static_cast(m_pSGNode->GetSGParent()->GetParentRelation())->SetTimeOffset(val); return 0; @@ -1199,7 +1201,7 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr return 0; } } - if (attr == "mass") { + if (!strcmp(attr, "mass")) { if (m_pPhysicsController1) m_pPhysicsController1->SetMass(val); return 0; @@ -1208,7 +1210,7 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr if (PySequence_Check(value)) { - if (attr == "orientation") + if (!strcmp(attr, "orientation")) { MT_Matrix3x3 rot; if (PyObject_IsMT_Matrix(value, 3)) @@ -1251,7 +1253,7 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr return 1; } - if (attr == "position") + if (!strcmp(attr, "position")) { MT_Point3 pos; if (PyVecTo(value, pos)) @@ -1263,7 +1265,7 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr return 1; } - if (attr == "scaling") + if (!strcmp(attr, "scaling")) { MT_Vector3 scale; if (PyVecTo(value, scale)) @@ -1278,7 +1280,7 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr if (PyString_Check(value)) { - if (attr == "name") + if (!strcmp(attr, "name")) { m_name = PyString_AsString(value); return 0; diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 4f26031356f..7fe3009a957 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -756,18 +756,8 @@ public: * @section Python interface functions. */ - virtual - PyObject* - _getattr( - const STR_String& attr - ); - - virtual - int - _setattr( - const STR_String& attr, - PyObject *value - ); // _setattr method + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); // _setattr method KX_PYMETHOD_NOARGS(KX_GameObject,GetPosition); KX_PYMETHOD_O(KX_GameObject,SetPosition); diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index f5e17118ffb..a67fbe55c37 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -457,7 +457,7 @@ PyMethodDef KX_IpoActuator::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* KX_IpoActuator::_getattr(const STR_String& attr) { +PyObject* KX_IpoActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_IpoActuator.h b/source/gameengine/Ketsji/KX_IpoActuator.h index 8e5baed0530..12e1835ab49 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.h +++ b/source/gameengine/Ketsji/KX_IpoActuator.h @@ -141,7 +141,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); //KX_PYMETHOD_DOC KX_PYMETHOD_DOC(KX_IpoActuator,Set); KX_PYMETHOD_DOC(KX_IpoActuator,SetProperty); diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp index e0f171e78e0..36700265260 100644 --- a/source/gameengine/Ketsji/KX_Light.cpp +++ b/source/gameengine/Ketsji/KX_Light.cpp @@ -172,65 +172,59 @@ void KX_LightObject::UnbindShadowBuffer(RAS_IRasterizer *ras) GPU_lamp_shadow_buffer_unbind(lamp); } -PyObject* KX_LightObject::_getattr(const STR_String& attr) +PyObject* KX_LightObject::_getattr(const char *attr) { - if (attr == "layer") + if (!strcmp(attr, "layer")) return PyInt_FromLong(m_lightobj.m_layer); - if (attr == "energy") + if (!strcmp(attr, "energy")) return PyFloat_FromDouble(m_lightobj.m_energy); - if (attr == "distance") + if (!strcmp(attr, "distance")) return PyFloat_FromDouble(m_lightobj.m_distance); - if (attr == "colour" || attr == "color") + if (!strcmp(attr, "colour") || !strcmp(attr, "color")) return Py_BuildValue("[fff]", m_lightobj.m_red, m_lightobj.m_green, m_lightobj.m_blue); - if (attr == "lin_attenuation") + if (!strcmp(attr, "lin_attenuation")) return PyFloat_FromDouble(m_lightobj.m_att1); - if (attr == "quad_attenuation") + if (!strcmp(attr, "quad_attenuation")) return PyFloat_FromDouble(m_lightobj.m_att2); - if (attr == "spotsize") + if (!strcmp(attr, "spotsize")) return PyFloat_FromDouble(m_lightobj.m_spotsize); - if (attr == "spotblend") + if (!strcmp(attr, "spotblend")) return PyFloat_FromDouble(m_lightobj.m_spotblend); - if (attr == "SPOT") + if (!strcmp(attr, "SPOT")) return PyInt_FromLong(RAS_LightObject::LIGHT_SPOT); - if (attr == "SUN") + if (!strcmp(attr, "SUN")) return PyInt_FromLong(RAS_LightObject::LIGHT_SUN); - if (attr == "NORMAL") + if (!strcmp(attr, "NORMAL")) return PyInt_FromLong(RAS_LightObject::LIGHT_NORMAL); - if (attr == "type") + if (!strcmp(attr, "type")) return PyInt_FromLong(m_lightobj.m_type); _getattr_up(KX_GameObject); } -int KX_LightObject::_setattr(const STR_String& attr, PyObject *pyvalue) -{ - if (attr == "SPOT" || attr == "SUN" || attr == "NORMAL") - { - PyErr_Format(PyExc_RuntimeError, "Attribute %s is read only.", attr.ReadPtr()); - return 1; - } - +int KX_LightObject::_setattr(const char *attr, PyObject *pyvalue) +{ if (PyInt_Check(pyvalue)) { int value = PyInt_AsLong(pyvalue); - if (attr == "layer") + if (!strcmp(attr, "layer")) { m_lightobj.m_layer = value; return 0; } - if (attr == "type") + if (!strcmp(attr, "type")) { if (value >= RAS_LightObject::LIGHT_SPOT && value <= RAS_LightObject::LIGHT_NORMAL) m_lightobj.m_type = (RAS_LightObject::LightType) value; @@ -241,37 +235,37 @@ int KX_LightObject::_setattr(const STR_String& attr, PyObject *pyvalue) if (PyFloat_Check(pyvalue)) { float value = PyFloat_AsDouble(pyvalue); - if (attr == "energy") + if (!strcmp(attr, "energy")) { m_lightobj.m_energy = value; return 0; } - if (attr == "distance") + if (!strcmp(attr, "distance")) { m_lightobj.m_distance = value; return 0; } - if (attr == "lin_attenuation") + if (!strcmp(attr, "lin_attenuation")) { m_lightobj.m_att1 = value; return 0; } - if (attr == "quad_attenuation") + if (!strcmp(attr, "quad_attenuation")) { m_lightobj.m_att2 = value; return 0; } - if (attr == "spotsize") + if (!strcmp(attr, "spotsize")) { m_lightobj.m_spotsize = value; return 0; } - if (attr == "spotblend") + if (!strcmp(attr, "spotblend")) { m_lightobj.m_spotblend = value; return 0; @@ -280,7 +274,7 @@ int KX_LightObject::_setattr(const STR_String& attr, PyObject *pyvalue) if (PySequence_Check(pyvalue)) { - if (attr == "colour" || attr == "color") + if (!strcmp(attr, "colour") || !strcmp(attr, "color")) { MT_Vector3 color; if (PyVecTo(pyvalue, color)) @@ -294,6 +288,12 @@ int KX_LightObject::_setattr(const STR_String& attr, PyObject *pyvalue) } } + if (!strcmp(attr, "SPOT") || !strcmp(attr, "SUN") || !strcmp(attr, "NORMAL")) + { + PyErr_Format(PyExc_RuntimeError, "Attribute %s is read only.", attr); + return 1; + } + return KX_GameObject::_setattr(attr, pyvalue); } diff --git a/source/gameengine/Ketsji/KX_Light.h b/source/gameengine/Ketsji/KX_Light.h index e5dbf0b7f4a..47edd09b5b9 100644 --- a/source/gameengine/Ketsji/KX_Light.h +++ b/source/gameengine/Ketsji/KX_Light.h @@ -63,8 +63,8 @@ public: void UnbindShadowBuffer(class RAS_IRasterizer *ras); void Update(); - virtual PyObject* _getattr(const STR_String& attr); /* lens, near, far, projection_matrix */ - virtual int _setattr(const STR_String& attr, PyObject *pyvalue); + virtual PyObject* _getattr(const char *attr); /* lens, near, far, projection_matrix */ + virtual int _setattr(const char *attr, PyObject *pyvalue); virtual bool IsLight(void) { return true; } }; diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index 5cc102248f2..4b949903c88 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -93,9 +93,9 @@ void KX_MeshProxy::SetMeshModified(bool v) PyObject* -KX_MeshProxy::_getattr(const STR_String& attr) +KX_MeshProxy::_getattr(const char *attr) { - if (attr == "materials") + if (!strcmp(attr, "materials")) { PyObject *materials = PyList_New(0); list::iterator mit = m_meshobj->GetFirstMaterial(); diff --git a/source/gameengine/Ketsji/KX_MeshProxy.h b/source/gameengine/Ketsji/KX_MeshProxy.h index 3335c349673..34f60a54a3a 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.h +++ b/source/gameengine/Ketsji/KX_MeshProxy.h @@ -53,7 +53,7 @@ public: virtual CValue* GetReplica(); // stuff for python integration - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); KX_PYMETHOD(KX_MeshProxy,GetNumMaterials); KX_PYMETHOD(KX_MeshProxy,GetMaterialName); KX_PYMETHOD(KX_MeshProxy,GetTextureName); diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index 28279b9a6b8..3dd70cbb1b8 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -331,7 +331,7 @@ PyMethodDef KX_MouseFocusSensor::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* KX_MouseFocusSensor::_getattr(const STR_String& attr) { +PyObject* KX_MouseFocusSensor::_getattr(const char *attr) { _getattr_up(SCA_MouseSensor); } diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.h b/source/gameengine/Ketsji/KX_MouseFocusSensor.h index 6731444699b..704198ce5a3 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.h +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.h @@ -87,7 +87,7 @@ class KX_MouseFocusSensor : public SCA_MouseSensor /* --------------------------------------------------------------------- */ /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetRayTarget); KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetRaySource); diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index bae87c28123..7ef544618f8 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -320,7 +320,7 @@ PyMethodDef KX_NearSensor::Methods[] = { PyObject* -KX_NearSensor::_getattr(const STR_String& attr) +KX_NearSensor::_getattr(const char *attr) { _getattr_up(KX_TouchSensor); } diff --git a/source/gameengine/Ketsji/KX_NearSensor.h b/source/gameengine/Ketsji/KX_NearSensor.h index 3f7078ef9fd..58c7cc7da91 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.h +++ b/source/gameengine/Ketsji/KX_NearSensor.h @@ -79,7 +79,7 @@ public: virtual void RegisterSumo(KX_TouchEventManager *touchman); virtual void UnregisterSumo(KX_TouchEventManager* touchman); - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); }; diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index 98e73d4f0d7..e04f73a65e5 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -332,7 +332,7 @@ PyMethodDef KX_ObjectActuator::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* KX_ObjectActuator::_getattr(const STR_String& attr) { +PyObject* KX_ObjectActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); }; diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.h b/source/gameengine/Ketsji/KX_ObjectActuator.h index aa686f41233..0331c67617c 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.h +++ b/source/gameengine/Ketsji/KX_ObjectActuator.h @@ -153,7 +153,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForce); KX_PYMETHOD(KX_ObjectActuator,SetForce); diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index c7ac52e571a..5a908186235 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -172,9 +172,9 @@ PyMethodDef KX_ParentActuator::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* KX_ParentActuator::_getattr(const STR_String& attr) { +PyObject* KX_ParentActuator::_getattr(const char *attr) { - if (attr == "object") { + if (!strcmp(attr, "object")) { if (!m_ob) Py_RETURN_NONE; else return m_ob->AddRef(); } @@ -182,9 +182,9 @@ PyObject* KX_ParentActuator::_getattr(const STR_String& attr) { _getattr_up(SCA_IActuator); } -int KX_ParentActuator::_setattr(const STR_String& attr, PyObject* value) { +int KX_ParentActuator::_setattr(const char *attr, PyObject* value) { - if (attr == "object") { + if (!strcmp(attr, "object")) { KX_GameObject *gameobj; if (!ConvertPythonToGameObject(value, &gameobj, true)) diff --git a/source/gameengine/Ketsji/KX_ParentActuator.h b/source/gameengine/Ketsji/KX_ParentActuator.h index e082b4fc209..c974001c0d0 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.h +++ b/source/gameengine/Ketsji/KX_ParentActuator.h @@ -76,8 +76,8 @@ class KX_ParentActuator : public SCA_IActuator /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject* value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject* value); /* 1. setObject */ KX_PYMETHOD_DOC_O(KX_ParentActuator,SetObject); diff --git a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp index da4f05ced7c..246c63feb21 100644 --- a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp +++ b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp @@ -142,23 +142,21 @@ PyParentObject KX_PhysicsObjectWrapper::Parents[] = { NULL }; -PyObject* KX_PhysicsObjectWrapper::_getattr(const STR_String& attr) +PyObject* KX_PhysicsObjectWrapper::_getattr(const char *attr) { _getattr_up(PyObjectPlus); } -int KX_PhysicsObjectWrapper::_setattr(const STR_String& attr,PyObject* pyobj) +int KX_PhysicsObjectWrapper::_setattr(const char *attr,PyObject *pyobj) { - PyTypeObject* type = pyobj->ob_type; int result = 1; - - if (type == &PyInt_Type) + if (PyInt_Check(pyobj)) { result = 0; } - if (type == &PyString_Type) + if (PyString_Check(pyobj)) { result = 0; } diff --git a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.h b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.h index 3dbd1be9323..95560698896 100644 --- a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.h +++ b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.h @@ -36,8 +36,8 @@ class KX_PhysicsObjectWrapper : public PyObjectPlus { Py_Header; - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); public: KX_PhysicsObjectWrapper(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsEnvironment* physenv,PyTypeObject *T = &Type); virtual ~KX_PhysicsObjectWrapper(); diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp index bb9072b34dc..1c9e2a49c11 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.cpp +++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp @@ -77,18 +77,17 @@ PyMethodDef KX_PolyProxy::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* -KX_PolyProxy::_getattr(const STR_String& attr) +PyObject* KX_PolyProxy::_getattr(const char *attr) { - if (attr == "matname") + if (!strcmp(attr, "matname")) { return PyString_FromString(m_polygon->GetMaterial()->GetPolyMaterial()->GetMaterialName()); } - if (attr == "texture") + if (!strcmp(attr, "texture")) { return PyString_FromString(m_polygon->GetMaterial()->GetPolyMaterial()->GetTextureName()); } - if (attr == "material") + if (!strcmp(attr, "material")) { RAS_IPolyMaterial *polymat = m_polygon->GetMaterial()->GetPolyMaterial(); if(polymat->GetFlag() & RAS_BLENDERMAT) @@ -104,7 +103,7 @@ KX_PolyProxy::_getattr(const STR_String& attr) return mat; } } - if (attr == "matid") + if (!strcmp(attr, "matid")) { // we'll have to scan through the material bucket of the mes and compare with // the one of the polygon @@ -119,27 +118,27 @@ KX_PolyProxy::_getattr(const STR_String& attr) } return PyInt_FromLong(matid); } - if (attr == "v1") + if (!strcmp(attr, "v1")) { return PyInt_FromLong(m_polygon->GetVertexOffset(0)); } - if (attr == "v2") + if (!strcmp(attr, "v2")) { return PyInt_FromLong(m_polygon->GetVertexOffset(1)); } - if (attr == "v3") + if (!strcmp(attr, "v3")) { return PyInt_FromLong(m_polygon->GetVertexOffset(2)); } - if (attr == "v4") + if (!strcmp(attr, "v4")) { return PyInt_FromLong(((m_polygon->VertexCount()>3)?m_polygon->GetVertexOffset(3):0)); } - if (attr == "visible") + if (!strcmp(attr, "visible")) { return PyInt_FromLong(m_polygon->IsVisible()); } - if (attr == "collide") + if (!strcmp(attr, "collide")) { return PyInt_FromLong(m_polygon->IsCollider()); } diff --git a/source/gameengine/Ketsji/KX_PolyProxy.h b/source/gameengine/Ketsji/KX_PolyProxy.h index 506e2c2a656..9b548f9490d 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.h +++ b/source/gameengine/Ketsji/KX_PolyProxy.h @@ -53,7 +53,7 @@ public: // stuff for python integration - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,getMaterialIndex) KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,getNumVertex) diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index c9180bf3a80..9c792a3e673 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -202,7 +202,7 @@ PyParentObject KX_PolygonMaterial::Parents[] = { NULL }; -PyObject* KX_PolygonMaterial::_getattr(const STR_String& attr) +PyObject* KX_PolygonMaterial::_getattr(const char *attr) { if (attr == "texture") return PyString_FromString(m_texturename.ReadPtr()); @@ -253,7 +253,7 @@ PyObject* KX_PolygonMaterial::_getattr(const STR_String& attr) _getattr_up(PyObjectPlus); } -int KX_PolygonMaterial::_setattr(const STR_String &attr, PyObject *pyvalue) +int KX_PolygonMaterial::_setattr(const char *attr, PyObject *pyvalue) { if (PyFloat_Check(pyvalue)) { diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.h b/source/gameengine/Ketsji/KX_PolygonMaterial.h index fe116f757db..a3ef4ca51ef 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.h +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.h @@ -115,8 +115,8 @@ public: KX_PYMETHOD_DOC(KX_PolygonMaterial, setCustomMaterial); KX_PYMETHOD_DOC(KX_PolygonMaterial, loadProgram); - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *pyvalue); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *pyvalue); }; #endif // __KX_POLYGONMATERIAL_H__ diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp index 244e9b75d8e..1321b862463 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.cpp +++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp @@ -229,7 +229,7 @@ PyMethodDef KX_RadarSensor::Methods[] = { {NULL,NULL,NULL,NULL} //Sentinel }; -PyObject* KX_RadarSensor::_getattr(const STR_String& attr) { +PyObject* KX_RadarSensor::_getattr(const char *attr) { _getattr_up(KX_TouchSensor); } diff --git a/source/gameengine/Ketsji/KX_RadarSensor.h b/source/gameengine/Ketsji/KX_RadarSensor.h index 7272b219e37..f8f80725145 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.h +++ b/source/gameengine/Ketsji/KX_RadarSensor.h @@ -81,7 +81,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); KX_PYMETHOD_DOC(KX_RadarSensor,GetConeOrigin); KX_PYMETHOD_DOC(KX_RadarSensor,GetConeTarget); diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index e24fb773eac..22611c444df 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -418,6 +418,6 @@ PyObject* KX_RaySensor::PyGetHitNormal(PyObject* self, -PyObject* KX_RaySensor::_getattr(const STR_String& attr) { +PyObject* KX_RaySensor::_getattr(const char *attr) { _getattr_up(SCA_ISensor); } diff --git a/source/gameengine/Ketsji/KX_RaySensor.h b/source/gameengine/Ketsji/KX_RaySensor.h index 02a755fedc1..2baec12f74e 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.h +++ b/source/gameengine/Ketsji/KX_RaySensor.h @@ -79,7 +79,7 @@ public: KX_PYMETHOD_DOC(KX_RaySensor,GetHitNormal); KX_PYMETHOD_DOC(KX_RaySensor,GetRayDirection); - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); }; diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index ab65c93529e..4c331b2c9d6 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -205,9 +205,9 @@ PyMethodDef KX_SCA_AddObjectActuator::Methods[] = { }; -PyObject* KX_SCA_AddObjectActuator::_getattr(const STR_String& attr) +PyObject* KX_SCA_AddObjectActuator::_getattr(const char *attr) { - if (attr == "object") { + if (!strcmp(attr, "object")) { if (!m_OriginalObject) Py_RETURN_NONE; else return m_OriginalObject->AddRef(); } @@ -219,9 +219,9 @@ PyObject* KX_SCA_AddObjectActuator::_getattr(const STR_String& attr) _getattr_up(SCA_IActuator); } -int KX_SCA_AddObjectActuator::_setattr(const STR_String& attr, PyObject* value) { +int KX_SCA_AddObjectActuator::_setattr(const char *attr, PyObject* value) { - if (attr == "object") { + if (!strcmp(attr, "object")) { KX_GameObject *gameobj; if (!ConvertPythonToGameObject(value, &gameobj, true)) diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h index 035f44f16c9..18298cbcb0c 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h @@ -110,8 +110,8 @@ public: virtual bool Update(); - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject* value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject* value); SCA_IObject* GetLastCreatedObject( diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp index 176ccf1a84a..e8d9a7f07c8 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp @@ -87,7 +87,7 @@ PyMethodDef KX_SCA_DynamicActuator::Methods[] = { -PyObject* KX_SCA_DynamicActuator::_getattr(const STR_String& attr) +PyObject* KX_SCA_DynamicActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h index de2fab68d15..a82cddd66a7 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h @@ -64,10 +64,7 @@ class KX_SCA_DynamicActuator : public SCA_IActuator virtual bool Update(); - virtual PyObject* - _getattr( - const STR_String& attr - ); + virtual PyObject* _getattr(const char *attr); /* 1. setOperation */ KX_PYMETHOD_DOC(KX_SCA_DynamicActuator,setOperation); diff --git a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp index ec29448907f..443921d22b0 100644 --- a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp @@ -128,7 +128,7 @@ PyMethodDef KX_SCA_EndObjectActuator::Methods[] = { }; -PyObject* KX_SCA_EndObjectActuator::_getattr(const STR_String& attr) +PyObject* KX_SCA_EndObjectActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.h b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.h index add9c05b000..12118743f0a 100644 --- a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.h @@ -64,10 +64,7 @@ class KX_SCA_EndObjectActuator : public SCA_IActuator /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* - _getattr( - const STR_String& attr - ); + virtual PyObject* _getattr(const char *attr); }; /* end of class KX_EditObjectActuator : public SCA_PropertyActuator */ diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index 261d9ec8f0c..ccc3b8fdb18 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -91,7 +91,7 @@ PyMethodDef KX_SCA_ReplaceMeshActuator::Methods[] = { -PyObject* KX_SCA_ReplaceMeshActuator::_getattr(const STR_String& attr) +PyObject* KX_SCA_ReplaceMeshActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h index 1da154cc222..0ba60650683 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h @@ -69,10 +69,7 @@ class KX_SCA_ReplaceMeshActuator : public SCA_IActuator virtual bool Update(); - virtual PyObject* - _getattr( - const STR_String& attr - ); + virtual PyObject* _getattr(const char *attr); void InstantReplaceMesh(); /* 1. setMesh */ diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 476a931355f..49babedd467 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1544,28 +1544,28 @@ PyParentObject KX_Scene::Parents[] = { NULL }; -PyObject* KX_Scene::_getattr(const STR_String& attr) +PyObject* KX_Scene::_getattr(const char *attr) { - if (attr == "name") + if (!strcmp(attr, "name")) return PyString_FromString(GetName()); - if (attr == "active_camera") + if (!strcmp(attr, "active_camera")) { KX_Camera *camera = GetActiveCamera(); camera->AddRef(); return (PyObject*) camera; } - if (attr == "suspended") + if (!strcmp(attr, "suspended")) return PyInt_FromLong(m_suspend); - if (attr == "activity_culling") + if (!strcmp(attr, "activity_culling")) return PyInt_FromLong(m_activity_culling); - if (attr == "activity_culling_radius") + if (!strcmp(attr, "activity_culling_radius")) return PyFloat_FromDouble(m_activity_box_radius); - PyObject* value = PyDict_GetItemString(m_attrlist, const_cast(attr.ReadPtr())); + PyObject* value = PyDict_GetItemString(m_attrlist, attr); if (value) { Py_INCREF(value); @@ -1575,16 +1575,15 @@ PyObject* KX_Scene::_getattr(const STR_String& attr) _getattr_up(PyObjectPlus); } -int KX_Scene::_delattr(const STR_String &attr) +int KX_Scene::_delattr(const char *attr) { - PyDict_DelItemString(m_attrlist, const_cast(attr.ReadPtr())); + PyDict_DelItemString(m_attrlist, attr); return 0; } -int KX_Scene::_setattr(const STR_String &attr, PyObject *pyvalue) +int KX_Scene::_setattr(const char *attr, PyObject *pyvalue) { - - if (!PyDict_SetItemString(m_attrlist, const_cast(attr.ReadPtr()), pyvalue)) + if (!PyDict_SetItemString(m_attrlist, attr, pyvalue)) return 0; return PyObjectPlus::_setattr(attr, pyvalue); diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 5f7e1167e27..ecc0fd51d73 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -564,9 +564,9 @@ public: KX_PYMETHOD_DOC(KX_Scene, setSceneViewport); */ - virtual PyObject* _getattr(const STR_String& attr); /* name, active_camera, gravity, suspended, viewport, framing, activity_culling, activity_culling_radius */ - virtual int _setattr(const STR_String &attr, PyObject *pyvalue); - virtual int _delattr(const STR_String &attr); + virtual PyObject* _getattr(const char *attr); /* name, active_camera, gravity, suspended, viewport, framing, activity_culling, activity_culling_radius */ + virtual int _setattr(const char *attr, PyObject *pyvalue); + virtual int _delattr(const char *attr); /** * Sets the time the scene was suspended diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index 35484699b17..a5f49f97d4b 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -270,7 +270,7 @@ PyMethodDef KX_SceneActuator::Methods[] = -PyObject* KX_SceneActuator::_getattr(const STR_String& attr) +PyObject* KX_SceneActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_SceneActuator.h b/source/gameengine/Ketsji/KX_SceneActuator.h index 55aaf629d7c..af11af955bf 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.h +++ b/source/gameengine/Ketsji/KX_SceneActuator.h @@ -92,7 +92,7 @@ class KX_SceneActuator : public SCA_IActuator /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); /* 1. set */ /* Removed */ diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index afa5af3bc04..ba60ea81739 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -287,7 +287,7 @@ PyMethodDef KX_SoundActuator::Methods[] = { -PyObject* KX_SoundActuator::_getattr(const STR_String& attr) +PyObject* KX_SoundActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_SoundActuator.h b/source/gameengine/Ketsji/KX_SoundActuator.h index 5a9edbc4c5e..68d5b792729 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.h +++ b/source/gameengine/Ketsji/KX_SoundActuator.h @@ -80,7 +80,7 @@ public: /* Python interface --------------------------------------------------- */ /* -------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); KX_PYMETHOD(KX_SoundActuator,SetFilename); KX_PYMETHOD(KX_SoundActuator,GetFilename); diff --git a/source/gameengine/Ketsji/KX_StateActuator.cpp b/source/gameengine/Ketsji/KX_StateActuator.cpp index e360c4bac1f..7237d6ced1e 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.cpp +++ b/source/gameengine/Ketsji/KX_StateActuator.cpp @@ -146,10 +146,7 @@ KX_StateActuator::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* -KX_StateActuator::_getattr( - const STR_String& attr - ) +PyObject* KX_StateActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); }; diff --git a/source/gameengine/Ketsji/KX_StateActuator.h b/source/gameengine/Ketsji/KX_StateActuator.h index 8698e51b2c1..023b8993d7c 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.h +++ b/source/gameengine/Ketsji/KX_StateActuator.h @@ -73,7 +73,7 @@ class KX_StateActuator : public SCA_IActuator /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); //KX_PYMETHOD_DOC KX_PYMETHOD_DOC(KX_StateActuator,SetOperation); KX_PYMETHOD_DOC(KX_StateActuator,SetMask); diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 0000d5793b6..6528ec466ce 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -261,7 +261,7 @@ PyMethodDef KX_TouchSensor::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* KX_TouchSensor::_getattr(const STR_String& attr) { +PyObject* KX_TouchSensor::_getattr(const char *attr) { _getattr_up(SCA_ISensor); } diff --git a/source/gameengine/Ketsji/KX_TouchSensor.h b/source/gameengine/Ketsji/KX_TouchSensor.h index 8fbb1c676ba..e07f89f0a31 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.h +++ b/source/gameengine/Ketsji/KX_TouchSensor.h @@ -106,7 +106,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); /* 1. setProperty */ KX_PYMETHOD_DOC(KX_TouchSensor,SetProperty); diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 515349fbba8..f9f804cfc66 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -470,9 +470,9 @@ PyMethodDef KX_TrackToActuator::Methods[] = { -PyObject* KX_TrackToActuator::_getattr(const STR_String& attr) +PyObject* KX_TrackToActuator::_getattr(const char *attr) { - if (attr == "object") { + if (!strcmp(attr, "object")) { if (!m_object) Py_RETURN_NONE; else return m_object->AddRef(); } @@ -480,10 +480,10 @@ PyObject* KX_TrackToActuator::_getattr(const STR_String& attr) _getattr_up(SCA_IActuator); } -int KX_TrackToActuator::_setattr(const STR_String& attr, PyObject* value) { +int KX_TrackToActuator::_setattr(const char *attr, PyObject* value) { int ret; - if (attr == "object") { + if (!strcmp(attr, "object")) { KX_GameObject *gameobj; if (!ConvertPythonToGameObject(value, &gameobj, true)) diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.h b/source/gameengine/Ketsji/KX_TrackToActuator.h index c9cae905240..392e55402f1 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.h +++ b/source/gameengine/Ketsji/KX_TrackToActuator.h @@ -72,8 +72,8 @@ class KX_TrackToActuator : public SCA_IActuator virtual bool Update(double curtime, bool frame); /* Python part */ - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject* value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject* value); /* 1. setObject */ KX_PYMETHOD_DOC_O(KX_TrackToActuator,SetObject); diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp index 028f96f6c5b..057e10f195a 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp @@ -322,13 +322,13 @@ PyParentObject KX_VehicleWrapper::Parents[] = { NULL }; -PyObject* KX_VehicleWrapper::_getattr(const STR_String& attr) +PyObject* KX_VehicleWrapper::_getattr(const char *attr) { //here you can search for existing data members (like mass,friction etc.) _getattr_up(PyObjectPlus); } -int KX_VehicleWrapper::_setattr(const STR_String& attr,PyObject* pyobj) +int KX_VehicleWrapper::_setattr(const char *attr,PyObject* pyobj) { PyTypeObject* type = pyobj->ob_type; diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.h b/source/gameengine/Ketsji/KX_VehicleWrapper.h index b98369d401a..cad926ce85a 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.h +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.h @@ -12,8 +12,8 @@ class PHY_IMotionState; class KX_VehicleWrapper : public PyObjectPlus { Py_Header; - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *value); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); std::vector m_motionStates; diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp index 25205714308..eddd110ee81 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.cpp +++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp @@ -79,15 +79,43 @@ PyMethodDef KX_VertexProxy::Methods[] = { }; PyObject* -KX_VertexProxy::_getattr(const STR_String& attr) +KX_VertexProxy::_getattr(const char *attr) { - if (attr == "XYZ") + + if (attr[1]=='\0') { // Group single letters + // pos + if (attr[0]=='x') + return PyFloat_FromDouble(m_vertex->getXYZ()[0]); + if (attr[0]=='y') + return PyFloat_FromDouble(m_vertex->getXYZ()[1]); + if (attr[0]=='z') + return PyFloat_FromDouble(m_vertex->getXYZ()[2]); + + // Col + if (attr[0]=='r') + return PyFloat_FromDouble(m_vertex->getRGBA()[0]/255.0); + if (attr[0]=='g') + return PyFloat_FromDouble(m_vertex->getRGBA()[1]/255.0); + if (attr[0]=='b') + return PyFloat_FromDouble(m_vertex->getRGBA()[2]/255.0); + if (attr[0]=='a') + return PyFloat_FromDouble(m_vertex->getRGBA()[3]/255.0); + + // UV + if (attr[0]=='u') + return PyFloat_FromDouble(m_vertex->getUV1()[0]); + if (attr[0]=='v') + return PyFloat_FromDouble(m_vertex->getUV1()[1]); + } + + + if (!strcmp(attr, "XYZ")) return PyObjectFrom(MT_Vector3(m_vertex->getXYZ())); - if (attr == "UV") + if (!strcmp(attr, "UV")) return PyObjectFrom(MT_Point2(m_vertex->getUV1())); - if (attr == "colour" || attr == "color") + if (!strcmp(attr, "color") || !strcmp(attr, "colour")) { const unsigned char *colp = m_vertex->getRGBA(); MT_Vector4 color(colp[0], colp[1], colp[2], colp[3]); @@ -95,43 +123,19 @@ KX_VertexProxy::_getattr(const STR_String& attr) return PyObjectFrom(color); } - if (attr == "normal") + if (!strcmp(attr, "normal")) { return PyObjectFrom(MT_Vector3(m_vertex->getNormal())); } - - // pos - if (attr == "x") - return PyFloat_FromDouble(m_vertex->getXYZ()[0]); - if (attr == "y") - return PyFloat_FromDouble(m_vertex->getXYZ()[1]); - if (attr == "z") - return PyFloat_FromDouble(m_vertex->getXYZ()[2]); - - // Col - if (attr == "r") - return PyFloat_FromDouble(m_vertex->getRGBA()[0]/255.0); - if (attr == "g") - return PyFloat_FromDouble(m_vertex->getRGBA()[1]/255.0); - if (attr == "b") - return PyFloat_FromDouble(m_vertex->getRGBA()[2]/255.0); - if (attr == "a") - return PyFloat_FromDouble(m_vertex->getRGBA()[3]/255.0); - - // UV - if (attr == "u") - return PyFloat_FromDouble(m_vertex->getUV1()[0]); - if (attr == "v") - return PyFloat_FromDouble(m_vertex->getUV1()[1]); - + _getattr_up(SCA_IObject); } -int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue) +int KX_VertexProxy::_setattr(const char *attr, PyObject *pyvalue) { if (PySequence_Check(pyvalue)) { - if (attr == "XYZ") + if (!strcmp(attr, "XYZ")) { MT_Point3 vec; if (PyVecTo(pyvalue, vec)) @@ -143,7 +147,7 @@ int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue) return 1; } - if (attr == "UV") + if (!strcmp(attr, "UV")) { MT_Point2 vec; if (PyVecTo(pyvalue, vec)) @@ -155,7 +159,7 @@ int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue) return 1; } - if (attr == "colour" || attr == "color") + if (!strcmp(attr, "color") || !strcmp(attr, "colour")) { MT_Vector4 vec; if (PyVecTo(pyvalue, vec)) @@ -167,7 +171,7 @@ int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue) return 1; } - if (attr == "normal") + if (!strcmp(attr, "normal")) { MT_Vector3 vec; if (PyVecTo(pyvalue, vec)) @@ -185,7 +189,7 @@ int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue) float val = PyFloat_AsDouble(pyvalue); // pos MT_Point3 pos(m_vertex->getXYZ()); - if (attr == "x") + if (!strcmp(attr, "x")) { pos.x() = val; m_vertex->SetXYZ(pos); @@ -193,7 +197,7 @@ int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue) return 0; } - if (attr == "y") + if (!strcmp(attr, "y")) { pos.y() = val; m_vertex->SetXYZ(pos); @@ -201,7 +205,7 @@ int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue) return 0; } - if (attr == "z") + if (!strcmp(attr, "z")) { pos.z() = val; m_vertex->SetXYZ(pos); @@ -211,7 +215,7 @@ int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue) // uv MT_Point2 uv = m_vertex->getUV1(); - if (attr == "u") + if (!strcmp(attr, "u")) { uv[0] = val; m_vertex->SetUV(uv); @@ -219,7 +223,7 @@ int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue) return 0; } - if (attr == "v") + if (!strcmp(attr, "v")) { uv[1] = val; m_vertex->SetUV(uv); @@ -229,7 +233,7 @@ int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue) // uv MT_Point2 uv2 = m_vertex->getUV2(); - if (attr == "u2") + if (!strcmp(attr, "u2")) { uv[0] = val; m_vertex->SetUV2(uv); @@ -237,7 +241,7 @@ int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue) return 0; } - if (attr == "v2") + if (!strcmp(attr, "v2")) { uv[1] = val; m_vertex->SetUV2(uv); @@ -249,28 +253,28 @@ int KX_VertexProxy::_setattr(const STR_String& attr, PyObject *pyvalue) unsigned int icol = *((const unsigned int *)m_vertex->getRGBA()); unsigned char *cp = (unsigned char*) &icol; val *= 255.0; - if (attr == "r") + if (!strcmp(attr, "r")) { cp[0] = (unsigned char) val; m_vertex->SetRGBA(icol); m_mesh->SetMeshModified(true); return 0; } - if (attr == "g") + if (!strcmp(attr, "g")) { cp[1] = (unsigned char) val; m_vertex->SetRGBA(icol); m_mesh->SetMeshModified(true); return 0; } - if (attr == "b") + if (!strcmp(attr, "b")) { cp[2] = (unsigned char) val; m_vertex->SetRGBA(icol); m_mesh->SetMeshModified(true); return 0; } - if (attr == "a") + if (!strcmp(attr, "a")) { cp[3] = (unsigned char) val; m_vertex->SetRGBA(icol); diff --git a/source/gameengine/Ketsji/KX_VertexProxy.h b/source/gameengine/Ketsji/KX_VertexProxy.h index e154ea11b40..72949268e6d 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.h +++ b/source/gameengine/Ketsji/KX_VertexProxy.h @@ -54,8 +54,8 @@ public: // stuff for python integration - virtual PyObject* _getattr(const STR_String& attr); - virtual int _setattr(const STR_String& attr, PyObject *pyvalue); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *pyvalue); KX_PYMETHOD(KX_VertexProxy,GetXYZ); KX_PYMETHOD(KX_VertexProxy,SetXYZ); diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp index 4b0db5a7953..0a4aaa0dffe 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp @@ -126,10 +126,7 @@ KX_VisibilityActuator::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* -KX_VisibilityActuator::_getattr( - const STR_String& attr - ) +PyObject* KX_VisibilityActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); }; diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.h b/source/gameengine/Ketsji/KX_VisibilityActuator.h index d1b85ab998c..323280de8cb 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.h +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.h @@ -67,7 +67,7 @@ class KX_VisibilityActuator : public SCA_IActuator /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const STR_String& attr); + virtual PyObject* _getattr(const char *attr); //KX_PYMETHOD_DOC KX_PYMETHOD_DOC(KX_VisibilityActuator,SetVisible); -- cgit v1.2.3 From d3e7b37fff6d2644c5b931ba38777550faad7011 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Thu, 19 Feb 2009 23:13:41 +0000 Subject: BGE API Cleanup: distinction between array and list of values in KX_PYATTRIBUTE macros. Fix compilation problem under Windows with strcasecmp: define it as stricmp --- source/gameengine/Expressions/InputParser.cpp | 3 ++ source/gameengine/Expressions/PyObjectPlus.h | 32 +++++++++++++++++----- source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 4 +-- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 2 +- 4 files changed, 31 insertions(+), 10 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/InputParser.cpp b/source/gameengine/Expressions/InputParser.cpp index c3869d8f89b..a60e1ee59dc 100644 --- a/source/gameengine/Expressions/InputParser.cpp +++ b/source/gameengine/Expressions/InputParser.cpp @@ -38,6 +38,9 @@ // cool things like (IF(LOD==1,CCurvedValue,IF(LOD==2,CCurvedValue2)) etc... #include "IfExpr.h" +#if defined(WIN32) || defined(WIN64) +#define strcasecmp _stricmp +#endif /* Def WIN32 or Def WIN64 */ #define NUM_PRIORITY 6 ////////////////////////////////////////////////////////////////////// diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 5092c8106ec..5ba894ef23a 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -283,10 +283,17 @@ typedef struct KX_PYATTRIBUTE_DEF { #define KX_PYATTRIBUTE_SHORT_RO(name,object,field) \ { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_SHORT_ARRAY_RW(name,min,max,clamp,object,field,length) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_SHORT_ARRAY_RW_CHECK(name,min,max,clamp,object,field,length,function) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, {NULL, &((object *)0)->field, NULL, NULL, NULL} } + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, {NULL, ((object *)0)->field, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_SHORT_ARRAY_RO(name,object,field,length) \ + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL} } +// SHORT_LIST +#define KX_PYATTRIBUTE_SHORT_LIST_RW(name,min,max,clamp,object,field,length) \ + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_SHORT_LIST_RW_CHECK(name,min,max,clamp,object,field,length,function) \ + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, {NULL, &((object *)0)->field, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_SHORT_LIST_RO(name,object,field,length) \ { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_INT_RW(name,min,max,clamp,object,field) \ @@ -296,10 +303,17 @@ typedef struct KX_PYATTRIBUTE_DEF { #define KX_PYATTRIBUTE_INT_RO(name,object,field) \ { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } #define KX_PYATTRIBUTE_INT_ARRAY_RW(name,min,max,clamp,object,field,length) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL} } #define KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK(name,min,max,clamp,object,field,length,function) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, {NULL, NULL, &((object *)0)->field, NULL, NULL} } + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, {NULL, NULL, ((object *)0)->field, NULL, NULL} } #define KX_PYATTRIBUTE_INT_ARRAY_RO(name,object,field,length) \ + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL} } +// INT_LIST +#define KX_PYATTRIBUTE_INT_LIST_RW(name,min,max,clamp,object,field,length) \ + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } +#define KX_PYATTRIBUTE_INT_LIST_RW_CHECK(name,min,max,clamp,object,field,length,function) \ + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, {NULL, NULL, &((object *)0)->field, NULL, NULL} } +#define KX_PYATTRIBUTE_INT_LIST_RO(name,object,field,length) \ { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL} } // always clamp for float @@ -310,11 +324,11 @@ typedef struct KX_PYATTRIBUTE_DEF { #define KX_PYATTRIBUTE_FLOAT_RO(name,object,field) \ { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } #define KX_PYATTRIBUTE_FLOAT_ARRAY_RW(name,min,max,object,field,length) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, offsetof(object,field), 0, length, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, offsetof(object,field), 0, length, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL} } #define KX_PYATTRIBUTE_FLOAT_ARRAY_RW_CHECK(name,min,max,object,field,length,function) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, offsetof(object,field), 0, length, &object::function, {NULL, NULL, NULL, &((object *)0)->field, NULL} } + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, offsetof(object,field), 0, length, &object::function, {NULL, NULL, NULL, ((object *)0)->field, NULL} } #define KX_PYATTRIBUTE_FLOAT_ARRAY_RO(name,object,field,length) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL} } + { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL} } #define KX_PYATTRIBUTE_STRING_RW(name,min,max,clamp,object,field) \ { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field} } @@ -323,6 +337,10 @@ typedef struct KX_PYATTRIBUTE_DEF { #define KX_PYATTRIBUTE_STRING_RO(name,object,field) \ { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, 1 , NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field} } +//Multiple integer +#define KX_PYATTRIBUTE_MINT_RW_CHECK(name,min,max,clamp,object,field,length,function) \ + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, {NULL, NULL, &((object *)0)->field, NULL, NULL} } + /*------------------------------ * PyObjectPlus ------------------------------*/ diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 17a8710ed48..c2d90c830cf 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -331,8 +331,8 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = { KX_PYATTRIBUTE_SHORT_RW("index",0,JOYINDEX_MAX-1,true,SCA_JoystickSensor,m_joyindex), KX_PYATTRIBUTE_INT_RW("threshold",0,32768,true,SCA_JoystickSensor,m_precision), KX_PYATTRIBUTE_INT_RW("button",0,100,false,SCA_JoystickSensor,m_button), - KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK("axis",0,3,true,SCA_JoystickSensor,m_axis,2,CheckAxis), - KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK("hat",0,12,true,SCA_JoystickSensor,m_hat,2,CheckHat), + KX_PYATTRIBUTE_INT_LIST_RW_CHECK("axis",0,3,true,SCA_JoystickSensor,m_axis,2,CheckAxis), + KX_PYATTRIBUTE_INT_LIST_RW_CHECK("hat",0,12,true,SCA_JoystickSensor,m_hat,2,CheckHat), // dummy attributes will just be read-only in _setattr // you still need to defined them in _getattr KX_PYATTRIBUTE_DUMMY("axisPosition"), diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index a96d3758d3c..73f784b7e92 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -337,7 +337,7 @@ PyMethodDef SCA_MouseSensor::Methods[] = { PyAttributeDef SCA_MouseSensor::Attributes[] = { KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",KX_MOUSESENSORMODE_NODEF,KX_MOUSESENSORMODE_MAX-1,true,SCA_MouseSensor,m_mousemode,UpdateHotkey), - KX_PYATTRIBUTE_SHORT_ARRAY_RO("position",SCA_MouseSensor,m_x,2), + KX_PYATTRIBUTE_SHORT_LIST_RO("position",SCA_MouseSensor,m_x,2), { NULL } //Sentinel }; -- cgit v1.2.3 From 9d5c2af1d1e11d40fec6c0da96cb37de1684f13c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 21 Feb 2009 12:43:24 +0000 Subject: * removed typedefs that were not used (from anonymous enums and structs) * Missed some cases of using a 'char *' as an attribute * replace BGE's Py_Return macro with Pythons Py_RETURN_NONE * other minor warnings removed --- .../Converter/BL_ShapeActionActuator.cpp | 2 +- source/gameengine/Expressions/ListValue.cpp | 2 +- source/gameengine/Expressions/PyObjectPlus.cpp | 1 - source/gameengine/Expressions/PyObjectPlus.h | 9 +-- source/gameengine/GameLogic/SCA_ActuatorSensor.cpp | 2 +- source/gameengine/GameLogic/SCA_DelaySensor.cpp | 6 +- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 2 +- source/gameengine/GameLogic/SCA_ISensor.cpp | 12 ++-- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 12 ++-- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 2 +- .../gameengine/GameLogic/SCA_PropertyActuator.cpp | 4 +- source/gameengine/GameLogic/SCA_PropertySensor.cpp | 6 +- source/gameengine/GameLogic/SCA_RandomActuator.cpp | 24 ++++---- source/gameengine/GameLogic/SCA_RandomSensor.cpp | 2 +- source/gameengine/Ketsji/BL_Shader.cpp | 50 ++++++++-------- .../Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp | 8 +-- source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 10 ++-- source/gameengine/Ketsji/KX_CDActuator.cpp | 8 +-- source/gameengine/Ketsji/KX_Camera.cpp | 8 +-- source/gameengine/Ketsji/KX_Camera.h | 2 +- source/gameengine/Ketsji/KX_CameraActuator.cpp | 8 +-- source/gameengine/Ketsji/KX_ConstraintActuator.cpp | 18 +++--- source/gameengine/Ketsji/KX_GameActuator.cpp | 2 +- source/gameengine/Ketsji/KX_GameObject.cpp | 2 +- source/gameengine/Ketsji/KX_IpoActuator.cpp | 16 ++--- source/gameengine/Ketsji/KX_MouseFocusSensor.cpp | 2 +- source/gameengine/Ketsji/KX_ObjectActuator.cpp | 22 +++---- source/gameengine/Ketsji/KX_PolygonMaterial.cpp | 68 +++++++++++----------- source/gameengine/Ketsji/KX_RaySensor.cpp | 2 +- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp | 3 +- .../gameengine/Ketsji/KX_SCA_DynamicActuator.cpp | 2 +- source/gameengine/Ketsji/KX_SceneActuator.cpp | 8 +-- source/gameengine/Ketsji/KX_SoundActuator.cpp | 24 ++++---- source/gameengine/Ketsji/KX_StateActuator.cpp | 4 +- source/gameengine/Ketsji/KX_TouchSensor.cpp | 6 +- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 9 ++- source/gameengine/Ketsji/KX_VertexProxy.cpp | 12 ++-- source/gameengine/Ketsji/KX_VisibilityActuator.cpp | 2 +- .../Physics/Sumo/Fuzzics/include/SM_Scene.h | 2 +- .../gameengine/Physics/common/PHY_DynamicTypes.h | 2 +- 40 files changed, 190 insertions(+), 196 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index 7cba6b01e1a..2e02ee9b941 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -911,6 +911,6 @@ PyObject* BL_ShapeActionActuator::PySetType(PyObject* self, printf("Invalid type for action actuator: %d\n", typeArg); /* error */ } - Py_Return; + Py_RETURN_NONE; } diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 3cf22bdc9bd..b8a8a1a63b2 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -429,7 +429,7 @@ PyObject* CListValue::Pyreverse(PyObject* self, { std::reverse(m_pValueArray.begin(),m_pValueArray.end()); - Py_Return; + Py_RETURN_NONE; } diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 16184b7c5f2..2c4fbd5a867 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -697,7 +697,6 @@ bool PyObjectPlus::isA(const char *mytypename) // check typename of each parent PyObject *PyObjectPlus::Py_isA(PyObject *value) // Python wrapper for isA { - char *mytypename; if (!PyString_Check(value)) { PyErr_SetString(PyExc_TypeError, "expected a string"); return NULL; diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 5ba894ef23a..0fae175e3cf 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -72,9 +72,6 @@ typedef int Py_ssize_t; #define PY_METHODCHAR const char * #endif - // some basic python macros -#define Py_Return { Py_INCREF(Py_None); return Py_None;} - static inline void Py_Fatal(const char *M) { //cout << M << endl; exit(-1); @@ -394,10 +391,10 @@ public: // isA methods bool isA(PyTypeObject *T); bool isA(const char *mytypename); - PyObject *Py_isA(PyObject *args); - static PyObject *sPy_isA(PyObject *self, PyObject *args, PyObject *kwd) + PyObject *Py_isA(PyObject *value); + static PyObject *sPy_isA(PyObject *self, PyObject *value) { - return ((PyObjectPlus*)self)->Py_isA(args); + return ((PyObjectPlus*)self)->Py_isA(value); } }; diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp index dcdd7df50d4..7f8dbef7758 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp @@ -221,7 +221,7 @@ PyObject* SCA_ActuatorSensor::PySetActuator(PyObject* self, PyObject* args, PyOb } else { ; /* error: bad actuator name */ } - Py_Return; + Py_RETURN_NONE; } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp index 802edc4b6cf..25c9888cadd 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp +++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp @@ -211,7 +211,7 @@ PyObject* SCA_DelaySensor::PySetDelay(PyObject* self, PyObject* args, PyObject* return NULL; } m_delay = delay; - Py_Return; + Py_RETURN_NONE; } const char SCA_DelaySensor::SetDuration_doc[] = @@ -233,7 +233,7 @@ PyObject* SCA_DelaySensor::PySetDuration(PyObject* self, PyObject* args, PyObjec return NULL; } m_duration = duration; - Py_Return; + Py_RETURN_NONE; } const char SCA_DelaySensor::SetRepeat_doc[] = @@ -250,7 +250,7 @@ PyObject* SCA_DelaySensor::PySetRepeat(PyObject* self, PyObject* args, PyObject* return NULL; } m_repeat = (repeat != 0); - Py_Return; + Py_RETURN_NONE; } const char SCA_DelaySensor::GetDelay_doc[] = diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index 70938db7c3d..49d39f75814 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -324,7 +324,7 @@ PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* self, m_Execute_Ueber_Priority = priority; - Py_Return; + Py_RETURN_NONE; } diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index 73475b018fc..e8a072f4c46 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -264,7 +264,7 @@ PyObject* SCA_ISensor::PySetUsePosPulseMode(PyObject* self, PyObject* args, PyOb int pyarg = 0; if(!PyArg_ParseTuple(args, "i", &pyarg)) { return NULL; } m_pos_pulsemode = PyArgToBool(pyarg); - Py_Return; + Py_RETURN_NONE; } /** @@ -303,7 +303,7 @@ PyObject* SCA_ISensor::PySetFrequency(PyObject* self, PyObject* args, PyObject* }; m_pulse_frequency = pulse_frequencyArg; - Py_Return; + Py_RETURN_NONE; } @@ -326,7 +326,7 @@ PyObject* SCA_ISensor::PySetInvert(PyObject* self, PyObject* args, PyObject* kwd int pyarg = 0; if(!PyArg_ParseTuple(args, "i", &pyarg)) { return NULL; } m_invert = PyArgToBool(pyarg); - Py_Return; + Py_RETURN_NONE; } const char SCA_ISensor::GetLevel_doc[] = @@ -352,7 +352,7 @@ PyObject* SCA_ISensor::PySetLevel(PyObject* self, PyObject* args, PyObject* kwds int pyarg = 0; if(!PyArg_ParseTuple(args, "i", &pyarg)) { return NULL; } m_level = PyArgToBool(pyarg); - Py_Return; + Py_RETURN_NONE; } const char SCA_ISensor::GetUseNegPulseMode_doc[] = @@ -375,7 +375,7 @@ PyObject* SCA_ISensor::PySetUseNegPulseMode(PyObject* self, PyObject* args, PyOb int pyarg = 0; if(!PyArg_ParseTuple(args, "i", &pyarg)) { return NULL; } m_neg_pulsemode = PyArgToBool(pyarg); - Py_Return; + Py_RETURN_NONE; } //<------Deprecated @@ -385,7 +385,7 @@ KX_PYMETHODDEF_DOC_NOARGS(SCA_ISensor, reset, "\tThe sensor is put in its initial state as if it was just activated.\n") { Init(); - Py_Return; + Py_RETURN_NONE; } /* ----------------------------------------------- */ diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index 0edc41bef7b..324e5eae98a 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -577,7 +577,7 @@ PyObject* SCA_KeyboardSensor::PySetKey(PyObject* self, PyObject* args, PyObject* /* anything. It's up to the user to provide a sensible number. */ m_hotkey = keyCode; - Py_Return; + Py_RETURN_NONE; } /** 3. GetHold1 : set the first bucky bit */ @@ -609,7 +609,7 @@ PyObject* SCA_KeyboardSensor::PySetHold1(PyObject* self, PyObject* args, PyObjec /* anything. It's up to the user to provide a sensible number. */ m_qual = keyCode; - Py_Return; + Py_RETURN_NONE; } /** 5. GetHold2 : get the second bucky bit */ @@ -641,7 +641,7 @@ PyObject* SCA_KeyboardSensor::PySetHold2(PyObject* self, PyObject* args, PyObjec /* anything. It's up to the user to provide a sensible number. */ m_qual2 = keyCode; - Py_Return; + Py_RETURN_NONE; } @@ -682,7 +682,7 @@ PyObject* SCA_KeyboardSensor::PyGetPressedKeys(PyObject* self, PyObject* args, P if (index>0) return resultlist; } - Py_Return; + Py_RETURN_NONE; } @@ -725,7 +725,7 @@ SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); if (index > 0) return resultlist; } - Py_Return; + Py_RETURN_NONE; } //<---- Deprecated @@ -770,7 +770,7 @@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus, return PyInt_FromLong(inevent.m_status); } - Py_Return; + Py_RETURN_NONE; } /* ------------------------------------------------------------------------- */ diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index 73f784b7e92..4f4d62f13b9 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -292,7 +292,7 @@ KX_PYMETHODDEF_DOC_O(SCA_MouseSensor, getButtonStatus, return PyInt_FromLong(event.m_status); } - Py_Return; + Py_RETURN_NONE; } /* ------------------------------------------------------------------------- */ diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index 644b82a92bf..c9ace081bae 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -298,7 +298,7 @@ PyObject* SCA_PropertyActuator::PySetProperty(PyObject* self, PyObject* args, Py } prop->Release(); - Py_Return; + Py_RETURN_NONE; } /* 2. getProperty */ @@ -328,7 +328,7 @@ PyObject* SCA_PropertyActuator::PySetValue(PyObject* self, PyObject* args, PyObj if (valArg) m_exprtxt = valArg; - Py_Return; + Py_RETURN_NONE; } /* 4. getValue */ diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp index 10d49769162..d683c8bb3e7 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp +++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp @@ -397,7 +397,7 @@ PyObject* SCA_PropertySensor::PySetType(PyObject* self, PyObject* args, PyObject m_checktype = typeArg; } - Py_Return; + Py_RETURN_NONE; } /* 3. getProperty */ @@ -434,7 +434,7 @@ PyObject* SCA_PropertySensor::PySetProperty(PyObject* self, PyObject* args, PyOb ; /* error: bad property name */ } prop->Release(); - Py_Return; + Py_RETURN_NONE; } /* 5. getValue */ @@ -470,7 +470,7 @@ PyObject* SCA_PropertySensor::PySetValue(PyObject* self, PyObject* args, PyObjec m_checkpropval = oldval; return NULL; } - Py_Return; + Py_RETURN_NONE; } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp index 7aa25d22b3f..d6c73f21f37 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp +++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp @@ -413,7 +413,7 @@ PyObject* SCA_RandomActuator::PySetSeed(PyObject* self, PyObject* args, PyObject m_base->SetSeed(seedArg); - Py_Return; + Py_RETURN_NONE; } /* 2. getSeed */ const char SCA_RandomActuator::GetSeed_doc[] = @@ -478,7 +478,7 @@ PyObject* SCA_RandomActuator::PySetProperty(PyObject* self, PyObject* args, PyOb } prop->Release(); - Py_Return; + Py_RETURN_NONE; } /* 10. getProperty */ const char SCA_RandomActuator::GetProperty_doc[] = @@ -506,7 +506,7 @@ PyObject* SCA_RandomActuator::PySetBoolConst(PyObject* self, m_distribution = KX_RANDOMACT_BOOL_CONST; m_parameter1 = (paraArg) ? 1.0 : 0.0; - Py_Return; + Py_RETURN_NONE; } /* 12. setBoolUniform, */ const char SCA_RandomActuator::SetBoolUniform_doc[] = @@ -518,7 +518,7 @@ PyObject* SCA_RandomActuator::PySetBoolUniform(PyObject* self, /* no args */ m_distribution = KX_RANDOMACT_BOOL_UNIFORM; enforceConstraints(); - Py_Return; + Py_RETURN_NONE; } /* 13. setBoolBernouilli, */ const char SCA_RandomActuator::SetBoolBernouilli_doc[] = @@ -536,7 +536,7 @@ PyObject* SCA_RandomActuator::PySetBoolBernouilli(PyObject* self, m_distribution = KX_RANDOMACT_BOOL_BERNOUILLI; m_parameter1 = paraArg; enforceConstraints(); - Py_Return; + Py_RETURN_NONE; } /* 14. setIntConst,*/ const char SCA_RandomActuator::SetIntConst_doc[] = @@ -554,7 +554,7 @@ PyObject* SCA_RandomActuator::PySetIntConst(PyObject* self, m_distribution = KX_RANDOMACT_INT_CONST; m_parameter1 = paraArg; enforceConstraints(); - Py_Return; + Py_RETURN_NONE; } /* 15. setIntUniform,*/ const char SCA_RandomActuator::SetIntUniform_doc[] = @@ -575,7 +575,7 @@ PyObject* SCA_RandomActuator::PySetIntUniform(PyObject* self, m_parameter1 = paraArg1; m_parameter2 = paraArg2; enforceConstraints(); - Py_Return; + Py_RETURN_NONE; } /* 16. setIntPoisson, */ const char SCA_RandomActuator::SetIntPoisson_doc[] = @@ -595,7 +595,7 @@ PyObject* SCA_RandomActuator::PySetIntPoisson(PyObject* self, m_distribution = KX_RANDOMACT_INT_POISSON; m_parameter1 = paraArg; enforceConstraints(); - Py_Return; + Py_RETURN_NONE; } /* 17. setFloatConst,*/ const char SCA_RandomActuator::SetFloatConst_doc[] = @@ -613,7 +613,7 @@ PyObject* SCA_RandomActuator::PySetFloatConst(PyObject* self, m_distribution = KX_RANDOMACT_FLOAT_CONST; m_parameter1 = paraArg; enforceConstraints(); - Py_Return; + Py_RETURN_NONE; } /* 18. setFloatUniform, */ const char SCA_RandomActuator::SetFloatUniform_doc[] = @@ -634,7 +634,7 @@ PyObject* SCA_RandomActuator::PySetFloatUniform(PyObject* self, m_parameter1 = paraArg1; m_parameter2 = paraArg2; enforceConstraints(); - Py_Return; + Py_RETURN_NONE; } /* 19. setFloatNormal, */ const char SCA_RandomActuator::SetFloatNormal_doc[] = @@ -655,7 +655,7 @@ PyObject* SCA_RandomActuator::PySetFloatNormal(PyObject* self, m_parameter1 = paraArg1; m_parameter2 = paraArg2; enforceConstraints(); - Py_Return; + Py_RETURN_NONE; } /* 20. setFloatNegativeExponential, */ const char SCA_RandomActuator::SetFloatNegativeExponential_doc[] = @@ -674,7 +674,7 @@ PyObject* SCA_RandomActuator::PySetFloatNegativeExponential(PyObject* self, m_distribution = KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL; m_parameter1 = paraArg; enforceConstraints(); - Py_Return; + Py_RETURN_NONE; } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp index 5a1bd10e044..5354c120f52 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp +++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp @@ -209,7 +209,7 @@ PyObject* SCA_RandomSensor::PySetSeed(PyObject* self, PyObject* args, PyObject* m_basegenerator->SetSeed(seedArg); - Py_Return; + Py_RETURN_NONE; } /* 2. getSeed */ diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index 0c57b2d03a5..2a4a74d5b90 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -796,7 +796,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setSource," setSource(vertexProgram, fragmentProg if(mShader !=0 && mOk ) { // already set... - Py_Return; + Py_RETURN_NONE; } char *v,*f; int apply=0; @@ -807,12 +807,12 @@ KX_PYMETHODDEF_DOC( BL_Shader, setSource," setSource(vertexProgram, fragmentProg if( LinkProgram() ) { glUseProgramObjectARB( mShader ); mUse = apply!=0; - Py_Return; + Py_RETURN_NONE; } vertProg = 0; fragProg = 0; mUse = 0; - Py_Return; + Py_RETURN_NONE; } return NULL; } @@ -827,7 +827,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, delSource, "delSource( )" ) mShader = 0; mOk = 0; mUse = 0; - Py_Return; + Py_RETURN_NONE; } KX_PYMETHODDEF_DOC( BL_Shader, isValid, "isValid()" ) @@ -871,7 +871,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, validate, "validate()") MEM_freeN(logInf); logInf=0; } - Py_Return; + Py_RETURN_NONE; } @@ -912,7 +912,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setNumberOfPasses, "setNumberOfPasses( max-pass ) return NULL; mPass = 1; - Py_Return; + Py_RETURN_NONE; } /// access functions @@ -935,7 +935,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform1f, "setUniform1f(name, fx)" ) SetUniform( loc, (float)value ); #endif } - Py_Return; + Py_RETURN_NONE; } return NULL; } @@ -959,7 +959,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform2f , "setUniform2f(name, fx, fy)") SetUniform(loc, array, 2); #endif } - Py_Return; + Py_RETURN_NONE; } return NULL; } @@ -983,7 +983,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform3f, "setUniform3f(name, fx,fy,fz) ") SetUniform(loc, array, 3); #endif } - Py_Return; + Py_RETURN_NONE; } return NULL; @@ -1008,7 +1008,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform4f, "setUniform4f(name, fx,fy,fz, fw) " SetUniform(loc, array, 4); #endif } - Py_Return; + Py_RETURN_NONE; } return NULL; } @@ -1032,7 +1032,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform1i, "setUniform1i(name, ix)" ) SetUniform(loc, (int)value); #endif } - Py_Return; + Py_RETURN_NONE; } return NULL; } @@ -1056,7 +1056,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform2i , "setUniform2i(name, ix, iy)") SetUniform(loc, array, 2); #endif } - Py_Return; + Py_RETURN_NONE; } return NULL; } @@ -1081,7 +1081,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform3i, "setUniform3i(name, ix,iy,iz) ") SetUniform(loc, array, 3); #endif } - Py_Return; + Py_RETURN_NONE; } return NULL; } @@ -1104,7 +1104,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform4i, "setUniform4i(name, ix,iy,iz, iw) " SetUniform(loc, array, 4); #endif } - Py_Return; + Py_RETURN_NONE; } return NULL; } @@ -1144,7 +1144,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformfv , "setUniformfv( float (list2 or lis #else SetUniform(loc, array2, 2); #endif - Py_Return; + Py_RETURN_NONE; } break; case 3: { @@ -1154,7 +1154,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformfv , "setUniformfv( float (list2 or lis #else SetUniform(loc, array3, 3); #endif - Py_Return; + Py_RETURN_NONE; }break; case 4: { @@ -1164,7 +1164,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformfv , "setUniformfv( float (list2 or lis #else SetUniform(loc, array4, 4); #endif - Py_Return; + Py_RETURN_NONE; }break; default: { @@ -1212,7 +1212,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformiv, "setUniformiv( int (list2 or list3 #else SetUniform(loc, array2, 2); #endif - Py_Return; + Py_RETURN_NONE; } break; case 3: { @@ -1223,7 +1223,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformiv, "setUniformiv( int (list2 or list3 #else SetUniform(loc, array3, 3); #endif - Py_Return; + Py_RETURN_NONE; }break; case 4: { @@ -1234,7 +1234,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformiv, "setUniformiv( int (list2 or list3 #else SetUniform(loc, array4, 4); #endif - Py_Return; + Py_RETURN_NONE; }break; default: { @@ -1282,7 +1282,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformMatrix4, #else SetUniform(loc,mat,(transp!=0)); #endif - Py_Return; + Py_RETURN_NONE; } } } @@ -1323,7 +1323,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformMatrix3, #else SetUniform(loc,mat,(transp!=0)); #endif - Py_Return; + Py_RETURN_NONE; } } @@ -1346,7 +1346,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setAttrib, "setAttrib(enum)" ) mAttr=SHD_TANGENT; glUseProgramObjectARB(mShader); glBindAttribLocationARB(mShader, mAttr, "Tangent"); - Py_Return; + Py_RETURN_NONE; } return NULL; } @@ -1376,7 +1376,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformDef, "setUniformDef(name, enum)" ) } if(defined) { - Py_Return; + Py_RETURN_NONE; } BL_DefUniform *uni = new BL_DefUniform(); @@ -1384,7 +1384,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformDef, "setUniformDef(name, enum)" ) uni->mType = nloc; uni->mFlag = 0; mPreDef.push_back(uni); - Py_Return; + Py_RETURN_NONE; } } return NULL; diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp index a332295ad72..31f1d2dd3ee 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp @@ -162,7 +162,7 @@ PyObject* KX_NetworkMessageActuator::PySetToPropName( return NULL; } - Py_Return; + Py_RETURN_NONE; } // 2. SetSubject @@ -180,7 +180,7 @@ PyObject* KX_NetworkMessageActuator::PySetSubject( return NULL; } - Py_Return; + Py_RETURN_NONE; } // 3. SetBodyType @@ -198,7 +198,7 @@ PyObject* KX_NetworkMessageActuator::PySetBodyType( return NULL; } - Py_Return; + Py_RETURN_NONE; } // 4. SetBody @@ -216,6 +216,6 @@ PyObject* KX_NetworkMessageActuator::PySetBody( return NULL; } - Py_Return; + Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index 83148ea9a2b..5fa19924267 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -790,7 +790,7 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()") spit("Fragment shaders not supported"); mModified = true; - Py_Return; + Py_RETURN_NONE; } if( !GLEW_ARB_vertex_shader) { @@ -798,14 +798,14 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()") spit("Vertex shaders not supported"); mModified = true; - Py_Return; + Py_RETURN_NONE; } if(!GLEW_ARB_shader_objects) { if(!mModified) spit("GLSL not supported"); mModified = true; - Py_Return; + Py_RETURN_NONE; } else { // returns Py_None on error @@ -838,7 +838,7 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()") } } } - Py_Return; + Py_RETURN_NONE; } PyErr_Format(PyExc_ValueError, "GLSL Error"); return NULL; @@ -910,7 +910,7 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, setBlending , "setBlending( GameLogic.sr return NULL; } mUserDefBlend = true; - Py_Return; + Py_RETURN_NONE; } return NULL; } diff --git a/source/gameengine/Ketsji/KX_CDActuator.cpp b/source/gameengine/Ketsji/KX_CDActuator.cpp index 44d073193b1..7d238e28add 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.cpp +++ b/source/gameengine/Ketsji/KX_CDActuator.cpp @@ -210,7 +210,7 @@ PyObject* KX_CDActuator::_getattr(const char *attr) PyObject* KX_CDActuator::PyStartCD(PyObject* self, PyObject* args, PyObject* kwds) { SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); - Py_Return; + Py_RETURN_NONE; } @@ -218,7 +218,7 @@ PyObject* KX_CDActuator::PyStartCD(PyObject* self, PyObject* args, PyObject* kwd PyObject* KX_CDActuator::PyPauseCD(PyObject* self, PyObject* args, PyObject* kwds) { SND_CDObject::Instance()->SetPlaystate(SND_MUST_PAUSE); - Py_Return; + Py_RETURN_NONE; } @@ -226,7 +226,7 @@ PyObject* KX_CDActuator::PyPauseCD(PyObject* self, PyObject* args, PyObject* kwd PyObject* KX_CDActuator::PyStopCD(PyObject* self, PyObject* args, PyObject* kwds) { SND_CDObject::Instance()->SetPlaystate(SND_MUST_STOP); - Py_Return; + Py_RETURN_NONE; } @@ -239,7 +239,7 @@ PyObject* KX_CDActuator::PySetGain(PyObject* self, PyObject* args, PyObject* kwd SND_CDObject::Instance()->SetGain(gain); - Py_Return; + Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index 809bcdba8c9..043070ee207 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -812,7 +812,7 @@ KX_PYMETHODDEF_DOC(KX_Camera, setProjectionMatrix, if (PyMatTo(pymat, mat)) { SetProjectionMatrix(mat); - Py_Return; + Py_RETURN_NONE; } } @@ -837,7 +837,7 @@ KX_PYMETHODDEF_DOC(KX_Camera, enableViewport, return NULL; } - Py_Return; + Py_RETURN_NONE; } KX_PYMETHODDEF_DOC(KX_Camera, setViewport, @@ -851,7 +851,7 @@ KX_PYMETHODDEF_DOC(KX_Camera, setViewport, } else { return NULL; } - Py_Return; + Py_RETURN_NONE; } KX_PYMETHODDEF_DOC(KX_Camera, setOnTop, @@ -863,5 +863,5 @@ KX_PYMETHODDEF_DOC(KX_Camera, setOnTop, scene = KX_GetActiveScene(); MT_assert(scene); scene->SetCameraOnTop(this); - Py_Return; + Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_Camera.h b/source/gameengine/Ketsji/KX_Camera.h index 9ff9c545f2c..3e93745d888 100644 --- a/source/gameengine/Ketsji/KX_Camera.h +++ b/source/gameengine/Ketsji/KX_Camera.h @@ -126,7 +126,7 @@ protected: void ExtractFrustumSphere(); public: - typedef enum { INSIDE, INTERSECT, OUTSIDE } ; + enum { INSIDE, INTERSECT, OUTSIDE } ; KX_Camera(void* sgReplicationInfo,SG_Callbacks callbacks,const RAS_CameraData& camdata, bool frustum_culling = true, PyTypeObject *T = &Type); virtual ~KX_Camera(); diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index dc2c4c4b414..65f3aea12f9 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -530,7 +530,7 @@ PyObject* KX_CameraActuator::PySetMin(PyObject* self, if(PyArg_ParseTuple(args,"f", &min)) { m_minHeight = min; - Py_Return; + Py_RETURN_NONE; } return NULL; } @@ -558,7 +558,7 @@ PyObject* KX_CameraActuator::PySetMax(PyObject* self, if(PyArg_ParseTuple(args,"f", &max)) { m_maxHeight = max; - Py_Return; + Py_RETURN_NONE; } return NULL; } @@ -586,7 +586,7 @@ PyObject* KX_CameraActuator::PySetHeight(PyObject* self, if(PyArg_ParseTuple(args,"f", &height)) { m_height = height; - Py_Return; + Py_RETURN_NONE; } return NULL; } @@ -604,7 +604,7 @@ PyObject* KX_CameraActuator::PySetXY(PyObject* self, if(PyArg_ParseTuple(args,"i", &value)) { m_x = value != 0; - Py_Return; + Py_RETURN_NONE; } return NULL; } diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index 5c08bdc94a3..c0d802a9cf9 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -633,7 +633,7 @@ PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self, m_posDampTime = dampArg; if (m_posDampTime < 0) m_posDampTime = 0; - Py_Return; + Py_RETURN_NONE; } /* 3. getDamp */ const char KX_ConstraintActuator::GetDamp_doc[] = @@ -660,7 +660,7 @@ PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* self, m_rotDampTime = dampArg; if (m_rotDampTime < 0) m_rotDampTime = 0; - Py_Return; + Py_RETURN_NONE; } /* 3. getRotDamp */ const char KX_ConstraintActuator::GetRotDamp_doc[] = @@ -695,7 +695,7 @@ PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, } m_refDirection = dir/len; - Py_Return; + Py_RETURN_NONE; } /* 3. getDirection */ const char KX_ConstraintActuator::GetDirection_doc[] = @@ -730,7 +730,7 @@ PyObject* KX_ConstraintActuator::PySetOption(PyObject* self, m_option = option; - Py_Return; + Py_RETURN_NONE; } /* 3. getOption */ const char KX_ConstraintActuator::GetOption_doc[] = @@ -759,7 +759,7 @@ PyObject* KX_ConstraintActuator::PySetTime(PyObject* self, t = 0; m_activeTime = t; - Py_Return; + Py_RETURN_NONE; } /* 3. getTime */ const char KX_ConstraintActuator::GetTime_doc[] = @@ -789,7 +789,7 @@ PyObject* KX_ConstraintActuator::PySetProperty(PyObject* self, m_property[sizeof(m_property)-1] = 0; } - Py_Return; + Py_RETURN_NONE; } /* 3. getProperty */ const char KX_ConstraintActuator::GetProperty_doc[] = @@ -829,7 +829,7 @@ PyObject* KX_ConstraintActuator::PySetMin(PyObject* self, break; } - Py_Return; + Py_RETURN_NONE; } /* 5. getDistance */ const char KX_ConstraintActuator::GetDistance_doc[] = @@ -874,7 +874,7 @@ PyObject* KX_ConstraintActuator::PySetMax(PyObject* self, break; } - Py_Return; + Py_RETURN_NONE; } /* 7. getRayLength */ const char KX_ConstraintActuator::GetRayLength_doc[] = @@ -918,7 +918,7 @@ PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self, if (IsValidMode((KX_CONSTRAINTTYPE)locrotArg)) m_locrot = locrotArg; - Py_Return; + Py_RETURN_NONE; } /* 9. getLimit */ const char KX_ConstraintActuator::GetLimit_doc[] = diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp index a8b4e0d7d2c..2387dcdef3a 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.cpp +++ b/source/gameengine/Ketsji/KX_GameActuator.cpp @@ -270,7 +270,7 @@ PyObject* KX_GameActuator::PySetFile(PyObject* self, PyObject* args, PyObject* k m_filename = STR_String(new_file); - Py_Return; + Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 521fd317305..7d785f07ed2 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -521,7 +521,7 @@ KX_GameObject::UpdateMaterialData( { KX_BlenderMaterial *m = static_cast(poly); - if (matname_hash == NULL) + if (matname_hash == 0) { m->UpdateIPO(rgba, specrgb,hard,spec,ref,emit, alpha); // if mesh has only one material attached to it then use original hack with no need to edit vertices (better performance) diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index a67fbe55c37..ca8419666b5 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -503,7 +503,7 @@ PyObject* KX_IpoActuator::PySet(PyObject* self, ; /* error */ } - Py_Return; + Py_RETURN_NONE; } /* set property ----------------------------------------------------------- */ @@ -523,7 +523,7 @@ PyObject* KX_IpoActuator::PySetProperty(PyObject* self, m_propname = propertyName; - Py_Return; + Py_RETURN_NONE; } /* 4. setStart: */ @@ -541,7 +541,7 @@ PyObject* KX_IpoActuator::PySetStart(PyObject* self, m_startframe = startArg; - Py_Return; + Py_RETURN_NONE; } /* 5. getStart: */ const char KX_IpoActuator::GetStart_doc[] = @@ -566,7 +566,7 @@ PyObject* KX_IpoActuator::PySetEnd(PyObject* self, m_endframe = endArg; - Py_Return; + Py_RETURN_NONE; } /* 7. getEnd: */ const char KX_IpoActuator::GetEnd_doc[] = @@ -594,7 +594,7 @@ PyObject* KX_IpoActuator::PySetIpoAsForce(PyObject* self, if (m_ipo_as_force) m_ipo_add = false; - Py_Return; + Py_RETURN_NONE; } /* 7. getIpoAsForce: */ const char KX_IpoActuator::GetIpoAsForce_doc[] = @@ -622,7 +622,7 @@ PyObject* KX_IpoActuator::PySetIpoAdd(PyObject* self, if (m_ipo_add) m_ipo_as_force = false; - Py_Return; + Py_RETURN_NONE; } /* 7. getIpoAsForce: */ const char KX_IpoActuator::GetIpoAdd_doc[] = @@ -651,7 +651,7 @@ PyObject* KX_IpoActuator::PySetType(PyObject* self, m_type = (IpoActType) typeArg; } - Py_Return; + Py_RETURN_NONE; } /* 9. getType: */ const char KX_IpoActuator::GetType_doc[] = @@ -679,7 +679,7 @@ PyObject* KX_IpoActuator::PySetForceIpoActsLocal(PyObject* self, m_ipo_local = PyArgToBool(boolArg); - Py_Return; + Py_RETURN_NONE; } /* 11. getForceIpoActsLocal: */ const char KX_IpoActuator::GetForceIpoActsLocal_doc[] = diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index 3dd70cbb1b8..bd15d3cffbe 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -347,7 +347,7 @@ PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self, { return m_hitObject->AddRef(); } - Py_Return; + Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index e04f73a65e5..9a620998538 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -365,7 +365,7 @@ PyObject* KX_ObjectActuator::PySetForce(PyObject* self, m_force.setValue(vecArg); m_bitLocalFlag.Force = PyArgToBool(bToggle); UpdateFuzzyFlags(); - Py_Return; + Py_RETURN_NONE; } /* 4. getTorque */ @@ -394,7 +394,7 @@ PyObject* KX_ObjectActuator::PySetTorque(PyObject* self, m_torque.setValue(vecArg); m_bitLocalFlag.Torque = PyArgToBool(bToggle); UpdateFuzzyFlags(); - Py_Return; + Py_RETURN_NONE; } /* 6. getDLoc */ @@ -423,7 +423,7 @@ PyObject* KX_ObjectActuator::PySetDLoc(PyObject* self, m_dloc.setValue(vecArg); m_bitLocalFlag.DLoc = PyArgToBool(bToggle); UpdateFuzzyFlags(); - Py_Return; + Py_RETURN_NONE; } /* 8. getDRot */ @@ -452,7 +452,7 @@ PyObject* KX_ObjectActuator::PySetDRot(PyObject* self, m_drot.setValue(vecArg); m_bitLocalFlag.DRot = PyArgToBool(bToggle); UpdateFuzzyFlags(); - Py_Return; + Py_RETURN_NONE; } /* 10. getLinearVelocity */ @@ -480,7 +480,7 @@ PyObject* KX_ObjectActuator::PySetLinearVelocity(PyObject* self, m_linear_velocity.setValue(vecArg); m_bitLocalFlag.LinearVelocity = PyArgToBool(bToggle); UpdateFuzzyFlags(); - Py_Return; + Py_RETURN_NONE; } @@ -508,7 +508,7 @@ PyObject* KX_ObjectActuator::PySetAngularVelocity(PyObject* self, m_angular_velocity.setValue(vecArg); m_bitLocalFlag.AngularVelocity = PyArgToBool(bToggle); UpdateFuzzyFlags(); - Py_Return; + Py_RETURN_NONE; } /* 13. setDamping */ @@ -520,7 +520,7 @@ PyObject* KX_ObjectActuator::PySetDamping(PyObject* self, return NULL; } m_damping = damping; - Py_Return; + Py_RETURN_NONE; } /* 13. getVelocityDamping */ @@ -551,7 +551,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitX(PyObject* self, m_drot[0] = vecArg[0]; m_dloc[0] = vecArg[1]; m_bitLocalFlag.Torque = PyArgToBool(bToggle); - Py_Return; + Py_RETURN_NONE; } /* 6. getForceLimitY */ @@ -578,7 +578,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitY(PyObject* self, m_drot[1] = vecArg[0]; m_dloc[1] = vecArg[1]; m_bitLocalFlag.DLoc = PyArgToBool(bToggle); - Py_Return; + Py_RETURN_NONE; } /* 6. getForceLimitZ */ @@ -605,7 +605,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitZ(PyObject* self, m_drot[2] = vecArg[0]; m_dloc[2] = vecArg[1]; m_bitLocalFlag.DRot = PyArgToBool(bToggle); - Py_Return; + Py_RETURN_NONE; } /* 4. getPID */ @@ -629,7 +629,7 @@ PyObject* KX_ObjectActuator::PySetPID(PyObject* self, return NULL; } m_torque.setValue(vecArg); - Py_Return; + Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index 9c792a3e673..52c5b013e65 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -204,15 +204,15 @@ PyParentObject KX_PolygonMaterial::Parents[] = { PyObject* KX_PolygonMaterial::_getattr(const char *attr) { - if (attr == "texture") + if (!strcmp(attr, "texture")) return PyString_FromString(m_texturename.ReadPtr()); - if (attr == "material") + if (!strcmp(attr, "material")) return PyString_FromString(m_materialname.ReadPtr()); - if (attr == "tface") + if (!strcmp(attr, "tface")) return PyCObject_FromVoidPtr(m_tface, NULL); - if (attr == "gl_texture") + if (!strcmp(attr, "gl_texture")) { Image *ima = m_tface->tpage; int bind = 0; @@ -222,32 +222,32 @@ PyObject* KX_PolygonMaterial::_getattr(const char *attr) return PyInt_FromLong(bind); } - if (attr == "tile") + if (!strcmp(attr, "tile")) return PyInt_FromLong(m_tile); - if (attr == "tilexrep") + if (!strcmp(attr, "tilexrep")) return PyInt_FromLong(m_tilexrep); - if (attr == "tileyrep") + if (!strcmp(attr, "tileyrep")) return PyInt_FromLong(m_tileyrep); - if (attr == "drawingmode") + if (!strcmp(attr, "drawingmode")) return PyInt_FromLong(m_drawingmode); - if (attr == "transparent") + if (!strcmp(attr, "transparent")) return PyInt_FromLong(m_alpha); - if (attr == "zsort") + if (!strcmp(attr, "zsort")) return PyInt_FromLong(m_zsort); - if (attr == "lightlayer") + if (!strcmp(attr, "lightlayer")) return PyInt_FromLong(m_lightlayer); - if (attr == "triangle") + if (!strcmp(attr, "triangle")) // deprecated, triangle/quads shouldn't have been a material property return 0; - if (attr == "diffuse") + if (!strcmp(attr, "diffuse")) return PyObjectFrom(m_diffuse); - if (attr == "shininess") + if (!strcmp(attr, "shininess")) return PyFloat_FromDouble(m_shininess); - if (attr == "specular") + if (!strcmp(attr, "specular")) return PyObjectFrom(m_specular); - if (attr == "specularity") + if (!strcmp(attr, "specularity")) return PyFloat_FromDouble(m_specularity); _getattr_up(PyObjectPlus); @@ -258,13 +258,13 @@ int KX_PolygonMaterial::_setattr(const char *attr, PyObject *pyvalue) if (PyFloat_Check(pyvalue)) { float value = PyFloat_AsDouble(pyvalue); - if (attr == "shininess") + if (!strcmp(attr, "shininess")) { m_shininess = value; return 0; } - if (attr == "specularity") + if (!strcmp(attr, "specularity")) { m_specularity = value; return 0; @@ -274,50 +274,50 @@ int KX_PolygonMaterial::_setattr(const char *attr, PyObject *pyvalue) if (PyInt_Check(pyvalue)) { int value = PyInt_AsLong(pyvalue); - if (attr == "tile") + if (!strcmp(attr, "tile")) { m_tile = value; return 0; } - if (attr == "tilexrep") + if (!strcmp(attr, "tilexrep")) { m_tilexrep = value; return 0; } - if (attr == "tileyrep") + if (!strcmp(attr, "tileyrep")) { m_tileyrep = value; return 0; } - if (attr == "drawingmode") + if (!strcmp(attr, "drawingmode")) { m_drawingmode = value; return 0; } - if (attr == "transparent") + if (!strcmp(attr, "transparent")) { m_alpha = value; return 0; } - if (attr == "zsort") + if (!strcmp(attr, "zsort")) { m_zsort = value; return 0; } - if (attr == "lightlayer") + if (!strcmp(attr, "lightlayer")) { m_lightlayer = value; return 0; } // This probably won't work... - if (attr == "triangle") + if (!strcmp(attr, "triangle")) { // deprecated, triangle/quads shouldn't have been a material property return 0; @@ -331,13 +331,13 @@ int KX_PolygonMaterial::_setattr(const char *attr, PyObject *pyvalue) MT_Vector3 value; if (PyVecTo(pyvalue, value)) { - if (attr == "diffuse") + if (!strcmp(attr, "diffuse")) { m_diffuse = value; return 0; } - if (attr == "specular") + if (!strcmp(attr, "specular")) { m_specular = value; return 0; @@ -354,12 +354,12 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setCustomMaterial, "setCustomMaterial(mat PyObject *material; if (PyArg_ParseTuple(args, "O", &material)) { - if (m_pymaterial) + if (m_pymaterial) { Py_DECREF(m_pymaterial); - + } m_pymaterial = material; Py_INCREF(m_pymaterial); - Py_Return; + Py_RETURN_NONE; } return NULL; @@ -375,7 +375,7 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, updateTexture, "updateTexture(tface, rast Image *ima = (Image*)tface->tpage; GPU_update_image_time(ima, rasty->GetTime()); - Py_Return; + Py_RETURN_NONE; } return NULL; @@ -388,7 +388,7 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setTexture, "setTexture(tface)") { MTFace *tface = (MTFace*) PyCObject_AsVoidPtr(pytface); GPU_set_tpage(tface); - Py_Return; + Py_RETURN_NONE; } return NULL; @@ -404,7 +404,7 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, activate, "activate(rasty, cachingInfo)") if (rasty && cachingInfo) { DefaultActivate(rasty, *cachingInfo); - Py_Return; + Py_RETURN_NONE; } } diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index 22611c444df..b8ebce28814 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -353,7 +353,7 @@ PyObject* KX_RaySensor::PyGetHitObject(PyObject* self, { return m_hitObject->AddRef(); } - Py_Return; + Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index 4c331b2c9d6..017ab5d6c97 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -210,8 +210,7 @@ PyObject* KX_SCA_AddObjectActuator::_getattr(const char *attr) if (!strcmp(attr, "object")) { if (!m_OriginalObject) Py_RETURN_NONE; else return m_OriginalObject->AddRef(); - } - else if (attr == "objectLastCreated") { + } else if (!strcmp(attr, "objectLastCreated")) { if (!m_OriginalObject) Py_RETURN_NONE; else return m_lastCreatedObject->AddRef(); } diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp index e8d9a7f07c8..1aba05c1d83 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp @@ -115,7 +115,7 @@ KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, setOperation, return NULL; } m_dyn_operation= dyn_operation; - Py_Return; + Py_RETURN_NONE; } KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, getOperation, diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index a5f49f97d4b..8e33177cf3a 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -295,7 +295,7 @@ PyObject* KX_SceneActuator::PySetUseRestart(PyObject* self, m_restart = boolArg != 0; - Py_Return; + Py_RETURN_NONE; } @@ -333,7 +333,7 @@ PyObject* KX_SceneActuator::PySetScene(PyObject* self, /* Scene switch is done by name. */ m_nextSceneName = scene_name; - Py_Return; + Py_RETURN_NONE; } @@ -368,7 +368,7 @@ PyObject* KX_SceneActuator::PySetCamera(PyObject* self, m_camera = (KX_Camera*) cam; if (m_camera) m_camera->RegisterActuator(this); - Py_Return; + Py_RETURN_NONE; } PyErr_Clear(); @@ -388,7 +388,7 @@ PyObject* KX_SceneActuator::PySetCamera(PyObject* self, m_camera->RegisterActuator(this); } - Py_Return; + Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index ba60ea81739..37604518486 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -302,7 +302,7 @@ PyObject* KX_SoundActuator::PySetFilename(PyObject* self, PyObject* args, PyObje if (!PyArg_ParseTuple(args, "s", &soundName)) return NULL; - Py_Return; + Py_RETURN_NONE; } @@ -332,7 +332,7 @@ PyObject* KX_SoundActuator::PyStartSound(PyObject* self, PyObject* args, PyObjec // To start the sound you must activate the actuator. // This function is to restart the sound. m_soundObject->StartSound(); - Py_Return; + Py_RETURN_NONE; } @@ -342,7 +342,7 @@ PyObject* KX_SoundActuator::PyPauseSound(PyObject* self, PyObject* args, PyObjec if (m_soundObject) // unfortunately, openal does not implement pause correctly, it is equivalent to a stop m_soundObject->PauseSound(); - Py_Return; + Py_RETURN_NONE; } @@ -351,7 +351,7 @@ PyObject* KX_SoundActuator::PyStopSound(PyObject* self, PyObject* args, PyObject { if (m_soundObject) m_soundObject->StopSound(); - Py_Return; + Py_RETURN_NONE; } @@ -365,7 +365,7 @@ PyObject* KX_SoundActuator::PySetGain(PyObject* self, PyObject* args, PyObject* if (m_soundObject) m_soundObject->SetGain(gain); - Py_Return; + Py_RETURN_NONE; } @@ -389,7 +389,7 @@ PyObject* KX_SoundActuator::PySetPitch(PyObject* self, PyObject* args, PyObject* if (m_soundObject) m_soundObject->SetPitch(pitch); - Py_Return; + Py_RETURN_NONE; } @@ -413,7 +413,7 @@ PyObject* KX_SoundActuator::PySetRollOffFactor(PyObject* self, PyObject* args, P if (m_soundObject) m_soundObject->SetRollOffFactor(rollofffactor); - Py_Return; + Py_RETURN_NONE; } @@ -437,7 +437,7 @@ PyObject* KX_SoundActuator::PySetLooping(PyObject* self, PyObject* args, PyObjec if (m_soundObject) m_soundObject->SetLoopMode(looping); - Py_Return; + Py_RETURN_NONE; } @@ -465,7 +465,7 @@ PyObject* KX_SoundActuator::PySetPosition(PyObject* self, PyObject* args, PyObje if (m_soundObject) m_soundObject->SetPosition(pos); - Py_Return; + Py_RETURN_NONE; } @@ -483,7 +483,7 @@ PyObject* KX_SoundActuator::PySetVelocity(PyObject* self, PyObject* args, PyObje if (m_soundObject) m_soundObject->SetVelocity(vel); - Py_Return; + Py_RETURN_NONE; } @@ -507,7 +507,7 @@ PyObject* KX_SoundActuator::PySetOrientation(PyObject* self, PyObject* args, PyO if (m_soundObject) m_soundObject->SetOrientation(ori); - Py_Return; + Py_RETURN_NONE; } PyObject* KX_SoundActuator::PySetType(PyObject* self, PyObject* args, PyObject* kwds) @@ -523,7 +523,7 @@ PyObject* KX_SoundActuator::PySetType(PyObject* self, PyObject* args, PyObject* m_type = (KX_SOUNDACT_TYPE) typeArg; } - Py_Return; + Py_RETURN_NONE; } PyObject* KX_SoundActuator::PyGetType(PyObject* self, PyObject* args, PyObject* kwds) diff --git a/source/gameengine/Ketsji/KX_StateActuator.cpp b/source/gameengine/Ketsji/KX_StateActuator.cpp index 7237d6ced1e..cd5c5d29ab1 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.cpp +++ b/source/gameengine/Ketsji/KX_StateActuator.cpp @@ -173,7 +173,7 @@ KX_StateActuator::PySetOperation(PyObject* self, m_operation = oper; - Py_Return; + Py_RETURN_NONE; } /* set mask ---------------------------------------------------------- */ @@ -198,7 +198,7 @@ KX_StateActuator::PySetMask(PyObject* self, m_mask = mask; - Py_Return; + Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 6528ec466ce..117adb44742 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -291,7 +291,7 @@ PyObject* KX_TouchSensor::PySetProperty(PyObject* self, } prop->Release(); - Py_Return; + Py_RETURN_NONE; } /* 2. getProperty */ const char KX_TouchSensor::GetProperty_doc[] = @@ -318,7 +318,7 @@ PyObject* KX_TouchSensor::PyGetHitObject(PyObject* self, { return m_hitObject->AddRef(); } - Py_Return; + Py_RETURN_NONE; } const char KX_TouchSensor::GetHitObjectList_doc[] = @@ -402,7 +402,7 @@ PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject* self, PyObject* args, PyO m_bFindMaterial = pulseArg != 0; - Py_Return; + Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index f9f804cfc66..89dfc8e57ad 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -480,9 +480,8 @@ PyObject* KX_TrackToActuator::_getattr(const char *attr) _getattr_up(SCA_IActuator); } -int KX_TrackToActuator::_setattr(const char *attr, PyObject* value) { - int ret; - +int KX_TrackToActuator::_setattr(const char *attr, PyObject* value) +{ if (!strcmp(attr, "object")) { KX_GameObject *gameobj; @@ -570,7 +569,7 @@ PyObject* KX_TrackToActuator::PySetTime(PyObject* self, PyObject* args, PyObject m_time= timeArg; - Py_Return; + Py_RETURN_NONE; } @@ -614,7 +613,7 @@ PyObject* KX_TrackToActuator::PySetUse3D(PyObject* self, PyObject* args, PyObjec m_allow3D = !(boolArg == 0); - Py_Return; + Py_RETURN_NONE; } /* eof */ diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp index eddd110ee81..ab102ee547a 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.cpp +++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp @@ -328,7 +328,7 @@ PyObject* KX_VertexProxy::PySetXYZ(PyObject*, { m_vertex->SetXYZ(vec); m_mesh->SetMeshModified(true); - Py_Return; + Py_RETURN_NONE; } return NULL; @@ -350,7 +350,7 @@ PyObject* KX_VertexProxy::PySetNormal(PyObject*, { m_vertex->SetNormal(vec); m_mesh->SetMeshModified(true); - Py_Return; + Py_RETURN_NONE; } return NULL; @@ -374,7 +374,7 @@ PyObject* KX_VertexProxy::PySetRGBA(PyObject*, { m_vertex->SetRGBA(MT_Vector4(r, g, b, a)); m_mesh->SetMeshModified(true); - Py_Return; + Py_RETURN_NONE; } PyErr_Clear(); @@ -383,7 +383,7 @@ PyObject* KX_VertexProxy::PySetRGBA(PyObject*, { m_vertex->SetRGBA(rgba); m_mesh->SetMeshModified(true); - Py_Return; + Py_RETURN_NONE; } return NULL; @@ -406,7 +406,7 @@ PyObject* KX_VertexProxy::PySetUV(PyObject*, { m_vertex->SetUV(vec); m_mesh->SetMeshModified(true); - Py_Return; + Py_RETURN_NONE; } return NULL; @@ -434,7 +434,7 @@ PyObject* KX_VertexProxy::PySetUV2(PyObject*, m_vertex->SetUnit(unit); m_vertex->SetUV2(vec); m_mesh->SetMeshModified(true); - Py_Return; + Py_RETURN_NONE; } } return NULL; diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp index 0a4aaa0dffe..ca89a63de62 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp @@ -152,7 +152,7 @@ KX_VisibilityActuator::PySetVisible(PyObject* self, m_visible = PyArgToBool(vis); - Py_Return; + Py_RETURN_NONE; } diff --git a/source/gameengine/Physics/Sumo/Fuzzics/include/SM_Scene.h b/source/gameengine/Physics/Sumo/Fuzzics/include/SM_Scene.h index 2326bdee523..3d8eef2bae0 100644 --- a/source/gameengine/Physics/Sumo/Fuzzics/include/SM_Scene.h +++ b/source/gameengine/Physics/Sumo/Fuzzics/include/SM_Scene.h @@ -46,7 +46,7 @@ #include "SM_Object.h" -typedef enum +enum { FH_RESPONSE, SENSOR_RESPONSE, /* Touch Sensors */ diff --git a/source/gameengine/Physics/common/PHY_DynamicTypes.h b/source/gameengine/Physics/common/PHY_DynamicTypes.h index 09126264dcc..c5cf92b553a 100644 --- a/source/gameengine/Physics/common/PHY_DynamicTypes.h +++ b/source/gameengine/Physics/common/PHY_DynamicTypes.h @@ -36,7 +36,7 @@ struct PHY__Vector3 }; //typedef float PHY__Vector3[4]; -typedef enum +enum { PHY_FH_RESPONSE, PHY_SENSOR_RESPONSE, /* Touch Sensors */ -- cgit v1.2.3 From 570b48aae6f074ed19a3fc58b8e2a34b38123a49 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 22 Feb 2009 10:22:49 +0000 Subject: BGE Py API print filename:line with ShowDeprecationWarning(). Typo in scripttemplate_gamelogic.py removed 2 unneeded typedefs --- source/gameengine/Expressions/Value.cpp | 37 ++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index f30dd1a71ed..9b26cda01b3 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -859,7 +859,42 @@ void CValue::SetDeprecationWarnings(bool ignoreDeprecationWarnings) void CValue::ShowDeprecationWarning(const char* old_way,const char* new_way) { - if (!m_ignore_deprecation_warnings) + if (!m_ignore_deprecation_warnings) { printf("Method %s is deprecated, please use %s instead.\n", old_way, new_way); + + // import sys; print '\t%s:%d' % (sys._getframe(0).f_code.co_filename, sys._getframe(0).f_lineno) + + PyObject *getframe, *frame; + PyObject *f_lineno, *f_code, *co_filename; + + getframe = PySys_GetObject("_getframe"); // borrowed + if (getframe) { + frame = PyObject_CallObject(getframe, NULL); + if (frame) { + f_lineno= PyObject_GetAttrString(frame, "f_lineno"); + f_code= PyObject_GetAttrString(frame, "f_code"); + if (f_lineno && f_code) { + co_filename= PyObject_GetAttrString(f_code, "co_filename"); + if (co_filename) { + + printf("\t%s:%d\n", PyString_AsString(co_filename), (int)PyInt_AsLong(f_lineno)); + + Py_DECREF(f_lineno); + Py_DECREF(f_code); + Py_DECREF(co_filename); + Py_DECREF(frame); + return; + } + } + + Py_XDECREF(f_lineno); + Py_XDECREF(f_code); + Py_DECREF(frame); + } + + } + PyErr_Clear(); + printf("\tERROR - Could not access sys._getframe(0).f_lineno or sys._getframe().f_code.co_filename\n"); + } } -- cgit v1.2.3 From 5488175d0bc79b07fd3fb0f279323b4f33487b5f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 23 Feb 2009 06:41:10 +0000 Subject: BGE Python API * fixed segfaults in CListValue.index(val) and CListValue.count(val) when the pyTypes could not be converted into a CValue. * added scene.objects to replace scene.getObjectList() * added function names to PyArg_ParseTuple() so errors will include the function names * removed cases of PyArg_ParseTuple(args,"O",&pyobj) where METH_O ensures a single argument. * Made PyObjectFrom use ugly python api rather then Py_BuildValue(), approx %40 speedup for functions that return Python vector and matrix types like ob.orientation. --- source/gameengine/Expressions/ListValue.cpp | 91 +++++++---------- source/gameengine/Expressions/ListValue.h | 8 +- source/gameengine/Ketsji/KX_Camera.cpp | 117 ++++++++++------------ source/gameengine/Ketsji/KX_Camera.h | 20 ++-- source/gameengine/Ketsji/KX_GameObject.cpp | 64 ++++++------ source/gameengine/Ketsji/KX_GameObject.h | 4 +- source/gameengine/Ketsji/KX_PyMath.cpp | 57 +++++++++++ source/gameengine/Ketsji/KX_PyMath.h | 14 --- source/gameengine/Ketsji/KX_PythonInit.cpp | 38 ++++---- source/gameengine/Ketsji/KX_Scene.cpp | 28 +++--- source/gameengine/Ketsji/KX_Scene.h | 6 +- source/gameengine/Ketsji/KX_VertexProxy.cpp | 145 +++++++++++----------------- source/gameengine/Ketsji/KX_VertexProxy.h | 20 ++-- 13 files changed, 292 insertions(+), 320 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index b8a8a1a63b2..9acc6ad2cde 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -224,10 +224,10 @@ PyParentObject CListValue::Parents[] = { PyMethodDef CListValue::Methods[] = { - {"append", (PyCFunction)CListValue::sPyappend,METH_VARARGS}, - {"reverse", (PyCFunction)CListValue::sPyreverse,METH_VARARGS}, - {"index", (PyCFunction)CListValue::sPyindex,METH_VARARGS}, - {"count", (PyCFunction)CListValue::sPycount,METH_VARARGS}, + {"append", (PyCFunction)CListValue::sPyappend,METH_O}, + {"reverse", (PyCFunction)CListValue::sPyreverse,METH_NOARGS}, + {"index", (PyCFunction)CListValue::sPyindex,METH_O}, + {"count", (PyCFunction)CListValue::sPycount,METH_O}, {NULL,NULL} //Sentinel }; @@ -403,34 +403,17 @@ void CListValue::MergeList(CListValue *otherlist) -PyObject* CListValue::Pyappend(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* CListValue::Pyappend(PyObject* self, PyObject* value) { - - PyObject* pyobj = NULL; - if (PyArg_ParseTuple(args,"O",&pyobj)) - { - return listvalue_buffer_concat(self,pyobj); - } - else - { - return NULL; - } - - + return listvalue_buffer_concat(self, value); } -PyObject* CListValue::Pyreverse(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* CListValue::Pyreverse(PyObject* self) { std::reverse(m_pValueArray.begin(),m_pValueArray.end()); - Py_RETURN_NONE; - } @@ -452,58 +435,56 @@ bool CListValue::CheckEqual(CValue* first,CValue* second) -PyObject* CListValue::Pyindex(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* CListValue::Pyindex(PyObject* self, PyObject *value) { PyObject* result = NULL; - PyObject* pyobj = NULL; - if (PyArg_ParseTuple(args,"O",&pyobj)) + CValue* checkobj = ConvertPythonToValue(value); + if (checkobj==NULL) + return NULL; /* ConvertPythonToValue sets the error */ + + int numelem = GetCount(); + for (int i=0;iRelease(); } + checkobj->Release(); + if (result==NULL) { + PyErr_SetString(PyExc_ValueError, "ValueError: list.index(x): x not in CListValue"); + } return result; } -PyObject* CListValue::Pycount(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* CListValue::Pycount(PyObject* self, PyObject* value) { - int numfound = 0; - PyObject* pyobj = NULL; - if (PyArg_ParseTuple(args,"O",&pyobj)) + CValue* checkobj = ConvertPythonToValue(value); + + if (checkobj==NULL) { /* in this case just return that there are no items in the list */ + PyErr_Clear(); + PyInt_FromLong(0); + } + + int numelem = GetCount(); + for (int i=0;iRelease(); } + checkobj->Release(); return PyInt_FromLong(numfound); } diff --git a/source/gameengine/Expressions/ListValue.h b/source/gameengine/Expressions/ListValue.h index 8c0bd767938..104e3e63283 100644 --- a/source/gameengine/Expressions/ListValue.h +++ b/source/gameengine/Expressions/ListValue.h @@ -61,10 +61,10 @@ public: virtual PyObject* _getattr(const char *attr); - KX_PYMETHOD(CListValue,append); - KX_PYMETHOD(CListValue,reverse); - KX_PYMETHOD(CListValue,index); - KX_PYMETHOD(CListValue,count); + KX_PYMETHOD_O(CListValue,append); + KX_PYMETHOD_NOARGS(CListValue,reverse); + KX_PYMETHOD_O(CListValue,index); + KX_PYMETHOD_O(CListValue,count); private: diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index 043070ee207..99e2d3b7c06 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -470,15 +470,15 @@ int KX_Camera::GetViewportTop() const PyMethodDef KX_Camera::Methods[] = { KX_PYMETHODTABLE(KX_Camera, sphereInsideFrustum), - KX_PYMETHODTABLE(KX_Camera, boxInsideFrustum), - KX_PYMETHODTABLE(KX_Camera, pointInsideFrustum), - KX_PYMETHODTABLE(KX_Camera, getCameraToWorld), - KX_PYMETHODTABLE(KX_Camera, getWorldToCamera), - KX_PYMETHODTABLE(KX_Camera, getProjectionMatrix), - KX_PYMETHODTABLE(KX_Camera, setProjectionMatrix), - KX_PYMETHODTABLE(KX_Camera, enableViewport), + KX_PYMETHODTABLE_O(KX_Camera, boxInsideFrustum), + KX_PYMETHODTABLE_O(KX_Camera, pointInsideFrustum), + KX_PYMETHODTABLE_NOARGS(KX_Camera, getCameraToWorld), + KX_PYMETHODTABLE_NOARGS(KX_Camera, getWorldToCamera), + KX_PYMETHODTABLE_NOARGS(KX_Camera, getProjectionMatrix), + KX_PYMETHODTABLE_O(KX_Camera, setProjectionMatrix), + KX_PYMETHODTABLE_O(KX_Camera, enableViewport), KX_PYMETHODTABLE(KX_Camera, setViewport), - KX_PYMETHODTABLE(KX_Camera, setOnTop), + KX_PYMETHODTABLE_NOARGS(KX_Camera, setOnTop), {NULL,NULL} //Sentinel }; @@ -624,7 +624,7 @@ int KX_Camera::_setattr(const char *attr, PyObject *pyvalue) return KX_GameObject::_setattr(attr, pyvalue); } -KX_PYMETHODDEF_DOC(KX_Camera, sphereInsideFrustum, +KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, sphereInsideFrustum, "sphereInsideFrustum(center, radius) -> Integer\n" "\treturns INSIDE, OUTSIDE or INTERSECT if the given sphere is\n" "\tinside/outside/intersects this camera's viewing frustum.\n\n" @@ -658,7 +658,7 @@ KX_PYMETHODDEF_DOC(KX_Camera, sphereInsideFrustum, return NULL; } -KX_PYMETHODDEF_DOC(KX_Camera, boxInsideFrustum, +KX_PYMETHODDEF_DOC_O(KX_Camera, boxInsideFrustum, "boxInsideFrustum(box) -> Integer\n" "\treturns INSIDE, OUTSIDE or INTERSECT if the given box is\n" "\tinside/outside/intersects this camera's viewing frustum.\n\n" @@ -683,34 +683,27 @@ KX_PYMETHODDEF_DOC(KX_Camera, boxInsideFrustum, "\t\t# Box is outside the frustum !\n" ) { - PyObject *pybox; - if (PyArg_ParseTuple(args, "O", &pybox)) + unsigned int num_points = PySequence_Size(value); + if (num_points != 8) { - unsigned int num_points = PySequence_Size(pybox); - if (num_points != 8) - { - PyErr_Format(PyExc_TypeError, "boxInsideFrustum: Expected eight (8) points, got %d", num_points); + PyErr_Format(PyExc_TypeError, "boxInsideFrustum: Expected eight (8) points, got %d", num_points); + return NULL; + } + + MT_Point3 box[8]; + for (unsigned int p = 0; p < 8 ; p++) + { + PyObject *item = PySequence_GetItem(value, p); /* new ref */ + bool error = !PyVecTo(item, box[p]); + Py_DECREF(item); + if (error) return NULL; - } - - MT_Point3 box[8]; - for (unsigned int p = 0; p < 8 ; p++) - { - PyObject *item = PySequence_GetItem(pybox, p); /* new ref */ - bool error = !PyVecTo(item, box[p]); - Py_DECREF(item); - if (error) - return NULL; - } - - return PyInt_FromLong(BoxInsideFrustum(box)); /* new ref */ } - PyErr_SetString(PyExc_TypeError, "boxInsideFrustum: Expected argument: list of points."); - return NULL; + return PyInt_FromLong(BoxInsideFrustum(box)); /* new ref */ } -KX_PYMETHODDEF_DOC(KX_Camera, pointInsideFrustum, +KX_PYMETHODDEF_DOC_O(KX_Camera, pointInsideFrustum, "pointInsideFrustum(point) -> Bool\n" "\treturns 1 if the given point is inside this camera's viewing frustum.\n\n" "\tpoint = The point to test (in world coordinates.)\n\n" @@ -727,7 +720,7 @@ KX_PYMETHODDEF_DOC(KX_Camera, pointInsideFrustum, ) { MT_Point3 point; - if (PyVecArgTo(args, point)) + if (PyVecTo(value, point)) { return PyInt_FromLong(PointInsideFrustum(point)); /* new ref */ } @@ -736,7 +729,7 @@ KX_PYMETHODDEF_DOC(KX_Camera, pointInsideFrustum, return NULL; } -KX_PYMETHODDEF_DOC(KX_Camera, getCameraToWorld, +KX_PYMETHODDEF_DOC_NOARGS(KX_Camera, getCameraToWorld, "getCameraToWorld() -> Matrix4x4\n" "\treturns the camera to world transformation matrix, as a list of four lists of four values.\n\n" "\tie: [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n" @@ -745,7 +738,7 @@ KX_PYMETHODDEF_DOC(KX_Camera, getCameraToWorld, return PyObjectFrom(GetCameraToWorld()); /* new ref */ } -KX_PYMETHODDEF_DOC(KX_Camera, getWorldToCamera, +KX_PYMETHODDEF_DOC_NOARGS(KX_Camera, getWorldToCamera, "getWorldToCamera() -> Matrix4x4\n" "\treturns the world to camera transformation matrix, as a list of four lists of four values.\n\n" "\tie: [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n" @@ -754,7 +747,7 @@ KX_PYMETHODDEF_DOC(KX_Camera, getWorldToCamera, return PyObjectFrom(GetWorldToCamera()); /* new ref */ } -KX_PYMETHODDEF_DOC(KX_Camera, getProjectionMatrix, +KX_PYMETHODDEF_DOC_NOARGS(KX_Camera, getProjectionMatrix, "getProjectionMatrix() -> Matrix4x4\n" "\treturns this camera's projection matrix, as a list of four lists of four values.\n\n" "\tie: [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n" @@ -763,7 +756,7 @@ KX_PYMETHODDEF_DOC(KX_Camera, getProjectionMatrix, return PyObjectFrom(GetProjectionMatrix()); /* new ref */ } -KX_PYMETHODDEF_DOC(KX_Camera, setProjectionMatrix, +KX_PYMETHODDEF_DOC_O(KX_Camera, setProjectionMatrix, "setProjectionMatrix(MT_Matrix4x4 m) -> None\n" "\tSets this camera's projection matrix\n" "\n" @@ -805,56 +798,50 @@ KX_PYMETHODDEF_DOC(KX_Camera, setProjectionMatrix, "\tcam = co.getOwner()\n" "\tcam.setProjectionMatrix(Perspective(-1.0, 1.0, -1.0, 1.0, 0.1, 1))\n") { - PyObject *pymat; - if (PyArg_ParseTuple(args, "O", &pymat)) + MT_Matrix4x4 mat; + if (!PyMatTo(value, mat)) { - MT_Matrix4x4 mat; - if (PyMatTo(pymat, mat)) - { - SetProjectionMatrix(mat); - Py_RETURN_NONE; - } + PyErr_SetString(PyExc_TypeError, "setProjectionMatrix: Expected 4x4 list as matrix argument."); + return NULL; } - - PyErr_SetString(PyExc_TypeError, "setProjectionMatrix: Expected 4x4 list as matrix argument."); - return NULL; + + SetProjectionMatrix(mat); + Py_RETURN_NONE; } -KX_PYMETHODDEF_DOC(KX_Camera, enableViewport, +KX_PYMETHODDEF_DOC_O(KX_Camera, enableViewport, "enableViewport(viewport)\n" "Sets this camera's viewport status\n" ) { - int viewport; - if (PyArg_ParseTuple(args,"i",&viewport)) - { - if(viewport) - EnableViewport(true); - else - EnableViewport(false); - } - else { + int viewport = PyObject_IsTrue(value); + + if (viewport == -1) { + PyErr_SetString(PyExc_ValueError, "expected True/False or 0/1"); return NULL; } + if(viewport) + EnableViewport(true); + else + EnableViewport(false); + Py_RETURN_NONE; } -KX_PYMETHODDEF_DOC(KX_Camera, setViewport, +KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, setViewport, "setViewport(left, bottom, right, top)\n" "Sets this camera's viewport\n") { int left, bottom, right, top; - if (PyArg_ParseTuple(args,"iiii",&left, &bottom, &right, &top)) - { - SetViewport(left, bottom, right, top); - } else { + if (!PyArg_ParseTuple(args,"iiii:setViewport",&left, &bottom, &right, &top)) return NULL; - } + + SetViewport(left, bottom, right, top); Py_RETURN_NONE; } -KX_PYMETHODDEF_DOC(KX_Camera, setOnTop, +KX_PYMETHODDEF_DOC_NOARGS(KX_Camera, setOnTop, "setOnTop()\n" "Sets this camera's viewport on top\n") { diff --git a/source/gameengine/Ketsji/KX_Camera.h b/source/gameengine/Ketsji/KX_Camera.h index 3e93745d888..efd18f99390 100644 --- a/source/gameengine/Ketsji/KX_Camera.h +++ b/source/gameengine/Ketsji/KX_Camera.h @@ -257,18 +257,18 @@ public: int GetViewportTop() const; - KX_PYMETHOD_DOC(KX_Camera, sphereInsideFrustum); - KX_PYMETHOD_DOC(KX_Camera, boxInsideFrustum); - KX_PYMETHOD_DOC(KX_Camera, pointInsideFrustum); + KX_PYMETHOD_DOC_VARARGS(KX_Camera, sphereInsideFrustum); + KX_PYMETHOD_DOC_O(KX_Camera, boxInsideFrustum); + KX_PYMETHOD_DOC_O(KX_Camera, pointInsideFrustum); - KX_PYMETHOD_DOC(KX_Camera, getCameraToWorld); - KX_PYMETHOD_DOC(KX_Camera, getWorldToCamera); - KX_PYMETHOD_DOC(KX_Camera, getProjectionMatrix); - KX_PYMETHOD_DOC(KX_Camera, setProjectionMatrix); + KX_PYMETHOD_DOC_NOARGS(KX_Camera, getCameraToWorld); + KX_PYMETHOD_DOC_NOARGS(KX_Camera, getWorldToCamera); + KX_PYMETHOD_DOC_NOARGS(KX_Camera, getProjectionMatrix); + KX_PYMETHOD_DOC_O(KX_Camera, setProjectionMatrix); - KX_PYMETHOD_DOC(KX_Camera, enableViewport); - KX_PYMETHOD_DOC(KX_Camera, setViewport); - KX_PYMETHOD_DOC(KX_Camera, setOnTop); + KX_PYMETHOD_DOC_O(KX_Camera, enableViewport); + KX_PYMETHOD_DOC_VARARGS(KX_Camera, setViewport); + KX_PYMETHOD_DOC_NOARGS(KX_Camera, setOnTop); virtual PyObject* _getattr(const char *attr); /* lens, near, far, projection_matrix */ virtual int _setattr(const char *attr, PyObject *pyvalue); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 7d785f07ed2..82b5fff534c 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1030,8 +1030,8 @@ PyMethodDef KX_GameObject::Methods[] = { {"endObject",(PyCFunction) KX_GameObject::sPyEndObject, METH_NOARGS}, KX_PYMETHODTABLE(KX_GameObject, rayCastTo), KX_PYMETHODTABLE(KX_GameObject, rayCast), - KX_PYMETHODTABLE(KX_GameObject, getDistanceTo), - KX_PYMETHODTABLE(KX_GameObject, getVectTo), + KX_PYMETHODTABLE_O(KX_GameObject, getDistanceTo), + KX_PYMETHODTABLE_O(KX_GameObject, getVectTo), {NULL,NULL} //Sentinel }; @@ -1136,10 +1136,7 @@ PyObject* KX_GameObject::_getattr(const char *attr) { KX_GameObject* parent = GetParent(); if (parent) - { - parent->AddRef(); - return parent; - } + return parent->AddRef(); Py_RETURN_NONE; } @@ -1297,7 +1294,7 @@ PyObject* KX_GameObject::PyApplyForce(PyObject* self, PyObject* args) int local = 0; PyObject* pyvect; - if (PyArg_ParseTuple(args, "O|i", &pyvect, &local)) { + if (PyArg_ParseTuple(args, "O|i:applyForce", &pyvect, &local)) { MT_Vector3 force; if (PyVecTo(pyvect, force)) { ApplyForce(force, (local!=0)); @@ -1312,7 +1309,7 @@ PyObject* KX_GameObject::PyApplyTorque(PyObject* self, PyObject* args) int local = 0; PyObject* pyvect; - if (PyArg_ParseTuple(args, "O|i", &pyvect, &local)) { + if (PyArg_ParseTuple(args, "O|i:applyTorque", &pyvect, &local)) { MT_Vector3 torque; if (PyVecTo(pyvect, torque)) { ApplyTorque(torque, (local!=0)); @@ -1327,7 +1324,7 @@ PyObject* KX_GameObject::PyApplyRotation(PyObject* self, PyObject* args) int local = 0; PyObject* pyvect; - if (PyArg_ParseTuple(args, "O|i", &pyvect, &local)) { + if (PyArg_ParseTuple(args, "O|i:applyRotation", &pyvect, &local)) { MT_Vector3 rotation; if (PyVecTo(pyvect, rotation)) { ApplyRotation(rotation, (local!=0)); @@ -1342,7 +1339,7 @@ PyObject* KX_GameObject::PyApplyMovement(PyObject* self, PyObject* args) int local = 0; PyObject* pyvect; - if (PyArg_ParseTuple(args, "O|i", &pyvect, &local)) { + if (PyArg_ParseTuple(args, "O|i:applyMovement", &pyvect, &local)) { MT_Vector3 movement; if (PyVecTo(pyvect, movement)) { ApplyMovement(movement, (local!=0)); @@ -1356,7 +1353,7 @@ PyObject* KX_GameObject::PyGetLinearVelocity(PyObject* self, PyObject* args) { // only can get the velocity if we have a physics object connected to us... int local = 0; - if (PyArg_ParseTuple(args,"|i",&local)) + if (PyArg_ParseTuple(args,"|i:getLinearVelocity",&local)) { return PyObjectFrom(GetLinearVelocity((local!=0))); } @@ -1371,7 +1368,7 @@ PyObject* KX_GameObject::PySetLinearVelocity(PyObject* self, PyObject* args) int local = 0; PyObject* pyvect; - if (PyArg_ParseTuple(args,"O|i",&pyvect,&local)) { + if (PyArg_ParseTuple(args,"O|i:setLinearVelocity",&pyvect,&local)) { MT_Vector3 velocity; if (PyVecTo(pyvect, velocity)) { setLinearVelocity(velocity, (local!=0)); @@ -1385,7 +1382,7 @@ PyObject* KX_GameObject::PyGetAngularVelocity(PyObject* self, PyObject* args) { // only can get the velocity if we have a physics object connected to us... int local = 0; - if (PyArg_ParseTuple(args,"|i",&local)) + if (PyArg_ParseTuple(args,"|i:getAngularVelocity",&local)) { return PyObjectFrom(GetAngularVelocity((local!=0))); } @@ -1400,7 +1397,7 @@ PyObject* KX_GameObject::PySetAngularVelocity(PyObject* self, PyObject* args) int local = 0; PyObject* pyvect; - if (PyArg_ParseTuple(args,"O|i",&pyvect,&local)) { + if (PyArg_ParseTuple(args,"O|i:setAngularVelocity",&pyvect,&local)) { MT_Vector3 velocity; if (PyVecTo(pyvect, velocity)) { setAngularVelocity(velocity, (local!=0)); @@ -1413,7 +1410,7 @@ PyObject* KX_GameObject::PySetAngularVelocity(PyObject* self, PyObject* args) PyObject* KX_GameObject::PySetVisible(PyObject* self, PyObject* args) { int visible, recursive = 0; - if (!PyArg_ParseTuple(args,"i|i",&visible, &recursive)) + if (!PyArg_ParseTuple(args,"i|i:setVisible",&visible, &recursive)) return NULL; SetVisible(visible ? true:false, recursive ? true:false); @@ -1464,7 +1461,7 @@ PyObject* KX_GameObject::PyGetVelocity(PyObject* self, PyObject* args) PyObject* pypos = NULL; - if (PyArg_ParseTuple(args, "|O", &pypos)) + if (PyArg_ParseTuple(args, "|O:getVelocity", &pypos)) { if (pypos) PyVecTo(pypos, point); @@ -1520,10 +1517,7 @@ PyObject* KX_GameObject::PyGetParent(PyObject* self) { KX_GameObject* parent = this->GetParent(); if (parent) - { - parent->AddRef(); - return parent; - } + return parent->AddRef(); Py_RETURN_NONE; } @@ -1592,7 +1586,7 @@ PyObject* KX_GameObject::PyGetMesh(PyObject* self, PyObject* args) { int mesh = 0; - if (!PyArg_ParseTuple(args, "|i", &mesh)) + if (!PyArg_ParseTuple(args, "|i:getMesh", &mesh)) return NULL; // python sets a simple error if (((unsigned int)mesh < m_meshes.size()) && mesh >= 0) @@ -1638,7 +1632,7 @@ PyObject* KX_GameObject::PyApplyImpulse(PyObject* self, PyObject* args) return NULL; } - if (PyArg_ParseTuple(args, "OO", &pyattach, &pyimpulse)) + if (PyArg_ParseTuple(args, "OO:applyImpulse", &pyattach, &pyimpulse)) { MT_Point3 attach; MT_Vector3 impulse; @@ -1705,7 +1699,7 @@ PyObject* KX_GameObject::PyAlignAxisToVect(PyObject* self, PyObject* args) int axis = 2; //z axis is the default float fac = 1.0; - if (PyArg_ParseTuple(args,"O|if",&pyvect,&axis, &fac)) + if (PyArg_ParseTuple(args,"O|if:alignAxisToVect",&pyvect,&axis, &fac)) { MT_Vector3 vect; if (PyVecTo(pyvect, vect)) @@ -1773,19 +1767,18 @@ PyObject* KX_GameObject::PyGetPropertyNames(PyObject* self) return ConvertKeysToPython(); } -KX_PYMETHODDEF_DOC(KX_GameObject, getDistanceTo, +KX_PYMETHODDEF_DOC_O(KX_GameObject, getDistanceTo, "getDistanceTo(other): get distance to another point/KX_GameObject") { MT_Point3 b; - if (PyVecArgTo(args, b)) + if (PyVecTo(value, b)) { return PyFloat_FromDouble(NodeGetWorldPosition().distance(b)); } PyErr_Clear(); - PyObject *pyother; KX_GameObject *other; - if (PyArg_ParseTuple(args, "O", &pyother) && ConvertPythonToGameObject(pyother, &other, false)) + if (ConvertPythonToGameObject(value, &other, false)) { return PyFloat_FromDouble(NodeGetWorldPosition().distance(other->NodeGetWorldPosition())); } @@ -1793,7 +1786,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getDistanceTo, return NULL; } -KX_PYMETHODDEF_DOC(KX_GameObject, getVectTo, +KX_PYMETHODDEF_DOC_O(KX_GameObject, getVectTo, "getVectTo(other): get vector and the distance to another point/KX_GameObject\n" "Returns a 3-tuple with (distance,worldVector,localVector)\n") { @@ -1802,14 +1795,13 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getVectTo, MT_Scalar distance; PyObject *returnValue; - PyObject *pyother; - if (!PyVecArgTo(args, toPoint)) + if (!PyVecTo(value, toPoint)) { PyErr_Clear(); KX_GameObject *other; - if (PyArg_ParseTuple(args, "O", &pyother) && ConvertPythonToGameObject(pyother, &other, false)) + if (ConvertPythonToGameObject(value, &other, false)) { toPoint = other->NodeGetWorldPosition(); } else @@ -1894,7 +1886,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo, float dist = 0.0f; char *propName = NULL; - if (!PyArg_ParseTuple(args,"O|fs", &pyarg, &dist, &propName)) { + if (!PyArg_ParseTuple(args,"O|fs:rayCastTo", &pyarg, &dist, &propName)) { return NULL; // python sets simple error } @@ -1937,10 +1929,8 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo, KX_RayCast::RayTest(pe, fromPoint, toPoint, callback); if (m_pHitObject) - { - m_pHitObject->AddRef(); - return m_pHitObject; - } + return m_pHitObject->AddRef(); + Py_RETURN_NONE; } @@ -1973,7 +1963,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, KX_GameObject *other; int face=0, xray=0, poly=0; - if (!PyArg_ParseTuple(args,"O|Ofsiii", &pyto, &pyfrom, &dist, &propName, &face, &xray, &poly)) { + if (!PyArg_ParseTuple(args,"O|Ofsiii:rayCast", &pyto, &pyfrom, &dist, &propName, &face, &xray, &poly)) { return NULL; // Python sets a simple error } diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 7fe3009a957..d95e3751d33 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -799,8 +799,8 @@ public: KX_PYMETHOD_NOARGS(KX_GameObject,EndObject); KX_PYMETHOD_DOC(KX_GameObject,rayCastTo); KX_PYMETHOD_DOC(KX_GameObject,rayCast); - KX_PYMETHOD_DOC(KX_GameObject,getDistanceTo); - KX_PYMETHOD_DOC(KX_GameObject,getVectTo); + KX_PYMETHOD_DOC_O(KX_GameObject,getDistanceTo); + KX_PYMETHOD_DOC_O(KX_GameObject,getVectTo); private : diff --git a/source/gameengine/Ketsji/KX_PyMath.cpp b/source/gameengine/Ketsji/KX_PyMath.cpp index afb20acec2d..92f18590a7e 100644 --- a/source/gameengine/Ketsji/KX_PyMath.cpp +++ b/source/gameengine/Ketsji/KX_PyMath.cpp @@ -77,35 +77,92 @@ bool PyObject_IsMT_Matrix(PyObject *pymat, unsigned int rank) PyObject* PyObjectFrom(const MT_Matrix4x4 &mat) { +#if 0 return Py_BuildValue("[[ffff][ffff][ffff][ffff]]", mat[0][0], mat[0][1], mat[0][2], mat[0][3], mat[1][0], mat[1][1], mat[1][2], mat[1][3], mat[2][0], mat[2][1], mat[2][2], mat[2][3], mat[3][0], mat[3][1], mat[3][2], mat[3][3]); +#else + PyObject *list = PyList_New(4); + PyObject *sublist; + int i; + + for(i=0; i < 4; i++) { + sublist = PyList_New(4); + PyList_SET_ITEM(sublist, 0, PyFloat_FromDouble(mat[i][0])); + PyList_SET_ITEM(sublist, 1, PyFloat_FromDouble(mat[i][1])); + PyList_SET_ITEM(sublist, 2, PyFloat_FromDouble(mat[i][2])); + PyList_SET_ITEM(sublist, 2, PyFloat_FromDouble(mat[i][3])); + PyList_SET_ITEM(list, i, sublist); + } + + return list; +#endif } PyObject* PyObjectFrom(const MT_Matrix3x3 &mat) { +#if 0 return Py_BuildValue("[[fff][fff][fff]]", mat[0][0], mat[0][1], mat[0][2], mat[1][0], mat[1][1], mat[1][2], mat[2][0], mat[2][1], mat[2][2]); +#else + PyObject *list = PyList_New(3); + PyObject *sublist; + int i; + + for(i=0; i < 3; i++) { + sublist = PyList_New(3); + PyList_SET_ITEM(sublist, 0, PyFloat_FromDouble(mat[i][0])); + PyList_SET_ITEM(sublist, 1, PyFloat_FromDouble(mat[i][1])); + PyList_SET_ITEM(sublist, 2, PyFloat_FromDouble(mat[i][2])); + PyList_SET_ITEM(list, i, sublist); + } + + return list; +#endif } PyObject* PyObjectFrom(const MT_Tuple4 &vec) { +#if 0 return Py_BuildValue("[ffff]", vec[0], vec[1], vec[2], vec[3]); +#else + PyObject *list = PyList_New(4); + PyList_SET_ITEM(list, 0, PyFloat_FromDouble(vec[0])); + PyList_SET_ITEM(list, 1, PyFloat_FromDouble(vec[1])); + PyList_SET_ITEM(list, 2, PyFloat_FromDouble(vec[2])); + PyList_SET_ITEM(list, 3, PyFloat_FromDouble(vec[3])); + return list; +#endif } PyObject* PyObjectFrom(const MT_Tuple3 &vec) { +#if 0 return Py_BuildValue("[fff]", vec[0], vec[1], vec[2]); +#else + PyObject *list = PyList_New(3); + PyList_SET_ITEM(list, 0, PyFloat_FromDouble(vec[0])); + PyList_SET_ITEM(list, 1, PyFloat_FromDouble(vec[1])); + PyList_SET_ITEM(list, 2, PyFloat_FromDouble(vec[2])); + return list; +#endif } PyObject* PyObjectFrom(const MT_Tuple2 &vec) { +#if 0 return Py_BuildValue("[ff]", vec[0], vec[1]); +#else + PyObject *list = PyList_New(2); + PyList_SET_ITEM(list, 0, PyFloat_FromDouble(vec[0])); + PyList_SET_ITEM(list, 1, PyFloat_FromDouble(vec[1])); + return list; +#endif } diff --git a/source/gameengine/Ketsji/KX_PyMath.h b/source/gameengine/Ketsji/KX_PyMath.h index 4e383e9b3d4..39c9c358792 100644 --- a/source/gameengine/Ketsji/KX_PyMath.h +++ b/source/gameengine/Ketsji/KX_PyMath.h @@ -130,20 +130,6 @@ bool PyVecTo(PyObject* pyval, T& vec) return false; } -/** - * Converts a python argument to an MT class. - * This paramater expects arguments as passed to a python method. - */ -template -bool PyVecArgTo(PyObject* args, T& vec) -{ - PyObject* pylist; - if (PyArg_ParseTuple(args,"O",&pylist)) - return PyVecTo(pylist, vec); - - return false; -} - /** * Converts an MT_Matrix4x4 to a python object. */ diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 13f141dec13..c3ae3d0ec52 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -125,10 +125,10 @@ static PyObject* gPyGetRandomFloat(PyObject*) return PyFloat_FromDouble(MT_random()); } -static PyObject* gPySetGravity(PyObject*, PyObject* args) +static PyObject* gPySetGravity(PyObject*, PyObject* value) { - MT_Vector3 vec = MT_Vector3(0., 0., 0.); - if (!PyVecArgTo(args, vec)) + MT_Vector3 vec; + if (!PyVecTo(value, vec)) return NULL; if (gp_KetsjiScene) @@ -412,7 +412,7 @@ static struct PyMethodDef game_methods[] = { METH_VARARGS, (PY_METHODCHAR)SCA_PythonController::sPyAddActiveActuator__doc__}, {"getRandomFloat",(PyCFunction) gPyGetRandomFloat, METH_NOARGS, (PY_METHODCHAR)gPyGetRandomFloat_doc.Ptr()}, - {"setGravity",(PyCFunction) gPySetGravity, METH_VARARGS, (PY_METHODCHAR)"set Gravitation"}, + {"setGravity",(PyCFunction) gPySetGravity, METH_O, (PY_METHODCHAR)"set Gravitation"}, {"getSpectrum",(PyCFunction) gPyGetSpectrum, METH_NOARGS, (PY_METHODCHAR)"get audio spectrum"}, {"stopDSP",(PyCFunction) gPyStopDSP, METH_VARARGS, (PY_METHODCHAR)"stop using the audio dsp (for performance reasons)"}, {"getLogicTicRate", (PyCFunction) gPyGetLogicTicRate, METH_NOARGS, (PY_METHODCHAR)"Gets the logic tic rate"}, @@ -542,11 +542,11 @@ static PyObject* gPyGetFocalLength(PyObject*, PyObject*, PyObject*) Py_RETURN_NONE; } -static PyObject* gPySetBackgroundColor(PyObject*, PyObject* args) +static PyObject* gPySetBackgroundColor(PyObject*, PyObject* value) { - MT_Vector4 vec = MT_Vector4(0., 0., 0.3, 0.); - if (!PyVecArgTo(args, vec)) + MT_Vector4 vec; + if (!PyVecTo(value, vec)) return NULL; if (gp_Canvas) @@ -558,11 +558,11 @@ static PyObject* gPySetBackgroundColor(PyObject*, PyObject* args) -static PyObject* gPySetMistColor(PyObject*, PyObject* args) +static PyObject* gPySetMistColor(PyObject*, PyObject* value) { - MT_Vector3 vec = MT_Vector3(0., 0., 0.); - if (!PyVecArgTo(args, vec)) + MT_Vector3 vec; + if (!PyVecTo(value, vec)) return NULL; if (!gp_Rasterizer) { @@ -613,11 +613,11 @@ static PyObject* gPySetMistEnd(PyObject*, PyObject* args) } -static PyObject* gPySetAmbientColor(PyObject*, PyObject* args) +static PyObject* gPySetAmbientColor(PyObject*, PyObject* value) { - MT_Vector3 vec = MT_Vector3(0., 0., 0.); - if (!PyVecArgTo(args, vec)) + MT_Vector3 vec; + if (!PyVecTo(value, vec)) return NULL; if (!gp_Rasterizer) { @@ -812,9 +812,9 @@ static PyObject* gPyDrawLine(PyObject*, PyObject* args) if (!PyArg_ParseTuple(args,"OOO",&ob_from,&ob_to,&ob_color)) return NULL; - MT_Vector3 from(0., 0., 0.); - MT_Vector3 to(0., 0., 0.); - MT_Vector3 color(0., 0., 0.); + MT_Vector3 from; + MT_Vector3 to; + MT_Vector3 color; if (!PyVecTo(ob_from, from)) return NULL; if (!PyVecTo(ob_to, to)) @@ -840,9 +840,9 @@ static struct PyMethodDef rasterizer_methods[] = { METH_VARARGS, "showMouse(bool visible)"}, {"setMousePosition",(PyCFunction) gPySetMousePosition, METH_VARARGS, "setMousePosition(int x,int y)"}, - {"setBackgroundColor",(PyCFunction)gPySetBackgroundColor,METH_VARARGS,"set Background Color (rgb)"}, - {"setAmbientColor",(PyCFunction)gPySetAmbientColor,METH_VARARGS,"set Ambient Color (rgb)"}, - {"setMistColor",(PyCFunction)gPySetMistColor,METH_VARARGS,"set Mist Color (rgb)"}, + {"setBackgroundColor",(PyCFunction)gPySetBackgroundColor,METH_O,"set Background Color (rgb)"}, + {"setAmbientColor",(PyCFunction)gPySetAmbientColor,METH_O,"set Ambient Color (rgb)"}, + {"setMistColor",(PyCFunction)gPySetMistColor,METH_O,"set Mist Color (rgb)"}, {"setMistStart",(PyCFunction)gPySetMistStart,METH_VARARGS,"set Mist Start(rgb)"}, {"setMistEnd",(PyCFunction)gPySetMistEnd,METH_VARARGS,"set Mist End(rgb)"}, {"enableMotionBlur",(PyCFunction)gPyEnableMotionBlur,METH_VARARGS,"enable motion blur"}, diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 49babedd467..7fcbf5b54bb 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1512,9 +1512,9 @@ double KX_Scene::getSuspendedDelta() //Python PyMethodDef KX_Scene::Methods[] = { - KX_PYMETHODTABLE(KX_Scene, getLightList), - KX_PYMETHODTABLE(KX_Scene, getObjectList), - KX_PYMETHODTABLE(KX_Scene, getName), + KX_PYMETHODTABLE_NOARGS(KX_Scene, getLightList), + KX_PYMETHODTABLE_NOARGS(KX_Scene, getObjectList), + KX_PYMETHODTABLE_NOARGS(KX_Scene, getName), {NULL,NULL} //Sentinel }; @@ -1549,12 +1549,11 @@ PyObject* KX_Scene::_getattr(const char *attr) if (!strcmp(attr, "name")) return PyString_FromString(GetName()); + if (!strcmp(attr, "objects")) + return (PyObject*) m_objectlist->AddRef(); + if (!strcmp(attr, "active_camera")) - { - KX_Camera *camera = GetActiveCamera(); - camera->AddRef(); - return (PyObject*) camera; - } + return (PyObject*) GetActiveCamera()->AddRef(); if (!strcmp(attr, "suspended")) return PyInt_FromLong(m_suspend); @@ -1589,25 +1588,24 @@ int KX_Scene::_setattr(const char *attr, PyObject *pyvalue) return PyObjectPlus::_setattr(attr, pyvalue); } -KX_PYMETHODDEF_DOC(KX_Scene, getLightList, +KX_PYMETHODDEF_DOC_NOARGS(KX_Scene, getLightList, "getLightList() -> list [KX_Light]\n" "Returns a list of all lights in the scene.\n" ) { - m_lightlist->AddRef(); - return (PyObject*) m_lightlist; + return (PyObject*) m_lightlist->AddRef(); } -KX_PYMETHODDEF_DOC(KX_Scene, getObjectList, +KX_PYMETHODDEF_DOC_NOARGS(KX_Scene, getObjectList, "getObjectList() -> list [KX_GameObject]\n" "Returns a list of all game objects in the scene.\n" ) { - m_objectlist->AddRef(); - return (PyObject*) m_objectlist; + // ShowDeprecationWarning("getObjectList()", "the objects property"); // XXX Grr, why doesnt this work? + return (PyObject*) m_objectlist->AddRef(); } -KX_PYMETHODDEF_DOC(KX_Scene, getName, +KX_PYMETHODDEF_DOC_NOARGS(KX_Scene, getName, "getName() -> string\n" "Returns the name of the scene.\n" ) diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index ecc0fd51d73..e4d4b6fe2cd 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -547,9 +547,9 @@ public: */ void SetNodeTree(SG_Tree* root); - KX_PYMETHOD_DOC(KX_Scene, getLightList); - KX_PYMETHOD_DOC(KX_Scene, getObjectList); - KX_PYMETHOD_DOC(KX_Scene, getName); + KX_PYMETHOD_DOC_NOARGS(KX_Scene, getLightList); + KX_PYMETHOD_DOC_NOARGS(KX_Scene, getObjectList); + KX_PYMETHOD_DOC_NOARGS(KX_Scene, getName); /* KX_PYMETHOD_DOC(KX_Scene, getActiveCamera); KX_PYMETHOD_DOC(KX_Scene, getActiveCamera); diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp index ab102ee547a..1c427768b66 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.cpp +++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp @@ -63,18 +63,18 @@ PyParentObject KX_VertexProxy::Parents[] = { }; PyMethodDef KX_VertexProxy::Methods[] = { -{"getXYZ", (PyCFunction)KX_VertexProxy::sPyGetXYZ,METH_VARARGS}, -{"setXYZ", (PyCFunction)KX_VertexProxy::sPySetXYZ,METH_VARARGS}, -{"getUV", (PyCFunction)KX_VertexProxy::sPyGetUV,METH_VARARGS}, -{"setUV", (PyCFunction)KX_VertexProxy::sPySetUV,METH_VARARGS}, +{"getXYZ", (PyCFunction)KX_VertexProxy::sPyGetXYZ,METH_NOARGS}, +{"setXYZ", (PyCFunction)KX_VertexProxy::sPySetXYZ,METH_O}, +{"getUV", (PyCFunction)KX_VertexProxy::sPyGetUV,METH_NOARGS}, +{"setUV", (PyCFunction)KX_VertexProxy::sPySetUV,METH_O}, -{"getUV2", (PyCFunction)KX_VertexProxy::sPyGetUV2,METH_VARARGS}, +{"getUV2", (PyCFunction)KX_VertexProxy::sPyGetUV2,METH_NOARGS}, {"setUV2", (PyCFunction)KX_VertexProxy::sPySetUV2,METH_VARARGS}, -{"getRGBA", (PyCFunction)KX_VertexProxy::sPyGetRGBA,METH_VARARGS}, -{"setRGBA", (PyCFunction)KX_VertexProxy::sPySetRGBA,METH_VARARGS}, -{"getNormal", (PyCFunction)KX_VertexProxy::sPyGetNormal,METH_VARARGS}, -{"setNormal", (PyCFunction)KX_VertexProxy::sPySetNormal,METH_VARARGS}, +{"getRGBA", (PyCFunction)KX_VertexProxy::sPyGetRGBA,METH_NOARGS}, +{"setRGBA", (PyCFunction)KX_VertexProxy::sPySetRGBA,METH_O}, +{"getNormal", (PyCFunction)KX_VertexProxy::sPyGetNormal,METH_NOARGS}, +{"setNormal", (PyCFunction)KX_VertexProxy::sPySetNormal,METH_O}, {NULL,NULL} //Sentinel }; @@ -312,130 +312,103 @@ void KX_VertexProxy::ReplicaSetName(STR_String) {}; // stuff for python integration -PyObject* KX_VertexProxy::PyGetXYZ(PyObject*, - PyObject*, - PyObject*) +PyObject* KX_VertexProxy::PyGetXYZ(PyObject*) { return PyObjectFrom(MT_Point3(m_vertex->getXYZ())); } -PyObject* KX_VertexProxy::PySetXYZ(PyObject*, - PyObject* args, - PyObject*) +PyObject* KX_VertexProxy::PySetXYZ(PyObject*, PyObject* value) { MT_Point3 vec; - if (PyVecArgTo(args, vec)) - { - m_vertex->SetXYZ(vec); - m_mesh->SetMeshModified(true); - Py_RETURN_NONE; - } - - return NULL; + if (!PyVecTo(value, vec)) + return NULL; + + m_vertex->SetXYZ(vec); + m_mesh->SetMeshModified(true); + Py_RETURN_NONE; } -PyObject* KX_VertexProxy::PyGetNormal(PyObject*, - PyObject*, - PyObject*) +PyObject* KX_VertexProxy::PyGetNormal(PyObject*) { return PyObjectFrom(MT_Vector3(m_vertex->getNormal())); } -PyObject* KX_VertexProxy::PySetNormal(PyObject*, - PyObject* args, - PyObject*) +PyObject* KX_VertexProxy::PySetNormal(PyObject*, PyObject* value) { MT_Vector3 vec; - if (PyVecArgTo(args, vec)) - { - m_vertex->SetNormal(vec); - m_mesh->SetMeshModified(true); - Py_RETURN_NONE; - } + if (!PyVecTo(value, vec)) + return NULL; - return NULL; + m_vertex->SetNormal(vec); + m_mesh->SetMeshModified(true); + Py_RETURN_NONE; } -PyObject* KX_VertexProxy::PyGetRGBA(PyObject*, - PyObject*, - PyObject*) +PyObject* KX_VertexProxy::PyGetRGBA(PyObject*) { int *rgba = (int *) m_vertex->getRGBA(); return PyInt_FromLong(*rgba); } -PyObject* KX_VertexProxy::PySetRGBA(PyObject*, - PyObject* args, - PyObject*) +PyObject* KX_VertexProxy::PySetRGBA(PyObject*, PyObject* value) { - float r, g, b, a; - if (PyArg_ParseTuple(args, "(ffff)", &r, &g, &b, &a)) - { - m_vertex->SetRGBA(MT_Vector4(r, g, b, a)); - m_mesh->SetMeshModified(true); - Py_RETURN_NONE; - } - PyErr_Clear(); - - int rgba; - if (PyArg_ParseTuple(args,"i",&rgba)) - { + if PyInt_Check(value) { + int rgba = PyInt_AsLong(value); m_vertex->SetRGBA(rgba); m_mesh->SetMeshModified(true); Py_RETURN_NONE; } + else { + MT_Vector4 vec; + if (PyVecTo(value, vec)) + { + m_vertex->SetRGBA(vec); + m_mesh->SetMeshModified(true); + Py_RETURN_NONE; + } + } + PyErr_SetString(PyExc_TypeError, "expected a 4D vector or an int"); return NULL; } -PyObject* KX_VertexProxy::PyGetUV(PyObject*, - PyObject*, - PyObject*) +PyObject* KX_VertexProxy::PyGetUV(PyObject*) { return PyObjectFrom(MT_Vector2(m_vertex->getUV1())); } -PyObject* KX_VertexProxy::PySetUV(PyObject*, - PyObject* args, - PyObject*) +PyObject* KX_VertexProxy::PySetUV(PyObject*, PyObject* value) { MT_Point2 vec; - if (PyVecArgTo(args, vec)) - { - m_vertex->SetUV(vec); - m_mesh->SetMeshModified(true); - Py_RETURN_NONE; - } + if (!PyVecTo(value, vec)) + return NULL; - return NULL; + m_vertex->SetUV(vec); + m_mesh->SetMeshModified(true); + Py_RETURN_NONE; } -PyObject* KX_VertexProxy::PyGetUV2(PyObject*, - PyObject*, - PyObject*) +PyObject* KX_VertexProxy::PyGetUV2(PyObject*) { return PyObjectFrom(MT_Vector2(m_vertex->getUV2())); } -PyObject* KX_VertexProxy::PySetUV2(PyObject*, - PyObject* args, - PyObject*) +PyObject* KX_VertexProxy::PySetUV2(PyObject*, PyObject* args) { MT_Point2 vec; unsigned int unit=0; - PyObject* list=0; - if(PyArg_ParseTuple(args, "Oi", &list, &unit)) - { - if (PyVecTo(list, vec)) - { - m_vertex->SetFlag((m_vertex->getFlag()|RAS_TexVert::SECOND_UV)); - m_vertex->SetUnit(unit); - m_vertex->SetUV2(vec); - m_mesh->SetMeshModified(true); - Py_RETURN_NONE; - } - } - return NULL; + PyObject* list= NULL; + if(!PyArg_ParseTuple(args, "Oi:setUV2", &list, &unit)) + return NULL; + + if (!PyVecTo(list, vec)) + return NULL; + + m_vertex->SetFlag((m_vertex->getFlag()|RAS_TexVert::SECOND_UV)); + m_vertex->SetUnit(unit); + m_vertex->SetUV2(vec); + m_mesh->SetMeshModified(true); + Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_VertexProxy.h b/source/gameengine/Ketsji/KX_VertexProxy.h index 72949268e6d..28196075904 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.h +++ b/source/gameengine/Ketsji/KX_VertexProxy.h @@ -57,18 +57,18 @@ public: virtual PyObject* _getattr(const char *attr); virtual int _setattr(const char *attr, PyObject *pyvalue); - KX_PYMETHOD(KX_VertexProxy,GetXYZ); - KX_PYMETHOD(KX_VertexProxy,SetXYZ); - KX_PYMETHOD(KX_VertexProxy,GetUV); - KX_PYMETHOD(KX_VertexProxy,SetUV); + KX_PYMETHOD_NOARGS(KX_VertexProxy,GetXYZ); + KX_PYMETHOD_O(KX_VertexProxy,SetXYZ); + KX_PYMETHOD_NOARGS(KX_VertexProxy,GetUV); + KX_PYMETHOD_O(KX_VertexProxy,SetUV); - KX_PYMETHOD(KX_VertexProxy,GetUV2); - KX_PYMETHOD(KX_VertexProxy,SetUV2); + KX_PYMETHOD_NOARGS(KX_VertexProxy,GetUV2); + KX_PYMETHOD_VARARGS(KX_VertexProxy,SetUV2); - KX_PYMETHOD(KX_VertexProxy,GetRGBA); - KX_PYMETHOD(KX_VertexProxy,SetRGBA); - KX_PYMETHOD(KX_VertexProxy,GetNormal); - KX_PYMETHOD(KX_VertexProxy,SetNormal); + KX_PYMETHOD_NOARGS(KX_VertexProxy,GetRGBA); + KX_PYMETHOD_O(KX_VertexProxy,SetRGBA); + KX_PYMETHOD_NOARGS(KX_VertexProxy,GetNormal); + KX_PYMETHOD_O(KX_VertexProxy,SetNormal); }; -- cgit v1.2.3 From 394d893e13257cb0fc5bec815e2111c12d5ed4ec Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 24 Feb 2009 03:29:31 +0000 Subject: compile scripts when converting controllers to give more predictable performance and print syntax errors early on rather then when the script is first executed. --- .../gameengine/Converter/KX_ConvertControllers.cpp | 7 +++ .../gameengine/GameLogic/SCA_PythonController.cpp | 69 ++++++++++++++-------- source/gameengine/GameLogic/SCA_PythonController.h | 1 + 3 files changed, 51 insertions(+), 26 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/KX_ConvertControllers.cpp b/source/gameengine/Converter/KX_ConvertControllers.cpp index da490b4ee85..fb100b0a68b 100644 --- a/source/gameengine/Converter/KX_ConvertControllers.cpp +++ b/source/gameengine/Converter/KX_ConvertControllers.cpp @@ -200,6 +200,13 @@ void BL_ConvertControllers( gameobj->AddController(gamecontroller); converter->RegisterGameController(gamecontroller, bcontr); + + if (bcontr->type==CONT_PYTHON) { + /* not strictly needed but gives syntax errors early on and + * gives more pradictable performance for larger scripts */ + (static_cast(gamecontroller))->Compile(); + } + //done with gamecontroller gamecontroller->Release(); } diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 2fff21f22fb..5ab8db2986d 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -242,6 +242,43 @@ PyMethodDef SCA_PythonController::Methods[] = { }; +bool SCA_PythonController::Compile() +{ + //printf("py script modified '%s'\n", m_scriptName.Ptr()); + + // if a script already exists, decref it before replace the pointer to a new script + if (m_bytecode) + { + Py_DECREF(m_bytecode); + m_bytecode=NULL; + } + // recompile the scripttext into bytecode + m_bytecode = Py_CompileString(m_scriptText.Ptr(), m_scriptName.Ptr(), Py_file_input); + m_bModified=false; + + if (m_bytecode) + { + + return true; + } + else { + // didn't compile, so instead of compile, complain + // something is wrong, tell the user what went wrong + printf("Python compile error from controller \"%s\": \n", GetName().Ptr()); + //PyRun_SimpleString(m_scriptText.Ptr()); + PyErr_Print(); + + /* Added in 2.48a, the last_traceback can reference Objects for example, increasing + * their user count. Not to mention holding references to wrapped data. + * This is especially bad when the PyObject for the wrapped data is free'd, after blender + * has alredy dealocated the pointer */ + PySys_SetObject( (char *)"last_traceback", Py_None); + PyErr_Clear(); /* just to be sure */ + + return false; + } +} + void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) { m_sCurrentController = this; @@ -249,33 +286,13 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) if (m_bModified) { - // if a script already exists, decref it before replace the pointer to a new script - if (m_bytecode) - { - Py_DECREF(m_bytecode); - m_bytecode=NULL; - } - // recompile the scripttext into bytecode - m_bytecode = Py_CompileString(m_scriptText.Ptr(), m_scriptName.Ptr(), Py_file_input); - if (!m_bytecode) - { - // didn't compile, so instead of compile, complain - // something is wrong, tell the user what went wrong - printf("Python compile error from controller \"%s\": \n", GetName().Ptr()); - //PyRun_SimpleString(m_scriptText.Ptr()); - PyErr_Print(); - - /* Added in 2.48a, the last_traceback can reference Objects for example, increasing - * their user count. Not to mention holding references to wrapped data. - * This is especially bad when the PyObject for the wrapped data is free'd, after blender - * has alredy dealocated the pointer */ - PySys_SetObject( "last_traceback", Py_None); - PyErr_Clear(); /* just to be sure */ - + if (Compile()==false) // sets m_bModified to false return; - } - m_bModified=false; } + if (!m_bytecode) { + return; + } + /* * This part here with excdict is a temporary patch @@ -313,7 +330,7 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) * their user count. Not to mention holding references to wrapped data. * This is especially bad when the PyObject for the wrapped data is free'd, after blender * has alredy dealocated the pointer */ - PySys_SetObject( "last_traceback", Py_None); + PySys_SetObject( (char *)"last_traceback", Py_None); PyErr_Clear(); /* just to be sure */ //PyRun_SimpleString(m_scriptText.Ptr()); diff --git a/source/gameengine/GameLogic/SCA_PythonController.h b/source/gameengine/GameLogic/SCA_PythonController.h index 00c30d7f3d5..046ef1f7aed 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.h +++ b/source/gameengine/GameLogic/SCA_PythonController.h @@ -70,6 +70,7 @@ class SCA_PythonController : public SCA_IController void AddTriggeredSensor(class SCA_ISensor* sensor) { m_triggeredSensors.push_back(sensor); } int IsTriggered(class SCA_ISensor* sensor); + bool Compile(); static const char* sPyGetCurrentController__doc__; static PyObject* sPyGetCurrentController(PyObject* self); -- cgit v1.2.3 From 6c7c38a4e4892677f8e7db2b41115209901a2d35 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 24 Feb 2009 05:50:45 +0000 Subject: BGE Py API * Made GameLogic.addActiveActuator(actu, bool) to raise an error if the actuator is not in the list. Before it would allow any value as the actuator and fail silently (makes debugging scripts more difficult). * Allow the actuator to be a string which is convenient if you dont want to change the settings of the actuator. * Added activate/deactivate functions to the controller, this is more logical since the GameLogic.addActiveActuator() function is running through the controller anyway. GameLogic.addActiveActuator(controller.getActuator("SomeAct"), True) ...can be replaced with... controller.activate("SomeAct") --- .../gameengine/GameLogic/SCA_PythonController.cpp | 91 ++++++++++++++++------ source/gameengine/GameLogic/SCA_PythonController.h | 4 + source/gameengine/PyDoc/GameLogic.py | 2 +- source/gameengine/PyDoc/KX_Scene.py | 2 + source/gameengine/PyDoc/SCA_PythonController.py | 12 ++- 5 files changed, 86 insertions(+), 25 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 5ab8db2986d..92852ee03cb 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -157,8 +157,40 @@ static const char* sPyGetCurrentController__doc__; PyObject* SCA_PythonController::sPyGetCurrentController(PyObject* self) { - m_sCurrentController->AddRef(); - return m_sCurrentController; + return m_sCurrentController->AddRef(); +} + +SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value) +{ + // for safety, todo: only allow for registered actuators (pointertable) + // we don't want to crash gameengine/blender by python scripts + std::vector lacts = m_sCurrentController->GetLinkedActuators(); + std::vector::iterator it; + + if (PyString_Check(value)) { + /* get the actuator from the name */ + char *name= PyString_AsString(value); + for(it = lacts.begin(); it!= lacts.end(); it++) { + if( name == (*it)->GetName() ) { + return *it; + } + } + } + else { + /* Expecting an actuator type */ + for(it = lacts.begin(); it!= lacts.end(); it++) { + if( static_cast(value) == (*it) ) { + return *it; + } + } + } + + /* set the exception */ + PyObject *value_str = PyObject_Repr(value); /* new ref */ + PyErr_Format(PyExc_ValueError, "'%s' not in this controllers actuator list", PyString_AsString(value_str)); + Py_DECREF(value_str); + + return false; } #if 0 @@ -175,26 +207,14 @@ PyObject* SCA_PythonController::sPyAddActiveActuator( int activate; if (!PyArg_ParseTuple(args, "Oi", &ob1,&activate)) return NULL; - - // for safety, todo: only allow for registered actuators (pointertable) - // we don't want to crash gameengine/blender by python scripts - std::vector lacts = m_sCurrentController->GetLinkedActuators(); - std::vector::iterator it; - bool found = false; - CValue* act = (CValue*)ob1; - - for(it = lacts.begin(); it!= lacts.end(); it++) { - if( static_cast(act) == (*it) ) { - found=true; - break; - } - } - if(found){ - CValue* boolval = new CBoolValue(activate!=0); - m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)act,boolval); - boolval->Release(); - } + SCA_IActuator* actu = LinkedActuatorFromPy(ob1); + if(actu==NULL) + return NULL; + + CValue* boolval = new CBoolValue(activate!=0); + m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu,boolval); + boolval->Release(); Py_RETURN_NONE; } @@ -229,6 +249,9 @@ PyParentObject SCA_PythonController::Parents[] = { NULL }; PyMethodDef SCA_PythonController::Methods[] = { + {"activate", (PyCFunction) SCA_PythonController::sPyActivate, METH_O}, + {"deactivate", (PyCFunction) SCA_PythonController::sPyDeActivate, METH_O}, + {"getActuators", (PyCFunction) SCA_PythonController::sPyGetActuators, METH_NOARGS, (PY_METHODCHAR)SCA_PythonController::GetActuators_doc}, {"getActuator", (PyCFunction) SCA_PythonController::sPyGetActuator, METH_O, (PY_METHODCHAR)SCA_PythonController::GetActuator_doc}, {"getSensors", (PyCFunction) SCA_PythonController::sPyGetSensors, METH_NOARGS, (PY_METHODCHAR)SCA_PythonController::GetSensors_doc}, @@ -380,6 +403,29 @@ int SCA_PythonController::_setattr(const char *attr, PyObject *value) return SCA_IController::_setattr(attr, value); } +PyObject* SCA_PythonController::PyActivate(PyObject* self, PyObject *value) +{ + SCA_IActuator* actu = LinkedActuatorFromPy(value); + if(actu==NULL) + return NULL; + + CValue* boolval = new CBoolValue(true); + m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu, boolval); + boolval->Release(); + Py_RETURN_NONE; +} + +PyObject* SCA_PythonController::PyDeActivate(PyObject* self, PyObject *value) +{ + SCA_IActuator* actu = LinkedActuatorFromPy(value); + if(actu==NULL) + return NULL; + + CValue* boolval = new CBoolValue(false); + m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu, boolval); + boolval->Release(); + Py_RETURN_NONE; +} PyObject* SCA_PythonController::PyGetActuators(PyObject* self) { @@ -437,8 +483,7 @@ SCA_PythonController::PyGetActuator(PyObject* self, PyObject* value) for (unsigned int index=0;indexGetName(); - if (realname == scriptArg) + if (actua->GetName() == scriptArg) { return actua->AddRef(); } diff --git a/source/gameengine/GameLogic/SCA_PythonController.h b/source/gameengine/GameLogic/SCA_PythonController.h index 046ef1f7aed..4ec18f32c23 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.h +++ b/source/gameengine/GameLogic/SCA_PythonController.h @@ -77,9 +77,13 @@ class SCA_PythonController : public SCA_IController static const char* sPyAddActiveActuator__doc__; static PyObject* sPyAddActiveActuator(PyObject* self, PyObject* args); + static SCA_IActuator* LinkedActuatorFromPy(PyObject *value); virtual PyObject* _getattr(const char *attr); virtual int _setattr(const char *attr, PyObject *value); + + KX_PYMETHOD_O(SCA_PythonController,Activate); + KX_PYMETHOD_O(SCA_PythonController,DeActivate); KX_PYMETHOD_DOC_NOARGS(SCA_PythonController,GetSensors); KX_PYMETHOD_DOC_NOARGS(SCA_PythonController,GetActuators); KX_PYMETHOD_DOC_O(SCA_PythonController,GetSensor); diff --git a/source/gameengine/PyDoc/GameLogic.py b/source/gameengine/PyDoc/GameLogic.py index 9dab7db6081..f743acf06fe 100644 --- a/source/gameengine/PyDoc/GameLogic.py +++ b/source/gameengine/PyDoc/GameLogic.py @@ -159,7 +159,7 @@ def addActiveActuator(actuator, activate): """ Activates the given actuator. - @type actuator: L{SCA_IActuator} + @type actuator: L{SCA_IActuator} or the actuator name as a string. @type activate: boolean @param activate: whether to activate or deactivate the given actuator. """ diff --git a/source/gameengine/PyDoc/KX_Scene.py b/source/gameengine/PyDoc/KX_Scene.py index 4a0a7a9556d..24b81bbf55e 100644 --- a/source/gameengine/PyDoc/KX_Scene.py +++ b/source/gameengine/PyDoc/KX_Scene.py @@ -39,6 +39,8 @@ class KX_Scene: @ivar name: The scene's name @type name: string + @type objects: A list of objects in the scene. + @type objects: list [L{KX_GameObject}] @ivar active_camera: The current active camera @type active_camera: L{KX_Camera} @ivar suspended: True if the scene is suspended. diff --git a/source/gameengine/PyDoc/SCA_PythonController.py b/source/gameengine/PyDoc/SCA_PythonController.py index 06f2b7e9d1d..9684b41d481 100644 --- a/source/gameengine/PyDoc/SCA_PythonController.py +++ b/source/gameengine/PyDoc/SCA_PythonController.py @@ -15,7 +15,17 @@ class SCA_PythonController(SCA_IController): This can be used with the GameObject's state to test if the controller is active. @type state: integer """ - + def activate(actuator): + """ + Activates an actuator attached to this controller. + @type actuator: actuator or the actuator name as a string + """ + def deactivate(actuator): + """ + Deactivates an actuator attached to this controller. + @type actuator: actuator or the actuator name as a string + """ + def getSensors(): """ Gets a list of all sensors attached to this controller. -- cgit v1.2.3 From 33aee345ed5b1e77b07f693fbea525dec7f728e7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 24 Feb 2009 09:49:28 +0000 Subject: fix for segfault when the replace mesh actuator references a mesh that has no object in the current scene. --- source/gameengine/Ketsji/KX_Scene.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 7fcbf5b54bb..5ae1abc6a89 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1014,6 +1014,12 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj) blendmesh->dvert!=NULL; // mesh has vertex group bool releaseParent = true; + + if (oldblendobj==NULL) { + std::cout << "warning: ReplaceMesh() new mesh is not used in an object from the current scene, you will get incorrect behavior" << std::endl; + bHasShapeKey= bHasDvert= bHasArmature= false; + } + if (bHasShapeKey) { BL_ShapeDeformer* shapeDeformer; -- cgit v1.2.3 From adaa4b0fd0c7dde64b9610b68188052d4d8a628c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 24 Feb 2009 12:38:56 +0000 Subject: Making KX_GameObject names read only. This was committed in revision 2832 but never accounted for existing object name hashes which existed since revision 2. Its possible to update the names elsewhere but unlikely anyone ever used this successfully so removing. --- source/gameengine/Ketsji/KX_GameObject.cpp | 6 ++++++ source/gameengine/PyDoc/KX_GameObject.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 82b5fff534c..37f16b92a26 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1279,8 +1279,14 @@ int KX_GameObject::_setattr(const char *attr, PyObject *value) // _setattr metho { if (!strcmp(attr, "name")) { +#if 0 // was added in revision 2832, but never took into account Object name mappings from revision 2 + // unlikely anyone ever used this successfully , removing. m_name = PyString_AsString(value); return 0; +#else + PyErr_SetString(PyExc_AttributeError, "object name readonly"); + return 1; +#endif } } diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index efeffab2eed..4f389a1ae4f 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -7,7 +7,7 @@ class KX_GameObject: Properties assigned to game objects are accessible as attributes of this class. - @ivar name: The object's name. + @ivar name: The object's name. (Read only) @type name: string. @ivar mass: The object's mass (provided the object has a physics controller). Read only. @type mass: float -- cgit v1.2.3 From 56e9c87309e155d6710067759c415279848b6bea Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 24 Feb 2009 17:34:41 +0000 Subject: building the game engine without SDL works again --- source/gameengine/Ketsji/SConscript | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript index e9e68f14df8..40cbc35e7f3 100644 --- a/source/gameengine/Ketsji/SConscript +++ b/source/gameengine/Ketsji/SConscript @@ -4,6 +4,7 @@ import sys Import ('env') sources = env.Glob('*.cpp') +defs = '' # Mathutils C files. sources.extend([\ @@ -41,10 +42,12 @@ incs += ' ' + env['BF_OPENGL_INC'] if env['WITH_BF_SDL']: incs += ' ' + env['BF_SDL_INC'] - +else: + defs += ' DISABLE_SDL' + cxxflags = [] if env['OURPLATFORM']=='win32-vc': cxxflags.append ('/GR') cxxflags.append ('/O2') -env.BlenderLib ( 'bf_ketsji', sources, Split(incs), [], libtype=['game','player'], priority=[25, 72], cxx_compileflags = cxxflags ) +env.BlenderLib ( 'bf_ketsji', sources, Split(incs), Split(defs), libtype=['game','player'], priority=[25, 72], cxx_compileflags = cxxflags ) -- cgit v1.2.3 From 2eb85c01f3e0ea2ba9dd129ae70e8b370953d7b5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 Feb 2009 03:26:02 +0000 Subject: remove warnings for the BGE - variables that shadow vers declared earlier - Py_Fatal print an error to the stderr - gcc was complaining about the order of initialized vars (for classes) - const return values for ints and bools didnt do anything. - braces for ambiguous if statements --- .../BlenderRoutines/BL_KetsjiEmbedStart.cpp | 2 + .../Converter/BL_BlenderDataConversion.cpp | 32 +++++++------- source/gameengine/Converter/KX_IpoConvert.cpp | 50 +++++++++++----------- source/gameengine/Expressions/InputParser.cpp | 2 +- source/gameengine/Expressions/PyObjectPlus.cpp | 2 +- source/gameengine/Expressions/PyObjectPlus.h | 2 +- .../gameengine/GameLogic/Joystick/SCA_Joystick.cpp | 8 ++-- source/gameengine/GameLogic/SCA_DelaySensor.cpp | 6 +-- source/gameengine/GameLogic/SCA_IActuator.cpp | 4 +- source/gameengine/GameLogic/SCA_IActuator.h | 2 +- source/gameengine/GameLogic/SCA_IController.cpp | 4 +- source/gameengine/GameLogic/SCA_IObject.cpp | 2 +- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 4 +- source/gameengine/Ketsji/BL_Shader.cpp | 4 +- source/gameengine/Ketsji/BL_Shader.h | 2 +- .../Ketsji/KX_BulletPhysicsController.cpp | 6 +-- source/gameengine/Ketsji/KX_ConstraintActuator.cpp | 4 +- source/gameengine/Ketsji/KX_GameActuator.cpp | 2 +- source/gameengine/Ketsji/KX_GameObject.cpp | 15 +++---- source/gameengine/Ketsji/KX_IPO_SGController.cpp | 2 +- source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 2 +- source/gameengine/Ketsji/KX_NearSensor.cpp | 2 +- source/gameengine/Ketsji/KX_ObjectActuator.cpp | 6 +-- source/gameengine/Ketsji/KX_PolyProxy.cpp | 4 +- source/gameengine/Ketsji/KX_PythonInit.cpp | 8 ++-- source/gameengine/Ketsji/KX_SoundActuator.cpp | 2 +- .../Physics/Bullet/CcdPhysicsEnvironment.cpp | 8 ++-- .../gameengine/Rasterizer/RAS_IPolygonMaterial.cpp | 2 +- .../gameengine/Rasterizer/RAS_IPolygonMaterial.h | 2 +- source/gameengine/Rasterizer/RAS_TexVert.h | 2 +- source/gameengine/VideoTexture/FilterBase.cpp | 2 +- source/gameengine/VideoTexture/FilterSource.h | 8 +++- 32 files changed, 104 insertions(+), 99 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 67bec97ea32..d89d2d80ab4 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -563,10 +563,12 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, // get some preferences SYS_SystemHandle syshandle = SYS_GetSystem(); + /* bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0); bool usefixed = (SYS_GetCommandLineInt(syshandle, "fixedtime", 0) != 0); bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0); bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0); + */ bool game2ipo = true;//(SYS_GetCommandLineInt(syshandle, "game2ipo", 0) != 0); bool displaylists = (SYS_GetCommandLineInt(syshandle, "displaylists", 0) != 0); bool usemat = false; diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 2fa3e192179..3293d37af3a 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -1997,18 +1997,18 @@ void BL_ConvertBlenderObjects(struct Main* maggie, MT_Vector3 x(ori.getColumn(0)); MT_Vector3 y(ori.getColumn(1)); MT_Vector3 z(ori.getColumn(2)); - MT_Vector3 scale(x.length(), y.length(), z.length()); - if (!MT_fuzzyZero(scale[0])) - x /= scale[0]; - if (!MT_fuzzyZero(scale[1])) - y /= scale[1]; - if (!MT_fuzzyZero(scale[2])) - z /= scale[2]; + MT_Vector3 parscale(x.length(), y.length(), z.length()); + if (!MT_fuzzyZero(parscale[0])) + x /= parscale[0]; + if (!MT_fuzzyZero(parscale[1])) + y /= parscale[1]; + if (!MT_fuzzyZero(parscale[2])) + z /= parscale[2]; ori.setColumn(0, x); ori.setColumn(1, y); ori.setColumn(2, z); parentinversenode->SetLocalOrientation(ori); - parentinversenode->SetLocalScale(scale); + parentinversenode->SetLocalScale(parscale); parentinversenode->AddChild(gameobj->GetSGNode()); } @@ -2194,18 +2194,18 @@ void BL_ConvertBlenderObjects(struct Main* maggie, MT_Vector3 x(ori.getColumn(0)); MT_Vector3 y(ori.getColumn(1)); MT_Vector3 z(ori.getColumn(2)); - MT_Vector3 scale(x.length(), y.length(), z.length()); - if (!MT_fuzzyZero(scale[0])) - x /= scale[0]; - if (!MT_fuzzyZero(scale[1])) - y /= scale[1]; - if (!MT_fuzzyZero(scale[2])) - z /= scale[2]; + MT_Vector3 localscale(x.length(), y.length(), z.length()); + if (!MT_fuzzyZero(localscale[0])) + x /= localscale[0]; + if (!MT_fuzzyZero(localscale[1])) + y /= localscale[1]; + if (!MT_fuzzyZero(localscale[2])) + z /= localscale[2]; ori.setColumn(0, x); ori.setColumn(1, y); ori.setColumn(2, z); parentinversenode->SetLocalOrientation(ori); - parentinversenode->SetLocalScale(scale); + parentinversenode->SetLocalScale(localscale); parentinversenode->AddChild(gameobj->GetSGNode()); } diff --git a/source/gameengine/Converter/KX_IpoConvert.cpp b/source/gameengine/Converter/KX_IpoConvert.cpp index ce004fa0504..f19390db8a9 100644 --- a/source/gameengine/Converter/KX_IpoConvert.cpp +++ b/source/gameengine/Converter/KX_IpoConvert.cpp @@ -311,67 +311,67 @@ void BL_ConvertIpos(struct Object* blenderobject,KX_GameObject* gameobj,KX_Blend } { - KX_ObColorIpoSGController* ipocontr=NULL; + KX_ObColorIpoSGController* ipocontr_obcol=NULL; ipo = ipoList->GetScalarInterpolator(OB_COL_R); if (ipo) { - if (!ipocontr) + if (!ipocontr_obcol) { - ipocontr = new KX_ObColorIpoSGController(); - gameobj->GetSGNode()->AddSGController(ipocontr); - ipocontr->SetObject(gameobj->GetSGNode()); + ipocontr_obcol = new KX_ObColorIpoSGController(); + gameobj->GetSGNode()->AddSGController(ipocontr_obcol); + ipocontr_obcol->SetObject(gameobj->GetSGNode()); } KX_IInterpolator *interpolator = new KX_ScalarInterpolator( - &ipocontr->m_rgba[0], + &ipocontr_obcol->m_rgba[0], ipo); - ipocontr->AddInterpolator(interpolator); + ipocontr_obcol->AddInterpolator(interpolator); } ipo = ipoList->GetScalarInterpolator(OB_COL_G); if (ipo) { - if (!ipocontr) + if (!ipocontr_obcol) { - ipocontr = new KX_ObColorIpoSGController(); - gameobj->GetSGNode()->AddSGController(ipocontr); - ipocontr->SetObject(gameobj->GetSGNode()); + ipocontr_obcol = new KX_ObColorIpoSGController(); + gameobj->GetSGNode()->AddSGController(ipocontr_obcol); + ipocontr_obcol->SetObject(gameobj->GetSGNode()); } KX_IInterpolator *interpolator = new KX_ScalarInterpolator( - &ipocontr->m_rgba[1], + &ipocontr_obcol->m_rgba[1], ipo); - ipocontr->AddInterpolator(interpolator); + ipocontr_obcol->AddInterpolator(interpolator); } ipo = ipoList->GetScalarInterpolator(OB_COL_B); if (ipo) { - if (!ipocontr) + if (!ipocontr_obcol) { - ipocontr = new KX_ObColorIpoSGController(); - gameobj->GetSGNode()->AddSGController(ipocontr); - ipocontr->SetObject(gameobj->GetSGNode()); + ipocontr_obcol = new KX_ObColorIpoSGController(); + gameobj->GetSGNode()->AddSGController(ipocontr_obcol); + ipocontr_obcol->SetObject(gameobj->GetSGNode()); } KX_IInterpolator *interpolator = new KX_ScalarInterpolator( - &ipocontr->m_rgba[2], + &ipocontr_obcol->m_rgba[2], ipo); - ipocontr->AddInterpolator(interpolator); + ipocontr_obcol->AddInterpolator(interpolator); } ipo = ipoList->GetScalarInterpolator(OB_COL_A); if (ipo) { - if (!ipocontr) + if (!ipocontr_obcol) { - ipocontr = new KX_ObColorIpoSGController(); - gameobj->GetSGNode()->AddSGController(ipocontr); - ipocontr->SetObject(gameobj->GetSGNode()); + ipocontr_obcol = new KX_ObColorIpoSGController(); + gameobj->GetSGNode()->AddSGController(ipocontr_obcol); + ipocontr_obcol->SetObject(gameobj->GetSGNode()); } KX_IInterpolator *interpolator = new KX_ScalarInterpolator( - &ipocontr->m_rgba[3], + &ipocontr_obcol->m_rgba[3], ipo); - ipocontr->AddInterpolator(interpolator); + ipocontr_obcol->AddInterpolator(interpolator); } } diff --git a/source/gameengine/Expressions/InputParser.cpp b/source/gameengine/Expressions/InputParser.cpp index a60e1ee59dc..e016fb8d007 100644 --- a/source/gameengine/Expressions/InputParser.cpp +++ b/source/gameengine/Expressions/InputParser.cpp @@ -274,7 +274,7 @@ void CParser::NextSym() } else if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z'))) { // reserved word? - int start; + start = chcount; CharRep(); GrabString(start); diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 2c4fbd5a867..e04b42ee9cc 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -147,7 +147,7 @@ PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *sel if (attrdef->m_length > 1) { PyObject* resultlist = PyList_New(attrdef->m_length); - for (int i=0; im_length; i++) + for (unsigned int i=0; im_length; i++) { switch (attrdef->m_type) { case KX_PYATTRIBUTE_TYPE_BOOL: diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 0fae175e3cf..37eae3a8c61 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -73,7 +73,7 @@ typedef int Py_ssize_t; #endif static inline void Py_Fatal(const char *M) { - //cout << M << endl; + fprintf(stderr, "%s\n", M); exit(-1); }; diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp index e8e29fb2769..c21e5db1410 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp +++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp @@ -42,14 +42,14 @@ SCA_Joystick::SCA_Joystick(short int index) m_axis21(0), m_prec(3200), m_buttonnum(-2), + m_axismax(-1), m_hatdir(-2), + m_buttonmax(-1), + m_hatmax(-1), m_isinit(0), m_istrig_axis(0), m_istrig_button(0), - m_istrig_hat(0), - m_axismax(-1), - m_buttonmax(-1), - m_hatmax(-1) + m_istrig_hat(0) { #ifndef DISABLE_SDL m_private = new PrivateData(); diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp index 25c9888cadd..31a620b939d 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp +++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp @@ -53,10 +53,10 @@ SCA_DelaySensor::SCA_DelaySensor(class SCA_EventManager* eventmgr, int duration, bool repeat, PyTypeObject* T) - : SCA_ISensor(gameobj,eventmgr, T), + : SCA_ISensor(gameobj,eventmgr, T), + m_repeat(repeat), m_delay(delay), - m_duration(duration), - m_repeat(repeat) + m_duration(duration) { Init(); } diff --git a/source/gameengine/GameLogic/SCA_IActuator.cpp b/source/gameengine/GameLogic/SCA_IActuator.cpp index eeca2d7b44c..309f3108418 100644 --- a/source/gameengine/GameLogic/SCA_IActuator.cpp +++ b/source/gameengine/GameLogic/SCA_IActuator.cpp @@ -36,8 +36,8 @@ using namespace std; SCA_IActuator::SCA_IActuator(SCA_IObject* gameobj, PyTypeObject* T) : - m_links(0), - SCA_ILogicBrick(gameobj,T) + SCA_ILogicBrick(gameobj,T), + m_links(0) { // nothing to do } diff --git a/source/gameengine/GameLogic/SCA_IActuator.h b/source/gameengine/GameLogic/SCA_IActuator.h index 7ffb21b5490..51bd6454d92 100644 --- a/source/gameengine/GameLogic/SCA_IActuator.h +++ b/source/gameengine/GameLogic/SCA_IActuator.h @@ -36,9 +36,9 @@ class SCA_IActuator : public SCA_ILogicBrick { friend class SCA_LogicManager; protected: - std::vector m_events; int m_links; // number of active links to controllers // when 0, the actuator is automatically stopped + std::vector m_events; void RemoveAllEvents(); public: diff --git a/source/gameengine/GameLogic/SCA_IController.cpp b/source/gameengine/GameLogic/SCA_IController.cpp index 0bd20117f31..f9c192cae5c 100644 --- a/source/gameengine/GameLogic/SCA_IController.cpp +++ b/source/gameengine/GameLogic/SCA_IController.cpp @@ -38,8 +38,8 @@ SCA_IController::SCA_IController(SCA_IObject* gameobj, PyTypeObject* T) : - m_statemask(0), - SCA_ILogicBrick(gameobj,T) + SCA_ILogicBrick(gameobj,T), + m_statemask(0) { } diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp index 3afc48b719c..e5ca26eac85 100644 --- a/source/gameengine/GameLogic/SCA_IObject.cpp +++ b/source/gameengine/GameLogic/SCA_IObject.cpp @@ -40,7 +40,7 @@ MT_Point3 SCA_IObject::m_sDummy=MT_Point3(0,0,0); -SCA_IObject::SCA_IObject(PyTypeObject* T): m_initState(0), m_state(0), CValue(T) +SCA_IObject::SCA_IObject(PyTypeObject* T): CValue(T), m_initState(0), m_state(0) { m_suspended = false; } diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index 4f4d62f13b9..36e4a5f2c30 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -158,8 +158,8 @@ bool SCA_MouseSensor::Evaluate(CValue* event) case KX_MOUSESENSORMODE_WHEELUP: case KX_MOUSESENSORMODE_WHEELDOWN: { - const SCA_InputEvent& event = mousedev->GetEventValue(m_hotkey); - switch (event.m_status){ + const SCA_InputEvent& mevent = mousedev->GetEventValue(m_hotkey); + switch (mevent.m_status){ case SCA_InputEvent::KX_JUSTACTIVATED: m_val = 1; result = true; diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index 2a4a74d5b90..e8281201d24 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -18,7 +18,7 @@ #define spit(x) std::cout << x << std::endl; #define SORT_UNIFORMS 1 -#define UNIFORM_MAX_LEN sizeof(float)*16 +#define UNIFORM_MAX_LEN (int)sizeof(float)*16 #define MAX_LOG_LEN 262144 // bounds BL_Uniform::BL_Uniform(int data_size) @@ -108,7 +108,7 @@ void BL_Uniform::SetData(int location, int type,bool transpose) #endif } -const bool BL_Shader::Ok()const +bool BL_Shader::Ok()const { return (mShader !=0 && mOk && mUse); } diff --git a/source/gameengine/Ketsji/BL_Shader.h b/source/gameengine/Ketsji/BL_Shader.h index 52cbd0cda51..76acd5513ef 100644 --- a/source/gameengine/Ketsji/BL_Shader.h +++ b/source/gameengine/Ketsji/BL_Shader.h @@ -166,7 +166,7 @@ public: //const BL_Sampler* GetSampler(int i); void SetSampler(int loc, int unit); - const bool Ok()const; + bool Ok()const; unsigned int GetProg(); void SetProg(bool enable); int GetAttribute(){return mAttr;}; diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp index 534c48661b7..062e9f7df50 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp @@ -384,10 +384,10 @@ SG_Controller* KX_BulletPhysicsController::GetReplica(class SG_Node* destnode) childit!= destnode->GetSGChildren().end(); ++childit ) { - KX_GameObject *clientgameobj = static_cast( (*childit)->GetSGClientObject()); - if (clientgameobj) + KX_GameObject *clientgameobj_child = static_cast( (*childit)->GetSGClientObject()); + if (clientgameobj_child) { - parentKxCtrl = (KX_BulletPhysicsController*)clientgameobj->GetPhysicsController(); + parentKxCtrl = (KX_BulletPhysicsController*)clientgameobj_child->GetPhysicsController(); parentctrl = parentKxCtrl; ccdParent = parentKxCtrl; } diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index c0d802a9cf9..8a7ff41dfa6 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -56,9 +56,9 @@ KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj, int option, char *property, PyTypeObject* T) : + SCA_IActuator(gameobj, T), m_refDirection(refDir), - m_currentTime(0), - SCA_IActuator(gameobj, T) + m_currentTime(0) { m_posDampTime = posDampTime; m_rotDampTime = rotDampTime; diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp index 2387dcdef3a..3090c668f03 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.cpp +++ b/source/gameengine/Ketsji/KX_GameActuator.cpp @@ -132,7 +132,7 @@ bool KX_GameActuator::Update() { char mashal_path[512]; char *marshal_buffer = NULL; - int marshal_length; + unsigned int marshal_length; FILE *fp = NULL; pathGamePythonConfig(mashal_path); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 37f16b92a26..60512991cf4 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1462,11 +1462,9 @@ PyObject* KX_GameObject::PySetState(PyObject* self, PyObject* value) PyObject* KX_GameObject::PyGetVelocity(PyObject* self, PyObject* args) { // only can get the velocity if we have a physics object connected to us... - MT_Vector3 velocity(0.0,0.0,0.0); MT_Point3 point(0.0,0.0,0.0); - - PyObject* pypos = NULL; + if (PyArg_ParseTuple(args, "|O:getVelocity", &pypos)) { if (pypos) @@ -1478,10 +1476,11 @@ PyObject* KX_GameObject::PyGetVelocity(PyObject* self, PyObject* args) if (m_pPhysicsController1) { - velocity = m_pPhysicsController1->GetVelocity(point); + return PyObjectFrom(m_pPhysicsController1->GetVelocity(point)); + } + else { + return PyObjectFrom(MT_Vector3(0.0,0.0,0.0)); } - - return PyObjectFrom(velocity); } @@ -2045,8 +2044,8 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, if (callback.m_hitMesh) { // if this field is set, then we can trust that m_hitPolygon is a valid polygon - RAS_Polygon* poly = callback.m_hitMesh->GetPolygon(callback.m_hitPolygon); - KX_PolyProxy* polyproxy = new KX_PolyProxy(callback.m_hitMesh, poly); + RAS_Polygon* polygon = callback.m_hitMesh->GetPolygon(callback.m_hitPolygon); + KX_PolyProxy* polyproxy = new KX_PolyProxy(callback.m_hitMesh, polygon); PyTuple_SET_ITEM(returnValue, 3, polyproxy); } else diff --git a/source/gameengine/Ketsji/KX_IPO_SGController.cpp b/source/gameengine/Ketsji/KX_IPO_SGController.cpp index 67d54cf0b0b..55a7e2ade60 100644 --- a/source/gameengine/Ketsji/KX_IPO_SGController.cpp +++ b/source/gameengine/Ketsji/KX_IPO_SGController.cpp @@ -58,8 +58,8 @@ KX_IpoSGController::KX_IpoSGController() m_ipo_add(false), m_ipo_local(false), m_modified(true), - m_ipo_start_initialized(false), m_ipotime(1.0), + m_ipo_start_initialized(false), m_ipo_start_euler(0.0,0.0,0.0), m_ipo_euler_initialized(false) { diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 1271474802c..074b3195121 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -713,7 +713,7 @@ void KX_KetsjiEngine::Render() if (!BeginFrame()) return; - KX_SceneList::iterator sceneit; + for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++) // for each scene, call the proceed functions { diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index 7ef544618f8..fb38f16c169 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -240,7 +240,7 @@ bool KX_NearSensor::BroadPhaseFilterCollision(void*obj1,void*obj2) bool KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData * coll_data) { // KX_TouchEventManager* toucheventmgr = static_cast(m_eventmgr); - KX_GameObject* parent = static_cast(GetParent()); +// KX_GameObject* parent = static_cast(GetParent()); // need the mapping from PHY_IPhysicsController to gameobjects now diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index 9a620998538..b647c72fc10 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -65,12 +65,12 @@ KX_ObjectActuator( m_current_linear_factor(0.0), m_current_angular_factor(0.0), m_damping(damping), + m_previous_error(0.0,0.0,0.0), + m_error_accumulator(0.0,0.0,0.0), m_bitLocalFlag (flag), m_active_combined_velocity (false), m_linear_damping_active(false), - m_angular_damping_active(false), - m_error_accumulator(0.0,0.0,0.0), - m_previous_error(0.0,0.0,0.0) + m_angular_damping_active(false) { if (m_bitLocalFlag.ServoControl) { diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp index 1c9e2a49c11..ff962d57c9d 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.cpp +++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp @@ -146,8 +146,8 @@ PyObject* KX_PolyProxy::_getattr(const char *attr) } KX_PolyProxy::KX_PolyProxy(const RAS_MeshObject*mesh, RAS_Polygon* polygon) -: m_mesh((RAS_MeshObject*)mesh), - m_polygon(polygon) +: m_polygon(polygon), + m_mesh((RAS_MeshObject*)mesh) { } diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index c3ae3d0ec52..b3e8d15189f 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -196,7 +196,7 @@ static PyObject* gPyGetSpectrum(PyObject*) } - +#if 0 // unused static PyObject* gPyStartDSP(PyObject*, PyObject* args) { SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance(); @@ -213,7 +213,7 @@ static PyObject* gPyStartDSP(PyObject*, PyObject* args) Py_RETURN_NONE; } - +#endif static PyObject* gPyStopDSP(PyObject*, PyObject* args) @@ -257,7 +257,7 @@ static PyObject* gPySetPhysicsTicRate(PyObject*, PyObject* args) PHY_GetActiveEnvironment()->setFixedTimeStep(true,ticrate); Py_RETURN_NONE; } - +#if 0 // unused static PyObject* gPySetPhysicsDebug(PyObject*, PyObject* args) { int debugMode; @@ -267,7 +267,7 @@ static PyObject* gPySetPhysicsDebug(PyObject*, PyObject* args) PHY_GetActiveEnvironment()->setDebugMode(debugMode); Py_RETURN_NONE; } - +#endif static PyObject* gPyGetPhysicsTicRate(PyObject*) diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index 37604518486..562c096d440 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -444,7 +444,7 @@ PyObject* KX_SoundActuator::PySetLooping(PyObject* self, PyObject* args, PyObjec PyObject* KX_SoundActuator::PyGetLooping(PyObject* self, PyObject* args, PyObject* kwds) { - int looping = (m_soundObject) ? m_soundObject->GetLoopMode() : SND_LOOP_OFF; + int looping = (m_soundObject) ? m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF; PyObject* result = PyInt_FromLong(looping); return result; diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index d2274c1e8d6..eb01385bc01 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -317,8 +317,8 @@ static void DrawAabb(btIDebugDraw* debugDrawer,const btVector3& from,const btVec CcdPhysicsEnvironment::CcdPhysicsEnvironment(btDispatcher* dispatcher,btOverlappingPairCache* pairCache) -:m_scalingPropagated(false), -m_numIterations(10), +:m_numIterations(10), +m_scalingPropagated(false), m_numTimeSubSteps(1), m_ccdMode(0), m_solverType(-1), @@ -326,8 +326,8 @@ m_profileTimings(0), m_enableSatCollisionDetection(false), m_solver(NULL), m_ownPairCache(NULL), -m_ownDispatcher(NULL), -m_filterCallback(NULL) +m_filterCallback(NULL), +m_ownDispatcher(NULL) { for (int i=0;im_previous != NULL; frst = frst->m_previous->m_filter); + for (frst = this; frst->m_previous != NULL; frst = frst->m_previous->m_filter) {}; // set first filter return frst; } diff --git a/source/gameengine/VideoTexture/FilterSource.h b/source/gameengine/VideoTexture/FilterSource.h index 7e90747d252..6385ed5108f 100644 --- a/source/gameengine/VideoTexture/FilterSource.h +++ b/source/gameengine/VideoTexture/FilterSource.h @@ -189,9 +189,10 @@ protected: int d = m_buffU[offset] - 128; int e = m_buffV[offset] - 128; // if horizontal interpolation is needed - if ((x & 1) == 1) + if ((x & 1) == 1) { // if vertical interpolation is needed too if ((y & 1) == 1) + { // if this pixel is on the edge if (isEdge(x, y, size)) { @@ -206,7 +207,8 @@ protected: e = interpolVH(m_buffV + offset) - 128; } // otherwise use horizontal interpolation only - else + } + else { // if this pixel is on the edge if (isEdge(x, y, size)) { @@ -221,6 +223,8 @@ protected: e = interpolH(m_buffV + offset) - 128; } // otherwise if only vertical interpolation is needed + } + } else if ((y & 1) == 1) // if this pixel is on the edge if (isEdge(x, y, size)) -- cgit v1.2.3 From c77af311665d230ed933138cd20962d021ad5c2b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 Feb 2009 06:43:03 +0000 Subject: Minor speedups for the BGE * Where possible use vec.setValue(x,y,z) to assign values to a vector instead of vec= MT_Vector3(x,y,z), for MT_Point and MT_Matrix types too. * Comparing TexVerts was creating 10 MT_Vector types - instead compare as floats. * Added SG_Spatial::SetWorldFromLocalTransform() since the local transform is use for world transform in some cases. * removed some unneeded vars from UpdateChildCoordinates functions * Py API - Mouse, Ray, Radar sensors - use PyObjectFrom(vec) rather then filling the lists in each function. Use METH_NOARGS for get*() functions. --- .../Converter/BL_BlenderDataConversion.cpp | 69 +++++++---------- source/gameengine/Converter/BL_MeshDeformer.cpp | 4 +- source/gameengine/Ketsji/KX_GameObject.cpp | 28 ++++--- source/gameengine/Ketsji/KX_MouseFocusSensor.cpp | 89 +++++----------------- source/gameengine/Ketsji/KX_MouseFocusSensor.h | 12 +-- source/gameengine/Ketsji/KX_RadarSensor.cpp | 35 +++------ source/gameengine/Ketsji/KX_RadarSensor.h | 6 +- source/gameengine/Ketsji/KX_RaySensor.cpp | 64 ++++------------ source/gameengine/Ketsji/KX_RaySensor.h | 8 +- .../Ketsji/KX_SG_BoneParentNodeRelationship.cpp | 19 +++-- .../gameengine/Ketsji/KX_SG_NodeRelationships.cpp | 80 ++++--------------- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 6 +- source/gameengine/Rasterizer/RAS_TexVert.cpp | 26 ++++--- source/gameengine/Rasterizer/RAS_TexVert.h | 1 + source/gameengine/SceneGraph/SG_BBox.cpp | 4 +- source/gameengine/SceneGraph/SG_Spatial.cpp | 19 +++-- source/gameengine/SceneGraph/SG_Spatial.h | 2 + 17 files changed, 159 insertions(+), 313 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 3293d37af3a..3a0302562e6 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -593,7 +593,7 @@ BL_Material* ConvertMaterial( MT_Point2 uv2[4]; const char *uvName = "", *uv2Name = ""; - uv[0]= uv[1]= uv[2]= uv[3]= MT_Point2(0.0f, 0.0f); + uv2[0]= uv2[1]= uv2[2]= uv2[3]= MT_Point2(0.0f, 0.0f); if( validface ) { @@ -607,12 +607,12 @@ BL_Material* ConvertMaterial( material->tile = tface->tile; material->mode = tface->mode; - uv[0] = MT_Point2(tface->uv[0]); - uv[1] = MT_Point2(tface->uv[1]); - uv[2] = MT_Point2(tface->uv[2]); + uv[0].setValue(tface->uv[0]); + uv[1].setValue(tface->uv[1]); + uv[2].setValue(tface->uv[2]); if (mface->v4) - uv[3] = MT_Point2(tface->uv[3]); + uv[3].setValue(tface->uv[3]); uvName = tfaceName; } @@ -622,6 +622,8 @@ BL_Material* ConvertMaterial( material->mode = default_face_mode; material->transp = TF_SOLID; material->tile = 0; + + uv[0]= uv[1]= uv[2]= uv[3]= MT_Point2(0.0f, 0.0f); } // with ztransp enabled, enforce alpha blending mode @@ -665,14 +667,14 @@ BL_Material* ConvertMaterial( { MT_Point2 uvSet[4]; - uvSet[0] = MT_Point2(layer.face->uv[0]); - uvSet[1] = MT_Point2(layer.face->uv[1]); - uvSet[2] = MT_Point2(layer.face->uv[2]); + uvSet[0].setValue(layer.face->uv[0]); + uvSet[1].setValue(layer.face->uv[1]); + uvSet[2].setValue(layer.face->uv[2]); if (mface->v4) - uvSet[3] = MT_Point2(layer.face->uv[3]); + uvSet[3].setValue(layer.face->uv[3]); else - uvSet[3] = MT_Point2(0.0f, 0.0f); + uvSet[3].setValue(0.0f, 0.0f); if (isFirstSet) { @@ -790,10 +792,10 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* MT_Vector4 tan0(0,0,0,0), tan1(0,0,0,0), tan2(0,0,0,0), tan3(0,0,0,0); /* get coordinates, normals and tangents */ - pt0 = MT_Point3(mvert[mface->v1].co); - pt1 = MT_Point3(mvert[mface->v2].co); - pt2 = MT_Point3(mvert[mface->v3].co); - pt3 = (mface->v4)? MT_Point3(mvert[mface->v4].co): MT_Point3(0.0, 0.0, 0.0); + pt0.setValue(mvert[mface->v1].co); + pt1.setValue(mvert[mface->v2].co); + pt2.setValue(mvert[mface->v3].co); + if (mface->v4) pt3.setValue(mvert[mface->v4].co); if(mface->flag & ME_SMOOTH) { float n0[3], n1[3], n2[3], n3[3]; @@ -894,12 +896,12 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* visible = !((mface->flag & ME_HIDE)||(tface->mode & TF_INVISIBLE)); - uv0 = MT_Point2(tface->uv[0]); - uv1 = MT_Point2(tface->uv[1]); - uv2 = MT_Point2(tface->uv[2]); + uv0.setValue(tface->uv[0]); + uv1.setValue(tface->uv[1]); + uv2.setValue(tface->uv[2]); if (mface->v4) - uv3 = MT_Point2(tface->uv[3]); + uv3.setValue(tface->uv[3]); } else { /* no texfaces, set COLLSION true and everything else FALSE */ @@ -960,7 +962,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* polymat->m_diffuse = MT_Vector3(ma->r, ma->g, ma->b)*(ma->emit + ma->ref); } else { - polymat->m_specular = MT_Vector3(0.0f,0.0f,0.0f); + polymat->m_specular.setValue(0.0f,0.0f,0.0f); polymat->m_shininess = 35.0; } } @@ -1911,21 +1913,14 @@ void BL_ConvertBlenderObjects(struct Main* maggie, MT_Matrix3x3 angor; if (converter->addInitFromFrame) blenderscene->r.cfra=blenderscene->r.sfra; - MT_Point3 pos = MT_Point3( + MT_Point3 pos; + pos.setValue( blenderobject->loc[0]+blenderobject->dloc[0], blenderobject->loc[1]+blenderobject->dloc[1], blenderobject->loc[2]+blenderobject->dloc[2] ); - MT_Vector3 eulxyz = MT_Vector3( - blenderobject->rot[0], - blenderobject->rot[1], - blenderobject->rot[2] - ); - MT_Vector3 scale = MT_Vector3( - blenderobject->size[0], - blenderobject->size[1], - blenderobject->size[2] - ); + MT_Vector3 eulxyz(blenderobject->rot); + MT_Vector3 scale(blenderobject->size); if (converter->addInitFromFrame){//rcruiz float eulxyzPrev[3]; blenderscene->r.cfra=blenderscene->r.sfra-1; @@ -2113,21 +2108,13 @@ void BL_ConvertBlenderObjects(struct Main* maggie, if (converter->addInitFromFrame) blenderscene->r.cfra=blenderscene->r.sfra; - MT_Point3 pos = MT_Point3( + MT_Point3 pos( blenderobject->loc[0]+blenderobject->dloc[0], blenderobject->loc[1]+blenderobject->dloc[1], blenderobject->loc[2]+blenderobject->dloc[2] ); - MT_Vector3 eulxyz = MT_Vector3( - blenderobject->rot[0], - blenderobject->rot[1], - blenderobject->rot[2] - ); - MT_Vector3 scale = MT_Vector3( - blenderobject->size[0], - blenderobject->size[1], - blenderobject->size[2] - ); + MT_Vector3 eulxyz(blenderobject->rot); + MT_Vector3 scale(blenderobject->size); if (converter->addInitFromFrame){//rcruiz float eulxyzPrev[3]; blenderscene->r.cfra=blenderscene->r.sfra-1; diff --git a/source/gameengine/Converter/BL_MeshDeformer.cpp b/source/gameengine/Converter/BL_MeshDeformer.cpp index fa3b8185fe2..80112346c72 100644 --- a/source/gameengine/Converter/BL_MeshDeformer.cpp +++ b/source/gameengine/Converter/BL_MeshDeformer.cpp @@ -51,7 +51,6 @@ bool BL_MeshDeformer::Apply(RAS_IPolyMaterial*) { size_t i; - float *co; // only apply once per frame if the mesh is actually modified if(m_pMeshObject->MeshModified() && @@ -70,8 +69,7 @@ bool BL_MeshDeformer::Apply(RAS_IPolyMaterial*) // For each vertex for(i=it.startvertex; imvert[v.getOrigIndex()].co; - v.SetXYZ(MT_Point3(co)); + v.SetXYZ(m_bmesh->mvert[v.getOrigIndex()].co); } } } diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 60512991cf4..5e013a1c647 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -690,9 +690,9 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac) switch (axis) { case 0: //x axis - ori = MT_Vector3(orimat[0][2], orimat[1][2], orimat[2][2]); //pivot axis + ori.setValue(orimat[0][2], orimat[1][2], orimat[2][2]); //pivot axis if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON) //is the vector paralell to the pivot? - ori = MT_Vector3(orimat[0][1], orimat[1][1], orimat[2][1]); //change the pivot! + ori.setValue(orimat[0][1], orimat[1][1], orimat[2][1]); //change the pivot! if (fac == 1.0) { x = vect; } else { @@ -705,9 +705,9 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac) z = x.cross(y); break; case 1: //y axis - ori = MT_Vector3(orimat[0][0], orimat[1][0], orimat[2][0]); + ori.setValue(orimat[0][0], orimat[1][0], orimat[2][0]); if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON) - ori = MT_Vector3(orimat[0][2], orimat[1][2], orimat[2][2]); + ori.setValue(orimat[0][2], orimat[1][2], orimat[2][2]); if (fac == 1.0) { y = vect; } else { @@ -720,9 +720,9 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac) x = y.cross(z); break; case 2: //z axis - ori = MT_Vector3(orimat[0][1], orimat[1][1], orimat[2][1]); + ori.setValue(orimat[0][1], orimat[1][1], orimat[2][1]); if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON) - ori = MT_Vector3(orimat[0][0], orimat[1][0], orimat[2][0]); + ori.setValue(orimat[0][0], orimat[1][0], orimat[2][0]); if (fac == 1.0) { z = vect; } else { @@ -741,9 +741,9 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac) x.normalize(); //normalize the vectors y.normalize(); z.normalize(); - orimat = MT_Matrix3x3( x[0],y[0],z[0], - x[1],y[1],z[1], - x[2],y[2],z[2]); + orimat.setValue( x[0],y[0],z[0], + x[1],y[1],z[1], + x[2],y[2],z[2]); if (GetSGNode()->GetSGParent() != NULL) { // the object is a child, adapt its local orientation so that @@ -945,13 +945,11 @@ const MT_Vector3& KX_GameObject::NodeGetWorldScaling() const const MT_Point3& KX_GameObject::NodeGetWorldPosition() const { - static MT_Point3 defaultPosition = MT_Point3(0.0, 0.0, 0.0); - // check on valid node in case a python controller holds a reference to a deleted object - if (!GetSGNode()) - return defaultPosition; - - return GetSGNode()->GetWorldPosition(); + if (GetSGNode()) + return GetSGNode()->GetWorldPosition(); + else + return MT_Point3(0.0, 0.0, 0.0); } /* Suspend/ resume: for the dynamic behaviour, there is a simple diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index bd15d3cffbe..afe4cd1e2a4 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -42,6 +42,7 @@ #include "KX_Scene.h" #include "KX_Camera.h" #include "KX_MouseFocusSensor.h" +#include "KX_PyMath.h" #include "KX_RayCast.h" #include "KX_IPhysicsController.h" @@ -320,12 +321,12 @@ PyParentObject KX_MouseFocusSensor::Parents[] = { }; PyMethodDef KX_MouseFocusSensor::Methods[] = { - {"getRayTarget", (PyCFunction) KX_MouseFocusSensor::sPyGetRayTarget, METH_VARARGS, (PY_METHODCHAR)GetRayTarget_doc}, - {"getRaySource", (PyCFunction) KX_MouseFocusSensor::sPyGetRaySource, METH_VARARGS, (PY_METHODCHAR)GetRaySource_doc}, - {"getHitObject",(PyCFunction) KX_MouseFocusSensor::sPyGetHitObject,METH_VARARGS, (PY_METHODCHAR)GetHitObject_doc}, - {"getHitPosition",(PyCFunction) KX_MouseFocusSensor::sPyGetHitPosition,METH_VARARGS, (PY_METHODCHAR)GetHitPosition_doc}, - {"getHitNormal",(PyCFunction) KX_MouseFocusSensor::sPyGetHitNormal,METH_VARARGS, (PY_METHODCHAR)GetHitNormal_doc}, - {"getRayDirection",(PyCFunction) KX_MouseFocusSensor::sPyGetRayDirection,METH_VARARGS, (PY_METHODCHAR)GetRayDirection_doc}, + {"getRayTarget", (PyCFunction) KX_MouseFocusSensor::sPyGetRayTarget, METH_NOARGS, (PY_METHODCHAR)GetRayTarget_doc}, + {"getRaySource", (PyCFunction) KX_MouseFocusSensor::sPyGetRaySource, METH_NOARGS, (PY_METHODCHAR)GetRaySource_doc}, + {"getHitObject",(PyCFunction) KX_MouseFocusSensor::sPyGetHitObject,METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc}, + {"getHitPosition",(PyCFunction) KX_MouseFocusSensor::sPyGetHitPosition,METH_NOARGS, (PY_METHODCHAR)GetHitPosition_doc}, + {"getHitNormal",(PyCFunction) KX_MouseFocusSensor::sPyGetHitNormal,METH_NOARGS, (PY_METHODCHAR)GetHitNormal_doc}, + {"getRayDirection",(PyCFunction) KX_MouseFocusSensor::sPyGetRayDirection,METH_NOARGS, (PY_METHODCHAR)GetRayDirection_doc}, {NULL,NULL} //Sentinel @@ -339,14 +340,11 @@ PyObject* KX_MouseFocusSensor::_getattr(const char *attr) { const char KX_MouseFocusSensor::GetHitObject_doc[] = "getHitObject()\n" "\tReturns the name of the object that was hit by this ray.\n"; -PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self) { if (m_hitObject) - { return m_hitObject->AddRef(); - } + Py_RETURN_NONE; } @@ -354,61 +352,28 @@ PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self, const char KX_MouseFocusSensor::GetHitPosition_doc[] = "getHitPosition()\n" "\tReturns the position (in worldcoordinates) where the object was hit by this ray.\n"; -PyObject* KX_MouseFocusSensor::PyGetHitPosition(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_MouseFocusSensor::PyGetHitPosition(PyObject* self) { - - MT_Point3 pos = m_hitPosition; - - PyObject* resultlist = PyList_New(3); - int index; - for (index=0;index<3;index++) - { - PyList_SetItem(resultlist,index,PyFloat_FromDouble(pos[index])); - } - return resultlist; - + return PyObjectFrom(m_hitPosition); } const char KX_MouseFocusSensor::GetRayDirection_doc[] = "getRayDirection()\n" "\tReturns the direction from the ray (in worldcoordinates) .\n"; -PyObject* KX_MouseFocusSensor::PyGetRayDirection(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_MouseFocusSensor::PyGetRayDirection(PyObject* self) { MT_Vector3 dir = m_prevTargetPoint - m_prevSourcePoint; dir.normalize(); - - PyObject* resultlist = PyList_New(3); - int index; - for (index=0;index<3;index++) - { - PyList_SetItem(resultlist,index,PyFloat_FromDouble(dir[index])); - } - return resultlist; - + return PyObjectFrom(dir); } const char KX_MouseFocusSensor::GetHitNormal_doc[] = "getHitNormal()\n" "\tReturns the normal (in worldcoordinates) of the object at the location where the object was hit by this ray.\n"; -PyObject* KX_MouseFocusSensor::PyGetHitNormal(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_MouseFocusSensor::PyGetHitNormal(PyObject* self) { - MT_Vector3 pos = m_hitNormal; - - PyObject* resultlist = PyList_New(3); - int index; - for (index=0;index<3;index++) - { - PyList_SetItem(resultlist,index,PyFloat_FromDouble(pos[index])); - } - return resultlist; - + return PyObjectFrom(m_hitNormal); } @@ -417,16 +382,8 @@ const char KX_MouseFocusSensor::GetRayTarget_doc[] = "getRayTarget()\n" "\tReturns the target of the ray that seeks the focus object,\n" "\tin worldcoordinates."; -PyObject* KX_MouseFocusSensor::PyGetRayTarget(PyObject* self, - PyObject* args, - PyObject* kwds) { - PyObject *retVal = PyList_New(3); - - PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_prevTargetPoint[0])); - PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_prevTargetPoint[1])); - PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_prevTargetPoint[2])); - - return retVal; +PyObject* KX_MouseFocusSensor::PyGetRayTarget(PyObject* self) { + return PyObjectFrom(m_prevTargetPoint); } /* getRayTarget */ @@ -434,16 +391,8 @@ const char KX_MouseFocusSensor::GetRaySource_doc[] = "getRaySource()\n" "\tReturns the source of the ray that seeks the focus object,\n" "\tin worldcoordinates."; -PyObject* KX_MouseFocusSensor::PyGetRaySource(PyObject* self, - PyObject* args, - PyObject* kwds) { - PyObject *retVal = PyList_New(3); - - PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_prevSourcePoint[0])); - PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_prevSourcePoint[1])); - PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_prevSourcePoint[2])); - - return retVal; +PyObject* KX_MouseFocusSensor::PyGetRaySource(PyObject* self) { + return PyObjectFrom(m_prevSourcePoint); } /* eof */ diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.h b/source/gameengine/Ketsji/KX_MouseFocusSensor.h index 704198ce5a3..4979783032c 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.h +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.h @@ -89,13 +89,13 @@ class KX_MouseFocusSensor : public SCA_MouseSensor /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const char *attr); - KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetRayTarget); - KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetRaySource); + KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRayTarget); + KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRaySource); - KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetHitObject); - KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetHitPosition); - KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetHitNormal); - KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetRayDirection); + KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetHitObject); + KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetHitPosition); + KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetHitNormal); + KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRayDirection); /* --------------------------------------------------------------------- */ SCA_IObject* m_hitObject; diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp index 1321b862463..2ba1126a633 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.cpp +++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp @@ -28,6 +28,7 @@ #include "KX_RadarSensor.h" #include "KX_GameObject.h" +#include "KX_PyMath.h" #include "PHY_IPhysicsController.h" #ifdef HAVE_CONFIG_H @@ -221,11 +222,11 @@ PyParentObject KX_RadarSensor::Parents[] = { PyMethodDef KX_RadarSensor::Methods[] = { {"getConeOrigin", (PyCFunction) KX_RadarSensor::sPyGetConeOrigin, - METH_VARARGS, (PY_METHODCHAR)GetConeOrigin_doc}, + METH_NOARGS, (PY_METHODCHAR)GetConeOrigin_doc}, {"getConeTarget", (PyCFunction) KX_RadarSensor::sPyGetConeTarget, - METH_VARARGS, (PY_METHODCHAR)GetConeTarget_doc}, + METH_NOARGS, (PY_METHODCHAR)GetConeTarget_doc}, {"getConeHeight", (PyCFunction) KX_RadarSensor::sPyGetConeHeight, - METH_VARARGS, (PY_METHODCHAR)GetConeHeight_doc}, + METH_NOARGS, (PY_METHODCHAR)GetConeHeight_doc}, {NULL,NULL,NULL,NULL} //Sentinel }; @@ -238,41 +239,23 @@ const char KX_RadarSensor::GetConeOrigin_doc[] = "getConeOrigin()\n" "\tReturns the origin of the cone with which to test. The origin\n" "\tis in the middle of the cone."; -PyObject* KX_RadarSensor::PyGetConeOrigin(PyObject* self, - PyObject* args, - PyObject* kwds) { - PyObject *retVal = PyList_New(3); - - PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_cone_origin[0])); - PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_cone_origin[1])); - PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_cone_origin[2])); - - return retVal; +PyObject* KX_RadarSensor::PyGetConeOrigin(PyObject* self) { + return PyObjectFrom(m_cone_origin); } /* getConeOrigin */ const char KX_RadarSensor::GetConeTarget_doc[] = "getConeTarget()\n" "\tReturns the center of the bottom face of the cone with which to test.\n"; -PyObject* KX_RadarSensor::PyGetConeTarget(PyObject* self, - PyObject* args, - PyObject* kwds) { - PyObject *retVal = PyList_New(3); - - PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_cone_target[0])); - PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_cone_target[1])); - PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_cone_target[2])); - - return retVal; +PyObject* KX_RadarSensor::PyGetConeTarget(PyObject* self) { + return PyObjectFrom(m_cone_target); } /* getConeOrigin */ const char KX_RadarSensor::GetConeHeight_doc[] = "getConeHeight()\n" "\tReturns the height of the cone with which to test.\n"; -PyObject* KX_RadarSensor::PyGetConeHeight(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_RadarSensor::PyGetConeHeight(PyObject* self) { return PyFloat_FromDouble(m_coneheight); } diff --git a/source/gameengine/Ketsji/KX_RadarSensor.h b/source/gameengine/Ketsji/KX_RadarSensor.h index f8f80725145..e4c6d73f22d 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.h +++ b/source/gameengine/Ketsji/KX_RadarSensor.h @@ -83,9 +83,9 @@ public: virtual PyObject* _getattr(const char *attr); - KX_PYMETHOD_DOC(KX_RadarSensor,GetConeOrigin); - KX_PYMETHOD_DOC(KX_RadarSensor,GetConeTarget); - KX_PYMETHOD_DOC(KX_RadarSensor,GetConeHeight); + KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeOrigin); + KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeTarget); + KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeHeight); }; diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index b8ebce28814..c7cb53f64ed 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -38,6 +38,7 @@ #include "KX_GameObject.h" #include "KX_Scene.h" #include "KX_RayCast.h" +#include "KX_PyMath.h" #include "PHY_IPhysicsEnvironment.h" #include "KX_IPhysicsController.h" #include "PHY_IPhysicsController.h" @@ -179,8 +180,8 @@ bool KX_RaySensor::Evaluate(CValue* event) bool reset = m_reset && m_level; m_rayHit = false; m_hitObject = NULL; - m_hitPosition = MT_Vector3(0,0,0); - m_hitNormal = MT_Vector3(1,0,0); + m_hitPosition.setValue(0,0,0); + m_hitNormal.setValue(1,0,0); KX_GameObject* obj = (KX_GameObject*)GetParent(); MT_Point3 frompoint = obj->NodeGetWorldPosition(); @@ -335,19 +336,17 @@ PyParentObject KX_RaySensor::Parents[] = { }; PyMethodDef KX_RaySensor::Methods[] = { - {"getHitObject",(PyCFunction) KX_RaySensor::sPyGetHitObject,METH_VARARGS, (PY_METHODCHAR)GetHitObject_doc}, - {"getHitPosition",(PyCFunction) KX_RaySensor::sPyGetHitPosition,METH_VARARGS, (PY_METHODCHAR)GetHitPosition_doc}, - {"getHitNormal",(PyCFunction) KX_RaySensor::sPyGetHitNormal,METH_VARARGS, (PY_METHODCHAR)GetHitNormal_doc}, - {"getRayDirection",(PyCFunction) KX_RaySensor::sPyGetRayDirection,METH_VARARGS, (PY_METHODCHAR)GetRayDirection_doc}, + {"getHitObject",(PyCFunction) KX_RaySensor::sPyGetHitObject,METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc}, + {"getHitPosition",(PyCFunction) KX_RaySensor::sPyGetHitPosition,METH_NOARGS, (PY_METHODCHAR)GetHitPosition_doc}, + {"getHitNormal",(PyCFunction) KX_RaySensor::sPyGetHitNormal,METH_NOARGS, (PY_METHODCHAR)GetHitNormal_doc}, + {"getRayDirection",(PyCFunction) KX_RaySensor::sPyGetRayDirection,METH_NOARGS, (PY_METHODCHAR)GetRayDirection_doc}, {NULL,NULL} //Sentinel }; const char KX_RaySensor::GetHitObject_doc[] = "getHitObject()\n" "\tReturns the name of the object that was hit by this ray.\n"; -PyObject* KX_RaySensor::PyGetHitObject(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_RaySensor::PyGetHitObject(PyObject* self) { if (m_hitObject) { @@ -360,60 +359,25 @@ PyObject* KX_RaySensor::PyGetHitObject(PyObject* self, const char KX_RaySensor::GetHitPosition_doc[] = "getHitPosition()\n" "\tReturns the position (in worldcoordinates) where the object was hit by this ray.\n"; -PyObject* KX_RaySensor::PyGetHitPosition(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_RaySensor::PyGetHitPosition(PyObject* self) { - - MT_Point3 pos = m_hitPosition; - - PyObject* resultlist = PyList_New(3); - int index; - for (index=0;index<3;index++) - { - PyList_SetItem(resultlist,index,PyFloat_FromDouble(pos[index])); - } - return resultlist; - + return PyObjectFrom(m_hitPosition); } const char KX_RaySensor::GetRayDirection_doc[] = "getRayDirection()\n" "\tReturns the direction from the ray (in worldcoordinates) .\n"; -PyObject* KX_RaySensor::PyGetRayDirection(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_RaySensor::PyGetRayDirection(PyObject* self) { - - MT_Vector3 dir = m_rayDirection; - - PyObject* resultlist = PyList_New(3); - int index; - for (index=0;index<3;index++) - { - PyList_SetItem(resultlist,index,PyFloat_FromDouble(dir[index])); - } - return resultlist; - + return PyObjectFrom(m_rayDirection); } const char KX_RaySensor::GetHitNormal_doc[] = "getHitNormal()\n" "\tReturns the normal (in worldcoordinates) of the object at the location where the object was hit by this ray.\n"; -PyObject* KX_RaySensor::PyGetHitNormal(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_RaySensor::PyGetHitNormal(PyObject* self) { - MT_Vector3 pos = m_hitNormal; - - PyObject* resultlist = PyList_New(3); - int index; - for (index=0;index<3;index++) - { - PyList_SetItem(resultlist,index,PyFloat_FromDouble(pos[index])); - } - return resultlist; - + return PyObjectFrom(m_hitNormal); } diff --git a/source/gameengine/Ketsji/KX_RaySensor.h b/source/gameengine/Ketsji/KX_RaySensor.h index 2baec12f74e..09d8bc1369a 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.h +++ b/source/gameengine/Ketsji/KX_RaySensor.h @@ -74,10 +74,10 @@ public: bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data); bool NeedRayCast(KX_ClientObjectInfo* client); - KX_PYMETHOD_DOC(KX_RaySensor,GetHitObject); - KX_PYMETHOD_DOC(KX_RaySensor,GetHitPosition); - KX_PYMETHOD_DOC(KX_RaySensor,GetHitNormal); - KX_PYMETHOD_DOC(KX_RaySensor,GetRayDirection); + KX_PYMETHOD_DOC_NOARGS(KX_RaySensor,GetHitObject); + KX_PYMETHOD_DOC_NOARGS(KX_RaySensor,GetHitPosition); + KX_PYMETHOD_DOC_NOARGS(KX_RaySensor,GetHitNormal); + KX_PYMETHOD_DOC_NOARGS(KX_RaySensor,GetRayDirection); virtual PyObject* _getattr(const char *attr); diff --git a/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp b/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp index d651373869a..151270cbd68 100644 --- a/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp +++ b/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp @@ -97,11 +97,11 @@ UpdateChildCoordinates( child_transform = parent_matrix * child_transform; // Recompute the child transform components from the transform. - child_w_scale = MT_Vector3( + child_w_scale.setValue( MT_Vector3(child_transform[0][0], child_transform[0][1], child_transform[0][2]).length(), MT_Vector3(child_transform[1][0], child_transform[1][1], child_transform[1][2]).length(), MT_Vector3(child_transform[2][0], child_transform[2][1], child_transform[2][2]).length()); - child_w_rotation = MT_Matrix3x3(child_transform[0][0], child_transform[0][1], child_transform[0][2], + child_w_rotation.setValue(child_transform[0][0], child_transform[0][1], child_transform[0][2], child_transform[1][0], child_transform[1][1], child_transform[1][2], child_transform[2][0], child_transform[2][1], child_transform[2][2]); child_w_rotation.scale(1.0/child_w_scale[0], 1.0/child_w_scale[1], 1.0/child_w_scale[2]); @@ -113,16 +113,15 @@ UpdateChildCoordinates( } } - if (!valid_parent_transform) + if (valid_parent_transform) { - child_w_scale = child_scale; - child_w_pos = child_pos; - child_w_rotation = child_rotation; + child->SetWorldScale(child_w_scale); + child->SetWorldPosition(child_w_pos); + child->SetWorldOrientation(child_w_rotation); + } + else { + child->SetWorldFromLocalTransform(); } - - child->SetWorldScale(child_w_scale); - child->SetWorldPosition(child_w_pos); - child->SetWorldOrientation(child_w_rotation); return valid_parent_transform; } diff --git a/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp b/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp index 0c8e7e28771..0729ec8a902 100644 --- a/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp +++ b/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp @@ -55,43 +55,21 @@ UpdateChildCoordinates( ){ MT_assert(child != NULL); - // This way of accessing child coordinates is a bit cumbersome - // be nice to have non constant reference access to these values. - - const MT_Vector3 & child_scale = child->GetLocalScale(); - const MT_Point3 & child_pos = child->GetLocalPosition(); - const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation(); - - // the childs world locations which we will update. - - MT_Vector3 child_w_scale; - MT_Point3 child_w_pos; - MT_Matrix3x3 child_w_rotation; - - if (parent) { - + if (parent==NULL) { /* Simple case */ + child->SetWorldFromLocalTransform(); + return false; + } + else { + // the childs world locations which we will update. const MT_Vector3 & p_world_scale = parent->GetWorldScaling(); const MT_Point3 & p_world_pos = parent->GetWorldPosition(); const MT_Matrix3x3 & p_world_rotation = parent->GetWorldOrientation(); - child_w_scale = p_world_scale * child_scale; - child_w_rotation = p_world_rotation * child_rotation; - - child_w_pos = p_world_pos + p_world_scale * - (p_world_rotation * child_pos); - - } else { - - child_w_scale = child_scale; - child_w_pos = child_pos; - child_w_rotation = child_rotation; + child->SetWorldScale(p_world_scale * child->GetLocalScale()); + child->SetWorldOrientation(p_world_rotation * child->GetLocalOrientation()); + child->SetWorldPosition(p_world_pos + p_world_scale * (p_world_rotation * child->GetLocalPosition())); + return true; } - - child->SetWorldScale(child_w_scale); - child->SetWorldPosition(child_w_pos); - child->SetWorldOrientation(child_w_rotation); - - return parent != NULL; } SG_ParentRelation * @@ -138,40 +116,14 @@ UpdateChildCoordinates( ){ MT_assert(child != NULL); - - const MT_Vector3 & child_scale = child->GetLocalScale(); - const MT_Point3 & child_pos = child->GetLocalPosition(); - const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation(); - - // the childs world locations which we will update. + child->SetWorldScale(child->GetLocalScale()); - MT_Vector3 child_w_scale; - MT_Point3 child_w_pos; - MT_Matrix3x3 child_w_rotation; - - if (parent) { - - // This is a vertex parent so we do not inherit orientation - // information. - - // const MT_Vector3 & p_world_scale = parent->GetWorldScaling(); /*unused*/ - const MT_Point3 & p_world_pos = parent->GetWorldPosition(); - // const MT_Matrix3x3 & p_world_rotation = parent->GetWorldOrientation(); /*unused*/ - - child_w_scale = child_scale; - child_w_rotation = child_rotation; - child_w_pos = p_world_pos + child_pos; - } else { - - child_w_scale = child_scale; - child_w_pos = child_pos; - child_w_rotation = child_rotation; - } - - child->SetWorldScale(child_w_scale); - child->SetWorldPosition(child_w_pos); - child->SetWorldOrientation(child_w_rotation); + if (parent) + child->SetWorldPosition(child->GetLocalPosition()+parent->GetWorldPosition()); + else + child->SetWorldPosition(child->GetLocalPosition()); + child->SetWorldOrientation(child->GetLocalOrientation()); return parent != NULL; } diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 89dfc8e57ad..9d4fa14ad8e 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -258,18 +258,18 @@ bool KX_TrackToActuator::Update(double curtime, bool frame) { case 0: { - up = MT_Vector3(1.0,0,0); + up.setValue(1.0,0,0); break; } case 1: { - up = MT_Vector3(0,1.0,0); + up.setValue(0,1.0,0); break; } case 2: default: { - up = MT_Vector3(0,0,1.0); + up.setValue(0,0,1.0); } } #endif diff --git a/source/gameengine/Rasterizer/RAS_TexVert.cpp b/source/gameengine/Rasterizer/RAS_TexVert.cpp index b92965ed1cc..210addfb927 100644 --- a/source/gameengine/Rasterizer/RAS_TexVert.cpp +++ b/source/gameengine/Rasterizer/RAS_TexVert.cpp @@ -59,10 +59,10 @@ const MT_Point3& RAS_TexVert::xyz() void RAS_TexVert::SetRGBA(const MT_Vector4& rgba) { unsigned char *colp = (unsigned char*) &m_rgba; - colp[0] = (unsigned char) (rgba[0]*255.0); - colp[1] = (unsigned char) (rgba[1]*255.0); - colp[2] = (unsigned char) (rgba[2]*255.0); - colp[3] = (unsigned char) (rgba[3]*255.0); + colp[0] = (unsigned char) (rgba[0]*255.0f); + colp[1] = (unsigned char) (rgba[1]*255.0f); + colp[2] = (unsigned char) (rgba[2]*255.0f); + colp[3] = (unsigned char) (rgba[3]*255.0f); } @@ -71,7 +71,10 @@ void RAS_TexVert::SetXYZ(const MT_Point3& xyz) xyz.getValue(m_localxyz); } - +void RAS_TexVert::SetXYZ(const float *xyz) +{ + m_localxyz[0]= xyz[0]; m_localxyz[1]= xyz[1]; m_localxyz[2]= xyz[2]; +} void RAS_TexVert::SetUV(const MT_Point2& uv) { @@ -111,15 +114,18 @@ void RAS_TexVert::SetTangent(const MT_Vector3& tangent) } // compare two vertices, and return TRUE if both are almost identical (they can be shared) +#define _VEC_EQUAL3(_v1, _v2) (_v1[0]==_v2[0] && _v1[1]==_v2[1] && _v1[2]==_v2[2]) +#define _VEC_EQUAL2(_v1, _v2) (_v1[0]==_v2[0] && _v1[1]==_v2[1]) bool RAS_TexVert::closeTo(const RAS_TexVert* other) { return (m_flag == other->m_flag && m_rgba == other->m_rgba && - MT_fuzzyEqual(MT_Vector3(m_normal), MT_Vector3(other->m_normal)) && - MT_fuzzyEqual(MT_Vector3(m_tangent), MT_Vector3(other->m_tangent)) && - MT_fuzzyEqual(MT_Vector2(m_uv1), MT_Vector2(other->m_uv1)) && - MT_fuzzyEqual(MT_Vector2(m_uv2), MT_Vector2(other->m_uv2)) && // p -- - MT_fuzzyEqual(MT_Vector3(m_localxyz), MT_Vector3(other->m_localxyz))) ; + _VEC_EQUAL3(m_normal, other->m_normal) && + _VEC_EQUAL3(m_tangent, other->m_tangent) && + _VEC_EQUAL2(m_uv1, other->m_uv1) && + _VEC_EQUAL2(m_uv2, other->m_uv2) // p -- + /* we know the verts must be shared so dont need to check this */ + /*&& FAST_MT_fuzzyEqual3(m_localxyz, other->m_localxyz)*/) ; } short RAS_TexVert::getFlag() const diff --git a/source/gameengine/Rasterizer/RAS_TexVert.h b/source/gameengine/Rasterizer/RAS_TexVert.h index 157a6ce3d51..811867f3579 100644 --- a/source/gameengine/Rasterizer/RAS_TexVert.h +++ b/source/gameengine/Rasterizer/RAS_TexVert.h @@ -115,6 +115,7 @@ public: } void SetXYZ(const MT_Point3& xyz); + void SetXYZ(const float *xyz); void SetUV(const MT_Point2& uv); void SetUV2(const MT_Point2& uv); diff --git a/source/gameengine/SceneGraph/SG_BBox.cpp b/source/gameengine/SceneGraph/SG_BBox.cpp index 4bd2805978e..a44262d04f7 100644 --- a/source/gameengine/SceneGraph/SG_BBox.cpp +++ b/source/gameengine/SceneGraph/SG_BBox.cpp @@ -34,8 +34,8 @@ #include "SG_Node.h" SG_BBox::SG_BBox() : - m_min(MT_Point3(0., 0., 0.)), - m_max(MT_Point3(0., 0., 0.)) + m_min(0., 0., 0.), + m_max(0., 0., 0.) { } diff --git a/source/gameengine/SceneGraph/SG_Spatial.cpp b/source/gameengine/SceneGraph/SG_Spatial.cpp index 5ba116e59db..99aeb3e72ee 100644 --- a/source/gameengine/SceneGraph/SG_Spatial.cpp +++ b/source/gameengine/SceneGraph/SG_Spatial.cpp @@ -44,13 +44,13 @@ SG_Spatial( ): SG_IObject(clientobj,clientinfo,callbacks), - m_localPosition(MT_Point3(0.0,0.0,0.0)), - m_localRotation(MT_Matrix3x3(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0)), - m_localScaling(MT_Vector3(1.f,1.f,1.f)), + m_localPosition(0.0,0.0,0.0), + m_localRotation(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0), + m_localScaling(1.f,1.f,1.f), - m_worldPosition(MT_Point3(0.0,0.0,0.0)), - m_worldRotation(MT_Matrix3x3(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0)), - m_worldScaling(MT_Vector3(1.f,1.f,1.f)), + m_worldPosition(0.0,0.0,0.0), + m_worldRotation(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0), + m_worldScaling(1.f,1.f,1.f), m_parent_relation (NULL), @@ -297,6 +297,13 @@ GetWorldScaling( return m_worldScaling; } +void SG_Spatial::SetWorldFromLocalTransform() +{ + m_worldPosition= m_localPosition; + m_worldScaling= m_localScaling; + m_worldRotation= m_localRotation; +} + SG_BBox& SG_Spatial::BBox() { return m_bbox; diff --git a/source/gameengine/SceneGraph/SG_Spatial.h b/source/gameengine/SceneGraph/SG_Spatial.h index 28848b0f933..6ccec2aa9c1 100644 --- a/source/gameengine/SceneGraph/SG_Spatial.h +++ b/source/gameengine/SceneGraph/SG_Spatial.h @@ -176,6 +176,8 @@ public: GetWorldScaling( ) const ; + void SetWorldFromLocalTransform(); + MT_Transform GetWorldTransform() const; bool ComputeWorldTransforms( const SG_Spatial *parent); -- cgit v1.2.3 From 7fffb0b6302618049a35e6bacf0aeed70a47d8aa Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 Feb 2009 12:07:51 +0000 Subject: Building the game engine with Solid/Sumo is now optional for scons using WITH_BF_SOLID. Now Sumo is has been deprecated for a while we might want to remove it for 2.5. --- source/gameengine/BlenderRoutines/SConscript | 13 +++++++++---- source/gameengine/Converter/SConscript | 13 +++++++++---- source/gameengine/GamePlayer/common/SConscript | 10 ++++++---- source/gameengine/GamePlayer/ghost/SConscript | 7 ++++--- source/gameengine/Ketsji/KX_ClientObjectInfo.h | 16 +++++++++++++--- source/gameengine/Ketsji/KX_ConvertPhysicsObject.h | 2 +- source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 3 +++ source/gameengine/Ketsji/KX_NearSensor.cpp | 3 +-- source/gameengine/Ketsji/KX_TouchSensor.cpp | 6 ++++-- source/gameengine/Ketsji/SConscript | 10 +++++++--- source/gameengine/SConscript | 4 +++- 11 files changed, 60 insertions(+), 27 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/SConscript b/source/gameengine/BlenderRoutines/SConscript index 7a1bf4d9ad6..f2d92384e3c 100644 --- a/source/gameengine/BlenderRoutines/SConscript +++ b/source/gameengine/BlenderRoutines/SConscript @@ -2,6 +2,7 @@ Import ('env') sources = env.Glob('*.cpp') +defs = [] incs = '. #source/kernel/gen_system #intern/string #intern/guardedalloc' incs += ' #source/gameengine/Rasterizer/RAS_OpenGLRasterizer #intern/bmfont' @@ -12,13 +13,17 @@ incs += ' #source/blender/blenkernel #source/blender #source/blender/include' incs += ' #source/blender/makesdna #source/gameengine/Rasterizer #source/gameengine/GameLogic' incs += ' #source/gameengine/Expressions #source/gameengine/Network' incs += ' #source/gameengine/SceneGraph #source/gameengine/Physics/common' -incs += ' #source/gameengine/Physics/Bullet #source/gameengine/Physics/Sumo' -incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork' +incs += ' #source/gameengine/Physics/Bullet' +incs += ' #source/gameengine/Network/LoopBackNetwork' incs += ' #intern/SoundSystem #source/blender/misc #source/blender/blenloader' incs += ' #extern/glew/include #source/blender/gpu' +if env['WITH_BF_SOLID']: + incs += ' #source/gameengine/Physics/Sumo #source/gameengine/Physics/Sumo/Fuzzics/include' + incs += ' ' + env['BF_SOLID_INC'] + defs.append('USE_SUMO_SOLID') + incs += ' ' + env['BF_PYTHON_INC'] -incs += ' ' + env['BF_SOLID_INC'] incs += ' ' + env['BF_BULLET_INC'] incs += ' ' + env['BF_OPENGL_INC'] @@ -27,4 +32,4 @@ if env['OURPLATFORM']=='win32-vc': cxxflags.append ('/GR') cxxflags.append ('/O2') -env.BlenderLib ( 'bf_bloutines', sources, Split(incs), [], libtype=['game', 'game2', 'player'], priority=[0, 0, 55] , cxx_compileflags=cxxflags) +env.BlenderLib ( 'bf_bloutines', sources, Split(incs), defs, libtype=['game', 'game2', 'player'], priority=[0, 0, 55] , cxx_compileflags=cxxflags) diff --git a/source/gameengine/Converter/SConscript b/source/gameengine/Converter/SConscript index 3be352c568b..361dca58005 100644 --- a/source/gameengine/Converter/SConscript +++ b/source/gameengine/Converter/SConscript @@ -2,6 +2,7 @@ Import ('env') sources = env.Glob('*.cpp') +defs = [] incs = '. #source/kernel/gen_system #intern/string #intern/guardedalloc' incs += ' #source/gameengine/Rasterizer/RAS_OpenGLRasterizer #intern/bmfont' @@ -14,12 +15,16 @@ incs += ' #source/blender/include #source/blender/makesdna #source/gameengine/Ra incs += ' #source/gameengine/Rasterizer/RAS_OpenGLRasterizer #source/gameengine/GameLogic' incs += ' #source/gameengine/Expressions #source/gameengine/Network #source/gameengine/SceneGraph' incs += ' #source/gameengine/Physics/common #source/gameengine/Physics/Bullet #source/gameengine/Physics/BlOde' -incs += ' #source/gameengine/Physics/Dummy #source/gameengine/Physics/Sumo' -incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork' +incs += ' #source/gameengine/Physics/Dummy' +incs += ' #source/gameengine/Network/LoopBackNetwork' incs += ' #source/blender/misc #source/blender/blenloader #source/blender/gpu' +if env['WITH_BF_SOLID']: + incs += ' #source/gameengine/Physics/Sumo #source/gameengine/Physics/Sumo/Fuzzics/include' + incs += ' ' + env['BF_SOLID_INC'] + defs.append('USE_SUMO_SOLID') + incs += ' ' + env['BF_PYTHON_INC'] -incs += ' ' + env['BF_SOLID_INC'] incs += ' ' + env['BF_BULLET_INC'] -env.BlenderLib ( 'bf_converter', sources, Split(incs), [], libtype=['game','player'], priority=[5,70] ) +env.BlenderLib ( 'bf_converter', sources, Split(incs), defs, libtype=['game','player'], priority=[5,70] ) diff --git a/source/gameengine/GamePlayer/common/SConscript b/source/gameengine/GamePlayer/common/SConscript index c9bda78d905..23ad413350b 100644 --- a/source/gameengine/GamePlayer/common/SConscript +++ b/source/gameengine/GamePlayer/common/SConscript @@ -39,15 +39,13 @@ incs = ['.', '#source/gameengine/Network', '#source/gameengine/SceneGraph', '#source/gameengine/Physics/common', - '#source/gameengine/Physics/Sumo', - '#source/gameengine/Physics/Sumo/Fuzzics/include', '#source/gameengine/Network/LoopBackNetwork', '#source/gameengine/GamePlayer/ghost', '#source/blender/misc', '#source/blender/blenloader', '#source/blender/gpu', '#extern/glew/include'] - + #This is all plugin stuff! #if sys.platform=='win32': # source_files += ['windows/GPW_Canvas.cpp', @@ -62,8 +60,12 @@ incs = ['.', # 'unix/GPU_System.cpp'] # gp_common_env.Append ( CPPPATH = ['unix']) +if env['WITH_BF_SOLID']: + incs.append('#source/gameengine/Physics/Sumo') + incs.append('#source/gameengine/Physics/Sumo/Fuzzics/include') + incs += Split(env['BF_SOLID_INC']) + incs += Split(env['BF_PYTHON_INC']) -incs += Split(env['BF_SOLID_INC']) incs += Split(env['BF_PNG_INC']) incs += Split(env['BF_ZLIB_INC']) diff --git a/source/gameengine/GamePlayer/ghost/SConscript b/source/gameengine/GamePlayer/ghost/SConscript index 0785ce4bd0d..dd8761e0a45 100644 --- a/source/gameengine/GamePlayer/ghost/SConscript +++ b/source/gameengine/GamePlayer/ghost/SConscript @@ -34,8 +34,6 @@ incs = ['.', '#source/gameengine/Network', '#source/gameengine/SceneGraph', '#source/gameengine/Physics/common', - '#source/gameengine/Physics/Sumo', - '#source/gameengine/Physics/Sumo/Fuzzics/include', '#source/gameengine/Network/LoopBackNetwork', '#source/gameengine/GamePlayer/common', '#source/blender/misc', @@ -43,8 +41,11 @@ incs = ['.', '#source/blender/gpu', '#extern/glew/include'] +if env['WITH_BF_SOLID']: + incs.append(['#source/gameengine/Physics/Sumo', '#source/gameengine/Physics/Sumo/Fuzzics/include']) + incs += Split(env['BF_SOLID_INC']) + incs += Split(env['BF_PYTHON_INC']) -incs += Split(env['BF_SOLID_INC']) cxxflags = [] if env['OURPLATFORM']=='win32-vc': diff --git a/source/gameengine/Ketsji/KX_ClientObjectInfo.h b/source/gameengine/Ketsji/KX_ClientObjectInfo.h index 5e8af0f040c..7345edb054b 100644 --- a/source/gameengine/Ketsji/KX_ClientObjectInfo.h +++ b/source/gameengine/Ketsji/KX_ClientObjectInfo.h @@ -29,7 +29,10 @@ #ifndef __KX_CLIENTOBJECT_INFO_H #define __KX_CLIENTOBJECT_INFO_H +/* Note, the way this works with/without sumo is a bit odd */ +#ifdef USE_SUMO_SOLID #include +#endif //USE_SUMO_SOLID #include @@ -38,7 +41,10 @@ class KX_GameObject; /** * Client Type and Additional Info. This structure can be use instead of a bare void* pointer, for safeness, and additional info for callbacks */ -struct KX_ClientObjectInfo : public SM_ClientObject +struct KX_ClientObjectInfo +#ifdef USE_SUMO_SOLID + : public SM_ClientObject +#endif { enum clienttype { STATIC, @@ -52,14 +58,18 @@ struct KX_ClientObjectInfo : public SM_ClientObject std::list m_sensors; public: KX_ClientObjectInfo(KX_GameObject *gameobject, clienttype type = STATIC, void *auxilary_info = NULL) : +#ifdef USE_SUMO_SOLID SM_ClientObject(), +#endif m_type(type), m_gameobject(gameobject), m_auxilary_info(auxilary_info) {} - KX_ClientObjectInfo(const KX_ClientObjectInfo ©) - : SM_ClientObject(copy), + KX_ClientObjectInfo(const KX_ClientObjectInfo ©) : +#ifdef USE_SUMO_SOLID + SM_ClientObject(copy), +#endif m_type(copy.m_type), m_gameobject(copy.m_gameobject), m_auxilary_info(copy.m_auxilary_info) diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h index 53486cecf73..edacf38ab43 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h @@ -32,7 +32,7 @@ /* These are defined by the build system... */ //but the build system is broken, because it doesn't allow for 2 or more defines at once. //Please leave Sumo _AND_ Bullet enabled -#define USE_SUMO_SOLID +//#define USE_SUMO_SOLID // scons defines this #define USE_BULLET //#define USE_ODE diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 074b3195121..87f348799df 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -59,7 +59,10 @@ #include "KX_PythonInit.h" #include "KX_PyConstraintBinding.h" #include "PHY_IPhysicsEnvironment.h" + +#ifdef USE_SUMO_SOLID #include "SumoPhysicsEnvironment.h" +#endif #include "SND_Scene.h" #include "SND_IAudioDevice.h" diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index fb38f16c169..5b1df8b1fe1 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -37,7 +37,6 @@ #include "PHY_IPhysicsEnvironment.h" #include "PHY_IPhysicsController.h" - #ifdef HAVE_CONFIG_H #include #endif @@ -272,7 +271,7 @@ bool KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData //} } - return DT_CONTINUE; + return false; // was DT_CONTINUE; but this was defined in Sumo as false } diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 117adb44742..0b4d66dbb34 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -34,7 +34,9 @@ #include "SCA_LogicManager.h" #include "KX_GameObject.h" #include "KX_TouchEventManager.h" -#include "KX_SumoPhysicsController.h" + +#include "PHY_IPhysicsController.h" + #include #include "PHY_IPhysicsEnvironment.h" @@ -214,7 +216,7 @@ bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll } } - return DT_CONTINUE; + return false; // was DT_CONTINUE but this was defined in sumo as false. } diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript index 40cbc35e7f3..5989d9d8b52 100644 --- a/source/gameengine/Ketsji/SConscript +++ b/source/gameengine/Ketsji/SConscript @@ -31,11 +31,15 @@ incs += ' #source/blender/makesdna #source/blender/python #source/gameengine/Ras incs += ' #source/gameengine/GameLogic #source/gameengine/Expressions #source/gameengine/Network' incs += ' #source/gameengine/SceneGraph #source/gameengine/Physics/common #source/gameengine/Physics/Bullet' incs += ' #source/gameengine/Physics/BlOde #source/gameengine/Physics/Dummy' -incs += ' #source/gameengine/Physics/Sumo #source/gameengine/Physics/Sumo/include' -incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork' incs += ' #source/blender/misc #source/blender/blenloader #extern/glew/include #source/blender/gpu' -incs += ' ' + env['BF_SOLID_INC'] +if env['WITH_BF_SOLID']: + incs += ' #source/gameengine/Physics/Sumo #source/gameengine/Physics/Sumo/include' + incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork' + incs += ' ' + env['BF_SOLID_INC'] + defs += ' USE_SUMO_SOLID' + + incs += ' ' + env['BF_PYTHON_INC'] incs += ' ' + env['BF_BULLET_INC'] incs += ' ' + env['BF_OPENGL_INC'] diff --git a/source/gameengine/SConscript b/source/gameengine/SConscript index e841f206eee..51a05e70a07 100644 --- a/source/gameengine/SConscript +++ b/source/gameengine/SConscript @@ -15,10 +15,12 @@ SConscript(['BlenderRoutines/SConscript', 'Rasterizer/RAS_OpenGLRasterizer/SConscript', 'SceneGraph/SConscript', 'Physics/Bullet/SConscript', - 'Physics/Sumo/SConscript', 'VideoTexture/SConscript' ]) +if env['WITH_BF_SOLID']: + SConscript(['Physics/Sumo/SConscript']) + if env['WITH_BF_PLAYER']: SConscript(['GamePlayer/SConscript']) -- cgit v1.2.3 From a4ad52f1aaa1c8ed0d2f1345cbff99769f353ae9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 25 Feb 2009 17:19:30 +0000 Subject: New Pulse option for the collision sensor (off by default wont change existing logic) Previously only the first collision would trigger an event (no collisions a negative event ofcourse) With the Pulse option enabled, any change to the set of colliding objects will trigger an event. Added this because there was no way to count how many sheep were on a platform in YoFrankie without running a script periodically. Changes in collision are detected by comparing the number of objects colliding with the last event, as well as a hash made from the object pointers. Also changed the touch sensors internal list of colliding objects to only contain objects that match the property or material. - pulse isnt a great name, could change this. --- source/gameengine/Converter/KX_ConvertSensors.cpp | 8 +-- source/gameengine/Ketsji/KX_NearSensor.cpp | 1 + source/gameengine/Ketsji/KX_TouchSensor.cpp | 66 ++++++++--------------- source/gameengine/Ketsji/KX_TouchSensor.h | 16 +++++- 4 files changed, 43 insertions(+), 48 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/KX_ConvertSensors.cpp b/source/gameengine/Converter/KX_ConvertSensors.cpp index 13b7f43195d..c9b51807767 100644 --- a/source/gameengine/Converter/KX_ConvertSensors.cpp +++ b/source/gameengine/Converter/KX_ConvertSensors.cpp @@ -306,12 +306,12 @@ void BL_ConvertSensors(struct Object* blenderobject, { // collision sensor can sense both materials and properties. - bool bFindMaterial = false; + bool bFindMaterial = false, bTouchPulse = false; bCollisionSensor* blendertouchsensor = (bCollisionSensor*)sens->data; - bFindMaterial = (blendertouchsensor->mode - & SENS_COLLISION_MATERIAL); + bFindMaterial = (blendertouchsensor->mode & SENS_COLLISION_MATERIAL); + bTouchPulse = (blendertouchsensor->mode & SENS_COLLISION_PULSE); STR_String touchPropOrMatName = ( bFindMaterial ? @@ -324,6 +324,7 @@ void BL_ConvertSensors(struct Object* blenderobject, gamesensor = new KX_TouchSensor(eventmgr, gameobj, bFindMaterial, + bTouchPulse, touchPropOrMatName); } @@ -349,6 +350,7 @@ void BL_ConvertSensors(struct Object* blenderobject, gamesensor = new KX_TouchSensor(eventmgr, gameobj, bFindMaterial, + false, touchpropertyname); } } diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index 5b1df8b1fe1..a4aebdd8b6b 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -52,6 +52,7 @@ KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr, :KX_TouchSensor(eventmgr, gameobj, bFindMaterial, + false, touchedpropname, /* scene, */ T), diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 0b4d66dbb34..a30dc34e2fa 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -59,6 +59,7 @@ void KX_TouchSensor::EndFrame() { m_colliders->ReleaseAndRemoveAll(); m_hitObject = NULL; m_bTriggered = false; + m_bColliderHash = 0; } void KX_TouchSensor::UnregisterToManager() @@ -72,7 +73,6 @@ bool KX_TouchSensor::Evaluate(CValue* event) { bool result = false; bool reset = m_reset && m_level; - m_reset = false; if (m_bTriggered != m_bLastTriggered) { @@ -84,13 +84,24 @@ bool KX_TouchSensor::Evaluate(CValue* event) if (reset) // force an event result = true; + + if (m_bTouchPulse) { /* pulse on changes to the colliders */ + int count = m_colliders->GetCount(); + + if (m_bLastCount!=count || m_bColliderHash!=m_bLastColliderHash) { + m_bLastCount = count; + m_bLastColliderHash= m_bColliderHash; + result = true; + } + } return result; } -KX_TouchSensor::KX_TouchSensor(SCA_EventManager* eventmgr,KX_GameObject* gameobj,bool bFindMaterial,const STR_String& touchedpropname,PyTypeObject* T) +KX_TouchSensor::KX_TouchSensor(SCA_EventManager* eventmgr,KX_GameObject* gameobj,bool bFindMaterial,bool bTouchPulse,const STR_String& touchedpropname,PyTypeObject* T) :SCA_ISensor(gameobj,eventmgr,T), m_touchedpropname(touchedpropname), m_bFindMaterial(bFindMaterial), +m_bTouchPulse(bTouchPulse), m_eventmgr(eventmgr) /*m_sumoObj(sumoObj),*/ { @@ -116,6 +127,8 @@ void KX_TouchSensor::Init() m_bCollision = false; m_bTriggered = false; m_bLastTriggered = (m_invert)?true:false; + m_bLastCount = 0; + m_bColliderHash = m_bLastColliderHash = 0; m_hitObject = NULL; m_reset = true; } @@ -191,8 +204,6 @@ bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll if (m_links && !m_suspended && gameobj && (gameobj != parent) && client_info->isActor()) { - if (!m_colliders->SearchValue(gameobj)) - m_colliders->Add(gameobj->AddRef()); bool found = m_touchedpropname.IsEmpty(); if (!found) @@ -210,6 +221,12 @@ bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll } if (found) { + if (!m_colliders->SearchValue(gameobj)) { + m_colliders->Add(gameobj->AddRef()); + + if (m_bTouchPulse) + m_bColliderHash += (uint_ptr)(static_cast(&gameobj)); + } m_bTriggered = true; m_hitObject = gameobj; //printf("KX_TouchSensor::HandleCollision\n"); @@ -334,46 +351,7 @@ PyObject* KX_TouchSensor::PyGetHitObjectList(PyObject* self, /* to do: do Py_IncRef if the object is already known in Python */ /* otherwise, this leaks memory */ - - if ( m_touchedpropname.IsEmpty() ) { - return m_colliders->AddRef(); - } else { - CListValue* newList = new CListValue(); - int i = 0; - while (i < m_colliders->GetCount()) { - if (m_bFindMaterial) { - /* need to associate the CValues from the list to material - * names. The collider list _should_ contains only - * KX_GameObjects. I am loathe to cast them, though... The - * material name must be retrieved from Sumo. To a Sumo - * object, a client-info block is attached. This block - * contains the material name. - * - this also doesn't work (obviously) for multi-materials... - */ - KX_GameObject* gameob = (KX_GameObject*) m_colliders->GetValue(i); - PHY_IPhysicsController* spc = dynamic_cast(gameob->GetPhysicsController()); - - if (spc) { - KX_ClientObjectInfo* cl_inf = static_cast(spc->getNewClientInfo()); - - if (NULL != cl_inf->m_auxilary_info && m_touchedpropname == ((char*)cl_inf->m_auxilary_info)) { - newList->Add(m_colliders->GetValue(i)->AddRef()); - } - } - - } else { - CValue* val = m_colliders->GetValue(i)->FindIdentifier(m_touchedpropname); - if (!val->IsError()) { - newList->Add(m_colliders->GetValue(i)->AddRef()); - } - val->Release(); - } - - i++; - } - return newList->AddRef(); - } - + return m_colliders->AddRef(); } /* 5. getTouchMaterial */ diff --git a/source/gameengine/Ketsji/KX_TouchSensor.h b/source/gameengine/Ketsji/KX_TouchSensor.h index e07f89f0a31..c463226a5be 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.h +++ b/source/gameengine/Ketsji/KX_TouchSensor.h @@ -39,6 +39,12 @@ struct PHY_CollData; #include "KX_ClientObjectInfo.h" +#if defined(_WIN64) +typedef unsigned __int64 uint_ptr; +#else +typedef unsigned long uint_ptr; +#endif + class KX_TouchEventManager; class KX_TouchSensor : public SCA_ISensor @@ -51,6 +57,7 @@ protected: */ STR_String m_touchedpropname; bool m_bFindMaterial; + bool m_bTouchPulse; /* changes in the colliding objects trigger pulses */ class SCA_EventManager* m_eventmgr; class PHY_IPhysicsController* m_physCtrl; @@ -58,13 +65,20 @@ protected: bool m_bCollision; bool m_bTriggered; bool m_bLastTriggered; + + // Use with m_bTouchPulse to detect changes + int m_bLastCount; /* size of m_colliders last tick */ + uint_ptr m_bColliderHash; /* hash collision objects pointers to trigger incase one object collides and another takes its place */ + uint_ptr m_bLastColliderHash; + SCA_IObject* m_hitObject; class CListValue* m_colliders; public: KX_TouchSensor(class SCA_EventManager* eventmgr, class KX_GameObject* gameobj, - bool fFindMaterial, + bool bFindMaterial, + bool bTouchPulse, const STR_String& touchedpropname, PyTypeObject* T=&Type) ; virtual ~KX_TouchSensor(); -- cgit v1.2.3 From 6bfb8ca6b09e983fe757c9590b462b113ad28b72 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Feb 2009 04:17:23 +0000 Subject: - Attributes for the collision sensor: propertyName, materialCheck, pulseCollisions, objectHit and objectHitList. Removed a check in Python API touch.setProperty() for the property name on the sensor owner before allowing the name to be set - it makes no sense and isnt checked when creating the sensor. - SCA_DelaySensor.py indent error making epydoc fail. --- source/gameengine/Ketsji/KX_NearSensor.cpp | 8 +-- source/gameengine/Ketsji/KX_TouchSensor.cpp | 100 ++++++++++++++++++---------- source/gameengine/Ketsji/KX_TouchSensor.h | 15 +++-- source/gameengine/PyDoc/KX_TouchSensor.py | 32 ++++++--- source/gameengine/PyDoc/SCA_DelaySensor.py | 7 +- 5 files changed, 100 insertions(+), 62 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index a4aebdd8b6b..d859f670b07 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -311,10 +311,10 @@ PyParentObject KX_NearSensor::Parents[] = { PyMethodDef KX_NearSensor::Methods[] = { - {"setProperty", (PyCFunction) KX_NearSensor::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc}, - {"getProperty", (PyCFunction) KX_NearSensor::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc}, - {"getHitObject",(PyCFunction) KX_NearSensor::sPyGetHitObject, METH_VARARGS, (PY_METHODCHAR)GetHitObject_doc}, - {"getHitObjectList", (PyCFunction) KX_NearSensor::sPyGetHitObjectList, METH_VARARGS, (PY_METHODCHAR)GetHitObjectList_doc}, + {"setProperty", (PyCFunction) KX_NearSensor::sPySetProperty, METH_O, (PY_METHODCHAR)SetProperty_doc}, + {"getProperty", (PyCFunction) KX_NearSensor::sPyGetProperty, METH_NOARGS, (PY_METHODCHAR)GetProperty_doc}, + {"getHitObject",(PyCFunction) KX_NearSensor::sPyGetHitObject, METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc}, + {"getHitObjectList", (PyCFunction) KX_NearSensor::sPyGetHitObjectList, METH_NOARGS, (PY_METHODCHAR)GetHitObjectList_doc}, {NULL,NULL} //Sentinel }; diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index a30dc34e2fa..de4b5c401fc 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -270,20 +270,57 @@ PyParentObject KX_TouchSensor::Parents[] = { PyMethodDef KX_TouchSensor::Methods[] = { {"setProperty", - (PyCFunction) KX_TouchSensor::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc}, + (PyCFunction) KX_TouchSensor::sPySetProperty, METH_O, (PY_METHODCHAR)SetProperty_doc}, {"getProperty", - (PyCFunction) KX_TouchSensor::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc}, + (PyCFunction) KX_TouchSensor::sPyGetProperty, METH_NOARGS, (PY_METHODCHAR)GetProperty_doc}, {"getHitObject", - (PyCFunction) KX_TouchSensor::sPyGetHitObject, METH_VARARGS, (PY_METHODCHAR)GetHitObject_doc}, + (PyCFunction) KX_TouchSensor::sPyGetHitObject, METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc}, {"getHitObjectList", - (PyCFunction) KX_TouchSensor::sPyGetHitObjectList, METH_VARARGS, (PY_METHODCHAR)GetHitObjectList_doc}, + (PyCFunction) KX_TouchSensor::sPyGetHitObjectList, METH_NOARGS, (PY_METHODCHAR)GetHitObjectList_doc}, {NULL,NULL} //Sentinel }; -PyObject* KX_TouchSensor::_getattr(const char *attr) { +PyAttributeDef KX_TouchSensor::Attributes[] = { + KX_PYATTRIBUTE_STRING_RW("propertyName",0,100,false,KX_TouchSensor,m_touchedpropname), + KX_PYATTRIBUTE_BOOL_RW("materialCheck",KX_TouchSensor,m_bFindMaterial), + KX_PYATTRIBUTE_BOOL_RW("pulseCollisions",KX_TouchSensor,m_bTouchPulse), + { NULL } //Sentinel +}; + +PyObject* KX_TouchSensor::_getattr(const char *attr) +{ + if (!strcmp(attr, "objectHit")) { + if (m_hitObject) return m_hitObject->AddRef(); + else Py_RETURN_NONE; + } + if (!strcmp(attr, "objectHitList")) { + return m_colliders->AddRef(); + } + + PyObject* object= _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_ISensor); } +int KX_TouchSensor::_setattr(const char *attr, PyObject *value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + + if (!strcmp(attr, "objectHit")) { + PyErr_SetString(PyExc_AttributeError, "attribute \"objectHit\" is read only"); + return 1; + } + if (!strcmp(attr, "objectHitList")) { + PyErr_SetString(PyExc_AttributeError, "attribute \"objectHit\" is read only"); + return 1; + } + + return SCA_ISensor::_setattr(attr, value); +} + /* Python API */ /* 1. setProperty */ @@ -293,23 +330,16 @@ const char KX_TouchSensor::SetProperty_doc[] = "\tSet the property or material to collide with. Use\n" "\tsetTouchMaterial() to switch between properties and\n" "\tmaterials."; -PyObject* KX_TouchSensor::PySetProperty(PyObject* self, - PyObject* args, - PyObject* kwds) { - char *nameArg; - if (!PyArg_ParseTuple(args, "s", &nameArg)) { +PyObject* KX_TouchSensor::PySetProperty(PyObject* self, PyObject* value) +{ + ShowDeprecationWarning("setProperty()", "the propertyName property"); + char *nameArg= PyString_AsString(value); + if (nameArg==NULL) { + PyErr_SetString(PyExc_ValueError, "expected a "); return NULL; } - - CValue* prop = GetParent()->FindIdentifier(nameArg); - - if (!prop->IsError()) { - m_touchedpropname = nameArg; - } else { - ; /* not found ... */ - } - prop->Release(); + m_touchedpropname = nameArg; Py_RETURN_NONE; } /* 2. getProperty */ @@ -318,19 +348,16 @@ const char KX_TouchSensor::GetProperty_doc[] = "\tReturns the property or material to collide with. Use\n" "\tgetTouchMaterial() to find out whether this sensor\n" "\tlooks for properties or materials."; -PyObject* KX_TouchSensor::PyGetProperty(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_TouchSensor::PyGetProperty(PyObject* self) { return PyString_FromString(m_touchedpropname); } const char KX_TouchSensor::GetHitObject_doc[] = "getHitObject()\n" ; -PyObject* KX_TouchSensor::PyGetHitObject(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_TouchSensor::PyGetHitObject(PyObject* self) { + ShowDeprecationWarning("getHitObject()", "the objectHit property"); /* to do: do Py_IncRef if the object is already known in Python */ /* otherwise, this leaks memory */ if (m_hitObject) @@ -344,13 +371,11 @@ const char KX_TouchSensor::GetHitObjectList_doc[] = "getHitObjectList()\n" "\tReturn a list of the objects this object collided with,\n" "\tbut only those matching the property/material condition.\n"; -PyObject* KX_TouchSensor::PyGetHitObjectList(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_TouchSensor::PyGetHitObjectList(PyObject* self) { - + ShowDeprecationWarning("getHitObjectList()", "the objectHitList property"); /* to do: do Py_IncRef if the object is already known in Python */ - /* otherwise, this leaks memory */ + /* otherwise, this leaks memory */ /* Edit, this seems ok and not to leak memory - Campbell */ return m_colliders->AddRef(); } @@ -359,24 +384,25 @@ const char KX_TouchSensor::GetTouchMaterial_doc[] = "getTouchMaterial()\n" "\tReturns KX_TRUE if this sensor looks for a specific material,\n" "\tKX_FALSE if it looks for a specific property.\n" ; -PyObject* KX_TouchSensor::PyGetTouchMaterial(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_TouchSensor::PyGetTouchMaterial(PyObject* self) { + ShowDeprecationWarning("getTouchMaterial()", "the materialCheck property"); return PyInt_FromLong(m_bFindMaterial); } /* 6. setTouchMaterial */ +#if 0 const char KX_TouchSensor::SetTouchMaterial_doc[] = "setTouchMaterial(flag)\n" "\t- flag: KX_TRUE or KX_FALSE.\n" "\tSet flag to KX_TRUE to switch on positive pulse mode,\n" "\tKX_FALSE to switch off positive pulse mode.\n" ; -PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject* self, PyObject *value) { - int pulseArg = 0; + int pulseArg = PyInt_AsLong(value); - if(!PyArg_ParseTuple(args, "i", &pulseArg)) { + if(pulseArg ==-1 && PyErr_Occurred()) { + PyErr_SetString(PyExc_ValueError, "expected a bool"); return NULL; } @@ -384,6 +410,6 @@ PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject* self, PyObject* args, PyO Py_RETURN_NONE; } - +#endif /* eof */ diff --git a/source/gameengine/Ketsji/KX_TouchSensor.h b/source/gameengine/Ketsji/KX_TouchSensor.h index c463226a5be..c523736967b 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.h +++ b/source/gameengine/Ketsji/KX_TouchSensor.h @@ -121,19 +121,22 @@ public: /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); /* 1. setProperty */ - KX_PYMETHOD_DOC(KX_TouchSensor,SetProperty); + KX_PYMETHOD_DOC_O(KX_TouchSensor,SetProperty); /* 2. getProperty */ - KX_PYMETHOD_DOC(KX_TouchSensor,GetProperty); + KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetProperty); /* 3. getHitObject */ - KX_PYMETHOD_DOC(KX_TouchSensor,GetHitObject); + KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetHitObject); /* 4. getHitObject */ - KX_PYMETHOD_DOC(KX_TouchSensor,GetHitObjectList); + KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetHitObjectList); /* 5. getTouchMaterial */ - KX_PYMETHOD_DOC(KX_TouchSensor,GetTouchMaterial); + KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetTouchMaterial); +#if 0 /* 6. setTouchMaterial */ - KX_PYMETHOD_DOC(KX_TouchSensor,SetTouchMaterial); + KX_PYMETHOD_DOC_O(KX_TouchSensor,SetTouchMaterial); +#endif }; diff --git a/source/gameengine/PyDoc/KX_TouchSensor.py b/source/gameengine/PyDoc/KX_TouchSensor.py index f2cc101af10..4f020930c4c 100644 --- a/source/gameengine/PyDoc/KX_TouchSensor.py +++ b/source/gameengine/PyDoc/KX_TouchSensor.py @@ -1,13 +1,26 @@ # $Id$ # Documentation for KX_TouchSensor from SCA_ISensor import * +from KX_GameObject import * class KX_TouchSensor(SCA_ISensor): """ Touch sensor detects collisions between objects. + + @ivar propertyName: The name of the property or material this sensor detects (depending on the materialCheck property). + @type propertyName: string + @ivar materialCheck: when enabled this sensor checks for object materials rather then properties. + @type materialCheck: bool + @ivar pulseCollisions: The last collided object. + @type pulseCollisions: bool + @ivar objectHit: The last collided object. (Read Only) + @type objectHit: L{KX_GameObject} or None + @ivar objectHitList: A list of colliding objects. (Read Only) + @type objectHitList: list """ def setProperty(name): """ + DEPRECATED: use the propertyName property Set the property or material to collide with. Use setTouchMaterial() to switch between properties and materials. @@ -15,22 +28,25 @@ class KX_TouchSensor(SCA_ISensor): """ def getProperty(): """ + DEPRECATED: use the propertyName property Returns the property or material to collide with. Use getTouchMaterial() to find out whether this sensor - looks for properties or materials. + looks for properties or materials. (B{deprecated}) @rtype: string """ def getHitObject(): """ - Returns the last object hit by this touch sensor. + DEPRECATED: use the objectHit property + Returns the last object hit by this touch sensor. (B{deprecated}) @rtype: L{KX_GameObject} """ def getHitObjectList(): """ - Returns a list of all objects hit in the last frame. + DEPRECATED: use the objectHitList property + Returns a list of all objects hit in the last frame. (B{deprecated}) Only objects that have the requisite material/property are listed. @@ -38,13 +54,7 @@ class KX_TouchSensor(SCA_ISensor): """ def getTouchMaterial(): """ + DEPRECATED: use the materialCheck property Returns KX_TRUE if this sensor looks for a specific material, - KX_FALSE if it looks for a specific property. - """ - def setTouchMaterial(flag): - """ - Set flag to KX_TRUE to switch on positive pulse mode, - KX_FALSE to switch off positive pulse mode. - - @type flag: KX_TRUE or KX_FALSE. + KX_FALSE if it looks for a specific property. (B{deprecated}) """ diff --git a/source/gameengine/PyDoc/SCA_DelaySensor.py b/source/gameengine/PyDoc/SCA_DelaySensor.py index b99ed08bed5..6560df6573e 100644 --- a/source/gameengine/PyDoc/SCA_DelaySensor.py +++ b/source/gameengine/PyDoc/SCA_DelaySensor.py @@ -20,10 +20,9 @@ class SCA_DelaySensor(SCA_ISensor): @type delay: integer. @ivar duration: length of the ON period in number of frame after the initial OFF period. If duration is greater than 0, a negative trigger is sent at the end of the ON pulse. - @type duration: integer - @ivar repeat: 1 if the OFF-ON cycle should be repeated indefinately, 0 if it should run once. - @type repeat: integer - + @type duration: integer + @ivar repeat: 1 if the OFF-ON cycle should be repeated indefinately, 0 if it should run once. + @type repeat: integer """ def setDelay(delay): """ -- cgit v1.2.3 From 936a6eeda87bfd36ada735e5edac06f161a5de25 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Feb 2009 05:17:54 +0000 Subject: small errors in touch sensor and gameObject --- source/gameengine/Ketsji/KX_GameObject.cpp | 2 +- source/gameengine/Ketsji/KX_TouchSensor.cpp | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 5e013a1c647..9c6bd2edf0e 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1170,7 +1170,7 @@ int KX_GameObject::_setattr(const char *attr, PyObject *value) // _setattr metho { if (!strcmp(attr, "parent")) { - PyErr_SetString(PyExc_AttributeError, "attribute \"mass\" is read only\nUse setParent()"); + PyErr_SetString(PyExc_AttributeError, "attribute \"parent\" is read only\nUse setParent()"); return 1; } diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index de4b5c401fc..32fcc148395 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -284,6 +284,8 @@ PyAttributeDef KX_TouchSensor::Attributes[] = { KX_PYATTRIBUTE_STRING_RW("propertyName",0,100,false,KX_TouchSensor,m_touchedpropname), KX_PYATTRIBUTE_BOOL_RW("materialCheck",KX_TouchSensor,m_bFindMaterial), KX_PYATTRIBUTE_BOOL_RW("pulseCollisions",KX_TouchSensor,m_bTouchPulse), + KX_PYATTRIBUTE_DUMMY("objectHit"), + KX_PYATTRIBUTE_DUMMY("objectHitList"), { NULL } //Sentinel }; @@ -309,15 +311,6 @@ int KX_TouchSensor::_setattr(const char *attr, PyObject *value) if (ret >= 0) return ret; - if (!strcmp(attr, "objectHit")) { - PyErr_SetString(PyExc_AttributeError, "attribute \"objectHit\" is read only"); - return 1; - } - if (!strcmp(attr, "objectHitList")) { - PyErr_SetString(PyExc_AttributeError, "attribute \"objectHit\" is read only"); - return 1; - } - return SCA_ISensor::_setattr(attr, value); } -- cgit v1.2.3 From c785532becca59aa2d1b3ae67784b7ac2b733ec2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Feb 2009 09:04:06 +0000 Subject: Py BGE API Python dir(ob) for game types now includes attributes names, * Use "__dict__" rather then "__methods__" attribute to be Python 3.0 compatible * Added _getattr_dict() for getting the method and attribute names from a PyObject, rather then building it in the macro. * Added place holder *::Attribute array, needed for the _getattr_up macro. --- source/gameengine/Expressions/ListValue.cpp | 4 ++- source/gameengine/Expressions/PyObjectPlus.cpp | 30 ++++++++++++++++++ source/gameengine/Expressions/PyObjectPlus.h | 37 ++++++++-------------- source/gameengine/Expressions/Value.cpp | 4 +++ .../gameengine/GameLogic/SCA_2DFilterActuator.cpp | 3 ++ source/gameengine/GameLogic/SCA_ANDController.cpp | 4 +++ source/gameengine/GameLogic/SCA_AlwaysSensor.cpp | 4 +++ source/gameengine/GameLogic/SCA_IObject.cpp | 3 ++ source/gameengine/GameLogic/SCA_NANDController.cpp | 4 +++ source/gameengine/GameLogic/SCA_NORController.cpp | 4 +++ source/gameengine/GameLogic/SCA_ORController.cpp | 5 +++ .../gameengine/GameLogic/SCA_PythonController.cpp | 3 ++ source/gameengine/GameLogic/SCA_XNORController.cpp | 4 +++ source/gameengine/GameLogic/SCA_XORController.cpp | 4 +++ source/gameengine/Ketsji/BL_Shader.cpp | 3 ++ .../Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp | 4 +++ .../Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp | 4 +++ source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 3 ++ source/gameengine/Ketsji/KX_CDActuator.cpp | 4 ++- source/gameengine/Ketsji/KX_Camera.cpp | 4 +++ source/gameengine/Ketsji/KX_ConstraintActuator.cpp | 4 +++ source/gameengine/Ketsji/KX_ConstraintWrapper.cpp | 4 +++ source/gameengine/Ketsji/KX_GameActuator.cpp | 4 +++ source/gameengine/Ketsji/KX_GameObject.cpp | 3 ++ source/gameengine/Ketsji/KX_IpoActuator.cpp | 4 +++ source/gameengine/Ketsji/KX_Light.cpp | 4 +++ source/gameengine/Ketsji/KX_MeshProxy.cpp | 4 +++ source/gameengine/Ketsji/KX_MouseFocusSensor.cpp | 4 +++ source/gameengine/Ketsji/KX_NearSensor.cpp | 3 ++ source/gameengine/Ketsji/KX_ObjectActuator.cpp | 4 +++ source/gameengine/Ketsji/KX_ParentActuator.cpp | 4 +++ source/gameengine/Ketsji/KX_PolyProxy.cpp | 4 +++ source/gameengine/Ketsji/KX_PolygonMaterial.cpp | 3 ++ source/gameengine/Ketsji/KX_RadarSensor.cpp | 4 +++ source/gameengine/Ketsji/KX_RaySensor.cpp | 4 +++ .../gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp | 3 ++ .../gameengine/Ketsji/KX_SCA_DynamicActuator.cpp | 3 ++ .../gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp | 3 ++ .../Ketsji/KX_SCA_ReplaceMeshActuator.cpp | 4 ++- source/gameengine/Ketsji/KX_Scene.cpp | 4 +++ source/gameengine/Ketsji/KX_SceneActuator.cpp | 4 ++- source/gameengine/Ketsji/KX_SoundActuator.cpp | 4 ++- source/gameengine/Ketsji/KX_StateActuator.cpp | 4 +++ source/gameengine/Ketsji/KX_TrackToActuator.cpp | 3 ++ source/gameengine/Ketsji/KX_VehicleWrapper.cpp | 3 ++ source/gameengine/Ketsji/KX_VertexProxy.cpp | 4 +++ source/gameengine/Ketsji/KX_VisibilityActuator.cpp | 4 +++ 47 files changed, 206 insertions(+), 29 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 9acc6ad2cde..90a939af236 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -232,7 +232,9 @@ PyMethodDef CListValue::Methods[] = { {NULL,NULL} //Sentinel }; - +PyAttributeDef CListValue::Attributes[] = { + { NULL } //Sentinel +}; PyObject* CListValue::_getattr(const char *attr) { _getattr_up(CValue); diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index e04b42ee9cc..1bead0a7664 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -707,5 +707,35 @@ PyObject *PyObjectPlus::Py_isA(PyObject *value) // Python wrapper for isA Py_RETURN_FALSE; } +/* Utility function called by the macro _getattr_up() + * for getting ob.__dict__() values from our PyObject + * this is used by python for doing dir() on an object, so its good + * if we return a list of attributes and methods. + * + * Other then making dir() useful the value returned from __dict__() is not useful + * since every value is a Py_None + * */ +PyObject *_getattr_dict(PyObject *pydict, PyMethodDef *meth, PyAttributeDef *attrdef) +{ + if(pydict==NULL) { /* incase calling __dict__ on the parent of this object raised an error */ + PyErr_Clear(); + pydict = PyDict_New(); + } + + if(meth) { + for (; meth->ml_name != NULL; meth++) { + PyDict_SetItemString(pydict, meth->ml_name, Py_None); + } + } + + if(attrdef) { + for (; attrdef->m_name != NULL; attrdef++) { + PyDict_SetItemString(pydict, attrdef->m_name, Py_None); + } + } + + return pydict; +} + #endif //NO_EXP_PYTHON_EMBEDDING diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 37eae3a8c61..1a5f50a3d23 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -89,35 +89,22 @@ static inline void Py_Fatal(const char *M) { virtual PyParentObject *GetParents(void) {return Parents;} + // This defines the _getattr_up macro // which allows attribute and method calls // to be properly passed up the hierarchy. #define _getattr_up(Parent) \ - PyObject *rvalue = NULL; \ - if (!strcmp(attr, "__methods__")) { \ - PyObject *_attr_string = NULL; \ - PyMethodDef *meth = Methods; \ - rvalue = Parent::_getattr(attr); \ - if (rvalue==NULL) { \ - PyErr_Clear(); \ - rvalue = PyList_New(0); \ - } \ - if (meth) { \ - for (; meth->ml_name != NULL; meth++) { \ - _attr_string = PyString_FromString(meth->ml_name); \ - PyList_Append(rvalue, _attr_string); \ - Py_DECREF(_attr_string); \ - } \ + PyObject *rvalue = Py_FindMethod(Methods, this, attr); \ + \ + if (rvalue == NULL) { \ + PyErr_Clear(); \ + rvalue = Parent::_getattr(attr); \ } \ - } else { \ - rvalue = Py_FindMethod(Methods, this, attr); \ - if (rvalue == NULL) { \ - PyErr_Clear(); \ - rvalue = Parent::_getattr(attr); \ - } \ - } \ - return rvalue; \ - + if ((rvalue == NULL) && !strcmp(attr, "__dict__")) {\ + PyErr_Clear(); \ + rvalue = _getattr_dict(Parent::_getattr(attr), Methods, Attributes); \ + } \ + return rvalue; \ /** * These macros are helpfull when embedding Python routines. The second @@ -398,6 +385,8 @@ public: } }; +PyObject *_getattr_dict(PyObject *pydict, PyMethodDef *meth, PyAttributeDef *attrdef); + #endif // _adr_py_lib_h_ #endif //NO_EXP_PYTHON_EMBEDDING diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index 9b26cda01b3..d29e3961c65 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -673,6 +673,10 @@ static PyMethodDef CValueMethods[] = { NULL,NULL} // Sentinel }; +PyAttributeDef CValue::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* CValue::_getattr(const char *attr) { diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp index 6fcb1be654c..7bf051f2b5c 100644 --- a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp +++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp @@ -113,6 +113,9 @@ PyMethodDef SCA_2DFilterActuator::Methods[] = { {NULL,NULL} }; +PyAttributeDef SCA_2DFilterActuator::Attributes[] = { + { NULL } //Sentinel +}; PyObject* SCA_2DFilterActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); diff --git a/source/gameengine/GameLogic/SCA_ANDController.cpp b/source/gameengine/GameLogic/SCA_ANDController.cpp index 98a3c2e96cd..b67ef7dabaf 100644 --- a/source/gameengine/GameLogic/SCA_ANDController.cpp +++ b/source/gameengine/GameLogic/SCA_ANDController.cpp @@ -137,6 +137,10 @@ PyMethodDef SCA_ANDController::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_ANDController::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* SCA_ANDController::_getattr(const char *attr) { _getattr_up(SCA_IController); } diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp index 76aa328aa48..154f0ad8cef 100644 --- a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp +++ b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp @@ -135,6 +135,10 @@ PyMethodDef SCA_AlwaysSensor::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_AlwaysSensor::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* SCA_AlwaysSensor::_getattr(const char *attr) { _getattr_up(SCA_ISensor); } diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp index e5ca26eac85..d8f5f3eede5 100644 --- a/source/gameengine/GameLogic/SCA_IObject.cpp +++ b/source/gameengine/GameLogic/SCA_IObject.cpp @@ -407,6 +407,9 @@ PyMethodDef SCA_IObject::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_IObject::Attributes[] = { + { NULL } //Sentinel +}; PyObject* SCA_IObject::_getattr(const char *attr) { diff --git a/source/gameengine/GameLogic/SCA_NANDController.cpp b/source/gameengine/GameLogic/SCA_NANDController.cpp index 0efa8da153a..18426d75582 100644 --- a/source/gameengine/GameLogic/SCA_NANDController.cpp +++ b/source/gameengine/GameLogic/SCA_NANDController.cpp @@ -137,6 +137,10 @@ PyMethodDef SCA_NANDController::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_NANDController::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* SCA_NANDController::_getattr(const char *attr) { _getattr_up(SCA_IController); } diff --git a/source/gameengine/GameLogic/SCA_NORController.cpp b/source/gameengine/GameLogic/SCA_NORController.cpp index fa24be9ebce..1de6a641c3d 100644 --- a/source/gameengine/GameLogic/SCA_NORController.cpp +++ b/source/gameengine/GameLogic/SCA_NORController.cpp @@ -137,6 +137,10 @@ PyMethodDef SCA_NORController::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_NORController::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* SCA_NORController::_getattr(const char *attr) { _getattr_up(SCA_IController); } diff --git a/source/gameengine/GameLogic/SCA_ORController.cpp b/source/gameengine/GameLogic/SCA_ORController.cpp index 42a29e1959b..61fbc889d90 100644 --- a/source/gameengine/GameLogic/SCA_ORController.cpp +++ b/source/gameengine/GameLogic/SCA_ORController.cpp @@ -129,6 +129,11 @@ PyMethodDef SCA_ORController::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_ORController::Attributes[] = { + { NULL } //Sentinel +}; + + PyObject* SCA_ORController::_getattr(const char *attr) { _getattr_up(SCA_IController); } diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 92852ee03cb..c75e36acab2 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -264,6 +264,9 @@ PyMethodDef SCA_PythonController::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_PythonController::Attributes[] = { + { NULL } //Sentinel +}; bool SCA_PythonController::Compile() { diff --git a/source/gameengine/GameLogic/SCA_XNORController.cpp b/source/gameengine/GameLogic/SCA_XNORController.cpp index b019aedc93d..b2734dd1b33 100644 --- a/source/gameengine/GameLogic/SCA_XNORController.cpp +++ b/source/gameengine/GameLogic/SCA_XNORController.cpp @@ -141,6 +141,10 @@ PyMethodDef SCA_XNORController::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_XNORController::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* SCA_XNORController::_getattr(const char *attr) { _getattr_up(SCA_IController); } diff --git a/source/gameengine/GameLogic/SCA_XORController.cpp b/source/gameengine/GameLogic/SCA_XORController.cpp index 11ffa19b8f1..662ef523d56 100644 --- a/source/gameengine/GameLogic/SCA_XORController.cpp +++ b/source/gameengine/GameLogic/SCA_XORController.cpp @@ -141,6 +141,10 @@ PyMethodDef SCA_XORController::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef SCA_XORController::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* SCA_XORController::_getattr(const char *attr) { _getattr_up(SCA_IController); } diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index e8281201d24..60cb288436a 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -767,6 +767,9 @@ PyMethodDef BL_Shader::Methods[] = {NULL,NULL} //Sentinel }; +PyAttributeDef BL_Shader::Attributes[] = { + { NULL } //Sentinel +}; PyTypeObject BL_Shader::Type = { PyObject_HEAD_INIT(&PyType_Type) diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp index 31f1d2dd3ee..4e5f27df2da 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp @@ -143,6 +143,10 @@ PyMethodDef KX_NetworkMessageActuator::Methods[] = { {NULL,NULL} // Sentinel }; +PyAttributeDef KX_NetworkMessageActuator::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* KX_NetworkMessageActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp index cb9956d4616..ac89d8b0716 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp @@ -213,6 +213,10 @@ PyMethodDef KX_NetworkMessageSensor::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_NetworkMessageSensor::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* KX_NetworkMessageSensor::_getattr(const char *attr) { _getattr_up(SCA_ISensor); // implicit return! } diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index 5fa19924267..b9bd7647f89 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -748,6 +748,9 @@ PyMethodDef KX_BlenderMaterial::Methods[] = {NULL,NULL} //Sentinel }; +PyAttributeDef KX_BlenderMaterial::Attributes[] = { + { NULL } //Sentinel +}; PyTypeObject KX_BlenderMaterial::Type = { PyObject_HEAD_INIT(&PyType_Type) diff --git a/source/gameengine/Ketsji/KX_CDActuator.cpp b/source/gameengine/Ketsji/KX_CDActuator.cpp index 7d238e28add..ef7883910fd 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.cpp +++ b/source/gameengine/Ketsji/KX_CDActuator.cpp @@ -197,7 +197,9 @@ PyMethodDef KX_CDActuator::Methods[] = { {NULL,NULL,NULL,NULL} //Sentinel }; - +PyAttributeDef KX_CDActuator::Attributes[] = { + { NULL } //Sentinel +}; PyObject* KX_CDActuator::_getattr(const char *attr) { diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index 99e2d3b7c06..5caac2fc670 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -483,6 +483,10 @@ PyMethodDef KX_Camera::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_Camera::Attributes[] = { + { NULL } //Sentinel +}; + char KX_Camera::doc[] = "Module KX_Camera\n\n" "Constants:\n" "\tINSIDE\n" diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index 8a7ff41dfa6..fba9544d702 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -612,6 +612,10 @@ PyMethodDef KX_ConstraintActuator::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_ConstraintActuator::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* KX_ConstraintActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp index 9ceb4a05b06..f014c1896fe 100644 --- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp @@ -130,3 +130,7 @@ PyMethodDef KX_ConstraintWrapper::Methods[] = { {"getConstraintId",(PyCFunction) KX_ConstraintWrapper::sPyGetConstraintId, METH_VARARGS}, {NULL,NULL} //Sentinel }; + +PyAttributeDef KX_ConstraintWrapper::Attributes[] = { + { NULL } //Sentinel +}; diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp index 3090c668f03..3c0695b5952 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.cpp +++ b/source/gameengine/Ketsji/KX_GameActuator.cpp @@ -246,6 +246,10 @@ PyMethodDef KX_GameActuator::Methods[] = {NULL,NULL} //Sentinel }; +PyAttributeDef KX_GameActuator::Attributes[] = { + { NULL } //Sentinel +}; + /* getFile */ const char KX_GameActuator::GetFile_doc[] = "getFile()\n" diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 9c6bd2edf0e..95df9d51a26 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1033,6 +1033,9 @@ PyMethodDef KX_GameObject::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_GameObject::Attributes[] = { + { NULL } //Sentinel +}; /* diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index ca8419666b5..623a939bf62 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -457,6 +457,10 @@ PyMethodDef KX_IpoActuator::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_IpoActuator::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* KX_IpoActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp index 36700265260..a2e93ecdd36 100644 --- a/source/gameengine/Ketsji/KX_Light.cpp +++ b/source/gameengine/Ketsji/KX_Light.cpp @@ -301,6 +301,10 @@ PyMethodDef KX_LightObject::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_LightObject::Attributes[] = { + { NULL } //Sentinel +}; + char KX_LightObject::doc[] = "Module KX_LightObject\n\n" "Constants:\n" "\tSPOT\n" diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index 4b949903c88..a0c0a496c06 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -86,6 +86,10 @@ KX_PYMETHODTABLE(KX_MeshProxy, reinstancePhysicsMesh), {NULL,NULL} //Sentinel }; +PyAttributeDef KX_MeshProxy::Attributes[] = { + { NULL } //Sentinel +}; + void KX_MeshProxy::SetMeshModified(bool v) { m_meshobj->SetMeshModified(v); diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index afe4cd1e2a4..384034485e7 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -332,6 +332,10 @@ PyMethodDef KX_MouseFocusSensor::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_MouseFocusSensor::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* KX_MouseFocusSensor::_getattr(const char *attr) { _getattr_up(SCA_MouseSensor); } diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index d859f670b07..066387abb93 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -318,6 +318,9 @@ PyMethodDef KX_NearSensor::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_NearSensor::Attributes[] = { + { NULL } //Sentinel +}; PyObject* KX_NearSensor::_getattr(const char *attr) diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index b647c72fc10..0666261b470 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -332,6 +332,10 @@ PyMethodDef KX_ObjectActuator::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_ObjectActuator::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* KX_ObjectActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); }; diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index 5a908186235..84d7ccb9c05 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -172,6 +172,10 @@ PyMethodDef KX_ParentActuator::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_ParentActuator::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* KX_ParentActuator::_getattr(const char *attr) { if (!strcmp(attr, "object")) { diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp index ff962d57c9d..b4bdd77fb66 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.cpp +++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp @@ -77,6 +77,10 @@ PyMethodDef KX_PolyProxy::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_PolyProxy::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* KX_PolyProxy::_getattr(const char *attr) { if (!strcmp(attr, "matname")) diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index 52c5b013e65..bbaf697b168 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -180,6 +180,9 @@ PyMethodDef KX_PolygonMaterial::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_PolygonMaterial::Attributes[] = { + { NULL } //Sentinel +}; PyTypeObject KX_PolygonMaterial::Type = { PyObject_HEAD_INIT(&PyType_Type) diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp index 2ba1126a633..c347faaee1a 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.cpp +++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp @@ -230,6 +230,10 @@ PyMethodDef KX_RadarSensor::Methods[] = { {NULL,NULL,NULL,NULL} //Sentinel }; +PyAttributeDef KX_RadarSensor::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* KX_RadarSensor::_getattr(const char *attr) { _getattr_up(KX_TouchSensor); } diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index c7cb53f64ed..ce12b983147 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -343,6 +343,10 @@ PyMethodDef KX_RaySensor::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_RaySensor::Attributes[] = { + { NULL } //Sentinel +}; + const char KX_RaySensor::GetHitObject_doc[] = "getHitObject()\n" "\tReturns the name of the object that was hit by this ray.\n"; diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index 017ab5d6c97..68b704f4889 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -204,6 +204,9 @@ PyMethodDef KX_SCA_AddObjectActuator::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_SCA_AddObjectActuator::Attributes[] = { + { NULL } //Sentinel +}; PyObject* KX_SCA_AddObjectActuator::_getattr(const char *attr) { diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp index 1aba05c1d83..394bb667728 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp @@ -85,6 +85,9 @@ PyMethodDef KX_SCA_DynamicActuator::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_SCA_DynamicActuator::Attributes[] = { + { NULL } //Sentinel +}; PyObject* KX_SCA_DynamicActuator::_getattr(const char *attr) diff --git a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp index 443921d22b0..9268a1df5f0 100644 --- a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp @@ -127,6 +127,9 @@ PyMethodDef KX_SCA_EndObjectActuator::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_SCA_EndObjectActuator::Attributes[] = { + { NULL } //Sentinel +}; PyObject* KX_SCA_EndObjectActuator::_getattr(const char *attr) { diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index ccc3b8fdb18..502990b2b27 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -89,7 +89,9 @@ PyMethodDef KX_SCA_ReplaceMeshActuator::Methods[] = { {NULL,NULL} //Sentinel }; - +PyAttributeDef KX_SCA_ReplaceMeshActuator::Attributes[] = { + { NULL } //Sentinel +}; PyObject* KX_SCA_ReplaceMeshActuator::_getattr(const char *attr) { diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 5ae1abc6a89..073cfc98bf1 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1525,6 +1525,10 @@ PyMethodDef KX_Scene::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_Scene::Attributes[] = { + { NULL } //Sentinel +}; + PyTypeObject KX_Scene::Type = { PyObject_HEAD_INIT(&PyType_Type) 0, diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index 8e33177cf3a..1cad4e21352 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -268,7 +268,9 @@ PyMethodDef KX_SceneActuator::Methods[] = {NULL,NULL} //Sentinel }; - +PyAttributeDef KX_SceneActuator::Attributes[] = { + { NULL } //Sentinel +}; PyObject* KX_SceneActuator::_getattr(const char *attr) { diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index 562c096d440..6de1d67bfdb 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -285,7 +285,9 @@ PyMethodDef KX_SoundActuator::Methods[] = { {NULL,NULL,NULL,NULL} //Sentinel }; - +PyAttributeDef KX_SoundActuator::Attributes[] = { + { NULL } //Sentinel +}; PyObject* KX_SoundActuator::_getattr(const char *attr) { diff --git a/source/gameengine/Ketsji/KX_StateActuator.cpp b/source/gameengine/Ketsji/KX_StateActuator.cpp index cd5c5d29ab1..0de4da79bd8 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.cpp +++ b/source/gameengine/Ketsji/KX_StateActuator.cpp @@ -146,6 +146,10 @@ KX_StateActuator::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_StateActuator::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* KX_StateActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 9d4fa14ad8e..8637bc92d39 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -468,6 +468,9 @@ PyMethodDef KX_TrackToActuator::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_TrackToActuator::Attributes[] = { + { NULL } //Sentinel +}; PyObject* KX_TrackToActuator::_getattr(const char *attr) diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp index 057e10f195a..8d5af1b9216 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp @@ -382,3 +382,6 @@ PyMethodDef KX_VehicleWrapper::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_VehicleWrapper::Attributes[] = { + { NULL } //Sentinel +}; diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp index 1c427768b66..da0e3dbdd8d 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.cpp +++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp @@ -78,6 +78,10 @@ PyMethodDef KX_VertexProxy::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_VertexProxy::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* KX_VertexProxy::_getattr(const char *attr) { diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp index ca89a63de62..0ec280080bd 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp @@ -126,6 +126,10 @@ KX_VisibilityActuator::Methods[] = { {NULL,NULL} //Sentinel }; +PyAttributeDef KX_VisibilityActuator::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* KX_VisibilityActuator::_getattr(const char *attr) { _getattr_up(SCA_IActuator); -- cgit v1.2.3 From 8d3dcfb104bcfc4fa9fdfecaa8e5c8fd9a900e98 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 27 Feb 2009 23:53:09 +0000 Subject: BGE Python API * Scene's and GameObjects can now be printed (raised an exception) * Added GameLogic.getSceneList() --- source/gameengine/Ketsji/KX_GameObject.h | 3 ++- source/gameengine/Ketsji/KX_PythonInit.cpp | 28 ++++++++++++++++++++++++++++ source/gameengine/Ketsji/KX_Scene.h | 2 ++ 3 files changed, 32 insertions(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index d95e3751d33..211c9b7ca7d 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -758,7 +758,8 @@ public: virtual PyObject* _getattr(const char *attr); virtual int _setattr(const char *attr, PyObject *value); // _setattr method - + virtual PyObject* _repr(void) { return PyString_FromString(GetName().ReadPtr()); } + KX_PYMETHOD_NOARGS(KX_GameObject,GetPosition); KX_PYMETHOD_O(KX_GameObject,SetPosition); KX_PYMETHOD_O(KX_GameObject,SetWorldPosition); diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index b3e8d15189f..93f57986181 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -329,6 +329,32 @@ static PyObject* gPyGetCurrentScene(PyObject* self) return (PyObject*) gp_KetsjiScene; } +static STR_String gPyGetSceneList_doc = +"getSceneList()\n" +"Return a list of converted scenes.\n"; +static PyObject* gPyGetSceneList(PyObject* self) +{ + KX_KetsjiEngine* m_engine = KX_GetActiveEngine(); + //CListValue* list = new CListValue(); + PyObject* list; + KX_SceneList* scenes = m_engine->CurrentScenes(); + int numScenes = scenes->size(); + int i; + + list = PyList_New(numScenes); + + for (i=0;iat(i); + //list->Add(scene); + PyList_SET_ITEM(list, i, scene); + Py_INCREF(scene); + + } + + return (PyObject*)list; +} + static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *) { #define pprint(x) std::cout << x << std::endl; @@ -408,6 +434,8 @@ static struct PyMethodDef game_methods[] = { METH_NOARGS, (PY_METHODCHAR)SCA_PythonController::sPyGetCurrentController__doc__}, {"getCurrentScene", (PyCFunction) gPyGetCurrentScene, METH_NOARGS, (PY_METHODCHAR)gPyGetCurrentScene_doc.Ptr()}, + {"getSceneList", (PyCFunction) gPyGetSceneList, + METH_NOARGS, (PY_METHODCHAR)gPyGetSceneList_doc.Ptr()}, {"addActiveActuator",(PyCFunction) SCA_PythonController::sPyAddActiveActuator, METH_VARARGS, (PY_METHODCHAR)SCA_PythonController::sPyAddActiveActuator__doc__}, {"getRandomFloat",(PyCFunction) gPyGetRandomFloat, diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index e4d4b6fe2cd..e49a87b0402 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -567,7 +567,9 @@ public: virtual PyObject* _getattr(const char *attr); /* name, active_camera, gravity, suspended, viewport, framing, activity_culling, activity_culling_radius */ virtual int _setattr(const char *attr, PyObject *pyvalue); virtual int _delattr(const char *attr); + virtual PyObject* _repr(void) { return PyString_FromString(GetName().ReadPtr()); } + /** * Sets the time the scene was suspended */ -- cgit v1.2.3 From 6c409ed541d84b662d16ee34e9128cc64d27d0d8 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sat, 28 Feb 2009 21:00:27 +0000 Subject: BGE API cleanup: apply patch from Moguri: Near, Radar, Touch sensor updated. --- source/gameengine/Ketsji/KX_NearSensor.cpp | 41 +++++++--- source/gameengine/Ketsji/KX_NearSensor.h | 27 +++++-- source/gameengine/Ketsji/KX_PythonInit.cpp | 9 +++ source/gameengine/Ketsji/KX_RadarSensor.cpp | 119 ++++++++++++++++++++-------- source/gameengine/Ketsji/KX_RadarSensor.h | 22 +++-- source/gameengine/Ketsji/KX_TouchSensor.cpp | 9 ++- source/gameengine/Ketsji/KX_TouchSensor.h | 2 + source/gameengine/PyDoc/GameLogic.py | 8 ++ source/gameengine/PyDoc/KX_NearSensor.py | 5 ++ source/gameengine/PyDoc/KX_RadarSensor.py | 18 +++++ source/gameengine/PyDoc/KX_Scene.py | 13 +++ source/gameengine/PyDoc/KX_TouchSensor.py | 19 +++-- 12 files changed, 226 insertions(+), 66 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index 066387abb93..993a6b3d86c 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -42,8 +42,8 @@ #endif KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr, KX_GameObject* gameobj, - double margin, - double resetmargin, + float margin, + float resetmargin, bool bFindMaterial, const STR_String& touchedpropname, class KX_Scene* scene, @@ -276,8 +276,16 @@ bool KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData } +/* ------------------------------------------------------------------------- */ +/* Python Functions */ +/* ------------------------------------------------------------------------- */ + +//No methods + +/* ------------------------------------------------------------------------- */ +/* Python Integration Hooks */ +/* ------------------------------------------------------------------------- */ -// python embedding PyTypeObject KX_NearSensor::Type = { PyObject_HEAD_INIT(&PyType_Type) 0, @@ -311,20 +319,31 @@ PyParentObject KX_NearSensor::Parents[] = { PyMethodDef KX_NearSensor::Methods[] = { - {"setProperty", (PyCFunction) KX_NearSensor::sPySetProperty, METH_O, (PY_METHODCHAR)SetProperty_doc}, - {"getProperty", (PyCFunction) KX_NearSensor::sPyGetProperty, METH_NOARGS, (PY_METHODCHAR)GetProperty_doc}, - {"getHitObject",(PyCFunction) KX_NearSensor::sPyGetHitObject, METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc}, - {"getHitObjectList", (PyCFunction) KX_NearSensor::sPyGetHitObjectList, METH_NOARGS, (PY_METHODCHAR)GetHitObjectList_doc}, + //No methods {NULL,NULL} //Sentinel }; PyAttributeDef KX_NearSensor::Attributes[] = { - { NULL } //Sentinel + KX_PYATTRIBUTE_FLOAT_RW_CHECK("distance", 0, 100, KX_NearSensor, m_Margin, CheckResetDistance), + KX_PYATTRIBUTE_FLOAT_RW_CHECK("resetDistance", 0, 100, KX_NearSensor, m_ResetMargin, CheckResetDistance), + {NULL} //Sentinel }; -PyObject* -KX_NearSensor::_getattr(const char *attr) + +PyObject* KX_NearSensor::_getattr(const char *attr) { - _getattr_up(KX_TouchSensor); + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + + _getattr_up(KX_TouchSensor); } +int KX_NearSensor::_setattr(const char *attr, PyObject* value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + + return KX_TouchSensor::_setattr(attr, value); +} diff --git a/source/gameengine/Ketsji/KX_NearSensor.h b/source/gameengine/Ketsji/KX_NearSensor.h index 58c7cc7da91..ee03992e734 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.h +++ b/source/gameengine/Ketsji/KX_NearSensor.h @@ -42,15 +42,15 @@ class KX_NearSensor : public KX_TouchSensor { Py_Header; protected: - double m_Margin; - double m_ResetMargin; + float m_Margin; + float m_ResetMargin; KX_Scene* m_scene; KX_ClientObjectInfo* m_client_info; public: KX_NearSensor(class SCA_EventManager* eventmgr, class KX_GameObject* gameobj, - double margin, - double resetmargin, + float margin, + float resetmargin, bool bFindMaterial, const STR_String& touchedpropname, class KX_Scene* scene, @@ -78,8 +78,25 @@ public: virtual bool BroadPhaseFilterCollision(void*obj1,void*obj2); virtual void RegisterSumo(KX_TouchEventManager *touchman); virtual void UnregisterSumo(KX_TouchEventManager* touchman); - + + /* --------------------------------------------------------------------- */ + /* Python interface ---------------------------------------------------- */ + /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject* value); + + //No methods + + //This method is used to make sure the distance does not exceed the reset distance + static int CheckResetDistance(void *self, const PyAttributeDef*) + { + KX_NearSensor* sensor = reinterpret_cast(self); + + if (sensor->m_Margin > sensor->m_ResetMargin) + sensor->m_ResetMargin = sensor->m_Margin; + + return 0; + } }; diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 93f57986181..d974d67bf33 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -47,6 +47,7 @@ #include "KX_PyConstraintBinding.h" #include "KX_KetsjiEngine.h" +#include "KX_RadarSensor.h" #include "SCA_IInputDevice.h" #include "SCA_PropertySensor.h" @@ -1060,6 +1061,14 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, KX_STATE29, (1<<28)); KX_MACRO_addTypesToDict(d, KX_STATE30, (1<<29)); + /* Radar Sensor */ + KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_X, KX_RadarSensor::KX_RADAR_AXIS_POS_X); + KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_Y, KX_RadarSensor::KX_RADAR_AXIS_POS_Y); + KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_Z, KX_RadarSensor::KX_RADAR_AXIS_POS_Z); + KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_X, KX_RadarSensor::KX_RADAR_AXIS_NEG_Y); + KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_Y, KX_RadarSensor::KX_RADAR_AXIS_NEG_X); + KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_Z, KX_RadarSensor::KX_RADAR_AXIS_NEG_Z); + // Check for errors if (PyErr_Occurred()) { diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp index c347faaee1a..fa8998cd81d 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.cpp +++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp @@ -171,8 +171,18 @@ void KX_RadarSensor::SynchronizeTransform() { } } - m_cone_origin = trans.getOrigin(); - m_cone_target = trans(MT_Point3(0, -m_coneheight/2.0 ,0)); + + //Using a temp variable to translate MT_Point3 to float[3]. + //float[3] works better for the Python interface. + MT_Point3 temp = trans.getOrigin(); + m_cone_origin[0] = temp[0]; + m_cone_origin[1] = temp[1]; + m_cone_origin[2] = temp[2]; + + temp = trans(MT_Point3(0, -m_coneheight/2.0 ,0)); + m_cone_target[0] = temp[0]; + m_cone_target[1] = temp[1]; + m_cone_target[2] = temp[2]; if (m_physCtrl) @@ -187,10 +197,58 @@ void KX_RadarSensor::SynchronizeTransform() } /* ------------------------------------------------------------------------- */ -/* Python functions */ +/* Python Functions */ /* ------------------------------------------------------------------------- */ -/* Integration hooks ------------------------------------------------------- */ +//Deprecated -----> +/* getConeOrigin */ +const char KX_RadarSensor::GetConeOrigin_doc[] = +"getConeOrigin()\n" +"\tReturns the origin of the cone with which to test. The origin\n" +"\tis in the middle of the cone."; +PyObject* KX_RadarSensor::PyGetConeOrigin(PyObject* self) { + ShowDeprecationWarning("getConeOrigin()", "the coneOrigin property"); + + PyObject *retVal = PyList_New(3); + + PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_cone_origin[0])); + PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_cone_origin[1])); + PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_cone_origin[2])); + + return retVal; +} + +/* getConeOrigin */ +const char KX_RadarSensor::GetConeTarget_doc[] = +"getConeTarget()\n" +"\tReturns the center of the bottom face of the cone with which to test.\n"; +PyObject* KX_RadarSensor::PyGetConeTarget(PyObject* self) { + ShowDeprecationWarning("getConeTarget()", "the coneTarget property"); + + PyObject *retVal = PyList_New(3); + + PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_cone_target[0])); + PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_cone_target[1])); + PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_cone_target[2])); + + return retVal; +} + +/* getConeHeight */ +const char KX_RadarSensor::GetConeHeight_doc[] = +"getConeHeight()\n" +"\tReturns the height of the cone with which to test.\n"; +PyObject* KX_RadarSensor::PyGetConeHeight(PyObject* self) { + + ShowDeprecationWarning("getConeHeight()", "the distance property"); + + return PyFloat_FromDouble(m_coneheight); +} +//<----- Deprecated + +/* ------------------------------------------------------------------------- */ +/* Python Integration Hooks */ +/* ------------------------------------------------------------------------- */ PyTypeObject KX_RadarSensor::Type = { PyObject_HEAD_INIT(&PyType_Type) 0, @@ -221,46 +279,39 @@ PyParentObject KX_RadarSensor::Parents[] = { }; PyMethodDef KX_RadarSensor::Methods[] = { + //Deprecated -----> {"getConeOrigin", (PyCFunction) KX_RadarSensor::sPyGetConeOrigin, - METH_NOARGS, (PY_METHODCHAR)GetConeOrigin_doc}, + METH_VARARGS, (PY_METHODCHAR)GetConeOrigin_doc}, {"getConeTarget", (PyCFunction) KX_RadarSensor::sPyGetConeTarget, - METH_NOARGS, (PY_METHODCHAR)GetConeTarget_doc}, + METH_VARARGS, (PY_METHODCHAR)GetConeTarget_doc}, {"getConeHeight", (PyCFunction) KX_RadarSensor::sPyGetConeHeight, - METH_NOARGS, (PY_METHODCHAR)GetConeHeight_doc}, - {NULL,NULL,NULL,NULL} //Sentinel + METH_VARARGS, (PY_METHODCHAR)GetConeHeight_doc}, + //<----- + {NULL} //Sentinel }; PyAttributeDef KX_RadarSensor::Attributes[] = { - { NULL } //Sentinel + KX_PYATTRIBUTE_FLOAT_ARRAY_RO("coneOrigin", KX_RadarSensor, m_cone_origin, 3), + KX_PYATTRIBUTE_FLOAT_ARRAY_RO("coneTarget", KX_RadarSensor, m_cone_target, 3), + KX_PYATTRIBUTE_FLOAT_RW("angle", 0, 360, KX_RadarSensor, m_coneradius), + KX_PYATTRIBUTE_INT_RW("axis", 0, 5, true, KX_RadarSensor, m_axis), + {NULL} //Sentinel }; -PyObject* KX_RadarSensor::_getattr(const char *attr) { - _getattr_up(KX_TouchSensor); -} +PyObject* KX_RadarSensor::_getattr(const char *attr) +{ + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; -/* getConeOrigin */ -const char KX_RadarSensor::GetConeOrigin_doc[] = -"getConeOrigin()\n" -"\tReturns the origin of the cone with which to test. The origin\n" -"\tis in the middle of the cone."; -PyObject* KX_RadarSensor::PyGetConeOrigin(PyObject* self) { - return PyObjectFrom(m_cone_origin); + _getattr_up(KX_NearSensor); } -/* getConeOrigin */ -const char KX_RadarSensor::GetConeTarget_doc[] = -"getConeTarget()\n" -"\tReturns the center of the bottom face of the cone with which to test.\n"; -PyObject* KX_RadarSensor::PyGetConeTarget(PyObject* self) { - return PyObjectFrom(m_cone_target); -} +int KX_RadarSensor::_setattr(const char *attr, PyObject* value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; -/* getConeOrigin */ -const char KX_RadarSensor::GetConeHeight_doc[] = -"getConeHeight()\n" -"\tReturns the height of the cone with which to test.\n"; -PyObject* KX_RadarSensor::PyGetConeHeight(PyObject* self) { - return PyFloat_FromDouble(m_coneheight); + return KX_NearSensor::_setattr(attr, value); } - - diff --git a/source/gameengine/Ketsji/KX_RadarSensor.h b/source/gameengine/Ketsji/KX_RadarSensor.h index e4c6d73f22d..6dfe0c42f5d 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.h +++ b/source/gameengine/Ketsji/KX_RadarSensor.h @@ -40,23 +40,23 @@ class KX_RadarSensor : public KX_NearSensor protected: Py_Header; - MT_Scalar m_coneradius; + float m_coneradius; /** * Height of the cone. */ - MT_Scalar m_coneheight; + float m_coneheight; int m_axis; /** * The previous position of the origin of the cone. */ - MT_Point3 m_cone_origin; + float m_cone_origin[3]; /** * The previous direction of the cone (origin to bottom plane). */ - MT_Point3 m_cone_target; + float m_cone_target[3]; public: @@ -80,13 +80,23 @@ public: /* --------------------------------------------------------------------- */ /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - + enum RadarAxis { + KX_RADAR_AXIS_POS_X = 0, + KX_RADAR_AXIS_POS_Y, + KX_RADAR_AXIS_POS_Z, + KX_RADAR_AXIS_NEG_X, + KX_RADAR_AXIS_NEG_Y, + KX_RADAR_AXIS_NEG_Z + }; + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject* value); + //Deprecated -----> KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeOrigin); KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeTarget); KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeHeight); - + //<----- }; #endif //__KX_RADAR_SENSOR_H diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 32fcc148395..705b54edd37 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -269,6 +269,7 @@ PyParentObject KX_TouchSensor::Parents[] = { }; PyMethodDef KX_TouchSensor::Methods[] = { + //Deprecated -----> {"setProperty", (PyCFunction) KX_TouchSensor::sPySetProperty, METH_O, (PY_METHODCHAR)SetProperty_doc}, {"getProperty", @@ -277,12 +278,13 @@ PyMethodDef KX_TouchSensor::Methods[] = { (PyCFunction) KX_TouchSensor::sPyGetHitObject, METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc}, {"getHitObjectList", (PyCFunction) KX_TouchSensor::sPyGetHitObjectList, METH_NOARGS, (PY_METHODCHAR)GetHitObjectList_doc}, + //<----- {NULL,NULL} //Sentinel }; PyAttributeDef KX_TouchSensor::Attributes[] = { - KX_PYATTRIBUTE_STRING_RW("propertyName",0,100,false,KX_TouchSensor,m_touchedpropname), - KX_PYATTRIBUTE_BOOL_RW("materialCheck",KX_TouchSensor,m_bFindMaterial), + KX_PYATTRIBUTE_STRING_RW("property",0,100,false,KX_TouchSensor,m_touchedpropname), + KX_PYATTRIBUTE_BOOL_RW("useMaterial",KX_TouchSensor,m_bFindMaterial), KX_PYATTRIBUTE_BOOL_RW("pulseCollisions",KX_TouchSensor,m_bTouchPulse), KX_PYATTRIBUTE_DUMMY("objectHit"), KX_PYATTRIBUTE_DUMMY("objectHitList"), @@ -372,6 +374,9 @@ PyObject* KX_TouchSensor::PyGetHitObjectList(PyObject* self) return m_colliders->AddRef(); } +/*getTouchMaterial and setTouchMaterial were never added to the api, +they can probably be removed with out anyone noticing*/ + /* 5. getTouchMaterial */ const char KX_TouchSensor::GetTouchMaterial_doc[] = "getTouchMaterial()\n" diff --git a/source/gameengine/Ketsji/KX_TouchSensor.h b/source/gameengine/Ketsji/KX_TouchSensor.h index c523736967b..18ce9406a9b 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.h +++ b/source/gameengine/Ketsji/KX_TouchSensor.h @@ -123,6 +123,7 @@ public: virtual PyObject* _getattr(const char *attr); virtual int _setattr(const char *attr, PyObject *value); + //Deprecated -----> /* 1. setProperty */ KX_PYMETHOD_DOC_O(KX_TouchSensor,SetProperty); /* 2. getProperty */ @@ -137,6 +138,7 @@ public: /* 6. setTouchMaterial */ KX_PYMETHOD_DOC_O(KX_TouchSensor,SetTouchMaterial); #endif + //<----- }; diff --git a/source/gameengine/PyDoc/GameLogic.py b/source/gameengine/PyDoc/GameLogic.py index f743acf06fe..0524a9df355 100644 --- a/source/gameengine/PyDoc/GameLogic.py +++ b/source/gameengine/PyDoc/GameLogic.py @@ -140,6 +140,14 @@ Documentation for the GameLogic Module. @var KX_SOUNDACT_LOOPEND: See L{KX_SoundActuator} @var KX_SOUNDACT_LOOPBIDIRECTIONAL: See L{KX_SoundActuator} @var KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: See L{KX_SoundActuator} + +@group Radar Sensor: KX_RADAR_AXIS_POS_X, KX_RADAR_AXIS_POS_Y, KX_RADAR_AXIS_POS_Z, KX_RADAR_AXIS_NEG_X, KX_RADAR_AXIS_NEG_Y, KX_RADAR_AXIS_NEG_Z +@var KX_RADAR_AXIS_POS_X: See L{KX_RadarSensor} +@var KX_RADAR_AXIS_POS_Y: See L{KX_RadarSensor} +@var KX_RADAR_AXIS_POS_Z: See L{KX_RadarSensor} +@var KX_RADAR_AXIS_NEG_X: See L{KX_RadarSensor} +@var KX_RADAR_AXIS_NEG_Y: See L{KX_RadarSensor} +@var KX_RADAR_AXIS_NEG_Z: See L{KX_RadarSensor} """ diff --git a/source/gameengine/PyDoc/KX_NearSensor.py b/source/gameengine/PyDoc/KX_NearSensor.py index fef2e4b2acc..a8c408827fe 100644 --- a/source/gameengine/PyDoc/KX_NearSensor.py +++ b/source/gameengine/PyDoc/KX_NearSensor.py @@ -5,5 +5,10 @@ from KX_TouchSensor import * class KX_NearSensor(KX_TouchSensor): """ A near sensor is a specialised form of touch sensor. + + @ivar distance: The near sensor activates when an object is within this distance. + @type distance: float + @ivar resetDistance: The near sensor deactivates when the object exceeds this distance. + @type resetDistance: float """ diff --git a/source/gameengine/PyDoc/KX_RadarSensor.py b/source/gameengine/PyDoc/KX_RadarSensor.py index 64be858371a..b68bf4ea0f3 100644 --- a/source/gameengine/PyDoc/KX_RadarSensor.py +++ b/source/gameengine/PyDoc/KX_RadarSensor.py @@ -5,8 +5,26 @@ from KX_NearSensor import * class KX_RadarSensor(KX_NearSensor): """ Radar sensor is a near sensor with a conical sensor object. + + @ivar coneOrigin: The origin of the cone with which to test. The origin + is in the middle of the cone. + (Read only) + @type coneOrigin: list of floats [x, y, z] + @ivar coneTarget: The center of the bottom face of the cone with which to test. + (Read only) + @type coneTarget: list of floats [x, y, z] + @ivar distance: The height of the cone with which to test. + @type distance: float + @ivar angle: The angle of the cone (in degrees) with which to test. + @type angle: float from 0 to 360 + @ivar axis: The axis on which the radar cone is cast + @type axis: int from 0 to 5 + KX_RADAR_AXIS_POS_X, KX_RADAR_AXIS_POS_Y, KX_RADAR_AXIS_POS_Z, + KX_RADAR_AXIS_NEG_X, KX_RADAR_AXIS_NEG_Y, KX_RADAR_AXIS_NEG_Z """ + + #--The following methods are deprecated, please use properties instead. def getConeOrigin(): """ Returns the origin of the cone with which to test. The origin diff --git a/source/gameengine/PyDoc/KX_Scene.py b/source/gameengine/PyDoc/KX_Scene.py index 24b81bbf55e..5e357e6eefc 100644 --- a/source/gameengine/PyDoc/KX_Scene.py +++ b/source/gameengine/PyDoc/KX_Scene.py @@ -70,3 +70,16 @@ class KX_Scene: @rtype: string """ + def addObject(object, other, time=0) + """ + Adds an object to the scene like the Add Object Actuator would, and returns the created object. + + @param object: The object to add + @type object: L{KX_GameObject} or string + @param other: The object's center to use when adding the object + @type other: L{KX_GameObject} or string + @param time: The lifetime of the added object, in frames. A time of 0 means the object will last forever. + @type time: int + + @rtype: L{KX_GameObject} + """ diff --git a/source/gameengine/PyDoc/KX_TouchSensor.py b/source/gameengine/PyDoc/KX_TouchSensor.py index 4f020930c4c..d7277be4c2a 100644 --- a/source/gameengine/PyDoc/KX_TouchSensor.py +++ b/source/gameengine/PyDoc/KX_TouchSensor.py @@ -7,10 +7,11 @@ class KX_TouchSensor(SCA_ISensor): """ Touch sensor detects collisions between objects. - @ivar propertyName: The name of the property or material this sensor detects (depending on the materialCheck property). - @type propertyName: string - @ivar materialCheck: when enabled this sensor checks for object materials rather then properties. - @type materialCheck: bool + @ivar property: The property or material to collide with. + @type property: string + @ivar useMaterial: Determines if the sensor is looking for a property or material. + KX_True = Find material; KX_False = Find property + @type useMaterial: boolean @ivar pulseCollisions: The last collided object. @type pulseCollisions: bool @ivar objectHit: The last collided object. (Read Only) @@ -18,24 +19,26 @@ class KX_TouchSensor(SCA_ISensor): @ivar objectHitList: A list of colliding objects. (Read Only) @type objectHitList: list """ + + #--The following methods are deprecated, please use properties instead. def setProperty(name): """ - DEPRECATED: use the propertyName property + DEPRECATED: use the property property Set the property or material to collide with. Use setTouchMaterial() to switch between properties and materials. @type name: string """ + def getProperty(): """ - DEPRECATED: use the propertyName property + DEPRECATED: use the property property Returns the property or material to collide with. Use getTouchMaterial() to find out whether this sensor looks for properties or materials. (B{deprecated}) @rtype: string """ - def getHitObject(): """ DEPRECATED: use the objectHit property @@ -54,7 +57,7 @@ class KX_TouchSensor(SCA_ISensor): """ def getTouchMaterial(): """ - DEPRECATED: use the materialCheck property + DEPRECATED: use the useMaterial property Returns KX_TRUE if this sensor looks for a specific material, KX_FALSE if it looks for a specific property. (B{deprecated}) """ -- cgit v1.2.3 From 56977d62d43f7591ddeef47ff4ff1f0858d5c41f Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sat, 28 Feb 2009 21:44:24 +0000 Subject: BGE patch #18181 commited: Fixing some blenderplayer arguments (-c, -w, -f). --- source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 75 +++++++++++------------- 1 file changed, 34 insertions(+), 41 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 70272d57357..87b6b2450f7 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -162,33 +162,39 @@ void usage(const char* program) consoleoption = ""; #endif - printf("usage: %s [-w l t w h] %s[-g gamengineoptions] " + printf("usage: %s [-w [w h l t]] [-f [fw fh fb ff]] %s[-g gamengineoptions] " "[-s stereomode] filename.blend\n", program, consoleoption); - printf(" -h: Prints this command summary\n"); + printf(" -h: Prints this command summary\n\n"); printf(" -w: display in a window\n"); + printf(" --Optional parameters--\n"); + printf(" w = window width\n"); + printf(" h = window height\n\n"); printf(" l = window left coordinate\n"); printf(" t = window top coordinate\n"); - printf(" w = window width\n"); - printf(" h = window height\n"); + printf(" Note: If w or h is defined, both must be defined.\n"); + printf(" Also, if l or t is defined, all options must be used.\n\n"); printf(" -f: start game in full screen mode\n"); + printf(" --Optional parameters--\n"); printf(" fw = full screen mode pixel width\n"); - printf(" fh = full screen mode pixel height\n"); + printf(" fh = full screen mode pixel height\n\n"); printf(" fb = full screen mode bits per pixel\n"); printf(" ff = full screen mode frequency\n"); + printf(" Note: If fw or fh is defined, both must be defined.\n"); + printf(" Also, if fb is used, fw and fh must be used. ff requires all options.\n\n"); printf(" -s: start player in stereo\n"); printf(" stereomode: hwpageflip (Quad buffered shutter glasses)\n"); printf(" syncdoubling (Above Below)\n"); printf(" sidebyside (Left Right)\n"); printf(" anaglyph (Red-Blue glasses)\n"); printf(" vinterlace (Vertical interlace for autostereo display)\n"); - printf(" depending on the type of stereo you want\n"); + printf(" depending on the type of stereo you want\n\n"); #ifndef _WIN32 - printf(" -i: parent windows ID \n"); + printf(" -i: parent windows ID \n\n"); #endif #ifdef _WIN32 - printf(" -c: keep console window open\n"); + printf(" -c: keep console window open\n\n"); #endif - printf(" -d: turn debugging on\n"); + printf(" -d: turn debugging on\n\n"); printf(" -g: game engine options:\n\n"); printf(" Name Default Description\n"); printf(" ------------------------------------------------------------------------\n"); @@ -200,7 +206,7 @@ void usage(const char* program) printf(" blender_material 0 Enable material settings\n"); printf(" ignore_deprecation_warnings 0 Ignore deprecation warnings\n"); printf("\n"); - printf("example: %s -w 10 10 320 200 -g noaudio c:\\loadtest.blend\n", program); + printf("example: %s -w 320 200 10 10 -g noaudio c:\\loadtest.blend\n", program); printf("example: %s -g show_framerate = 0 c:\\loadtest.blend\n", program); } @@ -431,54 +437,41 @@ int main(int argc, char** argv) G.f |= G_DEBUG; /* std output printf's */ MEM_set_memory_debug(); break; - - case 'p': - // Parse window position and size options - if (argv[i][2] == 0) { - i++; - if ((i + 4) < argc) - { - windowLeft = atoi(argv[i++]); - windowTop = atoi(argv[i++]); - windowWidth = atoi(argv[i++]); - windowHeight = atoi(argv[i++]); - windowParFound = true; - } - else - { - error = true; - printf("error: too few options for window argument.\n"); - } - } else { /* mac specific */ - - if (strncmp(argv[i], "-psn_", 5)==0) - i++; /* skip process serial number */ - } - break; + case 'f': i++; fullScreen = true; fullScreenParFound = true; - if ((i + 2) < argc && argv[i][0] != '-' && argv[i+1][0] != '-') + if ((i + 2) <= argc && argv[i][0] != '-' && argv[i+1][0] != '-') { fullScreenWidth = atoi(argv[i++]); fullScreenHeight = atoi(argv[i++]); - if ((i + 1) < argc && argv[i][0] != '-') + if ((i + 1) <= argc && argv[i][0] != '-') { fullScreenBpp = atoi(argv[i++]); - if ((i + 1) < argc && argv[i][0] != '-') + if ((i + 1) <= argc && argv[i][0] != '-') fullScreenFrequency = atoi(argv[i++]); } } break; case 'w': // Parse window position and size options + i++; + fullScreen = false; + windowParFound = true; + + if ((i + 2) <= argc && argv[i][0] != '-' && argv[i+1][0] != '-') { - fullScreen = false; - fullScreenParFound = true; - i++; + windowWidth = atoi(argv[i++]); + windowHeight = atoi(argv[i++]); + if ((i +2) <= argc && argv[i][0] != '-' && argv[i+1][0] != '-') + { + windowLeft = atoi(argv[i++]); + windowTop = atoi(argv[i++]); + } } break; + case 'h': usage(argv[0]); return 0; @@ -652,7 +645,7 @@ int main(int argc, char** argv) #ifdef NDEBUG if (closeConsole) { - //::FreeConsole(); // Close a console window + ::FreeConsole(); // Close a console window } #endif // NDEBUG #endif // WIN32 -- cgit v1.2.3 From d4adc43fc1746389ef89dce5c32163ba1d6011aa Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sat, 28 Feb 2009 22:25:23 +0000 Subject: BGE patch #18309 commited: Add an addObject() method to KX_Scene. --- source/gameengine/Ketsji/KX_Scene.cpp | 47 ++++++++++++++++++++++++++--------- source/gameengine/Ketsji/KX_Scene.h | 1 + 2 files changed, 36 insertions(+), 12 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 073cfc98bf1..0fded15f1a1 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1517,18 +1517,6 @@ double KX_Scene::getSuspendedDelta() //---------------------------------------------------------------------------- //Python -PyMethodDef KX_Scene::Methods[] = { - KX_PYMETHODTABLE_NOARGS(KX_Scene, getLightList), - KX_PYMETHODTABLE_NOARGS(KX_Scene, getObjectList), - KX_PYMETHODTABLE_NOARGS(KX_Scene, getName), - - {NULL,NULL} //Sentinel -}; - -PyAttributeDef KX_Scene::Attributes[] = { - { NULL } //Sentinel -}; - PyTypeObject KX_Scene::Type = { PyObject_HEAD_INIT(&PyType_Type) 0, @@ -1554,6 +1542,19 @@ PyParentObject KX_Scene::Parents[] = { NULL }; +PyMethodDef KX_Scene::Methods[] = { + KX_PYMETHODTABLE(KX_Scene, getLightList), + KX_PYMETHODTABLE(KX_Scene, getObjectList), + KX_PYMETHODTABLE(KX_Scene, getName), + KX_PYMETHODTABLE(KX_Scene, addObject), + + {NULL,NULL} //Sentinel +}; + +PyAttributeDef KX_Scene::Attributes[] = { + { NULL } //Sentinel +}; + PyObject* KX_Scene::_getattr(const char *attr) { if (!strcmp(attr, "name")) @@ -1622,3 +1623,25 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_Scene, getName, { return PyString_FromString(GetName()); } + +KX_PYMETHODDEF_DOC(KX_Scene, addObject, +"addObject(object, other, time=0)\n" +"Returns the added object.\n") +{ + PyObject *pyob, *pyother; + KX_GameObject *ob, *other; + + int time = 0; + + if (!PyArg_ParseTuple(args, "OO|i", &pyob, &pyother, &time)) + return NULL; + + if (!ConvertPythonToGameObject(pyob, &ob, false) + || !ConvertPythonToGameObject(pyother, &other, false)) + return NULL; + + + SCA_IObject* replica = AddReplicaObject((SCA_IObject*)ob, other, time); + replica->AddRef(); + return replica; +} \ No newline at end of file diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index e49a87b0402..962db1a9b96 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -550,6 +550,7 @@ public: KX_PYMETHOD_DOC_NOARGS(KX_Scene, getLightList); KX_PYMETHOD_DOC_NOARGS(KX_Scene, getObjectList); KX_PYMETHOD_DOC_NOARGS(KX_Scene, getName); + KX_PYMETHOD_DOC(KX_Scene, addObject); /* KX_PYMETHOD_DOC(KX_Scene, getActiveCamera); KX_PYMETHOD_DOC(KX_Scene, getActiveCamera); -- cgit v1.2.3 From f8ef887880ac217cc831b2ab9677e1f9e825537b Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Mon, 2 Mar 2009 17:43:35 +0000 Subject: minor update to be compatible with Bullet 2.74 physics: btPoint3 has been deprecated, it was already a typedef to btVector3 replace std::vector by btAlignedObjectArray when storing Bullet objects, because MSVC STL implementation has some bugs, preventing to contain aligned objects (btVector3 is 16-byte aligned, to allow SIMD) --- .../Physics/Bullet/CcdPhysicsController.cpp | 27 +++++++++++----------- .../Physics/Bullet/CcdPhysicsController.h | 2 +- .../Physics/Bullet/CcdPhysicsEnvironment.cpp | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index d09ad58fe3b..fc76af15301 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -1240,7 +1240,7 @@ void DefaultMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,flo void DefaultMotionState::setWorldPosition(float posX,float posY,float posZ) { - btPoint3 pos(posX,posY,posZ); + btVector3 pos(posX,posY,posZ); m_worldTransform.setOrigin( pos ); } @@ -1328,7 +1328,7 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo for (int i=0;iVertexCount();i++) { const float* vtx = poly->GetVertex(i)->getXYZ(); - btPoint3 point(vtx[0],vtx[1],vtx[2]); + btVector3 point(vtx[0],vtx[1],vtx[2]); //avoid duplicates (could better directly use vertex offsets, rather than a vertex compare) bool found = false; for (int j=0;jGetVertex(2)->getXYZ(); - btPoint3 vertex0(vtx[0],vtx[1],vtx[2]); + btVector3 vertex0(vtx[0],vtx[1],vtx[2]); vtx = poly->GetVertex(1)->getXYZ(); - btPoint3 vertex1(vtx[0],vtx[1],vtx[2]); + btVector3 vertex1(vtx[0],vtx[1],vtx[2]); vtx = poly->GetVertex(0)->getXYZ(); - btPoint3 vertex2(vtx[0],vtx[1],vtx[2]); + btVector3 vertex2(vtx[0],vtx[1],vtx[2]); m_vertexArray.push_back(vertex0); m_vertexArray.push_back(vertex1); @@ -1365,13 +1365,13 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo if (poly->VertexCount() == 4) { const float* vtx = poly->GetVertex(3)->getXYZ(); - btPoint3 vertex0(vtx[0],vtx[1],vtx[2]); + btVector3 vertex0(vtx[0],vtx[1],vtx[2]); vtx = poly->GetVertex(2)->getXYZ(); - btPoint3 vertex1(vtx[0],vtx[1],vtx[2]); + btVector3 vertex1(vtx[0],vtx[1],vtx[2]); vtx = poly->GetVertex(0)->getXYZ(); - btPoint3 vertex2(vtx[0],vtx[1],vtx[2]); + btVector3 vertex2(vtx[0],vtx[1],vtx[2]); m_vertexArray.push_back(vertex0); m_vertexArray.push_back(vertex1); @@ -1442,7 +1442,7 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape() break; case PHY_SHAPE_POLYTOPE: - collisionShape = new btConvexHullShape(&m_vertexArray.begin()->getX(), m_vertexArray.size()); + collisionShape = new btConvexHullShape(&m_vertexArray[0].getX(), m_vertexArray.size()); break; case PHY_SHAPE_MESH: @@ -1459,10 +1459,11 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape() // m_vertexArray is necessarily a multiple of 3 - for (std::vector::iterator it=m_vertexArray.begin(); it != m_vertexArray.end(); ) + for (int i=0;iaddTriangle(*it++,*it++,*it++); + collisionMeshData->addTriangle(m_vertexArray[i+2],m_vertexArray[i+1],m_vertexArray[i]); } + btGImpactMeshShape* gimpactShape = new btGImpactMeshShape(collisionMeshData); collisionShape = gimpactShape; @@ -1476,9 +1477,9 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape() collisionMeshData->m_weldingThreshold = m_weldingThreshold; // m_vertexArray is necessarily a multiple of 3 - for (std::vector::iterator it=m_vertexArray.begin(); it != m_vertexArray.end(); ) + for (int i=0;iaddTriangle(*it++,*it++,*it++); + collisionMeshData->addTriangle(m_vertexArray[i+2],m_vertexArray[i+1],m_vertexArray[i]); } // this shape will be shared and not deleted until shapeInfo is deleted m_unscaledShape = new btBvhTriangleMeshShape( collisionMeshData, true ); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index c771aa2624b..deb3c0880e9 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -161,7 +161,7 @@ public: btTransform m_childTrans; btVector3 m_childScale; void* m_userData; - std::vector m_vertexArray; // Contains both vertex array for polytope shape and + btAlignedObjectArray m_vertexArray; // Contains both vertex array for polytope shape and // triangle array for concave mesh shape. // In this case a triangle is made of 3 consecutive points std::vector m_polygonIndexArray; // Contains the array of polygon index in the diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index eb01385bc01..63ad427852e 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -414,7 +414,7 @@ void CcdPhysicsEnvironment::addCcdPhysicsController(CcdPhysicsController* ctrl) const btTransform& t = ctrl->GetCollisionObject()->getWorldTransform(); - btPoint3 minAabb,maxAabb; + btVector3 minAabb,maxAabb; shapeinterface->getAabb(t,minAabb,maxAabb); -- cgit v1.2.3 From 982a5cc60dd93b21ce110b3fff831d05720047bf Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Tue, 3 Mar 2009 03:41:24 +0000 Subject: Upgraded to Bullet 2.74. The upgrade introduced a few bugs, which need to be fixed before Blender 2.49. In particular, the Bullet vehicle seems broken, and some soft-body demos don't work. No new features or benefits are added yet, but a few improvements are planned before Blender 2.49 release. Please update the build systems, and add those 3 files: extern/bullet2/src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.cpp extern/bullet2/src/BulletCollision/CollisionDispatch/btGhostObject.cpp extern/bullet2/src/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp I'll watch the Blender mailing list, in case this commit causes some issues. --- source/gameengine/Physics/Bullet/CcdPhysicsController.cpp | 6 ++++-- source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index fc76af15301..eecdea55349 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -1457,11 +1457,12 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape() { collisionMeshData = new btTriangleMesh(); + bool removeDuplicateVertices=true; // m_vertexArray is necessarily a multiple of 3 for (int i=0;iaddTriangle(m_vertexArray[i+2],m_vertexArray[i+1],m_vertexArray[i]); + collisionMeshData->addTriangle(m_vertexArray[i+2],m_vertexArray[i+1],m_vertexArray[i],removeDuplicateVertices); } btGImpactMeshShape* gimpactShape = new btGImpactMeshShape(collisionMeshData); @@ -1476,10 +1477,11 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape() collisionMeshData = new btTriangleMesh(true,false); collisionMeshData->m_weldingThreshold = m_weldingThreshold; + bool removeDuplicateVertices=true; // m_vertexArray is necessarily a multiple of 3 for (int i=0;iaddTriangle(m_vertexArray[i+2],m_vertexArray[i+1],m_vertexArray[i]); + collisionMeshData->addTriangle(m_vertexArray[i+2],m_vertexArray[i+1],m_vertexArray[i],removeDuplicateVertices); } // this shape will be shared and not deleted until shapeInfo is deleted m_unscaledShape = new btBvhTriangleMeshShape( collisionMeshData, true ); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 63ad427852e..6504f77ec53 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -356,6 +356,7 @@ m_ownDispatcher(NULL) setSolverType(1);//issues with quickstep and memory allocations // m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,m_broadphase,m_solver,m_collisionConfiguration); m_dynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher,m_broadphase,m_solver,m_collisionConfiguration); + //m_dynamicsWorld->getSolverInfo().m_solverMode= SOLVER_USE_WARMSTARTING + SOLVER_USE_2_FRICTION_DIRECTIONS + SOLVER_RANDMIZE_ORDER + SOLVER_USE_FRICTION_WARMSTARTING; m_debugDrawer = 0; m_gravity = btVector3(0.f,-10.f,0.f); @@ -845,7 +846,8 @@ void CcdPhysicsEnvironment::setSolverType(int solverType) { m_solver = new btSequentialImpulseConstraintSolver(); -// ((btSequentialImpulseConstraintSolver*)m_solver)->setSolverMode(btSequentialImpulseConstraintSolver::SOLVER_USE_WARMSTARTING | btSequentialImpulseConstraintSolver::SOLVER_RANDMIZE_ORDER); + + break; } } -- cgit v1.2.3 From ab8e9ba3dd54fe8781f763644b882bbcb8cc7e8d Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Thu, 5 Mar 2009 15:16:43 +0000 Subject: VideoTexture: reactivate VideoTexture for scons/cmake/makefile compilation systems, fix video streaming, fix camera support in Linux, add multi-thread cache service, fix crash when a VideoFFmpeg object could not be created. The multi-thread cache service is activated only on multi-core processors. It consists in loading, decoding and caching the video frames in a separate thread. The cache size is 5 decoded frames and 30 raw frames. Note that the opening of video file/stream/camera is not multi-thread: you will still experience a delay at the VideoFFmpeg object creation. Processing of the video frame (resize, loading to texture) is still done in the main thread. Caching is automatically enabled for video file, video streaming and video camera. Video streaming now works correctly: the videos frames are loaded at the correct rate. Network delays and frequency drifts are automatically compensated. Note: an http video source is always treated as a streaming source, even though the http protocol allows seeking. For the user it means that he cannot define start/stop range and cannot restart the video except by reopening the source. Pause/play is however possible. Video camera is now correctly handled on Linux: it will not slow down the BGE. A video camera is treated as a streaming source. --- source/gameengine/BlenderRoutines/CMakeLists.txt | 4 + source/gameengine/BlenderRoutines/Makefile | 3 + source/gameengine/BlenderRoutines/SConscript | 3 + source/gameengine/VideoTexture/CMakeLists.txt | 2 +- source/gameengine/VideoTexture/Makefile | 3 + source/gameengine/VideoTexture/SConscript | 2 +- source/gameengine/VideoTexture/VideoFFmpeg.cpp | 538 +++++++++++++++++++---- source/gameengine/VideoTexture/VideoFFmpeg.h | 46 +- 8 files changed, 505 insertions(+), 96 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/CMakeLists.txt b/source/gameengine/BlenderRoutines/CMakeLists.txt index 340a1ae310b..d65e6a012df 100644 --- a/source/gameengine/BlenderRoutines/CMakeLists.txt +++ b/source/gameengine/BlenderRoutines/CMakeLists.txt @@ -38,5 +38,9 @@ SET(INC ${PYTHON_INC} ) +IF(WITH_FFMPEG) + ADD_DEFINITIONS(-DWITH_FFMPEG) +ENDIF(WITH_FFMPEG) + BLENDERLIB(bf_blroutines "${SRC}" "${INC}") #env.BlenderLib ( 'bf_bloutines', sources, Split(incs), [], libtype=['game', 'game2', 'player'], priority=[0, 0, 55] , compileflags=cxxflags) diff --git a/source/gameengine/BlenderRoutines/Makefile b/source/gameengine/BlenderRoutines/Makefile index c2f19ae1d8a..e77d8e8380e 100644 --- a/source/gameengine/BlenderRoutines/Makefile +++ b/source/gameengine/BlenderRoutines/Makefile @@ -76,3 +76,6 @@ endif CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION) +ifeq ($(WITH_FFMPEG), true) + CPPFLAGS += -DWITH_FFMPEG +endif diff --git a/source/gameengine/BlenderRoutines/SConscript b/source/gameengine/BlenderRoutines/SConscript index f2d92384e3c..4a9c0e1286b 100644 --- a/source/gameengine/BlenderRoutines/SConscript +++ b/source/gameengine/BlenderRoutines/SConscript @@ -23,6 +23,9 @@ if env['WITH_BF_SOLID']: incs += ' ' + env['BF_SOLID_INC'] defs.append('USE_SUMO_SOLID') +if env['WITH_BF_FFMPEG']: + defs.append('WITH_FFMPEG') + incs += ' ' + env['BF_PYTHON_INC'] incs += ' ' + env['BF_BULLET_INC'] incs += ' ' + env['BF_OPENGL_INC'] diff --git a/source/gameengine/VideoTexture/CMakeLists.txt b/source/gameengine/VideoTexture/CMakeLists.txt index 1674602edd7..1fca5374991 100644 --- a/source/gameengine/VideoTexture/CMakeLists.txt +++ b/source/gameengine/VideoTexture/CMakeLists.txt @@ -52,7 +52,7 @@ SET(INC ) IF(WITH_FFMPEG) - SET(INC ${INC} ${FFMPEG_INC}) + SET(INC ${INC} ${FFMPEG_INC} ${PTHREADS_INC}) ADD_DEFINITIONS(-DWITH_FFMPEG) ADD_DEFINITIONS(-D__STDC_CONSTANT_MACROS) ENDIF(WITH_FFMPEG) diff --git a/source/gameengine/VideoTexture/Makefile b/source/gameengine/VideoTexture/Makefile index bead176808b..a4611937a65 100644 --- a/source/gameengine/VideoTexture/Makefile +++ b/source/gameengine/VideoTexture/Makefile @@ -60,6 +60,9 @@ CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include ifeq ($(WITH_FFMPEG),true) CPPFLAGS += -DWITH_FFMPEG CPPFLAGS += $(NAN_FFMPEGCFLAGS) + ifdef NAN_PTHREADS + CPPFLAGS += -I$(NAN_PTHREADS)/include + endif endif diff --git a/source/gameengine/VideoTexture/SConscript b/source/gameengine/VideoTexture/SConscript index 28737ed06e5..edd44f98783 100644 --- a/source/gameengine/VideoTexture/SConscript +++ b/source/gameengine/VideoTexture/SConscript @@ -27,7 +27,7 @@ incs += ' ' + env['BF_PYTHON_INC'] if env['WITH_BF_FFMPEG']: defs += ' WITH_FFMPEG' - incs += ' ' + env['BF_FFMPEG_INC'] + incs += ' ' + env['BF_FFMPEG_INC'] + ' ' + env['BF_PTHREADS_INC'] defs += ' __STDC_CONSTANT_MACROS' env.BlenderLib ( 'bf_videotex', sources, Split(incs), Split(defs), libtype=['game','player'], priority=[25, 72], cxx_compileflags = cxxflags ) diff --git a/source/gameengine/VideoTexture/VideoFFmpeg.cpp b/source/gameengine/VideoTexture/VideoFFmpeg.cpp index 02798c7e596..5265b0ecb93 100644 --- a/source/gameengine/VideoTexture/VideoFFmpeg.cpp +++ b/source/gameengine/VideoTexture/VideoFFmpeg.cpp @@ -55,7 +55,8 @@ m_codec(NULL), m_formatCtx(NULL), m_codecCtx(NULL), m_frame(NULL), m_frameDeinterlaced(NULL), m_frameRGB(NULL), m_imgConvertCtx(NULL), m_deinterlace(false), m_preseek(0), m_videoStream(-1), m_baseFrameRate(25.0), m_lastFrame(-1), m_eof(false), m_curPosition(-1), m_startTime(0), -m_captWidth(0), m_captHeight(0), m_captRate(0.f), m_isImage(false) +m_captWidth(0), m_captHeight(0), m_captRate(0.f), m_isImage(false), +m_isThreaded(false), m_stopThread(false), m_cacheStarted(false) { // set video format m_format = RGB24; @@ -63,6 +64,12 @@ m_captWidth(0), m_captHeight(0), m_captRate(0.f), m_isImage(false) setFlip(true); // construction is OK *hRslt = S_OK; + m_thread.first = m_thread.last = NULL; + pthread_mutex_init(&m_cacheMutex, NULL); + m_frameCacheFree.first = m_frameCacheFree.last = NULL; + m_frameCacheBase.first = m_frameCacheBase.last = NULL; + m_packetCacheFree.first = m_packetCacheFree.last = NULL; + m_packetCacheBase.first = m_packetCacheBase.last = NULL; } // destructor @@ -75,6 +82,7 @@ VideoFFmpeg::~VideoFFmpeg () bool VideoFFmpeg::release() { // release + stopCache(); if (m_codecCtx) { avcodec_close(m_codecCtx); @@ -112,6 +120,29 @@ bool VideoFFmpeg::release() return true; } +AVFrame *VideoFFmpeg::allocFrameRGB() +{ + AVFrame *frame; + frame = avcodec_alloc_frame(); + if (m_format == RGBA32) + { + avpicture_fill((AVPicture*)frame, + (uint8_t*)MEM_callocN(avpicture_get_size( + PIX_FMT_RGBA, + m_codecCtx->width, m_codecCtx->height), + "ffmpeg rgba"), + PIX_FMT_RGBA, m_codecCtx->width, m_codecCtx->height); + } else + { + avpicture_fill((AVPicture*)frame, + (uint8_t*)MEM_callocN(avpicture_get_size( + PIX_FMT_RGB24, + m_codecCtx->width, m_codecCtx->height), + "ffmpeg rgb"), + PIX_FMT_RGB24, m_codecCtx->width, m_codecCtx->height); + } + return frame; +} // set initial parameters void VideoFFmpeg::initParams (short width, short height, float rate, bool image) @@ -122,6 +153,7 @@ void VideoFFmpeg::initParams (short width, short height, float rate, bool image) m_isImage = image; } + int VideoFFmpeg::openStream(const char *filename, AVInputFormat *inputFormat, AVFormatParameters *formatParams) { AVFormatContext *formatCtx; @@ -189,7 +221,6 @@ int VideoFFmpeg::openStream(const char *filename, AVInputFormat *inputFormat, AV m_videoStream = videoStream; m_frame = avcodec_alloc_frame(); m_frameDeinterlaced = avcodec_alloc_frame(); - m_frameRGB = avcodec_alloc_frame(); // allocate buffer if deinterlacing is required avpicture_fill((AVPicture*)m_frameDeinterlaced, @@ -207,12 +238,6 @@ int VideoFFmpeg::openStream(const char *filename, AVInputFormat *inputFormat, AV { // allocate buffer to store final decoded frame m_format = RGBA32; - avpicture_fill((AVPicture*)m_frameRGB, - (uint8_t*)MEM_callocN(avpicture_get_size( - PIX_FMT_RGBA, - m_codecCtx->width, m_codecCtx->height), - "ffmpeg rgba"), - PIX_FMT_RGBA, m_codecCtx->width, m_codecCtx->height); // allocate sws context m_imgConvertCtx = sws_getContext( m_codecCtx->width, @@ -227,12 +252,6 @@ int VideoFFmpeg::openStream(const char *filename, AVInputFormat *inputFormat, AV { // allocate buffer to store final decoded frame m_format = RGB24; - avpicture_fill((AVPicture*)m_frameRGB, - (uint8_t*)MEM_callocN(avpicture_get_size( - PIX_FMT_RGB24, - m_codecCtx->width, m_codecCtx->height), - "ffmpeg rgb"), - PIX_FMT_RGB24, m_codecCtx->width, m_codecCtx->height); // allocate sws context m_imgConvertCtx = sws_getContext( m_codecCtx->width, @@ -244,19 +263,247 @@ int VideoFFmpeg::openStream(const char *filename, AVInputFormat *inputFormat, AV SWS_FAST_BILINEAR, NULL, NULL, NULL); } + m_frameRGB = allocFrameRGB(); + if (!m_imgConvertCtx) { avcodec_close(m_codecCtx); + m_codecCtx = NULL; av_close_input_file(m_formatCtx); + m_formatCtx = NULL; av_free(m_frame); + m_frame = NULL; MEM_freeN(m_frameDeinterlaced->data[0]); av_free(m_frameDeinterlaced); + m_frameDeinterlaced = NULL; MEM_freeN(m_frameRGB->data[0]); av_free(m_frameRGB); + m_frameRGB = NULL; return -1; } return 0; } +/* + * This thread is used to load video frame asynchronously. + * It provides a frame caching service. + * The main thread is responsible for positionning the frame pointer in the + * file correctly before calling startCache() which starts this thread. + * The cache is organized in two layers: 1) a cache of 20-30 undecoded packets to keep + * memory and CPU low 2) a cache of 5 decoded frames. + * If the main thread does not find the frame in the cache (because the video has restarted + * or because the GE is lagging), it stops the cache with StopCache() (this is a synchronous + * function: it sends a signal to stop the cache thread and wait for confirmation), then + * change the position in the stream and restarts the cache thread. + */ +void *VideoFFmpeg::cacheThread(void *data) +{ + VideoFFmpeg* video = (VideoFFmpeg*)data; + // holds the frame that is being decoded + CacheFrame *currentFrame = NULL; + CachePacket *cachePacket; + bool endOfFile = false; + int frameFinished = 0; + + while (!video->m_stopThread) + { + // packet cache is used solely by this thread, no need to lock + // In case the stream/file contains other stream than the one we are looking for, + // allow a bit of cycling to get rid quickly of those frames + frameFinished = 0; + while ( !endOfFile + && (cachePacket = (CachePacket *)video->m_packetCacheFree.first) != NULL + && frameFinished < 25) + { + // free packet => packet cache is not full yet, just read more + if (av_read_frame(video->m_formatCtx, &cachePacket->packet)>=0) + { + if (cachePacket->packet.stream_index == video->m_videoStream) + { + // make sure fresh memory is allocated for the packet and move it to queue + av_dup_packet(&cachePacket->packet); + BLI_remlink(&video->m_packetCacheFree, cachePacket); + BLI_addtail(&video->m_packetCacheBase, cachePacket); + break; + } else { + // this is not a good packet for us, just leave it on free queue + // Note: here we could handle sound packet + av_free_packet(&cachePacket->packet); + frameFinished++; + } + + } else { + if (video->m_isFile) + // this mark the end of the file + endOfFile = true; + // if we cannot read a packet, no need to continue + break; + } + } + // frame cache is also used by main thread, lock + if (currentFrame == NULL) + { + // no current frame being decoded, take free one + pthread_mutex_lock(&video->m_cacheMutex); + if ((currentFrame = (CacheFrame *)video->m_frameCacheFree.first) != NULL) + BLI_remlink(&video->m_frameCacheFree, currentFrame); + pthread_mutex_unlock(&video->m_cacheMutex); + } + if (currentFrame != NULL) + { + // this frame is out of free and busy queue, we can manipulate it without locking + frameFinished = 0; + while (!frameFinished && (cachePacket = (CachePacket *)video->m_packetCacheBase.first) != NULL) + { + BLI_remlink(&video->m_packetCacheBase, cachePacket); + // use m_frame because when caching, it is not used in main thread + // we can't use currentFrame directly because we need to convert to RGB first + avcodec_decode_video(video->m_codecCtx, + video->m_frame, &frameFinished, + cachePacket->packet.data, cachePacket->packet.size); + if(frameFinished) + { + AVFrame * input = video->m_frame; + + /* This means the data wasnt read properly, this check stops crashing */ + if ( input->data[0]!=0 || input->data[1]!=0 + || input->data[2]!=0 || input->data[3]!=0) + { + if (video->m_deinterlace) + { + if (avpicture_deinterlace( + (AVPicture*) video->m_frameDeinterlaced, + (const AVPicture*) video->m_frame, + video->m_codecCtx->pix_fmt, + video->m_codecCtx->width, + video->m_codecCtx->height) >= 0) + { + input = video->m_frameDeinterlaced; + } + } + // convert to RGB24 + sws_scale(video->m_imgConvertCtx, + input->data, + input->linesize, + 0, + video->m_codecCtx->height, + currentFrame->frame->data, + currentFrame->frame->linesize); + // move frame to queue, this frame is necessarily the next one + currentFrame->framePosition = ++video->m_curPosition; + pthread_mutex_lock(&video->m_cacheMutex); + BLI_addtail(&video->m_frameCacheBase, currentFrame); + pthread_mutex_unlock(&video->m_cacheMutex); + currentFrame = NULL; + } + } + av_free_packet(&cachePacket->packet); + BLI_addtail(&video->m_packetCacheFree, cachePacket); + } + if (currentFrame && endOfFile) + { + // no more packet and end of file => put a special frame that indicates that + currentFrame->framePosition = -1; + pthread_mutex_lock(&video->m_cacheMutex); + BLI_addtail(&video->m_frameCacheBase, currentFrame); + pthread_mutex_unlock(&video->m_cacheMutex); + currentFrame = NULL; + // no need to stay any longer in this thread + break; + } + } + // small sleep to avoid unnecessary looping + PIL_sleep_ms(10); + } + // before quitting, put back the current frame to queue to allow freeing + if (currentFrame) + { + pthread_mutex_lock(&video->m_cacheMutex); + BLI_addtail(&video->m_frameCacheFree, currentFrame); + pthread_mutex_unlock(&video->m_cacheMutex); + } + return 0; +} + +// start thread to cache video frame from file/capture/stream +// this function should be called only when the position in the stream is set for the +// first frame to cache +bool VideoFFmpeg::startCache() +{ + if (!m_cacheStarted && m_isThreaded) + { + m_stopThread = false; + for (int i=0; iframe = allocFrameRGB(); + BLI_addtail(&m_frameCacheFree, frame); + } + for (int i=0; iframe->data[0]); + av_free(frame->frame); + delete frame; + } + while ((frame = (CacheFrame *)m_frameCacheFree.first) != NULL) + { + BLI_remlink(&m_frameCacheFree, frame); + MEM_freeN(frame->frame->data[0]); + av_free(frame->frame); + delete frame; + } + while((packet = (CachePacket *)m_packetCacheBase.first) != NULL) + { + BLI_remlink(&m_packetCacheBase, packet); + av_free_packet(&packet->packet); + delete packet; + } + while((packet = (CachePacket *)m_packetCacheFree.first) != NULL) + { + BLI_remlink(&m_packetCacheFree, packet); + delete packet; + } + m_cacheStarted = false; + } +} + +void VideoFFmpeg::releaseFrame(AVFrame* frame) +{ + if (frame == m_frameRGB) + { + // this is not a frame from the cache, ignore + return; + } + // this frame MUST be the first one of the queue + pthread_mutex_lock(&m_cacheMutex); + CacheFrame *cacheFrame = (CacheFrame *)m_frameCacheBase.first; + assert (cacheFrame != NULL && cacheFrame->frame == frame); + BLI_remlink(&m_frameCacheBase, cacheFrame); + BLI_addtail(&m_frameCacheFree, cacheFrame); + pthread_mutex_unlock(&m_cacheMutex); +} + // open video file void VideoFFmpeg::openFile (char * filename) { @@ -280,8 +527,12 @@ void VideoFFmpeg::openFile (char * filename) VideoBase::openFile(filename); if ( + // ffmpeg reports that http source are actually non stream + // but it is really not desirable to seek on http file, so force streaming. + // It would be good to find this information from the context but there are no simple indication + !strncmp(filename, "http://", 7) || #ifdef FFMPEG_PB_IS_POINTER - m_formatCtx->pb && m_formatCtx->pb->is_streamed + (m_formatCtx->pb && m_formatCtx->pb->is_streamed) #else m_formatCtx->pb.is_streamed #endif @@ -304,7 +555,13 @@ void VideoFFmpeg::openFile (char * filename) m_avail = false; play(); } - + // check if we should do multi-threading? + if (!m_isImage && BLI_system_thread_count() > 1) + { + // never thread image: there are no frame to read ahead + // no need to thread if the system has a single core + m_isThreaded = true; + } } @@ -385,6 +642,12 @@ void VideoFFmpeg::openCam (char * file, short camIdx) m_formatCtx->flags |= AVFMT_FLAG_NONBLOCK; // open base class VideoBase::openCam(file, camIdx); + // check if we should do multi-threading? + if (BLI_system_thread_count() > 1) + { + // no need to thread if the system has a single core + m_isThreaded = true; + } } // play video @@ -427,9 +690,12 @@ void VideoFFmpeg::setRange (double start, double stop) try { // set range - VideoBase::setRange(start, stop); - // set range for video - setPositions(); + if (m_isFile) + { + VideoBase::setRange(start, stop); + // set range for video + setPositions(); + } } CATCH_EXCP; } @@ -451,43 +717,61 @@ void VideoFFmpeg::calcImage (unsigned int texId) // load frame from video void VideoFFmpeg::loadFrame (void) { - // get actual time - double actTime = PIL_check_seconds_timer() - m_startTime; - // if video has ended - if (m_isFile && actTime * m_frameRate >= m_range[1]) - { - // if repeats are set, decrease them - if (m_repeat > 0) - --m_repeat; - // if video has to be replayed - if (m_repeat != 0) - { - // reset its position - actTime -= (m_range[1] - m_range[0]) / m_frameRate; - m_startTime += (m_range[1] - m_range[0]) / m_frameRate; - } - // if video has to be stopped, stop it - else - m_status = SourceStopped; - } - // if video is playing if (m_status == SourcePlaying) { + // get actual time + double startTime = PIL_check_seconds_timer(); + double actTime = startTime - m_startTime; + // if video has ended + if (m_isFile && actTime * m_frameRate >= m_range[1]) + { + // in any case, this resets the cache + stopCache(); + // if repeats are set, decrease them + if (m_repeat > 0) + --m_repeat; + // if video has to be replayed + if (m_repeat != 0) + { + // reset its position + actTime -= (m_range[1] - m_range[0]) / m_frameRate; + m_startTime += (m_range[1] - m_range[0]) / m_frameRate; + } + // if video has to be stopped, stop it + else + { + m_status = SourceStopped; + return; + } + } // actual frame - long actFrame = m_isFile ? long(actTime * actFrameRate()) : m_lastFrame + 1; + long actFrame = (m_isImage) ? m_lastFrame+1 : long(actTime * actFrameRate()); // if actual frame differs from last frame if (actFrame != m_lastFrame) { + AVFrame* frame; // get image - if(grabFrame(actFrame)) + if((frame = grabFrame(actFrame)) != NULL) { - AVFrame* frame = getFrame(); + if (!m_isFile && !m_cacheStarted) + { + // streaming without cache: detect synchronization problem + double execTime = PIL_check_seconds_timer() - startTime; + if (execTime > 0.005) + { + // exec time is too long, it means that the function was blocking + // resynchronize the stream from this time + m_startTime += execTime; + } + } // save actual frame m_lastFrame = actFrame; // init image, if needed init(short(m_codecCtx->width), short(m_codecCtx->height)); // process image process((BYTE*)(frame->data[0])); + // finished with the frame, release it so that cache can reuse it + releaseFrame(frame); // in case it is an image, automatically stop reading it if (m_isImage) { @@ -495,6 +779,12 @@ void VideoFFmpeg::loadFrame (void) // close the file as we don't need it anymore release(); } + } else if (!m_isFile) + { + // we didn't get a frame and we are streaming, this may be due to + // a delay in the network or because we are getting the frame too fast. + // In the later case, shift time by a small amount to compensate for a drift + m_startTime += 0.01; } } } @@ -507,77 +797,135 @@ void VideoFFmpeg::setPositions (void) // set video start time m_startTime = PIL_check_seconds_timer(); // if file is played and actual position is before end position - if (m_isFile && !m_eof && m_lastFrame >= 0 && m_lastFrame < m_range[1] * actFrameRate()) + if (!m_eof && m_lastFrame >= 0 && (!m_isFile || m_lastFrame < m_range[1] * actFrameRate())) // continue from actual position m_startTime -= double(m_lastFrame) / actFrameRate(); - else + else { m_startTime -= m_range[0]; + // start from begining, stop cache just in case + stopCache(); + } } // position pointer in file, position in second -bool VideoFFmpeg::grabFrame(long position) +AVFrame *VideoFFmpeg::grabFrame(long position) { AVPacket packet; int frameFinished; int posFound = 1; bool frameLoaded = false; long long targetTs = 0; + CacheFrame *frame; - // first check if the position that we are looking for is in the preseek range - // if so, just read the frame until we get there - if (position > m_curPosition + 1 - && m_preseek - && position - (m_curPosition + 1) < m_preseek) + if (m_cacheStarted) { - while(av_read_frame(m_formatCtx, &packet)>=0) + // when cache is active, we must not read the file directly + do { + pthread_mutex_lock(&m_cacheMutex); + frame = (CacheFrame *)m_frameCacheBase.first; + pthread_mutex_unlock(&m_cacheMutex); + // no need to remove the frame from the queue: the cache thread does not touch the head, only the tail + if (frame == NULL) + { + // no frame in cache, in case of file it is an abnormal situation + if (m_isFile) + { + // go back to no threaded reading + stopCache(); + break; + } + return NULL; + } + if (frame->framePosition == -1) + { + // this frame mark the end of the file (only used for file) + // leave in cache to make sure we don't miss it + m_eof = true; + return NULL; + } + // for streaming, always return the next frame, + // that's what grabFrame does in non cache mode anyway. + if (!m_isFile || frame->framePosition == position) + { + return frame->frame; + } + // this frame is not useful, release it + pthread_mutex_lock(&m_cacheMutex); + BLI_remlink(&m_frameCacheBase, frame); + BLI_addtail(&m_frameCacheFree, frame); + pthread_mutex_unlock(&m_cacheMutex); + } while (true); + } + // come here when there is no cache or cache has been stopped + // locate the frame, by seeking if necessary (seeking is only possible for files) + if (m_isFile) + { + // first check if the position that we are looking for is in the preseek range + // if so, just read the frame until we get there + if (position > m_curPosition + 1 + && m_preseek + && position - (m_curPosition + 1) < m_preseek) { - if (packet.stream_index == m_videoStream) + while(av_read_frame(m_formatCtx, &packet)>=0) { - avcodec_decode_video( - m_codecCtx, - m_frame, &frameFinished, - packet.data, packet.size); - if (frameFinished) - m_curPosition++; + if (packet.stream_index == m_videoStream) + { + avcodec_decode_video( + m_codecCtx, + m_frame, &frameFinished, + packet.data, packet.size); + if (frameFinished) + m_curPosition++; + } + av_free_packet(&packet); + if (position == m_curPosition+1) + break; } - av_free_packet(&packet); - if (position == m_curPosition+1) - break; } - } - // if the position is not in preseek, do a direct jump - if (position != m_curPosition + 1) - { - double timeBase = av_q2d(m_formatCtx->streams[m_videoStream]->time_base); - long long pos = (long long) - ((long long) (position - m_preseek) * AV_TIME_BASE / m_baseFrameRate); - long long startTs = m_formatCtx->streams[m_videoStream]->start_time; + // if the position is not in preseek, do a direct jump + if (position != m_curPosition + 1) + { + double timeBase = av_q2d(m_formatCtx->streams[m_videoStream]->time_base); + long long pos = (long long) + ((long long) (position - m_preseek) * AV_TIME_BASE / m_baseFrameRate); + long long startTs = m_formatCtx->streams[m_videoStream]->start_time; - if (pos < 0) - pos = 0; + if (pos < 0) + pos = 0; - if (startTs != AV_NOPTS_VALUE) - pos += (long long)(startTs * AV_TIME_BASE * timeBase); + if (startTs != AV_NOPTS_VALUE) + pos += (long long)(startTs * AV_TIME_BASE * timeBase); - if (position <= m_curPosition || !m_eof) - { - // no need to seek past the end of the file - if (av_seek_frame(m_formatCtx, -1, pos, AVSEEK_FLAG_BACKWARD) >= 0) + if (position <= m_curPosition || !m_eof) { - // current position is now lost, guess a value. - // It's not important because it will be set at this end of this function - m_curPosition = position - m_preseek - 1; + // no need to seek past the end of the file + if (av_seek_frame(m_formatCtx, -1, pos, AVSEEK_FLAG_BACKWARD) >= 0) + { + // current position is now lost, guess a value. + // It's not important because it will be set at this end of this function + m_curPosition = position - m_preseek - 1; + } } - } - // this is the timestamp of the frame we're looking for - targetTs = (long long)(((double) position) / m_baseFrameRate / timeBase); - if (startTs != AV_NOPTS_VALUE) - targetTs += startTs; + // this is the timestamp of the frame we're looking for + targetTs = (long long)(((double) position) / m_baseFrameRate / timeBase); + if (startTs != AV_NOPTS_VALUE) + targetTs += startTs; - posFound = 0; - avcodec_flush_buffers(m_codecCtx); + posFound = 0; + avcodec_flush_buffers(m_codecCtx); + } + } else if (m_isThreaded) + { + // cache is not started but threading is possible + // better not read the stream => make take some time, better start caching + if (startCache()) + return NULL; + // Abnormal!!! could not start cache, fall back on direct read + m_isThreaded = false; } + // find the correct frame, in case of streaming and no cache, it means just + // return the next frame. This is not quite correct, may need more work while(av_read_frame(m_formatCtx, &packet)>=0) { if(packet.stream_index == m_videoStream) @@ -632,10 +980,22 @@ bool VideoFFmpeg::grabFrame(long position) } av_free_packet(&packet); } - m_eof = !frameLoaded; + m_eof = m_isFile && !frameLoaded; if (frameLoaded) + { m_curPosition = position; - return frameLoaded; + if (m_isThreaded) + { + // normal case for file: first locate, then start cache + if (!startCache()) + { + // Abnormal!! could not start cache, return to non-cache mode + m_isThreaded = false; + } + } + return m_frameRGB; + } + return NULL; } diff --git a/source/gameengine/VideoTexture/VideoFFmpeg.h b/source/gameengine/VideoTexture/VideoFFmpeg.h index e60f1727aab..51ce2c4eebe 100644 --- a/source/gameengine/VideoTexture/VideoFFmpeg.h +++ b/source/gameengine/VideoTexture/VideoFFmpeg.h @@ -24,12 +24,17 @@ http://www.gnu.org/copyleft/lesser.txt. #ifdef WITH_FFMPEG extern "C" { +#include #include #include #include #include +#include "DNA_listBase.h" +#include "BLI_threads.h" +#include "BLI_blenlib.h" } + #if LIBAVFORMAT_VERSION_INT < (49 << 16) #define FFMPEG_OLD_FRAME_RATE 1 #else @@ -54,6 +59,8 @@ static inline AVCodecContext* get_codec_from_stream(AVStream* stream) #include "VideoBase.h" +#define CACHE_FRAME_SIZE 5 +#define CACHE_PACKET_SIZE 30 // type VideoFFmpeg declaration class VideoFFmpeg : public VideoBase @@ -91,7 +98,6 @@ public: char *getImageName(void) { return (m_isImage) ? m_imageName.Ptr() : NULL; } protected: - // format and codec information AVCodec *m_codec; AVFormatContext *m_formatCtx; @@ -138,6 +144,9 @@ protected: /// is file an image? bool m_isImage; + /// is image loading done in a separate thread? + bool m_isThreaded; + /// keep last image name STR_String m_imageName; @@ -157,10 +166,37 @@ protected: int openStream(const char *filename, AVInputFormat *inputFormat, AVFormatParameters *formatParams); /// check if a frame is available and load it in pFrame, return true if a frame could be retrieved - bool grabFrame(long frame); - - /// return the frame in RGB24 format, the image data is found in AVFrame.data[0] - AVFrame* getFrame(void) { return m_frameRGB; } + AVFrame* grabFrame(long frame); + + /// in case of caching, put the frame back in free queue + void releaseFrame(AVFrame* frame); + + /// start thread to load the video file/capture/stream + bool startCache(); + void stopCache(); + +private: + typedef struct { + Link link; + long framePosition; + AVFrame *frame; + } CacheFrame; + typedef struct { + Link link; + AVPacket packet; + } CachePacket; + + bool m_stopThread; + bool m_cacheStarted; + ListBase m_thread; + ListBase m_frameCacheBase; // list of frames that are ready + ListBase m_frameCacheFree; // list of frames that are unused + ListBase m_packetCacheBase; // list of packets that are ready for decoding + ListBase m_packetCacheFree; // list of packets that are unused + pthread_mutex_t m_cacheMutex; + + AVFrame *allocFrameRGB(); + static void *cacheThread(void *); }; inline VideoFFmpeg * getFFmpeg (PyImage * self) -- cgit v1.2.3 From e4ce0d629e021bcc1b910a1f49c251a17501cff6 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sun, 8 Mar 2009 17:23:36 +0000 Subject: BGE patch: undo patch about removing blenderplayer console in Windows: it interferes with scripts that write to the console. Back to previous state: console cannot be disabled in Windows. --- source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 87b6b2450f7..afee60c3192 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -645,7 +645,7 @@ int main(int argc, char** argv) #ifdef NDEBUG if (closeConsole) { - ::FreeConsole(); // Close a console window + //::FreeConsole(); // Close a console window } #endif // NDEBUG #endif // WIN32 -- cgit v1.2.3 From abb338ddf9dea9a26ca1092b3f7fda86b32bbd16 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Mon, 9 Mar 2009 04:21:28 +0000 Subject: upgrade to latest Bullet trunk, fix related to vehicle anti-roll, added constraint visualization. This commit doesn't add new functionality, but more updates are planned before Blender 2.49 release. --- source/gameengine/Converter/KX_BlenderSceneConverter.cpp | 2 +- source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 7eec93dc402..97a0819147c 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -321,7 +321,7 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename, SYS_SystemHandle syshandle = SYS_GetSystem(); /*unused*/ int visualizePhysics = SYS_GetCommandLineInt(syshandle,"show_physics",0); if (visualizePhysics) - ccdPhysEnv->setDebugMode(btIDebugDraw::DBG_DrawWireframe|btIDebugDraw::DBG_DrawAabb|btIDebugDraw::DBG_DrawContactPoints|btIDebugDraw::DBG_DrawText); + ccdPhysEnv->setDebugMode(btIDebugDraw::DBG_DrawWireframe|btIDebugDraw::DBG_DrawAabb|btIDebugDraw::DBG_DrawContactPoints|btIDebugDraw::DBG_DrawText|btIDebugDraw::DBG_DrawConstraintLimits|btIDebugDraw::DBG_DrawConstraints); //todo: get a button in blender ? //disable / enable debug drawing (contact points, aabb's etc) diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 6504f77ec53..8f540417aae 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -337,6 +337,7 @@ m_ownDispatcher(NULL) // m_collisionConfiguration = new btDefaultCollisionConfiguration(); m_collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration(); + //m_collisionConfiguration->setConvexConvexMultipointIterations(); if (!dispatcher) { @@ -356,6 +357,7 @@ m_ownDispatcher(NULL) setSolverType(1);//issues with quickstep and memory allocations // m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,m_broadphase,m_solver,m_collisionConfiguration); m_dynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher,m_broadphase,m_solver,m_collisionConfiguration); + //m_dynamicsWorld->getSolverInfo().m_linearSlop = 0.01f; //m_dynamicsWorld->getSolverInfo().m_solverMode= SOLVER_USE_WARMSTARTING + SOLVER_USE_2_FRICTION_DIRECTIONS + SOLVER_RANDMIZE_ORDER + SOLVER_USE_FRICTION_WARMSTARTING; m_debugDrawer = 0; -- cgit v1.2.3 From 6e85d00055d414e6be34f4738790851a63223ab7 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Mon, 9 Mar 2009 05:01:16 +0000 Subject: Fix: The debug lines of Physics Debug Visualization were drawn incorrectly when using overlay scenes (it was using the wrong camera) --- source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 5 +++++ .../gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp | 8 +++++--- source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h | 2 ++ .../gameengine/Physics/common/PHY_IPhysicsEnvironment.h | 2 ++ source/gameengine/Rasterizer/RAS_IRasterizer.h | 2 ++ .../RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp | 16 +++++++++++++--- .../RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h | 2 ++ 7 files changed, 31 insertions(+), 6 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 87f348799df..97b4213b8bd 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -1112,6 +1112,11 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam) scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools); + if (scene->GetPhysicsEnvironment()) + scene->GetPhysicsEnvironment()->debugDrawWorld(); + + m_rasterizer->FlushDebugLines(); + PostRenderFrame(); } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 8f540417aae..dd21e58bd68 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -563,6 +563,11 @@ void CcdPhysicsEnvironment::beginFrame() } +void CcdPhysicsEnvironment::debugDrawWorld() +{ + if (m_dynamicsWorld->getDebugDrawer() && m_dynamicsWorld->getDebugDrawer()->getDebugMode() >0) + m_dynamicsWorld->debugDrawWorld(); +} bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep) { @@ -599,9 +604,6 @@ bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep) veh->SyncWheels(); } - if (m_dynamicsWorld->getDebugDrawer() && m_dynamicsWorld->getDebugDrawer()->getDebugMode() >0) - m_dynamicsWorld->debugDrawWorld(); - CallbackTriggers(); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h index 4b28d3fddfc..2f1f0bb254b 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h @@ -110,6 +110,8 @@ protected: virtual void endFrame() {}; /// Perform an integration step of duration 'timeStep'. virtual bool proceedDeltaTime(double curTime,float timeStep); + + virtual void debugDrawWorld(); // virtual bool proceedDeltaTimeOneStep(float timeStep); virtual void setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep){}; diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h index 0e9c571924c..226ba3a7e74 100644 --- a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h +++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h @@ -90,6 +90,8 @@ class PHY_IPhysicsEnvironment virtual void endFrame() = 0; /// Perform an integration step of duration 'timeStep'. virtual bool proceedDeltaTime(double curTime,float timeStep)=0; + ///draw debug lines (make sure to call this during the render phase, otherwise lines are not drawn properly) + virtual void debugDrawWorld(){} virtual void setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep)=0; //returns 0.f if no fixed timestep is used virtual float getFixedTimeStep()=0; diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h index d529ca8973a..83adcfd8321 100644 --- a/source/gameengine/Rasterizer/RAS_IRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h @@ -361,6 +361,8 @@ public: virtual void SetPolygonOffset(float mult, float add) = 0; virtual void DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)=0; + virtual void FlushDebugLines()=0; + virtual void SetTexCoordNum(int num) = 0; diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 08c600e7682..d4d1b73c772 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -327,13 +327,12 @@ void RAS_OpenGLRasterizer::ClearCachingInfo(void) m_materialCachingInfo = 0; } - -void RAS_OpenGLRasterizer::EndFrame() +void RAS_OpenGLRasterizer::FlushDebugLines() { +//DrawDebugLines glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); - //DrawDebugLines glBegin(GL_LINES); for (unsigned int i=0;iEndFrame(); } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h index c72d4880437..83a9f759a8b 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h @@ -240,6 +240,8 @@ public: virtual void SetPolygonOffset(float mult, float add); + virtual void FlushDebugLines(); + virtual void DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color) { OglDebugLine line; -- cgit v1.2.3 From 06d455f4280815c9197f8d9cb6c0cadcdfc5e838 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Mon, 9 Mar 2009 07:12:16 +0000 Subject: Add support to lock individual axis during rigid body simulation, for translation and rotation. This makes it easier to do 1D or 2D physics (tetris, blockout) todo: create some example/demo.blend. --- .../Converter/BL_BlenderDataConversion.cpp | 6 ++++++ source/gameengine/Ketsji/KX_ConvertPhysicsObject.h | 8 ++++++++ .../gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp | 20 ++++++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 3a0302562e6..d74243b0eb0 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -1315,6 +1315,12 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj, CreateMaterialFromBlenderObject(blenderobject, kxscene); KX_ObjectProperties objprop; + objprop.m_lockXaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_X_AXIS) !=0; + objprop.m_lockYaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Y_AXIS) !=0; + objprop.m_lockZaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Z_AXIS) !=0; + objprop.m_lockXRotaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_X_ROT_AXIS) !=0; + objprop.m_lockYRotaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Y_ROT_AXIS) !=0; + objprop.m_lockZRotaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Z_ROT_AXIS) !=0; objprop.m_isCompoundChild = isCompoundChild; objprop.m_hasCompoundChildren = (blenderobject->gameflag & OB_CHILD) != 0; diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h index edacf38ab43..3534500e619 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h @@ -127,6 +127,14 @@ struct KX_ObjectProperties ///////////////////////// + bool m_lockXaxis; + bool m_lockYaxis; + bool m_lockZaxis; + bool m_lockXRotaxis; + bool m_lockYRotaxis; + bool m_lockZRotaxis; + + ///////////////////////// double m_margin; KX_BoundBoxClass m_boundclass; union { diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 46e46b014b5..602486e0017 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -1101,8 +1101,24 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, { btRigidBody* rbody = physicscontroller->GetRigidBody(); - if (rbody && objprop->m_disableSleeping) - rbody->setActivationState(DISABLE_DEACTIVATION); + if (rbody) + { + btVector3 linearFactor( + objprop->m_lockXaxis? 0 : 1, + objprop->m_lockYaxis? 0 : 1, + objprop->m_lockZaxis? 0 : 1); + btVector3 angularFactor( + objprop->m_lockXRotaxis? 0 : 1, + objprop->m_lockYRotaxis? 0 : 1, + objprop->m_lockZRotaxis? 0 : 1); + rbody->setLinearFactor(linearFactor); + rbody->setAngularFactor(angularFactor); + + if (rbody && objprop->m_disableSleeping) + { + rbody->setActivationState(DISABLE_DEACTIVATION); + } + } } CcdPhysicsController* parentCtrl = objprop->m_dynamic_parent ? (KX_BulletPhysicsController*)objprop->m_dynamic_parent->GetPhysicsController() : 0; -- cgit v1.2.3 From a37cec2802d96306426f41c64f6ed69ab3680355 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 11 Mar 2009 22:11:52 +0000 Subject: BGE patch 18368: Modulus (ie %) expression controller in BGE. Implement a cache for the expression for better performance. --- source/gameengine/Expressions/FloatValue.cpp | 6 ++++ source/gameengine/Expressions/InputParser.cpp | 5 ++++ source/gameengine/Expressions/InputParser.h | 1 + source/gameengine/Expressions/IntValue.cpp | 6 ++++ source/gameengine/Expressions/Value.cpp | 9 +++++- source/gameengine/Expressions/Value.h | 1 + .../GameLogic/SCA_ExpressionController.cpp | 35 +++++++++++++++++----- .../GameLogic/SCA_ExpressionController.h | 6 ++++ source/gameengine/GameLogic/SCA_ILogicBrick.h | 1 + source/gameengine/GameLogic/SCA_IObject.cpp | 4 ++- source/gameengine/GameLogic/SCA_ISensor.h | 5 ---- source/gameengine/GameLogic/SCA_PropertySensor.h | 4 +++ 12 files changed, 68 insertions(+), 15 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/FloatValue.cpp b/source/gameengine/Expressions/FloatValue.cpp index 93f102d04a6..460eaa73f35 100644 --- a/source/gameengine/Expressions/FloatValue.cpp +++ b/source/gameengine/Expressions/FloatValue.cpp @@ -127,6 +127,9 @@ ret: a new object containing the result of applying operator op to val and { switch (op) { + case VALUE_MOD_OPERATOR: + ret = new CFloatValue(fmod(((CIntValue *) val)->GetInt(), m_float)); + break; case VALUE_ADD_OPERATOR: ret = new CFloatValue(((CIntValue *) val)->GetInt() + m_float); break; @@ -171,6 +174,9 @@ ret: a new object containing the result of applying operator op to val and { switch (op) { + case VALUE_MOD_OPERATOR: + ret = new CFloatValue(fmod(((CFloatValue *) val)->GetFloat(), m_float)); + break; case VALUE_ADD_OPERATOR: ret = new CFloatValue(((CFloatValue *) val)->GetFloat() + m_float); break; diff --git a/source/gameengine/Expressions/InputParser.cpp b/source/gameengine/Expressions/InputParser.cpp index e016fb8d007..94663c4a365 100644 --- a/source/gameengine/Expressions/InputParser.cpp +++ b/source/gameengine/Expressions/InputParser.cpp @@ -175,6 +175,9 @@ void CParser::NextSym() case ',': sym = commasym; NextCh(); break; + case '%' : + sym = opsym; opkind = OPmodulus; NextCh(); + break; case '+' : sym = opsym; opkind = OPplus; NextCh(); break; @@ -370,6 +373,7 @@ int CParser::Priority(int optorkind) { case OPunequal: return 3; case OPplus: case OPminus: return 4; + case OPmodulus: case OPtimes: case OPdivide: return 5; } @@ -390,6 +394,7 @@ CExpression *CParser::Ex(int i) { NextSym(); e2 = Ex(i + 1); switch(opkind2) { + case OPmodulus: e1 = new COperator2Expr(VALUE_MOD_OPERATOR,e1, e2); break; case OPplus: e1 = new COperator2Expr(VALUE_ADD_OPERATOR,e1, e2); break; case OPminus: e1 = new COperator2Expr(VALUE_SUB_OPERATOR,e1, e2); break; case OPtimes: e1 = new COperator2Expr(VALUE_MUL_OPERATOR,e1, e2); break; diff --git a/source/gameengine/Expressions/InputParser.h b/source/gameengine/Expressions/InputParser.h index 4caa47cbb0c..f51c473ba18 100644 --- a/source/gameengine/Expressions/InputParser.h +++ b/source/gameengine/Expressions/InputParser.h @@ -49,6 +49,7 @@ private: }; // all kinds of symbols enum optype { + OPmodulus, OPplus, OPminus, OPtimes, diff --git a/source/gameengine/Expressions/IntValue.cpp b/source/gameengine/Expressions/IntValue.cpp index fbf4f4f59e0..fb586cb4979 100644 --- a/source/gameengine/Expressions/IntValue.cpp +++ b/source/gameengine/Expressions/IntValue.cpp @@ -125,6 +125,9 @@ this object case VALUE_INT_TYPE: { switch (op) { + case VALUE_MOD_OPERATOR: + ret = new CIntValue (((CIntValue *) val)->GetInt() % m_int); + break; case VALUE_ADD_OPERATOR: ret = new CIntValue (((CIntValue *) val)->GetInt() + m_int); break; @@ -181,6 +184,9 @@ this object case VALUE_FLOAT_TYPE: { switch (op) { + case VALUE_MOD_OPERATOR: + ret = new CFloatValue(fmod(((CFloatValue *) val)->GetFloat(), m_int)); + break; case VALUE_ADD_OPERATOR: ret = new CFloatValue (((CFloatValue *) val)->GetFloat() + m_int); break; diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index d29e3961c65..ebb12636ac2 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -52,6 +52,10 @@ PyObject* cvalue_div(PyObject*v, PyObject*w) { return ((CValue*)v)->Calc(VALUE_DIV_OPERATOR,(CValue*)w); } +PyObject* cvalue_mod(PyObject*v, PyObject*w) +{ + return ((CValue*)v)->Calc(VALUE_MOD_OPERATOR,(CValue*)w); +} PyObject* cvalue_neg(PyObject*v) { return ((CValue*)v)->Calc(VALUE_NEG_OPERATOR,(CValue*)v); @@ -112,7 +116,7 @@ static PyNumberMethods cvalue_as_number = { (binaryfunc)cvalue_sub, /*nb_subtract*/ (binaryfunc)cvalue_mul, /*nb_multiply*/ (binaryfunc)cvalue_div, /*nb_divide*/ - 0,//(binaryfunc)cvalue_remainder, /*nb_remainder*/ + (binaryfunc)cvalue_mod, /*nb_remainder*/ 0,//(binaryfunc)cvalue_divmod, /*nb_divmod*/ 0,//0,//0,//0,//(ternaryfunc)cvalue_pow, /*nb_power*/ (unaryfunc)cvalue_neg, /*nb_negative*/ @@ -257,6 +261,9 @@ STR_String CValue::op2str (VALUE_OPERATOR op) STR_String opmsg; switch (op) { + case VALUE_MOD_OPERATOR: + opmsg = " % "; + break; case VALUE_ADD_OPERATOR: opmsg = " + "; break; diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h index 854334b892b..caf1064dc32 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/Value.h @@ -75,6 +75,7 @@ enum VALUE_OPERATOR { + VALUE_MOD_OPERATOR, // % VALUE_ADD_OPERATOR, // + VALUE_SUB_OPERATOR, // - VALUE_MUL_OPERATOR, // * diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.cpp b/source/gameengine/GameLogic/SCA_ExpressionController.cpp index e9a543c9f31..8ed46beb7f3 100644 --- a/source/gameengine/GameLogic/SCA_ExpressionController.cpp +++ b/source/gameengine/GameLogic/SCA_ExpressionController.cpp @@ -49,7 +49,8 @@ SCA_ExpressionController::SCA_ExpressionController(SCA_IObject* gameobj, const STR_String& exprtext, PyTypeObject* T) :SCA_IController(gameobj,T), - m_exprText(exprtext) + m_exprText(exprtext), + m_exprCache(NULL) { } @@ -57,6 +58,8 @@ SCA_ExpressionController::SCA_ExpressionController(SCA_IObject* gameobj, SCA_ExpressionController::~SCA_ExpressionController() { + if (m_exprCache) + m_exprCache->Release(); } @@ -65,6 +68,7 @@ CValue* SCA_ExpressionController::GetReplica() { SCA_ExpressionController* replica = new SCA_ExpressionController(*this); replica->m_exprText = m_exprText; + replica->m_exprCache = NULL; // this will copy properties and so on... CValue::AddDataToReplica(replica); @@ -72,18 +76,32 @@ CValue* SCA_ExpressionController::GetReplica() } +// Forced deletion of precalculated expression to break reference loop +// Use this function when you know that you won't use the sensor anymore +void SCA_ExpressionController::Delete() +{ + if (m_exprCache) + { + m_exprCache->Release(); + m_exprCache = NULL; + } + Release(); +} + void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr) { bool expressionresult = false; - - CParser parser; - parser.SetContext(this->AddRef()); - CExpression* expr = parser.ProcessText(m_exprText); - if (expr) + if (!m_exprCache) + { + CParser parser; + parser.SetContext(this->AddRef()); + m_exprCache = parser.ProcessText(m_exprText); + } + if (m_exprCache) { - CValue* value = expr->Calculate(); + CValue* value = m_exprCache->Calculate(); if (value) { if (value->IsError()) @@ -97,7 +115,8 @@ void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr) value->Release(); } - expr->Release(); + //m_exprCache->Release(); + //m_exprCache = NULL; } /* diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.h b/source/gameengine/GameLogic/SCA_ExpressionController.h index 20e1eb77771..79c26eea1e7 100644 --- a/source/gameengine/GameLogic/SCA_ExpressionController.h +++ b/source/gameengine/GameLogic/SCA_ExpressionController.h @@ -38,6 +38,7 @@ class SCA_ExpressionController : public SCA_IController { // Py_Header; STR_String m_exprText; + CExpression* m_exprCache; public: SCA_ExpressionController(SCA_IObject* gameobj, @@ -48,6 +49,11 @@ public: virtual CValue* GetReplica(); virtual void Trigger(SCA_LogicManager* logicmgr); virtual CValue* FindIdentifier(const STR_String& identifiername); + /** + * used to release the expression cache + * so that self references are removed before the controller itself is released + */ + virtual void Delete(); /* --------------------------------------------------------------------- */ /* Python interface ---------------------------------------------------- */ diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h index cde1353275b..70d49941613 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.h +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h @@ -62,6 +62,7 @@ public: SCA_IObject* GetParent(); virtual void ReParent(SCA_IObject* parent); virtual void Relink(GEN_Map *obj_map); + virtual void Delete() { Release(); } // act as a BoolValue (with value IsPositiveTrigger) virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp index d8f5f3eede5..debd62d44e6 100644 --- a/source/gameengine/GameLogic/SCA_IObject.cpp +++ b/source/gameengine/GameLogic/SCA_IObject.cpp @@ -59,7 +59,9 @@ SCA_IObject::~SCA_IObject() SCA_ControllerList::iterator itc; for (itc = m_controllers.begin(); !(itc == m_controllers.end()); ++itc) { - ((CValue*)(*itc))->Release(); + //Use Delete for controller to ensure proper cleaning (expression controller) + (*itc)->Delete(); + //((CValue*)(*itc))->Release(); } SCA_ActuatorList::iterator ita; for (ita = m_registeredActuators.begin(); !(ita==m_registeredActuators.end()); ++ita) diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h index 5ae7ced2a2a..23f2c76c19f 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.h +++ b/source/gameengine/GameLogic/SCA_ISensor.h @@ -105,11 +105,6 @@ public: bool negmode, int freq); - /** Release sensor - * For property sensor, it is used to release the pre-calculated expression - * so that self references are removed before the sensor itself is released - */ - virtual void Delete() { Release(); } /** Set inversion of pulses on or off. */ void SetInvert(bool inv); /** set the level detection on or off */ diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.h b/source/gameengine/GameLogic/SCA_PropertySensor.h index 933de49de18..2594e3fca9d 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.h +++ b/source/gameengine/GameLogic/SCA_PropertySensor.h @@ -70,6 +70,10 @@ public: KX_PROPSENSOR_TYPE checktype, PyTypeObject* T=&Type ); + /** + * For property sensor, it is used to release the pre-calculated expression + * so that self references are removed before the sensor itself is released + */ virtual void Delete(); virtual ~SCA_PropertySensor(); virtual CValue* GetReplica(); -- cgit v1.2.3 From 1e1b88c118d6e6b2df3f6240547acc92e2d08e15 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Sun, 15 Mar 2009 23:40:59 +0000 Subject: BGE * getting state of RMB was impossible due to wrong check. --- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index 36e4a5f2c30..57535b29f32 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -282,7 +282,7 @@ KX_PYMETHODDEF_DOC_O(SCA_MouseSensor, getButtonStatus, int button = PyInt_AsLong(value); if ((button < SCA_IInputDevice::KX_LEFTMOUSE) - || (button > SCA_IInputDevice::KX_MIDDLEMOUSE)){ + || (button > SCA_IInputDevice::KX_RIGHTMOUSE)){ PyErr_SetString(PyExc_ValueError, "invalid button specified!"); return NULL; } -- cgit v1.2.3 From 28f6d223d079b1e5cb67e3fc22fb7f818deb8dcb Mon Sep 17 00:00:00 2001 From: Kent Mein Date: Mon, 16 Mar 2009 17:02:19 +0000 Subject: This is patch: [#17974] two small fix for blender 2.48 (memory leak and uninitalized vars) Submitted By: Pavel Nemec (nemecp) (changes delete to [] and sets to vars to NULL) Kent --- source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index afee60c3192..018c966ac69 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -246,7 +246,7 @@ static void get_filename(int argc, char **argv, char *filename) if (BLI_exists(gamefile)) BLI_strncpy(filename, gamefile, FILE_MAXDIR + FILE_MAXFILE); - delete gamefile; + delete [] gamefile; } #else -- cgit v1.2.3