From fd2b1156783d52dbb7c93c53fe008d9e14cbffdd Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 3 Apr 2009 14:51:06 +0000 Subject: Python BGE API - Initialize python types with PyType_Ready, which adds methods to the type dictionary. - use Pythons get/setattro (uses a python string for the attribute rather then char*). Using basic C strings seems nice but internally python converts them to python strings and discards them for most functions that accept char arrays. - Method lookups use the PyTypes dictionary (should be faster then Py_FindMethod) - Renamed __getattr -> py_base_getattro, _getattr -> py_getattro, __repr -> py_base_repr, py_delattro, py_getattro_self etc. From here is possible to put all the parent classes methods into each python types dictionary to avoid nested lookups (api has 4 levels of lookups in some places), tested this but its not ready yet. Simple tests for getting a method within a loop show this to be between 0.5 and 3.2x faster then using Py_FindMethod() --- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 204 ++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 source/gameengine/Ketsji/KX_PythonInitTypes.cpp (limited to 'source/gameengine/Ketsji/KX_PythonInitTypes.cpp') diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp new file mode 100644 index 00000000000..e2ff4ced122 --- /dev/null +++ b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp @@ -0,0 +1,204 @@ +/** + * $Id: PyObjectPlus.h 19511 2009-04-03 02:16:56Z campbellbarton $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + + + +#ifndef _adr_py_init_types_h_ // only process once, +#define _adr_py_init_types_h_ // even if multiply included + +/* Only for Class::Parents */ +#include "BL_BlenderShader.h" +#include "BL_ShapeActionActuator.h" +#include "KX_BlenderMaterial.h" +#include "KX_CDActuator.h" +#include "KX_CameraActuator.h" +#include "KX_ConstraintActuator.h" +#include "KX_ConstraintWrapper.h" +#include "KX_GameActuator.h" +#include "KX_Light.h" +#include "KX_MeshProxy.h" +#include "KX_MouseFocusSensor.h" +#include "KX_NetworkMessageActuator.h" +#include "KX_NetworkMessageSensor.h" +#include "KX_ObjectActuator.h" +#include "KX_ParentActuator.h" +#include "KX_PhysicsObjectWrapper.h" +#include "KX_PolyProxy.h" +#include "KX_PolygonMaterial.h" +#include "KX_SCA_AddObjectActuator.h" +#include "KX_SCA_EndObjectActuator.h" +#include "KX_SCA_ReplaceMeshActuator.h" +#include "KX_SceneActuator.h" +#include "KX_StateActuator.h" +#include "KX_TrackToActuator.h" +#include "KX_VehicleWrapper.h" +#include "KX_VertexProxy.h" +#include "SCA_2DFilterActuator.h" +#include "SCA_ANDController.h" +#include "SCA_ActuatorSensor.h" +#include "SCA_AlwaysSensor.h" +#include "SCA_DelaySensor.h" +#include "SCA_JoystickSensor.h" +#include "SCA_KeyboardSensor.h" +#include "SCA_MouseSensor.h" +#include "SCA_NANDController.h" +#include "SCA_NORController.h" +#include "SCA_ORController.h" +#include "SCA_RandomSensor.h" +#include "SCA_XNORController.h" +#include "SCA_XORController.h" +#include "KX_IpoActuator.h" +#include "KX_NearSensor.h" +#include "KX_RadarSensor.h" +#include "KX_RaySensor.h" +#include "KX_SCA_DynamicActuator.h" +#include "KX_SoundActuator.h" +#include "KX_TouchSensor.h" +#include "SCA_PropertySensor.h" +#include "SCA_PythonController.h" +#include "SCA_RandomActuator.h" + + +void initPyObjectPlusType(PyTypeObject **parents) +{ + int i; + + for (i=0; parents[i]; i++) { + if(PyType_Ready(parents[i]) < 0) { + /* This is very very unlikely */ + printf("Error, pytype could not initialize, Blender may crash \"%s\"\n", parents[i]->tp_name); + return; + } + +#if 0 + PyObject_Print((PyObject *)parents[i], stderr, 0); + fprintf(stderr, "\n"); + PyObject_Print(parents[i]->tp_dict, stderr, 0); + fprintf(stderr, "\n\n"); +#endif + + } + + PyObject *dict= NULL; + + while(i) { + i--; + + if (dict) { + PyDict_Update(parents[i]->tp_dict, dict); + } + dict= parents[i]->tp_dict; + +#if 1 + PyObject_Print((PyObject *)parents[i], stderr, 0); + fprintf(stderr, "\n"); + PyObject_Print(parents[i]->tp_dict, stderr, 0); + fprintf(stderr, "\n\n"); +#endif + + } +} + + + + +void initPyTypes(void) +{ + +/* + initPyObjectPlusType(BL_ActionActuator::Parents); + ..... +*/ + + /* For now just do PyType_Ready */ + + PyType_Ready(&BL_ActionActuator::Type); + PyType_Ready(&BL_Shader::Type); + PyType_Ready(&BL_ShapeActionActuator::Type); + PyType_Ready(&CListValue::Type); + PyType_Ready(&CValue::Type); + PyType_Ready(&KX_BlenderMaterial::Type); + PyType_Ready(&KX_CDActuator::Type); + PyType_Ready(&KX_Camera::Type); + PyType_Ready(&KX_CameraActuator::Type); + PyType_Ready(&KX_ConstraintActuator::Type); + PyType_Ready(&KX_ConstraintWrapper::Type); + PyType_Ready(&KX_GameActuator::Type); + PyType_Ready(&KX_GameObject::Type); + PyType_Ready(&KX_IpoActuator::Type); + PyType_Ready(&KX_LightObject::Type); + PyType_Ready(&KX_MeshProxy::Type); + PyType_Ready(&KX_MouseFocusSensor::Type); + PyType_Ready(&KX_NearSensor::Type); + PyType_Ready(&KX_NetworkMessageActuator::Type); + PyType_Ready(&KX_NetworkMessageSensor::Type); + PyType_Ready(&KX_ObjectActuator::Type); + PyType_Ready(&KX_ParentActuator::Type); + PyType_Ready(&KX_PhysicsObjectWrapper::Type); + PyType_Ready(&KX_PolyProxy::Type); + PyType_Ready(&KX_PolygonMaterial::Type); + PyType_Ready(&KX_RadarSensor::Type); + PyType_Ready(&KX_RaySensor::Type); + PyType_Ready(&KX_SCA_AddObjectActuator::Type); + PyType_Ready(&KX_SCA_DynamicActuator::Type); + PyType_Ready(&KX_SCA_EndObjectActuator::Type); + PyType_Ready(&KX_SCA_ReplaceMeshActuator::Type); + PyType_Ready(&KX_Scene::Type); + PyType_Ready(&KX_SceneActuator::Type); + PyType_Ready(&KX_SoundActuator::Type); + PyType_Ready(&KX_StateActuator::Type); + PyType_Ready(&KX_TouchSensor::Type); + PyType_Ready(&KX_TrackToActuator::Type); + PyType_Ready(&KX_VehicleWrapper::Type); + PyType_Ready(&KX_VertexProxy::Type); + PyType_Ready(&PyObjectPlus::Type); + PyType_Ready(&SCA_2DFilterActuator::Type); + PyType_Ready(&SCA_ANDController::Type); + PyType_Ready(&SCA_ActuatorSensor::Type); + PyType_Ready(&SCA_AlwaysSensor::Type); + PyType_Ready(&SCA_DelaySensor::Type); + PyType_Ready(&SCA_ILogicBrick::Type); + PyType_Ready(&SCA_IObject::Type); + PyType_Ready(&SCA_ISensor::Type); + PyType_Ready(&SCA_JoystickSensor::Type); + PyType_Ready(&SCA_KeyboardSensor::Type); + PyType_Ready(&SCA_MouseSensor::Type); + PyType_Ready(&SCA_NANDController::Type); + PyType_Ready(&SCA_NORController::Type); + PyType_Ready(&SCA_ORController::Type); + PyType_Ready(&SCA_PropertyActuator::Type); + PyType_Ready(&SCA_PropertySensor::Type); + PyType_Ready(&SCA_PythonController::Type); + PyType_Ready(&SCA_RandomActuator::Type); + PyType_Ready(&SCA_RandomSensor::Type); + PyType_Ready(&SCA_XNORController::Type); + PyType_Ready(&SCA_XORController::Type); +} + +#endif \ No newline at end of file -- cgit v1.2.3 From 033a63f8580227582a9695ebdd78ac0b4322e867 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 5 Apr 2009 14:01:49 +0000 Subject: BGE Bugfixes (mostly in the py api) KX_PolygonMaterial and KX_BlenderMaterial - Added a print function (would raise a python error on printing) * Crashes * KX_GameObject SetParent - Disallowed setting a parent to its self, caused a recursion crash. KX_MeshProxy "materials" attribute was segfaulting because of my recent change - I was wrong, you do need to check material types (no idea why since they are both PyObject * at the base) KX_VisibilityActuator - Wasn't initialized with PyType_Ready() making it crash on access (own fault) * Crashes because of missing NULL checks * KX_PolygonMaterial's "gl_texture" attribute wasnt checking for a valid m_tface KX_GameObject - added checks for GetPhysicsController() KX_RayCast::RayTest - didnt check for a valid physics_environment KX_SceneActuator's getCamera python function wasnt checking if there was a camera. --- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source/gameengine/Ketsji/KX_PythonInitTypes.cpp') diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp index e2ff4ced122..8eeed5d853b 100644 --- a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp +++ b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp @@ -80,6 +80,7 @@ #include "KX_SCA_DynamicActuator.h" #include "KX_SoundActuator.h" #include "KX_TouchSensor.h" +#include "KX_VisibilityActuator.h" #include "SCA_PropertySensor.h" #include "SCA_PythonController.h" #include "SCA_RandomActuator.h" @@ -177,6 +178,7 @@ void initPyTypes(void) PyType_Ready(&KX_TrackToActuator::Type); PyType_Ready(&KX_VehicleWrapper::Type); PyType_Ready(&KX_VertexProxy::Type); + PyType_Ready(&KX_VisibilityActuator::Type); PyType_Ready(&PyObjectPlus::Type); PyType_Ready(&SCA_2DFilterActuator::Type); PyType_Ready(&SCA_ANDController::Type); -- cgit v1.2.3 From 46a440c7a5393177dbc74cef466d1eb5643e068d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 6 Apr 2009 13:27:28 +0000 Subject: BGE Python API - added a module for the BGE - GameTypes, only contains types. - added KX_PYATTRIBUTE_DUMMY attributes for KX_Light, KX_PolyProxy, KX_VertexProxy, so all types should give correct results from a dir(). - added a script to check for missing methods in the epydocs - bge_api_validate_py.txt --- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 140 +++++++++++++----------- 1 file changed, 77 insertions(+), 63 deletions(-) (limited to 'source/gameengine/Ketsji/KX_PythonInitTypes.cpp') diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp index 8eeed5d853b..29a7a5f85f2 100644 --- a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp +++ b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp @@ -129,6 +129,13 @@ void initPyObjectPlusType(PyTypeObject **parents) +static int PyType_Ready_ADD(PyObject *dict, PyTypeObject * tp) +{ + PyType_Ready(tp); + PyDict_SetItemString(dict, tp->tp_name, (PyObject *)tp); +} + + void initPyTypes(void) { @@ -138,69 +145,76 @@ void initPyTypes(void) */ /* For now just do PyType_Ready */ - - PyType_Ready(&BL_ActionActuator::Type); - PyType_Ready(&BL_Shader::Type); - PyType_Ready(&BL_ShapeActionActuator::Type); - PyType_Ready(&CListValue::Type); - PyType_Ready(&CValue::Type); - PyType_Ready(&KX_BlenderMaterial::Type); - PyType_Ready(&KX_CDActuator::Type); - PyType_Ready(&KX_Camera::Type); - PyType_Ready(&KX_CameraActuator::Type); - PyType_Ready(&KX_ConstraintActuator::Type); - PyType_Ready(&KX_ConstraintWrapper::Type); - PyType_Ready(&KX_GameActuator::Type); - PyType_Ready(&KX_GameObject::Type); - PyType_Ready(&KX_IpoActuator::Type); - PyType_Ready(&KX_LightObject::Type); - PyType_Ready(&KX_MeshProxy::Type); - PyType_Ready(&KX_MouseFocusSensor::Type); - PyType_Ready(&KX_NearSensor::Type); - PyType_Ready(&KX_NetworkMessageActuator::Type); - PyType_Ready(&KX_NetworkMessageSensor::Type); - PyType_Ready(&KX_ObjectActuator::Type); - PyType_Ready(&KX_ParentActuator::Type); - PyType_Ready(&KX_PhysicsObjectWrapper::Type); - PyType_Ready(&KX_PolyProxy::Type); - PyType_Ready(&KX_PolygonMaterial::Type); - PyType_Ready(&KX_RadarSensor::Type); - PyType_Ready(&KX_RaySensor::Type); - PyType_Ready(&KX_SCA_AddObjectActuator::Type); - PyType_Ready(&KX_SCA_DynamicActuator::Type); - PyType_Ready(&KX_SCA_EndObjectActuator::Type); - PyType_Ready(&KX_SCA_ReplaceMeshActuator::Type); - PyType_Ready(&KX_Scene::Type); - PyType_Ready(&KX_SceneActuator::Type); - PyType_Ready(&KX_SoundActuator::Type); - PyType_Ready(&KX_StateActuator::Type); - PyType_Ready(&KX_TouchSensor::Type); - PyType_Ready(&KX_TrackToActuator::Type); - PyType_Ready(&KX_VehicleWrapper::Type); - PyType_Ready(&KX_VertexProxy::Type); - PyType_Ready(&KX_VisibilityActuator::Type); - PyType_Ready(&PyObjectPlus::Type); - PyType_Ready(&SCA_2DFilterActuator::Type); - PyType_Ready(&SCA_ANDController::Type); - PyType_Ready(&SCA_ActuatorSensor::Type); - PyType_Ready(&SCA_AlwaysSensor::Type); - PyType_Ready(&SCA_DelaySensor::Type); - PyType_Ready(&SCA_ILogicBrick::Type); - PyType_Ready(&SCA_IObject::Type); - PyType_Ready(&SCA_ISensor::Type); - PyType_Ready(&SCA_JoystickSensor::Type); - PyType_Ready(&SCA_KeyboardSensor::Type); - PyType_Ready(&SCA_MouseSensor::Type); - PyType_Ready(&SCA_NANDController::Type); - PyType_Ready(&SCA_NORController::Type); - PyType_Ready(&SCA_ORController::Type); - PyType_Ready(&SCA_PropertyActuator::Type); - PyType_Ready(&SCA_PropertySensor::Type); - PyType_Ready(&SCA_PythonController::Type); - PyType_Ready(&SCA_RandomActuator::Type); - PyType_Ready(&SCA_RandomSensor::Type); - PyType_Ready(&SCA_XNORController::Type); - PyType_Ready(&SCA_XORController::Type); + PyObject *mod= PyModule_New("GameTypes"); + PyObject *dict= PyModule_GetDict(mod); + PyDict_SetItemString(PySys_GetObject("modules"), "GameTypes", mod); + Py_DECREF(mod); + + PyType_Ready_ADD(dict, &BL_ActionActuator::Type); + PyType_Ready_ADD(dict, &BL_Shader::Type); + PyType_Ready_ADD(dict, &BL_ShapeActionActuator::Type); + PyType_Ready_ADD(dict, &CListValue::Type); + PyType_Ready_ADD(dict, &CValue::Type); + PyType_Ready_ADD(dict, &KX_BlenderMaterial::Type); + PyType_Ready_ADD(dict, &KX_CDActuator::Type); + PyType_Ready_ADD(dict, &KX_Camera::Type); + PyType_Ready_ADD(dict, &KX_CameraActuator::Type); + PyType_Ready_ADD(dict, &KX_ConstraintActuator::Type); + PyType_Ready_ADD(dict, &KX_ConstraintWrapper::Type); + PyType_Ready_ADD(dict, &KX_GameActuator::Type); + PyType_Ready_ADD(dict, &KX_GameObject::Type); + PyType_Ready_ADD(dict, &KX_IpoActuator::Type); + PyType_Ready_ADD(dict, &KX_LightObject::Type); + PyType_Ready_ADD(dict, &KX_MeshProxy::Type); + PyType_Ready_ADD(dict, &KX_MouseFocusSensor::Type); + PyType_Ready_ADD(dict, &KX_NearSensor::Type); + PyType_Ready_ADD(dict, &KX_NetworkMessageActuator::Type); + PyType_Ready_ADD(dict, &KX_NetworkMessageSensor::Type); + PyType_Ready_ADD(dict, &KX_ObjectActuator::Type); + PyType_Ready_ADD(dict, &KX_ParentActuator::Type); + PyType_Ready_ADD(dict, &KX_PhysicsObjectWrapper::Type); + PyType_Ready_ADD(dict, &KX_PolyProxy::Type); + PyType_Ready_ADD(dict, &KX_PolygonMaterial::Type); + PyType_Ready_ADD(dict, &KX_RadarSensor::Type); + PyType_Ready_ADD(dict, &KX_RaySensor::Type); + PyType_Ready_ADD(dict, &KX_SCA_AddObjectActuator::Type); + PyType_Ready_ADD(dict, &KX_SCA_DynamicActuator::Type); + PyType_Ready_ADD(dict, &KX_SCA_EndObjectActuator::Type); + PyType_Ready_ADD(dict, &KX_SCA_ReplaceMeshActuator::Type); + PyType_Ready_ADD(dict, &KX_Scene::Type); + PyType_Ready_ADD(dict, &KX_SceneActuator::Type); + PyType_Ready_ADD(dict, &KX_SoundActuator::Type); + PyType_Ready_ADD(dict, &KX_StateActuator::Type); + PyType_Ready_ADD(dict, &KX_TouchSensor::Type); + PyType_Ready_ADD(dict, &KX_TrackToActuator::Type); + PyType_Ready_ADD(dict, &KX_VehicleWrapper::Type); + PyType_Ready_ADD(dict, &KX_VertexProxy::Type); + PyType_Ready_ADD(dict, &KX_VisibilityActuator::Type); + PyType_Ready_ADD(dict, &PyObjectPlus::Type); + PyType_Ready_ADD(dict, &SCA_2DFilterActuator::Type); + PyType_Ready_ADD(dict, &SCA_ANDController::Type); + PyType_Ready_ADD(dict, &SCA_ActuatorSensor::Type); + PyType_Ready_ADD(dict, &SCA_AlwaysSensor::Type); + PyType_Ready_ADD(dict, &SCA_DelaySensor::Type); + PyType_Ready_ADD(dict, &SCA_ILogicBrick::Type); + PyType_Ready_ADD(dict, &SCA_IObject::Type); + PyType_Ready_ADD(dict, &SCA_ISensor::Type); + PyType_Ready_ADD(dict, &SCA_JoystickSensor::Type); + PyType_Ready_ADD(dict, &SCA_KeyboardSensor::Type); + PyType_Ready_ADD(dict, &SCA_MouseSensor::Type); + PyType_Ready_ADD(dict, &SCA_NANDController::Type); + PyType_Ready_ADD(dict, &SCA_NORController::Type); + PyType_Ready_ADD(dict, &SCA_ORController::Type); + PyType_Ready_ADD(dict, &SCA_PropertyActuator::Type); + PyType_Ready_ADD(dict, &SCA_PropertySensor::Type); + PyType_Ready_ADD(dict, &SCA_PythonController::Type); + PyType_Ready_ADD(dict, &SCA_RandomActuator::Type); + PyType_Ready_ADD(dict, &SCA_RandomSensor::Type); + PyType_Ready_ADD(dict, &SCA_XNORController::Type); + PyType_Ready_ADD(dict, &SCA_XORController::Type); + + + } #endif \ No newline at end of file -- cgit v1.2.3 From 816a9f3acb47f97d5bf92ae7ae8803e31f4a9f0a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Apr 2009 03:20:59 +0000 Subject: error in last commit --- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/gameengine/Ketsji/KX_PythonInitTypes.cpp') diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp index 29a7a5f85f2..676033cb898 100644 --- a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp +++ b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp @@ -129,7 +129,7 @@ void initPyObjectPlusType(PyTypeObject **parents) -static int PyType_Ready_ADD(PyObject *dict, PyTypeObject * tp) +static void PyType_Ready_ADD(PyObject *dict, PyTypeObject * tp) { PyType_Ready(tp); PyDict_SetItemString(dict, tp->tp_name, (PyObject *)tp); -- cgit v1.2.3 From 5d64dd019e7e8150db40505097d1b4048f4e0153 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Apr 2009 11:06:35 +0000 Subject: BGE Python API Use each types dictionary to store attributes PyAttributeDef's so it uses pythons hash lookup (which it was already doing for methods) rather then doing a string lookup on the array each time. This also means attributes can be found in the type without having to do a dir() on the instance. --- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 139 +++++++++++++----------- 1 file changed, 76 insertions(+), 63 deletions(-) (limited to 'source/gameengine/Ketsji/KX_PythonInitTypes.cpp') diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp index 676033cb898..636814b9009 100644 --- a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp +++ b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp @@ -129,13 +129,26 @@ void initPyObjectPlusType(PyTypeObject **parents) -static void PyType_Ready_ADD(PyObject *dict, PyTypeObject * tp) +static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *attributes) { + PyAttributeDef *attr; + PyObject *item; + PyType_Ready(tp); PyDict_SetItemString(dict, tp->tp_name, (PyObject *)tp); + + /* store attr defs in the tp_dict for to avoid string lookups */ + for(attr= attributes; attr->m_name; attr++) { + item= PyCObject_FromVoidPtr(attr, NULL); + PyDict_SetItemString(tp->tp_dict, attr->m_name, item); + Py_DECREF(item); + } + } +#define PyType_Ready_Attr(d, n) PyType_Ready_ADD(d, &n::Type, n::Attributes) + void initPyTypes(void) { @@ -150,68 +163,68 @@ void initPyTypes(void) PyDict_SetItemString(PySys_GetObject("modules"), "GameTypes", mod); Py_DECREF(mod); - PyType_Ready_ADD(dict, &BL_ActionActuator::Type); - PyType_Ready_ADD(dict, &BL_Shader::Type); - PyType_Ready_ADD(dict, &BL_ShapeActionActuator::Type); - PyType_Ready_ADD(dict, &CListValue::Type); - PyType_Ready_ADD(dict, &CValue::Type); - PyType_Ready_ADD(dict, &KX_BlenderMaterial::Type); - PyType_Ready_ADD(dict, &KX_CDActuator::Type); - PyType_Ready_ADD(dict, &KX_Camera::Type); - PyType_Ready_ADD(dict, &KX_CameraActuator::Type); - PyType_Ready_ADD(dict, &KX_ConstraintActuator::Type); - PyType_Ready_ADD(dict, &KX_ConstraintWrapper::Type); - PyType_Ready_ADD(dict, &KX_GameActuator::Type); - PyType_Ready_ADD(dict, &KX_GameObject::Type); - PyType_Ready_ADD(dict, &KX_IpoActuator::Type); - PyType_Ready_ADD(dict, &KX_LightObject::Type); - PyType_Ready_ADD(dict, &KX_MeshProxy::Type); - PyType_Ready_ADD(dict, &KX_MouseFocusSensor::Type); - PyType_Ready_ADD(dict, &KX_NearSensor::Type); - PyType_Ready_ADD(dict, &KX_NetworkMessageActuator::Type); - PyType_Ready_ADD(dict, &KX_NetworkMessageSensor::Type); - PyType_Ready_ADD(dict, &KX_ObjectActuator::Type); - PyType_Ready_ADD(dict, &KX_ParentActuator::Type); - PyType_Ready_ADD(dict, &KX_PhysicsObjectWrapper::Type); - PyType_Ready_ADD(dict, &KX_PolyProxy::Type); - PyType_Ready_ADD(dict, &KX_PolygonMaterial::Type); - PyType_Ready_ADD(dict, &KX_RadarSensor::Type); - PyType_Ready_ADD(dict, &KX_RaySensor::Type); - PyType_Ready_ADD(dict, &KX_SCA_AddObjectActuator::Type); - PyType_Ready_ADD(dict, &KX_SCA_DynamicActuator::Type); - PyType_Ready_ADD(dict, &KX_SCA_EndObjectActuator::Type); - PyType_Ready_ADD(dict, &KX_SCA_ReplaceMeshActuator::Type); - PyType_Ready_ADD(dict, &KX_Scene::Type); - PyType_Ready_ADD(dict, &KX_SceneActuator::Type); - PyType_Ready_ADD(dict, &KX_SoundActuator::Type); - PyType_Ready_ADD(dict, &KX_StateActuator::Type); - PyType_Ready_ADD(dict, &KX_TouchSensor::Type); - PyType_Ready_ADD(dict, &KX_TrackToActuator::Type); - PyType_Ready_ADD(dict, &KX_VehicleWrapper::Type); - PyType_Ready_ADD(dict, &KX_VertexProxy::Type); - PyType_Ready_ADD(dict, &KX_VisibilityActuator::Type); - PyType_Ready_ADD(dict, &PyObjectPlus::Type); - PyType_Ready_ADD(dict, &SCA_2DFilterActuator::Type); - PyType_Ready_ADD(dict, &SCA_ANDController::Type); - PyType_Ready_ADD(dict, &SCA_ActuatorSensor::Type); - PyType_Ready_ADD(dict, &SCA_AlwaysSensor::Type); - PyType_Ready_ADD(dict, &SCA_DelaySensor::Type); - PyType_Ready_ADD(dict, &SCA_ILogicBrick::Type); - PyType_Ready_ADD(dict, &SCA_IObject::Type); - PyType_Ready_ADD(dict, &SCA_ISensor::Type); - PyType_Ready_ADD(dict, &SCA_JoystickSensor::Type); - PyType_Ready_ADD(dict, &SCA_KeyboardSensor::Type); - PyType_Ready_ADD(dict, &SCA_MouseSensor::Type); - PyType_Ready_ADD(dict, &SCA_NANDController::Type); - PyType_Ready_ADD(dict, &SCA_NORController::Type); - PyType_Ready_ADD(dict, &SCA_ORController::Type); - PyType_Ready_ADD(dict, &SCA_PropertyActuator::Type); - PyType_Ready_ADD(dict, &SCA_PropertySensor::Type); - PyType_Ready_ADD(dict, &SCA_PythonController::Type); - PyType_Ready_ADD(dict, &SCA_RandomActuator::Type); - PyType_Ready_ADD(dict, &SCA_RandomSensor::Type); - PyType_Ready_ADD(dict, &SCA_XNORController::Type); - PyType_Ready_ADD(dict, &SCA_XORController::Type); + PyType_Ready_Attr(dict, BL_ActionActuator); + PyType_Ready_Attr(dict, BL_Shader); + PyType_Ready_Attr(dict, BL_ShapeActionActuator); + PyType_Ready_Attr(dict, CListValue); + PyType_Ready_Attr(dict, CValue); + PyType_Ready_Attr(dict, KX_BlenderMaterial); + PyType_Ready_Attr(dict, KX_CDActuator); + PyType_Ready_Attr(dict, KX_Camera); + PyType_Ready_Attr(dict, KX_CameraActuator); + PyType_Ready_Attr(dict, KX_ConstraintActuator); + PyType_Ready_Attr(dict, KX_ConstraintWrapper); + PyType_Ready_Attr(dict, KX_GameActuator); + PyType_Ready_Attr(dict, KX_GameObject); + PyType_Ready_Attr(dict, KX_IpoActuator); + PyType_Ready_Attr(dict, KX_LightObject); + PyType_Ready_Attr(dict, KX_MeshProxy); + PyType_Ready_Attr(dict, KX_MouseFocusSensor); + PyType_Ready_Attr(dict, KX_NearSensor); + PyType_Ready_Attr(dict, KX_NetworkMessageActuator); + PyType_Ready_Attr(dict, KX_NetworkMessageSensor); + PyType_Ready_Attr(dict, KX_ObjectActuator); + PyType_Ready_Attr(dict, KX_ParentActuator); + PyType_Ready_Attr(dict, KX_PhysicsObjectWrapper); + PyType_Ready_Attr(dict, KX_PolyProxy); + PyType_Ready_Attr(dict, KX_PolygonMaterial); + PyType_Ready_Attr(dict, KX_RadarSensor); + PyType_Ready_Attr(dict, KX_RaySensor); + PyType_Ready_Attr(dict, KX_SCA_AddObjectActuator); + PyType_Ready_Attr(dict, KX_SCA_DynamicActuator); + PyType_Ready_Attr(dict, KX_SCA_EndObjectActuator); + PyType_Ready_Attr(dict, KX_SCA_ReplaceMeshActuator); + PyType_Ready_Attr(dict, KX_Scene); + PyType_Ready_Attr(dict, KX_SceneActuator); + PyType_Ready_Attr(dict, KX_SoundActuator); + PyType_Ready_Attr(dict, KX_StateActuator); + PyType_Ready_Attr(dict, KX_TouchSensor); + PyType_Ready_Attr(dict, KX_TrackToActuator); + PyType_Ready_Attr(dict, KX_VehicleWrapper); + PyType_Ready_Attr(dict, KX_VertexProxy); + PyType_Ready_Attr(dict, KX_VisibilityActuator); + PyType_Ready_Attr(dict, PyObjectPlus); + PyType_Ready_Attr(dict, SCA_2DFilterActuator); + PyType_Ready_Attr(dict, SCA_ANDController); + PyType_Ready_Attr(dict, SCA_ActuatorSensor); + PyType_Ready_Attr(dict, SCA_AlwaysSensor); + PyType_Ready_Attr(dict, SCA_DelaySensor); + PyType_Ready_Attr(dict, SCA_ILogicBrick); + PyType_Ready_Attr(dict, SCA_IObject); + PyType_Ready_Attr(dict, SCA_ISensor); + PyType_Ready_Attr(dict, SCA_JoystickSensor); + PyType_Ready_Attr(dict, SCA_KeyboardSensor); + PyType_Ready_Attr(dict, SCA_MouseSensor); + PyType_Ready_Attr(dict, SCA_NANDController); + PyType_Ready_Attr(dict, SCA_NORController); + PyType_Ready_Attr(dict, SCA_ORController); + PyType_Ready_Attr(dict, SCA_PropertyActuator); + PyType_Ready_Attr(dict, SCA_PropertySensor); + PyType_Ready_Attr(dict, SCA_PythonController); + PyType_Ready_Attr(dict, SCA_RandomActuator); + PyType_Ready_Attr(dict, SCA_RandomSensor); + PyType_Ready_Attr(dict, SCA_XNORController); + PyType_Ready_Attr(dict, SCA_XORController); -- cgit v1.2.3 From 6f12e584a97f664c654ddfbe5f721d2a7be3d491 Mon Sep 17 00:00:00 2001 From: "Guillermo S. Romero" Date: Mon, 13 Apr 2009 19:33:22 +0000 Subject: SVN maintenance. --- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/gameengine/Ketsji/KX_PythonInitTypes.cpp') diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp index 636814b9009..06163ec8c4f 100644 --- a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp +++ b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp @@ -1,5 +1,5 @@ /** - * $Id: PyObjectPlus.h 19511 2009-04-03 02:16:56Z campbellbarton $ + * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** * -- cgit v1.2.3 From 8d2cb5bea44f4245dd17f2d82cbd0251d8090fd5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 19 Apr 2009 12:46:39 +0000 Subject: BGE Python API This changes how the BGE classes and Python work together, which hasnt changed since blender went opensource. The main difference is PyObjectPlus - the base class for most game engine classes, no longer inherit from PyObject, and cannot be cast to a PyObject. This has the advantage that the BGE does not have to keep 2 reference counts valid for C++ and Python. Previously C++ classes would never be freed while python held a reference, however this reference could be problematic eg: a GameObject that isnt in a scene anymore should not be used by python, doing so could even crash blender in some cases. Instead PyObjectPlus has a member "PyObject *m_proxy" which is lazily initialized when python needs it. m_proxy reference counts are managed by python, though it should never be freed while the C++ class exists since it holds a reference to avoid making and freeing it all the time. When the C++ class is free'd it sets the m_proxy reference to NULL, If python accesses this variable it will raise a RuntimeError, (check the isValid attribute to see if its valid without raising an error). - This replaces the m_zombie bool and IsZombie() tests added recently. In python return values that used to be.. return value->AddRef(); Are now return value->GetProxy(); or... return value->NewProxy(true); // true means python owns this C++ value which will be deleted when the PyObject is freed --- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/gameengine/Ketsji/KX_PythonInitTypes.cpp') diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp index 06163ec8c4f..2bf60dbc102 100644 --- a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp +++ b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp @@ -98,7 +98,7 @@ void initPyObjectPlusType(PyTypeObject **parents) } #if 0 - PyObject_Print((PyObject *)parents[i], stderr, 0); + PyObject_Print(reinterpret_castparents[i], stderr, 0); fprintf(stderr, "\n"); PyObject_Print(parents[i]->tp_dict, stderr, 0); fprintf(stderr, "\n\n"); @@ -117,7 +117,7 @@ void initPyObjectPlusType(PyTypeObject **parents) dict= parents[i]->tp_dict; #if 1 - PyObject_Print((PyObject *)parents[i], stderr, 0); + PyObject_Print(reinterpret_cast(parents[i]), stderr, 0); fprintf(stderr, "\n"); PyObject_Print(parents[i]->tp_dict, stderr, 0); fprintf(stderr, "\n\n"); @@ -135,7 +135,7 @@ static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *a PyObject *item; PyType_Ready(tp); - PyDict_SetItemString(dict, tp->tp_name, (PyObject *)tp); + PyDict_SetItemString(dict, tp->tp_name, reinterpret_cast(tp)); /* store attr defs in the tp_dict for to avoid string lookups */ for(attr= attributes; attr->m_name; attr++) { -- cgit v1.2.3 From 6bc162e679d8b52b28e205de76985a1735abbf0a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 19 Apr 2009 17:29:07 +0000 Subject: BGE Python API removed redundant (PyObject *self) argument from python functions that are not exposed to python directly. --- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/gameengine/Ketsji/KX_PythonInitTypes.cpp') diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp index 2bf60dbc102..dcd11b551a1 100644 --- a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp +++ b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp @@ -160,7 +160,7 @@ void initPyTypes(void) /* For now just do PyType_Ready */ PyObject *mod= PyModule_New("GameTypes"); PyObject *dict= PyModule_GetDict(mod); - PyDict_SetItemString(PySys_GetObject("modules"), "GameTypes", mod); + PyDict_SetItemString(PySys_GetObject((char *)"modules"), (char *)"GameTypes", mod); Py_DECREF(mod); PyType_Ready_Attr(dict, BL_ActionActuator); -- cgit v1.2.3