From 2a373f6c44756773ae45690848791de76704b37d Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 17 Mar 2009 22:03:21 +0000 Subject: Fix for bug #18419: game engine debug drawing interfered with alpha blending. --- .../RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp | 23 +++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index d4d1b73c772..765ff0174ee 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -327,17 +327,23 @@ void RAS_OpenGLRasterizer::ClearCachingInfo(void) m_materialCachingInfo = 0; } -void RAS_OpenGLRasterizer::FlushDebugLines() +void RAS_OpenGLRasterizer::FlushDebugLines() { -//DrawDebugLines - glDisable(GL_LIGHTING); - glDisable(GL_TEXTURE_2D); + if(!m_debugLines.size()) + return; + + // DrawDebugLines + GLboolean light, tex; + + light= glIsEnabled(GL_LIGHTING); + tex= glIsEnabled(GL_TEXTURE_2D); + + if(light) glDisable(GL_LIGHTING); + if(tex) glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); for (unsigned int i=0;i Date: Sun, 22 Mar 2009 17:03:55 +0000 Subject: removed edgecode from the game engines RAS_Polygon class since its not used --- source/gameengine/Rasterizer/RAS_Polygon.cpp | 5 +++-- source/gameengine/Rasterizer/RAS_Polygon.h | 11 ++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Rasterizer/RAS_Polygon.cpp b/source/gameengine/Rasterizer/RAS_Polygon.cpp index 50331d7a664..66b14bb60b0 100644 --- a/source/gameengine/Rasterizer/RAS_Polygon.cpp +++ b/source/gameengine/Rasterizer/RAS_Polygon.cpp @@ -39,7 +39,7 @@ RAS_Polygon::RAS_Polygon(RAS_MaterialBucket* bucket, RAS_DisplayArray *darray, i m_offset[0]= m_offset[1]= m_offset[2]= m_offset[3]= 0; m_numvert = numvert; - m_edgecode = 255; +// m_edgecode = 255; m_polyflags = 0; } @@ -63,6 +63,7 @@ int RAS_Polygon::GetVertexOffset(int i) return m_offset[i]; } +/* int RAS_Polygon::GetEdgeCode() { return m_edgecode; @@ -71,7 +72,7 @@ int RAS_Polygon::GetEdgeCode() void RAS_Polygon::SetEdgeCode(int edgecode) { m_edgecode = edgecode; -} +}*/ bool RAS_Polygon::IsVisible() diff --git a/source/gameengine/Rasterizer/RAS_Polygon.h b/source/gameengine/Rasterizer/RAS_Polygon.h index 18526ba45f7..224a7e0eed2 100644 --- a/source/gameengine/Rasterizer/RAS_Polygon.h +++ b/source/gameengine/Rasterizer/RAS_Polygon.h @@ -46,9 +46,13 @@ class RAS_Polygon unsigned short m_numvert; /* flags */ +#if 1 + unsigned short m_polyflags; +#else unsigned char m_edgecode; unsigned char m_polyflags; - +#endif + public: enum { VISIBLE = 1, @@ -65,8 +69,9 @@ public: int GetVertexOffset(int i); // each bit is for a visible edge, starting with bit 1 for the first edge, bit 2 for second etc. - int GetEdgeCode(); - void SetEdgeCode(int edgecode); + // - Not used yet! +/* int GetEdgeCode(); + void SetEdgeCode(int edgecode); */ bool IsVisible(); void SetVisible(bool visible); -- cgit v1.2.3 From 615c5232c7b2e51f9722fdff58e04ae53c043797 Mon Sep 17 00:00:00 2001 From: Peter Schlaile Date: Sun, 22 Mar 2009 19:19:21 +0000 Subject: == FFMPEG == Updated ffmpeg to release version 0.5 updated x264 to today's daily build thanks to ben2610 for first patches (but you got hddaudio.c wrong :) --- source/gameengine/VideoTexture/VideoFFmpeg.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/VideoTexture/VideoFFmpeg.h b/source/gameengine/VideoTexture/VideoFFmpeg.h index 51ce2c4eebe..51f1067c466 100644 --- a/source/gameengine/VideoTexture/VideoFFmpeg.h +++ b/source/gameengine/VideoTexture/VideoFFmpeg.h @@ -25,10 +25,10 @@ http://www.gnu.org/copyleft/lesser.txt. #ifdef WITH_FFMPEG extern "C" { #include -#include -#include -#include -#include +#include +#include +#include +#include #include "DNA_listBase.h" #include "BLI_threads.h" #include "BLI_blenlib.h" -- cgit v1.2.3 From 1914ed72b25cd856c7be3e341e87f9bfa8966275 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 22 Mar 2009 21:04:28 +0000 Subject: Speedup for bullet creating convex hull meshes In a simple test with ~12000 verts, overall BGE startup time went from ~4.5 sec to a bit under a second. - before adding each vert it did a check for a duplicates. - Using RAS_Polygon verts can give a lot of duplicates because the verts also store UV's and normals. - Was increasing the array one item at a time, now resize the array once. - Use the blender mesh mvert array rather then RAS_TexVert's, so needed to include some DNA headers. --- source/gameengine/Physics/Bullet/CMakeLists.txt | 1 + .../Physics/Bullet/CcdPhysicsController.cpp | 81 +++++++++++++++------- source/gameengine/Physics/Bullet/Makefile | 1 + source/gameengine/Physics/Bullet/SConscript | 2 +- 4 files changed, 59 insertions(+), 26 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Physics/Bullet/CMakeLists.txt b/source/gameengine/Physics/Bullet/CMakeLists.txt index 6c733786caf..83b77db4efd 100644 --- a/source/gameengine/Physics/Bullet/CMakeLists.txt +++ b/source/gameengine/Physics/Bullet/CMakeLists.txt @@ -34,6 +34,7 @@ SET(INC ../../../kernel/gen_system ../../../../intern/string ../../Rasterizer + ../../../../source/blender/makesdna ) BLENDERLIB(bf_bullet "${SRC}" "${INC}") diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index eecdea55349..61d02847164 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -24,10 +24,14 @@ subject to the following restrictions: #include "BulletSoftBody/btSoftBodyHelpers.h" #include "LinearMath/btConvexHull.h" #include "BulletCollision/Gimpact/btGImpactShape.h" +#include "BulletCollision/Gimpact/btGImpactShape.h" #include "BulletSoftBody/btSoftRigidDynamicsWorld.h" +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" + class BP_Proxy; ///todo: fill all the empty CcdPhysicsController methods, hook them up to the btRigidBody class @@ -1315,37 +1319,64 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo numvalidpolys = 0; - for (int p2=0; p2GetPolygon(p2); - - // only add polygons that have the collisionflag set - if (poly->IsCollider()) - { - //Bullet can raycast any shape, so - if (polytope) + Mesh *blen_mesh= meshobj->GetMesh(); + vector vuser_array(blen_mesh->totvert, false); + + unsigned int tot_bt_verts= 0; + unsigned int orig_index; + int i; + + // Tag verts we're using + for (int p2=0; p2GetPolygon(p2); + + // only add polygons that have the collisionflag set + if (poly->IsCollider()) { - for (int i=0;iVertexCount();i++) + for (i=0;iVertexCount();i++) { - const float* vtx = poly->GetVertex(i)->getXYZ(); - 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(i)->getOrigIndex(); + + if (vuser_array[orig_index]==false) { - if (m_vertexArray[j]==point) - { - found = true; - break; - } + vuser_array[orig_index]= true; + tot_bt_verts++; } - if (!found) - m_vertexArray.push_back(point); - - numvalidpolys++; } - } else + } + } + + m_vertexArray.resize(tot_bt_verts); + + // Copy used verts directly from the meshes vert location to the bullet vector array + MVert *mv= blen_mesh->mvert; + btVector3 *bt= &m_vertexArray[0]; + + for (i=0;isetX( mv->co[0] ); + bt->setY( mv->co[1] ); + bt->setZ( mv->co[2] ); + bt++; + } + } + numvalidpolys++; + } + else { + for (int p2=0; p2GetPolygon(p2); + + // only add polygons that have the collisionflag set + if (poly->IsCollider()) + { + //Bullet can raycast any shape, so + { const float* vtx = poly->GetVertex(2)->getXYZ(); btVector3 vertex0(vtx[0],vtx[1],vtx[2]); @@ -1379,7 +1410,7 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo m_polygonIndexArray.push_back(p2); numvalidpolys++; } - } + } } } diff --git a/source/gameengine/Physics/Bullet/Makefile b/source/gameengine/Physics/Bullet/Makefile index d5570e75833..bf3573138f7 100644 --- a/source/gameengine/Physics/Bullet/Makefile +++ b/source/gameengine/Physics/Bullet/Makefile @@ -43,4 +43,5 @@ CPPFLAGS += -I../../../kernel/gen_system CPPFLAGS += -I../../Physics/common CPPFLAGS += -I../../Physics/Dummy CPPFLAGS += -I../../Rasterizer +CPPFLAGS += -I../../../../source/blender/makesdna diff --git a/source/gameengine/Physics/Bullet/SConscript b/source/gameengine/Physics/Bullet/SConscript index 0d5bf4933d8..868a4d66af0 100644 --- a/source/gameengine/Physics/Bullet/SConscript +++ b/source/gameengine/Physics/Bullet/SConscript @@ -3,7 +3,7 @@ Import ('env') sources = 'CcdPhysicsEnvironment.cpp CcdPhysicsController.cpp' -incs = '. ../common #source/kernel/gen_system #intern/string #intern/moto/include #source/gameengine/Rasterizer' +incs = '. ../common #source/kernel/gen_system #intern/string #intern/moto/include #source/gameengine/Rasterizer #source/blender/makesdna' incs += ' ' + env['BF_BULLET_INC'] -- cgit v1.2.3 From e3d0dfc9eb3c9b20e0915256eab66ed23a34633f Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sun, 22 Mar 2009 21:36:48 +0000 Subject: BGE API cleanup: add support for attribute set/get through functions only. --- source/gameengine/Expressions/PyObjectPlus.cpp | 34 ++++++++-- source/gameengine/Expressions/PyObjectPlus.h | 90 +++++++++++++++----------- 2 files changed, 79 insertions(+), 45 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 1bead0a7664..494a848be74 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -143,6 +143,13 @@ PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *sel // fake attribute, ignore return NULL; } + if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION) + { + // the attribute has no field correspondance, handover processing to function. + if (attrdef->m_getFunction == NULL) + return NULL; + return (*attrdef->m_getFunction)(self, attrdef); + } char *ptr = reinterpret_cast(self)+attrdef->m_offset; if (attrdef->m_length > 1) { @@ -270,6 +277,13 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con } switch (attrdef->m_type) { + case KX_PYATTRIBUTE_TYPE_FUNCTION: + if (attrdef->m_setFunction == NULL) + { + PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org"); + return 1; + } + return (*attrdef->m_setFunction)(self, attrdef, value); case KX_PYATTRIBUTE_TYPE_BOOL: bufferSize = sizeof(bool); break; @@ -419,9 +433,9 @@ 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_checkFunction != NULL) { - if ((*attrdef->m_function)(self, attrdef) != 0) + if ((*attrdef->m_checkFunction)(self, attrdef) != 0) { // post check returned an error, restore values UNDO_AND_ERROR: @@ -439,8 +453,16 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con } else // simple attribute value { - - if (attrdef->m_function != NULL) + if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION) + { + if (attrdef->m_setFunction == NULL) + { + PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org"); + return 1; + } + return (*attrdef->m_setFunction)(self, attrdef, value); + } + if (attrdef->m_checkFunction != NULL) { // post check function is provided, prepare undo buffer sourceBuffer = ptr; @@ -628,9 +650,9 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con } } // check if post processing is needed - if (attrdef->m_function != NULL) + if (attrdef->m_checkFunction != NULL) { - if ((*attrdef->m_function)(self, attrdef) != 0) + if ((*attrdef->m_checkFunction)(self, attrdef) != 0) { // restore value RESTORE_AND_ERROR: diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 1a5f50a3d23..28b0e28b815 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -206,6 +206,7 @@ enum KX_PYATTRIBUTE_TYPE { KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_TYPE_DUMMY, + KX_PYATTRIBUTE_TYPE_FUNCTION, }; enum KX_PYATTRIBUTE_ACCESS { @@ -214,7 +215,9 @@ enum KX_PYATTRIBUTE_ACCESS { }; struct KX_PYATTRIBUTE_DEF; -typedef int (*KX_PYATTRIBUTE_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); +typedef int (*KX_PYATTRIBUTE_CHECK_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); +typedef int (*KX_PYATTRIBUTE_SET_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); +typedef PyObject* (*KX_PYATTRIBUTE_GET_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); typedef struct KX_PYATTRIBUTE_DEF { const char *m_name; // name of the python attribute @@ -228,7 +231,10 @@ typedef struct KX_PYATTRIBUTE_DEF { 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 + KX_PYATTRIBUTE_CHECK_FUNCTION m_checkFunction; // static function to check the assignment, returns 0 if no error + KX_PYATTRIBUTE_SET_FUNCTION m_setFunction; // static function to check the assignment, returns 0 if no error + KX_PYATTRIBUTE_GET_FUNCTION m_getFunction; // 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. @@ -242,88 +248,94 @@ 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, false, 0, 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, NULL, NULL} } #define KX_PYATTRIBUTE_BOOL_RW(name,object,field) \ - { 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} } + { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, NULL, 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, false, offsetof(object,field), 0, 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, NULL, NULL, {&((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, false, offsetof(object,field), 0, 1, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL} } + { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RO, 0, 1, 0.f, 0.f, false, offsetof(object,field), 0, 1, NULL, NULL, 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} } + { 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, 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} } + { 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, 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} } + { 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, 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} } + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, NULL, NULL, 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} } + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, &object::function, NULL, NULL, {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, false, offsetof(object,field), 0, 1, 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, 1, NULL, NULL, 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, 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, NULL, {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} } + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, NULL, 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} } + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, NULL, NULL, 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} } + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, NULL, NULL, {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} } + { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, 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} } + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, NULL, NULL, 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} } + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, 1, &object::function, NULL, NULL, {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, false, offsetof(object,field), 0, 1, 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, 1, NULL, NULL, 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, {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, {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} } + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, NULL, 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} } + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, NULL, NULL, 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} } + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, offsetof(object,field), 0, length, &object::function, NULL, NULL, {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} } + { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, offsetof(object,field), 0, length, NULL, NULL, 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, true, offsetof(object,field), 0, 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, 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, true, offsetof(object,field), 0, 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, 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, false, offsetof(object,field), 0, 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, 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, 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, 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, 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} } + { 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, 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} } + { 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, 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, false, offsetof(object,field), 0, 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, NULL, NULL, &((object *)0)->field} } + +#define KX_PYATTRIBUTE_RW_FUNCTION(name,object,setfunction,getfunction) \ + { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, false, 0, 0, 1, NULL, &object::setfunction, &object::getfunction, {NULL, NULL, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_RO_FUNCTION(name,object,getfunction) \ + { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, 0, 0, 1, NULL, NULL, &object::getfunction, {NULL, NULL, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_ARRAY_RW_FUNCTION(name,object,length,setfunction,getfunction) \ + { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0,f, false, 0, 0, length, NULL, &object::setfunction, &object::getfunction, {NULL, NULL, NULL, NULL, NULL} } +#define KX_PYATTRIBUTE_ARRAY_RO_FUNCTION(name,object,length,getfunction) \ + { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0,f, false, 0, 0, length, NULL, NULL, &object::getfunction, {NULL, NULL, NULL, NULL, NULL} } -//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 -- cgit v1.2.3 From 4a078765623b72641164a25291e925bb4e64bcba Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 23 Mar 2009 06:00:21 +0000 Subject: Speedup for bullet physics mesh conversion Was adding each face with a remove doubles option that made conversion increasingly slower for larger meshes, this would often hang blender when starting with the BGE with larger meshes. Replace btTriangleMesh()->addTriangle() with btTriangleIndexVertexArray() YoFrankie level_1_home.blend starts a third faster, level_nut about twice as fast. - previous commit was also incorrect using the original meshes vert locations rather then the vert locations that came from the derived mesh. - Softbody is relying on removing doubles at 0.01 to give stable results, this no longer works but seems a bit dodgy anyway. Maybe some post-processing filter could fix up a mesh for bullet softbody. --- .../gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp | 3 + .../Physics/Bullet/CcdPhysicsController.cpp | 280 +++++++++++++-------- .../Physics/Bullet/CcdPhysicsController.h | 5 +- source/gameengine/Rasterizer/RAS_MeshObject.h | 10 + 4 files changed, 189 insertions(+), 109 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 602486e0017..9b2d7403974 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -881,6 +881,9 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, { shapeInfo->SetMesh(meshobj, false,false); } + + // Note! since 2.48a bullet mesh conversion has been sped up not to remove doubles + // if softbody needs this there should be some post processing filter for softbody meshes. if (objprop->m_softbody) shapeInfo->setVertexWeldingThreshold(0.01f); //todo: expose this to the UI diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index 61d02847164..35602b4095a 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -16,6 +16,9 @@ subject to the following restrictions: #include "CcdPhysicsController.h" #include "btBulletDynamicsCommon.h" #include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h" + +#include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h" + #include "PHY_IMotionState.h" #include "CcdPhysicsEnvironment.h" #include "RAS_MeshObject.h" @@ -1276,150 +1279,212 @@ CcdShapeConstructionInfo* CcdShapeConstructionInfo::FindMesh(RAS_MeshObject* mes bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bool useGimpact) { + int numpolys; + m_useGimpact = useGimpact; // assume no shape information // no support for dynamic change of shape yet assert(IsUnused()); m_shapeType = PHY_SHAPE_NONE; - m_vertexArray.clear(); - m_polygonIndexArray.clear(); m_meshObject = NULL; - if (!meshobj) + // No mesh object or mesh has no polys + if (!meshobj || meshobj->HasColliderPolygon()==false) { + m_vertexArray.clear(); + m_polygonIndexArray.clear(); + m_triFaceArray.clear(); return false; - - // Mesh has no polygons! - int numpolys = meshobj->NumPolygons(); - if (!numpolys) - { - return false; - } - - // check that we have at least one colliding polygon - int numvalidpolys = 0; - - for (int p=0; pGetPolygon(p); - - // only add polygons that have the collisionflag set - if (poly->IsCollider()) - { - numvalidpolys++; - break; - } } - // No collision polygons - if (numvalidpolys < 1) - return false; + numpolys = meshobj->NumPolygons(); m_shapeType = (polytope) ? PHY_SHAPE_POLYTOPE : PHY_SHAPE_MESH; - numvalidpolys = 0; + /* Convert blender geometry into bullet mesh, need these vars for mapping */ + vector vert_tag_array(meshobj->GetMesh()->totvert, false); + unsigned int tot_bt_verts= 0; + unsigned int orig_index; + int i; if (polytope) { - Mesh *blen_mesh= meshobj->GetMesh(); - vector vuser_array(blen_mesh->totvert, false); - - unsigned int tot_bt_verts= 0; - unsigned int orig_index; - int i; - // Tag verts we're using for (int p2=0; p2GetPolygon(p2); - - // only add polygons that have the collisionflag set + + // only add polygons that have the collision flag set if (poly->IsCollider()) { - for (i=0;iVertexCount();i++) - { + for(i=0; iVertexCount(); i++) { orig_index= poly->GetVertex(i)->getOrigIndex(); - - if (vuser_array[orig_index]==false) + if (vert_tag_array[orig_index]==false) { - vuser_array[orig_index]= true; + vert_tag_array[orig_index]= true; tot_bt_verts++; } } } } - + m_vertexArray.resize(tot_bt_verts); - - // Copy used verts directly from the meshes vert location to the bullet vector array - MVert *mv= blen_mesh->mvert; + btVector3 *bt= &m_vertexArray[0]; - - for (i=0;iGetPolygon(p2); + + // only add polygons that have the collisionflag set + if (poly->IsCollider()) { - bt->setX( mv->co[0] ); - bt->setY( mv->co[1] ); - bt->setZ( mv->co[2] ); - bt++; + for(i=0; iVertexCount(); i++) { + RAS_TexVert *v= poly->GetVertex(i); + orig_index= v->getOrigIndex(); + + if (vert_tag_array[orig_index]==true) + { + const float* vtx = v->getXYZ(); + vert_tag_array[orig_index]= false; + + bt->setX(vtx[0]); bt->setY(vtx[1]); bt->setZ(vtx[2]); + bt++; + } + } } } - numvalidpolys++; } else { + unsigned int tot_bt_tris= 0; + vector vert_remap_array(meshobj->GetMesh()->totvert, 0); + + // Tag verts we're using for (int p2=0; p2GetPolygon(p2); + RAS_Polygon* poly= meshobj->GetPolygon(p2); - // only add polygons that have the collisionflag set + // only add polygons that have the collision flag set if (poly->IsCollider()) - { - //Bullet can raycast any shape, so - - { - const float* vtx = poly->GetVertex(2)->getXYZ(); - btVector3 vertex0(vtx[0],vtx[1],vtx[2]); + { + for(i=0; iVertexCount(); i++) { + orig_index= poly->GetVertex(i)->getOrigIndex(); + if (vert_tag_array[orig_index]==false) + { + vert_tag_array[orig_index]= true; + vert_remap_array[orig_index]= tot_bt_verts; + tot_bt_verts++; + } + } - vtx = poly->GetVertex(1)->getXYZ(); - btVector3 vertex1(vtx[0],vtx[1],vtx[2]); + tot_bt_tris += (i==4 ? 2:1); /* a quad or a tri */ + } + } - vtx = poly->GetVertex(0)->getXYZ(); - btVector3 vertex2(vtx[0],vtx[1],vtx[2]); + m_vertexArray.resize(tot_bt_verts); + m_polygonIndexArray.resize(tot_bt_tris); + m_triFaceArray.resize(tot_bt_tris*3); + + btVector3 *bt= &m_vertexArray[0]; + int *poly_index_pt= &m_polygonIndexArray[0]; + int *tri_pt= &m_triFaceArray[0]; - m_vertexArray.push_back(vertex0); - m_vertexArray.push_back(vertex1); - m_vertexArray.push_back(vertex2); - m_polygonIndexArray.push_back(p2); - numvalidpolys++; - } - if (poly->VertexCount() == 4) - { - const float* vtx = poly->GetVertex(3)->getXYZ(); - btVector3 vertex0(vtx[0],vtx[1],vtx[2]); - vtx = poly->GetVertex(2)->getXYZ(); - btVector3 vertex1(vtx[0],vtx[1],vtx[2]); + for (int p2=0; p2GetPolygon(p2); - vtx = poly->GetVertex(0)->getXYZ(); - btVector3 vertex2(vtx[0],vtx[1],vtx[2]); + // only add polygons that have the collisionflag set + if (poly->IsCollider()) + { + RAS_TexVert *v1= poly->GetVertex(0); + RAS_TexVert *v2= poly->GetVertex(1); + RAS_TexVert *v3= poly->GetVertex(2); + int i1= v1->getOrigIndex(); + int i2= v2->getOrigIndex(); + int i3= v3->getOrigIndex(); + const float* vtx; + + // the face indicies + tri_pt[0]= vert_remap_array[i1]; + tri_pt[1]= vert_remap_array[i2]; + tri_pt[2]= vert_remap_array[i3]; + tri_pt= tri_pt+3; + + // m_polygonIndexArray + *poly_index_pt= p2; + poly_index_pt++; + + // the vertex location + if (vert_tag_array[i1]==true) { /* *** v1 *** */ + vert_tag_array[i1]= false; + vtx = v1->getXYZ(); + bt->setX(vtx[0]); bt->setY( vtx[1]); bt->setZ(vtx[2]); + bt++; + } + if (vert_tag_array[i2]==true) { /* *** v2 *** */ + vert_tag_array[i2]= false; + vtx = v2->getXYZ(); + bt->setX(vtx[0]); bt->setY(vtx[1]); bt->setZ(vtx[2]); + bt++; + } + if (vert_tag_array[i3]==true) { /* *** v3 *** */ + vert_tag_array[i3]= false; + vtx = v3->getXYZ(); + bt->setX(vtx[0]); bt->setY(vtx[1]); bt->setZ(vtx[2]); + bt++; + } - m_vertexArray.push_back(vertex0); - m_vertexArray.push_back(vertex1); - m_vertexArray.push_back(vertex2); - m_polygonIndexArray.push_back(p2); - numvalidpolys++; + if (poly->VertexCount()==4) + { + RAS_TexVert *v4= poly->GetVertex(3); + int i4= v4->getOrigIndex(); + + tri_pt[0]= vert_remap_array[i1]; + tri_pt[1]= vert_remap_array[i3]; + tri_pt[2]= vert_remap_array[i4]; + tri_pt= tri_pt+3; + + // m_polygonIndexArray + *poly_index_pt= p2; + poly_index_pt++; + + // the vertex location + if (vert_tag_array[i4]==true) { /* *** v4 *** */ + vert_tag_array[i4]= false; + vtx = v4->getXYZ(); + bt->setX(vtx[0]); bt->setY(vtx[1]); bt->setZ(vtx[2]); + bt++; + } } } } + + + /* If this ever gets confusing, print out an OBJ file for debugging */ +#if 0 + printf("# vert count %d\n", m_vertexArray.size()); + for(i=0; iaddTriangle(m_vertexArray[i+2],m_vertexArray[i+1],m_vertexArray[i],removeDuplicateVertices); - } + { + btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray( + m_polygonIndexArray.size(), + &m_triFaceArray[0], + 3*sizeof(int), + m_vertexArray.size(), + (btScalar*) &m_vertexArray[0].x(), + sizeof(btVector3) + ); - btGImpactMeshShape* gimpactShape = new btGImpactMeshShape(collisionMeshData); + btGImpactMeshShape* gimpactShape = new btGImpactMeshShape(indexVertexArrays); collisionShape = gimpactShape; gimpactShape->updateBound(); @@ -1505,17 +1568,18 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape() { if (!m_unscaledShape) { - 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],removeDuplicateVertices); - } + + btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray( + m_polygonIndexArray.size(), + &m_triFaceArray[0], + 3*sizeof(int), + m_vertexArray.size(), + (btScalar*) &m_vertexArray[0].x(), + sizeof(btVector3) + ); + // this shape will be shared and not deleted until shapeInfo is deleted - m_unscaledShape = new btBvhTriangleMeshShape( collisionMeshData, true ); + m_unscaledShape = new btBvhTriangleMeshShape( indexVertexArrays, true ); m_unscaledShape->recalcLocalAabb(); } collisionShape = new btScaledBvhTriangleMeshShape(m_unscaledShape, btVector3(1.0f,1.0f,1.0f)); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index deb3c0880e9..67dd82db5cc 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -167,6 +167,9 @@ public: std::vector m_polygonIndexArray; // Contains the array of polygon index in the // original mesh that correspond to shape triangles. // only set for concave mesh shape. + + std::vector m_triFaceArray; // Contains an array of triplets of face indicies + // quads turn into 2 tris void setVertexWeldingThreshold(float threshold) { @@ -185,7 +188,7 @@ protected: // the actual shape is of type btScaledBvhTriangleMeshShape 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. + float m_weldingThreshold; //welding closeby vertices together can improve softbody stability etc. // Not used at the moment, maybe remove? CcdShapeConstructionInfo* m_shapeProxy; // only used for PHY_SHAPE_PROXY, pointer to actual shape info }; diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.h b/source/gameengine/Rasterizer/RAS_MeshObject.h index 0d35a2f402b..404b7f16a59 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.h +++ b/source/gameengine/Rasterizer/RAS_MeshObject.h @@ -147,6 +147,16 @@ public: /* polygon sorting by Z for alpha */ void SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transform); + + bool HasColliderPolygon() { + int numpolys= NumPolygons(); + for (int p=0; pIsCollider()) + return true; + + return false; + } + /* for construction to find shared vertices */ struct SharedVertex { RAS_DisplayArray *m_darray; -- cgit v1.2.3 From ce8badeb187931cc24d29730d0d10a7242bb7969 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 24 Mar 2009 15:45:08 +0000 Subject: Fix for bug #18423: BGE lights in overlay scene also affected other scenes, for texture face / multitexture materials. Fix for bug #18428: BGE lights on hidden layers were still used, for all material types, now they have no effect --- .../BlenderRoutines/KX_BlenderRenderTools.cpp | 166 +++++++++++---------- .../BlenderRoutines/KX_BlenderRenderTools.h | 3 +- .../GamePlayer/common/GPC_RenderTools.cpp | 166 +++++++++++---------- .../gameengine/GamePlayer/common/GPC_RenderTools.h | 3 +- source/gameengine/Ketsji/BL_BlenderShader.cpp | 2 +- source/gameengine/Ketsji/KX_Light.cpp | 1 + source/gameengine/Rasterizer/RAS_IRenderTools.h | 6 +- source/gameengine/Rasterizer/RAS_LightObject.h | 1 + .../gameengine/Rasterizer/RAS_MaterialBucket.cpp | 10 +- 9 files changed, 195 insertions(+), 163 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp index 42ad7769cbd..9dbda3f195b 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp @@ -28,6 +28,8 @@ #include "GL/glew.h" +#include "DNA_scene_types.h" + #include "RAS_IRenderTools.h" #include "RAS_IRasterizer.h" #include "RAS_LightObject.h" @@ -67,6 +69,7 @@ void KX_BlenderRenderTools::BeginFrame(RAS_IRasterizer* rasty) m_clientobject = NULL; m_lastlightlayer = -1; m_lastlighting = false; + m_lastauxinfo = NULL; DisableOpenGLLights(); } @@ -80,25 +83,27 @@ 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(RAS_IRasterizer *rasty, int layer, const MT_Transform& viewmat) +void KX_BlenderRenderTools::ProcessLighting(RAS_IRasterizer *rasty, bool uselights, const MT_Transform& viewmat) { - if(m_lastlightlayer == layer) - return; + bool enable = false; + int layer= -1; - m_lastlightlayer = layer; + /* find the layer */ + if(uselights) { + if(m_clientobject) + layer = static_cast(m_clientobject)->GetLayer(); + } - bool enable = false; + /* avoid state switching */ + if(m_lastlightlayer == layer && m_lastauxinfo == m_auxilaryClientInfo) + return; - if (layer >= 0) - { - if (m_clientobject) - { - if (layer == RAS_LIGHT_OBJECT_LAYER) - layer = static_cast(m_clientobject)->GetLayer(); + m_lastlightlayer = layer; + m_lastauxinfo = m_auxilaryClientInfo; - enable = applyLights(layer, viewmat); - } - } + /* enable/disable lights as needed */ + if(layer >= 0) + enable = applyLights(layer, viewmat); if(enable) EnableOpenGLLights(rasty); @@ -324,11 +329,16 @@ void KX_BlenderRenderTools::PopMatrix() int KX_BlenderRenderTools::applyLights(int objectlayer, const MT_Transform& viewmat) { // taken from blender source, incompatibility between Blender Object / GameObject + KX_Scene* kxscene = (KX_Scene*)m_auxilaryClientInfo; + int scenelayer = ~0; float glviewmat[16]; unsigned int count; float vec[4]; vec[3]= 1.0; + + if(kxscene && kxscene->GetBlenderScene()) + scenelayer = kxscene->GetBlenderScene()->lay; for(count=0; countm_layer & objectlayer) - { - vec[0] = (*(lightdata->m_worldmatrix))(0,3); - vec[1] = (*(lightdata->m_worldmatrix))(1,3); - vec[2] = (*(lightdata->m_worldmatrix))(2,3); - vec[3] = 1; + KX_Scene* lightscene = (KX_Scene*)lightdata->m_scene; - if(lightdata->m_type==RAS_LightObject::LIGHT_SUN) { - - vec[0] = (*(lightdata->m_worldmatrix))(0,2); - vec[1] = (*(lightdata->m_worldmatrix))(1,2); - vec[2] = (*(lightdata->m_worldmatrix))(2,2); - //vec[0]= base->object->obmat[2][0]; - //vec[1]= base->object->obmat[2][1]; - //vec[2]= base->object->obmat[2][2]; - vec[3]= 0.0; - glLightfv((GLenum)(GL_LIGHT0+count), GL_POSITION, vec); - } - else { - //vec[3]= 1.0; - glLightfv((GLenum)(GL_LIGHT0+count), GL_POSITION, vec); - glLightf((GLenum)(GL_LIGHT0+count), GL_CONSTANT_ATTENUATION, 1.0); - glLightf((GLenum)(GL_LIGHT0+count), GL_LINEAR_ATTENUATION, lightdata->m_att1/lightdata->m_distance); - // without this next line it looks backward compatible. - //attennuation still is acceptable - glLightf((GLenum)(GL_LIGHT0+count), GL_QUADRATIC_ATTENUATION, lightdata->m_att2/(lightdata->m_distance*lightdata->m_distance)); - - if(lightdata->m_type==RAS_LightObject::LIGHT_SPOT) { - vec[0] = -(*(lightdata->m_worldmatrix))(0,2); - vec[1] = -(*(lightdata->m_worldmatrix))(1,2); - vec[2] = -(*(lightdata->m_worldmatrix))(2,2); - //vec[0]= -base->object->obmat[2][0]; - //vec[1]= -base->object->obmat[2][1]; - //vec[2]= -base->object->obmat[2][2]; - glLightfv((GLenum)(GL_LIGHT0+count), GL_SPOT_DIRECTION, vec); - glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_CUTOFF, lightdata->m_spotsize/2.0); - glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_EXPONENT, 128.0*lightdata->m_spotblend); - } - else glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_CUTOFF, 180.0); - } + /* only use lights in the same layer as the object */ + if(!(lightdata->m_layer & objectlayer)) + continue; + /* only use lights in the same scene, and in a visible layer */ + if(kxscene != lightscene || !(lightdata->m_layer & scenelayer)) + continue; + + vec[0] = (*(lightdata->m_worldmatrix))(0,3); + vec[1] = (*(lightdata->m_worldmatrix))(1,3); + vec[2] = (*(lightdata->m_worldmatrix))(2,3); + vec[3] = 1; + + if(lightdata->m_type==RAS_LightObject::LIGHT_SUN) { - if (lightdata->m_nodiffuse) - { - vec[0] = vec[1] = vec[2] = vec[3] = 0.0; - } else { - vec[0]= lightdata->m_energy*lightdata->m_red; - vec[1]= lightdata->m_energy*lightdata->m_green; - vec[2]= lightdata->m_energy*lightdata->m_blue; - vec[3]= 1.0; - } - glLightfv((GLenum)(GL_LIGHT0+count), GL_DIFFUSE, vec); - if (lightdata->m_nospecular) - { - vec[0] = vec[1] = vec[2] = vec[3] = 0.0; - } else if (lightdata->m_nodiffuse) { - vec[0]= lightdata->m_energy*lightdata->m_red; - vec[1]= lightdata->m_energy*lightdata->m_green; - vec[2]= lightdata->m_energy*lightdata->m_blue; - vec[3]= 1.0; + vec[0] = (*(lightdata->m_worldmatrix))(0,2); + vec[1] = (*(lightdata->m_worldmatrix))(1,2); + vec[2] = (*(lightdata->m_worldmatrix))(2,2); + //vec[0]= base->object->obmat[2][0]; + //vec[1]= base->object->obmat[2][1]; + //vec[2]= base->object->obmat[2][2]; + vec[3]= 0.0; + glLightfv((GLenum)(GL_LIGHT0+count), GL_POSITION, vec); + } + else { + //vec[3]= 1.0; + glLightfv((GLenum)(GL_LIGHT0+count), GL_POSITION, vec); + glLightf((GLenum)(GL_LIGHT0+count), GL_CONSTANT_ATTENUATION, 1.0); + glLightf((GLenum)(GL_LIGHT0+count), GL_LINEAR_ATTENUATION, lightdata->m_att1/lightdata->m_distance); + // without this next line it looks backward compatible. + //attennuation still is acceptable + glLightf((GLenum)(GL_LIGHT0+count), GL_QUADRATIC_ATTENUATION, lightdata->m_att2/(lightdata->m_distance*lightdata->m_distance)); + + if(lightdata->m_type==RAS_LightObject::LIGHT_SPOT) { + vec[0] = -(*(lightdata->m_worldmatrix))(0,2); + vec[1] = -(*(lightdata->m_worldmatrix))(1,2); + vec[2] = -(*(lightdata->m_worldmatrix))(2,2); + //vec[0]= -base->object->obmat[2][0]; + //vec[1]= -base->object->obmat[2][1]; + //vec[2]= -base->object->obmat[2][2]; + glLightfv((GLenum)(GL_LIGHT0+count), GL_SPOT_DIRECTION, vec); + glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_CUTOFF, lightdata->m_spotsize/2.0); + glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_EXPONENT, 128.0*lightdata->m_spotblend); } - glLightfv((GLenum)(GL_LIGHT0+count), GL_SPECULAR, vec); - glEnable((GLenum)(GL_LIGHT0+count)); - - count++; + else glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_CUTOFF, 180.0); + } + + if (lightdata->m_nodiffuse) + { + vec[0] = vec[1] = vec[2] = vec[3] = 0.0; + } else { + vec[0]= lightdata->m_energy*lightdata->m_red; + vec[1]= lightdata->m_energy*lightdata->m_green; + vec[2]= lightdata->m_energy*lightdata->m_blue; + vec[3]= 1.0; + } + glLightfv((GLenum)(GL_LIGHT0+count), GL_DIFFUSE, vec); + if (lightdata->m_nospecular) + { + vec[0] = vec[1] = vec[2] = vec[3] = 0.0; + } else if (lightdata->m_nodiffuse) { + vec[0]= lightdata->m_energy*lightdata->m_red; + vec[1]= lightdata->m_energy*lightdata->m_green; + vec[2]= lightdata->m_energy*lightdata->m_blue; + vec[3]= 1.0; } + glLightfv((GLenum)(GL_LIGHT0+count), GL_SPECULAR, vec); + glEnable((GLenum)(GL_LIGHT0+count)); + + count++; } glPopMatrix(); diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h index ebf7562503f..60130e6bfc9 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h @@ -51,6 +51,7 @@ class KX_BlenderRenderTools : public RAS_IRenderTools { int m_lastlightlayer; bool m_lastlighting; + void *m_lastauxinfo; static unsigned int m_numgllights; public: @@ -62,7 +63,7 @@ public: void EnableOpenGLLights(RAS_IRasterizer *rasty); void DisableOpenGLLights(); - void ProcessLighting(RAS_IRasterizer *rasty, int layer, const MT_Transform& viewmat); + void ProcessLighting(RAS_IRasterizer *rasty, bool uselights, 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 c0d6248a3ca..8135635ddb3 100644 --- a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp +++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp @@ -29,6 +29,8 @@ #include "GL/glew.h" +#include "DNA_scene_types.h" + #include "RAS_IRenderTools.h" #include "RAS_IRasterizer.h" #include "RAS_LightObject.h" @@ -72,6 +74,7 @@ void GPC_RenderTools::BeginFrame(RAS_IRasterizer* rasty) m_clientobject = NULL; m_lastlightlayer = -1; m_lastlighting = false; + m_lastauxinfo = NULL; DisableOpenGLLights(); } @@ -85,25 +88,27 @@ 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(RAS_IRasterizer *rasty, int layer, const MT_Transform& viewmat) +void GPC_RenderTools::ProcessLighting(RAS_IRasterizer *rasty, bool uselights, const MT_Transform& viewmat) { - if(m_lastlightlayer == layer) - return; + bool enable = false; + int layer= -1; - m_lastlightlayer = layer; + /* find the layer */ + if(uselights) { + if(m_clientobject) + layer = static_cast(m_clientobject)->GetLayer(); + } - bool enable = false; + /* avoid state switching */ + if(m_lastlightlayer == layer && m_lastauxinfo == m_auxilaryClientInfo) + return; - if (layer >= 0) - { - if (m_clientobject) - { - if (layer == RAS_LIGHT_OBJECT_LAYER) - layer = static_cast(m_clientobject)->GetLayer(); + m_lastlightlayer = layer; + m_lastauxinfo = m_auxilaryClientInfo; - enable = applyLights(layer, viewmat); - } - } + /* enable/disable lights as needed */ + if(layer >= 0) + enable = applyLights(layer, viewmat); if(enable) EnableOpenGLLights(rasty); @@ -392,11 +397,16 @@ void GPC_RenderTools::PopMatrix() int GPC_RenderTools::applyLights(int objectlayer, const MT_Transform& viewmat) { // taken from blender source, incompatibility between Blender Object / GameObject + KX_Scene* kxscene = (KX_Scene*)m_auxilaryClientInfo; + int scenelayer = ~0; float glviewmat[16]; unsigned int count; float vec[4]; vec[3]= 1.0; + + if(kxscene && kxscene->GetBlenderScene()) + scenelayer = kxscene->GetBlenderScene()->lay; for(count=0; countm_layer & objectlayer) - { - vec[0] = (*(lightdata->m_worldmatrix))(0,3); - vec[1] = (*(lightdata->m_worldmatrix))(1,3); - vec[2] = (*(lightdata->m_worldmatrix))(2,3); - vec[3] = 1; + KX_Scene* lightscene = (KX_Scene*)lightdata->m_scene; - if(lightdata->m_type==RAS_LightObject::LIGHT_SUN) { - - vec[0] = (*(lightdata->m_worldmatrix))(0,2); - vec[1] = (*(lightdata->m_worldmatrix))(1,2); - vec[2] = (*(lightdata->m_worldmatrix))(2,2); - //vec[0]= base->object->obmat[2][0]; - //vec[1]= base->object->obmat[2][1]; - //vec[2]= base->object->obmat[2][2]; - vec[3]= 0.0; - glLightfv((GLenum)(GL_LIGHT0+count), GL_POSITION, vec); - } - else { - //vec[3]= 1.0; - glLightfv((GLenum)(GL_LIGHT0+count), GL_POSITION, vec); - glLightf((GLenum)(GL_LIGHT0+count), GL_CONSTANT_ATTENUATION, 1.0); - glLightf((GLenum)(GL_LIGHT0+count), GL_LINEAR_ATTENUATION, lightdata->m_att1/lightdata->m_distance); - // without this next line it looks backward compatible. - //attennuation still is acceptable - glLightf((GLenum)(GL_LIGHT0+count), GL_QUADRATIC_ATTENUATION, lightdata->m_att2/(lightdata->m_distance*lightdata->m_distance)); - - if(lightdata->m_type==RAS_LightObject::LIGHT_SPOT) { - vec[0] = -(*(lightdata->m_worldmatrix))(0,2); - vec[1] = -(*(lightdata->m_worldmatrix))(1,2); - vec[2] = -(*(lightdata->m_worldmatrix))(2,2); - //vec[0]= -base->object->obmat[2][0]; - //vec[1]= -base->object->obmat[2][1]; - //vec[2]= -base->object->obmat[2][2]; - glLightfv((GLenum)(GL_LIGHT0+count), GL_SPOT_DIRECTION, vec); - glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_CUTOFF, lightdata->m_spotsize/2.0); - glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_EXPONENT, 128.0*lightdata->m_spotblend); - } - else glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_CUTOFF, 180.0); - } + /* only use lights in the same layer as the object */ + if(!(lightdata->m_layer & objectlayer)) + continue; + /* only use lights in the same scene, and in a visible layer */ + if(kxscene != lightscene || !(lightdata->m_layer & scenelayer)) + continue; + + vec[0] = (*(lightdata->m_worldmatrix))(0,3); + vec[1] = (*(lightdata->m_worldmatrix))(1,3); + vec[2] = (*(lightdata->m_worldmatrix))(2,3); + vec[3] = 1; + + if(lightdata->m_type==RAS_LightObject::LIGHT_SUN) { - if (lightdata->m_nodiffuse) - { - vec[0] = vec[1] = vec[2] = vec[3] = 0.0; - } else { - vec[0]= lightdata->m_energy*lightdata->m_red; - vec[1]= lightdata->m_energy*lightdata->m_green; - vec[2]= lightdata->m_energy*lightdata->m_blue; - vec[3]= 1.0; - } - glLightfv((GLenum)(GL_LIGHT0+count), GL_DIFFUSE, vec); - if (lightdata->m_nospecular) - { - vec[0] = vec[1] = vec[2] = vec[3] = 0.0; - } else if (lightdata->m_nodiffuse) { - vec[0]= lightdata->m_energy*lightdata->m_red; - vec[1]= lightdata->m_energy*lightdata->m_green; - vec[2]= lightdata->m_energy*lightdata->m_blue; - vec[3]= 1.0; + vec[0] = (*(lightdata->m_worldmatrix))(0,2); + vec[1] = (*(lightdata->m_worldmatrix))(1,2); + vec[2] = (*(lightdata->m_worldmatrix))(2,2); + //vec[0]= base->object->obmat[2][0]; + //vec[1]= base->object->obmat[2][1]; + //vec[2]= base->object->obmat[2][2]; + vec[3]= 0.0; + glLightfv((GLenum)(GL_LIGHT0+count), GL_POSITION, vec); + } + else { + //vec[3]= 1.0; + glLightfv((GLenum)(GL_LIGHT0+count), GL_POSITION, vec); + glLightf((GLenum)(GL_LIGHT0+count), GL_CONSTANT_ATTENUATION, 1.0); + glLightf((GLenum)(GL_LIGHT0+count), GL_LINEAR_ATTENUATION, lightdata->m_att1/lightdata->m_distance); + // without this next line it looks backward compatible. + //attennuation still is acceptable + glLightf((GLenum)(GL_LIGHT0+count), GL_QUADRATIC_ATTENUATION, lightdata->m_att2/(lightdata->m_distance*lightdata->m_distance)); + + if(lightdata->m_type==RAS_LightObject::LIGHT_SPOT) { + vec[0] = -(*(lightdata->m_worldmatrix))(0,2); + vec[1] = -(*(lightdata->m_worldmatrix))(1,2); + vec[2] = -(*(lightdata->m_worldmatrix))(2,2); + //vec[0]= -base->object->obmat[2][0]; + //vec[1]= -base->object->obmat[2][1]; + //vec[2]= -base->object->obmat[2][2]; + glLightfv((GLenum)(GL_LIGHT0+count), GL_SPOT_DIRECTION, vec); + glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_CUTOFF, lightdata->m_spotsize/2.0); + glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_EXPONENT, 128.0*lightdata->m_spotblend); } - glLightfv((GLenum)(GL_LIGHT0+count), GL_SPECULAR, vec); - glEnable((GLenum)(GL_LIGHT0+count)); - - count++; + else glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_CUTOFF, 180.0); + } + + if (lightdata->m_nodiffuse) + { + vec[0] = vec[1] = vec[2] = vec[3] = 0.0; + } else { + vec[0]= lightdata->m_energy*lightdata->m_red; + vec[1]= lightdata->m_energy*lightdata->m_green; + vec[2]= lightdata->m_energy*lightdata->m_blue; + vec[3]= 1.0; + } + glLightfv((GLenum)(GL_LIGHT0+count), GL_DIFFUSE, vec); + if (lightdata->m_nospecular) + { + vec[0] = vec[1] = vec[2] = vec[3] = 0.0; + } else if (lightdata->m_nodiffuse) { + vec[0]= lightdata->m_energy*lightdata->m_red; + vec[1]= lightdata->m_energy*lightdata->m_green; + vec[2]= lightdata->m_energy*lightdata->m_blue; + vec[3]= 1.0; } + glLightfv((GLenum)(GL_LIGHT0+count), GL_SPECULAR, vec); + glEnable((GLenum)(GL_LIGHT0+count)); + + count++; } glPopMatrix(); diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.h b/source/gameengine/GamePlayer/common/GPC_RenderTools.h index 2a1b66a3aa9..316860a7d43 100644 --- a/source/gameengine/GamePlayer/common/GPC_RenderTools.h +++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.h @@ -54,6 +54,7 @@ class GPC_RenderTools : public RAS_IRenderTools { int m_lastlightlayer; bool m_lastlighting; + void *m_lastauxinfo; static unsigned int m_numgllights; BMF_Font* m_font; @@ -67,7 +68,7 @@ public: void EnableOpenGLLights(RAS_IRasterizer *rasty); void DisableOpenGLLights(); - void ProcessLighting(RAS_IRasterizer *rasty, int layer, const MT_Transform& viewmat); + void ProcessLighting(RAS_IRasterizer *rasty, bool uselights, const MT_Transform& viewmat); /* @attention mode is ignored here */ void RenderText2D(RAS_TEXT_RENDER_MODE mode, diff --git a/source/gameengine/Ketsji/BL_BlenderShader.cpp b/source/gameengine/Ketsji/BL_BlenderShader.cpp index 8ec463be6ff..3df483b0598 100644 --- a/source/gameengine/Ketsji/BL_BlenderShader.cpp +++ b/source/gameengine/Ketsji/BL_BlenderShader.cpp @@ -52,7 +52,7 @@ void BL_BlenderShader::SetProg(bool enable, double time) { if(VerifyShader()) { if(enable) - GPU_material_bind(GPU_material_from_blender(mBlenderScene, mMat), mLightLayer, ~0, time); + GPU_material_bind(GPU_material_from_blender(mBlenderScene, mMat), mLightLayer, mBlenderScene->lay, time); else GPU_material_unbind(GPU_material_from_blender(mBlenderScene, mMat)); } diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp index a2e93ecdd36..487b8f30e0d 100644 --- a/source/gameengine/Ketsji/KX_Light.cpp +++ b/source/gameengine/Ketsji/KX_Light.cpp @@ -57,6 +57,7 @@ KX_LightObject::KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks, { m_lightobj = lightobj; m_lightobj.m_worldmatrix = GetOpenGLMatrixPtr(); + m_lightobj.m_scene = sgReplicationInfo; m_rendertools->AddLight(&m_lightobj); m_glsl = glsl; m_blenderscene = ((KX_Scene*)sgReplicationInfo)->GetBlenderScene(); diff --git a/source/gameengine/Rasterizer/RAS_IRenderTools.h b/source/gameengine/Rasterizer/RAS_IRenderTools.h index a289ffed492..52f6397cf6c 100644 --- a/source/gameengine/Rasterizer/RAS_IRenderTools.h +++ b/source/gameengine/Rasterizer/RAS_IRenderTools.h @@ -58,10 +58,6 @@ public: RAS_TEXT_PADDED, RAS_TEXT_MAX }; - enum RAS_LIGHT_MODE { - RAS_LIGHT_NONE = -1, - RAS_LIGHT_OBJECT_LAYER = 0 - }; RAS_IRenderTools( ) : @@ -135,7 +131,7 @@ public: void ProcessLighting( RAS_IRasterizer *rasty, - int layer, + bool uselights, const MT_Transform& trans )=0; diff --git a/source/gameengine/Rasterizer/RAS_LightObject.h b/source/gameengine/Rasterizer/RAS_LightObject.h index 4c54857dc39..6b63a891981 100644 --- a/source/gameengine/Rasterizer/RAS_LightObject.h +++ b/source/gameengine/Rasterizer/RAS_LightObject.h @@ -40,6 +40,7 @@ struct RAS_LightObject }; bool m_modified; int m_layer; + void *m_scene; float m_energy; float m_distance; diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp index d8631c1edf6..20a8e9c3574 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp @@ -513,13 +513,13 @@ list::iterator RAS_MaterialBucket::msEnd() bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_IRasterizer* rasty, RAS_IRenderTools *rendertools) { - if (!rasty->SetMaterial(*m_material)) + bool uselights; + + if(!rasty->SetMaterial(*m_material)) return false; - if (m_material->UsesLighting(rasty)) - rendertools->ProcessLighting(rasty, RAS_IRenderTools::RAS_LIGHT_OBJECT_LAYER, cameratrans); - else - rendertools->ProcessLighting(rasty, -1, cameratrans); + uselights= m_material->UsesLighting(rasty); + rendertools->ProcessLighting(rasty, uselights, cameratrans); return true; } -- cgit v1.2.3 From c78b460fce4b1da228bd60809e281eea358cf2c9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 24 Mar 2009 19:37:17 +0000 Subject: Use Benoits attributes in KX_GameObject. Deprecated.. getPosition, setPosition, getOrientation, setOrientation, getState, setState, getParent, getVisible, getMass * swapped set/get to get/set in KX_PYATTRIBUTE_RW_FUNCTION macro to match pythons getsetattrs. * deprecation warnings in the api and notes in epydocs. * added 'state' attribute * gameob.mass = 10 # now works because its not checking only for float values. * dir(gameob) # includes attributes now --- source/gameengine/Expressions/PyObjectPlus.h | 4 +- source/gameengine/Ketsji/KX_GameObject.cpp | 380 ++++++++++++++++----------- source/gameengine/Ketsji/KX_GameObject.h | 20 ++ source/gameengine/PyDoc/KX_GameObject.py | 26 +- 4 files changed, 262 insertions(+), 168 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 28b0e28b815..6ba80255aa3 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -327,11 +327,11 @@ 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, NULL, NULL, &((object *)0)->field} } -#define KX_PYATTRIBUTE_RW_FUNCTION(name,object,setfunction,getfunction) \ +#define KX_PYATTRIBUTE_RW_FUNCTION(name,object,getfunction,setfunction) \ { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, false, 0, 0, 1, NULL, &object::setfunction, &object::getfunction, {NULL, NULL, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_RO_FUNCTION(name,object,getfunction) \ { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, 0, 0, 1, NULL, NULL, &object::getfunction, {NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_ARRAY_RW_FUNCTION(name,object,length,setfunction,getfunction) \ +#define KX_PYATTRIBUTE_ARRAY_RW_FUNCTION(name,object,length,getfunction,setfunction) \ { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0,f, false, 0, 0, length, NULL, &object::setfunction, &object::getfunction, {NULL, NULL, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_ARRAY_RO_FUNCTION(name,object,length,getfunction) \ { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0,f, false, 0, 0, length, NULL, NULL, &object::getfunction, {NULL, NULL, NULL, NULL, NULL} } diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 95df9d51a26..bbfa2ad324f 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -984,12 +984,7 @@ void KX_GameObject::Suspend() /* ------- python stuff ---------------------------------------------------*/ - - - PyMethodDef KX_GameObject::Methods[] = { - {"getPosition", (PyCFunction) KX_GameObject::sPyGetPosition, METH_NOARGS}, - {"setPosition", (PyCFunction) KX_GameObject::sPySetPosition, METH_O}, {"setWorldPosition", (PyCFunction) KX_GameObject::sPySetWorldPosition, METH_O}, {"applyForce", (PyCFunction) KX_GameObject::sPyApplyForce, METH_VARARGS}, {"applyTorque", (PyCFunction) KX_GameObject::sPyApplyTorque, METH_VARARGS}, @@ -1000,14 +995,7 @@ PyMethodDef KX_GameObject::Methods[] = { {"getAngularVelocity", (PyCFunction) KX_GameObject::sPyGetAngularVelocity, METH_VARARGS}, {"setAngularVelocity", (PyCFunction) KX_GameObject::sPySetAngularVelocity, METH_VARARGS}, {"getVelocity", (PyCFunction) KX_GameObject::sPyGetVelocity, METH_VARARGS}, - {"getMass", (PyCFunction) KX_GameObject::sPyGetMass, METH_NOARGS}, {"getReactionForce", (PyCFunction) KX_GameObject::sPyGetReactionForce, METH_NOARGS}, - {"getOrientation", (PyCFunction) KX_GameObject::sPyGetOrientation, METH_NOARGS}, - {"setOrientation", (PyCFunction) KX_GameObject::sPySetOrientation, METH_O}, - {"getVisible",(PyCFunction) KX_GameObject::sPyGetVisible, METH_NOARGS}, - {"setVisible",(PyCFunction) KX_GameObject::sPySetVisible, METH_VARARGS}, - {"getState",(PyCFunction) KX_GameObject::sPyGetState, METH_NOARGS}, - {"setState",(PyCFunction) KX_GameObject::sPySetState, METH_O}, {"alignAxisToVect",(PyCFunction) KX_GameObject::sPyAlignAxisToVect, METH_VARARGS}, {"getAxisVect",(PyCFunction) KX_GameObject::sPyGetAxisVect, METH_O}, {"suspendDynamics", (PyCFunction)KX_GameObject::sPySuspendDynamics,METH_NOARGS}, @@ -1016,8 +1004,8 @@ PyMethodDef KX_GameObject::Methods[] = { {"disableRigidBody", (PyCFunction)KX_GameObject::sPyDisableRigidBody,METH_NOARGS}, {"applyImpulse", (PyCFunction) KX_GameObject::sPyApplyImpulse, METH_VARARGS}, {"setCollisionMargin", (PyCFunction) KX_GameObject::sPySetCollisionMargin, METH_O}, - {"getParent", (PyCFunction)KX_GameObject::sPyGetParent,METH_NOARGS}, {"setParent", (PyCFunction)KX_GameObject::sPySetParent,METH_O}, + {"setVisible",(PyCFunction) KX_GameObject::sPySetVisible, METH_VARARGS}, {"removeParent", (PyCFunction)KX_GameObject::sPyRemoveParent,METH_NOARGS}, {"getChildren", (PyCFunction)KX_GameObject::sPyGetChildren,METH_NOARGS}, {"getChildrenRecursive", (PyCFunction)KX_GameObject::sPyGetChildrenRecursive,METH_NOARGS}, @@ -1026,15 +1014,36 @@ PyMethodDef KX_GameObject::Methods[] = { {"getPropertyNames", (PyCFunction)KX_GameObject::sPyGetPropertyNames,METH_NOARGS}, {"replaceMesh",(PyCFunction) KX_GameObject::sPyReplaceMesh, METH_O}, {"endObject",(PyCFunction) KX_GameObject::sPyEndObject, METH_NOARGS}, + KX_PYMETHODTABLE(KX_GameObject, rayCastTo), KX_PYMETHODTABLE(KX_GameObject, rayCast), KX_PYMETHODTABLE_O(KX_GameObject, getDistanceTo), KX_PYMETHODTABLE_O(KX_GameObject, getVectTo), + + // deprecated + {"getPosition", (PyCFunction) KX_GameObject::sPyGetPosition, METH_NOARGS}, + {"setPosition", (PyCFunction) KX_GameObject::sPySetPosition, METH_O}, + {"getOrientation", (PyCFunction) KX_GameObject::sPyGetOrientation, METH_NOARGS}, + {"setOrientation", (PyCFunction) KX_GameObject::sPySetOrientation, METH_O}, + {"getState",(PyCFunction) KX_GameObject::sPyGetState, METH_NOARGS}, + {"setState",(PyCFunction) KX_GameObject::sPySetState, METH_O}, + {"getParent", (PyCFunction)KX_GameObject::sPyGetParent,METH_NOARGS}, + {"getVisible",(PyCFunction) KX_GameObject::sPyGetVisible, METH_NOARGS}, + {"getMass", (PyCFunction) KX_GameObject::sPyGetMass, METH_NOARGS}, {NULL,NULL} //Sentinel }; PyAttributeDef KX_GameObject::Attributes[] = { - { NULL } //Sentinel + KX_PYATTRIBUTE_RO_FUNCTION("name", KX_GameObject, pyattr_get_name), + KX_PYATTRIBUTE_RO_FUNCTION("parent", KX_GameObject, pyattr_get_parent), + KX_PYATTRIBUTE_RW_FUNCTION("mass", KX_GameObject, pyattr_get_mass, pyattr_set_mass), + KX_PYATTRIBUTE_RW_FUNCTION("visible", KX_GameObject, pyattr_get_visible, pyattr_set_visible), + KX_PYATTRIBUTE_RW_FUNCTION("position", KX_GameObject, pyattr_get_position, pyattr_set_position), + KX_PYATTRIBUTE_RW_FUNCTION("orientation",KX_GameObject,pyattr_get_orientation,pyattr_set_orientation), + KX_PYATTRIBUTE_RW_FUNCTION("scaling", KX_GameObject, pyattr_get_scaling, pyattr_set_scaling), + KX_PYATTRIBUTE_RW_FUNCTION("timeOffset",KX_GameObject, pyattr_get_timeOffset,pyattr_set_timeOffset), + KX_PYATTRIBUTE_RW_FUNCTION("state", KX_GameObject, pyattr_get_state, pyattr_set_state), + {NULL} //Sentinel }; @@ -1089,6 +1098,7 @@ PyObject* KX_GameObject::PyEndObject(PyObject* self) PyObject* KX_GameObject::PyGetPosition(PyObject* self) { + ShowDeprecationWarning("getPosition()", "the position property"); return PyObjectFrom(NodeGetWorldPosition()); } @@ -1122,176 +1132,230 @@ PyParentObject KX_GameObject::Parents[] = { NULL }; +PyObject* KX_GameObject::pyattr_get_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + return PyString_FromString(self->GetName().ReadPtr()); +} +PyObject* KX_GameObject::pyattr_get_parent(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + KX_GameObject* parent = self->GetParent(); + if (parent) + return parent->AddRef(); + Py_RETURN_NONE; +} +PyObject* KX_GameObject::pyattr_get_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + KX_IPhysicsController *spc = self->GetPhysicsController(); + return PyFloat_FromDouble(spc ? spc->GetMass() : 0.0f); +} -PyObject* KX_GameObject::_getattr(const char *attr) +int KX_GameObject::pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { - if (m_pPhysicsController1) - { - if (!strcmp(attr, "mass")) - return PyFloat_FromDouble(m_pPhysicsController1->GetMass()); + KX_GameObject* self= static_cast(self_v); + KX_IPhysicsController *spc = self->GetPhysicsController(); + MT_Scalar val = PyFloat_AsDouble(value); + if (val < 0.0f) { /* also accounts for non float */ + PyErr_SetString(PyExc_AttributeError, "expected a float zero or above"); + return 1; } - if (!strcmp(attr, "parent")) - { - KX_GameObject* parent = GetParent(); - if (parent) - return parent->AddRef(); - Py_RETURN_NONE; - } + if (spc) + spc->SetMass(val); - if (!strcmp(attr, "visible")) - return PyInt_FromLong(m_bVisible); - - if (!strcmp(attr, "position")) - return PyObjectFrom(NodeGetWorldPosition()); - - if (!strcmp(attr, "orientation")) - return PyObjectFrom(NodeGetWorldOrientation()); - - if (!strcmp(attr, "scaling")) - return PyObjectFrom(NodeGetWorldScaling()); - - if (!strcmp(attr, "name")) - return PyString_FromString(m_name.ReadPtr()); - - if (!strcmp(attr, "timeOffset")) - { - if (m_pSGNode->GetSGParent()->IsSlowParent()) { - return PyFloat_FromDouble(static_cast(m_pSGNode->GetSGParent()->GetParentRelation())->GetTimeOffset()); - } else { - return PyFloat_FromDouble(0.0); - } + return 0; +} + +PyObject* KX_GameObject::pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + return PyBool_FromLong(self->GetVisible()); +} + +int KX_GameObject::pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_GameObject* self= static_cast(self_v); + int param = PyObject_IsTrue( value ); + if (param == -1) { + PyErr_SetString(PyExc_AttributeError, "expected True or False"); + return 1; } - - - _getattr_up(SCA_IObject); + + self->SetVisible(param, false); + self->UpdateBuckets(false); + return 0; } -int KX_GameObject::_setattr(const char *attr, PyObject *value) // _setattr method +PyObject* KX_GameObject::pyattr_get_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + return PyObjectFrom(self->NodeGetWorldPosition()); +} + +int KX_GameObject::pyattr_set_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { + KX_GameObject* self= static_cast(self_v); + MT_Point3 pos; + if (!PyVecTo(value, pos)) + return 1; - if (!strcmp(attr, "parent")) { - PyErr_SetString(PyExc_AttributeError, "attribute \"parent\" is read only\nUse setParent()"); + self->NodeSetLocalPosition(pos); + self->NodeUpdateGS(0.f,true); + return 0; +} + + +PyObject* KX_GameObject::pyattr_get_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + return PyObjectFrom(self->NodeGetWorldOrientation()); +} + +int KX_GameObject::pyattr_set_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_GameObject* self= static_cast(self_v); + if (!PySequence_Check(value)) { + PyErr_SetString(PyExc_AttributeError, "'orientation' attribute needs to be a sequence"); return 1; } - - if (PyInt_Check(value)) + + MT_Matrix3x3 rot; + if (PyObject_IsMT_Matrix(value, 3)) { - int val = PyInt_AsLong(value); - if (!strcmp(attr, "visible")) + if (PyMatTo(value, rot)) { - SetVisible(val != 0, false); - UpdateBuckets(false); + self->NodeSetLocalOrientation(rot); + self->NodeUpdateGS(0.f,true); return 0; } + return 1; } - if (PyFloat_Check(value)) + if (PySequence_Size(value) == 4) { - MT_Scalar val = PyFloat_AsDouble(value); - if (!strcmp(attr, "timeOffset")) { - if (m_pSGNode->GetSGParent() && m_pSGNode->GetSGParent()->IsSlowParent()) { - static_cast(m_pSGNode->GetSGParent()->GetParentRelation())->SetTimeOffset(val); - return 0; - } else { - return 0; - } - } - if (!strcmp(attr, "mass")) { - if (m_pPhysicsController1) - m_pPhysicsController1->SetMass(val); + MT_Quaternion qrot; + if (PyVecTo(value, qrot)) + { + rot.setRotation(qrot); + self->NodeSetLocalOrientation(rot); + self->NodeUpdateGS(0.f,true); return 0; } + return 1; } - - if (PySequence_Check(value)) + + if (PySequence_Size(value) == 3) { - if (!strcmp(attr, "orientation")) + MT_Vector3 erot; + if (PyVecTo(value, erot)) { - MT_Matrix3x3 rot; - if (PyObject_IsMT_Matrix(value, 3)) - { - if (PyMatTo(value, rot)) - { - NodeSetLocalOrientation(rot); - NodeUpdateGS(0.f,true); - return 0; - } - return 1; - } - - if (PySequence_Size(value) == 4) - { - MT_Quaternion qrot; - if (PyVecTo(value, qrot)) - { - rot.setRotation(qrot); - NodeSetLocalOrientation(rot); - NodeUpdateGS(0.f,true); - return 0; - } - return 1; - } - - if (PySequence_Size(value) == 3) - { - MT_Vector3 erot; - if (PyVecTo(value, erot)) - { - rot.setEuler(erot); - NodeSetLocalOrientation(rot); - NodeUpdateGS(0.f,true); - return 0; - } - return 1; - } - PyErr_SetString(PyExc_AttributeError, "could not set the orientation from a 3x3 matrix, quaternion or euler sequence"); - return 1; - } - - if (!strcmp(attr, "position")) - { - MT_Point3 pos; - if (PyVecTo(value, pos)) - { - NodeSetLocalPosition(pos); - NodeUpdateGS(0.f,true); - return 0; - } - return 1; - } - - if (!strcmp(attr, "scaling")) - { - MT_Vector3 scale; - if (PyVecTo(value, scale)) - { - NodeSetLocalScale(scale); - NodeUpdateGS(0.f,true); - return 0; - } - return 1; + rot.setEuler(erot); + self->NodeSetLocalOrientation(rot); + self->NodeUpdateGS(0.f,true); + return 0; } + return 1; + } + + PyErr_SetString(PyExc_AttributeError, "could not set the orientation from a 3x3 matrix, quaternion or euler sequence"); + return 1; +} + +PyObject* KX_GameObject::pyattr_get_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + return PyObjectFrom(self->NodeGetWorldScaling()); +} + +int KX_GameObject::pyattr_set_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_GameObject* self= static_cast(self_v); + MT_Vector3 scale; + if (!PyVecTo(value, scale)) + return 1; + + self->NodeSetLocalScale(scale); + self->NodeUpdateGS(0.f,true); + return 0; +} + +PyObject* KX_GameObject::pyattr_get_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + SG_Node* sg_parent= self->GetSGNode()->GetSGParent(); + if (sg_parent && sg_parent->IsSlowParent()) { + return PyFloat_FromDouble(static_cast(sg_parent->GetParentRelation())->GetTimeOffset()); + } else { + return PyFloat_FromDouble(0.0); + } +} + +int KX_GameObject::pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_GameObject* self= static_cast(self_v); + MT_Scalar val = PyFloat_AsDouble(value); + SG_Node* sg_parent= self->GetSGNode()->GetSGParent(); + if (val < 0.0f) { /* also accounts for non float */ + PyErr_SetString(PyExc_AttributeError, "expected a float zero or above"); + return 1; } + + if (sg_parent && sg_parent->IsSlowParent()) + static_cast(sg_parent->GetParentRelation())->SetTimeOffset(val); + + return 0; +} + +PyObject* KX_GameObject::pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + int state = 0; + state |= self->GetState(); + return PyInt_FromLong(state); +} + +int KX_GameObject::pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_GameObject* self= static_cast(self_v); + int state_i = PyInt_AsLong(value); + unsigned int state = 0; - if (PyString_Check(value)) - { - 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 - } + if (state_i == -1 && PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "expected an int bit field"); + return 1; } - /* Need to have parent settable here too */ + state |= state_i; + if ((state & ((1<<30)-1)) == 0) { + PyErr_SetString(PyExc_AttributeError, "The state bitfield was not between 0 and 30 (1<<0 and 1<<29)"); + return 1; + } + self->SetState(state); + return 0; +} + +PyObject* KX_GameObject::_getattr(const char *attr) +{ + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + + if (!strcmp(attr, "__dict__")) { /* python 3.0 uses .__dir__()*/ + return _getattr_dict(SCA_IObject::_getattr(attr), Methods, Attributes); + } + + _getattr_up(SCA_IObject); +} + +int KX_GameObject::_setattr(const char *attr, PyObject *value) // _setattr method +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; return SCA_IObject::_setattr(attr, value); } @@ -1428,11 +1492,13 @@ PyObject* KX_GameObject::PySetVisible(PyObject* self, PyObject* args) PyObject* KX_GameObject::PyGetVisible(PyObject* self) { + ShowDeprecationWarning("getVisible()", "the visible property"); return PyInt_FromLong(m_bVisible); } PyObject* KX_GameObject::PyGetState(PyObject* self) { + ShowDeprecationWarning("getState()", "the state property"); int state = 0; state |= GetState(); return PyInt_FromLong(state); @@ -1440,6 +1506,7 @@ PyObject* KX_GameObject::PyGetState(PyObject* self) PyObject* KX_GameObject::PySetState(PyObject* self, PyObject* value) { + ShowDeprecationWarning("setState()", "the state property"); int state_i = PyInt_AsLong(value); unsigned int state = 0; @@ -1458,8 +1525,6 @@ PyObject* KX_GameObject::PySetState(PyObject* self, PyObject* value) Py_RETURN_NONE; } - - PyObject* KX_GameObject::PyGetVelocity(PyObject* self, PyObject* args) { // only can get the velocity if we have a physics object connected to us... @@ -1488,6 +1553,7 @@ PyObject* KX_GameObject::PyGetVelocity(PyObject* self, PyObject* args) PyObject* KX_GameObject::PyGetMass(PyObject* self) { + ShowDeprecationWarning("getMass()", "the mass property"); return PyFloat_FromDouble(GetPhysicsController()->GetMass()); } @@ -1521,6 +1587,7 @@ PyObject* KX_GameObject::PyDisableRigidBody(PyObject* self) PyObject* KX_GameObject::PyGetParent(PyObject* self) { + ShowDeprecationWarning("getParent()", "the parent property"); KX_GameObject* parent = this->GetParent(); if (parent) return parent->AddRef(); @@ -1673,6 +1740,7 @@ PyObject* KX_GameObject::PyRestoreDynamics(PyObject* self) PyObject* KX_GameObject::PyGetOrientation(PyObject* self) //keywords { + ShowDeprecationWarning("getOrientation()", "the orientation property"); return PyObjectFrom(NodeGetWorldOrientation()); } @@ -1680,6 +1748,7 @@ PyObject* KX_GameObject::PyGetOrientation(PyObject* self) //keywords PyObject* KX_GameObject::PySetOrientation(PyObject* self, PyObject* value) { + ShowDeprecationWarning("setOrientation()", "the orientation property"); MT_Matrix3x3 matrix; if (PyObject_IsMT_Matrix(value, 3) && PyMatTo(value, matrix)) { @@ -1733,6 +1802,7 @@ PyObject* KX_GameObject::PyGetAxisVect(PyObject* self, PyObject* value) PyObject* KX_GameObject::PySetPosition(PyObject* self, PyObject* value) { + ShowDeprecationWarning("setPosition()", "the position property"); MT_Point3 pos; if (PyVecTo(value, pos)) { diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 211c9b7ca7d..326b3700ad7 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -802,7 +802,27 @@ public: KX_PYMETHOD_DOC(KX_GameObject,rayCast); KX_PYMETHOD_DOC_O(KX_GameObject,getDistanceTo); KX_PYMETHOD_DOC_O(KX_GameObject,getVectTo); + + /* attributes */ + static PyObject* pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_parent(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + + static PyObject* pyattr_get_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + private : /** diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index 4f389a1ae4f..694fe02a7cc 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -24,6 +24,8 @@ class KX_GameObject: @type scaling: list [sx, sy, sz] @ivar timeOffset: adjust the slowparent delay at runtime. @type timeOffset: float + @ivar state: the game object's state bitmask. + @type state: int """ def endObject(visible): """ @@ -37,33 +39,35 @@ class KX_GameObject: """ def getVisible(): """ - Gets the game object's visible flag. + Gets the game object's visible flag. (B{deprecated}) @rtype: boolean """ - def setVisible(visible): + def setVisible(visible, recursive): """ Sets the game object's visible flag. @type visible: boolean + @type recursive: boolean + @param recursive: optional argument to set all childrens visibility flag too. """ def getState(): """ - Gets the game object's state bitmask. + Gets the game object's state bitmask. (B{deprecated}) @rtype: int @return: the objects state. """ def setState(state): """ - Sets the game object's state flag. - The bitmasks for states from 1 to 30 can be set with (1<<0, 1<<1, 1<<2 ... 1<<29) + Sets the game object's state flag. (B{deprecated}). + The bitmasks for states from 1 to 30 can be set with (1<<0, 1<<1, 1<<2 ... 1<<29) @type state: integer """ def setPosition(pos): """ - Sets the game object's position. + Sets the game object's position. (B{deprecated}) Global coordinates for root object, local for child objects. @@ -79,14 +83,14 @@ class KX_GameObject: """ def getPosition(): """ - Gets the game object's position. + Gets the game object's position. (B{deprecated}) @rtype: list [x, y, z] @return: the object's position in world coordinates. """ def setOrientation(orn): """ - Sets the game object's orientation. + Sets the game object's orientation. (B{deprecated}) @type orn: 3x3 rotation matrix, or Quaternion. @param orn: a rotation matrix specifying the new rotation. @@ -117,7 +121,7 @@ class KX_GameObject: """ def getOrientation(): """ - Gets the game object's orientation. + Gets the game object's orientation. (B{deprecated}) @rtype: 3x3 rotation matrix @return: The game object's rotation matrix @@ -231,7 +235,7 @@ class KX_GameObject: """ def getMass(): """ - Gets the game object's mass. + Gets the game object's mass. (B{deprecated}) @rtype: float @return: the object's mass. @@ -280,7 +284,7 @@ class KX_GameObject: """ def getParent(): """ - Gets this object's parent. + Gets this object's parent. (B{deprecated}) @rtype: L{KX_GameObject} @return: this object's parent object, or None if this object has no parent. -- cgit v1.2.3 From bba2bdf41e064c4c6602aa5e6c6c79364f51b08d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 26 Mar 2009 01:42:01 +0000 Subject: Added attributes for Ipo Actuator settings (replacing all methods) --- source/gameengine/Ketsji/KX_IpoActuator.cpp | 65 +++++++++++++++++++++++++---- source/gameengine/Ketsji/KX_IpoActuator.h | 6 ++- source/gameengine/Ketsji/KX_PythonInit.cpp | 1 + source/gameengine/PyDoc/KX_IpoActuator.py | 47 ++++++++++++++------- 4 files changed, 94 insertions(+), 25 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index 623a939bf62..f6fdce9de0f 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -84,7 +84,7 @@ KX_IpoActuator::KX_IpoActuator(SCA_IObject* gameobj, m_ipo_as_force(ipo_as_force), m_ipo_add(ipo_add), m_ipo_local(ipo_local), - m_type((IpoActType)acttype) + m_type(acttype) { m_starttime = -2.0*fabs(m_endframe - m_startframe) - 1.0; m_bIpoPlaying = false; @@ -190,7 +190,7 @@ bool KX_IpoActuator::Update(double curtime, bool frame) } } - switch (m_type) + switch ((IpoActType)m_type) { case KX_ACT_IPO_PLAY: @@ -383,7 +383,7 @@ bool KX_IpoActuator::Update(double curtime, bool frame) return result; } -KX_IpoActuator::IpoActType KX_IpoActuator::string2mode(char* modename) { +int KX_IpoActuator::string2mode(char* modename) { IpoActType res = KX_ACT_IPO_NODEF; if (modename == S_KX_ACT_IPO_PLAY_STRING) { @@ -441,6 +441,8 @@ PyParentObject KX_IpoActuator::Parents[] = { PyMethodDef KX_IpoActuator::Methods[] = { {"set", (PyCFunction) KX_IpoActuator::sPySet, METH_VARARGS, (PY_METHODCHAR)Set_doc}, + + // deprecated {"setProperty", (PyCFunction) KX_IpoActuator::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc}, {"setStart", (PyCFunction) KX_IpoActuator::sPySetStart, METH_VARARGS, (PY_METHODCHAR)SetStart_doc}, {"getStart", (PyCFunction) KX_IpoActuator::sPyGetStart, METH_NOARGS, (PY_METHODCHAR)GetStart_doc}, @@ -450,22 +452,47 @@ PyMethodDef KX_IpoActuator::Methods[] = { {"getIpoAsForce", (PyCFunction) KX_IpoActuator::sPyGetIpoAsForce, METH_NOARGS, (PY_METHODCHAR)GetIpoAsForce_doc}, {"setIpoAdd", (PyCFunction) KX_IpoActuator::sPySetIpoAdd, METH_VARARGS, (PY_METHODCHAR)SetIpoAdd_doc}, {"getIpoAdd", (PyCFunction) KX_IpoActuator::sPyGetIpoAdd, METH_NOARGS, (PY_METHODCHAR)GetIpoAdd_doc}, - {"setType", (PyCFunction) KX_IpoActuator::sPySetType, METH_VARARGS, (PY_METHODCHAR)SetType_doc}, - {"getType", (PyCFunction) KX_IpoActuator::sPyGetType, METH_NOARGS, (PY_METHODCHAR)GetType_doc}, {"setForceIpoActsLocal", (PyCFunction) KX_IpoActuator::sPySetForceIpoActsLocal, METH_VARARGS, (PY_METHODCHAR)SetForceIpoActsLocal_doc}, {"getForceIpoActsLocal", (PyCFunction) KX_IpoActuator::sPyGetForceIpoActsLocal, METH_NOARGS, (PY_METHODCHAR)GetForceIpoActsLocal_doc}, + {"setType", (PyCFunction) KX_IpoActuator::sPySetType, METH_VARARGS, (PY_METHODCHAR)SetType_doc}, + {"getType", (PyCFunction) KX_IpoActuator::sPyGetType, METH_NOARGS, (PY_METHODCHAR)GetType_doc}, {NULL,NULL} //Sentinel }; PyAttributeDef KX_IpoActuator::Attributes[] = { + KX_PYATTRIBUTE_FLOAT_RW("startFrame", 0, 300000, KX_IpoActuator, m_startframe), + KX_PYATTRIBUTE_FLOAT_RW("endFrame", 0, 300000, KX_IpoActuator, m_endframe), + KX_PYATTRIBUTE_STRING_RW("propName", 0, 64, false, KX_IpoActuator, m_propname), + KX_PYATTRIBUTE_STRING_RW("framePropName", 0, 64, false, KX_IpoActuator, m_framepropname), + KX_PYATTRIBUTE_INT_RW("type", KX_ACT_IPO_NODEF+1, KX_ACT_IPO_MAX-1, true, KX_IpoActuator, m_type), + KX_PYATTRIBUTE_BOOL_RW("useIpoAsForce", KX_IpoActuator, m_ipo_as_force), + KX_PYATTRIBUTE_BOOL_RW("useIpoAdd", KX_IpoActuator, m_ipo_add), + KX_PYATTRIBUTE_BOOL_RW("useIpoLocal", KX_IpoActuator, m_ipo_local), + KX_PYATTRIBUTE_BOOL_RW("useChildren", KX_IpoActuator, m_recurse), + { NULL } //Sentinel }; PyObject* KX_IpoActuator::_getattr(const char *attr) { + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + + if (!strcmp(attr, "__dict__")) { /* python 3.0 uses .__dir__()*/ + return _getattr_dict(SCA_IActuator::_getattr(attr), Methods, Attributes); + } + _getattr_up(SCA_IActuator); } - +int KX_IpoActuator::_setattr(const char *attr, PyObject *value) // _setattr method +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + + return SCA_IActuator::_setattr(attr, value); +} /* set --------------------------------------------------------------------- */ const char KX_IpoActuator::Set_doc[] = @@ -478,12 +505,15 @@ const char KX_IpoActuator::Set_doc[] = PyObject* KX_IpoActuator::PySet(PyObject* self, PyObject* args, PyObject* kwds) { + + ShowDeprecationWarning("set()", "a number properties"); + /* sets modes PLAY, PINGPONG, FLIPPER, LOOPSTOP, LOOPEND */ /* arg 1 = mode string, arg 2 = startframe, arg3 = stopframe, */ /* arg4 = force toggle */ char* mode; int forceToggle; - IpoActType modenum; + int modenum; int startFrame, stopFrame; if(!PyArg_ParseTuple(args, "siii", &mode, &startFrame, &stopFrame, &forceToggle)) { @@ -518,6 +548,9 @@ const char KX_IpoActuator::SetProperty_doc[] = PyObject* KX_IpoActuator::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds) { + + ShowDeprecationWarning("setProperty()", "the propName property"); + /* mode is implicit here, but not supported yet... */ /* args: property */ char *propertyName; @@ -538,6 +571,9 @@ const char KX_IpoActuator::SetStart_doc[] = PyObject* KX_IpoActuator::PySetStart(PyObject* self, PyObject* args, PyObject* kwds) { + + ShowDeprecationWarning("setStart()", "the startFrame property"); + float startArg; if(!PyArg_ParseTuple(args, "f", &startArg)) { return NULL; @@ -552,6 +588,7 @@ const char KX_IpoActuator::GetStart_doc[] = "getStart()\n" "\tReturns the frame from which the ipo starts playing.\n"; PyObject* KX_IpoActuator::PyGetStart(PyObject* self) { + ShowDeprecationWarning("getStart()", "the startFrame property"); return PyFloat_FromDouble(m_startframe); } @@ -563,6 +600,7 @@ const char KX_IpoActuator::SetEnd_doc[] = PyObject* KX_IpoActuator::PySetEnd(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setEnd()", "the endFrame property"); float endArg; if(!PyArg_ParseTuple(args, "f", &endArg)) { return NULL; @@ -577,6 +615,7 @@ const char KX_IpoActuator::GetEnd_doc[] = "getEnd()\n" "\tReturns the frame at which the ipo stops playing.\n"; PyObject* KX_IpoActuator::PyGetEnd(PyObject* self) { + ShowDeprecationWarning("getEnd()", "the endFrame property"); return PyFloat_FromDouble(m_endframe); } @@ -588,6 +627,7 @@ const char KX_IpoActuator::SetIpoAsForce_doc[] = PyObject* KX_IpoActuator::PySetIpoAsForce(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setIpoAsForce()", "the useIpoAsForce property"); int boolArg; if (!PyArg_ParseTuple(args, "i", &boolArg)) { @@ -605,6 +645,7 @@ const char KX_IpoActuator::GetIpoAsForce_doc[] = "getIpoAsForce()\n" "\tReturns whether to interpret the ipo as a force rather than a displacement.\n"; PyObject* KX_IpoActuator::PyGetIpoAsForce(PyObject* self) { + ShowDeprecationWarning("getIpoAsForce()", "the useIpoAsForce property"); return BoolToPyArg(m_ipo_as_force); } @@ -616,6 +657,7 @@ const char KX_IpoActuator::SetIpoAdd_doc[] = PyObject* KX_IpoActuator::PySetIpoAdd(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setIpoAdd()", "the useIpoAdd property"); int boolArg; if (!PyArg_ParseTuple(args, "i", &boolArg)) { @@ -633,6 +675,7 @@ const char KX_IpoActuator::GetIpoAdd_doc[] = "getIpoAsAdd()\n" "\tReturns whether to interpret the ipo as additive rather than absolute.\n"; PyObject* KX_IpoActuator::PyGetIpoAdd(PyObject* self) { + ShowDeprecationWarning("getIpoAdd()", "the useIpoAdd property"); return BoolToPyArg(m_ipo_add); } @@ -644,6 +687,7 @@ const char KX_IpoActuator::SetType_doc[] = PyObject* KX_IpoActuator::PySetType(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setType()", "the type property"); int typeArg; if (!PyArg_ParseTuple(args, "i", &typeArg)) { @@ -651,8 +695,8 @@ PyObject* KX_IpoActuator::PySetType(PyObject* self, } if ( (typeArg > KX_ACT_IPO_NODEF) - && (typeArg < KX_ACT_IPO_KEY2KEY) ) { - m_type = (IpoActType) typeArg; + && (typeArg < KX_ACT_IPO_MAX) ) { + m_type = typeArg; } Py_RETURN_NONE; @@ -662,6 +706,7 @@ const char KX_IpoActuator::GetType_doc[] = "getType()\n" "\tReturns the operation mode of the actuator.\n"; PyObject* KX_IpoActuator::PyGetType(PyObject* self) { + ShowDeprecationWarning("getType()", "the type property"); return PyInt_FromLong(m_type); } @@ -675,6 +720,7 @@ const char KX_IpoActuator::SetForceIpoActsLocal_doc[] = PyObject* KX_IpoActuator::PySetForceIpoActsLocal(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setForceIpoActsLocal()", "the useIpoLocal property"); int boolArg; if (!PyArg_ParseTuple(args, "i", &boolArg)) { @@ -691,6 +737,7 @@ const char KX_IpoActuator::GetForceIpoActsLocal_doc[] = "\tReturn whether to apply the force in the object's local\n" "\tcoordinates rather than the world global coordinates.\n"; PyObject* KX_IpoActuator::PyGetForceIpoActsLocal(PyObject* self) { + ShowDeprecationWarning("getForceIpoActsLocal()", "the useIpoLocal property"); return BoolToPyArg(m_ipo_local); } diff --git a/source/gameengine/Ketsji/KX_IpoActuator.h b/source/gameengine/Ketsji/KX_IpoActuator.h index 12e1835ab49..fa8e58ae861 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.h +++ b/source/gameengine/Ketsji/KX_IpoActuator.h @@ -108,9 +108,9 @@ public: static STR_String S_KX_ACT_IPO_KEY2KEY_STRING; static STR_String S_KX_ACT_IPO_FROM_PROP_STRING; - IpoActType string2mode(char* modename); + int string2mode(char* modename); - IpoActType m_type; + int m_type; KX_IpoActuator(SCA_IObject* gameobj, const STR_String& propname, @@ -142,6 +142,8 @@ public: /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); + //KX_PYMETHOD_DOC KX_PYMETHOD_DOC(KX_IpoActuator,Set); KX_PYMETHOD_DOC(KX_IpoActuator,SetProperty); diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index d974d67bf33..bc2111571ac 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -970,6 +970,7 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, KX_IPOACT_FLIPPER, KX_IpoActuator::KX_ACT_IPO_FLIPPER); KX_MACRO_addTypesToDict(d, KX_IPOACT_LOOPSTOP, KX_IpoActuator::KX_ACT_IPO_LOOPSTOP); KX_MACRO_addTypesToDict(d, KX_IPOACT_LOOPEND, KX_IpoActuator::KX_ACT_IPO_LOOPEND); + KX_MACRO_addTypesToDict(d, KX_IPOACT_FROM_PROP,KX_IpoActuator::KX_ACT_IPO_FROM_PROP); /* 5. Random distribution types */ KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_CONST, SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST); diff --git a/source/gameengine/PyDoc/KX_IpoActuator.py b/source/gameengine/PyDoc/KX_IpoActuator.py index e2fe3b289e3..ebc0b855f0a 100644 --- a/source/gameengine/PyDoc/KX_IpoActuator.py +++ b/source/gameengine/PyDoc/KX_IpoActuator.py @@ -5,10 +5,29 @@ from SCA_IActuator import * class KX_IpoActuator(SCA_IActuator): """ IPO actuator activates an animation. + + @ivar startFrame: Start frame. + @type startFrame: float + @ivar endFrame: End frame. + @type endFrame: float + @ivar propName: Use this property to define the Ipo position + @type propName: string + @ivar framePropName: Assign this property this action current frame number + @type framePropName: string + @ivar type: Play mode for the ipo. (In GameLogic.KX_IPOACT_PLAY, KX_IPOACT_PINGPONG, KX_IPOACT_FLIPPER, KX_IPOACT_LOOPSTOP, KX_IPOACT_LOOPEND, KX_IPOACT_FROM_PROP) + @type type: int + @ivar useIpoAsForce: Apply Ipo as a global or local force depending on the local option (dynamic objects only) + @type useIpoAsForce: bool + @ivar useIpoAdd: Ipo is added to the current loc/rot/scale in global or local coordinate according to Local flag + @type useIpoAdd: bool + @ivar useIpoLocal: Let the ipo acts in local coordinates, used in Force and Add mode. + @type useIpoLocal: bool + @ivar useChildren: Update IPO on all children Objects as well + @type useChildren: bool """ def set(mode, startframe, endframe, force): """ - Sets the properties of the actuator. + Sets the properties of the actuator. (B{deprecated}) @param mode: "Play", "PingPong", "Flipper", "LoopStop", "LoopEnd" or "FromProp" @type mode: string @@ -21,70 +40,70 @@ class KX_IpoActuator(SCA_IActuator): """ def setProperty(property): """ - Sets the name of the property to be used in FromProp mode. + Sets the name of the property to be used in FromProp mode. (B{deprecated}) @type property: string """ def setStart(startframe): """ - Sets the frame from which the IPO starts playing. + Sets the frame from which the IPO starts playing. (B{deprecated}) @type startframe: integer """ def getStart(): """ - Returns the frame from which the IPO starts playing. + Returns the frame from which the IPO starts playing. (B{deprecated}) @rtype: integer """ def setEnd(endframe): """ - Sets the frame at which the IPO stops playing. + Sets the frame at which the IPO stops playing. (B{deprecated}) @type endframe: integer """ def getEnd(): """ - Returns the frame at which the IPO stops playing. + Returns the frame at which the IPO stops playing. (B{deprecated}) @rtype: integer """ def setIpoAsForce(force): """ - Set whether to interpret the ipo as a force rather than a displacement. + Set whether to interpret the ipo as a force rather than a displacement. (B{deprecated}) @type force: boolean @param force: KX_TRUE or KX_FALSE """ def getIpoAsForce(): """ - Returns whether to interpret the ipo as a force rather than a displacement. + Returns whether to interpret the ipo as a force rather than a displacement. (B{deprecated}) @rtype: boolean """ def setIpoAdd(add): """ - Set whether to interpret the ipo as additive rather than absolute. + Set whether to interpret the ipo as additive rather than absolute. (B{deprecated}) @type add: boolean @param add: KX_TRUE or KX_FALSE """ def getIpoAdd(): """ - Returns whether to interpret the ipo as additive rather than absolute. + Returns whether to interpret the ipo as additive rather than absolute. (B{deprecated}) @rtype: boolean """ def setType(mode): """ - Sets the operation mode of the actuator. + Sets the operation mode of the actuator. (B{deprecated}) @param mode: KX_IPOACT_PLAY, KX_IPOACT_PINGPONG, KX_IPOACT_FLIPPER, KX_IPOACT_LOOPSTOP, KX_IPOACT_LOOPEND @type mode: string """ def getType(): """ - Returns the operation mode of the actuator. + Returns the operation mode of the actuator. (B{deprecated}) @rtype: integer @return: KX_IPOACT_PLAY, KX_IPOACT_PINGPONG, KX_IPOACT_FLIPPER, KX_IPOACT_LOOPSTOP, KX_IPOACT_LOOPEND @@ -92,7 +111,7 @@ class KX_IpoActuator(SCA_IActuator): def setForceIpoActsLocal(local): """ Set whether to apply the force in the object's local - coordinates rather than the world global coordinates. + coordinates rather than the world global coordinates. (B{deprecated}) @param local: Apply the ipo-as-force in the object's local coordinates? (KX_TRUE, KX_FALSE) @@ -101,5 +120,5 @@ class KX_IpoActuator(SCA_IActuator): def getForceIpoActsLocal(): """ Return whether to apply the force in the object's local - coordinates rather than the world global coordinates. + coordinates rather than the world global coordinates. (B{deprecated}) """ -- cgit v1.2.3 From 059c2a10c4df53a7cd96689e8a60be2afd4b4d46 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Fri, 27 Mar 2009 21:54:16 +0000 Subject: BGE API cleanup: AddObject, DeleteObject and Scene actuator added. --- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp | 110 ++++++++++++++------- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.h | 11 ++- source/gameengine/Ketsji/KX_SceneActuator.cpp | 65 ++++++++++++ source/gameengine/Ketsji/KX_SceneActuator.h | 4 + .../gameengine/PyDoc/KX_SCA_AddObjectActuator.py | 15 +++ source/gameengine/PyDoc/KX_SceneActuator.py | 14 +++ 6 files changed, 179 insertions(+), 40 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index 68b704f4889..7c4f60a7f0a 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -38,7 +38,7 @@ #include "SCA_IScene.h" #include "KX_GameObject.h" #include "KX_IPhysicsController.h" - +#include "blendef.h" #include "PyObjectPlus.h" #ifdef HAVE_CONFIG_H @@ -53,9 +53,9 @@ KX_SCA_AddObjectActuator::KX_SCA_AddObjectActuator(SCA_IObject *gameobj, SCA_IObject *original, int time, SCA_IScene* scene, - const MT_Vector3& linvel, + const float *linvel, bool linv_local, - const MT_Vector3& angvel, + const float *angvel, bool angv_local, PyTypeObject* T) : @@ -63,12 +63,16 @@ KX_SCA_AddObjectActuator::KX_SCA_AddObjectActuator(SCA_IObject *gameobj, m_OriginalObject(original), m_scene(scene), - m_linear_velocity(linvel), m_localLinvFlag(linv_local), - - m_angular_velocity(angvel), m_localAngvFlag(angv_local) { + m_linear_velocity[0] = linvel[0]; + m_linear_velocity[1] = linvel[1]; + m_linear_velocity[2] = linvel[2]; + m_angular_velocity[0] = angvel[0]; + m_angular_velocity[1] = angvel[1]; + m_angular_velocity[2] = angvel[2]; + if (m_OriginalObject) m_OriginalObject->RegisterActuator(this); @@ -188,6 +192,7 @@ PyParentObject KX_SCA_AddObjectActuator::Parents[] = { NULL }; PyMethodDef KX_SCA_AddObjectActuator::Methods[] = { + // ---> deprecated {"setTime", (PyCFunction) KX_SCA_AddObjectActuator::sPySetTime, METH_O, (PY_METHODCHAR)SetTime_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}, @@ -196,8 +201,6 @@ PyMethodDef KX_SCA_AddObjectActuator::Methods[] = { {"setAngularVelocity", (PyCFunction) KX_SCA_AddObjectActuator::sPySetAngularVelocity, METH_VARARGS, (PY_METHODCHAR)SetAngularVelocity_doc}, {"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}, @@ -205,41 +208,65 @@ PyMethodDef KX_SCA_AddObjectActuator::Methods[] = { }; PyAttributeDef KX_SCA_AddObjectActuator::Attributes[] = { + KX_PYATTRIBUTE_RW_FUNCTION("object",KX_SCA_AddObjectActuator,pyattr_get_object,pyattr_set_object), + KX_PYATTRIBUTE_RO_FUNCTION("objectLastCreated",KX_SCA_AddObjectActuator,pyattr_get_objectLastCreated), + KX_PYATTRIBUTE_INT_RW("time",0,2000,true,KX_SCA_AddObjectActuator,m_timeProp), + KX_PYATTRIBUTE_FLOAT_ARRAY_RW("linearVelocity",-MAXFLOAT,MAXFLOAT,KX_SCA_AddObjectActuator,m_linear_velocity,3), + KX_PYATTRIBUTE_FLOAT_ARRAY_RW("angularVelocity",-MAXFLOAT,MAXFLOAT,KX_SCA_AddObjectActuator,m_angular_velocity,3), { NULL } //Sentinel }; -PyObject* KX_SCA_AddObjectActuator::_getattr(const char *attr) +PyObject* KX_SCA_AddObjectActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { - if (!strcmp(attr, "object")) { - if (!m_OriginalObject) Py_RETURN_NONE; - else return m_OriginalObject->AddRef(); - } else if (!strcmp(attr, "objectLastCreated")) { - if (!m_OriginalObject) Py_RETURN_NONE; - else return m_lastCreatedObject->AddRef(); - } - - _getattr_up(SCA_IActuator); + KX_SCA_AddObjectActuator* actuator = static_cast(self); + if (!actuator->m_OriginalObject) + Py_RETURN_NONE; + else + return actuator->m_OriginalObject->AddRef(); } -int KX_SCA_AddObjectActuator::_setattr(const char *attr, PyObject* value) { - - if (!strcmp(attr, "object")) { - KX_GameObject *gameobj; +int KX_SCA_AddObjectActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_SCA_AddObjectActuator* actuator = static_cast(self); + KX_GameObject *gameobj; - if (!ConvertPythonToGameObject(value, &gameobj, true)) - return 1; // ConvertPythonToGameObject sets the error + if (!ConvertPythonToGameObject(value, &gameobj, true)) + return 1; // ConvertPythonToGameObject sets the error - if (m_OriginalObject != NULL) - m_OriginalObject->UnregisterActuator(this); + if (actuator->m_OriginalObject != NULL) + actuator->m_OriginalObject->UnregisterActuator(actuator); - m_OriginalObject = (SCA_IObject*)gameobj; + actuator->m_OriginalObject = (SCA_IObject*)gameobj; - if (m_OriginalObject) - m_OriginalObject->RegisterActuator(this); + if (actuator->m_OriginalObject) + actuator->m_OriginalObject->RegisterActuator(actuator); - return 0; - } - + return 0; +} + +PyObject* KX_SCA_AddObjectActuator::pyattr_get_objectLastCreated(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_SCA_AddObjectActuator* actuator = static_cast(self); + if (!actuator->m_lastCreatedObject) + Py_RETURN_NONE; + else + return actuator->m_lastCreatedObject->AddRef(); +} + + +PyObject* KX_SCA_AddObjectActuator::_getattr(const char *attr) +{ + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + _getattr_up(SCA_IActuator); +} + +int KX_SCA_AddObjectActuator::_setattr(const char *attr, PyObject* value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; return SCA_IActuator::_setattr(attr, value); } @@ -280,6 +307,7 @@ const char KX_SCA_AddObjectActuator::SetTime_doc[] = PyObject* KX_SCA_AddObjectActuator::PySetTime(PyObject* self, PyObject* value) { + ShowDeprecationWarning("setTime()", "the time property"); int deltatime = PyInt_AsLong(value); if (deltatime==-1 && PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "expected an int"); @@ -296,12 +324,13 @@ PyObject* KX_SCA_AddObjectActuator::PySetTime(PyObject* self, PyObject* value) /* 3. getTime */ const char KX_SCA_AddObjectActuator::GetTime_doc[] = -"GetTime()\n" +"getTime()\n" "\tReturns the lifetime of the object that will be added.\n"; PyObject* KX_SCA_AddObjectActuator::PyGetTime(PyObject* self) { + ShowDeprecationWarning("getTime()", "the time property"); return PyInt_FromLong(m_timeProp); } @@ -339,6 +368,7 @@ const char KX_SCA_AddObjectActuator::GetLinearVelocity_doc[] = PyObject* KX_SCA_AddObjectActuator::PyGetLinearVelocity(PyObject* self) { + ShowDeprecationWarning("getLinearVelocity()", "the linearVelocity property"); PyObject *retVal = PyList_New(3); PyList_SET_ITEM(retVal, 0, PyFloat_FromDouble(m_linear_velocity[0])); @@ -361,12 +391,15 @@ const char KX_SCA_AddObjectActuator::SetLinearVelocity_doc[] = PyObject* KX_SCA_AddObjectActuator::PySetLinearVelocity(PyObject* self, PyObject* args) { + ShowDeprecationWarning("setLinearVelocity()", "the linearVelocity property"); float vecArg[3]; if (!PyArg_ParseTuple(args, "fff", &vecArg[0], &vecArg[1], &vecArg[2])) return NULL; - m_linear_velocity.setValue(vecArg); + m_linear_velocity[0] = vecArg[0]; + m_linear_velocity[1] = vecArg[1]; + m_linear_velocity[2] = vecArg[2]; Py_RETURN_NONE; } @@ -378,6 +411,7 @@ const char KX_SCA_AddObjectActuator::GetAngularVelocity_doc[] = PyObject* KX_SCA_AddObjectActuator::PyGetAngularVelocity(PyObject* self) { + ShowDeprecationWarning("getAngularVelocity()", "the angularVelocity property"); PyObject *retVal = PyList_New(3); PyList_SET_ITEM(retVal, 0, PyFloat_FromDouble(m_angular_velocity[0])); @@ -400,12 +434,15 @@ const char KX_SCA_AddObjectActuator::SetAngularVelocity_doc[] = PyObject* KX_SCA_AddObjectActuator::PySetAngularVelocity(PyObject* self, PyObject* args) { + ShowDeprecationWarning("setAngularVelocity()", "the angularVelocity property"); float vecArg[3]; if (!PyArg_ParseTuple(args, "fff", &vecArg[0], &vecArg[1], &vecArg[2])) return NULL; - m_angular_velocity.setValue(vecArg); + m_angular_velocity[0] = vecArg[0]; + m_angular_velocity[1] = vecArg[1]; + m_angular_velocity[2] = vecArg[2]; Py_RETURN_NONE; } @@ -417,7 +454,7 @@ void KX_SCA_AddObjectActuator::InstantAddObject() // Now it needs to be added to the current scene. SCA_IObject* replica = m_scene->AddReplicaObject(m_OriginalObject,GetParent(),m_timeProp ); KX_GameObject * game_obj = static_cast(replica); - game_obj->setLinearVelocity(m_linear_velocity,m_localLinvFlag); + game_obj->setLinearVelocity(m_linear_velocity ,m_localLinvFlag); game_obj->setAngularVelocity(m_angular_velocity,m_localAngvFlag); game_obj->ResolveCombinedVelocities(m_linear_velocity, m_angular_velocity, m_localLinvFlag, m_localAngvFlag); @@ -453,6 +490,7 @@ const char KX_SCA_AddObjectActuator::GetLastCreatedObject_doc[] = PyObject* KX_SCA_AddObjectActuator::PyGetLastCreatedObject(PyObject* self) { + ShowDeprecationWarning("getLastCreatedObject()", "the objectLastCreated property"); SCA_IObject* result = this->GetLastCreatedObject(); // if result->GetSGNode() is NULL diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h index 18298cbcb0c..c8cc7113347 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h @@ -59,12 +59,12 @@ class KX_SCA_AddObjectActuator : public SCA_IActuator SCA_IScene* m_scene; /// Linear velocity upon creation of the object. - MT_Vector3 m_linear_velocity; + float m_linear_velocity[3]; /// Apply the velocity locally bool m_localLinvFlag; /// Angular velocity upon creation of the object. - MT_Vector3 m_angular_velocity; + float m_angular_velocity[3]; /// Apply the velocity locally bool m_localAngvFlag; @@ -85,9 +85,9 @@ public: SCA_IObject *original, int time, SCA_IScene* scene, - const MT_Vector3& linvel, + const float *linvel, bool linv_local, - const MT_Vector3& angvel, + const float *angvel, bool angv_local, PyTypeObject* T=&Type ); @@ -140,6 +140,9 @@ public: /* 10. instantAddObject*/ KX_PYMETHOD_DOC_NOARGS(KX_SCA_AddObjectActuator,InstantAddObject); + static PyObject* pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_objectLastCreated(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); }; /* end of class KX_SCA_AddObjectActuator : public KX_EditObjectActuator */ diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index 1cad4e21352..579c53974d5 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -259,24 +259,83 @@ PyParentObject KX_SceneActuator::Parents[] = PyMethodDef KX_SceneActuator::Methods[] = { + //Deprecated functions ------> {"setUseRestart", (PyCFunction) KX_SceneActuator::sPySetUseRestart, METH_VARARGS, (PY_METHODCHAR)SetUseRestart_doc}, {"setScene", (PyCFunction) KX_SceneActuator::sPySetScene, METH_VARARGS, (PY_METHODCHAR)SetScene_doc}, {"setCamera", (PyCFunction) KX_SceneActuator::sPySetCamera, METH_VARARGS, (PY_METHODCHAR)SetCamera_doc}, {"getUseRestart", (PyCFunction) KX_SceneActuator::sPyGetUseRestart, METH_VARARGS, (PY_METHODCHAR)GetUseRestart_doc}, {"getScene", (PyCFunction) KX_SceneActuator::sPyGetScene, METH_VARARGS, (PY_METHODCHAR)GetScene_doc}, {"getCamera", (PyCFunction) KX_SceneActuator::sPyGetCamera, METH_VARARGS, (PY_METHODCHAR)GetCamera_doc}, + //<----- Deprecated {NULL,NULL} //Sentinel }; PyAttributeDef KX_SceneActuator::Attributes[] = { + KX_PYATTRIBUTE_STRING_RW("scene",0,32,true,KX_SceneActuator,m_nextSceneName), + KX_PYATTRIBUTE_RW_FUNCTION("camera",KX_SceneActuator,pyattr_get_camera,pyattr_set_camera), { NULL } //Sentinel }; PyObject* KX_SceneActuator::_getattr(const char *attr) { + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_IActuator); } +int KX_SceneActuator::_setattr(const char *attr, PyObject *value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_IActuator::_setattr(attr, value); +} + +PyObject* KX_SceneActuator::pyattr_get_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_SceneActuator* actuator = static_cast(self); + if (!actuator->m_camera) + Py_RETURN_NONE; + actuator->m_camera->AddRef(); + return actuator->m_camera; +} + +int KX_SceneActuator::pyattr_set_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_SceneActuator* actuator = static_cast(self); + KX_Camera *camOb; + + if (PyObject_TypeCheck(value, &KX_Camera::Type)) + { + camOb = static_cast(value); + if (actuator->m_camera) + actuator->m_camera->UnregisterActuator(actuator); + actuator->m_camera = camOb; + if (actuator->m_camera) + actuator->m_camera->RegisterActuator(actuator); + return 0; + } + + if (PyString_Check(value)) + { + char *camName = PyString_AsString(value); + + camOb = actuator->FindCamera(camName); + if (camOb) + { + if (actuator->m_camera) + actuator->m_camera->UnregisterActuator(actuator); + actuator->m_camera = camOb; + actuator->m_camera->RegisterActuator(actuator); + return 0; + } + PyErr_SetString(PyExc_TypeError, "not a valid camera name"); + return 1; + } + PyErr_SetString(PyExc_TypeError, "expected a string or a camera object reference"); + return 1; +} /* 2. setUseRestart--------------------------------------------------------- */ @@ -288,6 +347,7 @@ PyObject* KX_SceneActuator::PySetUseRestart(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setUseRestart()", "(no replacement)"); int boolArg; if (!PyArg_ParseTuple(args, "i", &boolArg)) @@ -310,6 +370,7 @@ PyObject* KX_SceneActuator::PyGetUseRestart(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getUseRestart()", "(no replacement)"); return PyInt_FromLong(!(m_restart == 0)); } @@ -324,6 +385,7 @@ PyObject* KX_SceneActuator::PySetScene(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setScene()", "the scene property"); /* one argument: a scene, ignore the rest */ char *scene_name; @@ -348,6 +410,7 @@ PyObject* KX_SceneActuator::PyGetScene(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getScene()", "the scene property"); return PyString_FromString(m_nextSceneName); } @@ -362,6 +425,7 @@ PyObject* KX_SceneActuator::PySetCamera(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setCamera()", "the camera property"); PyObject *cam; if (PyArg_ParseTuple(args, "O!", &KX_Camera::Type, &cam)) { @@ -403,6 +467,7 @@ PyObject* KX_SceneActuator::PyGetCamera(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getCamera()", "the camera property"); return PyString_FromString(m_camera->GetName()); } /* eof */ diff --git a/source/gameengine/Ketsji/KX_SceneActuator.h b/source/gameengine/Ketsji/KX_SceneActuator.h index af11af955bf..83b0d63bcd2 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.h +++ b/source/gameengine/Ketsji/KX_SceneActuator.h @@ -93,6 +93,7 @@ class KX_SceneActuator : public SCA_IActuator /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); /* 1. set */ /* Removed */ @@ -110,6 +111,9 @@ class KX_SceneActuator : public SCA_IActuator /* 7. getCamera: */ KX_PYMETHOD_DOC(KX_SceneActuator,GetCamera); + static PyObject* pyattr_get_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + }; /* end of class KXSceneActuator */ #endif diff --git a/source/gameengine/PyDoc/KX_SCA_AddObjectActuator.py b/source/gameengine/PyDoc/KX_SCA_AddObjectActuator.py index 56068fa641a..974ef718ccf 100644 --- a/source/gameengine/PyDoc/KX_SCA_AddObjectActuator.py +++ b/source/gameengine/PyDoc/KX_SCA_AddObjectActuator.py @@ -9,6 +9,12 @@ class KX_SCA_AddObjectActuator(SCA_IActuator): @type object: KX_GameObject or None @ivar objectLastCreated: the last added object from this actuator (read only). @type objectLastCreated: KX_GameObject or None + @ivar time: the lifetime of added objects, in frames. + @type time: integer + @ivar linearVelocity: the initial linear velocity of added objects. + @type linearVelocity: list [vx, vy, vz] + @ivar angularVelocity: the initial angular velocity of added objects. + @type angularVelocity: list [vx, vy, vz] @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. @@ -19,6 +25,7 @@ class KX_SCA_AddObjectActuator(SCA_IActuator): """ def setObject(object): """ + DEPRECATED: use the object property Sets the game object to add. A copy of the object will be added to the scene when the actuator is activated. @@ -31,6 +38,7 @@ class KX_SCA_AddObjectActuator(SCA_IActuator): """ def getObject(name_only = 0): """ + DEPRECATED: use the object property Returns the name of the game object to be added. Returns None if no game object has been assigned to be added. @@ -40,6 +48,7 @@ class KX_SCA_AddObjectActuator(SCA_IActuator): """ def setTime(time): """ + DEPRECATED: use the time property Sets the lifetime of added objects, in frames. If time == 0, the object will last forever. @@ -49,12 +58,14 @@ class KX_SCA_AddObjectActuator(SCA_IActuator): """ def getTime(): """ + DEPRECATED: use the time property Returns the lifetime of the added object, in frames. @rtype: integer """ def setLinearVelocity(vx, vy, vz): """ + DEPRECATED: use the linearVelocity property Sets the initial linear velocity of added objects. @type vx: float @@ -66,12 +77,14 @@ class KX_SCA_AddObjectActuator(SCA_IActuator): """ def getLinearVelocity(): """ + DEPRECATED: use the linearVelocity property Returns the initial linear velocity of added objects. @rtype: list [vx, vy, vz] """ def setAngularVelocity(vx, vy, vz): """ + DEPRECATED: use the angularVelocity property Sets the initial angular velocity of added objects. @type vx: float @@ -83,12 +96,14 @@ class KX_SCA_AddObjectActuator(SCA_IActuator): """ def getAngularVelocity(): """ + DEPRECATED: use the angularVelocity property Returns the initial angular velocity of added objects. @rtype: list [vx, vy, vz] """ def getLastCreatedObject(): """ + DEPRECATED: use the objectLastCreated property Returns the last object created by this actuator. @rtype: L{KX_GameObject} diff --git a/source/gameengine/PyDoc/KX_SceneActuator.py b/source/gameengine/PyDoc/KX_SceneActuator.py index cfb40ae072f..c8912783ab7 100644 --- a/source/gameengine/PyDoc/KX_SceneActuator.py +++ b/source/gameengine/PyDoc/KX_SceneActuator.py @@ -12,21 +12,32 @@ class KX_SceneActuator(SCA_IActuator): This will generate a warning in the console: C{ERROR: GameObject I{OBName} has a SceneActuator I{ActuatorName} (SetScene) without scene} + + Properties: + + @ivar scene: the name of the scene to change to/overlay/underlay/remove/suspend/resume + @type scene: string. + @ivar camera: the camera to change to. + When setting the attribute, you can use either a L{KX_Camera} or the name of the camera. + @type camera: L{KX_Camera} on read, string or L{KX_Camera} on write """ def setUseRestart(flag): """ + DEPRECATED Set flag to True to restart the scene. @type flag: boolean """ def setScene(scene): """ + DEPRECATED: use the scene property instead Sets the name of the scene to change to/overlay/underlay/remove/suspend/resume. @type scene: string """ def setCamera(camera): """ + DEPRECATED: use the camera property instead Sets the camera to change to. Camera can be either a L{KX_Camera} or the name of the camera. @@ -35,12 +46,14 @@ class KX_SceneActuator(SCA_IActuator): """ def getUseRestart(): """ + DEPRECATED Returns True if the scene will be restarted. @rtype: boolean """ def getScene(): """ + DEPRECATED: use the scene property instead Returns the name of the scene to change to/overlay/underlay/remove/suspend/resume. Returns an empty string ("") if no scene has been set. @@ -49,6 +62,7 @@ class KX_SceneActuator(SCA_IActuator): """ def getCamera(): """ + DEPRECATED: use the camera property instead Returns the name of the camera to change to. @rtype: string -- cgit v1.2.3 From afec4049626690e91e75dc88f3b9097a21f9c168 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Fri, 27 Mar 2009 22:11:30 +0000 Subject: BGE API Cleanup: GameActuator (patch from Andre) --- source/gameengine/Ketsji/KX_GameActuator.cpp | 35 +++++++++++++++++++++------- source/gameengine/Ketsji/KX_GameActuator.h | 4 ++++ source/gameengine/PyDoc/KX_GameActuator.py | 7 ++++++ 3 files changed, 37 insertions(+), 9 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp index 3c0695b5952..6799ac7269c 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.cpp +++ b/source/gameengine/Ketsji/KX_GameActuator.cpp @@ -241,21 +241,44 @@ PyParentObject KX_GameActuator::Parents[] = PyMethodDef KX_GameActuator::Methods[] = { + // Deprecated -----> {"getFile", (PyCFunction) KX_GameActuator::sPyGetFile, METH_VARARGS, (PY_METHODCHAR)GetFile_doc}, {"setFile", (PyCFunction) KX_GameActuator::sPySetFile, METH_VARARGS, (PY_METHODCHAR)SetFile_doc}, + // <----- {NULL,NULL} //Sentinel }; PyAttributeDef KX_GameActuator::Attributes[] = { + KX_PYATTRIBUTE_STRING_RW("file",0,100,false,KX_GameActuator,m_filename), { NULL } //Sentinel }; +PyObject* +KX_GameActuator::_getattr(const char *attr) +{ + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + _getattr_up(SCA_IActuator); +} + +int KX_GameActuator::_setattr(const char *attr, PyObject *value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_IActuator::_setattr(attr, value); +} + + +// Deprecated -----> /* getFile */ const char KX_GameActuator::GetFile_doc[] = "getFile()\n" "get the name of the file to start.\n"; PyObject* KX_GameActuator::PyGetFile(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getFile()", "the file property"); return PyString_FromString(m_filename); } @@ -266,6 +289,8 @@ const char KX_GameActuator::SetFile_doc[] = PyObject* KX_GameActuator::PySetFile(PyObject* self, PyObject* args, PyObject* kwds) { char* new_file; + + ShowDeprecationWarning("setFile()", "the file property"); if (!PyArg_ParseTuple(args, "s", &new_file)) { @@ -277,12 +302,4 @@ PyObject* KX_GameActuator::PySetFile(PyObject* self, PyObject* args, PyObject* k Py_RETURN_NONE; } - - - -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 856fa0c24e9..ad638254c31 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.h +++ b/source/gameengine/Ketsji/KX_GameActuator.h @@ -78,8 +78,12 @@ protected: /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); + + // Deprecated functions -----> KX_PYMETHOD_DOC(KX_GameActuator,GetFile); KX_PYMETHOD_DOC(KX_GameActuator,SetFile); + // <----- }; /* end of class KX_GameActuator */ diff --git a/source/gameengine/PyDoc/KX_GameActuator.py b/source/gameengine/PyDoc/KX_GameActuator.py index b916b3b5617..fc5bd6005fc 100644 --- a/source/gameengine/PyDoc/KX_GameActuator.py +++ b/source/gameengine/PyDoc/KX_GameActuator.py @@ -5,15 +5,22 @@ from SCA_IActuator import * class KX_GameActuator(SCA_IActuator): """ The game actuator loads a new .blend file, restarts the current .blend file or quits the game. + + Properties: + + @ivar file: the new .blend file to load + @type file: string. """ def getFile(): """ + DEPRECATED: use the file property Returns the filename of the new .blend file to load. @rtype: string """ def setFile(filename): """ + DEPRECATED: use the file property Sets the new .blend file to load. @param filename: The file name this actuator will load. -- cgit v1.2.3 From fdc6df925390ec5e2814609e968a7c95155f7139 Mon Sep 17 00:00:00 2001 From: Andrea Weikert Date: Sat, 28 Mar 2009 11:09:53 +0000 Subject: game engine compile fix for MSVC, game engine team might want to check. --- source/gameengine/Converter/KX_ConvertActuators.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index 3a6122e6608..f7635856ad9 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -585,15 +585,6 @@ void BL_ConvertActuators(char* maggiename, originalval = converter->FindGameObject(editobact->ob); } } - MT_Vector3 linvelvec ( - KX_BLENDERTRUNC(editobact->linVelocity[0]), - KX_BLENDERTRUNC(editobact->linVelocity[1]), - KX_BLENDERTRUNC(editobact->linVelocity[2])); - - MT_Vector3 angvelvec ( - KX_BLENDERTRUNC(editobact->angVelocity[0]), - KX_BLENDERTRUNC(editobact->angVelocity[1]), - KX_BLENDERTRUNC(editobact->angVelocity[2])); KX_SCA_AddObjectActuator* tmpaddact = new KX_SCA_AddObjectActuator( @@ -601,9 +592,9 @@ void BL_ConvertActuators(char* maggiename, originalval, editobact->time, scene, - linvelvec.getValue(), + editobact->linVelocity, (editobact->localflag & ACT_EDOB_LOCAL_LINV)!=0, - angvelvec.getValue(), + editobact->angVelocity, (editobact->localflag & ACT_EDOB_LOCAL_ANGV)!=0 ); -- cgit v1.2.3 From d57811ada14ad3f9833e77b2cff0d624c7e1ff89 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sun, 29 Mar 2009 15:17:55 +0000 Subject: BGE API cleanup: CDActuator, ParentActuator, VisibilityActuator done. Thanks to Andre. --- source/gameengine/Ketsji/KX_CDActuator.cpp | 91 ++++++++++++++++++---- source/gameengine/Ketsji/KX_CDActuator.h | 17 +++- source/gameengine/Ketsji/KX_ParentActuator.cpp | 65 ++++++++++------ source/gameengine/Ketsji/KX_ParentActuator.h | 8 +- source/gameengine/Ketsji/KX_VisibilityActuator.cpp | 23 +++++- source/gameengine/Ketsji/KX_VisibilityActuator.h | 6 +- source/gameengine/PyDoc/KX_CDActuator.py | 21 +++++ source/gameengine/PyDoc/KX_ParentActuator.py | 5 +- source/gameengine/PyDoc/KX_VisibilityActuator.py | 7 +- 9 files changed, 193 insertions(+), 50 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_CDActuator.cpp b/source/gameengine/Ketsji/KX_CDActuator.cpp index ef7883910fd..98f76dbee54 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.cpp +++ b/source/gameengine/Ketsji/KX_CDActuator.cpp @@ -98,7 +98,7 @@ bool KX_CDActuator::Update() SND_CDObject::Instance()->SetPlaymode(SND_CD_ALL); SND_CDObject::Instance()->SetTrack(1); SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); - result = true; + //result = true; break; } case KX_CDACT_PLAY_TRACK: @@ -106,7 +106,7 @@ bool KX_CDActuator::Update() SND_CDObject::Instance()->SetPlaymode(SND_CD_TRACK); SND_CDObject::Instance()->SetTrack(m_track); SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); - result = true; + //result = true; break; } case KX_CDACT_LOOP_TRACK: @@ -114,7 +114,7 @@ bool KX_CDActuator::Update() SND_CDObject::Instance()->SetPlaymode(SND_CD_ALL); SND_CDObject::Instance()->SetTrack(m_track); SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); - result = true; + //result = true; break; } case KX_CDACT_STOP: @@ -125,19 +125,19 @@ bool KX_CDActuator::Update() case KX_CDACT_PAUSE: { SND_CDObject::Instance()->SetPlaystate(SND_MUST_PAUSE); - result = true; + //result = true; break; } case KX_CDACT_RESUME: { SND_CDObject::Instance()->SetPlaystate(SND_MUST_RESUME); - result = true; + //result = true; break; } case KX_CDACT_VOLUME: { SND_CDObject::Instance()->SetGain(m_gain); - result = true; + //result = true; break; } default: @@ -189,53 +189,116 @@ PyParentObject KX_CDActuator::Parents[] = { PyMethodDef KX_CDActuator::Methods[] = { - {"startCD",(PyCFunction) KX_CDActuator::sPyStartCD,METH_VARARGS,NULL}, - {"pauseCD",(PyCFunction) KX_CDActuator::sPyPauseCD,METH_VARARGS,NULL}, - {"stopCD",(PyCFunction) KX_CDActuator::sPyStopCD,METH_VARARGS,NULL}, + // Deprecated -----> {"setGain",(PyCFunction) KX_CDActuator::sPySetGain,METH_VARARGS,NULL}, {"getGain",(PyCFunction) KX_CDActuator::sPyGetGain,METH_VARARGS,NULL}, + // <----- + KX_PYMETHODTABLE_NOARGS(KX_CDActuator, startCD), + KX_PYMETHODTABLE_NOARGS(KX_CDActuator, pauseCD), + KX_PYMETHODTABLE_NOARGS(KX_CDActuator, resumeCD), + KX_PYMETHODTABLE_NOARGS(KX_CDActuator, stopCD), + KX_PYMETHODTABLE_NOARGS(KX_CDActuator, playAll), + KX_PYMETHODTABLE_O(KX_CDActuator, playTrack), {NULL,NULL,NULL,NULL} //Sentinel }; PyAttributeDef KX_CDActuator::Attributes[] = { + KX_PYATTRIBUTE_FLOAT_RW_CHECK("volume", 0.0, 1.0, KX_CDActuator, m_gain,pyattr_setGain), + KX_PYATTRIBUTE_INT_RW("track", 1, 99, false, KX_CDActuator, m_track), { NULL } //Sentinel }; +int KX_CDActuator::pyattr_setGain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_CDActuator* act = static_cast(self); + SND_CDObject::Instance()->SetGain(act->m_gain); + return 0; +} + PyObject* KX_CDActuator::_getattr(const char *attr) { + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_IActuator); } +int KX_CDActuator::_setattr(const char *attr, PyObject *value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_IActuator::_setattr(attr, value); +} -PyObject* KX_CDActuator::PyStartCD(PyObject* self, PyObject* args, PyObject* kwds) +KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, startCD, +"startCD()\n" +"\tStarts the CD playing.\n") { SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); Py_RETURN_NONE; } - -PyObject* KX_CDActuator::PyPauseCD(PyObject* self, PyObject* args, PyObject* kwds) +KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, pauseCD, +"pauseCD()\n" +"\tPauses the CD playing.\n") { SND_CDObject::Instance()->SetPlaystate(SND_MUST_PAUSE); Py_RETURN_NONE; } +KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, resumeCD, +"resumeCD()\n" +"\tResumes the CD playing.\n") +{ + SND_CDObject::Instance()->SetPlaystate(SND_MUST_RESUME); + Py_RETURN_NONE; +} + -PyObject* KX_CDActuator::PyStopCD(PyObject* self, PyObject* args, PyObject* kwds) +KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, stopCD, +"stopCD()\n" +"\tStops the CD playing.\n") { SND_CDObject::Instance()->SetPlaystate(SND_MUST_STOP); Py_RETURN_NONE; } +KX_PYMETHODDEF_DOC_O(KX_CDActuator, playTrack, +"playTrack(trackNumber)\n" +"\tPlays the track selected.\n") +{ + if (PyInt_Check(value)) { + int track = PyInt_AsLong(value); + SND_CDObject::Instance()->SetPlaymode(SND_CD_TRACK); + SND_CDObject::Instance()->SetTrack(track); + SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); + } + Py_RETURN_NONE; +} + + + +KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, playAll, +"playAll()\n" +"\tPlays the CD from the beginning.\n") +{ + SND_CDObject::Instance()->SetPlaymode(SND_CD_ALL); + SND_CDObject::Instance()->SetTrack(1); + SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); + Py_RETURN_NONE; +} +// Deprecated -----> PyObject* KX_CDActuator::PySetGain(PyObject* self, PyObject* args, PyObject* kwds) { float gain = 1.0; + ShowDeprecationWarning("setGain()", "the volume property"); if (!PyArg_ParseTuple(args, "f", &gain)) return NULL; @@ -249,7 +312,9 @@ PyObject* KX_CDActuator::PySetGain(PyObject* self, PyObject* args, PyObject* kwd PyObject* KX_CDActuator::PyGetGain(PyObject* self, PyObject* args, PyObject* kwds) { float gain = SND_CDObject::Instance()->GetGain(); + ShowDeprecationWarning("getGain()", "the volume property"); PyObject* result = PyFloat_FromDouble(gain); return result; } +// <----- diff --git a/source/gameengine/Ketsji/KX_CDActuator.h b/source/gameengine/Ketsji/KX_CDActuator.h index 393c49083f9..08ca6a82db3 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.h +++ b/source/gameengine/Ketsji/KX_CDActuator.h @@ -82,12 +82,23 @@ public: /* -------------------------------------------------------------------- */ virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); - KX_PYMETHOD(KX_CDActuator,StartCD); - KX_PYMETHOD(KX_CDActuator,PauseCD); - KX_PYMETHOD(KX_CDActuator,StopCD); + // Deprecated -----> KX_PYMETHOD(KX_CDActuator,SetGain); KX_PYMETHOD(KX_CDActuator,GetGain); + // <----- + + KX_PYMETHOD_DOC_NOARGS(KX_CDActuator, startCD); + KX_PYMETHOD_DOC_NOARGS(KX_CDActuator, pauseCD); + KX_PYMETHOD_DOC_NOARGS(KX_CDActuator, resumeCD); + KX_PYMETHOD_DOC_NOARGS(KX_CDActuator, stopCD); + KX_PYMETHOD_DOC_NOARGS(KX_CDActuator, playAll); + KX_PYMETHOD_DOC_O(KX_CDActuator, playTrack); + + static int pyattr_setGain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + + }; #endif //__KX_CDACTUATOR diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index 84d7ccb9c05..fc5d679f200 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -166,48 +166,64 @@ 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}, + // Deprecated -----> + {"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 }; PyAttributeDef KX_ParentActuator::Attributes[] = { + KX_PYATTRIBUTE_RW_FUNCTION("object", KX_ParentActuator, pyattr_get_object, pyattr_set_object), { NULL } //Sentinel }; -PyObject* KX_ParentActuator::_getattr(const char *attr) { - - if (!strcmp(attr, "object")) { - if (!m_ob) Py_RETURN_NONE; - else return m_ob->AddRef(); - } - - _getattr_up(SCA_IActuator); +PyObject* KX_ParentActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_ParentActuator* actuator = static_cast(self); + if (!actuator->m_ob) + Py_RETURN_NONE; + else + return actuator->m_ob->AddRef(); } -int KX_ParentActuator::_setattr(const char *attr, PyObject* value) { - - if (!strcmp(attr, "object")) { - KX_GameObject *gameobj; +int KX_ParentActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_ParentActuator* actuator = static_cast(self); + KX_GameObject *gameobj; - if (!ConvertPythonToGameObject(value, &gameobj, true)) - return 1; // ConvertPythonToGameObject sets the error + if (!ConvertPythonToGameObject(value, &gameobj, true)) + return 1; // ConvertPythonToGameObject sets the error - if (m_ob != NULL) - m_ob->UnregisterActuator(this); + if (actuator->m_ob != NULL) + actuator->m_ob->UnregisterActuator(actuator); - m_ob = (SCA_IObject*)gameobj; + actuator->m_ob = (SCA_IObject*) gameobj; - if (m_ob) - m_ob->RegisterActuator(this); + if (actuator->m_ob) + actuator->m_ob->RegisterActuator(actuator); - return 0; - } + return 0; +} + + +PyObject* KX_ParentActuator::_getattr(const char *attr) { + + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + _getattr_up(SCA_IActuator); +} + +int KX_ParentActuator::_setattr(const char *attr, PyObject* value) { + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; return SCA_IActuator::_setattr(attr, value); } +/* Deprecated -----> */ /* 1. setObject */ const char KX_ParentActuator::SetObject_doc[] = "setObject(object)\n" @@ -255,5 +271,6 @@ PyObject* KX_ParentActuator::PyGetObject(PyObject* self, PyObject* args) else return m_ob->AddRef(); } +/* <----- */ /* eof */ diff --git a/source/gameengine/Ketsji/KX_ParentActuator.h b/source/gameengine/Ketsji/KX_ParentActuator.h index c974001c0d0..c647e6cc8a9 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.h +++ b/source/gameengine/Ketsji/KX_ParentActuator.h @@ -79,10 +79,14 @@ class KX_ParentActuator : public SCA_IActuator virtual PyObject* _getattr(const char *attr); virtual int _setattr(const char *attr, PyObject* value); - /* 1. setObject */ + /* These are used to get and set m_ob */ + static PyObject* pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + + // Deprecated -----> KX_PYMETHOD_DOC_O(KX_ParentActuator,SetObject); - /* 2. getObject */ KX_PYMETHOD_DOC_VARARGS(KX_ParentActuator,GetObject); + // <----- }; /* end of class KX_ParentActuator : public SCA_PropertyActuator */ diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp index 0ec280080bd..6d3c4e79280 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp @@ -121,20 +121,34 @@ KX_VisibilityActuator::Parents[] = { PyMethodDef KX_VisibilityActuator::Methods[] = { - {"set", (PyCFunction) KX_VisibilityActuator::sPySetVisible, - METH_VARARGS, (PY_METHODCHAR)SetVisible_doc}, + // Deprecated -----> + {"set", (PyCFunction) KX_VisibilityActuator::sPySetVisible, METH_VARARGS, + (PY_METHODCHAR) SetVisible_doc}, + // <----- {NULL,NULL} //Sentinel }; PyAttributeDef KX_VisibilityActuator::Attributes[] = { + KX_PYATTRIBUTE_BOOL_RW("visibility", KX_VisibilityActuator, m_visible), + KX_PYATTRIBUTE_BOOL_RW("recursion", KX_VisibilityActuator, m_recursive), { NULL } //Sentinel }; -PyObject* KX_VisibilityActuator::_getattr(const char *attr) +PyObject* KX_VisibilityActuator::_getattr(const char *attr) { + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_IActuator); -}; +} +int KX_VisibilityActuator::_setattr(const char *attr, PyObject *value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_IActuator::_setattr(attr, value); +} /* set visibility ---------------------------------------------------------- */ @@ -149,6 +163,7 @@ KX_VisibilityActuator::PySetVisible(PyObject* self, PyObject* args, PyObject* kwds) { int vis; + ShowDeprecationWarning("SetVisible()", "the visible property"); if(!PyArg_ParseTuple(args, "i", &vis)) { return NULL; diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.h b/source/gameengine/Ketsji/KX_VisibilityActuator.h index 323280de8cb..2e2a5957777 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.h +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.h @@ -68,8 +68,12 @@ class KX_VisibilityActuator : public SCA_IActuator /* --------------------------------------------------------------------- */ virtual PyObject* _getattr(const char *attr); - //KX_PYMETHOD_DOC + virtual int _setattr(const char *attr, PyObject *value); + + // Deprecated -----> KX_PYMETHOD_DOC(KX_VisibilityActuator,SetVisible); + // <----- + }; diff --git a/source/gameengine/PyDoc/KX_CDActuator.py b/source/gameengine/PyDoc/KX_CDActuator.py index 2c202476584..ffc8ddefa43 100644 --- a/source/gameengine/PyDoc/KX_CDActuator.py +++ b/source/gameengine/PyDoc/KX_CDActuator.py @@ -3,6 +3,13 @@ from SCA_IActuator import * class KX_CDActuator(SCA_IActuator): + """ + CD Controller actuator. + @ivar volume: controls the volume to set the CD to. 0.0 = silent, 1.0 = max volume. + @type volume: float + @ivar track: the track selected to be played + @type track: integer + """ def startCD(): """ Starts the CD playing. @@ -15,8 +22,21 @@ class KX_CDActuator(SCA_IActuator): """ Pauses the CD. """ + def resumeCD(): + """ + Resumes the CD after a pause. + """ + def playAll(): + """ + Plays the CD from the beginning. + """ + def playTrack(trackNumber): + """ + Plays the track selected. + """ def setGain(gain): """ + DEPRECATED: Use the volume property. Sets the gain (volume) of the CD. @type gain: float @@ -24,6 +44,7 @@ class KX_CDActuator(SCA_IActuator): """ def getGain(): """ + DEPRECATED: Use the volume property. Gets the current gain (volume) of the CD. @rtype: float diff --git a/source/gameengine/PyDoc/KX_ParentActuator.py b/source/gameengine/PyDoc/KX_ParentActuator.py index 7b5625ec82d..76252e5cfad 100644 --- a/source/gameengine/PyDoc/KX_ParentActuator.py +++ b/source/gameengine/PyDoc/KX_ParentActuator.py @@ -4,13 +4,13 @@ from SCA_IActuator import * class KX_ParentActuator(SCA_IActuator): """ - The parent actuator can set or remove an objects parent object. - + 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): """ + DEPRECATED: Use the object property. Sets the object to set as parent. Object can be either a L{KX_GameObject} or the name of the object. @@ -19,6 +19,7 @@ class KX_ParentActuator(SCA_IActuator): """ def getObject(name_only = 1): """ + DEPRECATED: Use the object property. Returns the name of the object to change to. @type name_only: bool @param name_only: optional argument, when 0 return a KX_GameObject diff --git a/source/gameengine/PyDoc/KX_VisibilityActuator.py b/source/gameengine/PyDoc/KX_VisibilityActuator.py index 22499f25d81..17d22fa5f83 100644 --- a/source/gameengine/PyDoc/KX_VisibilityActuator.py +++ b/source/gameengine/PyDoc/KX_VisibilityActuator.py @@ -5,13 +5,18 @@ from SCA_IActuator import * class KX_VisibilityActuator(SCA_IActuator): """ Visibility Actuator. + @ivar visibility: whether the actuator makes its parent object visible or invisible + @type visibility: boolean + @ivar recursion: whether the visibility/invisibility should be propagated to all children of the object + @type recursion: boolean """ def set(visible): """ + DEPRECATED: Use the visibility property instead. Sets whether the actuator makes its parent object visible or invisible. @param visible: - True: Makes its parent visible. - False: Makes its parent invisible. """ - \ No newline at end of file + -- cgit v1.2.3 From 30fa7a7286a2d4b5f8abedc2ce43602fb229b25c Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Sun, 29 Mar 2009 18:34:35 +0000 Subject: Only apply advanced setting of angular/linear factor to rigid bodies (with angular rotation). The setting broke 'dynamic'-only objects. --- .../gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 9b2d7403974..8002da6b8d4 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -1106,16 +1106,19 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, 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 (objprop->m_angular_rigidbody) + { + 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) { -- cgit v1.2.3 From b182778e7155abe09bd2101b851fb1178c9babb8 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Sun, 29 Mar 2009 19:54:05 +0000 Subject: Applied patch #18446, to do versions on damping Re-enable vertex welding, only for soft bodies. They require it. Future versions could expose such vertexWeldingThreshold. --- .../gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp | 5 ++-- .../Physics/Bullet/CcdPhysicsController.cpp | 33 ++++++++++++++++------ .../Physics/Bullet/CcdPhysicsController.h | 12 ++++---- 3 files changed, 33 insertions(+), 17 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 8002da6b8d4..03149859f4d 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -882,10 +882,9 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, shapeInfo->SetMesh(meshobj, false,false); } - // Note! since 2.48a bullet mesh conversion has been sped up not to remove doubles - // if softbody needs this there should be some post processing filter for softbody meshes. + // Soft bodies require welding. Only avoid remove doubles for non-soft bodies! if (objprop->m_softbody) - shapeInfo->setVertexWeldingThreshold(0.01f); //todo: expose this to the UI + shapeInfo->setVertexWeldingThreshold1(0.01f); //todo: expose this to the UI bm = shapeInfo->CreateBulletShape(); //no moving concave meshes, so don't bother calculating inertia diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index 35602b4095a..cc6be9a7ae3 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -1569,14 +1569,31 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape() if (!m_unscaledShape) { - btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray( - m_polygonIndexArray.size(), - &m_triFaceArray[0], - 3*sizeof(int), - m_vertexArray.size(), - (btScalar*) &m_vertexArray[0].x(), - sizeof(btVector3) - ); + btTriangleIndexVertexArray* indexVertexArrays = 0; + + ///enable welding, only for the objects that need it (such as soft bodies) + if (0.f != m_weldingThreshold1) + { + btTriangleMesh* collisionMeshData = new btTriangleMesh(true,false); + collisionMeshData->m_weldingThreshold = m_weldingThreshold1; + 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],removeDuplicateVertices); + } + indexVertexArrays = collisionMeshData; + + } else + { + indexVertexArrays = new btTriangleIndexVertexArray( + m_polygonIndexArray.size(), + &m_triFaceArray[0], + 3*sizeof(int), + m_vertexArray.size(), + (btScalar*) &m_vertexArray[0].x(), + sizeof(btVector3)); + } // this shape will be shared and not deleted until shapeInfo is deleted m_unscaledShape = new btBvhTriangleMeshShape( indexVertexArrays, true ); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index 67dd82db5cc..510454a7b63 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -72,7 +72,7 @@ public: m_meshObject(NULL), m_unscaledShape(NULL), m_useGimpact(false), - m_weldingThreshold(0.f), + m_weldingThreshold1(0.f), m_shapeProxy(NULL) { m_childTrans.setIdentity(); @@ -171,13 +171,13 @@ public: std::vector m_triFaceArray; // Contains an array of triplets of face indicies // quads turn into 2 tris - void setVertexWeldingThreshold(float threshold) + void setVertexWeldingThreshold1(float threshold) { - m_weldingThreshold = threshold; + m_weldingThreshold1 = threshold; } - float getVertexWeldingThreshold() const + float getVertexWeldingThreshold1() const { - return m_weldingThreshold; + return m_weldingThreshold1; } protected: static std::map m_meshShapeMap; @@ -188,7 +188,7 @@ protected: // the actual shape is of type btScaledBvhTriangleMeshShape 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. // Not used at the moment, maybe remove? + float m_weldingThreshold1; //welding closeby vertices together can improve softbody stability etc. CcdShapeConstructionInfo* m_shapeProxy; // only used for PHY_SHAPE_PROXY, pointer to actual shape info }; -- cgit v1.2.3 From c1b41b20b0e938152f3e100c7a56cfd5fc49cabf Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 30 Mar 2009 00:40:19 +0000 Subject: r19455 to Re-enable vertex welding for soft-bodies failed even on simple cases like a cube with scrambled mesh data. Please test before committing. m_vertexArray has no doubles now and is not aligned to 3, using m_triFaceArray to get the verts for each face. --- source/gameengine/Physics/Bullet/CcdPhysicsController.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index cc6be9a7ae3..bb2f53a1988 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -1577,10 +1577,14 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape() btTriangleMesh* collisionMeshData = new btTriangleMesh(true,false); collisionMeshData->m_weldingThreshold = m_weldingThreshold1; 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],removeDuplicateVertices); + // m_vertexArray not in multiple of 3 anymore, use m_triFaceArray + for(int i=0; iaddTriangle( + m_vertexArray[m_triFaceArray[i]], + m_vertexArray[m_triFaceArray[i+1]], + m_vertexArray[m_triFaceArray[i+2]], + removeDuplicateVertices + ); } indexVertexArrays = collisionMeshData; -- cgit v1.2.3 From 8518f6e6603ed93d126771e1b372021ae0b4ff98 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Tue, 31 Mar 2009 19:02:01 +0000 Subject: BGE API cleanup, patch from Moguri: RaySensor, NetworkMessageActuator, NetworkMessageSensor. --- .../Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp | 28 ++++++- .../Ketsji/KXNetwork/KX_NetworkMessageActuator.h | 5 +- .../Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp | 45 ++++++++++- .../Ketsji/KXNetwork/KX_NetworkMessageSensor.h | 6 ++ source/gameengine/Ketsji/KX_PythonInit.cpp | 9 +++ source/gameengine/Ketsji/KX_RaySensor.cpp | 86 ++++++++++++++++++++-- source/gameengine/Ketsji/KX_RaySensor.h | 28 +++++-- source/gameengine/PyDoc/GameLogic.py | 8 ++ .../gameengine/PyDoc/KX_NetworkMessageActuator.py | 13 ++++ source/gameengine/PyDoc/KX_NetworkMessageSensor.py | 17 +++++ source/gameengine/PyDoc/KX_RaySensor.py | 25 +++++++ 11 files changed, 252 insertions(+), 18 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp index 4e5f27df2da..fa4fdaee972 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp @@ -47,7 +47,7 @@ KX_NetworkMessageActuator::KX_NetworkMessageActuator( m_networkscene(networkscene), m_toPropName(toPropName), m_subject(subject), - m_bodyType(bodyType), + m_bPropBody(bodyType), m_body(body) { } @@ -69,7 +69,7 @@ bool KX_NetworkMessageActuator::Update() } //printf("messageactuator true event\n"); - if (m_bodyType == 1) // ACT_MESG_PROP in DNA_actuator_types.h + if (m_bPropBody) // ACT_MESG_PROP in DNA_actuator_types.h { m_networkscene->SendMessage( m_toPropName, @@ -132,6 +132,7 @@ PyParentObject KX_NetworkMessageActuator::Parents[] = { }; PyMethodDef KX_NetworkMessageActuator::Methods[] = { + // Deprecated -----> {"setToPropName", (PyCFunction) KX_NetworkMessageActuator::sPySetToPropName, METH_VARARGS}, {"setSubject", (PyCFunction) @@ -140,23 +141,40 @@ PyMethodDef KX_NetworkMessageActuator::Methods[] = { KX_NetworkMessageActuator::sPySetBodyType, METH_VARARGS}, {"setBody", (PyCFunction) KX_NetworkMessageActuator::sPySetBody, METH_VARARGS}, + // <----- {NULL,NULL} // Sentinel }; PyAttributeDef KX_NetworkMessageActuator::Attributes[] = { + KX_PYATTRIBUTE_STRING_RW("propName", 0, 100, false, KX_NetworkMessageActuator, m_toPropName), + KX_PYATTRIBUTE_STRING_RW("subject", 0, 100, false, KX_NetworkMessageActuator, m_subject), + KX_PYATTRIBUTE_BOOL_RW("usePropBody", KX_NetworkMessageActuator, m_bPropBody), + KX_PYATTRIBUTE_STRING_RW("body", 0, 100, false, KX_NetworkMessageActuator, m_body), { NULL } //Sentinel }; PyObject* KX_NetworkMessageActuator::_getattr(const char *attr) { + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_IActuator); } +int KX_NetworkMessageActuator::_setattr(const char *attr, PyObject *value) { + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_IActuator::_setattr(attr, value); +} + +// Deprecated -----> // 1. SetToPropName PyObject* KX_NetworkMessageActuator::PySetToPropName( PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setToProp()", "the propName property"); char* ToPropName; if (PyArg_ParseTuple(args, "s", &ToPropName)) { @@ -175,6 +193,7 @@ PyObject* KX_NetworkMessageActuator::PySetSubject( PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setSubject()", "the subject property"); char* Subject; if (PyArg_ParseTuple(args, "s", &Subject)) { @@ -193,10 +212,11 @@ PyObject* KX_NetworkMessageActuator::PySetBodyType( PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setBodyType()", "the usePropBody property"); int BodyType; if (PyArg_ParseTuple(args, "i", &BodyType)) { - m_bodyType = BodyType; + m_bPropBody = (BodyType != 0); } else { return NULL; @@ -211,6 +231,7 @@ PyObject* KX_NetworkMessageActuator::PySetBody( PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setBody()", "the body property"); char* Body; if (PyArg_ParseTuple(args, "s", &Body)) { @@ -223,3 +244,4 @@ PyObject* KX_NetworkMessageActuator::PySetBody( Py_RETURN_NONE; } +// <----- Deprecated \ No newline at end of file diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h index 96b55ef839b..d9a7f787333 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h @@ -41,7 +41,7 @@ class KX_NetworkMessageActuator : public SCA_IActuator class NG_NetworkScene* m_networkscene; // needed for replication STR_String m_toPropName; STR_String m_subject; - int m_bodyType; + bool m_bPropBody; STR_String m_body; public: KX_NetworkMessageActuator( @@ -62,11 +62,14 @@ public: /* ------------------------------------------------------------ */ virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); + // Deprecated -----> KX_PYMETHOD(KX_NetworkMessageActuator, SetToPropName); KX_PYMETHOD(KX_NetworkMessageActuator, SetSubject); KX_PYMETHOD(KX_NetworkMessageActuator, SetBodyType); KX_PYMETHOD(KX_NetworkMessageActuator, SetBody); + // <----- }; diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp index ac89d8b0716..40ade460792 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp @@ -195,6 +195,7 @@ PyParentObject KX_NetworkMessageSensor::Parents[] = { }; PyMethodDef KX_NetworkMessageSensor::Methods[] = { + // Deprecated -----> {"setSubjectFilterText", (PyCFunction) KX_NetworkMessageSensor::sPySetSubjectFilterText, METH_O, (PY_METHODCHAR)SetSubjectFilterText_doc}, @@ -210,17 +211,53 @@ PyMethodDef KX_NetworkMessageSensor::Methods[] = { {"getSubjects", (PyCFunction) KX_NetworkMessageSensor::sPyGetSubjects, METH_NOARGS, (PY_METHODCHAR)GetSubjects_doc}, + // <----- {NULL,NULL} //Sentinel }; PyAttributeDef KX_NetworkMessageSensor::Attributes[] = { + KX_PYATTRIBUTE_STRING_RW("subject", 0, 100, false, KX_NetworkMessageSensor, m_subject), + KX_PYATTRIBUTE_INT_RO("frameMessageCount", KX_NetworkMessageSensor, m_frame_message_count), + KX_PYATTRIBUTE_RO_FUNCTION("bodies", KX_NetworkMessageSensor, pyattr_get_bodies), + KX_PYATTRIBUTE_RO_FUNCTION("subjects", KX_NetworkMessageSensor, pyattr_get_subjects), { NULL } //Sentinel }; PyObject* KX_NetworkMessageSensor::_getattr(const char *attr) { - _getattr_up(SCA_ISensor); // implicit return! + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + _getattr_up(SCA_ISensor); } +int KX_NetworkMessageSensor::_setattr(const char *attr, PyObject *value) { + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_ISensor::_setattr(attr, value); +} + +PyObject* KX_NetworkMessageSensor::pyattr_get_bodies(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_NetworkMessageSensor *self = static_cast(self_v); + if (self->m_BodyList) { + return ((PyObject*) self->m_BodyList->AddRef()); + } else { + return ((PyObject*) new CListValue()); + } +} + +PyObject* KX_NetworkMessageSensor::pyattr_get_subjects(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_NetworkMessageSensor *self = static_cast(self_v); + if (self->m_SubjectList) { + return ((PyObject*) self->m_SubjectList->AddRef()); + } else { + return ((PyObject*) new CListValue()); + } +} + +// Deprecated -----> // 1. Set the message subject that this sensor listens for const char KX_NetworkMessageSensor::SetSubjectFilterText_doc[] = "\tsetSubjectFilterText(value)\n" @@ -228,6 +265,7 @@ const char KX_NetworkMessageSensor::SetSubjectFilterText_doc[] = PyObject* KX_NetworkMessageSensor::PySetSubjectFilterText( PyObject* self, PyObject* value) { + ShowDeprecationWarning("setSubjectFilterText()", "subject"); char* Subject = PyString_AsString(value); if (Subject==NULL) { PyErr_SetString(PyExc_TypeError, "expected a string message"); @@ -245,6 +283,7 @@ const char KX_NetworkMessageSensor::GetFrameMessageCount_doc[] = PyObject* KX_NetworkMessageSensor::PyGetFrameMessageCount( PyObject* ) { + ShowDeprecationWarning("getFrameMessageCount()", "frameMessageCount"); return PyInt_FromLong(long(m_frame_message_count)); } @@ -255,6 +294,7 @@ const char KX_NetworkMessageSensor::GetBodies_doc[] = PyObject* KX_NetworkMessageSensor::PyGetBodies( PyObject* ) { + ShowDeprecationWarning("getBodies()", "bodies"); if (m_BodyList) { return ((PyObject*) m_BodyList->AddRef()); } else { @@ -269,6 +309,7 @@ const char KX_NetworkMessageSensor::GetSubject_doc[] = PyObject* KX_NetworkMessageSensor::PyGetSubject( PyObject* ) { + ShowDeprecationWarning("getSubject()", "subject"); return PyString_FromString(m_subject ? m_subject : ""); } @@ -279,9 +320,11 @@ const char KX_NetworkMessageSensor::GetSubjects_doc[] = PyObject* KX_NetworkMessageSensor::PyGetSubjects( PyObject* ) { + ShowDeprecationWarning("getSubjects()", "subjects"); if (m_SubjectList) { return ((PyObject*) m_SubjectList->AddRef()); } else { return ((PyObject*) new CListValue()); } } +// <----- Deprecated \ No newline at end of file diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h index 26adbc9945a..79e8bc910d1 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h @@ -73,13 +73,19 @@ public: /* ------------------------------------------------------------- */ virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); + // Deprecated -----> KX_PYMETHOD_DOC_O(KX_NetworkMessageSensor, SetSubjectFilterText); KX_PYMETHOD_DOC_NOARGS(KX_NetworkMessageSensor, GetFrameMessageCount); KX_PYMETHOD_DOC_NOARGS(KX_NetworkMessageSensor, GetBodies); KX_PYMETHOD_DOC_NOARGS(KX_NetworkMessageSensor, GetSubject); KX_PYMETHOD_DOC_NOARGS(KX_NetworkMessageSensor, GetSubjects); + // <----- + /* attributes */ + static PyObject* pyattr_get_bodies(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_subjects(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); }; diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index bc2111571ac..bf41f3a555f 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -48,6 +48,7 @@ #include "KX_KetsjiEngine.h" #include "KX_RadarSensor.h" +#include "KX_RaySensor.h" #include "SCA_IInputDevice.h" #include "SCA_PropertySensor.h" @@ -1070,6 +1071,14 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack 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); + /* Ray Sensor */ + KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_POS_X, KX_RaySensor::KX_RAY_AXIS_POS_X); + KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_POS_Y, KX_RaySensor::KX_RAY_AXIS_POS_Y); + KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_POS_Z, KX_RaySensor::KX_RAY_AXIS_POS_Z); + KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_X, KX_RaySensor::KX_RAY_AXIS_NEG_Y); + KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_Y, KX_RaySensor::KX_RAY_AXIS_NEG_X); + KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_Z, KX_RaySensor::KX_RAY_AXIS_NEG_Z); + // Check for errors if (PyErr_Occurred()) { diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index ce12b983147..253fe11fe05 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -136,8 +136,13 @@ bool KX_RaySensor::RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void { m_rayHit = true; m_hitObject = hitKXObj; - m_hitPosition = result->m_hitPoint; - m_hitNormal = result->m_hitNormal; + m_hitPosition[0] = result->m_hitPoint[0]; + m_hitPosition[1] = result->m_hitPoint[1]; + m_hitPosition[2] = result->m_hitPoint[2]; + + m_hitNormal[0] = result->m_hitNormal[0]; + m_hitNormal[1] = result->m_hitNormal[1]; + m_hitNormal[2] = result->m_hitNormal[2]; } // no multi-hit search yet @@ -180,8 +185,13 @@ bool KX_RaySensor::Evaluate(CValue* event) bool reset = m_reset && m_level; m_rayHit = false; m_hitObject = NULL; - m_hitPosition.setValue(0,0,0); - m_hitNormal.setValue(1,0,0); + m_hitPosition[0] = 0; + m_hitPosition[1] = 0; + m_hitPosition[2] = 0; + + m_hitNormal[0] = 1; + m_hitNormal[1] = 0; + m_hitNormal[2] = 0; KX_GameObject* obj = (KX_GameObject*)GetParent(); MT_Point3 frompoint = obj->NodeGetWorldPosition(); @@ -236,7 +246,9 @@ bool KX_RaySensor::Evaluate(CValue* event) } } todir.normalize(); - m_rayDirection = todir; + m_rayDirection[0] = todir[0]; + m_rayDirection[1] = todir[1]; + m_rayDirection[2] = todir[2]; MT_Point3 topoint = frompoint + (m_distance) * todir; PHY_IPhysicsEnvironment* pe = m_scene->GetPhysicsEnvironment(); @@ -336,22 +348,44 @@ PyParentObject KX_RaySensor::Parents[] = { }; PyMethodDef KX_RaySensor::Methods[] = { + // Deprecated -----> {"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 }; PyAttributeDef KX_RaySensor::Attributes[] = { + KX_PYATTRIBUTE_BOOL_RW("useMaterial", KX_RaySensor, m_bFindMaterial), + KX_PYATTRIBUTE_BOOL_RW("useXRay", KX_RaySensor, m_bXRay), + KX_PYATTRIBUTE_FLOAT_RW("range", 0, 10000, KX_RaySensor, m_distance), + KX_PYATTRIBUTE_STRING_RW("property", 0, 100, false, KX_RaySensor, m_propertyname), + KX_PYATTRIBUTE_INT_RW("axis", 0, 5, true, KX_RaySensor, m_axis), + KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitPosition", KX_RaySensor, m_hitPosition, 3), + KX_PYATTRIBUTE_FLOAT_ARRAY_RO("rayDirection", KX_RaySensor, m_rayDirection, 3), + KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitNormal", KX_RaySensor, m_hitNormal, 3), + KX_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_RaySensor, pyattr_get_hitobject), { NULL } //Sentinel }; +PyObject* KX_RaySensor::pyattr_get_hitobject(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_RaySensor* self = static_cast(self_v); + if (self->m_hitObject) + return self->m_hitObject->AddRef(); + + Py_RETURN_NONE; +} + +// Deprecated -----> 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) { + ShowDeprecationWarning("getHitObject()", "the hitObject property"); if (m_hitObject) { return m_hitObject->AddRef(); @@ -365,7 +399,15 @@ const char KX_RaySensor::GetHitPosition_doc[] = "\tReturns the position (in worldcoordinates) where the object was hit by this ray.\n"; PyObject* KX_RaySensor::PyGetHitPosition(PyObject* self) { - return PyObjectFrom(m_hitPosition); + ShowDeprecationWarning("getHitPosition()", "the hitPosition property"); + + PyObject *retVal = PyList_New(3); + + PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_hitPosition[0])); + PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_hitPosition[1])); + PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_hitPosition[2])); + + return retVal; } const char KX_RaySensor::GetRayDirection_doc[] = @@ -373,7 +415,15 @@ const char KX_RaySensor::GetRayDirection_doc[] = "\tReturns the direction from the ray (in worldcoordinates) .\n"; PyObject* KX_RaySensor::PyGetRayDirection(PyObject* self) { - return PyObjectFrom(m_rayDirection); + ShowDeprecationWarning("getRayDirection()", "the rayDirection property"); + + PyObject *retVal = PyList_New(3); + + PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_rayDirection[0])); + PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_rayDirection[1])); + PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_rayDirection[2])); + + return retVal; } const char KX_RaySensor::GetHitNormal_doc[] = @@ -381,11 +431,31 @@ const char KX_RaySensor::GetHitNormal_doc[] = "\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) { - return PyObjectFrom(m_hitNormal); + ShowDeprecationWarning("getHitNormal()", "the hitNormal property"); + + PyObject *retVal = PyList_New(3); + + PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_hitNormal[0])); + PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_hitNormal[1])); + PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_hitNormal[2])); + + return retVal; } PyObject* KX_RaySensor::_getattr(const char *attr) { + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; _getattr_up(SCA_ISensor); } + +int KX_RaySensor::_setattr(const char *attr, PyObject *value) { + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_ISensor::_setattr(attr, value); +} + +// <----- Deprecated \ No newline at end of file diff --git a/source/gameengine/Ketsji/KX_RaySensor.h b/source/gameengine/Ketsji/KX_RaySensor.h index 09d8bc1369a..e7901a0d10d 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.h +++ b/source/gameengine/Ketsji/KX_RaySensor.h @@ -44,15 +44,15 @@ class KX_RaySensor : public SCA_ISensor STR_String m_propertyname; bool m_bFindMaterial; bool m_bXRay; - double m_distance; + float m_distance; class KX_Scene* m_scene; bool m_bTriggered; int m_axis; bool m_rayHit; - MT_Point3 m_hitPosition; + float m_hitPosition[3]; SCA_IObject* m_hitObject; - MT_Vector3 m_hitNormal; - MT_Vector3 m_rayDirection; + float m_hitNormal[3]; + float m_rayDirection[3]; public: KX_RaySensor(class SCA_EventManager* eventmgr, @@ -73,13 +73,31 @@ public: bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data); bool NeedRayCast(KX_ClientObjectInfo* client); + + + //Python Interface + enum RayAxis { + KX_RAY_AXIS_POS_Y = 0, + KX_RAY_AXIS_POS_X, + KX_RAY_AXIS_POS_Z, + KX_RAY_AXIS_NEG_X, + KX_RAY_AXIS_NEG_Y, + KX_RAY_AXIS_NEG_Z + }; + + + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); + // Deprecated -----> 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); + /* Attributes */ + static PyObject* pyattr_get_hitobject(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); }; diff --git a/source/gameengine/PyDoc/GameLogic.py b/source/gameengine/PyDoc/GameLogic.py index 0524a9df355..833d896ba6b 100644 --- a/source/gameengine/PyDoc/GameLogic.py +++ b/source/gameengine/PyDoc/GameLogic.py @@ -148,6 +148,14 @@ Documentation for the GameLogic Module. @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} + +@group Ray Sensor: KX_RAY_AXIS_POS_X, KX_RAY_AXIS_POS_Y, KX_RAY_AXIS_POS_Z, KX_RAY_AXIS_NEG_X, KX_RAY_AXIS_NEG_Y, KX_RAY_AXIS_NEG_Z +@var KX_RAY_AXIS_POS_X: See L{KX_RaySensor} +@var KX_RAY_AXIS_POS_Y: See L{KX_RaySensor} +@var KX_RAY_AXIS_POS_Z: See L{KX_RaySensor} +@var KX_RAY_AXIS_NEG_X: See L{KX_RaySensor} +@var KX_RAY_AXIS_NEG_Y: See L{KX_RaySensor} +@var KX_RAY_AXIS_NEG_Z: See L{KX_RaySensor} """ diff --git a/source/gameengine/PyDoc/KX_NetworkMessageActuator.py b/source/gameengine/PyDoc/KX_NetworkMessageActuator.py index aecd2897743..c9f48d47eb8 100644 --- a/source/gameengine/PyDoc/KX_NetworkMessageActuator.py +++ b/source/gameengine/PyDoc/KX_NetworkMessageActuator.py @@ -5,21 +5,33 @@ from SCA_IActuator import * class KX_NetworkMessageActuator(SCA_IActuator): """ Message Actuator + + @ivar propName: Messages will only be sent to objects with the given property name. + @type propName: string + @ivar subject: The subject field of the message. + @type subject: string + @ivar body: The body of the message. + @type body: string + @ivar usePropBody: Send a property instead of a regular body message. + @type usePropBody: boolean """ def setToPropName(name): """ + DEPRECATED: Use the propName property instead. Messages will only be sent to objects with the given property name. @type name: string """ def setSubject(subject): """ + DEPRECATED: Use the subject property instead. Sets the subject field of the message. @type subject: string """ def setBodyType(bodytype): """ + DEPRECATED: Use the usePropBody property instead. Sets the type of body to send. @type bodytype: boolean @@ -27,6 +39,7 @@ class KX_NetworkMessageActuator(SCA_IActuator): """ def setBody(body): """ + DEPRECATED: Use the body property instead. Sets the message body. @type body: string diff --git a/source/gameengine/PyDoc/KX_NetworkMessageSensor.py b/source/gameengine/PyDoc/KX_NetworkMessageSensor.py index 8f5f3609df7..0fecad58437 100644 --- a/source/gameengine/PyDoc/KX_NetworkMessageSensor.py +++ b/source/gameengine/PyDoc/KX_NetworkMessageSensor.py @@ -7,9 +7,22 @@ class KX_NetworkMessageSensor(SCA_ISensor): The Message Sensor logic brick. Currently only loopback (local) networks are supported. + + @ivar subject: The subject the sensor is looking for. + @type subject: string + @ivar frameMessageCount: The number of messages received since the last frame. + (Read-only) + @type framemessageCount: int + @ivar subjects: The list of message subjects received. (Read-only) + @type subjects: list of strings + @ivar bodies: The list of message bodies received. (Read-only) + @type bodies: list of strings """ + + def setSubjectFilterText(subject): """ + DEPRECATED: Use the subject property instead. Change the message subject text that this sensor is listening to. @type subject: string @@ -18,24 +31,28 @@ class KX_NetworkMessageSensor(SCA_ISensor): def getFrameMessageCount(): """ + DEPRECATED: Use the frameMessageCount property instead. Get the number of messages received since the last frame. @rtype: integer """ def getBodies(): """ + DEPRECATED: Use the bodies property instead. Gets the list of message bodies. @rtype: list """ def getSubject(): """ + DEPRECATED: Use the subject property instead. Gets the message subject this sensor is listening for from the Subject: field. @rtype: string """ def getSubjects(): """ + DEPRECATED: Use the subjects property instead. Gets the list of message subjects received. @rtype: list diff --git a/source/gameengine/PyDoc/KX_RaySensor.py b/source/gameengine/PyDoc/KX_RaySensor.py index e487edcb655..b9de54e92a5 100644 --- a/source/gameengine/PyDoc/KX_RaySensor.py +++ b/source/gameengine/PyDoc/KX_RaySensor.py @@ -5,28 +5,53 @@ from SCA_ISensor import * class KX_RaySensor(SCA_ISensor): """ A ray sensor detects the first object in a given direction. + + @ivar property: The property the ray is looking for. + @type property: string + @ivar range: The distance of the ray. + @type range: float + @ivar useMaterial: Whether or not to look for a material (false = property) + @type useMaterial: boolean + @ivar useXRay: Whether or not to use XRay. + @type useXRay: boolean + @ivar hitObject: The game object that was hit by the ray. (Read-only) + @type hitObject: KX_GameObject + @ivar hitPosition: The position (in worldcoordinates) where the object was hit by the ray. (Read-only) + @type hitPosition: list [x, y, z] + @ivar hitNormal: The normal (in worldcoordinates) of the object at the location where the object was hit by the ray. (Read-only) + @type hitNormal: list [x, y, z] + @ivar rayDirection: The direction from the ray (in worldcoordinates). (Read-only) + @type rayDirection: list [x, y, z] + @ivar axis: The axis the ray is pointing on. + @type axis: int from 0 to 5 + KX_RAY_AXIS_POS_X, KX_RAY_AXIS_POS_Y, KX_RAY_AXIS_POS_Z, + KX_RAY_AXIS_NEG_X, KX_RAY_AXIS_NEG_Y, KX_RAY_AXIS_NEG_Z """ def getHitObject(): """ + DEPRECATED: Use the hitObject property instead. Returns the game object that was hit by this ray. @rtype: KX_GameObject """ def getHitPosition(): """ + DEPRECATED: Use the hitPosition property instead. Returns the position (in worldcoordinates) where the object was hit by this ray. @rtype: list [x, y, z] """ def getHitNormal(): """ + DEPRECATED: Use the hitNormal property instead. Returns the normal (in worldcoordinates) of the object at the location where the object was hit by this ray. @rtype: list [nx, ny, nz] """ def getRayDirection(): """ + DEPRECATED: Use the rayDirection property instead. Returns the direction from the ray (in worldcoordinates) @rtype: list [dx, dy, dz] -- cgit v1.2.3 From f6f47a08eba8991419853f66ade3b1ad44f5b3e4 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Tue, 31 Mar 2009 21:03:15 +0000 Subject: BGE API cleanup: DynamicActuator, ReplaceMeshActuator, TrackToActuator. --- source/gameengine/Ketsji/KX_PythonInit.cpp | 8 +++ .../gameengine/Ketsji/KX_SCA_DynamicActuator.cpp | 18 +++++- source/gameengine/Ketsji/KX_SCA_DynamicActuator.h | 11 ++++ .../Ketsji/KX_SCA_ReplaceMeshActuator.cpp | 47 ++++++++++++++- .../gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h | 7 ++- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 67 ++++++++++++++-------- source/gameengine/Ketsji/KX_TrackToActuator.h | 6 +- source/gameengine/PyDoc/GameLogic.py | 9 +++ source/gameengine/PyDoc/KX_SCA_DynamicActuator.py | 30 ++++++++++ .../gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py | 7 +++ source/gameengine/PyDoc/KX_TrackToActuator.py | 11 ++++ 11 files changed, 191 insertions(+), 30 deletions(-) create mode 100644 source/gameengine/PyDoc/KX_SCA_DynamicActuator.py (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index bf41f3a555f..7ddfbb0d5fe 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -49,6 +49,7 @@ #include "KX_KetsjiEngine.h" #include "KX_RadarSensor.h" #include "KX_RaySensor.h" +#include "KX_SCA_DynamicActuator.h" #include "SCA_IInputDevice.h" #include "SCA_PropertySensor.h" @@ -1079,6 +1080,13 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_Y, KX_RaySensor::KX_RAY_AXIS_NEG_X); KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_Z, KX_RaySensor::KX_RAY_AXIS_NEG_Z); + /* Dynamic actuator */ + KX_MACRO_addTypesToDict(d, KX_DYN_RESTORE_DYNAMICS, KX_SCA_DynamicActuator::KX_DYN_RESTORE_DYNAMICS); + KX_MACRO_addTypesToDict(d, KX_DYN_DISABLE_DYNAMICS, KX_SCA_DynamicActuator::KX_DYN_DISABLE_DYNAMICS); + KX_MACRO_addTypesToDict(d, KX_DYN_ENABLE_RIGID_BODY, KX_SCA_DynamicActuator::KX_DYN_ENABLE_RIGID_BODY); + KX_MACRO_addTypesToDict(d, KX_DYN_DISABLE_RIGID_BODY, KX_SCA_DynamicActuator::KX_DYN_DISABLE_RIGID_BODY); + KX_MACRO_addTypesToDict(d, KX_DYN_SET_MASS, KX_SCA_DynamicActuator::KX_DYN_SET_MASS); + // Check for errors if (PyErr_Occurred()) { diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp index 394bb667728..8df3af61721 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp @@ -36,6 +36,7 @@ // Please look here for revision history. #include "KX_SCA_DynamicActuator.h" +#include "blendef.h" #ifdef HAVE_CONFIG_H #include @@ -80,21 +81,34 @@ PyParentObject KX_SCA_DynamicActuator::Parents[] = { PyMethodDef KX_SCA_DynamicActuator::Methods[] = { + // ---> deprecated KX_PYMETHODTABLE(KX_SCA_DynamicActuator, setOperation), KX_PYMETHODTABLE(KX_SCA_DynamicActuator, getOperation), {NULL,NULL} //Sentinel }; PyAttributeDef KX_SCA_DynamicActuator::Attributes[] = { + KX_PYATTRIBUTE_SHORT_RW("operation",0,4,false,KX_SCA_DynamicActuator,m_dyn_operation), + KX_PYATTRIBUTE_FLOAT_RW("mass",0.0,MAXFLOAT,KX_SCA_DynamicActuator,m_setmass), { NULL } //Sentinel }; PyObject* KX_SCA_DynamicActuator::_getattr(const char *attr) { - _getattr_up(SCA_IActuator); + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + _getattr_up(SCA_IActuator); } +int KX_SCA_DynamicActuator::_setattr(const char *attr, PyObject* value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_IActuator::_setattr(attr, value); +} /* 1. setOperation */ @@ -107,6 +121,7 @@ KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, setOperation, "\t 3 = disable rigid body\n" "Change the dynamic status of the parent object.\n") { + ShowDeprecationWarning("setOperation()", "the operation property"); int dyn_operation; if (!PyArg_ParseTuple(args, "i", &dyn_operation)) @@ -126,6 +141,7 @@ KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, getOperation, "Returns the operation type of this actuator.\n" ) { + ShowDeprecationWarning("getOperation()", "the operation property"); return PyInt_FromLong((long)m_dyn_operation); } diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h index a82cddd66a7..082fcd72035 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h @@ -64,7 +64,18 @@ class KX_SCA_DynamicActuator : public SCA_IActuator virtual bool Update(); + //Python Interface + enum DynamicOperation { + KX_DYN_RESTORE_DYNAMICS = 0, + KX_DYN_DISABLE_DYNAMICS, + KX_DYN_ENABLE_RIGID_BODY, + KX_DYN_DISABLE_RIGID_BODY, + KX_DYN_SET_MASS, + }; + + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject *value); /* 1. setOperation */ KX_PYMETHOD_DOC(KX_SCA_DynamicActuator,setOperation); diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index 502990b2b27..2f971084a39 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -82,23 +82,62 @@ PyParentObject KX_SCA_ReplaceMeshActuator::Parents[] = { PyMethodDef KX_SCA_ReplaceMeshActuator::Methods[] = { - {"setMesh", (PyCFunction) KX_SCA_ReplaceMeshActuator::sPySetMesh, METH_O, (PY_METHODCHAR)SetMesh_doc}, - KX_PYMETHODTABLE(KX_SCA_ReplaceMeshActuator, instantReplaceMesh), + // Deprecated -----> + {"setMesh", (PyCFunction) KX_SCA_ReplaceMeshActuator::sPySetMesh, METH_O, (PY_METHODCHAR)SetMesh_doc}, KX_PYMETHODTABLE(KX_SCA_ReplaceMeshActuator, getMesh), {NULL,NULL} //Sentinel }; PyAttributeDef KX_SCA_ReplaceMeshActuator::Attributes[] = { + KX_PYATTRIBUTE_RW_FUNCTION("mesh", KX_SCA_ReplaceMeshActuator, pyattr_get_mesh, pyattr_set_mesh), { NULL } //Sentinel }; PyObject* KX_SCA_ReplaceMeshActuator::_getattr(const char *attr) { - _getattr_up(SCA_IActuator); + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + _getattr_up(SCA_IActuator); } +int KX_SCA_ReplaceMeshActuator::_setattr(const char *attr, PyObject* value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_IActuator::_setattr(attr, value); +} +PyObject* KX_SCA_ReplaceMeshActuator::pyattr_get_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_SCA_ReplaceMeshActuator* actuator = static_cast(self); + if (!actuator->m_mesh) + Py_RETURN_NONE; + return PyString_FromString(const_cast(actuator->m_mesh->GetName().ReadPtr())); +} + +int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_SCA_ReplaceMeshActuator* actuator = static_cast(self); + if (value == Py_None) { + actuator->m_mesh = NULL; + } else { + char* meshname = PyString_AsString(value); + if (!meshname) { + PyErr_SetString(PyExc_ValueError, "Expected the name of a mesh or None"); + return 1; + } + void* mesh = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(meshname)); + if (mesh==NULL) { + PyErr_SetString(PyExc_ValueError, "The mesh name given does not exist"); + return 1; + } + actuator->m_mesh= (class RAS_MeshObject*)mesh; + } + return 0; +} /* 1. setMesh */ const char KX_SCA_ReplaceMeshActuator::SetMesh_doc[] = @@ -108,6 +147,7 @@ const char KX_SCA_ReplaceMeshActuator::SetMesh_doc[] = PyObject* KX_SCA_ReplaceMeshActuator::PySetMesh(PyObject* self, PyObject* value) { + ShowDeprecationWarning("setMesh()", "the mesh property"); if (value == Py_None) { m_mesh = NULL; } else { @@ -133,6 +173,7 @@ KX_PYMETHODDEF_DOC(KX_SCA_ReplaceMeshActuator, getMesh, "Returns the name of the mesh to be substituted.\n" ) { + ShowDeprecationWarning("getMesh()", "the mesh property"); if (!m_mesh) Py_RETURN_NONE; diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h index 0ba60650683..ba43975bd51 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h @@ -69,9 +69,14 @@ class KX_SCA_ReplaceMeshActuator : public SCA_IActuator virtual bool Update(); - virtual PyObject* _getattr(const char *attr); void InstantReplaceMesh(); + virtual PyObject* _getattr(const char *attr); + virtual int _setattr(const char *attr, PyObject* value); + + static PyObject* pyattr_get_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + /* 1. setMesh */ KX_PYMETHOD_DOC_O(KX_SCA_ReplaceMeshActuator,SetMesh); KX_PYMETHOD_DOC(KX_SCA_ReplaceMeshActuator,getMesh); diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 8637bc92d39..e54528c7bd4 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -402,7 +402,7 @@ bool KX_TrackToActuator::Update(double curtime, bool frame) // set the models tranformation properties curobj->NodeSetLocalOrientation(mat); curobj->NodeSetLocalPosition(localpos); - curobj->UpdateTransform(); + //curobj->UpdateTransform(); } else { @@ -456,12 +456,11 @@ PyParentObject KX_TrackToActuator::Parents[] = { PyMethodDef KX_TrackToActuator::Methods[] = { + // ---> deprecated {"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}, @@ -469,39 +468,55 @@ PyMethodDef KX_TrackToActuator::Methods[] = { }; PyAttributeDef KX_TrackToActuator::Attributes[] = { + KX_PYATTRIBUTE_INT_RW("time",0,1000,true,KX_TrackToActuator,m_time), + KX_PYATTRIBUTE_BOOL_RW("user3D",KX_TrackToActuator,m_allow3D), + KX_PYATTRIBUTE_RW_FUNCTION("object", KX_TrackToActuator, pyattr_get_object, pyattr_set_object), + { NULL } //Sentinel }; - -PyObject* KX_TrackToActuator::_getattr(const char *attr) +PyObject* KX_TrackToActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { - if (!strcmp(attr, "object")) { - if (!m_object) Py_RETURN_NONE; - else return m_object->AddRef(); - } - - _getattr_up(SCA_IActuator); + KX_TrackToActuator* actuator = static_cast(self); + if (!actuator->m_object) + Py_RETURN_NONE; + else + return actuator->m_object->AddRef(); } -int KX_TrackToActuator::_setattr(const char *attr, PyObject* value) +int KX_TrackToActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { - if (!strcmp(attr, "object")) { - KX_GameObject *gameobj; + KX_TrackToActuator* actuator = static_cast(self); + KX_GameObject *gameobj; - if (!ConvertPythonToGameObject(value, &gameobj, true)) - return 1; // ConvertPythonToGameObject sets the error + if (!ConvertPythonToGameObject(value, &gameobj, true)) + return 1; // ConvertPythonToGameObject sets the error - if (m_object != NULL) - m_object->UnregisterActuator(this); + if (actuator->m_object != NULL) + actuator->m_object->UnregisterActuator(actuator); - m_object = (SCA_IObject*)gameobj; + actuator->m_object = (SCA_IObject*) gameobj; - if (m_object) - m_object->RegisterActuator(this); + if (actuator->m_object) + actuator->m_object->RegisterActuator(actuator); - return 0; - } - + return 0; +} + + +PyObject* KX_TrackToActuator::_getattr(const char *attr) +{ + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; + _getattr_up(SCA_IActuator); +} + +int KX_TrackToActuator::_setattr(const char *attr, PyObject* value) +{ + int ret = _setattr_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; return SCA_IActuator::_setattr(attr, value); } @@ -563,6 +578,7 @@ const char KX_TrackToActuator::SetTime_doc[] = "\tSet the time in frames with which to delay the tracking motion.\n"; PyObject* KX_TrackToActuator::PySetTime(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setTime()", "the timer property"); int timeArg; if (!PyArg_ParseTuple(args, "i", &timeArg)) @@ -584,6 +600,7 @@ const char KX_TrackToActuator::GetTime_doc[] = "\tReturn the time in frames with which the tracking motion is delayed.\n"; PyObject* KX_TrackToActuator::PyGetTime(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getTime()", "the timer property"); return PyInt_FromLong(m_time); } @@ -595,6 +612,7 @@ const char KX_TrackToActuator::GetUse3D_doc[] = "\tReturns 1 if the motion is allowed to extend in the z-direction.\n"; PyObject* KX_TrackToActuator::PyGetUse3D(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setTime()", "the use3D property"); return PyInt_FromLong(!(m_allow3D == 0)); } @@ -608,6 +626,7 @@ const char KX_TrackToActuator::SetUse3D_doc[] = "\tset to 0 to lock the tracking motion to the x-y plane.\n"; PyObject* KX_TrackToActuator::PySetUse3D(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setTime()", "the use3D property"); int boolArg; if (!PyArg_ParseTuple(args, "i", &boolArg)) { diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.h b/source/gameengine/Ketsji/KX_TrackToActuator.h index 392e55402f1..f81958dfb33 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.h +++ b/source/gameengine/Ketsji/KX_TrackToActuator.h @@ -74,7 +74,11 @@ class KX_TrackToActuator : public SCA_IActuator /* Python part */ virtual PyObject* _getattr(const char *attr); virtual int _setattr(const char *attr, PyObject* value); - + + /* These are used to get and set m_ob */ + static PyObject* pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + /* 1. setObject */ KX_PYMETHOD_DOC_O(KX_TrackToActuator,SetObject); /* 2. getObject */ diff --git a/source/gameengine/PyDoc/GameLogic.py b/source/gameengine/PyDoc/GameLogic.py index 833d896ba6b..f158b410975 100644 --- a/source/gameengine/PyDoc/GameLogic.py +++ b/source/gameengine/PyDoc/GameLogic.py @@ -72,6 +72,7 @@ Documentation for the GameLogic Module. - L{SoundActuator} - L{TrackToActuator} - L{VisibilityActuator} + - L{DynamicActuator} Most logic brick's methods are accessors for the properties available in the logic buttons. Consult the logic bricks documentation for more information on how each logic brick works. @@ -156,6 +157,14 @@ Documentation for the GameLogic Module. @var KX_RAY_AXIS_NEG_X: See L{KX_RaySensor} @var KX_RAY_AXIS_NEG_Y: See L{KX_RaySensor} @var KX_RAY_AXIS_NEG_Z: See L{KX_RaySensor} + +@group Dynamic Actuator: KX_DYN_RESTORE_DYNAMICS, KX_DYN_DISABLE_DYNAMICS, KX_DYN_ENABLE_RIGID_BODY, KX_DYN_DISABLE_RIGID_BODY, KX_DYN_SET_MASS +@var KX_DYN_RESTORE_DYNAMICS: See L{KX_SCA_DynamicActuator} +@var KX_DYN_DISABLE_DYNAMICS: See L{KX_SCA_DynamicActuator} +@var KX_DYN_ENABLE_RIGID_BODY: See L{KX_SCA_DynamicActuator} +@var KX_DYN_DISABLE_RIGID_BODY: See L{KX_SCA_DynamicActuator} +@var KX_DYN_SET_MASS: See L{KX_SCA_DynamicActuator} + """ diff --git a/source/gameengine/PyDoc/KX_SCA_DynamicActuator.py b/source/gameengine/PyDoc/KX_SCA_DynamicActuator.py new file mode 100644 index 00000000000..a6a3bce1f31 --- /dev/null +++ b/source/gameengine/PyDoc/KX_SCA_DynamicActuator.py @@ -0,0 +1,30 @@ +# $Id$ +# Documentation for KX_SCA_DynamicActuator +from SCA_IActuator import * + +class KX_SCA_DynamicActuator(SCA_IActuator): + """ + Dynamic Actuator. + @ivar operation: the type of operation of the actuator, 0-4 + KX_DYN_RESTORE_DYNAMICS, KX_DYN_DISABLE_DYNAMICS, + KX_DYN_ENABLE_RIGID_BODY, KX_DYN_DISABLE_RIGID_BODY, KX_DYN_SET_MASS + @type operation: integer + @ivar mass: the mass value for the KX_DYN_SET_MASS operation + @type mass: float + """ + def setOperation(operation): + """ + DEPRECATED: Use the operation property instead. + Set the type of operation when the actuator is activated: + 0 = restore dynamics + 1 = disable dynamics + 2 = enable rigid body + 3 = disable rigid body + 4 = set mass + """ + def getOperatoin() + """ + DEPRECATED: Use the operation property instead. + return the type of operation + """ + diff --git a/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py b/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py index 498f6072e23..1faf215ed56 100644 --- a/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py +++ b/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py @@ -55,9 +55,15 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator): This will generate a warning in the console: C{ERROR: GameObject I{OBName} ReplaceMeshActuator I{ActuatorName} without object} + + Properties: + @ivar mesh: the name of the mesh that will replace the current one + Set to None to disable actuator + @type mesh: string or None if no mesh is set """ def setMesh(name): """ + DEPRECATED: Use the mesh property instead. Sets the name of the mesh that will replace the current one. When the name is None it will unset the mesh value so no action is taken. @@ -65,6 +71,7 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator): """ def getMesh(): """ + DEPRECATED: Use the mesh property instead. Returns the name of the mesh that will replace the current one. Returns None if no mesh has been scheduled to be added. diff --git a/source/gameengine/PyDoc/KX_TrackToActuator.py b/source/gameengine/PyDoc/KX_TrackToActuator.py index 730ab21166b..ff533e22ac0 100644 --- a/source/gameengine/PyDoc/KX_TrackToActuator.py +++ b/source/gameengine/PyDoc/KX_TrackToActuator.py @@ -15,9 +15,15 @@ class KX_TrackToActuator(SCA_IActuator): @ivar object: the object this actuator tracks. @type object: KX_GameObject or None + @ivar time: the time in frames with which to delay the tracking motion + @type time: integer + @ivar use3D: the tracking motion to use 3D + @type use3D: boolean + """ def setObject(object): """ + DEPRECATED: Use the object property. Sets the object to track. @type object: L{KX_GameObject}, string or None @@ -25,6 +31,7 @@ class KX_TrackToActuator(SCA_IActuator): """ def getObject(name_only): """ + DEPRECATED: Use the object property. Returns the name of the object to track. @type name_only: bool @@ -33,18 +40,21 @@ class KX_TrackToActuator(SCA_IActuator): """ def setTime(time): """ + DEPRECATED: Use the time property. Sets the time in frames with which to delay the tracking motion. @type time: integer """ def getTime(): """ + DEPRECATED: Use the time property. Returns the time in frames with which the tracking motion is delayed. @rtype: integer """ def setUse3D(use3d): """ + DEPRECATED: Use the use3D property. Sets the tracking motion to use 3D. @type use3d: boolean @@ -53,6 +63,7 @@ class KX_TrackToActuator(SCA_IActuator): """ def getUse3D(): """ + DEPRECATED: Use the use3D property. Returns True if the tracking motion will track in the z direction. @rtype: boolean -- cgit v1.2.3 From 441f26a1702444d256a54e5baf67bc7c07d75af5 Mon Sep 17 00:00:00 2001 From: "Guillermo S. Romero" Date: Tue, 31 Mar 2009 22:34:34 +0000 Subject: Clean up for the imminent migration from SVN to GIT. --- source/gameengine/Ketsji/KX_ParentActuator.cpp | 2 +- source/gameengine/Ketsji/KX_ParentActuator.h | 2 +- source/gameengine/PyDoc/KX_ParentActuator.py | 2 +- source/gameengine/PyDoc/SCA_JoystickSensor.py | 2 +- source/gameengine/PyDoc/epy_docgen.sh | 0 5 files changed, 4 insertions(+), 4 deletions(-) mode change 100644 => 100755 source/gameengine/PyDoc/epy_docgen.sh (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index fc5d679f200..3430fd85184 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -1,7 +1,7 @@ /** * Set or remove an objects parent * - * $Id: SCA_ParentActuator.cpp 13932 2008-03-01 19:05:41Z ben2610 $ + * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** * diff --git a/source/gameengine/Ketsji/KX_ParentActuator.h b/source/gameengine/Ketsji/KX_ParentActuator.h index c647e6cc8a9..257c95c9260 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.h +++ b/source/gameengine/Ketsji/KX_ParentActuator.h @@ -2,7 +2,7 @@ * Set or remove an objects parent * * - * $Id: KX_ParentActuator.h 3271 2004-10-16 11:41:50Z kester $ + * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** * diff --git a/source/gameengine/PyDoc/KX_ParentActuator.py b/source/gameengine/PyDoc/KX_ParentActuator.py index 76252e5cfad..4a5f72e7cc2 100644 --- a/source/gameengine/PyDoc/KX_ParentActuator.py +++ b/source/gameengine/PyDoc/KX_ParentActuator.py @@ -1,4 +1,4 @@ -# $Id: KX_ParentActuator.py 2615 2004-06-02 12:43:27Z kester $ +# $Id$ # Documentation for KX_ParentActuator from SCA_IActuator import * diff --git a/source/gameengine/PyDoc/SCA_JoystickSensor.py b/source/gameengine/PyDoc/SCA_JoystickSensor.py index 111ee7f4cfa..944ff64dc64 100644 --- a/source/gameengine/PyDoc/SCA_JoystickSensor.py +++ b/source/gameengine/PyDoc/SCA_JoystickSensor.py @@ -1,4 +1,4 @@ -# $Id: SCA_RandomSensor.py 15444 2008-07-05 17:05:05Z lukep $ +# $Id$ # Documentation for SCA_RandomSensor from SCA_ISensor import * diff --git a/source/gameengine/PyDoc/epy_docgen.sh b/source/gameengine/PyDoc/epy_docgen.sh old mode 100644 new mode 100755 -- cgit v1.2.3 From 48e4a4834092a8772141e6240e5e70d67110f126 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 1 Apr 2009 08:59:36 +0000 Subject: BGE API cleanup: ReplaceMeshActuator mesh attributes now returns a KX_MeshProxy. Fix a bug in KX_MeshProxy where the Python type was not set right. --- source/gameengine/Ketsji/KX_MeshProxy.cpp | 2 +- source/gameengine/Ketsji/KX_MeshProxy.h | 1 + .../gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp | 19 +++++++++++-------- source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index a0c0a496c06..f40c307315e 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -124,7 +124,7 @@ KX_MeshProxy::_getattr(const char *attr) KX_MeshProxy::KX_MeshProxy(RAS_MeshObject* mesh) - : m_meshobj(mesh) + : SCA_IObject(&Type), m_meshobj(mesh) { } diff --git a/source/gameengine/Ketsji/KX_MeshProxy.h b/source/gameengine/Ketsji/KX_MeshProxy.h index 34f60a54a3a..9e08937de07 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.h +++ b/source/gameengine/Ketsji/KX_MeshProxy.h @@ -47,6 +47,7 @@ public: virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); virtual const STR_String & GetText(); virtual float GetNumber(); + virtual RAS_MeshObject* GetMesh() { return m_meshobj; } virtual STR_String GetName(); virtual void SetName(STR_String name); // Set the name of the value virtual void ReplicaSetName(STR_String name); diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index 2f971084a39..58d6f659135 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -36,6 +36,7 @@ // Please look here for revision history. #include "KX_SCA_ReplaceMeshActuator.h" +#include "KX_MeshProxy.h" #include "PyObjectPlus.h" @@ -115,7 +116,8 @@ PyObject* KX_SCA_ReplaceMeshActuator::pyattr_get_mesh(void *self, const struct K KX_SCA_ReplaceMeshActuator* actuator = static_cast(self); if (!actuator->m_mesh) Py_RETURN_NONE; - return PyString_FromString(const_cast(actuator->m_mesh->GetName().ReadPtr())); + KX_MeshProxy* meshproxy = new KX_MeshProxy(actuator->m_mesh); + return meshproxy; } int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) @@ -123,18 +125,19 @@ int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYAT KX_SCA_ReplaceMeshActuator* actuator = static_cast(self); if (value == Py_None) { actuator->m_mesh = NULL; - } else { - char* meshname = PyString_AsString(value); - if (!meshname) { - PyErr_SetString(PyExc_ValueError, "Expected the name of a mesh or None"); - return 1; - } - void* mesh = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(meshname)); + } else if (PyString_Check(value)) { + void* mesh = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(PyString_AsString(value))); if (mesh==NULL) { PyErr_SetString(PyExc_ValueError, "The mesh name given does not exist"); return 1; } actuator->m_mesh= (class RAS_MeshObject*)mesh; + } else if PyObject_TypeCheck(value, &KX_MeshProxy::Type) { + KX_MeshProxy* proxy = (KX_MeshProxy*)value; + actuator->m_mesh= proxy->GetMesh(); + } else { + PyErr_SetString(PyExc_ValueError, "Expected the name of a mesh, a mesh proxy or None"); + return 1; } return 0; } diff --git a/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py b/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py index 1faf215ed56..1013dd53cb9 100644 --- a/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py +++ b/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py @@ -57,9 +57,9 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator): C{ERROR: GameObject I{OBName} ReplaceMeshActuator I{ActuatorName} without object} Properties: - @ivar mesh: the name of the mesh that will replace the current one + @ivar mesh: L{KX_MeshProxy} or the name of the mesh that will replace the current one Set to None to disable actuator - @type mesh: string or None if no mesh is set + @type mesh: L{KX_MeshProxy} or None if no mesh is set """ def setMesh(name): """ -- cgit v1.2.3 From fcc23faa3a5ec3c697e85e9a6b604ac7db80a05b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 2 Apr 2009 05:38:05 +0000 Subject: Added getitem/setitem access for KX_GameObject ob.someProp = 10 can now be... ob["someProp"] = 10 For simple get/set test with an objects 10 properties, this is ~30% faster. Though I like the attribute access, its slower because it needs to lookup BGE attributes and methods (for parent classes as well as KX_GameObject class). This could also be an advantage if there are collisions between new attributes added for 2.49 and existing properties a game uses. Made some other small optimizations, - Getting and setting property can use const char* as well as STR_String (avoids making new STR_Strings just to do the lookup). - CValue::SetPropertiesModified() and CValue::SetPropertiesModified(), were looping through all items in the std::map, advancing from the beginning each time. --- source/gameengine/Expressions/Value.cpp | 178 ++++++++++++++--------------- source/gameengine/Expressions/Value.h | 6 +- source/gameengine/Ketsji/KX_GameObject.cpp | 76 +++++++++++- source/gameengine/Ketsji/KX_GameObject.h | 8 +- 4 files changed, 174 insertions(+), 94 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index ebb12636ac2..2ab0a9addee 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -320,55 +320,70 @@ STR_String CValue::op2str (VALUE_OPERATOR op) // void CValue::SetProperty(const STR_String & name,CValue* ioProperty) { - // Check if somebody is setting an empty property if (ioProperty==NULL) - { + { // Check if somebody is setting an empty property trace("Warning:trying to set empty property!"); return; } - // Make sure we have a property array - if (m_pNamedPropertyArray == NULL) + if (m_pNamedPropertyArray) + { // Try to replace property (if so -> exit as soon as we replaced it) + CValue* oldval = (*m_pNamedPropertyArray)[name]; + if (oldval) + oldval->Release(); + } + else { // Make sure we have a property array m_pNamedPropertyArray = new std::map; - - // Try to replace property (if so -> exit as soon as we replaced it) - CValue* oldval = (*m_pNamedPropertyArray)[name]; - if (oldval) - { - oldval->Release(); } // Add property at end of array (*m_pNamedPropertyArray)[name] = ioProperty->AddRef();//->Add(ioProperty); } +void CValue::SetProperty(const char* name,CValue* ioProperty) +{ + if (ioProperty==NULL) + { // Check if somebody is setting an empty property + trace("Warning:trying to set empty property!"); + return; + } + if (m_pNamedPropertyArray) + { // Try to replace property (if so -> exit as soon as we replaced it) + CValue* oldval = (*m_pNamedPropertyArray)[name]; + if (oldval) + oldval->Release(); + } + else { // Make sure we have a property array + m_pNamedPropertyArray = new std::map; + } + + // Add property at end of array + (*m_pNamedPropertyArray)[name] = ioProperty->AddRef();//->Add(ioProperty); +} // // Get pointer to a property with name , returns NULL if there is no property named // CValue* CValue::GetProperty(const STR_String & inName) { - // Check properties, as soon as we found it -> Return a pointer to the property - CValue* result = NULL; - if (m_pNamedPropertyArray) - { - std::map::iterator it = (*m_pNamedPropertyArray).find(inName); - if (!( it==m_pNamedPropertyArray->end())) - { - result = (*it).second; - } - + if (m_pNamedPropertyArray) { + std::map::iterator it = m_pNamedPropertyArray->find(inName); + if (it != m_pNamedPropertyArray->end()) + return (*it).second; } - //for (int i=0; isize(); i++) - // if ((*m_pValuePropertyArray)[i]->GetName() == inName) - // return (*m_pValuePropertyArray)[i]; - - // Did not find property with name , return NULL property pointer - return result; + return NULL; } - +CValue* CValue::GetProperty(const char *inName) +{ + if (m_pNamedPropertyArray) { + std::map::iterator it = m_pNamedPropertyArray->find(inName); + if (it != m_pNamedPropertyArray->end()) + return (*it).second; + } + return NULL; +} // // Get text description of property with name , returns an empty string if there is no property named @@ -396,26 +411,20 @@ float CValue::GetPropertyNumber(const STR_String& inName,float defnumber) // // Remove the property named , returns true if the property was succesfully removed, false if property was not found or could not be removed // -bool CValue::RemoveProperty(const STR_String & inName) +bool CValue::RemoveProperty(const char *inName) { // Check if there are properties at all which can be removed - if (m_pNamedPropertyArray) { - CValue* val = GetProperty(inName); - if (NULL != val) + if (m_pNamedPropertyArray) + { + std::map::iterator it = m_pNamedPropertyArray->find(inName); + if (it != m_pNamedPropertyArray->end()) { - val->Release(); - m_pNamedPropertyArray->erase(inName); + ((*it).second)->Release(); + m_pNamedPropertyArray->erase(it); return true; } - } - - char err[128]; - if (m_pNamedPropertyArray) - sprintf(err, "attribute \"%s\" dosnt exist", inName.ReadPtr()); - else - sprintf(err, "attribute \"%s\" dosnt exist (no property array)", inName.ReadPtr()); + } - PyErr_SetString(PyExc_AttributeError, err); return false; } @@ -426,8 +435,8 @@ vector CValue::GetPropertyNames() { vector result; if(!m_pNamedPropertyArray) return result; - for ( std::map::iterator it = m_pNamedPropertyArray->begin(); - !(it == m_pNamedPropertyArray->end());it++) + std::map::iterator it; + for (it= m_pNamedPropertyArray->begin(); (it != m_pNamedPropertyArray->end()); it++) { result.push_back((*it).first); } @@ -444,8 +453,8 @@ void CValue::ClearProperties() return; // Remove all properties - for ( std::map::iterator it = m_pNamedPropertyArray->begin(); - !(it == m_pNamedPropertyArray->end());it++) + std::map::iterator it; + for (it= m_pNamedPropertyArray->begin();(it != m_pNamedPropertyArray->end()); it++) { CValue* tmpval = (*it).second; //STR_String name = (*it).first; @@ -464,9 +473,11 @@ void CValue::ClearProperties() // void CValue::SetPropertiesModified(bool inModified) { - int numprops = GetPropertyCount(); - for (int i=0; iSetModified(inModified); + if(!m_pNamedPropertyArray) return; + std::map::iterator it; + + for (it= m_pNamedPropertyArray->begin();(it != m_pNamedPropertyArray->end()); it++) + ((*it).second)->SetModified(inModified); } @@ -476,11 +487,13 @@ void CValue::SetPropertiesModified(bool inModified) // bool CValue::IsAnyPropertyModified() { - int numprops = GetPropertyCount(); - for (int i=0;iIsModified()) + if(!m_pNamedPropertyArray) return false; + std::map::iterator it; + + for (it= m_pNamedPropertyArray->begin();(it != m_pNamedPropertyArray->end()); it++) + if (((*it).second)->IsModified()) return true; - + return false; } @@ -489,7 +502,6 @@ bool CValue::IsAnyPropertyModified() // // Get property number // - CValue* CValue::GetProperty(int inIndex) { @@ -498,8 +510,8 @@ CValue* CValue::GetProperty(int inIndex) if (m_pNamedPropertyArray) { - for ( std::map::iterator it = m_pNamedPropertyArray->begin(); - !(it == m_pNamedPropertyArray->end());it++) + std::map::iterator it; + for (it= m_pNamedPropertyArray->begin(); (it != m_pNamedPropertyArray->end()); it++) { if (count++==inIndex) { @@ -535,8 +547,8 @@ void CValue::CloneProperties(CValue *replica) if (m_pNamedPropertyArray) { replica->m_pNamedPropertyArray=NULL; - for ( std::map::iterator it = m_pNamedPropertyArray->begin(); - !(it == m_pNamedPropertyArray->end());it++) + std::map::iterator it; + for (it= m_pNamedPropertyArray->begin(); (it != m_pNamedPropertyArray->end()); it++) { CValue *val = (*it).second->GetReplica(); replica->SetProperty((*it).first,val); @@ -687,28 +699,15 @@ PyAttributeDef CValue::Attributes[] = { PyObject* CValue::_getattr(const char *attr) { - CValue* resultattr = FindIdentifier(STR_String(attr)); - STR_String text; + CValue* resultattr = GetProperty(attr); if (resultattr) { - if (resultattr->IsError()) - { - resultattr->Release(); - } else - { - // to avoid some compare problems, return a real pythonthing - PyObject* pyconvert = resultattr->ConvertValueToPython(); - if (pyconvert) - { - resultattr->Release(); - return pyconvert; - } else - { - // also check if it's already in pythoninterpreter! - return resultattr; - } - - } + PyObject* pyconvert = resultattr->ConvertValueToPython(); + + if (pyconvert) + return pyconvert; + else + return resultattr; // also check if it's already in pythoninterpreter! } _getattr_up(PyObjectPlus); } @@ -774,26 +773,25 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj) int CValue::_delattr(const char *attr) { - if (!RemoveProperty(STR_String(attr))) /* sets error */ - return 1; - return 0; + if (RemoveProperty(STR_String(attr))) + return 0; + + PyErr_Format(PyExc_AttributeError, "attribute \"%s\" dosnt exist", attr); + return 1; } -int CValue::_setattr(const char *attr,PyObject* pyobj) +int CValue::_setattr(const char *attr, PyObject* pyobj) { CValue* vallie = ConvertPythonToValue(pyobj); if (vallie) { - STR_String attr_str = attr; - CValue* oldprop = GetProperty(attr_str); + CValue* oldprop = GetProperty(attr); if (oldprop) - { oldprop->SetValue(vallie); - } else - { - SetProperty(attr_str, vallie); - } + else + SetProperty(attr, vallie); + vallie->Release(); } else { @@ -811,8 +809,8 @@ PyObject* CValue::ConvertKeysToPython( void ) if (m_pNamedPropertyArray) { - for ( std::map::iterator it = m_pNamedPropertyArray->begin(); - !(it == m_pNamedPropertyArray->end());it++) + std::map::iterator it; + for (it= m_pNamedPropertyArray->begin(); (it != m_pNamedPropertyArray->end()); it++) { pystr = PyString_FromString( (*it).first ); PyList_Append(pylist, pystr); diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h index caf1064dc32..4678ab1f0c2 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/Value.h @@ -283,10 +283,12 @@ public: /// Property Management virtual void SetProperty(const STR_String& name,CValue* ioProperty); // Set property , overwrites and releases a previous property with the same name if needed - virtual CValue* GetProperty(const STR_String & inName); // Get pointer to a property with name , returns NULL if there is no property named + virtual void SetProperty(const char* name,CValue* ioProperty); + virtual CValue* GetProperty(const char* inName); // Get pointer to a property with name , returns NULL if there is no property named + virtual CValue* GetProperty(const STR_String & inName); STR_String GetPropertyText(const STR_String & inName,const STR_String& deftext=""); // Get text description of property with name , returns an empty string if there is no property named float GetPropertyNumber(const STR_String& inName,float defnumber); - virtual bool RemoveProperty(const STR_String & inName); // Remove the property named , returns true if the property was succesfully removed, false if property was not found or could not be removed + virtual bool RemoveProperty(const char *inName); // Remove the property named , returns true if the property was succesfully removed, false if property was not found or could not be removed virtual vector GetPropertyNames(); virtual void ClearProperties(); // Clear all properties diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index bbfa2ad324f..281de1965d4 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1103,6 +1103,80 @@ PyObject* KX_GameObject::PyGetPosition(PyObject* self) } +int KX_GameObject::Map_Len(PyObject* self_v) +{ + return (static_cast(self_v))->GetPropertyCount(); +} + + +PyObject *KX_GameObject::Map_GetItem(PyObject *self_v, PyObject *item) +{ + KX_GameObject* self= static_cast(self_v); + const char *attr= PyString_AsString(item); + CValue* resultattr; + PyObject* pyconvert; + + + if(attr==NULL) { + PyErr_SetString(PyExc_TypeError, "KX_GameObject key but a string"); + return NULL; + } + + resultattr = self->GetProperty(attr); + + if(resultattr==NULL) { + PyErr_SetString(PyExc_KeyError, "KX_GameObject key does not exist"); + return NULL; + } + + pyconvert = resultattr->ConvertValueToPython(); + + return pyconvert ? pyconvert:resultattr; +} + + +int KX_GameObject::Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val) +{ + KX_GameObject* self= static_cast(self_v); + const char *attr= PyString_AsString(key); + + if(attr==NULL) { + PyErr_SetString(PyExc_TypeError, "KX_GameObject key but a string"); + return 1; + } + + if (val==NULL) { /* del ob["key"] */ + if (self->RemoveProperty(attr)==false) { + PyErr_Format(PyExc_KeyError, "KX_GameObject key \"%s\" not found", attr); + return 1; + } + } + else { /* ob["key"] = value */ + CValue* vallie = self->ConvertPythonToValue(val); + + if(vallie==NULL) + return 1; /* ConvertPythonToValue sets the error */ + + CValue* oldprop = self->GetProperty(attr); + + if (oldprop) + oldprop->SetValue(vallie); + else + self->SetProperty(attr, vallie); + + vallie->Release(); + } + + return 0; +} + + +PyMappingMethods KX_GameObject::Mapping = { + (inquiry)KX_GameObject::Map_Len, /*inquiry mp_length */ + (binaryfunc)KX_GameObject::Map_GetItem, /*binaryfunc mp_subscript */ + (objobjargproc)KX_GameObject::Map_SetItem, /*objobjargproc mp_ass_subscript */ +}; + PyTypeObject KX_GameObject::Type = { PyObject_HEAD_INIT(&PyType_Type) @@ -1118,7 +1192,7 @@ PyTypeObject KX_GameObject::Type = { __repr, 0, //&cvalue_as_number, 0, - 0, + &Mapping, 0, 0 }; diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 326b3700ad7..774977f2ecf 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -822,7 +822,13 @@ public: static PyObject* pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - + /* getitem/setitem */ + static int Map_Len(PyObject* self); + static PyMappingMethods Mapping; + static PyObject* Map_GetItem(PyObject *self_v, PyObject *item); + static int Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val); + + private : /** -- cgit v1.2.3 From 941a8a25040b8fdce1ac0fbe11e6391e06b79c17 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 2 Apr 2009 06:59:27 +0000 Subject: [#18472] [patch] Speeding up Blenderplayer's profile drawing from Mitchell Stokes (moguri) --- .../GamePlayer/common/GPC_RenderTools.cpp | 34 +++++++++------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp index 8135635ddb3..eafdb8a96bb 100644 --- a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp +++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp @@ -29,6 +29,8 @@ #include "GL/glew.h" +#include "BMF_Api.h" + #include "DNA_scene_types.h" #include "RAS_IRenderTools.h" @@ -54,6 +56,7 @@ #include "GPC_RenderTools.h" + unsigned int GPC_RenderTools::m_numgllights; GPC_RenderTools::GPC_RenderTools() @@ -311,28 +314,19 @@ void GPC_RenderTools::RenderText2D(RAS_TEXT_RENDER_MODE mode, glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - - // Actual drawing - unsigned char colors[2][3] = { - {0x00, 0x00, 0x00}, - {0xFF, 0xFF, 0xFF} - }; - int numTimes = mode == RAS_TEXT_PADDED ? 2 : 1; - for (int i = 0; i < numTimes; i++) { - glColor3ub(colors[i][0], colors[i][1], colors[i][2]); - glRasterPos2i(xco, yco); - for (p = s, lines = 0; *p; p++) { - if (*p == '\n') - { - lines++; - glRasterPos2i(xco, yco-(lines*18)); - } - BMF_DrawCharacter(m_font, *p); - } - xco += 1; - yco += 1; + + // Actual drawing (draw black first if padded) + if (mode == RAS_IRenderTools::RAS_TEXT_PADDED) + { + glColor3ub(0, 0, 0); + glRasterPos2s(xco+1, height-yco-1); + BMF_DrawString(m_font, s); } + glColor3ub(255, 255, 255); + glRasterPos2s(xco, height-yco); + BMF_DrawString(m_font, s); + // Restore view settings glMatrixMode(GL_PROJECTION); glPopMatrix(); -- cgit v1.2.3 From b22705f1694f83756f7ca785b6f20caf353f5998 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 3 Apr 2009 02:16:56 +0000 Subject: BGE Python - Bugfix for running dir() on all BGE python objects. was not getting the immediate methods and attributes for each class. - Use attributes for KX_Scene (so they are included with dir()) - Override __dict__ attributes for KX_Scene and KX_GameObject so custom properties are included with a dir() --- source/gameengine/Expressions/PyObjectPlus.h | 5 +-- source/gameengine/Ketsji/KX_GameObject.cpp | 34 ++++++++++++--- source/gameengine/Ketsji/KX_GameObject.h | 3 ++ source/gameengine/Ketsji/KX_Scene.cpp | 65 ++++++++++++++++++---------- source/gameengine/Ketsji/KX_Scene.h | 9 ++++ 5 files changed, 85 insertions(+), 31 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 6ba80255aa3..345eb8c9c3f 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -100,9 +100,8 @@ static inline void Py_Fatal(const char *M) { PyErr_Clear(); \ rvalue = Parent::_getattr(attr); \ } \ - if ((rvalue == NULL) && !strcmp(attr, "__dict__")) {\ - PyErr_Clear(); \ - rvalue = _getattr_dict(Parent::_getattr(attr), Methods, Attributes); \ + if (strcmp(attr, "__dict__")==0) {\ + rvalue = _getattr_dict(rvalue, Methods, Attributes); \ } \ return rvalue; \ diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 281de1965d4..5c9615c408b 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -942,14 +942,14 @@ const MT_Vector3& KX_GameObject::NodeGetWorldScaling() const } - +static MT_Point3 dummy_point= MT_Point3(0.0, 0.0, 0.0); const MT_Point3& KX_GameObject::NodeGetWorldPosition() const { // check on valid node in case a python controller holds a reference to a deleted object if (GetSGNode()) return GetSGNode()->GetWorldPosition(); else - return MT_Point3(0.0, 0.0, 0.0); + return dummy_point; } /* Suspend/ resume: for the dynamic behaviour, there is a simple @@ -1043,6 +1043,7 @@ PyAttributeDef KX_GameObject::Attributes[] = { KX_PYATTRIBUTE_RW_FUNCTION("scaling", KX_GameObject, pyattr_get_scaling, pyattr_set_scaling), KX_PYATTRIBUTE_RW_FUNCTION("timeOffset",KX_GameObject, pyattr_get_timeOffset,pyattr_set_timeOffset), KX_PYATTRIBUTE_RW_FUNCTION("state", KX_GameObject, pyattr_get_state, pyattr_set_state), + KX_PYATTRIBUTE_RO_FUNCTION("__dict__", KX_GameObject, pyattr_get_dir_dict), {NULL} //Sentinel }; @@ -1412,16 +1413,37 @@ int KX_GameObject::pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attr return 0; } +/* __dict__ only for the purpose of giving useful dir() results */ +PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + PyObject *dict= _getattr_dict(self->SCA_IObject::_getattr("__dict__"), KX_GameObject::Methods, KX_GameObject::Attributes); + + if(dict==NULL) + return NULL; + + /* Not super fast getting as a list then making into dict keys but its only for dir() */ + PyObject *list= self->ConvertKeysToPython(); + if(list) + { + int i; + for(i=0; i(self_v); + return PyString_FromString(self->GetName().ReadPtr()); +} + +PyObject* KX_Scene::pyattr_get_objects(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_Scene* self= static_cast(self_v); + return self->GetObjectList()->AddRef(); +} + +PyObject* KX_Scene::pyattr_get_active_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_Scene* self= static_cast(self_v); + return self->GetActiveCamera()->AddRef(); +} + +/* __dict__ only for the purpose of giving useful dir() results */ +PyObject* KX_Scene::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_Scene* self= static_cast(self_v); + /* Useually done by _getattr_up but in this case we want to include m_attrlist dict */ + PyObject *dict= _getattr_dict(self->PyObjectPlus::_getattr("__dict__"), KX_Scene::Methods, KX_Scene::Attributes); + + PyDict_Update(dict, self->m_attrlist); + return dict; +} + PyAttributeDef KX_Scene::Attributes[] = { + KX_PYATTRIBUTE_RO_FUNCTION("name", KX_Scene, pyattr_get_name), + KX_PYATTRIBUTE_RO_FUNCTION("objects", KX_Scene, pyattr_get_objects), + KX_PYATTRIBUTE_RO_FUNCTION("active_camera", KX_Scene, pyattr_get_active_camera), + KX_PYATTRIBUTE_BOOL_RO("suspended", KX_Scene, m_suspend), + KX_PYATTRIBUTE_BOOL_RO("activity_culling", KX_Scene, m_activity_culling), + KX_PYATTRIBUTE_FLOAT_RW("activity_culling_radius", 0.5f, FLT_MAX, KX_Scene, m_activity_box_radius), + KX_PYATTRIBUTE_RO_FUNCTION("__dict__", KX_Scene, pyattr_get_dir_dict), { NULL } //Sentinel }; 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")) - return (PyObject*) GetActiveCamera()->AddRef(); - - if (!strcmp(attr, "suspended")) - return PyInt_FromLong(m_suspend); - - if (!strcmp(attr, "activity_culling")) - return PyInt_FromLong(m_activity_culling); - - if (!strcmp(attr, "activity_culling_radius")) - return PyFloat_FromDouble(m_activity_box_radius); + PyObject* object = _getattr_self(Attributes, this, attr); + if (object != NULL) + return object; - PyObject* value = PyDict_GetItemString(m_attrlist, attr); - if (value) + object = PyDict_GetItemString(m_attrlist, attr); + if (object) { - Py_INCREF(value); - return value; + Py_INCREF(object); + return object; } _getattr_up(PyObjectPlus); diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 962db1a9b96..d1da44c600e 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -565,6 +565,15 @@ public: KX_PYMETHOD_DOC(KX_Scene, setSceneViewport); */ + /* attributes */ + static PyObject* pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_objects(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_active_camera(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + + /* for dir(), python3 uses __dir__() */ + static PyObject* pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + + 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); -- cgit v1.2.3 From 0499d98311c6c9ce1a096ca2ee7bd0e361b5188c Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 3 Apr 2009 03:52:19 +0000 Subject: Setting ignore_deprecation_warnings as 1 by default in GamePlayer (in the embed BGE it is still 0) --- source/gameengine/GamePlayer/ghost/GPG_Application.cpp | 2 +- source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index e858c852b70..cca344a03bb 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -530,7 +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); + bool nodepwarnings = (SYS_GetCommandLineInt(syshandle, "ignore_deprecation_warnings", 1) != 0); if(GLEW_ARB_multitexture && GLEW_VERSION_1_1) m_blendermat = (SYS_GetCommandLineInt(syshandle, "blender_material", 1) != 0); diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 018c966ac69..a41446ad88c 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -204,7 +204,7 @@ void usage(const char* program) 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(" ignore_deprecation_warnings 1 Ignore deprecation warnings\n"); printf("\n"); 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); -- cgit v1.2.3 From d573e9c5390a438b6e606a12d05dc2c6ad06a174 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 3 Apr 2009 04:12:20 +0000 Subject: BGE Python api Added the method into the PyType so python knows about the methods (its supposed to work this way). This means in the future the api can use PyType_Ready() to store the methods in the types dictionary. Python3 removes Py_FindMethod and we should not be using it anyway since its not that efficient. --- source/gameengine/Converter/BL_ActionActuator.cpp | 9 ++---- .../Converter/BL_ShapeActionActuator.cpp | 7 ++-- source/gameengine/Expressions/ListValue.cpp | 2 ++ source/gameengine/Expressions/PyObjectPlus.cpp | 9 ++---- source/gameengine/Expressions/Value.cpp | 6 ++-- .../gameengine/GameLogic/SCA_2DFilterActuator.cpp | 9 ++---- source/gameengine/GameLogic/SCA_ANDController.cpp | 9 ++---- source/gameengine/GameLogic/SCA_ActuatorSensor.cpp | 9 ++---- source/gameengine/GameLogic/SCA_AlwaysSensor.cpp | 7 ++-- source/gameengine/GameLogic/SCA_DelaySensor.cpp | 7 ++-- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 7 ++-- source/gameengine/GameLogic/SCA_IObject.cpp | 7 ++-- source/gameengine/GameLogic/SCA_ISensor.cpp | 9 ++---- source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 7 ++-- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 7 ++-- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 9 ++---- source/gameengine/GameLogic/SCA_NANDController.cpp | 9 ++---- source/gameengine/GameLogic/SCA_NORController.cpp | 9 ++---- source/gameengine/GameLogic/SCA_ORController.cpp | 7 ++-- .../gameengine/GameLogic/SCA_PropertyActuator.cpp | 9 ++---- source/gameengine/GameLogic/SCA_PropertySensor.cpp | 9 ++---- .../gameengine/GameLogic/SCA_PythonController.cpp | 7 ++-- source/gameengine/GameLogic/SCA_RandomActuator.cpp | 9 ++---- source/gameengine/GameLogic/SCA_RandomSensor.cpp | 9 ++---- source/gameengine/GameLogic/SCA_XNORController.cpp | 9 ++---- source/gameengine/GameLogic/SCA_XORController.cpp | 9 ++---- source/gameengine/Ketsji/BL_Shader.cpp | 3 +- .../Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp | 9 ++---- .../Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp | 9 ++---- source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 3 +- source/gameengine/Ketsji/KX_CDActuator.cpp | 9 ++---- source/gameengine/Ketsji/KX_Camera.cpp | 37 ++-------------------- source/gameengine/Ketsji/KX_Camera.h | 5 --- source/gameengine/Ketsji/KX_CameraActuator.cpp | 9 ++---- source/gameengine/Ketsji/KX_ConstraintActuator.cpp | 9 ++---- source/gameengine/Ketsji/KX_ConstraintWrapper.cpp | 9 ++---- source/gameengine/Ketsji/KX_GameActuator.cpp | 9 ++---- source/gameengine/Ketsji/KX_GameObject.cpp | 11 ++++--- source/gameengine/Ketsji/KX_IpoActuator.cpp | 9 ++---- source/gameengine/Ketsji/KX_Light.cpp | 33 ++----------------- source/gameengine/Ketsji/KX_Light.h | 1 - source/gameengine/Ketsji/KX_MeshProxy.cpp | 9 ++---- source/gameengine/Ketsji/KX_MouseFocusSensor.cpp | 9 ++---- source/gameengine/Ketsji/KX_NearSensor.cpp | 9 ++---- source/gameengine/Ketsji/KX_ObjectActuator.cpp | 9 ++---- source/gameengine/Ketsji/KX_ParentActuator.cpp | 9 ++---- .../gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp | 9 ++---- source/gameengine/Ketsji/KX_PolyProxy.cpp | 9 ++---- source/gameengine/Ketsji/KX_PolygonMaterial.cpp | 5 +-- source/gameengine/Ketsji/KX_RadarSensor.cpp | 9 ++---- source/gameengine/Ketsji/KX_RaySensor.cpp | 10 +++--- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp | 9 ++---- .../gameengine/Ketsji/KX_SCA_DynamicActuator.cpp | 13 +++----- .../gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp | 9 ++---- .../Ketsji/KX_SCA_ReplaceMeshActuator.cpp | 13 +++----- source/gameengine/Ketsji/KX_Scene.cpp | 9 ++---- source/gameengine/Ketsji/KX_SceneActuator.cpp | 9 ++---- source/gameengine/Ketsji/KX_SoundActuator.cpp | 9 ++---- source/gameengine/Ketsji/KX_StateActuator.cpp | 12 +++---- source/gameengine/Ketsji/KX_TouchSensor.cpp | 9 ++---- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 9 ++---- source/gameengine/Ketsji/KX_VehicleWrapper.cpp | 9 ++---- source/gameengine/Ketsji/KX_VertexProxy.cpp | 9 ++---- source/gameengine/Ketsji/KX_VisibilityActuator.cpp | 13 +++----- 64 files changed, 183 insertions(+), 407 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 22c6c95b158..88f75eac1d5 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -974,13 +974,10 @@ PyTypeObject BL_ActionActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject BL_ActionActuator::Parents[] = { diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index 2e02ee9b941..74953a90bb3 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -431,11 +431,8 @@ PyTypeObject BL_ShapeActionActuator::Type = { __setattr, 0, //&MyPyCompare, __repr, - 0, //&cvalue_as_number, - 0, - 0, - 0, - 0 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject BL_ShapeActionActuator::Parents[] = { diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 90a939af236..aa84cab0266 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -210,6 +210,8 @@ PyTypeObject CListValue::Type = { &instance_as_mapping, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call */ + 0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 494a848be74..417388be464 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -66,12 +66,9 @@ PyTypeObject PyObjectPlus::Type = { __getattr, /*tp_getattr*/ __setattr, /*tp_setattr*/ 0, /*tp_compare*/ - __repr, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call */ + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyObjectPlus::~PyObjectPlus() diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index 2ab0a9addee..36509763454 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -151,10 +151,8 @@ PyTypeObject CValue::Type = { &MyPyCompare, __repr, &cvalue_as_number, - 0, - 0, - 0, - 0 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject CValue::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp index 7bf051f2b5c..0b410728512 100644 --- a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp +++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp @@ -90,12 +90,9 @@ PyTypeObject SCA_2DFilterActuator::Type = { __getattr, __setattr, 0, - __repr, - 0, - 0, - 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; diff --git a/source/gameengine/GameLogic/SCA_ANDController.cpp b/source/gameengine/GameLogic/SCA_ANDController.cpp index b67ef7dabaf..de67037b64a 100644 --- a/source/gameengine/GameLogic/SCA_ANDController.cpp +++ b/source/gameengine/GameLogic/SCA_ANDController.cpp @@ -116,13 +116,10 @@ PyTypeObject SCA_ANDController::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_ANDController::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp index 7f8dbef7758..d5c3e1960fe 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp @@ -131,13 +131,10 @@ PyTypeObject SCA_ActuatorSensor::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_ActuatorSensor::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp index 154f0ad8cef..e2125b8b08d 100644 --- a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp +++ b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp @@ -116,11 +116,8 @@ PyTypeObject SCA_AlwaysSensor::Type = { __setattr, 0, //&MyPyCompare, __repr, - 0, //&cvalue_as_number, - 0, - 0, - 0, - 0 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_AlwaysSensor::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp index 31a620b939d..733057017a7 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp +++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp @@ -142,11 +142,8 @@ PyTypeObject SCA_DelaySensor::Type = { __setattr, 0, //&MyPyCompare, __repr, - 0, //&cvalue_as_number, - 0, - 0, - 0, - 0 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_DelaySensor::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index 49d39f75814..3cefe638726 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -228,11 +228,8 @@ PyTypeObject SCA_ILogicBrick::Type = { __setattr, 0, //&MyPyCompare, __repr, - 0, //&cvalue_as_number, - 0, - 0, - 0, - 0 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp index debd62d44e6..976665a3ccd 100644 --- a/source/gameengine/GameLogic/SCA_IObject.cpp +++ b/source/gameengine/GameLogic/SCA_IObject.cpp @@ -386,11 +386,8 @@ PyTypeObject SCA_IObject::Type = { __setattr, 0, //&MyPyCompare, __repr, - 0, //&cvalue_as_number, - 0, - 0, - 0, - 0 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index e8a072f4c46..0d7dffca17a 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -402,13 +402,10 @@ PyTypeObject SCA_ISensor::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_ISensor::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index c2d90c830cf..6b8779ee37a 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -286,11 +286,8 @@ PyTypeObject SCA_JoystickSensor::Type = { __setattr, 0, //&MyPyCompare, __repr, - 0, //&cvalue_as_number, - 0, - 0, - 0, - 0 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index 324e5eae98a..bf470daa349 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -789,11 +789,8 @@ PyTypeObject SCA_KeyboardSensor::Type = { __setattr, 0, //&MyPyCompare, __repr, - 0, //&cvalue_as_number, - 0, - 0, - 0, - 0 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_KeyboardSensor::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index 57535b29f32..19365fbbb88 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -309,13 +309,10 @@ PyTypeObject SCA_MouseSensor::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_MouseSensor::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_NANDController.cpp b/source/gameengine/GameLogic/SCA_NANDController.cpp index 18426d75582..2bc6a3ef1d6 100644 --- a/source/gameengine/GameLogic/SCA_NANDController.cpp +++ b/source/gameengine/GameLogic/SCA_NANDController.cpp @@ -116,13 +116,10 @@ PyTypeObject SCA_NANDController::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_NANDController::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_NORController.cpp b/source/gameengine/GameLogic/SCA_NORController.cpp index 1de6a641c3d..98ba77df54c 100644 --- a/source/gameengine/GameLogic/SCA_NORController.cpp +++ b/source/gameengine/GameLogic/SCA_NORController.cpp @@ -116,13 +116,10 @@ PyTypeObject SCA_NORController::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_NORController::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_ORController.cpp b/source/gameengine/GameLogic/SCA_ORController.cpp index 61fbc889d90..ba616402ac9 100644 --- a/source/gameengine/GameLogic/SCA_ORController.cpp +++ b/source/gameengine/GameLogic/SCA_ORController.cpp @@ -110,11 +110,8 @@ PyTypeObject SCA_ORController::Type = { __setattr, 0, //&MyPyCompare, __repr, - 0, //&cvalue_as_number, - 0, - 0, - 0, - 0 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_ORController::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index c9ace081bae..28a3b6b822a 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -227,13 +227,10 @@ PyTypeObject SCA_PropertyActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_PropertyActuator::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp index d683c8bb3e7..ef3dbe7e049 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp +++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp @@ -315,13 +315,10 @@ PyTypeObject SCA_PropertySensor::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_PropertySensor::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index c75e36acab2..4ad3f135d31 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -235,11 +235,8 @@ PyTypeObject SCA_PythonController::Type = { __setattr, 0, //&MyPyCompare, __repr, - 0, //&cvalue_as_number, - 0, - 0, - 0, - 0 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_PythonController::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp index d6c73f21f37..78614f9ace3 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp +++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp @@ -321,13 +321,10 @@ PyTypeObject SCA_RandomActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_RandomActuator::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp index 5354c120f52..d88f8f500c0 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp +++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp @@ -136,13 +136,10 @@ PyTypeObject SCA_RandomSensor::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_RandomSensor::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_XNORController.cpp b/source/gameengine/GameLogic/SCA_XNORController.cpp index b2734dd1b33..a9fe906f54e 100644 --- a/source/gameengine/GameLogic/SCA_XNORController.cpp +++ b/source/gameengine/GameLogic/SCA_XNORController.cpp @@ -120,13 +120,10 @@ PyTypeObject SCA_XNORController::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_XNORController::Parents[] = { diff --git a/source/gameengine/GameLogic/SCA_XORController.cpp b/source/gameengine/GameLogic/SCA_XORController.cpp index 662ef523d56..b0053ca17fb 100644 --- a/source/gameengine/GameLogic/SCA_XORController.cpp +++ b/source/gameengine/GameLogic/SCA_XORController.cpp @@ -120,13 +120,10 @@ PyTypeObject SCA_XORController::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject SCA_XORController::Parents[] = { diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index 60cb288436a..14f672bb68f 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -783,7 +783,8 @@ PyTypeObject BL_Shader::Type = { __setattr, 0, __repr, - 0 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp index fa4fdaee972..0a7e20b8650 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp @@ -114,13 +114,10 @@ PyTypeObject KX_NetworkMessageActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_NetworkMessageActuator::Parents[] = { diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp index 40ade460792..d5434a34eb7 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp @@ -177,13 +177,10 @@ PyTypeObject KX_NetworkMessageSensor::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_NetworkMessageSensor::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index b9bd7647f89..668873883af 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -764,7 +764,8 @@ PyTypeObject KX_BlenderMaterial::Type = { __setattr, 0, __repr, - 0 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; diff --git a/source/gameengine/Ketsji/KX_CDActuator.cpp b/source/gameengine/Ketsji/KX_CDActuator.cpp index 98f76dbee54..f86a5669225 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.cpp +++ b/source/gameengine/Ketsji/KX_CDActuator.cpp @@ -167,13 +167,10 @@ PyTypeObject KX_CDActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index 5caac2fc670..cb138efba89 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -487,33 +487,6 @@ PyAttributeDef KX_Camera::Attributes[] = { { NULL } //Sentinel }; -char KX_Camera::doc[] = "Module KX_Camera\n\n" -"Constants:\n" -"\tINSIDE\n" -"\tINTERSECT\n" -"\tOUTSIDE\n" -"Attributes:\n" -"\tlens -> float\n" -"\t\tThe camera's lens value\n" -"\tnear -> float\n" -"\t\tThe camera's near clip distance\n" -"\tfar -> float\n" -"\t\tThe camera's far clip distance\n" -"\tfrustum_culling -> bool\n" -"\t\tNon zero if this camera is frustum culling.\n" -"\tprojection_matrix -> [[float]]\n" -"\t\tThis camera's projection matrix.\n" -"\tmodelview_matrix -> [[float]] (read only)\n" -"\t\tThis camera's model view matrix.\n" -"\t\tRegenerated every frame from the camera's position and orientation.\n" -"\tcamera_to_world -> [[float]] (read only)\n" -"\t\tThis camera's camera to world transform.\n" -"\t\tRegenerated every frame from the camera's position and orientation.\n" -"\tworld_to_camera -> [[float]] (read only)\n" -"\t\tThis camera's world to camera transform.\n" -"\t\tRegenerated every frame from the camera's position and orientation.\n" -"\t\tThis is camera_to_world inverted.\n"; - PyTypeObject KX_Camera::Type = { PyObject_HEAD_INIT(&PyType_Type) 0, @@ -524,14 +497,10 @@ PyTypeObject KX_Camera::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0, 0, 0, 0, 0, 0, - doc + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_Camera::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_Camera.h b/source/gameengine/Ketsji/KX_Camera.h index efd18f99390..b80be9a7fee 100644 --- a/source/gameengine/Ketsji/KX_Camera.h +++ b/source/gameengine/Ketsji/KX_Camera.h @@ -107,11 +107,6 @@ protected: MT_Scalar m_frustum_radius; bool m_set_frustum_center; - /** - * Python module doc string. - */ - static char doc[]; - /** * Extracts the camera clip frames from the projection and world-to-camera matrices. */ diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 65f3aea12f9..08afa2853c3 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -380,13 +380,10 @@ PyTypeObject KX_CameraActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_CameraActuator::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index fba9544d702..31a566f34ad 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -569,13 +569,10 @@ PyTypeObject KX_ConstraintActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_ConstraintActuator::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp index f014c1896fe..05e677b9fd3 100644 --- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp @@ -78,13 +78,10 @@ PyTypeObject KX_ConstraintWrapper::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_ConstraintWrapper::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp index 6799ac7269c..6800c75d807 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.cpp +++ b/source/gameengine/Ketsji/KX_GameActuator.cpp @@ -217,13 +217,10 @@ PyTypeObject KX_GameActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 5c9615c408b..2bd4b2834d1 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1189,17 +1189,20 @@ PyTypeObject KX_GameObject::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, + 0, __repr, - 0, //&cvalue_as_number, 0, - &Mapping, 0, - 0 + &Mapping, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; + + + PyParentObject KX_GameObject::Parents[] = { &KX_GameObject::Type, &SCA_IObject::Type, diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index f6fdce9de0f..5d1d45879c9 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -422,13 +422,10 @@ PyTypeObject KX_IpoActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_IpoActuator::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp index 487b8f30e0d..f71dd69a7a3 100644 --- a/source/gameengine/Ketsji/KX_Light.cpp +++ b/source/gameengine/Ketsji/KX_Light.cpp @@ -306,29 +306,6 @@ PyAttributeDef KX_LightObject::Attributes[] = { { NULL } //Sentinel }; -char KX_LightObject::doc[] = "Module KX_LightObject\n\n" -"Constants:\n" -"\tSPOT\n" -"\tSUN\n" -"\tNORMAL\n" -"Attributes:\n" -"\ttype -> SPOT, SUN or NORMAL\n" -"\t\tThe type of light.\n" -"\tlayer -> integer bit field.\n" -"\t\tThe layers this light applies to.\n" -"\tenergy -> float.\n" -"\t\tThe brightness of the light.\n" -"\tdistance -> float.\n" -"\t\tThe effect radius of the light.\n" -"\tcolour -> list [r, g, b].\n" -"\tcolor -> list [r, g, b].\n" -"\t\tThe color of the light.\n" -"\tlin_attenuation -> float.\n" -"\t\tThe attenuation factor for the light.\n" -"\tspotsize -> float.\n" -"\t\tThe size of the spot.\n" -"\tspotblend -> float.\n" -"\t\tThe blend? of the spot.\n"; PyTypeObject KX_LightObject::Type = { PyObject_HEAD_INIT(&PyType_Type) @@ -340,14 +317,10 @@ PyTypeObject KX_LightObject::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0, 0, 0, 0, 0, 0, - doc + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_LightObject::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_Light.h b/source/gameengine/Ketsji/KX_Light.h index 47edd09b5b9..98dcc8ef873 100644 --- a/source/gameengine/Ketsji/KX_Light.h +++ b/source/gameengine/Ketsji/KX_Light.h @@ -47,7 +47,6 @@ protected: class RAS_IRenderTools* m_rendertools; //needed for registering and replication of lightobj bool m_glsl; Scene* m_blenderscene; - static char doc[]; public: KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,class RAS_IRenderTools* rendertools,const struct RAS_LightObject& lightobj, bool glsl, PyTypeObject *T = &Type); diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index f40c307315e..f349a6b519a 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -55,13 +55,10 @@ PyTypeObject KX_MeshProxy::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_MeshProxy::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index 384034485e7..973dfce505b 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -302,13 +302,10 @@ PyTypeObject KX_MouseFocusSensor::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_MouseFocusSensor::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index 993a6b3d86c..383d673b7ea 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -296,13 +296,10 @@ PyTypeObject KX_NearSensor::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index 0666261b470..ca2157f2bc0 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -286,13 +286,10 @@ PyTypeObject KX_ObjectActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_ObjectActuator::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index 3430fd85184..4c0507cd0bf 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -148,13 +148,10 @@ PyTypeObject KX_ParentActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_ParentActuator::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp index 246c63feb21..4c04a96eae2 100644 --- a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp +++ b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp @@ -128,13 +128,10 @@ PyTypeObject KX_PhysicsObjectWrapper::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_PhysicsObjectWrapper::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp index b4bdd77fb66..27fbe8b19f3 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.cpp +++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp @@ -48,13 +48,10 @@ PyTypeObject KX_PolyProxy::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_PolyProxy::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index bbaf697b168..9e979144c47 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -194,9 +194,10 @@ PyTypeObject KX_PolygonMaterial::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, + 0, __repr, - 0 //&cvalue_as_number, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_PolygonMaterial::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp index fa8998cd81d..91ad60e8cee 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.cpp +++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp @@ -259,13 +259,10 @@ PyTypeObject KX_RadarSensor::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_RadarSensor::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index 253fe11fe05..fdaf48218b3 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -330,13 +330,11 @@ PyTypeObject KX_RaySensor::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, - 0, 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods + }; PyParentObject KX_RaySensor::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index 7c4f60a7f0a..33e74d4dc5a 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -176,13 +176,10 @@ PyTypeObject KX_SCA_AddObjectActuator::Type = { 0, __getattr, __setattr, - 0, - __repr, - 0, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_SCA_AddObjectActuator::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp index 8df3af61721..7dd5301385c 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp @@ -50,9 +50,7 @@ PyTypeObject -KX_SCA_DynamicActuator:: - -Type = { +KX_SCA_DynamicActuator::Type = { PyObject_HEAD_INIT(&PyType_Type) 0, "KX_SCA_DynamicActuator", @@ -62,13 +60,10 @@ Type = { 0, __getattr, __setattr, - 0, - __repr, - 0, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_SCA_DynamicActuator::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp index 9268a1df5f0..6f0bd65ce43 100644 --- a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp @@ -103,13 +103,10 @@ PyTypeObject KX_SCA_EndObjectActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index 58d6f659135..c892af71159 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -52,9 +52,7 @@ PyTypeObject -KX_SCA_ReplaceMeshActuator:: - -Type = { +KX_SCA_ReplaceMeshActuator::Type = { PyObject_HEAD_INIT(&PyType_Type) 0, "KX_SCA_ReplaceMeshActuator", @@ -64,13 +62,10 @@ Type = { 0, __getattr, __setattr, - 0, - __repr, - 0, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_SCA_ReplaceMeshActuator::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index b24b5cd9693..67f6c567549 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1526,13 +1526,10 @@ PyTypeObject KX_Scene::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0, 0, 0, 0, 0, 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_Scene::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index 579c53974d5..595d2cb4070 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -235,13 +235,10 @@ PyTypeObject KX_SceneActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index 6de1d67bfdb..f6c0283d49f 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -242,13 +242,10 @@ PyTypeObject KX_SoundActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; diff --git a/source/gameengine/Ketsji/KX_StateActuator.cpp b/source/gameengine/Ketsji/KX_StateActuator.cpp index 0de4da79bd8..e48c4209923 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.cpp +++ b/source/gameengine/Ketsji/KX_StateActuator.cpp @@ -108,8 +108,7 @@ KX_StateActuator::Update() /* Integration hooks ------------------------------------------------------- */ -PyTypeObject -KX_StateActuator::Type = { +PyTypeObject KX_StateActuator::Type = { PyObject_HEAD_INIT(&PyType_Type) 0, "KX_StateActuator", @@ -119,13 +118,10 @@ KX_StateActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 705b54edd37..b1c22a86f3d 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -251,13 +251,10 @@ PyTypeObject KX_TouchSensor::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_TouchSensor::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index e54528c7bd4..575abc5d748 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -434,13 +434,10 @@ PyTypeObject KX_TrackToActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp index 8d5af1b9216..4960228056a 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp @@ -308,13 +308,10 @@ PyTypeObject KX_VehicleWrapper::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_VehicleWrapper::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp index da0e3dbdd8d..d7b5203795d 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.cpp +++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp @@ -46,13 +46,10 @@ PyTypeObject KX_VertexProxy::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, 0, - 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods }; PyParentObject KX_VertexProxy::Parents[] = { diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp index 6d3c4e79280..10e8c827394 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp @@ -90,8 +90,7 @@ KX_VisibilityActuator::Update() /* Integration hooks ------------------------------------------------------- */ -PyTypeObject -KX_VisibilityActuator::Type = { +PyTypeObject KX_VisibilityActuator::Type = { PyObject_HEAD_INIT(&PyType_Type) 0, "KX_VisibilityActuator", @@ -101,13 +100,11 @@ KX_VisibilityActuator::Type = { 0, __getattr, __setattr, - 0, //&MyPyCompare, - __repr, - 0, //&cvalue_as_number, - 0, - 0, 0, - 0 + __repr, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + Methods + }; PyParentObject -- cgit v1.2.3 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/Converter/BL_ActionActuator.cpp | 32 ++-- source/gameengine/Converter/BL_ActionActuator.h | 4 +- .../Converter/BL_ShapeActionActuator.cpp | 33 ++-- .../gameengine/Converter/BL_ShapeActionActuator.h | 4 +- source/gameengine/Expressions/ListValue.cpp | 17 +- source/gameengine/Expressions/ListValue.h | 2 +- source/gameengine/Expressions/PyObjectPlus.cpp | 54 +++--- source/gameengine/Expressions/PyObjectPlus.h | 50 ++--- source/gameengine/Expressions/Value.cpp | 36 ++-- source/gameengine/Expressions/Value.h | 8 +- .../gameengine/GameLogic/SCA_2DFilterActuator.cpp | 23 ++- source/gameengine/GameLogic/SCA_2DFilterActuator.h | 2 +- source/gameengine/GameLogic/SCA_ANDController.cpp | 17 +- source/gameengine/GameLogic/SCA_ANDController.h | 2 +- source/gameengine/GameLogic/SCA_ActuatorSensor.cpp | 25 +-- source/gameengine/GameLogic/SCA_ActuatorSensor.h | 4 +- source/gameengine/GameLogic/SCA_AlwaysSensor.cpp | 19 +- source/gameengine/GameLogic/SCA_AlwaysSensor.h | 2 +- source/gameengine/GameLogic/SCA_DelaySensor.cpp | 27 +-- source/gameengine/GameLogic/SCA_DelaySensor.h | 4 +- .../GameLogic/SCA_ExpressionController.h | 2 +- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 27 +-- source/gameengine/GameLogic/SCA_ILogicBrick.h | 4 +- source/gameengine/GameLogic/SCA_IObject.cpp | 19 +- source/gameengine/GameLogic/SCA_IObject.h | 2 +- source/gameengine/GameLogic/SCA_ISensor.cpp | 33 ++-- source/gameengine/GameLogic/SCA_ISensor.h | 4 +- source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 43 +++-- source/gameengine/GameLogic/SCA_JoystickSensor.h | 4 +- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 27 +-- source/gameengine/GameLogic/SCA_KeyboardSensor.h | 4 +- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 27 +-- source/gameengine/GameLogic/SCA_MouseSensor.h | 4 +- source/gameengine/GameLogic/SCA_NANDController.cpp | 17 +- source/gameengine/GameLogic/SCA_NANDController.h | 2 +- source/gameengine/GameLogic/SCA_NORController.cpp | 17 +- source/gameengine/GameLogic/SCA_NORController.h | 2 +- source/gameengine/GameLogic/SCA_ORController.cpp | 19 +- source/gameengine/GameLogic/SCA_ORController.h | 2 +- .../gameengine/GameLogic/SCA_PropertyActuator.cpp | 25 +-- source/gameengine/GameLogic/SCA_PropertyActuator.h | 4 +- source/gameengine/GameLogic/SCA_PropertySensor.cpp | 25 +-- source/gameengine/GameLogic/SCA_PropertySensor.h | 4 +- .../gameengine/GameLogic/SCA_PythonController.cpp | 33 ++-- source/gameengine/GameLogic/SCA_PythonController.h | 4 +- source/gameengine/GameLogic/SCA_RandomActuator.cpp | 32 ++-- source/gameengine/GameLogic/SCA_RandomActuator.h | 4 +- source/gameengine/GameLogic/SCA_RandomSensor.cpp | 32 ++-- source/gameengine/GameLogic/SCA_RandomSensor.h | 4 +- source/gameengine/GameLogic/SCA_XNORController.cpp | 17 +- source/gameengine/GameLogic/SCA_XNORController.h | 2 +- source/gameengine/GameLogic/SCA_XORController.cpp | 17 +- source/gameengine/GameLogic/SCA_XORController.h | 2 +- source/gameengine/Ketsji/BL_Shader.cpp | 19 +- source/gameengine/Ketsji/BL_Shader.h | 2 +- .../Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp | 25 +-- .../Ketsji/KXNetwork/KX_NetworkMessageActuator.h | 4 +- .../Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp | 25 +-- .../Ketsji/KXNetwork/KX_NetworkMessageSensor.h | 4 +- source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 23 ++- source/gameengine/Ketsji/KX_BlenderMaterial.h | 4 +- source/gameengine/Ketsji/KX_CDActuator.cpp | 25 +-- source/gameengine/Ketsji/KX_CDActuator.h | 4 +- source/gameengine/Ketsji/KX_Camera.cpp | 60 +++--- source/gameengine/Ketsji/KX_Camera.h | 4 +- source/gameengine/Ketsji/KX_CameraActuator.cpp | 34 ++-- source/gameengine/Ketsji/KX_CameraActuator.h | 4 +- source/gameengine/Ketsji/KX_ConstraintActuator.cpp | 17 +- source/gameengine/Ketsji/KX_ConstraintActuator.h | 2 +- source/gameengine/Ketsji/KX_ConstraintWrapper.cpp | 21 ++- source/gameengine/Ketsji/KX_ConstraintWrapper.h | 4 +- source/gameengine/Ketsji/KX_GameActuator.cpp | 25 +-- source/gameengine/Ketsji/KX_GameActuator.h | 4 +- source/gameengine/Ketsji/KX_GameObject.cpp | 28 +-- source/gameengine/Ketsji/KX_GameObject.h | 6 +- source/gameengine/Ketsji/KX_IpoActuator.cpp | 29 ++- source/gameengine/Ketsji/KX_IpoActuator.h | 4 +- source/gameengine/Ketsji/KX_Light.cpp | 72 ++++---- source/gameengine/Ketsji/KX_Light.h | 4 +- source/gameengine/Ketsji/KX_MeshProxy.cpp | 21 ++- source/gameengine/Ketsji/KX_MeshProxy.h | 2 +- source/gameengine/Ketsji/KX_MouseFocusSensor.cpp | 17 +- source/gameengine/Ketsji/KX_MouseFocusSensor.h | 2 +- source/gameengine/Ketsji/KX_NearSensor.cpp | 25 +-- source/gameengine/Ketsji/KX_NearSensor.h | 4 +- source/gameengine/Ketsji/KX_ObjectActuator.cpp | 17 +- source/gameengine/Ketsji/KX_ObjectActuator.h | 2 +- source/gameengine/Ketsji/KX_ParentActuator.cpp | 25 +-- source/gameengine/Ketsji/KX_ParentActuator.h | 4 +- .../gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp | 25 ++- source/gameengine/Ketsji/KX_PhysicsObjectWrapper.h | 4 +- source/gameengine/Ketsji/KX_PolyProxy.cpp | 38 ++-- source/gameengine/Ketsji/KX_PolyProxy.h | 2 +- source/gameengine/Ketsji/KX_PolygonMaterial.cpp | 81 ++++---- source/gameengine/Ketsji/KX_PolygonMaterial.h | 4 +- source/gameengine/Ketsji/KX_PythonInit.cpp | 6 +- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 204 +++++++++++++++++++++ source/gameengine/Ketsji/KX_PythonInitTypes.h | 35 ++++ source/gameengine/Ketsji/KX_RadarSensor.cpp | 25 +-- source/gameengine/Ketsji/KX_RadarSensor.h | 4 +- source/gameengine/Ketsji/KX_RaySensor.cpp | 25 +-- source/gameengine/Ketsji/KX_RaySensor.h | 4 +- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp | 26 +-- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.h | 4 +- .../gameengine/Ketsji/KX_SCA_DynamicActuator.cpp | 25 +-- source/gameengine/Ketsji/KX_SCA_DynamicActuator.h | 4 +- .../gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp | 17 +- .../gameengine/Ketsji/KX_SCA_EndObjectActuator.h | 2 +- .../Ketsji/KX_SCA_ReplaceMeshActuator.cpp | 26 +-- .../gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h | 4 +- source/gameengine/Ketsji/KX_Scene.cpp | 37 ++-- source/gameengine/Ketsji/KX_Scene.h | 8 +- source/gameengine/Ketsji/KX_SceneActuator.cpp | 25 +-- source/gameengine/Ketsji/KX_SceneActuator.h | 4 +- source/gameengine/Ketsji/KX_SoundActuator.cpp | 17 +- source/gameengine/Ketsji/KX_SoundActuator.h | 2 +- source/gameengine/Ketsji/KX_StateActuator.cpp | 17 +- source/gameengine/Ketsji/KX_StateActuator.h | 2 +- source/gameengine/Ketsji/KX_TouchSensor.cpp | 37 ++-- source/gameengine/Ketsji/KX_TouchSensor.h | 4 +- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 25 +-- source/gameengine/Ketsji/KX_TrackToActuator.h | 4 +- source/gameengine/Ketsji/KX_VehicleWrapper.cpp | 22 ++- source/gameengine/Ketsji/KX_VehicleWrapper.h | 4 +- source/gameengine/Ketsji/KX_VertexProxy.cpp | 82 +++++---- source/gameengine/Ketsji/KX_VertexProxy.h | 4 +- source/gameengine/Ketsji/KX_VisibilityActuator.cpp | 25 +-- source/gameengine/Ketsji/KX_VisibilityActuator.h | 4 +- 128 files changed, 1384 insertions(+), 905 deletions(-) create mode 100644 source/gameengine/Ketsji/KX_PythonInitTypes.cpp create mode 100644 source/gameengine/Ketsji/KX_PythonInitTypes.h (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 88f75eac1d5..943bb68f6f2 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -965,18 +965,21 @@ KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel, /* ------------------------------------------------------------------------- */ PyTypeObject BL_ActionActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "BL_ActionActuator", sizeof(BL_ActionActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -1032,17 +1035,20 @@ PyAttributeDef BL_ActionActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* BL_ActionActuator::_getattr(const char *attr) { - if (!strcmp(attr, "action")) +PyObject* BL_ActionActuator::py_getattro(PyObject *attr) { + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "action")) return PyString_FromString(m_action->id.name+2); - PyObject* object = _getattr_self(Attributes, this, attr); + + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int BL_ActionActuator::_setattr(const char *attr, PyObject* value) { - if (!strcmp(attr, "action")) +int BL_ActionActuator::py_setattro(PyObject *attr, PyObject* value) { + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "action")) { if (!PyString_Check(value)) { @@ -1072,8 +1078,8 @@ int BL_ActionActuator::_setattr(const char *attr, PyObject* value) { m_action = action; return 0; } - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(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 6161048afb8..7160dd4dad0 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 char *attr); - virtual int _setattr(const char *attr, PyObject* value); + virtual PyObject* py_getattro(PyObject* attr); + virtual int py_setattro(PyObject* attr, PyObject* value); /* attribute check */ static int CheckFrame(void *self, const PyAttributeDef*) diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index 74953a90bb3..c53be4653ca 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -420,18 +420,21 @@ bool BL_ShapeActionActuator::Update(double curtime, bool frame) /* Integration hooks ------------------------------------------------------- */ PyTypeObject BL_ShapeActionActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "BL_ShapeActionActuator", sizeof(BL_ShapeActionActuator), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -481,17 +484,19 @@ PyAttributeDef BL_ShapeActionActuator::Attributes[] = { }; -PyObject* BL_ShapeActionActuator::_getattr(const char *attr) { - if (!strcmp(attr, "action")) +PyObject* BL_ShapeActionActuator::py_getattro(PyObject* attr) { + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "action")) return PyString_FromString(m_action->id.name+2); - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int BL_ShapeActionActuator::_setattr(const char *attr, PyObject* value) { - if (!strcmp(attr, "action")) +int BL_ShapeActionActuator::py_setattro(PyObject *attr, PyObject* value) { + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "action")) { if (!PyString_Check(value)) { @@ -521,10 +526,10 @@ int BL_ShapeActionActuator::_setattr(const char *attr, PyObject* value) { m_action = action; return 0; } - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } /* setStart */ diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.h b/source/gameengine/Converter/BL_ShapeActionActuator.h index 7f2431bcfa5..ea25d66e050 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 char *attr); - virtual int _setattr(const char *attr, PyObject* value); + virtual PyObject* py_getattro(PyObject* attr); + virtual int py_setattro(PyObject* 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 aa84cab0266..15eb8835b79 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -193,7 +193,7 @@ static PyMappingMethods instance_as_mapping = { PyTypeObject CListValue::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "CListValue", /*tp_name*/ sizeof(CListValue), /*tp_basicsize*/ @@ -201,16 +201,19 @@ PyTypeObject CListValue::Type = { /* methods */ PyDestructor, /*tp_dealloc*/ 0, /*tp_print*/ - __getattr, /*tp_getattr*/ - __setattr, /*tp_setattr*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ 0, /*tp_compare*/ - __repr, /*tp_repr*/ + py_base_repr, /*tp_repr*/ 0, /*tp_as_number*/ &listvalue_as_sequence, /*tp_as_sequence*/ &instance_as_mapping, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call */ - 0,0,0,0,0,0,0,0,0,0,0,0, + 0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -238,8 +241,8 @@ PyAttributeDef CListValue::Attributes[] = { { NULL } //Sentinel }; -PyObject* CListValue::_getattr(const char *attr) { - _getattr_up(CValue); +PyObject* CListValue::py_getattro(PyObject* attr) { + py_getattro_up(CValue); } diff --git a/source/gameengine/Expressions/ListValue.h b/source/gameengine/Expressions/ListValue.h index 104e3e63283..f936298a8c4 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 char *attr); + virtual PyObject* py_getattro(PyObject* attr); KX_PYMETHOD_O(CListValue,append); KX_PYMETHOD_NOARGS(CListValue,reverse); diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 417388be464..ed6932b414a 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -55,19 +55,22 @@ ------------------------------*/ PyTypeObject PyObjectPlus::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "PyObjectPlus", /*tp_name*/ sizeof(PyObjectPlus), /*tp_basicsize*/ 0, /*tp_itemsize*/ /* methods */ - PyDestructor, /*tp_dealloc*/ - 0, /*tp_print*/ - __getattr, /*tp_getattr*/ - __setattr, /*tp_setattr*/ - 0, /*tp_compare*/ - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + PyDestructor, + 0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -103,37 +106,41 @@ PyParentObject PyObjectPlus::Parents[] = {&PyObjectPlus::Type, NULL}; /*------------------------------ * PyObjectPlus attributes -- attributes ------------------------------*/ -PyObject *PyObjectPlus::_getattr(const char *attr) +PyObject *PyObjectPlus::py_getattro(PyObject* attr) { - if (!strcmp(attr, "__doc__") && GetType()->tp_doc) - return PyString_FromString(GetType()->tp_doc); - + PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \ + if (descr == NULL) { + PyErr_SetString(PyExc_AttributeError, "attribute not found"); + return NULL; + } else { + return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); \ + } //if (streq(attr, "type")) // return Py_BuildValue("s", (*(GetParents()))->tp_name); - - return Py_FindMethod(Methods, this, attr); } -int PyObjectPlus::_delattr(const char *attr) +int PyObjectPlus::py_delattro(PyObject* attr) { PyErr_SetString(PyExc_AttributeError, "attribute cant be deleted"); return 1; } -int PyObjectPlus::_setattr(const char *attr, PyObject *value) +int PyObjectPlus::py_setattro(PyObject *attr, PyObject* value) { - //return PyObject::_setattr(attr,value); + //return PyObject::py_setattro(attr,value); //cerr << "Unknown attribute" << endl; PyErr_SetString(PyExc_AttributeError, "attribute cant be set"); return 1; } -PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *self, const char *attr) +PyObject *PyObjectPlus::py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr) { + char *attr_str= PyString_AsString(attr); + const PyAttributeDef *attrdef; for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++) { - if (!strcmp(attr, attrdef->m_name)) + if (!strcmp(attr_str, attrdef->m_name)) { if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY) { @@ -242,16 +249,17 @@ PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *sel return NULL; } -int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, const char *attr, PyObject *value) +int PyObjectPlus::py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value) { const PyAttributeDef *attrdef; void *undoBuffer = NULL; void *sourceBuffer = NULL; size_t bufferSize = 0; + char *attr_str= PyString_AsString(attr); for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++) { - if (!strcmp(attr, attrdef->m_name)) + if (!strcmp(attr_str, attrdef->m_name)) { if (attrdef->m_access == KX_PYATTRIBUTE_RO || attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY) @@ -684,7 +692,7 @@ int PyObjectPlus::_setattr_self(const PyAttributeDef attrlist[], void *self, con /*------------------------------ * PyObjectPlus repr -- representations ------------------------------*/ -PyObject *PyObjectPlus::_repr(void) +PyObject *PyObjectPlus::py_repr(void) { PyErr_SetString(PyExc_SystemError, "Representation not overridden by object."); return NULL; @@ -726,7 +734,7 @@ PyObject *PyObjectPlus::Py_isA(PyObject *value) // Python wrapper for isA Py_RETURN_FALSE; } -/* Utility function called by the macro _getattr_up() +/* Utility function called by the macro py_getattro_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. diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 345eb8c9c3f..77963c092eb 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -72,6 +72,8 @@ typedef int Py_ssize_t; #define PY_METHODCHAR const char * #endif +#include "descrobject.h" + static inline void Py_Fatal(const char *M) { fprintf(stderr, "%s\n", M); exit(-1); @@ -90,21 +92,27 @@ static inline void Py_Fatal(const char *M) { - // This defines the _getattr_up macro + // This defines the py_getattro_up macro // which allows attribute and method calls // to be properly passed up the hierarchy. -#define _getattr_up(Parent) \ - PyObject *rvalue = Py_FindMethod(Methods, this, attr); \ + +#define py_getattro_up(Parent) \ + PyObject *rvalue; \ + PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \ \ - if (rvalue == NULL) { \ + if (descr == NULL) { \ PyErr_Clear(); \ - rvalue = Parent::_getattr(attr); \ + rvalue = Parent::py_getattro(attr); \ + } else { \ + rvalue= PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); \ } \ - if (strcmp(attr, "__dict__")==0) {\ + \ + if (strcmp(PyString_AsString(attr), "__dict__")==0) {\ rvalue = _getattr_dict(rvalue, Methods, Attributes); \ } \ return rvalue; \ + /** * These macros are helpfull when embedding Python routines. The second * macro is one that also requires a documentation string @@ -361,29 +369,29 @@ public: // Py_DECREF(this); // }; // decref method - virtual PyObject *_getattr(const char *attr); // _getattr method - static PyObject *__getattr(PyObject * PyObj, char *attr) // This should be the entry in Type. + virtual PyObject *py_getattro(PyObject *attr); // py_getattro method + static PyObject *py_base_getattro(PyObject * PyObj, PyObject *attr) // This should be the entry in Type. { - return ((PyObjectPlus*) PyObj)->_getattr(attr); + return ((PyObjectPlus*) PyObj)->py_getattro(attr); } - 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); + static PyObject *py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr); + static int py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value); - 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, + virtual int py_delattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method + static int py_base_setattro(PyObject *PyObj, // This should be the entry in Type. + PyObject *attr, PyObject *value) { - if (!value) - return ((PyObjectPlus*) PyObj)->_delattr(attr); - return ((PyObjectPlus*) PyObj)->_setattr(attr, value); + if (value==NULL) + return ((PyObjectPlus*) PyObj)->py_delattro(attr); + return ((PyObjectPlus*) PyObj)->py_setattro(attr, value); } - virtual PyObject *_repr(void); // _repr method - static PyObject *__repr(PyObject *PyObj) // This should be the entry in Type. + virtual PyObject *py_repr(void); // py_repr method + static PyObject *py_base_repr(PyObject *PyObj) // This should be the entry in Type. { - return ((PyObjectPlus*) PyObj)->_repr(); + return ((PyObjectPlus*) PyObj)->py_repr(); } // isA methods diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index 36509763454..8b910b9038b 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -139,19 +139,22 @@ static PyNumberMethods cvalue_as_number = { PyTypeObject CValue::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "CValue", sizeof(CValue), 0, PyDestructor, 0, - __getattr, - __setattr, + 0, + 0, &MyPyCompare, - __repr, + py_base_repr, &cvalue_as_number, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -695,9 +698,10 @@ PyAttributeDef CValue::Attributes[] = { }; -PyObject* CValue::_getattr(const char *attr) +PyObject* CValue::py_getattro(PyObject *attr) { - CValue* resultattr = GetProperty(attr); + char *attr_str= PyString_AsString(attr); + CValue* resultattr = GetProperty(attr_str); if (resultattr) { PyObject* pyconvert = resultattr->ConvertValueToPython(); @@ -707,7 +711,7 @@ PyObject* CValue::_getattr(const char *attr) else return resultattr; // also check if it's already in pythoninterpreter! } - _getattr_up(PyObjectPlus); + py_getattro_up(PyObjectPlus); } CValue* CValue::ConvertPythonToValue(PyObject* pyobj) @@ -769,26 +773,28 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj) } -int CValue::_delattr(const char *attr) +int CValue::py_delattro(PyObject *attr) { - if (RemoveProperty(STR_String(attr))) + char *attr_str= PyString_AsString(attr); + if (RemoveProperty(STR_String(attr_str))) return 0; - PyErr_Format(PyExc_AttributeError, "attribute \"%s\" dosnt exist", attr); + PyErr_Format(PyExc_AttributeError, "attribute \"%s\" dosnt exist", attr_str); return 1; } -int CValue::_setattr(const char *attr, PyObject* pyobj) +int CValue::py_setattro(PyObject *attr, PyObject* pyobj) { CValue* vallie = ConvertPythonToValue(pyobj); if (vallie) { - CValue* oldprop = GetProperty(attr); + char *attr_str= PyString_AsString(attr); + CValue* oldprop = GetProperty(attr_str); if (oldprop) oldprop->SetValue(vallie); else - SetProperty(attr, vallie); + SetProperty(attr_str, vallie); vallie->Release(); } else @@ -796,7 +802,7 @@ int CValue::_setattr(const char *attr, PyObject* pyobj) return 1; /* ConvertPythonToValue sets the error message */ } - //PyObjectPlus::_setattr(attr,value); + //PyObjectPlus::py_setattro(attr,value); return 0; }; diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h index 4678ab1f0c2..7a2816a9778 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/Value.h @@ -217,14 +217,14 @@ public: CValue(PyTypeObject *T = &Type); //static PyObject* PyMake(PyObject*,PyObject*); - virtual PyObject *_repr(void) + virtual PyObject *py_repr(void) { return Py_BuildValue("s",(const char*)GetText()); } - virtual PyObject* _getattr(const char *attr); + virtual PyObject* py_getattro(PyObject *attr); void SpecialRelease() { @@ -251,8 +251,8 @@ public: virtual CValue* ConvertPythonToValue(PyObject* pyobj); - virtual int _delattr(const char *attr); - virtual int _setattr(const char *attr, PyObject* value); + virtual int py_delattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject* value); virtual PyObject* ConvertKeysToPython( void ); diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp index 0b410728512..9d4dc1f33d6 100644 --- a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp +++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp @@ -80,18 +80,21 @@ bool SCA_2DFilterActuator::Update() PyTypeObject SCA_2DFilterActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_2DFilterActuator", sizeof(SCA_2DFilterActuator), 0, - PyDestructor, - 0, - __getattr, - __setattr, - 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + PyDestructor, + 0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -114,6 +117,6 @@ PyAttributeDef SCA_2DFilterActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_2DFilterActuator::_getattr(const char *attr) { - _getattr_up(SCA_IActuator); +PyObject* SCA_2DFilterActuator::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IActuator); } diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.h b/source/gameengine/GameLogic/SCA_2DFilterActuator.h index 9da0500afff..f69c680b774 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 char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; #endif diff --git a/source/gameengine/GameLogic/SCA_ANDController.cpp b/source/gameengine/GameLogic/SCA_ANDController.cpp index de67037b64a..cb62e2b5a1d 100644 --- a/source/gameengine/GameLogic/SCA_ANDController.cpp +++ b/source/gameengine/GameLogic/SCA_ANDController.cpp @@ -107,18 +107,21 @@ CValue* SCA_ANDController::GetReplica() /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_ANDController::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_ANDController", sizeof(SCA_ANDController), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -138,8 +141,8 @@ PyAttributeDef SCA_ANDController::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_ANDController::_getattr(const char *attr) { - _getattr_up(SCA_IController); +PyObject* SCA_ANDController::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IController); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_ANDController.h b/source/gameengine/GameLogic/SCA_ANDController.h index eba7e1b545a..fdb93d0fc42 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 char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp index d5c3e1960fe..ed7aa66d04b 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp @@ -122,18 +122,21 @@ void SCA_ActuatorSensor::Update() /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_ActuatorSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_ActuatorSensor", sizeof(SCA_ActuatorSensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -158,11 +161,11 @@ PyAttributeDef SCA_ActuatorSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_ActuatorSensor::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* SCA_ActuatorSensor::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_ISensor); /* implicit return! */ + py_getattro_up(SCA_ISensor); /* implicit return! */ } int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*) @@ -177,11 +180,11 @@ int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*) return 1; } -int SCA_ActuatorSensor::_setattr(const char *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); +int SCA_ActuatorSensor::py_setattro(PyObject *attr, PyObject *value) { + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } /* 3. getActuator */ diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.h b/source/gameengine/GameLogic/SCA_ActuatorSensor.h index 75ee08f42d6..9bc873e4ee1 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 char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 e2125b8b08d..a7b0e5a14d2 100644 --- a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp +++ b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp @@ -105,18 +105,21 @@ bool SCA_AlwaysSensor::Evaluate(CValue* event) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_AlwaysSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_AlwaysSensor", sizeof(SCA_AlwaysSensor), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -136,8 +139,8 @@ PyAttributeDef SCA_AlwaysSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_AlwaysSensor::_getattr(const char *attr) { - _getattr_up(SCA_ISensor); +PyObject* SCA_AlwaysSensor::py_getattro(PyObject *attr) { + py_getattro_up(SCA_ISensor); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.h b/source/gameengine/GameLogic/SCA_AlwaysSensor.h index ebe6ba80208..87949babf59 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 char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp index 733057017a7..5082caacfd5 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp +++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp @@ -131,18 +131,21 @@ bool SCA_DelaySensor::Evaluate(CValue* event) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_DelaySensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_DelaySensor", sizeof(SCA_DelaySensor), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -175,18 +178,18 @@ PyAttributeDef SCA_DelaySensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_DelaySensor::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* SCA_DelaySensor::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_ISensor); + py_getattro_up(SCA_ISensor); } -int SCA_DelaySensor::_setattr(const char *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); +int SCA_DelaySensor::py_setattro(PyObject *attr, PyObject *value) { + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.h b/source/gameengine/GameLogic/SCA_DelaySensor.h index 491eee61da8..f9e3d619198 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 char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 79c26eea1e7..2936742be19 100644 --- a/source/gameengine/GameLogic/SCA_ExpressionController.h +++ b/source/gameengine/GameLogic/SCA_ExpressionController.h @@ -59,7 +59,7 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ -// virtual PyObject* _getattr(const char *attr); +// virtual PyObject* py_getattro(PyObject *attr); }; diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index 3cefe638726..45ebd874ea5 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -217,18 +217,21 @@ CValue* SCA_ILogicBrick::GetEvent() /* python stuff */ PyTypeObject SCA_ILogicBrick::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_ILogicBrick", sizeof(SCA_ILogicBrick), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -275,20 +278,20 @@ int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef) } PyObject* -SCA_ILogicBrick::_getattr(const char *attr) +SCA_ILogicBrick::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(CValue); + py_getattro_up(CValue); } -int SCA_ILogicBrick::_setattr(const char *attr, PyObject *value) +int SCA_ILogicBrick::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return CValue::_setattr(attr, value); + return CValue::py_setattro(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h index 70d49941613..c098f9dfd8a 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.h +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h @@ -79,8 +79,8 @@ public: virtual bool LessComparedTo(SCA_ILogicBrick* other); - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 976665a3ccd..d1ce377316b 100644 --- a/source/gameengine/GameLogic/SCA_IObject.cpp +++ b/source/gameengine/GameLogic/SCA_IObject.cpp @@ -375,18 +375,21 @@ void SCA_IObject::SetState(unsigned int state) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_IObject::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_IObject", sizeof(SCA_IObject), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -411,7 +414,7 @@ PyAttributeDef SCA_IObject::Attributes[] = { }; -PyObject* SCA_IObject::_getattr(const char *attr) { - _getattr_up(CValue); +PyObject* SCA_IObject::py_getattro(PyObject *attr) { + py_getattro_up(CValue); } diff --git a/source/gameengine/GameLogic/SCA_IObject.h b/source/gameengine/GameLogic/SCA_IObject.h index d47353b1ac0..44ed3c8f3fe 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 char *attr); + virtual PyObject* py_getattro(PyObject *attr); virtual int GetGameObjectType() {return -1;} diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index 0d7dffca17a..8a40c0c35f3 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -393,18 +393,21 @@ KX_PYMETHODDEF_DOC_NOARGS(SCA_ISensor, reset, /* ----------------------------------------------- */ PyTypeObject SCA_ISensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_ISensor", sizeof(SCA_ISensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -451,38 +454,40 @@ PyAttributeDef SCA_ISensor::Attributes[] = { 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 + // make these properties read-only in _setaddr, must still implement them in py_getattro KX_PYATTRIBUTE_DUMMY("triggered"), KX_PYATTRIBUTE_DUMMY("positive"), { NULL } //Sentinel }; PyObject* -SCA_ISensor::_getattr(const char *attr) +SCA_ISensor::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - if (!strcmp(attr, "triggered")) + + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "triggered")) { int retval = 0; if (SCA_PythonController::m_sCurrentController) retval = SCA_PythonController::m_sCurrentController->IsTriggered(this); return PyInt_FromLong(retval); } - if (!strcmp(attr, "positive")) + if (!strcmp(attr_str, "positive")) { int retval = IsPositiveTrigger(); return PyInt_FromLong(retval); } - _getattr_up(SCA_ILogicBrick); + py_getattro_up(SCA_ILogicBrick); } -int SCA_ISensor::_setattr(const char *attr, PyObject *value) +int SCA_ISensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ILogicBrick::_setattr(attr, value); + return SCA_ILogicBrick::py_setattro(attr, value); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h index 23f2c76c19f..ce7b66df1cd 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.h +++ b/source/gameengine/GameLogic/SCA_ISensor.h @@ -136,8 +136,8 @@ public: /* Python functions: */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 6b8779ee37a..0cfd6843c1b 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -275,18 +275,21 @@ bool SCA_JoystickSensor::isValid(SCA_JoystickSensor::KX_JOYSENSORMODE m) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_JoystickSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_JoystickSensor", sizeof(SCA_JoystickSensor), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -330,8 +333,8 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = { KX_PYATTRIBUTE_INT_RW("button",0,100,false,SCA_JoystickSensor,m_button), 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 + // dummy attributes will just be read-only in py_setattro + // you still need to defined them in py_getattro KX_PYATTRIBUTE_DUMMY("axisPosition"), KX_PYATTRIBUTE_DUMMY("numAxis"), KX_PYATTRIBUTE_DUMMY("numButtons"), @@ -340,38 +343,40 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_JoystickSensor::_getattr(const char *attr) { +PyObject* SCA_JoystickSensor::py_getattro(PyObject *attr) { SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); - if (!strcmp(attr, "axisPosition")) { + char *attr_str= PyString_AsString(attr); + + if (!strcmp(attr_str, "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 (!strcmp(attr, "numAxis")) { + if (!strcmp(attr_str, "numAxis")) { return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 ); } - if (!strcmp(attr, "numButtons")) { + if (!strcmp(attr_str, "numButtons")) { return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 ); } - if (!strcmp(attr, "numHats")) { + if (!strcmp(attr_str, "numHats")) { return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 ); } - if (!strcmp(attr, "connected")) { + if (!strcmp(attr_str, "connected")) { return PyBool_FromLong( joy ? joy->Connected() : 0 ); } - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_ISensor); + py_getattro_up(SCA_ISensor); } -int SCA_JoystickSensor::_setattr(const char *attr, PyObject *value) +int SCA_JoystickSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.h b/source/gameengine/GameLogic/SCA_JoystickSensor.h index 49d220c056d..ccdd2107b21 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 char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 bf470daa349..fc1b5be3540 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -778,18 +778,21 @@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus, /* ------------------------------------------------------------------------- */ PyTypeObject SCA_KeyboardSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_KeyboardSensor", sizeof(SCA_KeyboardSensor), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -828,18 +831,18 @@ PyAttributeDef SCA_KeyboardSensor::Attributes[] = { }; PyObject* -SCA_KeyboardSensor::_getattr(const char *attr) +SCA_KeyboardSensor::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_ISensor); + py_getattro_up(SCA_ISensor); } -int SCA_KeyboardSensor::_setattr(const char *attr, PyObject *value) +int SCA_KeyboardSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.h b/source/gameengine/GameLogic/SCA_KeyboardSensor.h index bc2f86327a5..c579b6a82f8 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 char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 19365fbbb88..c5f6fdabbe8 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -102,7 +102,7 @@ int SCA_MouseSensor::UpdateHotkey(void *self, const PyAttributeDef*) default: ; /* ignore, no hotkey */ } - // return value is used in _setattr(), + // return value is used in py_setattro(), // 0=attribute checked ok (see Attributes array definition) return 0; } @@ -300,18 +300,21 @@ KX_PYMETHODDEF_DOC_O(SCA_MouseSensor, getButtonStatus, /* ------------------------------------------------------------------------- */ PyTypeObject SCA_MouseSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_MouseSensor", sizeof(SCA_MouseSensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -338,20 +341,20 @@ PyAttributeDef SCA_MouseSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_MouseSensor::_getattr(const char *attr) +PyObject* SCA_MouseSensor::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_ISensor); + py_getattro_up(SCA_ISensor); } -int SCA_MouseSensor::_setattr(const char *attr, PyObject *value) +int SCA_MouseSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.h b/source/gameengine/GameLogic/SCA_MouseSensor.h index 30b43fe53cc..73410569cc2 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 char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 2bc6a3ef1d6..bddd5f4d3ab 100644 --- a/source/gameengine/GameLogic/SCA_NANDController.cpp +++ b/source/gameengine/GameLogic/SCA_NANDController.cpp @@ -107,18 +107,21 @@ CValue* SCA_NANDController::GetReplica() /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_NANDController::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_NANDController", sizeof(SCA_NANDController), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -138,8 +141,8 @@ PyAttributeDef SCA_NANDController::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_NANDController::_getattr(const char *attr) { - _getattr_up(SCA_IController); +PyObject* SCA_NANDController::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IController); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_NANDController.h b/source/gameengine/GameLogic/SCA_NANDController.h index d88504cfc0d..11600914a1a 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 char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; diff --git a/source/gameengine/GameLogic/SCA_NORController.cpp b/source/gameengine/GameLogic/SCA_NORController.cpp index 98ba77df54c..3ee073523c3 100644 --- a/source/gameengine/GameLogic/SCA_NORController.cpp +++ b/source/gameengine/GameLogic/SCA_NORController.cpp @@ -107,18 +107,21 @@ CValue* SCA_NORController::GetReplica() /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_NORController::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_NORController", sizeof(SCA_NORController), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -138,8 +141,8 @@ PyAttributeDef SCA_NORController::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_NORController::_getattr(const char *attr) { - _getattr_up(SCA_IController); +PyObject* SCA_NORController::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IController); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_NORController.h b/source/gameengine/GameLogic/SCA_NORController.h index 45b639f3f3f..fc814e28d37 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 char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; diff --git a/source/gameengine/GameLogic/SCA_ORController.cpp b/source/gameengine/GameLogic/SCA_ORController.cpp index ba616402ac9..91d5e56d4f3 100644 --- a/source/gameengine/GameLogic/SCA_ORController.cpp +++ b/source/gameengine/GameLogic/SCA_ORController.cpp @@ -99,18 +99,21 @@ void SCA_ORController::Trigger(SCA_LogicManager* logicmgr) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_ORController::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_ORController", sizeof(SCA_ORController), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -131,8 +134,8 @@ PyAttributeDef SCA_ORController::Attributes[] = { }; -PyObject* SCA_ORController::_getattr(const char *attr) { - _getattr_up(SCA_IController); +PyObject* SCA_ORController::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IController); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_ORController.h b/source/gameengine/GameLogic/SCA_ORController.h index 9a6e9e75022..fdc81486e74 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 char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; #endif //__KX_ORCONTROLLER diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index 28a3b6b822a..e1f303430ec 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -218,18 +218,21 @@ void SCA_PropertyActuator::Relink(GEN_Map *obj_map) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_PropertyActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_PropertyActuator", sizeof(SCA_PropertyActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -257,18 +260,18 @@ PyAttributeDef SCA_PropertyActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_PropertyActuator::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* SCA_PropertyActuator::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int SCA_PropertyActuator::_setattr(const char *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); +int SCA_PropertyActuator::py_setattro(PyObject *attr, PyObject *value) { + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } /* 1. setProperty */ diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.h b/source/gameengine/GameLogic/SCA_PropertyActuator.h index 444d9285796..6a975716ed0 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 char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 ef3dbe7e049..659823f6fba 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp +++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp @@ -306,18 +306,21 @@ int SCA_PropertySensor::validValueForProperty(void *self, const PyAttributeDef*) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_PropertySensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_PropertySensor", sizeof(SCA_PropertySensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -349,18 +352,18 @@ PyAttributeDef SCA_PropertySensor::Attributes[] = { }; -PyObject* SCA_PropertySensor::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* SCA_PropertySensor::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_ISensor); /* implicit return! */ + py_getattro_up(SCA_ISensor); /* implicit return! */ } -int SCA_PropertySensor::_setattr(const char *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); +int SCA_PropertySensor::py_setattro(PyObject *attr, PyObject *value) { + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } /* 1. getType */ diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.h b/source/gameengine/GameLogic/SCA_PropertySensor.h index 2594e3fca9d..076c1ae51ec 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.h +++ b/source/gameengine/GameLogic/SCA_PropertySensor.h @@ -89,8 +89,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 4ad3f135d31..2d200e0a238 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -224,18 +224,21 @@ const char* SCA_PythonController::sPyAddActiveActuator__doc__= "addActiveActuato const char SCA_PythonController::GetActuators_doc[] = "getActuator"; PyTypeObject SCA_PythonController::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_PythonController", sizeof(SCA_PythonController), 0, PyDestructor, 0, - __getattr, - __setattr, - 0, //&MyPyCompare, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -369,24 +372,26 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) -PyObject* SCA_PythonController::_getattr(const char *attr) +PyObject* SCA_PythonController::py_getattro(PyObject *attr) { - if (!strcmp(attr,"state")) { + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str,"state")) { return PyInt_FromLong(m_statemask); } - if (!strcmp(attr,"script")) { + if (!strcmp(attr_str,"script")) { return PyString_FromString(m_scriptText); } - _getattr_up(SCA_IController); + py_getattro_up(SCA_IController); } -int SCA_PythonController::_setattr(const char *attr, PyObject *value) +int SCA_PythonController::py_setattro(PyObject *attr, PyObject *value) { - if (!strcmp(attr,"state")) { + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str,"state")) { PyErr_SetString(PyExc_AttributeError, "state is read only"); return 1; } - if (!strcmp(attr,"script")) { + if (!strcmp(attr_str,"script")) { char *scriptArg = PyString_AsString(value); if (scriptArg==NULL) { @@ -400,7 +405,7 @@ int SCA_PythonController::_setattr(const char *attr, PyObject *value) return 1; } - return SCA_IController::_setattr(attr, value); + return SCA_IController::py_setattro(attr, value); } PyObject* SCA_PythonController::PyActivate(PyObject* self, PyObject *value) diff --git a/source/gameengine/GameLogic/SCA_PythonController.h b/source/gameengine/GameLogic/SCA_PythonController.h index 4ec18f32c23..3348071c00f 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.h +++ b/source/gameengine/GameLogic/SCA_PythonController.h @@ -78,8 +78,8 @@ class SCA_PythonController : public SCA_IController 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); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); KX_PYMETHOD_O(SCA_PythonController,Activate); diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp index 78614f9ace3..a9a664b0686 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp +++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp @@ -312,18 +312,21 @@ void SCA_RandomActuator::enforceConstraints() { /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_RandomActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_RandomActuator", sizeof(SCA_RandomActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -366,22 +369,25 @@ PyAttributeDef SCA_RandomActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_RandomActuator::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* SCA_RandomActuator::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - if (!strcmp(attr, "seed")) { + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "seed")) { return PyInt_FromLong(m_base->GetSeed()); } - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int SCA_RandomActuator::_setattr(const char *attr, PyObject *value) +int SCA_RandomActuator::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - if (!strcmp(attr, "seed")) { + + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "seed")) { if (PyInt_Check(value)) { int ival = PyInt_AsLong(value); m_base->SetSeed(ival); @@ -391,7 +397,7 @@ int SCA_RandomActuator::_setattr(const char *attr, PyObject *value) return 1; } } - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } /* 1. setSeed */ diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.h b/source/gameengine/GameLogic/SCA_RandomActuator.h index 0d404fa8a9f..96ca353257f 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 char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 d88f8f500c0..84a9ef95e84 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp +++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp @@ -127,18 +127,21 @@ bool SCA_RandomSensor::Evaluate(CValue* event) /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_RandomSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_RandomSensor", sizeof(SCA_RandomSensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -162,22 +165,25 @@ PyAttributeDef SCA_RandomSensor::Attributes[] = { {NULL} //Sentinel }; -PyObject* SCA_RandomSensor::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* SCA_RandomSensor::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - if (!strcmp(attr,"seed")) { + + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str,"seed")) { return PyInt_FromLong(m_basegenerator->GetSeed()); } - _getattr_up(SCA_ISensor); + py_getattro_up(SCA_ISensor); } -int SCA_RandomSensor::_setattr(const char *attr, PyObject *value) +int SCA_RandomSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - if (!strcmp(attr,"seed")) { + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str,"seed")) { if (PyInt_Check(value)) { int ival = PyInt_AsLong(value); m_basegenerator->SetSeed(ival); @@ -187,7 +193,7 @@ int SCA_RandomSensor::_setattr(const char *attr, PyObject *value) return 1; } } - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } /* 1. setSeed */ diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.h b/source/gameengine/GameLogic/SCA_RandomSensor.h index d808db07536..39d072dd316 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 char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 a9fe906f54e..10757e1c935 100644 --- a/source/gameengine/GameLogic/SCA_XNORController.cpp +++ b/source/gameengine/GameLogic/SCA_XNORController.cpp @@ -111,18 +111,21 @@ CValue* SCA_XNORController::GetReplica() /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_XNORController::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_XNORController", sizeof(SCA_XNORController), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -142,8 +145,8 @@ PyAttributeDef SCA_XNORController::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_XNORController::_getattr(const char *attr) { - _getattr_up(SCA_IController); +PyObject* SCA_XNORController::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IController); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_XNORController.h b/source/gameengine/GameLogic/SCA_XNORController.h index a431a72c177..c992d5f1834 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 char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; diff --git a/source/gameengine/GameLogic/SCA_XORController.cpp b/source/gameengine/GameLogic/SCA_XORController.cpp index b0053ca17fb..d2290fe207a 100644 --- a/source/gameengine/GameLogic/SCA_XORController.cpp +++ b/source/gameengine/GameLogic/SCA_XORController.cpp @@ -111,18 +111,21 @@ CValue* SCA_XORController::GetReplica() /* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_XORController::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "SCA_XORController", sizeof(SCA_XORController), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -142,8 +145,8 @@ PyAttributeDef SCA_XORController::Attributes[] = { { NULL } //Sentinel }; -PyObject* SCA_XORController::_getattr(const char *attr) { - _getattr_up(SCA_IController); +PyObject* SCA_XORController::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IController); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_XORController.h b/source/gameengine/GameLogic/SCA_XORController.h index 2fbc7866ecf..065b31fd901 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 char *attr); + virtual PyObject* py_getattro(PyObject *attr); }; diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index 14f672bb68f..279721b4840 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -729,9 +729,9 @@ void BL_Shader::SetUniform(int uniform, const int* val, int len) } -PyObject* BL_Shader::_getattr(const char *attr) +PyObject* BL_Shader::py_getattro(PyObject *attr) { - _getattr_up(PyObjectPlus); + py_getattro_up(PyObjectPlus); } @@ -772,25 +772,28 @@ PyAttributeDef BL_Shader::Attributes[] = { }; PyTypeObject BL_Shader::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "BL_Shader", sizeof(BL_Shader), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; PyParentObject BL_Shader::Parents[] = { - &PyObjectPlus::Type, &BL_Shader::Type, + &PyObjectPlus::Type, NULL }; diff --git a/source/gameengine/Ketsji/BL_Shader.h b/source/gameengine/Ketsji/BL_Shader.h index 76acd5513ef..490c0268a6d 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 char *attr); + virtual PyObject* py_getattro(PyObject *attr); // ----------------------------------- KX_PYMETHOD_DOC( BL_Shader, setSource ); diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp index 0a7e20b8650..a5fd8ebab6b 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp @@ -105,18 +105,21 @@ CValue* KX_NetworkMessageActuator::GetReplica() /* Integration hooks -------------------------------------------------- */ PyTypeObject KX_NetworkMessageActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_NetworkMessageActuator", sizeof(KX_NetworkMessageActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -150,18 +153,18 @@ PyAttributeDef KX_NetworkMessageActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_NetworkMessageActuator::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* KX_NetworkMessageActuator::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int KX_NetworkMessageActuator::_setattr(const char *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); +int KX_NetworkMessageActuator::py_setattro(PyObject *attr, PyObject *value) { + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } // Deprecated -----> diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h index d9a7f787333..850f825b8f3 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h @@ -61,8 +61,8 @@ public: /* Python interface ------------------------------------------- */ /* ------------------------------------------------------------ */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); // Deprecated -----> KX_PYMETHOD(KX_NetworkMessageActuator, SetToPropName); diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp index d5434a34eb7..7922c341659 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp @@ -168,18 +168,21 @@ bool KX_NetworkMessageSensor::IsPositiveTrigger() /* Integration hooks --------------------------------------------------- */ PyTypeObject KX_NetworkMessageSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_NetworkMessageSensor", sizeof(KX_NetworkMessageSensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -220,18 +223,18 @@ PyAttributeDef KX_NetworkMessageSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_NetworkMessageSensor::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* KX_NetworkMessageSensor::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_ISensor); + py_getattro_up(SCA_ISensor); } -int KX_NetworkMessageSensor::_setattr(const char *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); +int KX_NetworkMessageSensor::py_setattro(PyObject *attr, PyObject *value) { + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } PyObject* KX_NetworkMessageSensor::pyattr_get_bodies(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h index 79e8bc910d1..ac0e880d25c 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h @@ -72,8 +72,8 @@ public: /* Python interface -------------------------------------------- */ /* ------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); // Deprecated -----> KX_PYMETHOD_DOC_O(KX_NetworkMessageSensor, SetSubjectFilterText); diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index 668873883af..bd137196ac6 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -753,37 +753,40 @@ PyAttributeDef KX_BlenderMaterial::Attributes[] = { }; PyTypeObject KX_BlenderMaterial::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_BlenderMaterial", sizeof(KX_BlenderMaterial), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; PyParentObject KX_BlenderMaterial::Parents[] = { - &PyObjectPlus::Type, &KX_BlenderMaterial::Type, + &PyObjectPlus::Type, NULL }; -PyObject* KX_BlenderMaterial::_getattr(const char *attr) +PyObject* KX_BlenderMaterial::py_getattro(PyObject *attr) { - _getattr_up(PyObjectPlus); + py_getattro_up(PyObjectPlus); } -int KX_BlenderMaterial::_setattr(const char *attr, PyObject *pyvalue) +int KX_BlenderMaterial::py_setattro(PyObject *attr, PyObject *pyvalue) { - return PyObjectPlus::_setattr(attr, pyvalue); + return PyObjectPlus::py_setattro(attr, pyvalue); } diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.h b/source/gameengine/Ketsji/KX_BlenderMaterial.h index 2cf623dbd85..2d9dc8fd022 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.h +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.h @@ -82,8 +82,8 @@ public: ); // -------------------------------- - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *pyvalue); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 f86a5669225..57c9d30e92e 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.cpp +++ b/source/gameengine/Ketsji/KX_CDActuator.cpp @@ -158,18 +158,21 @@ bool KX_CDActuator::Update() /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_CDActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_SoundActuator", sizeof(KX_CDActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -212,20 +215,20 @@ int KX_CDActuator::pyattr_setGain(void *self, const struct KX_PYATTRIBUTE_DEF *a return 0; } -PyObject* KX_CDActuator::_getattr(const char *attr) +PyObject* KX_CDActuator::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int KX_CDActuator::_setattr(const char *attr, PyObject *value) +int KX_CDActuator::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } diff --git a/source/gameengine/Ketsji/KX_CDActuator.h b/source/gameengine/Ketsji/KX_CDActuator.h index 08ca6a82db3..e7683297c7a 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.h +++ b/source/gameengine/Ketsji/KX_CDActuator.h @@ -81,8 +81,8 @@ public: /* Python interface --------------------------------------------------- */ /* -------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); // Deprecated -----> KX_PYMETHOD(KX_CDActuator,SetGain); diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index cb138efba89..19370d83322 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -488,18 +488,21 @@ PyAttributeDef KX_Camera::Attributes[] = { }; PyTypeObject KX_Camera::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_Camera", sizeof(KX_Camera), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -511,48 +514,51 @@ PyParentObject KX_Camera::Parents[] = { NULL }; -PyObject* KX_Camera::_getattr(const char *attr) +PyObject* KX_Camera::py_getattro(PyObject *attr) { - if (!strcmp(attr, "INSIDE")) + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "INSIDE")) return PyInt_FromLong(INSIDE); /* new ref */ - if (!strcmp(attr, "OUTSIDE")) + if (!strcmp(attr_str, "OUTSIDE")) return PyInt_FromLong(OUTSIDE); /* new ref */ - if (!strcmp(attr, "INTERSECT")) + if (!strcmp(attr_str, "INTERSECT")) return PyInt_FromLong(INTERSECT); /* new ref */ - if (!strcmp(attr, "lens")) + if (!strcmp(attr_str, "lens")) return PyFloat_FromDouble(GetLens()); /* new ref */ - if (!strcmp(attr, "near")) + if (!strcmp(attr_str, "near")) return PyFloat_FromDouble(GetCameraNear()); /* new ref */ - if (!strcmp(attr, "far")) + if (!strcmp(attr_str, "far")) return PyFloat_FromDouble(GetCameraFar()); /* new ref */ - if (!strcmp(attr, "frustum_culling")) + if (!strcmp(attr_str, "frustum_culling")) return PyInt_FromLong(m_frustum_culling); /* new ref */ - if (!strcmp(attr, "perspective")) + if (!strcmp(attr_str, "perspective")) return PyInt_FromLong(m_camdata.m_perspective); /* new ref */ - if (!strcmp(attr, "projection_matrix")) + if (!strcmp(attr_str, "projection_matrix")) return PyObjectFrom(GetProjectionMatrix()); /* new ref */ - if (!strcmp(attr, "modelview_matrix")) + if (!strcmp(attr_str, "modelview_matrix")) return PyObjectFrom(GetModelviewMatrix()); /* new ref */ - if (!strcmp(attr, "camera_to_world")) + if (!strcmp(attr_str, "camera_to_world")) return PyObjectFrom(GetCameraToWorld()); /* new ref */ - if (!strcmp(attr, "world_to_camera")) + if (!strcmp(attr_str, "world_to_camera")) return PyObjectFrom(GetWorldToCamera()); /* new ref */ - _getattr_up(KX_GameObject); + py_getattro_up(KX_GameObject); } -int KX_Camera::_setattr(const char *attr, PyObject *pyvalue) +int KX_Camera::py_setattro(PyObject *attr, PyObject *pyvalue) { + char *attr_str= PyString_AsString(attr); + if (PyInt_Check(pyvalue)) { - if (!strcmp(attr, "frustum_culling")) + if (!strcmp(attr_str, "frustum_culling")) { m_frustum_culling = PyInt_AsLong(pyvalue); return 0; } - if (!strcmp(attr, "perspective")) + if (!strcmp(attr_str, "perspective")) { m_camdata.m_perspective = PyInt_AsLong(pyvalue); return 0; @@ -561,19 +567,19 @@ int KX_Camera::_setattr(const char *attr, PyObject *pyvalue) if (PyFloat_Check(pyvalue)) { - if (!strcmp(attr, "lens")) + if (!strcmp(attr_str, "lens")) { m_camdata.m_lens = PyFloat_AsDouble(pyvalue); m_set_projection_matrix = false; return 0; } - if (!strcmp(attr, "near")) + if (!strcmp(attr_str, "near")) { m_camdata.m_clipstart = PyFloat_AsDouble(pyvalue); m_set_projection_matrix = false; return 0; } - if (!strcmp(attr, "far")) + if (!strcmp(attr_str, "far")) { m_camdata.m_clipend = PyFloat_AsDouble(pyvalue); m_set_projection_matrix = false; @@ -583,7 +589,7 @@ int KX_Camera::_setattr(const char *attr, PyObject *pyvalue) if (PyObject_IsMT_Matrix(pyvalue, 4)) { - if (!strcmp(attr, "projection_matrix")) + if (!strcmp(attr_str, "projection_matrix")) { MT_Matrix4x4 mat; if (PyMatTo(pyvalue, mat)) @@ -594,7 +600,7 @@ int KX_Camera::_setattr(const char *attr, PyObject *pyvalue) return 1; } } - return KX_GameObject::_setattr(attr, pyvalue); + return KX_GameObject::py_setattro(attr, pyvalue); } KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, sphereInsideFrustum, diff --git a/source/gameengine/Ketsji/KX_Camera.h b/source/gameengine/Ketsji/KX_Camera.h index b80be9a7fee..499db66ab14 100644 --- a/source/gameengine/Ketsji/KX_Camera.h +++ b/source/gameengine/Ketsji/KX_Camera.h @@ -265,8 +265,8 @@ public: 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); + virtual PyObject* py_getattro(PyObject *attr); /* lens, near, far, projection_matrix */ + virtual int py_setattro(PyObject *attr, PyObject *pyvalue); }; diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 08afa2853c3..354143f1e69 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -371,18 +371,21 @@ bool KX_CameraActuator::string2axischoice(const char *axisString) /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_CameraActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_CameraActuator", sizeof(KX_CameraActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -414,27 +417,28 @@ PyAttributeDef KX_CameraActuator::Attributes[] = { 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), + KX_PYATTRIBUTE_DUMMY("object"), {NULL} }; -PyObject* KX_CameraActuator::_getattr(const char *attr) { +PyObject* KX_CameraActuator::py_getattro(PyObject *attr) { PyObject* object; - - if (!strcmp(attr, "object")) { + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "object")) { if (!m_ob) Py_RETURN_NONE; else return m_ob->AddRef(); } - object = _getattr_self(Attributes, this, attr); + object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int KX_CameraActuator::_setattr(const char *attr, PyObject* value) { +int KX_CameraActuator::py_setattro(PyObject *attr, PyObject* value) { int ret; - - if (!strcmp(attr, "object")) { + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "object")) { KX_GameObject *gameobj; if (!ConvertPythonToGameObject(value, &gameobj, true)) @@ -451,10 +455,10 @@ int KX_CameraActuator::_setattr(const char *attr, PyObject* value) { return 0; } - ret = _setattr_self(Attributes, this, attr, value); + ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } /* get obj ---------------------------------------------------------- */ diff --git a/source/gameengine/Ketsji/KX_CameraActuator.h b/source/gameengine/Ketsji/KX_CameraActuator.h index 3b08536fc21..5d7473a5bf0 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 char *attr); - virtual int _setattr(const char *attr, PyObject* value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 31a566f34ad..feee851bb01 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -560,18 +560,21 @@ bool KX_ConstraintActuator::IsValidMode(KX_ConstraintActuator::KX_CONSTRAINTTYPE /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_ConstraintActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_ConstraintActuator", sizeof(KX_ConstraintActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -613,8 +616,8 @@ PyAttributeDef KX_ConstraintActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_ConstraintActuator::_getattr(const char *attr) { - _getattr_up(SCA_IActuator); +PyObject* KX_ConstraintActuator::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IActuator); } /* 2. setDamp */ diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.h b/source/gameengine/Ketsji/KX_ConstraintActuator.h index 132b8a7328a..193400fbf2b 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 char *attr); + virtual PyObject* py_getattro(PyObject *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 05e677b9fd3..edd6e991e9f 100644 --- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp @@ -69,18 +69,21 @@ PyObject* KX_ConstraintWrapper::PyGetConstraintId(PyObject* self, //python specific stuff PyTypeObject KX_ConstraintWrapper::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_ConstraintWrapper", sizeof(KX_ConstraintWrapper), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -89,13 +92,13 @@ PyParentObject KX_ConstraintWrapper::Parents[] = { NULL }; -PyObject* KX_ConstraintWrapper::_getattr(const char *attr) +PyObject* KX_ConstraintWrapper::py_getattro(PyObject *attr) { //here you can search for existing data members (like mass,friction etc.) - _getattr_up(PyObjectPlus); + py_getattro_up(PyObjectPlus); } -int KX_ConstraintWrapper::_setattr(const char *attr,PyObject* pyobj) +int KX_ConstraintWrapper::py_setattro(PyObject *attr,PyObject* pyobj) { int result = 1; @@ -117,7 +120,7 @@ int KX_ConstraintWrapper::_setattr(const char *attr,PyObject* pyobj) result = 0; } if (result) - result = PyObjectPlus::_setattr(attr,pyobj); + result = PyObjectPlus::py_setattro(attr,pyobj); return result; }; diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.h b/source/gameengine/Ketsji/KX_ConstraintWrapper.h index 36606d2d67b..6e67d842cb6 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 char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 6800c75d807..a2a3d486420 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.cpp +++ b/source/gameengine/Ketsji/KX_GameActuator.cpp @@ -208,18 +208,21 @@ bool KX_GameActuator::Update() /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_GameActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_GameActuator", sizeof(KX_GameActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -251,20 +254,20 @@ PyAttributeDef KX_GameActuator::Attributes[] = { }; PyObject* -KX_GameActuator::_getattr(const char *attr) +KX_GameActuator::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int KX_GameActuator::_setattr(const char *attr, PyObject *value) +int KX_GameActuator::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } diff --git a/source/gameengine/Ketsji/KX_GameActuator.h b/source/gameengine/Ketsji/KX_GameActuator.h index ad638254c31..570cb2e68ef 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.h +++ b/source/gameengine/Ketsji/KX_GameActuator.h @@ -77,8 +77,8 @@ protected: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); // Deprecated functions -----> KX_PYMETHOD_DOC(KX_GameActuator,GetFile); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 2bd4b2834d1..f0c5667479c 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1180,21 +1180,21 @@ PyMappingMethods KX_GameObject::Mapping = { PyTypeObject KX_GameObject::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_GameObject", sizeof(KX_GameObject), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, 0, 0, - &Mapping, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -1420,7 +1420,9 @@ int KX_GameObject::pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attr PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_GameObject* self= static_cast(self_v); - PyObject *dict= _getattr_dict(self->SCA_IObject::_getattr("__dict__"), KX_GameObject::Methods, KX_GameObject::Attributes); + PyObject *dict_str = PyString_FromString("__dict__"); + PyObject *dict= _getattr_dict(self->SCA_IObject::py_getattro(dict_str), KX_GameObject::Methods, KX_GameObject::Attributes); + Py_DECREF(dict_str); if(dict==NULL) return NULL; @@ -1441,22 +1443,22 @@ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_ return dict; } -PyObject* KX_GameObject::_getattr(const char *attr) +PyObject* KX_GameObject::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IObject); + py_getattro_up(SCA_IObject); } -int KX_GameObject::_setattr(const char *attr, PyObject *value) // _setattr method +int KX_GameObject::py_setattro(PyObject *attr, PyObject *value) // py_setattro method { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IObject::_setattr(attr, value); + return SCA_IObject::py_setattro(attr, value); } PyObject* KX_GameObject::PyApplyForce(PyObject* self, PyObject* args) diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index bada19c4895..4b136e268db 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -756,9 +756,9 @@ public: * @section Python interface functions. */ - 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()); } + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method + virtual PyObject* py_repr(void) { return PyString_FromString(GetName().ReadPtr()); } 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 5d1d45879c9..adb9c284828 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -413,18 +413,21 @@ int KX_IpoActuator::string2mode(char* modename) { /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_IpoActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_IpoActuator", sizeof(KX_IpoActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -470,25 +473,21 @@ PyAttributeDef KX_IpoActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_IpoActuator::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* KX_IpoActuator::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - if (!strcmp(attr, "__dict__")) { /* python 3.0 uses .__dir__()*/ - return _getattr_dict(SCA_IActuator::_getattr(attr), Methods, Attributes); - } - - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int KX_IpoActuator::_setattr(const char *attr, PyObject *value) // _setattr method +int KX_IpoActuator::py_setattro(PyObject *attr, PyObject *value) // py_setattro method { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } /* set --------------------------------------------------------------------- */ diff --git a/source/gameengine/Ketsji/KX_IpoActuator.h b/source/gameengine/Ketsji/KX_IpoActuator.h index fa8e58ae861..7e85a28eb96 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.h +++ b/source/gameengine/Ketsji/KX_IpoActuator.h @@ -141,8 +141,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); //KX_PYMETHOD_DOC KX_PYMETHOD_DOC(KX_IpoActuator,Set); diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp index f71dd69a7a3..6f9d8b0211b 100644 --- a/source/gameengine/Ketsji/KX_Light.cpp +++ b/source/gameengine/Ketsji/KX_Light.cpp @@ -173,59 +173,62 @@ void KX_LightObject::UnbindShadowBuffer(RAS_IRasterizer *ras) GPU_lamp_shadow_buffer_unbind(lamp); } -PyObject* KX_LightObject::_getattr(const char *attr) +PyObject* KX_LightObject::py_getattro(PyObject *attr) { - if (!strcmp(attr, "layer")) + char *attr_str= PyString_AsString(attr); + + if (!strcmp(attr_str, "layer")) return PyInt_FromLong(m_lightobj.m_layer); - if (!strcmp(attr, "energy")) + if (!strcmp(attr_str, "energy")) return PyFloat_FromDouble(m_lightobj.m_energy); - if (!strcmp(attr, "distance")) + if (!strcmp(attr_str, "distance")) return PyFloat_FromDouble(m_lightobj.m_distance); - if (!strcmp(attr, "colour") || !strcmp(attr, "color")) + if (!strcmp(attr_str, "colour") || !strcmp(attr_str, "color")) return Py_BuildValue("[fff]", m_lightobj.m_red, m_lightobj.m_green, m_lightobj.m_blue); - if (!strcmp(attr, "lin_attenuation")) + if (!strcmp(attr_str, "lin_attenuation")) return PyFloat_FromDouble(m_lightobj.m_att1); - if (!strcmp(attr, "quad_attenuation")) + if (!strcmp(attr_str, "quad_attenuation")) return PyFloat_FromDouble(m_lightobj.m_att2); - if (!strcmp(attr, "spotsize")) + if (!strcmp(attr_str, "spotsize")) return PyFloat_FromDouble(m_lightobj.m_spotsize); - if (!strcmp(attr, "spotblend")) + if (!strcmp(attr_str, "spotblend")) return PyFloat_FromDouble(m_lightobj.m_spotblend); - if (!strcmp(attr, "SPOT")) + if (!strcmp(attr_str, "SPOT")) return PyInt_FromLong(RAS_LightObject::LIGHT_SPOT); - if (!strcmp(attr, "SUN")) + if (!strcmp(attr_str, "SUN")) return PyInt_FromLong(RAS_LightObject::LIGHT_SUN); - if (!strcmp(attr, "NORMAL")) + if (!strcmp(attr_str, "NORMAL")) return PyInt_FromLong(RAS_LightObject::LIGHT_NORMAL); - if (!strcmp(attr, "type")) + if (!strcmp(attr_str, "type")) return PyInt_FromLong(m_lightobj.m_type); - _getattr_up(KX_GameObject); + py_getattro_up(KX_GameObject); } -int KX_LightObject::_setattr(const char *attr, PyObject *pyvalue) -{ +int KX_LightObject::py_setattro(PyObject *attr, PyObject *pyvalue) +{ + char *attr_str= PyString_AsString(attr); if (PyInt_Check(pyvalue)) { int value = PyInt_AsLong(pyvalue); - if (!strcmp(attr, "layer")) + if (!strcmp(attr_str, "layer")) { m_lightobj.m_layer = value; return 0; } - if (!strcmp(attr, "type")) + if (!strcmp(attr_str, "type")) { if (value >= RAS_LightObject::LIGHT_SPOT && value <= RAS_LightObject::LIGHT_NORMAL) m_lightobj.m_type = (RAS_LightObject::LightType) value; @@ -236,37 +239,37 @@ int KX_LightObject::_setattr(const char *attr, PyObject *pyvalue) if (PyFloat_Check(pyvalue)) { float value = PyFloat_AsDouble(pyvalue); - if (!strcmp(attr, "energy")) + if (!strcmp(attr_str, "energy")) { m_lightobj.m_energy = value; return 0; } - if (!strcmp(attr, "distance")) + if (!strcmp(attr_str, "distance")) { m_lightobj.m_distance = value; return 0; } - if (!strcmp(attr, "lin_attenuation")) + if (!strcmp(attr_str, "lin_attenuation")) { m_lightobj.m_att1 = value; return 0; } - if (!strcmp(attr, "quad_attenuation")) + if (!strcmp(attr_str, "quad_attenuation")) { m_lightobj.m_att2 = value; return 0; } - if (!strcmp(attr, "spotsize")) + if (!strcmp(attr_str, "spotsize")) { m_lightobj.m_spotsize = value; return 0; } - if (!strcmp(attr, "spotblend")) + if (!strcmp(attr_str, "spotblend")) { m_lightobj.m_spotblend = value; return 0; @@ -275,7 +278,7 @@ int KX_LightObject::_setattr(const char *attr, PyObject *pyvalue) if (PySequence_Check(pyvalue)) { - if (!strcmp(attr, "colour") || !strcmp(attr, "color")) + if (!strcmp(attr_str, "colour") || !strcmp(attr_str, "color")) { MT_Vector3 color; if (PyVecTo(pyvalue, color)) @@ -289,13 +292,13 @@ int KX_LightObject::_setattr(const char *attr, PyObject *pyvalue) } } - if (!strcmp(attr, "SPOT") || !strcmp(attr, "SUN") || !strcmp(attr, "NORMAL")) + if (!strcmp(attr_str, "SPOT") || !strcmp(attr_str, "SUN") || !strcmp(attr_str, "NORMAL")) { - PyErr_Format(PyExc_RuntimeError, "Attribute %s is read only.", attr); + PyErr_Format(PyExc_RuntimeError, "Attribute %s is read only.", attr_str); return 1; } - return KX_GameObject::_setattr(attr, pyvalue); + return KX_GameObject::py_setattro(attr, pyvalue); } PyMethodDef KX_LightObject::Methods[] = { @@ -308,18 +311,21 @@ PyAttributeDef KX_LightObject::Attributes[] = { PyTypeObject KX_LightObject::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_LightObject", sizeof(KX_LightObject), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; diff --git a/source/gameengine/Ketsji/KX_Light.h b/source/gameengine/Ketsji/KX_Light.h index 98dcc8ef873..4559954c8d7 100644 --- a/source/gameengine/Ketsji/KX_Light.h +++ b/source/gameengine/Ketsji/KX_Light.h @@ -62,8 +62,8 @@ public: void UnbindShadowBuffer(class RAS_IRasterizer *ras); void Update(); - virtual PyObject* _getattr(const char *attr); /* lens, near, far, projection_matrix */ - virtual int _setattr(const char *attr, PyObject *pyvalue); + virtual PyObject* py_getattro(PyObject *attr); /* lens, near, far, projection_matrix */ + virtual int py_setattro(PyObject *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 f349a6b519a..f464cb798e8 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -46,18 +46,21 @@ #include "PyObjectPlus.h" PyTypeObject KX_MeshProxy::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_MeshProxy", sizeof(KX_MeshProxy), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -94,9 +97,11 @@ void KX_MeshProxy::SetMeshModified(bool v) PyObject* -KX_MeshProxy::_getattr(const char *attr) +KX_MeshProxy::py_getattro(PyObject *attr) { - if (!strcmp(attr, "materials")) + char *attr_str= PyString_AsString(attr); + + if (!strcmp(attr_str, "materials")) { PyObject *materials = PyList_New(0); list::iterator mit = m_meshobj->GetFirstMaterial(); @@ -115,7 +120,7 @@ KX_MeshProxy::_getattr(const char *attr) } return materials; } - _getattr_up(SCA_IObject); + py_getattro_up(SCA_IObject); } diff --git a/source/gameengine/Ketsji/KX_MeshProxy.h b/source/gameengine/Ketsji/KX_MeshProxy.h index 9e08937de07..0b9738153ff 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.h +++ b/source/gameengine/Ketsji/KX_MeshProxy.h @@ -54,7 +54,7 @@ public: virtual CValue* GetReplica(); // stuff for python integration - virtual PyObject* _getattr(const char *attr); + virtual PyObject* py_getattro(PyObject *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 973dfce505b..72a0381e8dc 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -293,18 +293,21 @@ bool KX_MouseFocusSensor::ParentObjectHasFocus(void) /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_MouseFocusSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_MouseFocusSensor", sizeof(KX_MouseFocusSensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -333,8 +336,8 @@ PyAttributeDef KX_MouseFocusSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_MouseFocusSensor::_getattr(const char *attr) { - _getattr_up(SCA_MouseSensor); +PyObject* KX_MouseFocusSensor::py_getattro(PyObject *attr) { + py_getattro_up(SCA_MouseSensor); } diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.h b/source/gameengine/Ketsji/KX_MouseFocusSensor.h index 4979783032c..804f34e6076 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 char *attr); + virtual PyObject* py_getattro(PyObject *attr); KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRayTarget); KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRaySource); diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index 383d673b7ea..2debfd793c1 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -287,18 +287,21 @@ bool KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData /* ------------------------------------------------------------------------- */ PyTypeObject KX_NearSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_NearSensor", sizeof(KX_NearSensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -327,20 +330,20 @@ PyAttributeDef KX_NearSensor::Attributes[] = { }; -PyObject* KX_NearSensor::_getattr(const char *attr) +PyObject* KX_NearSensor::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(KX_TouchSensor); + py_getattro_up(KX_TouchSensor); } -int KX_NearSensor::_setattr(const char *attr, PyObject* value) +int KX_NearSensor::py_setattro(PyObject*attr, PyObject* value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return KX_TouchSensor::_setattr(attr, value); + return KX_TouchSensor::py_setattro(attr, value); } diff --git a/source/gameengine/Ketsji/KX_NearSensor.h b/source/gameengine/Ketsji/KX_NearSensor.h index ee03992e734..26c5feb4e67 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.h +++ b/source/gameengine/Ketsji/KX_NearSensor.h @@ -82,8 +82,8 @@ public: /* --------------------------------------------------------------------- */ /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject* value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject* value); //No methods diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index ca2157f2bc0..a343eeb71cc 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -277,18 +277,21 @@ bool KX_ObjectActuator::isValid(KX_ObjectActuator::KX_OBJECT_ACT_VEC_TYPE type) /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_ObjectActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_ObjectActuator", sizeof(KX_ObjectActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -333,8 +336,8 @@ PyAttributeDef KX_ObjectActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_ObjectActuator::_getattr(const char *attr) { - _getattr_up(SCA_IActuator); +PyObject* KX_ObjectActuator::py_getattro(PyObject *attr) { + py_getattro_up(SCA_IActuator); }; /* 1. set ------------------------------------------------------------------ */ diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.h b/source/gameengine/Ketsji/KX_ObjectActuator.h index 0331c67617c..00c8fb700ae 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 char *attr); + virtual PyObject* py_getattro(PyObject *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 4c0507cd0bf..1baf581f8a0 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -139,18 +139,21 @@ bool KX_ParentActuator::Update() /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_ParentActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_ParentActuator", sizeof(KX_ParentActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -204,20 +207,20 @@ int KX_ParentActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE } -PyObject* KX_ParentActuator::_getattr(const char *attr) { +PyObject* KX_ParentActuator::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int KX_ParentActuator::_setattr(const char *attr, PyObject* value) { +int KX_ParentActuator::py_setattro(PyObject *attr, PyObject* value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } /* Deprecated -----> */ diff --git a/source/gameengine/Ketsji/KX_ParentActuator.h b/source/gameengine/Ketsji/KX_ParentActuator.h index 257c95c9260..f9f0b73b876 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 char *attr); - virtual int _setattr(const char *attr, PyObject* value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject* value); /* These are used to get and set m_ob */ static PyObject* pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); diff --git a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp index 4c04a96eae2..3bef85e7f93 100644 --- a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp +++ b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp @@ -115,22 +115,27 @@ PyObject* KX_PhysicsObjectWrapper::PySetActive(PyObject* self, } - +PyAttributeDef KX_PhysicsObjectWrapper::Attributes[] = { + { NULL } //Sentinel +}; //python specific stuff PyTypeObject KX_PhysicsObjectWrapper::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_PhysicsObjectWrapper", sizeof(KX_PhysicsObjectWrapper), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -139,13 +144,13 @@ PyParentObject KX_PhysicsObjectWrapper::Parents[] = { NULL }; -PyObject* KX_PhysicsObjectWrapper::_getattr(const char *attr) +PyObject* KX_PhysicsObjectWrapper::py_getattro(PyObject *attr) { - _getattr_up(PyObjectPlus); + py_getattro_up(PyObjectPlus); } -int KX_PhysicsObjectWrapper::_setattr(const char *attr,PyObject *pyobj) +int KX_PhysicsObjectWrapper::py_setattro(PyObject *attr,PyObject *pyobj) { int result = 1; @@ -158,7 +163,7 @@ int KX_PhysicsObjectWrapper::_setattr(const char *attr,PyObject *pyobj) result = 0; } if (result) - result = PyObjectPlus::_setattr(attr,pyobj); + result = PyObjectPlus::py_setattro(attr,pyobj); return result; }; diff --git a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.h b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.h index 95560698896..6dc10f030f0 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 char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 27fbe8b19f3..6f74c3ed3f9 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.cpp +++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp @@ -39,18 +39,21 @@ #include "KX_PyMath.h" PyTypeObject KX_PolyProxy::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_PolyProxy", sizeof(KX_PolyProxy), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -78,17 +81,18 @@ PyAttributeDef KX_PolyProxy::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_PolyProxy::_getattr(const char *attr) +PyObject* KX_PolyProxy::py_getattro(PyObject *attr) { - if (!strcmp(attr, "matname")) + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "matname")) { return PyString_FromString(m_polygon->GetMaterial()->GetPolyMaterial()->GetMaterialName()); } - if (!strcmp(attr, "texture")) + if (!strcmp(attr_str, "texture")) { return PyString_FromString(m_polygon->GetMaterial()->GetPolyMaterial()->GetTextureName()); } - if (!strcmp(attr, "material")) + if (!strcmp(attr_str, "material")) { RAS_IPolyMaterial *polymat = m_polygon->GetMaterial()->GetPolyMaterial(); if(polymat->GetFlag() & RAS_BLENDERMAT) @@ -104,7 +108,7 @@ PyObject* KX_PolyProxy::_getattr(const char *attr) return mat; } } - if (!strcmp(attr, "matid")) + if (!strcmp(attr_str, "matid")) { // we'll have to scan through the material bucket of the mes and compare with // the one of the polygon @@ -119,31 +123,31 @@ PyObject* KX_PolyProxy::_getattr(const char *attr) } return PyInt_FromLong(matid); } - if (!strcmp(attr, "v1")) + if (!strcmp(attr_str, "v1")) { return PyInt_FromLong(m_polygon->GetVertexOffset(0)); } - if (!strcmp(attr, "v2")) + if (!strcmp(attr_str, "v2")) { return PyInt_FromLong(m_polygon->GetVertexOffset(1)); } - if (!strcmp(attr, "v3")) + if (!strcmp(attr_str, "v3")) { return PyInt_FromLong(m_polygon->GetVertexOffset(2)); } - if (!strcmp(attr, "v4")) + if (!strcmp(attr_str, "v4")) { return PyInt_FromLong(((m_polygon->VertexCount()>3)?m_polygon->GetVertexOffset(3):0)); } - if (!strcmp(attr, "visible")) + if (!strcmp(attr_str, "visible")) { return PyInt_FromLong(m_polygon->IsVisible()); } - if (!strcmp(attr, "collide")) + if (!strcmp(attr_str, "collide")) { return PyInt_FromLong(m_polygon->IsCollider()); } - _getattr_up(SCA_IObject); + py_getattro_up(SCA_IObject); } KX_PolyProxy::KX_PolyProxy(const RAS_MeshObject*mesh, RAS_Polygon* polygon) diff --git a/source/gameengine/Ketsji/KX_PolyProxy.h b/source/gameengine/Ketsji/KX_PolyProxy.h index 9b548f9490d..a549d9841cc 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 char *attr); + virtual PyObject* py_getattro(PyObject *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 9e979144c47..6b9a6201d5c 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -185,38 +185,42 @@ PyAttributeDef KX_PolygonMaterial::Attributes[] = { }; PyTypeObject KX_PolygonMaterial::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_PolygonMaterial", sizeof(KX_PolygonMaterial), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; PyParentObject KX_PolygonMaterial::Parents[] = { - &PyObjectPlus::Type, &KX_PolygonMaterial::Type, + &PyObjectPlus::Type, NULL }; -PyObject* KX_PolygonMaterial::_getattr(const char *attr) +PyObject* KX_PolygonMaterial::py_getattro(PyObject *attr) { - if (!strcmp(attr, "texture")) + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "texture")) return PyString_FromString(m_texturename.ReadPtr()); - if (!strcmp(attr, "material")) + if (!strcmp(attr_str, "material")) return PyString_FromString(m_materialname.ReadPtr()); - if (!strcmp(attr, "tface")) + if (!strcmp(attr_str, "tface")) return PyCObject_FromVoidPtr(m_tface, NULL); - if (!strcmp(attr, "gl_texture")) + if (!strcmp(attr_str, "gl_texture")) { Image *ima = m_tface->tpage; int bind = 0; @@ -226,49 +230,50 @@ PyObject* KX_PolygonMaterial::_getattr(const char *attr) return PyInt_FromLong(bind); } - if (!strcmp(attr, "tile")) + if (!strcmp(attr_str, "tile")) return PyInt_FromLong(m_tile); - if (!strcmp(attr, "tilexrep")) + if (!strcmp(attr_str, "tilexrep")) return PyInt_FromLong(m_tilexrep); - if (!strcmp(attr, "tileyrep")) + if (!strcmp(attr_str, "tileyrep")) return PyInt_FromLong(m_tileyrep); - if (!strcmp(attr, "drawingmode")) + if (!strcmp(attr_str, "drawingmode")) return PyInt_FromLong(m_drawingmode); - if (!strcmp(attr, "transparent")) + if (!strcmp(attr_str, "transparent")) return PyInt_FromLong(m_alpha); - if (!strcmp(attr, "zsort")) + if (!strcmp(attr_str, "zsort")) return PyInt_FromLong(m_zsort); - if (!strcmp(attr, "lightlayer")) + if (!strcmp(attr_str, "lightlayer")) return PyInt_FromLong(m_lightlayer); - if (!strcmp(attr, "triangle")) + if (!strcmp(attr_str, "triangle")) // deprecated, triangle/quads shouldn't have been a material property return 0; - if (!strcmp(attr, "diffuse")) + if (!strcmp(attr_str, "diffuse")) return PyObjectFrom(m_diffuse); - if (!strcmp(attr, "shininess")) + if (!strcmp(attr_str, "shininess")) return PyFloat_FromDouble(m_shininess); - if (!strcmp(attr, "specular")) + if (!strcmp(attr_str, "specular")) return PyObjectFrom(m_specular); - if (!strcmp(attr, "specularity")) + if (!strcmp(attr_str, "specularity")) return PyFloat_FromDouble(m_specularity); - _getattr_up(PyObjectPlus); + py_getattro_up(PyObjectPlus); } -int KX_PolygonMaterial::_setattr(const char *attr, PyObject *pyvalue) +int KX_PolygonMaterial::py_setattro(PyObject *attr, PyObject *pyvalue) { + char *attr_str= PyString_AsString(attr); if (PyFloat_Check(pyvalue)) { float value = PyFloat_AsDouble(pyvalue); - if (!strcmp(attr, "shininess")) + if (!strcmp(attr_str, "shininess")) { m_shininess = value; return 0; } - if (!strcmp(attr, "specularity")) + if (!strcmp(attr_str, "specularity")) { m_specularity = value; return 0; @@ -278,50 +283,50 @@ int KX_PolygonMaterial::_setattr(const char *attr, PyObject *pyvalue) if (PyInt_Check(pyvalue)) { int value = PyInt_AsLong(pyvalue); - if (!strcmp(attr, "tile")) + if (!strcmp(attr_str, "tile")) { m_tile = value; return 0; } - if (!strcmp(attr, "tilexrep")) + if (!strcmp(attr_str, "tilexrep")) { m_tilexrep = value; return 0; } - if (!strcmp(attr, "tileyrep")) + if (!strcmp(attr_str, "tileyrep")) { m_tileyrep = value; return 0; } - if (!strcmp(attr, "drawingmode")) + if (!strcmp(attr_str, "drawingmode")) { m_drawingmode = value; return 0; } - if (!strcmp(attr, "transparent")) + if (!strcmp(attr_str, "transparent")) { m_alpha = value; return 0; } - if (!strcmp(attr, "zsort")) + if (!strcmp(attr_str, "zsort")) { m_zsort = value; return 0; } - if (!strcmp(attr, "lightlayer")) + if (!strcmp(attr_str, "lightlayer")) { m_lightlayer = value; return 0; } // This probably won't work... - if (!strcmp(attr, "triangle")) + if (!strcmp(attr_str, "triangle")) { // deprecated, triangle/quads shouldn't have been a material property return 0; @@ -335,13 +340,13 @@ int KX_PolygonMaterial::_setattr(const char *attr, PyObject *pyvalue) MT_Vector3 value; if (PyVecTo(pyvalue, value)) { - if (!strcmp(attr, "diffuse")) + if (!strcmp(attr_str, "diffuse")) { m_diffuse = value; return 0; } - if (!strcmp(attr, "specular")) + if (!strcmp(attr_str, "specular")) { m_specular = value; return 0; @@ -350,7 +355,7 @@ int KX_PolygonMaterial::_setattr(const char *attr, PyObject *pyvalue) } } - return PyObjectPlus::_setattr(attr, pyvalue); + return PyObjectPlus::py_setattro(attr, pyvalue); } KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setCustomMaterial, "setCustomMaterial(material)") diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.h b/source/gameengine/Ketsji/KX_PolygonMaterial.h index a3ef4ca51ef..f3eb1979f34 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 char *attr); - virtual int _setattr(const char *attr, PyObject *pyvalue); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *pyvalue); }; #endif // __KX_POLYGONMATERIAL_H__ diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 7ddfbb0d5fe..f065eb29c44 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -71,7 +71,9 @@ #include "KX_PyMath.h" -#include "PyObjectPlus.h" +#include "PyObjectPlus.h" + +#include "KX_PythonInitTypes.h" extern "C" { #include "Mathutils.h" // Blender.Mathutils module copied here so the blenderlayer can use. @@ -1257,6 +1259,7 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur //importBlenderModules() setSandbox(level); + initPyTypes(); PyObject* moduleobj = PyImport_AddModule("__main__"); return PyModule_GetDict(moduleobj); @@ -1278,6 +1281,7 @@ PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLev Py_FrozenFlag=1; setSandbox(level); + initPyTypes(); PyObject* moduleobj = PyImport_AddModule("__main__"); return PyModule_GetDict(moduleobj); 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 diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.h b/source/gameengine/Ketsji/KX_PythonInitTypes.h new file mode 100644 index 00000000000..b30f0334b6e --- /dev/null +++ b/source/gameengine/Ketsji/KX_PythonInitTypes.h @@ -0,0 +1,35 @@ +/** + * $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 + +void initPyTypes(void); + +#endif diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp index 91ad60e8cee..77cde79b54d 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.cpp +++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp @@ -250,18 +250,21 @@ PyObject* KX_RadarSensor::PyGetConeHeight(PyObject* self) { /* Python Integration Hooks */ /* ------------------------------------------------------------------------- */ PyTypeObject KX_RadarSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_RadarSensor", sizeof(KX_RadarSensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -295,20 +298,20 @@ PyAttributeDef KX_RadarSensor::Attributes[] = { {NULL} //Sentinel }; -PyObject* KX_RadarSensor::_getattr(const char *attr) +PyObject* KX_RadarSensor::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(KX_NearSensor); + py_getattro_up(KX_NearSensor); } -int KX_RadarSensor::_setattr(const char *attr, PyObject* value) +int KX_RadarSensor::py_setattro(PyObject *attr, PyObject* value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return KX_NearSensor::_setattr(attr, value); + return KX_NearSensor::py_setattro(attr, value); } diff --git a/source/gameengine/Ketsji/KX_RadarSensor.h b/source/gameengine/Ketsji/KX_RadarSensor.h index 6dfe0c42f5d..c3a941696ce 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.h +++ b/source/gameengine/Ketsji/KX_RadarSensor.h @@ -89,8 +89,8 @@ public: KX_RADAR_AXIS_NEG_Z }; - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject* value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject* value); //Deprecated -----> KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeOrigin); diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index fdaf48218b3..cdcb5d74f30 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -321,18 +321,21 @@ bool KX_RaySensor::Evaluate(CValue* event) /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_RaySensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_RaySensor", sizeof(KX_RaySensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -442,18 +445,18 @@ PyObject* KX_RaySensor::PyGetHitNormal(PyObject* self) -PyObject* KX_RaySensor::_getattr(const char *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); +PyObject* KX_RaySensor::py_getattro(PyObject *attr) { + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_ISensor); + py_getattro_up(SCA_ISensor); } -int KX_RaySensor::_setattr(const char *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); +int KX_RaySensor::py_setattro(PyObject *attr, PyObject *value) { + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } // <----- Deprecated \ No newline at end of file diff --git a/source/gameengine/Ketsji/KX_RaySensor.h b/source/gameengine/Ketsji/KX_RaySensor.h index e7901a0d10d..a5d7d15c60c 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.h +++ b/source/gameengine/Ketsji/KX_RaySensor.h @@ -86,8 +86,8 @@ public: }; - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); // Deprecated -----> KX_PYMETHOD_DOC_NOARGS(KX_RaySensor,GetHitObject); diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index 33e74d4dc5a..1dd642e0966 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -167,22 +167,26 @@ void KX_SCA_AddObjectActuator::Relink(GEN_Map *obj_map) /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_SCA_AddObjectActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_SCA_AddObjectActuator", sizeof(KX_SCA_AddObjectActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; PyParentObject KX_SCA_AddObjectActuator::Parents[] = { + &KX_SCA_AddObjectActuator::Type, &SCA_IActuator::Type, &SCA_ILogicBrick::Type, &CValue::Type, @@ -251,20 +255,20 @@ PyObject* KX_SCA_AddObjectActuator::pyattr_get_objectLastCreated(void *self, con } -PyObject* KX_SCA_AddObjectActuator::_getattr(const char *attr) +PyObject* KX_SCA_AddObjectActuator::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int KX_SCA_AddObjectActuator::_setattr(const char *attr, PyObject* value) +int KX_SCA_AddObjectActuator::py_setattro(PyObject *attr, PyObject* value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } /* 1. setObject */ diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h index c8cc7113347..4ece5a6d83b 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 char *attr); - virtual int _setattr(const char *attr, PyObject* value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *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 7dd5301385c..ae21209fc4e 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp @@ -51,18 +51,21 @@ PyTypeObject KX_SCA_DynamicActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_SCA_DynamicActuator", sizeof(KX_SCA_DynamicActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -89,20 +92,20 @@ PyAttributeDef KX_SCA_DynamicActuator::Attributes[] = { }; -PyObject* KX_SCA_DynamicActuator::_getattr(const char *attr) +PyObject* KX_SCA_DynamicActuator::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int KX_SCA_DynamicActuator::_setattr(const char *attr, PyObject* value) +int KX_SCA_DynamicActuator::py_setattro(PyObject *attr, PyObject* value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h index 082fcd72035..99855124bdb 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h @@ -74,8 +74,8 @@ class KX_SCA_DynamicActuator : public SCA_IActuator }; - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); /* 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 6f0bd65ce43..0db9e1c4930 100644 --- a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp @@ -94,18 +94,21 @@ CValue* KX_SCA_EndObjectActuator::GetReplica() /* ------------------------------------------------------------------------- */ PyTypeObject KX_SCA_EndObjectActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_SCA_EndObjectActuator", sizeof(KX_SCA_EndObjectActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -128,9 +131,9 @@ PyAttributeDef KX_SCA_EndObjectActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_SCA_EndObjectActuator::_getattr(const char *attr) +PyObject* KX_SCA_EndObjectActuator::py_getattro(PyObject *attr) { - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } /* eof */ diff --git a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.h b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.h index 12118743f0a..2940246f443 100644 --- a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.h @@ -64,7 +64,7 @@ class KX_SCA_EndObjectActuator : public SCA_IActuator /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); + virtual PyObject* py_getattro(PyObject *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 c892af71159..0cac07b4585 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -53,22 +53,26 @@ PyTypeObject KX_SCA_ReplaceMeshActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_SCA_ReplaceMeshActuator", sizeof(KX_SCA_ReplaceMeshActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; PyParentObject KX_SCA_ReplaceMeshActuator::Parents[] = { + &KX_SCA_ReplaceMeshActuator::Type, &SCA_IActuator::Type, &SCA_ILogicBrick::Type, &CValue::Type, @@ -90,20 +94,20 @@ PyAttributeDef KX_SCA_ReplaceMeshActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_SCA_ReplaceMeshActuator::_getattr(const char *attr) +PyObject* KX_SCA_ReplaceMeshActuator::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int KX_SCA_ReplaceMeshActuator::_setattr(const char *attr, PyObject* value) +int KX_SCA_ReplaceMeshActuator::py_setattro(PyObject *attr, PyObject* value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } PyObject* KX_SCA_ReplaceMeshActuator::pyattr_get_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h index ba43975bd51..7a18df2356d 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h @@ -71,8 +71,8 @@ class KX_SCA_ReplaceMeshActuator : public SCA_IActuator void InstantReplaceMesh(); - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject* value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject* value); static PyObject* pyattr_get_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 67f6c567549..94ea234f1bf 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1517,18 +1517,21 @@ double KX_Scene::getSuspendedDelta() //Python PyTypeObject KX_Scene::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_Scene", sizeof(KX_Scene), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -1569,8 +1572,10 @@ PyObject* KX_Scene::pyattr_get_active_camera(void *self_v, const KX_PYATTRIBUTE_ PyObject* KX_Scene::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_Scene* self= static_cast(self_v); - /* Useually done by _getattr_up but in this case we want to include m_attrlist dict */ - PyObject *dict= _getattr_dict(self->PyObjectPlus::_getattr("__dict__"), KX_Scene::Methods, KX_Scene::Attributes); + /* Useually done by py_getattro_up but in this case we want to include m_attrlist dict */ + PyObject *dict_str= PyString_FromString("__dict__"); + PyObject *dict= _getattr_dict(self->PyObjectPlus::py_getattro(dict_str), KX_Scene::Methods, KX_Scene::Attributes); + Py_DECREF(dict_str); PyDict_Update(dict, self->m_attrlist); return dict; @@ -1587,34 +1592,34 @@ PyAttributeDef KX_Scene::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_Scene::_getattr(const char *attr) +PyObject* KX_Scene::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - object = PyDict_GetItemString(m_attrlist, attr); + object = PyDict_GetItem(m_attrlist, attr); if (object) { Py_INCREF(object); return object; } - _getattr_up(PyObjectPlus); + py_getattro_up(PyObjectPlus); } -int KX_Scene::_delattr(const char *attr) +int KX_Scene::py_delattro(PyObject *attr) { - PyDict_DelItemString(m_attrlist, attr); + PyDict_DelItem(m_attrlist, attr); return 0; } -int KX_Scene::_setattr(const char *attr, PyObject *pyvalue) +int KX_Scene::py_setattro(PyObject *attr, PyObject *pyvalue) { - if (!PyDict_SetItemString(m_attrlist, attr, pyvalue)) + if (!PyDict_SetItem(m_attrlist, attr, pyvalue)) return 0; - return PyObjectPlus::_setattr(attr, pyvalue); + return PyObjectPlus::py_setattro(attr, pyvalue); } KX_PYMETHODDEF_DOC_NOARGS(KX_Scene, getLightList, diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index d1da44c600e..df51fcec8f7 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -574,10 +574,10 @@ public: static PyObject* pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); - 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()); } + virtual PyObject* py_getattro(PyObject *attr); /* name, active_camera, gravity, suspended, viewport, framing, activity_culling, activity_culling_radius */ + virtual int py_setattro(PyObject *attr, PyObject *pyvalue); + virtual int py_delattro(PyObject *attr); + virtual PyObject* py_repr(void) { return PyString_FromString(GetName().ReadPtr()); } /** diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index 595d2cb4070..40a2ff2ef66 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -226,18 +226,21 @@ KX_Scene* KX_SceneActuator::FindScene(char * sceneName) /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_SceneActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_SceneActuator", sizeof(KX_SceneActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -273,20 +276,20 @@ PyAttributeDef KX_SceneActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_SceneActuator::_getattr(const char *attr) +PyObject* KX_SceneActuator::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int KX_SceneActuator::_setattr(const char *attr, PyObject *value) +int KX_SceneActuator::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } PyObject* KX_SceneActuator::pyattr_get_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) diff --git a/source/gameengine/Ketsji/KX_SceneActuator.h b/source/gameengine/Ketsji/KX_SceneActuator.h index 83b0d63bcd2..f1904f95c2a 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.h +++ b/source/gameengine/Ketsji/KX_SceneActuator.h @@ -92,8 +92,8 @@ class KX_SceneActuator : public SCA_IActuator /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); /* 1. set */ /* Removed */ diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index f6c0283d49f..b8d660daa08 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -233,18 +233,21 @@ void KX_SoundActuator::setSoundObject(class SND_SoundObject* soundobject) /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_SoundActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_SoundActuator", sizeof(KX_SoundActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -286,9 +289,9 @@ PyAttributeDef KX_SoundActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_SoundActuator::_getattr(const char *attr) +PyObject* KX_SoundActuator::py_getattro(PyObject *attr) { - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_SoundActuator.h b/source/gameengine/Ketsji/KX_SoundActuator.h index 68d5b792729..3e4a4168434 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 char *attr); + virtual PyObject* py_getattro(PyObject *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 e48c4209923..31457230f60 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.cpp +++ b/source/gameengine/Ketsji/KX_StateActuator.cpp @@ -109,18 +109,21 @@ KX_StateActuator::Update() /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_StateActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_StateActuator", sizeof(KX_StateActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -146,9 +149,9 @@ PyAttributeDef KX_StateActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_StateActuator::_getattr(const char *attr) +PyObject* KX_StateActuator::py_getattro(PyObject *attr) { - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); }; diff --git a/source/gameengine/Ketsji/KX_StateActuator.h b/source/gameengine/Ketsji/KX_StateActuator.h index 023b8993d7c..b6f1acf4a00 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 char *attr); + virtual PyObject* py_getattro(PyObject *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 b1c22a86f3d..49d3d20dc3d 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -242,18 +242,21 @@ bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll /* ------------------------------------------------------------------------- */ /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_TouchSensor::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_TouchSensor", sizeof(KX_TouchSensor), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -288,29 +291,31 @@ PyAttributeDef KX_TouchSensor::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_TouchSensor::_getattr(const char *attr) +PyObject* KX_TouchSensor::py_getattro(PyObject *attr) { - if (!strcmp(attr, "objectHit")) { + PyObject* object= py_getattro_self(Attributes, this, attr); + if (object != NULL) + return object; + + char *attr_str= PyString_AsString(attr); + if (!strcmp(attr_str, "objectHit")) { if (m_hitObject) return m_hitObject->AddRef(); else Py_RETURN_NONE; } - if (!strcmp(attr, "objectHitList")) { + if (!strcmp(attr_str, "objectHitList")) { return m_colliders->AddRef(); } - - PyObject* object= _getattr_self(Attributes, this, attr); - if (object != NULL) - return object; - _getattr_up(SCA_ISensor); + + py_getattro_up(SCA_ISensor); } -int KX_TouchSensor::_setattr(const char *attr, PyObject *value) +int KX_TouchSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_ISensor::_setattr(attr, value); + return SCA_ISensor::py_setattro(attr, value); } /* Python API */ diff --git a/source/gameengine/Ketsji/KX_TouchSensor.h b/source/gameengine/Ketsji/KX_TouchSensor.h index 18ce9406a9b..93fadef4abd 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.h +++ b/source/gameengine/Ketsji/KX_TouchSensor.h @@ -120,8 +120,8 @@ public: /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); //Deprecated -----> /* 1. setProperty */ diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 575abc5d748..58e17785b81 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -425,18 +425,21 @@ bool KX_TrackToActuator::Update(double curtime, bool frame) /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_TrackToActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_TrackToActuator", sizeof(KX_TrackToActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -501,20 +504,20 @@ int KX_TrackToActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUT } -PyObject* KX_TrackToActuator::_getattr(const char *attr) +PyObject* KX_TrackToActuator::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int KX_TrackToActuator::_setattr(const char *attr, PyObject* value) +int KX_TrackToActuator::py_setattro(PyObject *attr, PyObject* value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } /* 1. setObject */ diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.h b/source/gameengine/Ketsji/KX_TrackToActuator.h index f81958dfb33..cc4049e19a8 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 char *attr); - virtual int _setattr(const char *attr, PyObject* value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject* value); /* These are used to get and set m_ob */ static PyObject* pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp index 4960228056a..6afea4d3227 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp @@ -299,33 +299,37 @@ PyObject* KX_VehicleWrapper::PyGetConstraintType(PyObject* self, //python specific stuff PyTypeObject KX_VehicleWrapper::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_VehicleWrapper", sizeof(KX_VehicleWrapper), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; PyParentObject KX_VehicleWrapper::Parents[] = { &KX_VehicleWrapper::Type, + &PyObjectPlus::Type, NULL }; -PyObject* KX_VehicleWrapper::_getattr(const char *attr) +PyObject* KX_VehicleWrapper::py_getattro(PyObject *attr) { //here you can search for existing data members (like mass,friction etc.) - _getattr_up(PyObjectPlus); + py_getattro_up(PyObjectPlus); } -int KX_VehicleWrapper::_setattr(const char *attr,PyObject* pyobj) +int KX_VehicleWrapper::py_setattro(PyObject *attr,PyObject* pyobj) { PyTypeObject* type = pyobj->ob_type; @@ -349,7 +353,7 @@ int KX_VehicleWrapper::_setattr(const char *attr,PyObject* pyobj) result = 0; } if (result) - result = PyObjectPlus::_setattr(attr,pyobj); + result = PyObjectPlus::py_setattro(attr,pyobj); return result; }; diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.h b/source/gameengine/Ketsji/KX_VehicleWrapper.h index cad926ce85a..4e03183bf85 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 char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); std::vector m_motionStates; diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp index d7b5203795d..8c8291ef791 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.cpp +++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp @@ -37,18 +37,21 @@ #include "KX_PyMath.h" PyTypeObject KX_VertexProxy::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_VertexProxy", sizeof(KX_VertexProxy), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -80,43 +83,43 @@ PyAttributeDef KX_VertexProxy::Attributes[] = { }; PyObject* -KX_VertexProxy::_getattr(const char *attr) +KX_VertexProxy::py_getattro(PyObject *attr) { - - if (attr[1]=='\0') { // Group single letters + char *attr_str= PyString_AsString(attr); + if (attr_str[1]=='\0') { // Group single letters // pos - if (attr[0]=='x') + if (attr_str[0]=='x') return PyFloat_FromDouble(m_vertex->getXYZ()[0]); - if (attr[0]=='y') + if (attr_str[0]=='y') return PyFloat_FromDouble(m_vertex->getXYZ()[1]); - if (attr[0]=='z') + if (attr_str[0]=='z') return PyFloat_FromDouble(m_vertex->getXYZ()[2]); // Col - if (attr[0]=='r') + if (attr_str[0]=='r') return PyFloat_FromDouble(m_vertex->getRGBA()[0]/255.0); - if (attr[0]=='g') + if (attr_str[0]=='g') return PyFloat_FromDouble(m_vertex->getRGBA()[1]/255.0); - if (attr[0]=='b') + if (attr_str[0]=='b') return PyFloat_FromDouble(m_vertex->getRGBA()[2]/255.0); - if (attr[0]=='a') + if (attr_str[0]=='a') return PyFloat_FromDouble(m_vertex->getRGBA()[3]/255.0); // UV - if (attr[0]=='u') + if (attr_str[0]=='u') return PyFloat_FromDouble(m_vertex->getUV1()[0]); - if (attr[0]=='v') + if (attr_str[0]=='v') return PyFloat_FromDouble(m_vertex->getUV1()[1]); } - if (!strcmp(attr, "XYZ")) + if (!strcmp(attr_str, "XYZ")) return PyObjectFrom(MT_Vector3(m_vertex->getXYZ())); - if (!strcmp(attr, "UV")) + if (!strcmp(attr_str, "UV")) return PyObjectFrom(MT_Point2(m_vertex->getUV1())); - if (!strcmp(attr, "color") || !strcmp(attr, "colour")) + if (!strcmp(attr_str, "color") || !strcmp(attr_str, "colour")) { const unsigned char *colp = m_vertex->getRGBA(); MT_Vector4 color(colp[0], colp[1], colp[2], colp[3]); @@ -124,19 +127,20 @@ KX_VertexProxy::_getattr(const char *attr) return PyObjectFrom(color); } - if (!strcmp(attr, "normal")) + if (!strcmp(attr_str, "normal")) { return PyObjectFrom(MT_Vector3(m_vertex->getNormal())); } - _getattr_up(SCA_IObject); + py_getattro_up(SCA_IObject); } -int KX_VertexProxy::_setattr(const char *attr, PyObject *pyvalue) +int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue) { + char *attr_str= PyString_AsString(attr); if (PySequence_Check(pyvalue)) { - if (!strcmp(attr, "XYZ")) + if (!strcmp(attr_str, "XYZ")) { MT_Point3 vec; if (PyVecTo(pyvalue, vec)) @@ -148,7 +152,7 @@ int KX_VertexProxy::_setattr(const char *attr, PyObject *pyvalue) return 1; } - if (!strcmp(attr, "UV")) + if (!strcmp(attr_str, "UV")) { MT_Point2 vec; if (PyVecTo(pyvalue, vec)) @@ -160,7 +164,7 @@ int KX_VertexProxy::_setattr(const char *attr, PyObject *pyvalue) return 1; } - if (!strcmp(attr, "color") || !strcmp(attr, "colour")) + if (!strcmp(attr_str, "color") || !strcmp(attr_str, "colour")) { MT_Vector4 vec; if (PyVecTo(pyvalue, vec)) @@ -172,7 +176,7 @@ int KX_VertexProxy::_setattr(const char *attr, PyObject *pyvalue) return 1; } - if (!strcmp(attr, "normal")) + if (!strcmp(attr_str, "normal")) { MT_Vector3 vec; if (PyVecTo(pyvalue, vec)) @@ -190,7 +194,7 @@ int KX_VertexProxy::_setattr(const char *attr, PyObject *pyvalue) float val = PyFloat_AsDouble(pyvalue); // pos MT_Point3 pos(m_vertex->getXYZ()); - if (!strcmp(attr, "x")) + if (!strcmp(attr_str, "x")) { pos.x() = val; m_vertex->SetXYZ(pos); @@ -198,7 +202,7 @@ int KX_VertexProxy::_setattr(const char *attr, PyObject *pyvalue) return 0; } - if (!strcmp(attr, "y")) + if (!strcmp(attr_str, "y")) { pos.y() = val; m_vertex->SetXYZ(pos); @@ -206,7 +210,7 @@ int KX_VertexProxy::_setattr(const char *attr, PyObject *pyvalue) return 0; } - if (!strcmp(attr, "z")) + if (!strcmp(attr_str, "z")) { pos.z() = val; m_vertex->SetXYZ(pos); @@ -216,7 +220,7 @@ int KX_VertexProxy::_setattr(const char *attr, PyObject *pyvalue) // uv MT_Point2 uv = m_vertex->getUV1(); - if (!strcmp(attr, "u")) + if (!strcmp(attr_str, "u")) { uv[0] = val; m_vertex->SetUV(uv); @@ -224,7 +228,7 @@ int KX_VertexProxy::_setattr(const char *attr, PyObject *pyvalue) return 0; } - if (!strcmp(attr, "v")) + if (!strcmp(attr_str, "v")) { uv[1] = val; m_vertex->SetUV(uv); @@ -234,7 +238,7 @@ int KX_VertexProxy::_setattr(const char *attr, PyObject *pyvalue) // uv MT_Point2 uv2 = m_vertex->getUV2(); - if (!strcmp(attr, "u2")) + if (!strcmp(attr_str, "u2")) { uv[0] = val; m_vertex->SetUV2(uv); @@ -242,7 +246,7 @@ int KX_VertexProxy::_setattr(const char *attr, PyObject *pyvalue) return 0; } - if (!strcmp(attr, "v2")) + if (!strcmp(attr_str, "v2")) { uv[1] = val; m_vertex->SetUV2(uv); @@ -254,28 +258,28 @@ int KX_VertexProxy::_setattr(const char *attr, PyObject *pyvalue) unsigned int icol = *((const unsigned int *)m_vertex->getRGBA()); unsigned char *cp = (unsigned char*) &icol; val *= 255.0; - if (!strcmp(attr, "r")) + if (!strcmp(attr_str, "r")) { cp[0] = (unsigned char) val; m_vertex->SetRGBA(icol); m_mesh->SetMeshModified(true); return 0; } - if (!strcmp(attr, "g")) + if (!strcmp(attr_str, "g")) { cp[1] = (unsigned char) val; m_vertex->SetRGBA(icol); m_mesh->SetMeshModified(true); return 0; } - if (!strcmp(attr, "b")) + if (!strcmp(attr_str, "b")) { cp[2] = (unsigned char) val; m_vertex->SetRGBA(icol); m_mesh->SetMeshModified(true); return 0; } - if (!strcmp(attr, "a")) + if (!strcmp(attr_str, "a")) { cp[3] = (unsigned char) val; m_vertex->SetRGBA(icol); @@ -284,7 +288,7 @@ int KX_VertexProxy::_setattr(const char *attr, PyObject *pyvalue) } } - return SCA_IObject::_setattr(attr, pyvalue); + return SCA_IObject::py_setattro(attr, pyvalue); } KX_VertexProxy::KX_VertexProxy(KX_MeshProxy*mesh, RAS_TexVert* vertex) diff --git a/source/gameengine/Ketsji/KX_VertexProxy.h b/source/gameengine/Ketsji/KX_VertexProxy.h index 28196075904..26772fc7d60 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 char *attr); - virtual int _setattr(const char *attr, PyObject *pyvalue); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *pyvalue); KX_PYMETHOD_NOARGS(KX_VertexProxy,GetXYZ); KX_PYMETHOD_O(KX_VertexProxy,SetXYZ); diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp index 10e8c827394..35edd84f994 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp @@ -91,18 +91,21 @@ KX_VisibilityActuator::Update() /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_VisibilityActuator::Type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(NULL) 0, "KX_VisibilityActuator", sizeof(KX_VisibilityActuator), 0, PyDestructor, 0, - __getattr, - __setattr, 0, - __repr, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0, + py_base_getattro, + py_base_setattro, + 0,0,0,0,0,0,0,0,0, Methods }; @@ -131,20 +134,20 @@ PyAttributeDef KX_VisibilityActuator::Attributes[] = { { NULL } //Sentinel }; -PyObject* KX_VisibilityActuator::_getattr(const char *attr) +PyObject* KX_VisibilityActuator::py_getattro(PyObject *attr) { - PyObject* object = _getattr_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - _getattr_up(SCA_IActuator); + py_getattro_up(SCA_IActuator); } -int KX_VisibilityActuator::_setattr(const char *attr, PyObject *value) +int KX_VisibilityActuator::py_setattro(PyObject *attr, PyObject *value) { - int ret = _setattr_self(Attributes, this, attr, value); + int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - return SCA_IActuator::_setattr(attr, value); + return SCA_IActuator::py_setattro(attr, value); } diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.h b/source/gameengine/Ketsji/KX_VisibilityActuator.h index 2e2a5957777..fca37500915 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.h +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.h @@ -67,8 +67,8 @@ class KX_VisibilityActuator : public SCA_IActuator /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */ - virtual PyObject* _getattr(const char *attr); - virtual int _setattr(const char *attr, PyObject *value); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); // Deprecated -----> KX_PYMETHOD_DOC(KX_VisibilityActuator,SetVisible); -- cgit v1.2.3 From e6985d31b589a232bb17dd4c156614df781b8dad Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 3 Apr 2009 15:08:38 +0000 Subject: Some users could not build with python 2.5, hopefully this fixes it. --- source/gameengine/Ketsji/KX_GameObject.cpp | 4 ++-- source/gameengine/Ketsji/KX_GameObject.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index f0c5667479c..e79ef5ab72b 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1104,7 +1104,7 @@ PyObject* KX_GameObject::PyGetPosition(PyObject* self) } -int KX_GameObject::Map_Len(PyObject* self_v) +Py_ssize_t KX_GameObject::Map_Len(PyObject* self_v) { return (static_cast(self_v))->GetPropertyCount(); } @@ -1173,7 +1173,7 @@ int KX_GameObject::Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val) PyMappingMethods KX_GameObject::Mapping = { - (inquiry)KX_GameObject::Map_Len, /*inquiry mp_length */ + (lenfunc)KX_GameObject::Map_Len, /*inquiry mp_length */ (binaryfunc)KX_GameObject::Map_GetItem, /*binaryfunc mp_subscript */ (objobjargproc)KX_GameObject::Map_SetItem, /*objobjargproc mp_ass_subscript */ }; diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 4b136e268db..9ed35b6d26b 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -826,7 +826,7 @@ public: static PyObject* pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); /* getitem/setitem */ - static int Map_Len(PyObject* self); + static Py_ssize_t Map_Len(PyObject* self); static PyMappingMethods Mapping; static PyObject* Map_GetItem(PyObject *self_v, PyObject *item); static int Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val); -- cgit v1.2.3 From 07930c0b0943810a4914f7ce2d035bfbe77f796a Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Fri, 3 Apr 2009 19:09:52 +0000 Subject: BGE API cleanup: RandomActuator. --- source/gameengine/GameLogic/SCA_RandomActuator.cpp | 140 ++++++++++----------- source/gameengine/GameLogic/SCA_RandomActuator.h | 46 +++---- 2 files changed, 79 insertions(+), 107 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp index a9a664b0686..7af116fad99 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp +++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp @@ -348,16 +348,18 @@ PyMethodDef SCA_RandomActuator::Methods[] = { {"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}, - {"setIntConst", (PyCFunction) SCA_RandomActuator::sPySetIntConst, METH_VARARGS, (PY_METHODCHAR)SetIntConst_doc}, - {"setIntUniform", (PyCFunction) SCA_RandomActuator::sPySetIntUniform, METH_VARARGS, (PY_METHODCHAR)SetIntUniform_doc}, - {"setIntPoisson", (PyCFunction) SCA_RandomActuator::sPySetIntPoisson, METH_VARARGS, (PY_METHODCHAR)SetIntPoisson_doc}, - {"setFloatConst", (PyCFunction) SCA_RandomActuator::sPySetFloatConst, METH_VARARGS, (PY_METHODCHAR)SetFloatConst_doc}, - {"setFloatUniform", (PyCFunction) SCA_RandomActuator::sPySetFloatUniform, METH_VARARGS, (PY_METHODCHAR)SetFloatUniform_doc}, - {"setFloatNormal", (PyCFunction) SCA_RandomActuator::sPySetFloatNormal, METH_VARARGS, (PY_METHODCHAR)SetFloatNormal_doc}, - {"setFloatNegativeExponential", (PyCFunction) SCA_RandomActuator::sPySetFloatNegativeExponential, METH_VARARGS, (PY_METHODCHAR)SetFloatNegativeExponential_doc}, + KX_PYMETHODTABLE(SCA_RandomActuator, setBoolConst), + KX_PYMETHODTABLE_NOARGS(SCA_RandomActuator, setBoolUniform), + KX_PYMETHODTABLE(SCA_RandomActuator, setBoolBernouilli), + + KX_PYMETHODTABLE(SCA_RandomActuator, setIntConst), + KX_PYMETHODTABLE(SCA_RandomActuator, setIntUniform), + KX_PYMETHODTABLE(SCA_RandomActuator, setIntPoisson), + + KX_PYMETHODTABLE(SCA_RandomActuator, setFloatConst), + KX_PYMETHODTABLE(SCA_RandomActuator, setFloatUniform), + KX_PYMETHODTABLE(SCA_RandomActuator, setFloatNormal), + KX_PYMETHODTABLE(SCA_RandomActuator, setFloatNegativeExponential), {NULL,NULL} //Sentinel }; @@ -366,17 +368,33 @@ PyAttributeDef SCA_RandomActuator::Attributes[] = { 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), + KX_PYATTRIBUTE_RW_FUNCTION("seed",SCA_RandomActuator,pyattr_get_seed,pyattr_set_seed), { NULL } //Sentinel }; +PyObject* SCA_RandomActuator::pyattr_get_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_RandomActuator* act = static_cast(self); + return PyInt_FromLong(act->m_base->GetSeed()); +} + +int SCA_RandomActuator::pyattr_set_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + SCA_RandomActuator* act = static_cast(self); + if (PyInt_Check(value)) { + int ival = PyInt_AsLong(value); + act->m_base->SetSeed(ival); + return 0; + } else { + PyErr_SetString(PyExc_TypeError, "expected an integer"); + return 1; + } +} + PyObject* SCA_RandomActuator::py_getattro(PyObject *attr) { PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "seed")) { - return PyInt_FromLong(m_base->GetSeed()); - } py_getattro_up(SCA_IActuator); } @@ -385,18 +403,6 @@ int SCA_RandomActuator::py_setattro(PyObject *attr, PyObject *value) int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "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 SCA_IActuator::py_setattro(attr, value); } @@ -494,13 +500,11 @@ PyObject* SCA_RandomActuator::PyGetProperty(PyObject* self, PyObject* args, PyOb } /* 11. setBoolConst */ -const char SCA_RandomActuator::SetBoolConst_doc[] = +KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setBoolConst, "setBoolConst(value)\n" "\t- value: 0 or 1\n" -"\tSet this generator to produce a constant boolean value.\n"; -PyObject* SCA_RandomActuator::PySetBoolConst(PyObject* self, - PyObject* args, - PyObject* kwds) { +"\tSet this generator to produce a constant boolean value.\n") +{ int paraArg; if(!PyArg_ParseTuple(args, "i", ¶Arg)) { return NULL; @@ -512,25 +516,21 @@ PyObject* SCA_RandomActuator::PySetBoolConst(PyObject* self, Py_RETURN_NONE; } /* 12. setBoolUniform, */ -const char SCA_RandomActuator::SetBoolUniform_doc[] = +KX_PYMETHODDEF_DOC_NOARGS(SCA_RandomActuator, setBoolUniform, "setBoolUniform()\n" -"\tSet this generator to produce true and false, each with 50%% chance of occuring\n"; -PyObject* SCA_RandomActuator::PySetBoolUniform(PyObject* self, - PyObject* args, - PyObject* kwds) { +"\tSet this generator to produce true and false, each with 50%% chance of occuring\n") +{ /* no args */ m_distribution = KX_RANDOMACT_BOOL_UNIFORM; enforceConstraints(); Py_RETURN_NONE; } /* 13. setBoolBernouilli, */ -const char SCA_RandomActuator::SetBoolBernouilli_doc[] = +KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setBoolBernouilli, "setBoolBernouilli(value)\n" "\t- value: a float between 0 and 1\n" -"\tReturn false value * 100%% of the time.\n"; -PyObject* SCA_RandomActuator::PySetBoolBernouilli(PyObject* self, - PyObject* args, - PyObject* kwds) { +"\tReturn false value * 100%% of the time.\n") +{ float paraArg; if(!PyArg_ParseTuple(args, "f", ¶Arg)) { return NULL; @@ -542,13 +542,11 @@ PyObject* SCA_RandomActuator::PySetBoolBernouilli(PyObject* self, Py_RETURN_NONE; } /* 14. setIntConst,*/ -const char SCA_RandomActuator::SetIntConst_doc[] = +KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntConst, "setIntConst(value)\n" "\t- value: integer\n" -"\tAlways return value\n"; -PyObject* SCA_RandomActuator::PySetIntConst(PyObject* self, - PyObject* args, - PyObject* kwds) { +"\tAlways return value\n") +{ int paraArg; if(!PyArg_ParseTuple(args, "i", ¶Arg)) { return NULL; @@ -560,15 +558,13 @@ PyObject* SCA_RandomActuator::PySetIntConst(PyObject* self, Py_RETURN_NONE; } /* 15. setIntUniform,*/ -const char SCA_RandomActuator::SetIntUniform_doc[] = +KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntUniform, "setIntUniform(lower_bound, upper_bound)\n" "\t- lower_bound: integer\n" "\t- upper_bound: integer\n" "\tReturn a random integer between lower_bound and\n" -"\tupper_bound. The boundaries are included.\n"; -PyObject* SCA_RandomActuator::PySetIntUniform(PyObject* self, - PyObject* args, - PyObject* kwds) { +"\tupper_bound. The boundaries are included.\n") +{ int paraArg1, paraArg2; if(!PyArg_ParseTuple(args, "ii", ¶Arg1, ¶Arg2)) { return NULL; @@ -581,15 +577,13 @@ PyObject* SCA_RandomActuator::PySetIntUniform(PyObject* self, Py_RETURN_NONE; } /* 16. setIntPoisson, */ -const char SCA_RandomActuator::SetIntPoisson_doc[] = +KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntPoisson, "setIntPoisson(value)\n" "\t- value: float\n" "\tReturn a Poisson-distributed number. This performs a series\n" "\tof Bernouilli tests with parameter value. It returns the\n" -"\tnumber of tries needed to achieve succes.\n"; -PyObject* SCA_RandomActuator::PySetIntPoisson(PyObject* self, - PyObject* args, - PyObject* kwds) { +"\tnumber of tries needed to achieve succes.\n") +{ float paraArg; if(!PyArg_ParseTuple(args, "f", ¶Arg)) { return NULL; @@ -600,14 +594,12 @@ PyObject* SCA_RandomActuator::PySetIntPoisson(PyObject* self, enforceConstraints(); Py_RETURN_NONE; } -/* 17. setFloatConst,*/ -const char SCA_RandomActuator::SetFloatConst_doc[] = +/* 17. setFloatConst */ +KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatConst, "setFloatConst(value)\n" "\t- value: float\n" -"\tAlways return value\n"; -PyObject* SCA_RandomActuator::PySetFloatConst(PyObject* self, - PyObject* args, - PyObject* kwds) { +"\tAlways return value\n") +{ float paraArg; if(!PyArg_ParseTuple(args, "f", ¶Arg)) { return NULL; @@ -619,15 +611,13 @@ PyObject* SCA_RandomActuator::PySetFloatConst(PyObject* self, Py_RETURN_NONE; } /* 18. setFloatUniform, */ -const char SCA_RandomActuator::SetFloatUniform_doc[] = +KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatUniform, "setFloatUniform(lower_bound, upper_bound)\n" "\t- lower_bound: float\n" "\t- upper_bound: float\n" "\tReturn a random integer between lower_bound and\n" -"\tupper_bound.\n"; -PyObject* SCA_RandomActuator::PySetFloatUniform(PyObject* self, - PyObject* args, - PyObject* kwds) { +"\tupper_bound.\n") +{ float paraArg1, paraArg2; if(!PyArg_ParseTuple(args, "ff", ¶Arg1, ¶Arg2)) { return NULL; @@ -640,15 +630,13 @@ PyObject* SCA_RandomActuator::PySetFloatUniform(PyObject* self, Py_RETURN_NONE; } /* 19. setFloatNormal, */ -const char SCA_RandomActuator::SetFloatNormal_doc[] = +KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatNormal, "setFloatNormal(mean, standard_deviation)\n" "\t- mean: float\n" "\t- standard_deviation: float\n" "\tReturn normal-distributed numbers. The average is mean, and the\n" -"\tdeviation from the mean is characterized by standard_deviation.\n"; -PyObject* SCA_RandomActuator::PySetFloatNormal(PyObject* self, - PyObject* args, - PyObject* kwds) { +"\tdeviation from the mean is characterized by standard_deviation.\n") +{ float paraArg1, paraArg2; if(!PyArg_ParseTuple(args, "ff", ¶Arg1, ¶Arg2)) { return NULL; @@ -661,14 +649,12 @@ PyObject* SCA_RandomActuator::PySetFloatNormal(PyObject* self, Py_RETURN_NONE; } /* 20. setFloatNegativeExponential, */ -const char SCA_RandomActuator::SetFloatNegativeExponential_doc[] = +KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatNegativeExponential, "setFloatNegativeExponential(half_life)\n" "\t- half_life: float\n" "\tReturn negative-exponentially distributed numbers. The half-life 'time'\n" -"\tis characterized by half_life.\n"; -PyObject* SCA_RandomActuator::PySetFloatNegativeExponential(PyObject* self, - PyObject* args, - PyObject* kwds) { +"\tis characterized by half_life.\n") +{ float paraArg; if(!PyArg_ParseTuple(args, "f", ¶Arg)) { return NULL; diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.h b/source/gameengine/GameLogic/SCA_RandomActuator.h index 96ca353257f..fbafbb69c01 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.h +++ b/source/gameengine/GameLogic/SCA_RandomActuator.h @@ -99,43 +99,29 @@ class SCA_RandomActuator : public SCA_IActuator virtual PyObject* py_getattro(PyObject *attr); virtual int py_setattro(PyObject *attr, PyObject *value); - /* 1. setSeed */ + static PyObject* pyattr_get_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + + // Deprecated methods -----> KX_PYMETHOD_DOC(SCA_RandomActuator,SetSeed); - /* 2. getSeed */ KX_PYMETHOD_DOC(SCA_RandomActuator,GetSeed); - /* 3. setPara1 -removed- */ - /* 4. getPara1 */ KX_PYMETHOD_DOC(SCA_RandomActuator,GetPara1); - /* 5. setPara2 -removed- */ - /* 6. getPara2 */ KX_PYMETHOD_DOC(SCA_RandomActuator,GetPara2); - /* 7. setDistribution -removed- */ - /* 8. getDistribution */ KX_PYMETHOD_DOC(SCA_RandomActuator,GetDistribution); - /* 9. setProperty */ KX_PYMETHOD_DOC(SCA_RandomActuator,SetProperty); - /* 10. getProperty */ KX_PYMETHOD_DOC(SCA_RandomActuator,GetProperty); - /* 11. setBoolConst */ - KX_PYMETHOD_DOC(SCA_RandomActuator,SetBoolConst); - /* 12. setBoolUniform, */ - KX_PYMETHOD_DOC(SCA_RandomActuator,SetBoolUniform); - /* 13. setBoolBernouilli, */ - KX_PYMETHOD_DOC(SCA_RandomActuator,SetBoolBernouilli); - /* 14. setIntConst,*/ - KX_PYMETHOD_DOC(SCA_RandomActuator,SetIntConst); - /* 15. setIntUniform,*/ - KX_PYMETHOD_DOC(SCA_RandomActuator,SetIntUniform); - /* 16. setIntPoisson, */ - KX_PYMETHOD_DOC(SCA_RandomActuator,SetIntPoisson); - /* 17. setFloatConst,*/ - KX_PYMETHOD_DOC(SCA_RandomActuator,SetFloatConst); - /* 18. setFloatUniform, */ - KX_PYMETHOD_DOC(SCA_RandomActuator,SetFloatUniform); - /* 19. setFloatNormal, */ - KX_PYMETHOD_DOC(SCA_RandomActuator,SetFloatNormal); - /* 20. setFloatNegativeExponential, */ - KX_PYMETHOD_DOC(SCA_RandomActuator,SetFloatNegativeExponential); + // <----- + + KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setBoolConst); + KX_PYMETHOD_DOC_NOARGS(SCA_RandomActuator, setBoolUniform); + KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setBoolBernouilli); + KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setIntConst); + KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setIntUniform); + KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setIntPoisson); + KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatConst); + KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatUniform); + KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatNormal); + KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatNegativeExponential); }; /* end of class KX_EditObjectActuator : public SCA_PropertyActuator */ #endif -- cgit v1.2.3 From 6be69211843ee37ab9be763df0621db94dbfd69b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 4 Apr 2009 02:57:35 +0000 Subject: moved more attributes from getattr into PyAttributeDef's --- source/gameengine/Converter/BL_ActionActuator.cpp | 64 +++++++++--------- source/gameengine/Converter/BL_ActionActuator.h | 8 ++- .../Converter/BL_ShapeActionActuator.cpp | 68 +++++++++---------- .../gameengine/Converter/BL_ShapeActionActuator.h | 6 ++ source/gameengine/GameLogic/SCA_ISensor.cpp | 35 +++++----- source/gameengine/GameLogic/SCA_ISensor.h | 3 + source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 77 +++++++++++++--------- source/gameengine/GameLogic/SCA_JoystickSensor.h | 7 ++ .../gameengine/GameLogic/SCA_PythonController.cpp | 65 +++++++++++------- source/gameengine/GameLogic/SCA_PythonController.h | 4 ++ source/gameengine/GameLogic/SCA_RandomSensor.cpp | 35 +++++----- source/gameengine/GameLogic/SCA_RandomSensor.h | 3 + source/gameengine/Ketsji/KX_CameraActuator.cpp | 55 ++++++++-------- source/gameengine/Ketsji/KX_CameraActuator.h | 3 + source/gameengine/Ketsji/KX_TouchSensor.cpp | 33 ++++++---- source/gameengine/Ketsji/KX_TouchSensor.h | 4 ++ 16 files changed, 276 insertions(+), 194 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 943bb68f6f2..b7a961d6a9d 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -1025,6 +1025,7 @@ 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_RW_FUNCTION("action", BL_ActionActuator, pyattr_get_action, pyattr_set_action), 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), @@ -1036,10 +1037,6 @@ PyAttributeDef BL_ActionActuator::Attributes[] = { }; PyObject* BL_ActionActuator::py_getattro(PyObject *attr) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "action")) - return PyString_FromString(m_action->id.name+2); - PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; @@ -1047,39 +1044,44 @@ PyObject* BL_ActionActuator::py_getattro(PyObject *attr) { } int BL_ActionActuator::py_setattro(PyObject *attr, PyObject* value) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "action")) - { - if (!PyString_Check(value)) - { - PyErr_SetString(PyExc_ValueError, "expected a string"); - return 1; - } + int ret = py_setattro_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; + return SCA_IActuator::py_setattro(attr, value); +} - STR_String val = PyString_AsString(value); - - if (val == "") - { - m_action = NULL; - return 0; - } - bAction *action; - - action = (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); - +PyObject* BL_ActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + BL_ActionActuator* self= static_cast(self_v); + return PyString_FromString(self->GetAction()->id.name+2); +} + +int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + BL_ActionActuator* self= static_cast(self_v); + + if (!PyString_Check(value)) + { + PyErr_SetString(PyExc_ValueError, "expected the string name of the action"); + return -1; + } + + bAction *action= NULL; + STR_String val = PyString_AsString(value); + + if (val != "") + { + (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 = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); -} \ No newline at end of file + + self->SetAction(action); + return 0; + +} diff --git a/source/gameengine/Converter/BL_ActionActuator.h b/source/gameengine/Converter/BL_ActionActuator.h index 7160dd4dad0..d5b5762d9e7 100644 --- a/source/gameengine/Converter/BL_ActionActuator.h +++ b/source/gameengine/Converter/BL_ActionActuator.h @@ -81,6 +81,9 @@ public: virtual void ProcessReplica(); void SetBlendTime (float newtime); + + bAction* GetAction() { return m_action; } + void SetAction(bAction* act) { m_action= act; } //Deprecated -----> KX_PYMETHOD_DOC(BL_ActionActuator,SetAction); @@ -113,6 +116,9 @@ public: virtual PyObject* py_getattro(PyObject* attr); virtual int py_setattro(PyObject* attr, PyObject* value); + static PyObject* pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + /* attribute check */ static int CheckFrame(void *self, const PyAttributeDef*) { @@ -151,8 +157,8 @@ public: PyErr_SetString(PyExc_ValueError, "invalid type supplied"); return 1; } - } + protected: void SetStartTime(float curtime); diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index c53be4653ca..3c0ce0918f2 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -474,6 +474,7 @@ 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_RW_FUNCTION("action", BL_ShapeActionActuator, pyattr_get_action, pyattr_set_action), 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), @@ -485,9 +486,6 @@ PyAttributeDef BL_ShapeActionActuator::Attributes[] = { PyObject* BL_ShapeActionActuator::py_getattro(PyObject* attr) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "action")) - return PyString_FromString(m_action->id.name+2); PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; @@ -495,37 +493,6 @@ PyObject* BL_ShapeActionActuator::py_getattro(PyObject* attr) { } int BL_ShapeActionActuator::py_setattro(PyObject *attr, PyObject* value) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "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 = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; @@ -916,3 +883,36 @@ PyObject* BL_ShapeActionActuator::PySetType(PyObject* self, Py_RETURN_NONE; } +PyObject* BL_ShapeActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + BL_ShapeActionActuator* self= static_cast(self_v); + return PyString_FromString(self->GetAction()->id.name+2); +} + +int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + BL_ShapeActionActuator* self= static_cast(self_v); + /* exact copy of BL_ActionActuator's function from here down */ + if (!PyString_Check(value)) + { + PyErr_SetString(PyExc_ValueError, "expected the string name of the action"); + return -1; + } + + bAction *action= NULL; + STR_String val = PyString_AsString(value); + + if (val != "") + { + (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); + if (action==NULL) + { + PyErr_SetString(PyExc_ValueError, "action not found!"); + return 1; + } + } + + self->SetAction(action); + return 0; + +} diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.h b/source/gameengine/Converter/BL_ShapeActionActuator.h index ea25d66e050..162580fca85 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.h +++ b/source/gameengine/Converter/BL_ShapeActionActuator.h @@ -79,6 +79,9 @@ public: void SetBlendTime (float newtime); void BlendShape(struct Key* key, float weigth); + + bAction* GetAction() { return m_action; } + void SetAction(bAction* act) { m_action= act; } KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetAction); KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetBlendin); @@ -106,6 +109,9 @@ public: virtual PyObject* py_getattro(PyObject* attr); virtual int py_setattro(PyObject* attr, PyObject* value); + static PyObject* pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int CheckBlendTime(void *self, const PyAttributeDef*) { BL_ShapeActionActuator* act = reinterpret_cast(self); diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index 8a40c0c35f3..a4f493d82c8 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -454,9 +454,8 @@ PyAttributeDef SCA_ISensor::Attributes[] = { 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 py_getattro - KX_PYATTRIBUTE_DUMMY("triggered"), - KX_PYATTRIBUTE_DUMMY("positive"), + KX_PYATTRIBUTE_RO_FUNCTION("triggered", SCA_ISensor, pyattr_get_triggered), + KX_PYATTRIBUTE_RO_FUNCTION("positive", SCA_ISensor, pyattr_get_positive), { NULL } //Sentinel }; @@ -466,20 +465,6 @@ SCA_ISensor::py_getattro(PyObject *attr) PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "triggered")) - { - int retval = 0; - if (SCA_PythonController::m_sCurrentController) - retval = SCA_PythonController::m_sCurrentController->IsTriggered(this); - return PyInt_FromLong(retval); - } - if (!strcmp(attr_str, "positive")) - { - int retval = IsPositiveTrigger(); - return PyInt_FromLong(retval); - } py_getattro_up(SCA_ILogicBrick); } @@ -490,4 +475,20 @@ int SCA_ISensor::py_setattro(PyObject *attr, PyObject *value) return ret; return SCA_ILogicBrick::py_setattro(attr, value); } + +PyObject* SCA_ISensor::pyattr_get_triggered(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_ISensor* self= static_cast(self_v); + int retval = 0; + if (SCA_PythonController::m_sCurrentController) + retval = SCA_PythonController::m_sCurrentController->IsTriggered(self); + return PyInt_FromLong(retval); +} + +PyObject* SCA_ISensor::pyattr_get_positive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_ISensor* self= static_cast(self_v); + return PyInt_FromLong(self->IsPositiveTrigger()); +} + /* eof */ diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h index ce7b66df1cd..cfc95682089 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.h +++ b/source/gameengine/GameLogic/SCA_ISensor.h @@ -154,6 +154,9 @@ public: KX_PYMETHOD_DOC(SCA_ISensor,SetLevel); //<------ KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,reset); + + static PyObject* pyattr_get_triggered(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_positive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); }; #endif //__SCA_ISENSOR diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 0cfd6843c1b..2744d7f6609 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -333,38 +333,18 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = { KX_PYATTRIBUTE_INT_RW("button",0,100,false,SCA_JoystickSensor,m_button), 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 py_setattro - // you still need to defined them in py_getattro - KX_PYATTRIBUTE_DUMMY("axisPosition"), - KX_PYATTRIBUTE_DUMMY("numAxis"), - KX_PYATTRIBUTE_DUMMY("numButtons"), - KX_PYATTRIBUTE_DUMMY("numHats"), - KX_PYATTRIBUTE_DUMMY("connected"), + KX_PYATTRIBUTE_RO_FUNCTION("axisPosition", SCA_JoystickSensor, pyattr_get_axis_position), + KX_PYATTRIBUTE_RO_FUNCTION("numAxis", SCA_JoystickSensor, pyattr_get_num_axis), + KX_PYATTRIBUTE_RO_FUNCTION("numButtons", SCA_JoystickSensor, pyattr_get_num_buttons), + KX_PYATTRIBUTE_RO_FUNCTION("numHats", SCA_JoystickSensor, pyattr_get_num_hats), + KX_PYATTRIBUTE_RO_FUNCTION("connected", SCA_JoystickSensor, pyattr_get_connected), + + { NULL } //Sentinel }; -PyObject* SCA_JoystickSensor::py_getattro(PyObject *attr) { - SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); - char *attr_str= PyString_AsString(attr); - - if (!strcmp(attr_str, "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 (!strcmp(attr_str, "numAxis")) { - return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 ); - } - if (!strcmp(attr_str, "numButtons")) { - return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 ); - } - if (!strcmp(attr_str, "numHats")) { - return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 ); - } - if (!strcmp(attr_str, "connected")) { - return PyBool_FromLong( joy ? joy->Connected() : 0 ); - } +PyObject* SCA_JoystickSensor::py_getattro(PyObject *attr) +{ PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; @@ -532,7 +512,6 @@ const char SCA_JoystickSensor::GetButtonStatus_doc[] = "\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)){ @@ -609,3 +588,41 @@ PyObject* SCA_JoystickSensor::PyConnected( PyObject* self ) { SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); return PyBool_FromLong( joy ? joy->Connected() : 0 ); } + + +PyObject* SCA_JoystickSensor::pyattr_get_axis_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_JoystickSensor* self= static_cast(self_v); + SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + + if(joy) return Py_BuildValue("[iiii]", joy->GetAxis10(), joy->GetAxis11(), joy->GetAxis20(), joy->GetAxis21()); + else return Py_BuildValue("[iiii]", 0, 0, 0, 0); +} + +PyObject* SCA_JoystickSensor::pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_JoystickSensor* self= static_cast(self_v); + SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + return PyInt_FromLong( joy ? joy->GetNumberOfAxes() : 0 ); +} + +PyObject* SCA_JoystickSensor::pyattr_get_num_buttons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_JoystickSensor* self= static_cast(self_v); + SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 ); +} + +PyObject* SCA_JoystickSensor::pyattr_get_num_hats(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_JoystickSensor* self= static_cast(self_v); + SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 ); +} + +PyObject* SCA_JoystickSensor::pyattr_get_connected(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_JoystickSensor* self= static_cast(self_v); + SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->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 ccdd2107b21..f8a3eb8756a 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.h +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.h @@ -148,6 +148,13 @@ public: KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,NumberOfHats); KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,Connected); + static PyObject* pyattr_get_axis_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_num_buttons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_num_hats(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_connected(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + + /* attribute check */ static int CheckAxis(void *self, const PyAttributeDef*) { diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 2d200e0a238..4b9248a908f 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -265,6 +265,8 @@ PyMethodDef SCA_PythonController::Methods[] = { }; PyAttributeDef SCA_PythonController::Attributes[] = { + KX_PYATTRIBUTE_RO_FUNCTION("state", SCA_PythonController, pyattr_get_state), + KX_PYATTRIBUTE_RW_FUNCTION("script", SCA_PythonController, pyattr_get_script, pyattr_set_script), { NULL } //Sentinel }; @@ -374,37 +376,19 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) PyObject* SCA_PythonController::py_getattro(PyObject *attr) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str,"state")) { - return PyInt_FromLong(m_statemask); - } - if (!strcmp(attr_str,"script")) { - return PyString_FromString(m_scriptText); - } + PyObject* object = py_getattro_self(Attributes, this, attr); + if (object != NULL) + return object; + py_getattro_up(SCA_IController); } int SCA_PythonController::py_setattro(PyObject *attr, PyObject *value) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str,"state")) { - PyErr_SetString(PyExc_AttributeError, "state is read only"); - return 1; - } - if (!strcmp(attr_str,"script")) { - char *scriptArg = PyString_AsString(value); - - if (scriptArg==NULL) { - PyErr_SetString(PyExc_TypeError, "expected a string (script name)"); - return -1; - } + int ret = py_setattro_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; - /* 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::py_setattro(attr, value); } @@ -548,4 +532,35 @@ PyObject* SCA_PythonController::PyGetState(PyObject* self) return PyInt_FromLong(m_statemask); } +PyObject* SCA_PythonController::pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_PythonController* self= static_cast(self_v); + return PyInt_FromLong(self->m_statemask); +} + +PyObject* SCA_PythonController::pyattr_get_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_PythonController* self= static_cast(self_v); + return PyString_FromString(self->m_scriptText); +} + +int SCA_PythonController::pyattr_set_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + SCA_PythonController* self= static_cast(self_v); + + 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 */ + self->SetScriptText(scriptArg); + + return 0; +} + + /* eof */ diff --git a/source/gameengine/GameLogic/SCA_PythonController.h b/source/gameengine/GameLogic/SCA_PythonController.h index 3348071c00f..f10c4e47ebb 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.h +++ b/source/gameengine/GameLogic/SCA_PythonController.h @@ -92,6 +92,10 @@ class SCA_PythonController : public SCA_IController KX_PYMETHOD_NOARGS(SCA_PythonController,GetScript); KX_PYMETHOD_NOARGS(SCA_PythonController,GetState); + static PyObject* pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + }; diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp index 84a9ef95e84..bdee64430fa 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp +++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp @@ -162,6 +162,7 @@ PyMethodDef SCA_RandomSensor::Methods[] = { PyAttributeDef SCA_RandomSensor::Attributes[] = { KX_PYATTRIBUTE_BOOL_RO("lastDraw",SCA_RandomSensor,m_lastdraw), + KX_PYATTRIBUTE_RW_FUNCTION("seed", SCA_RandomSensor, pyattr_get_seed, pyattr_set_seed), {NULL} //Sentinel }; @@ -169,11 +170,6 @@ PyObject* SCA_RandomSensor::py_getattro(PyObject *attr) { PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; - - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str,"seed")) { - return PyInt_FromLong(m_basegenerator->GetSeed()); - } py_getattro_up(SCA_ISensor); } @@ -182,17 +178,6 @@ int SCA_RandomSensor::py_setattro(PyObject *attr, PyObject *value) int ret = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str,"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::py_setattro(attr, value); } @@ -234,4 +219,22 @@ PyObject* SCA_RandomSensor::PyGetLastDraw(PyObject* self, PyObject* args, PyObje return PyInt_FromLong(m_lastdraw); } + +PyObject* SCA_RandomSensor::pyattr_get_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_RandomSensor* self= static_cast(self_v); + return PyInt_FromLong(self->m_basegenerator->GetSeed()); +} + +int SCA_RandomSensor::pyattr_set_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + SCA_RandomSensor* self= static_cast(self_v); + if (!PyInt_Check(value)) { + PyErr_SetString(PyExc_TypeError, "expected an integer"); + return -1; + } + self->m_basegenerator->SetSeed(PyInt_AsLong(value)); + return 0; +} + /* eof */ diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.h b/source/gameengine/GameLogic/SCA_RandomSensor.h index 39d072dd316..844552f0b64 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.h +++ b/source/gameengine/GameLogic/SCA_RandomSensor.h @@ -69,6 +69,9 @@ public: KX_PYMETHOD_DOC(SCA_RandomSensor,GetSeed); /* 3. getSeed */ KX_PYMETHOD_DOC(SCA_RandomSensor,GetLastDraw); + + static PyObject* pyattr_get_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); }; diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 354143f1e69..526c2dc404b 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -417,19 +417,12 @@ PyAttributeDef KX_CameraActuator::Attributes[] = { 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), - KX_PYATTRIBUTE_DUMMY("object"), + KX_PYATTRIBUTE_RW_FUNCTION("object", KX_CameraActuator, pyattr_get_object, pyattr_set_object), {NULL} }; PyObject* KX_CameraActuator::py_getattro(PyObject *attr) { - PyObject* object; - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "object")) { - if (!m_ob) Py_RETURN_NONE; - else return m_ob->AddRef(); - } - - object = py_getattro_self(Attributes, this, attr); + PyObject* object = py_getattro_self(Attributes, this, attr); if (object != NULL) return object; py_getattro_up(SCA_IActuator); @@ -437,24 +430,6 @@ PyObject* KX_CameraActuator::py_getattro(PyObject *attr) { int KX_CameraActuator::py_setattro(PyObject *attr, PyObject* value) { int ret; - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "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 = py_setattro_self(Attributes, this, attr, value); if (ret >= 0) return ret; @@ -623,4 +598,30 @@ PyObject* KX_CameraActuator::PyGetXY(PyObject* self, return PyInt_FromLong(m_x); } +PyObject* KX_CameraActuator::pyattr_get_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_CameraActuator* self= static_cast(self_v); + if (self->m_ob==NULL) + Py_RETURN_NONE; + else + return self->m_ob->AddRef(); +} + +int KX_CameraActuator::pyattr_set_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_CameraActuator* self= static_cast(self_v); + KX_GameObject *gameobj; + + if (!ConvertPythonToGameObject(value, &gameobj, true)) + return 1; // ConvertPythonToGameObject sets the error + + if (self->m_ob) + self->m_ob->UnregisterActuator(self); + + if (self->m_ob = (SCA_IObject*)gameobj) + self->m_ob->RegisterActuator(self); + + return 0; +} + /* eof */ diff --git a/source/gameengine/Ketsji/KX_CameraActuator.h b/source/gameengine/Ketsji/KX_CameraActuator.h index 5d7473a5bf0..d0aceb89aff 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.h +++ b/source/gameengine/Ketsji/KX_CameraActuator.h @@ -135,6 +135,9 @@ private : KX_PYMETHOD_DOC(KX_CameraActuator,GetHeight); KX_PYMETHOD_DOC(KX_CameraActuator,SetXY); KX_PYMETHOD_DOC(KX_CameraActuator,GetXY); + + static PyObject* pyattr_get_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); }; diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 49d3d20dc3d..c22885f3664 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -286,8 +286,8 @@ PyAttributeDef KX_TouchSensor::Attributes[] = { 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"), + KX_PYATTRIBUTE_RO_FUNCTION("objectHit", KX_TouchSensor, pyattr_get_object_hit), + KX_PYATTRIBUTE_RO_FUNCTION("objectHitList", KX_TouchSensor, pyattr_get_object_hit_list), { NULL } //Sentinel }; @@ -295,17 +295,7 @@ PyObject* KX_TouchSensor::py_getattro(PyObject *attr) { PyObject* object= py_getattro_self(Attributes, this, attr); if (object != NULL) - return object; - - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "objectHit")) { - if (m_hitObject) return m_hitObject->AddRef(); - else Py_RETURN_NONE; - } - if (!strcmp(attr_str, "objectHitList")) { - return m_colliders->AddRef(); - } - + return object; py_getattro_up(SCA_ISensor); } @@ -412,4 +402,21 @@ PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject* self, PyObject *value) } #endif +PyObject* KX_TouchSensor::pyattr_get_object_hit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_TouchSensor* self= static_cast(self_v); + + if (self->m_hitObject) + return self->m_hitObject->AddRef(); + else + Py_RETURN_NONE; +} + +PyObject* KX_TouchSensor::pyattr_get_object_hit_list(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_TouchSensor* self= static_cast(self_v); + return self->m_colliders->AddRef(); +} + + /* eof */ diff --git a/source/gameengine/Ketsji/KX_TouchSensor.h b/source/gameengine/Ketsji/KX_TouchSensor.h index 93fadef4abd..15ef653c1b2 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.h +++ b/source/gameengine/Ketsji/KX_TouchSensor.h @@ -140,6 +140,10 @@ public: #endif //<----- + static PyObject* pyattr_get_object_hit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_object_hit_list(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + + }; #endif //__KX_TOUCHSENSOR -- cgit v1.2.3 From a35a8f7a382e9f62834eaf355d448205665a07bc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 4 Apr 2009 08:20:52 +0000 Subject: - should fix compiling with older python versions (<2.5) - made the isA() function accept python types as well as strings. - renamed _getattr_dict to py_getattr_dict --- source/gameengine/Expressions/PyObjectPlus.cpp | 45 ++++++++++++++------------ source/gameengine/Expressions/PyObjectPlus.h | 6 ++-- source/gameengine/Ketsji/KX_GameObject.cpp | 2 +- source/gameengine/Ketsji/KX_Scene.cpp | 2 +- 4 files changed, 31 insertions(+), 24 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index ed6932b414a..ac1871300d0 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -703,35 +703,40 @@ PyObject *PyObjectPlus::py_repr(void) ------------------------------*/ bool PyObjectPlus::isA(PyTypeObject *T) // if called with a Type, use "typename" { - return isA(T->tp_name); + int i; + PyParentObject P; + PyParentObject *Ps = GetParents(); + + for (P = Ps[i=0]; P != NULL; P = Ps[i++]) + if (P==T) + return true; + + return false; } bool PyObjectPlus::isA(const char *mytypename) // check typename of each parent { - int i; - PyParentObject P; - PyParentObject *Ps = GetParents(); + int i; + PyParentObject P; + PyParentObject *Ps = GetParents(); - for (P = Ps[i=0]; P != NULL; P = Ps[i++]) - { - if (strcmp(P->tp_name, mytypename)==0) - return true; - } - - return false; + for (P = Ps[i=0]; P != NULL; P = Ps[i++]) + if (strcmp(P->tp_name, mytypename)==0) + return true; + + return false; } PyObject *PyObjectPlus::Py_isA(PyObject *value) // Python wrapper for isA { - if (!PyString_Check(value)) { - PyErr_SetString(PyExc_TypeError, "expected a string"); - return NULL; - } - if(isA(PyString_AsString(value))) - Py_RETURN_TRUE; - else - Py_RETURN_FALSE; + if (PyType_Check(value)) { + return PyBool_FromLong(isA((PyTypeObject *)value)); + } else if (PyString_Check(value)) { + return PyBool_FromLong(isA(PyString_AsString(value))); + } + PyErr_SetString(PyExc_TypeError, "expected a type or a string"); + return NULL; } /* Utility function called by the macro py_getattro_up() @@ -742,7 +747,7 @@ PyObject *PyObjectPlus::Py_isA(PyObject *value) // Python wrapper for isA * 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) +PyObject *py_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(); diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 77963c092eb..f178d03e131 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -62,6 +62,7 @@ /* for pre Py 2.5 */ #if PY_VERSION_HEX < 0x02050000 typedef int Py_ssize_t; +typedef Py_ssize_t (*lenfunc)(PyObject *); #define PY_SSIZE_T_MAX INT_MAX #define PY_SSIZE_T_MIN INT_MIN #define PY_METHODCHAR char * @@ -74,6 +75,7 @@ typedef int Py_ssize_t; #include "descrobject.h" + static inline void Py_Fatal(const char *M) { fprintf(stderr, "%s\n", M); exit(-1); @@ -108,7 +110,7 @@ static inline void Py_Fatal(const char *M) { } \ \ if (strcmp(PyString_AsString(attr), "__dict__")==0) {\ - rvalue = _getattr_dict(rvalue, Methods, Attributes); \ + rvalue = py_getattr_dict(rvalue, Methods, Attributes); \ } \ return rvalue; \ @@ -404,7 +406,7 @@ public: } }; -PyObject *_getattr_dict(PyObject *pydict, PyMethodDef *meth, PyAttributeDef *attrdef); +PyObject *py_getattr_dict(PyObject *pydict, PyMethodDef *meth, PyAttributeDef *attrdef); #endif // _adr_py_lib_h_ diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index e79ef5ab72b..5bba9190bd6 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1421,7 +1421,7 @@ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_ { KX_GameObject* self= static_cast(self_v); PyObject *dict_str = PyString_FromString("__dict__"); - PyObject *dict= _getattr_dict(self->SCA_IObject::py_getattro(dict_str), KX_GameObject::Methods, KX_GameObject::Attributes); + PyObject *dict= py_getattr_dict(self->SCA_IObject::py_getattro(dict_str), KX_GameObject::Methods, KX_GameObject::Attributes); Py_DECREF(dict_str); if(dict==NULL) diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 94ea234f1bf..254717894df 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1574,7 +1574,7 @@ PyObject* KX_Scene::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF * KX_Scene* self= static_cast(self_v); /* Useually done by py_getattro_up but in this case we want to include m_attrlist dict */ PyObject *dict_str= PyString_FromString("__dict__"); - PyObject *dict= _getattr_dict(self->PyObjectPlus::py_getattro(dict_str), KX_Scene::Methods, KX_Scene::Attributes); + PyObject *dict= py_getattr_dict(self->PyObjectPlus::py_getattro(dict_str), KX_Scene::Methods, KX_Scene::Attributes); Py_DECREF(dict_str); PyDict_Update(dict, self->m_attrlist); -- cgit v1.2.3 From b6114be5e388a4f3a1edf75ccbcb7121e88cad33 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 4 Apr 2009 09:54:05 +0000 Subject: include PyObjectPlus method in __dict__ --- source/gameengine/Expressions/PyObjectPlus.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index ac1871300d0..03afa62a6da 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -110,6 +110,9 @@ PyObject *PyObjectPlus::py_getattro(PyObject* attr) { PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \ if (descr == NULL) { + if (strcmp(PyString_AsString(attr), "__dict__")==0) { + return py_getattr_dict(NULL, Methods, NULL); /* no Attributes yet */ + } PyErr_SetString(PyExc_AttributeError, "attribute not found"); return NULL; } else { -- cgit v1.2.3 From cb26c7e75acce743d8f9d906293dea4f582a8ba7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 4 Apr 2009 11:02:13 +0000 Subject: BGE Py API, mistake when redoing set action as a static function. --- source/gameengine/Converter/BL_ActionActuator.cpp | 2 +- source/gameengine/Converter/BL_ShapeActionActuator.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index b7a961d6a9d..46ad344c5dd 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -1073,7 +1073,7 @@ int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF if (val != "") { - (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); + action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); if (!action) { PyErr_SetString(PyExc_ValueError, "action not found!"); diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index 3c0ce0918f2..a6dbf088ee3 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -904,7 +904,7 @@ int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE if (val != "") { - (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); + action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); if (action==NULL) { PyErr_SetString(PyExc_ValueError, "action not found!"); -- cgit v1.2.3 From 04ef5a492af04fa9317245c7a843afed1cbd8252 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 4 Apr 2009 15:54:07 +0000 Subject: Made KX_MeshProxy use PyAttributeDef. simplified getting the 'materials' attribute (no need to differentiate between types) Added KX_GameObject 'meshes' attribute to replace getMesh(i) --- source/gameengine/Ketsji/KX_GameObject.cpp | 21 ++++++++++++- source/gameengine/Ketsji/KX_GameObject.h | 3 ++ source/gameengine/Ketsji/KX_MeshProxy.cpp | 47 ++++++++++++++++-------------- source/gameengine/Ketsji/KX_MeshProxy.h | 2 ++ source/gameengine/PyDoc/KX_GameObject.py | 3 ++ 5 files changed, 53 insertions(+), 23 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 5bba9190bd6..d8fb54086b3 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1009,7 +1009,6 @@ PyMethodDef KX_GameObject::Methods[] = { {"removeParent", (PyCFunction)KX_GameObject::sPyRemoveParent,METH_NOARGS}, {"getChildren", (PyCFunction)KX_GameObject::sPyGetChildren,METH_NOARGS}, {"getChildrenRecursive", (PyCFunction)KX_GameObject::sPyGetChildrenRecursive,METH_NOARGS}, - {"getMesh", (PyCFunction)KX_GameObject::sPyGetMesh,METH_VARARGS}, {"getPhysicsId", (PyCFunction)KX_GameObject::sPyGetPhysicsId,METH_NOARGS}, {"getPropertyNames", (PyCFunction)KX_GameObject::sPyGetPropertyNames,METH_NOARGS}, {"replaceMesh",(PyCFunction) KX_GameObject::sPyReplaceMesh, METH_O}, @@ -1030,6 +1029,7 @@ PyMethodDef KX_GameObject::Methods[] = { {"getParent", (PyCFunction)KX_GameObject::sPyGetParent,METH_NOARGS}, {"getVisible",(PyCFunction) KX_GameObject::sPyGetVisible, METH_NOARGS}, {"getMass", (PyCFunction) KX_GameObject::sPyGetMass, METH_NOARGS}, + {"getMesh", (PyCFunction)KX_GameObject::sPyGetMesh,METH_VARARGS}, {NULL,NULL} //Sentinel }; @@ -1043,6 +1043,7 @@ PyAttributeDef KX_GameObject::Attributes[] = { KX_PYATTRIBUTE_RW_FUNCTION("scaling", KX_GameObject, pyattr_get_scaling, pyattr_set_scaling), KX_PYATTRIBUTE_RW_FUNCTION("timeOffset",KX_GameObject, pyattr_get_timeOffset,pyattr_set_timeOffset), KX_PYATTRIBUTE_RW_FUNCTION("state", KX_GameObject, pyattr_get_state, pyattr_set_state), + KX_PYATTRIBUTE_RO_FUNCTION("meshes", KX_GameObject, pyattr_get_meshes), KX_PYATTRIBUTE_RO_FUNCTION("__dict__", KX_GameObject, pyattr_get_dir_dict), {NULL} //Sentinel }; @@ -1416,6 +1417,22 @@ int KX_GameObject::pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attr return 0; } +PyObject* KX_GameObject::pyattr_get_meshes(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + PyObject *meshes= PyList_New(self->m_meshes.size()); + int i; + + for(i=0; i < self->m_meshes.size(); i++) + { + KX_MeshProxy* meshproxy = new KX_MeshProxy(self->m_meshes[i]); + PyList_SET_ITEM(meshes, i, meshproxy); + } + + return meshes; +} + + /* __dict__ only for the purpose of giving useful dir() results */ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { @@ -1758,6 +1775,8 @@ PyObject* KX_GameObject::PyGetChildrenRecursive(PyObject* self) PyObject* KX_GameObject::PyGetMesh(PyObject* self, PyObject* args) { + ShowDeprecationWarning("getMesh()", "the meshes property"); + int mesh = 0; if (!PyArg_ParseTuple(args, "|i:getMesh", &mesh)) diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 9ed35b6d26b..c2b0428240d 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -821,10 +821,13 @@ public: static int pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_meshes(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); /* for dir(), python3 uses __dir__() */ static PyObject* pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + + /* getitem/setitem */ static Py_ssize_t Map_Len(PyObject* self); static PyMappingMethods Mapping; diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index f464cb798e8..4a4c98603e3 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -87,6 +87,7 @@ KX_PYMETHODTABLE(KX_MeshProxy, reinstancePhysicsMesh), }; PyAttributeDef KX_MeshProxy::Attributes[] = { + KX_PYATTRIBUTE_RO_FUNCTION("materials", KX_MeshProxy, pyattr_get_materials), { NULL } //Sentinel }; @@ -96,30 +97,12 @@ void KX_MeshProxy::SetMeshModified(bool v) } -PyObject* -KX_MeshProxy::py_getattro(PyObject *attr) +PyObject* KX_MeshProxy::py_getattro(PyObject *attr) { - char *attr_str= PyString_AsString(attr); + PyObject* object = py_getattro_self(Attributes, this, attr); + if (object != NULL) + return object; - if (!strcmp(attr_str, "materials")) - { - PyObject *materials = PyList_New(0); - list::iterator mit = m_meshobj->GetFirstMaterial(); - for(; mit != m_meshobj->GetLastMaterial(); ++mit) - { - RAS_IPolyMaterial *polymat = mit->m_bucket->GetPolyMaterial(); - - if(polymat->GetFlag() & RAS_BLENDERMAT) - { - KX_BlenderMaterial *mat = static_cast(polymat); - PyList_Append(materials, mat); - }else - { - PyList_Append(materials, static_cast(polymat)); - } - } - return materials; - } py_getattro_up(SCA_IObject); } @@ -280,3 +263,23 @@ KX_PYMETHODDEF_DOC(KX_MeshProxy, reinstancePhysicsMesh, //this needs to be reviewed, it is dependend on Sumo/Solid. Who is using this ? Py_RETURN_NONE;//(KX_ReInstanceShapeFromMesh(m_meshobj)) ? Py_RETURN_TRUE : Py_RETURN_FALSE; } + +PyObject* KX_MeshProxy::pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_MeshProxy* self= static_cast(self_v); + + int tot= self->m_meshobj->NumMaterials(); + int i; + + PyObject *materials = PyList_New( tot ); + + list::iterator mit= self->m_meshobj->GetFirstMaterial(); + + /* Can be a KX_PolygonMaterial or KX_BlenderMaterial, since both are cast to a PyObject * we dont need to care */ + for(i=0; im_bucket->GetPolyMaterial(); + PyList_SET_ITEM(materials, i, py_mat); + Py_INCREF(py_mat); + } + return materials; +} diff --git a/source/gameengine/Ketsji/KX_MeshProxy.h b/source/gameengine/Ketsji/KX_MeshProxy.h index 0b9738153ff..56a6dfcac42 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.h +++ b/source/gameengine/Ketsji/KX_MeshProxy.h @@ -65,6 +65,8 @@ public: KX_PYMETHOD(KX_MeshProxy,GetVertex); KX_PYMETHOD(KX_MeshProxy,GetPolygon); KX_PYMETHOD_DOC(KX_MeshProxy, reinstancePhysicsMesh); + + static PyObject* pyattr_get_materials(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); }; #endif //__KX_MESHPROXY diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index 694fe02a7cc..12a395287b0 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -26,6 +26,9 @@ class KX_GameObject: @type timeOffset: float @ivar state: the game object's state bitmask. @type state: int + @ivar meshes: a list of L{KX_MeshProxy} objects. + B{Note}: Changes to this list will not update the KX_GameObject + @type meshes: list """ def endObject(visible): """ -- cgit v1.2.3 From 53e721305ef76505257bba3c62c24a042a3030a9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 5 Apr 2009 06:08:41 +0000 Subject: BGE Python API - made camera use PyAttributeDef's - removed unneeded duplicate matrix type checks - fixed own bug (added since 2.48a) that broke a converting 4x4 matrix to a PyObject --- source/gameengine/Ketsji/BL_Shader.cpp | 31 ++-- source/gameengine/Ketsji/KX_Camera.cpp | 228 +++++++++++++++++++---------- source/gameengine/Ketsji/KX_Camera.h | 20 +++ source/gameengine/Ketsji/KX_GameObject.cpp | 14 +- source/gameengine/Ketsji/KX_PyMath.cpp | 2 +- 5 files changed, 188 insertions(+), 107 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index 279721b4840..c82a9979fe1 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -1278,19 +1278,16 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformMatrix4, int loc = GetUniformLocation(uniform); if(loc != -1) { - if (PyObject_IsMT_Matrix(matrix, 4)) + MT_Matrix4x4 mat; + if (PyMatTo(matrix, mat)) { - MT_Matrix4x4 mat; - if (PyMatTo(matrix, mat)) - { #ifdef SORT_UNIFORMS - mat.getValue(matr); - SetUniformfv(loc, BL_Uniform::UNI_MAT4, matr, (sizeof(float)*16), (transp!=0) ); + mat.getValue(matr); + SetUniformfv(loc, BL_Uniform::UNI_MAT4, matr, (sizeof(float)*16), (transp!=0) ); #else - SetUniform(loc,mat,(transp!=0)); + SetUniform(loc,mat,(transp!=0)); #endif - Py_RETURN_NONE; - } + Py_RETURN_NONE; } } } @@ -1319,20 +1316,16 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformMatrix3, int loc = GetUniformLocation(uniform); if(loc != -1) { - if (PyObject_IsMT_Matrix(matrix, 3)) + MT_Matrix3x3 mat; + if (PyMatTo(matrix, mat)) { - MT_Matrix3x3 mat; - if (PyMatTo(matrix, mat)) - { #ifdef SORT_UNIFORMS - mat.getValue(matr); - SetUniformfv(loc, BL_Uniform::UNI_MAT3, matr, (sizeof(float)*9), (transp!=0) ); + mat.getValue(matr); + SetUniformfv(loc, BL_Uniform::UNI_MAT3, matr, (sizeof(float)*9), (transp!=0) ); #else - SetUniform(loc,mat,(transp!=0)); + SetUniform(loc,mat,(transp!=0)); #endif - Py_RETURN_NONE; - - } + Py_RETURN_NONE; } } } diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index 19370d83322..1540db5c44f 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -484,6 +484,24 @@ PyMethodDef KX_Camera::Methods[] = { }; PyAttributeDef KX_Camera::Attributes[] = { + + KX_PYATTRIBUTE_BOOL_RW("frustum_culling", KX_Camera, m_frustum_culling), + KX_PYATTRIBUTE_RW_FUNCTION("perspective", KX_Camera, pyattr_get_perspective, pyattr_set_perspective), + + KX_PYATTRIBUTE_RW_FUNCTION("lens", KX_Camera, pyattr_get_lens, pyattr_set_lens), + KX_PYATTRIBUTE_RW_FUNCTION("near", KX_Camera, pyattr_get_near, pyattr_set_near), + KX_PYATTRIBUTE_RW_FUNCTION("far", KX_Camera, pyattr_get_far, pyattr_set_far), + + KX_PYATTRIBUTE_RO_FUNCTION("projection_matrix", KX_Camera, pyattr_get_projection_matrix), + KX_PYATTRIBUTE_RO_FUNCTION("modelview_matrix", KX_Camera, pyattr_get_modelview_matrix), + KX_PYATTRIBUTE_RO_FUNCTION("camera_to_world", KX_Camera, pyattr_get_camera_to_world), + KX_PYATTRIBUTE_RO_FUNCTION("world_to_camera", KX_Camera, pyattr_get_world_to_camera), + + /* Grrr, functions for constants? */ + KX_PYATTRIBUTE_RO_FUNCTION("INSIDE", KX_Camera, pyattr_get_INSIDE), + KX_PYATTRIBUTE_RO_FUNCTION("OUTSIDE", KX_Camera, pyattr_get_OUTSIDE), + KX_PYATTRIBUTE_RO_FUNCTION("INTERSECT", KX_Camera, pyattr_get_INTERSECT), + { NULL } //Sentinel }; @@ -516,91 +534,20 @@ PyParentObject KX_Camera::Parents[] = { PyObject* KX_Camera::py_getattro(PyObject *attr) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "INSIDE")) - return PyInt_FromLong(INSIDE); /* new ref */ - if (!strcmp(attr_str, "OUTSIDE")) - return PyInt_FromLong(OUTSIDE); /* new ref */ - if (!strcmp(attr_str, "INTERSECT")) - return PyInt_FromLong(INTERSECT); /* new ref */ - - if (!strcmp(attr_str, "lens")) - return PyFloat_FromDouble(GetLens()); /* new ref */ - if (!strcmp(attr_str, "near")) - return PyFloat_FromDouble(GetCameraNear()); /* new ref */ - if (!strcmp(attr_str, "far")) - return PyFloat_FromDouble(GetCameraFar()); /* new ref */ - if (!strcmp(attr_str, "frustum_culling")) - return PyInt_FromLong(m_frustum_culling); /* new ref */ - if (!strcmp(attr_str, "perspective")) - return PyInt_FromLong(m_camdata.m_perspective); /* new ref */ - if (!strcmp(attr_str, "projection_matrix")) - return PyObjectFrom(GetProjectionMatrix()); /* new ref */ - if (!strcmp(attr_str, "modelview_matrix")) - return PyObjectFrom(GetModelviewMatrix()); /* new ref */ - if (!strcmp(attr_str, "camera_to_world")) - return PyObjectFrom(GetCameraToWorld()); /* new ref */ - if (!strcmp(attr_str, "world_to_camera")) - return PyObjectFrom(GetWorldToCamera()); /* new ref */ + PyObject* object = py_getattro_self(Attributes, this, attr); + if (object != NULL) + return object; py_getattro_up(KX_GameObject); } -int KX_Camera::py_setattro(PyObject *attr, PyObject *pyvalue) +int KX_Camera::py_setattro(PyObject *attr, PyObject *value) { - char *attr_str= PyString_AsString(attr); - - if (PyInt_Check(pyvalue)) - { - if (!strcmp(attr_str, "frustum_culling")) - { - m_frustum_culling = PyInt_AsLong(pyvalue); - return 0; - } - - if (!strcmp(attr_str, "perspective")) - { - m_camdata.m_perspective = PyInt_AsLong(pyvalue); - return 0; - } - } + int ret = py_setattro_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; - if (PyFloat_Check(pyvalue)) - { - if (!strcmp(attr_str, "lens")) - { - m_camdata.m_lens = PyFloat_AsDouble(pyvalue); - m_set_projection_matrix = false; - return 0; - } - if (!strcmp(attr_str, "near")) - { - m_camdata.m_clipstart = PyFloat_AsDouble(pyvalue); - m_set_projection_matrix = false; - return 0; - } - if (!strcmp(attr_str, "far")) - { - m_camdata.m_clipend = PyFloat_AsDouble(pyvalue); - m_set_projection_matrix = false; - return 0; - } - } - - if (PyObject_IsMT_Matrix(pyvalue, 4)) - { - if (!strcmp(attr_str, "projection_matrix")) - { - MT_Matrix4x4 mat; - if (PyMatTo(pyvalue, mat)) - { - SetProjectionMatrix(mat); - return 0; - } - return 1; - } - } - return KX_GameObject::py_setattro(attr, pyvalue); + return KX_GameObject::py_setattro(attr, value); } KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, sphereInsideFrustum, @@ -831,3 +778,126 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_Camera, setOnTop, scene->SetCameraOnTop(this); Py_RETURN_NONE; } + +PyObject* KX_Camera::pyattr_get_perspective(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_Camera* self= static_cast(self_v); + return PyBool_FromLong(self->m_camdata.m_perspective); +} + +int KX_Camera::pyattr_set_perspective(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_Camera* self= static_cast(self_v); + int param = PyObject_IsTrue( value ); + if (param == -1) { + PyErr_SetString(PyExc_AttributeError, "expected True or False"); + return -1; + } + + self->m_camdata.m_perspective= param; + return 0; +} + +PyObject* KX_Camera::pyattr_get_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_Camera* self= static_cast(self_v); + return PyFloat_FromDouble(self->m_camdata.m_lens); +} + +int KX_Camera::pyattr_set_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_Camera* self= static_cast(self_v); + float param = PyFloat_AsDouble(value); + if (param == -1) { + PyErr_SetString(PyExc_AttributeError, "expected a float greater then zero"); + return -1; + } + + self->m_camdata.m_lens= param; + self->m_set_projection_matrix = false; + return 0; +} + +PyObject* KX_Camera::pyattr_get_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_Camera* self= static_cast(self_v); + return PyFloat_FromDouble(self->m_camdata.m_clipstart); +} + +int KX_Camera::pyattr_set_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_Camera* self= static_cast(self_v); + float param = PyFloat_AsDouble(value); + if (param == -1) { + PyErr_SetString(PyExc_AttributeError, "expected a float greater then zero"); + return -1; + } + + self->m_camdata.m_clipstart= param; + self->m_set_projection_matrix = false; + return 0; +} + +PyObject* KX_Camera::pyattr_get_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_Camera* self= static_cast(self_v); + return PyFloat_FromDouble(self->m_camdata.m_clipend); +} + +int KX_Camera::pyattr_set_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_Camera* self= static_cast(self_v); + float param = PyFloat_AsDouble(value); + if (param == -1) { + PyErr_SetString(PyExc_AttributeError, "expected a float greater then zero"); + return -1; + } + + self->m_camdata.m_clipend= param; + self->m_set_projection_matrix = false; + return 0; +} + +PyObject* KX_Camera::pyattr_get_projection_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_Camera* self= static_cast(self_v); + return PyObjectFrom(self->GetProjectionMatrix()); +} + +int KX_Camera::pyattr_set_projection_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_Camera* self= static_cast(self_v); + MT_Matrix4x4 mat; + if (!PyMatTo(value, mat)) + return -1; + + self->SetProjectionMatrix(mat); + return 0; +} + +PyObject* KX_Camera::pyattr_get_modelview_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_Camera* self= static_cast(self_v); + return PyObjectFrom(self->GetModelviewMatrix()); +} + +PyObject* KX_Camera::pyattr_get_camera_to_world(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_Camera* self= static_cast(self_v); + return PyObjectFrom(self->GetCameraToWorld()); +} + +PyObject* KX_Camera::pyattr_get_world_to_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_Camera* self= static_cast(self_v); + return PyObjectFrom(self->GetWorldToCamera()); +} + + +PyObject* KX_Camera::pyattr_get_INSIDE(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ return PyInt_FromLong(INSIDE); } +PyObject* KX_Camera::pyattr_get_OUTSIDE(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ return PyInt_FromLong(OUTSIDE); } +PyObject* KX_Camera::pyattr_get_INTERSECT(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ return PyInt_FromLong(INTERSECT); } + diff --git a/source/gameengine/Ketsji/KX_Camera.h b/source/gameengine/Ketsji/KX_Camera.h index 499db66ab14..6ed21506372 100644 --- a/source/gameengine/Ketsji/KX_Camera.h +++ b/source/gameengine/Ketsji/KX_Camera.h @@ -267,7 +267,27 @@ public: virtual PyObject* py_getattro(PyObject *attr); /* lens, near, far, projection_matrix */ virtual int py_setattro(PyObject *attr, PyObject *pyvalue); + + static PyObject* pyattr_get_perspective(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_perspective(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + + static PyObject* pyattr_get_projection_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_projection_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + + static PyObject* pyattr_get_modelview_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_camera_to_world(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_world_to_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + + static PyObject* pyattr_get_INSIDE(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_OUTSIDE(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_INTERSECT(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); }; #endif //__KX_CAMERA diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index d8fb54086b3..dd38bdfb06f 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1303,16 +1303,14 @@ int KX_GameObject::pyattr_set_orientation(void *self_v, const KX_PYATTRIBUTE_DEF } MT_Matrix3x3 rot; - if (PyObject_IsMT_Matrix(value, 3)) + + if (PyMatTo(value, rot)) { - if (PyMatTo(value, rot)) - { - self->NodeSetLocalOrientation(rot); - self->NodeUpdateGS(0.f,true); - return 0; - } - return 1; + self->NodeSetLocalOrientation(rot); + self->NodeUpdateGS(0.f,true); + return 0; } + return 1; if (PySequence_Size(value) == 4) { diff --git a/source/gameengine/Ketsji/KX_PyMath.cpp b/source/gameengine/Ketsji/KX_PyMath.cpp index 92f18590a7e..cceb7a12446 100644 --- a/source/gameengine/Ketsji/KX_PyMath.cpp +++ b/source/gameengine/Ketsji/KX_PyMath.cpp @@ -93,7 +93,7 @@ PyObject* PyObjectFrom(const MT_Matrix4x4 &mat) 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(sublist, 3, PyFloat_FromDouble(mat[i][3])); PyList_SET_ITEM(list, i, sublist); } -- cgit v1.2.3 From 77da8461f3ed620ec06d69315d24b22d514d26f4 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 5 Apr 2009 07:41:03 +0000 Subject: Make materials use PyAttributeDef's --- source/gameengine/Ketsji/KX_PolygonMaterial.cpp | 232 ++++++++++-------------- source/gameengine/Ketsji/KX_PolygonMaterial.h | 12 ++ 2 files changed, 105 insertions(+), 139 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index 6b9a6201d5c..c5bddd6d166 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -181,6 +181,28 @@ PyMethodDef KX_PolygonMaterial::Methods[] = { }; PyAttributeDef KX_PolygonMaterial::Attributes[] = { + KX_PYATTRIBUTE_RO_FUNCTION("texture", KX_PolygonMaterial, pyattr_get_texture), + KX_PYATTRIBUTE_RO_FUNCTION("material", KX_PolygonMaterial, pyattr_get_material), /* should probably be .name ? */ + + KX_PYATTRIBUTE_INT_RW("tile", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_tile), + KX_PYATTRIBUTE_INT_RW("tilexrep", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_tilexrep), + KX_PYATTRIBUTE_INT_RW("tileyrep", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_tileyrep), + KX_PYATTRIBUTE_INT_RW("drawingmode", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_drawingmode), + KX_PYATTRIBUTE_INT_RW("lightlayer", INT_MIN, INT_MAX, true, KX_PolygonMaterial, m_lightlayer), + + KX_PYATTRIBUTE_BOOL_RW("transparent", KX_PolygonMaterial, m_alpha), + KX_PYATTRIBUTE_BOOL_RW("zsort", KX_PolygonMaterial, m_zsort), + + KX_PYATTRIBUTE_FLOAT_RW("shininess", 0.0f, 1000.0f, KX_PolygonMaterial, m_shininess), + KX_PYATTRIBUTE_FLOAT_RW("specularity", 0.0f, 1000.0f, KX_PolygonMaterial, m_specularity), + + KX_PYATTRIBUTE_RW_FUNCTION("diffuse", KX_PolygonMaterial, pyattr_get_texture, pyattr_set_diffuse), + KX_PYATTRIBUTE_RW_FUNCTION("specular",KX_PolygonMaterial, pyattr_get_specular, pyattr_set_specular), + + KX_PYATTRIBUTE_RO_FUNCTION("tface", KX_PolygonMaterial, pyattr_get_tface), /* How the heck is this even useful??? - Campbell */ + KX_PYATTRIBUTE_RO_FUNCTION("gl_texture", KX_PolygonMaterial, pyattr_get_gl_texture), /* could be called 'bindcode' */ + + /* triangle used to be an attribute, removed for 2.49, nobody should be using it */ { NULL } //Sentinel }; @@ -211,151 +233,20 @@ PyParentObject KX_PolygonMaterial::Parents[] = { PyObject* KX_PolygonMaterial::py_getattro(PyObject *attr) { - char *attr_str= PyString_AsString(attr); - if (!strcmp(attr_str, "texture")) - return PyString_FromString(m_texturename.ReadPtr()); - if (!strcmp(attr_str, "material")) - return PyString_FromString(m_materialname.ReadPtr()); - - if (!strcmp(attr_str, "tface")) - return PyCObject_FromVoidPtr(m_tface, NULL); - - if (!strcmp(attr_str, "gl_texture")) - { - Image *ima = m_tface->tpage; - int bind = 0; - if (ima) - bind = ima->bindcode; - - return PyInt_FromLong(bind); - } - - if (!strcmp(attr_str, "tile")) - return PyInt_FromLong(m_tile); - if (!strcmp(attr_str, "tilexrep")) - return PyInt_FromLong(m_tilexrep); - if (!strcmp(attr_str, "tileyrep")) - return PyInt_FromLong(m_tileyrep); - - if (!strcmp(attr_str, "drawingmode")) - return PyInt_FromLong(m_drawingmode); - if (!strcmp(attr_str, "transparent")) - return PyInt_FromLong(m_alpha); - if (!strcmp(attr_str, "zsort")) - return PyInt_FromLong(m_zsort); - if (!strcmp(attr_str, "lightlayer")) - return PyInt_FromLong(m_lightlayer); - if (!strcmp(attr_str, "triangle")) - // deprecated, triangle/quads shouldn't have been a material property - return 0; - - if (!strcmp(attr_str, "diffuse")) - return PyObjectFrom(m_diffuse); - if (!strcmp(attr_str, "shininess")) - return PyFloat_FromDouble(m_shininess); - if (!strcmp(attr_str, "specular")) - return PyObjectFrom(m_specular); - if (!strcmp(attr_str, "specularity")) - return PyFloat_FromDouble(m_specularity); + PyObject* object = py_getattro_self(Attributes, this, attr); + if (object != NULL) + return object; py_getattro_up(PyObjectPlus); } -int KX_PolygonMaterial::py_setattro(PyObject *attr, PyObject *pyvalue) +int KX_PolygonMaterial::py_setattro(PyObject *attr, PyObject *value) { - char *attr_str= PyString_AsString(attr); - if (PyFloat_Check(pyvalue)) - { - float value = PyFloat_AsDouble(pyvalue); - if (!strcmp(attr_str, "shininess")) - { - m_shininess = value; - return 0; - } - - if (!strcmp(attr_str, "specularity")) - { - m_specularity = value; - return 0; - } - } - - if (PyInt_Check(pyvalue)) - { - int value = PyInt_AsLong(pyvalue); - if (!strcmp(attr_str, "tile")) - { - m_tile = value; - return 0; - } - - if (!strcmp(attr_str, "tilexrep")) - { - m_tilexrep = value; - return 0; - } - - if (!strcmp(attr_str, "tileyrep")) - { - m_tileyrep = value; - return 0; - } - - if (!strcmp(attr_str, "drawingmode")) - { - m_drawingmode = value; - return 0; - } - - if (!strcmp(attr_str, "transparent")) - { - m_alpha = value; - return 0; - } - - if (!strcmp(attr_str, "zsort")) - { - m_zsort = value; - return 0; - } - - if (!strcmp(attr_str, "lightlayer")) - { - m_lightlayer = value; - return 0; - } - - // This probably won't work... - if (!strcmp(attr_str, "triangle")) - { - // deprecated, triangle/quads shouldn't have been a material property - return 0; - } - } - - if (PySequence_Check(pyvalue)) - { - if (PySequence_Size(pyvalue) == 3) - { - MT_Vector3 value; - if (PyVecTo(pyvalue, value)) - { - if (!strcmp(attr_str, "diffuse")) - { - m_diffuse = value; - return 0; - } - - if (!strcmp(attr_str, "specular")) - { - m_specular = value; - return 0; - } - } - } - } + int ret = py_setattro_self(Attributes, this, attr, value); + if (ret >= 0) + return ret; - return PyObjectPlus::py_setattro(attr, pyvalue); + return PyObjectPlus::py_setattro(attr, value); } KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setCustomMaterial, "setCustomMaterial(material)") @@ -419,3 +310,66 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, activate, "activate(rasty, cachingInfo)") return NULL; } + +PyObject* KX_PolygonMaterial::pyattr_get_texture(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolygonMaterial* self= static_cast(self_v); + return PyString_FromString(self->m_texturename.ReadPtr()); +} + +PyObject* KX_PolygonMaterial::pyattr_get_material(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolygonMaterial* self= static_cast(self_v); + return PyString_FromString(self->m_materialname.ReadPtr()); +} + +/* this does not seem useful */ +PyObject* KX_PolygonMaterial::pyattr_get_tface(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolygonMaterial* self= static_cast(self_v); + return PyCObject_FromVoidPtr(self->m_tface, NULL); +} + +PyObject* KX_PolygonMaterial::pyattr_get_gl_texture(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolygonMaterial* self= static_cast(self_v); + Image *ima = self->m_tface->tpage; + return PyInt_FromLong(ima ? ima->bindcode:0); +} + + +PyObject* KX_PolygonMaterial::pyattr_get_diffuse(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolygonMaterial* self= static_cast(self_v); + return PyObjectFrom(self->m_diffuse); +} + +int KX_PolygonMaterial::pyattr_set_diffuse(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_PolygonMaterial* self= static_cast(self_v); + MT_Vector3 vec; + + if (!PyVecTo(value, vec)) + return -1; + + self->m_diffuse= vec; + return 0; +} + +PyObject* KX_PolygonMaterial::pyattr_get_specular(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_PolygonMaterial* self= static_cast(self_v); + return PyObjectFrom(self->m_specular); +} + +int KX_PolygonMaterial::pyattr_set_specular(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_PolygonMaterial* self= static_cast(self_v); + MT_Vector3 vec; + + if (!PyVecTo(value, vec)) + return -1; + + self->m_specular= vec; + return 0; +} diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.h b/source/gameengine/Ketsji/KX_PolygonMaterial.h index f3eb1979f34..1e8ce5c3367 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.h +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.h @@ -117,6 +117,18 @@ public: virtual PyObject* py_getattro(PyObject *attr); virtual int py_setattro(PyObject *attr, PyObject *pyvalue); + + + static PyObject* pyattr_get_texture(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_material(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + + static PyObject* pyattr_get_tface(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_gl_texture(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + + static PyObject* pyattr_get_diffuse(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_diffuse(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_specular(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_specular(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); }; #endif // __KX_POLYGONMATERIAL_H__ -- cgit v1.2.3 From f8cc2725755ae02f9a12ad9a346ddf326533cc3e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 5 Apr 2009 08:48:51 +0000 Subject: added experimental KX_GameObject attributes "sensors", "controllers" and "actuators" --- source/gameengine/Ketsji/KX_GameObject.cpp | 47 ++++++++++++++++++++++++++++++ source/gameengine/Ketsji/KX_GameObject.h | 5 +++- source/gameengine/PyDoc/KX_GameObject.py | 25 ++++++++++++++-- 3 files changed, 73 insertions(+), 4 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index dd38bdfb06f..6f4aa2bc71a 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -64,6 +64,7 @@ typedef unsigned long uint_ptr; #include "KX_PyMath.h" #include "SCA_IActuator.h" #include "SCA_ISensor.h" +#include "SCA_IController.h" #include "PyObjectPlus.h" /* python stuff */ @@ -1044,7 +1045,14 @@ PyAttributeDef KX_GameObject::Attributes[] = { KX_PYATTRIBUTE_RW_FUNCTION("timeOffset",KX_GameObject, pyattr_get_timeOffset,pyattr_set_timeOffset), KX_PYATTRIBUTE_RW_FUNCTION("state", KX_GameObject, pyattr_get_state, pyattr_set_state), KX_PYATTRIBUTE_RO_FUNCTION("meshes", KX_GameObject, pyattr_get_meshes), + KX_PYATTRIBUTE_RO_FUNCTION("__dict__", KX_GameObject, pyattr_get_dir_dict), + + /* Experemental, dont rely on these yet */ + KX_PYATTRIBUTE_RO_FUNCTION("sensors", KX_GameObject, pyattr_get_sensors), + KX_PYATTRIBUTE_RO_FUNCTION("controllers", KX_GameObject, pyattr_get_controllers), + KX_PYATTRIBUTE_RO_FUNCTION("actuators", KX_GameObject, pyattr_get_actuators), + {NULL} //Sentinel }; @@ -1431,6 +1439,44 @@ PyObject* KX_GameObject::pyattr_get_meshes(void *self_v, const KX_PYATTRIBUTE_DE } +/* experemental! */ +PyObject* KX_GameObject::pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + SCA_SensorList& sensors= self->GetSensors(); + PyObject* resultlist = PyList_New(sensors.size()); + + for (unsigned int index=0;indexAddRef()); + + return resultlist; +} + +PyObject* KX_GameObject::pyattr_get_controllers(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + SCA_ControllerList& controllers= self->GetControllers(); + PyObject* resultlist = PyList_New(controllers.size()); + + for (unsigned int index=0;indexAddRef()); + + return resultlist; +} + +PyObject* KX_GameObject::pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + SCA_ActuatorList& actuators= self->GetActuators(); + PyObject* resultlist = PyList_New(actuators.size()); + + for (unsigned int index=0;indexAddRef()); + + return resultlist; +} + + /* __dict__ only for the purpose of giving useful dir() results */ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { @@ -1458,6 +1504,7 @@ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_ return dict; } + PyObject* KX_GameObject::py_getattro(PyObject *attr) { PyObject* object = py_getattro_self(Attributes, this, attr); diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index c2b0428240d..bc6b60102d6 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -826,7 +826,10 @@ public: /* for dir(), python3 uses __dir__() */ static PyObject* pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); - + /* Experemental! */ + static PyObject* pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_controllers(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); /* getitem/setitem */ static Py_ssize_t Map_Len(PyObject* self); diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index 12a395287b0..a8d37cbbe53 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -1,7 +1,13 @@ # $Id$ # Documentation for game objects -class KX_GameObject: +# from SCA_IObject import * +from SCA_ISensor import * +from SCA_IController import * +from SCA_IActuator import * + + +class KX_GameObject: # (SCA_IObject) """ All game objects are derived from this class. @@ -26,9 +32,22 @@ class KX_GameObject: @type timeOffset: float @ivar state: the game object's state bitmask. @type state: int - @ivar meshes: a list of L{KX_MeshProxy} objects. + @ivar meshes: a list meshes for this object. + B{Note}: Most objects use only 1 mesh. + B{Note}: Changes to this list will not update the KX_GameObject. + @type meshes: list of L{KX_MeshProxy} + @ivar sensors: a list of L{SCA_ISensor} objects. + B{Note}: This attribute is experemental and may be removed (but probably wont be). + B{Note}: Changes to this list will not update the KX_GameObject + @type sensors: list of L{SCA_ISensor} + @ivar controllers: a list of L{SCA_ISensor} objects. + B{Note}: This attribute is experemental and may be removed (but probably wont be). + B{Note}: Changes to this list will not update the KX_GameObject + @type controllers: list of L{SCA_IController} + @ivar the actuators assigned to this object. + B{Note}: This attribute is experemental and may be removed (but probably wont be). B{Note}: Changes to this list will not update the KX_GameObject - @type meshes: list + @type actuators: a list of L{SCA_IActuator} """ def endObject(visible): """ -- cgit v1.2.3 From 7d4dc4f0f5d34d91703b2219323ef4a3db28a572 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 5 Apr 2009 10:03:23 +0000 Subject: - fixed errors with bge epydocs - changed epy_docgen.sh so inherited attributes & methods are included inline for each type, removed source option since its not useful and makes the download bigger. --- source/gameengine/PyDoc/BL_ActionActuator.py | 8 ++-- source/gameengine/PyDoc/BL_ShapeActionActuator.py | 3 +- source/gameengine/PyDoc/KX_ActuatorSensor.py | 1 + source/gameengine/PyDoc/KX_CDActuator.py | 36 +++++++++--------- source/gameengine/PyDoc/KX_GameObject.py | 43 +++++++++++----------- source/gameengine/PyDoc/KX_ParentActuator.py | 4 +- source/gameengine/PyDoc/KX_SCA_DynamicActuator.py | 30 +++++++-------- .../gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py | 19 +++++----- source/gameengine/PyDoc/KX_Scene.py | 4 +- source/gameengine/PyDoc/KX_SceneActuator.py | 4 +- source/gameengine/PyDoc/KX_TrackToActuator.py | 12 +++--- source/gameengine/PyDoc/KX_VisibilityActuator.py | 14 +++---- source/gameengine/PyDoc/SCA_JoystickSensor.py | 14 +++---- source/gameengine/PyDoc/epy_docgen.sh | 2 +- 14 files changed, 97 insertions(+), 97 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/PyDoc/BL_ActionActuator.py b/source/gameengine/PyDoc/BL_ActionActuator.py index 3e95befe16b..480681dc14a 100644 --- a/source/gameengine/PyDoc/BL_ActionActuator.py +++ b/source/gameengine/PyDoc/BL_ActionActuator.py @@ -1,7 +1,9 @@ # $Id$ # Documentation for BL_ActionActuator +import SCA_ILogicBrick from SCA_IActuator import * + class BL_ActionActuator(SCA_IActuator): """ Action Actuators apply an action to an actor. @@ -10,7 +12,7 @@ class BL_ActionActuator(SCA_IActuator): @type action: string @ivar start: Specifies the starting frame of the animation. @type start: float - @type end: Specifies the ending frame of the animation. + @ivar 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 @@ -25,9 +27,7 @@ class BL_ActionActuator(SCA_IActuator): @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 + @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, diff --git a/source/gameengine/PyDoc/BL_ShapeActionActuator.py b/source/gameengine/PyDoc/BL_ShapeActionActuator.py index 209ff4e5580..e1e8b039749 100644 --- a/source/gameengine/PyDoc/BL_ShapeActionActuator.py +++ b/source/gameengine/PyDoc/BL_ShapeActionActuator.py @@ -1,6 +1,7 @@ # $Id$ # Documentation for BL_ShapeActionActuator from SCA_IActuator import * +from SCA_ILogicBrick import * class BL_ShapeActionActuator(SCA_IActuator): """ @@ -10,7 +11,7 @@ class BL_ShapeActionActuator(SCA_IActuator): @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. + @ivar 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 diff --git a/source/gameengine/PyDoc/KX_ActuatorSensor.py b/source/gameengine/PyDoc/KX_ActuatorSensor.py index b0e138a8009..27ee3a475e0 100644 --- a/source/gameengine/PyDoc/KX_ActuatorSensor.py +++ b/source/gameengine/PyDoc/KX_ActuatorSensor.py @@ -2,6 +2,7 @@ # Documentation for KX_ActuatorSensor from SCA_IActuator import * from SCA_ISensor import * +from SCA_ILogicBrick import * class KX_ActuatorSensor(SCA_ISensor): """ diff --git a/source/gameengine/PyDoc/KX_CDActuator.py b/source/gameengine/PyDoc/KX_CDActuator.py index ffc8ddefa43..e1067674e7e 100644 --- a/source/gameengine/PyDoc/KX_CDActuator.py +++ b/source/gameengine/PyDoc/KX_CDActuator.py @@ -3,13 +3,15 @@ from SCA_IActuator import * class KX_CDActuator(SCA_IActuator): - """ - CD Controller actuator. - @ivar volume: controls the volume to set the CD to. 0.0 = silent, 1.0 = max volume. - @type volume: float - @ivar track: the track selected to be played - @type track: integer - """ + """ + CD Controller actuator. + @ivar volume: controls the volume to set the CD to. 0.0 = silent, 1.0 = max volume. + @type volume: float + @ivar track: the track selected to be played + @type track: integer + @ivar gain: the gain (volume) of the CD between 0.0 and 1.0. + @type gain: float + """ def startCD(): """ Starts the CD playing. @@ -26,17 +28,17 @@ class KX_CDActuator(SCA_IActuator): """ Resumes the CD after a pause. """ - def playAll(): - """ - Plays the CD from the beginning. - """ - def playTrack(trackNumber): - """ - Plays the track selected. - """ + def playAll(): + """ + Plays the CD from the beginning. + """ + def playTrack(trackNumber): + """ + Plays the track selected. + """ def setGain(gain): """ - DEPRECATED: Use the volume property. + DEPRECATED: Use the volume property. Sets the gain (volume) of the CD. @type gain: float @@ -44,7 +46,7 @@ class KX_CDActuator(SCA_IActuator): """ def getGain(): """ - DEPRECATED: Use the volume property. + DEPRECATED: Use the volume property. Gets the current gain (volume) of the CD. @rtype: float diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index a8d37cbbe53..88c3a55280e 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -2,9 +2,9 @@ # Documentation for game objects # from SCA_IObject import * -from SCA_ISensor import * -from SCA_IController import * -from SCA_IActuator import * +# from SCA_ISensor import * +# from SCA_IController import * +# from SCA_IActuator import * class KX_GameObject: # (SCA_IObject) @@ -12,19 +12,20 @@ class KX_GameObject: # (SCA_IObject) All game objects are derived from this class. Properties assigned to game objects are accessible as attributes of this class. - + @ivar name: The object's name. (Read only) + - note: Currently (Blender 2.49) the prefix "OB" is added to all objects name. This may change in blender 2.5. @type name: string. @ivar mass: The object's mass (provided the object has a physics controller). Read only. @type mass: float @ivar parent: The object's parent object. (Read only) - @type parent: L{KX_GameObject} + @type parent: L{KX_GameObject} or None @ivar visible: visibility flag. + - note: Game logic will still run for invisible objects. @type visible: boolean @ivar position: The object's position. @type position: list [x, y, z] - @ivar orientation: The object's orientation. 3x3 Matrix. - You can also write a Quaternion or Euler vector. + @ivar orientation: The object's orientation. 3x3 Matrix. You can also write a Quaternion or Euler vector. @type orientation: 3x3 Matrix [[float]] @ivar scaling: The object's scaling factor. list [sx, sy, sz] @type scaling: list [sx, sy, sz] @@ -33,21 +34,21 @@ class KX_GameObject: # (SCA_IObject) @ivar state: the game object's state bitmask. @type state: int @ivar meshes: a list meshes for this object. - B{Note}: Most objects use only 1 mesh. - B{Note}: Changes to this list will not update the KX_GameObject. + - note: Most objects use only 1 mesh. + - note: Changes to this list will not update the KX_GameObject. @type meshes: list of L{KX_MeshProxy} @ivar sensors: a list of L{SCA_ISensor} objects. - B{Note}: This attribute is experemental and may be removed (but probably wont be). - B{Note}: Changes to this list will not update the KX_GameObject - @type sensors: list of L{SCA_ISensor} - @ivar controllers: a list of L{SCA_ISensor} objects. - B{Note}: This attribute is experemental and may be removed (but probably wont be). - B{Note}: Changes to this list will not update the KX_GameObject - @type controllers: list of L{SCA_IController} - @ivar the actuators assigned to this object. - B{Note}: This attribute is experemental and may be removed (but probably wont be). - B{Note}: Changes to this list will not update the KX_GameObject - @type actuators: a list of L{SCA_IActuator} + - note: This attribute is experemental and may be removed (but probably wont be). + - note: Changes to this list will not update the KX_GameObject. + @type sensors: list + @ivar controllers: a list of L{SCA_IController} objects. + - note: This attribute is experemental and may be removed (but probably wont be). + - note: Changes to this list will not update the KX_GameObject. + @type controllers: list of L{SCA_ISensor}. + @ivar actuators: a list of L{SCA_IActuator} objects. + - note: This attribute is experemental and may be removed (but probably wont be). + - note: Changes to this list will not update the KX_GameObject. + @type actuators: list """ def endObject(visible): """ @@ -159,7 +160,7 @@ class KX_GameObject: # (SCA_IObject) @param local: - False: you get the "global" movement ie: relative to world orientation (default). - True: you get the "local" movement ie: relative to object orientation. """ - def applyRotation(movement, local = 0): + def applyRotation(rotation, local = 0): """ Sets the game object's rotation. diff --git a/source/gameengine/PyDoc/KX_ParentActuator.py b/source/gameengine/PyDoc/KX_ParentActuator.py index 4a5f72e7cc2..2f5d9515d0b 100644 --- a/source/gameengine/PyDoc/KX_ParentActuator.py +++ b/source/gameengine/PyDoc/KX_ParentActuator.py @@ -10,7 +10,7 @@ class KX_ParentActuator(SCA_IActuator): """ def setObject(object): """ - DEPRECATED: Use the object property. + DEPRECATED: Use the object property. Sets the object to set as parent. Object can be either a L{KX_GameObject} or the name of the object. @@ -19,7 +19,7 @@ class KX_ParentActuator(SCA_IActuator): """ def getObject(name_only = 1): """ - DEPRECATED: Use the object property. + DEPRECATED: Use the object property. Returns the name of the object to change to. @type name_only: bool @param name_only: optional argument, when 0 return a KX_GameObject diff --git a/source/gameengine/PyDoc/KX_SCA_DynamicActuator.py b/source/gameengine/PyDoc/KX_SCA_DynamicActuator.py index a6a3bce1f31..d65d3c22993 100644 --- a/source/gameengine/PyDoc/KX_SCA_DynamicActuator.py +++ b/source/gameengine/PyDoc/KX_SCA_DynamicActuator.py @@ -5,26 +5,26 @@ from SCA_IActuator import * class KX_SCA_DynamicActuator(SCA_IActuator): """ Dynamic Actuator. - @ivar operation: the type of operation of the actuator, 0-4 - KX_DYN_RESTORE_DYNAMICS, KX_DYN_DISABLE_DYNAMICS, - KX_DYN_ENABLE_RIGID_BODY, KX_DYN_DISABLE_RIGID_BODY, KX_DYN_SET_MASS - @type operation: integer - @ivar mass: the mass value for the KX_DYN_SET_MASS operation - @type mass: float + @ivar operation: the type of operation of the actuator, 0-4 + KX_DYN_RESTORE_DYNAMICS, KX_DYN_DISABLE_DYNAMICS, + KX_DYN_ENABLE_RIGID_BODY, KX_DYN_DISABLE_RIGID_BODY, KX_DYN_SET_MASS + @type operation: integer + @ivar mass: the mass value for the KX_DYN_SET_MASS operation + @type mass: float """ def setOperation(operation): """ - DEPRECATED: Use the operation property instead. + DEPRECATED: Use the operation property instead. Set the type of operation when the actuator is activated: - 0 = restore dynamics - 1 = disable dynamics - 2 = enable rigid body - 3 = disable rigid body - 4 = set mass - """ - def getOperatoin() + - 0 = restore dynamics + - 1 = disable dynamics + - 2 = enable rigid body + - 3 = disable rigid body + - 4 = set mass """ - DEPRECATED: Use the operation property instead. + def getOperatoin(): + """ + DEPRECATED: Use the operation property instead. return the type of operation """ diff --git a/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py b/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py index 1013dd53cb9..4397a9152d0 100644 --- a/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py +++ b/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py @@ -18,13 +18,13 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator): # Mesh (name, near, far) # Meshes overlap so that they don't 'pop' when on the edge of the distance. meshes = ((".Hi", 0.0, -20.0), - (".Med", -15.0, -50.0), - (".Lo", -40.0, -100.0) - ) + (".Med", -15.0, -50.0), + (".Lo", -40.0, -100.0) + ) co = GameLogic.getCurrentController() obj = co.getOwner() - act = co.getActuator("LOD." + obj.getName()) + act = co.getActuator("LOD." + obj.name) cam = GameLogic.getCurrentScene().active_camera def Depth(pos, plane): @@ -39,10 +39,10 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator): for mesh in meshes: if depth < mesh[1] and depth > mesh[2]: newmesh = mesh - if "ME" + obj.getName() + mesh[0] == act.getMesh(): + if "ME" + obj.name + mesh[0] == act.getMesh(): curmesh = mesh - if newmesh != None and "ME" + obj.getName() + newmesh[0] != act.getMesh(): + if newmesh != None and "ME" + obj.name + newmesh[0] != act.getMesh(): # The mesh is a different mesh - switch it. # Check the current mesh is not a better fit. if curmesh == None or curmesh[1] < depth or curmesh[2] > depth: @@ -55,15 +55,14 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator): This will generate a warning in the console: C{ERROR: GameObject I{OBName} ReplaceMeshActuator I{ActuatorName} without object} - - Properties: + @ivar mesh: L{KX_MeshProxy} or the name of the mesh that will replace the current one Set to None to disable actuator @type mesh: L{KX_MeshProxy} or None if no mesh is set """ def setMesh(name): """ - DEPRECATED: Use the mesh property instead. + DEPRECATED: Use the mesh property instead. Sets the name of the mesh that will replace the current one. When the name is None it will unset the mesh value so no action is taken. @@ -71,7 +70,7 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator): """ def getMesh(): """ - DEPRECATED: Use the mesh property instead. + DEPRECATED: Use the mesh property instead. Returns the name of the mesh that will replace the current one. Returns None if no mesh has been scheduled to be added. diff --git a/source/gameengine/PyDoc/KX_Scene.py b/source/gameengine/PyDoc/KX_Scene.py index 5e357e6eefc..4f7beb9e300 100644 --- a/source/gameengine/PyDoc/KX_Scene.py +++ b/source/gameengine/PyDoc/KX_Scene.py @@ -39,7 +39,7 @@ class KX_Scene: @ivar name: The scene's name @type name: string - @type objects: A list of objects in the scene. + @ivar 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} @@ -70,7 +70,7 @@ class KX_Scene: @rtype: string """ - def addObject(object, other, time=0) + def addObject(object, other, time=0): """ Adds an object to the scene like the Add Object Actuator would, and returns the created object. diff --git a/source/gameengine/PyDoc/KX_SceneActuator.py b/source/gameengine/PyDoc/KX_SceneActuator.py index c8912783ab7..6e27257533e 100644 --- a/source/gameengine/PyDoc/KX_SceneActuator.py +++ b/source/gameengine/PyDoc/KX_SceneActuator.py @@ -8,12 +8,10 @@ class KX_SceneActuator(SCA_IActuator): @warning: Scene actuators that use a scene name will be ignored if at game start, the named scene doesn't exist or is empty - + This will generate a warning in the console: C{ERROR: GameObject I{OBName} has a SceneActuator I{ActuatorName} (SetScene) without scene} - - Properties: @ivar scene: the name of the scene to change to/overlay/underlay/remove/suspend/resume @type scene: string. diff --git a/source/gameengine/PyDoc/KX_TrackToActuator.py b/source/gameengine/PyDoc/KX_TrackToActuator.py index ff533e22ac0..ee2dc5d6144 100644 --- a/source/gameengine/PyDoc/KX_TrackToActuator.py +++ b/source/gameengine/PyDoc/KX_TrackToActuator.py @@ -23,7 +23,7 @@ class KX_TrackToActuator(SCA_IActuator): """ def setObject(object): """ - DEPRECATED: Use the object property. + DEPRECATED: Use the object property. Sets the object to track. @type object: L{KX_GameObject}, string or None @@ -31,7 +31,7 @@ class KX_TrackToActuator(SCA_IActuator): """ def getObject(name_only): """ - DEPRECATED: Use the object property. + DEPRECATED: Use the object property. Returns the name of the object to track. @type name_only: bool @@ -40,21 +40,21 @@ class KX_TrackToActuator(SCA_IActuator): """ def setTime(time): """ - DEPRECATED: Use the time property. + DEPRECATED: Use the time property. Sets the time in frames with which to delay the tracking motion. @type time: integer """ def getTime(): """ - DEPRECATED: Use the time property. + DEPRECATED: Use the time property. Returns the time in frames with which the tracking motion is delayed. @rtype: integer """ def setUse3D(use3d): """ - DEPRECATED: Use the use3D property. + DEPRECATED: Use the use3D property. Sets the tracking motion to use 3D. @type use3d: boolean @@ -63,7 +63,7 @@ class KX_TrackToActuator(SCA_IActuator): """ def getUse3D(): """ - DEPRECATED: Use the use3D property. + DEPRECATED: Use the use3D property. Returns True if the tracking motion will track in the z direction. @rtype: boolean diff --git a/source/gameengine/PyDoc/KX_VisibilityActuator.py b/source/gameengine/PyDoc/KX_VisibilityActuator.py index 17d22fa5f83..aca8d1ce243 100644 --- a/source/gameengine/PyDoc/KX_VisibilityActuator.py +++ b/source/gameengine/PyDoc/KX_VisibilityActuator.py @@ -5,18 +5,16 @@ from SCA_IActuator import * class KX_VisibilityActuator(SCA_IActuator): """ Visibility Actuator. - @ivar visibility: whether the actuator makes its parent object visible or invisible - @type visibility: boolean - @ivar recursion: whether the visibility/invisibility should be propagated to all children of the object - @type recursion: boolean + @ivar visibility: whether the actuator makes its parent object visible or invisible + @type visibility: boolean + @ivar recursion: whether the visibility/invisibility should be propagated to all children of the object + @type recursion: boolean """ def set(visible): """ - DEPRECATED: Use the visibility property instead. + DEPRECATED: Use the visibility property instead. Sets whether the actuator makes its parent object visible or invisible. - + @param visible: - True: Makes its parent visible. - False: Makes its parent invisible. """ - - diff --git a/source/gameengine/PyDoc/SCA_JoystickSensor.py b/source/gameengine/PyDoc/SCA_JoystickSensor.py index 944ff64dc64..e38e023143d 100644 --- a/source/gameengine/PyDoc/SCA_JoystickSensor.py +++ b/source/gameengine/PyDoc/SCA_JoystickSensor.py @@ -41,13 +41,13 @@ class SCA_JoystickSensor(SCA_ISensor): 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 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. diff --git a/source/gameengine/PyDoc/epy_docgen.sh b/source/gameengine/PyDoc/epy_docgen.sh index b243101ddcb..ddf39dcc081 100755 --- a/source/gameengine/PyDoc/epy_docgen.sh +++ b/source/gameengine/PyDoc/epy_docgen.sh @@ -8,4 +8,4 @@ LC_ALL=POSIX epydoc --debug -v -o BPY_GE --url "http://www.blender.org" --top GameLogic \ - --name "Blender GameEngine" --no-private --no-frames *.py + --name "Blender GameEngine" --no-private --no-frames --no-sourcecode --inheritance=included *.py -- 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_BlenderMaterial.h | 1 + source/gameengine/Ketsji/KX_GameObject.cpp | 33 ++++++++++++---- source/gameengine/Ketsji/KX_MeshProxy.cpp | 51 ++++++++++++++++--------- source/gameengine/Ketsji/KX_PolygonMaterial.cpp | 7 +++- source/gameengine/Ketsji/KX_PolygonMaterial.h | 3 +- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 2 + source/gameengine/Ketsji/KX_RayCast.cpp | 3 ++ source/gameengine/Ketsji/KX_SceneActuator.cpp | 7 +++- source/gameengine/PyDoc/KX_GameObject.py | 2 + 9 files changed, 81 insertions(+), 28 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.h b/source/gameengine/Ketsji/KX_BlenderMaterial.h index 2d9dc8fd022..48d4730ab07 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.h +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.h @@ -84,6 +84,7 @@ public: // -------------------------------- virtual PyObject* py_getattro(PyObject *attr); virtual int py_setattro(PyObject *attr, PyObject *pyvalue); + virtual PyObject* py_repr(void) { return PyString_FromString(mMaterial->matname.ReadPtr()); } KX_PYMETHOD_DOC( KX_BlenderMaterial, getShader ); KX_PYMETHOD_DOC( KX_BlenderMaterial, getMaterialIndex ); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 6f4aa2bc71a..a788b12b121 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -73,6 +73,8 @@ typedef unsigned long uint_ptr; #include "KX_SG_NodeRelationships.h" +static MT_Point3 dummy_point= MT_Point3(0.0, 0.0, 0.0); + KX_GameObject::KX_GameObject( void* sgReplicationInfo, SG_Callbacks callbacks, @@ -943,7 +945,7 @@ const MT_Vector3& KX_GameObject::NodeGetWorldScaling() const } -static MT_Point3 dummy_point= MT_Point3(0.0, 0.0, 0.0); + const MT_Point3& KX_GameObject::NodeGetWorldPosition() const { // check on valid node in case a python controller holds a reference to a deleted object @@ -964,7 +966,8 @@ void KX_GameObject::Resume(void) { if (m_suspended) { SCA_IObject::Resume(); - GetPhysicsController()->RestoreDynamics(); + if(GetPhysicsController()) + GetPhysicsController()->RestoreDynamics(); m_suspended = false; } @@ -975,7 +978,8 @@ void KX_GameObject::Suspend() if ((!m_ignore_activity_culling) && (!m_suspended)) { SCA_IObject::Suspend(); - GetPhysicsController()->SuspendDynamics(); + if(GetPhysicsController()) + GetPhysicsController()->SuspendDynamics(); m_suspended = true; } } @@ -1717,7 +1721,7 @@ PyObject* KX_GameObject::PyGetVelocity(PyObject* self, PyObject* args) PyObject* KX_GameObject::PyGetMass(PyObject* self) { ShowDeprecationWarning("getMass()", "the mass property"); - return PyFloat_FromDouble(GetPhysicsController()->GetMass()); + return PyFloat_FromDouble((GetPhysicsController() != NULL) ? GetPhysicsController()->GetMass() : 0.0f); } @@ -1725,14 +1729,24 @@ PyObject* KX_GameObject::PyGetMass(PyObject* self) PyObject* KX_GameObject::PyGetReactionForce(PyObject* self) { // only can get the velocity if we have a physics object connected to us... - return PyObjectFrom(GetPhysicsController()->getReactionForce()); + + // XXX - Currently not working with bullet intergration, see KX_BulletPhysicsController.cpp's getReactionForce + /* + if (GetPhysicsController()) + return PyObjectFrom(GetPhysicsController()->getReactionForce()); + return PyObjectFrom(dummy_point); + */ + + return Py_BuildValue("fff", 0.0f, 0.0f, 0.0f); + } PyObject* KX_GameObject::PyEnableRigidBody(PyObject* self) { - GetPhysicsController()->setRigidBody(true); + if(GetPhysicsController()) + GetPhysicsController()->setRigidBody(true); Py_RETURN_NONE; } @@ -1741,7 +1755,8 @@ PyObject* KX_GameObject::PyEnableRigidBody(PyObject* self) PyObject* KX_GameObject::PyDisableRigidBody(PyObject* self) { - GetPhysicsController()->setRigidBody(false); + if(GetPhysicsController()) + GetPhysicsController()->setRigidBody(false); Py_RETURN_NONE; } @@ -1763,6 +1778,10 @@ PyObject* KX_GameObject::PySetParent(PyObject* self, PyObject* value) PyErr_SetString(PyExc_TypeError, "expected a KX_GameObject type"); return NULL; } + if (self==value) { + PyErr_SetString(PyExc_ValueError, "cannot set the object to be its own parent!"); + return NULL; + } // The object we want to set as parent CValue *m_ob = (CValue*)value; diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index 4a4c98603e3..d9b1cc6df23 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -190,24 +190,24 @@ PyObject* KX_MeshProxy::PyGetVertexArrayLength(PyObject* self, PyObject* args, PyObject* kwds) { - int matid= -1; - int length = -1; + int matid= 0; + int length = 0; - if (PyArg_ParseTuple(args,"i",&matid)) + if (!PyArg_ParseTuple(args,"i",&matid)) + return NULL; + + + RAS_MeshMaterial *mmat = m_meshobj->GetMeshMaterial(matid); /* can be NULL*/ + + if (mmat) { - RAS_MeshMaterial *mmat = m_meshobj->GetMeshMaterial(matid); RAS_IPolyMaterial* mat = mmat->m_bucket->GetPolyMaterial(); - if (mat) length = m_meshobj->NumVertices(mat); } - else { - return NULL; - } - + return PyInt_FromLong(length); - } @@ -244,15 +244,21 @@ PyObject* KX_MeshProxy::PyGetPolygon(PyObject* self, if (!PyArg_ParseTuple(args,"i",&polyindex)) return NULL; + + if (polyindex<0 || polyindex >= m_meshobj->NumPolygons()) + { + PyErr_SetString(PyExc_AttributeError, "Invalid polygon index"); + return NULL; + } + RAS_Polygon* polygon = m_meshobj->GetPolygon(polyindex); if (polygon) { polyob = new KX_PolyProxy(m_meshobj, polygon); } - else - { - PyErr_SetString(PyExc_AttributeError, "Invalid polygon index"); + else { + PyErr_SetString(PyExc_AttributeError, "polygon is NULL, unknown reason"); } return polyob; } @@ -275,11 +281,22 @@ PyObject* KX_MeshProxy::pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_ list::iterator mit= self->m_meshobj->GetFirstMaterial(); - /* Can be a KX_PolygonMaterial or KX_BlenderMaterial, since both are cast to a PyObject * we dont need to care */ + for(i=0; im_bucket->GetPolyMaterial(); - PyList_SET_ITEM(materials, i, py_mat); - Py_INCREF(py_mat); + RAS_IPolyMaterial *polymat = mit->m_bucket->GetPolyMaterial(); + + /* Why do we need to check for RAS_BLENDERMAT if both are cast to a (PyObject*)? - Campbell */ + if(polymat->GetFlag() & RAS_BLENDERMAT) + { + KX_BlenderMaterial *mat = static_cast(polymat); + PyList_SET_ITEM(materials, i, mat); + Py_INCREF(mat); + } + else { + KX_PolygonMaterial *mat = static_cast(polymat); + PyList_SET_ITEM(materials, i, mat); + Py_INCREF(mat); + } } return materials; } diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index c5bddd6d166..3975189a9c2 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -333,8 +333,11 @@ PyObject* KX_PolygonMaterial::pyattr_get_tface(void *self_v, const KX_PYATTRIBUT PyObject* KX_PolygonMaterial::pyattr_get_gl_texture(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_PolygonMaterial* self= static_cast(self_v); - Image *ima = self->m_tface->tpage; - return PyInt_FromLong(ima ? ima->bindcode:0); + int bindcode= 0; + if (self->m_tface && self->m_tface->tpage) + bindcode= self->m_tface->tpage->bindcode; + + return PyInt_FromLong(bindcode); } diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.h b/source/gameengine/Ketsji/KX_PolygonMaterial.h index 1e8ce5c3367..9865a66e836 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.h +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.h @@ -33,6 +33,7 @@ #include "RAS_MaterialBucket.h" #include "RAS_IRasterizer.h" +#include "DNA_ID.h" struct MTFace; struct Material; @@ -117,7 +118,7 @@ public: virtual PyObject* py_getattro(PyObject *attr); virtual int py_setattro(PyObject *attr, PyObject *pyvalue); - + virtual PyObject* py_repr(void) { return PyString_FromString(m_material ? ((ID *)m_material)->name+2 : ""); } static PyObject* pyattr_get_texture(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_material(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 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); diff --git a/source/gameengine/Ketsji/KX_RayCast.cpp b/source/gameengine/Ketsji/KX_RayCast.cpp index 974d4b992a6..8c7612bf663 100644 --- a/source/gameengine/Ketsji/KX_RayCast.cpp +++ b/source/gameengine/Ketsji/KX_RayCast.cpp @@ -56,12 +56,15 @@ void KX_RayCast::reportHit(PHY_RayCastResult* result) bool KX_RayCast::RayTest(PHY_IPhysicsEnvironment* physics_environment, const MT_Point3& _frompoint, const MT_Point3& topoint, KX_RayCast& callback) { + if(physics_environment==NULL) return false; /* prevents crashing in some cases */ + // Loops over all physics objects between frompoint and topoint, // calling callback.RayHit for each one. // // callback.RayHit should return true to stop looking, or false to continue. // // returns true if an object was found, false if not. + MT_Point3 frompoint(_frompoint); const MT_Vector3 todir( (topoint - frompoint).safe_normalized() ); MT_Point3 prevpoint(_frompoint+todir*(-1.f)); diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index 40a2ff2ef66..f158eb29dd7 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -468,6 +468,11 @@ PyObject* KX_SceneActuator::PyGetCamera(PyObject* self, PyObject* kwds) { ShowDeprecationWarning("getCamera()", "the camera property"); - return PyString_FromString(m_camera->GetName()); + if (m_camera) { + PyString_FromString(m_camera->GetName()); + } + else { + Py_RETURN_NONE; + } } /* eof */ diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index 88c3a55280e..97e53ffacaa 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -270,6 +270,8 @@ class KX_GameObject: # (SCA_IObject) The reaction force is the force applied to this object over the last simulation timestep. This also includes impulses, eg from collisions. + (B{This is not implimented for bullet physics at the moment}) + @rtype: list [fx, fy, fz] @return: the reaction force of this object. """ -- cgit v1.2.3 From 3dacfbb23161a1b779c2c4ac0f06431c5adda6a2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 5 Apr 2009 14:55:50 +0000 Subject: BGE Python API - action attribute wasnt checking for NULL (own fault) - KX_Scene getCamera wasnt checking for NULL - CListValue had asserts for not yet implimented functionality, this would close blender. Better to print an error if the user manages to run this functions (I managed to by CListValue.count([1,2,3])) --- source/gameengine/Converter/BL_ActionActuator.cpp | 2 +- source/gameengine/Converter/BL_ShapeActionActuator.cpp | 2 +- source/gameengine/Expressions/ListValue.cpp | 12 +++++++++--- source/gameengine/Ketsji/KX_SceneActuator.cpp | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 46ad344c5dd..9102c453a16 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -1055,7 +1055,7 @@ int BL_ActionActuator::py_setattro(PyObject *attr, PyObject* value) { PyObject* BL_ActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { BL_ActionActuator* self= static_cast(self_v); - return PyString_FromString(self->GetAction()->id.name+2); + return PyString_FromString(self->GetAction() ? self->GetAction()->id.name+2 : ""); } int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index a6dbf088ee3..d52cc8cfccc 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -886,7 +886,7 @@ PyObject* BL_ShapeActionActuator::PySetType(PyObject* self, PyObject* BL_ShapeActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { BL_ShapeActionActuator* self= static_cast(self_v); - return PyString_FromString(self->GetAction()->id.name+2); + return PyString_FromString(self->GetAction() ? self->GetAction()->id.name+2 : ""); } int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 15eb8835b79..d0aec645468 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -430,6 +430,10 @@ bool CListValue::CheckEqual(CValue* first,CValue* second) bool result = false; CValue* eqval = ((CValue*)first)->Calc(VALUE_EQL_OPERATOR,(CValue*)second); + + if (eqval==NULL) + return false; + STR_String txt = eqval->GetText(); eqval->Release(); if (txt=="TRUE") @@ -479,7 +483,7 @@ PyObject* CListValue::Pycount(PyObject* self, PyObject* value) if (checkobj==NULL) { /* in this case just return that there are no items in the list */ PyErr_Clear(); - PyInt_FromLong(0); + return PyInt_FromLong(0); } int numelem = GetCount(); @@ -503,7 +507,8 @@ PyObject* CListValue::Pycount(PyObject* self, PyObject* value) * --------------------------------------------------------------------- */ CValue* CListValue::Calc(VALUE_OPERATOR op,CValue *val) { - assert(false); // todo: implement me! + //assert(false); // todo: implement me! + fprintf(stderr, "CValueList::Calc not yet implimented\n"); return NULL; } @@ -513,7 +518,8 @@ CValue* CListValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue* val) { - assert(false); // todo: implement me! + //assert(false); // todo: implement me! + fprintf(stderr, "CValueList::CalcFinal not yet implimented\n"); return NULL; } diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index f158eb29dd7..e1cd3d45503 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -469,7 +469,7 @@ PyObject* KX_SceneActuator::PyGetCamera(PyObject* self, { ShowDeprecationWarning("getCamera()", "the camera property"); if (m_camera) { - PyString_FromString(m_camera->GetName()); + return PyString_FromString(m_camera->GetName()); } else { Py_RETURN_NONE; -- cgit v1.2.3 From b4e4ccf92ddc8a7d4ed3da13c589b2f7c44baa0d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 5 Apr 2009 19:37:13 +0000 Subject: BGE PyAPI can now import text (within the blend-file) Previously this only worked with the Blender API. - bpy_internal_import small C file that Blender scripting and the game engine use. - Tested with blender, blenderplayer, loading files - Needed to use a hack to override the Main struct since the game engine doesn't set G.main - when the sandbox is set, only internal scripts can be imported. --- .../BlenderRoutines/BL_KetsjiEmbedStart.cpp | 4 +- .../GamePlayer/ghost/GPG_Application.cpp | 2 +- source/gameengine/Ketsji/CMakeLists.txt | 1 + source/gameengine/Ketsji/KX_PythonInit.cpp | 49 ++++++++++++++++++---- source/gameengine/Ketsji/KX_PythonInit.h | 4 +- source/gameengine/Ketsji/SConscript | 6 ++- 6 files changed, 52 insertions(+), 14 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index d89d2d80ab4..1d4cd011fe4 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -357,7 +357,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, blscene); // some python things - PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest); + PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest, blenderdata); ketsjiengine->SetPythonDictionary(dictionaryobject); initRasterizer(rasterizer, canvas); PyObject *gameLogic = initGameLogic(ketsjiengine, startscene); @@ -656,7 +656,7 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, blscene); // some python things - PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest); + PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest, blenderdata); ketsjiengine->SetPythonDictionary(dictionaryobject); initRasterizer(rasterizer, canvas); PyObject *gameLogic = initGameLogic(ketsjiengine, startscene); diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index cca344a03bb..6d846610109 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -681,7 +681,7 @@ bool GPG_Application::startEngine(void) // some python things - PyObject* dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest); + PyObject* dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest, m_maggie); m_ketsjiengine->SetPythonDictionary(dictionaryobject); initRasterizer(m_rasterizer, m_canvas); PyObject *gameLogic = initGameLogic(m_ketsjiengine, startscene); diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index 58411f6d25e..3bd05ca5137 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -35,6 +35,7 @@ SET(SRC ../../../source/blender/python/api2_2x/point.c ../../../source/blender/python/api2_2x/quat.c ../../../source/blender/python/api2_2x/vector.c + ../../../source/blender/python/api2_2x/bpy_internal_import.c ) SET(INC diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index f065eb29c44..ef7655f38a2 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -77,6 +77,7 @@ extern "C" { #include "Mathutils.h" // Blender.Mathutils module copied here so the blenderlayer can use. + #include "bpy_internal_import.h" /* from the blender python api, but we want to import text too! */ } #include "marshal.h" /* python header for loading/saving dicts */ @@ -1107,11 +1108,6 @@ PyObject *KXpy_open(PyObject *self, PyObject *args) { return NULL; } -PyObject *KXpy_reload(PyObject *self, PyObject *args) { - PyErr_SetString(PyExc_RuntimeError, "Sandbox: reload() function disabled!\nGame Scripts should not use this function."); - return NULL; -} - PyObject *KXpy_file(PyObject *self, PyObject *args) { PyErr_SetString(PyExc_RuntimeError, "Sandbox: file() function disabled!\nGame Scripts should not use this function."); return NULL; @@ -1162,6 +1158,11 @@ PyObject *KXpy_import(PyObject *self, PyObject *args) !strcmp(name, "Rasterizer") || !strcmp(name, "Mathutils")) { return PyImport_ImportModuleEx(name, globals, locals, fromlist); } + + /* Import blender texts as python modules */ + m= importText(name); + if (m) + return m; PyErr_Format(PyExc_ImportError, "Import of external Module %.20s not allowed.", name); @@ -1169,6 +1170,29 @@ PyObject *KXpy_import(PyObject *self, PyObject *args) } +PyObject *KXpy_reload(PyObject *self, PyObject *args) { + + /* Used to be sandboxed, bettet to allow importing of internal text only */ +#if 0 + PyErr_SetString(PyExc_RuntimeError, "Sandbox: reload() function disabled!\nGame Scripts should not use this function."); + return NULL; +#endif + + PyObject *module = NULL; + PyObject *newmodule = NULL; + + /* check for a module arg */ + if( !PyArg_ParseTuple( args, "O:bpy_reload", &module ) ) + return NULL; + + newmodule= reimportText( module ); + + if (newmodule==NULL) + PyErr_SetString(PyExc_ImportError, "failed to reload from blenders internal text"); + + return newmodule; +} + /* override python file type functions */ #if 0 static int @@ -1241,6 +1265,9 @@ void setSandbox(TPythonSecurityLevel level) } */ default: + /* Allow importing internal text, from bpy_internal_import.py */ + PyDict_SetItemString(d, "reload", PyCFunction_New(bpy_reload, NULL)); + PyDict_SetItemString(d, "__import__", PyCFunction_New(bpy_import, NULL)); break; } } @@ -1248,7 +1275,7 @@ void setSandbox(TPythonSecurityLevel level) /** * Python is not initialised. */ -PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level) +PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level, Main *maggie) { STR_String pname = progname; Py_SetProgramName(pname.Ptr()); @@ -1260,7 +1287,9 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur setSandbox(level); initPyTypes(); - + + bpy_import_main_set(maggie); + PyObject* moduleobj = PyImport_AddModule("__main__"); return PyModule_GetDict(moduleobj); } @@ -1268,12 +1297,13 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur void exitGamePlayerPythonScripting() { Py_Finalize(); + bpy_import_main_set(NULL); } /** * Python is already initialized. */ -PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level) +PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level, Main *maggie) { STR_String pname = progname; Py_SetProgramName(pname.Ptr()); @@ -1282,6 +1312,8 @@ PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLev setSandbox(level); initPyTypes(); + + bpy_import_main_set(maggie); PyObject* moduleobj = PyImport_AddModule("__main__"); return PyModule_GetDict(moduleobj); @@ -1291,6 +1323,7 @@ PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLev void exitGamePythonScripting() { + bpy_import_main_set(NULL); } diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h index 57ee0be9400..b709cee2f37 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.h +++ b/source/gameengine/Ketsji/KX_PythonInit.h @@ -43,11 +43,11 @@ extern bool gUseVisibilityTemp; PyObject* initGameLogic(class KX_KetsjiEngine *engine, class KX_Scene* ketsjiscene); PyObject* initGameKeys(); PyObject* initRasterizer(class RAS_IRasterizer* rasty,class RAS_ICanvas* canvas); -PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level); +PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level, struct Main *maggie); PyObject* initMathutils(); PyObject* initVideoTexture(void); void exitGamePlayerPythonScripting(); -PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level); +PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level, struct Main *maggie); void exitGamePythonScripting(); void setGamePythonPath(char *path); diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript index 5989d9d8b52..68e5c62ab6c 100644 --- a/source/gameengine/Ketsji/SConscript +++ b/source/gameengine/Ketsji/SConscript @@ -18,7 +18,11 @@ sources.extend([\ '#source/blender/python/api2_2x/vector.c',\ ]) -incs = '. #source/blender/python/api2_2x' # Only for Mathutils! - no other deps +sources.extend([\ + '#source/blender/python/api2_2x/bpy_internal_import.c' +]) + +incs = '. #source/blender/python/api2_2x' # Only for Mathutils! and bpy_internal_import.h, be very careful incs += ' #source/kernel/gen_system #intern/string #intern/guardedalloc' incs += ' #source/gameengine/Rasterizer/RAS_OpenGLRasterizer #intern/bmfont' -- cgit v1.2.3 From c10d1c28532e238f418244df7c994c212634114a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 6 Apr 2009 08:17:04 +0000 Subject: Python ref-counting fixes --- .../BlenderRoutines/BL_KetsjiEmbedStart.cpp | 4 +- source/gameengine/Ketsji/BL_Shader.h | 1 + .../gameengine/Ketsji/KX_PyConstraintBinding.cpp | 1 + source/gameengine/Ketsji/KX_PythonInit.cpp | 73 +++++++++++++++++----- source/gameengine/Ketsji/KX_Scene.cpp | 2 +- 5 files changed, 65 insertions(+), 16 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 1d4cd011fe4..9228798890a 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -527,7 +527,9 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, SND_DeviceManager::Unsubscribe(); } while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME); - + + Py_DECREF(pyGlobalDict); + if (bfd) BLO_blendfiledata_free(bfd); BLI_strncpy(G.sce, oldsce, sizeof(G.sce)); diff --git a/source/gameengine/Ketsji/BL_Shader.h b/source/gameengine/Ketsji/BL_Shader.h index 490c0268a6d..08cad5071fd 100644 --- a/source/gameengine/Ketsji/BL_Shader.h +++ b/source/gameengine/Ketsji/BL_Shader.h @@ -203,6 +203,7 @@ public: // Python interface virtual PyObject* py_getattro(PyObject *attr); + virtual PyObject* py_repr(void) { return PyString_FromFormat("BL_Shader\n\tvertex shader:%s\n\n\tfragment shader%s\n\n", vertProg, fragProg); } // ----------------------------------- KX_PYMETHOD_DOC( BL_Shader, setSource ); diff --git a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp index fb37eded450..34c975f6bf6 100644 --- a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp +++ b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp @@ -582,6 +582,7 @@ PyObject* initPythonConstraintBinding() d = PyModule_GetDict(m); ErrorObject = PyString_FromString("PhysicsConstraints.error"); PyDict_SetItemString(d, "error", ErrorObject); + Py_DECREF(ErrorObject); // XXXX Add constants here diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index ef7655f38a2..73342d891d8 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -113,9 +113,9 @@ void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,cons /* Macro for building the keyboard translation */ //#define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, PyInt_FromLong(SCA_IInputDevice::KX_##name)) -#define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, PyInt_FromLong(name)) +#define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, item=PyInt_FromLong(name)); Py_DECREF(item) /* For the defines for types from logic bricks, we do stuff explicitly... */ -#define KX_MACRO_addTypesToDict(dict, name, name2) PyDict_SetItemString(dict, #name, PyInt_FromLong(name2)) +#define KX_MACRO_addTypesToDict(dict, name, name2) PyDict_SetItemString(dict, #name, item=PyInt_FromLong(name2)); Py_DECREF(item) // temporarily python stuff, will be put in another place later ! @@ -916,26 +916,41 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack { PyObject* m; PyObject* d; - + PyObject* item; /* temp PyObject* storage */ + gp_KetsjiEngine = engine; gp_KetsjiScene = scene; gUseVisibilityTemp=false; // Create the module and add the functions - m = Py_InitModule4("GameLogic", game_methods, + + + m = PyImport_ImportModule("GameLogic"); + + if(m==NULL) { + printf("Import for the first time!\n"); + PyErr_Clear(); + m = Py_InitModule4("GameLogic", game_methods, GameLogic_module_documentation, (PyObject*)NULL,PYTHON_API_VERSION); - + } + else { + Py_DECREF(m); /**/ + printf("Alredy imported!\n"); + return(m); + } // Add some symbolic constants to the module d = PyModule_GetDict(m); // can be overwritten later for gameEngine instances that can load new blend files and re-initialize this module // for now its safe to make sure it exists for other areas such as the web plugin - PyDict_SetItemString(d, "globalDict", PyDict_New()); + + PyDict_SetItemString(d, "globalDict", item=PyDict_New()); Py_DECREF(item); ErrorObject = PyString_FromString("GameLogic.error"); PyDict_SetItemString(d, "error", ErrorObject); + Py_DECREF(ErrorObject); // XXXX Add constants here /* To use logic bricks, we need some sort of constants. Here, we associate */ @@ -1225,18 +1240,18 @@ void setSandbox(TPythonSecurityLevel level) { PyObject *m = PyImport_AddModule("__builtin__"); PyObject *d = PyModule_GetDict(m); - + PyObject *item; switch (level) { case psl_Highest: //if (!g_security) { //g_oldopen = PyDict_GetItemString(d, "open"); // functions we cant trust - PyDict_SetItemString(d, "open", PyCFunction_New(meth_open, NULL)); - PyDict_SetItemString(d, "reload", PyCFunction_New(meth_reload, NULL)); - PyDict_SetItemString(d, "file", PyCFunction_New(meth_file, NULL)); - PyDict_SetItemString(d, "execfile", PyCFunction_New(meth_execfile, NULL)); - PyDict_SetItemString(d, "compile", PyCFunction_New(meth_compile, NULL)); + PyDict_SetItemString(d, "open", item=PyCFunction_New(meth_open, NULL)); Py_DECREF(item); + PyDict_SetItemString(d, "reload", item=PyCFunction_New(meth_reload, NULL)); Py_DECREF(item); + PyDict_SetItemString(d, "file", item=PyCFunction_New(meth_file, NULL)); Py_DECREF(item); + PyDict_SetItemString(d, "execfile", item=PyCFunction_New(meth_execfile, NULL)); Py_DECREF(item); + PyDict_SetItemString(d, "compile", item=PyCFunction_New(meth_compile, NULL)); Py_DECREF(item); // our own import PyDict_SetItemString(d, "__import__", PyCFunction_New(meth_import, NULL)); @@ -1266,8 +1281,8 @@ void setSandbox(TPythonSecurityLevel level) */ default: /* Allow importing internal text, from bpy_internal_import.py */ - PyDict_SetItemString(d, "reload", PyCFunction_New(bpy_reload, NULL)); - PyDict_SetItemString(d, "__import__", PyCFunction_New(bpy_import, NULL)); + PyDict_SetItemString(d, "reload", item=PyCFunction_New(bpy_reload, NULL)); Py_DECREF(item); + PyDict_SetItemString(d, "__import__", item=PyCFunction_New(bpy_import, NULL)); Py_DECREF(item); break; } } @@ -1296,6 +1311,7 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur void exitGamePlayerPythonScripting() { + //clearGameModules(); // were closing python anyway Py_Finalize(); bpy_import_main_set(NULL); } @@ -1319,10 +1335,36 @@ PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLev return PyModule_GetDict(moduleobj); } +static void clearModule(PyObject *modules, const char *name) +{ + PyObject *mod= PyDict_GetItemString(modules, name); + + if (mod==NULL) + return; + + PyDict_Clear(PyModule_GetDict(mod)); /* incase there are any circular refs */ + PyDict_DelItemString(modules, name); +} +static void clearGameModules() +{ + /* Note, user modules could still reference these modules + * but since the dict's are cleared their members wont be accessible */ + + PyObject *modules= PySys_GetObject("modules"); + clearModule(modules, "Expression"); + clearModule(modules, "CValue"); + clearModule(modules, "PhysicsConstraints"); + clearModule(modules, "GameLogic"); + clearModule(modules, "Rasterizer"); + clearModule(modules, "GameKeys"); + clearModule(modules, "VideoTexture"); + PyErr_Clear(); // incase some of these were alredy removed. +} void exitGamePythonScripting() { + clearGameModules(); bpy_import_main_set(NULL); } @@ -1336,6 +1378,7 @@ PyObject* initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas) PyObject* m; PyObject* d; + PyObject* item; // Create the module and add the functions m = Py_InitModule4("Rasterizer", rasterizer_methods, @@ -1346,6 +1389,7 @@ PyObject* initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas) d = PyModule_GetDict(m); ErrorObject = PyString_FromString("Rasterizer.error"); PyDict_SetItemString(d, "error", ErrorObject); + Py_DECREF(ErrorObject); /* needed for get/setMaterialType */ KX_MACRO_addTypesToDict(d, KX_TEXFACE_MATERIAL, KX_TEXFACE_MATERIAL); @@ -1414,6 +1458,7 @@ PyObject* initGameKeys() { PyObject* m; PyObject* d; + PyObject* item; // Create the module and add the functions m = Py_InitModule4("GameKeys", gamekeys_methods, diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 254717894df..72f2fd9827f 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -244,7 +244,7 @@ KX_Scene::~KX_Scene() { delete m_bucketmanager; } - //Py_DECREF(m_attrlist); + Py_DECREF(m_attrlist); } void KX_Scene::SetProjectionMatrix(MT_CmMatrix4x4& pmat) -- cgit v1.2.3 From 64fe09ab20ce4f80f627d4c868f2b12936c2168c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 6 Apr 2009 12:47:15 +0000 Subject: - remove debug printf - remove test for importing the module rather then creating a new one (didnt mean to commit) - added constants for the mouse sensor to use. --- source/gameengine/Ketsji/KX_PythonInit.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 73342d891d8..9929e66c3a4 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -924,22 +924,10 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack gUseVisibilityTemp=false; // Create the module and add the functions - - - m = PyImport_ImportModule("GameLogic"); - - if(m==NULL) { - printf("Import for the first time!\n"); - PyErr_Clear(); - m = Py_InitModule4("GameLogic", game_methods, + m = Py_InitModule4("GameLogic", game_methods, GameLogic_module_documentation, (PyObject*)NULL,PYTHON_API_VERSION); - } - else { - Py_DECREF(m); /**/ - printf("Alredy imported!\n"); - return(m); - } + // Add some symbolic constants to the module d = PyModule_GetDict(m); @@ -1105,6 +1093,16 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, KX_DYN_DISABLE_RIGID_BODY, KX_SCA_DynamicActuator::KX_DYN_DISABLE_RIGID_BODY); KX_MACRO_addTypesToDict(d, KX_DYN_SET_MASS, KX_SCA_DynamicActuator::KX_DYN_SET_MASS); + /* Input & Mouse Sensor */ + KX_MACRO_addTypesToDict(d, KX_INPUT_NONE, SCA_InputEvent::KX_NO_INPUTSTATUS); + KX_MACRO_addTypesToDict(d, KX_INPUT_JUST_ACTIVATED, SCA_InputEvent::KX_JUSTACTIVATED); + KX_MACRO_addTypesToDict(d, KX_INPUT_ACTIVE, SCA_InputEvent::KX_ACTIVE); + KX_MACRO_addTypesToDict(d, KX_INPUT_JUST_RELEASED, SCA_InputEvent::KX_JUSTRELEASED); + + KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_LEFT, SCA_InputEvent::KX_LEFTMOUSE); + KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_MIDDLE, SCA_InputEvent::KX_MIDDLEMOUSE); + KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_RIGHT, SCA_InputEvent::KX_RIGHTMOUSE); + // Check for errors if (PyErr_Occurred()) { -- cgit v1.2.3 From 960fa534b7690796d463f062edf572ceae88457d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 6 Apr 2009 13:13:25 +0000 Subject: BGE Epydocs were missing some functions renamed KX_Light -> KX_LightObject added some missing controllers --- source/gameengine/PyDoc/GameLogic.py | 23 ++++++- source/gameengine/PyDoc/GameTypes.py | 75 ++++++++++++++++++++++ source/gameengine/PyDoc/KX_ActuatorSensor.py | 33 ---------- source/gameengine/PyDoc/KX_Camera.py | 22 +++++++ source/gameengine/PyDoc/KX_GameObject.py | 11 +++- source/gameengine/PyDoc/KX_Light.py | 45 ------------- source/gameengine/PyDoc/KX_LightObject.py | 45 +++++++++++++ source/gameengine/PyDoc/KX_MouseFocusSensor.py | 40 ++++++++++-- .../gameengine/PyDoc/KX_SCA_AddObjectActuator.py | 7 ++ source/gameengine/PyDoc/KX_SCA_DynamicActuator.py | 2 +- .../gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py | 6 +- source/gameengine/PyDoc/KX_Scene.py | 2 +- source/gameengine/PyDoc/KX_VertexProxy.py | 21 ++++++ source/gameengine/PyDoc/SCA_ActuatorSensor.py | 33 ++++++++++ source/gameengine/PyDoc/SCA_MouseSensor.py | 10 +++ source/gameengine/PyDoc/SCA_NANDController.py | 11 ++++ source/gameengine/PyDoc/SCA_NORController.py | 11 ++++ source/gameengine/PyDoc/SCA_XNORController.py | 11 ++++ source/gameengine/PyDoc/SCA_XORController.py | 11 ++++ source/gameengine/PyDoc/WhatsNew.py | 2 +- 20 files changed, 328 insertions(+), 93 deletions(-) create mode 100644 source/gameengine/PyDoc/GameTypes.py delete mode 100644 source/gameengine/PyDoc/KX_ActuatorSensor.py delete mode 100644 source/gameengine/PyDoc/KX_Light.py create mode 100644 source/gameengine/PyDoc/KX_LightObject.py create mode 100644 source/gameengine/PyDoc/SCA_ActuatorSensor.py create mode 100644 source/gameengine/PyDoc/SCA_NANDController.py create mode 100644 source/gameengine/PyDoc/SCA_NORController.py create mode 100644 source/gameengine/PyDoc/SCA_XNORController.py create mode 100644 source/gameengine/PyDoc/SCA_XORController.py (limited to 'source/gameengine') diff --git a/source/gameengine/PyDoc/GameLogic.py b/source/gameengine/PyDoc/GameLogic.py index f158b410975..da394288e25 100644 --- a/source/gameengine/PyDoc/GameLogic.py +++ b/source/gameengine/PyDoc/GameLogic.py @@ -3,10 +3,17 @@ Documentation for the GameLogic Module. ======================================= - There are only three importable modules in the game engine: + Modules available in the game engine: - GameLogic - L{GameKeys} - L{Rasterizer} + - L{GameTypes} + + Undocumented modules: + - VideoTexture + - CValue + - Expression + - PhysicsConstraints All the other modules are accessible through the methods in GameLogic. @@ -18,7 +25,7 @@ Documentation for the GameLogic Module. # To get the game object this controller is on: obj = co.getOwner() - L{KX_GameObject} and L{KX_Camera} or L{KX_Light} methods are + L{KX_GameObject} and L{KX_Camera} or L{KX_LightObject} methods are available depending on the type of object:: # To get a sensor linked to this controller. # "sensorname" is the name of the sensor as defined in the Blender interface. @@ -165,9 +172,19 @@ Documentation for the GameLogic Module. @var KX_DYN_DISABLE_RIGID_BODY: See L{KX_SCA_DynamicActuator} @var KX_DYN_SET_MASS: See L{KX_SCA_DynamicActuator} -""" +@group Input Status: KX_INPUT_NONE, KX_INPUT_JUST_ACTIVATED, KX_INPUT_ACTIVE, KX_INPUT_JUST_RELEASED +@var KX_INPUT_NONE: See L{SCA_MouseSensor} +@var KX_INPUT_JUST_ACTIVATED: See L{SCA_MouseSensor} +@var KX_INPUT_ACTIVE: See L{SCA_MouseSensor} +@var KX_INPUT_JUST_RELEASED: See L{SCA_MouseSensor} +@group Mouse Buttons: KX_MOUSE_BUT_LEFT, KX_MOUSE_BUT_MIDDLE, KX_MOUSE_BUT_RIGHT +@var KX_MOUSE_BUT_LEFT: See L{SCA_MouseSensor} +@var KX_MOUSE_BUT_MIDDLE: See L{SCA_MouseSensor} +@var KX_MOUSE_BUT_RIGHT: See L{SCA_MouseSensor} +""" + def getCurrentController(): """ Gets the Python controller associated with this Python script. diff --git a/source/gameengine/PyDoc/GameTypes.py b/source/gameengine/PyDoc/GameTypes.py new file mode 100644 index 00000000000..f39e4ed064d --- /dev/null +++ b/source/gameengine/PyDoc/GameTypes.py @@ -0,0 +1,75 @@ +# $Id: GameLogic.py 19483 2009-03-31 21:03:15Z ben2610 $ +""" +GameEngine Types +================ +@var BL_ActionActuator: L{BL_ActionActuator} +@var BL_Shader: L{BL_Shader} +@var BL_ShapeActionActuator: L{BL_ShapeActionActuator} +@var CListValue: L{CListValue} +@var CValue: L{CValue} +@var KX_BlenderMaterial: L{KX_BlenderMaterial} +@var KX_CDActuator: L{KX_CDActuator} +@var KX_Camera: L{KX_Camera} +@var KX_CameraActuator: L{KX_CameraActuator} +@var KX_ConstraintActuator: L{KX_ConstraintActuator} +@var KX_ConstraintWrapper: L{KX_ConstraintWrapper} +@var KX_GameActuator: L{KX_GameActuator} +@var KX_GameObject: L{KX_GameObject} +@var KX_IpoActuator: L{KX_IpoActuator} +@var KX_LightObject: L{KX_LightObject} +@var KX_MeshProxy: L{KX_MeshProxy} +@var KX_MouseFocusSensor: L{KX_MouseFocusSensor} +@var KX_NearSensor: L{KX_NearSensor} +@var KX_NetworkMessageActuator: L{KX_NetworkMessageActuator} +@var KX_NetworkMessageSensor: L{KX_NetworkMessageSensor} +@var KX_ObjectActuator: L{KX_ObjectActuator} +@var KX_ParentActuator: L{KX_ParentActuator} +@var KX_PhysicsObjectWrapper: L{KX_PhysicsObjectWrapper} +@var KX_PolyProxy: L{KX_PolyProxy} +@var KX_PolygonMaterial: L{KX_PolygonMaterial} +@var KX_RadarSensor: L{KX_RadarSensor} +@var KX_RaySensor: L{KX_RaySensor} +@var KX_SCA_AddObjectActuator: L{KX_SCA_AddObjectActuator} +@var KX_SCA_DynamicActuator: L{KX_SCA_DynamicActuator} +@var KX_SCA_EndObjectActuator: L{KX_SCA_EndObjectActuator} +@var KX_SCA_ReplaceMeshActuator: L{KX_SCA_ReplaceMeshActuator} +@var KX_Scene: L{KX_Scene} +@var KX_SceneActuator: L{KX_SceneActuator} +@var KX_SoundActuator: L{KX_SoundActuator} +@var KX_StateActuator: L{KX_StateActuator} +@var KX_TouchSensor: L{KX_TouchSensor} +@var KX_TrackToActuator: L{KX_TrackToActuator} +@var KX_VehicleWrapper: L{KX_VehicleWrapper} +@var KX_VertexProxy: L{KX_VertexProxy} +@var KX_VisibilityActuator: L{KX_VisibilityActuator} +@var PyObjectPlus: L{PyObjectPlus} +@var SCA_2DFilterActuator: L{SCA_2DFilterActuator} +@var SCA_ANDController: L{SCA_ANDController} +@var SCA_ActuatorSensor: L{SCA_ActuatorSensor} +@var SCA_AlwaysSensor: L{SCA_AlwaysSensor} +@var SCA_DelaySensor: L{SCA_DelaySensor} +@var SCA_ILogicBrick: L{SCA_ILogicBrick} +@var SCA_IObject: L{SCA_IObject} +@var SCA_ISensor: L{SCA_ISensor} +@var SCA_JoystickSensor: L{SCA_JoystickSensor} +@var SCA_KeyboardSensor: L{SCA_KeyboardSensor} +@var SCA_MouseSensor: L{SCA_MouseSensor} +@var SCA_NANDController: L{SCA_NANDController} +@var SCA_NORController: L{SCA_NORController} +@var SCA_ORController: L{SCA_ORController} +@var SCA_PropertyActuator: L{SCA_PropertyActuator} +@var SCA_PropertySensor: L{SCA_PropertySensor} +@var SCA_PythonController: L{SCA_PythonController} +@var SCA_RandomActuator: L{SCA_RandomActuator} +@var SCA_RandomSensor: L{SCA_RandomSensor} +@var SCA_XNORController: L{SCA_XNORController} +@var SCA_XORController: L{SCA_XORController} +""" + +if 0: + # Use to print out all the links + for i in a.split('\n'): + if i.startswith('@var'): + var = i.split(' ')[1].split(':')[0] + print '@var %s: L{%s<%s.%s>}' % (var, var, var, var) + diff --git a/source/gameengine/PyDoc/KX_ActuatorSensor.py b/source/gameengine/PyDoc/KX_ActuatorSensor.py deleted file mode 100644 index 27ee3a475e0..00000000000 --- a/source/gameengine/PyDoc/KX_ActuatorSensor.py +++ /dev/null @@ -1,33 +0,0 @@ -# $Id$ -# Documentation for KX_ActuatorSensor -from SCA_IActuator import * -from SCA_ISensor import * -from SCA_ILogicBrick import * - -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. - - @param name: actuator name - @type name: string - """ diff --git a/source/gameengine/PyDoc/KX_Camera.py b/source/gameengine/PyDoc/KX_Camera.py index 4cadf1c0ed0..f5d0d45f968 100644 --- a/source/gameengine/PyDoc/KX_Camera.py +++ b/source/gameengine/PyDoc/KX_Camera.py @@ -185,3 +185,25 @@ class KX_Camera(KX_GameObject): @param matrix: The new projection matrix for this camera. """ + def enableViewport(viewport): + """ + Use this camera to draw a viewport on the screen (for split screen games or overlay scenes). The viewport region is defined with L{setViewport}. + + @type viewport: bool + @param viewport: the new viewport status + """ + def setOnTop(): + """ + Set this cameras viewport ontop of all other viewport. + """ + def setViewport(left, bottom, right, top): + """ + Sets the region of this viewport on the screen in pixels. + + Use L{Rasterizer.getWindowHeight} L{Rasterizer.getWindowWidth} to calculate values relative to the entire display. + + @type left: int + @type bottom: int + @type right: int + @type top: int + """ diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index 97e53ffacaa..972a15b7765 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -442,5 +442,12 @@ class KX_GameObject: # (SCA_IObject) If no hit, returns (None,None,None) or (None,None,None,None) If the object hit is not a static mesh, polygon is None """ - - + def setCollisionMargin(margin): + """ + Set the objects collision margin. + + note: If this object has no physics controller (a physics ID of zero), this function will raise RuntimeError. + + @type margin: float + @param margin: the collision margin distance in blender units. + """ diff --git a/source/gameengine/PyDoc/KX_Light.py b/source/gameengine/PyDoc/KX_Light.py deleted file mode 100644 index ff0cf071d2d..00000000000 --- a/source/gameengine/PyDoc/KX_Light.py +++ /dev/null @@ -1,45 +0,0 @@ -# $Id$ -# Documentation for Light game objects. -from KX_GameObject import * - -class KX_Light(KX_GameObject): - """ - A Light object. - - Example: - - # Turn on a red alert light. - import GameLogic - - co = GameLogic.getCurrentController() - light = co.getOwner() - - light.energy = 1.0 - light.colour = [1.0, 0.0, 0.0] - - @group Constants: NORMAL, SPOT, SUN - @ivar SPOT: A spot light source. See attribute 'type' - @ivar SUN: A point light source with no attenuation. See attribute 'type' - @ivar NORMAL: A point light source. See attribute 'type' - - @ivar type: The type of light - must be SPOT, SUN or NORMAL - @ivar layer: The layer mask that this light affects object on. - @type layer: bitfield - @ivar energy: The brightness of this light. - @type energy: float - @ivar distance: The maximum distance this light can illuminate. (SPOT and NORMAL lights only) - @type distance: float - @ivar colour: The colour of this light. Black = [0.0, 0.0, 0.0], White = [1.0, 1.0, 1.0] - @type colour: list [r, g, b] - @ivar color: Synonym for colour. - @ivar lin_attenuation: The linear component of this light's attenuation. (SPOT and NORMAL lights only) - @type lin_attenuation: float - @ivar quad_attenuation: The quadratic component of this light's attenuation (SPOT and NORMAL lights only) - @type quad_attenuation: float - @ivar spotsize: The cone angle of the spot light, in degrees. (float) (SPOT lights only) - 0.0 <= spotsize <= 180.0. Spotsize = 360.0 is also accepted. - @ivar spotblend: Specifies the intensity distribution of the spot light. (float) (SPOT lights only) - Higher values result in a more focused light source. - 0.0 <= spotblend <= 1.0. - - """ diff --git a/source/gameengine/PyDoc/KX_LightObject.py b/source/gameengine/PyDoc/KX_LightObject.py new file mode 100644 index 00000000000..8cc1787887b --- /dev/null +++ b/source/gameengine/PyDoc/KX_LightObject.py @@ -0,0 +1,45 @@ +# $Id$ +# Documentation for Light game objects. +from KX_GameObject import * + +class KX_LightObject(KX_GameObject): + """ + A Light object. + + Example: + + # Turn on a red alert light. + import GameLogic + + co = GameLogic.getCurrentController() + light = co.getOwner() + + light.energy = 1.0 + light.colour = [1.0, 0.0, 0.0] + + @group Constants: NORMAL, SPOT, SUN + @ivar SPOT: A spot light source. See attribute 'type' + @ivar SUN: A point light source with no attenuation. See attribute 'type' + @ivar NORMAL: A point light source. See attribute 'type' + + @ivar type: The type of light - must be SPOT, SUN or NORMAL + @ivar layer: The layer mask that this light affects object on. + @type layer: bitfield + @ivar energy: The brightness of this light. + @type energy: float + @ivar distance: The maximum distance this light can illuminate. (SPOT and NORMAL lights only) + @type distance: float + @ivar colour: The colour of this light. Black = [0.0, 0.0, 0.0], White = [1.0, 1.0, 1.0] + @type colour: list [r, g, b] + @ivar color: Synonym for colour. + @ivar lin_attenuation: The linear component of this light's attenuation. (SPOT and NORMAL lights only) + @type lin_attenuation: float + @ivar quad_attenuation: The quadratic component of this light's attenuation (SPOT and NORMAL lights only) + @type quad_attenuation: float + @ivar spotsize: The cone angle of the spot light, in degrees. (float) (SPOT lights only) + 0.0 <= spotsize <= 180.0. Spotsize = 360.0 is also accepted. + @ivar spotblend: Specifies the intensity distribution of the spot light. (float) (SPOT lights only) + Higher values result in a more focused light source. + 0.0 <= spotblend <= 1.0. + + """ diff --git a/source/gameengine/PyDoc/KX_MouseFocusSensor.py b/source/gameengine/PyDoc/KX_MouseFocusSensor.py index 28d584037f8..ceab5b8c511 100644 --- a/source/gameengine/PyDoc/KX_MouseFocusSensor.py +++ b/source/gameengine/PyDoc/KX_MouseFocusSensor.py @@ -10,17 +10,45 @@ class KX_MouseFocusSensor(SCA_MouseSensor): space to 3d space then raycasting away from the camera. """ - def GetRayTarget(): + def getHitNormal(): """ - Returns the end point of the sensor ray. + Returns the normal (in worldcoordinates) at the point of collision where the object was hit by this ray. @rtype: list [x, y, z] - @return: the end point of the sensor ray, in world coordinates. + @return: the ray collision normal. """ - def GetRaySource(): + def getHitObject(): """ - Returns the start point of the sensor ray. + Returns the object that was hit by this ray or None. + + @rtype: L{KX_GameObject} or None + @return: the collision object. + """ + def getHitPosition(): + """ + Returns the position (in worldcoordinates) at the point of collision where the object was hit by this ray. + + @rtype: list [x, y, z] + @return: the ray collision position. + """ + def getRayDirection(): + """ + Returns the normalized direction (in worldcoordinates) of the ray cast by the mouse. @rtype: list [x, y, z] - @return: the start point of the sensor ray, in world coordinates. + @return: the ray direction. """ + def getRaySource(): + """ + Returns the position (in worldcoordinates) the ray was cast from by the mouse. + + @rtype: list [x, y, z] + @return: the ray source. + """ + def getRayTarget(): + """ + Returns the target of the ray (in worldcoordinates) that seeks the focus object. + + @rtype: list [x, y, z] + @return: the ray target. + """ \ No newline at end of file diff --git a/source/gameengine/PyDoc/KX_SCA_AddObjectActuator.py b/source/gameengine/PyDoc/KX_SCA_AddObjectActuator.py index 974ef718ccf..572b864ff0a 100644 --- a/source/gameengine/PyDoc/KX_SCA_AddObjectActuator.py +++ b/source/gameengine/PyDoc/KX_SCA_AddObjectActuator.py @@ -109,3 +109,10 @@ class KX_SCA_AddObjectActuator(SCA_IActuator): @rtype: L{KX_GameObject} @return: A L{KX_GameObject} or None if no object has been created. """ + def instantAddObject(): + """ + Returns the last object created by this actuator. The object can then be accessed from L{objectLastCreated}. + + @rtype: None + """ + diff --git a/source/gameengine/PyDoc/KX_SCA_DynamicActuator.py b/source/gameengine/PyDoc/KX_SCA_DynamicActuator.py index d65d3c22993..22da159ce71 100644 --- a/source/gameengine/PyDoc/KX_SCA_DynamicActuator.py +++ b/source/gameengine/PyDoc/KX_SCA_DynamicActuator.py @@ -22,7 +22,7 @@ class KX_SCA_DynamicActuator(SCA_IActuator): - 3 = disable rigid body - 4 = set mass """ - def getOperatoin(): + def getOperation(): """ DEPRECATED: Use the operation property instead. return the type of operation diff --git a/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py b/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py index 4397a9152d0..951c118a99a 100644 --- a/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py +++ b/source/gameengine/PyDoc/KX_SCA_ReplaceMeshActuator.py @@ -77,4 +77,8 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator): @rtype: string or None """ - + def instantReplaceMesh(): + """ + Immediately replace mesh without delay. + @rtype: None + """ \ No newline at end of file diff --git a/source/gameengine/PyDoc/KX_Scene.py b/source/gameengine/PyDoc/KX_Scene.py index 4f7beb9e300..a9fd44ffc9a 100644 --- a/source/gameengine/PyDoc/KX_Scene.py +++ b/source/gameengine/PyDoc/KX_Scene.py @@ -55,7 +55,7 @@ class KX_Scene: """ Returns the list of lights in the scene. - @rtype: list [L{KX_Light}] + @rtype: list [L{KX_LightObject}] """ def getObjectList(): """ diff --git a/source/gameengine/PyDoc/KX_VertexProxy.py b/source/gameengine/PyDoc/KX_VertexProxy.py index 8dc2752c037..5baaf76c3d9 100644 --- a/source/gameengine/PyDoc/KX_VertexProxy.py +++ b/source/gameengine/PyDoc/KX_VertexProxy.py @@ -70,6 +70,19 @@ class KX_VertexProxy: """ Sets the UV (texture) coordinates of this vertex. + @type uv: list [u, v] + """ + def getUV2(): + """ + Gets the 2nd UV (texture) coordinates of this vertex. + + @rtype: list [u, v] + @return: this vertexes UV (texture) coordinates. + """ + def setUV2(uv): + """ + Sets the 2nd UV (texture) coordinates of this vertex. + @type uv: list [u, v] """ def getRGBA(): @@ -120,3 +133,11 @@ class KX_VertexProxy: @rtype: list [nx, ny, nz] @return: normalised normal vector. """ + def setNormal(normal): + """ + Sets the normal vector of this vertex. + + @type normal: sequence of floats [r, g, b] + @param normal: the new normal of this vertex. + """ + diff --git a/source/gameengine/PyDoc/SCA_ActuatorSensor.py b/source/gameengine/PyDoc/SCA_ActuatorSensor.py new file mode 100644 index 00000000000..515354e8716 --- /dev/null +++ b/source/gameengine/PyDoc/SCA_ActuatorSensor.py @@ -0,0 +1,33 @@ +# $Id$ +# Documentation for SCA_ActuatorSensor +from SCA_IActuator import * +from SCA_ISensor import * +from SCA_ILogicBrick import * + +class SCA_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. + + @param name: actuator name + @type name: string + """ diff --git a/source/gameengine/PyDoc/SCA_MouseSensor.py b/source/gameengine/PyDoc/SCA_MouseSensor.py index 9550cbb4105..278ebe63b8a 100644 --- a/source/gameengine/PyDoc/SCA_MouseSensor.py +++ b/source/gameengine/PyDoc/SCA_MouseSensor.py @@ -32,3 +32,13 @@ class SCA_MouseSensor(SCA_ISensor): @rtype: integer @return: the current y coordinate of the mouse, in frame coordinates (pixels). """ + def getButtonStatus(button): + """ + Get the mouse button status. + + @type button: int + @param button: value in GameLogic members KX_MOUSE_BUT_LEFT, KX_MOUSE_BUT_MIDDLE, KX_MOUSE_BUT_RIGHT + + @rtype: integer + @return: value in GameLogic members KX_INPUT_NONE, KX_INPUT_NONE, KX_INPUT_JUST_ACTIVATED, KX_INPUT_ACTIVE, KX_INPUT_JUST_RELEASED + """ diff --git a/source/gameengine/PyDoc/SCA_NANDController.py b/source/gameengine/PyDoc/SCA_NANDController.py new file mode 100644 index 00000000000..81e1dfd6d92 --- /dev/null +++ b/source/gameengine/PyDoc/SCA_NANDController.py @@ -0,0 +1,11 @@ +# $Id: SCA_ANDController.py 15444 2008-07-05 17:05:05Z lukep $ +# Documentation for SCA_NANDController +from SCA_IController import * + +class SCA_NANDController(SCA_IController): + """ + An NAND controller activates when all linked sensors are not active. + + There are no special python methods for this controller. + """ + diff --git a/source/gameengine/PyDoc/SCA_NORController.py b/source/gameengine/PyDoc/SCA_NORController.py new file mode 100644 index 00000000000..e3bdeefa63e --- /dev/null +++ b/source/gameengine/PyDoc/SCA_NORController.py @@ -0,0 +1,11 @@ +# $Id: SCA_ANDController.py 15444 2008-07-05 17:05:05Z lukep $ +# Documentation for SCA_NORController +from SCA_IController import * + +class SCA_NORController(SCA_IController): + """ + An NOR controller activates only when all linked sensors are de-activated. + + There are no special python methods for this controller. + """ + diff --git a/source/gameengine/PyDoc/SCA_XNORController.py b/source/gameengine/PyDoc/SCA_XNORController.py new file mode 100644 index 00000000000..b1d9dddd9f2 --- /dev/null +++ b/source/gameengine/PyDoc/SCA_XNORController.py @@ -0,0 +1,11 @@ +# $Id: SCA_ANDController.py 15444 2008-07-05 17:05:05Z lukep $ +# Documentation for SCA_XNORController +from SCA_IController import * + +class SCA_XNORController(SCA_IController): + """ + An XNOR controller activates when all linked sensors are the same (activated or inative). + + There are no special python methods for this controller. + """ + diff --git a/source/gameengine/PyDoc/SCA_XORController.py b/source/gameengine/PyDoc/SCA_XORController.py new file mode 100644 index 00000000000..b8f2b5feef0 --- /dev/null +++ b/source/gameengine/PyDoc/SCA_XORController.py @@ -0,0 +1,11 @@ +# $Id: SCA_ANDController.py 15444 2008-07-05 17:05:05Z lukep $ +# Documentation for SCA_XORController +from SCA_IController import * + +class SCA_XORController(SCA_IController): + """ + An XOR controller activates when there is the input is mixed, but not when all are on or off. + + There are no special python methods for this controller. + """ + diff --git a/source/gameengine/PyDoc/WhatsNew.py b/source/gameengine/PyDoc/WhatsNew.py index 64bef7ee1c8..4d86e6ef3c4 100644 --- a/source/gameengine/PyDoc/WhatsNew.py +++ b/source/gameengine/PyDoc/WhatsNew.py @@ -26,7 +26,7 @@ Blender 2.34 - Added getType() and setType() to L{BL_ActionActuator} and L{KX_SoundActuator} (sgefant) - New Scene module: L{KX_Scene} - New Camera module: L{KX_Camera} - - New Light module: L{KX_Light} + - New Light module: L{KX_LightObject} - Added attributes to L{KX_GameObject}, L{KX_VertexProxy} - L{KX_SCA_AddObjectActuator}.setObject(), L{KX_TrackToActuator}.setObject() and L{KX_SceneActuator}.setCamera() now accept L{KX_GameObject}s as parameters -- 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/GameLogic/SCA_MouseSensor.cpp | 2 +- source/gameengine/Ketsji/KX_Light.cpp | 16 ++- source/gameengine/Ketsji/KX_MouseFocusSensor.cpp | 4 +- source/gameengine/Ketsji/KX_PolyProxy.cpp | 11 ++ source/gameengine/Ketsji/KX_PythonInit.cpp | 6 +- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 140 +++++++++++++---------- source/gameengine/Ketsji/KX_VertexProxy.cpp | 24 ++++ source/gameengine/PyDoc/bge_api_validate_py.txt | 66 +++++++++++ 8 files changed, 198 insertions(+), 71 deletions(-) create mode 100644 source/gameengine/PyDoc/bge_api_validate_py.txt (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index c5f6fdabbe8..3cd32391ce2 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -275,7 +275,7 @@ PyObject* SCA_MouseSensor::PyGetYPosition(PyObject* self, 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") +"\tGet the given button's status (KX_INPUT_NONE, KX_INPUT_NONE, KX_INPUT_JUST_ACTIVATED, KX_INPUT_ACTIVE, KX_INPUT_JUST_RELEASED).\n") { if (PyInt_Check(value)) { diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp index 6f9d8b0211b..7b5b77ccacf 100644 --- a/source/gameengine/Ketsji/KX_Light.cpp +++ b/source/gameengine/Ketsji/KX_Light.cpp @@ -236,7 +236,7 @@ int KX_LightObject::py_setattro(PyObject *attr, PyObject *pyvalue) } } - if (PyFloat_Check(pyvalue)) + if (PyFloat_Check(pyvalue) || PyInt_Check(pyvalue)) { float value = PyFloat_AsDouble(pyvalue); if (!strcmp(attr_str, "energy")) @@ -306,10 +306,22 @@ PyMethodDef KX_LightObject::Methods[] = { }; PyAttributeDef KX_LightObject::Attributes[] = { + KX_PYATTRIBUTE_DUMMY("layer"), + KX_PYATTRIBUTE_DUMMY("energy"), + KX_PYATTRIBUTE_DUMMY("distance"), + KX_PYATTRIBUTE_DUMMY("colour"), + KX_PYATTRIBUTE_DUMMY("color"), + KX_PYATTRIBUTE_DUMMY("lin_attenuation"), + KX_PYATTRIBUTE_DUMMY("quad_attenuation"), + KX_PYATTRIBUTE_DUMMY("spotsize"), + KX_PYATTRIBUTE_DUMMY("spotblend"), + KX_PYATTRIBUTE_DUMMY("SPOT"), + KX_PYATTRIBUTE_DUMMY("SUN"), + KX_PYATTRIBUTE_DUMMY("NORMAL"), + KX_PYATTRIBUTE_DUMMY("type"), { NULL } //Sentinel }; - PyTypeObject KX_LightObject::Type = { PyObject_HEAD_INIT(NULL) 0, diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index 72a0381e8dc..4afc6d6f1b8 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -343,7 +343,7 @@ PyObject* KX_MouseFocusSensor::py_getattro(PyObject *attr) { const char KX_MouseFocusSensor::GetHitObject_doc[] = "getHitObject()\n" -"\tReturns the name of the object that was hit by this ray.\n"; +"\tReturns the object that was hit by this ray.\n"; PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self) { if (m_hitObject) @@ -374,7 +374,7 @@ PyObject* KX_MouseFocusSensor::PyGetRayDirection(PyObject* self) 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"; +"\tReturns the normal (in worldcoordinates) at the point of collision where the object was hit by this ray.\n"; PyObject* KX_MouseFocusSensor::PyGetHitNormal(PyObject* self) { return PyObjectFrom(m_hitNormal); diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp index 6f74c3ed3f9..39eb6225864 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.cpp +++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp @@ -78,6 +78,17 @@ PyMethodDef KX_PolyProxy::Methods[] = { }; PyAttributeDef KX_PolyProxy::Attributes[] = { + /* All dummy's so they come up in a dir() */ + KX_PYATTRIBUTE_DUMMY("matname"), + KX_PYATTRIBUTE_DUMMY("texture"), + KX_PYATTRIBUTE_DUMMY("material"), + KX_PYATTRIBUTE_DUMMY("matid"), + KX_PYATTRIBUTE_DUMMY("v1"), + KX_PYATTRIBUTE_DUMMY("v2"), + KX_PYATTRIBUTE_DUMMY("v3"), + KX_PYATTRIBUTE_DUMMY("v4"), + KX_PYATTRIBUTE_DUMMY("visible"), + KX_PYATTRIBUTE_DUMMY("collide"), { NULL } //Sentinel }; diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 9929e66c3a4..9a6565d7627 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1099,9 +1099,9 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, KX_INPUT_ACTIVE, SCA_InputEvent::KX_ACTIVE); KX_MACRO_addTypesToDict(d, KX_INPUT_JUST_RELEASED, SCA_InputEvent::KX_JUSTRELEASED); - KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_LEFT, SCA_InputEvent::KX_LEFTMOUSE); - KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_MIDDLE, SCA_InputEvent::KX_MIDDLEMOUSE); - KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_RIGHT, SCA_InputEvent::KX_RIGHTMOUSE); + KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_LEFT, SCA_IInputDevice::KX_LEFTMOUSE); + KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_MIDDLE, SCA_IInputDevice::KX_MIDDLEMOUSE); + KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_RIGHT, SCA_IInputDevice::KX_RIGHTMOUSE); // Check for errors if (PyErr_Occurred()) 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 diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp index 8c8291ef791..f3e9bbf86b1 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.cpp +++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp @@ -79,6 +79,30 @@ PyMethodDef KX_VertexProxy::Methods[] = { }; PyAttributeDef KX_VertexProxy::Attributes[] = { + + KX_PYATTRIBUTE_DUMMY("x"), + KX_PYATTRIBUTE_DUMMY("y"), + KX_PYATTRIBUTE_DUMMY("z"), + + KX_PYATTRIBUTE_DUMMY("r"), + KX_PYATTRIBUTE_DUMMY("g"), + KX_PYATTRIBUTE_DUMMY("b"), + KX_PYATTRIBUTE_DUMMY("a"), + + KX_PYATTRIBUTE_DUMMY("u"), + KX_PYATTRIBUTE_DUMMY("v"), + + KX_PYATTRIBUTE_DUMMY("u2"), + KX_PYATTRIBUTE_DUMMY("v2"), + + KX_PYATTRIBUTE_DUMMY("XYZ"), + KX_PYATTRIBUTE_DUMMY("UV"), + + KX_PYATTRIBUTE_DUMMY("color"), + KX_PYATTRIBUTE_DUMMY("colour"), + + KX_PYATTRIBUTE_DUMMY("normal"), + { NULL } //Sentinel }; diff --git a/source/gameengine/PyDoc/bge_api_validate_py.txt b/source/gameengine/PyDoc/bge_api_validate_py.txt new file mode 100644 index 00000000000..e003f29831b --- /dev/null +++ b/source/gameengine/PyDoc/bge_api_validate_py.txt @@ -0,0 +1,66 @@ +#~ 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; version 2 of the License. + +#~ 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. + +# This script must run from a logic brick so it has access to the game engine api +# it assumes the root blender source directory is the current working directory +# +# Currently it only prints missing modules and methods (not attributes) + + +BGE_API_DOC_PATH = 'source/gameengine/PyDoc' + +type_members = {} + +for type_name in dir(GameTypes): + if type_name.startswith('__'): + continue + + type_object = getattr(GameTypes, type_name) + + members = [] + type_members[type_object.__name__] = members + + for member in type_object.__dict__.keys(): + if member.startswith('__'): + continue + + # print type_object.__name__ + '.' + k + members.append(member) + +import sys, os + +doc_dir= os.path.join(os.getcwd(), BGE_API_DOC_PATH) + +if doc_dir not in sys.path: + sys.path.append(doc_dir) + +for type_name in sorted(type_members.keys()): + members = type_members[type_name] + + try: + mod = __import__(type_name) + print "type: %s" % type_name + except: + print "missing: %s - %s" % (type_name, str(members)) + continue + + reload(mod) # incase were editing it + + try: + type_class = getattr(mod, type_name) + except: + print "missing class: %s.%s - %s" % (type_name, type_name, str(members)) + continue + + for member in sorted(members): + try: + getattr(type_class, member) + print "\tfound: %s.%s" % (type_name, member) + except: + print "\tmissing: %s.%s" % (type_name, member) -- 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') 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 885fa49aa4cd49a552bfe6210e3cb4701c4a5d04 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Apr 2009 06:23:45 +0000 Subject: BGE Joystick Sensor - Raised limit of 2 axis to 4 axis pairs (4==8 joysticks axis pairs) - Added a new Joystick Sensor type "Single Axis", so you can detect horizontal or vertical movement, rather then just Up/Down/Left/Right - added Python attribute "axisSingle" so you can get the value from the selected axis (rather then getting it out of the axis list) - renamed Py attribute "axisPosition" to "axisValues" (was never in a release) If we need to increase the axis limit again just change JOYAXIS_MAX and the button limits. --- source/gameengine/Converter/KX_ConvertSensors.cpp | 5 + .../gameengine/GameLogic/Joystick/SCA_Joystick.cpp | 90 ++++++------------ .../gameengine/GameLogic/Joystick/SCA_Joystick.h | 41 +++----- .../GameLogic/Joystick/SCA_JoystickDefines.h | 6 ++ .../GameLogic/Joystick/SCA_JoystickEvents.cpp | 4 +- source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 103 ++++++++++++--------- source/gameengine/GameLogic/SCA_JoystickSensor.h | 4 +- source/gameengine/PyDoc/SCA_JoystickSensor.py | 14 ++- 8 files changed, 128 insertions(+), 139 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/KX_ConvertSensors.cpp b/source/gameengine/Converter/KX_ConvertSensors.cpp index c9b51807767..64cfc101751 100644 --- a/source/gameengine/Converter/KX_ConvertSensors.cpp +++ b/source/gameengine/Converter/KX_ConvertSensors.cpp @@ -708,6 +708,11 @@ void BL_ConvertSensors(struct Object* blenderobject, hatf = bjoy->hatf; joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_HAT; break; + case SENS_JOY_AXIS_SINGLE: + axis = bjoy->axis_single; + prec = bjoy->precision; + joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_AXIS_SINGLE; + break; default: printf("Error: bad case statement\n"); break; diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp index c21e5db1410..eaffd483d70 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp +++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp @@ -36,21 +36,19 @@ SCA_Joystick::SCA_Joystick(short int index) : m_joyindex(index), - m_axis10(0), - m_axis11(0), - m_axis20(0), - m_axis21(0), m_prec(3200), m_buttonnum(-2), m_axismax(-1), - m_hatdir(-2), m_buttonmax(-1), m_hatmax(-1), + m_hatdir(-2), m_isinit(0), m_istrig_axis(0), m_istrig_button(0), m_istrig_hat(0) { + for(int i=0; i m_prec? result = true: result = false; - return result; + return (pAxisTest(axis) > m_prec) ? true:false; } -bool SCA_Joystick::aRightAxisIsPositive(int axis) +bool SCA_Joystick::aAxisPairDirectionIsPositive(int axis, int dir) { - bool result; - int res = pGetAxis(axis,1); - res > m_prec? result = true: result = false; - return result; -} - -bool SCA_Joystick::aUpAxisIsPositive(int axis) -{ - bool result; - int res = pGetAxis(axis,0); - res < -m_prec? result = true : result = false; - return result; + int res; + + if (dir==JOYAXIS_UP || dir==JOYAXIS_DOWN) + res = pGetAxis(axis, 1); + else /* JOYAXIS_LEFT || JOYAXIS_RIGHT */ + res = pGetAxis(axis, 0); + + if (dir==JOYAXIS_DOWN || dir==JOYAXIS_RIGHT) + return (res > m_prec) ? true : false; + else /* JOYAXIS_UP || JOYAXIS_LEFT */ + return (res < -m_prec) ? true : false; } - -bool SCA_Joystick::aLeftAxisIsPositive(int axis) +bool SCA_Joystick::aAxisIsPositive(int axis_single) { - bool result; - int res = pGetAxis(axis,1); - res < -m_prec ? result = true : result = false; - return result; -} - - -bool SCA_Joystick::aDownAxisIsPositive(int axis) -{ - bool result; - int res = pGetAxis(axis,0); - res > m_prec ? result = true:result = false; - return result; + return abs(m_axis_array[axis_single]) > m_prec ? true:false; } bool SCA_Joystick::aAnyButtonPressIsPositive(void) @@ -255,8 +236,12 @@ bool SCA_Joystick::CreateJoystickDevice(void) /* must run after being initialized */ m_axismax = SDL_JoystickNumAxes(m_private->m_joystick); + if (m_axismax > JOYAXIS_MAX) m_axismax= JOYAXIS_MAX; /* very unlikely */ + m_buttonmax = SDL_JoystickNumButtons(m_private->m_joystick); m_hatmax = SDL_JoystickNumHats(m_private->m_joystick); + + } return true; #endif @@ -288,17 +273,8 @@ int SCA_Joystick::Connected(void) void SCA_Joystick::pFillAxes() { #ifndef DISABLE_SDL - if(m_axismax == 1){ - m_axis10 = SDL_JoystickGetAxis(m_private->m_joystick, 0); - m_axis11 = SDL_JoystickGetAxis(m_private->m_joystick, 1); - }else if(m_axismax > 1){ - m_axis10 = SDL_JoystickGetAxis(m_private->m_joystick, 0); - m_axis11 = SDL_JoystickGetAxis(m_private->m_joystick, 1); - m_axis20 = SDL_JoystickGetAxis(m_private->m_joystick, 2); - m_axis21 = SDL_JoystickGetAxis(m_private->m_joystick, 3); - }else{ - m_axis10 = m_axis11 = m_axis20 = m_axis21 = 0; - } + for(int i=0; im_joystick, i); #endif } @@ -306,10 +282,7 @@ void SCA_Joystick::pFillAxes() int SCA_Joystick::pGetAxis(int axisnum, int udlr) { #ifndef DISABLE_SDL - if(axisnum == 1 && udlr == 1)return m_axis10; //u/d - if(axisnum == 1 && udlr == 0)return m_axis11; //l/r - if(axisnum == 2 && udlr == 0)return m_axis20; //... - if(axisnum == 2 && udlr == 1)return m_axis21; + return m_axis_array[(axisnum*2)+udlr]; #endif return 0; } @@ -317,13 +290,9 @@ int SCA_Joystick::pGetAxis(int axisnum, int udlr) int SCA_Joystick::pAxisTest(int axisnum) { #ifndef DISABLE_SDL - short i1,i2; - if(axisnum == 1) { - i1 = m_axis10; i2 = m_axis11; - } - else if(axisnum == 2) { - i1 = m_axis20; i2 = m_axis21; - } + short i1= m_axis_array[(axisnum*2)]; + short i2= m_axis_array[(axisnum*2)+1]; + /* long winded way to do * return MAX2(abs(i1), abs(i2)) * avoid abs from math.h */ @@ -335,4 +304,3 @@ int SCA_Joystick::pAxisTest(int axisnum) return 0; #endif } - diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h index 8335d5538ad..53cd65cd495 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h +++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h @@ -55,10 +55,8 @@ class SCA_Joystick /* *support for 2 axes */ - - int m_axis10,m_axis11; - int m_axis20,m_axis21; - + int m_axis_array[JOYAXIS_MAX]; + /* * Precision or range of the axes */ @@ -120,7 +118,10 @@ class SCA_Joystick void OnButtonUp(SDL_Event *sdl_event); void OnButtonDown(SDL_Event *sdl_event); void OnNothing(SDL_Event *sdl_event); +#if 0 /* not used yet */ void OnBallMotion(SDL_Event *sdl_event){} +#endif + #endif /* * Open the joystick @@ -139,12 +140,12 @@ class SCA_Joystick void pFillButtons(void); /* - * returns m_axis10,m_axis11... + * returns m_axis_array */ int pAxisTest(int axisnum); /* - * returns m_axis10,m_axis11... + * returns m_axis_array */ int pGetAxis(int axisnum, int udlr); @@ -166,11 +167,9 @@ public: /* */ - bool aAnyAxisIsPositive(int axis); - bool aUpAxisIsPositive(int axis); - bool aDownAxisIsPositive(int axis); - bool aLeftAxisIsPositive(int axis); - bool aRightAxisIsPositive(int axis); + bool aAxisPairIsPositive(int axis); + bool aAxisPairDirectionIsPositive(int axis, int dir); /* function assumes joysticks are in axis pairs */ + bool aAxisIsPositive(int axis_single); /* check a single axis only */ bool aAnyButtonPressIsPositive(void); bool aAnyButtonReleaseIsPositive(void); @@ -184,24 +183,10 @@ public: void cSetPrecision(int val); - int GetAxis10(void){ - - return m_axis10; - - } - - int GetAxis11(void){ - return m_axis11; - } - - int GetAxis20(void){ - return m_axis20; + int GetAxisPosition(int index){ + return m_axis_array[index]; } - - int GetAxis21(void){ - return m_axis21; - } - + int GetButton(void){ return m_buttonnum; } diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h index 73ffe1406d9..42fed51b19f 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h +++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h @@ -39,5 +39,11 @@ #endif #define JOYINDEX_MAX 8 +#define JOYAXIS_MAX 8 + +#define JOYAXIS_RIGHT 0 +#define JOYAXIS_UP 1 +#define JOYAXIS_DOWN 3 +#define JOYAXIS_LEFT 2 #endif diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp index 73ca288861d..8e190060e95 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp +++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp @@ -68,7 +68,7 @@ void SCA_Joystick::OnButtonUp(SDL_Event* sdl_event) void SCA_Joystick::OnButtonDown(SDL_Event* sdl_event) { - if(sdl_event->jbutton.button >= 0 || sdl_event->jbutton.button <= m_buttonmax) + if(sdl_event->jbutton.button <= m_buttonmax) /* unsigned int so always above 0 */ { m_istrig_button = 1; m_buttonnum = sdl_event->jbutton.button; @@ -111,9 +111,11 @@ void SCA_Joystick::HandleEvents(void) case SDL_JOYBUTTONDOWN: SCA_Joystick::m_instance[sdl_event.jbutton.which]->OnButtonDown(&sdl_event); break; +#if 0 /* Not used yet */ case SDL_JOYBALLMOTION: SCA_Joystick::m_instance[sdl_event.jball.which]->OnBallMotion(&sdl_event); break; +#endif default: printf("SCA_Joystick::HandleEvents, Unknown SDL event, this should not happen\n"); break; diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 2744d7f6609..1290b7c96ed 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -117,11 +117,15 @@ bool SCA_JoystickSensor::Evaluate(CValue* event) case KX_JOYSENSORMODE_AXIS: { /* what is what! - m_axisf == 0 == right + m_axisf == JOYAXIS_RIGHT, JOYAXIS_UP, JOYAXIS_DOWN, JOYAXIS_LEFT m_axisf == 1 == up m_axisf == 2 == left m_axisf == 3 == down - numberof== m_axis -- max 2 + + numberof== m_axis (1-4), range is half of JOYAXIS_MAX since + it assumes the axis joysticks are axis parirs (0,1), (2,3), etc + also note that this starts at 1 where functions its used + with expect a zero index. */ if (!js->IsTrigAxis() && !reset) /* No events from SDL? - dont bother */ @@ -129,18 +133,7 @@ bool SCA_JoystickSensor::Evaluate(CValue* event) js->cSetPrecision(m_precision); if (m_bAllEvents) { - if(js->aAnyAxisIsPositive(m_axis)){ - m_istrig = 1; - result = true; - }else{ - if(m_istrig){ - m_istrig = 0; - result = true; - } - } - } - else if(m_axisf == 1){ - if(js->aUpAxisIsPositive(m_axis)){ + if(js->aAxisPairIsPositive(m_axis-1)){ /* use zero based axis index internally */ m_istrig = 1; result = true; }else{ @@ -150,8 +143,8 @@ bool SCA_JoystickSensor::Evaluate(CValue* event) } } } - else if(m_axisf == 3){ - if(js->aDownAxisIsPositive(m_axis)){ + else { + if(js->aAxisPairDirectionIsPositive(m_axis-1, m_axisf)){ /* use zero based axis index internally */ m_istrig = 1; result = true; }else{ @@ -161,30 +154,28 @@ bool SCA_JoystickSensor::Evaluate(CValue* event) } } } - else if(m_axisf == 2){ - if(js->aLeftAxisIsPositive(m_axis)){ - m_istrig = 1; - result = true; - }else{ - if(m_istrig){ - m_istrig = 0; - result = true; - } - } - } - else if(m_axisf == 0){ - if(js->aRightAxisIsPositive(m_axis)){ - m_istrig = 1; + break; + } + case KX_JOYSENSORMODE_AXIS_SINGLE: + { + /* Like KX_JOYSENSORMODE_AXIS but dont pair up axis */ + if (!js->IsTrigAxis() && !reset) /* No events from SDL? - dont bother */ + return false; + + /* No need for 'm_bAllEvents' check here since were only checking 1 axis */ + js->cSetPrecision(m_precision); + if(js->aAxisIsPositive(m_axis-1)){ /* use zero based axis index internally */ + m_istrig = 1; + result = true; + }else{ + if(m_istrig){ + m_istrig = 0; result = true; - }else{ - if(m_istrig){ - m_istrig = 0; - result = true; - } } } break; } + case KX_JOYSENSORMODE_BUTTON: { /* what is what! @@ -333,13 +324,13 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = { KX_PYATTRIBUTE_INT_RW("button",0,100,false,SCA_JoystickSensor,m_button), 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), - KX_PYATTRIBUTE_RO_FUNCTION("axisPosition", SCA_JoystickSensor, pyattr_get_axis_position), + KX_PYATTRIBUTE_RO_FUNCTION("axisValues", SCA_JoystickSensor, pyattr_get_axis_values), + KX_PYATTRIBUTE_RO_FUNCTION("axisSingle", SCA_JoystickSensor, pyattr_get_axis_single), KX_PYATTRIBUTE_RO_FUNCTION("numAxis", SCA_JoystickSensor, pyattr_get_num_axis), KX_PYATTRIBUTE_RO_FUNCTION("numButtons", SCA_JoystickSensor, pyattr_get_num_buttons), KX_PYATTRIBUTE_RO_FUNCTION("numHats", SCA_JoystickSensor, pyattr_get_num_hats), KX_PYATTRIBUTE_RO_FUNCTION("connected", SCA_JoystickSensor, pyattr_get_connected), - { NULL } //Sentinel }; @@ -420,10 +411,15 @@ const char SCA_JoystickSensor::GetAxisValue_doc[] = 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()); - else - return Py_BuildValue("[iiii]", 0, 0, 0, 0); + + int axis_index= joy->GetNumberOfAxes(); + PyObject *list= PyList_New(axis_index); + + while(axis_index--) { + PyList_SET_ITEM(list, axis_index, PyInt_FromLong(joy->GetAxisPosition(axis_index))); + } + + return list; } @@ -590,13 +586,32 @@ PyObject* SCA_JoystickSensor::PyConnected( PyObject* self ) { } -PyObject* SCA_JoystickSensor::pyattr_get_axis_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +PyObject* SCA_JoystickSensor::pyattr_get_axis_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { SCA_JoystickSensor* self= static_cast(self_v); SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); - if(joy) return Py_BuildValue("[iiii]", joy->GetAxis10(), joy->GetAxis11(), joy->GetAxis20(), joy->GetAxis21()); - else return Py_BuildValue("[iiii]", 0, 0, 0, 0); + int axis_index= joy->GetNumberOfAxes(); + PyObject *list= PyList_New(axis_index); + + while(axis_index--) { + PyList_SET_ITEM(list, axis_index, PyInt_FromLong(joy->GetAxisPosition(axis_index))); + } + + return list; +} + +PyObject* SCA_JoystickSensor::pyattr_get_axis_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_JoystickSensor* self= static_cast(self_v); + SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); + + if(self->m_joymode != KX_JOYSENSORMODE_AXIS_SINGLE) { + PyErr_SetString(PyExc_TypeError, "joystick sensor is not an 'Single Axis' type"); + return NULL; + } + + return PyInt_FromLong(joy->GetAxisPosition(self->m_axis)); } PyObject* SCA_JoystickSensor::pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.h b/source/gameengine/GameLogic/SCA_JoystickSensor.h index f8a3eb8756a..cf3e7e74414 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.h +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.h @@ -93,6 +93,7 @@ class SCA_JoystickSensor :public SCA_ISensor KX_JOYSENSORMODE_AXIS, KX_JOYSENSORMODE_BUTTON, KX_JOYSENSORMODE_HAT, + KX_JOYSENSORMODE_AXIS_SINGLE, KX_JOYSENSORMODE_MAX }; bool isValid(KX_JOYSENSORMODE); @@ -148,7 +149,8 @@ public: KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,NumberOfHats); KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,Connected); - static PyObject* pyattr_get_axis_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_axis_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_axis_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_num_buttons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_num_hats(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); diff --git a/source/gameengine/PyDoc/SCA_JoystickSensor.py b/source/gameengine/PyDoc/SCA_JoystickSensor.py index e38e023143d..13b006e8dd6 100644 --- a/source/gameengine/PyDoc/SCA_JoystickSensor.py +++ b/source/gameengine/PyDoc/SCA_JoystickSensor.py @@ -8,10 +8,16 @@ class SCA_JoystickSensor(SCA_ISensor): 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 axisValues: (read-only) The state of the joysticks axis as a list of values L{numAxis} long. + 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 axisValues: list of ints + + @ivar axisSingle: (read-only) like L{axisValues} but returns a single axis value that is set by the sensor. + Only use this for "Single Axis" type sensors otherwise it will raise an error. + @type axisSingle: int + @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. -- 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/Converter/BL_ActionActuator.cpp | 9 +- .../Converter/BL_ShapeActionActuator.cpp | 8 +- source/gameengine/Expressions/PyObjectPlus.cpp | 949 +++++++++++---------- source/gameengine/Expressions/PyObjectPlus.h | 48 +- source/gameengine/GameLogic/SCA_ActuatorSensor.cpp | 16 +- source/gameengine/GameLogic/SCA_DelaySensor.cpp | 8 +- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 8 +- source/gameengine/GameLogic/SCA_ISensor.cpp | 8 +- source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 8 +- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 8 +- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 8 +- .../gameengine/GameLogic/SCA_PropertyActuator.cpp | 8 +- source/gameengine/GameLogic/SCA_PropertySensor.cpp | 10 +- .../gameengine/GameLogic/SCA_PythonController.cpp | 10 +- source/gameengine/GameLogic/SCA_RandomActuator.cpp | 8 +- source/gameengine/GameLogic/SCA_RandomSensor.cpp | 8 +- .../Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp | 8 +- .../Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp | 6 - source/gameengine/Ketsji/KX_CDActuator.cpp | 8 +- source/gameengine/Ketsji/KX_Camera.cpp | 10 +- source/gameengine/Ketsji/KX_CameraActuator.cpp | 9 +- source/gameengine/Ketsji/KX_GameActuator.cpp | 8 +- source/gameengine/Ketsji/KX_GameObject.cpp | 10 +- source/gameengine/Ketsji/KX_IpoActuator.cpp | 10 +- source/gameengine/Ketsji/KX_MeshProxy.cpp | 4 - source/gameengine/Ketsji/KX_NearSensor.cpp | 10 +- source/gameengine/Ketsji/KX_ParentActuator.cpp | 10 +- source/gameengine/Ketsji/KX_PolygonMaterial.cpp | 12 +- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 139 +-- source/gameengine/Ketsji/KX_RadarSensor.cpp | 10 +- source/gameengine/Ketsji/KX_RaySensor.cpp | 10 +- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp | 8 +- .../gameengine/Ketsji/KX_SCA_DynamicActuator.cpp | 8 +- .../Ketsji/KX_SCA_ReplaceMeshActuator.cpp | 8 +- source/gameengine/Ketsji/KX_Scene.cpp | 6 +- source/gameengine/Ketsji/KX_SceneActuator.cpp | 8 +- source/gameengine/Ketsji/KX_TouchSensor.cpp | 11 +- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 8 +- source/gameengine/Ketsji/KX_VisibilityActuator.cpp | 8 +- 39 files changed, 639 insertions(+), 812 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 9102c453a16..8d7624db5d4 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -1037,21 +1037,14 @@ PyAttributeDef BL_ActionActuator::Attributes[] = { }; PyObject* BL_ActionActuator::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int BL_ActionActuator::py_setattro(PyObject *attr, PyObject* value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } - PyObject* BL_ActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { BL_ActionActuator* self= static_cast(self_v); diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index d52cc8cfccc..32fd566983a 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -486,17 +486,11 @@ PyAttributeDef BL_ShapeActionActuator::Attributes[] = { PyObject* BL_ShapeActionActuator::py_getattro(PyObject* attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int BL_ShapeActionActuator::py_setattro(PyObject *attr, PyObject* value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } /* setStart */ diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 03afa62a6da..3148dfc2b89 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -98,6 +98,10 @@ PyMethodDef PyObjectPlus::Methods[] = { {NULL, NULL} /* Sentinel */ }; +PyAttributeDef PyObjectPlus::Attributes[] = { + {NULL} //Sentinel +}; + /*------------------------------ * PyObjectPlus Parents -- Every class, even the abstract one should have parents ------------------------------*/ @@ -136,561 +140,574 @@ int PyObjectPlus::py_setattro(PyObject *attr, PyObject* value) return 1; } -PyObject *PyObjectPlus::py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr) +PyObject *PyObjectPlus::py_get_attrdef(void *self, const PyAttributeDef *attrdef) { - char *attr_str= PyString_AsString(attr); - - const PyAttributeDef *attrdef; - for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++) + if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY) { - if (!strcmp(attr_str, attrdef->m_name)) + // fake attribute, ignore + return NULL; + } + if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION) + { + // the attribute has no field correspondance, handover processing to function. + if (attrdef->m_getFunction == NULL) + return NULL; + return (*attrdef->m_getFunction)(self, attrdef); + } + char *ptr = reinterpret_cast(self)+attrdef->m_offset; + if (attrdef->m_length > 1) + { + PyObject* resultlist = PyList_New(attrdef->m_length); + for (unsigned int i=0; im_length; i++) { - if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY) + 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_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); + 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 + Py_DECREF(resultlist); + 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_ENUM: + // enum are like int, just make sure the field size is the same + if (sizeof(int) != attrdef->m_size) { - // fake attribute, ignore return NULL; } - if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION) + // walkthrough + case KX_PYATTRIBUTE_TYPE_INT: { - // the attribute has no field correspondance, handover processing to function. - if (attrdef->m_getFunction == NULL) - return NULL; - return (*attrdef->m_getFunction)(self, attrdef); + int *val = reinterpret_cast(ptr); + return PyInt_FromLong(*val); } - char *ptr = reinterpret_cast(self)+attrdef->m_offset; - if (attrdef->m_length > 1) + case KX_PYATTRIBUTE_TYPE_FLOAT: { - PyObject* resultlist = PyList_New(attrdef->m_length); - for (unsigned 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_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); - 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 - Py_DECREF(resultlist); - return NULL; - } - } - return resultlist; + float *val = reinterpret_cast(ptr); + return PyFloat_FromDouble(*val); } - else + case KX_PYATTRIBUTE_TYPE_STRING: { - 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_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); - 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; - } + STR_String *val = reinterpret_cast(ptr); + return PyString_FromString(*val); } + default: + return NULL; } } - return NULL; } -int PyObjectPlus::py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value) +#if 0 +PyObject *PyObjectPlus::py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr) { + char *attr_str= PyString_AsString(attr); const PyAttributeDef *attrdef; + + for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++) + if (!strcmp(attr_str, attrdef->m_name)) + return py_get_attrdef(self, attrdef); + + return NULL; +} +#endif + +int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyObject *value) +{ void *undoBuffer = NULL; void *sourceBuffer = NULL; size_t bufferSize = 0; - char *attr_str= PyString_AsString(attr); - - for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++) + + char *ptr = reinterpret_cast(self)+attrdef->m_offset; + if (attrdef->m_length > 1) { - if (!strcmp(attr_str, attrdef->m_name)) + if (!PySequence_Check(value)) { - if (attrdef->m_access == KX_PYATTRIBUTE_RO || - attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY) + 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_FUNCTION: + if (attrdef->m_setFunction == NULL) { - PyErr_SetString(PyExc_AttributeError, "property is read-only"); + PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org"); return 1; } - char *ptr = reinterpret_cast(self)+attrdef->m_offset; - if (attrdef->m_length > 1) + return (*attrdef->m_setFunction)(self, attrdef, value); + case KX_PYATTRIBUTE_TYPE_BOOL: + bufferSize = sizeof(bool); + break; + case KX_PYATTRIBUTE_TYPE_SHORT: + bufferSize = sizeof(short int); + break; + case KX_PYATTRIBUTE_TYPE_ENUM: + 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) { - 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: { - case KX_PYATTRIBUTE_TYPE_FUNCTION: - if (attrdef->m_setFunction == NULL) + bool *var = reinterpret_cast(ptr); + ptr += sizeof(bool); + if (PyInt_Check(item)) + { + *var = (PyInt_AsLong(item) != 0); + } + else if (PyBool_Check(item)) { - PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org"); - return 1; + *var = (item == Py_True); + } + else + { + PyErr_SetString(PyExc_TypeError, "expected an integer or a bool"); + goto UNDO_AND_ERROR; } - return (*attrdef->m_setFunction)(self, attrdef, value); - case KX_PYATTRIBUTE_TYPE_BOOL: - bufferSize = sizeof(bool); - break; - case KX_PYATTRIBUTE_TYPE_SHORT: - bufferSize = sizeof(short int); - break; - case KX_PYATTRIBUTE_TYPE_ENUM: - 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) + case KX_PYATTRIBUTE_TYPE_SHORT: { - 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) + short int *var = reinterpret_cast(ptr); + ptr += sizeof(short int); + if (PyInt_Check(item)) { - 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: + long val = PyInt_AsLong(item); + if (attrdef->m_clamp) { - short int *var = reinterpret_cast(ptr); - ptr += sizeof(short int); - if (PyInt_Check(item)) - { - long val = PyInt_AsLong(item); - 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; - } - *var = (short int)val; - } - else - { - PyErr_SetString(PyExc_TypeError, "expected an integer"); - goto UNDO_AND_ERROR; - } - break; + if (val < attrdef->m_imin) + val = attrdef->m_imin; + else if (val > attrdef->m_imax) + val = attrdef->m_imax; } - case KX_PYATTRIBUTE_TYPE_ENUM: - // enum are equivalent to int, just make sure that the field size matches: - if (sizeof(int) != attrdef->m_size) + else if (val < attrdef->m_imin || val > attrdef->m_imax) { - PyErr_SetString(PyExc_AttributeError, "attribute size check error, report to blender.org"); + PyErr_SetString(PyExc_ValueError, "item value out of range"); goto UNDO_AND_ERROR; } - // walkthrough - case KX_PYATTRIBUTE_TYPE_INT: + *var = (short int)val; + } + else + { + PyErr_SetString(PyExc_TypeError, "expected an integer"); + goto UNDO_AND_ERROR; + } + 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); + ptr += sizeof(int); + if (PyInt_Check(item)) + { + long val = PyInt_AsLong(item); + if (attrdef->m_clamp) { - int *var = reinterpret_cast(ptr); - ptr += sizeof(int); - if (PyInt_Check(item)) - { - long val = PyInt_AsLong(item); - 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; - } - *var = (int)val; - } - else - { - PyErr_SetString(PyExc_TypeError, "expected an integer"); - goto UNDO_AND_ERROR; - } - break; + if (val < attrdef->m_imin) + val = attrdef->m_imin; + else if (val > attrdef->m_imax) + val = attrdef->m_imax; } - case KX_PYATTRIBUTE_TYPE_FLOAT: + else if (val < attrdef->m_imin || val > attrdef->m_imax) { - float *var = reinterpret_cast(ptr); - ptr += sizeof(float); - double val = PyFloat_AsDouble(item); - if (val == -1.0 && PyErr_Occurred()) - { - PyErr_SetString(PyExc_TypeError, "expected a float"); - goto UNDO_AND_ERROR; - } - else if (attrdef->m_clamp) - { - 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; + PyErr_SetString(PyExc_ValueError, "item value out of range"); + goto UNDO_AND_ERROR; } - default: - // should not happen - PyErr_SetString(PyExc_AttributeError, "attribute type check error, report to blender.org"); + *var = (int)val; + } + else + { + PyErr_SetString(PyExc_TypeError, "expected an integer"); goto UNDO_AND_ERROR; } + break; } - // no error, call check function if any - if (attrdef->m_checkFunction != NULL) + case KX_PYATTRIBUTE_TYPE_FLOAT: { - if ((*attrdef->m_checkFunction)(self, attrdef) != 0) + float *var = reinterpret_cast(ptr); + ptr += sizeof(float); + double val = PyFloat_AsDouble(item); + if (val == -1.0 && PyErr_Occurred()) { - // post check returned an error, restore values - UNDO_AND_ERROR: - if (undoBuffer) - { - memcpy(sourceBuffer, undoBuffer, bufferSize); - free(undoBuffer); - } - return 1; + PyErr_SetString(PyExc_TypeError, "expected a float"); + goto UNDO_AND_ERROR; } + else if (attrdef->m_clamp) + { + 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: + // 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_checkFunction != NULL) + { + if ((*attrdef->m_checkFunction)(self, attrdef) != 0) + { + // post check returned an error, restore values + UNDO_AND_ERROR: if (undoBuffer) + { + memcpy(sourceBuffer, undoBuffer, bufferSize); free(undoBuffer); - return 0; + } + return 1; } - else // simple attribute value + } + if (undoBuffer) + free(undoBuffer); + return 0; + } + else // simple attribute value + { + if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION) + { + if (attrdef->m_setFunction == NULL) { - if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION) + PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org"); + return 1; + } + return (*attrdef->m_setFunction)(self, attrdef, value); + } + if (attrdef->m_checkFunction != 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_ENUM: + 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) { - if (attrdef->m_setFunction == NULL) - { - PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org"); - return 1; - } - return (*attrdef->m_setFunction)(self, attrdef, value); + memcpy(undoBuffer, sourceBuffer, bufferSize); } - if (attrdef->m_checkFunction != NULL) + } + } + + 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)) { - // post check function is provided, prepare undo buffer - sourceBuffer = ptr; - switch (attrdef->m_type) + *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 (attrdef->m_clamp) { - case KX_PYATTRIBUTE_TYPE_BOOL: - bufferSize = sizeof(bool); - break; - case KX_PYATTRIBUTE_TYPE_SHORT: - bufferSize = sizeof(short); - break; - case KX_PYATTRIBUTE_TYPE_ENUM: - 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 (val < attrdef->m_imin) + val = attrdef->m_imin; + else if (val > attrdef->m_imax) + val = attrdef->m_imax; } - if (bufferSize) + else if (val < attrdef->m_imin || val > attrdef->m_imax) { - undoBuffer = malloc(bufferSize); - if (undoBuffer) - { - memcpy(undoBuffer, sourceBuffer, bufferSize); - } + PyErr_SetString(PyExc_ValueError, "value out of range"); + goto FREE_AND_ERROR; } + *var = (short int)val; } - - switch (attrdef->m_type) + else { - 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: + PyErr_SetString(PyExc_TypeError, "expected an integer"); + goto FREE_AND_ERROR; + } + 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 (attrdef->m_clamp) { - short int *var = reinterpret_cast(ptr); - if (PyInt_Check(value)) - { - long val = PyInt_AsLong(value); - 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; - } - *var = (short int)val; - } - else - { - PyErr_SetString(PyExc_TypeError, "expected an integer"); - goto FREE_AND_ERROR; - } - break; + if (val < attrdef->m_imin) + val = attrdef->m_imin; + else if (val > attrdef->m_imax) + val = attrdef->m_imax; } - case KX_PYATTRIBUTE_TYPE_ENUM: - // enum are equivalent to int, just make sure that the field size matches: - if (sizeof(int) != attrdef->m_size) + else if (val < attrdef->m_imin || val > attrdef->m_imax) { - PyErr_SetString(PyExc_AttributeError, "attribute size check error, report to blender.org"); + PyErr_SetString(PyExc_ValueError, "value out of range"); 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 (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; - } - *var = (int)val; - } - else - { - PyErr_SetString(PyExc_TypeError, "expected an integer"); - goto FREE_AND_ERROR; - } - break; - } - case KX_PYATTRIBUTE_TYPE_FLOAT: + *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); + double val = PyFloat_AsDouble(value); + if (val == -1.0 && PyErr_Occurred()) + { + PyErr_SetString(PyExc_TypeError, "expected a float"); + goto FREE_AND_ERROR; + } + else if (attrdef->m_clamp) + { + 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: + { + STR_String *var = reinterpret_cast(ptr); + if (PyString_Check(value)) + { + char *val = PyString_AsString(value); + if (attrdef->m_clamp) { - float *var = reinterpret_cast(ptr); - double val = PyFloat_AsDouble(value); - if (val == -1.0 && PyErr_Occurred()) + if (strlen(val) < attrdef->m_imin) { - PyErr_SetString(PyExc_TypeError, "expected a float"); + // can't increase the length of the string + PyErr_SetString(PyExc_ValueError, "string length too short"); goto FREE_AND_ERROR; } - else if (attrdef->m_clamp) - { - 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) + else if (strlen(val) > attrdef->m_imax) { - PyErr_SetString(PyExc_ValueError, "value out of range"); - goto FREE_AND_ERROR; - } - *var = (float)val; - break; - } - case KX_PYATTRIBUTE_TYPE_STRING: - { - STR_String *var = reinterpret_cast(ptr); - if (PyString_Check(value)) - { - char *val = PyString_AsString(value); - 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; - } + // trim the string + char c = val[attrdef->m_imax]; + val[attrdef->m_imax] = 0; *var = val; + val[attrdef->m_imax] = c; + break; } - else - { - PyErr_SetString(PyExc_TypeError, "expected a string"); - goto FREE_AND_ERROR; - } - 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; } - default: - // should not happen - PyErr_SetString(PyExc_AttributeError, "unknown attribute type, report to blender.org"); + *var = val; + } + else + { + PyErr_SetString(PyExc_TypeError, "expected a string"); goto FREE_AND_ERROR; } + break; } - // check if post processing is needed - if (attrdef->m_checkFunction != NULL) + 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_checkFunction != NULL) + { + if ((*attrdef->m_checkFunction)(self, attrdef) != 0) + { + // restore value + RESTORE_AND_ERROR: + if (undoBuffer) { - if ((*attrdef->m_checkFunction)(self, attrdef) != 0) + if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_STRING) { - // restore value - RESTORE_AND_ERROR: - 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; + // 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 0; + return 1; + } + } + if (undoBuffer) + free(undoBuffer); + return 0; +} + +#if 0 +int PyObjectPlus::py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value) +{ + const PyAttributeDef *attrdef; + char *attr_str= PyString_AsString(attr); + + for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++) + { + if (!strcmp(attr_str, 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; + } + + return py_set_attrdef(self, attrdef, value); } } return -1; } +#endif /*------------------------------ * PyObjectPlus repr -- representations diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index f178d03e131..41bf72964ce 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -99,20 +99,42 @@ static inline void Py_Fatal(const char *M) { // to be properly passed up the hierarchy. #define py_getattro_up(Parent) \ - PyObject *rvalue; \ + \ PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \ \ - if (descr == NULL) { \ - PyErr_Clear(); \ - rvalue = Parent::py_getattro(attr); \ + if(descr) { \ + if (PyCObject_Check(descr)) { \ + return py_get_attrdef((void *)this, (const PyAttributeDef*)PyCObject_AsVoidPtr(descr)); \ + } else { \ + return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); \ + } \ } else { \ - rvalue= PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); \ - } \ - \ - if (strcmp(PyString_AsString(attr), "__dict__")==0) {\ - rvalue = py_getattr_dict(rvalue, Methods, Attributes); \ + PyErr_Clear(); \ + PyObject *rvalue= Parent::py_getattro(attr); \ + \ + if (strcmp(PyString_AsString(attr), "__dict__")==0) { \ + return py_getattr_dict(rvalue, Methods, Attributes); \ + } \ + \ + return rvalue; \ } \ - return rvalue; \ + return NULL; + + +#define py_setattro_up(Parent) \ + PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \ + \ + if(descr) { \ + if (PyCObject_Check(descr)) { \ + return py_set_attrdef((void *)this, (const PyAttributeDef*)PyCObject_AsVoidPtr(descr), value); \ + } else { \ + PyErr_Format(PyExc_AttributeError, "\"%s\" cannot be set", PyString_AsString(attr)); \ + return -1; \ + } \ + } else { \ + PyErr_Clear(); \ + return Parent::py_setattro(attr, value); \ + } /** @@ -376,8 +398,14 @@ public: { return ((PyObjectPlus*) PyObj)->py_getattro(attr); } + + static PyObject* py_get_attrdef(void *self, const PyAttributeDef *attrdef); + static int py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyObject *value); + +#if 0 static PyObject *py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr); static int py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value); +#endif virtual int py_delattro(PyObject *attr); virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp index ed7aa66d04b..945d473f937 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp @@ -162,10 +162,11 @@ PyAttributeDef SCA_ActuatorSensor::Attributes[] = { }; PyObject* SCA_ActuatorSensor::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; - py_getattro_up(SCA_ISensor); /* implicit return! */ + py_getattro_up(SCA_ISensor); +} + +int SCA_ActuatorSensor::py_setattro(PyObject *attr, PyObject *value) { + py_setattro_up(SCA_ISensor); } int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*) @@ -180,13 +181,6 @@ int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*) return 1; } -int SCA_ActuatorSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_ISensor::py_setattro(attr, value); -} - /* 3. getActuator */ const char SCA_ActuatorSensor::GetActuator_doc[] = "getActuator()\n" diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp index 5082caacfd5..25161d21e72 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp +++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp @@ -179,17 +179,11 @@ PyAttributeDef SCA_DelaySensor::Attributes[] = { }; PyObject* SCA_DelaySensor::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_ISensor); } int SCA_DelaySensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_ISensor::py_setattro(attr, value); + py_setattro_up(SCA_ISensor); } diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index 45ebd874ea5..4b1f8b52bf5 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -280,18 +280,12 @@ int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef) PyObject* SCA_ILogicBrick::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(CValue); } int SCA_ILogicBrick::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return CValue::py_setattro(attr, value); + py_setattro_up(CValue); } diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index a4f493d82c8..80d42d8344d 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -462,18 +462,12 @@ PyAttributeDef SCA_ISensor::Attributes[] = { PyObject* SCA_ISensor::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_ILogicBrick); } int SCA_ISensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_ILogicBrick::py_setattro(attr, value); + py_setattro_up(SCA_ILogicBrick); } PyObject* SCA_ISensor::pyattr_get_triggered(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 1290b7c96ed..3df9b454b1d 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -336,18 +336,12 @@ PyAttributeDef SCA_JoystickSensor::Attributes[] = { PyObject* SCA_JoystickSensor::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_ISensor); } int SCA_JoystickSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_ISensor::py_setattro(attr, value); + py_setattro_up(SCA_ISensor); } diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index fc1b5be3540..3749bf2eda0 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -833,16 +833,10 @@ PyAttributeDef SCA_KeyboardSensor::Attributes[] = { PyObject* SCA_KeyboardSensor::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_ISensor); } int SCA_KeyboardSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_ISensor::py_setattro(attr, value); + py_setattro_up(SCA_ISensor); } diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index 3cd32391ce2..86e64491f6a 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -343,18 +343,12 @@ PyAttributeDef SCA_MouseSensor::Attributes[] = { PyObject* SCA_MouseSensor::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_ISensor); } int SCA_MouseSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_ISensor::py_setattro(attr, value); + py_setattro_up(SCA_ISensor); } /* eof */ diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index e1f303430ec..fa8763a3932 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -261,17 +261,11 @@ PyAttributeDef SCA_PropertyActuator::Attributes[] = { }; PyObject* SCA_PropertyActuator::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int SCA_PropertyActuator::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } /* 1. setProperty */ diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp index 659823f6fba..164e94b6597 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp +++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp @@ -353,17 +353,11 @@ PyAttributeDef SCA_PropertySensor::Attributes[] = { PyObject* SCA_PropertySensor::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; - py_getattro_up(SCA_ISensor); /* implicit return! */ + py_getattro_up(SCA_ISensor); } int SCA_PropertySensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_ISensor::py_setattro(attr, value); + py_setattro_up(SCA_ISensor); } /* 1. getType */ diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 4b9248a908f..3c2a1d09f82 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -376,20 +376,12 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) PyObject* SCA_PythonController::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; - py_getattro_up(SCA_IController); } int SCA_PythonController::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - - return SCA_IController::py_setattro(attr, value); + py_setattro_up(SCA_IController); } PyObject* SCA_PythonController::PyActivate(PyObject* self, PyObject *value) diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp index 7af116fad99..b1c0c7fec99 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp +++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp @@ -392,18 +392,12 @@ int SCA_RandomActuator::pyattr_set_seed(void *self, const struct KX_PYATTRIBUTE_ } PyObject* SCA_RandomActuator::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int SCA_RandomActuator::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } /* 1. setSeed */ diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp index bdee64430fa..fe4d88e2797 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp +++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp @@ -167,18 +167,12 @@ PyAttributeDef SCA_RandomSensor::Attributes[] = { }; PyObject* SCA_RandomSensor::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_ISensor); } int SCA_RandomSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_ISensor::py_setattro(attr, value); + py_setattro_up(SCA_ISensor); } /* 1. setSeed */ diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp index a5fd8ebab6b..72edde6ef24 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp @@ -154,17 +154,11 @@ PyAttributeDef KX_NetworkMessageActuator::Attributes[] = { }; PyObject* KX_NetworkMessageActuator::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int KX_NetworkMessageActuator::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } // Deprecated -----> diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp index 7922c341659..65600856377 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp @@ -224,16 +224,10 @@ PyAttributeDef KX_NetworkMessageSensor::Attributes[] = { }; PyObject* KX_NetworkMessageSensor::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_ISensor); } int KX_NetworkMessageSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; return SCA_ISensor::py_setattro(attr, value); } diff --git a/source/gameengine/Ketsji/KX_CDActuator.cpp b/source/gameengine/Ketsji/KX_CDActuator.cpp index 57c9d30e92e..8e889fb4129 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.cpp +++ b/source/gameengine/Ketsji/KX_CDActuator.cpp @@ -217,18 +217,12 @@ int KX_CDActuator::pyattr_setGain(void *self, const struct KX_PYATTRIBUTE_DEF *a PyObject* KX_CDActuator::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int KX_CDActuator::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index 1540db5c44f..339abb73531 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -534,20 +534,12 @@ PyParentObject KX_Camera::Parents[] = { PyObject* KX_Camera::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; - py_getattro_up(KX_GameObject); } int KX_Camera::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - - return KX_GameObject::py_setattro(attr, value); + py_setattro_up(KX_GameObject); } KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, sphereInsideFrustum, diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 526c2dc404b..4db24a6e365 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -422,18 +422,11 @@ PyAttributeDef KX_CameraActuator::Attributes[] = { }; PyObject* KX_CameraActuator::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int KX_CameraActuator::py_setattro(PyObject *attr, PyObject* value) { - int ret; - ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } /* get obj ---------------------------------------------------------- */ diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp index a2a3d486420..c9060486d44 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.cpp +++ b/source/gameengine/Ketsji/KX_GameActuator.cpp @@ -256,18 +256,12 @@ PyAttributeDef KX_GameActuator::Attributes[] = { PyObject* KX_GameActuator::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int KX_GameActuator::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index a788b12b121..af905114ee4 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1511,20 +1511,12 @@ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_ PyObject* KX_GameObject::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; - py_getattro_up(SCA_IObject); } int KX_GameObject::py_setattro(PyObject *attr, PyObject *value) // py_setattro method { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - - return SCA_IObject::py_setattro(attr, value); + py_setattro_up(SCA_IObject); } PyObject* KX_GameObject::PyApplyForce(PyObject* self, PyObject* args) diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index adb9c284828..1dc5471e77a 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -474,20 +474,12 @@ PyAttributeDef KX_IpoActuator::Attributes[] = { }; PyObject* KX_IpoActuator::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; - py_getattro_up(SCA_IActuator); } int KX_IpoActuator::py_setattro(PyObject *attr, PyObject *value) // py_setattro method { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } /* set --------------------------------------------------------------------- */ diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index d9b1cc6df23..7b58c8b288a 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -99,10 +99,6 @@ void KX_MeshProxy::SetMeshModified(bool v) PyObject* KX_MeshProxy::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; - py_getattro_up(SCA_IObject); } diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index 2debfd793c1..cd753210184 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -332,18 +332,10 @@ PyAttributeDef KX_NearSensor::Attributes[] = { PyObject* KX_NearSensor::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; - py_getattro_up(KX_TouchSensor); } int KX_NearSensor::py_setattro(PyObject*attr, PyObject* value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - - return KX_TouchSensor::py_setattro(attr, value); + py_setattro_up(KX_TouchSensor); } diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index 1baf581f8a0..32c279b2be1 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -208,19 +208,11 @@ int KX_ParentActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE PyObject* KX_ParentActuator::py_getattro(PyObject *attr) { - - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int KX_ParentActuator::py_setattro(PyObject *attr, PyObject* value) { - - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } /* Deprecated -----> */ diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index 3975189a9c2..e66d9d60db8 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -232,21 +232,13 @@ PyParentObject KX_PolygonMaterial::Parents[] = { }; PyObject* KX_PolygonMaterial::py_getattro(PyObject *attr) -{ - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; - +{ py_getattro_up(PyObjectPlus); } int KX_PolygonMaterial::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - - return PyObjectPlus::py_setattro(attr, value); + py_setattro_up(PyObjectPlus); } KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setCustomMaterial, "setCustomMaterial(material)") 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); diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp index 77cde79b54d..355ac89a926 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.cpp +++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp @@ -300,18 +300,10 @@ PyAttributeDef KX_RadarSensor::Attributes[] = { PyObject* KX_RadarSensor::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; - py_getattro_up(KX_NearSensor); } int KX_RadarSensor::py_setattro(PyObject *attr, PyObject* value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - - return KX_NearSensor::py_setattro(attr, value); + py_setattro_up(KX_NearSensor); } diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index cdcb5d74f30..42e2fdc3e14 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -446,17 +446,11 @@ PyObject* KX_RaySensor::PyGetHitNormal(PyObject* self) PyObject* KX_RaySensor::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_ISensor); } int KX_RaySensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_ISensor::py_setattro(attr, value); + py_setattro_up(SCA_ISensor); } -// <----- Deprecated \ No newline at end of file +// <----- Deprecated diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index 1dd642e0966..a59d8417f26 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -257,18 +257,12 @@ PyObject* KX_SCA_AddObjectActuator::pyattr_get_objectLastCreated(void *self, con PyObject* KX_SCA_AddObjectActuator::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int KX_SCA_AddObjectActuator::py_setattro(PyObject *attr, PyObject* value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } /* 1. setObject */ diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp index ae21209fc4e..aaa87e407ba 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp @@ -94,18 +94,12 @@ PyAttributeDef KX_SCA_DynamicActuator::Attributes[] = { PyObject* KX_SCA_DynamicActuator::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int KX_SCA_DynamicActuator::py_setattro(PyObject *attr, PyObject* value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index 0cac07b4585..9097ca6c85e 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -96,18 +96,12 @@ PyAttributeDef KX_SCA_ReplaceMeshActuator::Attributes[] = { PyObject* KX_SCA_ReplaceMeshActuator::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int KX_SCA_ReplaceMeshActuator::py_setattro(PyObject *attr, PyObject* value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } PyObject* KX_SCA_ReplaceMeshActuator::pyattr_get_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 72f2fd9827f..493df31d982 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1594,11 +1594,7 @@ PyAttributeDef KX_Scene::Attributes[] = { PyObject* KX_Scene::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; - - object = PyDict_GetItem(m_attrlist, attr); + PyObject *object = PyDict_GetItem(m_attrlist, attr); if (object) { Py_INCREF(object); diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index e1cd3d45503..1753c6570e9 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -278,18 +278,12 @@ PyAttributeDef KX_SceneActuator::Attributes[] = { PyObject* KX_SceneActuator::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int KX_SceneActuator::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } PyObject* KX_SceneActuator::pyattr_get_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index c22885f3664..70fa6326c19 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -292,20 +292,13 @@ PyAttributeDef KX_TouchSensor::Attributes[] = { }; PyObject* KX_TouchSensor::py_getattro(PyObject *attr) -{ - PyObject* object= py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; +{ py_getattro_up(SCA_ISensor); } int KX_TouchSensor::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - - return SCA_ISensor::py_setattro(attr, value); + py_setattro_up(SCA_ISensor); } /* Python API */ diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 58e17785b81..f8e2938bbe6 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -506,18 +506,12 @@ int KX_TrackToActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUT PyObject* KX_TrackToActuator::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int KX_TrackToActuator::py_setattro(PyObject *attr, PyObject* value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } /* 1. setObject */ diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp index 35edd84f994..18277245d17 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp @@ -136,18 +136,12 @@ PyAttributeDef KX_VisibilityActuator::Attributes[] = { PyObject* KX_VisibilityActuator::py_getattro(PyObject *attr) { - PyObject* object = py_getattro_self(Attributes, this, attr); - if (object != NULL) - return object; py_getattro_up(SCA_IActuator); } int KX_VisibilityActuator::py_setattro(PyObject *attr, PyObject *value) { - int ret = py_setattro_self(Attributes, this, attr, value); - if (ret >= 0) - return ret; - return SCA_IActuator::py_setattro(attr, value); + py_setattro_up(SCA_IActuator); } -- cgit v1.2.3 From 1534eca60f181dc4e4299f6bdf73a66bbdf87970 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Apr 2009 11:45:48 +0000 Subject: Updated bge_api_validate_py.txt to check for undocumented attributes All types methods and attributes are now documented (except for some types have no epydoc .py files for at all) --- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 2 +- source/gameengine/PyDoc/KX_MeshProxy.py | 3 +- source/gameengine/PyDoc/KX_VertexProxy.py | 5 +++ source/gameengine/PyDoc/SCA_RandomSensor.py | 7 ++++ source/gameengine/PyDoc/bge_api_validate_py.txt | 50 +++++++++++++++++++++++-- 5 files changed, 62 insertions(+), 5 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index f8e2938bbe6..c90ce06b916 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -469,7 +469,7 @@ PyMethodDef KX_TrackToActuator::Methods[] = { PyAttributeDef KX_TrackToActuator::Attributes[] = { KX_PYATTRIBUTE_INT_RW("time",0,1000,true,KX_TrackToActuator,m_time), - KX_PYATTRIBUTE_BOOL_RW("user3D",KX_TrackToActuator,m_allow3D), + KX_PYATTRIBUTE_BOOL_RW("use3D",KX_TrackToActuator,m_allow3D), KX_PYATTRIBUTE_RW_FUNCTION("object", KX_TrackToActuator, pyattr_get_object, pyattr_set_object), { NULL } //Sentinel diff --git a/source/gameengine/PyDoc/KX_MeshProxy.py b/source/gameengine/PyDoc/KX_MeshProxy.py index 03bc36b6ac1..c6855d3b0a5 100644 --- a/source/gameengine/PyDoc/KX_MeshProxy.py +++ b/source/gameengine/PyDoc/KX_MeshProxy.py @@ -45,7 +45,8 @@ class KX_MeshProxy: m_i += 1 mesh = obj.getMesh(m_i) - + @ivar materials: + @type materials: list of L{KX_BlenderMaterial} or L{KX_PolygonMaterial} types """ def getNumMaterials(): diff --git a/source/gameengine/PyDoc/KX_VertexProxy.py b/source/gameengine/PyDoc/KX_VertexProxy.py index 5baaf76c3d9..7ee5087b316 100644 --- a/source/gameengine/PyDoc/KX_VertexProxy.py +++ b/source/gameengine/PyDoc/KX_VertexProxy.py @@ -34,6 +34,11 @@ class KX_VertexProxy: @ivar v: The v texture coordinate of the vertex. @type v: float + @ivar u2: The second u texture coordinate of the vertex. + @type u2: float + @ivar v2: The second v texture coordinate of the vertex. + @type v2: float + @group Colour: r, g, b, a @ivar r: The red component of the vertex colour. 0.0 <= r <= 1.0 @type r: float diff --git a/source/gameengine/PyDoc/SCA_RandomSensor.py b/source/gameengine/PyDoc/SCA_RandomSensor.py index 940b8f879ff..6dc0a3c23c0 100644 --- a/source/gameengine/PyDoc/SCA_RandomSensor.py +++ b/source/gameengine/PyDoc/SCA_RandomSensor.py @@ -5,6 +5,11 @@ from SCA_ISensor import * class SCA_RandomSensor(SCA_ISensor): """ This sensor activates randomly. + + @ivar lastDraw: The seed of the random number generator. + @type lastDraw: int + @ivar seed: The seed of the random number generator. + @type seed: int """ def setSeed(seed): @@ -25,4 +30,6 @@ class SCA_RandomSensor(SCA_ISensor): def getLastDraw(): """ Returns the last random number generated. + + @rtype: integer """ diff --git a/source/gameengine/PyDoc/bge_api_validate_py.txt b/source/gameengine/PyDoc/bge_api_validate_py.txt index e003f29831b..58dfbadba15 100644 --- a/source/gameengine/PyDoc/bge_api_validate_py.txt +++ b/source/gameengine/PyDoc/bge_api_validate_py.txt @@ -15,6 +15,7 @@ BGE_API_DOC_PATH = 'source/gameengine/PyDoc' +import GameTypes type_members = {} for type_name in dir(GameTypes): @@ -40,12 +41,49 @@ doc_dir= os.path.join(os.getcwd(), BGE_API_DOC_PATH) if doc_dir not in sys.path: sys.path.append(doc_dir) + +def check_attribute(type_mame, member): + filename = os.path.join(doc_dir, type_mame + '.py') + # print filename + + file = open(filename, 'rU') + + for l in file: + l = l.strip() + + ''' + @ivar foo: blah blah + to + foo + + ''' + + if l.startswith('@ivar'): + var = l.split()[1].split(':')[0] + + if var == member: + file.close() + return True + + file.close() + return False + + + + + + +print '\n\n\nChecking Docs' + +PRINT_OK = False + for type_name in sorted(type_members.keys()): members = type_members[type_name] try: mod = __import__(type_name) - print "type: %s" % type_name + if PRINT_OK: + print "type: %s" % type_name except: print "missing: %s - %s" % (type_name, str(members)) continue @@ -61,6 +99,12 @@ for type_name in sorted(type_members.keys()): for member in sorted(members): try: getattr(type_class, member) - print "\tfound: %s.%s" % (type_name, member) + if PRINT_OK: + print "\tfound: %s.%s" % (type_name, member) except: - print "\tmissing: %s.%s" % (type_name, member) + if check_attribute(type_name, member): + if PRINT_OK: + print "\tfound attr: %s.%s" % (type_name, member) + else: + print "\tmissing: %s.%s" % (type_name, member) + -- cgit v1.2.3 From 18511c56d3cbfd0b368be61002960cc161cee526 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Apr 2009 16:00:32 +0000 Subject: BGE Python API (small changes) - Make BGE's ListValue types convert to python lists for printing since the CValue GetText() function didnt work well- printing lists as [,,,,,] for scene objects and mesh materials for eg. - Check attributes are descriptor types before casting. - py_getattr_dict use the Type dict rather then Method and Attribute array. --- source/gameengine/Expressions/ListValue.h | 6 ++++++ source/gameengine/Expressions/PyObjectPlus.cpp | 17 +++-------------- source/gameengine/Expressions/PyObjectPlus.h | 9 ++++++--- source/gameengine/Ketsji/KX_GameObject.cpp | 2 +- source/gameengine/Ketsji/KX_Scene.cpp | 2 +- 5 files changed, 17 insertions(+), 19 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/ListValue.h b/source/gameengine/Expressions/ListValue.h index f936298a8c4..1c01c2d221d 100644 --- a/source/gameengine/Expressions/ListValue.h +++ b/source/gameengine/Expressions/ListValue.h @@ -60,6 +60,12 @@ public: bool CheckEqual(CValue* first,CValue* second); virtual PyObject* py_getattro(PyObject* attr); + virtual PyObject* py_repr(void) { + PyObject *py_list= PySequence_List((PyObject *)this); + PyObject *py_string= PyObject_Repr(py_list); + Py_DECREF(py_list); + return py_string; + } KX_PYMETHOD_O(CListValue,append); KX_PYMETHOD_NOARGS(CListValue,reverse); diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 3148dfc2b89..4526f8f649b 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -115,7 +115,7 @@ PyObject *PyObjectPlus::py_getattro(PyObject* attr) PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \ if (descr == NULL) { if (strcmp(PyString_AsString(attr), "__dict__")==0) { - return py_getattr_dict(NULL, Methods, NULL); /* no Attributes yet */ + return py_getattr_dict(NULL, Type.tp_dict); /* no Attributes yet */ } PyErr_SetString(PyExc_AttributeError, "attribute not found"); return NULL; @@ -767,25 +767,14 @@ PyObject *PyObjectPlus::Py_isA(PyObject *value) // Python wrapper for isA * Other then making dir() useful the value returned from __dict__() is not useful * since every value is a Py_None * */ -PyObject *py_getattr_dict(PyObject *pydict, PyMethodDef *meth, PyAttributeDef *attrdef) +PyObject *py_getattr_dict(PyObject *pydict, PyObject *tp_dict) { 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); - } - } - + PyDict_Update(pydict, tp_dict); return pydict; } diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 41bf72964ce..d549be6ef60 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -105,15 +105,18 @@ static inline void Py_Fatal(const char *M) { if(descr) { \ if (PyCObject_Check(descr)) { \ return py_get_attrdef((void *)this, (const PyAttributeDef*)PyCObject_AsVoidPtr(descr)); \ - } else { \ + } else if (descr->ob_type->tp_descr_get) { \ return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); \ + } else { \ + fprintf(stderr, "unknown attribute type"); \ + return descr; \ } \ } else { \ PyErr_Clear(); \ PyObject *rvalue= Parent::py_getattro(attr); \ \ if (strcmp(PyString_AsString(attr), "__dict__")==0) { \ - return py_getattr_dict(rvalue, Methods, Attributes); \ + return py_getattr_dict(rvalue, Type.tp_dict); \ } \ \ return rvalue; \ @@ -434,7 +437,7 @@ public: } }; -PyObject *py_getattr_dict(PyObject *pydict, PyMethodDef *meth, PyAttributeDef *attrdef); +PyObject *py_getattr_dict(PyObject *pydict, PyObject *tp_dict); #endif // _adr_py_lib_h_ diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index af905114ee4..7f99a565769 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1486,7 +1486,7 @@ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_ { KX_GameObject* self= static_cast(self_v); PyObject *dict_str = PyString_FromString("__dict__"); - PyObject *dict= py_getattr_dict(self->SCA_IObject::py_getattro(dict_str), KX_GameObject::Methods, KX_GameObject::Attributes); + PyObject *dict= py_getattr_dict(self->SCA_IObject::py_getattro(dict_str), Type.tp_dict); Py_DECREF(dict_str); if(dict==NULL) diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 493df31d982..04d6bd75f92 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1574,7 +1574,7 @@ PyObject* KX_Scene::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF * KX_Scene* self= static_cast(self_v); /* Useually done by py_getattro_up but in this case we want to include m_attrlist dict */ PyObject *dict_str= PyString_FromString("__dict__"); - PyObject *dict= py_getattr_dict(self->PyObjectPlus::py_getattro(dict_str), KX_Scene::Methods, KX_Scene::Attributes); + PyObject *dict= py_getattr_dict(self->PyObjectPlus::py_getattro(dict_str), Type.tp_dict); Py_DECREF(dict_str); PyDict_Update(dict, self->m_attrlist); -- cgit v1.2.3 From bdfa61fbbe582bd37690ee79cfface325654b61c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Apr 2009 17:54:56 +0000 Subject: BGE api added place holder docs and CListValue docs. --- source/gameengine/PyDoc/BL_Shader.py | 228 +++++++++++++++++++++ source/gameengine/PyDoc/CListValue.py | 39 ++++ source/gameengine/PyDoc/KX_BlenderMaterial.py | 38 ++++ source/gameengine/PyDoc/KX_ConstraintWrapper.py | 28 +++ source/gameengine/PyDoc/KX_GameObject.py | 4 +- source/gameengine/PyDoc/KX_PhysicsObjectWrapper.py | 47 +++++ source/gameengine/PyDoc/KX_Scene.py | 10 +- source/gameengine/PyDoc/KX_TouchSensor.py | 4 +- source/gameengine/PyDoc/KX_VehicleWrapper.py | 158 ++++++++++++++ source/gameengine/PyDoc/bge_api_validate_py.txt | 4 +- 10 files changed, 549 insertions(+), 11 deletions(-) create mode 100644 source/gameengine/PyDoc/BL_Shader.py create mode 100644 source/gameengine/PyDoc/CListValue.py create mode 100644 source/gameengine/PyDoc/KX_BlenderMaterial.py create mode 100644 source/gameengine/PyDoc/KX_ConstraintWrapper.py create mode 100644 source/gameengine/PyDoc/KX_PhysicsObjectWrapper.py create mode 100644 source/gameengine/PyDoc/KX_VehicleWrapper.py (limited to 'source/gameengine') diff --git a/source/gameengine/PyDoc/BL_Shader.py b/source/gameengine/PyDoc/BL_Shader.py new file mode 100644 index 00000000000..182b73d437b --- /dev/null +++ b/source/gameengine/PyDoc/BL_Shader.py @@ -0,0 +1,228 @@ +class BL_Shader: # (PyObjectPlus) + """ + BL_Shader GLSL shaders. + + All placeholders have a __ prefix + """ + + def __setUniformfv(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + + def __delSource(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __getFragmentProg(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __getVertexProg(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __isValid(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setAttrib(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setNumberOfPasses(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setSampler(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setSource(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setUniform1f(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setUniform1i(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setUniform2f(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setUniform2i(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setUniform3f(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setUniform3i(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setUniform4f(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setUniform4i(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setUniformDef(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setUniformMatrix3(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setUniformMatrix4(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setUniformiv(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __validate(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ diff --git a/source/gameengine/PyDoc/CListValue.py b/source/gameengine/PyDoc/CListValue.py new file mode 100644 index 00000000000..33e77395c86 --- /dev/null +++ b/source/gameengine/PyDoc/CListValue.py @@ -0,0 +1,39 @@ +class CListValue: # (PyObjectPlus) + """ + CListValue + + This is a list like object used in the game engine internally that behaves similar to a python list in most ways. + + As well as the normal index lookup. + C{val= clist[i]} + + CListValue supports string lookups. + C{val= scene.objects["OBCube"]} + + Other operations such as C{len(clist), list(clist), clist[0:10]} are also supported. + """ + def append(val): + """ + Add an item to the list (like pythons append) + + Warning: Appending values to the list can cause crashes when the list is used internally by the game engine. + """ + + def count(val): + """ + Count the number of instances of a value in the list. + + @rtype: integer + @return: number of instances + """ + def index(val): + """ + Return the index of a value in the list. + + @rtype: integer + @return: The index of the value in the list. + """ + def reverse(val): + """ + Reverse the order of the list. + """ \ No newline at end of file diff --git a/source/gameengine/PyDoc/KX_BlenderMaterial.py b/source/gameengine/PyDoc/KX_BlenderMaterial.py new file mode 100644 index 00000000000..21417db1802 --- /dev/null +++ b/source/gameengine/PyDoc/KX_BlenderMaterial.py @@ -0,0 +1,38 @@ +class KX_BlenderMaterial: # (PyObjectPlus) + """ + KX_BlenderMaterial + + All placeholders have a __ prefix + """ + + def __getShader(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + + def __setBlending(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __getMaterialIndex(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ diff --git a/source/gameengine/PyDoc/KX_ConstraintWrapper.py b/source/gameengine/PyDoc/KX_ConstraintWrapper.py new file mode 100644 index 00000000000..5b34e1609e8 --- /dev/null +++ b/source/gameengine/PyDoc/KX_ConstraintWrapper.py @@ -0,0 +1,28 @@ +class KX_ConstraintWrapper: # (PyObjectPlus) + """ + KX_ConstraintWrapper + + All placeholders have a __ prefix + """ + def __getConstraintId(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + + def __testMethod(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index 972a15b7765..97f6dab52bf 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -328,13 +328,13 @@ class KX_GameObject: # (SCA_IObject) def getChildren(): """ Return a list of immediate children of this object. - @rtype: list + @rtype: L{CListValue} of L{KX_GameObject} @return: a list of all this objects children. """ def getChildrenRecursive(): """ Return a list of children of this object, including all their childrens children. - @rtype: list + @rtype: L{CListValue} of L{KX_GameObject} @return: a list of all this objects children recursivly. """ def getMesh(mesh): diff --git a/source/gameengine/PyDoc/KX_PhysicsObjectWrapper.py b/source/gameengine/PyDoc/KX_PhysicsObjectWrapper.py new file mode 100644 index 00000000000..2171cf4c7b6 --- /dev/null +++ b/source/gameengine/PyDoc/KX_PhysicsObjectWrapper.py @@ -0,0 +1,47 @@ +class KX_PhysicsObjectWrapper: # (PyObjectPlus) + """ + KX_PhysicsObjectWrapper + + All placeholders have a __ prefix + """ + def __setActive(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + + def __setAngularVelocity(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setLinearVelocity(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setPosition(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ diff --git a/source/gameengine/PyDoc/KX_Scene.py b/source/gameengine/PyDoc/KX_Scene.py index a9fd44ffc9a..5dcd560ee96 100644 --- a/source/gameengine/PyDoc/KX_Scene.py +++ b/source/gameengine/PyDoc/KX_Scene.py @@ -16,14 +16,14 @@ class KX_Scene: scene = GameLogic.getCurrentScene() # print all the objects in the scene - for obj in scene.getObjectList(): - print obj.getName() + for obj in scene.objects: + print obj.name # get an object named 'Cube' - obj = scene.getObjectList()["OBCube"] + obj = scene.objects["OBCube"] # get the first object in the scene. - obj = scene.getObjectList()[0] + obj = scene.objects[0] Example:: # Get the depth of an object in the camera view. @@ -40,7 +40,7 @@ class KX_Scene: @ivar name: The scene's name @type name: string @ivar objects: A list of objects in the scene. - @type objects: list [L{KX_GameObject}] + @type objects: L{CListValue} of 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/KX_TouchSensor.py b/source/gameengine/PyDoc/KX_TouchSensor.py index d7277be4c2a..f4fcbeefc62 100644 --- a/source/gameengine/PyDoc/KX_TouchSensor.py +++ b/source/gameengine/PyDoc/KX_TouchSensor.py @@ -17,7 +17,7 @@ class KX_TouchSensor(SCA_ISensor): @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 + @type objectHitList: L{CListValue} of L{KX_GameObject} """ #--The following methods are deprecated, please use properties instead. @@ -53,7 +53,7 @@ class KX_TouchSensor(SCA_ISensor): Only objects that have the requisite material/property are listed. - @rtype: list [L{KX_GameObject}] + @rtype: L{CListValue} of L{KX_GameObject} """ def getTouchMaterial(): """ diff --git a/source/gameengine/PyDoc/KX_VehicleWrapper.py b/source/gameengine/PyDoc/KX_VehicleWrapper.py new file mode 100644 index 00000000000..68240e15622 --- /dev/null +++ b/source/gameengine/PyDoc/KX_VehicleWrapper.py @@ -0,0 +1,158 @@ +class KX_VehicleWrapper: # (PyObjectPlus) + """ + KX_VehicleWrapper + + All placeholders have a __ prefix + """ + + def __addWheel(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + + def __applyBraking(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __applyEngineForce(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __getConstraintId(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __getConstraintType(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __getNumWheels(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __getWheelOrientationQuaternion(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __getWheelPosition(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __getWheelRotation(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setRollInfluence(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setSteeringValue(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setSuspensionCompression(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setSuspensionDamping(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setSuspensionStiffness(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ + def __setTyreFriction(val): + """ + TODO - Description + + @param val: the starting frame of the animation + @type val: float + + @rtype: integer + @return: TODO Description + """ diff --git a/source/gameengine/PyDoc/bge_api_validate_py.txt b/source/gameengine/PyDoc/bge_api_validate_py.txt index 58dfbadba15..0920e5d3c7d 100644 --- a/source/gameengine/PyDoc/bge_api_validate_py.txt +++ b/source/gameengine/PyDoc/bge_api_validate_py.txt @@ -85,7 +85,7 @@ for type_name in sorted(type_members.keys()): if PRINT_OK: print "type: %s" % type_name except: - print "missing: %s - %s" % (type_name, str(members)) + print "missing: %s - %s" % (type_name, str(sorted(members))) continue reload(mod) # incase were editing it @@ -93,7 +93,7 @@ for type_name in sorted(type_members.keys()): try: type_class = getattr(mod, type_name) except: - print "missing class: %s.%s - %s" % (type_name, type_name, str(members)) + print "missing class: %s.%s - %s" % (type_name, type_name, str(sorted(members))) continue for member in sorted(members): -- cgit v1.2.3 From ca1c3be3029a7a7aada686372ca1dd6ab39f0547 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Apr 2009 18:55:35 +0000 Subject: BGE Py API - Added OpenGL access to the game engine as a module so you can import BGL directly. --- source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp | 2 ++ source/gameengine/GamePlayer/ghost/GPG_Application.cpp | 1 + source/gameengine/Ketsji/CMakeLists.txt | 1 + source/gameengine/Ketsji/KX_PythonInit.cpp | 10 +++++++++- source/gameengine/Ketsji/KX_PythonInit.h | 1 + source/gameengine/Ketsji/SConscript | 5 +++++ 6 files changed, 19 insertions(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 9228798890a..1c91ad784ac 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -368,6 +368,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, initGameKeys(); initPythonConstraintBinding(); initMathutils(); + initBGL(); #ifdef WITH_FFMPEG initVideoTexture(); #endif @@ -666,6 +667,7 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, initGameKeys(); initPythonConstraintBinding(); initMathutils(); + initBGL(); #ifdef WITH_FFMPEG initVideoTexture(); #endif diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index 6d846610109..3432d498981 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -689,6 +689,7 @@ bool GPG_Application::startEngine(void) initGameKeys(); initPythonConstraintBinding(); initMathutils(); + initBGL(); #ifdef WITH_FFMPEG initVideoTexture(); #endif diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index 3bd05ca5137..d45d5345678 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -36,6 +36,7 @@ SET(SRC ../../../source/blender/python/api2_2x/quat.c ../../../source/blender/python/api2_2x/vector.c ../../../source/blender/python/api2_2x/bpy_internal_import.c + ../../../source/blender/python/api2_2x/BGL.c ) SET(INC diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 9a6565d7627..15397085b4a 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -78,6 +78,7 @@ extern "C" { #include "Mathutils.h" // Blender.Mathutils module copied here so the blenderlayer can use. #include "bpy_internal_import.h" /* from the blender python api, but we want to import text too! */ + #include "BGL.h" } #include "marshal.h" /* python header for loading/saving dicts */ @@ -1168,7 +1169,7 @@ PyObject *KXpy_import(PyObject *self, PyObject *args) /* quick hack for GamePython modules TODO: register builtin modules properly by ExtendInittab */ if (!strcmp(name, "GameLogic") || !strcmp(name, "GameKeys") || !strcmp(name, "PhysicsConstraints") || - !strcmp(name, "Rasterizer") || !strcmp(name, "Mathutils")) { + !strcmp(name, "Rasterizer") || !strcmp(name, "Mathutils") || !strcmp(name, "BGL")) { return PyImport_ImportModuleEx(name, globals, locals, fromlist); } @@ -1357,6 +1358,8 @@ static void clearGameModules() clearModule(modules, "Rasterizer"); clearModule(modules, "GameKeys"); clearModule(modules, "VideoTexture"); + clearModule(modules, "Mathutils"); + clearModule(modules, "BGL"); PyErr_Clear(); // incase some of these were alredy removed. } @@ -1596,6 +1599,11 @@ PyObject* initMathutils() return Mathutils_Init("Mathutils"); // Use as a top level module in BGE } +PyObject* initBGL() +{ + return BGL_Init("BGL"); // Use as a top level module in BGE +} + void KX_SetActiveScene(class KX_Scene* scene) { gp_KetsjiScene = scene; diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h index b709cee2f37..97d23fe391c 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.h +++ b/source/gameengine/Ketsji/KX_PythonInit.h @@ -45,6 +45,7 @@ PyObject* initGameKeys(); PyObject* initRasterizer(class RAS_IRasterizer* rasty,class RAS_ICanvas* canvas); PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level, struct Main *maggie); PyObject* initMathutils(); +PyObject* initBGL(); PyObject* initVideoTexture(void); void exitGamePlayerPythonScripting(); PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level, struct Main *maggie); diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript index 68e5c62ab6c..61e722fb957 100644 --- a/source/gameengine/Ketsji/SConscript +++ b/source/gameengine/Ketsji/SConscript @@ -22,6 +22,11 @@ sources.extend([\ '#source/blender/python/api2_2x/bpy_internal_import.c' ]) + +sources.extend([\ + '#source/blender/python/api2_2x/BGL.c' +]) + incs = '. #source/blender/python/api2_2x' # Only for Mathutils! and bpy_internal_import.h, be very careful incs += ' #source/kernel/gen_system #intern/string #intern/guardedalloc' -- cgit v1.2.3 From d012a222a21d4a2fb7f8879484755b89f80ecbb2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Apr 2009 19:21:48 +0000 Subject: Some users have odd joysticks with more then 8 axises, increased to 16 (so 4 joysticks) Ideally there would be no limit but I dont think its worth the effort. Also had a bug in last commit for the pytyhon api's "axisSingle" attribute, UI index starts at 1 not zero. --- source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h | 2 +- source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h index 42fed51b19f..636c4dd5a42 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h +++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h @@ -39,7 +39,7 @@ #endif #define JOYINDEX_MAX 8 -#define JOYAXIS_MAX 8 +#define JOYAXIS_MAX 16 #define JOYAXIS_RIGHT 0 #define JOYAXIS_UP 1 diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 3df9b454b1d..fa61e057b2c 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -605,7 +605,7 @@ PyObject* SCA_JoystickSensor::pyattr_get_axis_single(void *self_v, const KX_PYAT return NULL; } - return PyInt_FromLong(joy->GetAxisPosition(self->m_axis)); + return PyInt_FromLong(joy->GetAxisPosition(self->m_axis-1)); } PyObject* SCA_JoystickSensor::pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) -- cgit v1.2.3 From 51b4145841293d4a695b7bbe88e90ebd98443fc8 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Tue, 7 Apr 2009 22:14:06 +0000 Subject: BGE Scenegraph and View frustrum culling improvement. This commit contains a number of performance improvements for the BGE in the Scenegraph (parent relation between objects in the scene) and view frustrum culling. The scenegraph improvement consists in avoiding position update if the object has not moved since last update and the removal of redundant updates and synchronization with the physics engine. The view frustrum culling improvement consists in using the DBVT broadphase facility of Bullet to build a tree of graphical objects in the scene. The elements of the tree are Aabb boxes (Aligned Axis Bounding Boxes) enclosing the objects. This provides good precision in closed and opened scenes. This new culling system is enabled by default but just in case, it can be disabled with a button in the World settings. There is no do_version in this commit but it will be added before the 2.49 release. For now you must manually enable the DBVT culling option in World settings when you open an old file. The above improvements speed up scenegraph and culling up to 5x. However, this performance improvement is only visible when you have hundreds or thousands of objects. The main interest of the DBVT tree is to allow easy occlusion culling and automatic LOD system. This will be the object of further improvements. --- .../Converter/BL_BlenderDataConversion.cpp | 67 ++++++++++-- .../Converter/KX_BlenderSceneConverter.cpp | 7 +- .../Ketsji/KX_BulletPhysicsController.cpp | 3 +- source/gameengine/Ketsji/KX_Camera.h | 12 +++ source/gameengine/Ketsji/KX_GameObject.cpp | 58 ++++++----- source/gameengine/Ketsji/KX_GameObject.h | 25 +++-- source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 48 ++++++--- source/gameengine/Ketsji/KX_Light.cpp | 2 +- source/gameengine/Ketsji/KX_MotionState.cpp | 20 ++-- source/gameengine/Ketsji/KX_MotionState.h | 1 + source/gameengine/Ketsji/KX_NearSensor.cpp | 17 ++-- source/gameengine/Ketsji/KX_RadarSensor.cpp | 5 +- .../Ketsji/KX_SG_BoneParentNodeRelationship.cpp | 7 +- .../Ketsji/KX_SG_BoneParentNodeRelationship.h | 3 +- .../gameengine/Ketsji/KX_SG_NodeRelationships.cpp | 31 ++++-- source/gameengine/Ketsji/KX_SG_NodeRelationships.h | 9 +- source/gameengine/Ketsji/KX_Scene.cpp | 103 +++++++++++++------ source/gameengine/Ketsji/KX_Scene.h | 17 ++++ .../Physics/BlOde/OdePhysicsEnvironment.h | 1 + .../Physics/Bullet/CcdGraphicController.cpp | 112 +++++++++++++++++++++ .../Physics/Bullet/CcdGraphicController.h | 74 ++++++++++++++ .../Physics/Bullet/CcdPhysicsController.cpp | 16 +++ .../Physics/Bullet/CcdPhysicsController.h | 1 + .../Physics/Bullet/CcdPhysicsEnvironment.cpp | 107 ++++++++++++++++++-- .../Physics/Bullet/CcdPhysicsEnvironment.h | 15 ++- .../Physics/Dummy/DummyPhysicsEnvironment.h | 1 + .../Physics/Sumo/SumoPhysicsEnvironment.h | 1 + .../gameengine/Physics/common/PHY_DynamicTypes.h | 35 ++++++- .../gameengine/Physics/common/PHY_IController.cpp | 39 +++++++ source/gameengine/Physics/common/PHY_IController.h | 53 ++++++++++ .../Physics/common/PHY_IGraphicController.cpp | 39 +++++++ .../Physics/common/PHY_IGraphicController.h | 56 +++++++++++ .../gameengine/Physics/common/PHY_IMotionState.h | 2 + .../Physics/common/PHY_IPhysicsController.h | 8 +- .../Physics/common/PHY_IPhysicsEnvironment.h | 2 + source/gameengine/Rasterizer/RAS_BucketManager.cpp | 8 ++ source/gameengine/Rasterizer/RAS_FramingManager.h | 7 ++ source/gameengine/Rasterizer/RAS_MaterialBucket.h | 1 + source/gameengine/SceneGraph/SG_BBox.cpp | 7 ++ source/gameengine/SceneGraph/SG_BBox.h | 2 + source/gameengine/SceneGraph/SG_IObject.cpp | 2 + source/gameengine/SceneGraph/SG_IObject.h | 30 ++++++ source/gameengine/SceneGraph/SG_Node.cpp | 7 +- source/gameengine/SceneGraph/SG_Node.h | 3 +- source/gameengine/SceneGraph/SG_ParentRelation.h | 3 +- source/gameengine/SceneGraph/SG_Spatial.cpp | 19 +++- source/gameengine/SceneGraph/SG_Spatial.h | 13 ++- 47 files changed, 953 insertions(+), 146 deletions(-) create mode 100644 source/gameengine/Physics/Bullet/CcdGraphicController.cpp create mode 100644 source/gameengine/Physics/Bullet/CcdGraphicController.h create mode 100644 source/gameengine/Physics/common/PHY_IController.cpp create mode 100644 source/gameengine/Physics/common/PHY_IController.h create mode 100644 source/gameengine/Physics/common/PHY_IGraphicController.cpp create mode 100644 source/gameengine/Physics/common/PHY_IGraphicController.h (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index d74243b0eb0..3c77f122758 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -164,7 +164,11 @@ extern "C" { // defines USE_ODE to choose physics engine #include "KX_ConvertPhysicsObject.h" - +#ifdef USE_BULLET +#include "CcdPhysicsEnvironment.h" +#include "CcdGraphicController.h" +#endif +#include "KX_MotionState.h" // This file defines relationships between parents and children // in the game engine. @@ -1265,8 +1269,37 @@ static void my_get_local_bounds(Object *ob, float *center, float *size) ////////////////////////////////////////////////////// - - +void BL_CreateGraphicObjectNew(KX_GameObject* gameobj, + const MT_Point3& localAabbMin, + const MT_Point3& localAabbMax, + KX_Scene* kxscene, + bool isActive, + e_PhysicsEngine physics_engine) +{ + if (gameobj->GetMeshCount() > 0) + { + switch (physics_engine) + { +#ifdef USE_BULLET + case UseBullet: + { + CcdPhysicsEnvironment* env = (CcdPhysicsEnvironment*)kxscene->GetPhysicsEnvironment(); + assert(env); + PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode()); + CcdGraphicController* ctrl = new CcdGraphicController(env, motionstate); + gameobj->SetGraphicController(ctrl); + ctrl->setNewClientInfo(gameobj->getClientInfo()); + ctrl->setLocalAabb(localAabbMin, localAabbMax); + if (isActive) + env->addCcdGraphicController(ctrl); + } + break; +#endif + default: + break; + } + } +} void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj, struct Object* blenderobject, @@ -1859,8 +1892,10 @@ void BL_ConvertBlenderObjects(struct Main* maggie, if (blenderscene->world) { kxscene->SetActivityCulling( (blenderscene->world->mode & WO_ACTIVITY_CULLING) != 0); kxscene->SetActivityCullingRadius(blenderscene->world->activityBoxRadius); + kxscene->SetDbvtCameraCulling((blenderscene->world->mode & WO_DBVT_CAMERA_CULLING) != 0); } else { kxscene->SetActivityCulling(false); + kxscene->SetDbvtCameraCulling(false); } int activeLayerBitInfo = blenderscene->lay; @@ -1954,7 +1989,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, gameobj->NodeSetLocalPosition(pos); gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz)); gameobj->NodeSetLocalScale(scale); - gameobj->NodeUpdateGS(0,true); + gameobj->NodeUpdateGS(0); BL_ConvertIpos(blenderobject,gameobj,converter); BL_ConvertMaterialIpos(blenderobject, gameobj, converter); @@ -2037,7 +2072,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, objectlist->Add(gameobj->AddRef()); //tf.Add(gameobj->GetSGNode()); - gameobj->NodeUpdateGS(0,true); + gameobj->NodeUpdateGS(0); gameobj->AddMeshUser(); } @@ -2148,7 +2183,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, gameobj->NodeSetLocalPosition(pos); gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz)); gameobj->NodeSetLocalScale(scale); - gameobj->NodeUpdateGS(0,true); + gameobj->NodeUpdateGS(0); BL_ConvertIpos(blenderobject,gameobj,converter); BL_ConvertMaterialIpos(blenderobject,gameobj, converter); @@ -2226,7 +2261,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, objectlist->Add(gameobj->AddRef()); //tf.Add(gameobj->GetSGNode()); - gameobj->NodeUpdateGS(0,true); + gameobj->NodeUpdateGS(0); gameobj->AddMeshUser(); } else @@ -2377,7 +2412,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, if (gameobj->GetSGNode()->GetSGParent() == 0) { parentlist->Add(gameobj->AddRef()); - gameobj->NodeUpdateGS(0,true); + gameobj->NodeUpdateGS(0); } } @@ -2414,6 +2449,22 @@ void BL_ConvertBlenderObjects(struct Main* maggie, BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,layerMask,physics_engine,converter,processCompoundChildren); } + // create graphic controller for culling + if (kxscene->GetDbvtCameraCulling()) + { + for (i=0; iGetCount();i++) + { + KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i); + if (gameobj->GetMeshCount() > 0) + { + MT_Point3 box[2]; + gameobj->GetSGNode()->BBox().getmm(box, MT_Transform::Identity()); + // box[0] is the min, box[1] is the max + bool isactive = objectlist->SearchValue(gameobj); + BL_CreateGraphicObjectNew(gameobj,box[0],box[1],kxscene,isactive,physics_engine); + } + } + } //set ini linearVel and int angularVel //rcruiz if (converter->addInitFromFrame) diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 97a0819147c..b0c676a410d 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -267,9 +267,11 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename, Scene *blenderscene = GetBlenderSceneForName(scenename); e_PhysicsEngine physics_engine = UseBullet; + bool useDbvtCulling = false; // hook for registration function during conversion. m_currentScene = destinationscene; destinationscene->SetSceneConverter(this); + SG_SetActiveStage(SG_STAGE_CONVERTER); if (blenderscene) { @@ -281,6 +283,7 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename, case WOPHY_BULLET: { physics_engine = UseBullet; + useDbvtCulling = (blenderscene->world->mode & WO_DBVT_CAMERA_CULLING) != 0; break; } @@ -313,7 +316,7 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename, #ifdef USE_BULLET case UseBullet: { - CcdPhysicsEnvironment* ccdPhysEnv = new CcdPhysicsEnvironment(); + CcdPhysicsEnvironment* ccdPhysEnv = new CcdPhysicsEnvironment(useDbvtCulling); ccdPhysEnv->setDebugDrawer(new BlenderDebugDraw()); ccdPhysEnv->setDeactivationLinearTreshold(0.8f); // default, can be overridden by Python ccdPhysEnv->setDeactivationAngularTreshold(1.0f); // default, can be overridden by Python @@ -806,7 +809,7 @@ void KX_BlenderSceneConverter::resetNoneDynamicObjectToIpo(){ gameobj->NodeSetLocalPosition(pos); gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz)); gameobj->NodeSetLocalScale(scale); - gameobj->NodeUpdateGS(0,true); + gameobj->NodeUpdateGS(0); } } } diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp index 062e9f7df50..435b2b5db19 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp @@ -417,13 +417,14 @@ void KX_BulletPhysicsController::SetSumoTransform(bool nondynaonly) { if (!nondynaonly) { + /* btTransform worldTrans; if (GetRigidBody()) { GetRigidBody()->getMotionState()->getWorldTransform(worldTrans); GetRigidBody()->setCenterOfMassTransform(worldTrans); } - + */ /* scaling? if (m_bDyna) diff --git a/source/gameengine/Ketsji/KX_Camera.h b/source/gameengine/Ketsji/KX_Camera.h index 6ed21506372..4accd4bc2f1 100644 --- a/source/gameengine/Ketsji/KX_Camera.h +++ b/source/gameengine/Ketsji/KX_Camera.h @@ -45,6 +45,7 @@ class KX_Camera : public KX_GameObject { Py_Header; protected: + friend class KX_Scene; /** Camera parameters (clips distances, focal lenght). These * params are closely tied to Blender. In the gameengine, only the * projection and modelview matrices are relevant. There's a @@ -67,6 +68,7 @@ protected: * Storage for the projection matrix that is passed to the * rasterizer. */ MT_Matrix4x4 m_projection_matrix; + //MT_Matrix4x4 m_projection_matrix1; /** * Storage for the modelview matrix that is passed to the @@ -119,6 +121,16 @@ protected: * Extracts the bound sphere of the view frustum. */ void ExtractFrustumSphere(); + /** + * return the clip plane + */ + MT_Vector4 *GetNormalizedClipPlanes() + { + ExtractClipPlanes(); + NormalizeClipPlanes(); + return m_planes; + } + public: enum { INSIDE, INTERSECT, OUTSIDE } ; diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 7f99a565769..339a955702a 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -55,6 +55,7 @@ typedef unsigned long uint_ptr; #include // printf #include "SG_Controller.h" #include "KX_IPhysicsController.h" +#include "PHY_IGraphicController.h" #include "SG_Node.h" #include "SG_Controller.h" #include "KX_ClientObjectInfo.h" @@ -91,6 +92,7 @@ KX_GameObject::KX_GameObject( m_bVisible(true), m_bCulled(true), m_pPhysicsController1(NULL), + m_pGraphicController(NULL), m_pPhysicsEnvironment(NULL), m_xray(false), m_pHitObject(NULL), @@ -132,6 +134,10 @@ KX_GameObject::~KX_GameObject() } m_pSGNode->SetSGClientObject(NULL); } + if (m_pGraphicController) + { + delete m_pGraphicController; + } } @@ -249,7 +255,7 @@ void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj) NodeSetLocalScale(scale1); NodeSetLocalPosition(MT_Point3(newpos[0],newpos[1],newpos[2])); NodeSetLocalOrientation(invori*NodeGetWorldOrientation()); - NodeUpdateGS(0.f,true); + NodeUpdateGS(0.f); // object will now be a child, it must be removed from the parent list CListValue* rootlist = scene->GetRootParentList(); if (rootlist->RemoveValue(this)) @@ -269,6 +275,7 @@ void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj) rootobj->m_pPhysicsController1->AddCompoundChild(m_pPhysicsController1); } } + // graphically, the object hasn't change place, no need to update m_pGraphicController } } @@ -286,7 +293,7 @@ void KX_GameObject::RemoveParent(KX_Scene *scene) // Remove us from our parent GetSGNode()->DisconnectFromParent(); - NodeUpdateGS(0.f,true); + NodeUpdateGS(0.f); // the object is now a root object, add it to the parentlist CListValue* rootlist = scene->GetRootParentList(); if (!rootlist->SearchValue(this)) @@ -303,12 +310,14 @@ void KX_GameObject::RemoveParent(KX_Scene *scene) } m_pPhysicsController1->RestoreDynamics(); } + // graphically, the object hasn't change place, no need to update m_pGraphicController } } void KX_GameObject::ProcessReplica(KX_GameObject* replica) { replica->m_pPhysicsController1 = NULL; + replica->m_pGraphicController = NULL; replica->m_pSGNode = NULL; replica->m_pClient_info = new KX_ClientObjectInfo(*m_pClient_info); replica->m_pClient_info->m_gameobject = replica; @@ -437,22 +446,18 @@ void KX_GameObject::RemoveMeshes() m_meshes.clear(); } - - -void KX_GameObject::UpdateNonDynas() +void KX_GameObject::UpdateTransform() { if (m_pPhysicsController1) - { + // only update the transform of static object, dynamic object are handled differently + // note that for bullet, this does not even update the transform of static object + // but merely sets there collision flag to "kinematic" because the synchronization is + // done differently during physics simulation m_pPhysicsController1->SetSumoTransform(true); - } -} + if (m_pGraphicController) + // update the culling tree + m_pGraphicController->SetGraphicTransform(); - - -void KX_GameObject::UpdateTransform() -{ - if (m_pPhysicsController1) - m_pPhysicsController1->SetSumoTransform(false); } void KX_GameObject::UpdateTransformFunc(SG_IObject* node, void* gameobj, void* scene) @@ -832,6 +837,7 @@ void KX_GameObject::NodeSetLocalPosition(const MT_Point3& trans) } GetSGNode()->SetLocalPosition(trans); + } @@ -911,7 +917,7 @@ void KX_GameObject::NodeSetWorldPosition(const MT_Point3& trans) } -void KX_GameObject::NodeUpdateGS(double time,bool bInitiator) +void KX_GameObject::NodeUpdateGS(double time) { if (GetSGNode()) GetSGNode()->UpdateWorldData(time); @@ -1295,7 +1301,7 @@ int KX_GameObject::pyattr_set_position(void *self_v, const KX_PYATTRIBUTE_DEF *a return 1; self->NodeSetLocalPosition(pos); - self->NodeUpdateGS(0.f,true); + self->NodeUpdateGS(0.f); return 0; } @@ -1319,10 +1325,10 @@ int KX_GameObject::pyattr_set_orientation(void *self_v, const KX_PYATTRIBUTE_DEF if (PyMatTo(value, rot)) { self->NodeSetLocalOrientation(rot); - self->NodeUpdateGS(0.f,true); + self->NodeUpdateGS(0.f); return 0; } - return 1; + PyErr_Clear(); if (PySequence_Size(value) == 4) { @@ -1331,7 +1337,7 @@ int KX_GameObject::pyattr_set_orientation(void *self_v, const KX_PYATTRIBUTE_DEF { rot.setRotation(qrot); self->NodeSetLocalOrientation(rot); - self->NodeUpdateGS(0.f,true); + self->NodeUpdateGS(0.f); return 0; } return 1; @@ -1344,7 +1350,7 @@ int KX_GameObject::pyattr_set_orientation(void *self_v, const KX_PYATTRIBUTE_DEF { rot.setEuler(erot); self->NodeSetLocalOrientation(rot); - self->NodeUpdateGS(0.f,true); + self->NodeUpdateGS(0.f); return 0; } return 1; @@ -1368,7 +1374,7 @@ int KX_GameObject::pyattr_set_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *at return 1; self->NodeSetLocalScale(scale); - self->NodeUpdateGS(0.f,true); + self->NodeUpdateGS(0.f); return 0; } @@ -1929,7 +1935,7 @@ PyObject* KX_GameObject::PySetOrientation(PyObject* self, PyObject* value) if (PyObject_IsMT_Matrix(value, 3) && PyMatTo(value, matrix)) { NodeSetLocalOrientation(matrix); - NodeUpdateGS(0.f,true); + NodeUpdateGS(0.f); Py_RETURN_NONE; } @@ -1938,7 +1944,7 @@ PyObject* KX_GameObject::PySetOrientation(PyObject* self, PyObject* value) { matrix.setRotation(quat); NodeSetLocalOrientation(matrix); - NodeUpdateGS(0.f,true); + NodeUpdateGS(0.f); Py_RETURN_NONE; } return NULL; @@ -1959,7 +1965,7 @@ PyObject* KX_GameObject::PyAlignAxisToVect(PyObject* self, PyObject* args) if (fac> 1.0) fac= 1.0; AlignAxisToVect(vect,axis,fac); - NodeUpdateGS(0.f,true); + NodeUpdateGS(0.f); Py_RETURN_NONE; } } @@ -1983,7 +1989,7 @@ PyObject* KX_GameObject::PySetPosition(PyObject* self, PyObject* value) if (PyVecTo(value, pos)) { NodeSetLocalPosition(pos); - NodeUpdateGS(0.f,true); + NodeUpdateGS(0.f); Py_RETURN_NONE; } @@ -1996,7 +2002,7 @@ PyObject* KX_GameObject::PySetWorldPosition(PyObject* self, PyObject* value) if (PyVecTo(value, pos)) { NodeSetWorldPosition(pos); - NodeUpdateGS(0.f,true); + NodeUpdateGS(0.f); Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index bc6b60102d6..9c7dda5e394 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -57,6 +57,7 @@ struct KX_ClientObjectInfo; class KX_RayCast; class RAS_MeshObject; class KX_IPhysicsController; +class PHY_IGraphicController; class PHY_IPhysicsEnvironment; struct Object; @@ -88,6 +89,7 @@ protected: bool m_bCulled; KX_IPhysicsController* m_pPhysicsController1; + PHY_IGraphicController* m_pGraphicController; // used for ray casting PHY_IPhysicsEnvironment* m_pPhysicsEnvironment; STR_String m_testPropName; @@ -350,6 +352,19 @@ public: } + /** + * @return a pointer to the graphic controller owner by this class + */ + PHY_IGraphicController* GetGraphicController() + { + return m_pGraphicController; + } + + void SetGraphicController(PHY_IGraphicController* graphiccontroller) + { + m_pGraphicController = graphiccontroller; + } + /** * @section Coordinate system manipulation functions */ @@ -367,8 +382,7 @@ public: void NodeUpdateGS( - double time, - bool bInitiator + double time ); const @@ -524,13 +538,6 @@ public: static void UpdateTransformFunc(SG_IObject* node, void* gameobj, void* scene); - /** - * Only update the transform if it's a non-dynamic object - */ - void - UpdateNonDynas( - ); - /** * Function to set IPO option at start of IPO */ diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 97b4213b8bd..70ae0e4b937 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -412,7 +412,7 @@ else // Compute the number of logic frames to do each update (fixed tic bricks) - int frames =int(deltatime*m_ticrate); + int frames =int(deltatime*m_ticrate+1e-6); // if (frames>1) // printf("****************************************"); // printf("dt = %f, deltatime = %f, frames = %d\n",dt, deltatime,frames); @@ -465,12 +465,15 @@ else m_logger->StartLog(tc_network, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_NETWORK); scene->GetNetworkScene()->proceed(m_frameTime); - m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); - scene->UpdateParents(m_frameTime); + //m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); + //SG_SetActiveStage(SG_STAGE_NETWORK_UPDATE); + //scene->UpdateParents(m_frameTime); m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_PHYSICS1); // set Python hooks for each scene PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment()); KX_SetActiveScene(scene); @@ -479,31 +482,37 @@ else // Update scenegraph after physics step. This maps physics calculations // into node positions. - m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); - scene->UpdateParents(m_frameTime); + //m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); + //SG_SetActiveStage(SG_STAGE_PHYSICS1_UPDATE); + //scene->UpdateParents(m_frameTime); // Process sensors, and controllers m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_CONTROLLER); scene->LogicBeginFrame(m_frameTime); // Scenegraph needs to be updated again, because Logic Controllers // can affect the local matrices. m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_CONTROLLER_UPDATE); scene->UpdateParents(m_frameTime); // Process actuators // Do some cleanup work for this logic frame m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_ACTUATOR); scene->LogicUpdateFrame(m_frameTime, true); scene->LogicEndFrame(); // Actuators can affect the scenegraph m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_ACTUATOR_UPDATE); scene->UpdateParents(m_frameTime); m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_PHYSICS2); scene->GetPhysicsEnvironment()->beginFrame(); // Perform physics calculations on the scene. This can involve @@ -511,6 +520,7 @@ else scene->GetPhysicsEnvironment()->proceedDeltaTime(m_frameTime,1.0/m_ticrate);//m_deltatimerealDeltaTime); m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_PHYSICS2_UPDATE); scene->UpdateParents(m_frameTime); @@ -574,6 +584,7 @@ else KX_SetActiveScene(scene); m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_PHYSICS1); scene->UpdateParents(m_clockTime); // Perform physics calculations on the scene. This can involve @@ -583,6 +594,7 @@ else // Update scenegraph after physics step. This maps physics calculations // into node positions. m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_PHYSICS2); scene->UpdateParents(m_clockTime); // Do some cleanup work for this logic frame @@ -591,6 +603,7 @@ else // Actuators can affect the scenegraph m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_ACTUATOR); scene->UpdateParents(m_clockTime); scene->setSuspendedTime(0.0); @@ -622,6 +635,7 @@ void KX_KetsjiEngine::Render() const RAS_FrameSettings &framesettings = firstscene->GetFramingType(); m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_RENDER); // hiding mouse cursor each frame // (came back when going out of focus and then back in again) @@ -1102,14 +1116,22 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam) cam->GetCameraLocation(), cam->GetCameraOrientation()); cam->SetModelviewMatrix(viewmat); - scene->UpdateMeshTransformations(); + //redundant, already done in + //scene->UpdateMeshTransformations(); // The following actually reschedules all vertices to be // redrawn. There is a cache between the actual rescheduling // and this call though. Visibility is imparted when this call // runs through the individual objects. + + m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_CULLING); + scene->CalculateVisibleMeshes(m_rasterizer,cam); + m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_RENDER); + scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools); if (scene->GetPhysicsEnvironment()) @@ -1166,15 +1188,17 @@ void KX_KetsjiEngine::AddScene(KX_Scene* scene) void KX_KetsjiEngine::PostProcessScene(KX_Scene* scene) { bool override_camera = (m_overrideCam && (scene->GetName() == m_overrideSceneName)); - - // if there is no activecamera, or the camera is being - // overridden we need to construct a temporarily camera + + SG_SetActiveStage(SG_STAGE_SCENE); + + // if there is no activecamera, or the camera is being + // overridden we need to construct a temporarily camera if (!scene->GetActiveCamera() || override_camera) { KX_Camera* activecam = NULL; RAS_CameraData camdata = RAS_CameraData(); - activecam = new KX_Camera(scene,KX_Scene::m_callbacks,camdata, false); + activecam = new KX_Camera(scene,KX_Scene::m_callbacks,camdata); activecam->SetName("__default__cam__"); // set transformation @@ -1186,11 +1210,11 @@ void KX_KetsjiEngine::PostProcessScene(KX_Scene* scene) activecam->NodeSetLocalPosition(camtrans.getOrigin()); activecam->NodeSetLocalOrientation(camtrans.getBasis()); - activecam->NodeUpdateGS(0,true); + activecam->NodeUpdateGS(0); } else { activecam->NodeSetLocalPosition(MT_Point3(0.0, 0.0, 0.0)); activecam->NodeSetLocalOrientation(MT_Vector3(0.0, 0.0, 0.0)); - activecam->NodeUpdateGS(0,true); + activecam->NodeUpdateGS(0); } scene->AddCamera(activecam); diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp index 7b5b77ccacf..f996f86d751 100644 --- a/source/gameengine/Ketsji/KX_Light.cpp +++ b/source/gameengine/Ketsji/KX_Light.cpp @@ -159,7 +159,7 @@ void KX_LightObject::BindShadowBuffer(RAS_IRasterizer *ras, KX_Camera *cam, MT_T cam->NodeSetLocalPosition(camtrans.getOrigin()); cam->NodeSetLocalOrientation(camtrans.getBasis()); - cam->NodeUpdateGS(0,true); + cam->NodeUpdateGS(0); /* setup rasterizer transformations */ ras->SetProjectionMatrix(projectionmat); diff --git a/source/gameengine/Ketsji/KX_MotionState.cpp b/source/gameengine/Ketsji/KX_MotionState.cpp index 15f100af915..00d9a32eb38 100644 --- a/source/gameengine/Ketsji/KX_MotionState.cpp +++ b/source/gameengine/Ketsji/KX_MotionState.cpp @@ -44,7 +44,7 @@ KX_MotionState::~KX_MotionState() void KX_MotionState::getWorldPosition(float& posX,float& posY,float& posZ) { - MT_Point3 pos = m_node->GetWorldPosition(); + const MT_Point3& pos = m_node->GetWorldPosition(); posX = pos[0]; posY = pos[1]; posZ = pos[2]; @@ -52,7 +52,7 @@ void KX_MotionState::getWorldPosition(float& posX,float& posY,float& posZ) void KX_MotionState::getWorldScaling(float& scaleX,float& scaleY,float& scaleZ) { - MT_Vector3 scale = m_node->GetWorldScaling(); + const MT_Vector3& scale = m_node->GetWorldScaling(); scaleX = scale[0]; scaleY = scale[1]; scaleZ = scale[2]; @@ -60,17 +60,23 @@ void KX_MotionState::getWorldScaling(float& scaleX,float& scaleY,float& scaleZ) void KX_MotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal) { - MT_Quaternion orn = m_node->GetWorldOrientation().getRotation(); + MT_Quaternion& orn = m_node->GetWorldOrientation().getRotation(); quatIma0 = orn[0]; quatIma1 = orn[1]; quatIma2 = orn[2]; quatReal = orn[3]; } +void KX_MotionState::getWorldOrientation(float* ori) +{ + const MT_Matrix3x3& mat = m_node->GetWorldOrientation(); + mat.getValue(ori); +} + void KX_MotionState::setWorldPosition(float posX,float posY,float posZ) { m_node->SetLocalPosition(MT_Point3(posX,posY,posZ)); - m_node->SetWorldPosition(MT_Point3(posX,posY,posZ)); + //m_node->SetWorldPosition(MT_Point3(posX,posY,posZ)); } void KX_MotionState::setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal) @@ -82,13 +88,15 @@ void KX_MotionState::setWorldOrientation(float quatIma0,float quatIma1,float qua orn[3] = quatReal; m_node->SetLocalOrientation(orn); - m_node->SetWorldOrientation(orn); + //m_node->SetWorldOrientation(orn); } void KX_MotionState::calculateWorldTransformations() { - m_node->ComputeWorldTransforms(NULL); + //Not needed, will be done in KX_Scene::UpdateParents() after the physics simulation + //bool parentUpdated = false; + //m_node->ComputeWorldTransforms(NULL, parentUpdated); } diff --git a/source/gameengine/Ketsji/KX_MotionState.h b/source/gameengine/Ketsji/KX_MotionState.h index c83af664817..7ba3ca2f85c 100644 --- a/source/gameengine/Ketsji/KX_MotionState.h +++ b/source/gameengine/Ketsji/KX_MotionState.h @@ -44,6 +44,7 @@ public: virtual void getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal); virtual void setWorldPosition(float posX,float posY,float posZ); virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal); + virtual void getWorldOrientation(float* ori); virtual void calculateWorldTransformations(); }; diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index cd753210184..b9d1939e5db 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -127,13 +127,10 @@ CValue* KX_NearSensor::GetReplica() } } - //static_cast(m_eventmgr)->RegisterSensor(this); - //todo: make sure replication works fine - //>m_sumoObj = new SM_Object(DT_NewSphere(0.0),NULL,NULL,NULL); - //replica->m_sumoObj->setMargin(m_Margin); - //replica->m_sumoObj->setClientObject(replica->m_client_info); - - ((KX_GameObject*)replica->GetParent())->GetSGNode()->ComputeWorldTransforms(NULL); + //Wrong: the parent object could be a child, this code works only if it is a root parent. + //Anyway, at this stage, the parent object is already synchronized, nothing to do. + //bool parentUpdated = false; + //((KX_GameObject*)replica->GetParent())->GetSGNode()->ComputeWorldTransforms(NULL, parentUpdated); replica->SynchronizeTransform(); return replica; @@ -154,8 +151,10 @@ void KX_NearSensor::ReParent(SCA_IObject* parent) client_info->m_sensors.push_back(this); SCA_ISensor::ReParent(parent); */ - ((KX_GameObject*)GetParent())->GetSGNode()->ComputeWorldTransforms(NULL); - SynchronizeTransform(); + //Not needed, was done in GetReplica() already + //bool parentUpdated = false; + //((KX_GameObject*)GetParent())->GetSGNode()->ComputeWorldTransforms(NULL,parentUpdated); + //SynchronizeTransform(); SCA_ISensor::ReParent(parent); } diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp index 355ac89a926..b9abe69633e 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.cpp +++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp @@ -100,8 +100,9 @@ CValue* KX_RadarSensor::GetReplica() //>m_sumoObj = new SM_Object(DT_NewCone(m_coneradius, m_coneheight),NULL,NULL,NULL); //replica->m_sumoObj->setMargin(m_Margin); //replica->m_sumoObj->setClientObject(replica->m_client_info); - - ((KX_GameObject*)replica->GetParent())->GetSGNode()->ComputeWorldTransforms(NULL); + //Wrong: see KX_TouchSensor + //bool parentUpdated = false; + //((KX_GameObject*)replica->GetParent())->GetSGNode()->ComputeWorldTransforms(NULL,parentUpdated); replica->SynchronizeTransform(); return replica; diff --git a/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp b/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp index 151270cbd68..0e7571031e8 100644 --- a/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp +++ b/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp @@ -57,7 +57,8 @@ New(Bone* bone KX_BoneParentRelation:: UpdateChildCoordinates( SG_Spatial * child, - const SG_Spatial * parent + const SG_Spatial * parent, + bool& parentUpdated ){ MT_assert(child != NULL); @@ -67,6 +68,8 @@ UpdateChildCoordinates( const MT_Vector3 & child_scale = child->GetLocalScale(); const MT_Point3 & child_pos = child->GetLocalPosition(); const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation(); + // we don't know if the armature has been updated or not, assume yes + parentUpdated = true; // the childs world locations which we will update. @@ -122,7 +125,7 @@ UpdateChildCoordinates( else { child->SetWorldFromLocalTransform(); } - + child->SetModified(false); return valid_parent_transform; } diff --git a/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.h b/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.h index 2a19d8a1784..c9baf228855 100644 --- a/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.h +++ b/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.h @@ -82,7 +82,8 @@ public : bool UpdateChildCoordinates( SG_Spatial * child, - const SG_Spatial * parent + const SG_Spatial * parent, + bool& parentUpdated ); /** diff --git a/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp b/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp index 0729ec8a902..87ff3b53911 100644 --- a/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp +++ b/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp @@ -51,13 +51,20 @@ New( KX_NormalParentRelation:: UpdateChildCoordinates( SG_Spatial * child, - const SG_Spatial * parent + const SG_Spatial * parent, + bool& parentUpdated ){ MT_assert(child != NULL); + if (!parentUpdated && !child->IsModified()) + return false; + + parentUpdated = true; + if (parent==NULL) { /* Simple case */ child->SetWorldFromLocalTransform(); - return false; + child->SetModified(false); + return true; //false; } else { // the childs world locations which we will update. @@ -68,6 +75,7 @@ UpdateChildCoordinates( 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())); + child->SetModified(false); return true; } } @@ -112,10 +120,15 @@ New( KX_VertexParentRelation:: UpdateChildCoordinates( SG_Spatial * child, - const SG_Spatial * parent + const SG_Spatial * parent, + bool& parentUpdated ){ MT_assert(child != NULL); + + if (!parentUpdated && !child->IsModified()) + return false; + child->SetWorldScale(child->GetLocalScale()); if (parent) @@ -124,7 +137,8 @@ UpdateChildCoordinates( child->SetWorldPosition(child->GetLocalPosition()); child->SetWorldOrientation(child->GetLocalOrientation()); - return parent != NULL; + child->SetModified(false); + return true; //parent != NULL; } /** @@ -172,10 +186,14 @@ New( KX_SlowParentRelation:: UpdateChildCoordinates( SG_Spatial * child, - const SG_Spatial * parent + const SG_Spatial * parent, + bool& parentUpdated ){ MT_assert(child != NULL); + // the child will move even if the parent is not + parentUpdated = true; + const MT_Vector3 & child_scale = child->GetLocalScale(); const MT_Point3 & child_pos = child->GetLocalPosition(); const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation(); @@ -252,8 +270,9 @@ UpdateChildCoordinates( child->SetWorldScale(child_w_scale); child->SetWorldPosition(child_w_pos); child->SetWorldOrientation(child_w_rotation); + child->SetModified(false); - return parent != NULL; + return true; //parent != NULL; } /** diff --git a/source/gameengine/Ketsji/KX_SG_NodeRelationships.h b/source/gameengine/Ketsji/KX_SG_NodeRelationships.h index faa650106c8..d8fb9211f21 100644 --- a/source/gameengine/Ketsji/KX_SG_NodeRelationships.h +++ b/source/gameengine/Ketsji/KX_SG_NodeRelationships.h @@ -71,7 +71,8 @@ public : bool UpdateChildCoordinates( SG_Spatial * child, - const SG_Spatial * parent + const SG_Spatial * parent, + bool& parentUpdated ); /** @@ -115,7 +116,8 @@ public : bool UpdateChildCoordinates( SG_Spatial * child, - const SG_Spatial * parent + const SG_Spatial * parent, + bool& parentUpdated ); /** @@ -166,7 +168,8 @@ public : bool UpdateChildCoordinates( SG_Spatial * child, - const SG_Spatial * parent + const SG_Spatial * parent, + bool& parentUpdated ); /** diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 04d6bd75f92..7eed1cc387b 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -76,7 +76,9 @@ #include "NG_NetworkScene.h" #include "PHY_IPhysicsEnvironment.h" #include "KX_IPhysicsController.h" +#include "PHY_IGraphicController.h" #include "KX_BlenderSceneConverter.h" +#include "KX_MotionState.h" #include "BL_ShapeDeformer.h" #include "BL_DeformableGameObject.h" @@ -133,6 +135,7 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, m_suspendedtime = 0.0; m_suspendeddelta = 0.0; + m_dbvt_culling = false; m_activity_culling = false; m_suspend = false; m_isclearingZbuffer = true; @@ -407,6 +410,13 @@ void KX_Scene::RemoveNodeDestructObject(class SG_IObject* node,class CValue* gam // will in any case be deleted. This ensures that the object will not try to use the node // when it is finally deleted (see KX_GameObject destructor) orgobj->SetSGNode(NULL); + PHY_IGraphicController* ctrl = orgobj->GetGraphicController(); + if (ctrl) + { + // a graphic controller is set, we must delete it as the node will be deleted + delete ctrl; + orgobj->SetGraphicController(NULL); + } } if (node) delete node; @@ -485,7 +495,14 @@ KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CVal replicanode->AddSGController(replicacontroller); } } - + // replicate graphic controller + if (orgobj->GetGraphicController()) + { + PHY_IMotionState* motionstate = new KX_MotionState(newobj->GetSGNode()); + PHY_IGraphicController* newctrl = orgobj->GetGraphicController()->GetReplica(motionstate); + newctrl->setNewClientInfo(newobj->getClientInfo()); + newobj->SetGraphicController(newctrl); + } return newobj; } @@ -792,6 +809,24 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject, replica->GetSGNode()->AddChild(childreplicanode); } + // At this stage all the objects in the hierarchy have been duplicated, + // we can update the scenegraph, we need it for the duplication of logic + MT_Point3 newpos = ((KX_GameObject*) parentobject)->NodeGetWorldPosition(); + replica->NodeSetLocalPosition(newpos); + + MT_Matrix3x3 newori = ((KX_GameObject*) parentobject)->NodeGetWorldOrientation(); + replica->NodeSetLocalOrientation(newori); + + // get the rootnode's scale + MT_Vector3 newscale = parentobj->GetSGNode()->GetRootSGParent()->GetLocalScale(); + + // set the replica's relative scale with the rootnode's scale + replica->NodeSetRelativeScale(newscale); + + replica->GetSGNode()->UpdateWorldData(0); + replica->GetSGNode()->SetBBox(originalobj->GetSGNode()->BBox()); + replica->GetSGNode()->SetRadius(originalobj->GetSGNode()->Radius()); + // now replicate logic vector::iterator git; for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) @@ -814,21 +849,6 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject, ReplicateLogic((*git)); } - MT_Point3 newpos = ((KX_GameObject*) parentobject)->NodeGetWorldPosition(); - replica->NodeSetLocalPosition(newpos); - - MT_Matrix3x3 newori = ((KX_GameObject*) parentobject)->NodeGetWorldOrientation(); - replica->NodeSetLocalOrientation(newori); - - // get the rootnode's scale - MT_Vector3 newscale = parentobj->GetSGNode()->GetRootSGParent()->GetLocalScale(); - - // set the replica's relative scale with the rootnode's scale - replica->NodeSetRelativeScale(newscale); - - replica->GetSGNode()->UpdateWorldData(0); - replica->GetSGNode()->SetBBox(originalobj->GetSGNode()->BBox()); - replica->GetSGNode()->SetRadius(originalobj->GetSGNode()->Radius()); // check if there are objects with dupligroup in the hierarchy vector duplilist; for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) @@ -1163,7 +1183,6 @@ void KX_Scene::UpdateMeshTransformations() { KX_GameObject* gameobj = (KX_GameObject*)m_objectlist->GetValue(i); gameobj->GetOpenGLMatrix(); -// gameobj->UpdateNonDynas(); } } @@ -1298,21 +1317,46 @@ void KX_Scene::MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj,KX_Cam } } +void KX_Scene::PhysicsCullingCallback(KX_ClientObjectInfo* objectInfo, void* cullingInfo) +{ + KX_GameObject* gameobj = objectInfo->m_gameobject; + if (!gameobj->GetVisible()) + // ideally, invisible objects should be removed from the culling tree temporarily + return; + if(((CullingInfo*)cullingInfo)->m_layer && !(gameobj->GetLayer() & ((CullingInfo*)cullingInfo)->m_layer)) + // used for shadow: object is not in shadow layer + return; + + // make object visible + gameobj->SetCulled(false); + gameobj->UpdateBuckets(false); +} + void KX_Scene::CalculateVisibleMeshes(RAS_IRasterizer* rasty,KX_Camera* cam, int layer) { -// FIXME: When tree is operational -#if 1 - // do this incrementally in the future - for (int i = 0; i < m_objectlist->GetCount(); i++) + bool dbvt_culling = false; + if (m_dbvt_culling) { - MarkVisible(rasty, static_cast(m_objectlist->GetValue(i)), cam, layer); + // test culling through Bullet + PHY__Vector4 planes[5]; + // get the clip planes + MT_Vector4* cplanes = cam->GetNormalizedClipPlanes(); + // and convert + planes[0].setValue(cplanes[0].getValue()); + planes[1].setValue(cplanes[1].getValue()); + planes[2].setValue(cplanes[2].getValue()); + planes[3].setValue(cplanes[3].getValue()); + planes[4].setValue(cplanes[5].getValue()); + CullingInfo info(layer); + dbvt_culling = m_physicsEnvironment->cullingTest(PhysicsCullingCallback,&info,planes,5); + } + if (!dbvt_culling) { + // the physics engine couldn't help us, do it the hard way + for (int i = 0; i < m_objectlist->GetCount(); i++) + { + MarkVisible(rasty, static_cast(m_objectlist->GetValue(i)), cam, layer); + } } -#else - if (cam->GetFrustumCulling()) - MarkVisible(m_objecttree, rasty, cam, layer); - else - MarkSubTreeVisible(m_objecttree, rasty, true, cam, layer); -#endif } // logic stuff @@ -1393,7 +1437,7 @@ void KX_Scene::UpdateParents(double curtime) for (int i=0; iGetCount(); i++) { KX_GameObject* parentobj = (KX_GameObject*)GetRootParentList()->GetValue(i); - parentobj->NodeUpdateGS(curtime,true); + parentobj->NodeUpdateGS(curtime); } } @@ -1588,6 +1632,7 @@ PyAttributeDef KX_Scene::Attributes[] = { KX_PYATTRIBUTE_BOOL_RO("suspended", KX_Scene, m_suspend), KX_PYATTRIBUTE_BOOL_RO("activity_culling", KX_Scene, m_activity_culling), KX_PYATTRIBUTE_FLOAT_RW("activity_culling_radius", 0.5f, FLT_MAX, KX_Scene, m_activity_box_radius), + KX_PYATTRIBUTE_BOOL_RO("dbvt_culling", KX_Scene, m_dbvt_culling), KX_PYATTRIBUTE_RO_FUNCTION("__dict__", KX_Scene, pyattr_get_dir_dict), { NULL } //Sentinel }; diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index df51fcec8f7..9f05ddf70c2 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -85,6 +85,8 @@ class RAS_IRenderTools; class SCA_JoystickManager; class btCollisionShape; class KX_BlenderSceneConverter; +struct KX_ClientObjectInfo; + /** * The KX_Scene holds all data for an independent scene. It relates * KX_Objects to the specific objects in the modules. @@ -92,6 +94,12 @@ class KX_BlenderSceneConverter; class KX_Scene : public PyObjectPlus, public SCA_IScene { Py_Header; + + struct CullingInfo { + int m_layer; + CullingInfo(int layer) : m_layer(layer) {} + }; + protected: RAS_BucketManager* m_bucketmanager; CListValue* m_tempObjectList; @@ -251,6 +259,11 @@ protected: */ bool m_activity_culling; + /** + * Toggle to enable or disable culling via DBVT broadphase of Bullet. + */ + bool m_dbvt_culling; + /** * The framing settings used by this scene */ @@ -269,6 +282,7 @@ protected: void MarkVisible(SG_Tree *node, RAS_IRasterizer* rasty, KX_Camera*cam,int layer=0); void MarkSubTreeVisible(SG_Tree *node, RAS_IRasterizer* rasty, bool visible, KX_Camera*cam,int layer=0); void MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj, KX_Camera*cam, int layer=0); + static void PhysicsCullingCallback(KX_ClientObjectInfo* objectInfo, void* cullingInfo); double m_suspendedtime; double m_suspendeddelta; @@ -530,6 +544,9 @@ public: bool IsSuspended(); bool IsClearingZBuffer(); void EnableZBufferClearing(bool isclearingZbuffer); + // use of DBVT tree for camera culling + void SetDbvtCameraCulling(bool b) { m_dbvt_culling = b; }; + bool GetDbvtCameraCulling() { return m_dbvt_culling; }; void SetSceneConverter(class KX_BlenderSceneConverter* sceneConverter); diff --git a/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h b/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h index dcc87d614c0..e4aaef1803d 100644 --- a/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h +++ b/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h @@ -55,6 +55,7 @@ public: virtual void removeConstraint(void * constraintid); virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback,float fromX,float fromY,float fromZ, float toX,float toY,float toZ); + virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes) { return false; } //gamelogic callbacks diff --git a/source/gameengine/Physics/Bullet/CcdGraphicController.cpp b/source/gameengine/Physics/Bullet/CcdGraphicController.cpp new file mode 100644 index 00000000000..caf18fd28ba --- /dev/null +++ b/source/gameengine/Physics/Bullet/CcdGraphicController.cpp @@ -0,0 +1,112 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "CcdPhysicsEnvironment.h" +#include "CcdGraphicController.h" +#include "btBulletDynamicsCommon.h" +#include "MT_Point3.h" + + +CcdGraphicController::CcdGraphicController (CcdPhysicsEnvironment* phyEnv, PHY_IMotionState* motionState) : + m_localAabbMin(0.f, 0.f, 0.f), + m_localAabbMax(0.f, 0.f, 0.f), + m_motionState(motionState), + m_phyEnv(phyEnv), + m_handle(NULL), + m_newClientInfo(NULL) +{ +} + +CcdGraphicController::~CcdGraphicController() +{ + if (m_phyEnv) + m_phyEnv->removeCcdGraphicController(this); + + if (m_motionState) + delete m_motionState; +} + +void CcdGraphicController::setLocalAabb(const btVector3& aabbMin,const btVector3& aabbMax) +{ + m_localAabbMin = aabbMin; + m_localAabbMax = aabbMax; + SetGraphicTransform(); +} + +void CcdGraphicController::setLocalAabb(const MT_Point3& aabbMin,const MT_Point3& aabbMax) +{ + m_localAabbMin = btVector3(aabbMin[0],aabbMin[1],aabbMin[2]); + m_localAabbMax = btVector3(aabbMax[0],aabbMax[1],aabbMax[2]); + SetGraphicTransform(); +} + + +void CcdGraphicController::getAabb(btVector3& aabbMin, btVector3& aabbMax) +{ + btVector3 pos; + btVector3 scale; + float ori[12]; + m_motionState->getWorldPosition(pos.m_floats[0],pos.m_floats[1],pos.m_floats[2]); + m_motionState->getWorldScaling(scale.m_floats[0],scale.m_floats[1],scale.m_floats[2]); + m_motionState->getWorldOrientation(ori); + btMatrix3x3 rot(ori[0], ori[4], ori[8], + ori[1], ori[5], ori[9], + ori[2], ori[6], ori[10]); + + btVector3 localAabbMin = m_localAabbMin; + btVector3 localAabbMax = m_localAabbMax; + btVector3 tmpAabbMin = m_localAabbMin * scale; + btVector3 tmpAabbMax = m_localAabbMax * scale; + + localAabbMin[0] = (scale.getX() >= 0.) ? tmpAabbMin[0] : tmpAabbMax[0]; + localAabbMin[1] = (scale.getY() >= 0.) ? tmpAabbMin[1] : tmpAabbMax[1]; + localAabbMin[2] = (scale.getZ() >= 0.) ? tmpAabbMin[2] : tmpAabbMax[2]; + localAabbMax[0] = (scale.getX() <= 0.) ? tmpAabbMin[0] : tmpAabbMax[0]; + localAabbMax[1] = (scale.getY() <= 0.) ? tmpAabbMin[1] : tmpAabbMax[1]; + localAabbMax[2] = (scale.getZ() <= 0.) ? tmpAabbMin[2] : tmpAabbMax[2]; + + btVector3 localHalfExtents = btScalar(0.5)*(localAabbMax-localAabbMin); + btVector3 localCenter = btScalar(0.5)*(localAabbMax+localAabbMin); + + btMatrix3x3 abs_b = rot.absolute(); + btVector3 center = rot*localCenter + pos; + btVector3 extent = abs_b*localHalfExtents; + aabbMin = center - extent; + aabbMax = center + extent; +} + +bool CcdGraphicController::SetGraphicTransform() +{ + if (!m_handle) + return false; + btVector3 aabbMin; + btVector3 aabbMax; + getAabb(aabbMin, aabbMax); + // update Aabb in broadphase + m_phyEnv->getCullingTree()->setAabb(m_handle,aabbMin,aabbMax,NULL); + return true; +} + +PHY_IGraphicController* CcdGraphicController::GetReplica(class PHY_IMotionState* motionState) +{ + CcdGraphicController* replica = new CcdGraphicController(*this); + replica->m_motionState = motionState; + replica->m_newClientInfo = NULL; + replica->m_handle = NULL; + m_phyEnv->addCcdGraphicController(replica); + return replica; +} + + diff --git a/source/gameengine/Physics/Bullet/CcdGraphicController.h b/source/gameengine/Physics/Bullet/CcdGraphicController.h new file mode 100644 index 00000000000..8faa0944313 --- /dev/null +++ b/source/gameengine/Physics/Bullet/CcdGraphicController.h @@ -0,0 +1,74 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +#ifndef BULLET2_GRAPHICCONTROLLER_H +#define BULLET2_GRAPHICCONTROLLER_H + +#include "PHY_IGraphicController.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btTransform.h" + +#include "PHY_IMotionState.h" +#include "MT_Point3.h" + +class CcdPhysicsEnvironment; +class btCollisionObject; + +///CcdGraphicController is a graphic object that supports view frustrum culling and occlusion +class CcdGraphicController : public PHY_IGraphicController +{ +public: + CcdGraphicController(CcdPhysicsEnvironment* phyEnv, PHY_IMotionState* motionState); + + virtual ~CcdGraphicController(); + + void setLocalAabb(const btVector3& aabbMin,const btVector3& aabbMax); + void setLocalAabb(const MT_Point3& aabbMin,const MT_Point3& aabbMax); + + PHY_IMotionState* GetMotionState() { return m_motionState; } + void getAabb(btVector3& aabbMin, btVector3& aabbMax); + + virtual void setBroadphaseHandle(btBroadphaseProxy* handle) { m_handle = handle; } + virtual btBroadphaseProxy* getBroadphaseHandle() { return m_handle; } + + //////////////////////////////////// + // PHY_IGraphicController interface + //////////////////////////////////// + + /** + * Updates the Aabb based on the motion state + */ + virtual bool SetGraphicTransform(); + + // client info for culling + virtual void* getNewClientInfo() { return m_newClientInfo; } + virtual void setNewClientInfo(void* clientinfo) { m_newClientInfo = clientinfo; } + virtual PHY_IGraphicController* GetReplica(class PHY_IMotionState* motionstate); + +private: + // unscaled aabb corner + btVector3 m_localAabbMin; + btVector3 m_localAabbMax; + + PHY_IMotionState* m_motionState; + CcdPhysicsEnvironment* m_phyEnv; + btBroadphaseProxy* m_handle; + void* m_newClientInfo; + +}; + +#endif //BULLET2_PHYSICSCONTROLLER_H diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index bb2f53a1988..2283968801f 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -1245,6 +1245,22 @@ void DefaultMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,flo quatReal = m_worldTransform.getRotation()[3]; } +void DefaultMotionState::getWorldOrientation(float* ori) +{ + *ori++ = m_worldTransform.getBasis()[0].x(); + *ori++ = m_worldTransform.getBasis()[1].x(); + *ori++ = m_worldTransform.getBasis()[1].x(); + *ori++ = 0.f; + *ori++ = m_worldTransform.getBasis()[0].y(); + *ori++ = m_worldTransform.getBasis()[1].y(); + *ori++ = m_worldTransform.getBasis()[1].y(); + *ori++ = 0.f; + *ori++ = m_worldTransform.getBasis()[0].z(); + *ori++ = m_worldTransform.getBasis()[1].z(); + *ori++ = m_worldTransform.getBasis()[1].z(); + *ori++ = 0.f; +} + void DefaultMotionState::setWorldPosition(float posX,float posY,float posZ) { btVector3 pos(posX,posY,posZ); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index 510454a7b63..245cde2baaa 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -544,6 +544,7 @@ class DefaultMotionState : public PHY_IMotionState virtual void setWorldPosition(float posX,float posY,float posZ); virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal); + virtual void getWorldOrientation(float* ori); virtual void calculateWorldTransformations(); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index dd21e58bd68..cef2f2477b7 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -18,6 +18,7 @@ subject to the following restrictions: #include "CcdPhysicsEnvironment.h" #include "CcdPhysicsController.h" +#include "CcdGraphicController.h" #include #include "btBulletDynamicsCommon.h" @@ -316,8 +317,10 @@ static void DrawAabb(btIDebugDraw* debugDrawer,const btVector3& from,const btVec -CcdPhysicsEnvironment::CcdPhysicsEnvironment(btDispatcher* dispatcher,btOverlappingPairCache* pairCache) -:m_numIterations(10), +CcdPhysicsEnvironment::CcdPhysicsEnvironment(bool useDbvtCulling,btDispatcher* dispatcher,btOverlappingPairCache* pairCache) +:m_cullingCache(NULL), +m_cullingTree(NULL), +m_numIterations(10), m_scalingPropagated(false), m_numTimeSubSteps(1), m_ccdMode(0), @@ -350,6 +353,11 @@ m_ownDispatcher(NULL) //m_broadphase = new btAxisSweep3(btVector3(-1000,-1000,-1000),btVector3(1000,1000,1000)); //m_broadphase = new btSimpleBroadphase(); m_broadphase = new btDbvtBroadphase(); + // avoid any collision in the culling tree + if (useDbvtCulling) { + m_cullingCache = new btNullPairCache(); + m_cullingTree = new btDbvtBroadphase(m_cullingCache); + } m_filterCallback = new CcdOverlapFilterCallBack(this); m_broadphase->getOverlappingPairCache()->setOverlapFilterCallback(m_filterCallback); @@ -364,7 +372,6 @@ m_ownDispatcher(NULL) m_gravity = btVector3(0.f,-10.f,0.f); m_dynamicsWorld->setGravity(m_gravity); - } void CcdPhysicsEnvironment::addCcdPhysicsController(CcdPhysicsController* ctrl) @@ -558,6 +565,41 @@ void CcdPhysicsEnvironment::refreshCcdPhysicsController(CcdPhysicsController* ct } } +void CcdPhysicsEnvironment::addCcdGraphicController(CcdGraphicController* ctrl) +{ + if (m_cullingTree) + { + btVector3 minAabb; + btVector3 maxAabb; + ctrl->getAabb(minAabb, maxAabb); + + ctrl->setBroadphaseHandle(m_cullingTree->createProxy( + minAabb, + maxAabb, + INVALID_SHAPE_PROXYTYPE, // this parameter is not used + ctrl, + 0, // this object does not collision with anything + 0, + NULL, // dispatcher => this parameter is not used + 0)); + + assert(ctrl->getBroadphaseHandle()); + } +} + +void CcdPhysicsEnvironment::removeCcdGraphicController(CcdGraphicController* ctrl) +{ + if (m_cullingTree) + { + btBroadphaseProxy* bp = ctrl->getBroadphaseHandle(); + if (bp) + { + m_cullingTree->destroyProxy(bp,NULL); + ctrl->setBroadphaseHandle(0); + } + } +} + void CcdPhysicsEnvironment::beginFrame() { @@ -593,10 +635,10 @@ bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep) (*it)->SynchronizeMotionStates(timeStep); } - for (it=m_controllers.begin(); it!=m_controllers.end(); it++) - { - (*it)->SynchronizeMotionStates(timeStep); - } + //for (it=m_controllers.begin(); it!=m_controllers.end(); it++) + //{ + // (*it)->SynchronizeMotionStates(timeStep); + //} for (i=0;idata; + // the client object is a graphic controller + CcdGraphicController* ctrl = static_cast(proxy->m_clientObject); + KX_ClientObjectInfo* info = (KX_ClientObjectInfo*)ctrl->getNewClientInfo(); + if (info) + (*m_clientCallback)(info, m_userData); + } +}; + +bool CcdPhysicsEnvironment::cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4 *planes, int nplanes) +{ + if (!m_cullingTree) + return false; + DbvtCullingCallback dispatcher(callback, userData); + btVector3 planes_n[5]; + btScalar planes_o[5]; + if (nplanes > 5) + nplanes = 5; + for (int i=0; im_sets[1].m_root,planes_n,planes_o,nplanes,dispatcher); + btDbvt::collideKDOP(m_cullingTree->m_sets[0].m_root,planes_n,planes_o,nplanes,dispatcher); + return true; +} int CcdPhysicsEnvironment::getNumContactPoints() @@ -1211,6 +1297,13 @@ CcdPhysicsEnvironment::~CcdPhysicsEnvironment() if (NULL != m_broadphase) delete m_broadphase; + + if (NULL != m_cullingTree) + delete m_cullingTree; + + if (NULL != m_cullingCache) + delete m_cullingCache; + } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h index 2f1f0bb254b..ddbcbe6b4d6 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h @@ -20,6 +20,7 @@ subject to the following restrictions: #include #include class CcdPhysicsController; +class CcdGraphicController; #include "LinearMath/btVector3.h" #include "LinearMath/btTransform.h" @@ -40,6 +41,7 @@ class btDispatcher; class WrapperVehicle; class btPersistentManifold; class btBroadphaseInterface; +struct btDbvtBroadphase; class btOverlappingPairCache; class btIDebugDraw; class PHY_IVehicle; @@ -58,7 +60,10 @@ protected: btIDebugDraw* m_debugDrawer; class btDefaultCollisionConfiguration* m_collisionConfiguration; - class btBroadphaseInterface* m_broadphase; + class btBroadphaseInterface* m_broadphase; // broadphase for dynamic world + // for culling only + btOverlappingPairCache* m_cullingCache; + struct btDbvtBroadphase* m_cullingTree; // broadphase for culling //solver iterations int m_numIterations; @@ -77,7 +82,7 @@ protected: void processFhSprings(double curTime,float timeStep); public: - CcdPhysicsEnvironment(btDispatcher* dispatcher=0, btOverlappingPairCache* pairCache=0); + CcdPhysicsEnvironment(bool useDbvtCulling, btDispatcher* dispatcher=0, btOverlappingPairCache* pairCache=0); virtual ~CcdPhysicsEnvironment(); @@ -167,6 +172,7 @@ protected: btTypedConstraint* getConstraintById(int constraintId); virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ); + virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes); //Methods for gamelogic collision/physics callbacks @@ -200,7 +206,12 @@ protected: void refreshCcdPhysicsController(CcdPhysicsController* ctrl); + void addCcdGraphicController(CcdGraphicController* ctrl); + + void removeCcdGraphicController(CcdGraphicController* ctrl); + btBroadphaseInterface* getBroadphase(); + btDbvtBroadphase* getCullingTree() { return m_cullingTree; } btDispatcher* getDispatcher(); diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h index a92b1e7f4a6..fae1844d505 100644 --- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h +++ b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h @@ -70,6 +70,7 @@ public: } virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ); + virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes) { return false; } //gamelogic callbacks diff --git a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h index 65b07a7a0be..9942a367451 100644 --- a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h +++ b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h @@ -76,6 +76,7 @@ public: } virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback,float fromX,float fromY,float fromZ, float toX,float toY,float toZ); + virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4 *planes, int nplanes) { return false; } //gamelogic callbacks diff --git a/source/gameengine/Physics/common/PHY_DynamicTypes.h b/source/gameengine/Physics/common/PHY_DynamicTypes.h index c5cf92b553a..7ce40001af7 100644 --- a/source/gameengine/Physics/common/PHY_DynamicTypes.h +++ b/source/gameengine/Physics/common/PHY_DynamicTypes.h @@ -19,12 +19,42 @@ subject to the following restrictions: - +struct KX_ClientObjectInfo; class PHY_Shape; struct PHY__Vector3 { float m_vec[4]; + + operator const float* () const + { + return &m_vec[0]; + } + operator float* () + { + return &m_vec[0]; + } +}; + +struct PHY__Vector4 +{ + float m_vec[4]; + PHY__Vector4() {} + void setValue(const float *value) + { + m_vec[0] = *value++; + m_vec[1] = *value++; + m_vec[2] = *value++; + m_vec[3] = *value++; + } + void setValue(const double *value) + { + m_vec[0] = (float)(*value++); + m_vec[1] = (float)(*value++); + m_vec[2] = (float)(*value++); + m_vec[3] = (float)(*value++); + } + operator const float* () const { return &m_vec[0]; @@ -34,6 +64,7 @@ struct PHY__Vector3 return &m_vec[0]; } }; + //typedef float PHY__Vector3[4]; enum @@ -59,7 +90,7 @@ enum void *client_object1, void *client_object2, const PHY_CollData *coll_data); - + typedef void (*PHY_CullingCallback)(KX_ClientObjectInfo* info, void* param); /// PHY_PhysicsType enumerates all possible Physics Entities. diff --git a/source/gameengine/Physics/common/PHY_IController.cpp b/source/gameengine/Physics/common/PHY_IController.cpp new file mode 100644 index 00000000000..47fe9a9eea8 --- /dev/null +++ b/source/gameengine/Physics/common/PHY_IController.cpp @@ -0,0 +1,39 @@ +/** + * $Id$ + * + * ***** 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): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ +#include "PHY_IController.h" + +#ifdef HAVE_CONFIG_H +#include +#endif + +PHY_IController::~PHY_IController() +{ + +} + diff --git a/source/gameengine/Physics/common/PHY_IController.h b/source/gameengine/Physics/common/PHY_IController.h new file mode 100644 index 00000000000..45e93f9d24e --- /dev/null +++ b/source/gameengine/Physics/common/PHY_IController.h @@ -0,0 +1,53 @@ +/** + * $Id$ + * + * ***** 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): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ +#ifndef PHY_ICONTROLLER_H +#define PHY_ICONTROLLER_H + +#include "PHY_DynamicTypes.h" + + + +/** + PHY_IController is the abstract simplified Interface to objects + controlled by the physics engine. This includes the physics objects + and the graphics object for view frustrum and occlusion culling. +*/ +class PHY_IController +{ + public: + + virtual ~PHY_IController(); + // clientinfo for raycasts for example + virtual void* getNewClientInfo()=0; + virtual void setNewClientInfo(void* clientinfo)=0; + +}; + +#endif //PHY_ICONTROLLER_H + diff --git a/source/gameengine/Physics/common/PHY_IGraphicController.cpp b/source/gameengine/Physics/common/PHY_IGraphicController.cpp new file mode 100644 index 00000000000..4dccecd3d29 --- /dev/null +++ b/source/gameengine/Physics/common/PHY_IGraphicController.cpp @@ -0,0 +1,39 @@ +/** + * $Id$ + * + * ***** 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): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ +#include "PHY_IGraphicController.h" + +#ifdef HAVE_CONFIG_H +#include +#endif + +PHY_IGraphicController::~PHY_IGraphicController() +{ + +} + diff --git a/source/gameengine/Physics/common/PHY_IGraphicController.h b/source/gameengine/Physics/common/PHY_IGraphicController.h new file mode 100644 index 00000000000..36b8a978e87 --- /dev/null +++ b/source/gameengine/Physics/common/PHY_IGraphicController.h @@ -0,0 +1,56 @@ +/** + * $Id$ + * + * ***** 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): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ +#ifndef PHY_IGRAPHICCONTROLLER_H +#define PHY_IGRAPHICCONTROLLER_H + +#include "PHY_IController.h" + + + +/** + PHY_IPhysicsController is the abstract simplified Interface to a physical object. + It contains the IMotionState and IDeformableMesh Interfaces. +*/ +class PHY_IGraphicController : public PHY_IController +{ + + public: + + virtual ~PHY_IGraphicController(); + /** + SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding') + */ + virtual bool SetGraphicTransform()=0; + + virtual PHY_IGraphicController* GetReplica(class PHY_IMotionState* motionstate) {return 0;} + +}; + +#endif //PHY_IGRAPHICCONTROLLER_H + diff --git a/source/gameengine/Physics/common/PHY_IMotionState.h b/source/gameengine/Physics/common/PHY_IMotionState.h index d759b0aeff4..64bb810ee7c 100644 --- a/source/gameengine/Physics/common/PHY_IMotionState.h +++ b/source/gameengine/Physics/common/PHY_IMotionState.h @@ -43,6 +43,8 @@ class PHY_IMotionState virtual void getWorldPosition(float& posX,float& posY,float& posZ)=0; virtual void getWorldScaling(float& scaleX,float& scaleY,float& scaleZ)=0; virtual void getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)=0; + // ori = array 12 floats, [0..3] = first column + 0, [4..7] = second colum, [8..11] = third column + virtual void getWorldOrientation(float* ori)=0; virtual void setWorldPosition(float posX,float posY,float posZ)=0; virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)=0; diff --git a/source/gameengine/Physics/common/PHY_IPhysicsController.h b/source/gameengine/Physics/common/PHY_IPhysicsController.h index 884e14cfb5a..6cba6fa88af 100644 --- a/source/gameengine/Physics/common/PHY_IPhysicsController.h +++ b/source/gameengine/Physics/common/PHY_IPhysicsController.h @@ -29,7 +29,7 @@ #ifndef PHY_IPHYSICSCONTROLLER_H #define PHY_IPHYSICSCONTROLLER_H -#include "PHY_DynamicTypes.h" +#include "PHY_IController.h" @@ -37,7 +37,7 @@ PHY_IPhysicsController is the abstract simplified Interface to a physical object. It contains the IMotionState and IDeformableMesh Interfaces. */ -class PHY_IPhysicsController +class PHY_IPhysicsController : public PHY_IController { public: @@ -82,9 +82,7 @@ class PHY_IPhysicsController // dyna's that are rigidbody are free in orientation, dyna's with non-rigidbody are restricted virtual void setRigidBody(bool rigid)=0; - // clientinfo for raycasts for example - virtual void* getNewClientInfo()=0; - virtual void setNewClientInfo(void* clientinfo)=0; + virtual PHY_IPhysicsController* GetReplica() {return 0;} virtual void calcXform() =0; diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h index 226ba3a7e74..5edafe6b51e 100644 --- a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h +++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h @@ -142,6 +142,8 @@ class PHY_IPhysicsEnvironment virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ)=0; + //culling based on physical broad phase + virtual bool cullingTest(PHY_CullingCallback callback, void *userData, PHY__Vector4* planeNormals, int planeNumber) = 0; //Methods for gamelogic collision/physics callbacks //todo: diff --git a/source/gameengine/Rasterizer/RAS_BucketManager.cpp b/source/gameengine/Rasterizer/RAS_BucketManager.cpp index f7938bb62e6..ec290f89d9e 100644 --- a/source/gameengine/Rasterizer/RAS_BucketManager.cpp +++ b/source/gameengine/Rasterizer/RAS_BucketManager.cpp @@ -148,6 +148,10 @@ void RAS_BucketManager::RenderAlphaBuckets( while(sit->m_bucket->ActivateMaterial(cameratrans, rasty, rendertools)) sit->m_bucket->RenderMeshSlot(cameratrans, rasty, rendertools, *(sit->m_ms)); + + // make this mesh slot culled automatically for next frame + // it will be culled out by frustrum culling + sit->m_ms->SetCulled(true); } rasty->SetDepthMask(RAS_IRasterizer::KX_DEPTHMASK_ENABLED); @@ -170,6 +174,10 @@ void RAS_BucketManager::RenderSolidBuckets( while ((*bit)->ActivateMaterial(cameratrans, rasty, rendertools)) (*bit)->RenderMeshSlot(cameratrans, rasty, rendertools, *mit); + + // make this mesh slot culled automatically for next frame + // it will be culled out by frustrum culling + mit->SetCulled(true); } } diff --git a/source/gameengine/Rasterizer/RAS_FramingManager.h b/source/gameengine/Rasterizer/RAS_FramingManager.h index 610bd13ff12..0a226ac30f9 100644 --- a/source/gameengine/Rasterizer/RAS_FramingManager.h +++ b/source/gameengine/Rasterizer/RAS_FramingManager.h @@ -163,6 +163,13 @@ struct RAS_FrameFrustum float x2,y2; }; +/* must match R_CULLING_... from DNA_scene_types.h */ +enum RAS_CullingMode +{ + RAS_CULLING_DBVT = 0, + RAS_CULLING_NORMAL, + RAS_CULLING_NONE +}; /** * @section RAS_FramingManager diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.h b/source/gameengine/Rasterizer/RAS_MaterialBucket.h index 475f01d549a..211770318ae 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.h +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.h @@ -156,6 +156,7 @@ public: bool Join(RAS_MeshSlot *target, MT_Scalar distance); bool Equals(RAS_MeshSlot *target); bool IsCulled(); + void SetCulled(bool culled) { m_bCulled = culled; } }; /* Used by RAS_MeshObject, to point to it's slots in a bucket */ diff --git a/source/gameengine/SceneGraph/SG_BBox.cpp b/source/gameengine/SceneGraph/SG_BBox.cpp index a44262d04f7..66fcc5c7408 100644 --- a/source/gameengine/SceneGraph/SG_BBox.cpp +++ b/source/gameengine/SceneGraph/SG_BBox.cpp @@ -188,6 +188,13 @@ void SG_BBox::getaa(MT_Point3 *box, const MT_Transform &world) const *box++ = max; } +void SG_BBox::getmm(MT_Point3 *box, const MT_Transform &world) const +{ + const MT_Point3 min(world(m_min)), max(world(m_max)); + *box++ = min; + *box++ = max; +} + void SG_BBox::split(SG_BBox &left, SG_BBox &right) const { MT_Scalar sizex = m_max[0] - m_min[0]; diff --git a/source/gameengine/SceneGraph/SG_BBox.h b/source/gameengine/SceneGraph/SG_BBox.h index b7e8ff65865..c39ad268e25 100644 --- a/source/gameengine/SceneGraph/SG_BBox.h +++ b/source/gameengine/SceneGraph/SG_BBox.h @@ -122,6 +122,8 @@ public: */ void getaa(MT_Point3 *box, const MT_Transform &world) const; + void getmm(MT_Point3 *box, const MT_Transform &world) const; + void split(SG_BBox &left, SG_BBox &right) const; friend class SG_Tree; diff --git a/source/gameengine/SceneGraph/SG_IObject.cpp b/source/gameengine/SceneGraph/SG_IObject.cpp index d0bdac5c8f0..fbab4032a10 100644 --- a/source/gameengine/SceneGraph/SG_IObject.cpp +++ b/source/gameengine/SceneGraph/SG_IObject.cpp @@ -33,6 +33,8 @@ #include #endif +SG_Stage gSG_Stage = SG_STAGE_UNKNOWN; + SG_IObject:: SG_IObject( void* clientobj, diff --git a/source/gameengine/SceneGraph/SG_IObject.h b/source/gameengine/SceneGraph/SG_IObject.h index 7f6bdfbbb1c..9012b532059 100644 --- a/source/gameengine/SceneGraph/SG_IObject.h +++ b/source/gameengine/SceneGraph/SG_IObject.h @@ -31,6 +31,36 @@ #include +// used for debugging: stage of the game engine main loop at which a Scenegraph modification is done +enum SG_Stage +{ + SG_STAGE_UNKNOWN = 0, + SG_STAGE_NETWORK, + SG_STAGE_NETWORK_UPDATE, + SG_STAGE_PHYSICS1, + SG_STAGE_PHYSICS1_UPDATE, + SG_STAGE_CONTROLLER, + SG_STAGE_CONTROLLER_UPDATE, + SG_STAGE_ACTUATOR, + SG_STAGE_ACTUATOR_UPDATE, + SG_STAGE_PHYSICS2, + SG_STAGE_PHYSICS2_UPDATE, + SG_STAGE_SCENE, + SG_STAGE_RENDER, + SG_STAGE_CONVERTER, + SG_STAGE_CULLING, + SG_STAGE_MAX +}; + +extern SG_Stage gSG_Stage; + +inline void SG_SetActiveStage(SG_Stage stage) +{ + gSG_Stage = stage; +} + + + class SG_Controller; class SG_IObject; diff --git a/source/gameengine/SceneGraph/SG_Node.cpp b/source/gameengine/SceneGraph/SG_Node.cpp index 8de7ac83477..64d9019c86a 100644 --- a/source/gameengine/SceneGraph/SG_Node.cpp +++ b/source/gameengine/SceneGraph/SG_Node.cpp @@ -219,18 +219,19 @@ void SG_Node::RemoveChild(SG_Node* child) -void SG_Node::UpdateWorldData(double time) +void SG_Node::UpdateWorldData(double time, bool parentUpdated) { //if (!GetSGParent()) // return; - if (UpdateSpatialData(GetSGParent(),time)) + if (UpdateSpatialData(GetSGParent(),time,parentUpdated)) + // to update the ActivateUpdateTransformCallback(); // update children's worlddata for (NodeList::iterator it = m_children.begin();it!=m_children.end();++it) { - (*it)->UpdateWorldData(time); + (*it)->UpdateWorldData(time, parentUpdated); } } diff --git a/source/gameengine/SceneGraph/SG_Node.h b/source/gameengine/SceneGraph/SG_Node.h index ffaaad861e2..29943653a81 100644 --- a/source/gameengine/SceneGraph/SG_Node.h +++ b/source/gameengine/SceneGraph/SG_Node.h @@ -175,7 +175,8 @@ public: void UpdateWorldData( - double time + double time, + bool parentUpdated=false ); /** diff --git a/source/gameengine/SceneGraph/SG_ParentRelation.h b/source/gameengine/SceneGraph/SG_ParentRelation.h index 6507cb98519..8f45df09b27 100644 --- a/source/gameengine/SceneGraph/SG_ParentRelation.h +++ b/source/gameengine/SceneGraph/SG_ParentRelation.h @@ -69,7 +69,8 @@ public : bool UpdateChildCoordinates( SG_Spatial * child, - const SG_Spatial * parent + const SG_Spatial * parent, + bool& parentUpdated ) = 0; virtual diff --git a/source/gameengine/SceneGraph/SG_Spatial.cpp b/source/gameengine/SceneGraph/SG_Spatial.cpp index 99aeb3e72ee..2f3176816c6 100644 --- a/source/gameengine/SceneGraph/SG_Spatial.cpp +++ b/source/gameengine/SceneGraph/SG_Spatial.cpp @@ -55,7 +55,8 @@ SG_Spatial( m_parent_relation (NULL), m_bbox(MT_Point3(-1.0, -1.0, -1.0), MT_Point3(1.0, 1.0, 1.0)), - m_radius(1.0) + m_radius(1.0), + m_modified(true) { } @@ -101,6 +102,7 @@ SetParentRelation( ){ delete (m_parent_relation); m_parent_relation = relation; + m_modified = true; } @@ -114,7 +116,8 @@ SetParentRelation( SG_Spatial:: UpdateSpatialData( const SG_Spatial *parent, - double time + double time, + bool& parentUpdated ){ bool bComputesWorldTransform = false; @@ -135,14 +138,14 @@ UpdateSpatialData( // our world coordinates. if (!bComputesWorldTransform) - bComputesWorldTransform = ComputeWorldTransforms(parent); + bComputesWorldTransform = ComputeWorldTransforms(parent, parentUpdated); return bComputesWorldTransform; } -bool SG_Spatial::ComputeWorldTransforms(const SG_Spatial *parent) +bool SG_Spatial::ComputeWorldTransforms(const SG_Spatial *parent, bool& parentUpdated) { - return m_parent_relation->UpdateChildCoordinates(this,parent); + return m_parent_relation->UpdateChildCoordinates(this,parent,parentUpdated); } /** @@ -166,6 +169,7 @@ RelativeTranslate( m_localPosition += trans; } } + m_modified = true; } void @@ -174,6 +178,7 @@ SetLocalPosition( const MT_Point3& trans ){ m_localPosition = trans; + m_modified = true; } void @@ -194,6 +199,7 @@ RelativeScale( const MT_Vector3& scale ){ m_localScaling = m_localScaling * scale; + m_modified = true; } void @@ -202,6 +208,7 @@ SetLocalScale( const MT_Vector3& scale ){ m_localScaling = scale; + m_modified = true; } @@ -229,6 +236,7 @@ RelativeRotate( rot : (GetWorldOrientation().inverse() * rot * GetWorldOrientation())); + m_modified = true; } void @@ -236,6 +244,7 @@ SG_Spatial:: SetLocalOrientation(const MT_Matrix3x3& rot) { m_localRotation = rot; + m_modified = true; } diff --git a/source/gameengine/SceneGraph/SG_Spatial.h b/source/gameengine/SceneGraph/SG_Spatial.h index 6ccec2aa9c1..c2ed80d21b2 100644 --- a/source/gameengine/SceneGraph/SG_Spatial.h +++ b/source/gameengine/SceneGraph/SG_Spatial.h @@ -61,7 +61,7 @@ protected: SG_BBox m_bbox; MT_Scalar m_radius; - + bool m_modified; public: @@ -180,7 +180,7 @@ public: MT_Transform GetWorldTransform() const; - bool ComputeWorldTransforms( const SG_Spatial *parent); + bool ComputeWorldTransforms(const SG_Spatial *parent, bool& parentUpdated); /** * Bounding box functions. @@ -193,9 +193,14 @@ public: MT_Scalar Radius() const { return m_radius; } void SetRadius(MT_Scalar radius) { m_radius = radius; } + bool IsModified() { return m_modified; } protected: friend class SG_Controller; + friend class KX_BoneParentRelation; + friend class KX_VertexParentRelation; + friend class KX_SlowParentRelation; + friend class KX_NormalParentRelation; /** * Protected constructor this class is not @@ -223,8 +228,10 @@ protected: bool UpdateSpatialData( const SG_Spatial *parent, - double time + double time, + bool& parentUpdated ); + void SetModified(bool modified) { m_modified = modified; } }; -- cgit v1.2.3 From e063682ed3f8c7a9d6ead89371e3663feff4af3c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Apr 2009 23:21:30 +0000 Subject: gcc wouldn't compile using a reference --- source/gameengine/Ketsji/KX_MotionState.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_MotionState.cpp b/source/gameengine/Ketsji/KX_MotionState.cpp index 00d9a32eb38..b4d58dccfdf 100644 --- a/source/gameengine/Ketsji/KX_MotionState.cpp +++ b/source/gameengine/Ketsji/KX_MotionState.cpp @@ -60,7 +60,7 @@ void KX_MotionState::getWorldScaling(float& scaleX,float& scaleY,float& scaleZ) void KX_MotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal) { - MT_Quaternion& orn = m_node->GetWorldOrientation().getRotation(); + MT_Quaternion orn = m_node->GetWorldOrientation().getRotation(); quatIma0 = orn[0]; quatIma1 = orn[1]; quatIma2 = orn[2]; -- cgit v1.2.3 From 4b77f9504c7f468fe3b3e91ab503b09b5f1e1a9e Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 8 Apr 2009 08:22:03 +0000 Subject: Fixed scons and cmake after BGE scenegraph and culling improvements. --- source/gameengine/Physics/Bullet/CMakeLists.txt | 2 +- source/gameengine/Physics/Bullet/SConscript | 2 +- source/gameengine/Physics/common/CMakeLists.txt | 2 +- source/gameengine/Physics/common/SConscript | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Physics/Bullet/CMakeLists.txt b/source/gameengine/Physics/Bullet/CMakeLists.txt index 83b77db4efd..6bab9858011 100644 --- a/source/gameengine/Physics/Bullet/CMakeLists.txt +++ b/source/gameengine/Physics/Bullet/CMakeLists.txt @@ -24,7 +24,7 @@ # # ***** END GPL LICENSE BLOCK ***** -SET(SRC CcdPhysicsEnvironment.cpp CcdPhysicsController.cpp) +SET(SRC CcdPhysicsEnvironment.cpp CcdPhysicsController.cpp CcdGraphicController.cpp) SET(INC . diff --git a/source/gameengine/Physics/Bullet/SConscript b/source/gameengine/Physics/Bullet/SConscript index 868a4d66af0..f3b6549089d 100644 --- a/source/gameengine/Physics/Bullet/SConscript +++ b/source/gameengine/Physics/Bullet/SConscript @@ -1,7 +1,7 @@ #!/usr/bin/python Import ('env') -sources = 'CcdPhysicsEnvironment.cpp CcdPhysicsController.cpp' +sources = 'CcdPhysicsEnvironment.cpp CcdPhysicsController.cpp CcdGraphicController.cpp' incs = '. ../common #source/kernel/gen_system #intern/string #intern/moto/include #source/gameengine/Rasterizer #source/blender/makesdna' diff --git a/source/gameengine/Physics/common/CMakeLists.txt b/source/gameengine/Physics/common/CMakeLists.txt index a28fabe0c3a..41b2687fe38 100644 --- a/source/gameengine/Physics/common/CMakeLists.txt +++ b/source/gameengine/Physics/common/CMakeLists.txt @@ -24,7 +24,7 @@ # # ***** END GPL LICENSE BLOCK ***** -SET(SRC PHY_IMotionState.cpp PHY_IPhysicsController.cpp PHY_IPhysicsEnvironment.cpp PHY_IVehicle.cpp) +SET(SRC PHY_IMotionState.cpp PHY_IController.cpp PHY_IPhysicsController.cpp PHY_IGraphicController.cpp PHY_IPhysicsEnvironment.cpp PHY_IVehicle.cpp) SET(INC . diff --git a/source/gameengine/Physics/common/SConscript b/source/gameengine/Physics/common/SConscript index 474536e1f76..05c6f17a4a0 100644 --- a/source/gameengine/Physics/common/SConscript +++ b/source/gameengine/Physics/common/SConscript @@ -1,7 +1,7 @@ #!/usr/bin/python Import ('env') -sources = 'PHY_IMotionState.cpp PHY_IPhysicsController.cpp PHY_IPhysicsEnvironment.cpp PHY_IVehicle.cpp' +sources = 'PHY_IMotionState.cpp PHY_IController.cpp PHY_IPhysicsController.cpp PHY_IGraphicController.cpp PHY_IPhysicsEnvironment.cpp PHY_IVehicle.cpp' incs = '. ../Dummy #intern/moto/include' -- cgit v1.2.3 From 2074128fadbfd58ea13a68cbccaa1f6771bbd710 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 8 Apr 2009 15:06:20 +0000 Subject: Patch #18462: Fisheye (Dome) and Spherical Panoramic mode in BGE. User guide: http://wiki.blender.org/index.php/Dev:Source/GameEngine/Fisheye_Dome_Camera Fixed two bugs from original patch: - deleting a text will clear the warp field from Game framing settings - removed spurious black dots along the edge of the cube map in the gameplayer Known limitation: - resizing of the screen doesn't work in the gameplayer Known bugs: - Texture with reflexion are not rendered correctly - Spurious problems with light --- .../BlenderRoutines/BL_KetsjiEmbedStart.cpp | 4 + .../GamePlayer/ghost/GPG_Application.cpp | 5 + source/gameengine/Ketsji/KX_Dome.cpp | 1820 ++++++++++++++++++++ source/gameengine/Ketsji/KX_Dome.h | 183 ++ source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 127 +- source/gameengine/Ketsji/KX_KetsjiEngine.h | 9 + source/gameengine/Rasterizer/RAS_IRasterizer.h | 1 + .../RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp | 6 +- 8 files changed, 2151 insertions(+), 4 deletions(-) create mode 100644 source/gameengine/Ketsji/KX_Dome.cpp create mode 100644 source/gameengine/Ketsji/KX_Dome.h (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 1c91ad784ac..fee5a4ad899 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -373,6 +373,10 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, initVideoTexture(); #endif + //initialize Dome Settings + if(blscene->r.stereomode == RAS_IRasterizer::RAS_STEREO_DOME) + ketsjiengine->InitDome(blscene->r.domesize, blscene->r.domeres, blscene->r.domemode, blscene->r.domeangle, blscene->r.domeresbuf, blscene->r.dometext); + if (sceneconverter) { // convert and add scene diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index 3432d498981..6ff46ca8200 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -693,6 +693,11 @@ bool GPG_Application::startEngine(void) #ifdef WITH_FFMPEG initVideoTexture(); #endif + + //initialize Dome Settings + if(m_startScene->r.stereomode == RAS_IRasterizer::RAS_STEREO_DOME) + m_ketsjiengine->InitDome(m_startScene->r.domesize, m_startScene->r.domeres, m_startScene->r.domemode, m_startScene->r.domeangle, m_startScene->r.domeresbuf, m_startScene->r.dometext); + // 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/Ketsji/KX_Dome.cpp b/source/gameengine/Ketsji/KX_Dome.cpp new file mode 100644 index 00000000000..4ab0f93f687 --- /dev/null +++ b/source/gameengine/Ketsji/KX_Dome.cpp @@ -0,0 +1,1820 @@ +/* $Id$ +----------------------------------------------------------------------------- + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser 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, or go to +http://www.gnu.org/copyleft/lesser.txt. + +Contributor(s): Dalai Felinto + +This code is originally inspired on some of the ideas and codes from Paul Bourke. +Developed as part of a Research and Development project for SAT - La Société des arts technologiques. +----------------------------------------------------------------------------- +*/ + +#include "KX_Dome.h" + +#include +#include +#include + +#include "DNA_scene_types.h" +#include "RAS_CameraData.h" +#include "BLI_arithb.h" + +#include "GL/glew.h" +#include "GL/glu.h" + +// constructor +KX_Dome::KX_Dome ( + RAS_ICanvas* canvas, + /// rasterizer + RAS_IRasterizer* rasterizer, + /// render tools + RAS_IRenderTools* rendertools, + /// engine + KX_KetsjiEngine* engine, + + float size, //size for adjustments + short res, //resolution of the mesh + short mode, //mode - fisheye, truncated, warped, panoramic, ... + short angle, + float resbuf, //size adjustment of the buffer + struct Text* warptext + +): + m_canvas(canvas), + m_rasterizer(rasterizer), + m_rendertools(rendertools), + m_engine(engine), + m_drawingmode(engine->GetDrawType()), + m_size(size), + m_resolution(res), + m_mode(mode), + m_angle(angle), + m_resbuffer(resbuf), + canvaswidth(-1), canvasheight(-1), + dlistSupported(false) +{ + warp.usemesh = false; + + if (mode >= DOME_NUM_MODES) + m_mode = DOME_FISHEYE; + + if (warptext) // it there is a text data try to warp it + { + char *buf; + buf = txt_to_buf(warptext); + if (buf) + { + warp.usemesh = ParseWarpMesh(STR_String(buf)); + MEM_freeN(buf); + } + } + + //setting the viewport size + GLuint viewport[4]={0}; + glGetIntegerv(GL_VIEWPORT,(GLint *)viewport); + + SetViewPort(viewport); + + switch(m_mode){ + case DOME_FISHEYE: + if (m_angle <= 180){ + cubetop.resize(1); + cubebottom.resize(1); + cubeleft.resize(2); + cuberight.resize(2); + + CreateMeshDome180(); + m_numfaces = 4; + }else if (m_angle > 180){ + cubetop.resize(2); + cubebottom.resize(2); + cubeleft.resize(2); + cubefront.resize(2); + cuberight.resize(2); + + CreateMeshDome250(); + m_numfaces = 5; + } break; + case DOME_TRUNCATED: + cubetop.resize(1); + cubebottom.resize(1); + cubeleft.resize(2); + cuberight.resize(2); + + m_angle = 180; + CreateMeshDome180(); + m_numfaces = 4; + break; + case DOME_PANORAM_SPH: + cubeleft.resize(2); + cubeleftback.resize(2); + cuberight.resize(2); + cuberightback.resize(2); + cubetop.resize(2); + cubebottom.resize(2); + + m_angle = 360; + CreateMeshPanorama(); + m_numfaces = 6; + break; + } + + m_numimages =(warp.usemesh?m_numfaces+1:m_numfaces); + + CalculateCameraOrientation(); + + CreateGLImages(); + + dlistSupported = CreateDL(); +} + +// destructor +KX_Dome::~KX_Dome (void) +{ + GLuint m_numimages = m_numfaces; + + ClearGLImages(); + + if(dlistSupported) + glDeleteLists(dlistId, (GLsizei) m_numimages); +} + +void KX_Dome::SetViewPort(GLuint viewport[4]) +{ + if(canvaswidth != m_canvas->GetWidth() || canvasheight != m_canvas->GetHeight()) + { + m_viewport.SetLeft(viewport[0]); + m_viewport.SetBottom(viewport[1]); + m_viewport.SetRight(viewport[2]); + m_viewport.SetTop(viewport[3]); + + CalculateImageSize(); + } +} + +void KX_Dome::CreateGLImages(void) +{ + glGenTextures(m_numimages, (GLuint*)&domefacesId); + + for (int j=0;jGetWidth(); + canvasheight = m_canvas->GetHeight(); + + m_buffersize = (canvaswidth > canvasheight?canvasheight:canvaswidth); + m_buffersize *= m_resbuffer; //reduce buffer size for better performance + + int i = 0; + while ((1 << i) <= m_buffersize) + i++; + m_imagesize = (1 << i); + + if (warp.usemesh){ + warp.bufferwidth = canvaswidth; + warp.bufferheight = canvasheight; + + i = 0; + while ((1 << i) <= warp.bufferwidth) + i++; + warp.imagewidth = (1 << i); + + i = 0; + while ((1 << i) <= warp.bufferheight) + i++; + warp.imageheight = (1 << i); + } +} + +bool KX_Dome::CreateDL(){ + int i,j; + + dlistId = glGenLists((GLsizei) m_numimages); + if (dlistId != 0) { + if(m_mode == DOME_FISHEYE || m_mode == DOME_TRUNCATED){ + glNewList(dlistId, GL_COMPILE); + GLDrawTriangles(cubetop, nfacestop); + glEndList(); + + glNewList(dlistId+1, GL_COMPILE); + GLDrawTriangles(cubebottom, nfacesbottom); + glEndList(); + + glNewList(dlistId+2, GL_COMPILE); + GLDrawTriangles(cubeleft, nfacesleft); + glEndList(); + + glNewList(dlistId+3, GL_COMPILE); + GLDrawTriangles(cuberight, nfacesright); + glEndList(); + + if (m_angle > 180){ + glNewList(dlistId+4, GL_COMPILE); + GLDrawTriangles(cubefront, nfacesfront); + glEndList(); + } + } + else if (m_mode == DOME_PANORAM_SPH) + { + glNewList(dlistId, GL_COMPILE); + GLDrawTriangles(cubetop, nfacestop); + glEndList(); + + glNewList(dlistId+1, GL_COMPILE); + GLDrawTriangles(cubebottom, nfacesbottom); + glEndList(); + + glNewList(dlistId+2, GL_COMPILE); + GLDrawTriangles(cubeleft, nfacesleft); + glEndList(); + + glNewList(dlistId+3, GL_COMPILE); + GLDrawTriangles(cuberight, nfacesright); + glEndList(); + + glNewList(dlistId+4, GL_COMPILE); + GLDrawTriangles(cubeleftback, nfacesleftback); + glEndList(); + + glNewList(dlistId+5, GL_COMPILE); + GLDrawTriangles(cuberightback, nfacesrightback); + glEndList(); + } + + if(warp.usemesh){ + glNewList((dlistId + m_numfaces), GL_COMPILE); + GLDrawWarpQuads(); + glEndList(); + } + + //clearing the vectors + cubetop.clear(); + cubebottom.clear(); + cuberight.clear(); + cubeleft.clear(); + cubefront.clear(); + cubeleftback.clear(); + cuberightback.clear(); + warp.nodes.clear(); + + } else // genList failed + return false; + + return true; +} + +void KX_Dome::GLDrawTriangles(vector & face, int nfaces) +{ + int i,j; + glBegin(GL_TRIANGLES); + for (i=0;i columns, lines; + + lines = text.Explode('\n'); + if(lines.size() < 6){ + printf("Error: Warp Mesh File with insufficient data!\n"); + return false; + } + columns = lines[1].Explode(' '); + + if(columns.size() !=2){ + printf("Error: Warp Mesh File incorrect. The second line should contain: width height.\n"); + return false; + } + + warp.mode = atoi(lines[0]);// 1 = radial, 2 = fisheye + + warp.n_width = atoi(columns[0]); + warp.n_height = atoi(columns[1]); + + if (lines.size() < 2 + (warp.n_width * warp.n_height)){ + printf("Error: Warp Mesh File with insufficient data!\n"); + return false; + }else{ + warp.nodes = vector> (warp.n_height, vector(warp.n_width)); + + for(i=2; i-2 < (warp.n_width*warp.n_height); i++){ + columns = lines[i].Explode(' '); + + if (columns.size() == 5){ + nodeX = (i-2)%warp.n_width; + nodeY = ((i-2) - nodeX) / warp.n_width; + + warp.nodes[nodeY][nodeX].x = atof(columns[0]); + warp.nodes[nodeY][nodeX].y = atof(columns[1]); + warp.nodes[nodeY][nodeX].u = atof(columns[2]); + warp.nodes[nodeY][nodeX].v = atof(columns[3]); + warp.nodes[nodeY][nodeX].i = atof(columns[4]); + } + else{ + warp.nodes.clear(); + printf("Error: Warp Mesh File with wrong number of fields. You should use 5: x y u v i.\n"); + return false; + } + } + } + return true; +} + +void KX_Dome::CreateMeshDome180(void) +{ +/* +1)- Define the faces of half of a cube + - each face is made out of 2 triangles +2) Subdivide the faces + - more resolution == more curved lines +3) Spherize the cube + - normalize the verts +4) Flatten onto xz plane + - transform it onto an equidistant spherical projection techniques to transform the sphere onto a dome image +*/ + int i,j; + float sqrt_2 = sqrt(2.0); + float uv_ratio = (float)(m_buffersize-1) / m_imagesize; + + m_radangle = m_angle * M_PI/180.0;//calculates the radians angle, used for flattening + + //creating faces for the env mapcube 180º Dome + // Top Face - just a triangle + cubetop[0].verts[0][0] = -sqrt_2 / 2.0; + cubetop[0].verts[0][1] = 0.0; + cubetop[0].verts[0][2] = 0.5; + cubetop[0].u[0] = 0.0; + cubetop[0].v[0] = uv_ratio; + + cubetop[0].verts[1][0] = 0.0; + cubetop[0].verts[1][1] = sqrt_2 / 2.0; + cubetop[0].verts[1][2] = 0.5; + cubetop[0].u[1] = 0.0; + cubetop[0].v[1] = 0.0; + + cubetop[0].verts[2][0] = sqrt_2 / 2.0; + cubetop[0].verts[2][1] = 0.0; + cubetop[0].verts[2][2] = 0.5; + cubetop[0].u[2] = uv_ratio; + cubetop[0].v[2] = 0.0; + + nfacestop = 1; + + /* Bottom face - just a triangle */ + cubebottom[0].verts[0][0] = -sqrt_2 / 2.0; + cubebottom[0].verts[0][1] = 0.0; + cubebottom[0].verts[0][2] = -0.5; + cubebottom[0].u[0] = uv_ratio; + cubebottom[0].v[0] = 0.0; + + cubebottom[0].verts[1][0] = sqrt_2 / 2.0; + cubebottom[0].verts[1][1] = 0; + cubebottom[0].verts[1][2] = -0.5; + cubebottom[0].u[1] = 0.0; + cubebottom[0].v[1] = uv_ratio; + + cubebottom[0].verts[2][0] = 0.0; + cubebottom[0].verts[2][1] = sqrt_2 / 2.0; + cubebottom[0].verts[2][2] = -0.5; + cubebottom[0].u[2] = 0.0; + cubebottom[0].v[2] = 0.0; + + nfacesbottom = 1; + + /* Left face - two triangles */ + + cubeleft[0].verts[0][0] = -sqrt_2 / 2.0; + cubeleft[0].verts[0][1] = .0; + cubeleft[0].verts[0][2] = -0.5; + cubeleft[0].u[0] = 0.0; + cubeleft[0].v[0] = 0.0; + + cubeleft[0].verts[1][0] = 0.0; + cubeleft[0].verts[1][1] = sqrt_2 / 2.0; + cubeleft[0].verts[1][2] = -0.5; + cubeleft[0].u[1] = uv_ratio; + cubeleft[0].v[1] = 0.0; + + cubeleft[0].verts[2][0] = -sqrt_2 / 2.0; + cubeleft[0].verts[2][1] = 0.0; + cubeleft[0].verts[2][2] = 0.5; + cubeleft[0].u[2] = 0.0; + cubeleft[0].v[2] = uv_ratio; + + //second triangle + cubeleft[1].verts[0][0] = -sqrt_2 / 2.0; + cubeleft[1].verts[0][1] = 0.0; + cubeleft[1].verts[0][2] = 0.5; + cubeleft[1].u[0] = 0.0; + cubeleft[1].v[0] = uv_ratio; + + cubeleft[1].verts[1][0] = 0.0; + cubeleft[1].verts[1][1] = sqrt_2 / 2.0; + cubeleft[1].verts[1][2] = -0.5; + cubeleft[1].u[1] = uv_ratio; + cubeleft[1].v[1] = 0.0; + + cubeleft[1].verts[2][0] = 0.0; + cubeleft[1].verts[2][1] = sqrt_2 / 2.0; + cubeleft[1].verts[2][2] = 0.5; + cubeleft[1].u[2] = uv_ratio; + cubeleft[1].v[2] = uv_ratio; + + nfacesleft = 2; + + /* Right face - two triangles */ + cuberight[0].verts[0][0] = 0.0; + cuberight[0].verts[0][1] = sqrt_2 / 2.0; + cuberight[0].verts[0][2] = -0.5; + cuberight[0].u[0] = 0.0; + cuberight[0].v[0] = 0.0; + + cuberight[0].verts[1][0] = sqrt_2 / 2.0; + cuberight[0].verts[1][1] = 0.0; + cuberight[0].verts[1][2] = -0.5; + cuberight[0].u[1] = uv_ratio; + cuberight[0].v[1] = 0.0; + + cuberight[0].verts[2][0] = sqrt_2 / 2.0; + cuberight[0].verts[2][1] = 0.0; + cuberight[0].verts[2][2] = 0.5; + cuberight[0].u[2] = uv_ratio; + cuberight[0].v[2] = uv_ratio; + + //second triangle + cuberight[1].verts[0][0] = 0.0; + cuberight[1].verts[0][1] = sqrt_2 / 2.0; + cuberight[1].verts[0][2] = -0.5; + cuberight[1].u[0] = 0.0; + cuberight[1].v[0] = 0.0; + + cuberight[1].verts[1][0] = sqrt_2 / 2.0; + cuberight[1].verts[1][1] = 0.0; + cuberight[1].verts[1][2] = 0.5; + cuberight[1].u[1] = uv_ratio; + cuberight[1].v[1] = uv_ratio; + + cuberight[1].verts[2][0] = 0.0; + cuberight[1].verts[2][1] = sqrt_2 / 2.0; + cuberight[1].verts[2][2] = 0.5; + cuberight[1].u[2] = 0.0; + cuberight[1].v[2] = uv_ratio; + + nfacesright = 2; + + //Refine a triangular mesh by bisecting each edge forms 3 new triangles for each existing triangle on each iteration + //Could be made more efficient for drawing if the triangles were ordered in a fan. Not that important since we are using DisplayLists + + for(i=0;i 1.0){ + //round the border + verts[i][0] = cos(phi); + verts[i][1] = -3.0; + verts[i][2] = sin(phi); + } + } +} + +void KX_Dome::FlattenPanorama(MT_Vector3 verts[3]) +{ +// it creates a full spherical panoramic (360º) + int i; + double phi; + bool edge=false; + + for (i=0;i<3;i++){ + phi = atan2(verts[i][1], verts[i][0]); + phi *= -1.0; //flipping + + if (phi == -MT_PI) //It's on the edge + edge=true; + + verts[i][0] = phi / MT_PI; + verts[i][1] = 0; + + verts[i][2] = atan2(verts[i][2], 1.0); + verts[i][2] /= MT_PI / 2; + } + if(edge){ + bool right=false; + + for (i=0;i<3;i++){ + if(fmod(verts[i][0],1.0) > 0.0){ + right=true; + break; + } + } + if(right){ + for (i=0;i<3;i++){ + if(verts[i][0] < 0.0) + verts[i][0] *= -1.0; + } + } + } +} + +void KX_Dome::SplitFace(vector & face, int *nfaces) +{ + int i; + int n1, n2; + + n1 = n2 = *nfaces; + + for(i=0;iGetCameraNear(),cam->GetCameraFar()); + */ + + RAS_FrameFrustum m_frustrum; //90 deg. Frustum + + m_frustrum.camnear = cam->GetCameraNear(); + m_frustrum.camfar = cam->GetCameraFar(); + +// float top = tan(90.0*MT_PI/360.0) * m_frustrum.camnear; + float top = m_frustrum.camnear; // for deg = 90º, tan = 1 + + m_frustrum.x1 = -top; + m_frustrum.x2 = top; + m_frustrum.y1 = -top; + m_frustrum.y2 = top; + + m_projmat = m_rasterizer->GetFrustumMatrix( + m_frustrum.x1, m_frustrum.x2, m_frustrum.y1, m_frustrum.y2, m_frustrum.camnear, m_frustrum.camfar); + +} + +void KX_Dome::CalculateCameraOrientation() +{ +/* +Uses 4 cameras for angles up to 180º +Uses 5 cameras for angles up to 250º +Uses 6 cameras for angles up to 360º +*/ + float deg45 = MT_PI / 4; + MT_Scalar c = cos(deg45); + MT_Scalar s = sin(deg45); + + if ((m_mode == DOME_FISHEYE && m_angle <= 180)|| m_mode == DOME_TRUNCATED){ + + m_locRot[0] = MT_Matrix3x3( // 90º - Top + c, -s, 0.0, + 0.0,0.0, -1.0, + s, c, 0.0); + + m_locRot[1] = MT_Matrix3x3( // 90º - Bottom + -s, c, 0.0, + 0.0,0.0, 1.0, + s, c, 0.0); + + m_locRot[2] = MT_Matrix3x3( // 45º - Left + c, 0.0, s, + 0, 1.0, 0.0, + -s, 0.0, c); + + m_locRot[3] = MT_Matrix3x3( // 45º - Right + c, 0.0, -s, + 0.0, 1.0, 0.0, + s, 0.0, c); + + } else if ((m_mode == DOME_FISHEYE && m_angle > 180)){ + + m_locRot[0] = MT_Matrix3x3( // 90º - Top + 1.0, 0.0, 0.0, + 0.0, 0.0,-1.0, + 0.0, 1.0, 0.0); + + m_locRot[1] = MT_Matrix3x3( // 90º - Bottom + 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, + 0.0,-1.0, 0.0); + + m_locRot[2] = MT_Matrix3x3( // -90º - Left + 0.0, 0.0, 1.0, + 0.0, 1.0, 0.0, + -1.0, 0.0, 0.0); + + m_locRot[3] = MT_Matrix3x3( // 90º - Right + 0.0, 0.0,-1.0, + 0.0, 1.0, 0.0, + 1.0, 0.0, 0.0); + + m_locRot[4] = MT_Matrix3x3( // 0º - Front + 1.0, 0.0, 0.0, + 0.0, 1.0, 0.0, + 0.0, 0.0, 1.0); + + m_locRot[5] = MT_Matrix3x3( // 180º - Back - NOT USING + -1.0, 0.0, 0.0, + 0.0, 1.0, 0.0, + 0.0, 0.0,-1.0); + + } else if (m_mode == DOME_PANORAM_SPH){ + + m_locRot[0] = MT_Matrix3x3( // Top + c, s, 0.0, + 0.0,0.0, -1.0, + -s, c, 0.0); + + m_locRot[1] = MT_Matrix3x3( // Bottom + c, s, 0.0, + 0.0 ,0.0, 1.0, + s, -c, 0.0); + + m_locRot[2] = MT_Matrix3x3( // 45º - Left + -s, 0.0, c, + 0, 1.0, 0.0, + -c, 0.0, -s); + + m_locRot[3] = MT_Matrix3x3( // 45º - Right + c, 0.0, s, + 0, 1.0, 0.0, + -s, 0.0, c); + + m_locRot[4] = MT_Matrix3x3( // 135º - LeftBack + -s, 0.0, -c, + 0.0, 1.0, 0.0, + c, 0.0, -s); + + m_locRot[5] = MT_Matrix3x3( // 135º - RightBack + c, 0.0, -s, + 0.0, 1.0, 0.0, + s, 0.0, c); + } +} + +void KX_Dome::RotateCamera(KX_Camera* cam, int i) +{ +// I'm not using it, I'm doing inline calls for these commands +// but it's nice to have it here in case I need it + + MT_Matrix3x3 camori = cam->GetSGNode()->GetLocalOrientation(); + + cam->NodeSetLocalOrientation(camori*m_locRot[i]); + cam->NodeUpdateGS(0.f); + + MT_Transform camtrans(cam->GetWorldToCamera()); + MT_Matrix4x4 viewmat(camtrans); + m_rasterizer->SetViewMatrix(viewmat, cam->NodeGetWorldPosition(), + cam->GetCameraLocation(), cam->GetCameraOrientation()); + cam->SetModelviewMatrix(viewmat); + + // restore the original orientation + cam->NodeSetLocalOrientation(camori); + cam->NodeUpdateGS(0.f); +} + +void KX_Dome::Draw(void) +{ + + switch(m_mode){ + case DOME_FISHEYE: + DrawDomeFisheye(); + break; + case DOME_TRUNCATED: + DrawDomeFisheye(); + break; + case DOME_PANORAM_SPH: + DrawPanorama(); + break; + } + + if(warp.usemesh) + { + glBindTexture(GL_TEXTURE_2D, domefacesId[m_numfaces]); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_viewport.GetLeft(), m_viewport.GetBottom(), warp.bufferwidth, warp.bufferheight); + DrawDomeWarped(); + } +} + +void KX_Dome::DrawDomeFisheye(void) +{ + int i,j; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + // Making the viewport always square + + int can_width = m_viewport.GetRight(); + int can_height = m_viewport.GetTop(); + + float ortho_width, ortho_height; + + if (warp.usemesh) + glOrtho((-1.0), 1.0, (-1.0), 1.0, -20.0, 10.0); //stretch the image to reduce resolution lost + + else if(m_mode == DOME_TRUNCATED){ + ortho_width = 1.0; + ortho_height = 2 * ((float)can_height/can_width) - 1.0 ; + + ortho_width /= m_size; + ortho_height /= m_size; + + glOrtho((-ortho_width), ortho_width, (-ortho_height), ortho_width, -20.0, 10.0); + } else { + if (can_width < can_height){ + ortho_width = 1.0; + ortho_height = (float)can_height/can_width; + }else{ + ortho_width = (float)can_width/can_height; + ortho_height = 1.0; + } + + ortho_width /= m_size; + ortho_height /= m_size; + + glOrtho((-ortho_width), ortho_width, (-ortho_height), ortho_height, -20.0, 10.0); + } + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(0.0,-1.0,0.0, 0.0,0.0,0.0, 0.0,0.0,1.0); + + if(m_drawingmode == RAS_IRasterizer::KX_WIREFRAME) + glPolygonMode(GL_FRONT, GL_LINE); + else + glPolygonMode(GL_FRONT, GL_FILL); + + glShadeModel(GL_SMOOTH); + glDisable(GL_LIGHTING); + glDisable(GL_DEPTH_TEST); + + glEnable(GL_TEXTURE_2D); + glColor3f(1.0,1.0,1.0); + + if (dlistSupported){ + for(i=0;i 180){ + // front triangle + glBindTexture(GL_TEXTURE_2D, domefacesId[4]); + GLDrawTriangles(cubefront, nfacesfront); + } + } + glDisable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); +} + +void KX_Dome::DrawPanorama(void) +{ + int i,j; + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + // Making the viewport always square + + int can_width = m_viewport.GetRight(); + int can_height = m_viewport.GetTop(); + + float ortho_height = 1.0; + float ortho_width = 1.0; + + if (warp.usemesh) + glOrtho((-1.0), 1.0, (-0.5), 0.5, -20.0, 10.0); //stretch the image to reduce resolution lost + + else { + //using all the screen + if ((can_width / 2) <= (can_height)){ + ortho_width = 1.0; + ortho_height = (float)can_height/can_width; + }else{ + ortho_width = (float)can_width/can_height * 0.5; + ortho_height = 0.5; + } + + ortho_width /= m_size; + ortho_height /= m_size; + + glOrtho((-ortho_width), ortho_width, (-ortho_height), ortho_height, -20.0, 10.0); + } + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(0.0,-1.0,0.0, 0.0,0.0,0.0, 0.0,0.0,1.0); + + if(m_drawingmode == RAS_IRasterizer::KX_WIREFRAME) + glPolygonMode(GL_FRONT, GL_LINE); + else + glPolygonMode(GL_FRONT, GL_FILL); + + glShadeModel(GL_SMOOTH); + glDisable(GL_LIGHTING); + glDisable(GL_DEPTH_TEST); + + glEnable(GL_TEXTURE_2D); + glColor3f(1.0,1.0,1.0); + + if (dlistSupported){ + for(i=0;i (top) + glBindTexture(GL_TEXTURE_2D, domefacesId[0]); + GLDrawTriangles(cubetop, nfacestop); + + // domefacesId[5] => (bottom) + glBindTexture(GL_TEXTURE_2D, domefacesId[1]); + GLDrawTriangles(cubebottom, nfacesbottom); + + // domefacesId[1] => -45º (left) + glBindTexture(GL_TEXTURE_2D, domefacesId[2]); + GLDrawTriangles(cubeleft, nfacesleft); + + // domefacesId[2] => 45º (right) + glBindTexture(GL_TEXTURE_2D, domefacesId[3]); + GLDrawTriangles(cuberight, nfacesright); + + // domefacesId[0] => -135º (leftback) + glBindTexture(GL_TEXTURE_2D, domefacesId[4]); + GLDrawTriangles(cubeleftback, nfacesleftback); + + // domefacesId[3] => 135º (rightback) + glBindTexture(GL_TEXTURE_2D, domefacesId[5]); + GLDrawTriangles(cuberightback, nfacesrightback); + } + glDisable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); +} + +void KX_Dome::DrawDomeWarped(void) +{ + int i,j; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + // Making the viewport always square + int can_width = m_viewport.GetRight(); + int can_height = m_viewport.GetTop(); + + double screen_ratio = can_width/ (double) can_height; + screen_ratio /= m_size; + + glOrtho(-screen_ratio,screen_ratio,-1.0,1.0,-20.0,10.0); + + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(0.0, 0.0, 1.0, 0.0,0.0,0.0, 0.0,1.0,0.0); + + if(m_drawingmode == RAS_IRasterizer::KX_WIREFRAME) + glPolygonMode(GL_FRONT, GL_LINE); + else + glPolygonMode(GL_FRONT, GL_FILL); + + glShadeModel(GL_SMOOTH); + glDisable(GL_LIGHTING); + glDisable(GL_DEPTH_TEST); + + glEnable(GL_TEXTURE_2D); + glColor3f(1.0,1.0,1.0); + + + float uv_width = (float)(warp.bufferwidth-1) / warp.imagewidth; + float uv_height = (float)(warp.bufferheight-1) / warp.imageheight; + + if (dlistSupported){ + glBindTexture(GL_TEXTURE_2D, domefacesId[m_numfaces]); + glCallList(dlistId + m_numfaces); + } + else{ + glBindTexture(GL_TEXTURE_2D, domefacesId[m_numfaces]); + GLDrawWarpQuads(); + } + glDisable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); +} + +void KX_Dome::BindImages(int i) +{ + glBindTexture(GL_TEXTURE_2D, domefacesId[i]); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_viewport.GetLeft(), m_viewport.GetBottom(), m_buffersize, m_buffersize); +} + +void KX_Dome::RenderDomeFrame(KX_Scene* scene, KX_Camera* cam, int i) +{ + if (!cam) + return; + + m_canvas->SetViewPort(0,0,m_buffersize-1,m_buffersize-1); + +// m_rasterizer->SetAmbient(); + m_rasterizer->DisplayFog(); + + CalculateFrustum(cam); //calculates m_projmat + cam->SetProjectionMatrix(m_projmat); + m_rasterizer->SetProjectionMatrix(cam->GetProjectionMatrix()); +// Dome_RotateCamera(cam,i); + + MT_Matrix3x3 camori = cam->GetSGNode()->GetLocalOrientation(); + + cam->NodeSetLocalOrientation(camori*m_locRot[i]); + cam->NodeUpdateGS(0.f); + + MT_Transform camtrans(cam->GetWorldToCamera()); + MT_Matrix4x4 viewmat(camtrans); + m_rasterizer->SetViewMatrix(viewmat, cam->NodeGetWorldPosition(), + cam->GetCameraLocation(), cam->GetCameraOrientation()); + cam->SetModelviewMatrix(viewmat); + + scene->CalculateVisibleMeshes(m_rasterizer,cam); + scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools); + + // restore the original orientation + cam->NodeSetLocalOrientation(camori); + cam->NodeUpdateGS(0.f); +} \ No newline at end of file diff --git a/source/gameengine/Ketsji/KX_Dome.h b/source/gameengine/Ketsji/KX_Dome.h new file mode 100644 index 00000000000..de3360cd897 --- /dev/null +++ b/source/gameengine/Ketsji/KX_Dome.h @@ -0,0 +1,183 @@ +/* $Id$ +----------------------------------------------------------------------------- + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser 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, or go to +http://www.gnu.org/copyleft/lesser.txt. + +Contributor(s): Dalai Felinto + +This source uses some of the ideas and code from Paul Bourke. +Developed as part of a Research and Development project for SAT - La Société des arts technologiques. +----------------------------------------------------------------------------- +*/ + +#if !defined KX_DOME_H +#define KX_DOME_H + +#include "KX_Scene.h" +#include "KX_Camera.h" +#include "DNA_screen_types.h" +#include "RAS_ICanvas.h" +#include "RAS_IRasterizer.h" +#include "RAS_IRenderTools.h" +#include "KX_KetsjiEngine.h" + +#include +#include + +#include "MEM_guardedalloc.h" +#include "BKE_text.h" +//#include "BLI_blenlib.h" + +//Dome modes: limit hardcoded in buttons_scene.c +#define DOME_FISHEYE 1 +#define DOME_TRUNCATED 2 +#define DOME_PANORAM_SPH 3 +#define DOME_NUM_MODES 4 + + +/// class for render 3d scene +class KX_Dome +{ +public: + /// constructor + KX_Dome ( + RAS_ICanvas* m_canvas, + /// rasterizer + RAS_IRasterizer* m_rasterizer, + /// render tools + RAS_IRenderTools* m_rendertools, + /// engine + KX_KetsjiEngine* m_engine, + + float size, + short res, + short mode, + short angle, + float resbuf, + struct Text* warptext + ); + + /// destructor + virtual ~KX_Dome (void); + + //openGL checks: + bool dlistSupported; + + //openGL names: + GLuint domefacesId[7]; // ID of the images -- room for 7 images, using only 4 for 180º x 360º dome, 6 for panoramic and +1 for warp mesh + GLuint dlistId; // ID of the Display Lists of the images (used as an offset) + + typedef struct { + double u[3], v[3]; + MT_Vector3 verts[3]; //three verts + } DomeFace; + + //mesh warp functions + typedef struct { + double x, y, u, v, i; + } WarpMeshNode; + + struct { + bool usemesh; + int mode; + int n_width, n_height; //nodes width and height + int imagewidth, imageheight; + int bufferwidth, bufferheight; + vector > nodes; + } warp; + + bool ParseWarpMesh(STR_String text); + + vector cubetop, cubebottom, cuberight, cubeleft, cubefront, cubeback; //for fisheye + vector cubeleftback, cuberightback; //for panorama + + int nfacestop, nfacesbottom, nfacesleft, nfacesright, nfacesfront, nfacesback; + int nfacesleftback, nfacesrightback; + + int GetNumberRenders(){return m_numfaces;}; + + void RenderDome(void); + void RenderDomeFrame(KX_Scene* scene, KX_Camera* cam, int i); + void BindImages(int i); + + void SetViewPort(GLuint viewport[4]); + void CalculateFrustum(KX_Camera* cam); + void RotateCamera(KX_Camera* cam, int i); + + //Mesh Creating Functions + void CreateMeshDome180(void); + void CreateMeshDome250(void); + void CreateMeshPanorama(void); + + void SplitFace(vector & face, int *nfaces); + + void FlattenDome(MT_Vector3 verts[3]); + void FlattenPanorama(MT_Vector3 verts[3]); + + //Draw functions + void GLDrawTriangles(vector & face, int nfaces); + void GLDrawWarpQuads(void); + void Draw(void); + void DrawDomeFisheye(void); + void DrawPanorama(void); + void DrawDomeWarped(void); + + //setting up openGL + void CreateGLImages(void); + void ClearGLImages(void);//called on resize + bool CreateDL(void); //create Display Lists + void ClearDL(void); //remove Display Lists + + void CalculateCameraOrientation(); + void CalculateImageSize(); //set m_imagesize + + int canvaswidth; + int canvasheight; + +protected: + int m_drawingmode; + + int m_imagesize; + int m_buffersize; // canvas small dimension + int m_numfaces; // 4 to 6 depending on the kind of dome image + int m_numimages; //numfaces +1 if we have warp mesh + + float m_size; // size to adjust + short m_resolution; //resolution to tesselate the mesh + short m_mode; // the mode (truncated, warped, panoramic,...) + short m_angle; //the angle of the fisheye + float m_radangle; //the angle of the fisheye in radians + float m_resbuffer; //the resolution of the buffer + + RAS_Rect m_viewport; + + MT_Matrix4x4 m_projmat; + + MT_Matrix3x3 m_locRot [6];// the rotation matrix + + /// rendered scene + KX_Scene * m_scene; + + /// canvas + RAS_ICanvas* m_canvas; + /// rasterizer + RAS_IRasterizer* m_rasterizer; + /// render tools + RAS_IRenderTools* m_rendertools; + /// engine + KX_KetsjiEngine* m_engine; +}; + +#endif \ No newline at end of file diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 70ae0e4b937..e64ffa95161 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -55,6 +55,7 @@ #include "KX_Scene.h" #include "MT_CmMatrix4x4.h" #include "KX_Camera.h" +#include "KX_Dome.h" #include "KX_Light.h" #include "KX_PythonInit.h" #include "KX_PyConstraintBinding.h" @@ -144,6 +145,8 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system) m_stereo(false), m_curreye(0), + m_usedome(false), + m_logger(NULL), // Set up timing info display variables @@ -179,6 +182,8 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system) KX_KetsjiEngine::~KX_KetsjiEngine() { delete m_logger; + if(m_usedome) + delete m_dome; } @@ -256,7 +261,124 @@ void KX_KetsjiEngine::SetSceneConverter(KX_ISceneConverter* sceneconverter) m_sceneconverter = sceneconverter; } +void KX_KetsjiEngine::InitDome(float size, short res, short mode, short angle, float resbuf, struct Text* text) +{ + m_dome = new KX_Dome(m_canvas, m_rasterizer, m_rendertools,this, size, res, mode, angle, resbuf, text); + m_usedome = true; +} + +void KX_KetsjiEngine::RenderDome() +{ + GLuint viewport[4]={0}; + glGetIntegerv(GL_VIEWPORT,(GLint *)viewport); +// unsigned int m_viewport[4] = {viewport[0], viewport[1], viewport[2], viewport[3]}; + + m_dome->SetViewPort(viewport); + + KX_Scene* firstscene = *m_scenes.begin(); + const RAS_FrameSettings &framesettings = firstscene->GetFramingType(); + + m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true); + + // hiding mouse cursor each frame + // (came back when going out of focus and then back in again) + if (m_hideCursor) + m_canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE); + + // clear the entire game screen with the border color + // only once per frame + + m_canvas->BeginDraw(); + + // BeginFrame() sets the actual drawing area. You can use a part of the window + if (!BeginFrame()) + return; + + int n_renders=m_dome->GetNumberRenders();// usually 4 or 6 + KX_SceneList::iterator sceneit; + for (int i=0;iClearBuffer(RAS_ICanvas::COLOR_BUFFER|RAS_ICanvas::DEPTH_BUFFER); + for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++) + // for each scene, call the proceed functions + { + KX_Scene* scene = *sceneit; + KX_Camera* cam = scene->GetActiveCamera(); + + m_rendertools->BeginFrame(m_rasterizer); + // pass the scene's worldsettings to the rasterizer + SetWorldSettings(scene->GetWorldInfo()); + + // shadow buffers + if (i == 0){ + RenderShadowBuffers(scene); + scene->UpdateMeshTransformations();//I need to run it somewherelse, otherwise Im overrunning it + } + // Avoid drawing the scene with the active camera twice when it's viewport is enabled + if(cam && !cam->GetViewport()) + { + if (scene->IsClearingZBuffer()) + m_rasterizer->ClearDepthBuffer(); + + m_rendertools->SetAuxilaryClientInfo(scene); + + // do the rendering + m_dome->RenderDomeFrame(scene,cam, i); + } + + 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 + m_dome->RenderDomeFrame(scene, (*it),i); + } + + it++; + } + } + m_dome->BindImages(i); + } + +// m_dome->Dome_PostRender(scene, cam, stereomode); + m_canvas->EndFrame();//XXX do we really need that? + + m_canvas->SetViewPort(0, 0, m_canvas->GetWidth(), m_canvas->GetHeight()); + + if (m_overrideFrameColor) //XXX why do we want + { + // Do not use the framing bar color set in the Blender scenes + m_canvas->ClearColor( + m_overrideFrameColorR, + m_overrideFrameColorG, + m_overrideFrameColorB, + 1.0 + ); + } + else + { + // Use the framing bar color set in the Blender scenes + m_canvas->ClearColor( + framesettings.BarRed(), + framesettings.BarGreen(), + framesettings.BarBlue(), + 1.0 + ); + } + + m_dome->Draw(); + //run 2dfilters + EndFrame(); +} /** * Ketsji Init(), Initializes datastructures and converts data from @@ -631,6 +753,10 @@ else void KX_KetsjiEngine::Render() { + if(m_usedome){ + RenderDome(); + return; + } KX_Scene* firstscene = *m_scenes.begin(); const RAS_FrameSettings &framesettings = firstscene->GetFramingType(); @@ -1699,4 +1825,3 @@ void KX_KetsjiEngine::GetOverrideFrameColor(float& r, float& g, float& b) const } - diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h index 8516049f6d8..a8ccd6100d7 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.h +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h @@ -74,6 +74,7 @@ private: PyObject* m_pythondictionary; class SCA_IInputDevice* m_keyboarddevice; class SCA_IInputDevice* m_mousedevice; + class KX_Dome* m_dome; // dome stereo mode /** Lists of scenes scheduled to be removed at the end of the frame. */ std::set m_removingScenes; @@ -208,6 +209,12 @@ public: RAS_ICanvas* GetCanvas(){return m_canvas;}; RAS_IRenderTools* GetRenderTools(){return m_rendertools;}; + /// Dome functions + void InitDome(float size, short res, short mode, short angle, float resbuf, struct Text* text); + void EndDome(); + void RenderDome(); + bool m_usedome; + ///returns true if an update happened to indicate -> Render bool NextFrame(); void Render(); @@ -234,6 +241,8 @@ public: void GetSceneViewport(KX_Scene* scene, KX_Camera* cam, RAS_Rect& area, RAS_Rect& viewport); void SetDrawType(int drawingtype); + int GetDrawType(){return m_drawingmode;}; + void SetCameraZoom(float camzoom); void EnableCameraOverride(const STR_String& forscene); diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h index 83adcfd8321..cfeda06e670 100644 --- a/source/gameengine/Rasterizer/RAS_IRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h @@ -113,6 +113,7 @@ public: RAS_STEREO_ANAGLYPH, RAS_STEREO_SIDEBYSIDE, RAS_STEREO_VINTERLACE, + RAS_STEREO_DOME, RAS_STEREO_MAXSTEREO }; diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 765ff0174ee..1a9a28916de 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -436,7 +436,7 @@ RAS_IRasterizer::StereoMode RAS_OpenGLRasterizer::GetStereoMode() bool RAS_OpenGLRasterizer::Stereo() { - if(m_stereomode == RAS_STEREO_NOSTEREO) + if(m_stereomode == RAS_STEREO_NOSTEREO || m_stereomode == RAS_STEREO_DOME) return false; else return true; @@ -803,7 +803,7 @@ MT_Matrix4x4 RAS_OpenGLRasterizer::GetFrustumMatrix( double mat[16]; // correction for stereo - if(m_stereomode != RAS_STEREO_NOSTEREO) + if(Stereo()) { float near_div_focallength; // next 2 params should be specified on command line and in Blender publisher @@ -846,7 +846,7 @@ void RAS_OpenGLRasterizer::SetViewMatrix(const MT_Matrix4x4 &mat, const MT_Vecto m_viewmatrix = mat; // correction for stereo - if(m_stereomode != RAS_STEREO_NOSTEREO) + if(Stereo()) { MT_Matrix3x3 camOrientMat3x3(camOrientQuat); MT_Vector3 unitViewDir(0.0, -1.0, 0.0); // minus y direction, Blender convention -- cgit v1.2.3 From 370850146f5ab1af11ec3a28abd1bad2f60314a4 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 8 Apr 2009 16:25:00 +0000 Subject: BGE patch #18051: add localInertia attribute to GameObject. --- .../Ketsji/KX_BulletPhysicsController.cpp | 14 ++++++++++++++ .../gameengine/Ketsji/KX_BulletPhysicsController.h | 1 + source/gameengine/Ketsji/KX_GameObject.cpp | 22 ++++++++++++++++++++-- source/gameengine/Ketsji/KX_GameObject.h | 8 ++++++++ source/gameengine/Ketsji/KX_IPhysicsController.h | 1 + .../gameengine/Ketsji/KX_SumoPhysicsController.cpp | 5 +++++ .../gameengine/Ketsji/KX_SumoPhysicsController.h | 1 + source/gameengine/PyDoc/KX_GameObject.py | 4 +++- 8 files changed, 53 insertions(+), 3 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp index 435b2b5db19..c621f11994a 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp @@ -162,6 +162,20 @@ MT_Scalar KX_BulletPhysicsController::GetMass() } +MT_Vector3 KX_BulletPhysicsController::GetLocalInertia() +{ + MT_Vector3 inertia(0.f, 0.f, 0.f); + btVector3 inv_inertia; + if (GetRigidBody()) { + inv_inertia = GetRigidBody()->getInvInertiaDiagLocal(); + if (!btFuzzyZero(inv_inertia.getX()) && + !btFuzzyZero(inv_inertia.getY()) && + !btFuzzyZero(inv_inertia.getZ())) + inertia = MT_Vector3(1.f/inv_inertia.getX(), 1.f/inv_inertia.getY(), 1.f/inv_inertia.getZ()); + } + return inertia; +} + MT_Scalar KX_BulletPhysicsController::GetRadius() { return MT_Scalar(CcdPhysicsController::GetRadius()); diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.h b/source/gameengine/Ketsji/KX_BulletPhysicsController.h index 44fbde7054e..9821b3fd253 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.h +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.h @@ -42,6 +42,7 @@ public: virtual void setScaling(const MT_Vector3& scaling); virtual MT_Scalar GetMass(); virtual void SetMass(MT_Scalar newmass); + virtual MT_Vector3 GetLocalInertia(); 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 339a955702a..ea53ffea48f 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -772,6 +772,16 @@ MT_Scalar KX_GameObject::GetMass() return 0.0; } +MT_Vector3 KX_GameObject::GetLocalInertia() +{ + MT_Vector3 local_inertia(0.0,0.0,0.0); + if (m_pPhysicsController1) + { + local_inertia = m_pPhysicsController1->GetLocalInertia(); + } + return local_inertia; +} + MT_Vector3 KX_GameObject::GetLinearVelocity(bool local) { MT_Vector3 velocity(0.0,0.0,0.0), locvel; @@ -1050,6 +1060,7 @@ PyAttributeDef KX_GameObject::Attributes[] = { KX_PYATTRIBUTE_RW_FUNCTION("mass", KX_GameObject, pyattr_get_mass, pyattr_set_mass), KX_PYATTRIBUTE_RW_FUNCTION("visible", KX_GameObject, pyattr_get_visible, pyattr_set_visible), KX_PYATTRIBUTE_RW_FUNCTION("position", KX_GameObject, pyattr_get_position, pyattr_set_position), + KX_PYATTRIBUTE_RO_FUNCTION("localInertia", KX_GameObject, pyattr_get_localInertia), KX_PYATTRIBUTE_RW_FUNCTION("orientation",KX_GameObject,pyattr_get_orientation,pyattr_set_orientation), KX_PYATTRIBUTE_RW_FUNCTION("scaling", KX_GameObject, pyattr_get_scaling, pyattr_set_scaling), KX_PYATTRIBUTE_RW_FUNCTION("timeOffset",KX_GameObject, pyattr_get_timeOffset,pyattr_set_timeOffset), @@ -1305,6 +1316,15 @@ int KX_GameObject::pyattr_set_position(void *self_v, const KX_PYATTRIBUTE_DEF *a return 0; } +PyObject* KX_GameObject::pyattr_get_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + if (self->GetPhysicsController()) + { + return PyObjectFrom(self->GetPhysicsController()->GetLocalInertia()); + } + Py_RETURN_NONE; +} PyObject* KX_GameObject::pyattr_get_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { @@ -1722,8 +1742,6 @@ PyObject* KX_GameObject::PyGetMass(PyObject* self) return PyFloat_FromDouble((GetPhysicsController() != NULL) ? GetPhysicsController()->GetMass() : 0.0f); } - - PyObject* KX_GameObject::PyGetReactionForce(PyObject* self) { // only can get the velocity if we have a physics object connected to us... diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 9c7dda5e394..08cc3031479 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -281,6 +281,12 @@ public: MT_Scalar GetMass(); + /** + * Return the local inertia vector of the object + */ + MT_Vector3 + GetLocalInertia(); + /** * Return the angular velocity of the game object. */ @@ -820,6 +826,8 @@ public: static int pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); diff --git a/source/gameengine/Ketsji/KX_IPhysicsController.h b/source/gameengine/Ketsji/KX_IPhysicsController.h index 13501f1fbbd..b7603203241 100644 --- a/source/gameengine/Ketsji/KX_IPhysicsController.h +++ b/source/gameengine/Ketsji/KX_IPhysicsController.h @@ -79,6 +79,7 @@ public: virtual void setScaling(const MT_Vector3& scaling)=0; virtual MT_Scalar GetMass()=0; virtual void SetMass(MT_Scalar newmass)=0; + virtual MT_Vector3 GetLocalInertia()=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_SumoPhysicsController.cpp b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp index 7631ee05b0b..fc053f05e63 100644 --- a/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp @@ -209,6 +209,11 @@ void KX_SumoPhysicsController::SetMass(MT_Scalar newmass) { } +MT_Vector3 KX_SumoPhysicsController::GetLocalInertia() +{ + return MT_Vector3(0.f, 0.f, 0.f); // \todo +} + 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 46c8ba6df45..8762612eca2 100644 --- a/source/gameengine/Ketsji/KX_SumoPhysicsController.h +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.h @@ -88,6 +88,7 @@ public: virtual void setScaling(const MT_Vector3& scaling); virtual MT_Scalar GetMass(); virtual void SetMass(MT_Scalar newmass); + virtual MT_Vector3 GetLocalInertia(); virtual MT_Scalar GetRadius(); virtual MT_Vector3 getReactionForce(); virtual void setRigidBody(bool rigid); diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index 97f6dab52bf..42656503384 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -16,8 +16,10 @@ class KX_GameObject: # (SCA_IObject) @ivar name: The object's name. (Read only) - note: Currently (Blender 2.49) the prefix "OB" is added to all objects name. This may change in blender 2.5. @type name: string. - @ivar mass: The object's mass (provided the object has a physics controller). Read only. + @ivar mass: The object's mass (provided the object has a physics controller). @type mass: float + @ivar localInertia: the object's inertia vector in local coordinates. Read only. + @type localInertia: list [ix, iy, iz] @ivar parent: The object's parent object. (Read only) @type parent: L{KX_GameObject} or None @ivar visible: visibility flag. -- cgit v1.2.3 From db33320df7f4db6480a15502baecaafefc1be63d Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 8 Apr 2009 16:57:08 +0000 Subject: BGE patch #18350: Add sendMessage() to GameLogic. Added sendMessage to both GameLogic and KX_GameObject. --- source/gameengine/Ketsji/KX_GameObject.cpp | 24 +++++++++++++++++++++++- source/gameengine/Ketsji/KX_GameObject.h | 2 +- source/gameengine/Ketsji/KX_PythonInit.cpp | 25 +++++++++++++++++++++++++ source/gameengine/Network/NG_NetworkScene.h | 5 +++++ source/gameengine/PyDoc/GameLogic.py | 13 +++++++++++++ source/gameengine/PyDoc/KX_GameObject.py | 11 +++++++++++ 6 files changed, 78 insertions(+), 2 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index ea53ffea48f..5085b52adda 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -66,6 +66,7 @@ typedef unsigned long uint_ptr; #include "SCA_IActuator.h" #include "SCA_ISensor.h" #include "SCA_IController.h" +#include "NG_NetworkScene.h" //Needed for sendMessage() #include "PyObjectPlus.h" /* python stuff */ @@ -1039,7 +1040,8 @@ PyMethodDef KX_GameObject::Methods[] = { KX_PYMETHODTABLE(KX_GameObject, rayCast), KX_PYMETHODTABLE_O(KX_GameObject, getDistanceTo), KX_PYMETHODTABLE_O(KX_GameObject, getVectTo), - + KX_PYMETHODTABLE(KX_GameObject, sendMessage), + // deprecated {"getPosition", (PyCFunction) KX_GameObject::sPyGetPosition, METH_NOARGS}, {"setPosition", (PyCFunction) KX_GameObject::sPySetPosition, METH_O}, @@ -2335,6 +2337,26 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, return Py_BuildValue("OOO", Py_None, Py_None, Py_None); } +KX_PYMETHODDEF_DOC_VARARGS(KX_GameObject, sendMessage, + "sendMessage(subject, [body, to])\n" +"sends a message in same manner as a message actuator" +"subject = Subject of the message (string)" +"body = Message body (string)" +"to = Name of object to send the message to") +{ + char* subject; + char* body = ""; + char* to = ""; + const STR_String& from = GetName(); + + if (!PyArg_ParseTuple(args, "s|sss", &subject, &body, &to)) + return NULL; + + KX_GetActiveScene()->GetNetworkScene()->SendMessage(to, from, subject, body); + + Py_RETURN_NONE; +} + /* --------------------------------------------------------------------- * Some stuff taken from the header * --------------------------------------------------------------------- */ diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 08cc3031479..f4d35faaeb6 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -815,7 +815,7 @@ public: KX_PYMETHOD_DOC(KX_GameObject,rayCast); KX_PYMETHOD_DOC_O(KX_GameObject,getDistanceTo); KX_PYMETHOD_DOC_O(KX_GameObject,getVectTo); - + KX_PYMETHOD_DOC_VARARGS(KX_GameObject, sendMessage); /* attributes */ static PyObject* pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_parent(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 15397085b4a..57c84050397 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -67,6 +67,8 @@ #include "KX_Scene.h" #include "SND_DeviceManager.h" +#include "NG_NetworkScene.h" //Needed for sendMessage() + #include "BL_Shader.h" #include "KX_PyMath.h" @@ -167,6 +169,28 @@ static PyObject* gPyExpandPath(PyObject*, PyObject* args) return PyString_FromString(expanded); } +static char gPySendMessage_doc[] = +"sendMessage(subject, [body, to, from])\n\ +sends a message in same manner as a message actuator\ +subject = Subject of the message\ +body = Message body\ +to = Name of object to send the message to\ +from = Name of object to sned the string from"; + +static PyObject* gPySendMessage(PyObject*, PyObject* args) +{ + char* subject; + char* body = ""; + char* to = ""; + char* from = ""; + + if (!PyArg_ParseTuple(args, "s|sss", &subject, &body, &to, &from)) + return NULL; + + gp_KetsjiScene->GetNetworkScene()->SendMessage(to, from, subject, body); + + Py_RETURN_NONE; +} static bool usedsp = false; @@ -436,6 +460,7 @@ static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *) static struct PyMethodDef game_methods[] = { {"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, (PY_METHODCHAR)gPyExpandPath_doc}, + {"sendMessage", (PyCFunction)gPySendMessage, METH_VARARGS, (PY_METHODCHAR)gPySendMessage_doc}, {"getCurrentController", (PyCFunction) SCA_PythonController::sPyGetCurrentController, METH_NOARGS, (PY_METHODCHAR)SCA_PythonController::sPyGetCurrentController__doc__}, diff --git a/source/gameengine/Network/NG_NetworkScene.h b/source/gameengine/Network/NG_NetworkScene.h index 58de9cf6af2..fc6367c3526 100644 --- a/source/gameengine/Network/NG_NetworkScene.h +++ b/source/gameengine/Network/NG_NetworkScene.h @@ -34,6 +34,11 @@ #include "STR_HashedString.h" #include +//MSVC defines SendMessage as a win api function, even though we aren't using it +#ifdef SendMessage + #undef SendMessage +#endif + class NG_NetworkDeviceInterface; class NG_NetworkScene diff --git a/source/gameengine/PyDoc/GameLogic.py b/source/gameengine/PyDoc/GameLogic.py index da394288e25..29d1b64350a 100644 --- a/source/gameengine/PyDoc/GameLogic.py +++ b/source/gameengine/PyDoc/GameLogic.py @@ -205,6 +205,19 @@ def addActiveActuator(actuator, activate): @type activate: boolean @param activate: whether to activate or deactivate the given actuator. """ +def sendMessage(subject, body="", to="", from=""): + """ + Sends a message. + + @param subject: The subject of the message + @type subject: string + @param body: The body of the message (optional) + @type body: string + @param to: The name of the object to send the message to (optional) + @type to: string + @param from: The name of the object that the message is coming from (optional) + @type from: string + """ def getRandomFloat(): """ Returns a random floating point value in the range [0...1) diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index 42656503384..fb1e099e575 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -453,3 +453,14 @@ class KX_GameObject: # (SCA_IObject) @type margin: float @param margin: the collision margin distance in blender units. """ + def sendMessage(subject, body="", to=""): + """ + Sends a message. + + @param subject: The subject of the message + @type subject: string + @param body: The body of the message (optional) + @type body: string + @param to: The name of the object to send the message to (optional) + @type to: string + """ -- cgit v1.2.3 From 1ee970e03bb6395ed0c0e884826a8e08b91e97bf Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 8 Apr 2009 17:40:09 +0000 Subject: small bge edits - Only try and remove light objects from the light list. - Only loop over mesh verts once when getting the bounding box - dont return None from python attribute localInertia when theres no physics objects. better return a vector still. - add names to send message PyArg_ParseTuple functions. --- .../gameengine/Converter/BL_BlenderDataConversion.cpp | 18 ++++++++++-------- source/gameengine/Ketsji/KX_GameObject.cpp | 4 ++-- source/gameengine/Ketsji/KX_PythonInit.cpp | 2 +- source/gameengine/Ketsji/KX_Scene.cpp | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 3c77f122758..50a660e77c9 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -1120,6 +1120,7 @@ static float my_boundbox_mesh(Mesh *me, float *loc, float *size) BoundBox *bb; MT_Point3 min, max; float mloc[3], msize[3]; + float radius=0.0f, vert_radius, *co; int a; if(me->bb==0) me->bb= (struct BoundBox *)MEM_callocN(sizeof(BoundBox), "boundbox"); @@ -1132,7 +1133,15 @@ static float my_boundbox_mesh(Mesh *me, float *loc, float *size) mvert= me->mvert; for(a=0; atotvert; a++, mvert++) { - DO_MINMAX(mvert->co, min, max); + co= mvert->co; + + /* bounds */ + DO_MINMAX(co, min, max); + + /* radius */ + vert_radius= co[0]*co[0] + co[1]*co[1] + co[2]*co[2]; + if (vert_radius > radius) + radius= vert_radius; } if(me->totvert) { @@ -1158,13 +1167,6 @@ static float my_boundbox_mesh(Mesh *me, float *loc, float *size) bb->vec[0][2]=bb->vec[3][2]=bb->vec[4][2]=bb->vec[7][2]= loc[2]-size[2]; bb->vec[1][2]=bb->vec[2][2]=bb->vec[5][2]=bb->vec[6][2]= loc[2]+size[2]; - float radius = 0; - for (a=0, mvert = me->mvert; a < me->totvert; a++, mvert++) - { - float vert_radius = MT_Vector3(mvert->co).length2(); - if (vert_radius > radius) - radius = vert_radius; - } return sqrt(radius); } diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 5085b52adda..13e839d9d2e 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1325,7 +1325,7 @@ PyObject* KX_GameObject::pyattr_get_localInertia(void *self_v, const KX_PYATTRIB { return PyObjectFrom(self->GetPhysicsController()->GetLocalInertia()); } - Py_RETURN_NONE; + return Py_BuildValue("fff", 0.0f, 0.0f, 0.0f); } PyObject* KX_GameObject::pyattr_get_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) @@ -2349,7 +2349,7 @@ KX_PYMETHODDEF_DOC_VARARGS(KX_GameObject, sendMessage, char* to = ""; const STR_String& from = GetName(); - if (!PyArg_ParseTuple(args, "s|sss", &subject, &body, &to)) + if (!PyArg_ParseTuple(args, "s|sss:sendMessage", &subject, &body, &to)) return NULL; KX_GetActiveScene()->GetNetworkScene()->SendMessage(to, from, subject, body); diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 57c84050397..8302855577d 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -184,7 +184,7 @@ static PyObject* gPySendMessage(PyObject*, PyObject* args) char* to = ""; char* from = ""; - if (!PyArg_ParseTuple(args, "s|sss", &subject, &body, &to, &from)) + if (!PyArg_ParseTuple(args, "s|sss:sendMessage", &subject, &body, &to, &from)) return NULL; gp_KetsjiScene->GetNetworkScene()->SendMessage(to, from, subject, body); diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 7eed1cc387b..0bd7d7270e1 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -956,7 +956,7 @@ int KX_Scene::NewRemoveObject(class CValue* gameobj) newobj->RemoveMeshes(); ret = 1; - if (m_lightlist->RemoveValue(newobj)) // TODO - use newobj->IsLight() test when its merged in from apricot. - Campbell + if (newobj->IsLight() && m_lightlist->RemoveValue(newobj)) ret = newobj->Release(); if (m_objectlist->RemoveValue(newobj)) ret = newobj->Release(); -- cgit v1.2.3 From 24f1355d4f7d1121b4a1dd209ce86f9ce4aa5561 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 8 Apr 2009 20:10:27 +0000 Subject: Fix gcc compiling problem with C++ syntax in KX_Dome.cpp. --- source/gameengine/Ketsji/KX_Dome.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_Dome.cpp b/source/gameengine/Ketsji/KX_Dome.cpp index 4ab0f93f687..0324b08beab 100644 --- a/source/gameengine/Ketsji/KX_Dome.cpp +++ b/source/gameengine/Ketsji/KX_Dome.cpp @@ -442,7 +442,7 @@ i ranges from 0 to 1, if negative don't draw that mesh node printf("Error: Warp Mesh File with insufficient data!\n"); return false; }else{ - warp.nodes = vector> (warp.n_height, vector(warp.n_width)); + warp.nodes = vector > (warp.n_height, vector(warp.n_width)); for(i=2; i-2 < (warp.n_width*warp.n_height); i++){ columns = lines[i].Explode(' '); -- cgit v1.2.3 From 5b0d75e831d891015b82dcc3d30856125c7b913e Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 8 Apr 2009 21:40:55 +0000 Subject: BGE API cleanup: 2DFilterActuator. --- .../gameengine/GameLogic/SCA_2DFilterActuator.cpp | 64 ++++++++++++++++++---- source/gameengine/GameLogic/SCA_2DFilterActuator.h | 35 +++++++++++- source/gameengine/Ketsji/KX_PythonInit.cpp | 21 ++++++- source/gameengine/PyDoc/SCA_2DFilterActuator.py | 44 +++++++++++++++ 4 files changed, 150 insertions(+), 14 deletions(-) create mode 100644 source/gameengine/PyDoc/SCA_2DFilterActuator.py (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp index 9d4dc1f33d6..171d3fbc265 100644 --- a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp +++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp @@ -1,5 +1,29 @@ -#include "SCA_IActuator.h" +/** + * SCA_2DFilterActuator.cpp + * + * $Id$ + * + * ***** 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. + * + * + * ***** END GPL LICENSE BLOCK ***** + */ +#include "SCA_IActuator.h" #include "SCA_2DFilterActuator.h" #ifdef HAVE_CONFIG_H @@ -22,7 +46,7 @@ SCA_2DFilterActuator::SCA_2DFilterActuator( PyTypeObject* T) : SCA_IActuator(gameobj, T), m_type(type), - m_flag(flag), + m_disableMotionBlur(flag), m_float_arg(float_arg), m_int_arg(int_arg), m_rasterizer(rasterizer), @@ -35,12 +59,6 @@ SCA_2DFilterActuator::SCA_2DFilterActuator( } } -void SCA_2DFilterActuator::SetShaderText(STR_String text) -{ - m_shaderText = text; -} - - CValue* SCA_2DFilterActuator::GetReplica() { @@ -63,7 +81,7 @@ bool SCA_2DFilterActuator::Update() if( m_type == RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR ) { - if(!m_flag) + if(!m_disableMotionBlur) m_rasterizer->EnableMotionBlur(m_float_arg); else m_rasterizer->DisableMotionBlur(); @@ -79,6 +97,18 @@ bool SCA_2DFilterActuator::Update() } +void SCA_2DFilterActuator::SetShaderText(STR_String text) +{ + m_shaderText = text; +} + +/* ------------------------------------------------------------------------- */ +/* Python functions */ +/* ------------------------------------------------------------------------- */ + + + +/* Integration hooks ------------------------------------------------------- */ PyTypeObject SCA_2DFilterActuator::Type = { PyObject_HEAD_INIT(NULL) 0, @@ -109,14 +139,26 @@ PyParentObject SCA_2DFilterActuator::Parents[] = { PyMethodDef SCA_2DFilterActuator::Methods[] = { - /* add python functions to deal with m_msg... */ + /* add python functions to deal with m_msg... */ {NULL,NULL} }; PyAttributeDef SCA_2DFilterActuator::Attributes[] = { + KX_PYATTRIBUTE_STRING_RW("shaderText", 0, 64000, false, SCA_2DFilterActuator, m_shaderText), + KX_PYATTRIBUTE_SHORT_RW("disableMotionBlur", 0, 1, true, SCA_2DFilterActuator, m_disableMotionBlur), + KX_PYATTRIBUTE_ENUM_RW("type",RAS_2DFilterManager::RAS_2DFILTER_ENABLED,RAS_2DFilterManager::RAS_2DFILTER_NUMBER_OF_FILTERS,false,SCA_2DFilterActuator,m_type), + KX_PYATTRIBUTE_INT_RW("passNb", 0, 100, true, SCA_2DFilterActuator, m_int_arg), + KX_PYATTRIBUTE_FLOAT_RW("value", 0.0, 100.0, SCA_2DFilterActuator, m_float_arg), { NULL } //Sentinel }; -PyObject* SCA_2DFilterActuator::py_getattro(PyObject *attr) { +PyObject* SCA_2DFilterActuator::py_getattro(PyObject *attr) +{ py_getattro_up(SCA_IActuator); } + +int SCA_2DFilterActuator::py_setattro(PyObject *attr, PyObject* value) +{ + py_setattro_up(SCA_IActuator); +} + diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.h b/source/gameengine/GameLogic/SCA_2DFilterActuator.h index f69c680b774..de0201a4b19 100644 --- a/source/gameengine/GameLogic/SCA_2DFilterActuator.h +++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.h @@ -1,3 +1,30 @@ +/** + * SCA_2DFilterActuator.h + * + * $Id$ + * + * ***** 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. + * + * ***** END GPL LICENSE BLOCK ***** + */ + #ifndef __SCA_2DFILETRACTUATOR_H__ #define __SCA_2DFILETRACTUATOR_H__ @@ -13,7 +40,7 @@ private: vector m_propNames; void * m_gameObj; RAS_2DFilterManager::RAS_2DFILTER_MODE m_type; - short m_flag; + short m_disableMotionBlur; float m_float_arg; int m_int_arg; STR_String m_shaderText; @@ -38,7 +65,13 @@ public: virtual bool Update(); virtual CValue* GetReplica(); + + /* --------------------------------------------------------------------- */ + /* Python interface ---------------------------------------------------- */ + /* --------------------------------------------------------------------- */ + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject* value); }; #endif diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 8302855577d..88aa042f502 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -61,6 +61,7 @@ #include "RAS_IRasterizer.h" #include "RAS_ICanvas.h" #include "RAS_BucketManager.h" +#include "RAS_2DFilterManager.h" #include "MT_Vector3.h" #include "MT_Point3.h" #include "ListValue.h" @@ -184,7 +185,7 @@ static PyObject* gPySendMessage(PyObject*, PyObject* args) char* to = ""; char* from = ""; - if (!PyArg_ParseTuple(args, "s|sss:sendMessage", &subject, &body, &to, &from)) + if (!PyArg_ParseTuple(args, "s|sss", &subject, &body, &to, &from)) return NULL; gp_KetsjiScene->GetNetworkScene()->SendMessage(to, from, subject, body); @@ -1129,6 +1130,23 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_MIDDLE, SCA_IInputDevice::KX_MIDDLEMOUSE); KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_RIGHT, SCA_IInputDevice::KX_RIGHTMOUSE); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_ENABLED, RAS_2DFilterManager::RAS_2DFILTER_ENABLED); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_DISABLED, RAS_2DFilterManager::RAS_2DFILTER_DISABLED); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_NOFILTER, RAS_2DFilterManager::RAS_2DFILTER_NOFILTER); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_MOTIONBLUR, RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_BLUR, RAS_2DFilterManager::RAS_2DFILTER_BLUR); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_SHARPEN, RAS_2DFilterManager::RAS_2DFILTER_SHARPEN); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_DILATION, RAS_2DFilterManager::RAS_2DFILTER_DILATION); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_EROSION, RAS_2DFilterManager::RAS_2DFILTER_EROSION); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_LAPLACIAN, RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_SOBEL, RAS_2DFilterManager::RAS_2DFILTER_SOBEL); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_PREWITT, RAS_2DFilterManager::RAS_2DFILTER_PREWITT); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_GRAYSCALE, RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_SEPIA, RAS_2DFilterManager::RAS_2DFILTER_SEPIA); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_INVERT, RAS_2DFilterManager::RAS_2DFILTER_INVERT); + KX_MACRO_addTypesToDict(d, RAS_2DFILTER_CUSTOMFILTER, RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER); + + // Check for errors if (PyErr_Occurred()) { @@ -1609,7 +1627,6 @@ PyObject* initGameKeys() KX_MACRO_addTypesToDict(d, PAGEDOWNKEY, SCA_IInputDevice::KX_PAGEDOWNKEY); KX_MACRO_addTypesToDict(d, ENDKEY, SCA_IInputDevice::KX_ENDKEY); - // Check for errors if (PyErr_Occurred()) { diff --git a/source/gameengine/PyDoc/SCA_2DFilterActuator.py b/source/gameengine/PyDoc/SCA_2DFilterActuator.py new file mode 100644 index 00000000000..12baed6fa0c --- /dev/null +++ b/source/gameengine/PyDoc/SCA_2DFilterActuator.py @@ -0,0 +1,44 @@ +# $Id$ +# Documentation for SCA_2DFilterActuator +from SCA_IActuator import * +from SCA_ILogicBrick import * + +class SCA_2DFilterActuator(SCA_IActuator): + """ + Create, enable and disable 2D filters + + Properties: + + The following properties don't have an immediate effect. + You must active the actuator to get the result. + The actuator is not persistent: it automatically stops itself after setting up the filter + but the filter remains active. To stop a filter you must activate the actuator with 'type' + set to RAS_2DFILTER_DISABLED or RAS_2DFILTER_NOFILTER. + + @ivar shaderText: shader source code for custom shader + @type shaderText: string + @ivar disableMotionBlur: action on motion blur: 0=enable, 1=disable + @type disableMotionBlur: integer + @ivar type: type of 2D filter, use one of the following constants: + RAS_2DFILTER_ENABLED (-2) : enable the filter that was previously disabled + RAS_2DFILTER_DISABLED (-1) : disable the filter that is currently active + RAS_2DFILTER_NOFILTER (0) : disable and destroy the filter that is currently active + RAS_2DFILTER_MOTIONBLUR (1) : create and enable preset filters + RAS_2DFILTER_BLUR (2) + RAS_2DFILTER_SHARPEN (3) + RAS_2DFILTER_DILATION (4) + RAS_2DFILTER_EROSION (5) + RAS_2DFILTER_LAPLACIAN (6) + RAS_2DFILTER_SOBEL (7) + RAS_2DFILTER_PREWITT (8) + RAS_2DFILTER_GRAYSCALE (9) + RAS_2DFILTER_SEPIA (10) + RAS_2DFILTER_INVERT (11) + RAS_2DFILTER_CUSTOMFILTER (12) : customer filter, the code code is set via shaderText property + @type type: integer + @ivar passNb: order number of filter in the stack of 2D filters. Filters are executed in increasing order of passNb. + Only be one filter can be defined per passNb. + @type passNb: integer (0-100) + @ivar value: argument for motion blur filter + @type value: float (0.0-100.0) + """ -- cgit v1.2.3 From eacf5b5d6d406492ba79b44f9319867230585e9b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 9 Apr 2009 09:50:17 +0000 Subject: BGE Text - multi-line strings for bitmap text - keyboard sensor now logs return and pad enter as "\n" BGE std::vector use in Value.cpp and RAS_MaterialBucket.cpp The size of a new list is known before making them, reduce re-allocs, though probably not a noticeable speedup. --- source/gameengine/Expressions/Value.cpp | 2 ++ source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 9 ++++++--- source/gameengine/Rasterizer/RAS_MaterialBucket.cpp | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index 8b910b9038b..00d1c4ca77e 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -436,6 +436,8 @@ vector CValue::GetPropertyNames() { vector result; if(!m_pNamedPropertyArray) return result; + result.reserve(m_pNamedPropertyArray->size()); + std::map::iterator it; for (it= m_pNamedPropertyArray->begin(); (it != m_pNamedPropertyArray->end()); it++) { diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index 3749bf2eda0..9a8b68d8db3 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -376,7 +376,8 @@ bool SCA_KeyboardSensor::IsPrintable(int keyIndex) || ((keyIndex >= SCA_IInputDevice::KX_AKEY) && (keyIndex <= SCA_IInputDevice::KX_ZKEY)) || (keyIndex == SCA_IInputDevice::KX_SPACEKEY) -/* || (keyIndex == KX_RETKEY) */ + || (keyIndex == SCA_IInputDevice::KX_RETKEY) + || (keyIndex == SCA_IInputDevice::KX_PADENTER) || (keyIndex == SCA_IInputDevice::KX_PADASTERKEY) || (keyIndex == SCA_IInputDevice::KX_TABKEY) || ((keyIndex >= SCA_IInputDevice::KX_COMMAKEY) @@ -386,7 +387,7 @@ bool SCA_KeyboardSensor::IsPrintable(int keyIndex) || ((keyIndex >= SCA_IInputDevice::KX_PAD2) && (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY)) || (keyIndex == SCA_IInputDevice::KX_DELKEY) - || (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY) + || (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY) ) { return true; @@ -423,8 +424,10 @@ char SCA_KeyboardSensor::ToCharacter(int keyIndex, bool shifted) if (keyIndex == SCA_IInputDevice::KX_SPACEKEY) { return ' '; } + if (keyIndex == SCA_IInputDevice::KX_RETKEY || keyIndex == SCA_IInputDevice::KX_PADENTER) { + return '\n'; + } -/* || (keyIndex == SCA_IInputDevice::KX_RETKEY) */ if (keyIndex == SCA_IInputDevice::KX_PADASTERKEY) { return '*'; diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp index 20a8e9c3574..69f73c2ee25 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp @@ -330,6 +330,9 @@ bool RAS_MeshSlot::Join(RAS_MeshSlot *target, MT_Scalar distance) for(begin(mit); !end(mit); next(mit)) for(i=mit.startvertex; im_displayArrays.reserve(target->m_displayArrays.size() + m_displayArrays.size()); for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) { target->m_displayArrays.push_back(*it); -- cgit v1.2.3 From 65f65a729a46ae8d7e9b9f40f931cdcfd2922938 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 9 Apr 2009 10:28:14 +0000 Subject: key logging didnt work for alphanum keys -=_+ and |\ since revision 2 and nobody noticed! --- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index 9a8b68d8db3..d6ef4af2380 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -463,8 +463,8 @@ char SCA_KeyboardSensor::ToCharacter(int keyIndex, bool shifted) } /* semicolon to rightbracket */ - char semicolontorightbracket[] = ";\'` /\\=[]"; - char semicolontorightbracketshifted[] = ":\"~ \?|+{}"; + char semicolontorightbracket[] = ";\'`/\\=[]"; + char semicolontorightbracketshifted[] = ":\"~\?|+{}"; if ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY) && (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY)) { if (shifted) { -- cgit v1.2.3 From 3be2b8995e6c26b22c1e93ab4aff6a600b7283d2 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Thu, 9 Apr 2009 10:29:07 +0000 Subject: Remove redundant include GL/glu.h in KX_Dome.cpp. --- source/gameengine/Ketsji/KX_Dome.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_Dome.cpp b/source/gameengine/Ketsji/KX_Dome.cpp index 0324b08beab..321370f9f3f 100644 --- a/source/gameengine/Ketsji/KX_Dome.cpp +++ b/source/gameengine/Ketsji/KX_Dome.cpp @@ -33,7 +33,6 @@ Developed as part of a Research and Development project for SAT - La Soci #include "BLI_arithb.h" #include "GL/glew.h" -#include "GL/glu.h" // constructor KX_Dome::KX_Dome ( -- cgit v1.2.3 From e14e66f041104c87033ec0b58596fb49c591908c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 9 Apr 2009 12:53:56 +0000 Subject: BGE Py API - added keyboard senser attribute "events" to replace getEventList() - fix 2 memory leaks in the python api (was making a list but not returning it) - setting readonly attributes didnt give a good error message. --- source/gameengine/PyDoc/GameLogic.py | 8 +++---- source/gameengine/PyDoc/SCA_2DFilterActuator.py | 2 +- source/gameengine/PyDoc/SCA_KeyboardSensor.py | 32 +++++++++++++++++-------- 3 files changed, 27 insertions(+), 15 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/PyDoc/GameLogic.py b/source/gameengine/PyDoc/GameLogic.py index 29d1b64350a..1996aa3f8a9 100644 --- a/source/gameengine/PyDoc/GameLogic.py +++ b/source/gameengine/PyDoc/GameLogic.py @@ -205,9 +205,9 @@ def addActiveActuator(actuator, activate): @type activate: boolean @param activate: whether to activate or deactivate the given actuator. """ -def sendMessage(subject, body="", to="", from=""): +def sendMessage(subject, body="", to="", message_from=""): """ - Sends a message. + Sends a message to sensors in any active scene. @param subject: The subject of the message @type subject: string @@ -215,8 +215,8 @@ def sendMessage(subject, body="", to="", from=""): @type body: string @param to: The name of the object to send the message to (optional) @type to: string - @param from: The name of the object that the message is coming from (optional) - @type from: string + @param message_from: The name of the object that the message is coming from (optional) + @type message_from: string """ def getRandomFloat(): """ diff --git a/source/gameengine/PyDoc/SCA_2DFilterActuator.py b/source/gameengine/PyDoc/SCA_2DFilterActuator.py index 12baed6fa0c..9a010e8f221 100644 --- a/source/gameengine/PyDoc/SCA_2DFilterActuator.py +++ b/source/gameengine/PyDoc/SCA_2DFilterActuator.py @@ -20,7 +20,7 @@ class SCA_2DFilterActuator(SCA_IActuator): @ivar disableMotionBlur: action on motion blur: 0=enable, 1=disable @type disableMotionBlur: integer @ivar type: type of 2D filter, use one of the following constants: - RAS_2DFILTER_ENABLED (-2) : enable the filter that was previously disabled + RAS_2DFILTER_ENABLED (-2) : enable the filter that was previously disabled RAS_2DFILTER_DISABLED (-1) : disable the filter that is currently active RAS_2DFILTER_NOFILTER (0) : disable and destroy the filter that is currently active RAS_2DFILTER_MOTIONBLUR (1) : create and enable preset filters diff --git a/source/gameengine/PyDoc/SCA_KeyboardSensor.py b/source/gameengine/PyDoc/SCA_KeyboardSensor.py index f6a7a7d8a97..93a09acafcf 100644 --- a/source/gameengine/PyDoc/SCA_KeyboardSensor.py +++ b/source/gameengine/PyDoc/SCA_KeyboardSensor.py @@ -20,11 +20,23 @@ class SCA_KeyboardSensor(SCA_ISensor): @type targetProperty: string @ivar useAllKeys: Flag to determine whether or not to accept all keys. @type useAllKeys: boolean + @ivar events: a list of pressed keys that have either been pressed, or just released, or are active this frame. (read only). + + - 'keycode' matches the values in L{GameKeys}. + - 'status' uses... + - L{GameLogic.KX_INPUT_NONE} + - L{GameLogic.KX_INPUT_JUST_ACTIVATED} + - L{GameLogic.KX_INPUT_ACTIVE} + - L{GameLogic.KX_INPUT_JUST_RELEASED} + + @type events: list [[keycode, status], ...] """ def getEventList(): """ Get a list of pressed keys that have either been pressed, or just released, or are active this frame. + B{DEPRECATED: Use the "events" property instead}. + @rtype: list of key status. [[keycode, status]] @return: A list of keyboard events """ @@ -33,18 +45,18 @@ class SCA_KeyboardSensor(SCA_ISensor): """ Get the status of a key. - @rtype: key state (KX_NO_INPUTSTATUS, KX_JUSTACTIVATED, KX_ACTIVE or KX_JUSTRELEASED) + @rtype: key state L{GameLogic} members (KX_INPUT_NONE, KX_INPUT_JUST_ACTIVATED, KX_INPUT_ACTIVE, KX_INPUT_JUST_RELEASED) @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-- + #--The following methods are DEPRECATED-- def getKey(): """ Returns the key code this sensor is looking for. - Deprecated: Use the "key" property instead. + B{DEPRECATED: Use the "key" property instead}. @rtype: keycode from L{GameKeys} module """ @@ -53,7 +65,7 @@ class SCA_KeyboardSensor(SCA_ISensor): """ Set the key this sensor should listen for. - Deprecated: Use the "key" property instead. + B{DEPRECATED: Use the "key" property instead}. @type keycode: keycode from L{GameKeys} module """ @@ -62,7 +74,7 @@ class SCA_KeyboardSensor(SCA_ISensor): """ Returns the key code for the first modifier this sensor is looking for. - Deprecated: Use the "hold1" property instead. + B{DEPRECATED: Use the "hold1" property instead}. @rtype: keycode from L{GameKeys} module """ @@ -71,7 +83,7 @@ class SCA_KeyboardSensor(SCA_ISensor): """ Sets the key code for the first modifier this sensor should look for. - Deprecated: Use the "hold1" property instead. + B{DEPRECATED: Use the "hold1" property instead}. @type keycode: keycode from L{GameKeys} module """ @@ -80,7 +92,7 @@ class SCA_KeyboardSensor(SCA_ISensor): """ Returns the key code for the second modifier this sensor is looking for. - Deprecated: Use the "hold2" property instead. + B{DEPRECATED: Use the "hold2" property instead}. @rtype: keycode from L{GameKeys} module """ @@ -89,7 +101,7 @@ class SCA_KeyboardSensor(SCA_ISensor): """ Sets the key code for the second modifier this sensor should look for. - Deprecated: Use the "hold2" property instead. + B{DEPRECATED: Use the "hold2" property instead.} @type keycode: keycode from L{GameKeys} module """ @@ -98,7 +110,7 @@ class SCA_KeyboardSensor(SCA_ISensor): """ Get a list of keys that have either been pressed, or just released this frame. - Deprecated: Use getEventList() instead. + B{DEPRECATED: Use "events" instead.} @rtype: list of key status. [[keycode, status]] """ @@ -107,7 +119,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. + B{DEPRECATED: Use "events" instead.} @rtype: list of key status. [[keycode, status]] """ \ No newline at end of file -- cgit v1.2.3 From 4669fa48a82f5f1070cf885cd1714e0a8ff8db3a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 9 Apr 2009 16:00:45 +0000 Subject: Added GameKeys.EventToCharacter(event, is_shift) so you can get the character that would be types when pressing a key. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Last commit was made in the pydocs folder only, so this includes changes mentioned in rev 19620. --- source/gameengine/Expressions/PyObjectPlus.h | 9 +- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 400 +++++++++++---------- source/gameengine/GameLogic/SCA_KeyboardSensor.h | 38 +- source/gameengine/Ketsji/KX_PythonInit.cpp | 67 ++-- source/gameengine/PyDoc/GameKeys.py | 26 +- 5 files changed, 305 insertions(+), 235 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index d549be6ef60..786ca1fdc4f 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -129,7 +129,14 @@ static inline void Py_Fatal(const char *M) { \ if(descr) { \ if (PyCObject_Check(descr)) { \ - return py_set_attrdef((void *)this, (const PyAttributeDef*)PyCObject_AsVoidPtr(descr), value); \ + const PyAttributeDef* attrdef= reinterpret_cast(PyCObject_AsVoidPtr(descr)); \ + if (attrdef->m_access == KX_PYATTRIBUTE_RO) { \ + PyErr_Format(PyExc_AttributeError, "\"%s\" is read only", PyString_AsString(attr)); \ + return -1; \ + } \ + else { \ + return py_set_attrdef((void *)this, attrdef, value); \ + } \ } else { \ PyErr_Format(PyExc_AttributeError, "\"%s\" cannot be set", PyString_AsString(attr)); \ return -1; \ diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index d6ef4af2380..6c6f5b4d5e4 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -352,151 +352,7 @@ void SCA_KeyboardSensor::AddToTargetProp(int keyIndex) } } - -/** - * Determine whether this character can be printed. We cannot use - * the library functions here, because we need to test our own - * keycodes. */ -bool SCA_KeyboardSensor::IsPrintable(int keyIndex) -{ - /* only print - * - numerals: KX_ZEROKEY to KX_NINEKEY - * - alphas: KX_AKEY to KX_ZKEY. - * - specials: KX_RETKEY, KX_PADASTERKEY, KX_PADCOMMAKEY to KX_PERIODKEY, - * KX_TABKEY , KX_SEMICOLONKEY to KX_RIGHTBRACKETKEY, - * KX_PAD2 to KX_PADPLUSKEY - * - delete and backspace: also printable in the sense that they modify - * the string - * - retkey: should this be printable? - * - virgule: prints a space... don't know which key that's supposed - * to be... - */ - if ( ((keyIndex >= SCA_IInputDevice::KX_ZEROKEY) - && (keyIndex <= SCA_IInputDevice::KX_NINEKEY)) - || ((keyIndex >= SCA_IInputDevice::KX_AKEY) - && (keyIndex <= SCA_IInputDevice::KX_ZKEY)) - || (keyIndex == SCA_IInputDevice::KX_SPACEKEY) - || (keyIndex == SCA_IInputDevice::KX_RETKEY) - || (keyIndex == SCA_IInputDevice::KX_PADENTER) - || (keyIndex == SCA_IInputDevice::KX_PADASTERKEY) - || (keyIndex == SCA_IInputDevice::KX_TABKEY) - || ((keyIndex >= SCA_IInputDevice::KX_COMMAKEY) - && (keyIndex <= SCA_IInputDevice::KX_PERIODKEY)) - || ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY) - && (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY)) - || ((keyIndex >= SCA_IInputDevice::KX_PAD2) - && (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY)) - || (keyIndex == SCA_IInputDevice::KX_DELKEY) - || (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY) - ) - { - return true; - } else { - return false; - } -} - -// this code looks ugly, please use an ordinary hashtable - -char SCA_KeyboardSensor::ToCharacter(int keyIndex, bool shifted) -{ - /* numerals */ - if ( (keyIndex >= SCA_IInputDevice::KX_ZEROKEY) - && (keyIndex <= SCA_IInputDevice::KX_NINEKEY) ) { - if (shifted) { - char numshift[] = ")!@#$%^&*("; - return numshift[keyIndex - '0']; - } else { - return keyIndex - SCA_IInputDevice::KX_ZEROKEY + '0'; - } - } - - /* letters... always lowercase... is that desirable? */ - if ( (keyIndex >= SCA_IInputDevice::KX_AKEY) - && (keyIndex <= SCA_IInputDevice::KX_ZKEY) ) { - if (shifted) { - return keyIndex - SCA_IInputDevice::KX_AKEY + 'A'; - } else { - return keyIndex - SCA_IInputDevice::KX_AKEY + 'a'; - } - } - - if (keyIndex == SCA_IInputDevice::KX_SPACEKEY) { - return ' '; - } - if (keyIndex == SCA_IInputDevice::KX_RETKEY || keyIndex == SCA_IInputDevice::KX_PADENTER) { - return '\n'; - } - - - if (keyIndex == SCA_IInputDevice::KX_PADASTERKEY) { - return '*'; - } - - if (keyIndex == SCA_IInputDevice::KX_TABKEY) { - return '\t'; - } - - /* comma to period */ - char commatoperiod[] = ",-."; - char commatoperiodshifted[] = "<_>"; - if (keyIndex == SCA_IInputDevice::KX_COMMAKEY) { - if (shifted) { - return commatoperiodshifted[0]; - } else { - return commatoperiod[0]; - } - } - if (keyIndex == SCA_IInputDevice::KX_MINUSKEY) { - if (shifted) { - return commatoperiodshifted[1]; - } else { - return commatoperiod[1]; - } - } - if (keyIndex == SCA_IInputDevice::KX_PERIODKEY) { - if (shifted) { - return commatoperiodshifted[2]; - } else { - return commatoperiod[2]; - } - } - - /* semicolon to rightbracket */ - char semicolontorightbracket[] = ";\'`/\\=[]"; - char semicolontorightbracketshifted[] = ":\"~\?|+{}"; - if ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY) - && (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY)) { - if (shifted) { - return semicolontorightbracketshifted[keyIndex - SCA_IInputDevice::KX_SEMICOLONKEY]; - } else { - return semicolontorightbracket[keyIndex - SCA_IInputDevice::KX_SEMICOLONKEY]; - } - } - - /* keypad2 to padplus */ - char pad2topadplus[] = "246813579. 0- +"; - if ((keyIndex >= SCA_IInputDevice::KX_PAD2) - && (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY)) { - return pad2topadplus[keyIndex - SCA_IInputDevice::KX_PAD2]; - } - - return '!'; -} -/** - * Tests whether this is a delete key. - */ -bool SCA_KeyboardSensor::IsDelete(int keyIndex) -{ - if ( (keyIndex == SCA_IInputDevice::KX_DELKEY) - || (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY) ) { - return true; - } else { - return false; - } -} - /** * Tests whether shift is pressed */ @@ -654,7 +510,7 @@ const char SCA_KeyboardSensor::GetPressedKeys_doc[] = PyObject* SCA_KeyboardSensor::PyGetPressedKeys(PyObject* self, PyObject* args, PyObject* kwds) { - ShowDeprecationWarning("getPressedKeys()", "getEventList()"); + ShowDeprecationWarning("getPressedKeys()", "events"); SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); @@ -672,20 +528,19 @@ PyObject* SCA_KeyboardSensor::PyGetPressedKeys(PyObject* self, PyObject* args, P if ((inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED) || (inevent.m_status == SCA_InputEvent::KX_JUSTRELEASED)) { - if (index < num) - { - PyObject* keypair = PyList_New(2); - PyList_SetItem(keypair,0,PyInt_FromLong(i)); - PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status)); - PyList_SetItem(resultlist,index,keypair); - index++; - } + PyObject* keypair = PyList_New(2); + PyList_SET_ITEM(keypair,0,PyInt_FromLong(i)); + PyList_SET_ITEM(keypair,1,PyInt_FromLong(inevent.m_status)); + PyList_SET_ITEM(resultlist,index,keypair); + index++; + + if (index >= num) /* should not happen */ + break; } - } - if (index>0) return resultlist; + } } - Py_RETURN_NONE; + return resultlist; } @@ -696,9 +551,9 @@ const char SCA_KeyboardSensor::GetCurrentlyPressedKeys_doc[] = PyObject* SCA_KeyboardSensor::PyGetCurrentlyPressedKeys(PyObject* self, PyObject* args, PyObject* kwds) { -ShowDeprecationWarning("getCurrentlyPressedKeys()", "getEventList()"); + ShowDeprecationWarning("getCurrentlyPressedKeys()", "events"); -SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); + SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); int num = inputdev->GetNumActiveEvents(); PyObject* resultlist = PyList_New(num); @@ -713,29 +568,28 @@ SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); if ( (inevent.m_status == SCA_InputEvent::KX_ACTIVE) || (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED)) { - if (index < num) - { - PyObject* keypair = PyList_New(2); - PyList_SetItem(keypair,0,PyInt_FromLong(i)); - PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status)); - PyList_SetItem(resultlist,index,keypair); - index++; - } + PyObject* keypair = PyList_New(2); + PyList_SET_ITEM(keypair,0,PyInt_FromLong(i)); + PyList_SET_ITEM(keypair,1,PyInt_FromLong(inevent.m_status)); + PyList_SET_ITEM(resultlist,index,keypair); + index++; + + if (index >= num) /* should never happen */ + break; } } - - /* why?*/ - if (index > 0) return resultlist; } - Py_RETURN_NONE; + return resultlist; } -//<---- Deprecated + KX_PYMETHODDEF_DOC_NOARGS(SCA_KeyboardSensor, getEventList, "getEventList()\n" "\tGet the list of the keyboard events in this frame.\n") { + ShowDeprecationWarning("getEventList()", "events"); + SCA_IInputDevice* inputdev = m_pKeyboardMgr->GetInputDevice(); PyObject* resultlist = PyList_New(0); @@ -746,34 +600,35 @@ KX_PYMETHODDEF_DOC_NOARGS(SCA_KeyboardSensor, getEventList, if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS) { PyObject* keypair = PyList_New(2); - PyList_SetItem(keypair,0,PyInt_FromLong(i)); + PyList_SET_ITEM(keypair,0,PyInt_FromLong(i)); PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status)); PyList_Append(resultlist,keypair); } } return resultlist; } +//<---- Deprecated 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); + if (!PyInt_Check(value)) { + PyErr_SetString(PyExc_ValueError, "getKeyStatus expected an int"); + return NULL; } - Py_RETURN_NONE; + 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); } /* ------------------------------------------------------------------------- */ @@ -824,6 +679,7 @@ PyMethodDef SCA_KeyboardSensor::Methods[] = { }; PyAttributeDef SCA_KeyboardSensor::Attributes[] = { + KX_PYATTRIBUTE_RO_FUNCTION("events", SCA_KeyboardSensor, pyattr_get_events), KX_PYATTRIBUTE_BOOL_RW("useAllKeys",SCA_KeyboardSensor,m_bAllKeys), 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), @@ -843,3 +699,175 @@ int SCA_KeyboardSensor::py_setattro(PyObject *attr, PyObject *value) { py_setattro_up(SCA_ISensor); } + + +PyObject* SCA_KeyboardSensor::pyattr_get_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_KeyboardSensor* self= static_cast(self_v); + + SCA_IInputDevice* inputdev = self->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_SET_ITEM(keypair,0,PyInt_FromLong(i)); + PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status)); + PyList_Append(resultlist,keypair); + } + } + return resultlist; +} + + +/* Accessed from python */ + +// this code looks ugly, please use an ordinary hashtable + +char ToCharacter(int keyIndex, bool shifted) +{ + /* numerals */ + if ( (keyIndex >= SCA_IInputDevice::KX_ZEROKEY) + && (keyIndex <= SCA_IInputDevice::KX_NINEKEY) ) { + if (shifted) { + char numshift[] = ")!@#$%^&*("; + return numshift[keyIndex - '0']; + } else { + return keyIndex - SCA_IInputDevice::KX_ZEROKEY + '0'; + } + } + + /* letters... always lowercase... is that desirable? */ + if ( (keyIndex >= SCA_IInputDevice::KX_AKEY) + && (keyIndex <= SCA_IInputDevice::KX_ZKEY) ) { + if (shifted) { + return keyIndex - SCA_IInputDevice::KX_AKEY + 'A'; + } else { + return keyIndex - SCA_IInputDevice::KX_AKEY + 'a'; + } + } + + if (keyIndex == SCA_IInputDevice::KX_SPACEKEY) { + return ' '; + } + if (keyIndex == SCA_IInputDevice::KX_RETKEY || keyIndex == SCA_IInputDevice::KX_PADENTER) { + return '\n'; + } + + + if (keyIndex == SCA_IInputDevice::KX_PADASTERKEY) { + return '*'; + } + + if (keyIndex == SCA_IInputDevice::KX_TABKEY) { + return '\t'; + } + + /* comma to period */ + char commatoperiod[] = ",-."; + char commatoperiodshifted[] = "<_>"; + if (keyIndex == SCA_IInputDevice::KX_COMMAKEY) { + if (shifted) { + return commatoperiodshifted[0]; + } else { + return commatoperiod[0]; + } + } + if (keyIndex == SCA_IInputDevice::KX_MINUSKEY) { + if (shifted) { + return commatoperiodshifted[1]; + } else { + return commatoperiod[1]; + } + } + if (keyIndex == SCA_IInputDevice::KX_PERIODKEY) { + if (shifted) { + return commatoperiodshifted[2]; + } else { + return commatoperiod[2]; + } + } + + /* semicolon to rightbracket */ + char semicolontorightbracket[] = ";\'`/\\=[]"; + char semicolontorightbracketshifted[] = ":\"~\?|+{}"; + if ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY) + && (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY)) { + if (shifted) { + return semicolontorightbracketshifted[keyIndex - SCA_IInputDevice::KX_SEMICOLONKEY]; + } else { + return semicolontorightbracket[keyIndex - SCA_IInputDevice::KX_SEMICOLONKEY]; + } + } + + /* keypad2 to padplus */ + char pad2topadplus[] = "246813579. 0- +"; + if ((keyIndex >= SCA_IInputDevice::KX_PAD2) + && (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY)) { + return pad2topadplus[keyIndex - SCA_IInputDevice::KX_PAD2]; + } + + return '!'; +} + + + +/** + * Determine whether this character can be printed. We cannot use + * the library functions here, because we need to test our own + * keycodes. */ +bool IsPrintable(int keyIndex) +{ + /* only print + * - numerals: KX_ZEROKEY to KX_NINEKEY + * - alphas: KX_AKEY to KX_ZKEY. + * - specials: KX_RETKEY, KX_PADASTERKEY, KX_PADCOMMAKEY to KX_PERIODKEY, + * KX_TABKEY , KX_SEMICOLONKEY to KX_RIGHTBRACKETKEY, + * KX_PAD2 to KX_PADPLUSKEY + * - delete and backspace: also printable in the sense that they modify + * the string + * - retkey: should this be printable? + * - virgule: prints a space... don't know which key that's supposed + * to be... + */ + if ( ((keyIndex >= SCA_IInputDevice::KX_ZEROKEY) + && (keyIndex <= SCA_IInputDevice::KX_NINEKEY)) + || ((keyIndex >= SCA_IInputDevice::KX_AKEY) + && (keyIndex <= SCA_IInputDevice::KX_ZKEY)) + || (keyIndex == SCA_IInputDevice::KX_SPACEKEY) + || (keyIndex == SCA_IInputDevice::KX_RETKEY) + || (keyIndex == SCA_IInputDevice::KX_PADENTER) + || (keyIndex == SCA_IInputDevice::KX_PADASTERKEY) + || (keyIndex == SCA_IInputDevice::KX_TABKEY) + || ((keyIndex >= SCA_IInputDevice::KX_COMMAKEY) + && (keyIndex <= SCA_IInputDevice::KX_PERIODKEY)) + || ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY) + && (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY)) + || ((keyIndex >= SCA_IInputDevice::KX_PAD2) + && (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY)) + || (keyIndex == SCA_IInputDevice::KX_DELKEY) + || (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY) + ) + { + return true; + } else { + return false; + } +} + +/** + * Tests whether this is a delete key. + */ +bool IsDelete(int keyIndex) +{ + if ( (keyIndex == SCA_IInputDevice::KX_DELKEY) + || (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY) ) { + return true; + } else { + return false; + } +} diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.h b/source/gameengine/GameLogic/SCA_KeyboardSensor.h index c579b6a82f8..eb26afc96ff 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.h +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.h @@ -81,22 +81,6 @@ class SCA_KeyboardSensor : public SCA_ISensor */ void AddToTargetProp(int keyIndex); - /** - * Determine whether this character can be printed. We cannot use - * the library functions here, because we need to test our own - * keycodes. */ - bool IsPrintable(int keyIndex); - - /** - * Transform keycodes to something printable. - */ - char ToCharacter(int keyIndex, bool shifted); - - /** - * Tests whether this is a delete key. - */ - bool IsDelete(int keyIndex); - /** * Tests whether shift is pressed. */ @@ -152,7 +136,29 @@ public: KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,getEventList); // KeyStatus: KX_PYMETHOD_DOC_O(SCA_KeyboardSensor,getKeyStatus); + + static PyObject* pyattr_get_events(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); }; + +/** + * Transform keycodes to something printable. + */ +char ToCharacter(int keyIndex, bool shifted); + +/** + * Determine whether this character can be printed. We cannot use + * the library functions here, because we need to test our own + * keycodes. */ +bool IsPrintable(int keyIndex); + +/** + * Tests whether this is a delete key. + */ +bool IsDelete(int keyIndex); + + #endif //__KX_KEYBOARDSENSOR + + diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 88aa042f502..e1afde5353a 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -54,6 +54,7 @@ #include "SCA_IInputDevice.h" #include "SCA_PropertySensor.h" #include "SCA_RandomActuator.h" +#include "SCA_KeyboardSensor.h" /* IsPrintable, ToCharacter */ #include "KX_ConstraintActuator.h" #include "KX_IpoActuator.h" #include "KX_SoundActuator.h" @@ -162,7 +163,7 @@ static PyObject* gPyExpandPath(PyObject*, PyObject* args) char expanded[FILE_MAXDIR + FILE_MAXFILE]; char* filename; - if (!PyArg_ParseTuple(args,"s",&filename)) + if (!PyArg_ParseTuple(args,"s:ExpandPath",&filename)) return NULL; BLI_strncpy(expanded, filename, FILE_MAXDIR + FILE_MAXFILE); @@ -185,7 +186,7 @@ static PyObject* gPySendMessage(PyObject*, PyObject* args) char* to = ""; char* from = ""; - if (!PyArg_ParseTuple(args, "s|sss", &subject, &body, &to, &from)) + if (!PyArg_ParseTuple(args, "s|sss:sendMessage", &subject, &body, &to, &from)) return NULL; gp_KetsjiScene->GetNetworkScene()->SendMessage(to, from, subject, body); @@ -268,7 +269,7 @@ static PyObject* gPyStopDSP(PyObject*, PyObject* args) static PyObject* gPySetLogicTicRate(PyObject*, PyObject* args) { float ticrate; - if (!PyArg_ParseTuple(args, "f", &ticrate)) + if (!PyArg_ParseTuple(args, "f:setLogicTicRate", &ticrate)) return NULL; KX_KetsjiEngine::SetTicRate(ticrate); @@ -283,7 +284,7 @@ static PyObject* gPyGetLogicTicRate(PyObject*) static PyObject* gPySetPhysicsTicRate(PyObject*, PyObject* args) { float ticrate; - if (!PyArg_ParseTuple(args, "f", &ticrate)) + if (!PyArg_ParseTuple(args, "f:setPhysicsTicRate", &ticrate)) return NULL; PHY_GetActiveEnvironment()->setFixedTimeStep(true,ticrate); @@ -293,7 +294,7 @@ static PyObject* gPySetPhysicsTicRate(PyObject*, PyObject* args) static PyObject* gPySetPhysicsDebug(PyObject*, PyObject* args) { int debugMode; - if (!PyArg_ParseTuple(args, "i", &debugMode)) + if (!PyArg_ParseTuple(args, "i:setPhysicsDebug", &debugMode)) return NULL; PHY_GetActiveEnvironment()->setDebugMode(debugMode); @@ -321,7 +322,7 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args) DIR *dp; struct dirent *dirp; - if (!PyArg_ParseTuple(args, "|s", &searchpath)) + if (!PyArg_ParseTuple(args, "|s:getBlendFileList", &searchpath)) return NULL; list = PyList_New(0); @@ -507,7 +508,7 @@ bool gUseVisibilityTemp = false; static PyObject* gPyEnableVisibility(PyObject*, PyObject* args) { int visible; - if (!PyArg_ParseTuple(args,"i",&visible)) + if (!PyArg_ParseTuple(args,"i:enableVisibility",&visible)) return NULL; gUseVisibilityTemp = (visible != 0); @@ -519,7 +520,7 @@ static PyObject* gPyEnableVisibility(PyObject*, PyObject* args) static PyObject* gPyShowMouse(PyObject*, PyObject* args) { int visible; - if (!PyArg_ParseTuple(args,"i",&visible)) + if (!PyArg_ParseTuple(args,"i:showMouse",&visible)) return NULL; if (visible) @@ -540,7 +541,7 @@ static PyObject* gPyShowMouse(PyObject*, PyObject* args) static PyObject* gPySetMousePosition(PyObject*, PyObject* args) { int x,y; - if (!PyArg_ParseTuple(args,"ii",&x,&y)) + if (!PyArg_ParseTuple(args,"ii:setMousePosition",&x,&y)) return NULL; if (gp_Canvas) @@ -552,7 +553,7 @@ static PyObject* gPySetMousePosition(PyObject*, PyObject* args) static PyObject* gPySetEyeSeparation(PyObject*, PyObject* args) { float sep; - if (!PyArg_ParseTuple(args, "f", &sep)) + if (!PyArg_ParseTuple(args, "f:setEyeSeparation", &sep)) return NULL; if (!gp_Rasterizer) { @@ -565,7 +566,7 @@ static PyObject* gPySetEyeSeparation(PyObject*, PyObject* args) Py_RETURN_NONE; } -static PyObject* gPyGetEyeSeparation(PyObject*, PyObject*, PyObject*) +static PyObject* gPyGetEyeSeparation(PyObject*) { if (!gp_Rasterizer) { PyErr_SetString(PyExc_RuntimeError, "Rasterizer not available"); @@ -578,7 +579,7 @@ static PyObject* gPyGetEyeSeparation(PyObject*, PyObject*, PyObject*) static PyObject* gPySetFocalLength(PyObject*, PyObject* args) { float focus; - if (!PyArg_ParseTuple(args, "f", &focus)) + if (!PyArg_ParseTuple(args, "f:setFocalLength", &focus)) return NULL; if (!gp_Rasterizer) { @@ -641,7 +642,7 @@ static PyObject* gPySetMistStart(PyObject*, PyObject* args) { float miststart; - if (!PyArg_ParseTuple(args,"f",&miststart)) + if (!PyArg_ParseTuple(args,"f:setMistStart",&miststart)) return NULL; if (!gp_Rasterizer) { @@ -660,7 +661,7 @@ static PyObject* gPySetMistEnd(PyObject*, PyObject* args) { float mistend; - if (!PyArg_ParseTuple(args,"f",&mistend)) + if (!PyArg_ParseTuple(args,"f:setMistEnd",&mistend)) return NULL; if (!gp_Rasterizer) { @@ -696,7 +697,7 @@ static PyObject* gPySetAmbientColor(PyObject*, PyObject* value) static PyObject* gPyMakeScreenshot(PyObject*, PyObject* args) { char* filename; - if (!PyArg_ParseTuple(args,"s",&filename)) + if (!PyArg_ParseTuple(args,"s:makeScreenshot",&filename)) return NULL; if (gp_Canvas) @@ -710,7 +711,7 @@ static PyObject* gPyMakeScreenshot(PyObject*, PyObject* args) static PyObject* gPyEnableMotionBlur(PyObject*, PyObject* args) { float motionblurvalue; - if (!PyArg_ParseTuple(args,"f",&motionblurvalue)) + if (!PyArg_ParseTuple(args,"f:enableMotionBlur",&motionblurvalue)) return NULL; if (!gp_Rasterizer) { @@ -760,7 +761,7 @@ static PyObject* gPySetGLSLMaterialSetting(PyObject*, char *setting; int enable, flag, fileflags; - if (!PyArg_ParseTuple(args,"si",&setting,&enable)) + if (!PyArg_ParseTuple(args,"si:setGLSLMaterialSetting",&setting,&enable)) return NULL; flag = getGLSLSettingFlag(setting); @@ -801,7 +802,7 @@ static PyObject* gPyGetGLSLMaterialSetting(PyObject*, char *setting; int enabled = 0, flag; - if (!PyArg_ParseTuple(args,"s",&setting)) + if (!PyArg_ParseTuple(args,"s:getGLSLMaterialSetting",&setting)) return NULL; flag = getGLSLSettingFlag(setting); @@ -825,7 +826,7 @@ static PyObject* gPySetMaterialType(PyObject*, { int flag, type; - if (!PyArg_ParseTuple(args,"i",&type)) + if (!PyArg_ParseTuple(args,"i:setMaterialType",&type)) return NULL; if(type == KX_BLENDER_GLSL_MATERIAL) @@ -870,7 +871,7 @@ static PyObject* gPyDrawLine(PyObject*, PyObject* args) return NULL; } - if (!PyArg_ParseTuple(args,"OOO",&ob_from,&ob_to,&ob_color)) + if (!PyArg_ParseTuple(args,"OOO:drawLine",&ob_from,&ob_to,&ob_color)) return NULL; MT_Vector3 from; @@ -911,7 +912,7 @@ static struct PyMethodDef rasterizer_methods[] = { {"setEyeSeparation", (PyCFunction) gPySetEyeSeparation, METH_VARARGS, "set the eye separation for stereo mode"}, - {"getEyeSeparation", (PyCFunction) gPyGetEyeSeparation, METH_VARARGS, "get the eye separation for stereo mode"}, + {"getEyeSeparation", (PyCFunction) gPyGetEyeSeparation, METH_NOARGS, "get the eye separation for stereo mode"}, {"setFocalLength", (PyCFunction) gPySetFocalLength, METH_VARARGS, "set the focal length for stereo mode"}, {"getFocalLength", (PyCFunction) gPyGetFocalLength, METH_VARARGS, "get the focal length for stereo mode"}, {"setMaterialMode",(PyCFunction) gPySetMaterialType, @@ -1462,7 +1463,7 @@ static char GameKeys_module_documentation[] = ; static char gPyEventToString_doc[] = -"Take a valid event from the GameKeys module or Keyboard Sensor and return a name" +"EventToString(event) - Take a valid event from the GameKeys module or Keyboard Sensor and return a name" ; static PyObject* gPyEventToString(PyObject*, PyObject* value) @@ -1491,7 +1492,29 @@ static PyObject* gPyEventToString(PyObject*, PyObject* value) return ret; } +static char gPyEventToCharacter_doc[] = +"EventToCharacter(event, is_shift) - Take a valid event from the GameKeys module or Keyboard Sensor and return a character" +; + +static PyObject* gPyEventToCharacter(PyObject*, PyObject* args) +{ + int event, shift; + if (!PyArg_ParseTuple(args,"ii:EventToCharacter", &event, &shift)) + return NULL; + + if(IsPrintable(event)) { + char ch[2] = {'\0', '\0'}; + ch[0] = ToCharacter(event, (bool)shift); + return PyString_FromString(ch); + } + else { + return PyString_FromString(""); + } +} + + static struct PyMethodDef gamekeys_methods[] = { + {"EventToCharacter", (PyCFunction)gPyEventToCharacter, METH_VARARGS, (PY_METHODCHAR)gPyEventToCharacter_doc}, {"EventToString", (PyCFunction)gPyEventToString, METH_O, (PY_METHODCHAR)gPyEventToString_doc}, { NULL, (PyCFunction) NULL, 0, NULL } }; diff --git a/source/gameengine/PyDoc/GameKeys.py b/source/gameengine/PyDoc/GameKeys.py index 1a0a737718e..310f2b0d506 100644 --- a/source/gameengine/PyDoc/GameKeys.py +++ b/source/gameengine/PyDoc/GameKeys.py @@ -134,26 +134,20 @@ Example:: co = GameLogic.getCurrentController() # 'Keyboard' is a keyboard sensor sensor = co.getSensor('Keyboard') - sensor.setKey(GameKeys.F1KEY) + sensor.key = GameKeys.F1KEY Example:: # Do the all keys thing import GameLogic import GameKeys - - # status: these should be added to a module somewhere - KX_NO_INPUTSTATUS = 0 - KX_JUSTACTIVATED = 1 - KX_ACTIVE = 2 - KX_JUSTRELEASED = 3 - + co = GameLogic.getCurrentController() # 'Keyboard' is a keyboard sensor sensor = co.getSensor('Keyboard') - keylist = sensor.getPressedKeys() + keylist = sensor.events for key in keylist: # key[0] == GameKeys.keycode, key[1] = status - if key[1] == KX_JUSTACTIVATED: + if key[1] == GameLogic.KX_INPUT_JUST_ACTIVATED: if key[0] == GameKeys.WKEY: # Activate Forward! if key[0] == GameKeys.SKEY: @@ -173,3 +167,15 @@ def EventToString(event): @param event: key event from GameKeys or the keyboard sensor. @rtype: string """ + +def EventToCharacter(event, shift): + """ + Return the string name of a key event. Returns an empty string if the event cant be represented as a character. + + @type event: int + @param event: key event from GameKeys or the keyboard sensor. + @type event: bool + @param event: set to true if shift is held. + @rtype: string + """ + -- cgit v1.2.3 From 09a5ffdf07677016b4e8eae8df02c47cd94ca6d8 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Thu, 9 Apr 2009 20:40:12 +0000 Subject: BGE API cleanup: sound actuator. --- source/gameengine/Ketsji/KX_PythonInit.cpp | 7 + source/gameengine/Ketsji/KX_SoundActuator.cpp | 342 +++++++++++++++++++++++--- source/gameengine/Ketsji/KX_SoundActuator.h | 33 ++- source/gameengine/PyDoc/KX_SoundActuator.py | 53 +++- 4 files changed, 393 insertions(+), 42 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index e1afde5353a..8b8b62e9310 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1147,6 +1147,13 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, RAS_2DFILTER_INVERT, RAS_2DFilterManager::RAS_2DFILTER_INVERT); KX_MACRO_addTypesToDict(d, RAS_2DFILTER_CUSTOMFILTER, RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER); + KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYSTOP, KX_SoundActuator::KX_SOUNDACT_PLAYSTOP); + KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYEND, KX_SoundActuator::KX_SOUNDACT_PLAYEND); + KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPSTOP, KX_SoundActuator::KX_SOUNDACT_LOOPSTOP); + KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPEND, KX_SoundActuator:: KX_SOUNDACT_LOOPEND); + KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL); + KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP); + // Check for errors if (PyErr_Occurred()) diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index b8d660daa08..ecc3b574079 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -35,6 +35,7 @@ #include "KX_GameObject.h" #include "SND_SoundObject.h" #include "SND_Scene.h" // needed for replication +#include "KX_PyMath.h" // needed for PyObjectFrom() #include #ifdef HAVE_CONFIG_H @@ -264,11 +265,9 @@ PyParentObject KX_SoundActuator::Parents[] = { PyMethodDef KX_SoundActuator::Methods[] = { + // Deprecated -----> {"setFilename", (PyCFunction) KX_SoundActuator::sPySetFilename, METH_VARARGS,NULL}, {"getFilename", (PyCFunction) KX_SoundActuator::sPyGetFilename, METH_VARARGS,NULL}, - {"startSound",(PyCFunction) KX_SoundActuator::sPyStartSound,METH_VARARGS,NULL}, - {"pauseSound",(PyCFunction) KX_SoundActuator::sPyPauseSound,METH_VARARGS,NULL}, - {"stopSound",(PyCFunction) KX_SoundActuator::sPyStopSound,METH_VARARGS,NULL}, {"setGain",(PyCFunction) KX_SoundActuator::sPySetGain,METH_VARARGS,NULL}, {"getGain",(PyCFunction) KX_SoundActuator::sPyGetGain,METH_VARARGS,NULL}, {"setPitch",(PyCFunction) KX_SoundActuator::sPySetPitch,METH_VARARGS,NULL}, @@ -282,40 +281,77 @@ PyMethodDef KX_SoundActuator::Methods[] = { {"setOrientation",(PyCFunction) KX_SoundActuator::sPySetOrientation,METH_VARARGS,NULL}, {"setType",(PyCFunction) KX_SoundActuator::sPySetType,METH_VARARGS,NULL}, {"getType",(PyCFunction) KX_SoundActuator::sPyGetType,METH_VARARGS,NULL}, + // <----- + + KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, startSound), + KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, pauseSound), + KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, stopSound), {NULL,NULL,NULL,NULL} //Sentinel }; PyAttributeDef KX_SoundActuator::Attributes[] = { + KX_PYATTRIBUTE_RW_FUNCTION("filename", KX_SoundActuator, pyattr_get_filename, pyattr_set_filename), + KX_PYATTRIBUTE_RW_FUNCTION("volume", KX_SoundActuator, pyattr_get_gain, pyattr_set_gain), + KX_PYATTRIBUTE_RW_FUNCTION("pitch", KX_SoundActuator, pyattr_get_pitch, pyattr_set_pitch), + KX_PYATTRIBUTE_RW_FUNCTION("rollOffFactor", KX_SoundActuator, pyattr_get_rollOffFactor, pyattr_set_rollOffFactor), + KX_PYATTRIBUTE_RW_FUNCTION("looping", KX_SoundActuator, pyattr_get_looping, pyattr_set_looping), + KX_PYATTRIBUTE_RW_FUNCTION("position", KX_SoundActuator, pyattr_get_position, pyattr_set_position), + KX_PYATTRIBUTE_RW_FUNCTION("velocity", KX_SoundActuator, pyattr_get_velocity, pyattr_set_velocity), + KX_PYATTRIBUTE_RW_FUNCTION("orientation", KX_SoundActuator, pyattr_get_orientation, pyattr_set_orientation), + KX_PYATTRIBUTE_ENUM_RW("type",KX_SoundActuator::KX_SOUNDACT_NODEF+1,KX_SoundActuator::KX_SOUNDACT_MAX-1,false,KX_SoundActuator,m_type), { NULL } //Sentinel }; -PyObject* KX_SoundActuator::py_getattro(PyObject *attr) +/* Methods ----------------------------------------------------------------- */ +KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, startSound, +"startSound()\n" +"\tStarts the sound.\n") { - py_getattro_up(SCA_IActuator); -} - - + if (m_soundObject) + // This has no effect if the actuator is not active. + // To start the sound you must activate the actuator. + // This function is to restart the sound. + m_soundObject->StartSound(); + Py_RETURN_NONE; +} -PyObject* KX_SoundActuator::PySetFilename(PyObject* self, PyObject* args, PyObject* kwds) +KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, pauseSound, +"pauseSound()\n" +"\tPauses the sound.\n") { - char *soundName = NULL; - // void *soundPointer = NULL; /*unused*/ - - if (!PyArg_ParseTuple(args, "s", &soundName)) - return NULL; + if (m_soundObject) + // unfortunately, openal does not implement pause correctly, it is equivalent to a stop + m_soundObject->PauseSound(); + Py_RETURN_NONE; +} +KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, stopSound, +"stopSound()\n" +"\tStops the sound.\n") +{ + if (m_soundObject) + m_soundObject->StopSound(); Py_RETURN_NONE; } +/* Atribute setting and getting -------------------------------------------- */ +PyObject* KX_SoundActuator::py_getattro(PyObject *attr) +{ + py_getattro_up(SCA_IActuator); +} +int KX_SoundActuator::py_setattro(PyObject *attr, PyObject* value) { + py_setattro_up(SCA_IActuator); +} -PyObject* KX_SoundActuator::PyGetFilename(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::pyattr_get_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { - if (!m_soundObject) + KX_SoundActuator * actuator = static_cast (self); + if (!actuator->m_soundObject) { return PyString_FromString(""); } - STR_String objectname = m_soundObject->GetObjectName(); + STR_String objectname = actuator->m_soundObject->GetObjectName(); char* name = objectname.Ptr(); if (!name) { @@ -325,41 +361,264 @@ PyObject* KX_SoundActuator::PyGetFilename(PyObject* self, PyObject* args, PyObje return PyString_FromString(name); } +PyObject* KX_SoundActuator::pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_SoundActuator * actuator = static_cast (self); + float gain = (actuator->m_soundObject) ? actuator->m_soundObject->GetGain() : 1.0f; + PyObject* result = PyFloat_FromDouble(gain); + + return result; +} -PyObject* KX_SoundActuator::PyStartSound(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { - if (m_soundObject) - // This has no effect if the actuator is not active. - // To start the sound you must activate the actuator. - // This function is to restart the sound. - m_soundObject->StartSound(); - Py_RETURN_NONE; + KX_SoundActuator * actuator = static_cast (self); + float pitch = (actuator->m_soundObject) ? actuator->m_soundObject->GetPitch() : 1.0; + PyObject* result = PyFloat_FromDouble(pitch); + + return result; +} + +PyObject* KX_SoundActuator::pyattr_get_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_SoundActuator * actuator = static_cast (self); + float rollofffactor = (actuator->m_soundObject) ? actuator->m_soundObject->GetRollOffFactor() : 1.0; + PyObject* result = PyFloat_FromDouble(rollofffactor); + + return result; +} + +PyObject* KX_SoundActuator::pyattr_get_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_SoundActuator * actuator = static_cast (self); + int looping = (actuator->m_soundObject) ? actuator->m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF; + PyObject* result = PyInt_FromLong(looping); + + return result; +} + +PyObject* KX_SoundActuator::pyattr_get_position(void * self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_SoundActuator * actuator = static_cast (self); + MT_Vector3 pos(0.0, 0.0, 0.0); + + if (actuator->m_soundObject) + pos = actuator->m_soundObject->GetPosition(); + + PyObject * result = PyObjectFrom(pos); + return result; +} + +PyObject* KX_SoundActuator::pyattr_get_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_SoundActuator * actuator = static_cast (self); + MT_Vector3 vel; + + if (actuator->m_soundObject) + vel = actuator->m_soundObject->GetVelocity(); + + PyObject * result = PyObjectFrom(vel); + return result; +} + +PyObject* KX_SoundActuator::pyattr_get_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_SoundActuator * actuator = static_cast (self); + MT_Matrix3x3 ori; + + if (actuator->m_soundObject) + ori = actuator->m_soundObject->GetOrientation(); + + PyObject * result = PyObjectFrom(ori); + return result; +} + +int KX_SoundActuator::pyattr_set_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + char *soundName = NULL; + KX_SoundActuator * actuator = static_cast (self); + // void *soundPointer = NULL; /*unused*/ + + if (!PyArg_Parse(value, "s", &soundName)) + return 1; + + if (actuator->m_soundObject) { + actuator->m_soundObject->SetObjectName(soundName); + } + + return 0; +} + + +int KX_SoundActuator::pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + float gain = 1.0; + KX_SoundActuator * actuator = static_cast (self); + if (!PyArg_Parse(value, "f", &gain)) + return 1; + + if (actuator->m_soundObject) + actuator->m_soundObject->SetGain(gain); + + return 0; } +int KX_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + float pitch = 1.0; + KX_SoundActuator * actuator = static_cast (self); + if (!PyArg_Parse(value, "f", &pitch)) + return 1; + + if (actuator->m_soundObject) + actuator->m_soundObject->SetPitch(pitch); + + return 0; +} + +int KX_SoundActuator::pyattr_set_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_SoundActuator * actuator = static_cast (self); + float rollofffactor = 1.0; + if (!PyArg_Parse(value, "f", &rollofffactor)) + return 1; + + if (actuator->m_soundObject) + actuator->m_soundObject->SetRollOffFactor(rollofffactor); + return 0; +} -PyObject* KX_SoundActuator::PyPauseSound(PyObject* self, PyObject* args, PyObject* kwds) +int KX_SoundActuator::pyattr_set_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { - if (m_soundObject) - // unfortunately, openal does not implement pause correctly, it is equivalent to a stop - m_soundObject->PauseSound(); - Py_RETURN_NONE; -} + KX_SoundActuator * actuator = static_cast (self); + int looping = 1; + if (!PyArg_Parse(value, "i", &looping)) + return 1; + + if (actuator->m_soundObject) + actuator->m_soundObject->SetLoopMode(looping); + + return 0; +} +int KX_SoundActuator::pyattr_set_position(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + float pos[3]; + KX_SoundActuator * actuator = static_cast (self); -PyObject* KX_SoundActuator::PyStopSound(PyObject* self, PyObject* args, PyObject* kwds) + if (!PyArg_ParseTuple(value, "fff", &pos[0], &pos[1], &pos[2])) + return 1; + + if (actuator->m_soundObject) + actuator->m_soundObject->SetPosition(MT_Vector3(pos)); + + return 0; +} + +int KX_SoundActuator::pyattr_set_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { - if (m_soundObject) - m_soundObject->StopSound(); - Py_RETURN_NONE; + float vel[3]; + KX_SoundActuator * actuator = static_cast (self); + + + if (!PyArg_ParseTuple(value, "fff", &vel[0], &vel[1], &vel[2])) + return 1; + + if (actuator->m_soundObject) + actuator->m_soundObject->SetVelocity(MT_Vector3(vel)); + + return 0; + +} + +int KX_SoundActuator::pyattr_set_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + + MT_Matrix3x3 rot; + KX_SoundActuator * actuator = static_cast (self); + + if (!PySequence_Check(value)) { + PyErr_SetString(PyExc_AttributeError, "'orientation' attribute needs to be a sequence"); + return 1; + } + + if (!actuator->m_soundObject) + return 0; /* Since not having m_soundObject didn't do anything in the old version, + * it probably should be kept that way */ + + if (PyMatTo(value, rot)) + { + actuator->m_soundObject->SetOrientation(rot); + return 0; + } + PyErr_Clear(); + + + if (PySequence_Size(value) == 4) + { + MT_Quaternion qrot; + if (PyVecTo(value, qrot)) + { + rot.setRotation(qrot); + actuator->m_soundObject->SetOrientation(rot); + return 0; + } + return 1; + } + + if (PySequence_Size(value) == 3) + { + MT_Vector3 erot; + if (PyVecTo(value, erot)) + { + rot.setEuler(erot); + actuator->m_soundObject->SetOrientation(rot); + return 0; + } + return 1; + } + + PyErr_SetString(PyExc_AttributeError, "could not set the orientation from a 3x3 matrix, quaternion or euler sequence"); + return 1; + } +// Deprecated -----> +PyObject* KX_SoundActuator::PySetFilename(PyObject* self, PyObject* args, PyObject* kwds) +{ + char *soundName = NULL; + ShowDeprecationWarning("setFilename()", "the filename property"); + // void *soundPointer = NULL; /*unused*/ + + if (!PyArg_ParseTuple(args, "s", &soundName)) + return NULL; + + Py_RETURN_NONE; +} +PyObject* KX_SoundActuator::PyGetFilename(PyObject* self, PyObject* args, PyObject* kwds) +{ + ShowDeprecationWarning("getFilename()", "the filename property"); + if (!m_soundObject) + { + return PyString_FromString(""); + } + STR_String objectname = m_soundObject->GetObjectName(); + char* name = objectname.Ptr(); + + if (!name) { + PyErr_SetString(PyExc_RuntimeError, "Unable to get sound filename"); + return NULL; + } else + return PyString_FromString(name); +} PyObject* KX_SoundActuator::PySetGain(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setGain()", "the volume property"); float gain = 1.0; if (!PyArg_ParseTuple(args, "f", &gain)) return NULL; @@ -374,6 +633,7 @@ PyObject* KX_SoundActuator::PySetGain(PyObject* self, PyObject* args, PyObject* PyObject* KX_SoundActuator::PyGetGain(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getGain()", "the volume property"); float gain = (m_soundObject) ? m_soundObject->GetGain() : 1.0f; PyObject* result = PyFloat_FromDouble(gain); @@ -384,6 +644,7 @@ PyObject* KX_SoundActuator::PyGetGain(PyObject* self, PyObject* args, PyObject* PyObject* KX_SoundActuator::PySetPitch(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setPitch()", "the pitch property"); float pitch = 1.0; if (!PyArg_ParseTuple(args, "f", &pitch)) return NULL; @@ -398,6 +659,7 @@ PyObject* KX_SoundActuator::PySetPitch(PyObject* self, PyObject* args, PyObject* PyObject* KX_SoundActuator::PyGetPitch(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getPitch()", "the pitch property"); float pitch = (m_soundObject) ? m_soundObject->GetPitch() : 1.0; PyObject* result = PyFloat_FromDouble(pitch); @@ -408,6 +670,7 @@ PyObject* KX_SoundActuator::PyGetPitch(PyObject* self, PyObject* args, PyObject* PyObject* KX_SoundActuator::PySetRollOffFactor(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setRollOffFactor()", "the rollOffFactor property"); float rollofffactor = 1.0; if (!PyArg_ParseTuple(args, "f", &rollofffactor)) return NULL; @@ -422,6 +685,7 @@ PyObject* KX_SoundActuator::PySetRollOffFactor(PyObject* self, PyObject* args, P PyObject* KX_SoundActuator::PyGetRollOffFactor(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getRollOffFactor()", "the rollOffFactor property"); float rollofffactor = (m_soundObject) ? m_soundObject->GetRollOffFactor() : 1.0; PyObject* result = PyFloat_FromDouble(rollofffactor); @@ -432,6 +696,7 @@ PyObject* KX_SoundActuator::PyGetRollOffFactor(PyObject* self, PyObject* args, P PyObject* KX_SoundActuator::PySetLooping(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setLooping()", "the looping property"); bool looping = 1; if (!PyArg_ParseTuple(args, "i", &looping)) return NULL; @@ -446,6 +711,7 @@ PyObject* KX_SoundActuator::PySetLooping(PyObject* self, PyObject* args, PyObjec PyObject* KX_SoundActuator::PyGetLooping(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getLooping()", "the looping property"); int looping = (m_soundObject) ? m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF; PyObject* result = PyInt_FromLong(looping); @@ -457,6 +723,7 @@ PyObject* KX_SoundActuator::PyGetLooping(PyObject* self, PyObject* args, PyObjec PyObject* KX_SoundActuator::PySetPosition(PyObject* self, PyObject* args, PyObject* kwds) { MT_Point3 pos; + ShowDeprecationWarning("setPosition()", "the position property"); pos[0] = 0.0; pos[1] = 0.0; pos[2] = 0.0; @@ -475,6 +742,7 @@ PyObject* KX_SoundActuator::PySetPosition(PyObject* self, PyObject* args, PyObje PyObject* KX_SoundActuator::PySetVelocity(PyObject* self, PyObject* args, PyObject* kwds) { MT_Vector3 vel; + ShowDeprecationWarning("setVelocity()", "the velocity property"); vel[0] = 0.0; vel[1] = 0.0; vel[2] = 0.0; @@ -493,6 +761,7 @@ PyObject* KX_SoundActuator::PySetVelocity(PyObject* self, PyObject* args, PyObje PyObject* KX_SoundActuator::PySetOrientation(PyObject* self, PyObject* args, PyObject* kwds) { MT_Matrix3x3 ori; + ShowDeprecationWarning("setOrientation()", "the orientation property"); ori[0][0] = 1.0; ori[0][1] = 0.0; ori[0][2] = 0.0; @@ -515,6 +784,7 @@ PyObject* KX_SoundActuator::PySetOrientation(PyObject* self, PyObject* args, PyO PyObject* KX_SoundActuator::PySetType(PyObject* self, PyObject* args, PyObject* kwds) { int typeArg; + ShowDeprecationWarning("setType()", "the type property"); if (!PyArg_ParseTuple(args, "i", &typeArg)) { return NULL; @@ -530,8 +800,8 @@ PyObject* KX_SoundActuator::PySetType(PyObject* self, PyObject* args, PyObject* PyObject* KX_SoundActuator::PyGetType(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("getType()", "the type property"); return PyInt_FromLong(m_type); } - - +// <----- diff --git a/source/gameengine/Ketsji/KX_SoundActuator.h b/source/gameengine/Ketsji/KX_SoundActuator.h index 3e4a4168434..eb18ba9f13e 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.h +++ b/source/gameengine/Ketsji/KX_SoundActuator.h @@ -80,13 +80,36 @@ public: /* Python interface --------------------------------------------------- */ /* -------------------------------------------------------------------- */ - virtual PyObject* py_getattro(PyObject *attr); + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject* value); + KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, startSound); + KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, pauseSound); + KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, stopSound); + + static int pyattr_set_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_position(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + + static PyObject* pyattr_get_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_position(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + + // Deprecated -----> KX_PYMETHOD(KX_SoundActuator,SetFilename); KX_PYMETHOD(KX_SoundActuator,GetFilename); - KX_PYMETHOD(KX_SoundActuator,StartSound); - KX_PYMETHOD(KX_SoundActuator,PauseSound); - KX_PYMETHOD(KX_SoundActuator,StopSound); KX_PYMETHOD(KX_SoundActuator,SetGain); KX_PYMETHOD(KX_SoundActuator,GetGain); KX_PYMETHOD(KX_SoundActuator,SetPitch); @@ -100,6 +123,8 @@ public: KX_PYMETHOD(KX_SoundActuator,SetOrientation); KX_PYMETHOD(KX_SoundActuator,SetType); KX_PYMETHOD(KX_SoundActuator,GetType); + // <----- + }; #endif //__KX_SOUNDACTUATOR diff --git a/source/gameengine/PyDoc/KX_SoundActuator.py b/source/gameengine/PyDoc/KX_SoundActuator.py index 072af5b816c..383b45e6eb9 100644 --- a/source/gameengine/PyDoc/KX_SoundActuator.py +++ b/source/gameengine/PyDoc/KX_SoundActuator.py @@ -8,17 +8,53 @@ class KX_SoundActuator(SCA_IActuator): The L{startSound()}, L{pauseSound()} and L{stopSound()} do not require the actuator to be activated - they act instantly. + + @ivar filename: Sets the filename of the sound this actuator plays. + @type filename: string + + @ivar volume: Sets the volume (gain) of the sound. + @type volume: float + + @ivar pitch: Sets the pitch of the sound. + @type pitch: float + + @ivar rollOffFactor: Sets the roll off factor. Rolloff defines the rate of attenuation as the sound gets further away. + @type rollOffFactor: float + + @ivar looping: Sets the loop mode of the actuator. + @type looping: integer + + @ivar position: Sets the position of the sound. + @type position: float array + + @ivar velocity: Sets the speed of the sound; The speed of the sound alter the pitch. + @type velocity: float array + + @ivar orientation: Sets the orientation of the sound. When setting the orientation you can + also use quaternion [float,float,float,float] or euler angles [float,float,float] + @type orientation: 3x3 matrix [[float]] + + @ivar type: Sets the operation mode of the actuator. You can use one of the following constant: + KX_SOUNDACT_PLAYSTOP (1) + KX_SOUNDACT_PLAYEND (2) + KX_SOUNDACT_LOOPSTOP (3) + KX_SOUNDACT_LOOPEND (4) + KX_SOUNDACT_LOOPBIDIRECTIONAL (5) + KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP (6) + @type type: integer - @group Play Methods: startSound, pauseSound, stopSound + @group Play Methods: startSound, pauseSound, stopSound. """ def setFilename(filename): """ - Sets the filename of the sound this actuator plays. + DEPRECATED: Use the filename property instead. + Sets the filename of the sound this actuator plays. @type filename: string """ def getFilename(): """ + DEPRECATED: Use the filename property instead. Returns the filename of the sound this actuator plays. @rtype: string @@ -37,6 +73,7 @@ class KX_SoundActuator(SCA_IActuator): """ def setGain(gain): """ + DEPRECATED: Use the volume property instead Sets the gain (volume) of the sound @type gain: float @@ -44,24 +81,28 @@ class KX_SoundActuator(SCA_IActuator): """ def getGain(): """ + DEPRECATED: Use the volume property instead. Gets the gain (volume) of the sound. @rtype: float """ def setPitch(pitch): """ + DEPRECATED: Use the pitch property instead. Sets the pitch of the sound. @type pitch: float """ def getPitch(): """ + DEPRECATED: Use the pitch property instead. Returns the pitch of the sound. @rtype: float """ def setRollOffFactor(rolloff): """ + DEPRECATED: Use the rollOffFactor property instead. Sets the rolloff factor for the sounds. Rolloff defines the rate of attenuation as the sound gets further away. @@ -71,12 +112,14 @@ class KX_SoundActuator(SCA_IActuator): """ def getRollOffFactor(): """ + DEPRECATED: Use the rollOffFactor property instead. Returns the rolloff factor for the sound. @rtype: float """ def setLooping(loop): """ + DEPRECATED: Use the looping property instead. Sets the loop mode of the actuator. @bug: There are no constants defined for this method! @@ -90,12 +133,14 @@ class KX_SoundActuator(SCA_IActuator): """ def getLooping(): """ + DEPRECATED: Use the looping property instead. Returns the current loop mode of the actuator. @rtype: integer """ def setPosition(x, y, z): """ + DEPRECATED: Use the position property instead. Sets the position this sound will come from. @type x: float @@ -107,6 +152,7 @@ class KX_SoundActuator(SCA_IActuator): """ def setVelocity(vx, vy, vz): """ + DEPRECATED: Use the velocity property instead. Sets the velocity this sound is moving at. The sound's pitch is determined from the velocity. @@ -120,6 +166,7 @@ class KX_SoundActuator(SCA_IActuator): """ def setOrientation(o11, o12, o13, o21, o22, o23, o31, o32, o33): """ + DEPRECATED: Use the orientation property instead. Sets the orientation of the sound. The nine parameters specify a rotation matrix:: @@ -130,6 +177,7 @@ class KX_SoundActuator(SCA_IActuator): def setType(mode): """ + DEPRECATED: Use the type property instead. Sets the operation mode of the actuator. @param mode: KX_SOUNDACT_PLAYSTOP, KX_SOUNDACT_PLAYEND, KX_SOUNDACT_LOOPSTOP, KX_SOUNDACT_LOOPEND, KX_SOUNDACT_LOOPBIDIRECTIONAL, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP @@ -138,6 +186,7 @@ class KX_SoundActuator(SCA_IActuator): def getType(): """ + DEPRECATED: Use the type property instead. Returns the operation mode of the actuator. @rtype: integer -- cgit v1.2.3 From b0cca7de267f84768ee1eba0955373a24b661aad Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Thu, 9 Apr 2009 21:15:44 +0000 Subject: BGE API cleanup: StateActuator. --- source/gameengine/Ketsji/KX_PythonInit.cpp | 6 ++++++ source/gameengine/Ketsji/KX_StateActuator.cpp | 10 ++++++++++ source/gameengine/Ketsji/KX_StateActuator.h | 7 +++++-- source/gameengine/PyDoc/KX_SoundActuator.py | 3 ++- 4 files changed, 23 insertions(+), 3 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 8b8b62e9310..4ad9853f9c4 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -58,6 +58,7 @@ #include "KX_ConstraintActuator.h" #include "KX_IpoActuator.h" #include "KX_SoundActuator.h" +#include "KX_StateActuator.h" #include "BL_ActionActuator.h" #include "RAS_IRasterizer.h" #include "RAS_ICanvas.h" @@ -1154,6 +1155,11 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL); KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP); + KX_MACRO_addTypesToDict(d, KX_STATE_OP_CPY, KX_StateActuator::OP_CPY); + KX_MACRO_addTypesToDict(d, KX_STATE_OP_SET, KX_StateActuator::OP_SET); + KX_MACRO_addTypesToDict(d, KX_STATE_OP_CLR, KX_StateActuator::OP_CLR); + KX_MACRO_addTypesToDict(d, KX_STATE_OP_NEG, KX_StateActuator::OP_NEG); + // Check for errors if (PyErr_Occurred()) diff --git a/source/gameengine/Ketsji/KX_StateActuator.cpp b/source/gameengine/Ketsji/KX_StateActuator.cpp index 31457230f60..e9e3c091ef3 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.cpp +++ b/source/gameengine/Ketsji/KX_StateActuator.cpp @@ -138,14 +138,18 @@ KX_StateActuator::Parents[] = { PyMethodDef KX_StateActuator::Methods[] = { + // deprecated --> {"setOperation", (PyCFunction) KX_StateActuator::sPySetOperation, METH_VARARGS, (PY_METHODCHAR)SetOperation_doc}, {"setMask", (PyCFunction) KX_StateActuator::sPySetMask, METH_VARARGS, (PY_METHODCHAR)SetMask_doc}, + // <-- {NULL,NULL} //Sentinel }; PyAttributeDef KX_StateActuator::Attributes[] = { + KX_PYATTRIBUTE_INT_RW("operation",KX_StateActuator::OP_NOP+1,KX_StateActuator::OP_COUNT-1,false,KX_StateActuator,m_operation), + KX_PYATTRIBUTE_INT_RW("mask",0,0x3FFFFFFF,false,KX_StateActuator,m_mask), { NULL } //Sentinel }; @@ -154,6 +158,10 @@ PyObject* KX_StateActuator::py_getattro(PyObject *attr) py_getattro_up(SCA_IActuator); }; +int KX_StateActuator::py_setattro(PyObject *attr, PyObject* value) +{ + py_setattro_up(SCA_IActuator); +} /* set operation ---------------------------------------------------------- */ @@ -168,6 +176,7 @@ PyObject* KX_StateActuator::PySetOperation(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setOperation()", "the operation property"); int oper; if(!PyArg_ParseTuple(args, "i", &oper)) { @@ -193,6 +202,7 @@ PyObject* KX_StateActuator::PySetMask(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setMask()", "the mask property"); int mask; if(!PyArg_ParseTuple(args, "i", &mask)) { diff --git a/source/gameengine/Ketsji/KX_StateActuator.h b/source/gameengine/Ketsji/KX_StateActuator.h index b6f1acf4a00..426753dadfd 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.h +++ b/source/gameengine/Ketsji/KX_StateActuator.h @@ -39,13 +39,15 @@ class KX_StateActuator : public SCA_IActuator /** Make visible? */ enum { + OP_NOP = -1, OP_CPY = 0, OP_SET, OP_CLR, - OP_NEG + OP_NEG, + OP_COUNT }; int m_operation; - unsigned int m_mask; + int m_mask; public: @@ -74,6 +76,7 @@ class KX_StateActuator : public SCA_IActuator /* --------------------------------------------------------------------- */ virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject* value); //KX_PYMETHOD_DOC KX_PYMETHOD_DOC(KX_StateActuator,SetOperation); KX_PYMETHOD_DOC(KX_StateActuator,SetMask); diff --git a/source/gameengine/PyDoc/KX_SoundActuator.py b/source/gameengine/PyDoc/KX_SoundActuator.py index 383b45e6eb9..37ae3c6640d 100644 --- a/source/gameengine/PyDoc/KX_SoundActuator.py +++ b/source/gameengine/PyDoc/KX_SoundActuator.py @@ -7,7 +7,8 @@ class KX_SoundActuator(SCA_IActuator): Sound Actuator. The L{startSound()}, L{pauseSound()} and L{stopSound()} do not require - the actuator to be activated - they act instantly. + the actuator to be activated - they act instantly provided that the actuator has + been activated once at least. @ivar filename: Sets the filename of the sound this actuator plays. @type filename: string -- cgit v1.2.3 From ac45472a1707934573a12d629a21a81c3ed409ba Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 9 Apr 2009 22:15:26 +0000 Subject: BGE Bugfix The End key didn't work work at all for the keyboard sensor. Removed getEventList() since it was added since 2.48a release. --- .../BlenderRoutines/KX_BlenderKeyboardDevice.cpp | 4 +-- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 35 ++++------------------ .../GamePlayer/common/GPC_KeyboardDevice.cpp | 8 ++--- source/gameengine/PyDoc/SCA_KeyboardSensor.py | 9 ------ 4 files changed, 10 insertions(+), 46 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp b/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp index 4b794380610..877a0d39acf 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp @@ -74,7 +74,7 @@ void KX_BlenderKeyboardDevice::NextFrame() // now convert justpressed keyevents into regular (active) keyevents int previousTable = 1-m_currentTable; - for (int keyevent= KX_BEGINKEY; keyevent< KX_ENDKEY;keyevent++) + for (int keyevent= KX_BEGINKEY; keyevent<= KX_ENDKEY;keyevent++) { SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][keyevent]; if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || @@ -100,7 +100,7 @@ bool KX_BlenderKeyboardDevice::ConvertBlenderEvent(unsigned short incode,short v KX_EnumInputs kxevent = this->ToNative(incode); // only process it, if it's a key - if (kxevent >= KX_BEGINKEY && kxevent < KX_ENDKEY) + if (kxevent >= KX_BEGINKEY && kxevent <= KX_ENDKEY) { int previousTable = 1-m_currentTable; diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index 6c6f5b4d5e4..ecdf889124d 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -148,7 +148,7 @@ bool SCA_KeyboardSensor::Evaluate(CValue* eventval) bool justreleased = false; bool active = false; - for (int i=SCA_IInputDevice::KX_BEGINKEY ; i< SCA_IInputDevice::KX_ENDKEY;i++) + for (int i=SCA_IInputDevice::KX_BEGINKEY ; i<= SCA_IInputDevice::KX_ENDKEY;i++) { const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) i); switch (inevent.m_status) @@ -387,7 +387,7 @@ void SCA_KeyboardSensor::LogKeystrokes(void) int index = 0; /* Check on all keys whether they were pushed. This does not * untangle the ordering, so don't type too fast :) */ - for (int i=SCA_IInputDevice::KX_BEGINKEY ; i< SCA_IInputDevice::KX_ENDKEY;i++) + 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_JUSTACTIVATED) //NO_INPUTSTATUS) @@ -522,7 +522,7 @@ PyObject* SCA_KeyboardSensor::PyGetPressedKeys(PyObject* self, PyObject* args, P int index = 0; - for (int i=SCA_IInputDevice::KX_BEGINKEY ; i< SCA_IInputDevice::KX_ENDKEY;i++) + 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_JUSTACTIVATED) @@ -562,7 +562,7 @@ PyObject* SCA_KeyboardSensor::PyGetCurrentlyPressedKeys(PyObject* self, PyObject { int index = 0; - for (int i=SCA_IInputDevice::KX_BEGINKEY ; i< SCA_IInputDevice::KX_ENDKEY;i++) + 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_ACTIVE) @@ -583,30 +583,6 @@ PyObject* SCA_KeyboardSensor::PyGetCurrentlyPressedKeys(PyObject* self, PyObject return resultlist; } - -KX_PYMETHODDEF_DOC_NOARGS(SCA_KeyboardSensor, getEventList, -"getEventList()\n" -"\tGet the list of the keyboard events in this frame.\n") -{ - ShowDeprecationWarning("getEventList()", "events"); - - 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_SET_ITEM(keypair,0,PyInt_FromLong(i)); - PyList_SetItem(keypair,1,PyInt_FromLong(inevent.m_status)); - PyList_Append(resultlist,keypair); - } - } - return resultlist; -} //<---- Deprecated KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus, @@ -673,7 +649,6 @@ PyMethodDef SCA_KeyboardSensor::Methods[] = { {"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 }; @@ -709,7 +684,7 @@ PyObject* SCA_KeyboardSensor::pyattr_get_events(void *self_v, const KX_PYATTRIBU PyObject* resultlist = PyList_New(0); - for (int i=SCA_IInputDevice::KX_BEGINKEY ; i< SCA_IInputDevice::KX_ENDKEY;i++) + 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) diff --git a/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp b/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp index 474df9276a7..472ff580392 100644 --- a/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp +++ b/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp @@ -42,7 +42,7 @@ void GPC_KeyboardDevice::NextFrame() // Now convert justpressed key events into regular (active) keyevents int previousTable = 1-m_currentTable; - for (int keyevent= KX_BEGINKEY; keyevent< KX_ENDKEY;keyevent++) + for (int keyevent= KX_BEGINKEY; keyevent<= KX_ENDKEY;keyevent++) { SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][keyevent]; if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || @@ -69,7 +69,7 @@ bool GPC_KeyboardDevice::ConvertEvent(int incode, int val) KX_EnumInputs kxevent = this->ToNative(incode); // only process it, if it's a key - if (kxevent >= KX_BEGINKEY && kxevent < KX_ENDKEY) + if (kxevent >= KX_BEGINKEY && kxevent <= KX_ENDKEY) { int previousTable = 1-m_currentTable; @@ -114,9 +114,7 @@ bool GPC_KeyboardDevice::ConvertEvent(int incode, int val) } } } - } else if(kxevent==KX_ENDKEY) { - exit(1); - } + } return result; } diff --git a/source/gameengine/PyDoc/SCA_KeyboardSensor.py b/source/gameengine/PyDoc/SCA_KeyboardSensor.py index 93a09acafcf..8abb1fda762 100644 --- a/source/gameengine/PyDoc/SCA_KeyboardSensor.py +++ b/source/gameengine/PyDoc/SCA_KeyboardSensor.py @@ -31,15 +31,6 @@ class SCA_KeyboardSensor(SCA_ISensor): @type events: list [[keycode, status], ...] """ - def getEventList(): - """ - Get a list of pressed keys that have either been pressed, or just released, or are active this frame. - - B{DEPRECATED: Use the "events" property instead}. - - @rtype: list of key status. [[keycode, status]] - @return: A list of keyboard events - """ def getKeyStatus(keycode): """ -- cgit v1.2.3 From 5031fe982ea464ccb49ccfb4df857bf9dcb27c33 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Thu, 9 Apr 2009 23:10:12 +0000 Subject: BGE API cleanup: ConstraintActuator. --- source/gameengine/Ketsji/KX_ConstraintActuator.cpp | 107 ++++++++++++++++----- source/gameengine/Ketsji/KX_ConstraintActuator.h | 9 +- source/gameengine/Ketsji/KX_PythonInit.cpp | 12 +++ source/gameengine/PyDoc/KX_ConstraintActuator.py | 69 +++++++++++++ source/gameengine/PyDoc/KX_StateActuator.py | 18 ++++ 5 files changed, 189 insertions(+), 26 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index feee851bb01..b41435e71a1 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -36,6 +36,7 @@ #include "MT_Matrix3x3.h" #include "KX_GameObject.h" #include "KX_RayCast.h" +#include "blendef.h" #ifdef HAVE_CONFIG_H #include @@ -57,19 +58,21 @@ KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj, char *property, PyTypeObject* T) : SCA_IActuator(gameobj, T), - m_refDirection(refDir), + m_refDirVector(refDir), m_currentTime(0) { + m_refDirection[0] = refDir[0]; + m_refDirection[1] = refDir[1]; + m_refDirection[2] = refDir[2]; m_posDampTime = posDampTime; m_rotDampTime = rotDampTime; m_locrot = locrotxyz; m_option = option; m_activeTime = time; if (property) { - strncpy(m_property, property, sizeof(m_property)); - m_property[sizeof(m_property)-1] = 0; + m_property = property; } else { - m_property[0] = 0; + m_property = ""; } /* The units of bounds are determined by the type of constraint. To */ /* make the constraint application easier and more transparent later on, */ @@ -80,13 +83,16 @@ KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj, case KX_ACT_CONSTRAINT_ORIY: case KX_ACT_CONSTRAINT_ORIZ: { - MT_Scalar len = m_refDirection.length(); + MT_Scalar len = m_refDirVector.length(); if (MT_fuzzyZero(len)) { // missing a valid direction std::cout << "WARNING: Constraint actuator " << GetName() << ": There is no valid reference direction!" << std::endl; m_locrot = KX_ACT_CONSTRAINT_NODEF; } else { - m_refDirection /= len; + m_refDirection[0] /= len; + m_refDirection[1] /= len; + m_refDirection[2] /= len; + m_refDirVector /= len; } m_minimumBound = cos(minBound); m_maximumBound = cos(maxBound); @@ -116,7 +122,7 @@ bool KX_ConstraintActuator::RayHit(KX_ClientObjectInfo* client, KX_RayCast* resu bool bFound = false; - if (m_property[0] == 0) + if (m_property.IsEmpty()) { bFound = true; } @@ -126,7 +132,7 @@ bool KX_ConstraintActuator::RayHit(KX_ClientObjectInfo* client, KX_RayCast* resu { if (client->m_auxilary_info) { - bFound = !strcmp(m_property, ((char*)client->m_auxilary_info)); + bFound = !strcmp(m_property.Ptr(), ((char*)client->m_auxilary_info)); } } else @@ -209,7 +215,7 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame) if ((m_maximumBound < (1.0f-FLT_EPSILON)) || (m_minimumBound < (1.0f-FLT_EPSILON))) { // reference direction needs to be evaluated // 1. get the cosine between current direction and target - cosangle = direction.dot(m_refDirection); + cosangle = direction.dot(m_refDirVector); if (cosangle >= (m_maximumBound-FLT_EPSILON) && cosangle <= (m_minimumBound+FLT_EPSILON)) { // no change to do result = true; @@ -218,27 +224,27 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame) // 2. define a new reference direction // compute local axis with reference direction as X and // Y in direction X refDirection plane - MT_Vector3 zaxis = m_refDirection.cross(direction); + MT_Vector3 zaxis = m_refDirVector.cross(direction); if (MT_fuzzyZero2(zaxis.length2())) { // direction and refDirection are identical, // choose any other direction to define plane if (direction[0] < 0.9999) - zaxis = m_refDirection.cross(MT_Vector3(1.0,0.0,0.0)); + zaxis = m_refDirVector.cross(MT_Vector3(1.0,0.0,0.0)); else - zaxis = m_refDirection.cross(MT_Vector3(0.0,1.0,0.0)); + zaxis = m_refDirVector.cross(MT_Vector3(0.0,1.0,0.0)); } - MT_Vector3 yaxis = zaxis.cross(m_refDirection); + MT_Vector3 yaxis = zaxis.cross(m_refDirVector); yaxis.normalize(); if (cosangle > m_minimumBound) { // angle is too close to reference direction, // choose a new reference that is exactly at minimum angle - refDirection = m_minimumBound * m_refDirection + m_minimumSine * yaxis; + refDirection = m_minimumBound * m_refDirVector + m_minimumSine * yaxis; } else { // angle is too large, choose new reference direction at maximum angle - refDirection = m_maximumBound * m_refDirection + m_maximumSine * yaxis; + refDirection = m_maximumBound * m_refDirVector + m_maximumSine * yaxis; } } else { - refDirection = m_refDirection; + refDirection = m_refDirVector; } // apply damping on the direction direction = filter*direction + (1.0-filter)*refDirection; @@ -470,7 +476,7 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame) // Fh force is stored in m_maximum MT_Scalar springForce = springExtent * m_maximumBound; // damping is stored in m_refDirection [0] = damping, [1] = rot damping - MT_Scalar springDamp = relativeVelocityRay * m_refDirection[0]; + MT_Scalar springDamp = relativeVelocityRay * m_refDirVector[0]; MT_Vector3 newVelocity = spc->GetLinearVelocity()-(springForce+springDamp)*direction; if (m_option & KX_ACT_CONSTRAINT_NORMAL) { @@ -483,7 +489,7 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame) MT_Vector3 angVelocity = spc->GetAngularVelocity(); // remove component that is parallel to normal angVelocity -= angVelocity.dot(newnormal)*newnormal; - MT_Vector3 angDamp = angVelocity * ((m_refDirection[1]>MT_EPSILON)?m_refDirection[1]:m_refDirection[0]); + MT_Vector3 angDamp = angVelocity * ((m_refDirVector[1]>MT_EPSILON)?m_refDirVector[1]:m_refDirVector[0]); spc->SetAngularVelocity(spc->GetAngularVelocity()+(angSpring-angDamp), false); } } else if (m_option & KX_ACT_CONSTRAINT_PERMANENT) { @@ -587,6 +593,7 @@ PyParentObject KX_ConstraintActuator::Parents[] = { }; PyMethodDef KX_ConstraintActuator::Methods[] = { + // Deprecated --> {"setDamp", (PyCFunction) KX_ConstraintActuator::sPySetDamp, METH_VARARGS, (PY_METHODCHAR)SetDamp_doc}, {"getDamp", (PyCFunction) KX_ConstraintActuator::sPyGetDamp, METH_NOARGS, (PY_METHODCHAR)GetDamp_doc}, {"setRotDamp", (PyCFunction) KX_ConstraintActuator::sPySetRotDamp, METH_VARARGS, (PY_METHODCHAR)SetRotDamp_doc}, @@ -609,17 +616,49 @@ PyMethodDef KX_ConstraintActuator::Methods[] = { {"getRayLength", (PyCFunction) KX_ConstraintActuator::sPyGetMax, METH_NOARGS, (PY_METHODCHAR)GetRayLength_doc}, {"setLimit", (PyCFunction) KX_ConstraintActuator::sPySetLimit, METH_VARARGS, (PY_METHODCHAR)SetLimit_doc}, {"getLimit", (PyCFunction) KX_ConstraintActuator::sPyGetLimit, METH_NOARGS, (PY_METHODCHAR)GetLimit_doc}, + // <-- {NULL,NULL} //Sentinel }; PyAttributeDef KX_ConstraintActuator::Attributes[] = { + KX_PYATTRIBUTE_INT_RW("damp",0,100,true,KX_ConstraintActuator,m_posDampTime), + KX_PYATTRIBUTE_INT_RW("rotDamp",0,100,true,KX_ConstraintActuator,m_rotDampTime), + KX_PYATTRIBUTE_FLOAT_ARRAY_RW_CHECK("direction",-MAXFLOAT,MAXFLOAT,KX_ConstraintActuator,m_refDirection,3,pyattr_check_direction), + KX_PYATTRIBUTE_INT_RW("option",0,0xFFFF,false,KX_ConstraintActuator,m_option), + KX_PYATTRIBUTE_INT_RW("time",0,1000,true,KX_ConstraintActuator,m_activeTime), + KX_PYATTRIBUTE_STRING_RW("property",0,32,true,KX_ConstraintActuator,m_property), + KX_PYATTRIBUTE_FLOAT_RW("min",-MAXFLOAT,MAXFLOAT,KX_ConstraintActuator,m_minimumBound), + KX_PYATTRIBUTE_FLOAT_RW("distance",-MAXFLOAT,MAXFLOAT,KX_ConstraintActuator,m_minimumBound), + KX_PYATTRIBUTE_FLOAT_RW("max",-MAXFLOAT,MAXFLOAT,KX_ConstraintActuator,m_maximumBound), + KX_PYATTRIBUTE_FLOAT_RW("rayLength",0,2000.f,KX_ConstraintActuator,m_maximumBound), + KX_PYATTRIBUTE_INT_RW("limit",KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF+1,KX_ConstraintActuator::KX_ACT_CONSTRAINT_MAX-1,false,KX_ConstraintActuator,m_locrot), { NULL } //Sentinel }; -PyObject* KX_ConstraintActuator::py_getattro(PyObject *attr) { +PyObject* KX_ConstraintActuator::py_getattro(PyObject *attr) +{ py_getattro_up(SCA_IActuator); } +int KX_ConstraintActuator::py_setattro(PyObject *attr, PyObject* value) +{ + py_setattro_up(SCA_IActuator); +} + + +int KX_ConstraintActuator::pyattr_check_direction(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_ConstraintActuator* act = static_cast(self); + MT_Vector3 dir(act->m_refDirection); + MT_Scalar len = dir.length(); + if (MT_fuzzyZero(len)) { + PyErr_SetString(PyExc_ValueError, "Invalid direction"); + return 1; + } + act->m_refDirVector = dir/len; + return 0; +} + /* 2. setDamp */ const char KX_ConstraintActuator::SetDamp_doc[] = "setDamp(duration)\n" @@ -629,6 +668,7 @@ const char KX_ConstraintActuator::SetDamp_doc[] = PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setDamp()", "the damp property"); int dampArg; if(!PyArg_ParseTuple(args, "i", &dampArg)) { return NULL; @@ -644,6 +684,7 @@ const char KX_ConstraintActuator::GetDamp_doc[] = "getDamp()\n" "\tReturns the damping parameter.\n"; PyObject* KX_ConstraintActuator::PyGetDamp(PyObject* self){ + ShowDeprecationWarning("getDamp()", "the damp property"); return PyInt_FromLong(m_posDampTime); } @@ -656,6 +697,7 @@ const char KX_ConstraintActuator::SetRotDamp_doc[] = PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setRotDamp()", "the rotDamp property"); int dampArg; if(!PyArg_ParseTuple(args, "i", &dampArg)) { return NULL; @@ -671,6 +713,7 @@ const char KX_ConstraintActuator::GetRotDamp_doc[] = "getRotDamp()\n" "\tReturns the damping time for application of the constraint.\n"; PyObject* KX_ConstraintActuator::PyGetRotDamp(PyObject* self){ + ShowDeprecationWarning("getRotDamp()", "the rotDamp property"); return PyInt_FromLong(m_rotDampTime); } @@ -682,6 +725,7 @@ const char KX_ConstraintActuator::SetDirection_doc[] = PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setDirection()", "the direction property"); float x, y, z; MT_Scalar len; MT_Vector3 dir; @@ -697,7 +741,10 @@ PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, std::cout << "Invalid direction" << std::endl; return NULL; } - m_refDirection = dir/len; + m_refDirVector = dir/len; + m_refDirection[0] = x/len; + m_refDirection[1] = y/len; + m_refDirection[2] = z/len; Py_RETURN_NONE; } @@ -706,6 +753,7 @@ const char KX_ConstraintActuator::GetDirection_doc[] = "getDirection()\n" "\tReturns the reference direction of the orientation constraint as a 3-tuple.\n"; PyObject* KX_ConstraintActuator::PyGetDirection(PyObject* self){ + ShowDeprecationWarning("getDirection()", "the direction property"); PyObject *retVal = PyList_New(3); PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_refDirection[0])); @@ -727,6 +775,7 @@ const char KX_ConstraintActuator::SetOption_doc[] = PyObject* KX_ConstraintActuator::PySetOption(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setOption()", "the option property"); int option; if(!PyArg_ParseTuple(args, "i", &option)) { return NULL; @@ -741,6 +790,7 @@ const char KX_ConstraintActuator::GetOption_doc[] = "getOption()\n" "\tReturns the option parameter.\n"; PyObject* KX_ConstraintActuator::PyGetOption(PyObject* self){ + ShowDeprecationWarning("getOption()", "the option property"); return PyInt_FromLong(m_option); } @@ -754,6 +804,7 @@ const char KX_ConstraintActuator::SetTime_doc[] = PyObject* KX_ConstraintActuator::PySetTime(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setTime()", "the time property"); int t; if(!PyArg_ParseTuple(args, "i", &t)) { return NULL; @@ -770,6 +821,7 @@ const char KX_ConstraintActuator::GetTime_doc[] = "getTime()\n" "\tReturns the time parameter.\n"; PyObject* KX_ConstraintActuator::PyGetTime(PyObject* self){ + ShowDeprecationWarning("getTime()", "the time property"); return PyInt_FromLong(m_activeTime); } @@ -782,15 +834,15 @@ const char KX_ConstraintActuator::SetProperty_doc[] = PyObject* KX_ConstraintActuator::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setProperty()", "the 'property' property"); char *property; if (!PyArg_ParseTuple(args, "s", &property)) { return NULL; } if (property == NULL) { - m_property[0] = 0; + m_property = ""; } else { - strncpy(m_property, property, sizeof(m_property)); - m_property[sizeof(m_property)-1] = 0; + m_property = property; } Py_RETURN_NONE; @@ -800,7 +852,8 @@ const char KX_ConstraintActuator::GetProperty_doc[] = "getProperty()\n" "\tReturns the property parameter.\n"; PyObject* KX_ConstraintActuator::PyGetProperty(PyObject* self){ - return PyString_FromString(m_property); + ShowDeprecationWarning("getProperty()", "the 'property' property"); + return PyString_FromString(m_property.Ptr()); } /* 4. setDistance */ @@ -817,6 +870,7 @@ const char KX_ConstraintActuator::SetMin_doc[] = PyObject* KX_ConstraintActuator::PySetMin(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setMin() or setDistance()", "the min or distance property"); float minArg; if(!PyArg_ParseTuple(args, "f", &minArg)) { return NULL; @@ -845,6 +899,7 @@ const char KX_ConstraintActuator::GetMin_doc[] = "\tReturns the lower value of the interval to which the value\n" "\tis clipped.\n"; PyObject* KX_ConstraintActuator::PyGetMin(PyObject* self) { + ShowDeprecationWarning("getMin() or getDistance()", "the min or distance property"); return PyFloat_FromDouble(m_minimumBound); } @@ -862,6 +917,7 @@ const char KX_ConstraintActuator::SetMax_doc[] = PyObject* KX_ConstraintActuator::PySetMax(PyObject* self, PyObject* args, PyObject* kwds){ + ShowDeprecationWarning("setMax() or setRayLength()", "the max or rayLength property"); float maxArg; if(!PyArg_ParseTuple(args, "f", &maxArg)) { return NULL; @@ -890,6 +946,7 @@ const char KX_ConstraintActuator::GetMax_doc[] = "\tReturns the upper value of the interval to which the value\n" "\tis clipped.\n"; PyObject* KX_ConstraintActuator::PyGetMax(PyObject* self) { + ShowDeprecationWarning("getMax() or getRayLength()", "the max or rayLength property"); return PyFloat_FromDouble(m_maximumBound); } @@ -915,6 +972,7 @@ const char KX_ConstraintActuator::SetLimit_doc[] = PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self, PyObject* args, PyObject* kwds) { + ShowDeprecationWarning("setLimit()", "the limit property"); int locrotArg; if(!PyArg_ParseTuple(args, "i", &locrotArg)) { return NULL; @@ -929,6 +987,7 @@ const char KX_ConstraintActuator::GetLimit_doc[] = "getLimit()\n" "\tReturns the type of constraint.\n"; PyObject* KX_ConstraintActuator::PyGetLimit(PyObject* self) { + ShowDeprecationWarning("setLimit()", "the limit property"); return PyInt_FromLong(m_locrot); } diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.h b/source/gameengine/Ketsji/KX_ConstraintActuator.h index 193400fbf2b..7ad6e043c49 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.h +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.h @@ -56,7 +56,8 @@ protected: // sinus of maximum angle float m_maximumSine; // reference direction - MT_Vector3 m_refDirection; + float m_refDirection[3]; + MT_Vector3 m_refDirVector; // same as m_refDirection // locrotxyz choice (pick one): only one choice allowed at a time! int m_locrot; // active time of actuator @@ -65,7 +66,7 @@ protected: // option int m_option; // property to check - char m_property[32]; + STR_String m_property; // hit object KX_GameObject* m_hitObject; @@ -143,6 +144,10 @@ protected: /* --------------------------------------------------------------------- */ virtual PyObject* py_getattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject* value); + + static int pyattr_check_direction(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_check_min(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); KX_PYMETHOD_DOC(KX_ConstraintActuator,SetDamp); KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetDamp); diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 4ad9853f9c4..7ed83465c49 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1000,6 +1000,12 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX); KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY); KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ); + KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHPX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPX); + KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHPY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPY); + KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHPZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPZ); + KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHNX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNX); + KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHNY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNY); + KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_FHNZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNZ); /* 4. Ipo actuator, simple part */ KX_MACRO_addTypesToDict(d, KX_IPOACT_PLAY, KX_IpoActuator::KX_ACT_IPO_PLAY); @@ -1160,6 +1166,12 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, KX_STATE_OP_CLR, KX_StateActuator::OP_CLR); KX_MACRO_addTypesToDict(d, KX_STATE_OP_NEG, KX_StateActuator::OP_NEG); + KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_NORMAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_NORMAL); + KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_MATERIAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_MATERIAL); + KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_PERMANENT, KX_ConstraintActuator::KX_ACT_CONSTRAINT_PERMANENT); + KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_DISTANCE, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DISTANCE); + KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_LOCAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCAL); + KX_MACRO_addTypesToDict(d, KX_ACT_CONSTRAINT_DOROTFH, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DOROTFH); // Check for errors if (PyErr_Occurred()) diff --git a/source/gameengine/PyDoc/KX_ConstraintActuator.py b/source/gameengine/PyDoc/KX_ConstraintActuator.py index 7c7ad5aa0fa..a30b859548b 100644 --- a/source/gameengine/PyDoc/KX_ConstraintActuator.py +++ b/source/gameengine/PyDoc/KX_ConstraintActuator.py @@ -5,6 +5,75 @@ from SCA_IActuator import * class KX_ConstraintActuator(SCA_IActuator): """ A constraint actuator limits the position, rotation, distance or orientation of an object. + + Properties: + + @ivar damp: time constant of the constraint expressed in frame (not use by Force field constraint) + @type damp: integer + + @ivar rotDamp: time constant for the rotation expressed in frame (only for the distance constraint) + 0 = use damp for rotation as well + @type rotDamp: integer + + @ivar direction: the reference direction in world coordinate for the orientation constraint + @type direction: 3-tuple of float: [x,y,z] + + @ivar option: Binary combination of the following values: + Applicable to Distance constraint: + KX_ACT_CONSTRAINT_NORMAL ( 64) : Activate alignment to surface + KX_ACT_CONSTRAINT_DISTANCE ( 512) : Activate distance control + KX_ACT_CONSTRAINT_LOCAL (1024) : direction of the ray is along the local axis + Applicable to Force field constraint: + KX_ACT_CONSTRAINT_DOROTFH (2048) : Force field act on rotation as well + Applicable to both: + KX_ACT_CONSTRAINT_MATERIAL ( 128) : Detect material rather than property + KX_ACT_CONSTRAINT_PERMANENT ( 256) : No deactivation if ray does not hit target + @type option: integer + + @ivar time: activation time of the actuator. The actuator disables itself after this many frame. + If set to 0, the actuator is not limited in time. + @type time: integer + + @ivar property: the name of the property or material for the ray detection of the distance constraint. + @type property: string + + @ivar min: The lower bound of the constraint + For the rotation and orientation constraint, it represents radiant + @type min: float + + @ivar distance: the target distance of the distance constraint + @type distance: float + + @ivar max: the upper bound of the constraint. + For rotation and orientation constraints, it represents radiant. + @type max: float + + @ivar rayLength: the length of the ray of the distance constraint. + @type rayLength: float + + @ivar limit: type of constraint, use one of the following constant: + KX_ACT_CONSTRAINT_LOCX ( 1) : limit X coord + KX_ACT_CONSTRAINT_LOCY ( 2) : limit Y coord + KX_ACT_CONSTRAINT_LOCZ ( 3) : limit Z coord + KX_ACT_CONSTRAINT_ROTX ( 4) : limit X rotation + KX_ACT_CONSTRAINT_ROTY ( 5) : limit Y rotation + KX_ACT_CONSTRAINT_ROTZ ( 6) : limit Z rotation + KX_ACT_CONSTRAINT_DIRPX ( 7) : set distance along positive X axis + KX_ACT_CONSTRAINT_DIRPY ( 8) : set distance along positive Y axis + KX_ACT_CONSTRAINT_DIRPZ ( 9) : set distance along positive Z axis + KX_ACT_CONSTRAINT_DIRNX (10) : set distance along negative X axis + KX_ACT_CONSTRAINT_DIRNY (11) : set distance along negative Y axis + KX_ACT_CONSTRAINT_DIRNZ (12) : set distance along negative Z axis + KX_ACT_CONSTRAINT_ORIX (13) : set orientation of X axis + KX_ACT_CONSTRAINT_ORIY (14) : set orientation of Y axis + KX_ACT_CONSTRAINT_ORIZ (15) : set orientation of Z axis + KX_ACT_CONSTRAINT_FHPX (16) : set force field along positive X axis + KX_ACT_CONSTRAINT_FHPY (17) : set force field along positive Y axis + KX_ACT_CONSTRAINT_FHPZ (18) : set force field along positive Z axis + KX_ACT_CONSTRAINT_FHNX (19) : set force field along negative X axis + KX_ACT_CONSTRAINT_FHNY (20) : set force field along negative Y axis + KX_ACT_CONSTRAINT_FHNZ (21) : set force field along negative Z axis + @type limit: integer """ def setDamp(time): """ diff --git a/source/gameengine/PyDoc/KX_StateActuator.py b/source/gameengine/PyDoc/KX_StateActuator.py index fb6ae5a3621..fe3669d3809 100644 --- a/source/gameengine/PyDoc/KX_StateActuator.py +++ b/source/gameengine/PyDoc/KX_StateActuator.py @@ -5,9 +5,26 @@ from SCA_IActuator import * class KX_StateActuator(SCA_IActuator): """ State actuator changes the state mask of parent object. + + Property: + + @ivar operation: type of bit operation to be applied on object state mask. + You can use one of the following constant: + KX_STATE_OP_CPY (0) : Copy state mask + KX_STATE_OP_SET (1) : Add bits to state mask + KX_STATE_OP_CLR (2) : Substract bits to state mask + KX_STATE_OP_NEG (3) : Invert bits to state mask + @type operation: integer + + @ivar mask: value that defines the bits that will be modified by the operation. + The bits that are 1 in the mask will be updated in the object state, + the bits that are 0 are will be left unmodified expect for the Copy operation + which copies the mask to the object state + @type mask: integer """ def setOperation(op): """ + DEPRECATED: Use the operation property instead. Set the type of bit operation to be applied on object state mask. Use setMask() to specify the bits that will be modified. @@ -16,6 +33,7 @@ class KX_StateActuator(SCA_IActuator): """ def setMask(mask): """ + DEPRECATED: Use the mask property instead. Set the value that defines the bits that will be modified by the operation. The bits that are 1 in the value will be updated in the object state, the bits that are 0 are will be left unmodified expect for the Copy operation -- cgit v1.2.3 From 2fff90bbb4a922f454c15dbf2d6215bd4d8c519c Mon Sep 17 00:00:00 2001 From: Andre Susano Pinto Date: Fri, 10 Apr 2009 16:45:19 +0000 Subject: Added function name to many of the PyArg_ParseTuple calls in gameengine This way python raises more useful messages. --- source/gameengine/Converter/BL_ActionActuator.cpp | 24 +++++++-------- .../Converter/BL_ShapeActionActuator.cpp | 20 ++++++------- source/gameengine/Expressions/Value.cpp | 2 +- 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 | 10 +++---- source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 8 ++--- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 6 ++-- .../gameengine/GameLogic/SCA_PropertyActuator.cpp | 4 +-- source/gameengine/GameLogic/SCA_PropertySensor.cpp | 6 ++-- .../gameengine/GameLogic/SCA_PythonController.cpp | 2 +- source/gameengine/GameLogic/SCA_RandomActuator.cpp | 22 +++++++------- source/gameengine/GameLogic/SCA_RandomSensor.cpp | 2 +- source/gameengine/Ketsji/BL_Shader.cpp | 34 +++++++++++----------- .../Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp | 8 ++--- source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 2 +- source/gameengine/Ketsji/KX_CDActuator.cpp | 2 +- source/gameengine/Ketsji/KX_Camera.cpp | 2 +- source/gameengine/Ketsji/KX_CameraActuator.cpp | 10 +++---- source/gameengine/Ketsji/KX_ConstraintActuator.cpp | 18 ++++++------ source/gameengine/Ketsji/KX_GameActuator.cpp | 2 +- source/gameengine/Ketsji/KX_IpoActuator.cpp | 16 +++++----- source/gameengine/Ketsji/KX_MeshProxy.cpp | 10 +++---- source/gameengine/Ketsji/KX_ObjectActuator.cpp | 22 +++++++------- source/gameengine/Ketsji/KX_ParentActuator.cpp | 2 +- .../gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp | 8 ++--- source/gameengine/Ketsji/KX_PolyProxy.cpp | 2 +- source/gameengine/Ketsji/KX_PolygonMaterial.cpp | 8 ++--- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp | 6 ++-- .../gameengine/Ketsji/KX_SCA_DynamicActuator.cpp | 2 +- source/gameengine/Ketsji/KX_Scene.cpp | 2 +- source/gameengine/Ketsji/KX_SceneActuator.cpp | 8 ++--- source/gameengine/Ketsji/KX_SoundActuator.cpp | 16 +++++----- source/gameengine/Ketsji/KX_StateActuator.cpp | 4 +-- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 6 ++-- source/gameengine/Ketsji/KX_VehicleWrapper.cpp | 24 +++++++-------- source/gameengine/Ketsji/KX_VisibilityActuator.cpp | 2 +- 38 files changed, 166 insertions(+), 166 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 8d7624db5d4..960eafda230 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -573,7 +573,7 @@ PyObject* BL_ActionActuator::PySetAction(PyObject* self, char *string; int reset = 1; - if (PyArg_ParseTuple(args,"s|i",&string, &reset)) + if (PyArg_ParseTuple(args,"s|i:setAction",&string, &reset)) { bAction *action; @@ -608,7 +608,7 @@ PyObject* BL_ActionActuator::PySetStart(PyObject* self, float start; - if (PyArg_ParseTuple(args,"f",&start)) + if (PyArg_ParseTuple(args,"f:setStart",&start)) { m_startframe = start; } @@ -631,7 +631,7 @@ PyObject* BL_ActionActuator::PySetEnd(PyObject* self, float end; - if (PyArg_ParseTuple(args,"f",&end)) + if (PyArg_ParseTuple(args,"f:setEnd",&end)) { m_endframe = end; } @@ -655,7 +655,7 @@ PyObject* BL_ActionActuator::PySetBlendin(PyObject* self, float blendin; - if (PyArg_ParseTuple(args,"f",&blendin)) + if (PyArg_ParseTuple(args,"f:setBlendin",&blendin)) { m_blendin = blendin; } @@ -680,7 +680,7 @@ PyObject* BL_ActionActuator::PySetBlendtime(PyObject* self, float blendframe; - if (PyArg_ParseTuple(args,"f",&blendframe)) + if (PyArg_ParseTuple(args,"f:setBlendtime",&blendframe)) { m_blendframe = blendframe * m_blendin; if (m_blendframe<0) @@ -709,7 +709,7 @@ PyObject* BL_ActionActuator::PySetPriority(PyObject* self, int priority; - if (PyArg_ParseTuple(args,"i",&priority)) + if (PyArg_ParseTuple(args,"i:setPriority",&priority)) { m_priority = priority; } @@ -732,7 +732,7 @@ PyObject* BL_ActionActuator::PySetFrame(PyObject* self, float frame; - if (PyArg_ParseTuple(args,"f",&frame)) + if (PyArg_ParseTuple(args,"f:setFrame",&frame)) { m_localtime = frame; if (m_localtimeob_type == &CListValue::Type) diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index 32fd566983a..0d35b26d604 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -610,7 +610,7 @@ PyObject* BL_ShapeActionActuator::PySetAction(PyObject* self, char *string; int reset = 1; - if (PyArg_ParseTuple(args,"s|i",&string, &reset)) + if (PyArg_ParseTuple(args,"s|i:setAction",&string, &reset)) { bAction *action; @@ -644,7 +644,7 @@ PyObject* BL_ShapeActionActuator::PySetStart(PyObject* self, ShowDeprecationWarning("setStart()", "the start property"); float start; - if (PyArg_ParseTuple(args,"f",&start)) + if (PyArg_ParseTuple(args,"f:setStart",&start)) { m_startframe = start; } @@ -666,7 +666,7 @@ PyObject* BL_ShapeActionActuator::PySetEnd(PyObject* self, ShowDeprecationWarning("setEnd()", "the end property"); float end; - if (PyArg_ParseTuple(args,"f",&end)) + if (PyArg_ParseTuple(args,"f:setEnd",&end)) { m_endframe = end; } @@ -689,7 +689,7 @@ PyObject* BL_ShapeActionActuator::PySetBlendin(PyObject* self, ShowDeprecationWarning("setBlendin()", "the blendin property"); float blendin; - if (PyArg_ParseTuple(args,"f",&blendin)) + if (PyArg_ParseTuple(args,"f:setBlendin",&blendin)) { m_blendin = blendin; } @@ -713,7 +713,7 @@ PyObject* BL_ShapeActionActuator::PySetBlendtime(PyObject* self, ShowDeprecationWarning("setBlendtime()", "the blendTime property"); float blendframe; - if (PyArg_ParseTuple(args,"f",&blendframe)) + if (PyArg_ParseTuple(args,"f:setBlendtime",&blendframe)) { m_blendframe = blendframe * m_blendin; if (m_blendframe<0.f) @@ -741,7 +741,7 @@ PyObject* BL_ShapeActionActuator::PySetPriority(PyObject* self, ShowDeprecationWarning("setPriority()", "the priority property"); int priority; - if (PyArg_ParseTuple(args,"i",&priority)) + if (PyArg_ParseTuple(args,"i:setPriority",&priority)) { m_priority = priority; } @@ -778,7 +778,7 @@ PyObject* BL_ShapeActionActuator::PySetFrame(PyObject* self, ShowDeprecationWarning("setFrame()", "the frame property"); float frame; - if (PyArg_ParseTuple(args,"f",&frame)) + if (PyArg_ParseTuple(args,"f:setFrame",&frame)) { m_localtime = frame; if (m_localtimeGetJoystickDevice(m_joyindex); int index; - if(!PyArg_ParseTuple(args, "i", &index)){ + if(!PyArg_ParseTuple(args, "i:getButtonStatus", &index)){ return NULL; } if(joy && index >= 0 && index < joy->GetNumberOfButtons()) { @@ -530,7 +530,7 @@ const char SCA_JoystickSensor::SetHat_doc[] = PyObject* SCA_JoystickSensor::PySetHat( PyObject* self, PyObject* args ) { ShowDeprecationWarning("setHat()", "the hat property"); int hat,hatflag; - if(!PyArg_ParseTuple(args, "ii", &hat, &hatflag)){ + if(!PyArg_ParseTuple(args, "ii:setHat", &hat, &hatflag)){ return NULL; } m_hat = hat; diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index ecdf889124d..0bf19360b15 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -428,7 +428,7 @@ PyObject* SCA_KeyboardSensor::PySetKey(PyObject* self, PyObject* args, PyObject* ShowDeprecationWarning("setKey()", "the key property"); int keyCode; - if(!PyArg_ParseTuple(args, "i", &keyCode)) { + if(!PyArg_ParseTuple(args, "i:setKey", &keyCode)) { return NULL; } @@ -460,7 +460,7 @@ PyObject* SCA_KeyboardSensor::PySetHold1(PyObject* self, PyObject* args, PyObjec ShowDeprecationWarning("setHold1()", "the hold1 property"); int keyCode; - if(!PyArg_ParseTuple(args, "i", &keyCode)) { + if(!PyArg_ParseTuple(args, "i:setHold1", &keyCode)) { return NULL; } @@ -492,7 +492,7 @@ PyObject* SCA_KeyboardSensor::PySetHold2(PyObject* self, PyObject* args, PyObjec ShowDeprecationWarning("setHold2()", "the hold2 property"); int keyCode; - if(!PyArg_ParseTuple(args, "i", &keyCode)) { + if(!PyArg_ParseTuple(args, "i:setHold2", &keyCode)) { return NULL; } diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index fa8763a3932..444c616870d 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -279,7 +279,7 @@ PyObject* SCA_PropertyActuator::PySetProperty(PyObject* self, PyObject* args, Py ShowDeprecationWarning("setProperty()", "the 'property' property"); /* Check whether the name exists first ! */ char *nameArg; - if (!PyArg_ParseTuple(args, "s", &nameArg)) { + if (!PyArg_ParseTuple(args, "s:setProperty", &nameArg)) { return NULL; } @@ -316,7 +316,7 @@ PyObject* SCA_PropertyActuator::PySetValue(PyObject* self, PyObject* args, PyObj { ShowDeprecationWarning("setValue()", "the value property"); char *valArg; - if(!PyArg_ParseTuple(args, "s", &valArg)) { + if(!PyArg_ParseTuple(args, "s:setValue", &valArg)) { return NULL; } diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp index 164e94b6597..9ae7be16b12 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp +++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp @@ -382,7 +382,7 @@ PyObject* SCA_PropertySensor::PySetType(PyObject* self, PyObject* args, PyObject ShowDeprecationWarning("setType()", "the type property"); int typeArg; - if (!PyArg_ParseTuple(args, "i", &typeArg)) { + if (!PyArg_ParseTuple(args, "i:setType", &typeArg)) { return NULL; } @@ -417,7 +417,7 @@ PyObject* SCA_PropertySensor::PySetProperty(PyObject* self, PyObject* args, PyOb /* on the fly? */ char *propNameArg = NULL; - if (!PyArg_ParseTuple(args, "s", &propNameArg)) { + if (!PyArg_ParseTuple(args, "s:setProperty", &propNameArg)) { return NULL; } @@ -455,7 +455,7 @@ PyObject* SCA_PropertySensor::PySetValue(PyObject* self, PyObject* args, PyObjec /* We know that the property exists, or is NULL. */ char *propValArg = NULL; - if(!PyArg_ParseTuple(args, "s", &propValArg)) { + if(!PyArg_ParseTuple(args, "s:setValue", &propValArg)) { return NULL; } STR_String oldval = m_checkpropval; diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 3c2a1d09f82..0e6b9d1e8f1 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -205,7 +205,7 @@ PyObject* SCA_PythonController::sPyAddActiveActuator( PyObject* ob1; int activate; - if (!PyArg_ParseTuple(args, "Oi", &ob1,&activate)) + if (!PyArg_ParseTuple(args, "Oi:addActiveActuator", &ob1,&activate)) return NULL; SCA_IActuator* actu = LinkedActuatorFromPy(ob1); diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp index b1c0c7fec99..d5d993c4ba6 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp +++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp @@ -410,7 +410,7 @@ const char SCA_RandomActuator::SetSeed_doc[] = PyObject* SCA_RandomActuator::PySetSeed(PyObject* self, PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setSeed()", "the seed property"); long seedArg; - if(!PyArg_ParseTuple(args, "i", &seedArg)) { + if(!PyArg_ParseTuple(args, "i:setSeed", &seedArg)) { return NULL; } @@ -468,7 +468,7 @@ const char SCA_RandomActuator::SetProperty_doc[] = PyObject* SCA_RandomActuator::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setProperty()", "the 'property' property"); char *nameArg; - if (!PyArg_ParseTuple(args, "s", &nameArg)) { + if (!PyArg_ParseTuple(args, "s:setProperty", &nameArg)) { return NULL; } @@ -500,7 +500,7 @@ KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setBoolConst, "\tSet this generator to produce a constant boolean value.\n") { int paraArg; - if(!PyArg_ParseTuple(args, "i", ¶Arg)) { + if(!PyArg_ParseTuple(args, "i:setBoolConst", ¶Arg)) { return NULL; } @@ -526,7 +526,7 @@ KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setBoolBernouilli, "\tReturn false value * 100%% of the time.\n") { float paraArg; - if(!PyArg_ParseTuple(args, "f", ¶Arg)) { + if(!PyArg_ParseTuple(args, "f:setBoolBernouilli", ¶Arg)) { return NULL; } @@ -542,7 +542,7 @@ KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntConst, "\tAlways return value\n") { int paraArg; - if(!PyArg_ParseTuple(args, "i", ¶Arg)) { + if(!PyArg_ParseTuple(args, "i:setIntConst", ¶Arg)) { return NULL; } @@ -560,7 +560,7 @@ KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntUniform, "\tupper_bound. The boundaries are included.\n") { int paraArg1, paraArg2; - if(!PyArg_ParseTuple(args, "ii", ¶Arg1, ¶Arg2)) { + if(!PyArg_ParseTuple(args, "ii:setIntUniform", ¶Arg1, ¶Arg2)) { return NULL; } @@ -579,7 +579,7 @@ KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntPoisson, "\tnumber of tries needed to achieve succes.\n") { float paraArg; - if(!PyArg_ParseTuple(args, "f", ¶Arg)) { + if(!PyArg_ParseTuple(args, "f:setIntPoisson", ¶Arg)) { return NULL; } @@ -595,7 +595,7 @@ KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatConst, "\tAlways return value\n") { float paraArg; - if(!PyArg_ParseTuple(args, "f", ¶Arg)) { + if(!PyArg_ParseTuple(args, "f:setFloatConst", ¶Arg)) { return NULL; } @@ -613,7 +613,7 @@ KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatUniform, "\tupper_bound.\n") { float paraArg1, paraArg2; - if(!PyArg_ParseTuple(args, "ff", ¶Arg1, ¶Arg2)) { + if(!PyArg_ParseTuple(args, "ff:setFloatUniform", ¶Arg1, ¶Arg2)) { return NULL; } @@ -632,7 +632,7 @@ KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatNormal, "\tdeviation from the mean is characterized by standard_deviation.\n") { float paraArg1, paraArg2; - if(!PyArg_ParseTuple(args, "ff", ¶Arg1, ¶Arg2)) { + if(!PyArg_ParseTuple(args, "ff:setFloatNormal", ¶Arg1, ¶Arg2)) { return NULL; } @@ -650,7 +650,7 @@ KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatNegativeExponential, "\tis characterized by half_life.\n") { float paraArg; - if(!PyArg_ParseTuple(args, "f", ¶Arg)) { + if(!PyArg_ParseTuple(args, "f:setFloatNegativeExponential", ¶Arg)) { return NULL; } diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp index fe4d88e2797..3179c8522f9 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp +++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp @@ -185,7 +185,7 @@ const char SCA_RandomSensor::SetSeed_doc[] = PyObject* SCA_RandomSensor::PySetSeed(PyObject* self, PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setSeed()", "the seed property"); long seedArg; - if(!PyArg_ParseTuple(args, "i", &seedArg)) { + if(!PyArg_ParseTuple(args, "i:setSeed", &seedArg)) { return NULL; } diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index c82a9979fe1..aae4fd74a08 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -807,7 +807,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setSource," setSource(vertexProgram, fragmentProg } char *v,*f; int apply=0; - if( PyArg_ParseTuple(args, "ssi", &v, &f, &apply) ) + if( PyArg_ParseTuple(args, "ssi:setSource", &v, &f, &apply) ) { vertProg = v; fragProg = f; @@ -890,7 +890,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setSampler, "setSampler(name, index)" ) const char *uniform=""; int index=-1; - if(PyArg_ParseTuple(args, "si", &uniform, &index)) + if(PyArg_ParseTuple(args, "si:setSampler", &uniform, &index)) { int loc = GetUniformLocation(uniform); if(loc != -1) { @@ -915,7 +915,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setSampler, "setSampler(name, index)" ) KX_PYMETHODDEF_DOC( BL_Shader, setNumberOfPasses, "setNumberOfPasses( max-pass )" ) { int pass = 1; - if(!PyArg_ParseTuple(args, "i", &pass)) + if(!PyArg_ParseTuple(args, "i:setNumberOfPasses", &pass)) return NULL; mPass = 1; @@ -931,7 +931,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform1f, "setUniform1f(name, fx)" ) const char *uniform=""; float value=0; - if(PyArg_ParseTuple(args, "sf", &uniform, &value )) + if(PyArg_ParseTuple(args, "sf:setUniform1f", &uniform, &value )) { int loc = GetUniformLocation(uniform); if(loc != -1) @@ -955,7 +955,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform2f , "setUniform2f(name, fx, fy)") } const char *uniform=""; float array[2]={ 0,0 }; - if(PyArg_ParseTuple(args, "sff", &uniform, &array[0],&array[1] )) + if(PyArg_ParseTuple(args, "sff:setUniform2f", &uniform, &array[0],&array[1] )) { int loc = GetUniformLocation(uniform); if(loc != -1) @@ -979,7 +979,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform3f, "setUniform3f(name, fx,fy,fz) ") } const char *uniform=""; float array[3]={0,0,0}; - if(PyArg_ParseTuple(args, "sfff", &uniform, &array[0],&array[1],&array[2])) + if(PyArg_ParseTuple(args, "sfff:setUniform3f", &uniform, &array[0],&array[1],&array[2])) { int loc = GetUniformLocation(uniform); if(loc != -1) @@ -1004,7 +1004,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform4f, "setUniform4f(name, fx,fy,fz, fw) " } const char *uniform=""; float array[4]={0,0,0,0}; - if(PyArg_ParseTuple(args, "sffff", &uniform, &array[0],&array[1],&array[2], &array[3])) + if(PyArg_ParseTuple(args, "sffff:setUniform4f", &uniform, &array[0],&array[1],&array[2], &array[3])) { int loc = GetUniformLocation(uniform); if(loc != -1) @@ -1028,7 +1028,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform1i, "setUniform1i(name, ix)" ) } const char *uniform=""; int value=0; - if(PyArg_ParseTuple(args, "si", &uniform, &value )) + if(PyArg_ParseTuple(args, "si:setUniform1i", &uniform, &value )) { int loc = GetUniformLocation(uniform); if(loc != -1) @@ -1052,7 +1052,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform2i , "setUniform2i(name, ix, iy)") } const char *uniform=""; int array[2]={ 0,0 }; - if(PyArg_ParseTuple(args, "sii", &uniform, &array[0],&array[1] )) + if(PyArg_ParseTuple(args, "sii:setUniform2i", &uniform, &array[0],&array[1] )) { int loc = GetUniformLocation(uniform); if(loc != -1) @@ -1077,7 +1077,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform3i, "setUniform3i(name, ix,iy,iz) ") const char *uniform=""; int array[3]={0,0,0}; - if(PyArg_ParseTuple(args, "siii", &uniform, &array[0],&array[1],&array[2])) + if(PyArg_ParseTuple(args, "siii:setUniform3i", &uniform, &array[0],&array[1],&array[2])) { int loc = GetUniformLocation(uniform); if(loc != -1) @@ -1100,7 +1100,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniform4i, "setUniform4i(name, ix,iy,iz, iw) " } const char *uniform=""; int array[4]={0,0,0, 0}; - if(PyArg_ParseTuple(args, "siiii", &uniform, &array[0],&array[1],&array[2], &array[3] )) + if(PyArg_ParseTuple(args, "siiii:setUniform4i", &uniform, &array[0],&array[1],&array[2], &array[3] )) { int loc = GetUniformLocation(uniform); if(loc != -1) @@ -1125,7 +1125,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformfv , "setUniformfv( float (list2 or lis PyObject *listPtr =0; float array_data[4] = {0.f,0.f,0.f,0.f}; - if(PyArg_ParseTuple(args, "sO", &uniform, &listPtr)) + if(PyArg_ParseTuple(args, "sO:setUniformfv", &uniform, &listPtr)) { int loc = GetUniformLocation(uniform); if(loc != -1) @@ -1194,7 +1194,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformiv, "setUniformiv( int (list2 or list3 PyObject *listPtr =0; int array_data[4] = {0,0,0,0}; - if(PyArg_ParseTuple(args, "sO", &uniform, &listPtr)) + if(PyArg_ParseTuple(args, "sO:setUniformiv", &uniform, &listPtr)) { int loc = GetUniformLocation(uniform); if(loc != -1) @@ -1273,7 +1273,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformMatrix4, const char *uniform=""; PyObject *matrix=0; int transp=1; // MT_ is row major so transpose by default.... - if(PyArg_ParseTuple(args, "sO|i",&uniform, &matrix,&transp)) + if(PyArg_ParseTuple(args, "sO|i:setUniformMatrix4",&uniform, &matrix,&transp)) { int loc = GetUniformLocation(uniform); if(loc != -1) @@ -1311,7 +1311,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformMatrix3, const char *uniform=""; PyObject *matrix=0; int transp=1; // MT_ is row major so transpose by default.... - if(PyArg_ParseTuple(args, "sO|i",&uniform, &matrix,&transp)) + if(PyArg_ParseTuple(args, "sO|i:setUniformMatrix3",&uniform, &matrix,&transp)) { int loc = GetUniformLocation(uniform); if(loc != -1) @@ -1338,7 +1338,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setAttrib, "setAttrib(enum)" ) Py_RETURN_NONE; } int attr=0; - if(PyArg_ParseTuple(args, "i", &attr )) { + if(PyArg_ParseTuple(args, "i:setAttrib", &attr )) { if(mShader==0) { PyErr_Format(PyExc_ValueError, "invalid shader object"); return NULL; @@ -1360,7 +1360,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformDef, "setUniformDef(name, enum)" ) const char *uniform=""; int nloc=0; - if(PyArg_ParseTuple(args, "si",&uniform, &nloc)) + if(PyArg_ParseTuple(args, "si:setUniformDef",&uniform, &nloc)) { int loc = GetUniformLocation(uniform); if(loc != -1) diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp index 72edde6ef24..d6d59692745 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp @@ -171,7 +171,7 @@ PyObject* KX_NetworkMessageActuator::PySetToPropName( ShowDeprecationWarning("setToProp()", "the propName property"); char* ToPropName; - if (PyArg_ParseTuple(args, "s", &ToPropName)) { + if (PyArg_ParseTuple(args, "s:setToPropName", &ToPropName)) { m_toPropName = ToPropName; } else { @@ -190,7 +190,7 @@ PyObject* KX_NetworkMessageActuator::PySetSubject( ShowDeprecationWarning("setSubject()", "the subject property"); char* Subject; - if (PyArg_ParseTuple(args, "s", &Subject)) { + if (PyArg_ParseTuple(args, "s:setSubject", &Subject)) { m_subject = Subject; } else { @@ -209,7 +209,7 @@ PyObject* KX_NetworkMessageActuator::PySetBodyType( ShowDeprecationWarning("setBodyType()", "the usePropBody property"); int BodyType; - if (PyArg_ParseTuple(args, "i", &BodyType)) { + if (PyArg_ParseTuple(args, "i:setBodyType", &BodyType)) { m_bPropBody = (BodyType != 0); } else { @@ -228,7 +228,7 @@ PyObject* KX_NetworkMessageActuator::PySetBody( ShowDeprecationWarning("setBody()", "the body property"); char* Body; - if (PyArg_ParseTuple(args, "s", &Body)) { + if (PyArg_ParseTuple(args, "s:setBody", &Body)) { m_body = Body; } else { diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index bd137196ac6..0e417dde5d2 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -897,7 +897,7 @@ static unsigned int GL_array[11] = { KX_PYMETHODDEF_DOC( KX_BlenderMaterial, setBlending , "setBlending( GameLogic.src, GameLogic.dest)") { unsigned int b[2]; - if(PyArg_ParseTuple(args, "ii", &b[0], &b[1])) + if(PyArg_ParseTuple(args, "ii:setBlending", &b[0], &b[1])) { bool value_found[2] = {false, false}; for(int i=0; i<11; i++) diff --git a/source/gameengine/Ketsji/KX_CDActuator.cpp b/source/gameengine/Ketsji/KX_CDActuator.cpp index 8e889fb4129..c3d28656159 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.cpp +++ b/source/gameengine/Ketsji/KX_CDActuator.cpp @@ -293,7 +293,7 @@ PyObject* KX_CDActuator::PySetGain(PyObject* self, PyObject* args, PyObject* kwd { float gain = 1.0; ShowDeprecationWarning("setGain()", "the volume property"); - if (!PyArg_ParseTuple(args, "f", &gain)) + if (!PyArg_ParseTuple(args, "f:setGain", &gain)) return NULL; SND_CDObject::Instance()->SetGain(gain); diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index 339abb73531..8032e939a50 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -562,7 +562,7 @@ KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, sphereInsideFrustum, { PyObject *pycenter; float radius; - if (PyArg_ParseTuple(args, "Of", &pycenter, &radius)) + if (PyArg_ParseTuple(args, "Of:sphereInsideFrustum", &pycenter, &radius)) { MT_Point3 center; if (PyVecTo(pycenter, center)) diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 4db24a6e365..0118e490773 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -440,7 +440,7 @@ PyObject* KX_CameraActuator::PyGetObject(PyObject* self, PyObject* args) ShowDeprecationWarning("getObject()", "the object property"); - if (!PyArg_ParseTuple(args, "|i", &ret_name_only)) + if (!PyArg_ParseTuple(args, "|i:getObject", &ret_name_only)) return NULL; if (!m_ob) @@ -496,7 +496,7 @@ PyObject* KX_CameraActuator::PySetMin(PyObject* self, { ShowDeprecationWarning("setMin()", "the min property"); float min; - if(PyArg_ParseTuple(args,"f", &min)) + if(PyArg_ParseTuple(args,"f:setMin", &min)) { m_minHeight = min; Py_RETURN_NONE; @@ -524,7 +524,7 @@ PyObject* KX_CameraActuator::PySetMax(PyObject* self, { ShowDeprecationWarning("getMax()", "the max property"); float max; - if(PyArg_ParseTuple(args,"f", &max)) + if(PyArg_ParseTuple(args,"f:setMax", &max)) { m_maxHeight = max; Py_RETURN_NONE; @@ -552,7 +552,7 @@ PyObject* KX_CameraActuator::PySetHeight(PyObject* self, { ShowDeprecationWarning("getHeight()", "the height property"); float height; - if(PyArg_ParseTuple(args,"f", &height)) + if(PyArg_ParseTuple(args,"f:setHeight", &height)) { m_height = height; Py_RETURN_NONE; @@ -570,7 +570,7 @@ PyObject* KX_CameraActuator::PySetXY(PyObject* self, { ShowDeprecationWarning("setXY()", "the xy property"); int value; - if(PyArg_ParseTuple(args,"i", &value)) + if(PyArg_ParseTuple(args,"i:setXY", &value)) { m_x = value != 0; Py_RETURN_NONE; diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index b41435e71a1..3b8b4a93fd6 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -670,7 +670,7 @@ PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self, PyObject* kwds) { ShowDeprecationWarning("setDamp()", "the damp property"); int dampArg; - if(!PyArg_ParseTuple(args, "i", &dampArg)) { + if(!PyArg_ParseTuple(args, "i:setDamp", &dampArg)) { return NULL; } @@ -699,7 +699,7 @@ PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* self, PyObject* kwds) { ShowDeprecationWarning("setRotDamp()", "the rotDamp property"); int dampArg; - if(!PyArg_ParseTuple(args, "i", &dampArg)) { + if(!PyArg_ParseTuple(args, "i:setRotDamp", &dampArg)) { return NULL; } @@ -730,7 +730,7 @@ PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, MT_Scalar len; MT_Vector3 dir; - if(!PyArg_ParseTuple(args, "(fff)", &x, &y, &z)) { + if(!PyArg_ParseTuple(args, "(fff):setDirection", &x, &y, &z)) { return NULL; } dir[0] = x; @@ -777,7 +777,7 @@ PyObject* KX_ConstraintActuator::PySetOption(PyObject* self, PyObject* kwds) { ShowDeprecationWarning("setOption()", "the option property"); int option; - if(!PyArg_ParseTuple(args, "i", &option)) { + if(!PyArg_ParseTuple(args, "i:setOption", &option)) { return NULL; } @@ -806,7 +806,7 @@ PyObject* KX_ConstraintActuator::PySetTime(PyObject* self, PyObject* kwds) { ShowDeprecationWarning("setTime()", "the time property"); int t; - if(!PyArg_ParseTuple(args, "i", &t)) { + if(!PyArg_ParseTuple(args, "i:setTime", &t)) { return NULL; } @@ -836,7 +836,7 @@ PyObject* KX_ConstraintActuator::PySetProperty(PyObject* self, PyObject* kwds) { ShowDeprecationWarning("setProperty()", "the 'property' property"); char *property; - if (!PyArg_ParseTuple(args, "s", &property)) { + if (!PyArg_ParseTuple(args, "s:setProperty", &property)) { return NULL; } if (property == NULL) { @@ -872,7 +872,7 @@ PyObject* KX_ConstraintActuator::PySetMin(PyObject* self, PyObject* kwds) { ShowDeprecationWarning("setMin() or setDistance()", "the min or distance property"); float minArg; - if(!PyArg_ParseTuple(args, "f", &minArg)) { + if(!PyArg_ParseTuple(args, "f:setMin", &minArg)) { return NULL; } @@ -919,7 +919,7 @@ PyObject* KX_ConstraintActuator::PySetMax(PyObject* self, PyObject* kwds){ ShowDeprecationWarning("setMax() or setRayLength()", "the max or rayLength property"); float maxArg; - if(!PyArg_ParseTuple(args, "f", &maxArg)) { + if(!PyArg_ParseTuple(args, "f:setMax", &maxArg)) { return NULL; } @@ -974,7 +974,7 @@ PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self, PyObject* kwds) { ShowDeprecationWarning("setLimit()", "the limit property"); int locrotArg; - if(!PyArg_ParseTuple(args, "i", &locrotArg)) { + if(!PyArg_ParseTuple(args, "i:setLimit", &locrotArg)) { return NULL; } diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp index c9060486d44..cef874900a6 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.cpp +++ b/source/gameengine/Ketsji/KX_GameActuator.cpp @@ -286,7 +286,7 @@ PyObject* KX_GameActuator::PySetFile(PyObject* self, PyObject* args, PyObject* k ShowDeprecationWarning("setFile()", "the file property"); - if (!PyArg_ParseTuple(args, "s", &new_file)) + if (!PyArg_ParseTuple(args, "s:setFile", &new_file)) { return NULL; } diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index 1dc5471e77a..644f8ac8113 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, int forceToggle; int modenum; int startFrame, stopFrame; - if(!PyArg_ParseTuple(args, "siii", &mode, &startFrame, + if(!PyArg_ParseTuple(args, "siii:set", &mode, &startFrame, &stopFrame, &forceToggle)) { return NULL; } @@ -542,7 +542,7 @@ PyObject* KX_IpoActuator::PySetProperty(PyObject* self, /* mode is implicit here, but not supported yet... */ /* args: property */ char *propertyName; - if(!PyArg_ParseTuple(args, "s", &propertyName)) { + if(!PyArg_ParseTuple(args, "s:setProperty", &propertyName)) { return NULL; } @@ -563,7 +563,7 @@ PyObject* KX_IpoActuator::PySetStart(PyObject* self, ShowDeprecationWarning("setStart()", "the startFrame property"); float startArg; - if(!PyArg_ParseTuple(args, "f", &startArg)) { + if(!PyArg_ParseTuple(args, "f:setStart", &startArg)) { return NULL; } @@ -590,7 +590,7 @@ PyObject* KX_IpoActuator::PySetEnd(PyObject* self, PyObject* kwds) { ShowDeprecationWarning("setEnd()", "the endFrame property"); float endArg; - if(!PyArg_ParseTuple(args, "f", &endArg)) { + if(!PyArg_ParseTuple(args, "f:setEnd", &endArg)) { return NULL; } @@ -618,7 +618,7 @@ PyObject* KX_IpoActuator::PySetIpoAsForce(PyObject* self, ShowDeprecationWarning("setIpoAsForce()", "the useIpoAsForce property"); int boolArg; - if (!PyArg_ParseTuple(args, "i", &boolArg)) { + if (!PyArg_ParseTuple(args, "i:setIpoAsForce", &boolArg)) { return NULL; } @@ -648,7 +648,7 @@ PyObject* KX_IpoActuator::PySetIpoAdd(PyObject* self, ShowDeprecationWarning("setIpoAdd()", "the useIpoAdd property"); int boolArg; - if (!PyArg_ParseTuple(args, "i", &boolArg)) { + if (!PyArg_ParseTuple(args, "i:setIpoAdd", &boolArg)) { return NULL; } @@ -678,7 +678,7 @@ PyObject* KX_IpoActuator::PySetType(PyObject* self, ShowDeprecationWarning("setType()", "the type property"); int typeArg; - if (!PyArg_ParseTuple(args, "i", &typeArg)) { + if (!PyArg_ParseTuple(args, "i:setType", &typeArg)) { return NULL; } @@ -711,7 +711,7 @@ PyObject* KX_IpoActuator::PySetForceIpoActsLocal(PyObject* self, ShowDeprecationWarning("setForceIpoActsLocal()", "the useIpoLocal property"); int boolArg; - if (!PyArg_ParseTuple(args, "i", &boolArg)) { + if (!PyArg_ParseTuple(args, "i:setForceIpoActsLocal", &boolArg)) { return NULL; } diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index 7b58c8b288a..bcda4a8e3c4 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -150,7 +150,7 @@ PyObject* KX_MeshProxy::PyGetMaterialName(PyObject* self, int matid= 1; STR_String matname; - if (PyArg_ParseTuple(args,"i",&matid)) + if (PyArg_ParseTuple(args,"i:getMaterialName",&matid)) { matname = m_meshobj->GetMaterialName(matid); } @@ -170,7 +170,7 @@ PyObject* KX_MeshProxy::PyGetTextureName(PyObject* self, int matid= 1; STR_String matname; - if (PyArg_ParseTuple(args,"i",&matid)) + if (PyArg_ParseTuple(args,"i:getTextureName",&matid)) { matname = m_meshobj->GetTextureName(matid); } @@ -190,7 +190,7 @@ PyObject* KX_MeshProxy::PyGetVertexArrayLength(PyObject* self, int length = 0; - if (!PyArg_ParseTuple(args,"i",&matid)) + if (!PyArg_ParseTuple(args,"i:getVertexArrayLength",&matid)) return NULL; @@ -215,7 +215,7 @@ PyObject* KX_MeshProxy::PyGetVertex(PyObject* self, int matindex= 1; PyObject* vertexob = NULL; - if (PyArg_ParseTuple(args,"ii",&matindex,&vertexindex)) + if (PyArg_ParseTuple(args,"ii:getVertex",&matindex,&vertexindex)) { RAS_TexVert* vertex = m_meshobj->GetVertex(matindex,vertexindex); if (vertex) @@ -238,7 +238,7 @@ PyObject* KX_MeshProxy::PyGetPolygon(PyObject* self, int polyindex= 1; PyObject* polyob = NULL; - if (!PyArg_ParseTuple(args,"i",&polyindex)) + if (!PyArg_ParseTuple(args,"i:getPolygon",&polyindex)) return NULL; if (polyindex<0 || polyindex >= m_meshobj->NumPolygons()) diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index a343eeb71cc..0ea051723dc 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -362,7 +362,7 @@ PyObject* KX_ObjectActuator::PySetForce(PyObject* self, { float vecArg[3]; int bToggle = 0; - if (!PyArg_ParseTuple(args, "fffi", &vecArg[0], &vecArg[1], + if (!PyArg_ParseTuple(args, "fffi:setForce", &vecArg[0], &vecArg[1], &vecArg[2], &bToggle)) { return NULL; } @@ -391,7 +391,7 @@ PyObject* KX_ObjectActuator::PySetTorque(PyObject* self, { float vecArg[3]; int bToggle = 0; - if (!PyArg_ParseTuple(args, "fffi", &vecArg[0], &vecArg[1], + if (!PyArg_ParseTuple(args, "fffi:setTorque", &vecArg[0], &vecArg[1], &vecArg[2], &bToggle)) { return NULL; } @@ -420,7 +420,7 @@ PyObject* KX_ObjectActuator::PySetDLoc(PyObject* self, { float vecArg[3]; int bToggle = 0; - if(!PyArg_ParseTuple(args, "fffi", &vecArg[0], &vecArg[1], + if(!PyArg_ParseTuple(args, "fffi:setDLoc", &vecArg[0], &vecArg[1], &vecArg[2], &bToggle)) { return NULL; } @@ -449,7 +449,7 @@ PyObject* KX_ObjectActuator::PySetDRot(PyObject* self, { float vecArg[3]; int bToggle = 0; - if (!PyArg_ParseTuple(args, "fffi", &vecArg[0], &vecArg[1], + if (!PyArg_ParseTuple(args, "fffi:setDRot", &vecArg[0], &vecArg[1], &vecArg[2], &bToggle)) { return NULL; } @@ -477,7 +477,7 @@ PyObject* KX_ObjectActuator::PySetLinearVelocity(PyObject* self, PyObject* kwds) { float vecArg[3]; int bToggle = 0; - if (!PyArg_ParseTuple(args, "fffi", &vecArg[0], &vecArg[1], + if (!PyArg_ParseTuple(args, "fffi:setLinearVelocity", &vecArg[0], &vecArg[1], &vecArg[2], &bToggle)) { return NULL; } @@ -505,7 +505,7 @@ PyObject* KX_ObjectActuator::PySetAngularVelocity(PyObject* self, PyObject* kwds) { float vecArg[3]; int bToggle = 0; - if (!PyArg_ParseTuple(args, "fffi", &vecArg[0], &vecArg[1], + if (!PyArg_ParseTuple(args, "fffi:setAngularVelocity", &vecArg[0], &vecArg[1], &vecArg[2], &bToggle)) { return NULL; } @@ -520,7 +520,7 @@ PyObject* KX_ObjectActuator::PySetDamping(PyObject* self, PyObject* args, PyObject* kwds) { int damping = 0; - if (!PyArg_ParseTuple(args, "i", &damping) || damping < 0 || damping > 1000) { + if (!PyArg_ParseTuple(args, "i:setDamping", &damping) || damping < 0 || damping > 1000) { return NULL; } m_damping = damping; @@ -549,7 +549,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitX(PyObject* self, { float vecArg[2]; int bToggle = 0; - if(!PyArg_ParseTuple(args, "ffi", &vecArg[0], &vecArg[1], &bToggle)) { + if(!PyArg_ParseTuple(args, "ffi:setForceLimitX", &vecArg[0], &vecArg[1], &bToggle)) { return NULL; } m_drot[0] = vecArg[0]; @@ -576,7 +576,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitY(PyObject* self, { float vecArg[2]; int bToggle = 0; - if(!PyArg_ParseTuple(args, "ffi", &vecArg[0], &vecArg[1], &bToggle)) { + if(!PyArg_ParseTuple(args, "ffi:setForceLimitY", &vecArg[0], &vecArg[1], &bToggle)) { return NULL; } m_drot[1] = vecArg[0]; @@ -603,7 +603,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitZ(PyObject* self, { float vecArg[2]; int bToggle = 0; - if(!PyArg_ParseTuple(args, "ffi", &vecArg[0], &vecArg[1], &bToggle)) { + if(!PyArg_ParseTuple(args, "ffi:setForceLimitZ", &vecArg[0], &vecArg[1], &bToggle)) { return NULL; } m_drot[2] = vecArg[0]; @@ -629,7 +629,7 @@ PyObject* KX_ObjectActuator::PySetPID(PyObject* self, PyObject* kwds) { float vecArg[3]; - if (!PyArg_ParseTuple(args, "fff", &vecArg[0], &vecArg[1], &vecArg[2])) { + if (!PyArg_ParseTuple(args, "fff:setPID", &vecArg[0], &vecArg[1], &vecArg[2])) { return NULL; } m_torque.setValue(vecArg); diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index 32c279b2be1..d0d441e2c1c 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -252,7 +252,7 @@ PyObject* KX_ParentActuator::PyGetObject(PyObject* self, PyObject* args) ShowDeprecationWarning("getObject()", "the object property"); - if (!PyArg_ParseTuple(args, "|i", &ret_name_only)) + if (!PyArg_ParseTuple(args, "|i:getObject", &ret_name_only)) return NULL; if (!m_ob) diff --git a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp index 3bef85e7f93..9da86193622 100644 --- a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp +++ b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp @@ -56,7 +56,7 @@ PyObject* KX_PhysicsObjectWrapper::PySetPosition(PyObject* self, PyObject* kwds) { float x,y,z; - if (PyArg_ParseTuple(args,"fff",&x,&y,&z)) + if (PyArg_ParseTuple(args,"fff:setPosition",&x,&y,&z)) { m_ctrl->setPosition(x,y,z); } @@ -73,7 +73,7 @@ PyObject* KX_PhysicsObjectWrapper::PySetLinearVelocity(PyObject* self, { float x,y,z; int local; - if (PyArg_ParseTuple(args,"fffi",&x,&y,&z,&local)) + if (PyArg_ParseTuple(args,"fffi:setLinearVelocity",&x,&y,&z,&local)) { m_ctrl->SetLinearVelocity(x,y,z,local != 0); } @@ -89,7 +89,7 @@ PyObject* KX_PhysicsObjectWrapper::PySetAngularVelocity(PyObject* self, { float x,y,z; int local; - if (PyArg_ParseTuple(args,"fffi",&x,&y,&z,&local)) + if (PyArg_ParseTuple(args,"fffi:setAngularVelocity",&x,&y,&z,&local)) { m_ctrl->SetAngularVelocity(x,y,z,local != 0); } @@ -104,7 +104,7 @@ PyObject* KX_PhysicsObjectWrapper::PySetActive(PyObject* self, PyObject* kwds) { int active; - if (PyArg_ParseTuple(args,"i",&active)) + if (PyArg_ParseTuple(args,"i:setActive",&active)) { m_ctrl->SetActive(active!=0); } diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp index 39eb6225864..1e6f49ead2e 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.cpp +++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp @@ -238,7 +238,7 @@ KX_PYMETHODDEF_DOC(KX_PolyProxy, getVertexIndex, "Note: getVertexIndex(3) on a triangle polygon returns 0\n") { int index; - if (!PyArg_ParseTuple(args,"i",&index)) + if (!PyArg_ParseTuple(args,"i:getVertexIndex",&index)) { return NULL; } diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index e66d9d60db8..56a1daa7544 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -244,7 +244,7 @@ int KX_PolygonMaterial::py_setattro(PyObject *attr, PyObject *value) KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setCustomMaterial, "setCustomMaterial(material)") { PyObject *material; - if (PyArg_ParseTuple(args, "O", &material)) + if (PyArg_ParseTuple(args, "O:setCustomMaterial", &material)) { if (m_pymaterial) { Py_DECREF(m_pymaterial); @@ -260,7 +260,7 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setCustomMaterial, "setCustomMaterial(mat KX_PYMETHODDEF_DOC(KX_PolygonMaterial, updateTexture, "updateTexture(tface, rasty)") { PyObject *pyrasty, *pytface; - if (PyArg_ParseTuple(args, "O!O!", &PyCObject_Type, &pytface, &PyCObject_Type, &pyrasty)) + if (PyArg_ParseTuple(args, "O!O!:updateTexture", &PyCObject_Type, &pytface, &PyCObject_Type, &pyrasty)) { MTFace *tface = (MTFace*) PyCObject_AsVoidPtr(pytface); RAS_IRasterizer *rasty = (RAS_IRasterizer*) PyCObject_AsVoidPtr(pyrasty); @@ -276,7 +276,7 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, updateTexture, "updateTexture(tface, rast KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setTexture, "setTexture(tface)") { PyObject *pytface; - if (PyArg_ParseTuple(args, "O!", &PyCObject_Type, &pytface)) + if (PyArg_ParseTuple(args, "O!:setTexture", &PyCObject_Type, &pytface)) { MTFace *tface = (MTFace*) PyCObject_AsVoidPtr(pytface); GPU_set_tpage(tface); @@ -289,7 +289,7 @@ KX_PYMETHODDEF_DOC(KX_PolygonMaterial, setTexture, "setTexture(tface)") KX_PYMETHODDEF_DOC(KX_PolygonMaterial, activate, "activate(rasty, cachingInfo)") { PyObject *pyrasty, *pyCachingInfo; - if (PyArg_ParseTuple(args, "O!O!", &PyCObject_Type, &pyrasty, &PyCObject_Type, &pyCachingInfo)) + if (PyArg_ParseTuple(args, "O!O!:activate", &PyCObject_Type, &pyrasty, &PyCObject_Type, &pyCachingInfo)) { RAS_IRasterizer *rasty = static_cast(PyCObject_AsVoidPtr(pyrasty)); TCachingInfo *cachingInfo = static_cast(PyCObject_AsVoidPtr(pyCachingInfo)); diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index a59d8417f26..65b654ccba4 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -341,7 +341,7 @@ PyObject* KX_SCA_AddObjectActuator::PyGetObject(PyObject* self, PyObject* args) ShowDeprecationWarning("getObject()", "the object property"); - if (!PyArg_ParseTuple(args, "|i", &ret_name_only)) + if (!PyArg_ParseTuple(args, "|i:getObject", &ret_name_only)) return NULL; if (!m_OriginalObject) @@ -389,7 +389,7 @@ PyObject* KX_SCA_AddObjectActuator::PySetLinearVelocity(PyObject* self, PyObject ShowDeprecationWarning("setLinearVelocity()", "the linearVelocity property"); float vecArg[3]; - if (!PyArg_ParseTuple(args, "fff", &vecArg[0], &vecArg[1], &vecArg[2])) + if (!PyArg_ParseTuple(args, "fff:setLinearVelocity", &vecArg[0], &vecArg[1], &vecArg[2])) return NULL; m_linear_velocity[0] = vecArg[0]; @@ -432,7 +432,7 @@ PyObject* KX_SCA_AddObjectActuator::PySetAngularVelocity(PyObject* self, PyObjec ShowDeprecationWarning("setAngularVelocity()", "the angularVelocity property"); float vecArg[3]; - if (!PyArg_ParseTuple(args, "fff", &vecArg[0], &vecArg[1], &vecArg[2])) + if (!PyArg_ParseTuple(args, "fff:setAngularVelocity", &vecArg[0], &vecArg[1], &vecArg[2])) return NULL; m_angular_velocity[0] = vecArg[0]; diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp index aaa87e407ba..e03b153d813 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp @@ -116,7 +116,7 @@ KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, setOperation, ShowDeprecationWarning("setOperation()", "the operation property"); int dyn_operation; - if (!PyArg_ParseTuple(args, "i", &dyn_operation)) + if (!PyArg_ParseTuple(args, "i:setOperation", &dyn_operation)) { return NULL; } diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 0bd7d7270e1..30fed561519 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1697,7 +1697,7 @@ KX_PYMETHODDEF_DOC(KX_Scene, addObject, int time = 0; - if (!PyArg_ParseTuple(args, "OO|i", &pyob, &pyother, &time)) + if (!PyArg_ParseTuple(args, "OO|i:addObject", &pyob, &pyother, &time)) return NULL; if (!ConvertPythonToGameObject(pyob, &ob, false) diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index 1753c6570e9..2d3022a68f7 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -344,7 +344,7 @@ PyObject* KX_SceneActuator::PySetUseRestart(PyObject* self, ShowDeprecationWarning("setUseRestart()", "(no replacement)"); int boolArg; - if (!PyArg_ParseTuple(args, "i", &boolArg)) + if (!PyArg_ParseTuple(args, "i:setUseRestart", &boolArg)) { return NULL; } @@ -383,7 +383,7 @@ PyObject* KX_SceneActuator::PySetScene(PyObject* self, /* one argument: a scene, ignore the rest */ char *scene_name; - if(!PyArg_ParseTuple(args, "s", &scene_name)) + if(!PyArg_ParseTuple(args, "s:setScene", &scene_name)) { return NULL; } @@ -421,7 +421,7 @@ PyObject* KX_SceneActuator::PySetCamera(PyObject* self, { ShowDeprecationWarning("setCamera()", "the camera property"); PyObject *cam; - if (PyArg_ParseTuple(args, "O!", &KX_Camera::Type, &cam)) + if (PyArg_ParseTuple(args, "O!:setCamera", &KX_Camera::Type, &cam)) { if (m_camera) m_camera->UnregisterActuator(this); @@ -434,7 +434,7 @@ PyObject* KX_SceneActuator::PySetCamera(PyObject* self, /* one argument: a scene, ignore the rest */ char *camName; - if(!PyArg_ParseTuple(args, "s", &camName)) + if(!PyArg_ParseTuple(args, "s:setCamera", &camName)) { return NULL; } diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index ecc3b574079..6381c43e1c6 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -620,7 +620,7 @@ PyObject* KX_SoundActuator::PySetGain(PyObject* self, PyObject* args, PyObject* { ShowDeprecationWarning("setGain()", "the volume property"); float gain = 1.0; - if (!PyArg_ParseTuple(args, "f", &gain)) + if (!PyArg_ParseTuple(args, "f:setGain", &gain)) return NULL; if (m_soundObject) @@ -646,7 +646,7 @@ PyObject* KX_SoundActuator::PySetPitch(PyObject* self, PyObject* args, PyObject* { ShowDeprecationWarning("setPitch()", "the pitch property"); float pitch = 1.0; - if (!PyArg_ParseTuple(args, "f", &pitch)) + if (!PyArg_ParseTuple(args, "f:setPitch", &pitch)) return NULL; if (m_soundObject) @@ -672,7 +672,7 @@ PyObject* KX_SoundActuator::PySetRollOffFactor(PyObject* self, PyObject* args, P { ShowDeprecationWarning("setRollOffFactor()", "the rollOffFactor property"); float rollofffactor = 1.0; - if (!PyArg_ParseTuple(args, "f", &rollofffactor)) + if (!PyArg_ParseTuple(args, "f:setRollOffFactor", &rollofffactor)) return NULL; if (m_soundObject) @@ -698,7 +698,7 @@ PyObject* KX_SoundActuator::PySetLooping(PyObject* self, PyObject* args, PyObjec { ShowDeprecationWarning("setLooping()", "the looping property"); bool looping = 1; - if (!PyArg_ParseTuple(args, "i", &looping)) + if (!PyArg_ParseTuple(args, "i:setLooping", &looping)) return NULL; if (m_soundObject) @@ -728,7 +728,7 @@ PyObject* KX_SoundActuator::PySetPosition(PyObject* self, PyObject* args, PyObje pos[1] = 0.0; pos[2] = 0.0; - if (!PyArg_ParseTuple(args, "fff", &pos[0], &pos[1], &pos[2])) + if (!PyArg_ParseTuple(args, "fff:setPosition", &pos[0], &pos[1], &pos[2])) return NULL; if (m_soundObject) @@ -747,7 +747,7 @@ PyObject* KX_SoundActuator::PySetVelocity(PyObject* self, PyObject* args, PyObje vel[1] = 0.0; vel[2] = 0.0; - if (!PyArg_ParseTuple(args, "fff", &vel[0], &vel[1], &vel[2])) + if (!PyArg_ParseTuple(args, "fff:setVelocity", &vel[0], &vel[1], &vel[2])) return NULL; if (m_soundObject) @@ -772,7 +772,7 @@ PyObject* KX_SoundActuator::PySetOrientation(PyObject* self, PyObject* args, PyO ori[2][1] = 0.0; ori[2][2] = 1.0; - if (!PyArg_ParseTuple(args, "fffffffff", &ori[0][0], &ori[0][1], &ori[0][2], &ori[1][0], &ori[1][1], &ori[1][2], &ori[2][0], &ori[2][1], &ori[2][2])) + if (!PyArg_ParseTuple(args, "fffffffff:setOrientation", &ori[0][0], &ori[0][1], &ori[0][2], &ori[1][0], &ori[1][1], &ori[1][2], &ori[2][0], &ori[2][1], &ori[2][2])) return NULL; if (m_soundObject) @@ -786,7 +786,7 @@ PyObject* KX_SoundActuator::PySetType(PyObject* self, PyObject* args, PyObject* int typeArg; ShowDeprecationWarning("setType()", "the type property"); - if (!PyArg_ParseTuple(args, "i", &typeArg)) { + if (!PyArg_ParseTuple(args, "i:setType", &typeArg)) { return NULL; } diff --git a/source/gameengine/Ketsji/KX_StateActuator.cpp b/source/gameengine/Ketsji/KX_StateActuator.cpp index e9e3c091ef3..a251a987935 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.cpp +++ b/source/gameengine/Ketsji/KX_StateActuator.cpp @@ -179,7 +179,7 @@ KX_StateActuator::PySetOperation(PyObject* self, ShowDeprecationWarning("setOperation()", "the operation property"); int oper; - if(!PyArg_ParseTuple(args, "i", &oper)) { + if(!PyArg_ParseTuple(args, "i:setOperation", &oper)) { return NULL; } @@ -205,7 +205,7 @@ KX_StateActuator::PySetMask(PyObject* self, ShowDeprecationWarning("setMask()", "the mask property"); int mask; - if(!PyArg_ParseTuple(args, "i", &mask)) { + if(!PyArg_ParseTuple(args, "i:setMask", &mask)) { return NULL; } diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index c90ce06b916..29c6a21b0b3 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -551,7 +551,7 @@ PyObject* KX_TrackToActuator::PyGetObject(PyObject* self, PyObject* args) ShowDeprecationWarning("getObject()", "the object property"); - if (!PyArg_ParseTuple(args, "|i", &ret_name_only)) + if (!PyArg_ParseTuple(args, "|i:getObject", &ret_name_only)) return NULL; if (!m_object) @@ -575,7 +575,7 @@ PyObject* KX_TrackToActuator::PySetTime(PyObject* self, PyObject* args, PyObject ShowDeprecationWarning("setTime()", "the timer property"); int timeArg; - if (!PyArg_ParseTuple(args, "i", &timeArg)) + if (!PyArg_ParseTuple(args, "i:setTime", &timeArg)) { return NULL; } @@ -623,7 +623,7 @@ PyObject* KX_TrackToActuator::PySetUse3D(PyObject* self, PyObject* args, PyObjec ShowDeprecationWarning("setTime()", "the use3D property"); int boolArg; - if (!PyArg_ParseTuple(args, "i", &boolArg)) { + if (!PyArg_ParseTuple(args, "i:setUse3D", &boolArg)) { return NULL; } diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp index 6afea4d3227..315b60922b7 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp @@ -46,7 +46,7 @@ PyObject* KX_VehicleWrapper::PyAddWheel(PyObject* self, int hasSteering; - if (PyArg_ParseTuple(args,"OOOOffi",&wheelGameObject,&pylistPos,&pylistDir,&pylistAxleDir,&suspensionRestLength,&wheelRadius,&hasSteering)) + if (PyArg_ParseTuple(args,"OOOOffi:addWheel",&wheelGameObject,&pylistPos,&pylistDir,&pylistAxleDir,&suspensionRestLength,&wheelRadius,&hasSteering)) { KX_GameObject* gameOb = (KX_GameObject*) wheelGameObject; @@ -89,7 +89,7 @@ PyObject* KX_VehicleWrapper::PyGetWheelPosition(PyObject* self, int wheelIndex; - if (PyArg_ParseTuple(args,"i",&wheelIndex)) + if (PyArg_ParseTuple(args,"i:getWheelPosition",&wheelIndex)) { float position[3]; m_vehicle->GetWheelPosition(wheelIndex,position[0],position[1],position[2]); @@ -104,7 +104,7 @@ PyObject* KX_VehicleWrapper::PyGetWheelRotation(PyObject* self, PyObject* kwds) { int wheelIndex; - if (PyArg_ParseTuple(args,"i",&wheelIndex)) + if (PyArg_ParseTuple(args,"i:getWheelRotation",&wheelIndex)) { return PyFloat_FromDouble(m_vehicle->GetWheelRotation(wheelIndex)); } @@ -116,7 +116,7 @@ PyObject* KX_VehicleWrapper::PyGetWheelOrientationQuaternion(PyObject* self, PyObject* kwds) { int wheelIndex; - if (PyArg_ParseTuple(args,"i",&wheelIndex)) + if (PyArg_ParseTuple(args,"i:getWheelOrientationQuaternion",&wheelIndex)) { float orn[4]; m_vehicle->GetWheelOrientationQuaternion(wheelIndex,orn[0],orn[1],orn[2],orn[3]); @@ -153,7 +153,7 @@ PyObject* KX_VehicleWrapper::PyApplyEngineForce(PyObject* self, float force; int wheelIndex; - if (PyArg_ParseTuple(args,"fi",&force,&wheelIndex)) + if (PyArg_ParseTuple(args,"fi:applyEngineForce",&force,&wheelIndex)) { force *= -1.f;//someone reverse some conventions inside Bullet (axle winding) m_vehicle->ApplyEngineForce(force,wheelIndex); @@ -171,7 +171,7 @@ PyObject* KX_VehicleWrapper::PySetTyreFriction(PyObject* self, float wheelFriction; int wheelIndex; - if (PyArg_ParseTuple(args,"fi",&wheelFriction,&wheelIndex)) + if (PyArg_ParseTuple(args,"fi:setTyreFriction",&wheelFriction,&wheelIndex)) { m_vehicle->SetWheelFriction(wheelFriction,wheelIndex); } @@ -188,7 +188,7 @@ PyObject* KX_VehicleWrapper::PySetSuspensionStiffness(PyObject* self, float suspensionStiffness; int wheelIndex; - if (PyArg_ParseTuple(args,"fi",&suspensionStiffness,&wheelIndex)) + if (PyArg_ParseTuple(args,"fi:setSuspensionStiffness",&suspensionStiffness,&wheelIndex)) { m_vehicle->SetSuspensionStiffness(suspensionStiffness,wheelIndex); } @@ -205,7 +205,7 @@ PyObject* KX_VehicleWrapper::PySetSuspensionDamping(PyObject* self, float suspensionDamping; int wheelIndex; - if (PyArg_ParseTuple(args,"fi",&suspensionDamping,&wheelIndex)) + if (PyArg_ParseTuple(args,"fi:setSuspensionDamping",&suspensionDamping,&wheelIndex)) { m_vehicle->SetSuspensionDamping(suspensionDamping,wheelIndex); } else { @@ -221,7 +221,7 @@ PyObject* KX_VehicleWrapper::PySetSuspensionCompression(PyObject* self, float suspensionCompression; int wheelIndex; - if (PyArg_ParseTuple(args,"fi",&suspensionCompression,&wheelIndex)) + if (PyArg_ParseTuple(args,"fi:setSuspensionCompression",&suspensionCompression,&wheelIndex)) { m_vehicle->SetSuspensionCompression(suspensionCompression,wheelIndex); } else { @@ -237,7 +237,7 @@ PyObject* KX_VehicleWrapper::PySetRollInfluence(PyObject* self, float rollInfluence; int wheelIndex; - if (PyArg_ParseTuple(args,"fi",&rollInfluence,&wheelIndex)) + if (PyArg_ParseTuple(args,"fi:setRollInfluence",&rollInfluence,&wheelIndex)) { m_vehicle->SetRollInfluence(rollInfluence,wheelIndex); } @@ -255,7 +255,7 @@ PyObject* KX_VehicleWrapper::PyApplyBraking(PyObject* self, float braking; int wheelIndex; - if (PyArg_ParseTuple(args,"fi",&braking,&wheelIndex)) + if (PyArg_ParseTuple(args,"fi:applyBraking",&braking,&wheelIndex)) { m_vehicle->ApplyBraking(braking,wheelIndex); } @@ -275,7 +275,7 @@ PyObject* KX_VehicleWrapper::PySetSteeringValue(PyObject* self, float steeringValue; int wheelIndex; - if (PyArg_ParseTuple(args,"fi",&steeringValue,&wheelIndex)) + if (PyArg_ParseTuple(args,"fi:setSteeringValue",&steeringValue,&wheelIndex)) { m_vehicle->SetSteeringValue(steeringValue,wheelIndex); } diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp index 18277245d17..1ee2169adc4 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp @@ -159,7 +159,7 @@ KX_VisibilityActuator::PySetVisible(PyObject* self, int vis; ShowDeprecationWarning("SetVisible()", "the visible property"); - if(!PyArg_ParseTuple(args, "i", &vis)) { + if(!PyArg_ParseTuple(args, "i:setVisible", &vis)) { return NULL; } -- cgit v1.2.3 From 37e53b2e1f8107cb8ddbee2d67bf984a70a71276 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 11 Apr 2009 15:59:11 +0000 Subject: bugfix from Moguri, AddReplica wasnt setting the light layer from the parent --- source/gameengine/Ketsji/KX_Scene.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 30fed561519..7842076de66 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -91,6 +91,8 @@ #include "CcdPhysicsController.h" #endif +#include "KX_Light.h" + void* KX_SceneReplicationFunc(SG_IObject* node,void* gameobj,void* scene) { KX_GameObject* replica = ((KX_Scene*)scene)->AddNodeReplicaObject(node,(KX_GameObject*)gameobj); @@ -741,6 +743,12 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level) (*git)->Relink(&m_map_gameobject_to_replica); // add the object in the layer of the parent (*git)->SetLayer(groupobj->GetLayer()); + // If the object was a light, we need to update it's RAS_LightObject as well + if ((*git)->IsLight()) + { + KX_LightObject* lightobj = static_cast(*git); + lightobj->GetLightData()->m_layer = groupobj->GetLayer(); + } } // replicate crosslinks etc. between logic bricks @@ -841,6 +849,12 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject, (*git)->Relink(&m_map_gameobject_to_replica); // add the object in the layer of the parent (*git)->SetLayer(parentobj->GetLayer()); + // If the object was a light, we need to update it's RAS_LightObject as well + if ((*git)->IsLight()) + { + KX_LightObject* lightobj = static_cast(*git); + lightobj->GetLightData()->m_layer = parentobj->GetLayer(); + } } // replicate crosslinks etc. between logic bricks -- cgit v1.2.3 From 4cd088b1059afa2e7b998c184b2c9deecd4be4a9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 11 Apr 2009 20:58:09 +0000 Subject: BGE Py API - setting the scene attributes would always add to the scenes custom dictionary. - new CListValue method from_id(id) so you can store a Game Objects id and use it to get the game object back. ob_id = id(gameOb) ... gameOb = scene.objects.from_id(ob_id) This is useful because names are not always unique. --- source/gameengine/Expressions/ListValue.cpp | 29 ++++++++++++++++++++++++++++ source/gameengine/Expressions/ListValue.h | 1 + source/gameengine/Expressions/PyObjectPlus.h | 15 +++++++------- source/gameengine/Ketsji/KX_Scene.cpp | 6 ++---- source/gameengine/Ketsji/KX_Scene.h | 21 ++++++++++++++++++++ source/gameengine/PyDoc/CListValue.py | 22 ++++++++++++++++++++- 6 files changed, 81 insertions(+), 13 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index d0aec645468..16b4fbef6b7 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -233,6 +233,7 @@ PyMethodDef CListValue::Methods[] = { {"reverse", (PyCFunction)CListValue::sPyreverse,METH_NOARGS}, {"index", (PyCFunction)CListValue::sPyindex,METH_O}, {"count", (PyCFunction)CListValue::sPycount,METH_O}, + {"from_id", (PyCFunction)CListValue::sPyfrom_id,METH_O}, {NULL,NULL} //Sentinel }; @@ -502,6 +503,34 @@ PyObject* CListValue::Pycount(PyObject* self, PyObject* value) +PyObject* CListValue::Pyfrom_id(PyObject* self, PyObject* value) +{ +#if SIZEOF_VOID_P <= SIZEOF_LONG +#define BGE_ID_TYPE unsigned long + BGE_ID_TYPE id= PyLong_AsUnsignedLong(value); +#else +#define BGE_ID_TYPE unsigned long long + BGE_ID_TYPE id= PyLong_FromUnsignedLongLong(value); +#endif + + if (id==-1 && PyErr_Occurred()) + return NULL; + + int numelem = GetCount(); + for (int i=0;i(static_cast(m_pValueArray[i])) == id) + return GetValue(i); + + } + PyErr_SetString(PyExc_IndexError, "from_id(#), id not found in CValueList"); + return NULL; + +} + +#undef BGE_ID_TYPE + + /* --------------------------------------------------------------------- * Some stuff taken from the header * --------------------------------------------------------------------- */ diff --git a/source/gameengine/Expressions/ListValue.h b/source/gameengine/Expressions/ListValue.h index 1c01c2d221d..6f70acb9367 100644 --- a/source/gameengine/Expressions/ListValue.h +++ b/source/gameengine/Expressions/ListValue.h @@ -71,6 +71,7 @@ public: KX_PYMETHOD_NOARGS(CListValue,reverse); KX_PYMETHOD_O(CListValue,index); KX_PYMETHOD_O(CListValue,count); + KX_PYMETHOD_O(CListValue,from_id); private: diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 786ca1fdc4f..42168461634 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -404,9 +404,9 @@ public: // }; // decref method virtual PyObject *py_getattro(PyObject *attr); // py_getattro method - static PyObject *py_base_getattro(PyObject * PyObj, PyObject *attr) // This should be the entry in Type. + static PyObject *py_base_getattro(PyObject * self, PyObject *attr) // This should be the entry in Type. { - return ((PyObjectPlus*) PyObj)->py_getattro(attr); + return ((PyObjectPlus*) self)->py_getattro(attr); } static PyObject* py_get_attrdef(void *self, const PyAttributeDef *attrdef); @@ -419,13 +419,12 @@ public: virtual int py_delattro(PyObject *attr); virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method - static int py_base_setattro(PyObject *PyObj, // This should be the entry in Type. - PyObject *attr, - PyObject *value) - { + static int py_base_setattro(PyObject *self, PyObject *attr, PyObject *value) // the PyType should reference this + { if (value==NULL) - return ((PyObjectPlus*) PyObj)->py_delattro(attr); - return ((PyObjectPlus*) PyObj)->py_setattro(attr, value); + return ((PyObjectPlus*) self)->py_delattro(attr); + + return ((PyObjectPlus*) self)->py_setattro(attr, value); } virtual PyObject *py_repr(void); // py_repr method diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 7842076de66..2f7c1b77794 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1588,7 +1588,7 @@ PyTypeObject KX_Scene::Type = { py_base_repr, 0,0,0,0,0,0, py_base_getattro, - py_base_setattro, + py_base_setattro_scene, /* unlike almost all other types we need out own because user attributes are supported */ 0,0,0,0,0,0,0,0,0, Methods }; @@ -1669,11 +1669,9 @@ int KX_Scene::py_delattro(PyObject *attr) return 0; } +/* py_base_setattro_scene deals with setting the dict, it will run if this returns an error */ int KX_Scene::py_setattro(PyObject *attr, PyObject *pyvalue) { - if (!PyDict_SetItem(m_attrlist, attr, pyvalue)) - return 0; - return PyObjectPlus::py_setattro(attr, pyvalue); } diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 9f05ddf70c2..1bdfbd45d20 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -590,6 +590,27 @@ public: /* for dir(), python3 uses __dir__() */ static PyObject* pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int py_base_setattro_scene(PyObject * self, PyObject *attr, PyObject *value) + { + if (value==NULL) + return ((PyObjectPlus*) self)->py_delattro(attr); + + int ret= ((PyObjectPlus*) self)->py_setattro(attr, value); + + if (ret) { + if (!PyDict_SetItem(((KX_Scene *) self)->m_attrlist, attr, value)) { + PyErr_Clear(); + ret= 0; + } + else { + ret= -1; + } + } + + return ret; + } + + virtual PyObject* py_getattro(PyObject *attr); /* name, active_camera, gravity, suspended, viewport, framing, activity_culling, activity_culling_radius */ virtual int py_setattro(PyObject *attr, PyObject *pyvalue); diff --git a/source/gameengine/PyDoc/CListValue.py b/source/gameengine/PyDoc/CListValue.py index 33e77395c86..e9fc4215bb6 100644 --- a/source/gameengine/PyDoc/CListValue.py +++ b/source/gameengine/PyDoc/CListValue.py @@ -33,7 +33,27 @@ class CListValue: # (PyObjectPlus) @rtype: integer @return: The index of the value in the list. """ - def reverse(val): + def reverse(): """ Reverse the order of the list. + """ + def from_id(id): + """ + This is a funtion especially for the game engine to return a value with a spesific id. + + Since object names are not always unique, the id of an object can be used to get an object from the CValueList. + + Example. + + C{myObID = id(gameObject)} + + C{...} + + C{ob= scene.objects.from_id(myObID)} + + Where myObID is an int or long from the id function. + + This has the advantage that you can store the id in places you could not store a gameObject. + + Warning: the id is derived from a memory location and will be different each time the game engine starts. """ \ No newline at end of file -- cgit v1.2.3 From 33170295c8a2f3eb815b6086f47147113fd3de13 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 12 Apr 2009 06:41:01 +0000 Subject: use long long rather then int for storing game logic properties. There were also some problems with int to python conversion - assigning a PyLong to a KX_GameObject from python would raise an error - PyLong were coerced into floats when used with internal CValue arithmetic Changes... - PyLong is converted into CIntValue for coercing and assigning from python - CValue's generic GetNumber() function returns a double rather then a float. - Print an error when a PyType cant be coerced into a CValue Tested with python, expressions and property sensor. --- source/gameengine/Expressions/BoolValue.cpp | 4 ++-- source/gameengine/Expressions/BoolValue.h | 2 +- source/gameengine/Expressions/ConstExpr.cpp | 2 +- source/gameengine/Expressions/ConstExpr.h | 2 +- source/gameengine/Expressions/EmptyValue.cpp | 2 +- source/gameengine/Expressions/EmptyValue.h | 2 +- source/gameengine/Expressions/ErrorValue.cpp | 2 +- source/gameengine/Expressions/ErrorValue.h | 2 +- source/gameengine/Expressions/FloatValue.cpp | 4 ++-- source/gameengine/Expressions/FloatValue.h | 2 +- source/gameengine/Expressions/InputParser.cpp | 8 +++++--- source/gameengine/Expressions/InputParser.h | 2 ++ source/gameengine/Expressions/IntValue.cpp | 21 ++++++++++++--------- source/gameengine/Expressions/IntValue.h | 12 +++++++----- source/gameengine/Expressions/ListValue.cpp | 2 +- source/gameengine/Expressions/ListValue.h | 2 +- source/gameengine/Expressions/StringValue.cpp | 2 +- source/gameengine/Expressions/StringValue.h | 2 +- source/gameengine/Expressions/Value.cpp | 19 +++++++++++-------- source/gameengine/Expressions/Value.h | 2 +- source/gameengine/Expressions/VectorValue.cpp | 2 +- source/gameengine/Expressions/VectorValue.h | 2 +- source/gameengine/Expressions/VoidValue.h | 2 +- .../GameLogic/SCA_ExpressionController.cpp | 2 +- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 2 +- source/gameengine/GameLogic/SCA_ILogicBrick.h | 2 +- source/gameengine/GameLogic/SCA_ISensor.cpp | 2 +- source/gameengine/GameLogic/SCA_ISensor.h | 2 +- source/gameengine/Ketsji/KX_GameObject.cpp | 2 +- source/gameengine/Ketsji/KX_GameObject.h | 2 +- source/gameengine/Ketsji/KX_MeshProxy.cpp | 2 +- source/gameengine/Ketsji/KX_MeshProxy.h | 2 +- source/gameengine/Ketsji/KX_PolyProxy.cpp | 2 +- source/gameengine/Ketsji/KX_PolyProxy.h | 2 +- source/gameengine/Ketsji/KX_VertexProxy.cpp | 2 +- source/gameengine/Ketsji/KX_VertexProxy.h | 2 +- 36 files changed, 70 insertions(+), 58 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/BoolValue.cpp b/source/gameengine/Expressions/BoolValue.cpp index cadb34d7e8f..13c870b68e5 100644 --- a/source/gameengine/Expressions/BoolValue.cpp +++ b/source/gameengine/Expressions/BoolValue.cpp @@ -181,9 +181,9 @@ ret: the bool stored in the object -float CBoolValue::GetNumber() +double CBoolValue::GetNumber() { - return (float)m_bool; + return (double)m_bool; } diff --git a/source/gameengine/Expressions/BoolValue.h b/source/gameengine/Expressions/BoolValue.h index 6c4d964249f..9352b9d4b92 100644 --- a/source/gameengine/Expressions/BoolValue.h +++ b/source/gameengine/Expressions/BoolValue.h @@ -33,7 +33,7 @@ public: CBoolValue(bool innie, STR_String name, AllocationTYPE alloctype = CValue::HEAPVALUE); virtual const STR_String& GetText(); - virtual float GetNumber(); + virtual double GetNumber(); bool GetBool(); virtual void SetValue(CValue* newval); diff --git a/source/gameengine/Expressions/ConstExpr.cpp b/source/gameengine/Expressions/ConstExpr.cpp index e33ba091ac4..6b64be9c9a9 100644 --- a/source/gameengine/Expressions/ConstExpr.cpp +++ b/source/gameengine/Expressions/ConstExpr.cpp @@ -84,7 +84,7 @@ void CConstExpr::ClearModified() -float CConstExpr::GetNumber() +double CConstExpr::GetNumber() { return -1; } diff --git a/source/gameengine/Expressions/ConstExpr.h b/source/gameengine/Expressions/ConstExpr.h index e27ece52a83..b117140fe70 100644 --- a/source/gameengine/Expressions/ConstExpr.h +++ b/source/gameengine/Expressions/ConstExpr.h @@ -32,7 +32,7 @@ public: //bool IsInside(float x,float y,float z,bool bBorderInclude=true); bool NeedsRecalculated(); void ClearModified(); - virtual float GetNumber(); + virtual double GetNumber(); virtual CValue* Calculate(); CConstExpr(CValue* constval); CConstExpr(); diff --git a/source/gameengine/Expressions/EmptyValue.cpp b/source/gameengine/Expressions/EmptyValue.cpp index c2b60e590a4..f72ddc47096 100644 --- a/source/gameengine/Expressions/EmptyValue.cpp +++ b/source/gameengine/Expressions/EmptyValue.cpp @@ -76,7 +76,7 @@ this object -float CEmptyValue::GetNumber() +double CEmptyValue::GetNumber() { return 0; } diff --git a/source/gameengine/Expressions/EmptyValue.h b/source/gameengine/Expressions/EmptyValue.h index b9cca0e57e5..fb6b4a477a6 100644 --- a/source/gameengine/Expressions/EmptyValue.h +++ b/source/gameengine/Expressions/EmptyValue.h @@ -27,7 +27,7 @@ public: virtual ~CEmptyValue(); virtual const STR_String & GetText(); - virtual float GetNumber(); + virtual double GetNumber(); CListValue* GetPolySoup(); virtual double* GetVector3(bool bGetTransformedVec=false); bool IsInside(CValue* testpoint,bool bBorderInclude=true); diff --git a/source/gameengine/Expressions/ErrorValue.cpp b/source/gameengine/Expressions/ErrorValue.cpp index e52be4c8021..651a772db19 100644 --- a/source/gameengine/Expressions/ErrorValue.cpp +++ b/source/gameengine/Expressions/ErrorValue.cpp @@ -99,7 +99,7 @@ ret: a new object containing the result of applying operator op to val and -float CErrorValue::GetNumber() +double CErrorValue::GetNumber() { return -1; } diff --git a/source/gameengine/Expressions/ErrorValue.h b/source/gameengine/Expressions/ErrorValue.h index 16e608ca01a..5b5795196ba 100644 --- a/source/gameengine/Expressions/ErrorValue.h +++ b/source/gameengine/Expressions/ErrorValue.h @@ -23,7 +23,7 @@ class CErrorValue : public CPropValue public: virtual const STR_String & GetText(); - virtual float GetNumber(); + virtual double GetNumber(); CErrorValue(); CErrorValue(STR_String errmsg); virtual ~CErrorValue(); diff --git a/source/gameengine/Expressions/FloatValue.cpp b/source/gameengine/Expressions/FloatValue.cpp index 460eaa73f35..212a55fe457 100644 --- a/source/gameengine/Expressions/FloatValue.cpp +++ b/source/gameengine/Expressions/FloatValue.cpp @@ -278,7 +278,7 @@ ret: the float stored in the object -float CFloatValue::GetNumber() +double CFloatValue::GetNumber() { return m_float; } @@ -287,7 +287,7 @@ float CFloatValue::GetNumber() void CFloatValue::SetValue(CValue* newval) { - m_float = newval->GetNumber(); + m_float = (float)newval->GetNumber(); SetModified(true); } diff --git a/source/gameengine/Expressions/FloatValue.h b/source/gameengine/Expressions/FloatValue.h index 33f05f1d7f2..41f70b5c54c 100644 --- a/source/gameengine/Expressions/FloatValue.h +++ b/source/gameengine/Expressions/FloatValue.h @@ -28,7 +28,7 @@ public: virtual const STR_String & GetText(); void Configure(CValue* menuvalue); - virtual float GetNumber(); + virtual double GetNumber(); virtual void SetValue(CValue* newval); float GetFloat(); void SetFloat(float fl); diff --git a/source/gameengine/Expressions/InputParser.cpp b/source/gameengine/Expressions/InputParser.cpp index 94663c4a365..677bbb36d70 100644 --- a/source/gameengine/Expressions/InputParser.cpp +++ b/source/gameengine/Expressions/InputParser.cpp @@ -319,12 +319,14 @@ void CParser::NextSym() } } +#if 0 int CParser::MakeInt() { // returns the integer representation of the value in the global // variable const_as_string // pre: const_as_string contains only numercal chars return atoi(const_as_string); } +#endif STR_String CParser::Symbol2Str(int s) { // returns a string representation of of symbol s, @@ -436,8 +438,8 @@ CExpression *CParser::Ex(int i) { break; case inttype: { - int temp; - temp = atoi(const_as_string); + cInt temp; + temp = strtoll(const_as_string, NULL, 10); /* atoi is for int only */ e1 = new CConstExpr(new CIntValue(temp)); break; } @@ -580,7 +582,7 @@ float CParser::GetFloat(STR_String txt) CExpression* expr = ProcessText(txt); if (expr) { val = expr->Calculate(); - result=val->GetNumber(); + result=(float)val->GetNumber(); diff --git a/source/gameengine/Expressions/InputParser.h b/source/gameengine/Expressions/InputParser.h index f51c473ba18..3d517222639 100644 --- a/source/gameengine/Expressions/InputParser.h +++ b/source/gameengine/Expressions/InputParser.h @@ -94,7 +94,9 @@ private: void CharRep(); void GrabString(int start); void NextSym(); +#if 0 /* not used yet */ int MakeInt(); +#endif STR_String Symbol2Str(int s); void Term(int s); int Priority(int optor); diff --git a/source/gameengine/Expressions/IntValue.cpp b/source/gameengine/Expressions/IntValue.cpp index fb586cb4979..4e86f7bf789 100644 --- a/source/gameengine/Expressions/IntValue.cpp +++ b/source/gameengine/Expressions/IntValue.cpp @@ -42,10 +42,10 @@ effect: constructs a new CIntValue -CIntValue::CIntValue(int innie) +CIntValue::CIntValue(cInt innie) /* pre: -effect: constructs a new CIntValue containing int innie +effect: constructs a new CIntValue containing cInt innie */ { m_int = innie; @@ -54,7 +54,7 @@ effect: constructs a new CIntValue containing int innie -CIntValue::CIntValue(int innie,STR_String name,AllocationTYPE alloctype) +CIntValue::CIntValue(cInt innie,STR_String name,AllocationTYPE alloctype) { m_int = innie; SetName(name); @@ -280,10 +280,10 @@ this object -int CIntValue::GetInt() +cInt CIntValue::GetInt() /* pre: -ret: the int stored in the object +ret: the cInt stored in the object */ { return m_int; @@ -291,7 +291,7 @@ ret: the int stored in the object -float CIntValue::GetNumber() +double CIntValue::GetNumber() { return (float) m_int; } @@ -302,7 +302,7 @@ const STR_String & CIntValue::GetText() { if (!m_pstrRep) m_pstrRep=new STR_String(); - m_pstrRep->Format("%d",m_int); + m_pstrRep->Format("%lld",m_int); return *m_pstrRep; } @@ -321,7 +321,7 @@ CValue* CIntValue::GetReplica() { void CIntValue::SetValue(CValue* newval) { - m_int = (int)newval->GetNumber(); + m_int = (cInt)newval->GetNumber(); SetModified(true); } @@ -329,5 +329,8 @@ void CIntValue::SetValue(CValue* newval) PyObject* CIntValue::ConvertValueToPython() { - return PyInt_FromLong(m_int); + if((m_int > INT_MIN) && (m_int < INT_MAX)) + return PyInt_FromLong(m_int); + else + return PyLong_FromLongLong(m_int); } diff --git a/source/gameengine/Expressions/IntValue.h b/source/gameengine/Expressions/IntValue.h index 4fdc1089857..0f3a38b274b 100644 --- a/source/gameengine/Expressions/IntValue.h +++ b/source/gameengine/Expressions/IntValue.h @@ -18,18 +18,20 @@ #include "Value.h" +typedef long long cInt; + class CIntValue : public CPropValue { //PLUGIN_DECLARE_SERIAL (CIntValue,CValue) public: virtual const STR_String& GetText(); - virtual float GetNumber(); + virtual double GetNumber(); - int GetInt(); + cInt GetInt(); CIntValue(); - CIntValue(int innie); - CIntValue(int innie, + CIntValue(cInt innie); + CIntValue(cInt innie, STR_String name, AllocationTYPE alloctype=CValue::HEAPVALUE); @@ -51,7 +53,7 @@ protected: virtual ~CIntValue(); private: - int m_int; + cInt m_int; STR_String* m_pstrRep; }; diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 16b4fbef6b7..0f163ad07c1 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -561,7 +561,7 @@ void CListValue::Add(CValue* value) -float CListValue::GetNumber() +double CListValue::GetNumber() { return -1; } diff --git a/source/gameengine/Expressions/ListValue.h b/source/gameengine/Expressions/ListValue.h index 6f70acb9367..cf2976c2bbb 100644 --- a/source/gameengine/Expressions/ListValue.h +++ b/source/gameengine/Expressions/ListValue.h @@ -36,7 +36,7 @@ public: virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue* val); - virtual float GetNumber(); + virtual double GetNumber(); virtual CValue* GetReplica(); public: diff --git a/source/gameengine/Expressions/StringValue.cpp b/source/gameengine/Expressions/StringValue.cpp index 1ef8c5629a0..2b3c62c411e 100644 --- a/source/gameengine/Expressions/StringValue.cpp +++ b/source/gameengine/Expressions/StringValue.cpp @@ -113,7 +113,7 @@ this object -float CStringValue::GetNumber() +double CStringValue::GetNumber() { return -1; } diff --git a/source/gameengine/Expressions/StringValue.h b/source/gameengine/Expressions/StringValue.h index b824d4ef86d..16575ed7ffa 100644 --- a/source/gameengine/Expressions/StringValue.h +++ b/source/gameengine/Expressions/StringValue.h @@ -33,7 +33,7 @@ public: /// CValue implementation virtual bool IsEqual(const STR_String & other); virtual const STR_String & GetText(); - virtual float GetNumber(); + virtual double GetNumber(); virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index a631d58d21a..47f0686c4c3 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -86,20 +86,17 @@ int MyPyCompare (PyObject* v,PyObject* w) int cvalue_coerce(PyObject** pv,PyObject** pw) { if (PyInt_Check(*pw)) { - double db = (double)PyInt_AsLong(*pw); - *pw = new CIntValue((int) db); + *pw = new CIntValue((cInt)PyInt_AsLong(*pw)); Py_INCREF(*pv); return 0; } else if (PyLong_Check(*pw)) { - double db = PyLong_AsDouble(*pw); - *pw = new CFloatValue(db); + *pw = new CIntValue((cInt)PyLong_AsLongLong(*pw)); Py_INCREF(*pv); return 0; } else if (PyFloat_Check(*pw)) { - double db = PyFloat_AsDouble(*pw); - *pw = new CFloatValue(db); + *pw = new CFloatValue((float)PyFloat_AsDouble(*pw)); Py_INCREF(*pv); return 0; } else if (PyString_Check(*pw)) { @@ -108,6 +105,8 @@ int cvalue_coerce(PyObject** pv,PyObject** pw) Py_INCREF(*pv); return 0; } + + PyErr_SetString(PyExc_TypeError, "unable to coerce python type to cvalue"); return 1; /* Can't do it */ } @@ -402,7 +401,7 @@ float CValue::GetPropertyNumber(const STR_String& inName,float defnumber) { CValue *property = GetProperty(inName); if (property) - return property->GetNumber(); + return property->GetNumber(); else return defnumber; } @@ -757,7 +756,11 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj) } else if (PyInt_Check(pyobj)) { - vallie = new CIntValue( (int)PyInt_AS_LONG(pyobj) ); + vallie = new CIntValue( (cInt)PyInt_AS_LONG(pyobj) ); + } else + if (PyLong_Check(pyobj)) + { + vallie = new CIntValue( (cInt)PyLong_AsLongLong(pyobj) ); } else if (PyString_Check(pyobj)) { diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h index 7a2816a9778..4cdc80dc9bd 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/Value.h @@ -306,7 +306,7 @@ public: virtual void SetColorOperator(VALUE_OPERATOR op); virtual const STR_String & GetText() = 0; - virtual float GetNumber() = 0; + virtual double GetNumber() = 0; double* ZeroVector() { return m_sZeroVec; }; virtual double* GetVector3(bool bGetTransformedVec = false); diff --git a/source/gameengine/Expressions/VectorValue.cpp b/source/gameengine/Expressions/VectorValue.cpp index bea6902eba8..497a50b90e7 100644 --- a/source/gameengine/Expressions/VectorValue.cpp +++ b/source/gameengine/Expressions/VectorValue.cpp @@ -156,7 +156,7 @@ this object return ret; } -float CVectorValue::GetNumber() +double CVectorValue::GetNumber() { return m_vec[KX_X]; } diff --git a/source/gameengine/Expressions/VectorValue.h b/source/gameengine/Expressions/VectorValue.h index 5d9b2a98891..99bf0abb11b 100644 --- a/source/gameengine/Expressions/VectorValue.h +++ b/source/gameengine/Expressions/VectorValue.h @@ -32,7 +32,7 @@ public: void SetVector(double newvec[]); void Configure(CValue* menuvalue); virtual double* GetVector3(bool bGetTransformedVec=false); - virtual float GetNumber(); + virtual double GetNumber(); CValue* Calc(VALUE_OPERATOR op, CValue *val) { return val->CalcFinal(VALUE_VECTOR_TYPE, op, this); diff --git a/source/gameengine/Expressions/VoidValue.h b/source/gameengine/Expressions/VoidValue.h index 4bde0254787..10a6ff9ad3d 100644 --- a/source/gameengine/Expressions/VoidValue.h +++ b/source/gameengine/Expressions/VoidValue.h @@ -47,7 +47,7 @@ public: /// Value -> String or number virtual const STR_String & GetText(); // Get string description of void value (unimplemented) - virtual float GetNumber() { return -1; } + virtual double GetNumber() { return -1; } /// Value calculation virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.cpp b/source/gameengine/GameLogic/SCA_ExpressionController.cpp index 8ed46beb7f3..352a39a6fea 100644 --- a/source/gameengine/GameLogic/SCA_ExpressionController.cpp +++ b/source/gameengine/GameLogic/SCA_ExpressionController.cpp @@ -109,7 +109,7 @@ void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr) printf(value->GetText()); } else { - float num = value->GetNumber(); + float num = (float)value->GetNumber(); expressionresult = !MT_fuzzyZero(num); } value->Release(); diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index 900975b9f15..46e132c65fc 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -123,7 +123,7 @@ const STR_String& SCA_ILogicBrick::GetText() -float SCA_ILogicBrick::GetNumber() +double SCA_ILogicBrick::GetNumber() { return -1; } diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h index c098f9dfd8a..20fa3c2d687 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.h +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h @@ -69,7 +69,7 @@ public: virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); virtual const STR_String & GetText(); - virtual float GetNumber(); + virtual double GetNumber(); virtual STR_String GetName(); virtual void SetName(STR_String name); virtual void ReplicaSetName(STR_String name); diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index bb1f73bf7f9..3c21cf66e09 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -105,7 +105,7 @@ void SCA_ISensor::SetLevel(bool lvl) { } -float SCA_ISensor::GetNumber() { +double SCA_ISensor::GetNumber() { return IsPositiveTrigger(); } diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h index cfc95682089..18d630fce0e 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.h +++ b/source/gameengine/GameLogic/SCA_ISensor.h @@ -113,7 +113,7 @@ public: virtual void RegisterToManager(); virtual void UnregisterToManager(); - virtual float GetNumber(); + virtual double GetNumber(); /** Stop sensing for a while. */ void Suspend(); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 13e839d9d2e..f5bf868dd59 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -164,7 +164,7 @@ const STR_String & KX_GameObject::GetText() -float KX_GameObject::GetNumber() +double KX_GameObject::GetNumber() { return 0; } diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index f4d35faaeb6..58f2c56c1da 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -208,7 +208,7 @@ public: /** * Inherited from CValue -- does nothing! */ - float + double GetNumber( ); diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index bcda4a8e3c4..e7f562bda8e 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -120,7 +120,7 @@ CValue* KX_MeshProxy::Calc(VALUE_OPERATOR op, CValue *val) { return NULL;} CValue* KX_MeshProxy::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) { return NULL;} const STR_String & KX_MeshProxy::GetText() {return m_meshobj->GetName();}; -float KX_MeshProxy::GetNumber() { return -1;} +double KX_MeshProxy::GetNumber() { return -1;} STR_String KX_MeshProxy::GetName() { return m_meshobj->GetName();} void KX_MeshProxy::SetName(STR_String name) { }; CValue* KX_MeshProxy::GetReplica() { return NULL;} diff --git a/source/gameengine/Ketsji/KX_MeshProxy.h b/source/gameengine/Ketsji/KX_MeshProxy.h index 56a6dfcac42..3b72099eebb 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.h +++ b/source/gameengine/Ketsji/KX_MeshProxy.h @@ -46,7 +46,7 @@ public: virtual CValue* Calc(VALUE_OPERATOR op, CValue *val) ; virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); virtual const STR_String & GetText(); - virtual float GetNumber(); + virtual double GetNumber(); virtual RAS_MeshObject* GetMesh() { return m_meshobj; } virtual STR_String GetName(); virtual void SetName(STR_String name); // Set the name of the value diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp index 1e6f49ead2e..e102ca4e0e6 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.cpp +++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp @@ -177,7 +177,7 @@ CValue* KX_PolyProxy::Calc(VALUE_OPERATOR, CValue *) { return NULL;} CValue* KX_PolyProxy::CalcFinal(VALUE_DATA_TYPE, VALUE_OPERATOR, CValue *) { return NULL;} STR_String sPolyName="polygone"; const STR_String & KX_PolyProxy::GetText() {return sPolyName;}; -float KX_PolyProxy::GetNumber() { return -1;} +double KX_PolyProxy::GetNumber() { return -1;} STR_String KX_PolyProxy::GetName() { return sPolyName;} void KX_PolyProxy::SetName(STR_String) { }; CValue* KX_PolyProxy::GetReplica() { return NULL;} diff --git a/source/gameengine/Ketsji/KX_PolyProxy.h b/source/gameengine/Ketsji/KX_PolyProxy.h index a549d9841cc..275e65da810 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.h +++ b/source/gameengine/Ketsji/KX_PolyProxy.h @@ -45,7 +45,7 @@ public: CValue* Calc(VALUE_OPERATOR op, CValue *val) ; CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); const STR_String & GetText(); - float GetNumber(); + double GetNumber(); STR_String GetName(); void SetName(STR_String name); // Set the name of the value void ReplicaSetName(STR_String name); diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp index f3e9bbf86b1..bb12f405332 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.cpp +++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp @@ -332,7 +332,7 @@ CValue* KX_VertexProxy::Calc(VALUE_OPERATOR, CValue *) { return NULL;} CValue* KX_VertexProxy::CalcFinal(VALUE_DATA_TYPE, VALUE_OPERATOR, CValue *) { return NULL;} STR_String sVertexName="vertex"; const STR_String & KX_VertexProxy::GetText() {return sVertexName;}; -float KX_VertexProxy::GetNumber() { return -1;} +double KX_VertexProxy::GetNumber() { return -1;} STR_String KX_VertexProxy::GetName() { return sVertexName;} void KX_VertexProxy::SetName(STR_String) { }; CValue* KX_VertexProxy::GetReplica() { return NULL;} diff --git a/source/gameengine/Ketsji/KX_VertexProxy.h b/source/gameengine/Ketsji/KX_VertexProxy.h index 26772fc7d60..67a15d96768 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.h +++ b/source/gameengine/Ketsji/KX_VertexProxy.h @@ -46,7 +46,7 @@ public: CValue* Calc(VALUE_OPERATOR op, CValue *val) ; CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); const STR_String & GetText(); - float GetNumber(); + double GetNumber(); STR_String GetName(); void SetName(STR_String name); // Set the name of the value void ReplicaSetName(STR_String name); -- cgit v1.2.3 From 55d2b184ec1b2c1adfe182ead937cedae1a8208d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 12 Apr 2009 07:24:04 +0000 Subject: added "toggle" an option for the property actuator. much less hassle then setting up a property sensor and 2 assignment actuators, or through python. --- source/gameengine/GameLogic/SCA_PropertyActuator.cpp | 17 +++++++++++++++++ source/gameengine/GameLogic/SCA_PropertyActuator.h | 1 + 2 files changed, 18 insertions(+) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index 444c616870d..37df8a5c401 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -135,6 +135,23 @@ bool SCA_PropertyActuator::Update() } break; } + case KX_ACT_PROP_TOGGLE: + { + + CValue* newval; + CValue* oldprop = propowner->GetProperty(m_propname); + if (oldprop) + { + newval = new CBoolValue((oldprop->GetNumber()==0.0) ? true:false); + oldprop->SetValue(newval); + } else + { /* as not been assigned, evaluate as false, so assign true */ + newval = new CBoolValue(true); + propowner->SetProperty(m_propname,newval); + } + newval->Release(); + break; + } default: { diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.h b/source/gameengine/GameLogic/SCA_PropertyActuator.h index 6a975716ed0..bb841cf88ad 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.h +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.h @@ -43,6 +43,7 @@ class SCA_PropertyActuator : public SCA_IActuator KX_ACT_PROP_ASSIGN, KX_ACT_PROP_ADD, KX_ACT_PROP_COPY, + KX_ACT_PROP_TOGGLE, KX_ACT_PROP_MAX }; -- cgit v1.2.3 From 5b306b7541bfc60342b70bcc55456d5c453a294a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 12 Apr 2009 09:56:30 +0000 Subject: BGE Python API added defines PY_SET_ATTR_FAIL, PY_SET_ATTR_MISSING and PY_SET_ATTR_SUCCESS This is useful when objects that have user defined attributes (GameObject and Scene) When calling setattr on the parent, a return value of PY_SET_ATTR_FAIL means the attribute exists but failed to be set, so don't set the custom attribute. --- source/gameengine/Expressions/PyObjectPlus.cpp | 6 ++-- source/gameengine/Expressions/PyObjectPlus.h | 14 +++++++-- source/gameengine/Expressions/Value.cpp | 4 +-- source/gameengine/Ketsji/KX_ConstraintWrapper.cpp | 2 +- source/gameengine/Ketsji/KX_Light.cpp | 22 +++++++------- source/gameengine/Ketsji/KX_Scene.h | 8 ++--- source/gameengine/Ketsji/KX_VehicleWrapper.cpp | 2 +- source/gameengine/Ketsji/KX_VertexProxy.cpp | 36 +++++++++++------------ 8 files changed, 52 insertions(+), 42 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 4526f8f649b..33335ebef3e 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -137,7 +137,7 @@ int PyObjectPlus::py_setattro(PyObject *attr, PyObject* value) //return PyObject::py_setattro(attr,value); //cerr << "Unknown attribute" << endl; PyErr_SetString(PyExc_AttributeError, "attribute cant be set"); - return 1; + return PY_SET_ATTR_MISSING; } PyObject *PyObjectPlus::py_get_attrdef(void *self, const PyAttributeDef *attrdef) @@ -699,13 +699,13 @@ int PyObjectPlus::py_setattro_self(const PyAttributeDef attrlist[], void *self, attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY) { PyErr_SetString(PyExc_AttributeError, "property is read-only"); - return 1; + return PY_SET_ATTR_FAIL; } return py_set_attrdef(self, attrdef, value); } } - return -1; + return PY_SET_ATTR_MISSING; } #endif diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 42168461634..f61b9f8d0b8 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -124,6 +124,16 @@ static inline void Py_Fatal(const char *M) { return NULL; +/* + * nonzero values are an error for setattr + * however because of the nested lookups we need to know if the errors + * was because the attribute didnt exits of if there was some problem setting the value + */ + +#define PY_SET_ATTR_FAIL 1 +#define PY_SET_ATTR_MISSING -1 +#define PY_SET_ATTR_SUCCESS 0 + #define py_setattro_up(Parent) \ PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \ \ @@ -132,14 +142,14 @@ static inline void Py_Fatal(const char *M) { const PyAttributeDef* attrdef= reinterpret_cast(PyCObject_AsVoidPtr(descr)); \ if (attrdef->m_access == KX_PYATTRIBUTE_RO) { \ PyErr_Format(PyExc_AttributeError, "\"%s\" is read only", PyString_AsString(attr)); \ - return -1; \ + return PY_SET_ATTR_FAIL; \ } \ else { \ return py_set_attrdef((void *)this, attrdef, value); \ } \ } else { \ PyErr_Format(PyExc_AttributeError, "\"%s\" cannot be set", PyString_AsString(attr)); \ - return -1; \ + return PY_SET_ATTR_FAIL; \ } \ } else { \ PyErr_Clear(); \ diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index 47f0686c4c3..f1e367d6e59 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -804,11 +804,11 @@ int CValue::py_setattro(PyObject *attr, PyObject* pyobj) vallie->Release(); } else { - return 1; /* ConvertPythonToValue sets the error message */ + return PY_SET_ATTR_FAIL; /* ConvertPythonToValue sets the error message */ } //PyObjectPlus::py_setattro(attr,value); - return 0; + return PY_SET_ATTR_SUCCESS; }; PyObject* CValue::ConvertKeysToPython( void ) diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp index edd6e991e9f..6f4d970c568 100644 --- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp @@ -101,7 +101,7 @@ PyObject* KX_ConstraintWrapper::py_getattro(PyObject *attr) int KX_ConstraintWrapper::py_setattro(PyObject *attr,PyObject* pyobj) { int result = 1; - + /* what the heck is this supposed to do?, needs attention */ if (PyList_Check(pyobj)) { result = 0; diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp index f996f86d751..059345ea8de 100644 --- a/source/gameengine/Ketsji/KX_Light.cpp +++ b/source/gameengine/Ketsji/KX_Light.cpp @@ -225,14 +225,14 @@ int KX_LightObject::py_setattro(PyObject *attr, PyObject *pyvalue) if (!strcmp(attr_str, "layer")) { m_lightobj.m_layer = value; - return 0; + return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "type")) { if (value >= RAS_LightObject::LIGHT_SPOT && value <= RAS_LightObject::LIGHT_NORMAL) m_lightobj.m_type = (RAS_LightObject::LightType) value; - return 0; + return PY_SET_ATTR_SUCCESS; } } @@ -242,37 +242,37 @@ int KX_LightObject::py_setattro(PyObject *attr, PyObject *pyvalue) if (!strcmp(attr_str, "energy")) { m_lightobj.m_energy = value; - return 0; + return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "distance")) { m_lightobj.m_distance = value; - return 0; + return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "lin_attenuation")) { m_lightobj.m_att1 = value; - return 0; + return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "quad_attenuation")) { m_lightobj.m_att2 = value; - return 0; + return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "spotsize")) { m_lightobj.m_spotsize = value; - return 0; + return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "spotblend")) { m_lightobj.m_spotblend = value; - return 0; + return PY_SET_ATTR_SUCCESS; } } @@ -286,16 +286,16 @@ int KX_LightObject::py_setattro(PyObject *attr, PyObject *pyvalue) m_lightobj.m_red = color[0]; m_lightobj.m_green = color[1]; m_lightobj.m_blue = color[2]; - return 0; + return PY_SET_ATTR_SUCCESS; } - return 1; + return PY_SET_ATTR_FAIL; } } if (!strcmp(attr_str, "SPOT") || !strcmp(attr_str, "SUN") || !strcmp(attr_str, "NORMAL")) { PyErr_Format(PyExc_RuntimeError, "Attribute %s is read only.", attr_str); - return 1; + return PY_SET_ATTR_FAIL; } return KX_GameObject::py_setattro(attr, pyvalue); diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 1bdfbd45d20..b70c6d3e8d3 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -597,13 +597,13 @@ public: int ret= ((PyObjectPlus*) self)->py_setattro(attr, value); - if (ret) { - if (!PyDict_SetItem(((KX_Scene *) self)->m_attrlist, attr, value)) { + if (ret==PY_SET_ATTR_MISSING) { + if (PyDict_SetItem(((KX_Scene *) self)->m_attrlist, attr, value)==0) { PyErr_Clear(); - ret= 0; + ret= PY_SET_ATTR_SUCCESS; } else { - ret= -1; + ret= PY_SET_ATTR_FAIL; } } diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp index 315b60922b7..98f5a1ea87d 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp @@ -331,7 +331,7 @@ PyObject* KX_VehicleWrapper::py_getattro(PyObject *attr) int KX_VehicleWrapper::py_setattro(PyObject *attr,PyObject* pyobj) { - + /* TODO - strange setattr, needs updating */ PyTypeObject* type = pyobj->ob_type; int result = 1; diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp index bb12f405332..6a160dff7b7 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.cpp +++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp @@ -171,9 +171,9 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue) { m_vertex->SetXYZ(vec); m_mesh->SetMeshModified(true); - return 0; + return PY_SET_ATTR_SUCCESS; } - return 1; + return PY_SET_ATTR_FAIL; } if (!strcmp(attr_str, "UV")) @@ -183,9 +183,9 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue) { m_vertex->SetUV(vec); m_mesh->SetMeshModified(true); - return 0; + return PY_SET_ATTR_SUCCESS; } - return 1; + return PY_SET_ATTR_FAIL; } if (!strcmp(attr_str, "color") || !strcmp(attr_str, "colour")) @@ -195,9 +195,9 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue) { m_vertex->SetRGBA(vec); m_mesh->SetMeshModified(true); - return 0; + return PY_SET_ATTR_SUCCESS; } - return 1; + return PY_SET_ATTR_FAIL; } if (!strcmp(attr_str, "normal")) @@ -207,9 +207,9 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue) { m_vertex->SetNormal(vec); m_mesh->SetMeshModified(true); - return 0; + return PY_SET_ATTR_SUCCESS; } - return 1; + return PY_SET_ATTR_FAIL; } } @@ -223,7 +223,7 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue) pos.x() = val; m_vertex->SetXYZ(pos); m_mesh->SetMeshModified(true); - return 0; + return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "y")) @@ -231,7 +231,7 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue) pos.y() = val; m_vertex->SetXYZ(pos); m_mesh->SetMeshModified(true); - return 0; + return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "z")) @@ -239,7 +239,7 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue) pos.z() = val; m_vertex->SetXYZ(pos); m_mesh->SetMeshModified(true); - return 0; + return PY_SET_ATTR_SUCCESS; } // uv @@ -249,7 +249,7 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue) uv[0] = val; m_vertex->SetUV(uv); m_mesh->SetMeshModified(true); - return 0; + return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "v")) @@ -257,7 +257,7 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue) uv[1] = val; m_vertex->SetUV(uv); m_mesh->SetMeshModified(true); - return 0; + return PY_SET_ATTR_SUCCESS; } // uv @@ -275,7 +275,7 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue) uv[1] = val; m_vertex->SetUV2(uv); m_mesh->SetMeshModified(true); - return 0; + return PY_SET_ATTR_SUCCESS; } // col @@ -287,28 +287,28 @@ int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue) cp[0] = (unsigned char) val; m_vertex->SetRGBA(icol); m_mesh->SetMeshModified(true); - return 0; + return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "g")) { cp[1] = (unsigned char) val; m_vertex->SetRGBA(icol); m_mesh->SetMeshModified(true); - return 0; + return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "b")) { cp[2] = (unsigned char) val; m_vertex->SetRGBA(icol); m_mesh->SetMeshModified(true); - return 0; + return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "a")) { cp[3] = (unsigned char) val; m_vertex->SetRGBA(icol); m_mesh->SetMeshModified(true); - return 0; + return PY_SET_ATTR_SUCCESS; } } -- cgit v1.2.3 From ee24c829b56ebddb47ae2bcfe30db5d857610450 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 12 Apr 2009 10:56:36 +0000 Subject: need strtoll defined as _strtoi64 to build on windows --- source/gameengine/Expressions/InputParser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/InputParser.cpp b/source/gameengine/Expressions/InputParser.cpp index 677bbb36d70..181cd6f3907 100644 --- a/source/gameengine/Expressions/InputParser.cpp +++ b/source/gameengine/Expressions/InputParser.cpp @@ -39,7 +39,8 @@ #include "IfExpr.h" #if defined(WIN32) || defined(WIN64) -#define strcasecmp _stricmp +#define strcasecmp _stricmp +#define strtoll _strtoi64 #endif /* Def WIN32 or Def WIN64 */ #define NUM_PRIORITY 6 -- cgit v1.2.3 From 332032fb9925091da49efa2e9c3653bdb3e68cba Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 12 Apr 2009 14:22:51 +0000 Subject: BGE Python API Support for assigning any Type to a KX_GameObject so you can do... gameOb.follow = otherGameOb gameOb[otherGameOb] = distanceTo gameOb["path"] = [(x,y,x), (x,y,x)] del gameOb[mesh] * types that cannot be converted into CValue types are written into the KX_GameObject dict * the KX_GameObject dict is only initialized when needed * Python properties in this dict cannot be accessed by logic bricks * dir(ob) and ob.getPropertyNames() return items from both CValue and Py dictionary properties. Also found that CType was converting python lists to CType Lists but very buggy, would crash after printing the list most times. Use python lists instead since logic bricks dont deal with lists. --- source/gameengine/Expressions/PyObjectPlus.h | 5 +- source/gameengine/Expressions/Value.cpp | 29 +++-- source/gameengine/Ketsji/KX_GameObject.cpp | 157 ++++++++++++++++++++------- source/gameengine/Ketsji/KX_GameObject.h | 119 +++++++++++++++++++- source/gameengine/Ketsji/KX_Scene.h | 1 + 5 files changed, 262 insertions(+), 49 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index f61b9f8d0b8..ea26ea1d201 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -130,9 +130,10 @@ static inline void Py_Fatal(const char *M) { * was because the attribute didnt exits of if there was some problem setting the value */ +#define PY_SET_ATTR_COERCE_FAIL 2 #define PY_SET_ATTR_FAIL 1 -#define PY_SET_ATTR_MISSING -1 -#define PY_SET_ATTR_SUCCESS 0 +#define PY_SET_ATTR_MISSING -1 +#define PY_SET_ATTR_SUCCESS 0 #define py_setattro_up(Parent) \ PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \ diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index f1e367d6e59..b8b7a05aa64 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -719,7 +719,8 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj) { CValue* vallie = NULL; - + /* refcounting is broking here! - this crashes anyway, just store a python list for KX_GameObject */ +#if 0 if (PyList_Check(pyobj)) { CListValue* listval = new CListValue(); @@ -750,6 +751,7 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj) } } else +#endif if (PyFloat_Check(pyobj)) { vallie = new CFloatValue( (float)PyFloat_AsDouble(pyobj) ); @@ -790,21 +792,34 @@ int CValue::py_delattro(PyObject *attr) int CValue::py_setattro(PyObject *attr, PyObject* pyobj) { + char *attr_str= PyString_AsString(attr); + CValue* oldprop = GetProperty(attr_str); + CValue* vallie = ConvertPythonToValue(pyobj); if (vallie) { - char *attr_str= PyString_AsString(attr); - CValue* oldprop = GetProperty(attr_str); - if (oldprop) oldprop->SetValue(vallie); else SetProperty(attr_str, vallie); vallie->Release(); - } else - { - return PY_SET_ATTR_FAIL; /* ConvertPythonToValue sets the error message */ + } + else { + // ConvertPythonToValue sets the error message + // must return missing so KX_GameObect knows this + // attribute was not a function or bult in attribute, + // + // CValue attributes override internal attributes + // so if it exists as a CValue attribute already, + // assume your trying to set it to a differnt CValue attribute + // otherwise return PY_SET_ATTR_MISSING so children + // classes know they can set it without conflict + + if (GetProperty(attr_str)) + return PY_SET_ATTR_COERCE_FAIL; /* failed to set an existing attribute */ + else + return PY_SET_ATTR_MISSING; /* allow the KX_GameObject dict to set */ } //PyObjectPlus::py_setattro(attr,value); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index f5bf868dd59..817afedd205 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -97,7 +97,8 @@ KX_GameObject::KX_GameObject( m_pPhysicsEnvironment(NULL), m_xray(false), m_pHitObject(NULL), - m_isDeformable(false) + m_isDeformable(false), + m_attrlist(NULL) { m_ignore_activity_culling = false; m_pClient_info = new KX_ClientObjectInfo(this, KX_ClientObjectInfo::ACTOR); @@ -139,6 +140,10 @@ KX_GameObject::~KX_GameObject() { delete m_pGraphicController; } + + if (m_attrlist) { + Py_DECREF(m_attrlist); + } } @@ -323,6 +328,9 @@ void KX_GameObject::ProcessReplica(KX_GameObject* replica) replica->m_pClient_info = new KX_ClientObjectInfo(*m_pClient_info); replica->m_pClient_info->m_gameobject = replica; replica->m_state = 0; + if(m_attrlist) + replica->m_attrlist= PyDict_Copy(m_attrlist); + } @@ -1138,69 +1146,124 @@ PyObject* KX_GameObject::PyGetPosition(PyObject* self) Py_ssize_t KX_GameObject::Map_Len(PyObject* self_v) { - return (static_cast(self_v))->GetPropertyCount(); + KX_GameObject* self= static_cast(self_v); + Py_ssize_t len= self->GetPropertyCount(); + if(self->m_attrlist) + len += PyDict_Size(self->m_attrlist); + return len; } PyObject *KX_GameObject::Map_GetItem(PyObject *self_v, PyObject *item) { KX_GameObject* self= static_cast(self_v); - const char *attr= PyString_AsString(item); + const char *attr_str= PyString_AsString(item); CValue* resultattr; PyObject* pyconvert; - - if(attr==NULL) { - PyErr_SetString(PyExc_TypeError, "KX_GameObject key but a string"); - return NULL; + /* first see if the attributes a string and try get the cvalue attribute */ + if(attr_str && (resultattr=self->GetProperty(attr_str))) { + pyconvert = resultattr->ConvertValueToPython(); + return pyconvert ? pyconvert:resultattr; } - - resultattr = self->GetProperty(attr); - - if(resultattr==NULL) { - PyErr_SetString(PyExc_KeyError, "KX_GameObject key does not exist"); + /* no CValue attribute, try get the python only m_attrlist attribute */ + else if (self->m_attrlist && (pyconvert=PyDict_GetItem(self->m_attrlist, item))) { + + if (attr_str) + PyErr_Clear(); + Py_INCREF(pyconvert); + return pyconvert; + } + else { + if(attr_str) PyErr_Format(PyExc_KeyError, "KX_GameObject key \"%s\" does not exist", attr_str); + else PyErr_SetString(PyExc_KeyError, "KX_GameObject key does not exist"); return NULL; } - - pyconvert = resultattr->ConvertValueToPython(); - - return pyconvert ? pyconvert:resultattr; + } int KX_GameObject::Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val) { KX_GameObject* self= static_cast(self_v); - const char *attr= PyString_AsString(key); - - if(attr==NULL) { - PyErr_SetString(PyExc_TypeError, "KX_GameObject key but a string"); - return 1; - } + const char *attr_str= PyString_AsString(key); + if(attr_str==NULL) + PyErr_Clear(); if (val==NULL) { /* del ob["key"] */ - if (self->RemoveProperty(attr)==false) { - PyErr_Format(PyExc_KeyError, "KX_GameObject key \"%s\" not found", attr); - return 1; + int del= 0; + + /* try remove both just incase */ + if(attr_str) + del |= (self->RemoveProperty(attr_str)==true) ? 1:0; + + if(self->m_attrlist) + del |= (PyDict_DelItem(self->m_attrlist, key)==0) ? 1:0; + + if (del==0) { + if(attr_str) PyErr_Format(PyExc_KeyError, "KX_GameObject key \"%s\" not found", attr_str); + else PyErr_SetString(PyExc_KeyError, "KX_GameObject key not found"); + return -1; + } + else if (self->m_attrlist) { + PyErr_Clear(); /* PyDict_DelItem sets an error when it fails */ } } else { /* ob["key"] = value */ - CValue* vallie = self->ConvertPythonToValue(val); + int set= 0; - if(vallie==NULL) - return 1; /* ConvertPythonToValue sets the error */ + /* as CValue */ + if(attr_str) + { + CValue* vallie = self->ConvertPythonToValue(val); + + if(vallie) + { + CValue* oldprop = self->GetProperty(attr_str); + + if (oldprop) + oldprop->SetValue(vallie); + else + self->SetProperty(attr_str, vallie); + + vallie->Release(); + set= 1; + + /* try remove dict value to avoid double ups */ + if (self->m_attrlist){ + if (PyDict_DelItem(self->m_attrlist, key) != 0) + PyErr_Clear(); + } + } + else { + PyErr_Clear(); + } + } - CValue* oldprop = self->GetProperty(attr); + if(set==0) + { + if (self->m_attrlist==NULL) /* lazy init */ + self->m_attrlist= PyDict_New(); + + + if(PyDict_SetItem(self->m_attrlist, key, val)==0) + { + if(attr_str) + self->RemoveProperty(attr_str); /* overwrite the CValue if it exists */ + set= 1; + } + else { + if(attr_str) PyErr_Format(PyExc_KeyError, "KX_GameObject key \"%s\" not be added to internal dictionary", attr_str); + else PyErr_SetString(PyExc_KeyError, "KX_GameObject key not be added to internal dictionary"); + } + } - if (oldprop) - oldprop->SetValue(vallie); - else - self->SetProperty(attr, vallie); + if(set==0) + return -1; /* pythons error value */ - vallie->Release(); } - return 0; + return 0; /* success */ } @@ -1223,9 +1286,11 @@ PyTypeObject KX_GameObject::Type = { 0, 0, py_base_repr, - 0,0,0,0,0,0, - py_base_getattro, - py_base_setattro, + 0,0, + &Mapping, + 0,0,0, + py_base_getattro_gameobject, + py_base_setattro_gameobject, 0,0,0,0,0,0,0,0,0, Methods }; @@ -1533,6 +1598,10 @@ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_ Py_DECREF(list); + /* Add m_attrlist if we have it */ + if(self->m_attrlist) + PyDict_Update(dict, self->m_attrlist); + return dict; } @@ -2042,7 +2111,17 @@ PyObject* KX_GameObject::PyGetPhysicsId(PyObject* self) PyObject* KX_GameObject::PyGetPropertyNames(PyObject* self) { - return ConvertKeysToPython(); + PyObject *list= ConvertKeysToPython(); + + if(m_attrlist) { + PyObject *key, *value; + Py_ssize_t pos = 0; + + while (PyDict_Next(m_attrlist, &pos, &key, &value)) { + PyList_Append(list, key); + } + } + return list; } KX_PYMETHODDEF_DOC_O(KX_GameObject, getDistanceTo, diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 58f2c56c1da..172272150c0 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -103,6 +103,26 @@ protected: public: bool m_isDeformable; + // Python attributes that wont convert into CValue + // + // there are 2 places attributes can be stored, in the CValue, + // where attributes are converted into BGE's CValue types + // these can be used with property actuators + // + // For the python API, For types that cannot be converted into CValues (lists, dicts, GameObjects) + // these will be put into "m_attrlist", logic bricks cannot access them. + // + // rules for setting attributes. + // + // * there should NEVER be a CValue and a m_attrlist attribute with matching names. get/sets make sure of this. + // * if CValue conversion fails, use a PyObject in "m_attrlist" + // * when assigning a value, first see if it can be a CValue, if it can remove the "m_attrlist" and set the CValue + // + + PyObject* m_attrlist; + + + virtual void /* This function should be virtual - derived classed override it */ Relink( GEN_Map *map @@ -768,11 +788,108 @@ public: /** * @section Python interface functions. */ - + virtual PyObject* py_getattro(PyObject *attr); virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method virtual PyObject* py_repr(void) { return PyString_FromString(GetName().ReadPtr()); } + /* we need our own getattr and setattr types */ + /* See m_attrlist definition for rules on how this works */ + static PyObject *py_base_getattro_gameobject(PyObject * self, PyObject *attr) + { + PyObject *object= ((KX_GameObject *) self)->py_getattro(attr); + + if (object==NULL && ((KX_GameObject *) self)->m_attrlist) { + /* backup the exception incase the attr doesnt exist in the dict either */ + PyObject *err_type, *err_value, *err_tb; + PyErr_Fetch(&err_type, &err_value, &err_tb); + + object= PyDict_GetItem(((KX_GameObject *) self)->m_attrlist, attr); + if (object) { + Py_INCREF(object); + + PyErr_Clear(); + Py_XDECREF( err_type ); + Py_XDECREF( err_value ); + Py_XDECREF( err_tb ); + } + else { + PyErr_Restore(err_type, err_value, err_tb); /* use the error from the parent function */ + } + } + return object; + } + + static int py_base_setattro_gameobject(PyObject * self, PyObject *attr, PyObject *value) + { + int ret; + + /* Delete the item */ + if (value==NULL) + { + ret= ((PyObjectPlus*) self)->py_delattro(attr); + + if (ret != 0) /* CValue attribute failed, try KX_GameObject m_attrlist dict */ + { + if (((KX_GameObject *) self)->m_attrlist) + { + /* backup the exception incase the attr doesnt exist in the dict either */ + PyObject *err_type, *err_value, *err_tb; + PyErr_Fetch(&err_type, &err_value, &err_tb); + + if (PyDict_DelItem(((KX_GameObject *) self)->m_attrlist, attr) == 0) + { + ret= 0; + PyErr_Clear(); + Py_XDECREF( err_type ); + Py_XDECREF( err_value ); + Py_XDECREF( err_tb ); + } + else { + PyErr_Restore(err_type, err_value, err_tb); /* use the error from the parent function */ + } + } + } + return ret; + } + + + ret= ((PyObjectPlus*) self)->py_setattro(attr, value); + + if (ret==PY_SET_ATTR_SUCCESS) { + /* remove attribute in our own dict to avoid double ups */ + if (((KX_GameObject *) self)->m_attrlist) { + if (PyDict_DelItem(((KX_GameObject *) self)->m_attrlist, attr) != 0) + PyErr_Clear(); + } + } + + if (ret==PY_SET_ATTR_COERCE_FAIL) { + /* CValue attribute exists, remove and add dict value */ + ((KX_GameObject *) self)->RemoveProperty(STR_String(PyString_AsString(attr))); + ret= PY_SET_ATTR_MISSING; + } + + if (ret==PY_SET_ATTR_MISSING) { + /* Lazy initialization */ + if (((KX_GameObject *) self)->m_attrlist==NULL) + ((KX_GameObject *) self)->m_attrlist = PyDict_New(); + + if (PyDict_SetItem(((KX_GameObject *) self)->m_attrlist, attr, value)==0) { + PyErr_Clear(); + ret= PY_SET_ATTR_SUCCESS; + } + else { + PyErr_Format(PyExc_AttributeError, "failed assigning value to KX_GameObject internal dictionary"); + ret= PY_SET_ATTR_FAIL; + } + } + + return ret; + } + + + 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_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index b70c6d3e8d3..55e7afa4957 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -603,6 +603,7 @@ public: ret= PY_SET_ATTR_SUCCESS; } else { + PyErr_Format(PyExc_AttributeError, "failed assigning value to KX_Scenes internal dictionary"); ret= PY_SET_ATTR_FAIL; } } -- cgit v1.2.3 From 17f35293ee9d83605db7d73e7213d206d507a587 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 12 Apr 2009 16:10:43 +0000 Subject: PropertyActuator toggle option didnt run when the Value field was empty. --- .../gameengine/GameLogic/SCA_PropertyActuator.cpp | 40 ++++++++++------------ 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index 37df8a5c401..359ab8adac6 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -77,11 +77,25 @@ bool SCA_PropertyActuator::Update() CParser parser; parser.SetContext( propowner->AddRef()); - CExpression* userexpr = parser.ProcessText(m_exprtxt); - if (userexpr) + CExpression* userexpr= NULL; + + if (m_type==KX_ACT_PROP_TOGGLE) { - - + /* dont use */ + CValue* newval; + CValue* oldprop = propowner->GetProperty(m_propname); + if (oldprop) + { + newval = new CBoolValue((oldprop->GetNumber()==0.0) ? true:false); + oldprop->SetValue(newval); + } else + { /* as not been assigned, evaluate as false, so assign true */ + newval = new CBoolValue(true); + propowner->SetProperty(m_propname,newval); + } + newval->Release(); + } + else if (userexpr = parser.ProcessText(m_exprtxt)) { switch (m_type) { @@ -135,23 +149,7 @@ bool SCA_PropertyActuator::Update() } break; } - case KX_ACT_PROP_TOGGLE: - { - - CValue* newval; - CValue* oldprop = propowner->GetProperty(m_propname); - if (oldprop) - { - newval = new CBoolValue((oldprop->GetNumber()==0.0) ? true:false); - oldprop->SetValue(newval); - } else - { /* as not been assigned, evaluate as false, so assign true */ - newval = new CBoolValue(true); - propowner->SetProperty(m_propname,newval); - } - newval->Release(); - break; - } + /* case KX_ACT_PROP_TOGGLE: */ /* accounted for above, no need for userexpr */ default: { -- cgit v1.2.3 From 8664e35adf6be85b2c9603171049c5a880ced147 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Sun, 12 Apr 2009 19:46:50 +0000 Subject: 2DFilter bugfixes: [#18154] 2dFilter and motion blur should run only once to all the scenes [#18504] The GL_PROJECTION matrix is being reset by the 2dfilter. --- source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 7 +++---- source/gameengine/Rasterizer/RAS_2DFilterManager.cpp | 8 ++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index e64ffa95161..aeb80806f6c 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -898,6 +898,9 @@ void KX_KetsjiEngine::Render() } } // if(m_rasterizer->Stereo()) + // run the 2dfilters and motion blur once for all the scenes + PostRenderFrame(); + EndFrame(); } @@ -1264,16 +1267,12 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam) scene->GetPhysicsEnvironment()->debugDrawWorld(); m_rasterizer->FlushDebugLines(); - - PostRenderFrame(); } void KX_KetsjiEngine::PostRenderFrame() { - m_rendertools->PushMatrix(); m_rendertools->Render2DFilters(m_canvas); m_rendertools->MotionBlur(m_rasterizer); - m_rendertools->PopMatrix(); } void KX_KetsjiEngine::StopEngine() diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp index 282c7306285..176da51b183 100644 --- a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp @@ -435,11 +435,12 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) glViewport(0,0, texturewidth, textureheight); glDisable(GL_DEPTH_TEST); + glPushMatrix(); //GL_MODELVIEW + glLoadIdentity(); // GL_MODELVIEW glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + glPushMatrix(); glLoadIdentity(); for(passindex =0; passindex& propNames, void* gameObj, RAS_2DFILTER_MODE mode, int pass, STR_String& text) -- cgit v1.2.3 From 066098dfec0879bc6cab90cee4f3555471cc4818 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 12 Apr 2009 22:05:09 +0000 Subject: this should fix building with mingw --- source/gameengine/Expressions/InputParser.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/InputParser.cpp b/source/gameengine/Expressions/InputParser.cpp index 181cd6f3907..1698f1919d1 100644 --- a/source/gameengine/Expressions/InputParser.cpp +++ b/source/gameengine/Expressions/InputParser.cpp @@ -40,7 +40,11 @@ #if defined(WIN32) || defined(WIN64) #define strcasecmp _stricmp + +#ifndef strtoll #define strtoll _strtoi64 +#endif + #endif /* Def WIN32 or Def WIN64 */ #define NUM_PRIORITY 6 -- cgit v1.2.3 From 1b73d3ce058a0edbbdfcc573d0084f655a9c8465 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 13 Apr 2009 03:43:16 +0000 Subject: mesh proxy attributes from andrecastelo --- source/gameengine/Ketsji/KX_MeshProxy.cpp | 24 ++++++++++++++++++++++++ source/gameengine/Ketsji/KX_MeshProxy.h | 8 ++++++-- source/gameengine/PyDoc/KX_MeshProxy.py | 6 ++++++ 3 files changed, 36 insertions(+), 2 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index e7f562bda8e..0710d301c14 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -73,8 +73,11 @@ PyParentObject KX_MeshProxy::Parents[] = { }; PyMethodDef KX_MeshProxy::Methods[] = { +// Deprecated -----> {"getNumMaterials", (PyCFunction)KX_MeshProxy::sPyGetNumMaterials,METH_VARARGS}, {"getNumPolygons", (PyCFunction)KX_MeshProxy::sPyGetNumPolygons,METH_NOARGS}, +// <----- + {"getMaterialName", (PyCFunction)KX_MeshProxy::sPyGetMaterialName,METH_VARARGS}, {"getTextureName", (PyCFunction)KX_MeshProxy::sPyGetTextureName,METH_VARARGS}, {"getVertexArrayLength", (PyCFunction)KX_MeshProxy::sPyGetVertexArrayLength,METH_VARARGS}, @@ -88,6 +91,9 @@ KX_PYMETHODTABLE(KX_MeshProxy, reinstancePhysicsMesh), PyAttributeDef KX_MeshProxy::Attributes[] = { KX_PYATTRIBUTE_RO_FUNCTION("materials", KX_MeshProxy, pyattr_get_materials), + KX_PYATTRIBUTE_RO_FUNCTION("numPolygons", KX_MeshProxy, pyattr_get_materials), + KX_PYATTRIBUTE_RO_FUNCTION("numMaterials", KX_MeshProxy, pyattr_get_materials), + { NULL } //Sentinel }; @@ -102,6 +108,10 @@ PyObject* KX_MeshProxy::py_getattro(PyObject *attr) py_getattro_up(SCA_IObject); } +int KX_MeshProxy::py_setattro(PyObject *attr, PyObject* value) +{ + py_setattro_up(SCA_IObject); +} KX_MeshProxy::KX_MeshProxy(RAS_MeshObject* mesh) @@ -134,12 +144,14 @@ PyObject* KX_MeshProxy::PyGetNumMaterials(PyObject* self, PyObject* kwds) { int num = m_meshobj->NumMaterials(); + ShowDeprecationWarning("getNumMaterials()", "the numMaterials property"); return PyInt_FromLong(num); } PyObject* KX_MeshProxy::PyGetNumPolygons(PyObject* self) { int num = m_meshobj->NumPolygons(); + ShowDeprecationWarning("getNumPolygons()", "the numPolygons property"); return PyInt_FromLong(num); } @@ -296,3 +308,15 @@ PyObject* KX_MeshProxy::pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_ } return materials; } + +PyObject * KX_MeshProxy::pyattr_get_numMaterials(void * selfv, const KX_PYATTRIBUTE_DEF * attrdef) { + KX_MeshProxy * self = static_cast (selfv); + int num = self->m_meshobj->NumMaterials(); + return PyInt_FromLong(num); +} + +PyObject * KX_MeshProxy::pyattr_get_numPolygons(void * selfv, const KX_PYATTRIBUTE_DEF * attrdef) { + KX_MeshProxy * self = static_cast (selfv); + int num = self->m_meshobj->NumPolygons(); + return PyInt_FromLong(num); +} diff --git a/source/gameengine/Ketsji/KX_MeshProxy.h b/source/gameengine/Ketsji/KX_MeshProxy.h index 3b72099eebb..dfc498801a7 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.h +++ b/source/gameengine/Ketsji/KX_MeshProxy.h @@ -55,10 +55,12 @@ public: // stuff for python integration virtual PyObject* py_getattro(PyObject *attr); - KX_PYMETHOD(KX_MeshProxy,GetNumMaterials); + virtual int py_setattro(PyObject *attr, PyObject* value); + + KX_PYMETHOD(KX_MeshProxy,GetNumMaterials); // Deprecated KX_PYMETHOD(KX_MeshProxy,GetMaterialName); KX_PYMETHOD(KX_MeshProxy,GetTextureName); - KX_PYMETHOD_NOARGS(KX_MeshProxy,GetNumPolygons); + KX_PYMETHOD_NOARGS(KX_MeshProxy,GetNumPolygons); // Deprecated // both take materialid (int) KX_PYMETHOD(KX_MeshProxy,GetVertexArrayLength); @@ -67,6 +69,8 @@ public: KX_PYMETHOD_DOC(KX_MeshProxy, reinstancePhysicsMesh); static PyObject* pyattr_get_materials(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject * pyattr_get_numMaterials(void * self, const KX_PYATTRIBUTE_DEF * attrdef); + static PyObject * pyattr_get_numPolygons(void * self, const KX_PYATTRIBUTE_DEF * attrdef); }; #endif //__KX_MESHPROXY diff --git a/source/gameengine/PyDoc/KX_MeshProxy.py b/source/gameengine/PyDoc/KX_MeshProxy.py index c6855d3b0a5..e8839ac484c 100644 --- a/source/gameengine/PyDoc/KX_MeshProxy.py +++ b/source/gameengine/PyDoc/KX_MeshProxy.py @@ -47,6 +47,12 @@ class KX_MeshProxy: @ivar materials: @type materials: list of L{KX_BlenderMaterial} or L{KX_PolygonMaterial} types + + @ivar numPolygons: + @type numPolygons: integer + + @ivar numMaterials: + @type numMaterials: integer """ def getNumMaterials(): -- cgit v1.2.3 From 956d120098f4c9f6440266e6e95800d76c782827 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 13 Apr 2009 04:54:12 +0000 Subject: Bullet integration uninitialised values. Erwin, r16812 "Add Fh/Rot Fh to Bullet" - added this function ClosestRayResultCallbackNotMe(rayFromWorld,rayToWorld,body,parentBody) ...but parentBody was being ignored and the m_parent value wasn't being initialized. Run memset() on CcdConstructionInfo which had some unset members for CreateSphereController() and CreateConeController(). --- source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index cef2f2477b7..faf1ca42766 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -660,9 +660,10 @@ class ClosestRayResultCallbackNotMe : public btCollisionWorld::ClosestRayResultC public: ClosestRayResultCallbackNotMe(const btVector3& rayFromWorld,const btVector3& rayToWorld,btCollisionObject* owner,btCollisionObject* parent) :btCollisionWorld::ClosestRayResultCallback(rayFromWorld,rayToWorld), - m_owner(owner) + m_owner(owner), + m_parent(parent) { - + } virtual bool needsCollision(btBroadphaseProxy* proxy0) const @@ -710,7 +711,7 @@ void CcdPhysicsEnvironment::processFhSprings(double curTime,float timeStep) //btVector3 rayToWorld = rayFromWorld + body->getCenterOfMassTransform().getBasis() * rayDirLocal; //ray always points down the z axis in world space... btVector3 rayToWorld = rayFromWorld + rayDirLocal; - + ClosestRayResultCallbackNotMe resultCallback(rayFromWorld,rayToWorld,body,parentBody); m_dynamicsWorld->rayTest(rayFromWorld,rayToWorld,resultCallback); @@ -1558,8 +1559,8 @@ PHY_IPhysicsController* CcdPhysicsEnvironment::CreateSphereController(float radi { CcdConstructionInfo cinfo; - // memory leak! The shape is not deleted by Bullet and we cannot add it to the KX_Scene.m_shapes list - cinfo.m_collisionShape = new btSphereShape(radius); + memset(&cinfo, 0, sizeof(cinfo)); /* avoid uninitialized values */ + cinfo.m_collisionShape = new btSphereShape(radius); // memory leak! The shape is not deleted by Bullet and we cannot add it to the KX_Scene.m_shapes list cinfo.m_MotionState = 0; cinfo.m_physicsEnv = this; // declare this object as Dyamic rather then static!! @@ -2018,7 +2019,7 @@ int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl PHY_IPhysicsController* CcdPhysicsEnvironment::CreateConeController(float coneradius,float coneheight) { CcdConstructionInfo cinfo; - + memset(&cinfo, 0, sizeof(cinfo)); /* avoid uninitialized values */ // we don't need a CcdShapeConstructionInfo for this shape: // it is simple enough for the standard copy constructor (see CcdPhysicsController::GetReplica) cinfo.m_collisionShape = new btConeShape(coneradius,coneheight); -- 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 +- source/gameengine/Ketsji/KX_PythonInitTypes.h | 2 +- source/gameengine/PyDoc/GameTypes.py | 2 +- source/gameengine/PyDoc/SCA_NANDController.py | 2 +- source/gameengine/PyDoc/SCA_NORController.py | 2 +- source/gameengine/PyDoc/SCA_XNORController.py | 2 +- source/gameengine/PyDoc/SCA_XORController.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'source/gameengine') 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 ***** * diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.h b/source/gameengine/Ketsji/KX_PythonInitTypes.h index b30f0334b6e..6da79be9301 100644 --- a/source/gameengine/Ketsji/KX_PythonInitTypes.h +++ b/source/gameengine/Ketsji/KX_PythonInitTypes.h @@ -1,5 +1,5 @@ /** - * $Id: PyObjectPlus.h 19511 2009-04-03 02:16:56Z campbellbarton $ + * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** * diff --git a/source/gameengine/PyDoc/GameTypes.py b/source/gameengine/PyDoc/GameTypes.py index f39e4ed064d..2b07a18247c 100644 --- a/source/gameengine/PyDoc/GameTypes.py +++ b/source/gameengine/PyDoc/GameTypes.py @@ -1,4 +1,4 @@ -# $Id: GameLogic.py 19483 2009-03-31 21:03:15Z ben2610 $ +# $Id$ """ GameEngine Types ================ diff --git a/source/gameengine/PyDoc/SCA_NANDController.py b/source/gameengine/PyDoc/SCA_NANDController.py index 81e1dfd6d92..a864ff2981c 100644 --- a/source/gameengine/PyDoc/SCA_NANDController.py +++ b/source/gameengine/PyDoc/SCA_NANDController.py @@ -1,4 +1,4 @@ -# $Id: SCA_ANDController.py 15444 2008-07-05 17:05:05Z lukep $ +# $Id$ # Documentation for SCA_NANDController from SCA_IController import * diff --git a/source/gameengine/PyDoc/SCA_NORController.py b/source/gameengine/PyDoc/SCA_NORController.py index e3bdeefa63e..0bc0a71d7b1 100644 --- a/source/gameengine/PyDoc/SCA_NORController.py +++ b/source/gameengine/PyDoc/SCA_NORController.py @@ -1,4 +1,4 @@ -# $Id: SCA_ANDController.py 15444 2008-07-05 17:05:05Z lukep $ +# $Id$ # Documentation for SCA_NORController from SCA_IController import * diff --git a/source/gameengine/PyDoc/SCA_XNORController.py b/source/gameengine/PyDoc/SCA_XNORController.py index b1d9dddd9f2..5fb2561f35a 100644 --- a/source/gameengine/PyDoc/SCA_XNORController.py +++ b/source/gameengine/PyDoc/SCA_XNORController.py @@ -1,4 +1,4 @@ -# $Id: SCA_ANDController.py 15444 2008-07-05 17:05:05Z lukep $ +# $Id$ # Documentation for SCA_XNORController from SCA_IController import * diff --git a/source/gameengine/PyDoc/SCA_XORController.py b/source/gameengine/PyDoc/SCA_XORController.py index b8f2b5feef0..10e20fb0945 100644 --- a/source/gameengine/PyDoc/SCA_XORController.py +++ b/source/gameengine/PyDoc/SCA_XORController.py @@ -1,4 +1,4 @@ -# $Id: SCA_ANDController.py 15444 2008-07-05 17:05:05Z lukep $ +# $Id$ # Documentation for SCA_XORController from SCA_IController import * -- cgit v1.2.3 From 0b8661ab4da1a7cfbc756640649a2d07bb36cc64 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Mon, 13 Apr 2009 20:08:33 +0000 Subject: BGE: Occlusion culling and other performance improvements. Added occlusion culling capability in the BGE. More info: http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.49/Game_Engine#BGE_Scenegraph_improvement MSVC, scons, cmake, Makefile updated. Other minor performance improvements: - The rasterizer was computing the openGL model matrix of the objects too many times - DBVT view frustrum culling was not properly culling behind the near plane: Large objects behind the camera were sent to the GPU - Remove all references to mesh split/join feature as it is not yet functional --- .../Converter/BL_BlenderDataConversion.cpp | 20 +- .../Converter/KX_BlenderSceneConverter.cpp | 2 +- .../gameengine/Converter/KX_ConvertActuators.cpp | 3 +- source/gameengine/Ketsji/KX_GameObject.cpp | 51 +- source/gameengine/Ketsji/KX_GameObject.h | 35 +- source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 15 +- source/gameengine/Ketsji/KX_Scene.cpp | 16 +- source/gameengine/Ketsji/KX_Scene.h | 11 +- source/gameengine/Ketsji/KX_VisibilityActuator.cpp | 4 + source/gameengine/Ketsji/KX_VisibilityActuator.h | 2 + .../Physics/BlOde/OdePhysicsEnvironment.h | 2 +- source/gameengine/Physics/Bullet/CMakeLists.txt | 7 + .../Physics/Bullet/CcdPhysicsEnvironment.cpp | 553 ++++++++++++++++++++- .../Physics/Bullet/CcdPhysicsEnvironment.h | 2 +- source/gameengine/Physics/Bullet/Makefile | 7 + source/gameengine/Physics/Bullet/SConscript | 14 +- .../Physics/Dummy/DummyPhysicsEnvironment.h | 2 +- .../Physics/Sumo/SumoPhysicsEnvironment.h | 2 +- .../Physics/common/PHY_IPhysicsEnvironment.h | 4 +- source/gameengine/PyDoc/KX_GameObject.py | 10 + source/gameengine/PyDoc/KX_VisibilityActuator.py | 4 +- .../gameengine/Rasterizer/RAS_MaterialBucket.cpp | 6 +- source/gameengine/Rasterizer/RAS_MeshObject.cpp | 2 + source/gameengine/Rasterizer/RAS_Polygon.cpp | 11 + source/gameengine/Rasterizer/RAS_Polygon.h | 6 +- source/gameengine/VideoTexture/ImageRender.cpp | 2 +- 26 files changed, 735 insertions(+), 58 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 50a660e77c9..5de2c4a2fe7 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -843,6 +843,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* { bool visible = true; + bool twoside = false; RAS_IPolyMaterial* polymat = NULL; BL_Material *bl_mat = NULL; @@ -859,6 +860,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* visible = ((bl_mat->ras_mode & POLY_VIS)!=0); collider = ((bl_mat->ras_mode & COLLIDER)!=0); + twoside = ((bl_mat->mode & TF_TWOSIDE)!=0); /* vertex colors and uv's were stored in bl_mat temporarily */ bl_mat->GetConversionRGB(rgb); @@ -899,6 +901,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* mode = tface->mode; visible = !((mface->flag & ME_HIDE)||(tface->mode & TF_INVISIBLE)); + twoside = ((tface->mode & TF_TWOSIDE)!=0); uv0.setValue(tface->uv[0]); uv1.setValue(tface->uv[1]); @@ -999,6 +1002,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* poly->SetVisible(visible); poly->SetCollider(collider); + poly->SetTwoside(twoside); //poly->SetEdgeCode(mface->edcode); meshobj->AddVertex(poly,0,pt0,uv0,uv20,tan0,rgb0,no0,flat,mface->v1); @@ -1677,6 +1681,7 @@ static KX_GameObject *gameobject_from_blenderobject( bool ignoreActivityCulling = ((ob->gameflag2 & OB_NEVER_DO_ACTIVITY_CULLING)!=0); gameobj->SetIgnoreActivityCulling(ignoreActivityCulling); + gameobj->SetOccluder((ob->gameflag & OB_OCCLUDER) != 0, false); // two options exists for deform: shape keys and armature // only support relative shape key @@ -1894,12 +1899,14 @@ void BL_ConvertBlenderObjects(struct Main* maggie, if (blenderscene->world) { kxscene->SetActivityCulling( (blenderscene->world->mode & WO_ACTIVITY_CULLING) != 0); kxscene->SetActivityCullingRadius(blenderscene->world->activityBoxRadius); - kxscene->SetDbvtCameraCulling((blenderscene->world->mode & WO_DBVT_CAMERA_CULLING) != 0); + kxscene->SetDbvtCulling((blenderscene->world->mode & WO_DBVT_CULLING) != 0); } else { kxscene->SetActivityCulling(false); - kxscene->SetDbvtCameraCulling(false); + kxscene->SetDbvtCulling(false); } - + // no occlusion culling by default + kxscene->SetDbvtOcclusionRes(0); + int activeLayerBitInfo = blenderscene->lay; // templist to find Root Parents (object with no parents) @@ -2452,8 +2459,9 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } // create graphic controller for culling - if (kxscene->GetDbvtCameraCulling()) + if (kxscene->GetDbvtCulling()) { + bool occlusion = false; for (i=0; iGetCount();i++) { KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i); @@ -2464,8 +2472,12 @@ void BL_ConvertBlenderObjects(struct Main* maggie, // box[0] is the min, box[1] is the max bool isactive = objectlist->SearchValue(gameobj); BL_CreateGraphicObjectNew(gameobj,box[0],box[1],kxscene,isactive,physics_engine); + if (gameobj->GetOccluder()) + occlusion = true; } } + if (occlusion) + kxscene->SetDbvtOcclusionRes(blenderscene->world->occlusionRes); } //set ini linearVel and int angularVel //rcruiz diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index b0c676a410d..190f9dbb472 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -283,7 +283,7 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename, case WOPHY_BULLET: { physics_engine = UseBullet; - useDbvtCulling = (blenderscene->world->mode & WO_DBVT_CAMERA_CULLING) != 0; + useDbvtCulling = (blenderscene->world->mode & WO_DBVT_CULLING) != 0; break; } diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index f7635856ad9..eb2d0a1c4b1 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -1008,9 +1008,10 @@ void BL_ConvertActuators(char* maggiename, bVisibilityActuator *vis_act = (bVisibilityActuator *) bact->data; KX_VisibilityActuator * tmp_vis_act = NULL; bool v = ((vis_act->flag & ACT_VISIBILITY_INVISIBLE) != 0); + bool o = ((vis_act->flag & ACT_VISIBILITY_OCCLUSION) != 0); bool recursive = ((vis_act->flag & ACT_VISIBILITY_RECURSIVE) != 0); - tmp_vis_act = new KX_VisibilityActuator(gameobj, !v, recursive); + tmp_vis_act = new KX_VisibilityActuator(gameobj, !v, o, recursive); baseact = tmp_vis_act; } diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 817afedd205..16cf3d9ae32 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -92,6 +92,7 @@ KX_GameObject::KX_GameObject( m_bIsNegativeScaling(false), m_bVisible(true), m_bCulled(true), + m_bOccluder(false), m_pPhysicsController1(NULL), m_pGraphicController(NULL), m_pPhysicsEnvironment(NULL), @@ -146,7 +147,12 @@ KX_GameObject::~KX_GameObject() } } - +KX_GameObject* KX_GameObject::GetClientObject(KX_ClientObjectInfo* info) +{ + if (!info) + return NULL; + return info->m_gameobject; +} CValue* KX_GameObject:: Calc(VALUE_OPERATOR op, CValue *val) { @@ -435,7 +441,7 @@ static void UpdateBuckets_recursive(SG_Node* node) void KX_GameObject::UpdateBuckets( bool recursive ) { - double* fl = GetOpenGLMatrix(); + double* fl = GetOpenGLMatrixPtr()->getPointer(); for (size_t i=0;iUpdateBuckets(this, fl, m_bUseObjectColor, m_objectColor, m_bVisible, m_bCulled); @@ -597,23 +603,34 @@ KX_GameObject::SetVisible( setVisible_recursive(m_pSGNode, v); } -bool -KX_GameObject::GetCulled( - void - ) +static void setOccluder_recursive(SG_Node* node, bool v) { - return m_bCulled; + NodeList& children = node->GetSGChildren(); + + for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) + { + SG_Node* childnode = (*childit); + KX_GameObject *clientgameobj = static_cast( (*childit)->GetSGClientObject()); + if (clientgameobj != NULL) // This is a GameObject + clientgameobj->SetOccluder(v, false); + + // if the childobj is NULL then this may be an inverse parent link + // so a non recursive search should still look down this node. + setOccluder_recursive(childnode, v); + } } void -KX_GameObject::SetCulled( - bool c +KX_GameObject::SetOccluder( + bool v, + bool recursive ) { - m_bCulled = c; + m_bOccluder = v; + if (recursive) + setOccluder_recursive(m_pSGNode, v); } - void KX_GameObject::SetLayer( int l @@ -1036,6 +1053,7 @@ PyMethodDef KX_GameObject::Methods[] = { {"setCollisionMargin", (PyCFunction) KX_GameObject::sPySetCollisionMargin, METH_O}, {"setParent", (PyCFunction)KX_GameObject::sPySetParent,METH_O}, {"setVisible",(PyCFunction) KX_GameObject::sPySetVisible, METH_VARARGS}, + {"setOcclusion",(PyCFunction) KX_GameObject::sPySetOcclusion, METH_VARARGS}, {"removeParent", (PyCFunction)KX_GameObject::sPyRemoveParent,METH_NOARGS}, {"getChildren", (PyCFunction)KX_GameObject::sPyGetChildren,METH_NOARGS}, {"getChildrenRecursive", (PyCFunction)KX_GameObject::sPyGetChildrenRecursive,METH_NOARGS}, @@ -1069,6 +1087,7 @@ PyAttributeDef KX_GameObject::Attributes[] = { KX_PYATTRIBUTE_RO_FUNCTION("parent", KX_GameObject, pyattr_get_parent), KX_PYATTRIBUTE_RW_FUNCTION("mass", KX_GameObject, pyattr_get_mass, pyattr_set_mass), KX_PYATTRIBUTE_RW_FUNCTION("visible", KX_GameObject, pyattr_get_visible, pyattr_set_visible), + KX_PYATTRIBUTE_BOOL_RW ("occlusion", KX_GameObject, m_bOccluder), KX_PYATTRIBUTE_RW_FUNCTION("position", KX_GameObject, pyattr_get_position, pyattr_set_position), KX_PYATTRIBUTE_RO_FUNCTION("localInertia", KX_GameObject, pyattr_get_localInertia), KX_PYATTRIBUTE_RW_FUNCTION("orientation",KX_GameObject,pyattr_get_orientation,pyattr_set_orientation), @@ -1746,6 +1765,16 @@ PyObject* KX_GameObject::PySetVisible(PyObject* self, PyObject* args) } +PyObject* KX_GameObject::PySetOcclusion(PyObject* self, PyObject* args) +{ + int occlusion, recursive = 0; + if (!PyArg_ParseTuple(args,"i|i:setOcclusion",&occlusion, &recursive)) + return NULL; + + SetOccluder(occlusion ? true:false, recursive ? true:false); + Py_RETURN_NONE; +} + PyObject* KX_GameObject::PyGetVisible(PyObject* self) { ShowDeprecationWarning("getVisible()", "the visible property"); diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 172272150c0..c389d6cc776 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -87,6 +87,7 @@ protected: // culled = while rendering, depending on camera bool m_bVisible; bool m_bCulled; + bool m_bOccluder; KX_IPhysicsController* m_pPhysicsController1; PHY_IGraphicController* m_pGraphicController; @@ -103,6 +104,11 @@ protected: public: bool m_isDeformable; + /** + * Helper function for modules that can't include KX_ClientObjectInfo.h + */ + static KX_GameObject* GetClientObject(KX_ClientObjectInfo* info); + // Python attributes that wont convert into CValue // // there are 2 places attributes can be stored, in the CValue, @@ -118,11 +124,8 @@ public: // * if CValue conversion fails, use a PyObject in "m_attrlist" // * when assigning a value, first see if it can be a CValue, if it can remove the "m_attrlist" and set the CValue // - PyObject* m_attrlist; - - virtual void /* This function should be virtual - derived classed override it */ Relink( GEN_Map *map @@ -698,19 +701,36 @@ public: /** * Was this object culled? */ - bool + inline bool GetCulled( void - ); + ) { return m_bCulled; } /** * Set culled flag of this object */ - void + inline void SetCulled( bool c - ); + ) { m_bCulled = c; } + + /** + * Is this object an occluder? + */ + inline bool + GetOccluder( + void + ) { return m_bOccluder; } + /** + * Set occluder flag of this object + */ + void + SetOccluder( + bool v, + bool recursive + ); + /** * Change the layer of the object (when it is added in another layer * than the original layer) @@ -908,6 +928,7 @@ public: KX_PYMETHOD_O(KX_GameObject,SetOrientation); KX_PYMETHOD_NOARGS(KX_GameObject,GetVisible); KX_PYMETHOD_VARARGS(KX_GameObject,SetVisible); + KX_PYMETHOD_VARARGS(KX_GameObject,SetOcclusion); KX_PYMETHOD_NOARGS(KX_GameObject,GetState); KX_PYMETHOD_O(KX_GameObject,SetState); KX_PYMETHOD_VARARGS(KX_GameObject,AlignAxisToVect); diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index aeb80806f6c..83a2fa8a448 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -294,8 +294,14 @@ void KX_KetsjiEngine::RenderDome() if (!BeginFrame()) return; - int n_renders=m_dome->GetNumberRenders();// usually 4 or 6 KX_SceneList::iterator sceneit; + for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++) + { + // do this only once per scene + (*sceneit)->UpdateMeshTransformations(); + } + + int n_renders=m_dome->GetNumberRenders();// usually 4 or 6 for (int i=0;iClearBuffer(RAS_ICanvas::COLOR_BUFFER|RAS_ICanvas::DEPTH_BUFFER); for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++) @@ -311,7 +317,6 @@ void KX_KetsjiEngine::RenderDome() // shadow buffers if (i == 0){ RenderShadowBuffers(scene); - scene->UpdateMeshTransformations();//I need to run it somewherelse, otherwise Im overrunning it } // Avoid drawing the scene with the active camera twice when it's viewport is enabled if(cam && !cam->GetViewport()) @@ -812,6 +817,9 @@ void KX_KetsjiEngine::Render() // pass the scene's worldsettings to the rasterizer SetWorldSettings(scene->GetWorldInfo()); + // do this only once per scene + scene->UpdateMeshTransformations(); + // shadow buffers RenderShadowBuffers(scene); @@ -1140,7 +1148,6 @@ void KX_KetsjiEngine::RenderShadowBuffers(KX_Scene *scene) light->BindShadowBuffer(m_rasterizer, cam, camtrans); /* update scene */ - scene->UpdateMeshTransformations(); scene->CalculateVisibleMeshes(m_rasterizer, cam, light->GetShadowLayer()); /* render */ @@ -1245,7 +1252,7 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam) cam->GetCameraLocation(), cam->GetCameraOrientation()); cam->SetModelviewMatrix(viewmat); - //redundant, already done in + //redundant, already done in Render() //scene->UpdateMeshTransformations(); // The following actually reschedules all vertices to be diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 2f7c1b77794..98c129ebca5 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -138,6 +138,7 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, m_suspendeddelta = 0.0; m_dbvt_culling = false; + m_dbvt_occlusion_res = 0; m_activity_culling = false; m_suspend = false; m_isclearingZbuffer = true; @@ -1352,17 +1353,18 @@ void KX_Scene::CalculateVisibleMeshes(RAS_IRasterizer* rasty,KX_Camera* cam, int if (m_dbvt_culling) { // test culling through Bullet - PHY__Vector4 planes[5]; + PHY__Vector4 planes[6]; // get the clip planes MT_Vector4* cplanes = cam->GetNormalizedClipPlanes(); // and convert - planes[0].setValue(cplanes[0].getValue()); - planes[1].setValue(cplanes[1].getValue()); - planes[2].setValue(cplanes[2].getValue()); - planes[3].setValue(cplanes[3].getValue()); - planes[4].setValue(cplanes[5].getValue()); + planes[0].setValue(cplanes[4].getValue()); // near + planes[1].setValue(cplanes[5].getValue()); // far + planes[2].setValue(cplanes[0].getValue()); // left + planes[3].setValue(cplanes[1].getValue()); // right + planes[4].setValue(cplanes[2].getValue()); // top + planes[5].setValue(cplanes[3].getValue()); // bottom CullingInfo info(layer); - dbvt_culling = m_physicsEnvironment->cullingTest(PhysicsCullingCallback,&info,planes,5); + dbvt_culling = m_physicsEnvironment->cullingTest(PhysicsCullingCallback,&info,planes,5,m_dbvt_occlusion_res); } if (!dbvt_culling) { // the physics engine couldn't help us, do it the hard way diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 55e7afa4957..e1e89e253ed 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -264,6 +264,11 @@ protected: */ bool m_dbvt_culling; + /** + * Occlusion culling resolution + */ + int m_dbvt_occlusion_res; + /** * The framing settings used by this scene */ @@ -545,8 +550,10 @@ public: bool IsClearingZBuffer(); void EnableZBufferClearing(bool isclearingZbuffer); // use of DBVT tree for camera culling - void SetDbvtCameraCulling(bool b) { m_dbvt_culling = b; }; - bool GetDbvtCameraCulling() { return m_dbvt_culling; }; + void SetDbvtCulling(bool b) { m_dbvt_culling = b; }; + bool GetDbvtCulling() { return m_dbvt_culling; }; + void SetDbvtOcclusionRes(int i) { m_dbvt_occlusion_res = i; }; + int GetDbvtOcclusionRes() { return m_dbvt_occlusion_res; }; void SetSceneConverter(class KX_BlenderSceneConverter* sceneConverter); diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp index 1ee2169adc4..fceb0b5922c 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp @@ -38,11 +38,13 @@ KX_VisibilityActuator::KX_VisibilityActuator( SCA_IObject* gameobj, bool visible, + bool occlusion, bool recursive, PyTypeObject* T ) : SCA_IActuator(gameobj,T), m_visible(visible), + m_occlusion(occlusion), m_recursive(recursive) { // intentionally empty @@ -78,6 +80,7 @@ KX_VisibilityActuator::Update() KX_GameObject *obj = (KX_GameObject*) GetParent(); obj->SetVisible(m_visible, m_recursive); + obj->SetOccluder(m_occlusion, m_recursive); obj->UpdateBuckets(m_recursive); return false; @@ -130,6 +133,7 @@ KX_VisibilityActuator::Methods[] = { PyAttributeDef KX_VisibilityActuator::Attributes[] = { KX_PYATTRIBUTE_BOOL_RW("visibility", KX_VisibilityActuator, m_visible), + KX_PYATTRIBUTE_BOOL_RW("occlusion", KX_VisibilityActuator, m_occlusion), KX_PYATTRIBUTE_BOOL_RW("recursion", KX_VisibilityActuator, m_recursive), { NULL } //Sentinel }; diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.h b/source/gameengine/Ketsji/KX_VisibilityActuator.h index fca37500915..4269258f862 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.h +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.h @@ -39,6 +39,7 @@ class KX_VisibilityActuator : public SCA_IActuator /** Make visible? */ bool m_visible; + bool m_occlusion; bool m_recursive; public: @@ -46,6 +47,7 @@ class KX_VisibilityActuator : public SCA_IActuator KX_VisibilityActuator( SCA_IObject* gameobj, bool visible, + bool occlusion, bool recursive, PyTypeObject* T=&Type ); diff --git a/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h b/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h index e4aaef1803d..2e4709cf420 100644 --- a/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h +++ b/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h @@ -55,7 +55,7 @@ public: virtual void removeConstraint(void * constraintid); virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback,float fromX,float fromY,float fromZ, float toX,float toY,float toZ); - virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes) { return false; } + virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes, int occlusionRes) { return false; } //gamelogic callbacks diff --git a/source/gameengine/Physics/Bullet/CMakeLists.txt b/source/gameengine/Physics/Bullet/CMakeLists.txt index 6bab9858011..2cb2a540d97 100644 --- a/source/gameengine/Physics/Bullet/CMakeLists.txt +++ b/source/gameengine/Physics/Bullet/CMakeLists.txt @@ -30,11 +30,18 @@ SET(INC . ../common ../../../../extern/bullet2/src + ../../../../extern/glew/include ../../../../intern/moto/include ../../../kernel/gen_system ../../../../intern/string + ../../../intern/SoundSystem ../../Rasterizer + ../../Ketsji + ../../Expressions + ../../GameLogic + ../../SceneGraph ../../../../source/blender/makesdna + ${PYTHON_INC} ) BLENDERLIB(bf_bullet "${SRC}" "${INC}") diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index faf1ca42766..858416bae6a 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -33,6 +33,10 @@ subject to the following restrictions: #include "PHY_IMotionState.h" +#include "KX_GameObject.h" +#include "RAS_MeshObject.h" +#include "RAS_Polygon.h" +#include "RAS_TexVert.h" #define CCD_CONSTRAINT_DISABLE_LINKED_COLLISION 0x80 @@ -47,7 +51,9 @@ btRaycastVehicle::btVehicleTuning gTuning; #endif //NEW_BULLET_VEHICLE_SUPPORT #include "LinearMath/btAabbUtil2.h" - +#include "MT_Matrix4x4.h" +#include "MT_Vector3.h" +#include "GL/glew.h" #ifdef WIN32 void DrawRasterizerLine(const float* from,const float* to,int color); @@ -1189,17 +1195,492 @@ PHY_IPhysicsController* CcdPhysicsEnvironment::rayTest(PHY_IRayCastFilterCallbac return result.m_controller; } +// Handles occlusion culling. +// The implementation is based on the CDTestFramework +struct OcclusionBuffer +{ + struct WriteOCL + { + static inline bool Process(btScalar& q,btScalar v) { if(q + void CMmat4mul(btScalar* m, const T1* m1, const T2* m2) + { + m[ 0] = btScalar(m1[ 0]*m2[ 0]+m1[ 4]*m2[ 1]+m1[ 8]*m2[ 2]+m1[12]*m2[ 3]); + m[ 1] = btScalar(m1[ 1]*m2[ 0]+m1[ 5]*m2[ 1]+m1[ 9]*m2[ 2]+m1[13]*m2[ 3]); + m[ 2] = btScalar(m1[ 2]*m2[ 0]+m1[ 6]*m2[ 1]+m1[10]*m2[ 2]+m1[14]*m2[ 3]); + m[ 3] = btScalar(m1[ 3]*m2[ 0]+m1[ 7]*m2[ 1]+m1[11]*m2[ 2]+m1[15]*m2[ 3]); + + m[ 4] = btScalar(m1[ 0]*m2[ 4]+m1[ 4]*m2[ 5]+m1[ 8]*m2[ 6]+m1[12]*m2[ 7]); + m[ 5] = btScalar(m1[ 1]*m2[ 4]+m1[ 5]*m2[ 5]+m1[ 9]*m2[ 6]+m1[13]*m2[ 7]); + m[ 6] = btScalar(m1[ 2]*m2[ 4]+m1[ 6]*m2[ 5]+m1[10]*m2[ 6]+m1[14]*m2[ 7]); + m[ 7] = btScalar(m1[ 3]*m2[ 4]+m1[ 7]*m2[ 5]+m1[11]*m2[ 6]+m1[15]*m2[ 7]); + + m[ 8] = btScalar(m1[ 0]*m2[ 8]+m1[ 4]*m2[ 9]+m1[ 8]*m2[10]+m1[12]*m2[11]); + m[ 9] = btScalar(m1[ 1]*m2[ 8]+m1[ 5]*m2[ 9]+m1[ 9]*m2[10]+m1[13]*m2[11]); + m[10] = btScalar(m1[ 2]*m2[ 8]+m1[ 6]*m2[ 9]+m1[10]*m2[10]+m1[14]*m2[11]); + m[11] = btScalar(m1[ 3]*m2[ 8]+m1[ 7]*m2[ 9]+m1[11]*m2[10]+m1[15]*m2[11]); + + m[12] = btScalar(m1[ 0]*m2[12]+m1[ 4]*m2[13]+m1[ 8]*m2[14]+m1[12]*m2[15]); + m[13] = btScalar(m1[ 1]*m2[12]+m1[ 5]*m2[13]+m1[ 9]*m2[14]+m1[13]*m2[15]); + m[14] = btScalar(m1[ 2]*m2[12]+m1[ 6]*m2[13]+m1[10]*m2[14]+m1[14]*m2[15]); + m[15] = btScalar(m1[ 3]*m2[12]+m1[ 7]*m2[13]+m1[11]*m2[14]+m1[15]*m2[15]); + } + void setup(int size) + { + m_initialized=false; + m_occlusion=false; + // compute the size of the buffer + GLint v[4]; + GLdouble m[16],p[16]; + int maxsize; + double ratio; + glGetIntegerv(GL_VIEWPORT,v); + maxsize = (v[2] > v[3]) ? v[2] : v[3]; + assert(maxsize > 0); + ratio = 1.0/(2*maxsize); + // ensure even number + m_sizes[0] = 2*((int)(size*v[2]*ratio+0.5)); + m_sizes[1] = 2*((int)(size*v[3]*ratio+0.5)); + m_scales[0]=btScalar(m_sizes[0]/2); + m_scales[1]=btScalar(m_sizes[1]/2); + m_offsets[0]=m_scales[0]+0.5f; + m_offsets[1]=m_scales[1]+0.5f; + // prepare matrix + // at this time of the rendering, the modelview matrix is the + // world to camera transformation and the projection matrix is + // camera to clip transformation. combine both so that + glGetDoublev(GL_MODELVIEW_MATRIX,m); + glGetDoublev(GL_PROJECTION_MATRIX,p); + CMmat4mul(m_wtc,p,m); + } + void initialize() + { + size_t newsize = (m_sizes[0]*m_sizes[1])*sizeof(btScalar); + if (m_buffer) + { + // see if we can reuse + if (newsize > m_bufferSize) + { + free(m_buffer); + m_buffer = NULL; + m_bufferSize = 0; + } + } + if (!m_buffer) + { + m_buffer = (btScalar*)calloc(1, newsize); + m_bufferSize = newsize; + } else + { + // buffer exists already, just clears it + memset(m_buffer, 0, newsize); + } + // memory allocate must succeed + assert(m_buffer != NULL); + m_initialized = true; + m_occlusion = false; + } + void SetModelMatrix(double *fl) + { + CMmat4mul(m_mtc,m_wtc,fl); + if (!m_initialized) + initialize(); + } + + // transform a segment in world coordinate to clip coordinate + void transformW(const btVector3& x, btVector4& t) + { + t[0] = x[0]*m_wtc[0]+x[1]*m_wtc[4]+x[2]*m_wtc[8]+m_wtc[12]; + t[1] = x[0]*m_wtc[1]+x[1]*m_wtc[5]+x[2]*m_wtc[9]+m_wtc[13]; + t[2] = x[0]*m_wtc[2]+x[1]*m_wtc[6]+x[2]*m_wtc[10]+m_wtc[14]; + t[3] = x[0]*m_wtc[3]+x[1]*m_wtc[7]+x[2]*m_wtc[11]+m_wtc[15]; + } + void transformM(const float* x, btVector4& t) + { + t[0] = x[0]*m_mtc[0]+x[1]*m_mtc[4]+x[2]*m_mtc[8]+m_mtc[12]; + t[1] = x[0]*m_mtc[1]+x[1]*m_mtc[5]+x[2]*m_mtc[9]+m_mtc[13]; + t[2] = x[0]*m_mtc[2]+x[1]*m_mtc[6]+x[2]*m_mtc[10]+m_mtc[14]; + t[3] = x[0]*m_mtc[3]+x[1]*m_mtc[7]+x[2]*m_mtc[11]+m_mtc[15]; + } + // convert polygon to device coordinates + static bool project(btVector4* p,int n) + { + for(int i=0;i + static int clip(const btVector4* pi,btVector4* po) + { + btScalar s[2*NP]; + btVector4 pn[2*NP], *p; + int i, j, m, n, ni; + // deal with near clipping + for(i=0, m=0;i0)&&(t<1)) + { + pn[n][0] = a[0]+(b[0]-a[0])*t; + pn[n][1] = a[1]+(b[1]-a[1])*t; + pn[n][2] = a[2]+(b[2]-a[2])*t; + pn[n][3] = a[3]+(b[3]-a[3])*t; + ++n; + } + if(s[j]>0) pn[n++]=b; + } + // ready to test far clipping, start from the modified polygon + pi = pn; + ni = n; + } else + { + // no clipping on the near plane, keep same vector + ni = NP; + } + // now deal with far clipping + for(i=0, m=0;i0) m+=1<0)&&(t<1)) + { + po[n][0] = a[0]+(b[0]-a[0])*t; + po[n][1] = a[1]+(b[1]-a[1])*t; + po[n][2] = a[2]+(b[2]-a[2])*t; + po[n][3] = a[3]+(b[3]-a[3])*t; + ++n; + } + if(s[j]<0) po[n++]=b; + } + return(n); + } + for(int i=0;i + inline bool draw( const btVector4& a, + const btVector4& b, + const btVector4& c, + const float face, + const btScalar minarea) + { + const btScalar a2=cross(b-a,c-a)[2]; + if((face*a2)<0.f || btFabs(a2) must + // change the order of b and c otherwise the algorithm doesn't work + ib=2; + ic=1; + } + x[ib]=(int)(b.x()*m_scales[0]+m_offsets[0]); + x[ic]=(int)(c.x()*m_scales[0]+m_offsets[0]); + y[ib]=(int)(b.y()*m_scales[1]+m_offsets[1]); + y[ic]=(int)(c.y()*m_scales[1]+m_offsets[1]); + z[ib]=b.z(); + z[ic]=c.z(); + const int mix=btMax(0,btMin(x[0],btMin(x[1],x[2]))); + const int mxx=btMin(m_sizes[0],1+btMax(x[0],btMax(x[1],x[2]))); + const int miy=btMax(0,btMin(y[0],btMin(y[1],y[2]))); + const int mxy=btMin(m_sizes[1],1+btMax(y[0],btMax(y[1],y[2]))); + const int width=mxx-mix; + const int height=mxy-miy; + if ((width*height) <= 1) + { + // degenerated in at most one single pixel + btScalar* scan=&m_buffer[miy*m_sizes[0]+mix]; + // use for loop to detect the case where width or height == 0 + for(int iy=miy;iy y[1]) { ytmp=y[1];y[1]=y[0];y[0]=ytmp;ztmp=z[1];z[1]=z[0];z[0]=ztmp; } + if (y[0] > y[2]) { ytmp=y[2];y[2]=y[0];y[0]=ytmp;ztmp=z[2];z[2]=z[0];z[0]=ztmp; } + if (y[1] > y[2]) { ytmp=y[2];y[2]=y[1];y[1]=ytmp;ztmp=z[2];z[2]=z[1];z[1]=ztmp; } + int dy[]={ y[0]-y[1], + y[1]-y[2], + y[2]-y[0]}; + btScalar dzy[3]; + dzy[0] = (dy[0]) ? (z[0]-z[1])/dy[0] : btScalar(0.f); + dzy[1] = (dy[1]) ? (z[1]-z[2])/dy[1] : btScalar(0.f); + dzy[2] = (dy[2]) ? (z[2]-z[0])/dy[2] : btScalar(0.f); + btScalar v[3] = { dzy[0]*(miy-y[0])+z[0], + dzy[1]*(miy-y[1])+z[1], + dzy[2]*(miy-y[2])+z[2] }; + dy[0] = y[1]-y[0]; + dy[1] = y[0]-y[1]; + dy[2] = y[2]-y[0]; + btScalar* scan=&m_buffer[miy*m_sizes[0]+mix]; + for(int iy=miy;iy= 0 && POLICY::Process(*scan,v[0])) + return(true); + if(dy[1] >= 0 && POLICY::Process(*scan,v[1])) + return(true); + if(dy[2] >= 0 && POLICY::Process(*scan,v[2])) + return(true); + scan+=m_sizes[0]; + v[0] += dzy[0]; v[1] += dzy[1]; v[2] += dzy[2]; + dy[0]--; dy[1]++, dy[2]--; + } + } else if (height == 1) + { + // Degenerated in at least 2 horizontal lines + // The algorithm below doesn't work when face has a single pixel width + // We cannot use general formulas because the plane is degenerated. + // We have to interpolate along the 3 edges that overlaps and process each pixel. + int xtmp; + btScalar ztmp; + if (x[0] > x[1]) { xtmp=x[1];x[1]=x[0];x[0]=xtmp;ztmp=z[1];z[1]=z[0];z[0]=ztmp; } + if (x[0] > x[2]) { xtmp=x[2];x[2]=x[0];x[0]=xtmp;ztmp=z[2];z[2]=z[0];z[0]=ztmp; } + if (x[1] > x[2]) { xtmp=x[2];x[2]=x[1];x[1]=xtmp;ztmp=z[2];z[2]=z[1];z[1]=ztmp; } + int dx[]={ x[0]-x[1], + x[1]-x[2], + x[2]-x[0]}; + btScalar dzx[3]; + dzx[0] = (dx[0]) ? (z[0]-z[1])/dx[0] : btScalar(0.f); + dzx[1] = (dx[1]) ? (z[1]-z[2])/dx[1] : btScalar(0.f); + dzx[2] = (dx[2]) ? (z[2]-z[0])/dx[2] : btScalar(0.f); + btScalar v[3] = { dzx[0]*(mix-x[0])+z[0], + dzx[1]*(mix-x[1])+z[1], + dzx[2]*(mix-x[2])+z[2] }; + dx[0] = x[1]-x[0]; + dx[1] = x[0]-x[1]; + dx[2] = x[2]-x[0]; + btScalar* scan=&m_buffer[miy*m_sizes[0]+mix]; + for(int ix=mix;ix= 0 && POLICY::Process(*scan,v[0])) + return(true); + if(dx[1] >= 0 && POLICY::Process(*scan,v[1])) + return(true); + if(dx[2] >= 0 && POLICY::Process(*scan,v[2])) + return(true); + scan++; + v[0] += dzx[0]; v[1] += dzx[1]; v[2] += dzx[2]; + dx[0]--; dx[1]++, dx[2]--; + } + } else + { + // general case + const int dx[]={ y[0]-y[1], + y[1]-y[2], + y[2]-y[0]}; + const int dy[]={ x[1]-x[0]-dx[0]*width, + x[2]-x[1]-dx[1]*width, + x[0]-x[2]-dx[2]*width}; + const int a=x[2]*y[0]+x[0]*y[1]-x[2]*y[1]-x[0]*y[2]+x[1]*y[2]-x[1]*y[0]; + const btScalar ia=1/(btScalar)a; + const btScalar dzx=ia*(y[2]*(z[1]-z[0])+y[1]*(z[0]-z[2])+y[0]*(z[2]-z[1])); + const btScalar dzy=ia*(x[2]*(z[0]-z[1])+x[0]*(z[1]-z[2])+x[1]*(z[2]-z[0]))-(dzx*width); + int c[]={ miy*x[1]+mix*y[0]-x[1]*y[0]-mix*y[1]+x[0]*y[1]-miy*x[0], + miy*x[2]+mix*y[1]-x[2]*y[1]-mix*y[2]+x[1]*y[2]-miy*x[1], + miy*x[0]+mix*y[2]-x[0]*y[2]-mix*y[0]+x[2]*y[0]-miy*x[2]}; + btScalar v=ia*((z[2]*c[0])+(z[0]*c[1])+(z[1]*c[2])); + btScalar* scan=&m_buffer[miy*m_sizes[0]]; + for(int iy=miy;iy=0)&&(c[1]>=0)&&(c[2]>=0)) + { + if(POLICY::Process(scan[ix],v)) + return(true); + } + c[0]+=dx[0];c[1]+=dx[1];c[2]+=dx[2];v+=dzx; + } + c[0]+=dy[0];c[1]+=dy[1];c[2]+=dy[2];v+=dzy; + scan+=m_sizes[0]; + } + } + return(false); + } + // clip than write or check a polygon + template + inline bool clipDraw( const btVector4* p, + const float face, + btScalar minarea) + { + btVector4 o[NP*2]; + int n=clip(p,o); + bool earlyexit=false; + if (n) + { + project(o,n); + for(int i=2;i(o[0],o[i-1],o[i],face,minarea); + } + } + return(earlyexit); + } + // add a triangle (in model coordinate) + // face = 0.f if face is double side, + // = 1.f if face is single sided and scale is positive + // = -1.f if face is single sided and scale is negative + void appendOccluderM(const float* a, + const float* b, + const float* c, + const float face) + { + btVector4 p[3]; + transformM(a,p[0]); + transformM(b,p[1]); + transformM(c,p[2]); + clipDraw<3,WriteOCL>(p,face,btScalar(0.f)); + } + // add a quad (in model coordinate) + void appendOccluderM(const float* a, + const float* b, + const float* c, + const float* d, + const float face) + { + btVector4 p[4]; + transformM(a,p[0]); + transformM(b,p[1]); + transformM(c,p[2]); + transformM(d,p[3]); + clipDraw<4,WriteOCL>(p,face,btScalar(0.f)); + } + // query occluder for a box (c=center, e=extend) in world coordinate + inline bool queryOccluderW( const btVector3& c, + const btVector3& e) + { + if (!m_occlusion) + // no occlusion yet, no need to check + return true; + btVector4 x[8]; + transformW(btVector3(c[0]-e[0],c[1]-e[1],c[2]-e[2]),x[0]); + transformW(btVector3(c[0]+e[0],c[1]-e[1],c[2]-e[2]),x[1]); + transformW(btVector3(c[0]+e[0],c[1]+e[1],c[2]-e[2]),x[2]); + transformW(btVector3(c[0]-e[0],c[1]+e[1],c[2]-e[2]),x[3]); + transformW(btVector3(c[0]-e[0],c[1]-e[1],c[2]+e[2]),x[4]); + transformW(btVector3(c[0]+e[0],c[1]-e[1],c[2]+e[2]),x[5]); + transformW(btVector3(c[0]+e[0],c[1]+e[1],c[2]+e[2]),x[6]); + transformW(btVector3(c[0]-e[0],c[1]+e[1],c[2]+e[2]),x[7]); + for(int i=0;i<8;++i) + { + // the box is clipped, it's probably a large box, don't waste our time to check + if((x[i][2]+x[i][3])<=0) return(true); + } + static const int d[]={ 1,0,3,2, + 4,5,6,7, + 4,7,3,0, + 6,5,1,2, + 7,6,2,3, + 5,4,0,1}; + for(int i=0;i<(sizeof(d)/sizeof(d[0]));) + { + const btVector4 p[]={ x[d[i++]], + x[d[i++]], + x[d[i++]], + x[d[i++]]}; + if(clipDraw<4,QueryOCL>(p,1.f,0.f)) + return(true); + } + return(false); + } +}; + + struct DbvtCullingCallback : btDbvt::ICollide { PHY_CullingCallback m_clientCallback; void* m_userData; + OcclusionBuffer *m_ocb; DbvtCullingCallback(PHY_CullingCallback clientCallback, void* userData) { m_clientCallback = clientCallback; m_userData = userData; + m_ocb = NULL; + } + bool Descent(const btDbvtNode* node) + { + return(m_ocb->queryOccluderW(node->volume.Center(),node->volume.Extents())); } - void Process(const btDbvtNode* node,btScalar depth) { Process(node); @@ -1210,31 +1691,83 @@ struct DbvtCullingCallback : btDbvt::ICollide // the client object is a graphic controller CcdGraphicController* ctrl = static_cast(proxy->m_clientObject); KX_ClientObjectInfo* info = (KX_ClientObjectInfo*)ctrl->getNewClientInfo(); + if (m_ocb) + { + // means we are doing occlusion culling. Check if this object is an occluders + KX_GameObject* gameobj = KX_GameObject::GetClientObject(info); + if (gameobj && gameobj->GetOccluder()) + { + double* fl = gameobj->GetOpenGLMatrixPtr()->getPointer(); + // this will create the occlusion buffer if not already done + // and compute the transformation from model local space to clip space + m_ocb->SetModelMatrix(fl); + float face = (gameobj->IsNegativeScaling()) ? -1.0f : 1.0f; + // walk through the meshes and for each add to buffer + for (int i=0; iGetMeshCount(); i++) + { + RAS_MeshObject* meshobj = gameobj->GetMesh(i); + const float *v1, *v2, *v3, *v4; + + int polycount = meshobj->NumPolygons(); + for (int j=0; jGetPolygon(j); + switch (poly->VertexCount()) + { + case 3: + v1 = poly->GetVertex(0)->getXYZ(); + v2 = poly->GetVertex(1)->getXYZ(); + v3 = poly->GetVertex(2)->getXYZ(); + m_ocb->appendOccluderM(v1,v2,v3,((poly->IsTwoside())?0.f:face)); + break; + case 4: + v1 = poly->GetVertex(0)->getXYZ(); + v2 = poly->GetVertex(1)->getXYZ(); + v3 = poly->GetVertex(2)->getXYZ(); + v4 = poly->GetVertex(3)->getXYZ(); + m_ocb->appendOccluderM(v1,v2,v3,v4,((poly->IsTwoside())?0.f:face)); + break; + } + } + } + } + } if (info) (*m_clientCallback)(info, m_userData); } }; -bool CcdPhysicsEnvironment::cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4 *planes, int nplanes) +static OcclusionBuffer gOcb; +bool CcdPhysicsEnvironment::cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4 *planes, int nplanes, int occlusionRes) { if (!m_cullingTree) return false; DbvtCullingCallback dispatcher(callback, userData); - btVector3 planes_n[5]; - btScalar planes_o[5]; - if (nplanes > 5) - nplanes = 5; + btVector3 planes_n[6]; + btScalar planes_o[6]; + if (nplanes > 6) + nplanes = 6; for (int i=0; im_sets[1].m_root,planes_n,planes_o,nplanes,dispatcher); - btDbvt::collideKDOP(m_cullingTree->m_sets[0].m_root,planes_n,planes_o,nplanes,dispatcher); + // if occlusionRes != 0 => occlusion culling + if (occlusionRes) + { + gOcb.setup(occlusionRes); + dispatcher.m_ocb = &gOcb; + // occlusion culling, the direction of the view is taken from the first plan which MUST be the near plane + btDbvt::collideOCL(m_cullingTree->m_sets[1].m_root,planes_n,planes_o,planes_n[0],nplanes,dispatcher); + btDbvt::collideOCL(m_cullingTree->m_sets[0].m_root,planes_n,planes_o,planes_n[0],nplanes,dispatcher); + }else + { + btDbvt::collideKDOP(m_cullingTree->m_sets[1].m_root,planes_n,planes_o,nplanes,dispatcher); + btDbvt::collideKDOP(m_cullingTree->m_sets[0].m_root,planes_n,planes_o,nplanes,dispatcher); + } return true; } - int CcdPhysicsEnvironment::getNumContactPoints() { return 0; diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h index ddbcbe6b4d6..f861621ae37 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h @@ -172,7 +172,7 @@ protected: btTypedConstraint* getConstraintById(int constraintId); virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ); - virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes); + virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes, int occlusionRes); //Methods for gamelogic collision/physics callbacks diff --git a/source/gameengine/Physics/Bullet/Makefile b/source/gameengine/Physics/Bullet/Makefile index bf3573138f7..48e537bb6a3 100644 --- a/source/gameengine/Physics/Bullet/Makefile +++ b/source/gameengine/Physics/Bullet/Makefile @@ -39,9 +39,16 @@ CPPFLAGS += -I$(NAN_BULLET2)/include CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include CPPFLAGS += -I$(NAN_STRING)/include CPPFLAGS += -I$(NAN_MOTO)/include +CPPFLAGS += -I$(NAN_GLEW)/include +CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION) +CPPFLAGS += -I$(NAN_SOUNDSYSTEM)/include CPPFLAGS += -I../../../kernel/gen_system CPPFLAGS += -I../../Physics/common CPPFLAGS += -I../../Physics/Dummy CPPFLAGS += -I../../Rasterizer +CPPFLAGS += -I../../Ketsji +CPPFLAGS += -I../../Expressions +CPPFLAGS += -I../../GameLogic +CPPFLAGS += -I../../SceneGraph CPPFLAGS += -I../../../../source/blender/makesdna diff --git a/source/gameengine/Physics/Bullet/SConscript b/source/gameengine/Physics/Bullet/SConscript index f3b6549089d..115ab8bf730 100644 --- a/source/gameengine/Physics/Bullet/SConscript +++ b/source/gameengine/Physics/Bullet/SConscript @@ -3,9 +3,21 @@ Import ('env') sources = 'CcdPhysicsEnvironment.cpp CcdPhysicsController.cpp CcdGraphicController.cpp' -incs = '. ../common #source/kernel/gen_system #intern/string #intern/moto/include #source/gameengine/Rasterizer #source/blender/makesdna' +incs = '. ../common' +incs += ' #source/kernel/gen_system' +incs += ' #intern/string' +incs += ' #intern/moto/include' +incs += ' #extern/glew/include' +incs += ' #source/gameengine/Rasterizer' +incs += ' #source/gameengine/Ketsji' +incs += ' #source/gameengine/Expressions' +incs += ' #source/gameengine/GameLogic' +incs += ' #source/gameengine/SceneGraph' +incs += ' #source/blender/makesdna' +incs += ' #intern/SoundSystem' incs += ' ' + env['BF_BULLET_INC'] +incs += ' ' + env['BF_PYTHON_INC'] cxxflags = [] if env['OURPLATFORM']=='win32-vc': diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h index fae1844d505..4e15e6ec130 100644 --- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h +++ b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h @@ -70,7 +70,7 @@ public: } virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ); - virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes) { return false; } + virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4* planes, int nplanes, int occlusionRes) { return false; } //gamelogic callbacks diff --git a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h index 9942a367451..418a361a065 100644 --- a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h +++ b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h @@ -76,7 +76,7 @@ public: } virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback,float fromX,float fromY,float fromZ, float toX,float toY,float toZ); - virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4 *planes, int nplanes) { return false; } + virtual bool cullingTest(PHY_CullingCallback callback, void* userData, PHY__Vector4 *planes, int nplanes, int occlusionRes) { return false; } //gamelogic callbacks diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h index 5edafe6b51e..9a4500c3214 100644 --- a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h +++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h @@ -143,7 +143,9 @@ class PHY_IPhysicsEnvironment virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ)=0; //culling based on physical broad phase - virtual bool cullingTest(PHY_CullingCallback callback, void *userData, PHY__Vector4* planeNormals, int planeNumber) = 0; + // the plane number must be set as follow: near, far, left, right, top, botton + // the near plane must be the first one and must always be present, it is used to get the direction of the view + virtual bool cullingTest(PHY_CullingCallback callback, void *userData, PHY__Vector4* planeNormals, int planeNumber, int occlusionRes) = 0; //Methods for gamelogic collision/physics callbacks //todo: diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index fb1e099e575..fa4641c3e2f 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -25,6 +25,8 @@ class KX_GameObject: # (SCA_IObject) @ivar visible: visibility flag. - note: Game logic will still run for invisible objects. @type visible: boolean + @ivar occlusion: occlusion capability flag. + @type occlusion: boolean @ivar position: The object's position. @type position: list [x, y, z] @ivar orientation: The object's orientation. 3x3 Matrix. You can also write a Quaternion or Euler vector. @@ -76,6 +78,14 @@ class KX_GameObject: # (SCA_IObject) @type recursive: boolean @param recursive: optional argument to set all childrens visibility flag too. """ + def setOcclusion(occlusion, recursive): + """ + Sets the game object's occlusion capability. + + @type visible: boolean + @type recursive: boolean + @param recursive: optional argument to set all childrens occlusion flag too. + """ def getState(): """ Gets the game object's state bitmask. (B{deprecated}) diff --git a/source/gameengine/PyDoc/KX_VisibilityActuator.py b/source/gameengine/PyDoc/KX_VisibilityActuator.py index aca8d1ce243..36f25b2423c 100644 --- a/source/gameengine/PyDoc/KX_VisibilityActuator.py +++ b/source/gameengine/PyDoc/KX_VisibilityActuator.py @@ -7,7 +7,9 @@ class KX_VisibilityActuator(SCA_IActuator): Visibility Actuator. @ivar visibility: whether the actuator makes its parent object visible or invisible @type visibility: boolean - @ivar recursion: whether the visibility/invisibility should be propagated to all children of the object + @ivar occlusion: whether the actuator makes its parent object an occluder or not + @type occlusion: boolean + @ivar recursion: whether the visibility/occlusion should be propagated to all children of the object @type recursion: boolean """ def set(visible): diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp index 69f73c2ee25..5ddcdd310b0 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp @@ -62,10 +62,12 @@ RAS_MeshSlot::~RAS_MeshSlot() { vector::iterator it; +#ifdef USE_SPLIT Split(true); while(m_joinedSlots.size()) m_joinedSlots.front()->Split(true); +#endif for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) { (*it)->m_users--; @@ -428,11 +430,11 @@ bool RAS_MeshSlot::IsCulled() return true; if(!m_bCulled) return false; - +#ifdef USE_SPLIT for(it=m_joinedSlots.begin(); it!=m_joinedSlots.end(); it++) if(!(*it)->m_bCulled) return false; - +#endif return true; } diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.cpp b/source/gameengine/Rasterizer/RAS_MeshObject.cpp index a907994bf57..162f9a81335 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.cpp +++ b/source/gameengine/Rasterizer/RAS_MeshObject.cpp @@ -406,7 +406,9 @@ void RAS_MeshObject::UpdateBuckets(void* clientobj, ms->m_bCulled = culled || !visible; /* split if necessary */ +#ifdef USE_SPLIT ms->Split(); +#endif } } diff --git a/source/gameengine/Rasterizer/RAS_Polygon.cpp b/source/gameengine/Rasterizer/RAS_Polygon.cpp index 66b14bb60b0..eacc1285166 100644 --- a/source/gameengine/Rasterizer/RAS_Polygon.cpp +++ b/source/gameengine/Rasterizer/RAS_Polygon.cpp @@ -97,6 +97,17 @@ void RAS_Polygon::SetCollider(bool visible) else m_polyflags &= ~COLLIDER; } +bool RAS_Polygon::IsTwoside() +{ + return (m_polyflags & TWOSIDE) != 0; +} + +void RAS_Polygon::SetTwoside(bool twoside) +{ + if(twoside) m_polyflags |= TWOSIDE; + else m_polyflags &= ~TWOSIDE; +} + RAS_MaterialBucket* RAS_Polygon::GetMaterial() { return m_bucket; diff --git a/source/gameengine/Rasterizer/RAS_Polygon.h b/source/gameengine/Rasterizer/RAS_Polygon.h index 224a7e0eed2..41eaa6bdd4a 100644 --- a/source/gameengine/Rasterizer/RAS_Polygon.h +++ b/source/gameengine/Rasterizer/RAS_Polygon.h @@ -56,7 +56,8 @@ class RAS_Polygon public: enum { VISIBLE = 1, - COLLIDER = 2 + COLLIDER = 2, + TWOSIDE = 4 }; RAS_Polygon(RAS_MaterialBucket* bucket, RAS_DisplayArray* darray, int numvert); @@ -79,6 +80,9 @@ public: bool IsCollider(); void SetCollider(bool collider); + bool IsTwoside(); + void SetTwoside(bool twoside); + RAS_MaterialBucket* GetMaterial(); RAS_DisplayArray* GetDisplayArray(); }; diff --git a/source/gameengine/VideoTexture/ImageRender.cpp b/source/gameengine/VideoTexture/ImageRender.cpp index 58697ed3cc7..6ef62f64d3f 100644 --- a/source/gameengine/VideoTexture/ImageRender.cpp +++ b/source/gameengine/VideoTexture/ImageRender.cpp @@ -249,7 +249,7 @@ void ImageRender::Render() // restore the stereo mode now that the matrix is computed m_rasterizer->SetStereoMode(stereomode); - // do not update the mesh, we don't want to do it more than once per frame + // do not update the mesh transform, we don't want to do it more than once per frame //m_scene->UpdateMeshTransformations(); m_scene->CalculateVisibleMeshes(m_rasterizer,m_camera); -- cgit v1.2.3 From 1bc31fc7f901334f0ed20317985b2a84d51714ca Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 14 Apr 2009 03:08:09 +0000 Subject: BGE Bugfix [#17678] "Mouse over" sensor broken when using viewports Loop over all the scenes camera viewports and check the mouse is inside the viewport before casting a ray. --- source/gameengine/Ketsji/KX_MouseFocusSensor.cpp | 194 ++++++++++++----------- 1 file changed, 104 insertions(+), 90 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index 4afc6d6f1b8..2cb74ba65ab 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -150,11 +150,11 @@ bool KX_MouseFocusSensor::RayHit(KX_ClientObjectInfo* client_info, KX_RayCast* r -bool KX_MouseFocusSensor::ParentObjectHasFocus(void) +bool KX_MouseFocusSensor::ParentObjectHasFocus() { m_hitObject = 0; - 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); /* All screen handling in the gameengine is done by GL, * specifically the model/view and projection parts. The viewport @@ -188,6 +188,11 @@ bool KX_MouseFocusSensor::ParentObjectHasFocus(void) * * */ + MT_Vector4 frompoint; + MT_Vector4 topoint; + + bool result = false; + /* Because we don't want to worry about resize events, camera * changes and all that crap, we just determine this over and * over. Stop whining. We have lots of other calculations to do @@ -195,96 +200,105 @@ bool KX_MouseFocusSensor::ParentObjectHasFocus(void) * canvas, the test is irrelevant. The 1.0 makes sure the * calculations don't bomb. Maybe we should explicitly guard for * division by 0.0...*/ - - KX_Camera* cam = m_kxscene->GetActiveCamera(); - - /* get the scenes current viewport. we recompute it because there - * may be multiple cameras and m_kxscene->GetSceneViewport() only - * has the one that was last drawn */ - - RAS_Rect area, viewport; - m_kxengine->GetSceneViewport(m_kxscene, cam, area, viewport); - - float height = float(viewport.m_y2 - viewport.m_y1 + 1); - float width = float(viewport.m_x2 - viewport.m_x1 + 1); - - float x_lb = float(viewport.m_x1); - float y_lb = float(viewport.m_y1); - - /* There's some strangeness I don't fully get here... These values - * _should_ be wrong! */ - - - /* old: */ - float nearclip = 0.0; - float farclip = 1.0; - - /* build the from and to point in normalized device coordinates - * Looks like normailized device coordinates are [-1,1] in x [-1,1] in y - * [0,-1] in z - * - * The actual z coordinates used don't have to be exact just infront and - * behind of the near and far clip planes. - */ - MT_Vector4 frompoint = MT_Vector4( - (2 * (m_x-x_lb) / width) - 1.0, - 1.0 - (2 * (m_y - y_lb) / height), - nearclip, - 1.0 - ); - MT_Vector4 topoint = MT_Vector4( - (2 * (m_x-x_lb) / width) - 1.0, - 1.0 - (2 * (m_y-y_lb) / height), - farclip, - 1.0 - ); - - /* camera to world */ - MT_Transform wcs_camcs_tranform = cam->GetWorldToCamera(); - if (!cam->GetCameraData()->m_perspective) - wcs_camcs_tranform.getOrigin()[2] *= 100.0; - MT_Transform cams_wcs_transform; - cams_wcs_transform.invert(wcs_camcs_tranform); - - MT_Matrix4x4 camcs_wcs_matrix = MT_Matrix4x4(cams_wcs_transform); - - /* badly defined, the first time round.... I wonder why... I might - * want to guard against floating point errors here.*/ - MT_Matrix4x4 clip_camcs_matrix = MT_Matrix4x4(cam->GetProjectionMatrix()); - clip_camcs_matrix.invert(); - - /* shoot-points: clip to cam to wcs . win to clip was already done.*/ - frompoint = clip_camcs_matrix * frompoint; - topoint = clip_camcs_matrix * topoint; - frompoint = camcs_wcs_matrix * frompoint; - topoint = camcs_wcs_matrix * topoint; + list* cameras = m_kxscene->GetCameras(); - /* from hom wcs to 3d wcs: */ - MT_Point3 frompoint3 = MT_Point3(frompoint[0]/frompoint[3], - frompoint[1]/frompoint[3], - frompoint[2]/frompoint[3]); - MT_Point3 topoint3 = MT_Point3(topoint[0]/topoint[3], - topoint[1]/topoint[3], - topoint[2]/topoint[3]); - m_prevTargetPoint = topoint3; - m_prevSourcePoint = frompoint3; - - /* 2. Get the object from PhysicsEnvironment */ - /* Shoot! Beware that the first argument here is an - * ignore-object. We don't ignore anything... */ - - KX_IPhysicsController* physics_controller = cam->GetPhysicsController(); - PHY_IPhysicsEnvironment* physics_environment = m_kxscene->GetPhysicsEnvironment(); - - bool result = false; - - KX_RayCast::Callback callback(this,physics_controller); - KX_RayCast::RayTest(physics_environment, frompoint3, topoint3, callback); + // Draw the scene once for each camera with an enabled viewport + list::iterator it = cameras->begin(); + while(it != cameras->end()) + { + if((*it)->GetViewport()) + { + KX_Camera* cam= (*it); + + /* get the scenes current viewport. we recompute it because there + * may be multiple cameras and m_kxscene->GetSceneViewport() only + * has the one that was last drawn */ + + RAS_Rect area, viewport; + m_kxengine->GetSceneViewport(m_kxscene, cam, area, viewport); + + /* Check if the mouse is in the viewport */ + if ( m_x < viewport.m_x2 && // less then right + m_x > viewport.m_x1 && // more then then left + m_y < viewport.m_y2 && // below top + m_y > viewport.m_y1) // above bottom + { + float height = float(viewport.m_y2 - viewport.m_y1 + 1); + float width = float(viewport.m_x2 - viewport.m_x1 + 1); + + float x_lb = float(viewport.m_x1); + float y_lb = float(viewport.m_y1); + + /* There's some strangeness I don't fully get here... These values + * _should_ be wrong! - see from point Z values */ + + + /* build the from and to point in normalized device coordinates + * Looks like normailized device coordinates are [-1,1] in x [-1,1] in y + * [0,-1] in z + * + * The actual z coordinates used don't have to be exact just infront and + * behind of the near and far clip planes. + */ + frompoint.setValue( (2 * (m_x-x_lb) / width) - 1.0, + 1.0 - (2 * (m_y - y_lb) / height), + 0.0, /* nearclip, see above comments */ + 1.0 ); + + topoint.setValue( (2 * (m_x-x_lb) / width) - 1.0, + 1.0 - (2 * (m_y-y_lb) / height), + 1.0, /* farclip, see above comments */ + 1.0 ); + + /* camera to world */ + MT_Transform wcs_camcs_tranform = cam->GetWorldToCamera(); + if (!cam->GetCameraData()->m_perspective) + wcs_camcs_tranform.getOrigin()[2] *= 100.0; + MT_Transform cams_wcs_transform; + cams_wcs_transform.invert(wcs_camcs_tranform); + + MT_Matrix4x4 camcs_wcs_matrix = MT_Matrix4x4(cams_wcs_transform); + + /* badly defined, the first time round.... I wonder why... I might + * want to guard against floating point errors here.*/ + MT_Matrix4x4 clip_camcs_matrix = MT_Matrix4x4(cam->GetProjectionMatrix()); + clip_camcs_matrix.invert(); + + /* shoot-points: clip to cam to wcs . win to clip was already done.*/ + frompoint = clip_camcs_matrix * frompoint; + topoint = clip_camcs_matrix * topoint; + frompoint = camcs_wcs_matrix * frompoint; + topoint = camcs_wcs_matrix * topoint; + + /* from hom wcs to 3d wcs: */ + m_prevSourcePoint.setValue( frompoint[0]/frompoint[3], + frompoint[1]/frompoint[3], + frompoint[2]/frompoint[3]); + + m_prevTargetPoint.setValue( topoint[0]/topoint[3], + topoint[1]/topoint[3], + topoint[2]/topoint[3]); + + /* 2. Get the object from PhysicsEnvironment */ + /* Shoot! Beware that the first argument here is an + * ignore-object. We don't ignore anything... */ + KX_IPhysicsController* physics_controller = cam->GetPhysicsController(); + PHY_IPhysicsEnvironment* physics_environment = m_kxscene->GetPhysicsEnvironment(); + + KX_RayCast::Callback callback(this,physics_controller); + + KX_RayCast::RayTest(physics_environment, m_prevSourcePoint, m_prevTargetPoint, callback); + + if (m_hitObject) { + result= true; + break; + } + } + } + it++; + } - result = (m_hitObject!=0); - return result; - } /* ------------------------------------------------------------------------- */ -- cgit v1.2.3 From 3511f8ef9fe6a2a6491fbae3a44a407f280a19e0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 14 Apr 2009 12:34:39 +0000 Subject: BGE Physics Clamp objects min/max velocity. Accessed with bullet physics from the advanced button with dynamic and rigid body objects. - useful for preventing unstable physics in cases where objects move too fast. - can add linear velocity with the motion actuator to give smooth motion transitions, without moving too fast. - minimum velocity means objects don't stop moving. - python scripts can adjust these values speedup or throttle velocity in the existing direction. Also made copy properties from an object with no properties work (in case you want to clear all props) --- .../Converter/BL_BlenderDataConversion.cpp | 4 ++ .../Ketsji/KX_BulletPhysicsController.cpp | 27 +++++++++--- .../gameengine/Ketsji/KX_BulletPhysicsController.h | 6 ++- .../gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp | 2 + source/gameengine/Ketsji/KX_GameObject.cpp | 49 ++++++++++++++++++++++ source/gameengine/Ketsji/KX_GameObject.h | 4 ++ source/gameengine/Ketsji/KX_IPhysicsController.h | 6 +++ .../Physics/Bullet/CcdPhysicsController.cpp | 14 ++++++- .../Physics/Bullet/CcdPhysicsController.h | 23 +++++++++- .../Physics/common/PHY_IPhysicsController.h | 6 +++ source/gameengine/Physics/common/PHY_Pro.h | 6 ++- source/gameengine/PyDoc/KX_GameObject.py | 14 ++++++- 12 files changed, 149 insertions(+), 12 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 5de2c4a2fe7..2ae47e47d74 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -1107,6 +1107,10 @@ static PHY_ShapeProps *CreateShapePropsFromBlenderObject(struct Object* blendero shapeProps->m_do_fh = (blenderobject->gameflag & OB_DO_FH) != 0; shapeProps->m_do_rot_fh = (blenderobject->gameflag & OB_ROT_FH) != 0; +// velocity clamping XXX + shapeProps->m_clamp_vel_min = blenderobject->min_vel; + shapeProps->m_clamp_vel_max = blenderobject->max_vel; + return shapeProps; } diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp index c621f11994a..831f9241fec 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp @@ -59,6 +59,24 @@ void KX_BulletPhysicsController::applyImpulse(const MT_Point3& attach, const MT_ } +float KX_BulletPhysicsController::GetLinVelocityMin() +{ + return (float)CcdPhysicsController::GetLinVelocityMin(); +} +void KX_BulletPhysicsController::SetLinVelocityMin(float val) +{ + CcdPhysicsController::SetLinVelocityMin(val); +} + +float KX_BulletPhysicsController::GetLinVelocityMax() +{ + return (float)CcdPhysicsController::GetLinVelocityMax(); +} +void KX_BulletPhysicsController::SetLinVelocityMax(float val) +{ + CcdPhysicsController::SetLinVelocityMax(val); +} + void KX_BulletPhysicsController::SetObject (SG_IObject* object) { SG_Controller::SetObject(object); @@ -73,6 +91,10 @@ void KX_BulletPhysicsController::SetObject (SG_IObject* object) } +MT_Scalar KX_BulletPhysicsController::GetRadius() +{ + return MT_Scalar(CcdPhysicsController::GetRadius()); +} void KX_BulletPhysicsController::setMargin (float collisionMargin) { @@ -176,11 +198,6 @@ MT_Vector3 KX_BulletPhysicsController::GetLocalInertia() return inertia; } -MT_Scalar KX_BulletPhysicsController::GetRadius() -{ - return MT_Scalar(CcdPhysicsController::GetRadius()); -} - MT_Vector3 KX_BulletPhysicsController::getReactionForce() { assert(0); diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.h b/source/gameengine/Ketsji/KX_BulletPhysicsController.h index 9821b3fd253..b39098206f7 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.h +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.h @@ -56,7 +56,11 @@ public: virtual SG_Controller* GetReplica(class SG_Node* destnode); virtual MT_Scalar GetRadius(); - + + virtual float GetLinVelocityMin(); + virtual void SetLinVelocityMin(float val); + virtual float GetLinVelocityMax(); + virtual void SetLinVelocityMax(float val); virtual void SetSumoTransform(bool nondynaonly); // todo: remove next line ! diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 03149859f4d..08e2ea30414 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -801,6 +801,8 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, ci.m_gravity = btVector3(0,0,0); ci.m_localInertiaTensor =btVector3(0,0,0); ci.m_mass = objprop->m_dyna ? shapeprops->m_mass : 0.f; + ci.m_clamp_vel_min = shapeprops->m_clamp_vel_min; + ci.m_clamp_vel_max = shapeprops->m_clamp_vel_max; ci.m_margin = objprop->m_margin; shapeInfo->m_radius = objprop->m_radius; isbulletdyna = objprop->m_dyna; diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 16cf3d9ae32..a399d3b477a 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1086,6 +1086,8 @@ PyAttributeDef KX_GameObject::Attributes[] = { KX_PYATTRIBUTE_RO_FUNCTION("name", KX_GameObject, pyattr_get_name), KX_PYATTRIBUTE_RO_FUNCTION("parent", KX_GameObject, pyattr_get_parent), KX_PYATTRIBUTE_RW_FUNCTION("mass", KX_GameObject, pyattr_get_mass, pyattr_set_mass), + KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMin", KX_GameObject, pyattr_get_lin_vel_min, pyattr_set_lin_vel_min), + KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMax", KX_GameObject, pyattr_get_lin_vel_max, pyattr_set_lin_vel_max), KX_PYATTRIBUTE_RW_FUNCTION("visible", KX_GameObject, pyattr_get_visible, pyattr_set_visible), KX_PYATTRIBUTE_BOOL_RW ("occlusion", KX_GameObject, m_bOccluder), KX_PYATTRIBUTE_RW_FUNCTION("position", KX_GameObject, pyattr_get_position, pyattr_set_position), @@ -1364,6 +1366,53 @@ int KX_GameObject::pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrd return 0; } +PyObject* KX_GameObject::pyattr_get_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + KX_IPhysicsController *spc = self->GetPhysicsController(); + return PyFloat_FromDouble(spc ? spc->GetLinVelocityMax() : 0.0f); +} + +int KX_GameObject::pyattr_set_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_GameObject* self= static_cast(self_v); + KX_IPhysicsController *spc = self->GetPhysicsController(); + MT_Scalar val = PyFloat_AsDouble(value); + if (val < 0.0f) { /* also accounts for non float */ + PyErr_SetString(PyExc_AttributeError, "expected a float zero or above"); + return 1; + } + + if (spc) + spc->SetLinVelocityMin(val); + + return 0; +} + +PyObject* KX_GameObject::pyattr_get_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + KX_IPhysicsController *spc = self->GetPhysicsController(); + return PyFloat_FromDouble(spc ? spc->GetLinVelocityMax() : 0.0f); +} + +int KX_GameObject::pyattr_set_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_GameObject* self= static_cast(self_v); + KX_IPhysicsController *spc = self->GetPhysicsController(); + MT_Scalar val = PyFloat_AsDouble(value); + if (val < 0.0f) { /* also accounts for non float */ + PyErr_SetString(PyExc_AttributeError, "expected a float zero or above"); + return 1; + } + + if (spc) + spc->SetLinVelocityMax(val); + + return 0; +} + + PyObject* KX_GameObject::pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_GameObject* self= static_cast(self_v); diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index c389d6cc776..94192580859 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -960,6 +960,10 @@ public: static PyObject* pyattr_get_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); diff --git a/source/gameengine/Ketsji/KX_IPhysicsController.h b/source/gameengine/Ketsji/KX_IPhysicsController.h index b7603203241..10b66da7b76 100644 --- a/source/gameengine/Ketsji/KX_IPhysicsController.h +++ b/source/gameengine/Ketsji/KX_IPhysicsController.h @@ -79,6 +79,12 @@ public: virtual void setScaling(const MT_Vector3& scaling)=0; virtual MT_Scalar GetMass()=0; virtual void SetMass(MT_Scalar newmass)=0; + + virtual float GetLinVelocityMin()=0; + virtual void SetLinVelocityMin(float newmass)=0; + virtual float GetLinVelocityMax()=0; + virtual void SetLinVelocityMax(float newmass)=0; + virtual MT_Vector3 GetLocalInertia()=0; virtual MT_Vector3 getReactionForce()=0; virtual void setRigidBody(bool rigid)=0; diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index 2283968801f..0b9da8f46d3 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -584,7 +584,19 @@ bool CcdPhysicsController::SynchronizeMotionStates(float time) if (body && !body->isStaticObject()) { - + + if ((m_cci.m_clamp_vel_max>0.0) || (m_cci.m_clamp_vel_min>0.0)) + { + const btVector3& linvel = body->getLinearVelocity(); + float len= linvel.length(); + + if((m_cci.m_clamp_vel_max>0.0) && (len > m_cci.m_clamp_vel_max)) + body->setLinearVelocity(linvel * (m_cci.m_clamp_vel_max / len)); + + else if ((m_cci.m_clamp_vel_min>0.0) && btFuzzyZero(len)==0 && (len < m_cci.m_clamp_vel_min)) + body->setLinearVelocity(linvel * (m_cci.m_clamp_vel_min / len)); + } + const btVector3& worldPos = body->getCenterOfMassPosition(); m_MotionState->setWorldPosition(worldPos[0],worldPos[1],worldPos[2]); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index 245cde2baaa..c7638b36728 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -214,6 +214,8 @@ struct CcdConstructionInfo m_gravity(0,0,0), m_scaling(1.f,1.f,1.f), m_mass(0.f), + m_clamp_vel_min(-1.f), + m_clamp_vel_max(-1.f), m_restitution(0.1f), m_friction(0.5f), m_linearDamping(0.1f), @@ -239,6 +241,8 @@ struct CcdConstructionInfo btVector3 m_gravity; btVector3 m_scaling; btScalar m_mass; + btScalar m_clamp_vel_min; + btScalar m_clamp_vel_max; btScalar m_restitution; btScalar m_friction; btScalar m_linearDamping; @@ -479,7 +483,24 @@ class CcdPhysicsController : public PHY_IPhysicsController } m_cci.m_radius = margin; } - + + // velocity clamping + virtual void SetLinVelocityMin(float val) + { + m_cci.m_clamp_vel_min= val; + } + virtual float GetLinVelocityMin() const + { + return m_cci.m_clamp_vel_min; + } + virtual void SetLinVelocityMax(float val) + { + m_cci.m_clamp_vel_max= val; + } + virtual float GetLinVelocityMax() const + { + return m_cci.m_clamp_vel_max; + } bool wantsSleeping(); diff --git a/source/gameengine/Physics/common/PHY_IPhysicsController.h b/source/gameengine/Physics/common/PHY_IPhysicsController.h index 6cba6fa88af..770426b48db 100644 --- a/source/gameengine/Physics/common/PHY_IPhysicsController.h +++ b/source/gameengine/Physics/common/PHY_IPhysicsController.h @@ -90,6 +90,12 @@ class PHY_IPhysicsController : public PHY_IController virtual float GetMargin() const=0; virtual float GetRadius() const=0; virtual void SetRadius(float margin) = 0; + + virtual float GetLinVelocityMin() const=0; + virtual void SetLinVelocityMin(float val) = 0; + virtual float GetLinVelocityMax() const=0; + virtual void SetLinVelocityMax(float val) = 0; + PHY__Vector3 GetWorldPosition(PHY__Vector3& localpos); }; diff --git a/source/gameengine/Physics/common/PHY_Pro.h b/source/gameengine/Physics/common/PHY_Pro.h index 32e63ac2f6d..0249fc3118a 100644 --- a/source/gameengine/Physics/common/PHY_Pro.h +++ b/source/gameengine/Physics/common/PHY_Pro.h @@ -35,9 +35,11 @@ struct PHY_ShapeProps { MT_Scalar m_mass; // Total mass MT_Scalar m_inertia; // Inertia, should be a tensor some time - MT_Scalar m_lin_drag; // Linear drag (air, water) 0 = concrete, 1 = vacuum - MT_Scalar m_ang_drag; // Angular drag + MT_Scalar m_lin_drag; // Linear drag (air, water) 0 = concrete, 1 = vacuum, inverted and called dampening in blenders UI + MT_Scalar m_ang_drag; // Angular drag, inverted and called dampening in blenders UI MT_Scalar m_friction_scaling[3]; // Scaling for anisotropic friction. Component in range [0, 1] + MT_Scalar m_clamp_vel_min; // Clamp the minimum velocity, this ensures an object moves at a minimum speed unless its stationary + MT_Scalar m_clamp_vel_max; // Clamp max velocity bool m_do_anisotropic; // Should I do anisotropic friction? bool m_do_fh; // Should the object have a linear Fh spring? bool m_do_rot_fh; // Should the object have an angular Fh spring? diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index fa4641c3e2f..44b84d44d8d 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -16,8 +16,18 @@ class KX_GameObject: # (SCA_IObject) @ivar name: The object's name. (Read only) - note: Currently (Blender 2.49) the prefix "OB" is added to all objects name. This may change in blender 2.5. @type name: string. - @ivar mass: The object's mass (provided the object has a physics controller). + @ivar mass: The object's mass + - note: The object must have a physics controller for the mass to be applied, otherwise the mass value will be returned as 0.0 @type mass: float + @ivar linVelocityMin: Enforces the object keeps moving at a minimum velocity. + - note: Applies to dynamic and rigid body objects only. + - note: A value of 0.0 disables this option. + - note: While objects are stationary the minimum velocity will not be applied. + @type linVelocityMin: float + @ivar linVelocityMax: Clamp the maximum linear velocity to prevent objects moving beyond a set speed. + - note: Applies to dynamic and rigid body objects only. + - note: A value of 0.0 disables this option (rather then setting it stationary). + @type linVelocityMax: float @ivar localInertia: the object's inertia vector in local coordinates. Read only. @type localInertia: list [ix, iy, iz] @ivar parent: The object's parent object. (Read only) @@ -35,7 +45,7 @@ class KX_GameObject: # (SCA_IObject) @type scaling: list [sx, sy, sz] @ivar timeOffset: adjust the slowparent delay at runtime. @type timeOffset: float - @ivar state: the game object's state bitmask. + @ivar state: the game object's state bitmask, using the first 30 bits, one bit must always be set. @type state: int @ivar meshes: a list meshes for this object. - note: Most objects use only 1 mesh. -- cgit v1.2.3 From bc355482ab5963f8dc4fff3cbaf35d0384c9d8df Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Tue, 14 Apr 2009 17:22:14 +0000 Subject: BGE: Keep Sumo and ODE in sync with Bullet at API level, fix a compilation problem in MSVC. --- source/gameengine/Ketsji/KX_OdePhysicsController.h | 4 ++++ source/gameengine/Ketsji/KX_SumoPhysicsController.h | 4 ++++ source/gameengine/Physics/BlOde/OdePhysicsController.h | 4 ++++ source/gameengine/Physics/Sumo/SumoPhysicsController.h | 5 +++++ 4 files changed, 17 insertions(+) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_OdePhysicsController.h b/source/gameengine/Ketsji/KX_OdePhysicsController.h index e3b5336c0b5..21b7e632d83 100644 --- a/source/gameengine/Ketsji/KX_OdePhysicsController.h +++ b/source/gameengine/Ketsji/KX_OdePhysicsController.h @@ -82,6 +82,10 @@ public: virtual SG_Controller* GetReplica(class SG_Node* destnode); + virtual float GetLinVelocityMin() { return ODEPhysicsController::GetLinVelocityMin(); } + virtual void SetLinVelocityMin(float val) { ODEPhysicsController::SetLinVelocityMin(val); } + virtual float GetLinVelocityMax() { return ODEPhysicsController::GetLinVelocityMax(); } + virtual void SetLinVelocityMax(float val) { ODEPhysicsController::SetLinVelocityMax(val); } virtual void SetSumoTransform(bool nondynaonly); // todo: remove next line ! diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.h b/source/gameengine/Ketsji/KX_SumoPhysicsController.h index 8762612eca2..083d89896f6 100644 --- a/source/gameengine/Ketsji/KX_SumoPhysicsController.h +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.h @@ -93,6 +93,10 @@ public: virtual MT_Vector3 getReactionForce(); virtual void setRigidBody(bool rigid); + virtual float GetLinVelocityMin() { return SumoPhysicsController::GetLinVelocityMin(); } + virtual void SetLinVelocityMin(float val) { SumoPhysicsController::SetLinVelocityMin(val); } + virtual float GetLinVelocityMax() { return SumoPhysicsController::GetLinVelocityMax(); } + virtual void SetLinVelocityMax(float val) { SumoPhysicsController::SetLinVelocityMax(val); } virtual SG_Controller* GetReplica(class SG_Node* destnode); diff --git a/source/gameengine/Physics/BlOde/OdePhysicsController.h b/source/gameengine/Physics/BlOde/OdePhysicsController.h index 925f5b6686a..e97afdb68c3 100644 --- a/source/gameengine/Physics/BlOde/OdePhysicsController.h +++ b/source/gameengine/Physics/BlOde/OdePhysicsController.h @@ -124,6 +124,10 @@ public: float getFriction() { return m_friction;} float getRestitution() { return m_restitution;} + float GetLinVelocityMin() const { return 0.f; } + void SetLinVelocityMin(float val) { } + float GetLinVelocityMax() const { return 0.f; } + void SetLinVelocityMax(float val) { } private: diff --git a/source/gameengine/Physics/Sumo/SumoPhysicsController.h b/source/gameengine/Physics/Sumo/SumoPhysicsController.h index d8ee54935d7..415bc1e3982 100644 --- a/source/gameengine/Physics/Sumo/SumoPhysicsController.h +++ b/source/gameengine/Physics/Sumo/SumoPhysicsController.h @@ -144,6 +144,11 @@ public: void GetWorldPosition(MT_Point3& pos); void GetWorldScaling(MT_Vector3& scale); + float GetLinVelocityMin() const { return 0.f; } + void SetLinVelocityMin(float val) { } + float GetLinVelocityMax() const { return 0.f; } + void SetLinVelocityMax(float val) { } + // void SetSumoObject(class SM_Object* sumoObj) { // m_sumoObj = sumoObj; -- cgit v1.2.3 From 494f0fa4e7d5df3dee34aa61338b7c2010477bb5 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Tue, 14 Apr 2009 20:54:04 +0000 Subject: BGE bug #18522 fixed: Dupligroup offsets don't work in BGE. --- source/gameengine/Ketsji/KX_Scene.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 98c129ebca5..2bfa767dc3b 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -717,9 +717,9 @@ void KX_Scene::DupliGroupRecurse(CValue* obj, int level) MT_Matrix3x3 newori = groupobj->NodeGetWorldOrientation() * gameobj->NodeGetWorldOrientation(); replica->NodeSetLocalOrientation(newori); - + MT_Point3 offset(group->dupli_ofs); MT_Point3 newpos = groupobj->NodeGetWorldPosition() + - newscale*(groupobj->NodeGetWorldOrientation() * gameobj->NodeGetWorldPosition()); + newscale*(groupobj->NodeGetWorldOrientation() * (gameobj->NodeGetWorldPosition()-offset)); replica->NodeSetLocalPosition(newpos); replica->GetSGNode()->UpdateWorldData(0); -- cgit v1.2.3 From efb7dd86ff001efe26fba1caef70a87806d138f6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 15 Apr 2009 04:34:27 +0000 Subject: Fix for own recent reference count error. - The armature weakref list was being incref'd twice then decrefed twice (incref and decref were used incorrectly), now only once. My 'fix' broke this. - In bpy_pydriver_create_dict the 2 refs added from running PyDict_SetItemString twice were undone when clearing the dictionary (added comment) - changed Py_XDECREF to Py_DECREF int BPY_pyconstraint_update and BPY_pyconstraint_target, Py_XDECREF checs for NULL value which would have crashed blender before it got to Py_XDECREF anyway. - after every error is reported (PyErr_Print), remove sys.last_traceback and clear the error, I found this fixed certain crashes (usually when starting the game engine or exiting blender), so best do this all the time. - header_text.c, CcdPhysicsEnvironment.cpp, KX_CameraActuator.cpp - remove some warnings. --- source/gameengine/GameLogic/SCA_PythonController.cpp | 4 ++-- source/gameengine/Ketsji/KX_CameraActuator.cpp | 2 +- source/gameengine/Ketsji/KX_PolygonMaterial.cpp | 2 ++ source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 0e6b9d1e8f1..1c5b597f937 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -300,7 +300,7 @@ bool SCA_PythonController::Compile() * 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); + PySys_SetObject( (char *)"last_traceback", NULL); PyErr_Clear(); /* just to be sure */ return false; @@ -358,7 +358,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( (char *)"last_traceback", Py_None); + PySys_SetObject( (char *)"last_traceback", NULL); PyErr_Clear(); /* just to be sure */ //PyRun_SimpleString(m_scriptText.Ptr()); diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 0118e490773..329d31cfa25 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -611,7 +611,7 @@ int KX_CameraActuator::pyattr_set_object(void *self_v, const KX_PYATTRIBUTE_DEF if (self->m_ob) self->m_ob->UnregisterActuator(self); - if (self->m_ob = (SCA_IObject*)gameobj) + if ((self->m_ob = (SCA_IObject*)gameobj)) self->m_ob->RegisterActuator(self); return 0; diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index 56a1daa7544..056442f77d9 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -109,6 +109,8 @@ bool KX_PolygonMaterial::Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingI else { PyErr_Print(); + PyErr_Clear(); + PySys_SetObject( (char *)"last_traceback", NULL); } } else diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 858416bae6a..3e1e0294321 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -1346,7 +1346,7 @@ struct OcclusionBuffer static int clip(const btVector4* pi,btVector4* po) { btScalar s[2*NP]; - btVector4 pn[2*NP], *p; + btVector4 pn[2*NP]; int i, j, m, n, ni; // deal with near clipping for(i=0, m=0;i Date: Wed, 15 Apr 2009 07:00:11 +0000 Subject: [#7789] 3DS Import , Mesh not correct since Blender 2.44 There is a problem importing 3ds files where I cant find a way to check if the transforms are applied to the vertex locations or not. Since 2.44 I made the importer assume they were not since you can manually remove transformations, but not reverse. Nevertheless most 3ds files have the matrix applied, better not give a bad import by default. Did some research and other 3ds importers (lib3ds for eg), have the same problem and just assume the transformations applied. 3dsMax imports both correctly so there must be a way to tell but I could not link it to the 3ds version or other mesh options. Added an option to workaround this problem in rare cases where its needed. - KX_GameObject.cpp & KX_Scene.cpp, clear the dict before removing the reference in case there is a circular reference. --- source/gameengine/Ketsji/KX_GameObject.cpp | 1 + source/gameengine/Ketsji/KX_Scene.cpp | 1 + 2 files changed, 2 insertions(+) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index a399d3b477a..fd9ba93f4b6 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -143,6 +143,7 @@ KX_GameObject::~KX_GameObject() } if (m_attrlist) { + PyDict_Clear(m_attrlist); /* incase of circular refs or other weired cases */ Py_DECREF(m_attrlist); } } diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 2bfa767dc3b..c63167e2d56 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -250,6 +250,7 @@ KX_Scene::~KX_Scene() { delete m_bucketmanager; } + PyDict_Clear(m_attrlist); Py_DECREF(m_attrlist); } -- cgit v1.2.3 From 19c869ab64a0e14727217c7d221e03d32a614132 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 15 Apr 2009 08:08:42 +0000 Subject: BGE Py Api importing modules wasnt returning the error from the blender text if it failed. --- source/gameengine/Ketsji/KX_PythonInit.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 7ed83465c49..924c5451608 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1209,6 +1209,7 @@ PyObject *KXpy_compile(PyObject *self, PyObject *args) { PyObject *KXpy_import(PyObject *self, PyObject *args) { char *name; + int found; PyObject *globals = NULL; PyObject *locals = NULL; PyObject *fromlist = NULL; @@ -1243,12 +1244,13 @@ PyObject *KXpy_import(PyObject *self, PyObject *args) } /* Import blender texts as python modules */ - m= importText(name); + m= importText(name, &found); if (m) return m; - - PyErr_Format(PyExc_ImportError, - "Import of external Module %.20s not allowed.", name); + + if(found==0) /* if its found but could not import then it has its own error */ + PyErr_Format(PyExc_ImportError, "Import of external Module %.20s not allowed.", name); + return NULL; } @@ -1260,7 +1262,7 @@ PyObject *KXpy_reload(PyObject *self, PyObject *args) { PyErr_SetString(PyExc_RuntimeError, "Sandbox: reload() function disabled!\nGame Scripts should not use this function."); return NULL; #endif - + int found; PyObject *module = NULL; PyObject *newmodule = NULL; @@ -1268,9 +1270,11 @@ PyObject *KXpy_reload(PyObject *self, PyObject *args) { if( !PyArg_ParseTuple( args, "O:bpy_reload", &module ) ) return NULL; - newmodule= reimportText( module ); + newmodule= reimportText( module, &found ); + if (newmodule) + return newmodule; - if (newmodule==NULL) + if (found==0) /* if its found but could not import then it has its own error */ PyErr_SetString(PyExc_ImportError, "failed to reload from blenders internal text"); return newmodule; -- cgit v1.2.3 From e8f4d9322112e64677df11ba834a26159874b332 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 15 Apr 2009 10:57:28 +0000 Subject: Disable using KX_GameObjects in python that have been removed from the scene (zombie objects) by raising a RuntimeError when accessing methods, attributes or passing to a function. Common cases of this are when python references an object from the AddObject actuator that has ended, or a scene has been loaded and the old objects freed. This means some scripts will raise errors now in certain cases but better give the error early rather then failing silently with strange hard to track down behavior & crashes. Added "isValid" attribute for checking objects are in a scene. At the moment it uses the SceneGraph Node to check of the objects valid but it might be better to do this in a more generic way so scenes, meshes etc also have this check. --- source/gameengine/Ketsji/KX_Camera.cpp | 11 +++ source/gameengine/Ketsji/KX_GameObject.cpp | 152 ++++++++++++++++++++++++++++- source/gameengine/Ketsji/KX_GameObject.h | 110 +++------------------ source/gameengine/Ketsji/KX_Light.cpp | 15 ++- source/gameengine/PyDoc/KX_GameObject.py | 3 + 5 files changed, 186 insertions(+), 105 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index 8032e939a50..befc8462aa3 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -534,11 +534,22 @@ PyParentObject KX_Camera::Parents[] = { PyObject* KX_Camera::py_getattro(PyObject *attr) { + if (ValidPythonToGameObject(this)==false) { + if (!strcmp(PyString_AsString(attr), "isValid")) { + PyErr_Clear(); + Py_RETURN_FALSE; + } + return NULL; /* ValidPythonToGameObject sets the error */ + } + py_getattro_up(KX_GameObject); } int KX_Camera::py_setattro(PyObject *attr, PyObject *value) { + if (ValidPythonToGameObject(this)==false) + return -1; + py_setattro_up(KX_GameObject); } diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index fd9ba93f4b6..36fb9142adc 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1106,6 +1106,8 @@ PyAttributeDef KX_GameObject::Attributes[] = { KX_PYATTRIBUTE_RO_FUNCTION("controllers", KX_GameObject, pyattr_get_controllers), KX_PYATTRIBUTE_RO_FUNCTION("actuators", KX_GameObject, pyattr_get_actuators), + KX_PYATTRIBUTE_RO_FUNCTION("isValid", KX_GameObject, pyattr_get_is_valid), + {NULL} //Sentinel }; @@ -1169,6 +1171,12 @@ PyObject* KX_GameObject::PyGetPosition(PyObject* self) Py_ssize_t KX_GameObject::Map_Len(PyObject* self_v) { KX_GameObject* self= static_cast(self_v); + + if (ValidPythonToGameObject(self)==false) { + PyErr_Clear(); + return 0; + } + Py_ssize_t len= self->GetPropertyCount(); if(self->m_attrlist) len += PyDict_Size(self->m_attrlist); @@ -1183,6 +1191,9 @@ PyObject *KX_GameObject::Map_GetItem(PyObject *self_v, PyObject *item) CValue* resultattr; PyObject* pyconvert; + if (ValidPythonToGameObject(self)==false) + return NULL; + /* first see if the attributes a string and try get the cvalue attribute */ if(attr_str && (resultattr=self->GetProperty(attr_str))) { pyconvert = resultattr->ConvertValueToPython(); @@ -1212,6 +1223,9 @@ int KX_GameObject::Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val) if(attr_str==NULL) PyErr_Clear(); + if (ValidPythonToGameObject(self)==false) + return -1; + if (val==NULL) { /* del ob["key"] */ int del= 0; @@ -1537,7 +1551,7 @@ int KX_GameObject::pyattr_set_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *at PyObject* KX_GameObject::pyattr_get_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_GameObject* self= static_cast(self_v); - SG_Node* sg_parent= self->GetSGNode()->GetSGParent(); + SG_Node* sg_parent= self->GetSGNode()->GetSGParent(); /* GetSGNode() is valid or exception would be raised */ if (sg_parent && sg_parent->IsSlowParent()) { return PyFloat_FromDouble(static_cast(sg_parent->GetParentRelation())->GetTimeOffset()); } else { @@ -1549,7 +1563,7 @@ int KX_GameObject::pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF { KX_GameObject* self= static_cast(self_v); MT_Scalar val = PyFloat_AsDouble(value); - SG_Node* sg_parent= self->GetSGNode()->GetSGParent(); + SG_Node* sg_parent= self->GetSGNode()->GetSGParent(); /* GetSGNode() is valid or exception would be raised */ if (val < 0.0f) { /* also accounts for non float */ PyErr_SetString(PyExc_AttributeError, "expected a float zero or above"); return 1; @@ -1604,6 +1618,10 @@ PyObject* KX_GameObject::pyattr_get_meshes(void *self_v, const KX_PYATTRIBUTE_DE return meshes; } +PyObject* KX_GameObject::pyattr_get_is_valid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + Py_RETURN_TRUE; +} /* experemental! */ PyObject* KX_GameObject::pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) @@ -1642,7 +1660,6 @@ PyObject* KX_GameObject::pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE return resultlist; } - /* __dict__ only for the purpose of giving useful dir() results */ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { @@ -1674,7 +1691,6 @@ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_ return dict; } - PyObject* KX_GameObject::py_getattro(PyObject *attr) { py_getattro_up(SCA_IObject); @@ -1685,6 +1701,113 @@ int KX_GameObject::py_setattro(PyObject *attr, PyObject *value) // py_setattro m py_setattro_up(SCA_IObject); } + +/* we need our own getattr and setattr types */ +/* See m_attrlist definition for rules on how this works */ +PyObject *KX_GameObject::py_base_getattro_gameobject(PyObject * self, PyObject *attr) +{ + if(((KX_GameObject *) self)->GetSGNode()==NULL) { + if (!strcmp(PyString_AsString(attr), "isValid")) { + PyErr_Clear(); + Py_INCREF(Py_False); + return Py_False; + } + + ValidPythonToGameObject(((KX_GameObject *) self)); // we know its invalid, just get the error + return NULL; + } + + PyObject *object= ((KX_GameObject *) self)->py_getattro(attr); + + if (object==NULL && ((KX_GameObject *) self)->m_attrlist) { + /* backup the exception incase the attr doesnt exist in the dict either */ + PyObject *err_type, *err_value, *err_tb; + PyErr_Fetch(&err_type, &err_value, &err_tb); + + object= PyDict_GetItem(((KX_GameObject *) self)->m_attrlist, attr); + if (object) { + Py_INCREF(object); + + PyErr_Clear(); + Py_XDECREF( err_type ); + Py_XDECREF( err_value ); + Py_XDECREF( err_tb ); + } + else { + PyErr_Restore(err_type, err_value, err_tb); /* use the error from the parent function */ + } + } + return object; +} + +int KX_GameObject::py_base_setattro_gameobject(PyObject * self, PyObject *attr, PyObject *value) +{ + int ret; + + /* Delete the item */ + if (value==NULL) + { + ret= ((PyObjectPlus*) self)->py_delattro(attr); + + if (ret != 0) /* CValue attribute failed, try KX_GameObject m_attrlist dict */ + { + if (((KX_GameObject *) self)->m_attrlist) + { + /* backup the exception incase the attr doesnt exist in the dict either */ + PyObject *err_type, *err_value, *err_tb; + PyErr_Fetch(&err_type, &err_value, &err_tb); + + if (PyDict_DelItem(((KX_GameObject *) self)->m_attrlist, attr) == 0) + { + ret= 0; + PyErr_Clear(); + Py_XDECREF( err_type ); + Py_XDECREF( err_value ); + Py_XDECREF( err_tb ); + } + else { + PyErr_Restore(err_type, err_value, err_tb); /* use the error from the parent function */ + } + } + } + return ret; + } + + + ret= ((PyObjectPlus*) self)->py_setattro(attr, value); + + if (ret==PY_SET_ATTR_SUCCESS) { + /* remove attribute in our own dict to avoid double ups */ + if (((KX_GameObject *) self)->m_attrlist) { + if (PyDict_DelItem(((KX_GameObject *) self)->m_attrlist, attr) != 0) + PyErr_Clear(); + } + } + + if (ret==PY_SET_ATTR_COERCE_FAIL) { + /* CValue attribute exists, remove and add dict value */ + ((KX_GameObject *) self)->RemoveProperty(STR_String(PyString_AsString(attr))); + ret= PY_SET_ATTR_MISSING; + } + + if (ret==PY_SET_ATTR_MISSING) { + /* Lazy initialization */ + if (((KX_GameObject *) self)->m_attrlist==NULL) + ((KX_GameObject *) self)->m_attrlist = PyDict_New(); + + if (PyDict_SetItem(((KX_GameObject *) self)->m_attrlist, attr, value)==0) { + PyErr_Clear(); + ret= PY_SET_ATTR_SUCCESS; + } + else { + PyErr_Format(PyExc_AttributeError, "failed assigning value to KX_GameObject internal dictionary"); + ret= PY_SET_ATTR_FAIL; + } + } + + return ret; +} + PyObject* KX_GameObject::PyApplyForce(PyObject* self, PyObject* args) { int local = 0; @@ -1992,7 +2115,7 @@ static void walk_children(SG_Node* node, CListValue* list, bool recursive) PyObject* KX_GameObject::PyGetChildren(PyObject* self) { CListValue* list = new CListValue(); - walk_children(m_pSGNode, list, 0); + walk_children(GetSGNode(), list, 0); /* GetSGNode() is always valid or it would have raised an exception before this */ return list; } @@ -2569,6 +2692,11 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py if (PyObject_TypeCheck(value, &KX_GameObject::Type)) { *object = static_cast(value); + + /* sets the error */ + if (ValidPythonToGameObject(*object)==false) + return false; + return true; } @@ -2582,3 +2710,17 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py return false; } + +bool ValidPythonToGameObject(KX_GameObject *object) +{ + if (object->GetSGNode()==NULL) { + PyErr_Format( + PyExc_RuntimeError, + "KX_GameObject \"%s\" is not longer in a scene, " + "check for this case with the \"isValid\" attribute", + object->GetName().ReadPtr() ); + return false; + } + + return true; +} \ No newline at end of file diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 94192580859..0bf3e60f34b 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -51,7 +51,6 @@ #include "SCA_LogicManager.h" /* for ConvertPythonToGameObject to search object names */ #define KX_OB_DYNAMIC 1 - //Forward declarations. struct KX_ClientObjectInfo; class KX_RayCast; @@ -61,6 +60,10 @@ class PHY_IGraphicController; class PHY_IPhysicsEnvironment; struct Object; +/* utility conversion function */ +bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok); +bool ValidPythonToGameObject(KX_GameObject *object); + /** * KX_GameObject is the main class for dynamic objects. */ @@ -811,104 +814,15 @@ public: virtual PyObject* py_getattro(PyObject *attr); virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method - virtual PyObject* py_repr(void) { return PyString_FromString(GetName().ReadPtr()); } - - /* we need our own getattr and setattr types */ - /* See m_attrlist definition for rules on how this works */ - static PyObject *py_base_getattro_gameobject(PyObject * self, PyObject *attr) + virtual PyObject* py_repr(void) { - PyObject *object= ((KX_GameObject *) self)->py_getattro(attr); - - if (object==NULL && ((KX_GameObject *) self)->m_attrlist) { - /* backup the exception incase the attr doesnt exist in the dict either */ - PyObject *err_type, *err_value, *err_tb; - PyErr_Fetch(&err_type, &err_value, &err_tb); - - object= PyDict_GetItem(((KX_GameObject *) self)->m_attrlist, attr); - if (object) { - Py_INCREF(object); - - PyErr_Clear(); - Py_XDECREF( err_type ); - Py_XDECREF( err_value ); - Py_XDECREF( err_tb ); - } - else { - PyErr_Restore(err_type, err_value, err_tb); /* use the error from the parent function */ - } - } - return object; - } - - static int py_base_setattro_gameobject(PyObject * self, PyObject *attr, PyObject *value) - { - int ret; - - /* Delete the item */ - if (value==NULL) - { - ret= ((PyObjectPlus*) self)->py_delattro(attr); - - if (ret != 0) /* CValue attribute failed, try KX_GameObject m_attrlist dict */ - { - if (((KX_GameObject *) self)->m_attrlist) - { - /* backup the exception incase the attr doesnt exist in the dict either */ - PyObject *err_type, *err_value, *err_tb; - PyErr_Fetch(&err_type, &err_value, &err_tb); - - if (PyDict_DelItem(((KX_GameObject *) self)->m_attrlist, attr) == 0) - { - ret= 0; - PyErr_Clear(); - Py_XDECREF( err_type ); - Py_XDECREF( err_value ); - Py_XDECREF( err_tb ); - } - else { - PyErr_Restore(err_type, err_value, err_tb); /* use the error from the parent function */ - } - } - } - return ret; - } - - - ret= ((PyObjectPlus*) self)->py_setattro(attr, value); - - if (ret==PY_SET_ATTR_SUCCESS) { - /* remove attribute in our own dict to avoid double ups */ - if (((KX_GameObject *) self)->m_attrlist) { - if (PyDict_DelItem(((KX_GameObject *) self)->m_attrlist, attr) != 0) - PyErr_Clear(); - } - } - - if (ret==PY_SET_ATTR_COERCE_FAIL) { - /* CValue attribute exists, remove and add dict value */ - ((KX_GameObject *) self)->RemoveProperty(STR_String(PyString_AsString(attr))); - ret= PY_SET_ATTR_MISSING; - } - - if (ret==PY_SET_ATTR_MISSING) { - /* Lazy initialization */ - if (((KX_GameObject *) self)->m_attrlist==NULL) - ((KX_GameObject *) self)->m_attrlist = PyDict_New(); - - if (PyDict_SetItem(((KX_GameObject *) self)->m_attrlist, attr, value)==0) { - PyErr_Clear(); - ret= PY_SET_ATTR_SUCCESS; - } - else { - PyErr_Format(PyExc_AttributeError, "failed assigning value to KX_GameObject internal dictionary"); - ret= PY_SET_ATTR_FAIL; - } - } - - return ret; + if (ValidPythonToGameObject(this)==false) + return NULL; + return PyString_FromString(GetName().ReadPtr()); } - + static PyObject *py_base_getattro_gameobject(PyObject * self, PyObject *attr); + static int py_base_setattro_gameobject(PyObject * self, PyObject *attr, PyObject *value); KX_PYMETHOD_NOARGS(KX_GameObject,GetPosition); KX_PYMETHOD_O(KX_GameObject,SetPosition); @@ -979,6 +893,7 @@ public: static PyObject* pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_meshes(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_is_valid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); /* for dir(), python3 uses __dir__() */ static PyObject* pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); @@ -1012,8 +927,5 @@ private : }; -/* utility conversion function */ -bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok); - #endif //__KX_GAMEOBJECT diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp index 059345ea8de..0fcd2c39078 100644 --- a/source/gameengine/Ketsji/KX_Light.cpp +++ b/source/gameengine/Ketsji/KX_Light.cpp @@ -177,6 +177,14 @@ PyObject* KX_LightObject::py_getattro(PyObject *attr) { char *attr_str= PyString_AsString(attr); + if (ValidPythonToGameObject(this)==false) { + if (!strcmp(attr_str, "isValid")) { + PyErr_Clear(); + Py_RETURN_FALSE; + } + return NULL; + } + if (!strcmp(attr_str, "layer")) return PyInt_FromLong(m_lightobj.m_layer); @@ -216,9 +224,14 @@ PyObject* KX_LightObject::py_getattro(PyObject *attr) py_getattro_up(KX_GameObject); } -int KX_LightObject::py_setattro(PyObject *attr, PyObject *pyvalue) + +int KX_LightObject::py_setattro(PyObject *attr, PyObject *pyvalue) { char *attr_str= PyString_AsString(attr); + + if (ValidPythonToGameObject(this)==false) + return -1; + if (PyInt_Check(pyvalue)) { int value = PyInt_AsLong(pyvalue); diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index 44b84d44d8d..4aa9de2fe86 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -12,6 +12,7 @@ class KX_GameObject: # (SCA_IObject) All game objects are derived from this class. Properties assigned to game objects are accessible as attributes of this class. + - note: Calling ANY method or attribute on an object that has been removed from a scene will raise a RuntimeError, if an object may have been removed since last accessing it use the L{isValid} attribute to check. @ivar name: The object's name. (Read only) - note: Currently (Blender 2.49) the prefix "OB" is added to all objects name. This may change in blender 2.5. @@ -63,6 +64,8 @@ class KX_GameObject: # (SCA_IObject) - note: This attribute is experemental and may be removed (but probably wont be). - note: Changes to this list will not update the KX_GameObject. @type actuators: list + @ivar isValid: Retuerns fails when the object has been removed from the scene and can no longer be used. + @type isValid: bool """ def endObject(visible): """ -- cgit v1.2.3 From 514c78ba39f296fcac60b33d9a040af2051d23cc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 15 Apr 2009 13:50:56 +0000 Subject: BGE MouseFocusSensor - fix for multiple viewpors broke single viewport (both work now) - python could get uninitialized values from m_prevTargetPoint and m_prevSourcePoint - getting the RayDirection for python could crash blender trying to normalize a zero length vector. - added python attributes - removed unused canvas from the MouseFocusSensor class --- source/gameengine/Converter/KX_ConvertSensors.cpp | 1 - source/gameengine/Ketsji/KX_MouseFocusSensor.cpp | 309 ++++++++++++++-------- source/gameengine/Ketsji/KX_MouseFocusSensor.h | 26 +- source/gameengine/PyDoc/KX_MouseFocusSensor.py | 27 +- 4 files changed, 238 insertions(+), 125 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/KX_ConvertSensors.cpp b/source/gameengine/Converter/KX_ConvertSensors.cpp index 64cfc101751..19e594ff0cb 100644 --- a/source/gameengine/Converter/KX_ConvertSensors.cpp +++ b/source/gameengine/Converter/KX_ConvertSensors.cpp @@ -509,7 +509,6 @@ void BL_ConvertSensors(struct Object* blenderobject, starty, keytype, trackfocus, - canvas, kxscene, kxengine, gameobj); diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index 2cb74ba65ab..65190937f35 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -61,14 +61,12 @@ KX_MouseFocusSensor::KX_MouseFocusSensor(SCA_MouseManager* eventmgr, int starty, short int mousemode, int focusmode, - RAS_ICanvas* canvas, KX_Scene* kxscene, KX_KetsjiEngine *kxengine, SCA_IObject* gameobj, PyTypeObject* T) : SCA_MouseSensor(eventmgr, startx, starty, mousemode, gameobj, T), m_focusmode(focusmode), - m_gp_canvas(canvas), m_kxscene(kxscene), m_kxengine(kxengine) { @@ -81,6 +79,11 @@ void KX_MouseFocusSensor::Init() m_positive_event = false; m_hitObject = 0; m_reset = true; + + m_hitPosition.setValue(0,0,0); + m_prevTargetPoint.setValue(0,0,0); + m_prevSourcePoint.setValue(0,0,0); + m_hitNormal.setValue(0,0,1); } bool KX_MouseFocusSensor::Evaluate(CValue* event) @@ -150,12 +153,8 @@ bool KX_MouseFocusSensor::RayHit(KX_ClientObjectInfo* client_info, KX_RayCast* r -bool KX_MouseFocusSensor::ParentObjectHasFocus() +bool KX_MouseFocusSensor::ParentObjectHasFocusCamera(KX_Camera *cam) { - m_hitObject = 0; - m_hitPosition.setValue(0,0,0); - m_hitNormal.setValue(1,0,0); - /* All screen handling in the gameengine is done by GL, * specifically the model/view and projection parts. The viewport * part is in the creator. @@ -187,11 +186,7 @@ bool KX_MouseFocusSensor::ParentObjectHasFocus() * = 1.0 - 2(y_blender - y_lb)/height * * */ - - MT_Vector4 frompoint; - MT_Vector4 topoint; - - bool result = false; + /* Because we don't want to worry about resize events, camera * changes and all that crap, we just determine this over and @@ -200,105 +195,138 @@ bool KX_MouseFocusSensor::ParentObjectHasFocus() * canvas, the test is irrelevant. The 1.0 makes sure the * calculations don't bomb. Maybe we should explicitly guard for * division by 0.0...*/ - list* cameras = m_kxscene->GetCameras(); - // Draw the scene once for each camera with an enabled viewport + RAS_Rect area, viewport; + m_kxengine->GetSceneViewport(m_kxscene, cam, area, viewport); + + /* Check if the mouse is in the viewport */ + if (( m_x < viewport.m_x2 && // less then right + m_x > viewport.m_x1 && // more then then left + m_y < viewport.m_y2 && // below top + m_y > viewport.m_y1) == 0) // above bottom + { + return false; + } + + float height = float(viewport.m_y2 - viewport.m_y1 + 1); + float width = float(viewport.m_x2 - viewport.m_x1 + 1); + + float x_lb = float(viewport.m_x1); + float y_lb = float(viewport.m_y1); + + MT_Vector4 frompoint; + MT_Vector4 topoint; + + /* There's some strangeness I don't fully get here... These values + * _should_ be wrong! - see from point Z values */ + + + /* build the from and to point in normalized device coordinates + * Looks like normailized device coordinates are [-1,1] in x [-1,1] in y + * [0,-1] in z + * + * The actual z coordinates used don't have to be exact just infront and + * behind of the near and far clip planes. + */ + frompoint.setValue( (2 * (m_x-x_lb) / width) - 1.0, + 1.0 - (2 * (m_y - y_lb) / height), + 0.0, /* nearclip, see above comments */ + 1.0 ); + + topoint.setValue( (2 * (m_x-x_lb) / width) - 1.0, + 1.0 - (2 * (m_y-y_lb) / height), + 1.0, /* farclip, see above comments */ + 1.0 ); + + /* camera to world */ + MT_Transform wcs_camcs_tranform = cam->GetWorldToCamera(); + if (!cam->GetCameraData()->m_perspective) + wcs_camcs_tranform.getOrigin()[2] *= 100.0; + MT_Transform cams_wcs_transform; + cams_wcs_transform.invert(wcs_camcs_tranform); + + MT_Matrix4x4 camcs_wcs_matrix = MT_Matrix4x4(cams_wcs_transform); + + /* badly defined, the first time round.... I wonder why... I might + * want to guard against floating point errors here.*/ + MT_Matrix4x4 clip_camcs_matrix = MT_Matrix4x4(cam->GetProjectionMatrix()); + clip_camcs_matrix.invert(); + + /* shoot-points: clip to cam to wcs . win to clip was already done.*/ + frompoint = clip_camcs_matrix * frompoint; + topoint = clip_camcs_matrix * topoint; + frompoint = camcs_wcs_matrix * frompoint; + topoint = camcs_wcs_matrix * topoint; + + /* from hom wcs to 3d wcs: */ + m_prevSourcePoint.setValue( frompoint[0]/frompoint[3], + frompoint[1]/frompoint[3], + frompoint[2]/frompoint[3]); + + m_prevTargetPoint.setValue( topoint[0]/topoint[3], + topoint[1]/topoint[3], + topoint[2]/topoint[3]); + + /* 2. Get the object from PhysicsEnvironment */ + /* Shoot! Beware that the first argument here is an + * ignore-object. We don't ignore anything... */ + KX_IPhysicsController* physics_controller = cam->GetPhysicsController(); + PHY_IPhysicsEnvironment* physics_environment = m_kxscene->GetPhysicsEnvironment(); + + KX_RayCast::Callback callback(this,physics_controller); + + KX_RayCast::RayTest(physics_environment, m_prevSourcePoint, m_prevTargetPoint, callback); + + if (m_hitObject) + return true; + + return false; +} + +bool KX_MouseFocusSensor::ParentObjectHasFocus() +{ + m_hitObject = 0; + m_hitPosition.setValue(0,0,0); + m_hitNormal.setValue(1,0,0); + + KX_Camera *cam= m_kxscene->GetActiveCamera(); + + if(ParentObjectHasFocusCamera(cam)) + return true; + + list* cameras = m_kxscene->GetCameras(); list::iterator it = cameras->begin(); + while(it != cameras->end()) { - if((*it)->GetViewport()) - { - KX_Camera* cam= (*it); + if(((*it) != cam) && (*it)->GetViewport()) + if (ParentObjectHasFocusCamera(*it)) + return true; - /* get the scenes current viewport. we recompute it because there - * may be multiple cameras and m_kxscene->GetSceneViewport() only - * has the one that was last drawn */ - - RAS_Rect area, viewport; - m_kxengine->GetSceneViewport(m_kxscene, cam, area, viewport); - - /* Check if the mouse is in the viewport */ - if ( m_x < viewport.m_x2 && // less then right - m_x > viewport.m_x1 && // more then then left - m_y < viewport.m_y2 && // below top - m_y > viewport.m_y1) // above bottom - { - float height = float(viewport.m_y2 - viewport.m_y1 + 1); - float width = float(viewport.m_x2 - viewport.m_x1 + 1); - - float x_lb = float(viewport.m_x1); - float y_lb = float(viewport.m_y1); - - /* There's some strangeness I don't fully get here... These values - * _should_ be wrong! - see from point Z values */ - - - /* build the from and to point in normalized device coordinates - * Looks like normailized device coordinates are [-1,1] in x [-1,1] in y - * [0,-1] in z - * - * The actual z coordinates used don't have to be exact just infront and - * behind of the near and far clip planes. - */ - frompoint.setValue( (2 * (m_x-x_lb) / width) - 1.0, - 1.0 - (2 * (m_y - y_lb) / height), - 0.0, /* nearclip, see above comments */ - 1.0 ); - - topoint.setValue( (2 * (m_x-x_lb) / width) - 1.0, - 1.0 - (2 * (m_y-y_lb) / height), - 1.0, /* farclip, see above comments */ - 1.0 ); - - /* camera to world */ - MT_Transform wcs_camcs_tranform = cam->GetWorldToCamera(); - if (!cam->GetCameraData()->m_perspective) - wcs_camcs_tranform.getOrigin()[2] *= 100.0; - MT_Transform cams_wcs_transform; - cams_wcs_transform.invert(wcs_camcs_tranform); - - MT_Matrix4x4 camcs_wcs_matrix = MT_Matrix4x4(cams_wcs_transform); - - /* badly defined, the first time round.... I wonder why... I might - * want to guard against floating point errors here.*/ - MT_Matrix4x4 clip_camcs_matrix = MT_Matrix4x4(cam->GetProjectionMatrix()); - clip_camcs_matrix.invert(); - - /* shoot-points: clip to cam to wcs . win to clip was already done.*/ - frompoint = clip_camcs_matrix * frompoint; - topoint = clip_camcs_matrix * topoint; - frompoint = camcs_wcs_matrix * frompoint; - topoint = camcs_wcs_matrix * topoint; - - /* from hom wcs to 3d wcs: */ - m_prevSourcePoint.setValue( frompoint[0]/frompoint[3], - frompoint[1]/frompoint[3], - frompoint[2]/frompoint[3]); - - m_prevTargetPoint.setValue( topoint[0]/topoint[3], - topoint[1]/topoint[3], - topoint[2]/topoint[3]); - - /* 2. Get the object from PhysicsEnvironment */ - /* Shoot! Beware that the first argument here is an - * ignore-object. We don't ignore anything... */ - KX_IPhysicsController* physics_controller = cam->GetPhysicsController(); - PHY_IPhysicsEnvironment* physics_environment = m_kxscene->GetPhysicsEnvironment(); - - KX_RayCast::Callback callback(this,physics_controller); - - KX_RayCast::RayTest(physics_environment, m_prevSourcePoint, m_prevTargetPoint, callback); - - if (m_hitObject) { - result= true; - break; - } - } - } it++; } - return result; + return false; +} + +const MT_Point3& KX_MouseFocusSensor::RaySource() const +{ + return m_prevSourcePoint; +} + +const MT_Point3& KX_MouseFocusSensor::RayTarget() const +{ + return m_prevTargetPoint; +} + +const MT_Point3& KX_MouseFocusSensor::HitPosition() const +{ + return m_hitPosition; +} + +const MT_Vector3& KX_MouseFocusSensor::HitNormal() const +{ + return m_hitNormal; } /* ------------------------------------------------------------------------- */ @@ -342,11 +370,16 @@ PyMethodDef KX_MouseFocusSensor::Methods[] = { {"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 }; PyAttributeDef KX_MouseFocusSensor::Attributes[] = { + KX_PYATTRIBUTE_RO_FUNCTION("raySource", KX_MouseFocusSensor, pyattr_get_ray_source), + KX_PYATTRIBUTE_RO_FUNCTION("rayTarget", KX_MouseFocusSensor, pyattr_get_ray_target), + KX_PYATTRIBUTE_RO_FUNCTION("rayDirection", KX_MouseFocusSensor, pyattr_get_ray_direction), + KX_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_MouseFocusSensor, pyattr_get_hit_object), + KX_PYATTRIBUTE_RO_FUNCTION("hitPosition", KX_MouseFocusSensor, pyattr_get_hit_position), + KX_PYATTRIBUTE_RO_FUNCTION("hitNormal", KX_MouseFocusSensor, pyattr_get_hit_normal), { NULL } //Sentinel }; @@ -360,6 +393,8 @@ const char KX_MouseFocusSensor::GetHitObject_doc[] = "\tReturns the object that was hit by this ray.\n"; PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self) { + ShowDeprecationWarning("GetHitObject()", "the hitObject property"); + if (m_hitObject) return m_hitObject->AddRef(); @@ -372,6 +407,8 @@ const char KX_MouseFocusSensor::GetHitPosition_doc[] = "\tReturns the position (in worldcoordinates) where the object was hit by this ray.\n"; PyObject* KX_MouseFocusSensor::PyGetHitPosition(PyObject* self) { + ShowDeprecationWarning("getHitPosition()", "the hitPosition property"); + return PyObjectFrom(m_hitPosition); } @@ -380,9 +417,11 @@ const char KX_MouseFocusSensor::GetRayDirection_doc[] = "\tReturns the direction from the ray (in worldcoordinates) .\n"; PyObject* KX_MouseFocusSensor::PyGetRayDirection(PyObject* self) { - + ShowDeprecationWarning("getRayDirection()", "the rayDirection property"); + MT_Vector3 dir = m_prevTargetPoint - m_prevSourcePoint; - dir.normalize(); + if(MT_fuzzyZero(dir)) dir.setValue(0,0,0); + else dir.normalize(); return PyObjectFrom(dir); } @@ -391,6 +430,8 @@ const char KX_MouseFocusSensor::GetHitNormal_doc[] = "\tReturns the normal (in worldcoordinates) at the point of collision where the object was hit by this ray.\n"; PyObject* KX_MouseFocusSensor::PyGetHitNormal(PyObject* self) { + ShowDeprecationWarning("getHitNormal()", "the hitNormal property"); + return PyObjectFrom(m_hitNormal); } @@ -400,7 +441,10 @@ 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* KX_MouseFocusSensor::PyGetRayTarget(PyObject* self) +{ + ShowDeprecationWarning("getRayTarget()", "the rayTarget property"); + return PyObjectFrom(m_prevTargetPoint); } @@ -409,9 +453,58 @@ 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* KX_MouseFocusSensor::PyGetRaySource(PyObject* self) +{ + ShowDeprecationWarning("getRaySource()", "the raySource property"); + return PyObjectFrom(m_prevSourcePoint); } +/* Attributes */ +PyObject* KX_MouseFocusSensor::pyattr_get_ray_source(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_MouseFocusSensor* self= static_cast(self_v); + return PyObjectFrom(self->RaySource()); +} + +PyObject* KX_MouseFocusSensor::pyattr_get_ray_target(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_MouseFocusSensor* self= static_cast(self_v); + return PyObjectFrom(self->RayTarget()); +} + +PyObject* KX_MouseFocusSensor::pyattr_get_ray_direction(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_MouseFocusSensor* self= static_cast(self_v); + MT_Vector3 dir = self->RayTarget() - self->RaySource(); + if(MT_fuzzyZero(dir)) dir.setValue(0,0,0); + else dir.normalize(); + return PyObjectFrom(dir); +} + +PyObject* KX_MouseFocusSensor::pyattr_get_hit_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_MouseFocusSensor* self= static_cast(self_v); + + if(self->m_hitObject) + return self->m_hitObject->AddRef(); + + Py_RETURN_NONE; +} + +PyObject* KX_MouseFocusSensor::pyattr_get_hit_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_MouseFocusSensor* self= static_cast(self_v); + return PyObjectFrom(self->HitPosition()); +} + +PyObject* KX_MouseFocusSensor::pyattr_get_hit_normal(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_MouseFocusSensor* self= static_cast(self_v); + return PyObjectFrom(self->HitNormal()); +} + + + /* eof */ diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.h b/source/gameengine/Ketsji/KX_MouseFocusSensor.h index 804f34e6076..8de1f88c5c3 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.h +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.h @@ -54,7 +54,6 @@ class KX_MouseFocusSensor : public SCA_MouseSensor int starty, short int mousemode, int focusmode, - RAS_ICanvas* canvas, KX_Scene* kxscene, KX_KetsjiEngine* kxengine, SCA_IObject* gameobj, @@ -82,7 +81,10 @@ class KX_MouseFocusSensor : public SCA_MouseSensor bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data); bool NeedRayCast(KX_ClientObjectInfo* client) { return true; } - + const MT_Point3& RaySource() const; + const MT_Point3& RayTarget() const; + const MT_Point3& HitPosition() const; + const MT_Vector3& HitNormal() const; /* --------------------------------------------------------------------- */ /* Python interface ---------------------------------------------------- */ @@ -97,6 +99,14 @@ class KX_MouseFocusSensor : public SCA_MouseSensor KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetHitNormal); KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRayDirection); + /* attributes */ + static PyObject* pyattr_get_ray_source(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_ray_target(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_ray_direction(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_hit_object(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_hit_position(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_hit_normal(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + /* --------------------------------------------------------------------- */ SCA_IObject* m_hitObject; @@ -116,9 +126,13 @@ class KX_MouseFocusSensor : public SCA_MouseSensor */ bool m_positive_event; + /** + * Tests whether the object is in mouse focus for this camera + */ + bool ParentObjectHasFocusCamera(KX_Camera *cam); /** - * Tests whether the object is in mouse focus in this frame. + * Tests whether the object is in mouse focus in this scene. */ bool ParentObjectHasFocus(void); @@ -142,12 +156,6 @@ class KX_MouseFocusSensor : public SCA_MouseSensor * the object was hit. */ MT_Vector3 m_hitNormal; - - /** - * The active canvas. The size of this canvas determines a part of - * the start position of the picking ray. */ - RAS_ICanvas* m_gp_canvas; - /** * The KX scene that holds the camera. The camera position * determines a part of the start location of the picking ray. */ diff --git a/source/gameengine/PyDoc/KX_MouseFocusSensor.py b/source/gameengine/PyDoc/KX_MouseFocusSensor.py index ceab5b8c511..24f7716218b 100644 --- a/source/gameengine/PyDoc/KX_MouseFocusSensor.py +++ b/source/gameengine/PyDoc/KX_MouseFocusSensor.py @@ -8,46 +8,59 @@ class KX_MouseFocusSensor(SCA_MouseSensor): The mouse focus sensor works by transforming the mouse coordinates from 2d device space to 3d space then raycasting away from the camera. + + @ivar raySource: The worldspace source of the ray (the view position) + @type raySource: list (vector of 3 floats) + @ivar rayTarget: The worldspace target of the ray. + @type rayTarget: list (vector of 3 floats) + @ivar rayDirection: The L{rayTarget} - L{raySource} normalized. + @type rayDirection: list (normalized vector of 3 floats) + @ivar hitObject: the last object the mouse was over. + @type hitObject: L{KX_GameObject} or None + @ivar hitPosition: The worldspace position of the ray intersecton. + @type hitPosition: list (vector of 3 floats) + @ivar hitNormal: the worldspace normal from the face at point of intersection. + @type hitNormal: list (normalized vector of 3 floats) """ def getHitNormal(): """ - Returns the normal (in worldcoordinates) at the point of collision where the object was hit by this ray. - + Returns the normal (in worldcoordinates) at the point of collision where the object was hit by this ray. (B{deprecated}) + @rtype: list [x, y, z] @return: the ray collision normal. """ def getHitObject(): """ - Returns the object that was hit by this ray or None. + Returns the object that was hit by this ray or None. (B{deprecated}) @rtype: L{KX_GameObject} or None @return: the collision object. """ def getHitPosition(): """ - Returns the position (in worldcoordinates) at the point of collision where the object was hit by this ray. + Returns the position (in worldcoordinates) at the point of collision where the object was hit by this ray. (B{deprecated}) @rtype: list [x, y, z] @return: the ray collision position. """ def getRayDirection(): """ - Returns the normalized direction (in worldcoordinates) of the ray cast by the mouse. + Returns the normalized direction (in worldcoordinates) of the ray cast by the mouse. (B{deprecated}) @rtype: list [x, y, z] @return: the ray direction. """ def getRaySource(): """ - Returns the position (in worldcoordinates) the ray was cast from by the mouse. + Returns the position (in worldcoordinates) the ray was cast from by the mouse. (B{deprecated}) @rtype: list [x, y, z] @return: the ray source. """ def getRayTarget(): """ - Returns the target of the ray (in worldcoordinates) that seeks the focus object. + Returns the target of the ray (in worldcoordinates) that seeks the focus object. (B{deprecated}) @rtype: list [x, y, z] @return: the ray target. -- cgit v1.2.3 From f46f93ea139b52fa28e303216803222c61f4e451 Mon Sep 17 00:00:00 2001 From: Kent Mein Date: Wed, 15 Apr 2009 16:23:13 +0000 Subject: This is patch [#18408] Build issues with make on Cygwin hosted MinGW (2.48.1) submitted by Wayne Dennis adds an include, changes pythonlib and does a little cleaning of dlltool stuff. Kent --- source/gameengine/GamePlayer/common/windows/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'source/gameengine') diff --git a/source/gameengine/GamePlayer/common/windows/Makefile b/source/gameengine/GamePlayer/common/windows/Makefile index b0fb25f35b8..f35642f9651 100644 --- a/source/gameengine/GamePlayer/common/windows/Makefile +++ b/source/gameengine/GamePlayer/common/windows/Makefile @@ -50,6 +50,7 @@ CPPFLAGS += -I$(NAN_MOTO)/include CPPFLAGS += -I$(NAN_STRING)/include CPPFLAGS += -I$(NAN_BMFONT)/include CPPFLAGS += -I$(NAN_SOUNDSYSTEM)/include +CPPFLAGS += -I$(NAN_GLEW)/include # Blender stuff CPPFLAGS += -I$(SRCHOME)/blender/blenkernel -- cgit v1.2.3 From 52a3d5c518cb969dad321d6f0486d9f33dd95791 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 15 Apr 2009 19:20:12 +0000 Subject: BGE Python API Free python modules defined within the blendfile between loading scenes since they would end up accessing old GameLogic, Rasterizer modules as well as old game engine data in the module namespace which can cause problems. --- source/gameengine/Ketsji/KX_PythonInit.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 924c5451608..eafb7fc0cb8 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -102,7 +102,7 @@ extern "C" { #include "GPU_material.h" static void setSandbox(TPythonSecurityLevel level); - +static void clearGameModules(); // 'local' copy of canvas ptr, for window height/width python scripts static RAS_ICanvas* gp_Canvas = NULL; @@ -1402,6 +1402,10 @@ PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLev initPyTypes(); bpy_import_main_set(maggie); + + /* run this to clear game modules and user modules which + * may contain references to in game data */ + clearGameModules(); PyObject* moduleobj = PyImport_AddModule("__main__"); return PyModule_GetDict(moduleobj); @@ -1434,6 +1438,9 @@ static void clearGameModules() clearModule(modules, "Mathutils"); clearModule(modules, "BGL"); PyErr_Clear(); // incase some of these were alredy removed. + + /* clear user defined modules */ + importClearUserModules(); } void exitGamePythonScripting() -- cgit v1.2.3 From bbdaa03d6598a6f09e7272ade1ef96abf3ce1d53 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 15 Apr 2009 21:17:08 +0000 Subject: BGE bug #18168: Get local orientation of object using game engine python script system. Added localOrientation and worldOrientation. orientation attribute deprecated. Same for position and scaling. World attributes are read-only except for worldPosition. Add systematic check on NULL SGNode in all python functions. This is necessary to handle zombie objects (deleted by the game but kept alive by a reference in a list). --- source/gameengine/Ketsji/KX_GameObject.cpp | 171 +++++++++++++++++++---------- source/gameengine/Ketsji/KX_GameObject.h | 16 ++- source/gameengine/PyDoc/KX_GameObject.py | 21 +++- 3 files changed, 143 insertions(+), 65 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 36fb9142adc..283b78c2947 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -76,6 +76,10 @@ typedef unsigned long uint_ptr; #include "KX_SG_NodeRelationships.h" static MT_Point3 dummy_point= MT_Point3(0.0, 0.0, 0.0); +static MT_Vector3 dummy_scaling = MT_Vector3(1.0, 1.0, 1.0); +static MT_Matrix3x3 dummy_orientation = MT_Matrix3x3( 1.0, 0.0, 0.0, + 0.0, 1.0, 0.0, + 0.0, 0.0, 1.0); KX_GameObject::KX_GameObject( void* sgReplicationInfo, @@ -373,11 +377,14 @@ void KX_GameObject::ApplyTorque(const MT_Vector3& torque,bool local) void KX_GameObject::ApplyMovement(const MT_Vector3& dloc,bool local) { - if (m_pPhysicsController1) // (IsDynamic()) + if (GetSGNode()) { - m_pPhysicsController1->RelativeTranslate(dloc,local); + if (m_pPhysicsController1) // (IsDynamic()) + { + m_pPhysicsController1->RelativeTranslate(dloc,local); + } + GetSGNode()->RelativeTranslate(dloc,GetSGNode()->GetSGParent(),local); } - GetSGNode()->RelativeTranslate(dloc,GetSGNode()->GetSGParent(),local); } @@ -385,11 +392,13 @@ void KX_GameObject::ApplyMovement(const MT_Vector3& dloc,bool local) void KX_GameObject::ApplyRotation(const MT_Vector3& drot,bool local) { MT_Matrix3x3 rotmat(drot); + + if (GetSGNode()) { + GetSGNode()->RelativeRotate(rotmat,local); - GetSGNode()->RelativeRotate(rotmat,local); - - if (m_pPhysicsController1) { // (IsDynamic()) - m_pPhysicsController1->RelativeRotate(rotmat,local); + if (m_pPhysicsController1) { // (IsDynamic()) + m_pPhysicsController1->RelativeRotate(rotmat,local); + } } } @@ -402,16 +411,17 @@ double* KX_GameObject::GetOpenGLMatrix() { // todo: optimize and only update if necessary double* fl = m_OpenGL_4x4Matrix.getPointer(); - MT_Transform trans; + if (GetSGNode()) { + MT_Transform trans; - trans.setOrigin(GetSGNode()->GetWorldPosition()); - trans.setBasis(GetSGNode()->GetWorldOrientation()); + trans.setOrigin(GetSGNode()->GetWorldPosition()); + trans.setBasis(GetSGNode()->GetWorldOrientation()); - MT_Vector3 scaling = GetSGNode()->GetWorldScaling(); - m_bIsNegativeScaling = ((scaling[0] < 0.0) ^ (scaling[1] < 0.0) ^ (scaling[2] < 0.0)) ? true : false; - trans.scale(scaling[0], scaling[1], scaling[2]); - trans.getValue(fl); - + MT_Vector3 scaling = GetSGNode()->GetWorldScaling(); + m_bIsNegativeScaling = ((scaling[0] < 0.0) ^ (scaling[1] < 0.0) ^ (scaling[2] < 0.0)) ? true : false; + trans.scale(scaling[0], scaling[1], scaling[2]); + trans.getValue(fl); + } return fl; } @@ -442,13 +452,15 @@ static void UpdateBuckets_recursive(SG_Node* node) void KX_GameObject::UpdateBuckets( bool recursive ) { - double* fl = GetOpenGLMatrixPtr()->getPointer(); + if (GetSGNode()) { + double* fl = GetOpenGLMatrixPtr()->getPointer(); - for (size_t i=0;iUpdateBuckets(this, fl, m_bUseObjectColor, m_objectColor, m_bVisible, m_bCulled); + for (size_t i=0;iUpdateBuckets(this, fl, m_bUseObjectColor, m_objectColor, m_bVisible, m_bCulled); - if (recursive) { - UpdateBuckets_recursive(m_pSGNode); + if (recursive) { + UpdateBuckets_recursive(GetSGNode()); + } } } @@ -599,9 +611,11 @@ KX_GameObject::SetVisible( bool recursive ) { - m_bVisible = v; - if (recursive) - setVisible_recursive(m_pSGNode, v); + if (GetSGNode()) { + m_bVisible = v; + if (recursive) + setVisible_recursive(GetSGNode(), v); + } } static void setOccluder_recursive(SG_Node* node, bool v) @@ -627,9 +641,11 @@ KX_GameObject::SetOccluder( bool recursive ) { - m_bOccluder = v; - if (recursive) - setOccluder_recursive(m_pSGNode, v); + if (GetSGNode()) { + m_bOccluder = v; + if (recursive) + setOccluder_recursive(GetSGNode(), v); + } } void @@ -929,7 +945,9 @@ void KX_GameObject::NodeSetRelativeScale(const MT_Vector3& scale) void KX_GameObject::NodeSetWorldPosition(const MT_Point3& trans) { - SG_Node* parent = m_pSGNode->GetSGParent(); + if (!GetSGNode()) + return; + SG_Node* parent = GetSGNode()->GetSGParent(); if (parent != NULL) { // Make sure the objects have some scale @@ -964,13 +982,9 @@ void KX_GameObject::NodeUpdateGS(double time) const MT_Matrix3x3& KX_GameObject::NodeGetWorldOrientation() const { - static MT_Matrix3x3 defaultOrientation = MT_Matrix3x3( 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0); - // check on valid node in case a python controller holds a reference to a deleted object if (!GetSGNode()) - return defaultOrientation; + return dummy_orientation; return GetSGNode()->GetWorldOrientation(); } @@ -978,11 +992,9 @@ const MT_Matrix3x3& KX_GameObject::NodeGetWorldOrientation() const const MT_Vector3& KX_GameObject::NodeGetWorldScaling() const { - static MT_Vector3 defaultScaling = MT_Vector3(1.0, 1.0, 1.0); - // check on valid node in case a python controller holds a reference to a deleted object if (!GetSGNode()) - return defaultScaling; + return dummy_scaling; return GetSGNode()->GetWorldScaling(); } @@ -1091,13 +1103,19 @@ PyAttributeDef KX_GameObject::Attributes[] = { KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMax", KX_GameObject, pyattr_get_lin_vel_max, pyattr_set_lin_vel_max), KX_PYATTRIBUTE_RW_FUNCTION("visible", KX_GameObject, pyattr_get_visible, pyattr_set_visible), KX_PYATTRIBUTE_BOOL_RW ("occlusion", KX_GameObject, m_bOccluder), - KX_PYATTRIBUTE_RW_FUNCTION("position", KX_GameObject, pyattr_get_position, pyattr_set_position), + KX_PYATTRIBUTE_RW_FUNCTION("position", KX_GameObject, pyattr_get_worldPosition, pyattr_set_localPosition), KX_PYATTRIBUTE_RO_FUNCTION("localInertia", KX_GameObject, pyattr_get_localInertia), - KX_PYATTRIBUTE_RW_FUNCTION("orientation",KX_GameObject,pyattr_get_orientation,pyattr_set_orientation), - KX_PYATTRIBUTE_RW_FUNCTION("scaling", KX_GameObject, pyattr_get_scaling, pyattr_set_scaling), + KX_PYATTRIBUTE_RW_FUNCTION("orientation",KX_GameObject,pyattr_get_worldOrientation,pyattr_set_localOrientation), + KX_PYATTRIBUTE_RW_FUNCTION("scaling", KX_GameObject, pyattr_get_worldScaling, pyattr_set_localScaling), KX_PYATTRIBUTE_RW_FUNCTION("timeOffset",KX_GameObject, pyattr_get_timeOffset,pyattr_set_timeOffset), KX_PYATTRIBUTE_RW_FUNCTION("state", KX_GameObject, pyattr_get_state, pyattr_set_state), KX_PYATTRIBUTE_RO_FUNCTION("meshes", KX_GameObject, pyattr_get_meshes), + KX_PYATTRIBUTE_RW_FUNCTION("localOrientation",KX_GameObject,pyattr_get_localOrientation,pyattr_set_localOrientation), + KX_PYATTRIBUTE_RO_FUNCTION("worldOrientation",KX_GameObject,pyattr_get_worldOrientation), + KX_PYATTRIBUTE_RW_FUNCTION("localPosition", KX_GameObject, pyattr_get_localPosition, pyattr_set_localPosition), + KX_PYATTRIBUTE_RW_FUNCTION("worldPosition", KX_GameObject, pyattr_get_worldPosition, pyattr_set_worldPosition), + KX_PYATTRIBUTE_RW_FUNCTION("localScaling", KX_GameObject, pyattr_get_localScaling, pyattr_set_localScaling), + KX_PYATTRIBUTE_RO_FUNCTION("worldScaling", KX_GameObject, pyattr_get_worldScaling), KX_PYATTRIBUTE_RO_FUNCTION("__dict__", KX_GameObject, pyattr_get_dir_dict), @@ -1448,13 +1466,34 @@ int KX_GameObject::pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *at return 0; } -PyObject* KX_GameObject::pyattr_get_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +PyObject* KX_GameObject::pyattr_get_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_GameObject* self= static_cast(self_v); return PyObjectFrom(self->NodeGetWorldPosition()); } -int KX_GameObject::pyattr_set_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +int KX_GameObject::pyattr_set_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_GameObject* self= static_cast(self_v); + MT_Point3 pos; + if (!PyVecTo(value, pos)) + return 1; + + self->NodeSetWorldPosition(pos); + self->NodeUpdateGS(0.f); + return 0; +} + +PyObject* KX_GameObject::pyattr_get_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + if (self->GetSGNode()) + return PyObjectFrom(self->GetSGNode()->GetLocalPosition()); + else + return PyObjectFrom(dummy_point); +} + +int KX_GameObject::pyattr_set_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_GameObject* self= static_cast(self_v); MT_Point3 pos; @@ -1476,13 +1515,22 @@ PyObject* KX_GameObject::pyattr_get_localInertia(void *self_v, const KX_PYATTRIB return Py_BuildValue("fff", 0.0f, 0.0f, 0.0f); } -PyObject* KX_GameObject::pyattr_get_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +PyObject* KX_GameObject::pyattr_get_worldOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_GameObject* self= static_cast(self_v); return PyObjectFrom(self->NodeGetWorldOrientation()); } -int KX_GameObject::pyattr_set_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +PyObject* KX_GameObject::pyattr_get_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + if (self->GetSGNode()) + return PyObjectFrom(self->GetSGNode()->GetLocalOrientation()); + else + return PyObjectFrom(dummy_orientation); +} + +int KX_GameObject::pyattr_set_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_GameObject* self= static_cast(self_v); if (!PySequence_Check(value)) { @@ -1530,13 +1578,22 @@ int KX_GameObject::pyattr_set_orientation(void *self_v, const KX_PYATTRIBUTE_DEF return 1; } -PyObject* KX_GameObject::pyattr_get_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +PyObject* KX_GameObject::pyattr_get_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_GameObject* self= static_cast(self_v); return PyObjectFrom(self->NodeGetWorldScaling()); } -int KX_GameObject::pyattr_set_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +PyObject* KX_GameObject::pyattr_get_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_GameObject* self= static_cast(self_v); + if (self->GetSGNode()) + return PyObjectFrom(self->GetSGNode()->GetLocalScale()); + else + return PyObjectFrom(dummy_scaling); +} + +int KX_GameObject::pyattr_set_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_GameObject* self= static_cast(self_v); MT_Vector3 scale; @@ -1551,8 +1608,8 @@ int KX_GameObject::pyattr_set_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *at PyObject* KX_GameObject::pyattr_get_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_GameObject* self= static_cast(self_v); - SG_Node* sg_parent= self->GetSGNode()->GetSGParent(); /* GetSGNode() is valid or exception would be raised */ - if (sg_parent && sg_parent->IsSlowParent()) { + SG_Node* sg_parent; + if (self->GetSGNode() && (sg_parent = self->GetSGNode()->GetSGParent()) != NULL && sg_parent->IsSlowParent()) { return PyFloat_FromDouble(static_cast(sg_parent->GetParentRelation())->GetTimeOffset()); } else { return PyFloat_FromDouble(0.0); @@ -1562,16 +1619,16 @@ PyObject* KX_GameObject::pyattr_get_timeOffset(void *self_v, const KX_PYATTRIBUT int KX_GameObject::pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_GameObject* self= static_cast(self_v); - MT_Scalar val = PyFloat_AsDouble(value); - SG_Node* sg_parent= self->GetSGNode()->GetSGParent(); /* GetSGNode() is valid or exception would be raised */ - if (val < 0.0f) { /* also accounts for non float */ - PyErr_SetString(PyExc_AttributeError, "expected a float zero or above"); - return 1; + if (self->GetSGNode()) { + MT_Scalar val = PyFloat_AsDouble(value); + SG_Node* sg_parent= self->GetSGNode()->GetSGParent(); + if (val < 0.0f) { /* also accounts for non float */ + PyErr_SetString(PyExc_AttributeError, "expected a float zero or above"); + return 1; + } + if (sg_parent && sg_parent->IsSlowParent()) + static_cast(sg_parent->GetParentRelation())->SetTimeOffset(val); } - - if (sg_parent && sg_parent->IsSlowParent()) - static_cast(sg_parent->GetParentRelation())->SetTimeOffset(val); - return 0; } @@ -2092,6 +2149,8 @@ PyObject* KX_GameObject::PyRemoveParent(PyObject* self) static void walk_children(SG_Node* node, CListValue* list, bool recursive) { + if (!node) + return; NodeList& children = node->GetSGChildren(); for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) @@ -2122,7 +2181,7 @@ PyObject* KX_GameObject::PyGetChildren(PyObject* self) PyObject* KX_GameObject::PyGetChildrenRecursive(PyObject* self) { CListValue* list = new CListValue(); - walk_children(m_pSGNode, list, 1); + walk_children(GetSGNode(), list, 1); return list; } diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 0bf3e60f34b..cf0c0e6b0f5 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -880,14 +880,18 @@ public: static int pyattr_set_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - static PyObject* pyattr_get_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); - static int pyattr_set_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - static PyObject* pyattr_get_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); - static int pyattr_set_orientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - static PyObject* pyattr_get_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); - static int pyattr_set_scaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_worldOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static PyObject* pyattr_get_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index 4aa9de2fe86..21ddf439924 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -39,11 +39,26 @@ class KX_GameObject: # (SCA_IObject) @ivar occlusion: occlusion capability flag. @type occlusion: boolean @ivar position: The object's position. - @type position: list [x, y, z] + DEPRECATED: use localPosition and worldPosition + @type position: list [x, y, z] On write: local position, on read: world position @ivar orientation: The object's orientation. 3x3 Matrix. You can also write a Quaternion or Euler vector. - @type orientation: 3x3 Matrix [[float]] + DEPRECATED: use localOrientation and worldOrientation + @type orientation: 3x3 Matrix [[float]] On write: local orientation, on read: world orientation @ivar scaling: The object's scaling factor. list [sx, sy, sz] - @type scaling: list [sx, sy, sz] + DEPRECATED: use localScaling and worldScaling + @type scaling: list [sx, sy, sz] On write: local scaling, on read: world scaling + @ivar localOrientation: The object's local orientation. 3x3 Matrix. You can also write a Quaternion or Euler vector. + @type localOrientation: 3x3 Matrix [[float]] + @ivar worldOrientation: The object's world orientation. Read-only. + @type worldOrientation: 3x3 Matrix [[float]] + @ivar localScaling: The object's local scaling factor. + @type localScaling: list [sx, sy, sz] + @ivar worldScaling: The object's world scaling factor. Read-only + @type worldScaling: list [sx, sy, sz] + @ivar localPosition: The object's local position. + @type localPosition: list [x, y, z] + @ivar worldPosition: The object's world position. + @type worldPosition: list [x, y, z] @ivar timeOffset: adjust the slowparent delay at runtime. @type timeOffset: float @ivar state: the game object's state bitmask, using the first 30 bits, one bit must always be set. -- cgit v1.2.3 From 32253dfaaf43751037d4dcabd834e812902d6538 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 16 Apr 2009 06:24:47 +0000 Subject: bpy_internal_import.c should build with py2.3 now, also gave bpy_internal_import functions better names. --- source/gameengine/Ketsji/KX_PythonInit.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index eafb7fc0cb8..7643a043a7c 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1244,7 +1244,7 @@ PyObject *KXpy_import(PyObject *self, PyObject *args) } /* Import blender texts as python modules */ - m= importText(name, &found); + m= bpy_text_import(name, &found); if (m) return m; @@ -1267,10 +1267,10 @@ PyObject *KXpy_reload(PyObject *self, PyObject *args) { PyObject *newmodule = NULL; /* check for a module arg */ - if( !PyArg_ParseTuple( args, "O:bpy_reload", &module ) ) + if( !PyArg_ParseTuple( args, "O:bpy_reload_meth", &module ) ) return NULL; - newmodule= reimportText( module, &found ); + newmodule= bpy_text_reimport( module, &found ); if (newmodule) return newmodule; @@ -1353,8 +1353,8 @@ void setSandbox(TPythonSecurityLevel level) */ default: /* Allow importing internal text, from bpy_internal_import.py */ - PyDict_SetItemString(d, "reload", item=PyCFunction_New(bpy_reload, NULL)); Py_DECREF(item); - PyDict_SetItemString(d, "__import__", item=PyCFunction_New(bpy_import, NULL)); Py_DECREF(item); + PyDict_SetItemString(d, "reload", item=PyCFunction_New(bpy_reload_meth, NULL)); Py_DECREF(item); + PyDict_SetItemString(d, "__import__", item=PyCFunction_New(bpy_import_meth, NULL)); Py_DECREF(item); break; } } @@ -1440,7 +1440,7 @@ static void clearGameModules() PyErr_Clear(); // incase some of these were alredy removed. /* clear user defined modules */ - importClearUserModules(); + bpy_text_clear_modules(); } void exitGamePythonScripting() -- cgit v1.2.3 From 2c491b5d2e6db52e526a39e3040c59db4edd25de Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Thu, 16 Apr 2009 20:13:13 +0000 Subject: BGE: slow parent was causing scaling distortion, now use correct quaternion interpolation. --- .../gameengine/Ketsji/KX_SG_NodeRelationships.cpp | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp b/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp index 87ff3b53911..c3b0c21c8e0 100644 --- a/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp +++ b/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp @@ -235,23 +235,12 @@ UpdateChildCoordinates( // now 'interpolate' the normal coordinates with the last // world coordinates to get the new world coordinates. - // problem 1: - // The child world scale needs to be initialized in some way for this - // to make sense - // problem 2: - // This is way of doing interpolation is nonsense - - int i; - MT_Scalar weight = MT_Scalar(1)/(m_relax + 1); - for (i=0;i <3 ;i++) { - child_w_scale[i] = (m_relax * child_w_scale[i] + child_n_scale[i]) * weight; - child_w_pos[i] = (m_relax * child_w_pos[i] + child_n_pos[i]) * weight; - child_w_rotation[0][i] = (m_relax * child_w_rotation[0][i] + child_n_rotation[0][i]) * weight; - child_w_rotation[1][i] = (m_relax * child_w_rotation[1][i] + child_n_rotation[1][i]) * weight; - child_w_rotation[2][i] = (m_relax * child_w_rotation[2][i] + child_n_rotation[2][i]) * weight; - } - + child_w_scale = (m_relax * child_w_scale + child_n_scale) * weight; + child_w_pos = (m_relax * child_w_pos + child_n_pos) * weight; + // for rotation we must go through quaternion + MT_Quaternion child_w_quat = child_w_rotation.getRotation().slerp(child_n_rotation.getRotation(), weight); + child_w_rotation.setRotation(child_w_quat); //FIXME: update physics controller. } else { child_w_scale = child_n_scale; -- cgit v1.2.3 From 1dd980768d6f8c808e88251572a6bc503a2b905e Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Fri, 17 Apr 2009 10:24:44 +0000 Subject: Missing for abs() made this file not compile for me. --- source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp index eaffd483d70..c300baa9bd4 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp +++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp @@ -29,6 +29,7 @@ #endif #include +#include #include "SCA_Joystick.h" #include "SCA_JoystickPrivate.h" -- cgit v1.2.3 From 90c6cf77f10961de756f6ff06329d3fa65ce3da4 Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Fri, 17 Apr 2009 13:42:40 +0000 Subject: Fixing SND_Scene.h missing include problems with cmake + bullet --- source/gameengine/Physics/Bullet/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Physics/Bullet/CMakeLists.txt b/source/gameengine/Physics/Bullet/CMakeLists.txt index 2cb2a540d97..ec2cdede683 100644 --- a/source/gameengine/Physics/Bullet/CMakeLists.txt +++ b/source/gameengine/Physics/Bullet/CMakeLists.txt @@ -34,7 +34,7 @@ SET(INC ../../../../intern/moto/include ../../../kernel/gen_system ../../../../intern/string - ../../../intern/SoundSystem + ../../../../intern/SoundSystem ../../Rasterizer ../../Ketsji ../../Expressions -- cgit v1.2.3 From df8cf26404c7e922751643b1095e38f1ab430811 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 17 Apr 2009 20:06:06 +0000 Subject: Added m_zombie to the base python class (PyObjectPlus), when this is set all the subclasses will raise an error on access to their members. Other small changes... - KX_Camera and KX_Light didnt have get/setitem access in their PyType definition. - CList.from_id() error checking for a long was checking for -1 against an unsigned value (own fault) - CValue::SpecialRelease was incrementing an int for no reason. - renamed m_attrlist to m_attr_dict since its a PyDict type. - removed custom getattro/setattro functions for KX_Scene and KX_GameObject, use py_base_getattro, py_base_setattro for all subclasses of PyObjectPlus. - lowercase windows.h in VideoBase.cpp for cross compiling. --- source/gameengine/Expressions/ListValue.cpp | 2 +- source/gameengine/Expressions/PyObjectPlus.cpp | 20 ++- source/gameengine/Expressions/PyObjectPlus.h | 56 ++++++- source/gameengine/Expressions/Value.cpp | 7 + source/gameengine/Expressions/Value.h | 10 +- .../gameengine/GameLogic/SCA_PropertyActuator.cpp | 2 +- source/gameengine/Ketsji/KX_Camera.cpp | 22 ++- source/gameengine/Ketsji/KX_GameObject.cpp | 179 ++++++++------------- source/gameengine/Ketsji/KX_GameObject.h | 26 +-- source/gameengine/Ketsji/KX_Light.cpp | 15 +- source/gameengine/Ketsji/KX_Scene.cpp | 68 ++++++-- source/gameengine/Ketsji/KX_Scene.h | 26 +-- source/gameengine/VideoTexture/VideoBase.cpp | 2 +- 13 files changed, 233 insertions(+), 202 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 0f163ad07c1..37feba38f8b 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -513,7 +513,7 @@ PyObject* CListValue::Pyfrom_id(PyObject* self, PyObject* value) BGE_ID_TYPE id= PyLong_FromUnsignedLongLong(value); #endif - if (id==-1 && PyErr_Occurred()) + if (PyErr_Occurred()) return NULL; int numelem = GetCount(); diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 33335ebef3e..0db2e8991fc 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -88,6 +88,7 @@ PyObjectPlus::PyObjectPlus(PyTypeObject *T) // constructor MT_assert(T != NULL); this->ob_type = T; _Py_NewReference(this); + SetZombie(false); }; /*------------------------------ @@ -99,9 +100,15 @@ PyMethodDef PyObjectPlus::Methods[] = { }; PyAttributeDef PyObjectPlus::Attributes[] = { + KX_PYATTRIBUTE_RO_FUNCTION("isValid", PyObjectPlus, pyattr_get_is_valid), {NULL} //Sentinel }; +PyObject* PyObjectPlus::pyattr_get_is_valid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + Py_RETURN_TRUE; +} + /*------------------------------ * PyObjectPlus Parents -- Every class, even the abstract one should have parents ------------------------------*/ @@ -117,10 +124,19 @@ PyObject *PyObjectPlus::py_getattro(PyObject* attr) if (strcmp(PyString_AsString(attr), "__dict__")==0) { return py_getattr_dict(NULL, Type.tp_dict); /* no Attributes yet */ } - PyErr_SetString(PyExc_AttributeError, "attribute not found"); + PyErr_Format(PyExc_AttributeError, "attribute \"%s\" not found", PyString_AsString(attr)); return NULL; } else { - return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); \ + /* Copied from py_getattro_up */ + if (PyCObject_Check(descr)) { + return py_get_attrdef((void *)this, (const PyAttributeDef*)PyCObject_AsVoidPtr(descr)); + } else if (descr->ob_type->tp_descr_get) { + return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); + } else { + fprintf(stderr, "Unknown attribute type (PyObjectPlus::py_getattro)"); + return descr; + } + /* end py_getattro_up copy */ } //if (streq(attr, "type")) // return Py_BuildValue("s", (*(GetParents()))->tp_name); diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index ea26ea1d201..58a74e4ca74 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -400,10 +400,11 @@ class PyObjectPlus : public PyObject public: PyObjectPlus(PyTypeObject *T); + bool m_zombie; virtual ~PyObjectPlus(); // destructor static void PyDestructor(PyObject *P) // python wrapper - { + { delete ((PyObjectPlus *) P); }; @@ -417,6 +418,14 @@ public: virtual PyObject *py_getattro(PyObject *attr); // py_getattro method static PyObject *py_base_getattro(PyObject * self, PyObject *attr) // This should be the entry in Type. { + if (((PyObjectPlus*)self)->IsZombie()) { + if (!strcmp(PyString_AsString(attr), "isValid")) { + Py_RETURN_FALSE; + } + ((PyObjectPlus*)self)->IsZombiePyErr(); /* raise an error */ + return NULL; + } + return ((PyObjectPlus*) self)->py_getattro(attr); } @@ -432,10 +441,16 @@ public: virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method static int py_base_setattro(PyObject *self, PyObject *attr, PyObject *value) // the PyType should reference this { + if (((PyObjectPlus*)self)->IsZombie()) { + /* you cant set isValid anyway */ + ((PyObjectPlus*)self)->IsZombiePyErr(); + return -1; + } + if (value==NULL) - return ((PyObjectPlus*) self)->py_delattro(attr); + return ((PyObjectPlus*)self)->py_delattro(attr); - return ((PyObjectPlus*) self)->py_setattro(attr, value); + return ((PyObjectPlus*)self)->py_setattro(attr, value); } virtual PyObject *py_repr(void); // py_repr method @@ -452,6 +467,41 @@ public: { return ((PyObjectPlus*)self)->Py_isA(value); } + + /* Kindof dumb, always returns True, the false case is checked for, before this function gets accessed */ + static PyObject* pyattr_get_is_valid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + + bool IsZombie() + { + return m_zombie; + } + + bool IsZombiePyErr() + { + if(m_zombie) { + /* + PyObject *this_pystr = PyObject_Repr(this); + + PyErr_Format( + PyExc_RuntimeError, + "\"%s\" of type \"%s\" has been freed by the blender game engine, " + "scripts cannot access this anymore, check for this case with the \"isValid\" attribute", + PyString_AsString(this_pystr), ob_type->tp_name ); + + Py_DECREF(this_pystr); + */ + + PyErr_SetString(PyExc_RuntimeError, "This value has been freed by the blender game engine but python is still holding a reference, this value cant be used."); + } + + return m_zombie; + } + + void SetZombie(bool is_zombie) + { + m_zombie= is_zombie; + } + }; PyObject *py_getattr_dict(PyObject *pydict, PyObject *tp_dict); diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index b8b7a05aa64..e969f0c33aa 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -602,6 +602,12 @@ int CValue::Release() // Decrease local reference count, if it reaches 0 the object should be freed if (--m_refcount > 0) { + // Benoit suggest this as a way to automatically set the zombie flag, but I couldnt get it working - Campbell + /* + if (m_refcount == 1 && ob_refcnt > 1) + SetZombie(true); // the remaining refcount is held by Python!! + */ + // Reference count normal, return new reference count return m_refcount; } @@ -609,6 +615,7 @@ int CValue::Release() { // Reference count reached 0, delete ourselves and return 0 // MT_assert(m_refcount==0, "Reference count reached sub-zero, object released too much"); + delete this; return 0; } diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h index 4cdc80dc9bd..bcee355cda2 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/Value.h @@ -219,7 +219,7 @@ public: //static PyObject* PyMake(PyObject*,PyObject*); virtual PyObject *py_repr(void) { - return Py_BuildValue("s",(const char*)GetText()); + return PyString_FromString((const char*)GetText()); } @@ -228,14 +228,10 @@ public: void SpecialRelease() { - int i=0; - if (ob_refcnt == 0) + if (ob_refcnt == 0) /* make sure python always holds a reference */ { _Py_NewReference(this); - } else - { - i++; } Release(); } @@ -280,6 +276,7 @@ public: int GetRefCount() { return m_refcount; } virtual CValue* AddRef(); // Add a reference to this value virtual int Release(); // Release a reference to this value (when reference count reaches 0, the value is removed from the heap) + /// Property Management virtual void SetProperty(const STR_String& name,CValue* ioProperty); // Set property , overwrites and releases a previous property with the same name if needed @@ -355,6 +352,7 @@ private: std::map* m_pNamedPropertyArray; // Properties for user/game etc ValueFlags m_ValFlags; // Frequently used flags in a bitfield (low memoryusage) int m_refcount; // Reference Counter + bool m_zombie; // Object is invalid put its still being referenced (by python) static double m_sZeroVec[3]; static bool m_ignore_deprecation_warnings; diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index 359ab8adac6..9dbdc0e89d1 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -95,7 +95,7 @@ bool SCA_PropertyActuator::Update() } newval->Release(); } - else if (userexpr = parser.ProcessText(m_exprtxt)) { + else if ((userexpr = parser.ProcessText(m_exprtxt))) { switch (m_type) { diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index befc8462aa3..daa37056d68 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -517,13 +517,20 @@ PyTypeObject KX_Camera::Type = { 0, 0, py_base_repr, - 0,0,0,0,0,0, + 0,0, + &KX_GameObject::Mapping, + 0,0,0, py_base_getattro, py_base_setattro, 0,0,0,0,0,0,0,0,0, Methods }; + + + + + PyParentObject KX_Camera::Parents[] = { &KX_Camera::Type, &KX_GameObject::Type, @@ -534,22 +541,11 @@ PyParentObject KX_Camera::Parents[] = { PyObject* KX_Camera::py_getattro(PyObject *attr) { - if (ValidPythonToGameObject(this)==false) { - if (!strcmp(PyString_AsString(attr), "isValid")) { - PyErr_Clear(); - Py_RETURN_FALSE; - } - return NULL; /* ValidPythonToGameObject sets the error */ - } - py_getattro_up(KX_GameObject); } int KX_Camera::py_setattro(PyObject *attr, PyObject *value) -{ - if (ValidPythonToGameObject(this)==false) - return -1; - +{ py_setattro_up(KX_GameObject); } diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 283b78c2947..3e7c99dc472 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -103,7 +103,7 @@ KX_GameObject::KX_GameObject( m_xray(false), m_pHitObject(NULL), m_isDeformable(false), - m_attrlist(NULL) + m_attr_dict(NULL) { m_ignore_activity_culling = false; m_pClient_info = new KX_ClientObjectInfo(this, KX_ClientObjectInfo::ACTOR); @@ -146,9 +146,9 @@ KX_GameObject::~KX_GameObject() delete m_pGraphicController; } - if (m_attrlist) { - PyDict_Clear(m_attrlist); /* incase of circular refs or other weired cases */ - Py_DECREF(m_attrlist); + if (m_attr_dict) { + PyDict_Clear(m_attr_dict); /* incase of circular refs or other weired cases */ + Py_DECREF(m_attr_dict); } } @@ -339,8 +339,8 @@ void KX_GameObject::ProcessReplica(KX_GameObject* replica) replica->m_pClient_info = new KX_ClientObjectInfo(*m_pClient_info); replica->m_pClient_info->m_gameobject = replica; replica->m_state = 0; - if(m_attrlist) - replica->m_attrlist= PyDict_Copy(m_attrlist); + if(m_attr_dict) + replica->m_attr_dict= PyDict_Copy(m_attr_dict); } @@ -1123,9 +1123,6 @@ PyAttributeDef KX_GameObject::Attributes[] = { KX_PYATTRIBUTE_RO_FUNCTION("sensors", KX_GameObject, pyattr_get_sensors), KX_PYATTRIBUTE_RO_FUNCTION("controllers", KX_GameObject, pyattr_get_controllers), KX_PYATTRIBUTE_RO_FUNCTION("actuators", KX_GameObject, pyattr_get_actuators), - - KX_PYATTRIBUTE_RO_FUNCTION("isValid", KX_GameObject, pyattr_get_is_valid), - {NULL} //Sentinel }; @@ -1190,14 +1187,15 @@ Py_ssize_t KX_GameObject::Map_Len(PyObject* self_v) { KX_GameObject* self= static_cast(self_v); - if (ValidPythonToGameObject(self)==false) { + if (self->IsZombie()) /* not sure what to do here */ + { PyErr_Clear(); return 0; } Py_ssize_t len= self->GetPropertyCount(); - if(self->m_attrlist) - len += PyDict_Size(self->m_attrlist); + if(self->m_attr_dict) + len += PyDict_Size(self->m_attr_dict); return len; } @@ -1209,7 +1207,7 @@ PyObject *KX_GameObject::Map_GetItem(PyObject *self_v, PyObject *item) CValue* resultattr; PyObject* pyconvert; - if (ValidPythonToGameObject(self)==false) + if (self->IsZombiePyErr()) return NULL; /* first see if the attributes a string and try get the cvalue attribute */ @@ -1217,8 +1215,8 @@ PyObject *KX_GameObject::Map_GetItem(PyObject *self_v, PyObject *item) pyconvert = resultattr->ConvertValueToPython(); return pyconvert ? pyconvert:resultattr; } - /* no CValue attribute, try get the python only m_attrlist attribute */ - else if (self->m_attrlist && (pyconvert=PyDict_GetItem(self->m_attrlist, item))) { + /* no CValue attribute, try get the python only m_attr_dict attribute */ + else if (self->m_attr_dict && (pyconvert=PyDict_GetItem(self->m_attr_dict, item))) { if (attr_str) PyErr_Clear(); @@ -1241,7 +1239,7 @@ int KX_GameObject::Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val) if(attr_str==NULL) PyErr_Clear(); - if (ValidPythonToGameObject(self)==false) + if (self->IsZombiePyErr()) return -1; if (val==NULL) { /* del ob["key"] */ @@ -1251,15 +1249,15 @@ int KX_GameObject::Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val) if(attr_str) del |= (self->RemoveProperty(attr_str)==true) ? 1:0; - if(self->m_attrlist) - del |= (PyDict_DelItem(self->m_attrlist, key)==0) ? 1:0; + if(self->m_attr_dict) + del |= (PyDict_DelItem(self->m_attr_dict, key)==0) ? 1:0; if (del==0) { if(attr_str) PyErr_Format(PyExc_KeyError, "KX_GameObject key \"%s\" not found", attr_str); else PyErr_SetString(PyExc_KeyError, "KX_GameObject key not found"); return -1; } - else if (self->m_attrlist) { + else if (self->m_attr_dict) { PyErr_Clear(); /* PyDict_DelItem sets an error when it fails */ } } @@ -1284,8 +1282,8 @@ int KX_GameObject::Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val) set= 1; /* try remove dict value to avoid double ups */ - if (self->m_attrlist){ - if (PyDict_DelItem(self->m_attrlist, key) != 0) + if (self->m_attr_dict){ + if (PyDict_DelItem(self->m_attr_dict, key) != 0) PyErr_Clear(); } } @@ -1296,11 +1294,11 @@ int KX_GameObject::Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val) if(set==0) { - if (self->m_attrlist==NULL) /* lazy init */ - self->m_attrlist= PyDict_New(); + if (self->m_attr_dict==NULL) /* lazy init */ + self->m_attr_dict= PyDict_New(); - if(PyDict_SetItem(self->m_attrlist, key, val)==0) + if(PyDict_SetItem(self->m_attr_dict, key, val)==0) { if(attr_str) self->RemoveProperty(attr_str); /* overwrite the CValue if it exists */ @@ -1343,8 +1341,8 @@ PyTypeObject KX_GameObject::Type = { 0,0, &Mapping, 0,0,0, - py_base_getattro_gameobject, - py_base_setattro_gameobject, + py_base_getattro, + py_base_setattro, 0,0,0,0,0,0,0,0,0, Methods }; @@ -1675,11 +1673,6 @@ PyObject* KX_GameObject::pyattr_get_meshes(void *self_v, const KX_PYATTRIBUTE_DE return meshes; } -PyObject* KX_GameObject::pyattr_get_is_valid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) -{ - Py_RETURN_TRUE; -} - /* experemental! */ PyObject* KX_GameObject::pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { @@ -1741,47 +1734,36 @@ PyObject* KX_GameObject::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_ Py_DECREF(list); - /* Add m_attrlist if we have it */ - if(self->m_attrlist) - PyDict_Update(dict, self->m_attrlist); + /* Add m_attr_dict if we have it */ + if(self->m_attr_dict) + PyDict_Update(dict, self->m_attr_dict); return dict; } -PyObject* KX_GameObject::py_getattro(PyObject *attr) +/* We need these because the macros have a return in them */ +PyObject* KX_GameObject::py_getattro__internal(PyObject *attr) { py_getattro_up(SCA_IObject); } -int KX_GameObject::py_setattro(PyObject *attr, PyObject *value) // py_setattro method +int KX_GameObject::py_setattro__internal(PyObject *attr, PyObject *value) // py_setattro method { py_setattro_up(SCA_IObject); } -/* we need our own getattr and setattr types */ -/* See m_attrlist definition for rules on how this works */ -PyObject *KX_GameObject::py_base_getattro_gameobject(PyObject * self, PyObject *attr) +PyObject* KX_GameObject::py_getattro(PyObject *attr) { - if(((KX_GameObject *) self)->GetSGNode()==NULL) { - if (!strcmp(PyString_AsString(attr), "isValid")) { - PyErr_Clear(); - Py_INCREF(Py_False); - return Py_False; - } - - ValidPythonToGameObject(((KX_GameObject *) self)); // we know its invalid, just get the error - return NULL; - } - - PyObject *object= ((KX_GameObject *) self)->py_getattro(attr); + PyObject *object= py_getattro__internal(attr); - if (object==NULL && ((KX_GameObject *) self)->m_attrlist) { + if (object==NULL && m_attr_dict) + { /* backup the exception incase the attr doesnt exist in the dict either */ PyObject *err_type, *err_value, *err_tb; PyErr_Fetch(&err_type, &err_value, &err_tb); - object= PyDict_GetItem(((KX_GameObject *) self)->m_attrlist, attr); + object= PyDict_GetItem(m_attr_dict, attr); if (object) { Py_INCREF(object); @@ -1797,62 +1779,33 @@ PyObject *KX_GameObject::py_base_getattro_gameobject(PyObject * self, PyObject * return object; } -int KX_GameObject::py_base_setattro_gameobject(PyObject * self, PyObject *attr, PyObject *value) +int KX_GameObject::py_setattro(PyObject *attr, PyObject *value) // py_setattro method { int ret; - /* Delete the item */ - if (value==NULL) - { - ret= ((PyObjectPlus*) self)->py_delattro(attr); - - if (ret != 0) /* CValue attribute failed, try KX_GameObject m_attrlist dict */ - { - if (((KX_GameObject *) self)->m_attrlist) - { - /* backup the exception incase the attr doesnt exist in the dict either */ - PyObject *err_type, *err_value, *err_tb; - PyErr_Fetch(&err_type, &err_value, &err_tb); - - if (PyDict_DelItem(((KX_GameObject *) self)->m_attrlist, attr) == 0) - { - ret= 0; - PyErr_Clear(); - Py_XDECREF( err_type ); - Py_XDECREF( err_value ); - Py_XDECREF( err_tb ); - } - else { - PyErr_Restore(err_type, err_value, err_tb); /* use the error from the parent function */ - } - } - } - return ret; - } - - - ret= ((PyObjectPlus*) self)->py_setattro(attr, value); + ret= py_setattro__internal(attr, value); if (ret==PY_SET_ATTR_SUCCESS) { /* remove attribute in our own dict to avoid double ups */ - if (((KX_GameObject *) self)->m_attrlist) { - if (PyDict_DelItem(((KX_GameObject *) self)->m_attrlist, attr) != 0) + /* NOTE: Annoying that we also do this for setting builtin attributes like mass and visibility :/ */ + if (m_attr_dict) { + if (PyDict_DelItem(m_attr_dict, attr) != 0) PyErr_Clear(); } } if (ret==PY_SET_ATTR_COERCE_FAIL) { - /* CValue attribute exists, remove and add dict value */ - ((KX_GameObject *) self)->RemoveProperty(STR_String(PyString_AsString(attr))); + /* CValue attribute exists, remove CValue and add PyDict value */ + RemoveProperty(STR_String(PyString_AsString(attr))); ret= PY_SET_ATTR_MISSING; } if (ret==PY_SET_ATTR_MISSING) { /* Lazy initialization */ - if (((KX_GameObject *) self)->m_attrlist==NULL) - ((KX_GameObject *) self)->m_attrlist = PyDict_New(); + if (m_attr_dict==NULL) + m_attr_dict = PyDict_New(); - if (PyDict_SetItem(((KX_GameObject *) self)->m_attrlist, attr, value)==0) { + if (PyDict_SetItem(m_attr_dict, attr, value)==0) { PyErr_Clear(); ret= PY_SET_ATTR_SUCCESS; } @@ -1862,9 +1815,25 @@ int KX_GameObject::py_base_setattro_gameobject(PyObject * self, PyObject *attr, } } - return ret; + return ret; } + +int KX_GameObject::py_delattro(PyObject *attr) +{ + char *attr_str= PyString_AsString(attr); + + if (RemoveProperty(STR_String(attr_str))) // XXX - should call CValues instead but its only 2 lines here + return 0; + + if (m_attr_dict && (PyDict_DelItem(m_attr_dict, attr) == 0)) + return 0; + + PyErr_Format(PyExc_AttributeError, "attribute \"%s\" dosnt exist", attr_str); + return 1; +} + + PyObject* KX_GameObject::PyApplyForce(PyObject* self, PyObject* args) { int local = 0; @@ -2374,11 +2343,11 @@ PyObject* KX_GameObject::PyGetPropertyNames(PyObject* self) { PyObject *list= ConvertKeysToPython(); - if(m_attrlist) { + if(m_attr_dict) { PyObject *key, *value; Py_ssize_t pos = 0; - while (PyDict_Next(m_attrlist, &pos, &key, &value)) { + while (PyDict_Next(m_attr_dict, &pos, &key, &value)) { PyList_Append(list, key); } } @@ -2685,8 +2654,8 @@ KX_PYMETHODDEF_DOC_VARARGS(KX_GameObject, sendMessage, "to = Name of object to send the message to") { char* subject; - char* body = ""; - char* to = ""; + char* body = (char *)""; + char* to = (char *)""; const STR_String& from = GetName(); if (!PyArg_ParseTuple(args, "s|sss:sendMessage", &subject, &body, &to)) @@ -2753,7 +2722,7 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py *object = static_cast(value); /* sets the error */ - if (ValidPythonToGameObject(*object)==false) + if ((*object)->IsZombiePyErr()) return false; return true; @@ -2769,17 +2738,3 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py return false; } - -bool ValidPythonToGameObject(KX_GameObject *object) -{ - if (object->GetSGNode()==NULL) { - PyErr_Format( - PyExc_RuntimeError, - "KX_GameObject \"%s\" is not longer in a scene, " - "check for this case with the \"isValid\" attribute", - object->GetName().ReadPtr() ); - return false; - } - - return true; -} \ No newline at end of file diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index cf0c0e6b0f5..dd85c2f2faa 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -62,7 +62,6 @@ struct Object; /* utility conversion function */ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok); -bool ValidPythonToGameObject(KX_GameObject *object); /** * KX_GameObject is the main class for dynamic objects. @@ -119,15 +118,15 @@ public: // these can be used with property actuators // // For the python API, For types that cannot be converted into CValues (lists, dicts, GameObjects) - // these will be put into "m_attrlist", logic bricks cannot access them. + // these will be put into "m_attr_dict", logic bricks cannot access them. // // rules for setting attributes. // - // * there should NEVER be a CValue and a m_attrlist attribute with matching names. get/sets make sure of this. - // * if CValue conversion fails, use a PyObject in "m_attrlist" - // * when assigning a value, first see if it can be a CValue, if it can remove the "m_attrlist" and set the CValue + // * there should NEVER be a CValue and a m_attr_dict attribute with matching names. get/sets make sure of this. + // * if CValue conversion fails, use a PyObject in "m_attr_dict" + // * when assigning a value, first see if it can be a CValue, if it can remove the "m_attr_dict" and set the CValue // - PyObject* m_attrlist; + PyObject* m_attr_dict; virtual void /* This function should be virtual - derived classed override it */ Relink( @@ -814,16 +813,21 @@ public: virtual PyObject* py_getattro(PyObject *attr); virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method + virtual int py_delattro(PyObject *attr); virtual PyObject* py_repr(void) { - if (ValidPythonToGameObject(this)==false) + if (IsZombiePyErr()) return NULL; return PyString_FromString(GetName().ReadPtr()); } - static PyObject *py_base_getattro_gameobject(PyObject * self, PyObject *attr); - static int py_base_setattro_gameobject(PyObject * self, PyObject *attr, PyObject *value); + /* quite annoying that we need these but the bloody + * py_getattro_up and py_setattro_up macro's have a returns in them! */ + PyObject* py_getattro__internal(PyObject *attr); + int py_setattro__internal(PyObject *attr, PyObject *value); // py_setattro method + + KX_PYMETHOD_NOARGS(KX_GameObject,GetPosition); KX_PYMETHOD_O(KX_GameObject,SetPosition); KX_PYMETHOD_O(KX_GameObject,SetWorldPosition); @@ -897,7 +901,6 @@ public: static PyObject* pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_meshes(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); - static PyObject* pyattr_get_is_valid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); /* for dir(), python3 uses __dir__() */ static PyObject* pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); @@ -913,7 +916,6 @@ public: static PyObject* Map_GetItem(PyObject *self_v, PyObject *item); static int Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val); - private : /** @@ -931,5 +933,7 @@ private : }; + + #endif //__KX_GAMEOBJECT diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp index 0fcd2c39078..29033c2d802 100644 --- a/source/gameengine/Ketsji/KX_Light.cpp +++ b/source/gameengine/Ketsji/KX_Light.cpp @@ -177,14 +177,6 @@ PyObject* KX_LightObject::py_getattro(PyObject *attr) { char *attr_str= PyString_AsString(attr); - if (ValidPythonToGameObject(this)==false) { - if (!strcmp(attr_str, "isValid")) { - PyErr_Clear(); - Py_RETURN_FALSE; - } - return NULL; - } - if (!strcmp(attr_str, "layer")) return PyInt_FromLong(m_lightobj.m_layer); @@ -229,9 +221,6 @@ int KX_LightObject::py_setattro(PyObject *attr, PyObject *pyvalue) { char *attr_str= PyString_AsString(attr); - if (ValidPythonToGameObject(this)==false) - return -1; - if (PyInt_Check(pyvalue)) { int value = PyInt_AsLong(pyvalue); @@ -347,7 +336,9 @@ PyTypeObject KX_LightObject::Type = { 0, 0, py_base_repr, - 0,0,0,0,0,0, + 0,0, + &KX_GameObject::Mapping, + 0,0,0, py_base_getattro, py_base_setattro, 0,0,0,0,0,0,0,0,0, diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index c63167e2d56..c99fa363ffe 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -196,7 +196,7 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, m_canvasDesignWidth = 0; m_canvasDesignHeight = 0; - m_attrlist = PyDict_New(); /* new ref */ + m_attr_dict = PyDict_New(); /* new ref */ } @@ -250,8 +250,8 @@ KX_Scene::~KX_Scene() { delete m_bucketmanager; } - PyDict_Clear(m_attrlist); - Py_DECREF(m_attrlist); + PyDict_Clear(m_attr_dict); + Py_DECREF(m_attr_dict); } void KX_Scene::SetProjectionMatrix(MT_CmMatrix4x4& pmat) @@ -924,6 +924,8 @@ int KX_Scene::NewRemoveObject(class CValue* gameobj) { int ret; KX_GameObject* newobj = (KX_GameObject*) gameobj; + + gameobj->SetZombie(true); /* disallow future python access */ // keep the blender->game object association up to date // note that all the replicas of an object will have the same @@ -998,6 +1000,7 @@ int KX_Scene::NewRemoveObject(class CValue* gameobj) if (m_sceneConverter) m_sceneConverter->UnregisterGameObject(newobj); // return value will be 0 if the object is actually deleted (all reference gone) + return ret; } @@ -1591,7 +1594,7 @@ PyTypeObject KX_Scene::Type = { py_base_repr, 0,0,0,0,0,0, py_base_getattro, - py_base_setattro_scene, /* unlike almost all other types we need out own because user attributes are supported */ + py_base_setattro, 0,0,0,0,0,0,0,0,0, Methods }; @@ -1633,12 +1636,12 @@ PyObject* KX_Scene::pyattr_get_active_camera(void *self_v, const KX_PYATTRIBUTE_ PyObject* KX_Scene::pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_Scene* self= static_cast(self_v); - /* Useually done by py_getattro_up but in this case we want to include m_attrlist dict */ + /* Useually done by py_getattro_up but in this case we want to include m_attr_dict dict */ PyObject *dict_str= PyString_FromString("__dict__"); PyObject *dict= py_getattr_dict(self->PyObjectPlus::py_getattro(dict_str), Type.tp_dict); Py_DECREF(dict_str); - PyDict_Update(dict, self->m_attrlist); + PyDict_Update(dict, self->m_attr_dict); return dict; } @@ -1654,28 +1657,59 @@ PyAttributeDef KX_Scene::Attributes[] = { { NULL } //Sentinel }; + +PyObject* KX_Scene::py_getattro__internal(PyObject *attr) +{ + py_getattro_up(PyObjectPlus); +} + +int KX_Scene::py_setattro__internal(PyObject *attr, PyObject *pyvalue) +{ + return PyObjectPlus::py_setattro(attr, pyvalue); +} + PyObject* KX_Scene::py_getattro(PyObject *attr) { - PyObject *object = PyDict_GetItem(m_attrlist, attr); - if (object) + PyObject *object = py_getattro__internal(attr); + + if (object==NULL) { - Py_INCREF(object); - return object; + PyErr_Clear(); + object = PyDict_GetItem(m_attr_dict, attr); + if(object) { + Py_INCREF(object); + } + else { + PyErr_Format(PyExc_AttributeError, "KX_Scene attribute \"%s\" not found", PyString_AsString(attr)); + } } - py_getattro_up(PyObjectPlus); + return object; } -int KX_Scene::py_delattro(PyObject *attr) + +int KX_Scene::py_setattro(PyObject *attr, PyObject *value) { - PyDict_DelItem(m_attrlist, attr); - return 0; + int ret= py_setattro__internal(attr, value); + + if (ret==PY_SET_ATTR_MISSING) { + if (PyDict_SetItem(m_attr_dict, attr, value)==0) { + PyErr_Clear(); + ret= PY_SET_ATTR_SUCCESS; + } + else { + PyErr_SetString(PyExc_AttributeError, "failed assigning value to KX_Scenes internal dictionary"); + ret= PY_SET_ATTR_FAIL; + } + } + + return ret; } -/* py_base_setattro_scene deals with setting the dict, it will run if this returns an error */ -int KX_Scene::py_setattro(PyObject *attr, PyObject *pyvalue) +int KX_Scene::py_delattro(PyObject *attr) { - return PyObjectPlus::py_setattro(attr, pyvalue); + PyDict_DelItem(m_attr_dict, attr); + return 0; } KX_PYMETHODDEF_DOC_NOARGS(KX_Scene, getLightList, diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index e1e89e253ed..a06c66ec5dd 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -295,7 +295,7 @@ protected: /** * This stores anything from python */ - PyObject* m_attrlist; + PyObject* m_attr_dict; struct Scene* m_blenderScene; @@ -597,34 +597,14 @@ public: /* for dir(), python3 uses __dir__() */ static PyObject* pyattr_get_dir_dict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); - static int py_base_setattro_scene(PyObject * self, PyObject *attr, PyObject *value) - { - if (value==NULL) - return ((PyObjectPlus*) self)->py_delattro(attr); - - int ret= ((PyObjectPlus*) self)->py_setattro(attr, value); - - if (ret==PY_SET_ATTR_MISSING) { - if (PyDict_SetItem(((KX_Scene *) self)->m_attrlist, attr, value)==0) { - PyErr_Clear(); - ret= PY_SET_ATTR_SUCCESS; - } - else { - PyErr_Format(PyExc_AttributeError, "failed assigning value to KX_Scenes internal dictionary"); - ret= PY_SET_ATTR_FAIL; - } - } - - return ret; - } - - virtual PyObject* py_getattro(PyObject *attr); /* name, active_camera, gravity, suspended, viewport, framing, activity_culling, activity_culling_radius */ virtual int py_setattro(PyObject *attr, PyObject *pyvalue); virtual int py_delattro(PyObject *attr); virtual PyObject* py_repr(void) { return PyString_FromString(GetName().ReadPtr()); } + PyObject* py_getattro__internal(PyObject *attr); + int py_setattro__internal(PyObject *attr, PyObject *pyvalue); /** * Sets the time the scene was suspended diff --git a/source/gameengine/VideoTexture/VideoBase.cpp b/source/gameengine/VideoTexture/VideoBase.cpp index 10117c3af9e..3c703d75cda 100644 --- a/source/gameengine/VideoTexture/VideoBase.cpp +++ b/source/gameengine/VideoTexture/VideoBase.cpp @@ -22,7 +22,7 @@ http://www.gnu.org/copyleft/lesser.txt. #if defined WIN32 #define WINDOWS_LEAN_AND_MEAN -#include +#include #endif #include "VideoBase.h" -- cgit v1.2.3 From 53fd3847bcb577d580a16217a27b67fd3f679969 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sat, 18 Apr 2009 09:14:51 +0000 Subject: BGE: restore a feature that was lost in 2.48: sharing of display lists between duplicated objects. --- source/gameengine/Rasterizer/RAS_MaterialBucket.cpp | 10 +++++----- source/gameengine/Rasterizer/RAS_MaterialBucket.h | 4 +++- .../Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp | 4 ++-- .../Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp index 5ddcdd310b0..6beab28d61f 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp @@ -60,7 +60,7 @@ RAS_MeshSlot::RAS_MeshSlot() RAS_MeshSlot::~RAS_MeshSlot() { - vector::iterator it; + RAS_DisplayArrayList::iterator it; #ifdef USE_SPLIT Split(true); @@ -83,7 +83,7 @@ RAS_MeshSlot::~RAS_MeshSlot() RAS_MeshSlot::RAS_MeshSlot(const RAS_MeshSlot& slot) { - vector::iterator it; + RAS_DisplayArrayList::iterator it; m_clientObj = NULL; m_pDeformer = NULL; @@ -205,7 +205,7 @@ RAS_DisplayArray *RAS_MeshSlot::CurrentDisplayArray() void RAS_MeshSlot::SetDisplayArray(int numverts) { - vector::iterator it; + RAS_DisplayArrayList::iterator it; RAS_DisplayArray *darray = NULL; for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) { @@ -297,7 +297,7 @@ bool RAS_MeshSlot::Equals(RAS_MeshSlot *target) bool RAS_MeshSlot::Join(RAS_MeshSlot *target, MT_Scalar distance) { - vector::iterator it; + RAS_DisplayArrayList::iterator it; iterator mit; size_t i; @@ -362,7 +362,7 @@ bool RAS_MeshSlot::Split(bool force) { list::iterator jit; RAS_MeshSlot *target = m_joinSlot; - vector::iterator it, jt; + RAS_DisplayArrayList::iterator it, jt; iterator mit; size_t i, found0 = 0, found1 = 0; diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.h b/source/gameengine/Rasterizer/RAS_MaterialBucket.h index 211770318ae..f5c8cd3e107 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.h +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.h @@ -86,9 +86,11 @@ public: }; /* Entry of a RAS_MeshObject into RAS_MaterialBucket */ +typedef std::vector RAS_DisplayArrayList; class RAS_MeshSlot { + friend class RAS_ListRasterizer; private: // indices into display arrays int m_startarray; @@ -97,7 +99,7 @@ private: int m_endindex; int m_startvertex; int m_endvertex; - vector m_displayArrays; + RAS_DisplayArrayList m_displayArrays; // for construction only RAS_DisplayArray* m_currentArray; diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp index 2c4b55ff964..65aadd63a40 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp @@ -136,10 +136,10 @@ RAS_ListSlot* RAS_ListRasterizer::FindOrAdd(RAS_MeshSlot& ms) */ RAS_ListSlot* localSlot = (RAS_ListSlot*)ms.m_DisplayList; if(!localSlot) { - RAS_Lists::iterator it = mLists.find(&ms); + RAS_Lists::iterator it = mLists.find(ms.m_displayArrays); if(it == mLists.end()) { localSlot = new RAS_ListSlot(this); - mLists.insert(std::pair(&ms, localSlot)); + mLists.insert(std::pair(ms.m_displayArrays, localSlot)); } else { localSlot = static_cast(it->second->AddRef()); } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h index 96d6d2a995d..653bb43e534 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h @@ -35,7 +35,7 @@ enum RAS_ListSlotFlags { LIST_REGEN =64 }; -typedef std::map RAS_Lists; +typedef std::map RAS_Lists; class RAS_ListRasterizer : public RAS_VAOpenGLRasterizer { -- cgit v1.2.3 From d2ec468cd36a0924de99708542c504af3a4ed31e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 19 Apr 2009 06:29:15 +0000 Subject: Hidden faces were not rendering displayed in the game engine, only the invisible face flag should be used for this. Hiding faces is a editing option like selection and should not change rendering, it wasn't even working right because meshes without UVs ignored it. I thought this was needed for compatibility with old files but just noticed this messes up 2 of the files in demos-2.42.zip --- source/gameengine/Converter/BL_BlenderDataConversion.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 2ae47e47d74..792a3e309f3 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -602,10 +602,7 @@ BL_Material* ConvertMaterial( if( validface ) { - material->ras_mode |= !( - (mface->flag & ME_HIDE) || - (tface->mode & TF_INVISIBLE) - )?POLY_VIS:0; + material->ras_mode |= (tface->mode & TF_INVISIBLE)?0:POLY_VIS; material->transp = tface->transp; material->tile = tface->tile; @@ -900,7 +897,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* tile = tface->tile; mode = tface->mode; - visible = !((mface->flag & ME_HIDE)||(tface->mode & TF_INVISIBLE)); + visible = !(tface->mode & TF_INVISIBLE); twoside = ((tface->mode & TF_TWOSIDE)!=0); uv0.setValue(tface->uv[0]); -- cgit v1.2.3 From 92cea7c1b1540d11ed9729bacfabd23ccb7a79c7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 19 Apr 2009 06:48:27 +0000 Subject: KX_MeshProxy "numPolygons" and "numMaterials" attributes were using the "materials" attribute function, error made recently when converting attributes. --- source/gameengine/Expressions/Value.cpp | 105 +----------------------------- source/gameengine/Ketsji/KX_MeshProxy.cpp | 10 ++- 2 files changed, 6 insertions(+), 109 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index e969f0c33aa..63776c39d70 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -36,107 +36,6 @@ bool CValue::m_ignore_deprecation_warnings(false); #ifndef NO_EXP_PYTHON_EMBEDDING -PyObject* cvalue_add(PyObject*v, PyObject*w) -{ - return ((CValue*)v)->Calc(VALUE_ADD_OPERATOR,(CValue*)w); -} -PyObject* cvalue_sub(PyObject*v, PyObject*w) -{ - return ((CValue*)v)->Calc(VALUE_SUB_OPERATOR,(CValue*)w); -} -PyObject* cvalue_mul(PyObject*v, PyObject*w) -{ - return ((CValue*)v)->Calc(VALUE_MUL_OPERATOR,(CValue*)w); -} -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); -} -PyObject* cvalue_pos(PyObject*v) -{ - return ((CValue*)v)->Calc(VALUE_POS_OPERATOR,(CValue*)v); -} - - -int MyPyCompare (PyObject* v,PyObject* w) -{ - CValue* eqval = ((CValue*)v)->Calc(VALUE_EQL_OPERATOR,(CValue*)w); - STR_String txt = eqval->GetText(); - eqval->Release(); - if (txt=="TRUE") - return 0; - CValue* lessval = ((CValue*)v)->Calc(VALUE_LES_OPERATOR,(CValue*)w); - txt = lessval->GetText(); - lessval->Release(); - if (txt=="TRUE") - return -1; - - return 1; -} - - -int cvalue_coerce(PyObject** pv,PyObject** pw) -{ - if (PyInt_Check(*pw)) { - *pw = new CIntValue((cInt)PyInt_AsLong(*pw)); - Py_INCREF(*pv); - return 0; - } - else if (PyLong_Check(*pw)) { - *pw = new CIntValue((cInt)PyLong_AsLongLong(*pw)); - Py_INCREF(*pv); - return 0; - } - else if (PyFloat_Check(*pw)) { - *pw = new CFloatValue((float)PyFloat_AsDouble(*pw)); - Py_INCREF(*pv); - return 0; - } else if (PyString_Check(*pw)) { - const STR_String str = PyString_AsString(*pw); - *pw = new CStringValue(str,""); - Py_INCREF(*pv); - return 0; - } - - PyErr_SetString(PyExc_TypeError, "unable to coerce python type to cvalue"); - return 1; /* Can't do it */ - -} -static PyNumberMethods cvalue_as_number = { - (binaryfunc)cvalue_add, /*nb_add*/ - (binaryfunc)cvalue_sub, /*nb_subtract*/ - (binaryfunc)cvalue_mul, /*nb_multiply*/ - (binaryfunc)cvalue_div, /*nb_divide*/ - (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*/ - 0,//(unaryfunc)cvalue_pos, /*nb_positive*/ - 0,//(unaryfunc)cvalue_abs, /*nb_absolute*/ - 0,//(inquiry)cvalue_nonzero, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - (coercion)cvalue_coerce, /*nb_coerce*/ - 0,//(unaryfunc)cvalue_int, /*nb_int*/ - 0,//(unaryfunc)cvalue_long, /*nb_long*/ - 0,//(unaryfunc)cvalue_float, /*nb_float*/ - 0, /*nb_oct*/ - 0, /*nb_hex*/ -}; - - PyTypeObject CValue::Type = { PyObject_HEAD_INIT(NULL) 0, @@ -147,9 +46,9 @@ PyTypeObject CValue::Type = { 0, 0, 0, - &MyPyCompare, + 0, py_base_repr, - &cvalue_as_number, + 0, 0,0,0,0,0, py_base_getattro, py_base_setattro, diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index 0710d301c14..93d92480b3d 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -91,8 +91,8 @@ KX_PYMETHODTABLE(KX_MeshProxy, reinstancePhysicsMesh), PyAttributeDef KX_MeshProxy::Attributes[] = { KX_PYATTRIBUTE_RO_FUNCTION("materials", KX_MeshProxy, pyattr_get_materials), - KX_PYATTRIBUTE_RO_FUNCTION("numPolygons", KX_MeshProxy, pyattr_get_materials), - KX_PYATTRIBUTE_RO_FUNCTION("numMaterials", KX_MeshProxy, pyattr_get_materials), + KX_PYATTRIBUTE_RO_FUNCTION("numPolygons", KX_MeshProxy, pyattr_get_numPolygons), + KX_PYATTRIBUTE_RO_FUNCTION("numMaterials", KX_MeshProxy, pyattr_get_numMaterials), { NULL } //Sentinel }; @@ -311,12 +311,10 @@ PyObject* KX_MeshProxy::pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_ PyObject * KX_MeshProxy::pyattr_get_numMaterials(void * selfv, const KX_PYATTRIBUTE_DEF * attrdef) { KX_MeshProxy * self = static_cast (selfv); - int num = self->m_meshobj->NumMaterials(); - return PyInt_FromLong(num); + return PyInt_FromLong(self->m_meshobj->NumMaterials()); } PyObject * KX_MeshProxy::pyattr_get_numPolygons(void * selfv, const KX_PYATTRIBUTE_DEF * attrdef) { KX_MeshProxy * self = static_cast (selfv); - int num = self->m_meshobj->NumPolygons(); - return PyInt_FromLong(num); + return PyInt_FromLong(self->m_meshobj->NumPolygons()); } -- 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 --- .../Converter/BL_BlenderDataConversion.cpp | 2 +- source/gameengine/Expressions/InputParser.cpp | 2 +- source/gameengine/Expressions/ListValue.cpp | 67 +++++++--- source/gameengine/Expressions/ListValue.h | 4 +- source/gameengine/Expressions/PyObjectPlus.cpp | 69 +++++++++-- source/gameengine/Expressions/PyObjectPlus.h | 137 +++++++++++---------- source/gameengine/Expressions/Value.cpp | 11 +- source/gameengine/Expressions/Value.h | 16 --- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 3 +- .../gameengine/GameLogic/SCA_PythonController.cpp | 16 +-- .../Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp | 16 +-- source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 12 +- source/gameengine/Ketsji/KX_CameraActuator.cpp | 4 +- source/gameengine/Ketsji/KX_GameObject.cpp | 135 ++++++++++---------- source/gameengine/Ketsji/KX_GameObject.h | 6 +- source/gameengine/Ketsji/KX_MeshProxy.cpp | 10 +- source/gameengine/Ketsji/KX_MouseFocusSensor.cpp | 4 +- source/gameengine/Ketsji/KX_ParentActuator.cpp | 4 +- source/gameengine/Ketsji/KX_PolyProxy.cpp | 14 +-- source/gameengine/Ketsji/KX_PolygonMaterial.cpp | 3 +- .../gameengine/Ketsji/KX_PyConstraintBinding.cpp | 4 +- source/gameengine/Ketsji/KX_PythonInit.cpp | 11 +- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 6 +- source/gameengine/Ketsji/KX_RaySensor.cpp | 4 +- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp | 9 +- .../Ketsji/KX_SCA_ReplaceMeshActuator.cpp | 2 +- source/gameengine/Ketsji/KX_Scene.cpp | 13 +- source/gameengine/Ketsji/KX_SceneActuator.cpp | 44 +++++-- source/gameengine/Ketsji/KX_TouchSensor.cpp | 8 +- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 4 +- source/gameengine/Ketsji/KX_VehicleWrapper.cpp | 5 +- source/gameengine/VideoTexture/FilterSource.h | 3 +- source/gameengine/VideoTexture/ImageRender.cpp | 23 ++-- 33 files changed, 377 insertions(+), 294 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 792a3e309f3..9f214721c82 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -2354,7 +2354,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, // Remove the child reference in the local list! // Note: there may be descendents already if the children of the child were processed // by this loop before the child. In that case, we must remove the children also - CListValue* childrenlist = (CListValue*)childobj->PyGetChildrenRecursive(childobj); + CListValue* childrenlist = childobj->GetChildrenRecursive(); childrenlist->Add(childobj->AddRef()); for ( i=0;iGetCount();i++) { diff --git a/source/gameengine/Expressions/InputParser.cpp b/source/gameengine/Expressions/InputParser.cpp index 1698f1919d1..66075dd8d42 100644 --- a/source/gameengine/Expressions/InputParser.cpp +++ b/source/gameengine/Expressions/InputParser.cpp @@ -649,7 +649,7 @@ PyObject* CParserPyMake(PyObject* ignored,PyObject* args) CExpression* expr = parser.ProcessText(txt); CValue* val = expr->Calculate(); expr->Release(); - return val; + return val->GetProxy(); } static PyMethodDef CParserMethods[] = diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 37feba38f8b..eaed2b5c400 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -27,45 +27,61 @@ #define Py_ssize_t int #endif -Py_ssize_t listvalue_bufferlen(PyObject* list) +Py_ssize_t listvalue_bufferlen(PyObject* self) { - return (Py_ssize_t)( ((CListValue*)list)->GetCount()); + CListValue *list= static_cast(BGE_PROXY_REF(self)); + if (list==NULL) + return 0; + + return (Py_ssize_t)list->GetCount(); } -PyObject* listvalue_buffer_item(PyObject* list,Py_ssize_t index) +PyObject* listvalue_buffer_item(PyObject* self, Py_ssize_t index) { - int count = ((CListValue*) list)->GetCount(); + CListValue *list= static_cast(BGE_PROXY_REF(self)); + if (list==NULL) { + PyErr_SetString(PyExc_IndexError, BGE_PROXY_ERROR_MSG); + return NULL; + } + + int count = list->GetCount(); if (index < 0) index = count+index; if (index >= 0 && index < count) { - PyObject* pyobj = ((CListValue*) list)->GetValue(index)->ConvertValueToPython(); + PyObject* pyobj = list->GetValue(index)->ConvertValueToPython(); if (pyobj) return pyobj; else - return ((CListValue*) list)->GetValue(index)->AddRef(); + return list->GetValue(index)->GetProxy(); } PyErr_SetString(PyExc_IndexError, "Python ListIndex out of range"); return NULL; } -PyObject* listvalue_mapping_subscript(PyObject* list,PyObject* pyindex) +PyObject* listvalue_mapping_subscript(PyObject* self, PyObject* pyindex) { + CListValue *list= static_cast(BGE_PROXY_REF(self)); + if (list==NULL) { + PyErr_SetString(PyExc_IndexError, BGE_PROXY_ERROR_MSG); + return NULL; + } + if (PyString_Check(pyindex)) { STR_String index(PyString_AsString(pyindex)); CValue *item = ((CListValue*) list)->FindValue(index); if (item) - return (PyObject*) item; + return item->GetProxy(); } if (PyInt_Check(pyindex)) { int index = PyInt_AsLong(pyindex); - return listvalue_buffer_item(list, index); + return listvalue_buffer_item(self, index); } PyObject *pyindex_str = PyObject_Repr(pyindex); /* new ref */ @@ -76,10 +92,16 @@ PyObject* listvalue_mapping_subscript(PyObject* list,PyObject* pyindex) /* just slice it into a python list... */ -PyObject* listvalue_buffer_slice(PyObject* list,Py_ssize_t ilow, Py_ssize_t ihigh) +PyObject* listvalue_buffer_slice(PyObject* self,Py_ssize_t ilow, Py_ssize_t ihigh) { + CListValue *list= static_cast(BGE_PROXY_REF(self)); + if (list==NULL) { + PyErr_SetString(PyExc_IndexError, BGE_PROXY_ERROR_MSG); + return NULL; + } + int i, j; - PyListObject *newlist; + PyObject *newlist; if (ilow < 0) ilow = 0; @@ -90,18 +112,18 @@ PyObject* listvalue_buffer_slice(PyObject* list,Py_ssize_t ilow, Py_ssize_t ihig if (ihigh < ilow) ihigh = ilow; - newlist = (PyListObject *) PyList_New(ihigh - ilow); + newlist = PyList_New(ihigh - ilow); if (!newlist) return NULL; for (i = ilow, j = 0; i < ihigh; i++, j++) { - PyObject* pyobj = ((CListValue*) list)->GetValue(i)->ConvertValueToPython(); + PyObject* pyobj = list->GetValue(i)->ConvertValueToPython(); if (!pyobj) - pyobj = ((CListValue*) list)->GetValue(i)->AddRef(); - newlist->ob_item[j] = pyobj; + pyobj = list->GetValue(i)->GetProxy(); + PyList_SET_ITEM(newlist, i, pyobj); } - return (PyObject *) newlist; + return newlist; } @@ -109,11 +131,16 @@ PyObject* listvalue_buffer_slice(PyObject* list,Py_ssize_t ilow, Py_ssize_t ihig static PyObject * listvalue_buffer_concat(PyObject * self, PyObject * other) { + CListValue *listval= static_cast(BGE_PROXY_REF(self)); + if (listval==NULL) { + PyErr_SetString(PyExc_IndexError, BGE_PROXY_ERROR_MSG); + return NULL; + } + // for now, we support CListValue concatenated with items // and CListValue concatenated to Python Lists // and CListValue concatenated with another CListValue - - CListValue* listval = (CListValue*) self; + listval->AddRef(); if (other->ob_type == &PyList_Type) { @@ -519,8 +546,8 @@ PyObject* CListValue::Pyfrom_id(PyObject* self, PyObject* value) int numelem = GetCount(); for (int i=0;i(static_cast(m_pValueArray[i])) == id) - return GetValue(i); + if (reinterpret_cast(m_pValueArray[i]->m_proxy) == id) + return GetValue(i)->GetProxy(); } PyErr_SetString(PyExc_IndexError, "from_id(#), id not found in CValueList"); diff --git a/source/gameengine/Expressions/ListValue.h b/source/gameengine/Expressions/ListValue.h index cf2976c2bbb..2af5a330c43 100644 --- a/source/gameengine/Expressions/ListValue.h +++ b/source/gameengine/Expressions/ListValue.h @@ -61,9 +61,11 @@ public: virtual PyObject* py_getattro(PyObject* attr); virtual PyObject* py_repr(void) { - PyObject *py_list= PySequence_List((PyObject *)this); + PyObject *py_proxy= this->GetProxy(); + PyObject *py_list= PySequence_List(py_proxy); PyObject *py_string= PyObject_Repr(py_list); Py_DECREF(py_list); + Py_DECREF(py_proxy); return py_string; } diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 0db2e8991fc..2c5ba3f39fc 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -54,6 +54,7 @@ * PyObjectPlus Type -- Every class, even the abstract one should have a Type ------------------------------*/ + PyTypeObject PyObjectPlus::Type = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ @@ -74,21 +75,33 @@ PyTypeObject PyObjectPlus::Type = { Methods }; + PyObjectPlus::~PyObjectPlus() { - if (ob_refcnt) - { - _Py_ForgetReference(this); + if(m_proxy) { + Py_DECREF(m_proxy); /* Remove own reference, python may still have 1 */ + BGE_PROXY_REF(m_proxy)= NULL; } // assert(ob_refcnt==0); } +void PyObjectPlus::PyDestructor(PyObject *self) // python wrapper +{ + PyObjectPlus *self_plus= BGE_PROXY_REF(self); + if(self_plus) { + if(BGE_PROXY_PYOWNS(self)) { /* Does python own this?, then delete it */ + delete self_plus; + } + + BGE_PROXY_REF(self)= NULL; // not really needed + } + PyObject_DEL( self ); +}; + PyObjectPlus::PyObjectPlus(PyTypeObject *T) // constructor { MT_assert(T != NULL); - this->ob_type = T; - _Py_NewReference(this); - SetZombie(false); + m_proxy= NULL; }; /*------------------------------ @@ -131,7 +144,7 @@ PyObject *PyObjectPlus::py_getattro(PyObject* attr) if (PyCObject_Check(descr)) { return py_get_attrdef((void *)this, (const PyAttributeDef*)PyCObject_AsVoidPtr(descr)); } else if (descr->ob_type->tp_descr_get) { - return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); + return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, this->m_proxy); } else { fprintf(stderr, "Unknown attribute type (PyObjectPlus::py_getattro)"); return descr; @@ -794,5 +807,47 @@ PyObject *py_getattr_dict(PyObject *pydict, PyObject *tp_dict) return pydict; } + + +PyObject *PyObjectPlus::GetProxy_Ext(PyObjectPlus *self, PyTypeObject *tp) +{ + if (self->m_proxy==NULL) + { + self->m_proxy = reinterpret_castPyObject_NEW( PyObjectPlus_Proxy, tp); + BGE_PROXY_PYOWNS(self->m_proxy) = false; + } + //PyObject_Print(self->m_proxy, stdout, 0); + //printf("ref %d\n", self->m_proxy->ob_refcnt); + + BGE_PROXY_REF(self->m_proxy) = self; /* Its possible this was set to NULL, so set it back here */ + Py_INCREF(self->m_proxy); /* we own one, thos ones fore the return */ + return self->m_proxy; +} + +PyObject *PyObjectPlus::NewProxy_Ext(PyObjectPlus *self, PyTypeObject *tp, bool py_owns) +{ + if (self->m_proxy) + { + if(py_owns) + { /* Free */ + BGE_PROXY_REF(self->m_proxy) = NULL; + Py_DECREF(self->m_proxy); + self->m_proxy= NULL; + } + else { + Py_INCREF(self->m_proxy); + return self->m_proxy; + } + + } + + GetProxy_Ext(self, tp); + if(py_owns) { + BGE_PROXY_PYOWNS(self->m_proxy) = py_owns; + Py_DECREF(self->m_proxy); /* could avoid thrashing here but for now its ok */ + } + return self->m_proxy; +} + #endif //NO_EXP_PYTHON_EMBEDDING diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 58a74e4ca74..3be9a2f2bcb 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -81,6 +81,20 @@ static inline void Py_Fatal(const char *M) { exit(-1); }; +typedef struct { + PyObject_HEAD /* required python macro */ + class PyObjectPlus *ref; + bool py_owns; +} PyObjectPlus_Proxy; + +#define BGE_PROXY_ERROR_MSG "Blender Game Engine data has been freed, cannot use this python variable" +#define BGE_PROXY_REF(_self) (((PyObjectPlus_Proxy *)_self)->ref) +#define BGE_PROXY_PYOWNS(_self) (((PyObjectPlus_Proxy *)_self)->py_owns) + +/* Note, sometimes we dont care what BGE type this is as long as its a proxy */ +#define BGE_PROXY_CHECK_TYPE(_self) ((_self)->ob_type->tp_dealloc == PyDestructor) + + // This must be the first line of each // PyC++ class #define Py_Header \ @@ -90,7 +104,10 @@ static inline void Py_Fatal(const char *M) { static PyAttributeDef Attributes[]; \ static PyParentObject Parents[]; \ virtual PyTypeObject *GetType(void) {return &Type;}; \ - virtual PyParentObject *GetParents(void) {return Parents;} + virtual PyParentObject *GetParents(void) {return Parents;} \ + virtual PyObject *GetProxy() {return GetProxy_Ext(this, &Type);}; \ + virtual PyObject *NewProxy(bool py_owns) {return NewProxy_Ext(this, &Type, py_owns);}; \ + @@ -106,7 +123,7 @@ static inline void Py_Fatal(const char *M) { if (PyCObject_Check(descr)) { \ return py_get_attrdef((void *)this, (const PyAttributeDef*)PyCObject_AsVoidPtr(descr)); \ } else if (descr->ob_type->tp_descr_get) { \ - return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, (PyObject *)this); \ + return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, this->m_proxy); \ } else { \ fprintf(stderr, "unknown attribute type"); \ return descr; \ @@ -165,52 +182,60 @@ static inline void Py_Fatal(const char *M) { #define KX_PYMETHOD(class_name, method_name) \ PyObject* Py##method_name(PyObject* self, PyObject* args, PyObject* kwds); \ static PyObject* sPy##method_name( PyObject* self, PyObject* args, PyObject* kwds) { \ - return ((class_name*) self)->Py##method_name(self, args, kwds); \ + PyObjectPlus *self_plus= BGE_PROXY_REF(self); \ + return ((class_name*)self_plus)->Py##method_name(self, args, kwds); \ }; \ #define KX_PYMETHOD_VARARGS(class_name, method_name) \ PyObject* Py##method_name(PyObject* self, PyObject* args); \ static PyObject* sPy##method_name( PyObject* self, PyObject* args) { \ - return ((class_name*) self)->Py##method_name(self, args); \ + PyObjectPlus *self_plus= BGE_PROXY_REF(self); \ + return ((class_name*)self_plus)->Py##method_name(self, args); \ }; \ #define KX_PYMETHOD_NOARGS(class_name, method_name) \ PyObject* Py##method_name(PyObject* self); \ static PyObject* sPy##method_name( PyObject* self) { \ - return ((class_name*) self)->Py##method_name(self); \ + PyObjectPlus *self_plus= BGE_PROXY_REF(self); \ + return ((class_name*)self_plus)->Py##method_name(self); \ }; \ #define KX_PYMETHOD_O(class_name, method_name) \ PyObject* Py##method_name(PyObject* self, PyObject* value); \ static PyObject* sPy##method_name( PyObject* self, PyObject* value) { \ - return ((class_name*) self)->Py##method_name(self, value); \ + PyObjectPlus *self_plus= ((PyObjectPlus_Proxy *)self)->ref; \ + return ((class_name*) self_plus)->Py##method_name(self, value); \ }; \ #define KX_PYMETHOD_DOC(class_name, method_name) \ PyObject* Py##method_name(PyObject* self, PyObject* args, PyObject* kwds); \ static PyObject* sPy##method_name( PyObject* self, PyObject* args, PyObject* kwds) { \ - return ((class_name*) self)->Py##method_name(self, args, kwds); \ + PyObjectPlus *self_plus= BGE_PROXY_REF(self); \ + return ((class_name*)self_plus)->Py##method_name(self, args, kwds); \ }; \ static const char method_name##_doc[]; \ #define KX_PYMETHOD_DOC_VARARGS(class_name, method_name) \ PyObject* Py##method_name(PyObject* self, PyObject* args); \ static PyObject* sPy##method_name( PyObject* self, PyObject* args) { \ - return ((class_name*) self)->Py##method_name(self, args); \ + PyObjectPlus *self_plus= BGE_PROXY_REF(self); \ + return ((class_name*)self_plus)->Py##method_name(self, args); \ }; \ static const char method_name##_doc[]; \ #define KX_PYMETHOD_DOC_O(class_name, method_name) \ PyObject* Py##method_name(PyObject* self, PyObject* value); \ static PyObject* sPy##method_name( PyObject* self, PyObject* value) { \ - return ((class_name*) self)->Py##method_name(self, value); \ + PyObjectPlus *self_plus= BGE_PROXY_REF(self); \ + return ((class_name*)self_plus)->Py##method_name(self, value); \ }; \ static const char method_name##_doc[]; \ #define KX_PYMETHOD_DOC_NOARGS(class_name, method_name) \ PyObject* Py##method_name(PyObject* self); \ static PyObject* sPy##method_name( PyObject* self) { \ - return ((class_name*) self)->Py##method_name(self); \ + PyObjectPlus *self_plus= BGE_PROXY_REF(self); \ + return ((class_name*)self_plus)->Py##method_name(self); \ }; \ static const char method_name##_doc[]; \ @@ -233,19 +258,19 @@ static inline void Py_Fatal(const char *M) { */ #define KX_PYMETHODDEF_DOC(class_name, method_name, doc_string) \ const char class_name::method_name##_doc[] = doc_string; \ -PyObject* class_name::Py##method_name(PyObject*, PyObject* args, PyObject*) +PyObject* class_name::Py##method_name(PyObject* self, PyObject* args, PyObject*) #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) +PyObject* class_name::Py##method_name(PyObject* self, 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) +PyObject* class_name::Py##method_name(PyObject* self, 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*) +PyObject* class_name::Py##method_name(PyObject* self) /** * Attribute management @@ -394,19 +419,17 @@ typedef struct KX_PYATTRIBUTE_DEF { ------------------------------*/ typedef PyTypeObject * PyParentObject; // Define the PyParent Object -class PyObjectPlus : public PyObject +class PyObjectPlus { // The PyObjectPlus abstract class Py_Header; // Always start with Py_Header public: PyObjectPlus(PyTypeObject *T); - bool m_zombie; + + PyObject *m_proxy; /* actually a PyObjectPlus_Proxy */ virtual ~PyObjectPlus(); // destructor - static void PyDestructor(PyObject *P) // python wrapper - { - delete ((PyObjectPlus *) P); - }; + static void PyDestructor(PyObject *self); // python wrapper // void INCREF(void) { // Py_INCREF(this); @@ -418,15 +441,15 @@ public: virtual PyObject *py_getattro(PyObject *attr); // py_getattro method static PyObject *py_base_getattro(PyObject * self, PyObject *attr) // This should be the entry in Type. { - if (((PyObjectPlus*)self)->IsZombie()) { - if (!strcmp(PyString_AsString(attr), "isValid")) { - Py_RETURN_FALSE; + PyObjectPlus *self_plus= BGE_PROXY_REF(self); + if(self_plus==NULL) { + if(!strcmp("isValid", PyString_AsString(attr))) { + Py_RETURN_TRUE; } - ((PyObjectPlus*)self)->IsZombiePyErr(); /* raise an error */ + PyErr_SetString(PyExc_RuntimeError, "data has been removed"); return NULL; } - - return ((PyObjectPlus*) self)->py_getattro(attr); + return self_plus->py_getattro(attr); } static PyObject* py_get_attrdef(void *self, const PyAttributeDef *attrdef); @@ -441,22 +464,29 @@ public: virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method static int py_base_setattro(PyObject *self, PyObject *attr, PyObject *value) // the PyType should reference this { - if (((PyObjectPlus*)self)->IsZombie()) { - /* you cant set isValid anyway */ - ((PyObjectPlus*)self)->IsZombiePyErr(); + PyObjectPlus *self_plus= BGE_PROXY_REF(self); + if(self_plus==NULL) { + PyErr_SetString(PyExc_RuntimeError, "data has been removed"); return -1; } if (value==NULL) - return ((PyObjectPlus*)self)->py_delattro(attr); + return self_plus->py_delattro(attr); - return ((PyObjectPlus*)self)->py_setattro(attr, value); + return self_plus->py_setattro(attr, value); } virtual PyObject *py_repr(void); // py_repr method - static PyObject *py_base_repr(PyObject *PyObj) // This should be the entry in Type. + static PyObject *py_base_repr(PyObject *self) // This should be the entry in Type. { - return ((PyObjectPlus*) PyObj)->py_repr(); + + PyObjectPlus *self_plus= BGE_PROXY_REF(self); + if(self_plus==NULL) { + PyErr_SetString(PyExc_RuntimeError, "data has been removed"); + return NULL; + } + + return self_plus->py_repr(); } // isA methods @@ -465,43 +495,20 @@ public: PyObject *Py_isA(PyObject *value); static PyObject *sPy_isA(PyObject *self, PyObject *value) { - return ((PyObjectPlus*)self)->Py_isA(value); - } - - /* Kindof dumb, always returns True, the false case is checked for, before this function gets accessed */ - static PyObject* pyattr_get_is_valid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); - - bool IsZombie() - { - return m_zombie; - } - - bool IsZombiePyErr() - { - if(m_zombie) { - /* - PyObject *this_pystr = PyObject_Repr(this); - - PyErr_Format( - PyExc_RuntimeError, - "\"%s\" of type \"%s\" has been freed by the blender game engine, " - "scripts cannot access this anymore, check for this case with the \"isValid\" attribute", - PyString_AsString(this_pystr), ob_type->tp_name ); - - Py_DECREF(this_pystr); - */ - - PyErr_SetString(PyExc_RuntimeError, "This value has been freed by the blender game engine but python is still holding a reference, this value cant be used."); + PyObjectPlus *self_plus= BGE_PROXY_REF(self); + if(self_plus==NULL) { + PyErr_SetString(PyExc_RuntimeError, "data has been removed"); + return NULL; } - return m_zombie; + return self_plus->Py_isA(value); } - void SetZombie(bool is_zombie) - { - m_zombie= is_zombie; - } + /* Kindof dumb, always returns True, the false case is checked for, before this function gets accessed */ + static PyObject* pyattr_get_is_valid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject *GetProxy_Ext(PyObjectPlus *self, PyTypeObject *tp); + static PyObject *NewProxy_Ext(PyObjectPlus *self, PyTypeObject *tp, bool py_owns); }; PyObject *py_getattr_dict(PyObject *pydict, PyObject *tp_dict); diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index 63776c39d70..7958c16ca81 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -501,12 +501,6 @@ int CValue::Release() // Decrease local reference count, if it reaches 0 the object should be freed if (--m_refcount > 0) { - // Benoit suggest this as a way to automatically set the zombie flag, but I couldnt get it working - Campbell - /* - if (m_refcount == 1 && ob_refcnt > 1) - SetZombie(true); // the remaining refcount is held by Python!! - */ - // Reference count normal, return new reference count return m_refcount; } @@ -544,9 +538,6 @@ void CValue::AddDataToReplica(CValue *replica) { replica->m_refcount = 1; - //register with Python - _Py_NewReference(replica); - #ifdef _DEBUG //gRefCountValue++; #endif @@ -616,7 +607,7 @@ PyObject* CValue::py_getattro(PyObject *attr) if (pyconvert) return pyconvert; else - return resultattr; // also check if it's already in pythoninterpreter! + return resultattr->GetProxy(); } py_getattro_up(PyObjectPlus); } diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h index bcee355cda2..a687e1a493c 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/Value.h @@ -225,21 +225,6 @@ public: virtual PyObject* py_getattro(PyObject *attr); - - void SpecialRelease() - { - if (ob_refcnt == 0) /* make sure python always holds a reference */ - { - _Py_NewReference(this); - - } - Release(); - } - static void PyDestructor(PyObject *P) // python wrapper - { - ((CValue*)P)->SpecialRelease(); - }; - virtual PyObject* ConvertValueToPython() { return NULL; } @@ -352,7 +337,6 @@ private: std::map* m_pNamedPropertyArray; // Properties for user/game etc ValueFlags m_ValFlags; // Frequently used flags in a bitfield (low memoryusage) int m_refcount; // Reference Counter - bool m_zombie; // Object is invalid put its still being referenced (by python) static double m_sZeroVec[3]; static bool m_ignore_deprecation_warnings; diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index 46e132c65fc..7fa55cfb1ee 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -294,8 +294,7 @@ PyObject* SCA_ILogicBrick::PyGetOwner(PyObject* self) CValue* parent = GetParent(); if (parent) { - parent->AddRef(); - return parent; + return parent->GetProxy(); } printf("ERROR: Python scriptblock without owner\n"); diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 1c5b597f937..687ae421af1 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -157,7 +157,7 @@ static const char* sPyGetCurrentController__doc__; PyObject* SCA_PythonController::sPyGetCurrentController(PyObject* self) { - return m_sCurrentController->AddRef(); + return m_sCurrentController->GetProxy(); } SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value) @@ -176,10 +176,10 @@ SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value) } } } - else { - /* Expecting an actuator type */ + else if (BGE_PROXY_CHECK_TYPE(value)) { + PyObjectPlus *value_plus= BGE_PROXY_REF(value); /* Expecting an actuator type */ // XXX TODO - CHECK TYPE for(it = lacts.begin(); it!= lacts.end(); it++) { - if( static_cast(value) == (*it) ) { + if( static_cast(value_plus) == (*it) ) { return *it; } } @@ -413,7 +413,7 @@ PyObject* SCA_PythonController::PyGetActuators(PyObject* self) PyObject* resultlist = PyList_New(m_linkedactuators.size()); for (unsigned int index=0;indexAddRef()); + PyList_SET_ITEM(resultlist,index, m_linkedactuators[index]->GetProxy()); } return resultlist; @@ -437,7 +437,7 @@ SCA_PythonController::PyGetSensor(PyObject* self, PyObject* value) STR_String realname = sensor->GetName(); if (realname == scriptArg) { - return sensor->AddRef(); + return sensor->GetProxy(); } } @@ -466,7 +466,7 @@ SCA_PythonController::PyGetActuator(PyObject* self, PyObject* value) SCA_IActuator* actua = m_linkedactuators[index]; if (actua->GetName() == scriptArg) { - return actua->AddRef(); + return actua->GetProxy(); } } @@ -484,7 +484,7 @@ SCA_PythonController::PyGetSensors(PyObject* self) PyObject* resultlist = PyList_New(m_linkedsensors.size()); for (unsigned int index=0;indexAddRef()); + PyList_SET_ITEM(resultlist,index, m_linkedsensors[index]->GetProxy()); } return resultlist; diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp index 65600856377..8aca2e372d1 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp @@ -235,9 +235,9 @@ PyObject* KX_NetworkMessageSensor::pyattr_get_bodies(void *self_v, const KX_PYAT { KX_NetworkMessageSensor *self = static_cast(self_v); if (self->m_BodyList) { - return ((PyObject*) self->m_BodyList->AddRef()); + return self->m_BodyList->GetProxy(); } else { - return ((PyObject*) new CListValue()); + return (new CListValue())->NewProxy(true); } } @@ -245,9 +245,9 @@ PyObject* KX_NetworkMessageSensor::pyattr_get_subjects(void *self_v, const KX_PY { KX_NetworkMessageSensor *self = static_cast(self_v); if (self->m_SubjectList) { - return ((PyObject*) self->m_SubjectList->AddRef()); + return self->m_SubjectList->GetProxy(); } else { - return ((PyObject*) new CListValue()); + return (new CListValue())->NewProxy(true); } } @@ -290,9 +290,9 @@ PyObject* KX_NetworkMessageSensor::PyGetBodies( PyObject* ) { ShowDeprecationWarning("getBodies()", "bodies"); if (m_BodyList) { - return ((PyObject*) m_BodyList->AddRef()); + return m_BodyList->GetProxy(); } else { - return ((PyObject*) new CListValue()); + return (new CListValue())->NewProxy(true); } } @@ -316,9 +316,9 @@ PyObject* KX_NetworkMessageSensor::PyGetSubjects( PyObject* ) { ShowDeprecationWarning("getSubjects()", "subjects"); if (m_SubjectList) { - return ((PyObject*) m_SubjectList->AddRef()); + return m_SubjectList->GetProxy(); } else { - return ((PyObject*) new CListValue()); + return (new CListValue())->NewProxy(true); } } // <----- Deprecated \ No newline at end of file diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index 0e417dde5d2..bdad21f76eb 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -827,8 +827,7 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()") m_flag &= ~RAS_BLENDERGLSL; mMaterial->SetSharedMaterial(true); mScene->GetBucketManager()->ReleaseDisplayLists(this); - Py_INCREF(mShader); - return mShader; + return mShader->GetProxy(); }else { // decref all references to the object @@ -836,13 +835,8 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()") // We will then go back to fixed functionality // for this material if(mShader) { - if(mShader->ob_refcnt > 1) { - Py_DECREF(mShader); - } - else { - delete mShader; - mShader=0; - } + delete mShader; /* will handle python de-referencing */ + mShader=0; } } Py_RETURN_NONE; diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 329d31cfa25..a1159dbc23f 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -449,7 +449,7 @@ PyObject* KX_CameraActuator::PyGetObject(PyObject* self, PyObject* args) if (ret_name_only) return PyString_FromString(m_ob->GetName()); else - return m_ob->AddRef(); + return m_ob->GetProxy(); } /* set obj ---------------------------------------------------------- */ const char KX_CameraActuator::SetObject_doc[] = @@ -597,7 +597,7 @@ PyObject* KX_CameraActuator::pyattr_get_object(void *self_v, const KX_PYATTRIBUT if (self->m_ob==NULL) Py_RETURN_NONE; else - return self->m_ob->AddRef(); + return self->m_ob->GetProxy(); } int KX_CameraActuator::pyattr_set_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 3e7c99dc472..402c242315a 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1039,7 +1039,43 @@ void KX_GameObject::Suspend() } } +static void walk_children(SG_Node* node, CListValue* list, bool recursive) +{ + if (!node) + return; + NodeList& children = node->GetSGChildren(); + + for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) + { + SG_Node* childnode = (*childit); + CValue* childobj = (CValue*)childnode->GetSGClientObject(); + if (childobj != NULL) // This is a GameObject + { + // add to the list + list->Add(childobj->AddRef()); + } + + // if the childobj is NULL then this may be an inverse parent link + // so a non recursive search should still look down this node. + if (recursive || childobj==NULL) { + walk_children(childnode, list, recursive); + } + } +} + +CListValue* KX_GameObject::GetChildren() +{ + CListValue* list = new CListValue(); + walk_children(GetSGNode(), list, 0); /* GetSGNode() is always valid or it would have raised an exception before this */ + return list; +} +CListValue* KX_GameObject::GetChildrenRecursive() +{ + CListValue* list = new CListValue(); + walk_children(GetSGNode(), list, 1); + return list; +} /* ------- python stuff ---------------------------------------------------*/ @@ -1185,13 +1221,10 @@ PyObject* KX_GameObject::PyGetPosition(PyObject* self) Py_ssize_t KX_GameObject::Map_Len(PyObject* self_v) { - KX_GameObject* self= static_cast(self_v); + KX_GameObject* self= static_castBGE_PROXY_REF(self_v); - if (self->IsZombie()) /* not sure what to do here */ - { - PyErr_Clear(); + if (self==NULL) /* not sure what to do here */ return 0; - } Py_ssize_t len= self->GetPropertyCount(); if(self->m_attr_dict) @@ -1202,18 +1235,20 @@ Py_ssize_t KX_GameObject::Map_Len(PyObject* self_v) PyObject *KX_GameObject::Map_GetItem(PyObject *self_v, PyObject *item) { - KX_GameObject* self= static_cast(self_v); + KX_GameObject* self= static_castBGE_PROXY_REF(self_v); const char *attr_str= PyString_AsString(item); CValue* resultattr; PyObject* pyconvert; - if (self->IsZombiePyErr()) + if (self==NULL) { + PyErr_SetString(PyExc_RuntimeError, BGE_PROXY_ERROR_MSG); return NULL; + } /* first see if the attributes a string and try get the cvalue attribute */ if(attr_str && (resultattr=self->GetProperty(attr_str))) { pyconvert = resultattr->ConvertValueToPython(); - return pyconvert ? pyconvert:resultattr; + return pyconvert ? pyconvert:resultattr->GetProxy(); } /* no CValue attribute, try get the python only m_attr_dict attribute */ else if (self->m_attr_dict && (pyconvert=PyDict_GetItem(self->m_attr_dict, item))) { @@ -1234,13 +1269,15 @@ PyObject *KX_GameObject::Map_GetItem(PyObject *self_v, PyObject *item) int KX_GameObject::Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val) { - KX_GameObject* self= static_cast(self_v); + KX_GameObject* self= static_castBGE_PROXY_REF(self_v); const char *attr_str= PyString_AsString(key); if(attr_str==NULL) PyErr_Clear(); - if (self->IsZombiePyErr()) + if (self==NULL) { + PyErr_SetString(PyExc_RuntimeError, BGE_PROXY_ERROR_MSG); return -1; + } if (val==NULL) { /* del ob["key"] */ int del= 0; @@ -1370,7 +1407,7 @@ PyObject* KX_GameObject::pyattr_get_parent(void *self_v, const KX_PYATTRIBUTE_DE KX_GameObject* self= static_cast(self_v); KX_GameObject* parent = self->GetParent(); if (parent) - return parent->AddRef(); + return parent->GetProxy(); Py_RETURN_NONE; } @@ -1667,7 +1704,7 @@ PyObject* KX_GameObject::pyattr_get_meshes(void *self_v, const KX_PYATTRIBUTE_DE for(i=0; i < self->m_meshes.size(); i++) { KX_MeshProxy* meshproxy = new KX_MeshProxy(self->m_meshes[i]); - PyList_SET_ITEM(meshes, i, meshproxy); + PyList_SET_ITEM(meshes, i, meshproxy->GetProxy()); } return meshes; @@ -1681,7 +1718,7 @@ PyObject* KX_GameObject::pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_D PyObject* resultlist = PyList_New(sensors.size()); for (unsigned int index=0;indexAddRef()); + PyList_SET_ITEM(resultlist, index, sensors[index]->GetProxy()); return resultlist; } @@ -1693,7 +1730,7 @@ PyObject* KX_GameObject::pyattr_get_controllers(void *self_v, const KX_PYATTRIBU PyObject* resultlist = PyList_New(controllers.size()); for (unsigned int index=0;indexAddRef()); + PyList_SET_ITEM(resultlist, index, controllers[index]->GetProxy()); return resultlist; } @@ -1705,7 +1742,7 @@ PyObject* KX_GameObject::pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE PyObject* resultlist = PyList_New(actuators.size()); for (unsigned int index=0;indexAddRef()); + PyList_SET_ITEM(resultlist, index, actuators[index]->GetProxy()); return resultlist; } @@ -2083,28 +2120,17 @@ PyObject* KX_GameObject::PyGetParent(PyObject* self) ShowDeprecationWarning("getParent()", "the parent property"); KX_GameObject* parent = this->GetParent(); if (parent) - return parent->AddRef(); + return parent->GetProxy(); Py_RETURN_NONE; } PyObject* KX_GameObject::PySetParent(PyObject* self, PyObject* value) { - if (!PyObject_TypeCheck(value, &KX_GameObject::Type)) { - PyErr_SetString(PyExc_TypeError, "expected a KX_GameObject type"); + KX_GameObject *obj; + if (!ConvertPythonToGameObject(value, &obj, false)) return NULL; - } - if (self==value) { - PyErr_SetString(PyExc_ValueError, "cannot set the object to be its own parent!"); - return NULL; - } - // The object we want to set as parent - CValue *m_ob = (CValue*)value; - KX_GameObject *obj = ((KX_GameObject*)m_ob); - KX_Scene *scene = KX_GetActiveScene(); - - this->SetParent(scene, obj); - + this->SetParent(KX_GetActiveScene(), obj); Py_RETURN_NONE; } @@ -2115,43 +2141,14 @@ PyObject* KX_GameObject::PyRemoveParent(PyObject* self) Py_RETURN_NONE; } - -static void walk_children(SG_Node* node, CListValue* list, bool recursive) -{ - if (!node) - return; - NodeList& children = node->GetSGChildren(); - - for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) - { - SG_Node* childnode = (*childit); - CValue* childobj = (CValue*)childnode->GetSGClientObject(); - if (childobj != NULL) // This is a GameObject - { - // add to the list - list->Add(childobj->AddRef()); - } - - // if the childobj is NULL then this may be an inverse parent link - // so a non recursive search should still look down this node. - if (recursive || childobj==NULL) { - walk_children(childnode, list, recursive); - } - } -} - PyObject* KX_GameObject::PyGetChildren(PyObject* self) { - CListValue* list = new CListValue(); - walk_children(GetSGNode(), list, 0); /* GetSGNode() is always valid or it would have raised an exception before this */ - return list; + return GetChildren()->NewProxy(true); } PyObject* KX_GameObject::PyGetChildrenRecursive(PyObject* self) { - CListValue* list = new CListValue(); - walk_children(GetSGNode(), list, 1); - return list; + return GetChildrenRecursive()->NewProxy(true); } PyObject* KX_GameObject::PyGetMesh(PyObject* self, PyObject* args) @@ -2166,7 +2163,7 @@ PyObject* KX_GameObject::PyGetMesh(PyObject* self, PyObject* args) if (((unsigned int)mesh < m_meshes.size()) && mesh >= 0) { KX_MeshProxy* meshproxy = new KX_MeshProxy(m_meshes[mesh]); - return meshproxy; + return meshproxy->NewProxy(true); // XXX Todo Python own. } Py_RETURN_NONE; @@ -2516,7 +2513,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo, KX_RayCast::RayTest(pe, fromPoint, toPoint, callback); if (m_pHitObject) - return m_pHitObject->AddRef(); + return m_pHitObject->GetProxy(); Py_RETURN_NONE; } @@ -2618,7 +2615,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, { PyObject* returnValue = (poly) ? PyTuple_New(4) : PyTuple_New(3); if (returnValue) { // unlikely this would ever fail, if it does python sets an error - PyTuple_SET_ITEM(returnValue, 0, m_pHitObject->AddRef()); + PyTuple_SET_ITEM(returnValue, 0, m_pHitObject->GetProxy()); PyTuple_SET_ITEM(returnValue, 1, PyObjectFrom(callback.m_hitPoint)); PyTuple_SET_ITEM(returnValue, 2, PyObjectFrom(callback.m_hitNormal)); if (poly) @@ -2628,7 +2625,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, // if this field is set, then we can trust that m_hitPolygon is a valid polygon 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); + PyTuple_SET_ITEM(returnValue, 3, polyproxy->NewProxy(true)); } else { @@ -2708,7 +2705,7 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py } if (PyString_Check(value)) { - *object = (KX_GameObject *)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String( PyString_AsString(value) )); + *object = (KX_GameObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String( PyString_AsString(value) )); if (*object) { return true; @@ -2719,11 +2716,13 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py } if (PyObject_TypeCheck(value, &KX_GameObject::Type)) { - *object = static_cast(value); + *object = static_castBGE_PROXY_REF(value); /* sets the error */ - if ((*object)->IsZombiePyErr()) + if (*object==NULL) { + PyErr_SetString(PyExc_RuntimeError, BGE_PROXY_ERROR_MSG); return false; + } return true; } diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index dd85c2f2faa..89517bd76ce 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -807,6 +807,10 @@ public: } KX_ClientObjectInfo* getClientInfo() { return m_pClient_info; } + + CListValue* GetChildren(); + CListValue* GetChildrenRecursive(); + /** * @section Python interface functions. */ @@ -816,8 +820,6 @@ public: virtual int py_delattro(PyObject *attr); virtual PyObject* py_repr(void) { - if (IsZombiePyErr()) - return NULL; return PyString_FromString(GetName().ReadPtr()); } diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index 93d92480b3d..09e19933dd9 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -232,7 +232,7 @@ PyObject* KX_MeshProxy::PyGetVertex(PyObject* self, RAS_TexVert* vertex = m_meshobj->GetVertex(matindex,vertexindex); if (vertex) { - vertexob = new KX_VertexProxy(this, vertex); + vertexob = (new KX_VertexProxy(this, vertex))->NewProxy(true); } } else { @@ -263,7 +263,7 @@ PyObject* KX_MeshProxy::PyGetPolygon(PyObject* self, RAS_Polygon* polygon = m_meshobj->GetPolygon(polyindex); if (polygon) { - polyob = new KX_PolyProxy(m_meshobj, polygon); + polyob = (new KX_PolyProxy(m_meshobj, polygon))->NewProxy(true); } else { PyErr_SetString(PyExc_AttributeError, "polygon is NULL, unknown reason"); @@ -297,13 +297,11 @@ PyObject* KX_MeshProxy::pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_ if(polymat->GetFlag() & RAS_BLENDERMAT) { KX_BlenderMaterial *mat = static_cast(polymat); - PyList_SET_ITEM(materials, i, mat); - Py_INCREF(mat); + PyList_SET_ITEM(materials, i, mat->GetProxy()); } else { KX_PolygonMaterial *mat = static_cast(polymat); - PyList_SET_ITEM(materials, i, mat); - Py_INCREF(mat); + PyList_SET_ITEM(materials, i, mat->GetProxy()); } } return materials; diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index 65190937f35..e1b89eb3095 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -396,7 +396,7 @@ PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self) ShowDeprecationWarning("GetHitObject()", "the hitObject property"); if (m_hitObject) - return m_hitObject->AddRef(); + return m_hitObject->GetProxy(); Py_RETURN_NONE; } @@ -487,7 +487,7 @@ PyObject* KX_MouseFocusSensor::pyattr_get_hit_object(void *self_v, const KX_PYAT KX_MouseFocusSensor* self= static_cast(self_v); if(self->m_hitObject) - return self->m_hitObject->AddRef(); + return self->m_hitObject->GetProxy(); Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index d0d441e2c1c..a667b459c22 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -184,7 +184,7 @@ PyObject* KX_ParentActuator::pyattr_get_object(void *self, const struct KX_PYATT if (!actuator->m_ob) Py_RETURN_NONE; else - return actuator->m_ob->AddRef(); + return actuator->m_ob->GetProxy(); } int KX_ParentActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) @@ -261,7 +261,7 @@ PyObject* KX_ParentActuator::PyGetObject(PyObject* self, PyObject* args) if (ret_name_only) return PyString_FromString(m_ob->GetName()); else - return m_ob->AddRef(); + return m_ob->GetProxy(); } /* <----- */ diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp index e102ca4e0e6..c03d585395c 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.cpp +++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp @@ -109,14 +109,12 @@ PyObject* KX_PolyProxy::py_getattro(PyObject *attr) if(polymat->GetFlag() & RAS_BLENDERMAT) { KX_BlenderMaterial* mat = static_cast(polymat); - Py_INCREF(mat); - return mat; + return mat->GetProxy(); } else { KX_PolygonMaterial* mat = static_cast(polymat); - Py_INCREF(mat); - return mat; + return mat->GetProxy(); } } if (!strcmp(attr_str, "matid")) @@ -258,7 +256,7 @@ 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; + return meshproxy->NewProxy(true); } KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getMaterial, @@ -268,13 +266,11 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getMaterial, if(polymat->GetFlag() & RAS_BLENDERMAT) { KX_BlenderMaterial* mat = static_cast(polymat); - Py_INCREF(mat); - return mat; + return mat->GetProxy(); } else { KX_PolygonMaterial* mat = static_cast(polymat); - Py_INCREF(mat); - return mat; + return mat->GetProxy(); } } diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index 056442f77d9..bf1fbe386e6 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -98,8 +98,7 @@ bool KX_PolygonMaterial::Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingI { PyObject *pyRasty = PyCObject_FromVoidPtr((void*)rasty, NULL); /* new reference */ PyObject *pyCachingInfo = PyCObject_FromVoidPtr((void*) &cachingInfo, NULL); /* new reference */ - - PyObject *ret = PyObject_CallMethod(m_pymaterial, "activate", "(NNO)", pyRasty, pyCachingInfo, (PyObject*) this); + PyObject *ret = PyObject_CallMethod(m_pymaterial, "activate", "(NNO)", pyRasty, pyCachingInfo, (PyObject*) this->m_proxy); if (ret) { bool value = PyInt_AsLong(ret); diff --git a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp index 34c975f6bf6..2c65c184a9c 100644 --- a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp +++ b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp @@ -381,7 +381,7 @@ static PyObject* gPyGetVehicleConstraint(PyObject* self, if (vehicle) { KX_VehicleWrapper* pyWrapper = new KX_VehicleWrapper(vehicle,PHY_GetActiveEnvironment()); - return pyWrapper; + return pyWrapper->NewProxy(true); } } @@ -440,7 +440,7 @@ static PyObject* gPyCreateConstraint(PyObject* self, KX_ConstraintWrapper* wrap = new KX_ConstraintWrapper((enum PHY_ConstraintType)constrainttype,constraintid,PHY_GetActiveEnvironment()); - return wrap; + return wrap->NewProxy(true); } diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 7643a043a7c..1c3bb250b03 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -359,8 +359,7 @@ static STR_String gPyGetCurrentScene_doc = "Gets a reference to the current scene.\n"; static PyObject* gPyGetCurrentScene(PyObject* self) { - Py_INCREF(gp_KetsjiScene); - return (PyObject*) gp_KetsjiScene; + return gp_KetsjiScene->GetProxy(); } static STR_String gPyGetSceneList_doc = @@ -369,7 +368,6 @@ static STR_String gPyGetSceneList_doc = 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(); @@ -380,13 +378,10 @@ static PyObject* gPyGetSceneList(PyObject* self) for (i=0;iat(i); - //list->Add(scene); - PyList_SET_ITEM(list, i, scene); - Py_INCREF(scene); - + PyList_SET_ITEM(list, i, scene->GetProxy()); } - return (PyObject*)list; + return list; } static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *) 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++) { diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index 42e2fdc3e14..9dfc8243330 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -375,7 +375,7 @@ PyObject* KX_RaySensor::pyattr_get_hitobject(void *self_v, const KX_PYATTRIBUTE_ { KX_RaySensor* self = static_cast(self_v); if (self->m_hitObject) - return self->m_hitObject->AddRef(); + return self->m_hitObject->GetProxy(); Py_RETURN_NONE; } @@ -389,7 +389,7 @@ PyObject* KX_RaySensor::PyGetHitObject(PyObject* self) ShowDeprecationWarning("getHitObject()", "the hitObject property"); if (m_hitObject) { - return m_hitObject->AddRef(); + return m_hitObject->GetProxy(); } Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index 65b654ccba4..975e6d9d6cc 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -223,7 +223,7 @@ PyObject* KX_SCA_AddObjectActuator::pyattr_get_object(void *self, const struct K if (!actuator->m_OriginalObject) Py_RETURN_NONE; else - return actuator->m_OriginalObject->AddRef(); + return actuator->m_OriginalObject->GetProxy(); } int KX_SCA_AddObjectActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) @@ -251,7 +251,7 @@ PyObject* KX_SCA_AddObjectActuator::pyattr_get_objectLastCreated(void *self, con if (!actuator->m_lastCreatedObject) Py_RETURN_NONE; else - return actuator->m_lastCreatedObject->AddRef(); + return actuator->m_lastCreatedObject->GetProxy(); } @@ -350,7 +350,7 @@ PyObject* KX_SCA_AddObjectActuator::PyGetObject(PyObject* self, PyObject* args) if (ret_name_only) return PyString_FromString(m_OriginalObject->GetName()); else - return m_OriginalObject->AddRef(); + return m_OriginalObject->GetProxy(); } @@ -492,8 +492,7 @@ PyObject* KX_SCA_AddObjectActuator::PyGetLastCreatedObject(PyObject* self) // it means the object has ended, The BGE python api crashes in many places if the object is returned. if (result && (static_cast(result))->GetSGNode()) { - result->AddRef(); - return result; + return result->GetProxy(); } // don't return NULL to python anymore, it gives trouble in the scripts Py_RETURN_NONE; diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index 9097ca6c85e..999b017b64c 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -110,7 +110,7 @@ PyObject* KX_SCA_ReplaceMeshActuator::pyattr_get_mesh(void *self, const struct K if (!actuator->m_mesh) Py_RETURN_NONE; KX_MeshProxy* meshproxy = new KX_MeshProxy(actuator->m_mesh); - return meshproxy; + return meshproxy->NewProxy(true); } int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index c99fa363ffe..d8d6f215213 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -924,8 +924,6 @@ int KX_Scene::NewRemoveObject(class CValue* gameobj) { int ret; KX_GameObject* newobj = (KX_GameObject*) gameobj; - - gameobj->SetZombie(true); /* disallow future python access */ // keep the blender->game object association up to date // note that all the replicas of an object will have the same @@ -1623,13 +1621,13 @@ PyObject* KX_Scene::pyattr_get_name(void *self_v, const KX_PYATTRIBUTE_DEF *attr PyObject* KX_Scene::pyattr_get_objects(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_Scene* self= static_cast(self_v); - return self->GetObjectList()->AddRef(); + return self->GetObjectList()->GetProxy(); } PyObject* KX_Scene::pyattr_get_active_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_Scene* self= static_cast(self_v); - return self->GetActiveCamera()->AddRef(); + return self->GetActiveCamera()->GetProxy(); } /* __dict__ only for the purpose of giving useful dir() results */ @@ -1717,7 +1715,7 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_Scene, getLightList, "Returns a list of all lights in the scene.\n" ) { - return (PyObject*) m_lightlist->AddRef(); + return m_lightlist->GetProxy(); } KX_PYMETHODDEF_DOC_NOARGS(KX_Scene, getObjectList, @@ -1726,7 +1724,7 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_Scene, getObjectList, ) { // ShowDeprecationWarning("getObjectList()", "the objects property"); // XXX Grr, why doesnt this work? - return (PyObject*) m_objectlist->AddRef(); + return m_objectlist->GetProxy(); } KX_PYMETHODDEF_DOC_NOARGS(KX_Scene, getName, @@ -1755,6 +1753,5 @@ KX_PYMETHODDEF_DOC(KX_Scene, addObject, SCA_IObject* replica = AddReplicaObject((SCA_IObject*)ob, other, time); - replica->AddRef(); - return replica; + return replica->GetProxy(); } \ No newline at end of file diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index 2d3022a68f7..b52cc81f68b 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -291,23 +291,39 @@ PyObject* KX_SceneActuator::pyattr_get_camera(void *self, const struct KX_PYATTR KX_SceneActuator* actuator = static_cast(self); if (!actuator->m_camera) Py_RETURN_NONE; - actuator->m_camera->AddRef(); - return actuator->m_camera; + + return actuator->m_camera->GetProxy(); } int KX_SceneActuator::pyattr_set_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_SceneActuator* actuator = static_cast(self); KX_Camera *camOb; - + + if(value==Py_None) + { + if (actuator->m_camera) + actuator->m_camera->UnregisterActuator(actuator); + + actuator->m_camera= NULL; + return 0; + } + if (PyObject_TypeCheck(value, &KX_Camera::Type)) { - camOb = static_cast(value); + KX_Camera *camOb= static_castBGE_PROXY_REF(value); + + if(camOb==NULL) + { + PyErr_SetString(PyExc_RuntimeError, BGE_PROXY_ERROR_MSG); + return 1; + } + if (actuator->m_camera) actuator->m_camera->UnregisterActuator(actuator); + actuator->m_camera = camOb; - if (actuator->m_camera) - actuator->m_camera->RegisterActuator(actuator); + actuator->m_camera->RegisterActuator(actuator); return 0; } @@ -423,11 +439,21 @@ PyObject* KX_SceneActuator::PySetCamera(PyObject* self, PyObject *cam; if (PyArg_ParseTuple(args, "O!:setCamera", &KX_Camera::Type, &cam)) { + KX_Camera *new_camera; + + new_camera = static_castBGE_PROXY_REF(cam); + if(new_camera==NULL) + { + PyErr_SetString(PyExc_RuntimeError, BGE_PROXY_ERROR_MSG); + return NULL; + } + if (m_camera) m_camera->UnregisterActuator(this); - m_camera = (KX_Camera*) cam; - if (m_camera) - m_camera->RegisterActuator(this); + + m_camera= new_camera; + + m_camera->RegisterActuator(this); Py_RETURN_NONE; } PyErr_Clear(); diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 70fa6326c19..7265ade6789 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -342,7 +342,7 @@ PyObject* KX_TouchSensor::PyGetHitObject(PyObject* self) /* otherwise, this leaks memory */ if (m_hitObject) { - return m_hitObject->AddRef(); + return m_hitObject->GetProxy(); } Py_RETURN_NONE; } @@ -356,7 +356,7 @@ 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 */ /* Edit, this seems ok and not to leak memory - Campbell */ - return m_colliders->AddRef(); + return m_colliders->GetProxy(); } /*getTouchMaterial and setTouchMaterial were never added to the api, @@ -400,7 +400,7 @@ PyObject* KX_TouchSensor::pyattr_get_object_hit(void *self_v, const KX_PYATTRIBU KX_TouchSensor* self= static_cast(self_v); if (self->m_hitObject) - return self->m_hitObject->AddRef(); + return self->m_hitObject->GetProxy(); else Py_RETURN_NONE; } @@ -408,7 +408,7 @@ PyObject* KX_TouchSensor::pyattr_get_object_hit(void *self_v, const KX_PYATTRIBU PyObject* KX_TouchSensor::pyattr_get_object_hit_list(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_TouchSensor* self= static_cast(self_v); - return self->m_colliders->AddRef(); + return self->m_colliders->GetProxy(); } diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 29c6a21b0b3..5ea08f855a3 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -481,7 +481,7 @@ PyObject* KX_TrackToActuator::pyattr_get_object(void *self, const struct KX_PYAT if (!actuator->m_object) Py_RETURN_NONE; else - return actuator->m_object->AddRef(); + return actuator->m_object->GetProxy(); } int KX_TrackToActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) @@ -560,7 +560,7 @@ PyObject* KX_TrackToActuator::PyGetObject(PyObject* self, PyObject* args) if (ret_name_only) return PyString_FromString(m_object->GetName()); else - return m_object->AddRef(); + return m_object->GetProxy(); } diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp index 98f5a1ea87d..0ba55fe5986 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp @@ -48,7 +48,10 @@ PyObject* KX_VehicleWrapper::PyAddWheel(PyObject* self, if (PyArg_ParseTuple(args,"OOOOffi:addWheel",&wheelGameObject,&pylistPos,&pylistDir,&pylistAxleDir,&suspensionRestLength,&wheelRadius,&hasSteering)) { - KX_GameObject* gameOb = (KX_GameObject*) wheelGameObject; + KX_GameObject *gameOb; + if (!ConvertPythonToGameObject(wheelGameObject, &gameOb, false)) + return NULL; + if (gameOb->GetSGNode()) { diff --git a/source/gameengine/VideoTexture/FilterSource.h b/source/gameengine/VideoTexture/FilterSource.h index 6385ed5108f..254e0a02679 100644 --- a/source/gameengine/VideoTexture/FilterSource.h +++ b/source/gameengine/VideoTexture/FilterSource.h @@ -225,7 +225,7 @@ protected: // otherwise if only vertical interpolation is needed } } - else if ((y & 1) == 1) + else if ((y & 1) == 1) { // if this pixel is on the edge if (isEdge(x, y, size)) { @@ -239,6 +239,7 @@ protected: d = interpolV(m_buffU + offset) - 128; e = interpolV(m_buffV + offset) - 128; } + } // convert to RGB // R = clip(( 298 * C + 409 * E + 128) >> 8) // G = clip(( 298 * C - 100 * D - 208 * E + 128) >> 8) diff --git a/source/gameengine/VideoTexture/ImageRender.cpp b/source/gameengine/VideoTexture/ImageRender.cpp index 6ef62f64d3f..9a3c4fea70e 100644 --- a/source/gameengine/VideoTexture/ImageRender.cpp +++ b/source/gameengine/VideoTexture/ImageRender.cpp @@ -434,26 +434,35 @@ static int ImageMirror_init (PyObject * pySelf, PyObject * args, PyObject * kwds { // get scene pointer KX_Scene * scenePtr (NULL); - if (scene != NULL && PyObject_TypeCheck(scene, &KX_Scene::Type)) - scenePtr = static_cast(scene); - else + if (scene != NULL && PyObject_TypeCheck(scene, &KX_Scene::Type)) + scenePtr = static_castBGE_PROXY_REF(scene); + else THRWEXCP(SceneInvalid, S_OK); - + + if(scenePtr==NULL) /* incase the python proxy reference is invalid */ + THRWEXCP(SceneInvalid, S_OK); + // get observer pointer KX_GameObject * observerPtr (NULL); if (observer != NULL && PyObject_TypeCheck(observer, &KX_GameObject::Type)) - observerPtr = static_cast(observer); + observerPtr = static_castBGE_PROXY_REF(observer); else if (observer != NULL && PyObject_TypeCheck(observer, &KX_Camera::Type)) - observerPtr = static_cast(observer); + observerPtr = static_castBGE_PROXY_REF(observer); else THRWEXCP(ObserverInvalid, S_OK); + + if(observerPtr==NULL) /* incase the python proxy reference is invalid */ + THRWEXCP(ObserverInvalid, S_OK); // get mirror pointer KX_GameObject * mirrorPtr (NULL); if (mirror != NULL && PyObject_TypeCheck(mirror, &KX_GameObject::Type)) - mirrorPtr = static_cast(mirror); + mirrorPtr = static_castBGE_PROXY_REF(mirror); else THRWEXCP(MirrorInvalid, S_OK); + + if(mirrorPtr==NULL) /* incase the python proxy reference is invalid */ + THRWEXCP(MirrorInvalid, S_OK); // locate the material in the mirror RAS_IPolyMaterial * material = getMaterial(mirror, materialID); -- cgit v1.2.3 From 7dbc9dc719c3eb0823e4f9e7ae94a479f9427ea7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 19 Apr 2009 14:57:52 +0000 Subject: BGE Python API cleanup - no functionality changes - comments to PyObjectPlus.h - remove unused/commented junk. - renamed PyDestructor to py_base_dealloc for consistency - all the PyTypeObject's were still using the sizeof() their class, can use sizeof(PyObjectPlus_Proxy) now which is smaller too. --- source/gameengine/Converter/BL_ActionActuator.cpp | 4 +- .../Converter/BL_ShapeActionActuator.cpp | 4 +- source/gameengine/Expressions/ListValue.cpp | 4 +- source/gameengine/Expressions/PyObjectPlus.cpp | 93 ++++++++++--------- source/gameengine/Expressions/PyObjectPlus.h | 102 ++++++--------------- source/gameengine/Expressions/Value.cpp | 4 +- .../gameengine/GameLogic/SCA_2DFilterActuator.cpp | 4 +- source/gameengine/GameLogic/SCA_ANDController.cpp | 4 +- source/gameengine/GameLogic/SCA_ActuatorSensor.cpp | 4 +- source/gameengine/GameLogic/SCA_AlwaysSensor.cpp | 4 +- source/gameengine/GameLogic/SCA_DelaySensor.cpp | 4 +- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 4 +- source/gameengine/GameLogic/SCA_IObject.cpp | 4 +- source/gameengine/GameLogic/SCA_ISensor.cpp | 4 +- source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 4 +- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 4 +- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 4 +- source/gameengine/GameLogic/SCA_NANDController.cpp | 4 +- source/gameengine/GameLogic/SCA_NORController.cpp | 4 +- source/gameengine/GameLogic/SCA_ORController.cpp | 4 +- .../gameengine/GameLogic/SCA_PropertyActuator.cpp | 4 +- source/gameengine/GameLogic/SCA_PropertySensor.cpp | 4 +- .../gameengine/GameLogic/SCA_PythonController.cpp | 12 +-- source/gameengine/GameLogic/SCA_RandomActuator.cpp | 4 +- source/gameengine/GameLogic/SCA_RandomSensor.cpp | 4 +- source/gameengine/GameLogic/SCA_XNORController.cpp | 4 +- source/gameengine/GameLogic/SCA_XORController.cpp | 4 +- source/gameengine/Ketsji/BL_Shader.cpp | 4 +- .../Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp | 4 +- .../Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp | 4 +- source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 4 +- source/gameengine/Ketsji/KX_CDActuator.cpp | 4 +- source/gameengine/Ketsji/KX_Camera.cpp | 4 +- source/gameengine/Ketsji/KX_CameraActuator.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 | 4 +- 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 | 4 +- source/gameengine/Ketsji/KX_ObjectActuator.cpp | 4 +- source/gameengine/Ketsji/KX_ParentActuator.cpp | 4 +- .../gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp | 4 +- source/gameengine/Ketsji/KX_PolyProxy.cpp | 4 +- source/gameengine/Ketsji/KX_PolygonMaterial.cpp | 4 +- source/gameengine/Ketsji/KX_RadarSensor.cpp | 4 +- source/gameengine/Ketsji/KX_RaySensor.cpp | 4 +- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp | 4 +- .../gameengine/Ketsji/KX_SCA_DynamicActuator.cpp | 4 +- .../gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp | 4 +- .../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_TouchSensor.cpp | 4 +- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 4 +- source/gameengine/Ketsji/KX_VehicleWrapper.cpp | 4 +- source/gameengine/Ketsji/KX_VertexProxy.cpp | 4 +- source/gameengine/Ketsji/KX_VisibilityActuator.cpp | 4 +- 63 files changed, 200 insertions(+), 247 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 960eafda230..530a74dfb12 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -968,9 +968,9 @@ PyTypeObject BL_ActionActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "BL_ActionActuator", - sizeof(BL_ActionActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index 0d35b26d604..783fdd814b7 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -423,9 +423,9 @@ PyTypeObject BL_ShapeActionActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "BL_ShapeActionActuator", - sizeof(BL_ShapeActionActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index eaed2b5c400..5bb1eb0aeb9 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -223,10 +223,10 @@ PyTypeObject CListValue::Type = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "CListValue", /*tp_name*/ - sizeof(CListValue), /*tp_basicsize*/ + sizeof(PyObjectPlus_Proxy), /*tp_basicsize*/ 0, /*tp_itemsize*/ /* methods */ - PyDestructor, /*tp_dealloc*/ + py_base_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 2c5ba3f39fc..3c414c6b16d 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -59,10 +59,10 @@ PyTypeObject PyObjectPlus::Type = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "PyObjectPlus", /*tp_name*/ - sizeof(PyObjectPlus), /*tp_basicsize*/ + sizeof(PyObjectPlus_Proxy), /*tp_basicsize*/ 0, /*tp_itemsize*/ /* methods */ - PyDestructor, + py_base_dealloc, 0, 0, 0, @@ -85,7 +85,7 @@ PyObjectPlus::~PyObjectPlus() // assert(ob_refcnt==0); } -void PyObjectPlus::PyDestructor(PyObject *self) // python wrapper +void PyObjectPlus::py_base_dealloc(PyObject *self) // python wrapper { PyObjectPlus *self_plus= BGE_PROXY_REF(self); if(self_plus) { @@ -108,7 +108,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_O}, + {"isA", (PyCFunction) sPyisA, METH_O}, {NULL, NULL} /* Sentinel */ }; @@ -130,6 +130,49 @@ PyParentObject PyObjectPlus::Parents[] = {&PyObjectPlus::Type, NULL}; /*------------------------------ * PyObjectPlus attributes -- attributes ------------------------------*/ + + +/* This should be the entry in Type since it takes the C++ class from PyObjectPlus_Proxy */ +PyObject *PyObjectPlus::py_base_getattro(PyObject * self, PyObject *attr) +{ + PyObjectPlus *self_plus= BGE_PROXY_REF(self); + if(self_plus==NULL) { + if(!strcmp("isValid", PyString_AsString(attr))) { + Py_RETURN_TRUE; + } + PyErr_SetString(PyExc_RuntimeError, BGE_PROXY_ERROR_MSG); + return NULL; + } + return self_plus->py_getattro(attr); +} + +/* This should be the entry in Type since it takes the C++ class from PyObjectPlus_Proxy */ +int PyObjectPlus::py_base_setattro(PyObject *self, PyObject *attr, PyObject *value) +{ + PyObjectPlus *self_plus= BGE_PROXY_REF(self); + if(self_plus==NULL) { + PyErr_SetString(PyExc_RuntimeError, BGE_PROXY_ERROR_MSG); + return -1; + } + + if (value==NULL) + return self_plus->py_delattro(attr); + + return self_plus->py_setattro(attr, value); +} + +PyObject *PyObjectPlus::py_base_repr(PyObject *self) // This should be the entry in Type. +{ + + PyObjectPlus *self_plus= BGE_PROXY_REF(self); + if(self_plus==NULL) { + PyErr_SetString(PyExc_RuntimeError, BGE_PROXY_ERROR_MSG); + return NULL; + } + + return self_plus->py_repr(); +} + PyObject *PyObjectPlus::py_getattro(PyObject* attr) { PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \ @@ -151,8 +194,6 @@ PyObject *PyObjectPlus::py_getattro(PyObject* attr) } /* end py_getattro_up copy */ } - //if (streq(attr, "type")) - // return Py_BuildValue("s", (*(GetParents()))->tp_name); } int PyObjectPlus::py_delattro(PyObject* attr) @@ -163,8 +204,6 @@ int PyObjectPlus::py_delattro(PyObject* attr) int PyObjectPlus::py_setattro(PyObject *attr, PyObject* value) { - //return PyObject::py_setattro(attr,value); - //cerr << "Unknown attribute" << endl; PyErr_SetString(PyExc_AttributeError, "attribute cant be set"); return PY_SET_ATTR_MISSING; } @@ -275,20 +314,6 @@ PyObject *PyObjectPlus::py_get_attrdef(void *self, const PyAttributeDef *attrdef } } -#if 0 -PyObject *PyObjectPlus::py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr) -{ - char *attr_str= PyString_AsString(attr); - const PyAttributeDef *attrdef; - - for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++) - if (!strcmp(attr_str, attrdef->m_name)) - return py_get_attrdef(self, attrdef); - - return NULL; -} -#endif - int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyObject *value) { void *undoBuffer = NULL; @@ -714,29 +739,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb return 0; } -#if 0 -int PyObjectPlus::py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value) -{ - const PyAttributeDef *attrdef; - char *attr_str= PyString_AsString(attr); - for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++) - { - if (!strcmp(attr_str, 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 PY_SET_ATTR_FAIL; - } - - return py_set_attrdef(self, attrdef, value); - } - } - return PY_SET_ATTR_MISSING; -} -#endif /*------------------------------ * PyObjectPlus repr -- representations @@ -777,7 +780,7 @@ bool PyObjectPlus::isA(const char *mytypename) // check typename of each parent return false; } -PyObject *PyObjectPlus::Py_isA(PyObject *value) // Python wrapper for isA +PyObject *PyObjectPlus::PyisA(PyObject *self, PyObject *value) // Python wrapper for isA { if (PyType_Check(value)) { return PyBool_FromLong(isA((PyTypeObject *)value)); diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 3be9a2f2bcb..9f30e6570ee 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -50,13 +50,13 @@ also in api2_2x/gen_utils.h */ #ifndef Py_RETURN_NONE -#define Py_RETURN_NONE return Py_BuildValue("O", Py_None) +#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None #endif #ifndef Py_RETURN_FALSE -#define Py_RETURN_FALSE return PyBool_FromLong(0) +#define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False #endif #ifndef Py_RETURN_TRUE -#define Py_RETURN_TRUE return PyBool_FromLong(1) +#define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True #endif /* for pre Py 2.5 */ @@ -92,7 +92,7 @@ typedef struct { #define BGE_PROXY_PYOWNS(_self) (((PyObjectPlus_Proxy *)_self)->py_owns) /* Note, sometimes we dont care what BGE type this is as long as its a proxy */ -#define BGE_PROXY_CHECK_TYPE(_self) ((_self)->ob_type->tp_dealloc == PyDestructor) +#define BGE_PROXY_CHECK_TYPE(_self) ((_self)->ob_type->tp_dealloc == py_base_dealloc) // This must be the first line of each @@ -429,80 +429,34 @@ public: PyObject *m_proxy; /* actually a PyObjectPlus_Proxy */ virtual ~PyObjectPlus(); // destructor - static void PyDestructor(PyObject *self); // python wrapper -// void INCREF(void) { -// Py_INCREF(this); -// }; // incref method -// void DECREF(void) { -// Py_DECREF(this); -// }; // decref method + /* These static functions are referenced by ALL PyObjectPlus_Proxy types + * they take the C++ reference from the PyObjectPlus_Proxy and call + * its own virtual py_getattro, py_setattro etc. functions. + */ + static void py_base_dealloc(PyObject *self); + static PyObject* py_base_getattro(PyObject * self, PyObject *attr); + static int py_base_setattro(PyObject *self, PyObject *attr, PyObject *value); + static PyObject* py_base_repr(PyObject *self); + + /* These are all virtual python methods that are defined in each class + * Our own fake subclassing calls these on each class, then calls the parent */ + virtual PyObject* py_getattro(PyObject *attr); + virtual int py_delattro(PyObject *attr); + virtual int py_setattro(PyObject *attr, PyObject *value); + virtual PyObject* py_repr(void); + + static PyObject* py_get_attrdef(void *self, const PyAttributeDef *attrdef); + static int py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyObject *value); - virtual PyObject *py_getattro(PyObject *attr); // py_getattro method - static PyObject *py_base_getattro(PyObject * self, PyObject *attr) // This should be the entry in Type. - { - PyObjectPlus *self_plus= BGE_PROXY_REF(self); - if(self_plus==NULL) { - if(!strcmp("isValid", PyString_AsString(attr))) { - Py_RETURN_TRUE; - } - PyErr_SetString(PyExc_RuntimeError, "data has been removed"); - return NULL; - } - return self_plus->py_getattro(attr); - } - - static PyObject* py_get_attrdef(void *self, const PyAttributeDef *attrdef); - static int py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyObject *value); - -#if 0 - static PyObject *py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr); - static int py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value); -#endif - - virtual int py_delattro(PyObject *attr); - virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method - static int py_base_setattro(PyObject *self, PyObject *attr, PyObject *value) // the PyType should reference this - { - PyObjectPlus *self_plus= BGE_PROXY_REF(self); - if(self_plus==NULL) { - PyErr_SetString(PyExc_RuntimeError, "data has been removed"); - return -1; - } - - if (value==NULL) - return self_plus->py_delattro(attr); - - return self_plus->py_setattro(attr, value); - } - - virtual PyObject *py_repr(void); // py_repr method - static PyObject *py_base_repr(PyObject *self) // This should be the entry in Type. - { - - PyObjectPlus *self_plus= BGE_PROXY_REF(self); - if(self_plus==NULL) { - PyErr_SetString(PyExc_RuntimeError, "data has been removed"); - return NULL; - } - - return self_plus->py_repr(); - } - - // isA methods + /* isA() methods, shonky replacement for pythons issubclass() + * which we cant use because we have our own subclass system */ bool isA(PyTypeObject *T); bool isA(const char *mytypename); - PyObject *Py_isA(PyObject *value); - static PyObject *sPy_isA(PyObject *self, PyObject *value) - { - PyObjectPlus *self_plus= BGE_PROXY_REF(self); - if(self_plus==NULL) { - PyErr_SetString(PyExc_RuntimeError, "data has been removed"); - return NULL; - } - - return self_plus->Py_isA(value); - } + PyObject *PyisA(PyObject *value); + //static PyObject *sPy_isA(PyObject *self, PyObject *value); + + KX_PYMETHOD_O(PyObjectPlus,isA); /* Kindof dumb, always returns True, the false case is checked for, before this function gets accessed */ static PyObject* pyattr_get_is_valid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index 7958c16ca81..17813d0ab52 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -40,9 +40,9 @@ PyTypeObject CValue::Type = { PyObject_HEAD_INIT(NULL) 0, "CValue", - sizeof(CValue), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp index 171d3fbc265..251a586308e 100644 --- a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp +++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp @@ -113,9 +113,9 @@ PyTypeObject SCA_2DFilterActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_2DFilterActuator", - sizeof(SCA_2DFilterActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_ANDController.cpp b/source/gameengine/GameLogic/SCA_ANDController.cpp index cb62e2b5a1d..1cb03f375cb 100644 --- a/source/gameengine/GameLogic/SCA_ANDController.cpp +++ b/source/gameengine/GameLogic/SCA_ANDController.cpp @@ -110,9 +110,9 @@ PyTypeObject SCA_ANDController::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_ANDController", - sizeof(SCA_ANDController), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp index 99f3788ad2e..c51555a02b4 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp @@ -125,9 +125,9 @@ PyTypeObject SCA_ActuatorSensor::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_ActuatorSensor", - sizeof(SCA_ActuatorSensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp index a7b0e5a14d2..b7ecb0233a1 100644 --- a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp +++ b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp @@ -108,9 +108,9 @@ PyTypeObject SCA_AlwaysSensor::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_AlwaysSensor", - sizeof(SCA_AlwaysSensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp index 3f08f301dc1..dad85a435c8 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp +++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp @@ -134,9 +134,9 @@ PyTypeObject SCA_DelaySensor::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_DelaySensor", - sizeof(SCA_DelaySensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index 7fa55cfb1ee..1ae78321959 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -220,9 +220,9 @@ PyTypeObject SCA_ILogicBrick::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_ILogicBrick", - sizeof(SCA_ILogicBrick), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp index d1ce377316b..75804525e7a 100644 --- a/source/gameengine/GameLogic/SCA_IObject.cpp +++ b/source/gameengine/GameLogic/SCA_IObject.cpp @@ -378,9 +378,9 @@ PyTypeObject SCA_IObject::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_IObject", - sizeof(SCA_IObject), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index 3c21cf66e09..269038db4f9 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -396,9 +396,9 @@ PyTypeObject SCA_ISensor::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_ISensor", - sizeof(SCA_ISensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 9cf850ceb3e..087fb036fae 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -269,9 +269,9 @@ PyTypeObject SCA_JoystickSensor::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_JoystickSensor", - sizeof(SCA_JoystickSensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index 0bf19360b15..3e19c880c4d 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -615,9 +615,9 @@ PyTypeObject SCA_KeyboardSensor::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_KeyboardSensor", - sizeof(SCA_KeyboardSensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index 86e64491f6a..0c30f503068 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -303,9 +303,9 @@ PyTypeObject SCA_MouseSensor::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_MouseSensor", - sizeof(SCA_MouseSensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_NANDController.cpp b/source/gameengine/GameLogic/SCA_NANDController.cpp index bddd5f4d3ab..703c9c1bbaf 100644 --- a/source/gameengine/GameLogic/SCA_NANDController.cpp +++ b/source/gameengine/GameLogic/SCA_NANDController.cpp @@ -110,9 +110,9 @@ PyTypeObject SCA_NANDController::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_NANDController", - sizeof(SCA_NANDController), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_NORController.cpp b/source/gameengine/GameLogic/SCA_NORController.cpp index 3ee073523c3..06acae5a81a 100644 --- a/source/gameengine/GameLogic/SCA_NORController.cpp +++ b/source/gameengine/GameLogic/SCA_NORController.cpp @@ -110,9 +110,9 @@ PyTypeObject SCA_NORController::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_NORController", - sizeof(SCA_NORController), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_ORController.cpp b/source/gameengine/GameLogic/SCA_ORController.cpp index 91d5e56d4f3..319ff04f776 100644 --- a/source/gameengine/GameLogic/SCA_ORController.cpp +++ b/source/gameengine/GameLogic/SCA_ORController.cpp @@ -102,9 +102,9 @@ PyTypeObject SCA_ORController::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_ORController", - sizeof(SCA_ORController), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index 9dbdc0e89d1..4bcb59d0812 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -236,9 +236,9 @@ PyTypeObject SCA_PropertyActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_PropertyActuator", - sizeof(SCA_PropertyActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp index 9ae7be16b12..5c8a14db563 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp +++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp @@ -309,9 +309,9 @@ PyTypeObject SCA_PropertySensor::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_PropertySensor", - sizeof(SCA_PropertySensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 687ae421af1..0d096385fa9 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -227,9 +227,9 @@ PyTypeObject SCA_PythonController::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_PythonController", - sizeof(SCA_PythonController), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, @@ -441,9 +441,7 @@ SCA_PythonController::PyGetSensor(PyObject* self, PyObject* value) } } - char emsg[96]; - PyOS_snprintf( emsg, sizeof( emsg ), "Unable to find requested sensor \"%s\"", scriptArg ); - PyErr_SetString(PyExc_AttributeError, emsg); + PyErr_Format(PyExc_AttributeError, "Unable to find requested sensor \"%s\"", scriptArg); return NULL; } @@ -470,9 +468,7 @@ SCA_PythonController::PyGetActuator(PyObject* self, PyObject* value) } } - char emsg[96]; - PyOS_snprintf( emsg, sizeof( emsg ), "Unable to find requested actuator \"%s\"", scriptArg ); - PyErr_SetString(PyExc_AttributeError, emsg); + PyErr_Format(PyExc_AttributeError, "Unable to find requested actuator \"%s\"", scriptArg); return NULL; } diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp index d5d993c4ba6..7a3fdc862f6 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp +++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp @@ -315,9 +315,9 @@ PyTypeObject SCA_RandomActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_RandomActuator", - sizeof(SCA_RandomActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp index 3179c8522f9..b0bc518825b 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp +++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp @@ -130,9 +130,9 @@ PyTypeObject SCA_RandomSensor::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_RandomSensor", - sizeof(SCA_RandomSensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_XNORController.cpp b/source/gameengine/GameLogic/SCA_XNORController.cpp index 10757e1c935..e9bb37ee958 100644 --- a/source/gameengine/GameLogic/SCA_XNORController.cpp +++ b/source/gameengine/GameLogic/SCA_XNORController.cpp @@ -114,9 +114,9 @@ PyTypeObject SCA_XNORController::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_XNORController", - sizeof(SCA_XNORController), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/GameLogic/SCA_XORController.cpp b/source/gameengine/GameLogic/SCA_XORController.cpp index d2290fe207a..791a139975f 100644 --- a/source/gameengine/GameLogic/SCA_XORController.cpp +++ b/source/gameengine/GameLogic/SCA_XORController.cpp @@ -114,9 +114,9 @@ PyTypeObject SCA_XORController::Type = { PyObject_HEAD_INIT(NULL) 0, "SCA_XORController", - sizeof(SCA_XORController), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index aae4fd74a08..01b6805ae7a 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -775,9 +775,9 @@ PyTypeObject BL_Shader::Type = { PyObject_HEAD_INIT(NULL) 0, "BL_Shader", - sizeof(BL_Shader), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp index d6d59692745..c3b27d4d6e6 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp @@ -108,9 +108,9 @@ PyTypeObject KX_NetworkMessageActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_NetworkMessageActuator", - sizeof(KX_NetworkMessageActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp index 8aca2e372d1..9fd30450515 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp @@ -171,9 +171,9 @@ PyTypeObject KX_NetworkMessageSensor::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_NetworkMessageSensor", - sizeof(KX_NetworkMessageSensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index bdad21f76eb..6722cd232fe 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -756,9 +756,9 @@ PyTypeObject KX_BlenderMaterial::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_BlenderMaterial", - sizeof(KX_BlenderMaterial), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_CDActuator.cpp b/source/gameengine/Ketsji/KX_CDActuator.cpp index c3d28656159..56610f2e787 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.cpp +++ b/source/gameengine/Ketsji/KX_CDActuator.cpp @@ -161,9 +161,9 @@ PyTypeObject KX_CDActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_SoundActuator", - sizeof(KX_CDActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index daa37056d68..db8186e4586 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -509,9 +509,9 @@ PyTypeObject KX_Camera::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_Camera", - sizeof(KX_Camera), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index a1159dbc23f..35165af1f82 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -374,9 +374,9 @@ PyTypeObject KX_CameraActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_CameraActuator", - sizeof(KX_CameraActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index 3b8b4a93fd6..fc15568ae4f 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -569,9 +569,9 @@ PyTypeObject KX_ConstraintActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_ConstraintActuator", - sizeof(KX_ConstraintActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp index 6f4d970c568..d5577584616 100644 --- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp @@ -72,9 +72,9 @@ PyTypeObject KX_ConstraintWrapper::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_ConstraintWrapper", - sizeof(KX_ConstraintWrapper), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp index cef874900a6..215c30d65b5 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.cpp +++ b/source/gameengine/Ketsji/KX_GameActuator.cpp @@ -211,9 +211,9 @@ PyTypeObject KX_GameActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_GameActuator", - sizeof(KX_GameActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 402c242315a..60d2fb0a2f6 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1367,9 +1367,9 @@ PyTypeObject KX_GameObject::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_GameObject", - sizeof(KX_GameObject), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index 644f8ac8113..558b77c1f77 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -416,9 +416,9 @@ PyTypeObject KX_IpoActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_IpoActuator", - sizeof(KX_IpoActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp index 29033c2d802..713838c88ec 100644 --- a/source/gameengine/Ketsji/KX_Light.cpp +++ b/source/gameengine/Ketsji/KX_Light.cpp @@ -328,9 +328,9 @@ PyTypeObject KX_LightObject::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_LightObject", - sizeof(KX_LightObject), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index 09e19933dd9..8ce5e888349 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -49,9 +49,9 @@ PyTypeObject KX_MeshProxy::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_MeshProxy", - sizeof(KX_MeshProxy), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index e1b89eb3095..b59f18bf935 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -338,9 +338,9 @@ PyTypeObject KX_MouseFocusSensor::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_MouseFocusSensor", - sizeof(KX_MouseFocusSensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index b9d1939e5db..0489b7090e9 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -289,9 +289,9 @@ PyTypeObject KX_NearSensor::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_NearSensor", - sizeof(KX_NearSensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index 0ea051723dc..4f1890772d7 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -280,9 +280,9 @@ PyTypeObject KX_ObjectActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_ObjectActuator", - sizeof(KX_ObjectActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index a667b459c22..5263dd72065 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -142,9 +142,9 @@ PyTypeObject KX_ParentActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_ParentActuator", - sizeof(KX_ParentActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp index 9da86193622..f000d079927 100644 --- a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp +++ b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp @@ -124,9 +124,9 @@ PyTypeObject KX_PhysicsObjectWrapper::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_PhysicsObjectWrapper", - sizeof(KX_PhysicsObjectWrapper), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp index c03d585395c..e227ba09fba 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.cpp +++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp @@ -42,9 +42,9 @@ PyTypeObject KX_PolyProxy::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_PolyProxy", - sizeof(KX_PolyProxy), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index bf1fbe386e6..46d04486cc6 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -211,9 +211,9 @@ PyTypeObject KX_PolygonMaterial::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_PolygonMaterial", - sizeof(KX_PolygonMaterial), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp index b9abe69633e..40af3b22aeb 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.cpp +++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp @@ -254,9 +254,9 @@ PyTypeObject KX_RadarSensor::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_RadarSensor", - sizeof(KX_RadarSensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index 9dfc8243330..080a217b9bd 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -324,9 +324,9 @@ PyTypeObject KX_RaySensor::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_RaySensor", - sizeof(KX_RaySensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index 975e6d9d6cc..1ab4bd21120 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -170,9 +170,9 @@ PyTypeObject KX_SCA_AddObjectActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_SCA_AddObjectActuator", - sizeof(KX_SCA_AddObjectActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp index e03b153d813..9c9cdcd6c4c 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp @@ -54,9 +54,9 @@ KX_SCA_DynamicActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_SCA_DynamicActuator", - sizeof(KX_SCA_DynamicActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp index 0db9e1c4930..3b42577810e 100644 --- a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp @@ -97,9 +97,9 @@ PyTypeObject KX_SCA_EndObjectActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_SCA_EndObjectActuator", - sizeof(KX_SCA_EndObjectActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index 999b017b64c..b678b14c2f5 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -56,9 +56,9 @@ KX_SCA_ReplaceMeshActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_SCA_ReplaceMeshActuator", - sizeof(KX_SCA_ReplaceMeshActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index d8d6f215213..96f2f3e8ed3 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1582,9 +1582,9 @@ PyTypeObject KX_Scene::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_Scene", - sizeof(KX_Scene), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index b52cc81f68b..414251d6b06 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -229,9 +229,9 @@ PyTypeObject KX_SceneActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_SceneActuator", - sizeof(KX_SceneActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index 6381c43e1c6..d7449c7effa 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -237,9 +237,9 @@ PyTypeObject KX_SoundActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_SoundActuator", - sizeof(KX_SoundActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_StateActuator.cpp b/source/gameengine/Ketsji/KX_StateActuator.cpp index a251a987935..3cfa40c6f80 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.cpp +++ b/source/gameengine/Ketsji/KX_StateActuator.cpp @@ -112,9 +112,9 @@ PyTypeObject KX_StateActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_StateActuator", - sizeof(KX_StateActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 7265ade6789..79da4984740 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -245,9 +245,9 @@ PyTypeObject KX_TouchSensor::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_TouchSensor", - sizeof(KX_TouchSensor), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 5ea08f855a3..6c522b35528 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -428,9 +428,9 @@ PyTypeObject KX_TrackToActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_TrackToActuator", - sizeof(KX_TrackToActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp index 0ba55fe5986..558b2849cc7 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp @@ -305,9 +305,9 @@ PyTypeObject KX_VehicleWrapper::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_VehicleWrapper", - sizeof(KX_VehicleWrapper), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp index 6a160dff7b7..4954e94f3e4 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.cpp +++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp @@ -40,9 +40,9 @@ PyTypeObject KX_VertexProxy::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_VertexProxy", - sizeof(KX_VertexProxy), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp index fceb0b5922c..6d984f0d77a 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp @@ -97,9 +97,9 @@ PyTypeObject KX_VisibilityActuator::Type = { PyObject_HEAD_INIT(NULL) 0, "KX_VisibilityActuator", - sizeof(KX_VisibilityActuator), + sizeof(PyObjectPlus_Proxy), 0, - PyDestructor, + py_base_dealloc, 0, 0, 0, -- cgit v1.2.3 From fe08da3b4c4097c87c4ee1ee02e9218aaaffde4b Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sun, 19 Apr 2009 17:26:03 +0000 Subject: BGE: fix Pyfrom_id to work on w64. --- source/gameengine/Expressions/ListValue.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 5bb1eb0aeb9..4e14ce35eb9 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -532,13 +532,7 @@ PyObject* CListValue::Pycount(PyObject* self, PyObject* value) PyObject* CListValue::Pyfrom_id(PyObject* self, PyObject* value) { -#if SIZEOF_VOID_P <= SIZEOF_LONG -#define BGE_ID_TYPE unsigned long - BGE_ID_TYPE id= PyLong_AsUnsignedLong(value); -#else -#define BGE_ID_TYPE unsigned long long - BGE_ID_TYPE id= PyLong_FromUnsignedLongLong(value); -#endif + uintptr_t id= (uintptr_t)PyLong_AsVoidPtr(value); if (PyErr_Occurred()) return NULL; @@ -546,17 +540,14 @@ PyObject* CListValue::Pyfrom_id(PyObject* self, PyObject* value) int numelem = GetCount(); for (int i=0;i(m_pValueArray[i]->m_proxy) == id) + if (reinterpret_cast(m_pValueArray[i]->m_proxy) == id) return GetValue(i)->GetProxy(); - } PyErr_SetString(PyExc_IndexError, "from_id(#), id not found in CValueList"); return NULL; } -#undef BGE_ID_TYPE - /* --------------------------------------------------------------------- * Some stuff taken from the header -- 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/Converter/BL_ActionActuator.cpp | 64 ++++++----------- .../Converter/BL_ShapeActionActuator.cpp | 58 +++++----------- .../gameengine/Converter/BL_ShapeActionActuator.h | 22 +++--- source/gameengine/Expressions/ListValue.cpp | 12 ++-- source/gameengine/Expressions/PyObjectPlus.cpp | 2 +- source/gameengine/Expressions/PyObjectPlus.h | 50 ++++++-------- source/gameengine/Expressions/Value.cpp | 4 +- source/gameengine/GameLogic/SCA_ActuatorSensor.cpp | 4 +- source/gameengine/GameLogic/SCA_ActuatorSensor.h | 2 +- source/gameengine/GameLogic/SCA_DelaySensor.cpp | 12 ++-- source/gameengine/GameLogic/SCA_DelaySensor.h | 6 +- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 8 +-- source/gameengine/GameLogic/SCA_ILogicBrick.h | 2 +- source/gameengine/GameLogic/SCA_ISensor.cpp | 24 +++---- source/gameengine/GameLogic/SCA_ISensor.h | 10 +-- source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 38 +++++----- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 26 +++---- source/gameengine/GameLogic/SCA_KeyboardSensor.h | 16 ++--- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 8 +-- source/gameengine/GameLogic/SCA_MouseSensor.h | 4 +- .../gameengine/GameLogic/SCA_PropertyActuator.cpp | 8 +-- source/gameengine/GameLogic/SCA_PropertySensor.cpp | 20 +++--- source/gameengine/GameLogic/SCA_PropertySensor.h | 12 ++-- .../gameengine/GameLogic/SCA_PythonController.cpp | 29 ++++---- source/gameengine/GameLogic/SCA_RandomActuator.cpp | 29 ++++---- source/gameengine/GameLogic/SCA_RandomActuator.h | 14 ++-- source/gameengine/GameLogic/SCA_RandomSensor.cpp | 10 +-- source/gameengine/GameLogic/SCA_RandomSensor.h | 8 +-- .../Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp | 4 -- .../Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp | 10 +-- source/gameengine/Ketsji/KX_CDActuator.cpp | 4 +- source/gameengine/Ketsji/KX_CDActuator.h | 4 +- source/gameengine/Ketsji/KX_CameraActuator.cpp | 38 +++------- source/gameengine/Ketsji/KX_CameraActuator.h | 16 ++--- source/gameengine/Ketsji/KX_ConstraintActuator.cpp | 54 +++++---------- source/gameengine/Ketsji/KX_ConstraintActuator.h | 18 ++--- source/gameengine/Ketsji/KX_ConstraintWrapper.cpp | 9 +-- source/gameengine/Ketsji/KX_GameActuator.cpp | 4 +- source/gameengine/Ketsji/KX_GameObject.cpp | 80 +++++++++++----------- source/gameengine/Ketsji/KX_IpoActuator.cpp | 44 ++++-------- source/gameengine/Ketsji/KX_IpoActuator.h | 16 ++--- source/gameengine/Ketsji/KX_MeshProxy.cpp | 26 ++----- source/gameengine/Ketsji/KX_MouseFocusSensor.cpp | 12 ++-- source/gameengine/Ketsji/KX_ObjectActuator.cpp | 66 ++++++------------ source/gameengine/Ketsji/KX_ObjectActuator.h | 22 +++--- source/gameengine/Ketsji/KX_ParentActuator.cpp | 4 +- .../gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp | 16 ++--- source/gameengine/Ketsji/KX_PhysicsObjectWrapper.h | 8 +-- source/gameengine/Ketsji/KX_PolyProxy.cpp | 4 +- source/gameengine/Ketsji/KX_PythonInit.cpp | 8 +-- source/gameengine/Ketsji/KX_PythonInitTypes.cpp | 2 +- source/gameengine/Ketsji/KX_RadarSensor.cpp | 6 +- source/gameengine/Ketsji/KX_RaySensor.cpp | 8 +-- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp | 20 +++--- .../Ketsji/KX_SCA_ReplaceMeshActuator.cpp | 2 +- source/gameengine/Ketsji/KX_SceneActuator.cpp | 30 +++----- source/gameengine/Ketsji/KX_SceneActuator.h | 12 ++-- source/gameengine/Ketsji/KX_SoundActuator.cpp | 42 ++++++------ source/gameengine/Ketsji/KX_SoundActuator.h | 30 ++++---- source/gameengine/Ketsji/KX_StateActuator.cpp | 8 +-- source/gameengine/Ketsji/KX_StateActuator.h | 4 +- source/gameengine/Ketsji/KX_TouchSensor.cpp | 12 ++-- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 16 ++--- source/gameengine/Ketsji/KX_TrackToActuator.h | 8 +-- source/gameengine/Ketsji/KX_VehicleWrapper.cpp | 60 ++++------------ source/gameengine/Ketsji/KX_VehicleWrapper.h | 30 ++++---- source/gameengine/Ketsji/KX_VertexProxy.cpp | 20 +++--- source/gameengine/Ketsji/KX_VisibilityActuator.cpp | 4 +- source/gameengine/Ketsji/KX_VisibilityActuator.h | 2 +- .../Physics/Bullet/CcdPhysicsController.h | 8 +-- 70 files changed, 545 insertions(+), 748 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 530a74dfb12..f413ad969f4 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -423,8 +423,7 @@ const char BL_ActionActuator::GetAction_doc[] = "getAction()\n" "\tReturns a string containing the name of the current action.\n"; -PyObject* BL_ActionActuator::PyGetAction(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PyGetAction(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("getAction()", "the action property"); @@ -439,8 +438,7 @@ const char BL_ActionActuator::GetProperty_doc[] = "getProperty()\n" "\tReturns the name of the property to be used in FromProp mode.\n"; -PyObject* BL_ActionActuator::PyGetProperty(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PyGetProperty(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("getProperty()", "the property property"); @@ -456,8 +454,7 @@ const char BL_ActionActuator::GetFrameProperty_doc[] = "getFrameProperty()\n" "\tReturns the name of the property, that is set to the current frame number.\n"; -PyObject* BL_ActionActuator::PyGetFrameProperty(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PyGetFrameProperty(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("getFrameProperty()", "the frameProperty property"); @@ -473,8 +470,7 @@ const char BL_ActionActuator::GetFrame_doc[] = "getFrame()\n" "\tReturns the current frame number.\n"; -PyObject* BL_ActionActuator::PyGetFrame(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PyGetFrame(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("getFrame()", "the frame property"); @@ -490,8 +486,7 @@ const char BL_ActionActuator::GetEnd_doc[] = "getEnd()\n" "\tReturns the last frame of the action.\n"; -PyObject* BL_ActionActuator::PyGetEnd(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PyGetEnd(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("getEnd()", "the end property"); @@ -507,8 +502,7 @@ const char BL_ActionActuator::GetStart_doc[] = "getStart()\n" "\tReturns the starting frame of the action.\n"; -PyObject* BL_ActionActuator::PyGetStart(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PyGetStart(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("getStart()", "the start property"); @@ -525,8 +519,7 @@ const char BL_ActionActuator::GetBlendin_doc[] = "\tReturns the number of interpolation animation frames to be\n" "\tgenerated when this actuator is triggered.\n"; -PyObject* BL_ActionActuator::PyGetBlendin(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PyGetBlendin(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("getBlendin()", "the blendin property"); @@ -543,8 +536,7 @@ const char BL_ActionActuator::GetPriority_doc[] = "\tReturns the priority for this actuator. Actuators with lower\n" "\tPriority numbers will override actuators with higher numbers.\n"; -PyObject* BL_ActionActuator::PyGetPriority(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PyGetPriority(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("getPriority()", "the priority property"); @@ -565,8 +557,7 @@ const char BL_ActionActuator::SetAction_doc[] = "\t unchanged. If reset is not specified, the timer will" "\t be reset.\n"; -PyObject* BL_ActionActuator::PySetAction(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PySetAction(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setAction()", "the action property"); @@ -601,8 +592,7 @@ const char BL_ActionActuator::SetStart_doc[] = "setStart(start)\n" "\t - start : Specifies the starting frame of the animation.\n"; -PyObject* BL_ActionActuator::PySetStart(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PySetStart(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setStart()", "the start property"); @@ -624,8 +614,7 @@ const char BL_ActionActuator::SetEnd_doc[] = "setEnd(end)\n" "\t - end : Specifies the ending frame of the animation.\n"; -PyObject* BL_ActionActuator::PySetEnd(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PySetEnd(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setEnd()", "the end property"); @@ -648,8 +637,7 @@ const char BL_ActionActuator::SetBlendin_doc[] = "\t - blendin : Specifies the number of frames of animation to generate\n" "\t when making transitions between actions.\n"; -PyObject* BL_ActionActuator::PySetBlendin(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PySetBlendin(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setBlendin()", "the blendin property"); @@ -673,8 +661,7 @@ const char BL_ActionActuator::SetBlendtime_doc[] = "\t used when generating transitions between actions. This\n" "\t parameter must be in the range from 0.0 to 1.0.\n"; -PyObject* BL_ActionActuator::PySetBlendtime(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PySetBlendtime(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setBlendtime()", "the blendtime property"); @@ -702,8 +689,7 @@ const char BL_ActionActuator::SetPriority_doc[] = "\t priority numbers will override actuators with higher\n" "\t numbers.\n"; -PyObject* BL_ActionActuator::PySetPriority(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PySetPriority(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setPriority()", "the priority property"); @@ -725,8 +711,7 @@ const char BL_ActionActuator::SetFrame_doc[] = "setFrame(frame)\n" "\t - frame : Specifies the new current frame for the animation\n"; -PyObject* BL_ActionActuator::PySetFrame(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PySetFrame(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setFrame()", "the frame property"); @@ -753,8 +738,7 @@ const char BL_ActionActuator::SetProperty_doc[] = "\t - prop : A string specifying the property name to be used in\n" "\t FromProp playback mode.\n"; -PyObject* BL_ActionActuator::PySetProperty(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PySetProperty(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setProperty()", "the property property"); @@ -776,8 +760,7 @@ const char BL_ActionActuator::SetFrameProperty_doc[] = "setFrameProperty(prop)\n" "\t - prop : A string specifying the property of the frame set up update.\n"; -PyObject* BL_ActionActuator::PySetFrameProperty(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PySetFrameProperty(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setFrameProperty()", "the frameProperty property"); @@ -795,8 +778,7 @@ PyObject* BL_ActionActuator::PySetFrameProperty(PyObject* self, } /* -PyObject* BL_ActionActuator::PyGetChannel(PyObject* self, - PyObject* args, +PyObject* BL_ActionActuator::PyGetChannel(PyObject* args, PyObject* kwds) { char *string; @@ -816,8 +798,7 @@ PyObject* BL_ActionActuator::PyGetChannel(PyObject* self, 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* BL_ActionActuator::PyGetType(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("getType()", "the type property"); @@ -829,8 +810,7 @@ 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* BL_ActionActuator::PySetType(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setType()", "the type property"); @@ -854,13 +834,13 @@ PyObject* BL_ActionActuator::PySetType(PyObject* self, Py_RETURN_NONE; } -PyObject* BL_ActionActuator::PyGetContinue(PyObject* self) { +PyObject* BL_ActionActuator::PyGetContinue() { ShowDeprecationWarning("getContinue()", "the continue property"); return PyInt_FromLong((long)(m_end_reset==0)); } -PyObject* BL_ActionActuator::PySetContinue(PyObject* self, PyObject* value) { +PyObject* BL_ActionActuator::PySetContinue(PyObject* value) { ShowDeprecationWarning("setContinue()", "the continue property"); int param = PyObject_IsTrue( value ); diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index 783fdd814b7..25a4413a31d 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -498,7 +498,7 @@ 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) { +PyObject* BL_ShapeActionActuator::PyGetAction() { ShowDeprecationWarning("getAction()", "the action property"); if (m_action){ return PyString_FromString(m_action->id.name+2); @@ -511,7 +511,7 @@ const char BL_ShapeActionActuator::GetProperty_doc[] = "getProperty()\n" "\tReturns the name of the property to be used in FromProp mode.\n"; -PyObject* BL_ShapeActionActuator::PyGetProperty(PyObject* self) { +PyObject* BL_ShapeActionActuator::PyGetProperty() { ShowDeprecationWarning("getProperty()", "the property property"); PyObject *result; @@ -525,7 +525,7 @@ const char BL_ShapeActionActuator::GetFrame_doc[] = "getFrame()\n" "\tReturns the current frame number.\n"; -PyObject* BL_ShapeActionActuator::PyGetFrame(PyObject* self) { +PyObject* BL_ShapeActionActuator::PyGetFrame() { ShowDeprecationWarning("getFrame()", "the frame property"); PyObject *result; @@ -539,7 +539,7 @@ const char BL_ShapeActionActuator::GetEnd_doc[] = "getEnd()\n" "\tReturns the last frame of the action.\n"; -PyObject* BL_ShapeActionActuator::PyGetEnd(PyObject* self) { +PyObject* BL_ShapeActionActuator::PyGetEnd() { ShowDeprecationWarning("getEnd()", "the end property"); PyObject *result; @@ -553,7 +553,7 @@ const char BL_ShapeActionActuator::GetStart_doc[] = "getStart()\n" "\tReturns the starting frame of the action.\n"; -PyObject* BL_ShapeActionActuator::PyGetStart(PyObject* self) { +PyObject* BL_ShapeActionActuator::PyGetStart() { ShowDeprecationWarning("getStart()", "the start property"); PyObject *result; @@ -568,7 +568,7 @@ const char BL_ShapeActionActuator::GetBlendin_doc[] = "\tReturns the number of interpolation animation frames to be\n" "\tgenerated when this actuator is triggered.\n"; -PyObject* BL_ShapeActionActuator::PyGetBlendin(PyObject* self) { +PyObject* BL_ShapeActionActuator::PyGetBlendin() { ShowDeprecationWarning("getBlendin()", "the blendin property"); PyObject *result; @@ -583,7 +583,7 @@ const char BL_ShapeActionActuator::GetPriority_doc[] = "\tReturns the priority for this actuator. Actuators with lower\n" "\tPriority numbers will override actuators with higher numbers.\n"; -PyObject* BL_ShapeActionActuator::PyGetPriority(PyObject* self) { +PyObject* BL_ShapeActionActuator::PyGetPriority() { ShowDeprecationWarning("getPriority()", "the priority property"); PyObject *result; @@ -603,9 +603,7 @@ const char BL_ShapeActionActuator::SetAction_doc[] = "\t unchanged. If reset is not specified, the timer will" "\t be reset.\n"; -PyObject* BL_ShapeActionActuator::PySetAction(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PySetAction(PyObject* args) { ShowDeprecationWarning("setAction()", "the action property"); char *string; int reset = 1; @@ -638,9 +636,7 @@ const char BL_ShapeActionActuator::SetStart_doc[] = "setStart(start)\n" "\t - start : Specifies the starting frame of the animation.\n"; -PyObject* BL_ShapeActionActuator::PySetStart(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PySetStart(PyObject* args) { ShowDeprecationWarning("setStart()", "the start property"); float start; @@ -660,9 +656,7 @@ const char BL_ShapeActionActuator::SetEnd_doc[] = "setEnd(end)\n" "\t - end : Specifies the ending frame of the animation.\n"; -PyObject* BL_ShapeActionActuator::PySetEnd(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PySetEnd(PyObject* args) { ShowDeprecationWarning("setEnd()", "the end property"); float end; @@ -683,9 +677,7 @@ const char BL_ShapeActionActuator::SetBlendin_doc[] = "\t - blendin : Specifies the number of frames of animation to generate\n" "\t when making transitions between actions.\n"; -PyObject* BL_ShapeActionActuator::PySetBlendin(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PySetBlendin(PyObject* args) { ShowDeprecationWarning("setBlendin()", "the blendin property"); float blendin; @@ -707,9 +699,7 @@ const char BL_ShapeActionActuator::SetBlendtime_doc[] = "\t used when generating transitions between actions. This\n" "\t parameter must be in the range from 0.0 to 1.0.\n"; -PyObject* BL_ShapeActionActuator::PySetBlendtime(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PySetBlendtime(PyObject* args) { ShowDeprecationWarning("setBlendtime()", "the blendTime property"); float blendframe; @@ -735,9 +725,7 @@ const char BL_ShapeActionActuator::SetPriority_doc[] = "\t priority numbers will override actuators with higher\n" "\t numbers.\n"; -PyObject* BL_ShapeActionActuator::PySetPriority(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PySetPriority(PyObject* args) { ShowDeprecationWarning("setPriority()", "the priority property"); int priority; @@ -757,7 +745,7 @@ const char BL_ShapeActionActuator::GetFrameProperty_doc[] = "getFrameProperty()\n" "\tReturns the name of the property, that is set to the current frame number.\n"; -PyObject* BL_ShapeActionActuator::PyGetFrameProperty(PyObject* self) { +PyObject* BL_ShapeActionActuator::PyGetFrameProperty() { ShowDeprecationWarning("getFrameProperty()", "the frameProperty property"); PyObject *result; @@ -772,9 +760,7 @@ const char BL_ShapeActionActuator::SetFrame_doc[] = "setFrame(frame)\n" "\t - frame : Specifies the new current frame for the animation\n"; -PyObject* BL_ShapeActionActuator::PySetFrame(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PySetFrame(PyObject* args) { ShowDeprecationWarning("setFrame()", "the frame property"); float frame; @@ -799,9 +785,7 @@ const char BL_ShapeActionActuator::SetProperty_doc[] = "\t - prop : A string specifying the property name to be used in\n" "\t FromProp playback mode.\n"; -PyObject* BL_ShapeActionActuator::PySetProperty(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PySetProperty(PyObject* args) { ShowDeprecationWarning("setProperty()", "the property property"); char *string; @@ -821,9 +805,7 @@ const char BL_ShapeActionActuator::SetFrameProperty_doc[] = "setFrameProperty(prop)\n" "\t - prop : A string specifying the property of the frame set up update.\n"; -PyObject* BL_ShapeActionActuator::PySetFrameProperty(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PySetFrameProperty(PyObject* args) { ShowDeprecationWarning("setFrameProperty()", "the frameProperty property"); char *string; @@ -842,7 +824,7 @@ PyObject* BL_ShapeActionActuator::PySetFrameProperty(PyObject* self, const char BL_ShapeActionActuator::GetType_doc[] = "getType()\n" "\tReturns the operation mode of the actuator.\n"; -PyObject* BL_ShapeActionActuator::PyGetType(PyObject* self) { +PyObject* BL_ShapeActionActuator::PyGetType() { ShowDeprecationWarning("getType()", "the type property"); return Py_BuildValue("h", m_playtype); } @@ -852,9 +834,7 @@ const char BL_ShapeActionActuator::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_ShapeActionActuator::PySetType(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PySetType(PyObject* args) { ShowDeprecationWarning("setType()", "the type property"); short typeArg; diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.h b/source/gameengine/Converter/BL_ShapeActionActuator.h index 162580fca85..716d8c9995b 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.h +++ b/source/gameengine/Converter/BL_ShapeActionActuator.h @@ -83,16 +83,16 @@ public: bAction* GetAction() { return m_action; } void SetAction(bAction* act) { m_action= act; } - KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetAction); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetBlendin); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetPriority); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetStart); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetEnd); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetFrame); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetProperty); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetFrameProperty); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetBlendtime); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetChannel); + KX_PYMETHOD_DOC_VARARGS(BL_ShapeActionActuator,SetAction); + KX_PYMETHOD_DOC_VARARGS(BL_ShapeActionActuator,SetBlendin); + KX_PYMETHOD_DOC_VARARGS(BL_ShapeActionActuator,SetPriority); + KX_PYMETHOD_DOC_VARARGS(BL_ShapeActionActuator,SetStart); + KX_PYMETHOD_DOC_VARARGS(BL_ShapeActionActuator,SetEnd); + KX_PYMETHOD_DOC_VARARGS(BL_ShapeActionActuator,SetFrame); + KX_PYMETHOD_DOC_VARARGS(BL_ShapeActionActuator,SetProperty); + KX_PYMETHOD_DOC_VARARGS(BL_ShapeActionActuator,SetFrameProperty); + KX_PYMETHOD_DOC_VARARGS(BL_ShapeActionActuator,SetBlendtime); + KX_PYMETHOD_DOC_VARARGS(BL_ShapeActionActuator,SetChannel); KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetAction); KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetBlendin); @@ -104,7 +104,7 @@ public: KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetFrameProperty); // KX_PYMETHOD(BL_ActionActuator,GetChannel); KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetType); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetType); + KX_PYMETHOD_DOC_VARARGS(BL_ShapeActionActuator,SetType); virtual PyObject* py_getattro(PyObject* attr); virtual int py_setattro(PyObject* attr, PyObject* value); diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 4e14ce35eb9..5c7e6a4383e 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -438,14 +438,14 @@ void CListValue::MergeList(CListValue *otherlist) -PyObject* CListValue::Pyappend(PyObject* self, PyObject* value) +PyObject* CListValue::Pyappend(PyObject* value) { - return listvalue_buffer_concat(self, value); + return listvalue_buffer_concat(m_proxy, value); /* m_proxy is the same as self */ } -PyObject* CListValue::Pyreverse(PyObject* self) +PyObject* CListValue::Pyreverse() { std::reverse(m_pValueArray.begin(),m_pValueArray.end()); Py_RETURN_NONE; @@ -474,7 +474,7 @@ bool CListValue::CheckEqual(CValue* first,CValue* second) -PyObject* CListValue::Pyindex(PyObject* self, PyObject *value) +PyObject* CListValue::Pyindex(PyObject *value) { PyObject* result = NULL; @@ -503,7 +503,7 @@ PyObject* CListValue::Pyindex(PyObject* self, PyObject *value) -PyObject* CListValue::Pycount(PyObject* self, PyObject* value) +PyObject* CListValue::Pycount(PyObject* value) { int numfound = 0; @@ -530,7 +530,7 @@ PyObject* CListValue::Pycount(PyObject* self, PyObject* value) -PyObject* CListValue::Pyfrom_id(PyObject* self, PyObject* value) +PyObject* CListValue::Pyfrom_id(PyObject* value) { uintptr_t id= (uintptr_t)PyLong_AsVoidPtr(value); diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index 3c414c6b16d..da761bd22cb 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -780,7 +780,7 @@ bool PyObjectPlus::isA(const char *mytypename) // check typename of each parent return false; } -PyObject *PyObjectPlus::PyisA(PyObject *self, PyObject *value) // Python wrapper for isA +PyObject *PyObjectPlus::PyisA(PyObject *value) // Python wrapper for isA { if (PyType_Check(value)) { return PyBool_FromLong(isA((PyTypeObject *)value)); diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index 9f30e6570ee..370717a919b 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -180,62 +180,54 @@ typedef struct { * macro is one that also requires a documentation string */ #define KX_PYMETHOD(class_name, method_name) \ - PyObject* Py##method_name(PyObject* self, PyObject* args, PyObject* kwds); \ + PyObject* Py##method_name(PyObject* args, PyObject* kwds); \ static PyObject* sPy##method_name( PyObject* self, PyObject* args, PyObject* kwds) { \ - PyObjectPlus *self_plus= BGE_PROXY_REF(self); \ - return ((class_name*)self_plus)->Py##method_name(self, args, kwds); \ + return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(args, kwds); \ }; \ #define KX_PYMETHOD_VARARGS(class_name, method_name) \ - PyObject* Py##method_name(PyObject* self, PyObject* args); \ + PyObject* Py##method_name(PyObject* args); \ static PyObject* sPy##method_name( PyObject* self, PyObject* args) { \ - PyObjectPlus *self_plus= BGE_PROXY_REF(self); \ - return ((class_name*)self_plus)->Py##method_name(self, args); \ + return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(args); \ }; \ #define KX_PYMETHOD_NOARGS(class_name, method_name) \ - PyObject* Py##method_name(PyObject* self); \ + PyObject* Py##method_name(); \ static PyObject* sPy##method_name( PyObject* self) { \ - PyObjectPlus *self_plus= BGE_PROXY_REF(self); \ - return ((class_name*)self_plus)->Py##method_name(self); \ + return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(); \ }; \ #define KX_PYMETHOD_O(class_name, method_name) \ - PyObject* Py##method_name(PyObject* self, PyObject* value); \ + PyObject* Py##method_name(PyObject* value); \ static PyObject* sPy##method_name( PyObject* self, PyObject* value) { \ - PyObjectPlus *self_plus= ((PyObjectPlus_Proxy *)self)->ref; \ - return ((class_name*) self_plus)->Py##method_name(self, value); \ + return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(value); \ }; \ #define KX_PYMETHOD_DOC(class_name, method_name) \ - PyObject* Py##method_name(PyObject* self, PyObject* args, PyObject* kwds); \ + PyObject* Py##method_name(PyObject* args, PyObject* kwds); \ static PyObject* sPy##method_name( PyObject* self, PyObject* args, PyObject* kwds) { \ - PyObjectPlus *self_plus= BGE_PROXY_REF(self); \ - return ((class_name*)self_plus)->Py##method_name(self, args, kwds); \ + return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(args, kwds); \ }; \ static const char method_name##_doc[]; \ #define KX_PYMETHOD_DOC_VARARGS(class_name, method_name) \ - PyObject* Py##method_name(PyObject* self, PyObject* args); \ + PyObject* Py##method_name(PyObject* args); \ static PyObject* sPy##method_name( PyObject* self, PyObject* args) { \ - PyObjectPlus *self_plus= BGE_PROXY_REF(self); \ - return ((class_name*)self_plus)->Py##method_name(self, args); \ + return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(args); \ }; \ static const char method_name##_doc[]; \ #define KX_PYMETHOD_DOC_O(class_name, method_name) \ - PyObject* Py##method_name(PyObject* self, PyObject* value); \ + PyObject* Py##method_name(PyObject* value); \ static PyObject* sPy##method_name( PyObject* self, PyObject* value) { \ - PyObjectPlus *self_plus= BGE_PROXY_REF(self); \ - return ((class_name*)self_plus)->Py##method_name(self, value); \ + return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(value); \ }; \ static const char method_name##_doc[]; \ #define KX_PYMETHOD_DOC_NOARGS(class_name, method_name) \ - PyObject* Py##method_name(PyObject* self); \ + PyObject* Py##method_name(); \ static PyObject* sPy##method_name( PyObject* self) { \ - PyObjectPlus *self_plus= BGE_PROXY_REF(self); \ - return ((class_name*)self_plus)->Py##method_name(self); \ + return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(); \ }; \ static const char method_name##_doc[]; \ @@ -258,19 +250,19 @@ typedef struct { */ #define KX_PYMETHODDEF_DOC(class_name, method_name, doc_string) \ const char class_name::method_name##_doc[] = doc_string; \ -PyObject* class_name::Py##method_name(PyObject* self, PyObject* args, PyObject*) +PyObject* class_name::Py##method_name(PyObject* args, PyObject*) #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* self, PyObject* args) +PyObject* class_name::Py##method_name(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* self, PyObject* value) +PyObject* class_name::Py##method_name(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* self) +PyObject* class_name::Py##method_name() /** * Attribute management @@ -453,8 +445,6 @@ public: * which we cant use because we have our own subclass system */ bool isA(PyTypeObject *T); bool isA(const char *mytypename); - PyObject *PyisA(PyObject *value); - //static PyObject *sPy_isA(PyObject *self, PyObject *value); KX_PYMETHOD_O(PyObjectPlus,isA); diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index 17813d0ab52..ca46d782992 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -67,7 +67,7 @@ PyMethodDef CValue::Methods[] = { {NULL,NULL} //Sentinel }; -PyObject* CValue::PyGetName(PyObject* self) +PyObject* CValue::PyGetName() { return PyString_FromString(this->GetName()); } @@ -797,7 +797,7 @@ void CValue::ShowDeprecationWarning(const char* old_way,const char* new_way) PyObject *getframe, *frame; PyObject *f_lineno, *f_code, *co_filename; - getframe = PySys_GetObject("_getframe"); // borrowed + getframe = PySys_GetObject((char *)"_getframe"); // borrowed if (getframe) { frame = PyObject_CallObject(getframe, NULL); if (frame) { diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp index c51555a02b4..acd906ef9dd 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp @@ -185,7 +185,7 @@ int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*) const char SCA_ActuatorSensor::GetActuator_doc[] = "getActuator()\n" "\tReturn the Actuator with which the sensor operates.\n"; -PyObject* SCA_ActuatorSensor::PyGetActuator(PyObject* self) +PyObject* SCA_ActuatorSensor::PyGetActuator() { ShowDeprecationWarning("getActuator()", "the actuator property"); return PyString_FromString(m_checkactname); @@ -197,7 +197,7 @@ const char SCA_ActuatorSensor::SetActuator_doc[] = "\t- name: string\n" "\tSets the Actuator with which to operate. If there is no Actuator\n" "\tof this name, the call is ignored.\n"; -PyObject* SCA_ActuatorSensor::PySetActuator(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_ActuatorSensor::PySetActuator(PyObject* args) { ShowDeprecationWarning("setActuator()", "the actuator property"); /* We should query whether the name exists. Or should we create a prop */ diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.h b/source/gameengine/GameLogic/SCA_ActuatorSensor.h index 9bc873e4ee1..21960993497 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.h +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.h @@ -65,7 +65,7 @@ public: virtual int py_setattro(PyObject *attr, PyObject *value); /* 3. setProperty */ - KX_PYMETHOD_DOC(SCA_ActuatorSensor,SetActuator); + KX_PYMETHOD_DOC_VARARGS(SCA_ActuatorSensor,SetActuator); /* 4. getProperty */ KX_PYMETHOD_DOC_NOARGS(SCA_ActuatorSensor,GetActuator); diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp index dad85a435c8..44a0175d916 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp +++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp @@ -192,7 +192,7 @@ const char SCA_DelaySensor::SetDelay_doc[] = "\t- delay: length of the initial OFF period as number of frame\n" "\t 0 for immediate trigger\n" "\tSet the initial delay before the positive trigger\n"; -PyObject* SCA_DelaySensor::PySetDelay(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_DelaySensor::PySetDelay(PyObject* args) { ShowDeprecationWarning("setDelay()", "the delay property"); int delay; @@ -214,7 +214,7 @@ const char SCA_DelaySensor::SetDuration_doc[] = "\t 0 for no ON period\n" "\tSet the duration of the ON pulse after initial delay.\n" "\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) +PyObject* SCA_DelaySensor::PySetDuration(PyObject* args) { ShowDeprecationWarning("setDuration()", "the duration property"); int duration; @@ -235,7 +235,7 @@ const char SCA_DelaySensor::SetRepeat_doc[] = "\t- repeat: 1 if the initial OFF-ON cycle should be repeated indefinately\n" "\t 0 if the initial OFF-ON cycle should run only once\n" "\tSet the sensor repeat mode\n"; -PyObject* SCA_DelaySensor::PySetRepeat(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_DelaySensor::PySetRepeat(PyObject* args) { ShowDeprecationWarning("setRepeat()", "the repeat property"); int repeat; @@ -250,7 +250,7 @@ PyObject* SCA_DelaySensor::PySetRepeat(PyObject* self, PyObject* args, PyObject* const char SCA_DelaySensor::GetDelay_doc[] = "getDelay()\n" "\tReturn the delay parameter value\n"; -PyObject* SCA_DelaySensor::PyGetDelay(PyObject* self) +PyObject* SCA_DelaySensor::PyGetDelay() { ShowDeprecationWarning("getDelay()", "the delay property"); return PyInt_FromLong(m_delay); @@ -259,7 +259,7 @@ PyObject* SCA_DelaySensor::PyGetDelay(PyObject* self) const char SCA_DelaySensor::GetDuration_doc[] = "getDuration()\n" "\tReturn the duration parameter value\n"; -PyObject* SCA_DelaySensor::PyGetDuration(PyObject* self) +PyObject* SCA_DelaySensor::PyGetDuration() { ShowDeprecationWarning("getDuration()", "the duration property"); return PyInt_FromLong(m_duration); @@ -268,7 +268,7 @@ PyObject* SCA_DelaySensor::PyGetDuration(PyObject* self) const char SCA_DelaySensor::GetRepeat_doc[] = "getRepeat()\n" "\tReturn the repeat parameter value\n"; -PyObject* SCA_DelaySensor::PyGetRepeat(PyObject* self) +PyObject* SCA_DelaySensor::PyGetRepeat() { 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 f9e3d619198..8da76ff7189 100644 --- a/source/gameengine/GameLogic/SCA_DelaySensor.h +++ b/source/gameengine/GameLogic/SCA_DelaySensor.h @@ -64,9 +64,9 @@ public: virtual int py_setattro(PyObject *attr, PyObject *value); /* setProperty */ - KX_PYMETHOD_DOC(SCA_DelaySensor,SetDelay); - KX_PYMETHOD_DOC(SCA_DelaySensor,SetDuration); - KX_PYMETHOD_DOC(SCA_DelaySensor,SetRepeat); + KX_PYMETHOD_DOC_VARARGS(SCA_DelaySensor,SetDelay); + KX_PYMETHOD_DOC_VARARGS(SCA_DelaySensor,SetDuration); + KX_PYMETHOD_DOC_VARARGS(SCA_DelaySensor,SetRepeat); /* getProperty */ KX_PYMETHOD_DOC_NOARGS(SCA_DelaySensor,GetDelay); KX_PYMETHOD_DOC_NOARGS(SCA_DelaySensor,GetDuration); diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index 1ae78321959..b3045402c2c 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -289,7 +289,7 @@ int SCA_ILogicBrick::py_setattro(PyObject *attr, PyObject *value) } -PyObject* SCA_ILogicBrick::PyGetOwner(PyObject* self) +PyObject* SCA_ILogicBrick::PyGetOwner() { CValue* parent = GetParent(); if (parent) @@ -303,9 +303,7 @@ PyObject* SCA_ILogicBrick::PyGetOwner(PyObject* self) -PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* args) { ShowDeprecationWarning("setExecutePriority()", "the executePriority property"); @@ -322,7 +320,7 @@ PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* self, -PyObject* SCA_ILogicBrick::PyGetExecutePriority(PyObject* self) +PyObject* SCA_ILogicBrick::PyGetExecutePriority() { 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 20fa3c2d687..c0ff0fd633f 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.h +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h @@ -88,7 +88,7 @@ public: // python methods KX_PYMETHOD_NOARGS(SCA_ILogicBrick,GetOwner); - KX_PYMETHOD(SCA_ILogicBrick,SetExecutePriority); + KX_PYMETHOD_VARARGS(SCA_ILogicBrick,SetExecutePriority); KX_PYMETHOD_NOARGS(SCA_ILogicBrick,GetExecutePriority); // check that attribute is a property diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index 269038db4f9..68f5653d53a 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -218,7 +218,7 @@ void SCA_ISensor::Activate(class SCA_LogicManager* logicmgr, CValue* event) const char SCA_ISensor::IsPositive_doc[] = "isPositive()\n" "\tReturns whether the sensor is in an active state.\n"; -PyObject* SCA_ISensor::PyIsPositive(PyObject* self) +PyObject* SCA_ISensor::PyIsPositive() { ShowDeprecationWarning("isPositive()", "the read-only positive property"); int retval = IsPositiveTrigger(); @@ -228,7 +228,7 @@ PyObject* SCA_ISensor::PyIsPositive(PyObject* self) const char SCA_ISensor::IsTriggered_doc[] = "isTriggered()\n" "\tReturns whether the sensor has triggered the current controller.\n"; -PyObject* SCA_ISensor::PyIsTriggered(PyObject* self) +PyObject* SCA_ISensor::PyIsTriggered() { ShowDeprecationWarning("isTriggered()", "the read-only triggered property"); // check with the current controller @@ -244,7 +244,7 @@ PyObject* SCA_ISensor::PyIsTriggered(PyObject* self) const char SCA_ISensor::GetUsePosPulseMode_doc[] = "getUsePosPulseMode()\n" "\tReturns whether positive pulse mode is active.\n"; -PyObject* SCA_ISensor::PyGetUsePosPulseMode(PyObject* self) +PyObject* SCA_ISensor::PyGetUsePosPulseMode() { ShowDeprecationWarning("getUsePosPulseMode()", "the usePosPulseMode property"); return BoolToPyArg(m_pos_pulsemode); @@ -258,7 +258,7 @@ const char SCA_ISensor::SetUsePosPulseMode_doc[] = "\t - pulse? : Pulse when a positive event occurs?\n" "\t (KX_TRUE, KX_FALSE)\n" "\tSet whether to do pulsing when positive pulses occur.\n"; -PyObject* SCA_ISensor::PySetUsePosPulseMode(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_ISensor::PySetUsePosPulseMode(PyObject* args) { ShowDeprecationWarning("setUsePosPulseMode()", "the usePosPulseMode property"); int pyarg = 0; @@ -273,7 +273,7 @@ PyObject* SCA_ISensor::PySetUsePosPulseMode(PyObject* self, PyObject* args, PyOb const char SCA_ISensor::GetFrequency_doc[] = "getFrequency()\n" "\tReturns the frequency of the updates in pulse mode.\n" ; -PyObject* SCA_ISensor::PyGetFrequency(PyObject* self) +PyObject* SCA_ISensor::PyGetFrequency() { ShowDeprecationWarning("getFrequency()", "the frequency property"); return PyInt_FromLong(m_pulse_frequency); @@ -287,7 +287,7 @@ const char SCA_ISensor::SetFrequency_doc[] = "\t- pulse_frequency: The frequency of the updates in pulse mode (integer)" "\tSet the frequency of the updates in pulse mode.\n" "\tIf the frequency is negative, it is set to 0.\n" ; -PyObject* SCA_ISensor::PySetFrequency(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_ISensor::PySetFrequency(PyObject* args) { ShowDeprecationWarning("setFrequency()", "the frequency property"); int pulse_frequencyArg = 0; @@ -310,7 +310,7 @@ PyObject* SCA_ISensor::PySetFrequency(PyObject* self, PyObject* args, PyObject* const char SCA_ISensor::GetInvert_doc[] = "getInvert()\n" "\tReturns whether or not pulses from this sensor are inverted.\n" ; -PyObject* SCA_ISensor::PyGetInvert(PyObject* self) +PyObject* SCA_ISensor::PyGetInvert() { ShowDeprecationWarning("getInvert()", "the invert property"); return BoolToPyArg(m_invert); @@ -320,7 +320,7 @@ const char SCA_ISensor::SetInvert_doc[] = "setInvert(invert?)\n" "\t- invert?: Invert the event-values? (KX_TRUE, KX_FALSE)\n" "\tSet whether to invert pulses.\n"; -PyObject* SCA_ISensor::PySetInvert(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_ISensor::PySetInvert(PyObject* args) { ShowDeprecationWarning("setInvert()", "the invert property"); int pyarg = 0; @@ -336,7 +336,7 @@ const char SCA_ISensor::GetLevel_doc[] = "\tA level detector will immediately generate a pulse, negative or positive\n" "\tdepending on the sensor condition, as soon as the state is activated.\n" "\tA edge detector will wait for a state change before generating a pulse.\n"; -PyObject* SCA_ISensor::PyGetLevel(PyObject* self) +PyObject* SCA_ISensor::PyGetLevel() { ShowDeprecationWarning("getLevel()", "the level property"); return BoolToPyArg(m_level); @@ -346,7 +346,7 @@ const char SCA_ISensor::SetLevel_doc[] = "setLevel(level?)\n" "\t- level?: Detect level instead of edge? (KX_TRUE, KX_FALSE)\n" "\tSet whether to detect level or edge transition when entering a state.\n"; -PyObject* SCA_ISensor::PySetLevel(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_ISensor::PySetLevel(PyObject* args) { ShowDeprecationWarning("setLevel()", "the level property"); int pyarg = 0; @@ -358,7 +358,7 @@ PyObject* SCA_ISensor::PySetLevel(PyObject* self, PyObject* args, PyObject* kwds const char SCA_ISensor::GetUseNegPulseMode_doc[] = "getUseNegPulseMode()\n" "\tReturns whether negative pulse mode is active.\n"; -PyObject* SCA_ISensor::PyGetUseNegPulseMode(PyObject* self) +PyObject* SCA_ISensor::PyGetUseNegPulseMode() { ShowDeprecationWarning("getUseNegPulseMode()", "the useNegPulseMode property"); return BoolToPyArg(m_neg_pulsemode); @@ -369,7 +369,7 @@ const char SCA_ISensor::SetUseNegPulseMode_doc[] = "\t - pulse? : Pulse when a negative event occurs?\n" "\t (KX_TRUE, KX_FALSE)\n" "\tSet whether to do pulsing when negative pulses occur.\n"; -PyObject* SCA_ISensor::PySetUseNegPulseMode(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_ISensor::PySetUseNegPulseMode(PyObject* args) { ShowDeprecationWarning("setUseNegPulseMode()", "the useNegPulseMode property"); int pyarg = 0; diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h index 18d630fce0e..6b1c8cca104 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.h +++ b/source/gameengine/GameLogic/SCA_ISensor.h @@ -143,15 +143,15 @@ public: KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,IsPositive); KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,IsTriggered); KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetUsePosPulseMode); - KX_PYMETHOD_DOC(SCA_ISensor,SetUsePosPulseMode); + KX_PYMETHOD_DOC_VARARGS(SCA_ISensor,SetUsePosPulseMode); KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetFrequency); - KX_PYMETHOD_DOC(SCA_ISensor,SetFrequency); + KX_PYMETHOD_DOC_VARARGS(SCA_ISensor,SetFrequency); KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetUseNegPulseMode); - KX_PYMETHOD_DOC(SCA_ISensor,SetUseNegPulseMode); + KX_PYMETHOD_DOC_VARARGS(SCA_ISensor,SetUseNegPulseMode); KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetInvert); - KX_PYMETHOD_DOC(SCA_ISensor,SetInvert); + KX_PYMETHOD_DOC_VARARGS(SCA_ISensor,SetInvert); KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetLevel); - KX_PYMETHOD_DOC(SCA_ISensor,SetLevel); + KX_PYMETHOD_DOC_VARARGS(SCA_ISensor,SetLevel); //<------ KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,reset); diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 087fb036fae..28ff1c82924 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -349,7 +349,7 @@ int SCA_JoystickSensor::py_setattro(PyObject *attr, PyObject *value) const char SCA_JoystickSensor::GetIndex_doc[] = "getIndex\n" "\tReturns the joystick index to use.\n"; -PyObject* SCA_JoystickSensor::PyGetIndex( PyObject* self ) { +PyObject* SCA_JoystickSensor::PyGetIndex( ) { ShowDeprecationWarning("getIndex()", "the index property"); return PyInt_FromLong(m_joyindex); } @@ -359,7 +359,7 @@ PyObject* SCA_JoystickSensor::PyGetIndex( PyObject* self ) { const char SCA_JoystickSensor::SetIndex_doc[] = "setIndex\n" "\tSets the joystick index to use.\n"; -PyObject* SCA_JoystickSensor::PySetIndex( PyObject* self, PyObject* value ) { +PyObject* SCA_JoystickSensor::PySetIndex( 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) { @@ -375,7 +375,7 @@ PyObject* SCA_JoystickSensor::PySetIndex( PyObject* self, PyObject* value ) { const char SCA_JoystickSensor::GetAxis_doc[] = "getAxis\n" "\tReturns the current axis this sensor reacts to.\n"; -PyObject* SCA_JoystickSensor::PyGetAxis( PyObject* self) { +PyObject* SCA_JoystickSensor::PyGetAxis( ) { ShowDeprecationWarning("getAxis()", "the axis property"); return Py_BuildValue("[ii]",m_axis, m_axisf); } @@ -385,7 +385,7 @@ PyObject* SCA_JoystickSensor::PyGetAxis( PyObject* self) { 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 ) { +PyObject* SCA_JoystickSensor::PySetAxis( PyObject* args ) { ShowDeprecationWarning("setAxis()", "the axis property"); int axis,axisflag; @@ -402,7 +402,7 @@ PyObject* SCA_JoystickSensor::PySetAxis( PyObject* self, PyObject* args ) { 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) { +PyObject* SCA_JoystickSensor::PyGetAxisValue( ) { ShowDeprecationWarning("getAxisValue()", "the axisPosition property"); SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); @@ -421,7 +421,7 @@ PyObject* SCA_JoystickSensor::PyGetAxisValue( PyObject* self) { const char SCA_JoystickSensor::GetThreshold_doc[] = "getThreshold\n" "\tReturns the threshold of the axis.\n"; -PyObject* SCA_JoystickSensor::PyGetThreshold( PyObject* self) { +PyObject* SCA_JoystickSensor::PyGetThreshold( ) { ShowDeprecationWarning("getThreshold()", "the threshold property"); return PyInt_FromLong(m_precision); } @@ -431,7 +431,7 @@ PyObject* SCA_JoystickSensor::PyGetThreshold( PyObject* self) { const char SCA_JoystickSensor::SetThreshold_doc[] = "setThreshold\n" "\tSets the threshold of the axis.\n"; -PyObject* SCA_JoystickSensor::PySetThreshold( PyObject* self, PyObject* args ) { +PyObject* SCA_JoystickSensor::PySetThreshold( PyObject* args ) { ShowDeprecationWarning("setThreshold()", "the threshold property"); int thresh; if(!PyArg_ParseTuple(args, "i:setThreshold", &thresh)){ @@ -445,7 +445,7 @@ PyObject* SCA_JoystickSensor::PySetThreshold( PyObject* self, PyObject* args ) { const char SCA_JoystickSensor::GetButton_doc[] = "getButton\n" "\tReturns the current button this sensor is checking.\n"; -PyObject* SCA_JoystickSensor::PyGetButton( PyObject* self) { +PyObject* SCA_JoystickSensor::PyGetButton( ) { ShowDeprecationWarning("getButton()", "the button property"); return PyInt_FromLong(m_button); } @@ -454,7 +454,7 @@ PyObject* SCA_JoystickSensor::PyGetButton( PyObject* self) { const char SCA_JoystickSensor::SetButton_doc[] = "setButton\n" "\tSets the button the sensor reacts to.\n"; -PyObject* SCA_JoystickSensor::PySetButton( PyObject* self, PyObject* value ) { +PyObject* SCA_JoystickSensor::PySetButton( PyObject* value ) { ShowDeprecationWarning("setButton()", "the button property"); int button = PyInt_AsLong(value); if(button==-1 && PyErr_Occurred()) { @@ -469,16 +469,16 @@ PyObject* SCA_JoystickSensor::PySetButton( PyObject* self, PyObject* value ) { 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) { +PyObject* SCA_JoystickSensor::PyGetButtonValue( ) { ShowDeprecationWarning("getButtonValue()", "getButtonActiveList"); - return PyGetButtonActiveList(self); + return PyGetButtonActiveList( ); } /* 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) { +PyObject* SCA_JoystickSensor::PyGetButtonActiveList( ) { SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); PyObject *ls = PyList_New(0); PyObject *value; @@ -500,7 +500,7 @@ PyObject* SCA_JoystickSensor::PyGetButtonActiveList( PyObject* self) { 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 ) { +PyObject* SCA_JoystickSensor::PyGetButtonStatus( PyObject* args ) { SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); int index; @@ -517,7 +517,7 @@ PyObject* SCA_JoystickSensor::PyGetButtonStatus( PyObject* self, PyObject* args const char SCA_JoystickSensor::GetHat_doc[] = "getHat\n" "\tReturns the current direction of the hat.\n"; -PyObject* SCA_JoystickSensor::PyGetHat( PyObject* self ) { +PyObject* SCA_JoystickSensor::PyGetHat( ) { ShowDeprecationWarning("getHat()", "the hat property"); return Py_BuildValue("[ii]",m_hat, m_hatf); } @@ -527,7 +527,7 @@ PyObject* SCA_JoystickSensor::PyGetHat( PyObject* self ) { const char SCA_JoystickSensor::SetHat_doc[] = "setHat\n" "\tSets the hat the sensor reacts to.\n"; -PyObject* SCA_JoystickSensor::PySetHat( PyObject* self, PyObject* args ) { +PyObject* SCA_JoystickSensor::PySetHat( PyObject* args ) { ShowDeprecationWarning("setHat()", "the hat property"); int hat,hatflag; if(!PyArg_ParseTuple(args, "ii:setHat", &hat, &hatflag)){ @@ -543,7 +543,7 @@ PyObject* SCA_JoystickSensor::PySetHat( PyObject* self, PyObject* args ) { const char SCA_JoystickSensor::NumberOfAxes_doc[] = "getNumAxes\n" "\tReturns the number of axes .\n"; -PyObject* SCA_JoystickSensor::PyNumberOfAxes( PyObject* self ) { +PyObject* SCA_JoystickSensor::PyNumberOfAxes( ) { 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() @@ -554,7 +554,7 @@ PyObject* SCA_JoystickSensor::PyNumberOfAxes( PyObject* self ) { const char SCA_JoystickSensor::NumberOfButtons_doc[] = "getNumButtons\n" "\tReturns the number of buttons .\n"; -PyObject* SCA_JoystickSensor::PyNumberOfButtons( PyObject* self ) { +PyObject* SCA_JoystickSensor::PyNumberOfButtons( ) { ShowDeprecationWarning("getNumButtons()", "the numButtons property"); SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); return PyInt_FromLong( joy ? joy->GetNumberOfButtons() : 0 ); @@ -564,7 +564,7 @@ PyObject* SCA_JoystickSensor::PyNumberOfButtons( PyObject* self ) { const char SCA_JoystickSensor::NumberOfHats_doc[] = "getNumHats\n" "\tReturns the number of hats .\n"; -PyObject* SCA_JoystickSensor::PyNumberOfHats( PyObject* self ) { +PyObject* SCA_JoystickSensor::PyNumberOfHats( ) { ShowDeprecationWarning("getNumHats()", "the numHats property"); SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex); return PyInt_FromLong( joy ? joy->GetNumberOfHats() : 0 ); @@ -573,7 +573,7 @@ PyObject* SCA_JoystickSensor::PyNumberOfHats( PyObject* self ) { 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 ) { +PyObject* SCA_JoystickSensor::PyConnected( ) { 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_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index 3e19c880c4d..d56e5fe29dc 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -412,7 +412,7 @@ void SCA_KeyboardSensor::LogKeystrokes(void) 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) +PyObject* SCA_KeyboardSensor::PyGetKey() { ShowDeprecationWarning("getKey()", "the key property"); return PyInt_FromLong(m_hotkey); @@ -423,7 +423,7 @@ const char SCA_KeyboardSensor::SetKey_doc[] = "setKey(keycode)\n" "\t- keycode: any code from GameKeys\n" "\tSet the key this sensor should listen to.\n" ; -PyObject* SCA_KeyboardSensor::PySetKey(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_KeyboardSensor::PySetKey(PyObject* args) { ShowDeprecationWarning("setKey()", "the key property"); int keyCode; @@ -444,7 +444,7 @@ const char SCA_KeyboardSensor::GetHold1_doc[] = "getHold1()\n" "\tReturn the code of the first key modifier to the key this \n" "\tsensor is listening to.\n" ; -PyObject* SCA_KeyboardSensor::PyGetHold1(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_KeyboardSensor::PyGetHold1() { ShowDeprecationWarning("getHold1()", "the hold1 property"); return PyInt_FromLong(m_qual); @@ -455,7 +455,7 @@ const char SCA_KeyboardSensor::SetHold1_doc[] = "setHold1(keycode)\n" "\t- keycode: any code from GameKeys\n" "\tSet the first modifier to the key this sensor should listen to.\n" ; -PyObject* SCA_KeyboardSensor::PySetHold1(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_KeyboardSensor::PySetHold1(PyObject* args) { ShowDeprecationWarning("setHold1()", "the hold1 property"); int keyCode; @@ -476,7 +476,7 @@ const char SCA_KeyboardSensor::GetHold2_doc[] = "getHold2()\n" "\tReturn the code of the second key modifier to the key this \n" "\tsensor is listening to.\n" ; -PyObject* SCA_KeyboardSensor::PyGetHold2(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_KeyboardSensor::PyGetHold2() { ShowDeprecationWarning("getHold2()", "the hold2 property"); return PyInt_FromLong(m_qual2); @@ -487,7 +487,7 @@ const char SCA_KeyboardSensor::SetHold2_doc[] = "setHold2(keycode)\n" "\t- keycode: any code from GameKeys\n" "\tSet the first modifier to the key this sensor should listen to.\n" ; -PyObject* SCA_KeyboardSensor::PySetHold2(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_KeyboardSensor::PySetHold2(PyObject* args) { ShowDeprecationWarning("setHold2()", "the hold2 property"); int keyCode; @@ -508,7 +508,7 @@ const char SCA_KeyboardSensor::GetPressedKeys_doc[] = "getPressedKeys()\n" "\tGet a list of pressed keys that have either been pressed, or just released this frame.\n" ; -PyObject* SCA_KeyboardSensor::PyGetPressedKeys(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_KeyboardSensor::PyGetPressedKeys() { ShowDeprecationWarning("getPressedKeys()", "events"); @@ -549,7 +549,7 @@ const char SCA_KeyboardSensor::GetCurrentlyPressedKeys_doc[] = "getCurrentlyPressedKeys()\n" "\tGet a list of keys that are currently pressed.\n" ; -PyObject* SCA_KeyboardSensor::PyGetCurrentlyPressedKeys(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_KeyboardSensor::PyGetCurrentlyPressedKeys() { ShowDeprecationWarning("getCurrentlyPressedKeys()", "events"); @@ -640,14 +640,14 @@ PyParentObject SCA_KeyboardSensor::Parents[] = { PyMethodDef SCA_KeyboardSensor::Methods[] = { //Deprecated functions ------> - {"getKey", (PyCFunction) SCA_KeyboardSensor::sPyGetKey, METH_VARARGS, (PY_METHODCHAR)GetKey_doc}, + {"getKey", (PyCFunction) SCA_KeyboardSensor::sPyGetKey, METH_NOARGS, (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}, + {"getHold1", (PyCFunction) SCA_KeyboardSensor::sPyGetHold1, METH_NOARGS, (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}, + {"getHold2", (PyCFunction) SCA_KeyboardSensor::sPyGetHold2, METH_NOARGS, (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}, + {"getPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetPressedKeys, METH_NOARGS, (PY_METHODCHAR)GetPressedKeys_doc}, + {"getCurrentlyPressedKeys", (PyCFunction) SCA_KeyboardSensor::sPyGetCurrentlyPressedKeys, METH_NOARGS, (PY_METHODCHAR)GetCurrentlyPressedKeys_doc}, //<----- Deprecated KX_PYMETHODTABLE_O(SCA_KeyboardSensor, getKeyStatus), {NULL,NULL} //Sentinel diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.h b/source/gameengine/GameLogic/SCA_KeyboardSensor.h index eb26afc96ff..073b3e6dbe0 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.h +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.h @@ -115,21 +115,21 @@ public: //Deprecated functions -----> /** 1. GetKey : check which key this sensor looks at */ - KX_PYMETHOD_DOC(SCA_KeyboardSensor,GetKey); + KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,GetKey); /** 2. SetKey: change the key to look at */ - KX_PYMETHOD_DOC(SCA_KeyboardSensor,SetKey); + KX_PYMETHOD_DOC_VARARGS(SCA_KeyboardSensor,SetKey); /** 3. GetHold1 : set the first bucky bit */ - KX_PYMETHOD_DOC(SCA_KeyboardSensor,GetHold1); + KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,GetHold1); /** 4. SetHold1: change the first bucky bit */ - KX_PYMETHOD_DOC(SCA_KeyboardSensor,SetHold1); + KX_PYMETHOD_DOC_VARARGS(SCA_KeyboardSensor,SetHold1); /** 5. GetHold2 : set the second bucky bit */ - KX_PYMETHOD_DOC(SCA_KeyboardSensor,GetHold2); + KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,GetHold2); /** 6. SetHold2: change the second bucky bit */ - KX_PYMETHOD_DOC(SCA_KeyboardSensor,SetHold2); + KX_PYMETHOD_DOC_VARARGS(SCA_KeyboardSensor,SetHold2); /** 9. GetPressedKeys: */ - KX_PYMETHOD_DOC(SCA_KeyboardSensor,GetPressedKeys); + KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,GetPressedKeys); /** 9. GetCurrrentlyPressedKeys: */ - KX_PYMETHOD_DOC(SCA_KeyboardSensor,GetCurrentlyPressedKeys); + KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,GetCurrentlyPressedKeys); // <------ // KeyEvents: diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index 0c30f503068..8f41e799b01 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -252,9 +252,7 @@ const char SCA_MouseSensor::GetXPosition_doc[] = "\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) { +PyObject* SCA_MouseSensor::PyGetXPosition() { ShowDeprecationWarning("getXPosition()", "the position property"); return PyInt_FromLong(m_x); } @@ -265,9 +263,7 @@ const char SCA_MouseSensor::GetYPosition_doc[] = "\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) { +PyObject* SCA_MouseSensor::PyGetYPosition() { ShowDeprecationWarning("getYPosition()", "the position property"); return PyInt_FromLong(m_y); } diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.h b/source/gameengine/GameLogic/SCA_MouseSensor.h index 73410569cc2..2d1c496029d 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.h +++ b/source/gameengine/GameLogic/SCA_MouseSensor.h @@ -114,9 +114,9 @@ class SCA_MouseSensor : public SCA_ISensor //Deprecated functions -----> /* read x-coordinate */ - KX_PYMETHOD_DOC(SCA_MouseSensor,GetXPosition); + KX_PYMETHOD_DOC_NOARGS(SCA_MouseSensor,GetXPosition); /* read y-coordinate */ - KX_PYMETHOD_DOC(SCA_MouseSensor,GetYPosition); + KX_PYMETHOD_DOC_NOARGS(SCA_MouseSensor,GetYPosition); //<----- deprecated // get button status diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index 4bcb59d0812..c4db723ee89 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -289,7 +289,7 @@ const char SCA_PropertyActuator::SetProperty_doc[] = "\t- name: string\n" "\tSet the property on which to operate. If there is no property\n" "\tof this name, the call is ignored.\n"; -PyObject* SCA_PropertyActuator::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_PropertyActuator::PySetProperty(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setProperty()", "the 'property' property"); /* Check whether the name exists first ! */ @@ -314,7 +314,7 @@ PyObject* SCA_PropertyActuator::PySetProperty(PyObject* self, PyObject* args, Py const char SCA_PropertyActuator::GetProperty_doc[] = "getProperty(name)\n" "\tReturn the property on which the actuator operates.\n"; -PyObject* SCA_PropertyActuator::PyGetProperty(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_PropertyActuator::PyGetProperty(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("getProperty()", "the 'property' property"); return PyString_FromString(m_propname); @@ -327,7 +327,7 @@ const char SCA_PropertyActuator::SetValue_doc[] = "\tSet the value with which the actuator operates. If the value\n" "\tis not compatible with the type of the property, the subsequent\n" "\t action is ignored.\n"; -PyObject* SCA_PropertyActuator::PySetValue(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_PropertyActuator::PySetValue(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("setValue()", "the value property"); char *valArg; @@ -344,7 +344,7 @@ PyObject* SCA_PropertyActuator::PySetValue(PyObject* self, PyObject* args, PyObj const char SCA_PropertyActuator::GetValue_doc[] = "getValue()\n" "\tReturns the value with which the actuator operates.\n"; -PyObject* SCA_PropertyActuator::PyGetValue(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_PropertyActuator::PyGetValue(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("getValue()", "the value property"); return PyString_FromString(m_exprtxt); diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp index 5c8a14db563..de8a9fcf03e 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp +++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp @@ -334,11 +334,11 @@ PyParentObject SCA_PropertySensor::Parents[] = { PyMethodDef SCA_PropertySensor::Methods[] = { //Deprecated functions ------> - {"getType", (PyCFunction) SCA_PropertySensor::sPyGetType, METH_VARARGS, (PY_METHODCHAR)GetType_doc}, + {"getType", (PyCFunction) SCA_PropertySensor::sPyGetType, METH_NOARGS, (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}, + {"getProperty", (PyCFunction) SCA_PropertySensor::sPyGetProperty, METH_NOARGS, (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}, + {"getValue", (PyCFunction) SCA_PropertySensor::sPyGetValue, METH_NOARGS, (PY_METHODCHAR)GetValue_doc}, {"setValue", (PyCFunction) SCA_PropertySensor::sPySetValue, METH_VARARGS, (PY_METHODCHAR)SetValue_doc}, //<----- Deprecated {NULL,NULL} //Sentinel @@ -364,7 +364,7 @@ int SCA_PropertySensor::py_setattro(PyObject *attr, PyObject *value) { 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) +PyObject* SCA_PropertySensor::PyGetType() { ShowDeprecationWarning("getType()", "the type property"); return PyInt_FromLong(m_checktype); @@ -377,7 +377,7 @@ const char SCA_PropertySensor::SetType_doc[] = "\t KX_PROPSENSOR_INTERVAL, KX_PROPSENSOR_CHANGED,\n" "\t or KX_PROPSENSOR_EXPRESSION.\n" "\tSet the type of check to perform.\n"; -PyObject* SCA_PropertySensor::PySetType(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_PropertySensor::PySetType(PyObject* args) { ShowDeprecationWarning("setType()", "the type property"); int typeArg; @@ -398,7 +398,7 @@ PyObject* SCA_PropertySensor::PySetType(PyObject* self, PyObject* args, PyObject const char SCA_PropertySensor::GetProperty_doc[] = "getProperty()\n" "\tReturn the property with which the sensor operates.\n"; -PyObject* SCA_PropertySensor::PyGetProperty(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_PropertySensor::PyGetProperty() { ShowDeprecationWarning("getProperty()", "the 'property' property"); return PyString_FromString(m_checkpropname); @@ -410,7 +410,7 @@ const char SCA_PropertySensor::SetProperty_doc[] = "\t- name: string\n" "\tSets the property with which to operate. If there is no property\n" "\tof this name, the call is ignored.\n"; -PyObject* SCA_PropertySensor::PySetProperty(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_PropertySensor::PySetProperty(PyObject* args) { ShowDeprecationWarning("setProperty()", "the 'property' property"); /* We should query whether the name exists. Or should we create a prop */ @@ -435,7 +435,7 @@ PyObject* SCA_PropertySensor::PySetProperty(PyObject* self, PyObject* args, PyOb const char SCA_PropertySensor::GetValue_doc[] = "getValue()\n" "\tReturns the value with which the sensor operates.\n"; -PyObject* SCA_PropertySensor::PyGetValue(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_PropertySensor::PyGetValue() { ShowDeprecationWarning("getValue()", "the value property"); return PyString_FromString(m_checkpropval); @@ -448,7 +448,7 @@ const char SCA_PropertySensor::SetValue_doc[] = "\tSet the value with which the sensor operates. If the value\n" "\tis not compatible with the type of the property, the subsequent\n" "\t action is ignored.\n"; -PyObject* SCA_PropertySensor::PySetValue(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_PropertySensor::PySetValue(PyObject* args) { ShowDeprecationWarning("setValue()", "the value property"); /* Here, we need to check whether the value is 'valid' for this property.*/ @@ -460,7 +460,7 @@ PyObject* SCA_PropertySensor::PySetValue(PyObject* self, PyObject* args, PyObjec } STR_String oldval = m_checkpropval; m_checkpropval = propValArg; - if (validValueForProperty(self, NULL)) { + if (validValueForProperty(m_proxy, NULL)) { m_checkpropval = oldval; return NULL; } diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.h b/source/gameengine/GameLogic/SCA_PropertySensor.h index 076c1ae51ec..e1e378a973c 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.h +++ b/source/gameengine/GameLogic/SCA_PropertySensor.h @@ -93,17 +93,17 @@ public: virtual int py_setattro(PyObject *attr, PyObject *value); /* 1. getType */ - KX_PYMETHOD_DOC(SCA_PropertySensor,GetType); + KX_PYMETHOD_DOC_NOARGS(SCA_PropertySensor,GetType); /* 2. setType */ - KX_PYMETHOD_DOC(SCA_PropertySensor,SetType); + KX_PYMETHOD_DOC_VARARGS(SCA_PropertySensor,SetType); /* 3. setProperty */ - KX_PYMETHOD_DOC(SCA_PropertySensor,SetProperty); + KX_PYMETHOD_DOC_VARARGS(SCA_PropertySensor,SetProperty); /* 4. getProperty */ - KX_PYMETHOD_DOC(SCA_PropertySensor,GetProperty); + KX_PYMETHOD_DOC_NOARGS(SCA_PropertySensor,GetProperty); /* 5. getValue */ - KX_PYMETHOD_DOC(SCA_PropertySensor,GetValue); + KX_PYMETHOD_DOC_NOARGS(SCA_PropertySensor,GetValue); /* 6. setValue */ - KX_PYMETHOD_DOC(SCA_PropertySensor,SetValue); + KX_PYMETHOD_DOC_VARARGS(SCA_PropertySensor,SetValue); /** * Test whether this is a sensible value (type check) */ diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 0d096385fa9..121f868a281 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -154,8 +154,8 @@ int SCA_PythonController::IsTriggered(class SCA_ISensor* sensor) static const char* sPyGetCurrentController__doc__; #endif - -PyObject* SCA_PythonController::sPyGetCurrentController(PyObject* self) +/* warning, self is not the SCA_PythonController, its a PyObjectPlus_Proxy */ +PyObject* SCA_PythonController::sPyGetCurrentController(PyObject *self) { return m_sCurrentController->GetProxy(); } @@ -197,12 +197,9 @@ SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value) static const char* sPyAddActiveActuator__doc__; #endif -PyObject* SCA_PythonController::sPyAddActiveActuator( - - PyObject* self, - PyObject* args) +/* warning, self is not the SCA_PythonController, its a PyObjectPlus_Proxy */ +PyObject* SCA_PythonController::sPyAddActiveActuator(PyObject* self, PyObject* args) { - PyObject* ob1; int activate; if (!PyArg_ParseTuple(args, "Oi:addActiveActuator", &ob1,&activate)) @@ -384,7 +381,7 @@ int SCA_PythonController::py_setattro(PyObject *attr, PyObject *value) py_setattro_up(SCA_IController); } -PyObject* SCA_PythonController::PyActivate(PyObject* self, PyObject *value) +PyObject* SCA_PythonController::PyActivate(PyObject *value) { SCA_IActuator* actu = LinkedActuatorFromPy(value); if(actu==NULL) @@ -396,7 +393,7 @@ PyObject* SCA_PythonController::PyActivate(PyObject* self, PyObject *value) Py_RETURN_NONE; } -PyObject* SCA_PythonController::PyDeActivate(PyObject* self, PyObject *value) +PyObject* SCA_PythonController::PyDeActivate(PyObject *value) { SCA_IActuator* actu = LinkedActuatorFromPy(value); if(actu==NULL) @@ -408,7 +405,7 @@ PyObject* SCA_PythonController::PyDeActivate(PyObject* self, PyObject *value) Py_RETURN_NONE; } -PyObject* SCA_PythonController::PyGetActuators(PyObject* self) +PyObject* SCA_PythonController::PyGetActuators() { PyObject* resultlist = PyList_New(m_linkedactuators.size()); for (unsigned int index=0;index {"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}, - {"getPara2", (PyCFunction) SCA_RandomActuator::sPyGetPara2, METH_VARARGS, (PY_METHODCHAR)GetPara2_doc}, - {"getDistribution", (PyCFunction) SCA_RandomActuator::sPyGetDistribution, METH_VARARGS, (PY_METHODCHAR)GetDistribution_doc}, + {"getSeed", (PyCFunction) SCA_RandomActuator::sPyGetSeed, METH_NOARGS, (PY_METHODCHAR)GetSeed_doc}, + {"getPara1", (PyCFunction) SCA_RandomActuator::sPyGetPara1, METH_NOARGS, (PY_METHODCHAR)GetPara1_doc}, + {"getPara2", (PyCFunction) SCA_RandomActuator::sPyGetPara2, METH_NOARGS, (PY_METHODCHAR)GetPara2_doc}, + {"getDistribution", (PyCFunction) SCA_RandomActuator::sPyGetDistribution, METH_NOARGS, (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}, + {"getProperty", (PyCFunction) SCA_RandomActuator::sPyGetProperty, METH_NOARGS, (PY_METHODCHAR)GetProperty_doc}, //<----- Deprecated KX_PYMETHODTABLE(SCA_RandomActuator, setBoolConst), KX_PYMETHODTABLE_NOARGS(SCA_RandomActuator, setBoolUniform), @@ -407,7 +407,7 @@ const char SCA_RandomActuator::SetSeed_doc[] = "\tSet the initial seed of the generator. Equal seeds produce\n" "\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) { +PyObject* SCA_RandomActuator::PySetSeed(PyObject* args) { ShowDeprecationWarning("setSeed()", "the seed property"); long seedArg; if(!PyArg_ParseTuple(args, "i:setSeed", &seedArg)) { @@ -423,7 +423,8 @@ const char SCA_RandomActuator::GetSeed_doc[] = "getSeed()\n" "\tReturns the initial seed of the generator. Equal seeds produce\n" "\tequal series.\n"; -PyObject* SCA_RandomActuator::PyGetSeed(PyObject* self, PyObject* args, PyObject* kwds) { +PyObject* SCA_RandomActuator::PyGetSeed() +{ ShowDeprecationWarning("getSeed()", "the seed property"); return PyInt_FromLong(m_base->GetSeed()); } @@ -434,7 +435,8 @@ const char SCA_RandomActuator::GetPara1_doc[] = "\tReturns the first parameter of the active distribution. Refer\n" "\tto the documentation of the generator types for the meaning\n" "\tof this value."; -PyObject* SCA_RandomActuator::PyGetPara1(PyObject* self, PyObject* args, PyObject* kwds) { +PyObject* SCA_RandomActuator::PyGetPara1() +{ ShowDeprecationWarning("getPara1()", "the para1 property"); return PyFloat_FromDouble(m_parameter1); } @@ -445,7 +447,8 @@ const char SCA_RandomActuator::GetPara2_doc[] = "\tReturns the first parameter of the active distribution. Refer\n" "\tto the documentation of the generator types for the meaning\n" "\tof this value."; -PyObject* SCA_RandomActuator::PyGetPara2(PyObject* self, PyObject* args, PyObject* kwds) { +PyObject* SCA_RandomActuator::PyGetPara2() +{ ShowDeprecationWarning("getPara2()", "the para2 property"); return PyFloat_FromDouble(m_parameter2); } @@ -454,7 +457,8 @@ PyObject* SCA_RandomActuator::PyGetPara2(PyObject* self, PyObject* args, PyObjec 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) { +PyObject* SCA_RandomActuator::PyGetDistribution() +{ ShowDeprecationWarning("getDistribution()", "the distribution property"); return PyInt_FromLong(m_distribution); } @@ -465,7 +469,7 @@ const char SCA_RandomActuator::SetProperty_doc[] = "\t- name: string\n" "\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) { +PyObject* SCA_RandomActuator::PySetProperty(PyObject* args) { ShowDeprecationWarning("setProperty()", "the 'property' property"); char *nameArg; if (!PyArg_ParseTuple(args, "s:setProperty", &nameArg)) { @@ -488,7 +492,8 @@ const char SCA_RandomActuator::GetProperty_doc[] = "getProperty(name)\n" "\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) { +PyObject* SCA_RandomActuator::PyGetProperty() +{ ShowDeprecationWarning("getProperty()", "the 'property' property"); return PyString_FromString(m_propname); } diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.h b/source/gameengine/GameLogic/SCA_RandomActuator.h index fbafbb69c01..8f58ed0dcec 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.h +++ b/source/gameengine/GameLogic/SCA_RandomActuator.h @@ -103,13 +103,13 @@ class SCA_RandomActuator : public SCA_IActuator static int pyattr_set_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); // Deprecated methods -----> - KX_PYMETHOD_DOC(SCA_RandomActuator,SetSeed); - KX_PYMETHOD_DOC(SCA_RandomActuator,GetSeed); - KX_PYMETHOD_DOC(SCA_RandomActuator,GetPara1); - KX_PYMETHOD_DOC(SCA_RandomActuator,GetPara2); - KX_PYMETHOD_DOC(SCA_RandomActuator,GetDistribution); - KX_PYMETHOD_DOC(SCA_RandomActuator,SetProperty); - KX_PYMETHOD_DOC(SCA_RandomActuator,GetProperty); + KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator,SetSeed); + KX_PYMETHOD_DOC_NOARGS(SCA_RandomActuator,GetSeed); + KX_PYMETHOD_DOC_NOARGS(SCA_RandomActuator,GetPara1); + KX_PYMETHOD_DOC_NOARGS(SCA_RandomActuator,GetPara2); + KX_PYMETHOD_DOC_NOARGS(SCA_RandomActuator,GetDistribution); + KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator,SetProperty); + KX_PYMETHOD_DOC_NOARGS(SCA_RandomActuator,GetProperty); // <----- KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setBoolConst); diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp index b0bc518825b..e04d2a8ab90 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp +++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp @@ -155,8 +155,8 @@ PyParentObject SCA_RandomSensor::Parents[] = { PyMethodDef SCA_RandomSensor::Methods[] = { {"setSeed", (PyCFunction) SCA_RandomSensor::sPySetSeed, METH_VARARGS, (PY_METHODCHAR)SetSeed_doc}, - {"getSeed", (PyCFunction) SCA_RandomSensor::sPyGetSeed, METH_VARARGS, (PY_METHODCHAR)GetSeed_doc}, - {"getLastDraw", (PyCFunction) SCA_RandomSensor::sPyGetLastDraw, METH_VARARGS, (PY_METHODCHAR)GetLastDraw_doc}, + {"getSeed", (PyCFunction) SCA_RandomSensor::sPyGetSeed, METH_NOARGS, (PY_METHODCHAR)GetSeed_doc}, + {"getLastDraw", (PyCFunction) SCA_RandomSensor::sPyGetLastDraw, METH_NOARGS, (PY_METHODCHAR)GetLastDraw_doc}, {NULL,NULL} //Sentinel }; @@ -182,7 +182,7 @@ const char SCA_RandomSensor::SetSeed_doc[] = "\tSet the initial seed of the generator. Equal seeds produce\n" "\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) { +PyObject* SCA_RandomSensor::PySetSeed(PyObject* args) { ShowDeprecationWarning("setSeed()", "the seed property"); long seedArg; if(!PyArg_ParseTuple(args, "i:setSeed", &seedArg)) { @@ -199,7 +199,7 @@ const char SCA_RandomSensor::GetSeed_doc[] = "getSeed()\n" "\tReturns the initial seed of the generator. Equal seeds produce\n" "\tequal series.\n"; -PyObject* SCA_RandomSensor::PyGetSeed(PyObject* self, PyObject* args, PyObject* kwds) { +PyObject* SCA_RandomSensor::PyGetSeed() { ShowDeprecationWarning("getSeed()", "the seed property"); return PyInt_FromLong(m_basegenerator->GetSeed()); } @@ -208,7 +208,7 @@ PyObject* SCA_RandomSensor::PyGetSeed(PyObject* self, PyObject* args, PyObject* 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) { +PyObject* SCA_RandomSensor::PyGetLastDraw() { 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 844552f0b64..764692600c3 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.h +++ b/source/gameengine/GameLogic/SCA_RandomSensor.h @@ -64,11 +64,11 @@ public: virtual int py_setattro(PyObject *attr, PyObject *value); /* 1. setSeed */ - KX_PYMETHOD_DOC(SCA_RandomSensor,SetSeed); + KX_PYMETHOD_DOC_VARARGS(SCA_RandomSensor,SetSeed); /* 2. getSeed */ - KX_PYMETHOD_DOC(SCA_RandomSensor,GetSeed); - /* 3. getSeed */ - KX_PYMETHOD_DOC(SCA_RandomSensor,GetLastDraw); + KX_PYMETHOD_DOC_NOARGS(SCA_RandomSensor,GetSeed); + /* 3. getLastDraw */ + KX_PYMETHOD_DOC_NOARGS(SCA_RandomSensor,GetLastDraw); static PyObject* pyattr_get_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp index c3b27d4d6e6..2483a6bfb39 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp @@ -164,7 +164,6 @@ int KX_NetworkMessageActuator::py_setattro(PyObject *attr, PyObject *value) { // Deprecated -----> // 1. SetToPropName PyObject* KX_NetworkMessageActuator::PySetToPropName( - PyObject* self, PyObject* args, PyObject* kwds) { @@ -183,7 +182,6 @@ PyObject* KX_NetworkMessageActuator::PySetToPropName( // 2. SetSubject PyObject* KX_NetworkMessageActuator::PySetSubject( - PyObject* self, PyObject* args, PyObject* kwds) { @@ -202,7 +200,6 @@ PyObject* KX_NetworkMessageActuator::PySetSubject( // 3. SetBodyType PyObject* KX_NetworkMessageActuator::PySetBodyType( - PyObject* self, PyObject* args, PyObject* kwds) { @@ -221,7 +218,6 @@ PyObject* KX_NetworkMessageActuator::PySetBodyType( // 4. SetBody PyObject* KX_NetworkMessageActuator::PySetBody( - PyObject* self, PyObject* args, PyObject* kwds) { diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp index 9fd30450515..0c23c9b2712 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp @@ -257,7 +257,7 @@ const char KX_NetworkMessageSensor::SetSubjectFilterText_doc[] = "\tsetSubjectFilterText(value)\n" "\tChange the message subject text that this sensor is listening to.\n"; -PyObject* KX_NetworkMessageSensor::PySetSubjectFilterText( PyObject* self, PyObject* value) +PyObject* KX_NetworkMessageSensor::PySetSubjectFilterText(PyObject* value) { ShowDeprecationWarning("setSubjectFilterText()", "subject"); char* Subject = PyString_AsString(value); @@ -275,7 +275,7 @@ const char KX_NetworkMessageSensor::GetFrameMessageCount_doc[] = "\tgetFrameMessageCount()\n" "\tGet the number of messages received since the last frame.\n"; -PyObject* KX_NetworkMessageSensor::PyGetFrameMessageCount( PyObject* ) +PyObject* KX_NetworkMessageSensor::PyGetFrameMessageCount() { ShowDeprecationWarning("getFrameMessageCount()", "frameMessageCount"); return PyInt_FromLong(long(m_frame_message_count)); @@ -286,7 +286,7 @@ const char KX_NetworkMessageSensor::GetBodies_doc[] = "\tgetBodies()\n" "\tGet the list of message bodies.\n"; -PyObject* KX_NetworkMessageSensor::PyGetBodies( PyObject* ) +PyObject* KX_NetworkMessageSensor::PyGetBodies() { ShowDeprecationWarning("getBodies()", "bodies"); if (m_BodyList) { @@ -301,7 +301,7 @@ const char KX_NetworkMessageSensor::GetSubject_doc[] = "\tgetSubject()\n" "\tGet the subject: field of the message sensor.\n"; -PyObject* KX_NetworkMessageSensor::PyGetSubject( PyObject* ) +PyObject* KX_NetworkMessageSensor::PyGetSubject() { ShowDeprecationWarning("getSubject()", "subject"); return PyString_FromString(m_subject ? m_subject : ""); @@ -312,7 +312,7 @@ const char KX_NetworkMessageSensor::GetSubjects_doc[] = "\tgetSubjects()\n" "\tGet list of message subjects.\n"; -PyObject* KX_NetworkMessageSensor::PyGetSubjects( PyObject* ) +PyObject* KX_NetworkMessageSensor::PyGetSubjects() { ShowDeprecationWarning("getSubjects()", "subjects"); if (m_SubjectList) { diff --git a/source/gameengine/Ketsji/KX_CDActuator.cpp b/source/gameengine/Ketsji/KX_CDActuator.cpp index 56610f2e787..121d4512265 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.cpp +++ b/source/gameengine/Ketsji/KX_CDActuator.cpp @@ -289,7 +289,7 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, playAll, } // Deprecated -----> -PyObject* KX_CDActuator::PySetGain(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_CDActuator::PySetGain(PyObject* args) { float gain = 1.0; ShowDeprecationWarning("setGain()", "the volume property"); @@ -303,7 +303,7 @@ PyObject* KX_CDActuator::PySetGain(PyObject* self, PyObject* args, PyObject* kwd -PyObject* KX_CDActuator::PyGetGain(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_CDActuator::PyGetGain(PyObject* args) { float gain = SND_CDObject::Instance()->GetGain(); ShowDeprecationWarning("getGain()", "the volume property"); diff --git a/source/gameengine/Ketsji/KX_CDActuator.h b/source/gameengine/Ketsji/KX_CDActuator.h index e7683297c7a..b674755e59f 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.h +++ b/source/gameengine/Ketsji/KX_CDActuator.h @@ -85,8 +85,8 @@ public: virtual int py_setattro(PyObject *attr, PyObject *value); // Deprecated -----> - KX_PYMETHOD(KX_CDActuator,SetGain); - KX_PYMETHOD(KX_CDActuator,GetGain); + KX_PYMETHOD_VARARGS(KX_CDActuator,SetGain); + KX_PYMETHOD_VARARGS(KX_CDActuator,GetGain); // <----- KX_PYMETHOD_DOC_NOARGS(KX_CDActuator, startCD); diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 35165af1f82..6cc48856a94 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -408,7 +408,7 @@ PyMethodDef KX_CameraActuator::Methods[] = { {"setHeight",(PyCFunction) KX_CameraActuator::sPySetHeight, METH_VARARGS, (PY_METHODCHAR)SetHeight_doc}, {"getHeight",(PyCFunction) KX_CameraActuator::sPyGetHeight, METH_NOARGS, (PY_METHODCHAR)GetHeight_doc}, {"setXY" ,(PyCFunction) KX_CameraActuator::sPySetXY, METH_VARARGS, (PY_METHODCHAR)SetXY_doc}, - {"getXY" ,(PyCFunction) KX_CameraActuator::sPyGetXY, METH_VARARGS, (PY_METHODCHAR)GetXY_doc}, + {"getXY" ,(PyCFunction) KX_CameraActuator::sPyGetXY, METH_NOARGS, (PY_METHODCHAR)GetXY_doc}, {NULL,NULL,NULL,NULL} //Sentinel }; @@ -434,7 +434,7 @@ const char KX_CameraActuator::GetObject_doc[] = "getObject(name_only = 1)\n" "name_only - optional arg, when true will return the KX_GameObject rather then its name\n" "\tReturns the object this sensor reacts to.\n"; -PyObject* KX_CameraActuator::PyGetObject(PyObject* self, PyObject* args) +PyObject* KX_CameraActuator::PyGetObject(PyObject* args) { int ret_name_only = 1; @@ -456,7 +456,7 @@ const char KX_CameraActuator::SetObject_doc[] = "setObject(object)\n" "\t- object: KX_GameObject, string or None\n" "\tSets the object this sensor reacts to.\n"; -PyObject* KX_CameraActuator::PySetObject(PyObject* self, PyObject* value) +PyObject* KX_CameraActuator::PySetObject(PyObject* value) { KX_GameObject *gameobj; @@ -479,9 +479,7 @@ PyObject* KX_CameraActuator::PySetObject(PyObject* self, PyObject* value) const char KX_CameraActuator::GetMin_doc[] = "getMin\n" "\tReturns the minimum value set in the Min: field.\n"; -PyObject* KX_CameraActuator::PyGetMin(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_CameraActuator::PyGetMin() { ShowDeprecationWarning("getMin()", "the min property"); return PyFloat_FromDouble(m_minHeight); @@ -490,9 +488,7 @@ PyObject* KX_CameraActuator::PyGetMin(PyObject* self, const char KX_CameraActuator::SetMin_doc[] = "setMin\n" "\tSets the minimum value.\n"; -PyObject* KX_CameraActuator::PySetMin(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_CameraActuator::PySetMin(PyObject* args) { ShowDeprecationWarning("setMin()", "the min property"); float min; @@ -507,9 +503,7 @@ PyObject* KX_CameraActuator::PySetMin(PyObject* self, const char KX_CameraActuator::GetMax_doc[] = "getMax\n" "\tReturns the maximum value set in the Max: field.\n"; -PyObject* KX_CameraActuator::PyGetMax(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_CameraActuator::PyGetMax() { ShowDeprecationWarning("getMax()", "the max property"); return PyFloat_FromDouble(m_maxHeight); @@ -518,9 +512,7 @@ PyObject* KX_CameraActuator::PyGetMax(PyObject* self, const char KX_CameraActuator::SetMax_doc[] = "setMax\n" "\tSets the maximum value.\n"; -PyObject* KX_CameraActuator::PySetMax(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_CameraActuator::PySetMax(PyObject* args) { ShowDeprecationWarning("getMax()", "the max property"); float max; @@ -535,9 +527,7 @@ PyObject* KX_CameraActuator::PySetMax(PyObject* self, const char KX_CameraActuator::GetHeight_doc[] = "getHeight\n" "\tReturns the height value set in the height: field.\n"; -PyObject* KX_CameraActuator::PyGetHeight(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_CameraActuator::PyGetHeight() { ShowDeprecationWarning("getHeight()", "the height property"); return PyFloat_FromDouble(m_height); @@ -546,9 +536,7 @@ PyObject* KX_CameraActuator::PyGetHeight(PyObject* self, const char KX_CameraActuator::SetHeight_doc[] = "setHeight\n" "\tSets the height value.\n"; -PyObject* KX_CameraActuator::PySetHeight(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_CameraActuator::PySetHeight(PyObject* args) { ShowDeprecationWarning("getHeight()", "the height property"); float height; @@ -564,9 +552,7 @@ const char KX_CameraActuator::SetXY_doc[] = "setXY\n" "\tSets axis the camera tries to get behind.\n" "\t1=x, 0=y\n"; -PyObject* KX_CameraActuator::PySetXY(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_CameraActuator::PySetXY(PyObject* args) { ShowDeprecationWarning("setXY()", "the xy property"); int value; @@ -583,9 +569,7 @@ const char KX_CameraActuator::GetXY_doc[] = "getXY\n" "\tGets the axis the camera tries to get behind.\n" "\tTrue = X, False = Y\n"; -PyObject* KX_CameraActuator::PyGetXY(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_CameraActuator::PyGetXY() { 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 d0aceb89aff..9298e1e868d 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.h +++ b/source/gameengine/Ketsji/KX_CameraActuator.h @@ -127,14 +127,14 @@ private : KX_PYMETHOD_DOC_O(KX_CameraActuator,SetObject); /* get current object */ KX_PYMETHOD_DOC_VARARGS(KX_CameraActuator,GetObject); - KX_PYMETHOD_DOC(KX_CameraActuator,SetMin); - KX_PYMETHOD_DOC(KX_CameraActuator,GetMin); - KX_PYMETHOD_DOC(KX_CameraActuator,SetMax); - KX_PYMETHOD_DOC(KX_CameraActuator,GetMax); - KX_PYMETHOD_DOC(KX_CameraActuator,SetHeight); - KX_PYMETHOD_DOC(KX_CameraActuator,GetHeight); - KX_PYMETHOD_DOC(KX_CameraActuator,SetXY); - KX_PYMETHOD_DOC(KX_CameraActuator,GetXY); + KX_PYMETHOD_DOC_VARARGS(KX_CameraActuator,SetMin); + KX_PYMETHOD_DOC_NOARGS(KX_CameraActuator,GetMin); + KX_PYMETHOD_DOC_VARARGS(KX_CameraActuator,SetMax); + KX_PYMETHOD_DOC_NOARGS(KX_CameraActuator,GetMax); + KX_PYMETHOD_DOC_VARARGS(KX_CameraActuator,SetHeight); + KX_PYMETHOD_DOC_NOARGS(KX_CameraActuator,GetHeight); + KX_PYMETHOD_DOC_VARARGS(KX_CameraActuator,SetXY); + KX_PYMETHOD_DOC_NOARGS(KX_CameraActuator,GetXY); static PyObject* pyattr_get_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index fc15568ae4f..462abd3a584 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -665,9 +665,7 @@ const char KX_ConstraintActuator::SetDamp_doc[] = "\t- duration: integer\n" "\tSets the time constant of the orientation and distance constraint.\n" "\tIf the duration is negative, it is set to 0.\n"; -PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetDamp(PyObject* args) { ShowDeprecationWarning("setDamp()", "the damp property"); int dampArg; if(!PyArg_ParseTuple(args, "i:setDamp", &dampArg)) { @@ -683,7 +681,7 @@ PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self, const char KX_ConstraintActuator::GetDamp_doc[] = "getDamp()\n" "\tReturns the damping parameter.\n"; -PyObject* KX_ConstraintActuator::PyGetDamp(PyObject* self){ +PyObject* KX_ConstraintActuator::PyGetDamp(){ ShowDeprecationWarning("getDamp()", "the damp property"); return PyInt_FromLong(m_posDampTime); } @@ -694,9 +692,7 @@ const char KX_ConstraintActuator::SetRotDamp_doc[] = "\t- duration: integer\n" "\tSets the time constant of the orientation constraint.\n" "\tIf the duration is negative, it is set to 0.\n"; -PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* args) { ShowDeprecationWarning("setRotDamp()", "the rotDamp property"); int dampArg; if(!PyArg_ParseTuple(args, "i:setRotDamp", &dampArg)) { @@ -712,7 +708,7 @@ PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* self, const char KX_ConstraintActuator::GetRotDamp_doc[] = "getRotDamp()\n" "\tReturns the damping time for application of the constraint.\n"; -PyObject* KX_ConstraintActuator::PyGetRotDamp(PyObject* self){ +PyObject* KX_ConstraintActuator::PyGetRotDamp(){ ShowDeprecationWarning("getRotDamp()", "the rotDamp property"); return PyInt_FromLong(m_rotDampTime); } @@ -722,9 +718,7 @@ const char KX_ConstraintActuator::SetDirection_doc[] = "setDirection(vector)\n" "\t- vector: 3-tuple\n" "\tSets the reference direction in world coordinate for the orientation constraint.\n"; -PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetDirection(PyObject* args) { ShowDeprecationWarning("setDirection()", "the direction property"); float x, y, z; MT_Scalar len; @@ -752,7 +746,7 @@ PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, const char KX_ConstraintActuator::GetDirection_doc[] = "getDirection()\n" "\tReturns the reference direction of the orientation constraint as a 3-tuple.\n"; -PyObject* KX_ConstraintActuator::PyGetDirection(PyObject* self){ +PyObject* KX_ConstraintActuator::PyGetDirection(){ ShowDeprecationWarning("getDirection()", "the direction property"); PyObject *retVal = PyList_New(3); @@ -772,9 +766,7 @@ const char KX_ConstraintActuator::SetOption_doc[] = "\t\t128 : Detect material rather than property\n" "\t\t256 : No deactivation if ray does not hit target\n" "\t\t512 : Activate distance control\n"; -PyObject* KX_ConstraintActuator::PySetOption(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetOption(PyObject* args) { ShowDeprecationWarning("setOption()", "the option property"); int option; if(!PyArg_ParseTuple(args, "i:setOption", &option)) { @@ -789,7 +781,7 @@ PyObject* KX_ConstraintActuator::PySetOption(PyObject* self, const char KX_ConstraintActuator::GetOption_doc[] = "getOption()\n" "\tReturns the option parameter.\n"; -PyObject* KX_ConstraintActuator::PyGetOption(PyObject* self){ +PyObject* KX_ConstraintActuator::PyGetOption(){ ShowDeprecationWarning("getOption()", "the option property"); return PyInt_FromLong(m_option); } @@ -801,9 +793,7 @@ const char KX_ConstraintActuator::SetTime_doc[] = "\tSets the activation time of the actuator.\n" "\tThe actuator disables itself after this many frame.\n" "\tIf set to 0 or negative, the actuator is not limited in time.\n"; -PyObject* KX_ConstraintActuator::PySetTime(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetTime(PyObject* args) { ShowDeprecationWarning("setTime()", "the time property"); int t; if(!PyArg_ParseTuple(args, "i:setTime", &t)) { @@ -820,7 +810,7 @@ PyObject* KX_ConstraintActuator::PySetTime(PyObject* self, const char KX_ConstraintActuator::GetTime_doc[] = "getTime()\n" "\tReturns the time parameter.\n"; -PyObject* KX_ConstraintActuator::PyGetTime(PyObject* self){ +PyObject* KX_ConstraintActuator::PyGetTime(){ ShowDeprecationWarning("getTime()", "the time property"); return PyInt_FromLong(m_activeTime); } @@ -831,9 +821,7 @@ const char KX_ConstraintActuator::SetProperty_doc[] = "\t- property: string\n" "\tSets the name of the property or material for the ray detection of the distance constraint.\n" "\tIf empty, the ray will detect any collisioning object.\n"; -PyObject* KX_ConstraintActuator::PySetProperty(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetProperty(PyObject* args) { ShowDeprecationWarning("setProperty()", "the 'property' property"); char *property; if (!PyArg_ParseTuple(args, "s:setProperty", &property)) { @@ -851,7 +839,7 @@ PyObject* KX_ConstraintActuator::PySetProperty(PyObject* self, const char KX_ConstraintActuator::GetProperty_doc[] = "getProperty()\n" "\tReturns the property parameter.\n"; -PyObject* KX_ConstraintActuator::PyGetProperty(PyObject* self){ +PyObject* KX_ConstraintActuator::PyGetProperty(){ ShowDeprecationWarning("getProperty()", "the 'property' property"); return PyString_FromString(m_property.Ptr()); } @@ -867,9 +855,7 @@ const char KX_ConstraintActuator::SetMin_doc[] = "\t- lower_bound: float\n" "\tSets the lower value of the interval to which the value\n" "\tis clipped.\n"; -PyObject* KX_ConstraintActuator::PySetMin(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetMin(PyObject* args) { ShowDeprecationWarning("setMin() or setDistance()", "the min or distance property"); float minArg; if(!PyArg_ParseTuple(args, "f:setMin", &minArg)) { @@ -898,7 +884,7 @@ const char KX_ConstraintActuator::GetMin_doc[] = "getMin()\n" "\tReturns the lower value of the interval to which the value\n" "\tis clipped.\n"; -PyObject* KX_ConstraintActuator::PyGetMin(PyObject* self) { +PyObject* KX_ConstraintActuator::PyGetMin() { ShowDeprecationWarning("getMin() or getDistance()", "the min or distance property"); return PyFloat_FromDouble(m_minimumBound); } @@ -914,9 +900,7 @@ const char KX_ConstraintActuator::SetMax_doc[] = "\t- upper_bound: float\n" "\tSets the upper value of the interval to which the value\n" "\tis clipped.\n"; -PyObject* KX_ConstraintActuator::PySetMax(PyObject* self, - PyObject* args, - PyObject* kwds){ +PyObject* KX_ConstraintActuator::PySetMax(PyObject* args){ ShowDeprecationWarning("setMax() or setRayLength()", "the max or rayLength property"); float maxArg; if(!PyArg_ParseTuple(args, "f:setMax", &maxArg)) { @@ -945,7 +929,7 @@ const char KX_ConstraintActuator::GetMax_doc[] = "getMax()\n" "\tReturns the upper value of the interval to which the value\n" "\tis clipped.\n"; -PyObject* KX_ConstraintActuator::PyGetMax(PyObject* self) { +PyObject* KX_ConstraintActuator::PyGetMax() { ShowDeprecationWarning("getMax() or getRayLength()", "the max or rayLength property"); return PyFloat_FromDouble(m_maximumBound); } @@ -969,9 +953,7 @@ const char KX_ConstraintActuator::SetLimit_doc[] = "\t 14 : Align Y axis\n" "\t 15 : Align Z axis\n" "\tSets the type of constraint.\n"; -PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PySetLimit(PyObject* args) { ShowDeprecationWarning("setLimit()", "the limit property"); int locrotArg; if(!PyArg_ParseTuple(args, "i:setLimit", &locrotArg)) { @@ -986,7 +968,7 @@ PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self, const char KX_ConstraintActuator::GetLimit_doc[] = "getLimit()\n" "\tReturns the type of constraint.\n"; -PyObject* KX_ConstraintActuator::PyGetLimit(PyObject* self) { +PyObject* KX_ConstraintActuator::PyGetLimit() { ShowDeprecationWarning("setLimit()", "the limit property"); return PyInt_FromLong(m_locrot); } diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.h b/source/gameengine/Ketsji/KX_ConstraintActuator.h index 7ad6e043c49..98f6fcd7906 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.h +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.h @@ -149,27 +149,27 @@ protected: static int pyattr_check_direction(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_check_min(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); - KX_PYMETHOD_DOC(KX_ConstraintActuator,SetDamp); + KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetDamp); KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetDamp); - KX_PYMETHOD_DOC(KX_ConstraintActuator,SetRotDamp); + KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetRotDamp); KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetRotDamp); - KX_PYMETHOD_DOC(KX_ConstraintActuator,SetDirection); + KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetDirection); KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetDirection); - KX_PYMETHOD_DOC(KX_ConstraintActuator,SetOption); + KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetOption); KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetOption); - KX_PYMETHOD_DOC(KX_ConstraintActuator,SetTime); + KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetTime); KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetTime); - KX_PYMETHOD_DOC(KX_ConstraintActuator,SetProperty); + KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetProperty); KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetProperty); - KX_PYMETHOD_DOC(KX_ConstraintActuator,SetMin); + KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetMin); KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetMin); static const char SetDistance_doc[]; static const char GetDistance_doc[]; - KX_PYMETHOD_DOC(KX_ConstraintActuator,SetMax); + KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetMax); KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetMax); static const char SetRayLength_doc[]; static const char GetRayLength_doc[]; - KX_PYMETHOD_DOC(KX_ConstraintActuator,SetLimit); + KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetLimit); KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetLimit); }; diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp index d5577584616..7c3abb49159 100644 --- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp @@ -49,17 +49,12 @@ KX_ConstraintWrapper::~KX_ConstraintWrapper() { } //python integration methods -PyObject* KX_ConstraintWrapper::PyTestMethod(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ConstraintWrapper::PyTestMethod(PyObject* args, PyObject* kwds) { - Py_RETURN_NONE; } -PyObject* KX_ConstraintWrapper::PyGetConstraintId(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ConstraintWrapper::PyGetConstraintId(PyObject* args, PyObject* kwds) { return PyInt_FromLong(m_constraintId); } diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp index 215c30d65b5..8b587c6f7de 100644 --- a/source/gameengine/Ketsji/KX_GameActuator.cpp +++ b/source/gameengine/Ketsji/KX_GameActuator.cpp @@ -270,7 +270,7 @@ int KX_GameActuator::py_setattro(PyObject *attr, PyObject *value) const char KX_GameActuator::GetFile_doc[] = "getFile()\n" "get the name of the file to start.\n"; -PyObject* KX_GameActuator::PyGetFile(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_GameActuator::PyGetFile(PyObject* args, PyObject* kwds) { ShowDeprecationWarning("getFile()", "the file property"); return PyString_FromString(m_filename); @@ -280,7 +280,7 @@ PyObject* KX_GameActuator::PyGetFile(PyObject* self, PyObject* args, PyObject* k const char KX_GameActuator::SetFile_doc[] = "setFile(name)\n" "set the name of the file to start.\n"; -PyObject* KX_GameActuator::PySetFile(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_GameActuator::PySetFile(PyObject* args, PyObject* kwds) { char* new_file; diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 60d2fb0a2f6..9fe7ab75267 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1179,7 +1179,7 @@ bool KX_GameObject::ConvertPythonVectorArgs(PyObject* args, } */ -PyObject* KX_GameObject::PyReplaceMesh(PyObject* self, PyObject* value) +PyObject* KX_GameObject::PyReplaceMesh(PyObject* value) { KX_Scene *scene = KX_GetActiveScene(); char* meshname; @@ -1201,7 +1201,7 @@ PyObject* KX_GameObject::PyReplaceMesh(PyObject* self, PyObject* value) Py_RETURN_NONE; } -PyObject* KX_GameObject::PyEndObject(PyObject* self) +PyObject* KX_GameObject::PyEndObject() { KX_Scene *scene = KX_GetActiveScene(); @@ -1212,7 +1212,7 @@ PyObject* KX_GameObject::PyEndObject(PyObject* self) } -PyObject* KX_GameObject::PyGetPosition(PyObject* self) +PyObject* KX_GameObject::PyGetPosition() { ShowDeprecationWarning("getPosition()", "the position property"); return PyObjectFrom(NodeGetWorldPosition()); @@ -1701,7 +1701,7 @@ PyObject* KX_GameObject::pyattr_get_meshes(void *self_v, const KX_PYATTRIBUTE_DE PyObject *meshes= PyList_New(self->m_meshes.size()); int i; - for(i=0; i < self->m_meshes.size(); i++) + for(i=0; i < (int)self->m_meshes.size(); i++) { KX_MeshProxy* meshproxy = new KX_MeshProxy(self->m_meshes[i]); PyList_SET_ITEM(meshes, i, meshproxy->GetProxy()); @@ -1871,7 +1871,7 @@ int KX_GameObject::py_delattro(PyObject *attr) } -PyObject* KX_GameObject::PyApplyForce(PyObject* self, PyObject* args) +PyObject* KX_GameObject::PyApplyForce(PyObject* args) { int local = 0; PyObject* pyvect; @@ -1886,7 +1886,7 @@ PyObject* KX_GameObject::PyApplyForce(PyObject* self, PyObject* args) return NULL; } -PyObject* KX_GameObject::PyApplyTorque(PyObject* self, PyObject* args) +PyObject* KX_GameObject::PyApplyTorque(PyObject* args) { int local = 0; PyObject* pyvect; @@ -1901,7 +1901,7 @@ PyObject* KX_GameObject::PyApplyTorque(PyObject* self, PyObject* args) return NULL; } -PyObject* KX_GameObject::PyApplyRotation(PyObject* self, PyObject* args) +PyObject* KX_GameObject::PyApplyRotation(PyObject* args) { int local = 0; PyObject* pyvect; @@ -1916,7 +1916,7 @@ PyObject* KX_GameObject::PyApplyRotation(PyObject* self, PyObject* args) return NULL; } -PyObject* KX_GameObject::PyApplyMovement(PyObject* self, PyObject* args) +PyObject* KX_GameObject::PyApplyMovement(PyObject* args) { int local = 0; PyObject* pyvect; @@ -1931,7 +1931,7 @@ PyObject* KX_GameObject::PyApplyMovement(PyObject* self, PyObject* args) return NULL; } -PyObject* KX_GameObject::PyGetLinearVelocity(PyObject* self, PyObject* args) +PyObject* KX_GameObject::PyGetLinearVelocity(PyObject* args) { // only can get the velocity if we have a physics object connected to us... int local = 0; @@ -1945,7 +1945,7 @@ PyObject* KX_GameObject::PyGetLinearVelocity(PyObject* self, PyObject* args) } } -PyObject* KX_GameObject::PySetLinearVelocity(PyObject* self, PyObject* args) +PyObject* KX_GameObject::PySetLinearVelocity(PyObject* args) { int local = 0; PyObject* pyvect; @@ -1960,7 +1960,7 @@ PyObject* KX_GameObject::PySetLinearVelocity(PyObject* self, PyObject* args) return NULL; } -PyObject* KX_GameObject::PyGetAngularVelocity(PyObject* self, PyObject* args) +PyObject* KX_GameObject::PyGetAngularVelocity(PyObject* args) { // only can get the velocity if we have a physics object connected to us... int local = 0; @@ -1974,7 +1974,7 @@ PyObject* KX_GameObject::PyGetAngularVelocity(PyObject* self, PyObject* args) } } -PyObject* KX_GameObject::PySetAngularVelocity(PyObject* self, PyObject* args) +PyObject* KX_GameObject::PySetAngularVelocity(PyObject* args) { int local = 0; PyObject* pyvect; @@ -1989,7 +1989,7 @@ PyObject* KX_GameObject::PySetAngularVelocity(PyObject* self, PyObject* args) return NULL; } -PyObject* KX_GameObject::PySetVisible(PyObject* self, PyObject* args) +PyObject* KX_GameObject::PySetVisible(PyObject* args) { int visible, recursive = 0; if (!PyArg_ParseTuple(args,"i|i:setVisible",&visible, &recursive)) @@ -2001,7 +2001,7 @@ PyObject* KX_GameObject::PySetVisible(PyObject* self, PyObject* args) } -PyObject* KX_GameObject::PySetOcclusion(PyObject* self, PyObject* args) +PyObject* KX_GameObject::PySetOcclusion(PyObject* args) { int occlusion, recursive = 0; if (!PyArg_ParseTuple(args,"i|i:setOcclusion",&occlusion, &recursive)) @@ -2011,13 +2011,13 @@ PyObject* KX_GameObject::PySetOcclusion(PyObject* self, PyObject* args) Py_RETURN_NONE; } -PyObject* KX_GameObject::PyGetVisible(PyObject* self) +PyObject* KX_GameObject::PyGetVisible() { ShowDeprecationWarning("getVisible()", "the visible property"); return PyInt_FromLong(m_bVisible); } -PyObject* KX_GameObject::PyGetState(PyObject* self) +PyObject* KX_GameObject::PyGetState() { ShowDeprecationWarning("getState()", "the state property"); int state = 0; @@ -2025,7 +2025,7 @@ PyObject* KX_GameObject::PyGetState(PyObject* self) return PyInt_FromLong(state); } -PyObject* KX_GameObject::PySetState(PyObject* self, PyObject* value) +PyObject* KX_GameObject::PySetState(PyObject* value) { ShowDeprecationWarning("setState()", "the state property"); int state_i = PyInt_AsLong(value); @@ -2046,7 +2046,7 @@ PyObject* KX_GameObject::PySetState(PyObject* self, PyObject* value) Py_RETURN_NONE; } -PyObject* KX_GameObject::PyGetVelocity(PyObject* self, PyObject* args) +PyObject* KX_GameObject::PyGetVelocity(PyObject* args) { // only can get the velocity if we have a physics object connected to us... MT_Point3 point(0.0,0.0,0.0); @@ -2072,13 +2072,13 @@ PyObject* KX_GameObject::PyGetVelocity(PyObject* self, PyObject* args) -PyObject* KX_GameObject::PyGetMass(PyObject* self) +PyObject* KX_GameObject::PyGetMass() { ShowDeprecationWarning("getMass()", "the mass property"); return PyFloat_FromDouble((GetPhysicsController() != NULL) ? GetPhysicsController()->GetMass() : 0.0f); } -PyObject* KX_GameObject::PyGetReactionForce(PyObject* self) +PyObject* KX_GameObject::PyGetReactionForce() { // only can get the velocity if we have a physics object connected to us... @@ -2095,7 +2095,7 @@ PyObject* KX_GameObject::PyGetReactionForce(PyObject* self) -PyObject* KX_GameObject::PyEnableRigidBody(PyObject* self) +PyObject* KX_GameObject::PyEnableRigidBody() { if(GetPhysicsController()) GetPhysicsController()->setRigidBody(true); @@ -2105,7 +2105,7 @@ PyObject* KX_GameObject::PyEnableRigidBody(PyObject* self) -PyObject* KX_GameObject::PyDisableRigidBody(PyObject* self) +PyObject* KX_GameObject::PyDisableRigidBody() { if(GetPhysicsController()) GetPhysicsController()->setRigidBody(false); @@ -2115,7 +2115,7 @@ PyObject* KX_GameObject::PyDisableRigidBody(PyObject* self) -PyObject* KX_GameObject::PyGetParent(PyObject* self) +PyObject* KX_GameObject::PyGetParent() { ShowDeprecationWarning("getParent()", "the parent property"); KX_GameObject* parent = this->GetParent(); @@ -2124,7 +2124,7 @@ PyObject* KX_GameObject::PyGetParent(PyObject* self) Py_RETURN_NONE; } -PyObject* KX_GameObject::PySetParent(PyObject* self, PyObject* value) +PyObject* KX_GameObject::PySetParent(PyObject* value) { KX_GameObject *obj; if (!ConvertPythonToGameObject(value, &obj, false)) @@ -2134,24 +2134,24 @@ PyObject* KX_GameObject::PySetParent(PyObject* self, PyObject* value) Py_RETURN_NONE; } -PyObject* KX_GameObject::PyRemoveParent(PyObject* self) +PyObject* KX_GameObject::PyRemoveParent() { KX_Scene *scene = KX_GetActiveScene(); this->RemoveParent(scene); Py_RETURN_NONE; } -PyObject* KX_GameObject::PyGetChildren(PyObject* self) +PyObject* KX_GameObject::PyGetChildren() { return GetChildren()->NewProxy(true); } -PyObject* KX_GameObject::PyGetChildrenRecursive(PyObject* self) +PyObject* KX_GameObject::PyGetChildrenRecursive() { return GetChildrenRecursive()->NewProxy(true); } -PyObject* KX_GameObject::PyGetMesh(PyObject* self, PyObject* args) +PyObject* KX_GameObject::PyGetMesh(PyObject* args) { ShowDeprecationWarning("getMesh()", "the meshes property"); @@ -2173,7 +2173,7 @@ PyObject* KX_GameObject::PyGetMesh(PyObject* self, PyObject* args) -PyObject* KX_GameObject::PySetCollisionMargin(PyObject* self, PyObject* value) +PyObject* KX_GameObject::PySetCollisionMargin(PyObject* value) { float collisionMargin = PyFloat_AsDouble(value); @@ -2193,7 +2193,7 @@ PyObject* KX_GameObject::PySetCollisionMargin(PyObject* self, PyObject* value) -PyObject* KX_GameObject::PyApplyImpulse(PyObject* self, PyObject* args) +PyObject* KX_GameObject::PyApplyImpulse(PyObject* args) { PyObject* pyattach; PyObject* pyimpulse; @@ -2220,7 +2220,7 @@ PyObject* KX_GameObject::PyApplyImpulse(PyObject* self, PyObject* args) -PyObject* KX_GameObject::PySuspendDynamics(PyObject* self) +PyObject* KX_GameObject::PySuspendDynamics() { SuspendDynamics(); Py_RETURN_NONE; @@ -2228,7 +2228,7 @@ PyObject* KX_GameObject::PySuspendDynamics(PyObject* self) -PyObject* KX_GameObject::PyRestoreDynamics(PyObject* self) +PyObject* KX_GameObject::PyRestoreDynamics() { RestoreDynamics(); Py_RETURN_NONE; @@ -2236,7 +2236,7 @@ PyObject* KX_GameObject::PyRestoreDynamics(PyObject* self) -PyObject* KX_GameObject::PyGetOrientation(PyObject* self) //keywords +PyObject* KX_GameObject::PyGetOrientation() //keywords { ShowDeprecationWarning("getOrientation()", "the orientation property"); return PyObjectFrom(NodeGetWorldOrientation()); @@ -2244,7 +2244,7 @@ PyObject* KX_GameObject::PyGetOrientation(PyObject* self) //keywords -PyObject* KX_GameObject::PySetOrientation(PyObject* self, PyObject* value) +PyObject* KX_GameObject::PySetOrientation(PyObject* value) { ShowDeprecationWarning("setOrientation()", "the orientation property"); MT_Matrix3x3 matrix; @@ -2266,7 +2266,7 @@ PyObject* KX_GameObject::PySetOrientation(PyObject* self, PyObject* value) return NULL; } -PyObject* KX_GameObject::PyAlignAxisToVect(PyObject* self, PyObject* args) +PyObject* KX_GameObject::PyAlignAxisToVect(PyObject* args) { PyObject* pyvect; int axis = 2; //z axis is the default @@ -2288,7 +2288,7 @@ PyObject* KX_GameObject::PyAlignAxisToVect(PyObject* self, PyObject* args) return NULL; } -PyObject* KX_GameObject::PyGetAxisVect(PyObject* self, PyObject* value) +PyObject* KX_GameObject::PyGetAxisVect(PyObject* value) { MT_Vector3 vect; if (PyVecTo(value, vect)) @@ -2298,7 +2298,7 @@ PyObject* KX_GameObject::PyGetAxisVect(PyObject* self, PyObject* value) return NULL; } -PyObject* KX_GameObject::PySetPosition(PyObject* self, PyObject* value) +PyObject* KX_GameObject::PySetPosition(PyObject* value) { ShowDeprecationWarning("setPosition()", "the position property"); MT_Point3 pos; @@ -2312,7 +2312,7 @@ PyObject* KX_GameObject::PySetPosition(PyObject* self, PyObject* value) return NULL; } -PyObject* KX_GameObject::PySetWorldPosition(PyObject* self, PyObject* value) +PyObject* KX_GameObject::PySetWorldPosition(PyObject* value) { MT_Point3 pos; if (PyVecTo(value, pos)) @@ -2325,7 +2325,7 @@ PyObject* KX_GameObject::PySetWorldPosition(PyObject* self, PyObject* value) return NULL; } -PyObject* KX_GameObject::PyGetPhysicsId(PyObject* self) +PyObject* KX_GameObject::PyGetPhysicsId() { KX_IPhysicsController* ctrl = GetPhysicsController(); uint_ptr physid=0; @@ -2336,7 +2336,7 @@ PyObject* KX_GameObject::PyGetPhysicsId(PyObject* self) return PyInt_FromLong((long)physid); } -PyObject* KX_GameObject::PyGetPropertyNames(PyObject* self) +PyObject* KX_GameObject::PyGetPropertyNames() { PyObject *list= ConvertKeysToPython(); diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index 558b77c1f77..f04e3c79a8e 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -490,9 +490,7 @@ const char KX_IpoActuator::Set_doc[] = "\t - endframe : last frame to use (int)\n" "\t - mode? : special mode (0=normal, 1=interpret location as force, 2=additive)" "\tSet the properties of the actuator.\n"; -PyObject* KX_IpoActuator::PySet(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_IpoActuator::PySet(PyObject* args) { ShowDeprecationWarning("set()", "a number properties"); @@ -533,9 +531,7 @@ const char KX_IpoActuator::SetProperty_doc[] = "setProperty(propname)\n" "\t - propname: name of the property (string)\n" "\tSet the property to be used in FromProp mode.\n"; -PyObject* KX_IpoActuator::PySetProperty(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_IpoActuator::PySetProperty(PyObject* args) { ShowDeprecationWarning("setProperty()", "the propName property"); @@ -556,9 +552,7 @@ const char KX_IpoActuator::SetStart_doc[] = "setStart(frame)\n" "\t - frame: first frame to use (int)\n" "\tSet the frame from which the ipo starts playing.\n"; -PyObject* KX_IpoActuator::PySetStart(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_IpoActuator::PySetStart(PyObject* args) { ShowDeprecationWarning("setStart()", "the startFrame property"); @@ -575,7 +569,7 @@ PyObject* KX_IpoActuator::PySetStart(PyObject* self, const char KX_IpoActuator::GetStart_doc[] = "getStart()\n" "\tReturns the frame from which the ipo starts playing.\n"; -PyObject* KX_IpoActuator::PyGetStart(PyObject* self) { +PyObject* KX_IpoActuator::PyGetStart() { ShowDeprecationWarning("getStart()", "the startFrame property"); return PyFloat_FromDouble(m_startframe); } @@ -585,9 +579,7 @@ const char KX_IpoActuator::SetEnd_doc[] = "setEnd(frame)\n" "\t - frame: last frame to use (int)\n" "\tSet the frame at which the ipo stops playing.\n"; -PyObject* KX_IpoActuator::PySetEnd(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_IpoActuator::PySetEnd(PyObject* args) { ShowDeprecationWarning("setEnd()", "the endFrame property"); float endArg; if(!PyArg_ParseTuple(args, "f:setEnd", &endArg)) { @@ -602,7 +594,7 @@ PyObject* KX_IpoActuator::PySetEnd(PyObject* self, const char KX_IpoActuator::GetEnd_doc[] = "getEnd()\n" "\tReturns the frame at which the ipo stops playing.\n"; -PyObject* KX_IpoActuator::PyGetEnd(PyObject* self) { +PyObject* KX_IpoActuator::PyGetEnd() { ShowDeprecationWarning("getEnd()", "the endFrame property"); return PyFloat_FromDouble(m_endframe); } @@ -612,9 +604,7 @@ const char KX_IpoActuator::SetIpoAsForce_doc[] = "setIpoAsForce(force?)\n" "\t - force? : interpret this ipo as a force? (KX_TRUE, KX_FALSE)\n" "\tSet whether to interpret the ipo as a force rather than a displacement.\n"; -PyObject* KX_IpoActuator::PySetIpoAsForce(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_IpoActuator::PySetIpoAsForce(PyObject* args) { ShowDeprecationWarning("setIpoAsForce()", "the useIpoAsForce property"); int boolArg; @@ -632,7 +622,7 @@ PyObject* KX_IpoActuator::PySetIpoAsForce(PyObject* self, const char KX_IpoActuator::GetIpoAsForce_doc[] = "getIpoAsForce()\n" "\tReturns whether to interpret the ipo as a force rather than a displacement.\n"; -PyObject* KX_IpoActuator::PyGetIpoAsForce(PyObject* self) { +PyObject* KX_IpoActuator::PyGetIpoAsForce() { ShowDeprecationWarning("getIpoAsForce()", "the useIpoAsForce property"); return BoolToPyArg(m_ipo_as_force); } @@ -642,9 +632,7 @@ const char KX_IpoActuator::SetIpoAdd_doc[] = "setIpoAdd(add?)\n" "\t - add? : add flag (KX_TRUE, KX_FALSE)\n" "\tSet whether to interpret the ipo as additive rather than absolute.\n"; -PyObject* KX_IpoActuator::PySetIpoAdd(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_IpoActuator::PySetIpoAdd(PyObject* args) { ShowDeprecationWarning("setIpoAdd()", "the useIpoAdd property"); int boolArg; @@ -662,7 +650,7 @@ PyObject* KX_IpoActuator::PySetIpoAdd(PyObject* self, const char KX_IpoActuator::GetIpoAdd_doc[] = "getIpoAsAdd()\n" "\tReturns whether to interpret the ipo as additive rather than absolute.\n"; -PyObject* KX_IpoActuator::PyGetIpoAdd(PyObject* self) { +PyObject* KX_IpoActuator::PyGetIpoAdd() { ShowDeprecationWarning("getIpoAdd()", "the useIpoAdd property"); return BoolToPyArg(m_ipo_add); } @@ -672,9 +660,7 @@ const char KX_IpoActuator::SetType_doc[] = "setType(mode)\n" "\t - mode: Play, PingPong, Flipper, LoopStop, LoopEnd or FromProp (string)\n" "\tSet the operation mode of the actuator.\n"; -PyObject* KX_IpoActuator::PySetType(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_IpoActuator::PySetType(PyObject* args) { ShowDeprecationWarning("setType()", "the type property"); int typeArg; @@ -693,7 +679,7 @@ PyObject* KX_IpoActuator::PySetType(PyObject* self, const char KX_IpoActuator::GetType_doc[] = "getType()\n" "\tReturns the operation mode of the actuator.\n"; -PyObject* KX_IpoActuator::PyGetType(PyObject* self) { +PyObject* KX_IpoActuator::PyGetType() { ShowDeprecationWarning("getType()", "the type property"); return PyInt_FromLong(m_type); } @@ -705,9 +691,7 @@ const char KX_IpoActuator::SetForceIpoActsLocal_doc[] = "\t coordinates? (KX_TRUE, KX_FALSE)\n" "\tSet whether to apply the force in the object's local\n" "\tcoordinates rather than the world global coordinates.\n"; -PyObject* KX_IpoActuator::PySetForceIpoActsLocal(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_IpoActuator::PySetForceIpoActsLocal(PyObject* args) { ShowDeprecationWarning("setForceIpoActsLocal()", "the useIpoLocal property"); int boolArg; @@ -724,7 +708,7 @@ const char KX_IpoActuator::GetForceIpoActsLocal_doc[] = "getForceIpoActsLocal()\n" "\tReturn whether to apply the force in the object's local\n" "\tcoordinates rather than the world global coordinates.\n"; -PyObject* KX_IpoActuator::PyGetForceIpoActsLocal(PyObject* self) { +PyObject* KX_IpoActuator::PyGetForceIpoActsLocal() { ShowDeprecationWarning("getForceIpoActsLocal()", "the useIpoLocal property"); return BoolToPyArg(m_ipo_local); } diff --git a/source/gameengine/Ketsji/KX_IpoActuator.h b/source/gameengine/Ketsji/KX_IpoActuator.h index 7e85a28eb96..184ad5512de 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.h +++ b/source/gameengine/Ketsji/KX_IpoActuator.h @@ -145,20 +145,20 @@ public: virtual int py_setattro(PyObject *attr, PyObject *value); //KX_PYMETHOD_DOC - KX_PYMETHOD_DOC(KX_IpoActuator,Set); - KX_PYMETHOD_DOC(KX_IpoActuator,SetProperty); + KX_PYMETHOD_DOC_VARARGS(KX_IpoActuator,Set); + KX_PYMETHOD_DOC_VARARGS(KX_IpoActuator,SetProperty); /* KX_PYMETHOD_DOC(KX_IpoActuator,SetKey2Key); */ - KX_PYMETHOD_DOC(KX_IpoActuator,SetStart); + KX_PYMETHOD_DOC_VARARGS(KX_IpoActuator,SetStart); KX_PYMETHOD_DOC_NOARGS(KX_IpoActuator,GetStart); - KX_PYMETHOD_DOC(KX_IpoActuator,SetEnd); + KX_PYMETHOD_DOC_VARARGS(KX_IpoActuator,SetEnd); KX_PYMETHOD_DOC_NOARGS(KX_IpoActuator,GetEnd); - KX_PYMETHOD_DOC(KX_IpoActuator,SetIpoAsForce); + KX_PYMETHOD_DOC_VARARGS(KX_IpoActuator,SetIpoAsForce); KX_PYMETHOD_DOC_NOARGS(KX_IpoActuator,GetIpoAsForce); - KX_PYMETHOD_DOC(KX_IpoActuator,SetIpoAdd); + KX_PYMETHOD_DOC_VARARGS(KX_IpoActuator,SetIpoAdd); KX_PYMETHOD_DOC_NOARGS(KX_IpoActuator,GetIpoAdd); - KX_PYMETHOD_DOC(KX_IpoActuator,SetType); + KX_PYMETHOD_DOC_VARARGS(KX_IpoActuator,SetType); KX_PYMETHOD_DOC_NOARGS(KX_IpoActuator,GetType); - KX_PYMETHOD_DOC(KX_IpoActuator,SetForceIpoActsLocal); + KX_PYMETHOD_DOC_VARARGS(KX_IpoActuator,SetForceIpoActsLocal); KX_PYMETHOD_DOC_NOARGS(KX_IpoActuator,GetForceIpoActsLocal); }; diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index 8ce5e888349..ded862fb21d 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -139,25 +139,21 @@ void KX_MeshProxy::ReplicaSetName(STR_String name) {}; // stuff for python integration -PyObject* KX_MeshProxy::PyGetNumMaterials(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_MeshProxy::PyGetNumMaterials(PyObject* args, PyObject* kwds) { int num = m_meshobj->NumMaterials(); ShowDeprecationWarning("getNumMaterials()", "the numMaterials property"); return PyInt_FromLong(num); } -PyObject* KX_MeshProxy::PyGetNumPolygons(PyObject* self) +PyObject* KX_MeshProxy::PyGetNumPolygons() { int num = m_meshobj->NumPolygons(); ShowDeprecationWarning("getNumPolygons()", "the numPolygons property"); return PyInt_FromLong(num); } -PyObject* KX_MeshProxy::PyGetMaterialName(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_MeshProxy::PyGetMaterialName(PyObject* args, PyObject* kwds) { int matid= 1; STR_String matname; @@ -175,9 +171,7 @@ PyObject* KX_MeshProxy::PyGetMaterialName(PyObject* self, } -PyObject* KX_MeshProxy::PyGetTextureName(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_MeshProxy::PyGetTextureName(PyObject* args, PyObject* kwds) { int matid= 1; STR_String matname; @@ -194,9 +188,7 @@ PyObject* KX_MeshProxy::PyGetTextureName(PyObject* self, } -PyObject* KX_MeshProxy::PyGetVertexArrayLength(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_MeshProxy::PyGetVertexArrayLength(PyObject* args, PyObject* kwds) { int matid= 0; int length = 0; @@ -219,9 +211,7 @@ PyObject* KX_MeshProxy::PyGetVertexArrayLength(PyObject* self, } -PyObject* KX_MeshProxy::PyGetVertex(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_MeshProxy::PyGetVertex(PyObject* args, PyObject* kwds) { int vertexindex= 1; int matindex= 1; @@ -243,9 +233,7 @@ PyObject* KX_MeshProxy::PyGetVertex(PyObject* self, } -PyObject* KX_MeshProxy::PyGetPolygon(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_MeshProxy::PyGetPolygon(PyObject* args, PyObject* kwds) { int polyindex= 1; PyObject* polyob = NULL; diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index b59f18bf935..87b5c81392d 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -391,7 +391,7 @@ PyObject* KX_MouseFocusSensor::py_getattro(PyObject *attr) { const char KX_MouseFocusSensor::GetHitObject_doc[] = "getHitObject()\n" "\tReturns the object that was hit by this ray.\n"; -PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self) +PyObject* KX_MouseFocusSensor::PyGetHitObject() { ShowDeprecationWarning("GetHitObject()", "the hitObject property"); @@ -405,7 +405,7 @@ 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* KX_MouseFocusSensor::PyGetHitPosition() { ShowDeprecationWarning("getHitPosition()", "the hitPosition property"); @@ -415,7 +415,7 @@ PyObject* KX_MouseFocusSensor::PyGetHitPosition(PyObject* self) const char KX_MouseFocusSensor::GetRayDirection_doc[] = "getRayDirection()\n" "\tReturns the direction from the ray (in worldcoordinates) .\n"; -PyObject* KX_MouseFocusSensor::PyGetRayDirection(PyObject* self) +PyObject* KX_MouseFocusSensor::PyGetRayDirection() { ShowDeprecationWarning("getRayDirection()", "the rayDirection property"); @@ -428,7 +428,7 @@ PyObject* KX_MouseFocusSensor::PyGetRayDirection(PyObject* self) const char KX_MouseFocusSensor::GetHitNormal_doc[] = "getHitNormal()\n" "\tReturns the normal (in worldcoordinates) at the point of collision where the object was hit by this ray.\n"; -PyObject* KX_MouseFocusSensor::PyGetHitNormal(PyObject* self) +PyObject* KX_MouseFocusSensor::PyGetHitNormal() { ShowDeprecationWarning("getHitNormal()", "the hitNormal property"); @@ -441,7 +441,7 @@ 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* KX_MouseFocusSensor::PyGetRayTarget() { ShowDeprecationWarning("getRayTarget()", "the rayTarget property"); @@ -453,7 +453,7 @@ 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* KX_MouseFocusSensor::PyGetRaySource() { ShowDeprecationWarning("getRaySource()", "the raySource property"); diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index 4f1890772d7..861c5757971 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -344,7 +344,7 @@ PyObject* KX_ObjectActuator::py_getattro(PyObject *attr) { /* Removed! */ /* 2. getForce */ -PyObject* KX_ObjectActuator::PyGetForce(PyObject* self) +PyObject* KX_ObjectActuator::PyGetForce() { PyObject *retVal = PyList_New(4); @@ -356,9 +356,7 @@ PyObject* KX_ObjectActuator::PyGetForce(PyObject* self) return retVal; } /* 3. setForce */ -PyObject* KX_ObjectActuator::PySetForce(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PySetForce(PyObject* args) { float vecArg[3]; int bToggle = 0; @@ -373,7 +371,7 @@ PyObject* KX_ObjectActuator::PySetForce(PyObject* self, } /* 4. getTorque */ -PyObject* KX_ObjectActuator::PyGetTorque(PyObject* self) +PyObject* KX_ObjectActuator::PyGetTorque() { PyObject *retVal = PyList_New(4); @@ -385,9 +383,7 @@ PyObject* KX_ObjectActuator::PyGetTorque(PyObject* self) return retVal; } /* 5. setTorque */ -PyObject* KX_ObjectActuator::PySetTorque(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PySetTorque(PyObject* args) { float vecArg[3]; int bToggle = 0; @@ -402,7 +398,7 @@ PyObject* KX_ObjectActuator::PySetTorque(PyObject* self, } /* 6. getDLoc */ -PyObject* KX_ObjectActuator::PyGetDLoc(PyObject* self) +PyObject* KX_ObjectActuator::PyGetDLoc() { PyObject *retVal = PyList_New(4); @@ -414,9 +410,7 @@ PyObject* KX_ObjectActuator::PyGetDLoc(PyObject* self) return retVal; } /* 7. setDLoc */ -PyObject* KX_ObjectActuator::PySetDLoc(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PySetDLoc(PyObject* args) { float vecArg[3]; int bToggle = 0; @@ -431,7 +425,7 @@ PyObject* KX_ObjectActuator::PySetDLoc(PyObject* self, } /* 8. getDRot */ -PyObject* KX_ObjectActuator::PyGetDRot(PyObject* self) +PyObject* KX_ObjectActuator::PyGetDRot() { PyObject *retVal = PyList_New(4); @@ -443,9 +437,7 @@ PyObject* KX_ObjectActuator::PyGetDRot(PyObject* self) return retVal; } /* 9. setDRot */ -PyObject* KX_ObjectActuator::PySetDRot(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PySetDRot(PyObject* args) { float vecArg[3]; int bToggle = 0; @@ -460,7 +452,7 @@ PyObject* KX_ObjectActuator::PySetDRot(PyObject* self, } /* 10. getLinearVelocity */ -PyObject* KX_ObjectActuator::PyGetLinearVelocity(PyObject* self) { +PyObject* KX_ObjectActuator::PyGetLinearVelocity() { PyObject *retVal = PyList_New(4); PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_linear_velocity[0])); @@ -472,9 +464,7 @@ PyObject* KX_ObjectActuator::PyGetLinearVelocity(PyObject* self) { } /* 11. setLinearVelocity */ -PyObject* KX_ObjectActuator::PySetLinearVelocity(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ObjectActuator::PySetLinearVelocity(PyObject* args) { float vecArg[3]; int bToggle = 0; if (!PyArg_ParseTuple(args, "fffi:setLinearVelocity", &vecArg[0], &vecArg[1], @@ -489,7 +479,7 @@ PyObject* KX_ObjectActuator::PySetLinearVelocity(PyObject* self, /* 12. getAngularVelocity */ -PyObject* KX_ObjectActuator::PyGetAngularVelocity(PyObject* self) { +PyObject* KX_ObjectActuator::PyGetAngularVelocity() { PyObject *retVal = PyList_New(4); PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_angular_velocity[0])); @@ -500,9 +490,7 @@ PyObject* KX_ObjectActuator::PyGetAngularVelocity(PyObject* self) { return retVal; } /* 13. setAngularVelocity */ -PyObject* KX_ObjectActuator::PySetAngularVelocity(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ObjectActuator::PySetAngularVelocity(PyObject* args) { float vecArg[3]; int bToggle = 0; if (!PyArg_ParseTuple(args, "fffi:setAngularVelocity", &vecArg[0], &vecArg[1], @@ -516,9 +504,7 @@ PyObject* KX_ObjectActuator::PySetAngularVelocity(PyObject* self, } /* 13. setDamping */ -PyObject* KX_ObjectActuator::PySetDamping(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ObjectActuator::PySetDamping(PyObject* args) { int damping = 0; if (!PyArg_ParseTuple(args, "i:setDamping", &damping) || damping < 0 || damping > 1000) { return NULL; @@ -528,11 +514,11 @@ PyObject* KX_ObjectActuator::PySetDamping(PyObject* self, } /* 13. getVelocityDamping */ -PyObject* KX_ObjectActuator::PyGetDamping(PyObject* self) { +PyObject* KX_ObjectActuator::PyGetDamping() { return Py_BuildValue("i",m_damping); } /* 6. getForceLimitX */ -PyObject* KX_ObjectActuator::PyGetForceLimitX(PyObject* self) +PyObject* KX_ObjectActuator::PyGetForceLimitX() { PyObject *retVal = PyList_New(3); @@ -543,9 +529,7 @@ PyObject* KX_ObjectActuator::PyGetForceLimitX(PyObject* self) return retVal; } /* 7. setForceLimitX */ -PyObject* KX_ObjectActuator::PySetForceLimitX(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PySetForceLimitX(PyObject* args) { float vecArg[2]; int bToggle = 0; @@ -559,7 +543,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitX(PyObject* self, } /* 6. getForceLimitY */ -PyObject* KX_ObjectActuator::PyGetForceLimitY(PyObject* self) +PyObject* KX_ObjectActuator::PyGetForceLimitY() { PyObject *retVal = PyList_New(3); @@ -570,9 +554,7 @@ PyObject* KX_ObjectActuator::PyGetForceLimitY(PyObject* self) return retVal; } /* 7. setForceLimitY */ -PyObject* KX_ObjectActuator::PySetForceLimitY(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PySetForceLimitY(PyObject* args) { float vecArg[2]; int bToggle = 0; @@ -586,7 +568,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitY(PyObject* self, } /* 6. getForceLimitZ */ -PyObject* KX_ObjectActuator::PyGetForceLimitZ(PyObject* self) +PyObject* KX_ObjectActuator::PyGetForceLimitZ() { PyObject *retVal = PyList_New(3); @@ -597,9 +579,7 @@ PyObject* KX_ObjectActuator::PyGetForceLimitZ(PyObject* self) return retVal; } /* 7. setForceLimitZ */ -PyObject* KX_ObjectActuator::PySetForceLimitZ(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PySetForceLimitZ(PyObject* args) { float vecArg[2]; int bToggle = 0; @@ -613,7 +593,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitZ(PyObject* self, } /* 4. getPID */ -PyObject* KX_ObjectActuator::PyGetPID(PyObject* self) +PyObject* KX_ObjectActuator::PyGetPID() { PyObject *retVal = PyList_New(3); @@ -624,9 +604,7 @@ PyObject* KX_ObjectActuator::PyGetPID(PyObject* self) return retVal; } /* 5. setPID */ -PyObject* KX_ObjectActuator::PySetPID(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PySetPID(PyObject* args) { float vecArg[3]; if (!PyArg_ParseTuple(args, "fff:setPID", &vecArg[0], &vecArg[1], &vecArg[2])) { diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.h b/source/gameengine/Ketsji/KX_ObjectActuator.h index 00c8fb700ae..a812942a0ae 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.h +++ b/source/gameengine/Ketsji/KX_ObjectActuator.h @@ -156,27 +156,27 @@ public: virtual PyObject* py_getattro(PyObject *attr); KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForce); - KX_PYMETHOD(KX_ObjectActuator,SetForce); + KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetForce); KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetTorque); - KX_PYMETHOD(KX_ObjectActuator,SetTorque); + KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetTorque); KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetDLoc); - KX_PYMETHOD(KX_ObjectActuator,SetDLoc); + KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetDLoc); KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetDRot); - KX_PYMETHOD(KX_ObjectActuator,SetDRot); + KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetDRot); KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetLinearVelocity); - KX_PYMETHOD(KX_ObjectActuator,SetLinearVelocity); + KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetLinearVelocity); KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetAngularVelocity); - KX_PYMETHOD(KX_ObjectActuator,SetAngularVelocity); - KX_PYMETHOD(KX_ObjectActuator,SetDamping); + KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetAngularVelocity); + KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetDamping); KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetDamping); KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForceLimitX); - KX_PYMETHOD(KX_ObjectActuator,SetForceLimitX); + KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetForceLimitX); KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForceLimitY); - KX_PYMETHOD(KX_ObjectActuator,SetForceLimitY); + KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetForceLimitY); KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForceLimitZ); - KX_PYMETHOD(KX_ObjectActuator,SetForceLimitZ); + KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetForceLimitZ); KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetPID); - KX_PYMETHOD(KX_ObjectActuator,SetPID); + KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetPID); }; #endif //__KX_OBJECTACTUATOR diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index 5263dd72065..69c0a3cd510 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -221,7 +221,7 @@ const char KX_ParentActuator::SetObject_doc[] = "setObject(object)\n" "\t- object: KX_GameObject, string or None\n" "\tSet the object to set as parent.\n"; -PyObject* KX_ParentActuator::PySetObject(PyObject* self, PyObject* value) { +PyObject* KX_ParentActuator::PySetObject(PyObject* value) { KX_GameObject *gameobj; ShowDeprecationWarning("setObject()", "the object property"); @@ -246,7 +246,7 @@ const char KX_ParentActuator::GetObject_doc[] = "getObject(name_only = 1)\n" "name_only - optional arg, when true will return the KX_GameObject rather then its name\n" "\tReturns the object that is set to.\n"; -PyObject* KX_ParentActuator::PyGetObject(PyObject* self, PyObject* args) +PyObject* KX_ParentActuator::PyGetObject(PyObject* args) { int ret_name_only = 1; diff --git a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp index f000d079927..fda639c09e0 100644 --- a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp +++ b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp @@ -51,9 +51,7 @@ KX_PhysicsObjectWrapper::~KX_PhysicsObjectWrapper() } -PyObject* KX_PhysicsObjectWrapper::PySetPosition(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_PhysicsObjectWrapper::PySetPosition(PyObject* args) { float x,y,z; if (PyArg_ParseTuple(args,"fff:setPosition",&x,&y,&z)) @@ -67,9 +65,7 @@ PyObject* KX_PhysicsObjectWrapper::PySetPosition(PyObject* self, } -PyObject* KX_PhysicsObjectWrapper::PySetLinearVelocity(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_PhysicsObjectWrapper::PySetLinearVelocity(PyObject* args) { float x,y,z; int local; @@ -83,9 +79,7 @@ PyObject* KX_PhysicsObjectWrapper::PySetLinearVelocity(PyObject* self, Py_RETURN_NONE; } -PyObject* KX_PhysicsObjectWrapper::PySetAngularVelocity(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_PhysicsObjectWrapper::PySetAngularVelocity(PyObject* args) { float x,y,z; int local; @@ -99,9 +93,7 @@ PyObject* KX_PhysicsObjectWrapper::PySetAngularVelocity(PyObject* self, Py_RETURN_NONE; } -PyObject* KX_PhysicsObjectWrapper::PySetActive(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_PhysicsObjectWrapper::PySetActive(PyObject* args) { int active; if (PyArg_ParseTuple(args,"i:setActive",&active)) diff --git a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.h b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.h index 6dc10f030f0..7e10dc3ccf4 100644 --- a/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.h +++ b/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.h @@ -42,10 +42,10 @@ public: KX_PhysicsObjectWrapper(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsEnvironment* physenv,PyTypeObject *T = &Type); virtual ~KX_PhysicsObjectWrapper(); - KX_PYMETHOD(KX_PhysicsObjectWrapper , SetPosition); - KX_PYMETHOD(KX_PhysicsObjectWrapper,SetLinearVelocity); - KX_PYMETHOD(KX_PhysicsObjectWrapper,SetAngularVelocity); - KX_PYMETHOD(KX_PhysicsObjectWrapper,SetActive); + KX_PYMETHOD_VARARGS(KX_PhysicsObjectWrapper,SetPosition); + KX_PYMETHOD_VARARGS(KX_PhysicsObjectWrapper,SetLinearVelocity); + KX_PYMETHOD_VARARGS(KX_PhysicsObjectWrapper,SetAngularVelocity); + KX_PYMETHOD_VARARGS(KX_PhysicsObjectWrapper,SetActive); private: class PHY_IPhysicsController* m_ctrl; diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp index e227ba09fba..5888579431a 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.cpp +++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp @@ -123,7 +123,7 @@ PyObject* KX_PolyProxy::py_getattro(PyObject *attr) // the one of the polygon RAS_MaterialBucket* polyBucket = m_polygon->GetMaterial(); unsigned int matid; - for (matid=0; matidNumMaterials(); matid++) + for (matid=0; matid<(unsigned int)m_mesh->NumMaterials(); matid++) { RAS_MeshMaterial* meshMat = m_mesh->GetMeshMaterial(matid); if (meshMat->m_bucket == polyBucket) @@ -189,7 +189,7 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getMaterialIndex, { RAS_MaterialBucket* polyBucket = m_polygon->GetMaterial(); unsigned int matid; - for (matid=0; matidNumMaterials(); matid++) + for (matid=0; matid<(unsigned int)m_mesh->NumMaterials(); matid++) { RAS_MeshMaterial* meshMat = m_mesh->GetMeshMaterial(matid); if (meshMat->m_bucket == polyBucket) diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 1c3bb250b03..2227072d2e7 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -183,9 +183,9 @@ from = Name of object to sned the string from"; static PyObject* gPySendMessage(PyObject*, PyObject* args) { char* subject; - char* body = ""; - char* to = ""; - char* from = ""; + char* body = (char *)""; + char* to = (char *)""; + char* from = (char *)""; if (!PyArg_ParseTuple(args, "s|sss:sendMessage", &subject, &body, &to, &from)) return NULL; @@ -1422,7 +1422,7 @@ static void clearGameModules() /* Note, user modules could still reference these modules * but since the dict's are cleared their members wont be accessible */ - PyObject *modules= PySys_GetObject("modules"); + PyObject *modules= PySys_GetObject((char *)"modules"); clearModule(modules, "Expression"); clearModule(modules, "CValue"); clearModule(modules, "PhysicsConstraints"); 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); diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp index 40af3b22aeb..8277e7ef19c 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.cpp +++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp @@ -207,7 +207,7 @@ 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* KX_RadarSensor::PyGetConeOrigin() { ShowDeprecationWarning("getConeOrigin()", "the coneOrigin property"); PyObject *retVal = PyList_New(3); @@ -223,7 +223,7 @@ PyObject* KX_RadarSensor::PyGetConeOrigin(PyObject* self) { 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* KX_RadarSensor::PyGetConeTarget() { ShowDeprecationWarning("getConeTarget()", "the coneTarget property"); PyObject *retVal = PyList_New(3); @@ -239,7 +239,7 @@ PyObject* KX_RadarSensor::PyGetConeTarget(PyObject* self) { 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* KX_RadarSensor::PyGetConeHeight() { ShowDeprecationWarning("getConeHeight()", "the distance property"); diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index 080a217b9bd..06c04dbf10d 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -384,7 +384,7 @@ PyObject* KX_RaySensor::pyattr_get_hitobject(void *self_v, const KX_PYATTRIBUTE_ 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* KX_RaySensor::PyGetHitObject() { ShowDeprecationWarning("getHitObject()", "the hitObject property"); if (m_hitObject) @@ -398,7 +398,7 @@ 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* KX_RaySensor::PyGetHitPosition() { ShowDeprecationWarning("getHitPosition()", "the hitPosition property"); @@ -414,7 +414,7 @@ PyObject* KX_RaySensor::PyGetHitPosition(PyObject* self) const char KX_RaySensor::GetRayDirection_doc[] = "getRayDirection()\n" "\tReturns the direction from the ray (in worldcoordinates) .\n"; -PyObject* KX_RaySensor::PyGetRayDirection(PyObject* self) +PyObject* KX_RaySensor::PyGetRayDirection() { ShowDeprecationWarning("getRayDirection()", "the rayDirection property"); @@ -430,7 +430,7 @@ PyObject* KX_RaySensor::PyGetRayDirection(PyObject* self) 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* KX_RaySensor::PyGetHitNormal() { ShowDeprecationWarning("getHitNormal()", "the hitNormal property"); diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index 1ab4bd21120..f1c7b757579 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -271,7 +271,7 @@ const char KX_SCA_AddObjectActuator::SetObject_doc[] = "\t- object: KX_GameObject, string or None\n" "\tSets the object that will be added. There has to be an object\n" "\tof this name. If not, this function does nothing.\n"; -PyObject* KX_SCA_AddObjectActuator::PySetObject(PyObject* self, PyObject* value) +PyObject* KX_SCA_AddObjectActuator::PySetObject(PyObject* value) { KX_GameObject *gameobj; @@ -300,7 +300,7 @@ const char KX_SCA_AddObjectActuator::SetTime_doc[] = "\tIf the duration is negative, it is set to 0.\n"; -PyObject* KX_SCA_AddObjectActuator::PySetTime(PyObject* self, PyObject* value) +PyObject* KX_SCA_AddObjectActuator::PySetTime(PyObject* value) { ShowDeprecationWarning("setTime()", "the time property"); int deltatime = PyInt_AsLong(value); @@ -323,7 +323,7 @@ const char KX_SCA_AddObjectActuator::GetTime_doc[] = "\tReturns the lifetime of the object that will be added.\n"; -PyObject* KX_SCA_AddObjectActuator::PyGetTime(PyObject* self) +PyObject* KX_SCA_AddObjectActuator::PyGetTime() { ShowDeprecationWarning("getTime()", "the time property"); return PyInt_FromLong(m_timeProp); @@ -335,7 +335,7 @@ const char KX_SCA_AddObjectActuator::GetObject_doc[] = "getObject(name_only = 1)\n" "name_only - optional arg, when true will return the KX_GameObject rather then its name\n" "\tReturns the name of the object that will be added.\n"; -PyObject* KX_SCA_AddObjectActuator::PyGetObject(PyObject* self, PyObject* args) +PyObject* KX_SCA_AddObjectActuator::PyGetObject(PyObject* args) { int ret_name_only = 1; @@ -361,7 +361,7 @@ const char KX_SCA_AddObjectActuator::GetLinearVelocity_doc[] = "\tReturns the linear velocity that will be assigned to \n" "\tthe created object.\n"; -PyObject* KX_SCA_AddObjectActuator::PyGetLinearVelocity(PyObject* self) +PyObject* KX_SCA_AddObjectActuator::PyGetLinearVelocity() { ShowDeprecationWarning("getLinearVelocity()", "the linearVelocity property"); PyObject *retVal = PyList_New(3); @@ -384,7 +384,7 @@ const char KX_SCA_AddObjectActuator::SetLinearVelocity_doc[] = "\t- local: bool\n" "\tAssign this velocity to the created object. \n"; -PyObject* KX_SCA_AddObjectActuator::PySetLinearVelocity(PyObject* self, PyObject* args) +PyObject* KX_SCA_AddObjectActuator::PySetLinearVelocity(PyObject* args) { ShowDeprecationWarning("setLinearVelocity()", "the linearVelocity property"); @@ -404,7 +404,7 @@ const char KX_SCA_AddObjectActuator::GetAngularVelocity_doc[] = "\tReturns the angular velocity that will be assigned to \n" "\tthe created object.\n"; -PyObject* KX_SCA_AddObjectActuator::PyGetAngularVelocity(PyObject* self) +PyObject* KX_SCA_AddObjectActuator::PyGetAngularVelocity() { ShowDeprecationWarning("getAngularVelocity()", "the angularVelocity property"); PyObject *retVal = PyList_New(3); @@ -427,7 +427,7 @@ const char KX_SCA_AddObjectActuator::SetAngularVelocity_doc[] = "\t- local: bool\n" "\tAssign this angular velocity to the created object. \n"; -PyObject* KX_SCA_AddObjectActuator::PySetAngularVelocity(PyObject* self, PyObject* args) +PyObject* KX_SCA_AddObjectActuator::PySetAngularVelocity(PyObject* args) { ShowDeprecationWarning("setAngularVelocity()", "the angularVelocity property"); @@ -468,7 +468,7 @@ void KX_SCA_AddObjectActuator::InstantAddObject() } } -PyObject* KX_SCA_AddObjectActuator::PyInstantAddObject(PyObject* self) +PyObject* KX_SCA_AddObjectActuator::PyInstantAddObject() { InstantAddObject(); @@ -483,7 +483,7 @@ const char KX_SCA_AddObjectActuator::GetLastCreatedObject_doc[] = "\tReturn the last created object. \n"; -PyObject* KX_SCA_AddObjectActuator::PyGetLastCreatedObject(PyObject* self) +PyObject* KX_SCA_AddObjectActuator::PyGetLastCreatedObject() { ShowDeprecationWarning("getLastCreatedObject()", "the objectLastCreated property"); SCA_IObject* result = this->GetLastCreatedObject(); diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index b678b14c2f5..44dedb38429 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -141,7 +141,7 @@ const char KX_SCA_ReplaceMeshActuator::SetMesh_doc[] = "\t- name: string or None\n" "\tSet the mesh that will be substituted for the current one.\n"; -PyObject* KX_SCA_ReplaceMeshActuator::PySetMesh(PyObject* self, PyObject* value) +PyObject* KX_SCA_ReplaceMeshActuator::PySetMesh(PyObject* value) { ShowDeprecationWarning("setMesh()", "the mesh property"); if (value == Py_None) { diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index 414251d6b06..f54d8542260 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -263,9 +263,9 @@ PyMethodDef KX_SceneActuator::Methods[] = {"setUseRestart", (PyCFunction) KX_SceneActuator::sPySetUseRestart, METH_VARARGS, (PY_METHODCHAR)SetUseRestart_doc}, {"setScene", (PyCFunction) KX_SceneActuator::sPySetScene, METH_VARARGS, (PY_METHODCHAR)SetScene_doc}, {"setCamera", (PyCFunction) KX_SceneActuator::sPySetCamera, METH_VARARGS, (PY_METHODCHAR)SetCamera_doc}, - {"getUseRestart", (PyCFunction) KX_SceneActuator::sPyGetUseRestart, METH_VARARGS, (PY_METHODCHAR)GetUseRestart_doc}, - {"getScene", (PyCFunction) KX_SceneActuator::sPyGetScene, METH_VARARGS, (PY_METHODCHAR)GetScene_doc}, - {"getCamera", (PyCFunction) KX_SceneActuator::sPyGetCamera, METH_VARARGS, (PY_METHODCHAR)GetCamera_doc}, + {"getUseRestart", (PyCFunction) KX_SceneActuator::sPyGetUseRestart, METH_NOARGS, (PY_METHODCHAR)GetUseRestart_doc}, + {"getScene", (PyCFunction) KX_SceneActuator::sPyGetScene, METH_NOARGS, (PY_METHODCHAR)GetScene_doc}, + {"getCamera", (PyCFunction) KX_SceneActuator::sPyGetCamera, METH_NOARGS, (PY_METHODCHAR)GetCamera_doc}, //<----- Deprecated {NULL,NULL} //Sentinel }; @@ -353,9 +353,7 @@ const char KX_SceneActuator::SetUseRestart_doc[] = "setUseRestart(flag)\n" "\t- flag: 0 or 1.\n" "\tSet flag to 1 to restart the scene.\n" ; -PyObject* KX_SceneActuator::PySetUseRestart(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_SceneActuator::PySetUseRestart(PyObject* args) { ShowDeprecationWarning("setUseRestart()", "(no replacement)"); int boolArg; @@ -376,9 +374,7 @@ PyObject* KX_SceneActuator::PySetUseRestart(PyObject* self, const char KX_SceneActuator::GetUseRestart_doc[] = "getUseRestart()\n" "\tReturn whether the scene will be restarted.\n" ; -PyObject* KX_SceneActuator::PyGetUseRestart(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_SceneActuator::PyGetUseRestart() { ShowDeprecationWarning("getUseRestart()", "(no replacement)"); return PyInt_FromLong(!(m_restart == 0)); @@ -391,9 +387,7 @@ const char KX_SceneActuator::SetScene_doc[] = "setScene(scene)\n" "\t- scene: string\n" "\tSet the name of scene the actuator will switch to.\n" ; -PyObject* KX_SceneActuator::PySetScene(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_SceneActuator::PySetScene(PyObject* args) { ShowDeprecationWarning("setScene()", "the scene property"); /* one argument: a scene, ignore the rest */ @@ -416,9 +410,7 @@ PyObject* KX_SceneActuator::PySetScene(PyObject* self, const char KX_SceneActuator::GetScene_doc[] = "getScene()\n" "\tReturn the name of the scene the actuator wants to switch to.\n" ; -PyObject* KX_SceneActuator::PyGetScene(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_SceneActuator::PyGetScene() { ShowDeprecationWarning("getScene()", "the scene property"); return PyString_FromString(m_nextSceneName); @@ -431,9 +423,7 @@ const char KX_SceneActuator::SetCamera_doc[] = "setCamera(camera)\n" "\t- camera: string\n" "\tSet the camera to switch to.\n" ; -PyObject* KX_SceneActuator::PySetCamera(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_SceneActuator::PySetCamera(PyObject* args) { ShowDeprecationWarning("setCamera()", "the camera property"); PyObject *cam; @@ -483,9 +473,7 @@ PyObject* KX_SceneActuator::PySetCamera(PyObject* self, const char KX_SceneActuator::GetCamera_doc[] = "getCamera()\n" "\tReturn the name of the camera to switch to.\n" ; -PyObject* KX_SceneActuator::PyGetCamera(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_SceneActuator::PyGetCamera() { ShowDeprecationWarning("getCamera()", "the camera property"); if (m_camera) { diff --git a/source/gameengine/Ketsji/KX_SceneActuator.h b/source/gameengine/Ketsji/KX_SceneActuator.h index f1904f95c2a..803c5106a60 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.h +++ b/source/gameengine/Ketsji/KX_SceneActuator.h @@ -99,17 +99,17 @@ class KX_SceneActuator : public SCA_IActuator /* Removed */ /* 2. setUseRestart: */ - KX_PYMETHOD_DOC(KX_SceneActuator,SetUseRestart); + KX_PYMETHOD_DOC_VARARGS(KX_SceneActuator,SetUseRestart); /* 3. getUseRestart: */ - KX_PYMETHOD_DOC(KX_SceneActuator,GetUseRestart); + KX_PYMETHOD_DOC_NOARGS(KX_SceneActuator,GetUseRestart); /* 4. setScene: */ - KX_PYMETHOD_DOC(KX_SceneActuator,SetScene); + KX_PYMETHOD_DOC_VARARGS(KX_SceneActuator,SetScene); /* 5. getScene: */ - KX_PYMETHOD_DOC(KX_SceneActuator,GetScene); + KX_PYMETHOD_DOC_NOARGS(KX_SceneActuator,GetScene); /* 6. setCamera: */ - KX_PYMETHOD_DOC(KX_SceneActuator,SetCamera); + KX_PYMETHOD_DOC_VARARGS(KX_SceneActuator,SetCamera); /* 7. getCamera: */ - KX_PYMETHOD_DOC(KX_SceneActuator,GetCamera); + KX_PYMETHOD_DOC_NOARGS(KX_SceneActuator,GetCamera); static PyObject* pyattr_get_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index d7449c7effa..eb1d91d760f 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -267,20 +267,20 @@ PyParentObject KX_SoundActuator::Parents[] = { PyMethodDef KX_SoundActuator::Methods[] = { // Deprecated -----> {"setFilename", (PyCFunction) KX_SoundActuator::sPySetFilename, METH_VARARGS,NULL}, - {"getFilename", (PyCFunction) KX_SoundActuator::sPyGetFilename, METH_VARARGS,NULL}, + {"getFilename", (PyCFunction) KX_SoundActuator::sPyGetFilename, METH_NOARGS,NULL}, {"setGain",(PyCFunction) KX_SoundActuator::sPySetGain,METH_VARARGS,NULL}, - {"getGain",(PyCFunction) KX_SoundActuator::sPyGetGain,METH_VARARGS,NULL}, + {"getGain",(PyCFunction) KX_SoundActuator::sPyGetGain,METH_NOARGS,NULL}, {"setPitch",(PyCFunction) KX_SoundActuator::sPySetPitch,METH_VARARGS,NULL}, - {"getPitch",(PyCFunction) KX_SoundActuator::sPyGetPitch,METH_VARARGS,NULL}, + {"getPitch",(PyCFunction) KX_SoundActuator::sPyGetPitch,METH_NOARGS,NULL}, {"setRollOffFactor",(PyCFunction) KX_SoundActuator::sPySetRollOffFactor,METH_VARARGS,NULL}, - {"getRollOffFactor",(PyCFunction) KX_SoundActuator::sPyGetRollOffFactor,METH_VARARGS,NULL}, + {"getRollOffFactor",(PyCFunction) KX_SoundActuator::sPyGetRollOffFactor,METH_NOARGS,NULL}, {"setLooping",(PyCFunction) KX_SoundActuator::sPySetLooping,METH_VARARGS,NULL}, - {"getLooping",(PyCFunction) KX_SoundActuator::sPyGetLooping,METH_VARARGS,NULL}, + {"getLooping",(PyCFunction) KX_SoundActuator::sPyGetLooping,METH_NOARGS,NULL}, {"setPosition",(PyCFunction) KX_SoundActuator::sPySetPosition,METH_VARARGS,NULL}, {"setVelocity",(PyCFunction) KX_SoundActuator::sPySetVelocity,METH_VARARGS,NULL}, {"setOrientation",(PyCFunction) KX_SoundActuator::sPySetOrientation,METH_VARARGS,NULL}, {"setType",(PyCFunction) KX_SoundActuator::sPySetType,METH_VARARGS,NULL}, - {"getType",(PyCFunction) KX_SoundActuator::sPyGetType,METH_VARARGS,NULL}, + {"getType",(PyCFunction) KX_SoundActuator::sPyGetType,METH_NOARGS,NULL}, // <----- KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, startSound), @@ -587,7 +587,7 @@ int KX_SoundActuator::pyattr_set_orientation(void *self, const struct KX_PYATTRI } // Deprecated -----> -PyObject* KX_SoundActuator::PySetFilename(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PySetFilename(PyObject* args) { char *soundName = NULL; ShowDeprecationWarning("setFilename()", "the filename property"); @@ -599,7 +599,7 @@ PyObject* KX_SoundActuator::PySetFilename(PyObject* self, PyObject* args, PyObje Py_RETURN_NONE; } -PyObject* KX_SoundActuator::PyGetFilename(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PyGetFilename() { ShowDeprecationWarning("getFilename()", "the filename property"); if (!m_soundObject) @@ -616,7 +616,7 @@ PyObject* KX_SoundActuator::PyGetFilename(PyObject* self, PyObject* args, PyObje return PyString_FromString(name); } -PyObject* KX_SoundActuator::PySetGain(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PySetGain(PyObject* args) { ShowDeprecationWarning("setGain()", "the volume property"); float gain = 1.0; @@ -631,7 +631,7 @@ PyObject* KX_SoundActuator::PySetGain(PyObject* self, PyObject* args, PyObject* -PyObject* KX_SoundActuator::PyGetGain(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PyGetGain() { ShowDeprecationWarning("getGain()", "the volume property"); float gain = (m_soundObject) ? m_soundObject->GetGain() : 1.0f; @@ -642,7 +642,7 @@ PyObject* KX_SoundActuator::PyGetGain(PyObject* self, PyObject* args, PyObject* -PyObject* KX_SoundActuator::PySetPitch(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PySetPitch(PyObject* args) { ShowDeprecationWarning("setPitch()", "the pitch property"); float pitch = 1.0; @@ -657,7 +657,7 @@ PyObject* KX_SoundActuator::PySetPitch(PyObject* self, PyObject* args, PyObject* -PyObject* KX_SoundActuator::PyGetPitch(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PyGetPitch() { ShowDeprecationWarning("getPitch()", "the pitch property"); float pitch = (m_soundObject) ? m_soundObject->GetPitch() : 1.0; @@ -668,7 +668,7 @@ PyObject* KX_SoundActuator::PyGetPitch(PyObject* self, PyObject* args, PyObject* -PyObject* KX_SoundActuator::PySetRollOffFactor(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PySetRollOffFactor(PyObject* args) { ShowDeprecationWarning("setRollOffFactor()", "the rollOffFactor property"); float rollofffactor = 1.0; @@ -683,7 +683,7 @@ PyObject* KX_SoundActuator::PySetRollOffFactor(PyObject* self, PyObject* args, P -PyObject* KX_SoundActuator::PyGetRollOffFactor(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PyGetRollOffFactor() { ShowDeprecationWarning("getRollOffFactor()", "the rollOffFactor property"); float rollofffactor = (m_soundObject) ? m_soundObject->GetRollOffFactor() : 1.0; @@ -694,7 +694,7 @@ PyObject* KX_SoundActuator::PyGetRollOffFactor(PyObject* self, PyObject* args, P -PyObject* KX_SoundActuator::PySetLooping(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PySetLooping(PyObject* args) { ShowDeprecationWarning("setLooping()", "the looping property"); bool looping = 1; @@ -709,7 +709,7 @@ PyObject* KX_SoundActuator::PySetLooping(PyObject* self, PyObject* args, PyObjec -PyObject* KX_SoundActuator::PyGetLooping(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PyGetLooping() { ShowDeprecationWarning("getLooping()", "the looping property"); int looping = (m_soundObject) ? m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF; @@ -720,7 +720,7 @@ PyObject* KX_SoundActuator::PyGetLooping(PyObject* self, PyObject* args, PyObjec -PyObject* KX_SoundActuator::PySetPosition(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PySetPosition(PyObject* args) { MT_Point3 pos; ShowDeprecationWarning("setPosition()", "the position property"); @@ -739,7 +739,7 @@ PyObject* KX_SoundActuator::PySetPosition(PyObject* self, PyObject* args, PyObje -PyObject* KX_SoundActuator::PySetVelocity(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PySetVelocity(PyObject* args) { MT_Vector3 vel; ShowDeprecationWarning("setVelocity()", "the velocity property"); @@ -758,7 +758,7 @@ PyObject* KX_SoundActuator::PySetVelocity(PyObject* self, PyObject* args, PyObje -PyObject* KX_SoundActuator::PySetOrientation(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PySetOrientation(PyObject* args) { MT_Matrix3x3 ori; ShowDeprecationWarning("setOrientation()", "the orientation property"); @@ -781,7 +781,7 @@ PyObject* KX_SoundActuator::PySetOrientation(PyObject* self, PyObject* args, PyO Py_RETURN_NONE; } -PyObject* KX_SoundActuator::PySetType(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PySetType(PyObject* args) { int typeArg; ShowDeprecationWarning("setType()", "the type property"); @@ -798,7 +798,7 @@ PyObject* KX_SoundActuator::PySetType(PyObject* self, PyObject* args, PyObject* Py_RETURN_NONE; } -PyObject* KX_SoundActuator::PyGetType(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_SoundActuator::PyGetType() { ShowDeprecationWarning("getType()", "the type property"); return PyInt_FromLong(m_type); diff --git a/source/gameengine/Ketsji/KX_SoundActuator.h b/source/gameengine/Ketsji/KX_SoundActuator.h index eb18ba9f13e..d5e678bbecd 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.h +++ b/source/gameengine/Ketsji/KX_SoundActuator.h @@ -108,21 +108,21 @@ public: static PyObject* pyattr_get_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); // Deprecated -----> - KX_PYMETHOD(KX_SoundActuator,SetFilename); - KX_PYMETHOD(KX_SoundActuator,GetFilename); - KX_PYMETHOD(KX_SoundActuator,SetGain); - KX_PYMETHOD(KX_SoundActuator,GetGain); - KX_PYMETHOD(KX_SoundActuator,SetPitch); - KX_PYMETHOD(KX_SoundActuator,GetPitch); - KX_PYMETHOD(KX_SoundActuator,SetRollOffFactor); - KX_PYMETHOD(KX_SoundActuator,GetRollOffFactor); - KX_PYMETHOD(KX_SoundActuator,SetLooping); - KX_PYMETHOD(KX_SoundActuator,GetLooping); - KX_PYMETHOD(KX_SoundActuator,SetPosition); - KX_PYMETHOD(KX_SoundActuator,SetVelocity); - KX_PYMETHOD(KX_SoundActuator,SetOrientation); - KX_PYMETHOD(KX_SoundActuator,SetType); - KX_PYMETHOD(KX_SoundActuator,GetType); + KX_PYMETHOD_VARARGS(KX_SoundActuator,SetFilename); + KX_PYMETHOD_NOARGS(KX_SoundActuator,GetFilename); + KX_PYMETHOD_VARARGS(KX_SoundActuator,SetGain); + KX_PYMETHOD_NOARGS(KX_SoundActuator,GetGain); + KX_PYMETHOD_VARARGS(KX_SoundActuator,SetPitch); + KX_PYMETHOD_NOARGS(KX_SoundActuator,GetPitch); + KX_PYMETHOD_VARARGS(KX_SoundActuator,SetRollOffFactor); + KX_PYMETHOD_NOARGS(KX_SoundActuator,GetRollOffFactor); + KX_PYMETHOD_VARARGS(KX_SoundActuator,SetLooping); + KX_PYMETHOD_NOARGS(KX_SoundActuator,GetLooping); + KX_PYMETHOD_VARARGS(KX_SoundActuator,SetPosition); + KX_PYMETHOD_VARARGS(KX_SoundActuator,SetVelocity); + KX_PYMETHOD_VARARGS(KX_SoundActuator,SetOrientation); + KX_PYMETHOD_VARARGS(KX_SoundActuator,SetType); + KX_PYMETHOD_NOARGS(KX_SoundActuator,GetType); // <----- }; diff --git a/source/gameengine/Ketsji/KX_StateActuator.cpp b/source/gameengine/Ketsji/KX_StateActuator.cpp index 3cfa40c6f80..976e7ea5204 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.cpp +++ b/source/gameengine/Ketsji/KX_StateActuator.cpp @@ -173,9 +173,7 @@ KX_StateActuator::SetOperation_doc[] = "\tUse setMask() to specify the bits that will be modified.\n"; PyObject* -KX_StateActuator::PySetOperation(PyObject* self, - PyObject* args, - PyObject* kwds) { +KX_StateActuator::PySetOperation(PyObject* args) { ShowDeprecationWarning("setOperation()", "the operation property"); int oper; @@ -199,9 +197,7 @@ KX_StateActuator::SetMask_doc[] = "\twhich copies the value to the object state.\n"; PyObject* -KX_StateActuator::PySetMask(PyObject* self, - PyObject* args, - PyObject* kwds) { +KX_StateActuator::PySetMask(PyObject* args) { ShowDeprecationWarning("setMask()", "the mask property"); int mask; diff --git a/source/gameengine/Ketsji/KX_StateActuator.h b/source/gameengine/Ketsji/KX_StateActuator.h index 426753dadfd..4a64894259d 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.h +++ b/source/gameengine/Ketsji/KX_StateActuator.h @@ -78,8 +78,8 @@ class KX_StateActuator : public SCA_IActuator virtual PyObject* py_getattro(PyObject *attr); virtual int py_setattro(PyObject *attr, PyObject* value); //KX_PYMETHOD_DOC - KX_PYMETHOD_DOC(KX_StateActuator,SetOperation); - KX_PYMETHOD_DOC(KX_StateActuator,SetMask); + KX_PYMETHOD_DOC_VARARGS(KX_StateActuator,SetOperation); + KX_PYMETHOD_DOC_VARARGS(KX_StateActuator,SetMask); }; #endif diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 79da4984740..e7f8acbd1a8 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -310,7 +310,7 @@ 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* value) +PyObject* KX_TouchSensor::PySetProperty(PyObject* value) { ShowDeprecationWarning("setProperty()", "the propertyName property"); char *nameArg= PyString_AsString(value); @@ -328,14 +328,14 @@ 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* KX_TouchSensor::PyGetProperty() { return PyString_FromString(m_touchedpropname); } const char KX_TouchSensor::GetHitObject_doc[] = "getHitObject()\n" ; -PyObject* KX_TouchSensor::PyGetHitObject(PyObject* self) +PyObject* KX_TouchSensor::PyGetHitObject() { ShowDeprecationWarning("getHitObject()", "the objectHit property"); /* to do: do Py_IncRef if the object is already known in Python */ @@ -351,7 +351,7 @@ 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* KX_TouchSensor::PyGetHitObjectList() { ShowDeprecationWarning("getHitObjectList()", "the objectHitList property"); /* to do: do Py_IncRef if the object is already known in Python */ @@ -367,7 +367,7 @@ 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* KX_TouchSensor::PyGetTouchMaterial() { ShowDeprecationWarning("getTouchMaterial()", "the materialCheck property"); return PyInt_FromLong(m_bFindMaterial); @@ -380,7 +380,7 @@ const char KX_TouchSensor::SetTouchMaterial_doc[] = "\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 *value) +PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject *value) { int pulseArg = PyInt_AsLong(value); diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 6c522b35528..c89d88389c4 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -458,9 +458,9 @@ PyParentObject KX_TrackToActuator::Parents[] = { PyMethodDef KX_TrackToActuator::Methods[] = { // ---> deprecated {"setTime", (PyCFunction) KX_TrackToActuator::sPySetTime, METH_VARARGS, (PY_METHODCHAR)SetTime_doc}, - {"getTime", (PyCFunction) KX_TrackToActuator::sPyGetTime, METH_VARARGS, (PY_METHODCHAR)GetTime_doc}, + {"getTime", (PyCFunction) KX_TrackToActuator::sPyGetTime, METH_NOARGS, (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}, + {"getUse3D", (PyCFunction) KX_TrackToActuator::sPyGetUse3D, METH_NOARGS, (PY_METHODCHAR)GetUse3D_doc}, {"setObject", (PyCFunction) KX_TrackToActuator::sPySetObject, METH_O, (PY_METHODCHAR)SetObject_doc}, {"getObject", (PyCFunction) KX_TrackToActuator::sPyGetObject, METH_VARARGS, (PY_METHODCHAR)GetObject_doc}, @@ -519,7 +519,7 @@ const char KX_TrackToActuator::SetObject_doc[] = "setObject(object)\n" "\t- object: KX_GameObject, string or None\n" "\tSet the object to track with the parent of this actuator.\n"; -PyObject* KX_TrackToActuator::PySetObject(PyObject* self, PyObject* value) +PyObject* KX_TrackToActuator::PySetObject(PyObject* value) { KX_GameObject *gameobj; @@ -545,7 +545,7 @@ const char KX_TrackToActuator::GetObject_doc[] = "getObject(name_only = 1)\n" "name_only - optional arg, when true will return the KX_GameObject rather then its name\n" "\tReturns the object to track with the parent of this actuator\n"; -PyObject* KX_TrackToActuator::PyGetObject(PyObject* self, PyObject* args) +PyObject* KX_TrackToActuator::PyGetObject(PyObject* args) { int ret_name_only = 1; @@ -570,7 +570,7 @@ const char KX_TrackToActuator::SetTime_doc[] = "setTime(time)\n" "\t- time: integer\n" "\tSet the time in frames with which to delay the tracking motion.\n"; -PyObject* KX_TrackToActuator::PySetTime(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_TrackToActuator::PySetTime(PyObject* args) { ShowDeprecationWarning("setTime()", "the timer property"); int timeArg; @@ -592,7 +592,7 @@ const char KX_TrackToActuator::GetTime_doc[] = "getTime()\n" "\t- time: integer\n" "\tReturn the time in frames with which the tracking motion is delayed.\n"; -PyObject* KX_TrackToActuator::PyGetTime(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_TrackToActuator::PyGetTime() { ShowDeprecationWarning("getTime()", "the timer property"); return PyInt_FromLong(m_time); @@ -604,7 +604,7 @@ PyObject* KX_TrackToActuator::PyGetTime(PyObject* self, PyObject* args, PyObject const char KX_TrackToActuator::GetUse3D_doc[] = "getUse3D()\n" "\tReturns 1 if the motion is allowed to extend in the z-direction.\n"; -PyObject* KX_TrackToActuator::PyGetUse3D(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_TrackToActuator::PyGetUse3D() { ShowDeprecationWarning("setTime()", "the use3D property"); return PyInt_FromLong(!(m_allow3D == 0)); @@ -618,7 +618,7 @@ const char KX_TrackToActuator::SetUse3D_doc[] = "\t- value: 0 or 1\n" "\tSet to 1 to allow the tracking motion to extend in the z-direction,\n" "\tset to 0 to lock the tracking motion to the x-y plane.\n"; -PyObject* KX_TrackToActuator::PySetUse3D(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* KX_TrackToActuator::PySetUse3D(PyObject* args) { ShowDeprecationWarning("setTime()", "the use3D property"); int boolArg; diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.h b/source/gameengine/Ketsji/KX_TrackToActuator.h index cc4049e19a8..99505f93cfe 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.h +++ b/source/gameengine/Ketsji/KX_TrackToActuator.h @@ -84,13 +84,13 @@ class KX_TrackToActuator : public SCA_IActuator /* 2. getObject */ KX_PYMETHOD_DOC_VARARGS(KX_TrackToActuator,GetObject); /* 3. setTime */ - KX_PYMETHOD_DOC(KX_TrackToActuator,SetTime); + KX_PYMETHOD_DOC_VARARGS(KX_TrackToActuator,SetTime); /* 4. getTime */ - KX_PYMETHOD_DOC(KX_TrackToActuator,GetTime); + KX_PYMETHOD_DOC_NOARGS(KX_TrackToActuator,GetTime); /* 5. getUse3D */ - KX_PYMETHOD_DOC(KX_TrackToActuator,GetUse3D); + KX_PYMETHOD_DOC_NOARGS(KX_TrackToActuator,GetUse3D); /* 6. setUse3D */ - KX_PYMETHOD_DOC(KX_TrackToActuator,SetUse3D); + KX_PYMETHOD_DOC_VARARGS(KX_TrackToActuator,SetUse3D); }; /* end of class KX_TrackToActuator : public KX_EditObjectActuator */ diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp index 558b2849cc7..f77c135e994 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp @@ -35,9 +35,7 @@ KX_VehicleWrapper::~KX_VehicleWrapper() } -PyObject* KX_VehicleWrapper::PyAddWheel(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PyAddWheel(PyObject* args) { PyObject* pylistPos,*pylistDir,*pylistAxleDir; @@ -85,9 +83,7 @@ PyObject* KX_VehicleWrapper::PyAddWheel(PyObject* self, -PyObject* KX_VehicleWrapper::PyGetWheelPosition(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PyGetWheelPosition(PyObject* args) { int wheelIndex; @@ -102,9 +98,7 @@ PyObject* KX_VehicleWrapper::PyGetWheelPosition(PyObject* self, return NULL; } -PyObject* KX_VehicleWrapper::PyGetWheelRotation(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PyGetWheelRotation(PyObject* args) { int wheelIndex; if (PyArg_ParseTuple(args,"i:getWheelRotation",&wheelIndex)) @@ -114,9 +108,7 @@ PyObject* KX_VehicleWrapper::PyGetWheelRotation(PyObject* self, return NULL; } -PyObject* KX_VehicleWrapper::PyGetWheelOrientationQuaternion(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PyGetWheelOrientationQuaternion(PyObject* args) { int wheelIndex; if (PyArg_ParseTuple(args,"i:getWheelOrientationQuaternion",&wheelIndex)) @@ -132,26 +124,20 @@ PyObject* KX_VehicleWrapper::PyGetWheelOrientationQuaternion(PyObject* self, } -PyObject* KX_VehicleWrapper::PyGetNumWheels(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PyGetNumWheels(PyObject* args) { return PyInt_FromLong(m_vehicle->GetNumWheels()); } -PyObject* KX_VehicleWrapper::PyGetConstraintId(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PyGetConstraintId(PyObject* args) { return PyInt_FromLong(m_vehicle->GetUserConstraintId()); } -PyObject* KX_VehicleWrapper::PyApplyEngineForce(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PyApplyEngineForce(PyObject* args) { float force; int wheelIndex; @@ -167,9 +153,7 @@ PyObject* KX_VehicleWrapper::PyApplyEngineForce(PyObject* self, Py_RETURN_NONE; } -PyObject* KX_VehicleWrapper::PySetTyreFriction(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PySetTyreFriction(PyObject* args) { float wheelFriction; int wheelIndex; @@ -184,9 +168,7 @@ PyObject* KX_VehicleWrapper::PySetTyreFriction(PyObject* self, Py_RETURN_NONE; } -PyObject* KX_VehicleWrapper::PySetSuspensionStiffness(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PySetSuspensionStiffness(PyObject* args) { float suspensionStiffness; int wheelIndex; @@ -201,9 +183,7 @@ PyObject* KX_VehicleWrapper::PySetSuspensionStiffness(PyObject* self, Py_RETURN_NONE; } -PyObject* KX_VehicleWrapper::PySetSuspensionDamping(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PySetSuspensionDamping(PyObject* args) { float suspensionDamping; int wheelIndex; @@ -217,9 +197,7 @@ PyObject* KX_VehicleWrapper::PySetSuspensionDamping(PyObject* self, Py_RETURN_NONE; } -PyObject* KX_VehicleWrapper::PySetSuspensionCompression(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PySetSuspensionCompression(PyObject* args) { float suspensionCompression; int wheelIndex; @@ -233,9 +211,7 @@ PyObject* KX_VehicleWrapper::PySetSuspensionCompression(PyObject* self, Py_RETURN_NONE; } -PyObject* KX_VehicleWrapper::PySetRollInfluence(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PySetRollInfluence(PyObject* args) { float rollInfluence; int wheelIndex; @@ -251,9 +227,7 @@ PyObject* KX_VehicleWrapper::PySetRollInfluence(PyObject* self, } -PyObject* KX_VehicleWrapper::PyApplyBraking(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PyApplyBraking(PyObject* args) { float braking; int wheelIndex; @@ -271,9 +245,7 @@ PyObject* KX_VehicleWrapper::PyApplyBraking(PyObject* self, -PyObject* KX_VehicleWrapper::PySetSteeringValue(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PySetSteeringValue(PyObject* args) { float steeringValue; int wheelIndex; @@ -289,9 +261,7 @@ PyObject* KX_VehicleWrapper::PySetSteeringValue(PyObject* self, } -PyObject* KX_VehicleWrapper::PyGetConstraintType(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_VehicleWrapper::PyGetConstraintType(PyObject* args) { return PyInt_FromLong(m_vehicle->GetUserConstraintType()); } diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.h b/source/gameengine/Ketsji/KX_VehicleWrapper.h index 4e03183bf85..de7fe75cfba 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.h +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.h @@ -23,31 +23,31 @@ public: int getConstraintId(); - KX_PYMETHOD(KX_VehicleWrapper,AddWheel); - KX_PYMETHOD(KX_VehicleWrapper,GetNumWheels); - KX_PYMETHOD(KX_VehicleWrapper,GetWheelOrientationQuaternion); - KX_PYMETHOD(KX_VehicleWrapper,GetWheelRotation); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,AddWheel); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,GetNumWheels); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,GetWheelOrientationQuaternion); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,GetWheelRotation); - KX_PYMETHOD(KX_VehicleWrapper,GetWheelPosition); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,GetWheelPosition); - KX_PYMETHOD(KX_VehicleWrapper,GetConstraintId); - KX_PYMETHOD(KX_VehicleWrapper,GetConstraintType); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,GetConstraintId); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,GetConstraintType); - KX_PYMETHOD(KX_VehicleWrapper,SetSteeringValue); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,SetSteeringValue); - KX_PYMETHOD(KX_VehicleWrapper,ApplyEngineForce); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,ApplyEngineForce); - KX_PYMETHOD(KX_VehicleWrapper,ApplyBraking); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,ApplyBraking); - KX_PYMETHOD(KX_VehicleWrapper,SetTyreFriction); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,SetTyreFriction); - KX_PYMETHOD(KX_VehicleWrapper,SetSuspensionStiffness); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,SetSuspensionStiffness); - KX_PYMETHOD(KX_VehicleWrapper,SetSuspensionDamping); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,SetSuspensionDamping); - KX_PYMETHOD(KX_VehicleWrapper,SetSuspensionCompression); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,SetSuspensionCompression); - KX_PYMETHOD(KX_VehicleWrapper,SetRollInfluence); + KX_PYMETHOD_VARARGS(KX_VehicleWrapper,SetRollInfluence); private: diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp index 4954e94f3e4..8be125011bb 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.cpp +++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp @@ -341,12 +341,12 @@ void KX_VertexProxy::ReplicaSetName(STR_String) {}; // stuff for python integration -PyObject* KX_VertexProxy::PyGetXYZ(PyObject*) +PyObject* KX_VertexProxy::PyGetXYZ() { return PyObjectFrom(MT_Point3(m_vertex->getXYZ())); } -PyObject* KX_VertexProxy::PySetXYZ(PyObject*, PyObject* value) +PyObject* KX_VertexProxy::PySetXYZ(PyObject* value) { MT_Point3 vec; if (!PyVecTo(value, vec)) @@ -357,12 +357,12 @@ PyObject* KX_VertexProxy::PySetXYZ(PyObject*, PyObject* value) Py_RETURN_NONE; } -PyObject* KX_VertexProxy::PyGetNormal(PyObject*) +PyObject* KX_VertexProxy::PyGetNormal() { return PyObjectFrom(MT_Vector3(m_vertex->getNormal())); } -PyObject* KX_VertexProxy::PySetNormal(PyObject*, PyObject* value) +PyObject* KX_VertexProxy::PySetNormal(PyObject* value) { MT_Vector3 vec; if (!PyVecTo(value, vec)) @@ -374,13 +374,13 @@ PyObject* KX_VertexProxy::PySetNormal(PyObject*, PyObject* value) } -PyObject* KX_VertexProxy::PyGetRGBA(PyObject*) +PyObject* KX_VertexProxy::PyGetRGBA() { int *rgba = (int *) m_vertex->getRGBA(); return PyInt_FromLong(*rgba); } -PyObject* KX_VertexProxy::PySetRGBA(PyObject*, PyObject* value) +PyObject* KX_VertexProxy::PySetRGBA(PyObject* value) { if PyInt_Check(value) { int rgba = PyInt_AsLong(value); @@ -403,12 +403,12 @@ PyObject* KX_VertexProxy::PySetRGBA(PyObject*, PyObject* value) } -PyObject* KX_VertexProxy::PyGetUV(PyObject*) +PyObject* KX_VertexProxy::PyGetUV() { return PyObjectFrom(MT_Vector2(m_vertex->getUV1())); } -PyObject* KX_VertexProxy::PySetUV(PyObject*, PyObject* value) +PyObject* KX_VertexProxy::PySetUV(PyObject* value) { MT_Point2 vec; if (!PyVecTo(value, vec)) @@ -419,12 +419,12 @@ PyObject* KX_VertexProxy::PySetUV(PyObject*, PyObject* value) Py_RETURN_NONE; } -PyObject* KX_VertexProxy::PyGetUV2(PyObject*) +PyObject* KX_VertexProxy::PyGetUV2() { return PyObjectFrom(MT_Vector2(m_vertex->getUV2())); } -PyObject* KX_VertexProxy::PySetUV2(PyObject*, PyObject* args) +PyObject* KX_VertexProxy::PySetUV2(PyObject* args) { MT_Point2 vec; unsigned int unit=0; diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp index 6d984f0d77a..ba59d0d3d47 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp @@ -157,9 +157,7 @@ KX_VisibilityActuator::SetVisible_doc[] = "\tSet the properties of the actuator.\n"; PyObject* -KX_VisibilityActuator::PySetVisible(PyObject* self, - PyObject* args, - PyObject* kwds) { +KX_VisibilityActuator::PySetVisible(PyObject* args) { int vis; ShowDeprecationWarning("SetVisible()", "the visible property"); diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.h b/source/gameengine/Ketsji/KX_VisibilityActuator.h index 4269258f862..04633bce665 100644 --- a/source/gameengine/Ketsji/KX_VisibilityActuator.h +++ b/source/gameengine/Ketsji/KX_VisibilityActuator.h @@ -73,7 +73,7 @@ class KX_VisibilityActuator : public SCA_IActuator virtual int py_setattro(PyObject *attr, PyObject *value); // Deprecated -----> - KX_PYMETHOD_DOC(KX_VisibilityActuator,SetVisible); + KX_PYMETHOD_DOC_VARARGS(KX_VisibilityActuator,SetVisible); // <----- diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index c7638b36728..4510bbddf65 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -107,7 +107,7 @@ public: } CcdShapeConstructionInfo* GetChildShape(int i) { - if (i < 0 || i >= m_shapeArray.size()) + if (i < 0 || i >= (int)m_shapeArray.size()) return NULL; return m_shapeArray.at(i); @@ -116,7 +116,7 @@ public: { if (shapeInfo == NULL) return -1; - for (int i=0; im_userData) && @@ -130,10 +130,10 @@ public: bool RemoveChildShape(int i) { - if (i < 0 || i >= m_shapeArray.size()) + if (i < 0 || i >= (int)m_shapeArray.size()) return false; m_shapeArray.at(i)->Release(); - if (i < m_shapeArray.size()-1) + if (i < (int)m_shapeArray.size()-1) m_shapeArray[i] = m_shapeArray.back(); m_shapeArray.pop_back(); return true; -- cgit v1.2.3 From 71448386069cfc00dba40deb6735b273a3ba33ad Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Sun, 19 Apr 2009 19:31:32 +0000 Subject: Compile fixed for Win64. Please check if that also compiles on win32. --- source/gameengine/GamePlayer/ghost/GPG_Application.cpp | 6 +++--- source/gameengine/Ketsji/CMakeLists.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index 6ff46ca8200..0ecbbea3af6 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -208,7 +208,7 @@ static LRESULT CALLBACK screenSaverWindowProc(HWND hwnd, UINT uMsg, WPARAM wPara BOOL CALLBACK findGhostWindowHWNDProc(HWND hwnd, LPARAM lParam) { - GHOST_IWindow *p = (GHOST_IWindow*) GetWindowLong(hwnd, GWL_USERDATA); + GHOST_IWindow *p = (GHOST_IWindow*) GetWindowLongPtr(hwnd, GWLP_USERDATA); BOOL ret = TRUE; if (p == ghost_window_to_find) { @@ -292,8 +292,8 @@ bool GPG_Application::startScreenSaverFullScreen( if (ghost_hwnd != NULL) { GetCursorPos(&scr_save_mouse_pos); - ghost_wnd_proc = (WNDPROC) GetWindowLong(ghost_hwnd, GWL_WNDPROC); - SetWindowLong(ghost_hwnd,GWL_WNDPROC, (LONG) screenSaverWindowProc); + ghost_wnd_proc = (WNDPROC) GetWindowLongPtr(ghost_hwnd, GWLP_WNDPROC); + SetWindowLongPtr(ghost_hwnd,GWLP_WNDPROC, (uintptr_t) screenSaverWindowProc); } } return ret; diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index d45d5345678..b848fa9ef42 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -68,7 +68,7 @@ SET(INC ../../../source/gameengine/Physics/Sumo ../../../source/gameengine/Physics/Sumo/Fuzzics/include ../../../source/gameengine/Network/LoopBackNetwork - ../../../intern/SoundSystem + ../../../intern/SoundSystem ../../../source/blender/misc ../../../source/blender/blenloader ../../../source/blender/gpu -- cgit v1.2.3 From f5fc4ebdd8ede5263f4b34f161ebe139d40466dc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 19 Apr 2009 21:01:12 +0000 Subject: BGE Python API - More verbose error messages. - BL_Shader wasnt setting error messages on some errors - FilterNormal depth attribute was checking for float which is bad because scripts often expect ints assigned to float attributes. - Added a check to PyVecTo for a tuple rather then always using a generic python sequence. On my system this is over 2x faster with an optmized build. --- source/gameengine/Converter/BL_ActionActuator.cpp | 4 +- source/gameengine/Converter/BL_ActionActuator.h | 2 +- .../Converter/BL_ShapeActionActuator.cpp | 4 +- .../gameengine/Converter/BL_ShapeActionActuator.h | 2 +- source/gameengine/Expressions/ListValue.cpp | 12 +- source/gameengine/Expressions/PyObjectPlus.cpp | 56 +++--- source/gameengine/Expressions/Value.cpp | 2 +- source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 2 +- source/gameengine/GameLogic/SCA_KeyboardSensor.cpp | 4 +- source/gameengine/GameLogic/SCA_MouseSensor.cpp | 2 +- .../gameengine/GameLogic/SCA_PythonController.cpp | 16 +- source/gameengine/GameLogic/SCA_RandomActuator.cpp | 2 +- source/gameengine/GameLogic/SCA_RandomSensor.cpp | 2 +- source/gameengine/Ketsji/BL_Shader.cpp | 219 ++++++++++++--------- .../Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp | 2 +- source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 4 +- source/gameengine/Ketsji/KX_Camera.cpp | 18 +- source/gameengine/Ketsji/KX_ConstraintActuator.cpp | 2 +- source/gameengine/Ketsji/KX_GameObject.cpp | 46 ++--- source/gameengine/Ketsji/KX_MeshProxy.cpp | 4 +- source/gameengine/Ketsji/KX_PolyProxy.cpp | 2 +- source/gameengine/Ketsji/KX_PyMath.h | 31 ++- source/gameengine/Ketsji/KX_PythonInit.cpp | 32 +-- .../Ketsji/KX_SCA_ReplaceMeshActuator.cpp | 4 +- source/gameengine/Ketsji/KX_Scene.cpp | 4 +- source/gameengine/Ketsji/KX_SoundActuator.cpp | 4 +- source/gameengine/Ketsji/KX_TouchSensor.cpp | 3 +- source/gameengine/Ketsji/KX_VertexProxy.cpp | 2 +- source/gameengine/VideoTexture/FilterNormal.cpp | 21 +- source/gameengine/VideoTexture/blendVideoTex.cpp | 10 +- 30 files changed, 285 insertions(+), 233 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index f413ad969f4..7515f3f5f91 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -1037,7 +1037,7 @@ int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF if (!PyString_Check(value)) { - PyErr_SetString(PyExc_ValueError, "expected the string name of the action"); + PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, expected the string name of the action"); return -1; } @@ -1049,7 +1049,7 @@ int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); if (!action) { - PyErr_SetString(PyExc_ValueError, "action not found!"); + PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, action not found!"); return 1; } } diff --git a/source/gameengine/Converter/BL_ActionActuator.h b/source/gameengine/Converter/BL_ActionActuator.h index d5b5762d9e7..6ae7f716b4b 100644 --- a/source/gameengine/Converter/BL_ActionActuator.h +++ b/source/gameengine/Converter/BL_ActionActuator.h @@ -154,7 +154,7 @@ public: case ACT_ACTION_FROM_PROP: return 0; default: - PyErr_SetString(PyExc_ValueError, "invalid type supplied"); + PyErr_SetString(PyExc_ValueError, "Action Actuator, invalid play type supplied"); return 1; } } diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index 25a4413a31d..62bc99bb437 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -869,7 +869,7 @@ int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE /* exact copy of BL_ActionActuator's function from here down */ if (!PyString_Check(value)) { - PyErr_SetString(PyExc_ValueError, "expected the string name of the action"); + PyErr_SetString(PyExc_ValueError, "actuator.action = val: Shape Action Actuator, expected the string name of the action"); return -1; } @@ -881,7 +881,7 @@ int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val); if (action==NULL) { - PyErr_SetString(PyExc_ValueError, "action not found!"); + PyErr_SetString(PyExc_ValueError, "actuator.action = val: Shape Action Actuator, action not found!"); return 1; } } diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.h b/source/gameengine/Converter/BL_ShapeActionActuator.h index 716d8c9995b..3bc35ac9495 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.h +++ b/source/gameengine/Converter/BL_ShapeActionActuator.h @@ -144,7 +144,7 @@ public: case ACT_ACTION_FROM_PROP: return 0; default: - PyErr_SetString(PyExc_ValueError, "invalid type supplied"); + PyErr_SetString(PyExc_ValueError, "Shape Action Actuator, invalid play type supplied"); return 1; } diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 5c7e6a4383e..dd9b296dce1 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -58,7 +58,7 @@ PyObject* listvalue_buffer_item(PyObject* self, Py_ssize_t index) return list->GetValue(index)->GetProxy(); } - PyErr_SetString(PyExc_IndexError, "Python ListIndex out of range"); + PyErr_SetString(PyExc_IndexError, "list[i]: Python ListIndex out of range in CValueList"); return NULL; } @@ -85,7 +85,7 @@ PyObject* listvalue_mapping_subscript(PyObject* self, PyObject* pyindex) } PyObject *pyindex_str = PyObject_Repr(pyindex); /* new ref */ - PyErr_Format(PyExc_KeyError, "'%s' not in list", PyString_AsString(pyindex_str)); + PyErr_Format(PyExc_KeyError, "list[key]: '%s' key not in list", PyString_AsString(pyindex_str)); Py_DECREF(pyindex_str); return NULL; } @@ -162,7 +162,7 @@ listvalue_buffer_concat(PyObject * self, PyObject * other) } if (error) { - PyErr_SetString(PyExc_SystemError, "Python Error: couldn't add one or more items to a list"); + PyErr_SetString(PyExc_SystemError, "list.append(val): couldn't add one or more items to this CValueList"); return NULL; } @@ -187,7 +187,7 @@ listvalue_buffer_concat(PyObject * self, PyObject * other) listval->Add(objval); } else { - PyErr_SetString(PyExc_SystemError, "Python Error: couldn't add item to a list"); + PyErr_SetString(PyExc_SystemError, "list.append(i): couldn't add item to this CValueList"); return NULL; } } @@ -495,7 +495,7 @@ PyObject* CListValue::Pyindex(PyObject *value) checkobj->Release(); if (result==NULL) { - PyErr_SetString(PyExc_ValueError, "ValueError: list.index(x): x not in CListValue"); + PyErr_SetString(PyExc_ValueError, "list.index(x): x not in CListValue"); } return result; @@ -543,7 +543,7 @@ PyObject* CListValue::Pyfrom_id(PyObject* value) if (reinterpret_cast(m_pValueArray[i]->m_proxy) == id) return GetValue(i)->GetProxy(); } - PyErr_SetString(PyExc_IndexError, "from_id(#), id not found in CValueList"); + PyErr_SetString(PyExc_IndexError, "from_id(#): id not found in CValueList"); return NULL; } diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp index da761bd22cb..6cfa14ddc80 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/PyObjectPlus.cpp @@ -325,12 +325,12 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb { if (!PySequence_Check(value)) { - PyErr_SetString(PyExc_TypeError, "expected a sequence"); + PyErr_Format(PyExc_TypeError, "expected a sequence for attribute \"%s\"", attrdef->m_name); return 1; } if (PySequence_Size(value) != attrdef->m_length) { - PyErr_SetString(PyExc_TypeError, "incorrect number of elements in sequence"); + PyErr_Format(PyExc_TypeError, "incorrect number of elements in sequence for attribute \"%s\"", attrdef->m_name); return 1; } switch (attrdef->m_type) @@ -338,7 +338,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb case KX_PYATTRIBUTE_TYPE_FUNCTION: if (attrdef->m_setFunction == NULL) { - PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org"); + PyErr_Format(PyExc_AttributeError, "function attribute without function for attribute \"%s\", report to blender.org", attrdef->m_name); return 1; } return (*attrdef->m_setFunction)(self, attrdef, value); @@ -357,7 +357,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb break; default: // should not happen - PyErr_SetString(PyExc_AttributeError, "Unsupported attribute type, report to blender.org"); + PyErr_Format(PyExc_AttributeError, "Unsupported attribute type for attribute \"%s\", report to blender.org", attrdef->m_name); return 1; } // let's implement a smart undo method @@ -390,7 +390,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb } else { - PyErr_SetString(PyExc_TypeError, "expected an integer or a bool"); + PyErr_Format(PyExc_TypeError, "expected an integer or a bool for attribute \"%s\"", attrdef->m_name); goto UNDO_AND_ERROR; } break; @@ -411,14 +411,14 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb } else if (val < attrdef->m_imin || val > attrdef->m_imax) { - PyErr_SetString(PyExc_ValueError, "item value out of range"); + PyErr_Format(PyExc_ValueError, "item value out of range for attribute \"%s\"", attrdef->m_name); goto UNDO_AND_ERROR; } *var = (short int)val; } else { - PyErr_SetString(PyExc_TypeError, "expected an integer"); + PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name); goto UNDO_AND_ERROR; } break; @@ -427,7 +427,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb // 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"); + PyErr_Format(PyExc_AttributeError, "Size check error for attribute, \"%s\", report to blender.org", attrdef->m_name); goto UNDO_AND_ERROR; } // walkthrough @@ -447,14 +447,14 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb } else if (val < attrdef->m_imin || val > attrdef->m_imax) { - PyErr_SetString(PyExc_ValueError, "item value out of range"); + PyErr_Format(PyExc_ValueError, "item value out of range for attribute \"%s\"", attrdef->m_name); goto UNDO_AND_ERROR; } *var = (int)val; } else { - PyErr_SetString(PyExc_TypeError, "expected an integer"); + PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name); goto UNDO_AND_ERROR; } break; @@ -466,7 +466,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb double val = PyFloat_AsDouble(item); if (val == -1.0 && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "expected a float"); + PyErr_Format(PyExc_TypeError, "expected a float for attribute \"%s\"", attrdef->m_name); goto UNDO_AND_ERROR; } else if (attrdef->m_clamp) @@ -478,7 +478,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb } else if (val < attrdef->m_fmin || val > attrdef->m_fmax) { - PyErr_SetString(PyExc_ValueError, "item value out of range"); + PyErr_Format(PyExc_ValueError, "item value out of range for attribute \"%s\"", attrdef->m_name); goto UNDO_AND_ERROR; } *var = (float)val; @@ -486,7 +486,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb } default: // should not happen - PyErr_SetString(PyExc_AttributeError, "attribute type check error, report to blender.org"); + PyErr_Format(PyExc_AttributeError, "type check error for attribute \"%s\", report to blender.org", attrdef->m_name); goto UNDO_AND_ERROR; } } @@ -515,7 +515,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb { if (attrdef->m_setFunction == NULL) { - PyErr_SetString(PyExc_AttributeError, "function attribute without function, report to blender.org"); + PyErr_Format(PyExc_AttributeError, "function attribute without function \"%s\", report to blender.org", attrdef->m_name); return 1; } return (*attrdef->m_setFunction)(self, attrdef, value); @@ -545,7 +545,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb bufferSize = strlen(reinterpret_cast(sourceBuffer))+1; break; default: - PyErr_SetString(PyExc_AttributeError, "unknown attribute type, report to blender.org"); + PyErr_Format(PyExc_AttributeError, "unknown type for attribute \"%s\", report to blender.org", attrdef->m_name); return 1; } if (bufferSize) @@ -573,7 +573,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb } else { - PyErr_SetString(PyExc_TypeError, "expected an integer or a bool"); + PyErr_Format(PyExc_TypeError, "expected an integer or a bool for attribute \"%s\"", attrdef->m_name); goto FREE_AND_ERROR; } break; @@ -593,14 +593,14 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb } else if (val < attrdef->m_imin || val > attrdef->m_imax) { - PyErr_SetString(PyExc_ValueError, "value out of range"); + PyErr_Format(PyExc_ValueError, "value out of range for attribute \"%s\"", attrdef->m_name); goto FREE_AND_ERROR; } *var = (short int)val; } else { - PyErr_SetString(PyExc_TypeError, "expected an integer"); + PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name); goto FREE_AND_ERROR; } break; @@ -609,7 +609,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb // 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"); + PyErr_Format(PyExc_AttributeError, "attribute size check error for attribute \"%s\", report to blender.org", attrdef->m_name); goto FREE_AND_ERROR; } // walkthrough @@ -628,14 +628,14 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb } else if (val < attrdef->m_imin || val > attrdef->m_imax) { - PyErr_SetString(PyExc_ValueError, "value out of range"); + PyErr_Format(PyExc_ValueError, "value out of range for attribute \"%s\"", attrdef->m_name); goto FREE_AND_ERROR; } *var = (int)val; } else { - PyErr_SetString(PyExc_TypeError, "expected an integer"); + PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name); goto FREE_AND_ERROR; } break; @@ -646,7 +646,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb double val = PyFloat_AsDouble(value); if (val == -1.0 && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "expected a float"); + PyErr_Format(PyExc_TypeError, "expected a float for attribute \"%s\"", attrdef->m_name); goto FREE_AND_ERROR; } else if (attrdef->m_clamp) @@ -658,7 +658,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb } else if (val < attrdef->m_fmin || val > attrdef->m_fmax) { - PyErr_SetString(PyExc_ValueError, "value out of range"); + PyErr_Format(PyExc_ValueError, "value out of range for attribute \"%s\"", attrdef->m_name); goto FREE_AND_ERROR; } *var = (float)val; @@ -675,7 +675,7 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb if (strlen(val) < attrdef->m_imin) { // can't increase the length of the string - PyErr_SetString(PyExc_ValueError, "string length too short"); + PyErr_Format(PyExc_ValueError, "string length too short for attribute \"%s\"", attrdef->m_name); goto FREE_AND_ERROR; } else if (strlen(val) > attrdef->m_imax) @@ -689,21 +689,21 @@ int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyOb } } else if (strlen(val) < attrdef->m_imin || strlen(val) > attrdef->m_imax) { - PyErr_SetString(PyExc_ValueError, "string length out of range"); + PyErr_Format(PyExc_ValueError, "string length out of range for attribute \"%s\"", attrdef->m_name); goto FREE_AND_ERROR; } *var = val; } else { - PyErr_SetString(PyExc_TypeError, "expected a string"); + PyErr_Format(PyExc_TypeError, "expected a string for attribute \"%s\"", attrdef->m_name); goto FREE_AND_ERROR; } break; } default: // should not happen - PyErr_SetString(PyExc_AttributeError, "unknown attribute type, report to blender.org"); + PyErr_Format(PyExc_AttributeError, "unknown type for attribute \"%s\", report to blender.org", attrdef->m_name); goto FREE_AND_ERROR; } } @@ -787,7 +787,7 @@ PyObject *PyObjectPlus::PyisA(PyObject *value) // Python wrapper for isA } else if (PyString_Check(value)) { return PyBool_FromLong(isA(PyString_AsString(value))); } - PyErr_SetString(PyExc_TypeError, "expected a type or a string"); + PyErr_SetString(PyExc_TypeError, "object.isA(value): expected a type or a string"); return NULL; } diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index ca46d782992..7cb97909119 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -671,7 +671,7 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj) } else { /* return an error value from the caller */ - PyErr_SetString(PyExc_TypeError, "This python value could not be assigned to a game engine property"); + PyErr_SetString(PyExc_TypeError, "This python type could not be converted to a to a game engine property"); } return vallie; diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 28ff1c82924..1c601eded81 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -601,7 +601,7 @@ PyObject* SCA_JoystickSensor::pyattr_get_axis_single(void *self_v, const KX_PYAT SCA_Joystick *joy = self->m_pJoystickMgr->GetJoystickDevice(self->m_joyindex); if(self->m_joymode != KX_JOYSENSORMODE_AXIS_SINGLE) { - PyErr_SetString(PyExc_TypeError, "joystick sensor is not an 'Single Axis' type"); + PyErr_SetString(PyExc_TypeError, "val = sensor.axisSingle: Joystick Sensor, not 'Single Axis' type"); return NULL; } diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index d56e5fe29dc..c946156283f 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -590,7 +590,7 @@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus, "\tGet the given key's status (KX_NO_INPUTSTATUS, KX_JUSTACTIVATED, KX_ACTIVE or KX_JUSTRELEASED).\n") { if (!PyInt_Check(value)) { - PyErr_SetString(PyExc_ValueError, "getKeyStatus expected an int"); + PyErr_SetString(PyExc_ValueError, "sensor.getKeyStatus(int): Keyboard Sensor, expected an int"); return NULL; } @@ -598,7 +598,7 @@ KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus, if ((keycode < SCA_IInputDevice::KX_BEGINKEY) || (keycode > SCA_IInputDevice::KX_ENDKEY)){ - PyErr_SetString(PyExc_AttributeError, "invalid keycode specified!"); + PyErr_SetString(PyExc_AttributeError, "sensor.getKeyStatus(int): Keyboard Sensor, invalid keycode specified!"); return NULL; } diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp index 8f41e799b01..4dbeb156e63 100644 --- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp +++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp @@ -279,7 +279,7 @@ KX_PYMETHODDEF_DOC_O(SCA_MouseSensor, getButtonStatus, if ((button < SCA_IInputDevice::KX_LEFTMOUSE) || (button > SCA_IInputDevice::KX_RIGHTMOUSE)){ - PyErr_SetString(PyExc_ValueError, "invalid button specified!"); + PyErr_SetString(PyExc_ValueError, "sensor.getButtonStatus(int): Mouse Sensor, invalid button specified!"); return NULL; } diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 121f868a281..b8052555528 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -187,7 +187,7 @@ SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value) /* 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)); + PyErr_Format(PyExc_ValueError, "'%s' not in this python controllers actuator list", PyString_AsString(value_str)); Py_DECREF(value_str); return false; @@ -417,14 +417,14 @@ PyObject* SCA_PythonController::PyGetActuators() } const char SCA_PythonController::GetSensor_doc[] = -"GetSensor (char sensorname) return linked sensor that is named [sensorname]\n"; +"getSensor (char sensorname) return linked sensor that is named [sensorname]\n"; PyObject* SCA_PythonController::PyGetSensor(PyObject* value) { char *scriptArg = PyString_AsString(value); if (scriptArg==NULL) { - PyErr_SetString(PyExc_TypeError, "expected a string (sensor name)"); + PyErr_SetString(PyExc_TypeError, "controller.getSensor(string): Python Controller, expected a string (sensor name)"); return NULL; } @@ -438,21 +438,21 @@ SCA_PythonController::PyGetSensor(PyObject* value) } } - PyErr_Format(PyExc_AttributeError, "Unable to find requested sensor \"%s\"", scriptArg); + PyErr_Format(PyExc_AttributeError, "controller.getSensor(string): Python Controller, unable to find requested sensor \"%s\"", scriptArg); return NULL; } const char SCA_PythonController::GetActuator_doc[] = -"GetActuator (char sensorname) return linked actuator that is named [actuatorname]\n"; +"getActuator (char sensorname) return linked actuator that is named [actuatorname]\n"; PyObject* SCA_PythonController::PyGetActuator(PyObject* value) { char *scriptArg = PyString_AsString(value); if (scriptArg==NULL) { - PyErr_SetString(PyExc_TypeError, "expected a string (actuator name)"); + PyErr_SetString(PyExc_TypeError, "controller.getActuator(string): Python Controller, expected a string (actuator name)"); return NULL; } @@ -465,7 +465,7 @@ SCA_PythonController::PyGetActuator(PyObject* value) } } - PyErr_Format(PyExc_AttributeError, "Unable to find requested actuator \"%s\"", scriptArg); + PyErr_Format(PyExc_AttributeError, "controller.getActuator(string): Python Controller, unable to find requested actuator \"%s\"", scriptArg); return NULL; } @@ -536,7 +536,7 @@ int SCA_PythonController::pyattr_set_script(void *self_v, const KX_PYATTRIBUTE_D char *scriptArg = PyString_AsString(value); if (scriptArg==NULL) { - PyErr_SetString(PyExc_TypeError, "expected a string (script name)"); + PyErr_SetString(PyExc_TypeError, "controller.script = string: Python Controller, expected a string script text"); return -1; } diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp index 6fb10faaf8c..3a72d9b7652 100644 --- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp +++ b/source/gameengine/GameLogic/SCA_RandomActuator.cpp @@ -386,7 +386,7 @@ int SCA_RandomActuator::pyattr_set_seed(void *self, const struct KX_PYATTRIBUTE_ act->m_base->SetSeed(ival); return 0; } else { - PyErr_SetString(PyExc_TypeError, "expected an integer"); + PyErr_SetString(PyExc_TypeError, "actuator.seed = int: Random Actuator, expected an integer"); return 1; } } diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp index e04d2a8ab90..5ead82db428 100644 --- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp +++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp @@ -224,7 +224,7 @@ int SCA_RandomSensor::pyattr_set_seed(void *self_v, const KX_PYATTRIBUTE_DEF *at { SCA_RandomSensor* self= static_cast(self_v); if (!PyInt_Check(value)) { - PyErr_SetString(PyExc_TypeError, "expected an integer"); + PyErr_SetString(PyExc_TypeError, "sensor.seed = int: Random Sensor, expected an integer"); return -1; } self->m_basegenerator->SetSeed(PyInt_AsLong(value)); diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index 01b6805ae7a..88d920043e0 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -858,7 +858,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, validate, "validate()") Py_RETURN_NONE; } if(mShader==0) { - PyErr_Format(PyExc_TypeError, "invalid shader object"); + PyErr_SetString(PyExc_TypeError, "shader.validate(): BL_Shader, invalid shader object"); return NULL; } int stat = 0; @@ -1175,7 +1175,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformfv , "setUniformfv( float (list2 or lis }break; default: { - PyErr_Format(PyExc_TypeError, "Invalid list size"); + PyErr_SetString(PyExc_TypeError, "shader.setUniform4i(name, ix,iy,iz, iw): BL_Shader. invalid list size"); return NULL; }break; } @@ -1185,7 +1185,7 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformfv , "setUniformfv( float (list2 or lis return NULL; } -KX_PYMETHODDEF_DOC( BL_Shader, setUniformiv, "setUniformiv( int (list2 or list3 or list4) )") +KX_PYMETHODDEF_DOC( BL_Shader, setUniformiv, "setUniformiv( uniform_name, (list2 or list3 or list4) )") { if(mError) { Py_RETURN_NONE; @@ -1194,70 +1194,84 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformiv, "setUniformiv( int (list2 or list3 PyObject *listPtr =0; int array_data[4] = {0,0,0,0}; - if(PyArg_ParseTuple(args, "sO:setUniformiv", &uniform, &listPtr)) + if(!PyArg_ParseTuple(args, "sO:setUniformiv", &uniform, &listPtr)) + return NULL; + + int loc = GetUniformLocation(uniform); + + if(loc == -1) { + PyErr_SetString(PyExc_TypeError, "shader.setUniformiv(...): BL_Shader, first string argument is not a valid uniform value"); + return NULL; + } + + if(!PySequence_Check(listPtr)) { + PyErr_SetString(PyExc_TypeError, "shader.setUniformiv(...): BL_Shader, second argument is not a sequence"); + return NULL; + } + + unsigned int list_size = PySequence_Size(listPtr); + + for(unsigned int i=0; (i(self_v); int param = PyObject_IsTrue( value ); if (param == -1) { - PyErr_SetString(PyExc_AttributeError, "expected True or False"); + PyErr_SetString(PyExc_AttributeError, "camera.perspective = bool: KX_Camera, expected True/False or 0/1"); return -1; } @@ -808,7 +808,7 @@ int KX_Camera::pyattr_set_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, KX_Camera* self= static_cast(self_v); float param = PyFloat_AsDouble(value); if (param == -1) { - PyErr_SetString(PyExc_AttributeError, "expected a float greater then zero"); + PyErr_SetString(PyExc_AttributeError, "camera.lens = float: KX_Camera, expected a float greater then zero"); return -1; } @@ -828,7 +828,7 @@ int KX_Camera::pyattr_set_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, KX_Camera* self= static_cast(self_v); float param = PyFloat_AsDouble(value); if (param == -1) { - PyErr_SetString(PyExc_AttributeError, "expected a float greater then zero"); + PyErr_SetString(PyExc_AttributeError, "camera.near = float: KX_Camera, expected a float greater then zero"); return -1; } @@ -848,7 +848,7 @@ int KX_Camera::pyattr_set_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, P KX_Camera* self= static_cast(self_v); float param = PyFloat_AsDouble(value); if (param == -1) { - PyErr_SetString(PyExc_AttributeError, "expected a float greater then zero"); + PyErr_SetString(PyExc_AttributeError, "camera.far = float: KX_Camera, expected a float greater then zero"); return -1; } diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index 462abd3a584..1ce7fac0cfe 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -652,7 +652,7 @@ int KX_ConstraintActuator::pyattr_check_direction(void *self, const struct KX_PY MT_Vector3 dir(act->m_refDirection); MT_Scalar len = dir.length(); if (MT_fuzzyZero(len)) { - PyErr_SetString(PyExc_ValueError, "Invalid direction"); + PyErr_SetString(PyExc_ValueError, "actuator.direction = vec: KX_ConstraintActuator, invalid direction"); return 1; } act->m_refDirVector = dir/len; diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 9fe7ab75267..af1dc7f67b2 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1187,13 +1187,13 @@ PyObject* KX_GameObject::PyReplaceMesh(PyObject* value) meshname = PyString_AsString(value); if (meshname==NULL) { - PyErr_SetString(PyExc_ValueError, "Expected a mesh name"); + PyErr_SetString(PyExc_ValueError, "gameOb.replaceMesh(value): KX_GameObject, expected a mesh name"); return NULL; } mesh_pt = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(meshname)); if (mesh_pt==NULL) { - PyErr_SetString(PyExc_ValueError, "The mesh name given does not exist"); + PyErr_SetString(PyExc_ValueError, "gameOb.replaceMesh(value): KX_GameObject, the mesh name given does not exist"); return NULL; } scene->ReplaceMesh(this, (class RAS_MeshObject*)mesh_pt); @@ -1259,8 +1259,8 @@ PyObject *KX_GameObject::Map_GetItem(PyObject *self_v, PyObject *item) return pyconvert; } else { - if(attr_str) PyErr_Format(PyExc_KeyError, "KX_GameObject key \"%s\" does not exist", attr_str); - else PyErr_SetString(PyExc_KeyError, "KX_GameObject key does not exist"); + if(attr_str) PyErr_Format(PyExc_KeyError, "value = gameOb[key]: KX_GameObject, key \"%s\" does not exist", attr_str); + else PyErr_SetString(PyExc_KeyError, "value = gameOb[key]: KX_GameObject, key does not exist"); return NULL; } @@ -1290,8 +1290,8 @@ int KX_GameObject::Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val) del |= (PyDict_DelItem(self->m_attr_dict, key)==0) ? 1:0; if (del==0) { - if(attr_str) PyErr_Format(PyExc_KeyError, "KX_GameObject key \"%s\" not found", attr_str); - else PyErr_SetString(PyExc_KeyError, "KX_GameObject key not found"); + if(attr_str) PyErr_Format(PyExc_KeyError, "gameOb[key] = value: KX_GameObject, key \"%s\" could not be set", attr_str); + else PyErr_SetString(PyExc_KeyError, "gameOb[key] = value: KX_GameObject, key could not be set"); return -1; } else if (self->m_attr_dict) { @@ -1342,8 +1342,8 @@ int KX_GameObject::Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val) set= 1; } else { - if(attr_str) PyErr_Format(PyExc_KeyError, "KX_GameObject key \"%s\" not be added to internal dictionary", attr_str); - else PyErr_SetString(PyExc_KeyError, "KX_GameObject key not be added to internal dictionary"); + if(attr_str) PyErr_Format(PyExc_KeyError, "gameOb[key] = value: KX_GameObject, key \"%s\" not be added to internal dictionary", attr_str); + else PyErr_SetString(PyExc_KeyError, "gameOb[key] = value: KX_GameObject, key not be added to internal dictionary"); } } @@ -1424,7 +1424,7 @@ int KX_GameObject::pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrd KX_IPhysicsController *spc = self->GetPhysicsController(); MT_Scalar val = PyFloat_AsDouble(value); if (val < 0.0f) { /* also accounts for non float */ - PyErr_SetString(PyExc_AttributeError, "expected a float zero or above"); + PyErr_SetString(PyExc_AttributeError, "gameOb.mass = float: KX_GameObject, expected a float zero or above"); return 1; } @@ -1447,7 +1447,7 @@ int KX_GameObject::pyattr_set_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF KX_IPhysicsController *spc = self->GetPhysicsController(); MT_Scalar val = PyFloat_AsDouble(value); if (val < 0.0f) { /* also accounts for non float */ - PyErr_SetString(PyExc_AttributeError, "expected a float zero or above"); + PyErr_SetString(PyExc_AttributeError, "gameOb.linVelocityMin = float: KX_GameObject, expected a float zero or above"); return 1; } @@ -1470,7 +1470,7 @@ int KX_GameObject::pyattr_set_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF KX_IPhysicsController *spc = self->GetPhysicsController(); MT_Scalar val = PyFloat_AsDouble(value); if (val < 0.0f) { /* also accounts for non float */ - PyErr_SetString(PyExc_AttributeError, "expected a float zero or above"); + PyErr_SetString(PyExc_AttributeError, "gameOb.linVelocityMax = float: KX_GameObject, expected a float zero or above"); return 1; } @@ -1492,7 +1492,7 @@ int KX_GameObject::pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *at KX_GameObject* self= static_cast(self_v); int param = PyObject_IsTrue( value ); if (param == -1) { - PyErr_SetString(PyExc_AttributeError, "expected True or False"); + PyErr_SetString(PyExc_AttributeError, "gameOb.visible = bool: KX_GameObject, expected True or False"); return 1; } @@ -1569,7 +1569,7 @@ int KX_GameObject::pyattr_set_localOrientation(void *self_v, const KX_PYATTRIBUT { KX_GameObject* self= static_cast(self_v); if (!PySequence_Check(value)) { - PyErr_SetString(PyExc_AttributeError, "'orientation' attribute needs to be a sequence"); + PyErr_SetString(PyExc_AttributeError, "gameOb.orientation = [...]: KX_GameObject, expected a sequence"); return 1; } @@ -1609,7 +1609,7 @@ int KX_GameObject::pyattr_set_localOrientation(void *self_v, const KX_PYATTRIBUT return 1; } - PyErr_SetString(PyExc_AttributeError, "could not set the orientation from a 3x3 matrix, quaternion or euler sequence"); + PyErr_SetString(PyExc_AttributeError, "gameOb.orientation = [...]: KX_GameObject, could not set the orientation from a 3x3 matrix, quaternion or euler sequence"); return 1; } @@ -1658,7 +1658,7 @@ int KX_GameObject::pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF MT_Scalar val = PyFloat_AsDouble(value); SG_Node* sg_parent= self->GetSGNode()->GetSGParent(); if (val < 0.0f) { /* also accounts for non float */ - PyErr_SetString(PyExc_AttributeError, "expected a float zero or above"); + PyErr_SetString(PyExc_AttributeError, "gameOb.timeOffset = float: KX_GameObject, expected a float zero or above"); return 1; } if (sg_parent && sg_parent->IsSlowParent()) @@ -1682,13 +1682,13 @@ int KX_GameObject::pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attr unsigned int state = 0; if (state_i == -1 && PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, "expected an int bit field"); + PyErr_SetString(PyExc_TypeError, "gameOb.state = int: KX_GameObject, expected an int bit field"); return 1; } state |= state_i; if ((state & ((1<<30)-1)) == 0) { - PyErr_SetString(PyExc_AttributeError, "The state bitfield was not between 0 and 30 (1<<0 and 1<<29)"); + PyErr_SetString(PyExc_AttributeError, "gameOb.state = int: KX_GameObject, state bitfield was not between 0 and 30 (1<<0 and 1<<29)"); return 1; } self->SetState(state); @@ -1701,7 +1701,7 @@ PyObject* KX_GameObject::pyattr_get_meshes(void *self_v, const KX_PYATTRIBUTE_DE PyObject *meshes= PyList_New(self->m_meshes.size()); int i; - for(i=0; i < (int)self->m_meshes.size(); i++) + for(i=0; i < self->m_meshes.size(); i++) { KX_MeshProxy* meshproxy = new KX_MeshProxy(self->m_meshes[i]); PyList_SET_ITEM(meshes, i, meshproxy->GetProxy()); @@ -1847,7 +1847,7 @@ int KX_GameObject::py_setattro(PyObject *attr, PyObject *value) // py_setattro m ret= PY_SET_ATTR_SUCCESS; } else { - PyErr_Format(PyExc_AttributeError, "failed assigning value to KX_GameObject internal dictionary"); + PyErr_Format(PyExc_AttributeError, "gameOb.myAttr = value: KX_GameObject, failed assigning value to internal dictionary"); ret= PY_SET_ATTR_FAIL; } } @@ -1866,7 +1866,7 @@ int KX_GameObject::py_delattro(PyObject *attr) if (m_attr_dict && (PyDict_DelItem(m_attr_dict, attr) == 0)) return 0; - PyErr_Format(PyExc_AttributeError, "attribute \"%s\" dosnt exist", attr_str); + PyErr_Format(PyExc_AttributeError, "del gameOb.myAttr: KX_GameObject, attribute \"%s\" dosnt exist", attr_str); return 1; } @@ -2390,7 +2390,7 @@ KX_PYMETHODDEF_DOC_O(KX_GameObject, getVectTo, toPoint = other->NodeGetWorldPosition(); } else { - PyErr_SetString(PyExc_TypeError, "Expected a 3D Vector or GameObject type"); + PyErr_SetString(PyExc_TypeError, "gameOb.getVectTo(other): KX_GameObject, expected a 3D Vector or KX_GameObject type"); return NULL; } } @@ -2484,7 +2484,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo, toPoint = other->NodeGetWorldPosition(); } else { - PyErr_SetString(PyExc_TypeError, "the first argument to rayCastTo must be a vector or a KX_GameObject"); + PyErr_SetString(PyExc_TypeError, "gameOb.rayCastTo(other,dist,prop): KX_GameObject, the first argument to rayCastTo must be a vector or a KX_GameObject"); return NULL; } } @@ -2577,7 +2577,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, fromPoint = other->NodeGetWorldPosition(); } else { - PyErr_SetString(PyExc_TypeError, "the second optional argument to rayCast must be a vector or a KX_GameObject"); + PyErr_SetString(PyExc_TypeError, "gameOb.rayCast(to,from,dist,prop,face,xray,poly): KX_GameObject, the second optional argument to rayCast must be a vector or a KX_GameObject"); return NULL; } } diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index ded862fb21d..e2c59ab4242 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -243,7 +243,7 @@ PyObject* KX_MeshProxy::PyGetPolygon(PyObject* args, PyObject* kwds) if (polyindex<0 || polyindex >= m_meshobj->NumPolygons()) { - PyErr_SetString(PyExc_AttributeError, "Invalid polygon index"); + PyErr_SetString(PyExc_AttributeError, "mesh.getPolygon(int): KX_MeshProxy, invalid polygon index"); return NULL; } @@ -254,7 +254,7 @@ PyObject* KX_MeshProxy::PyGetPolygon(PyObject* args, PyObject* kwds) polyob = (new KX_PolyProxy(m_meshobj, polygon))->NewProxy(true); } else { - PyErr_SetString(PyExc_AttributeError, "polygon is NULL, unknown reason"); + PyErr_SetString(PyExc_AttributeError, "mesh.getPolygon(int): KX_MeshProxy, polygon is NULL, unknown reason"); } return polyob; } diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp index 5888579431a..2e5dd72db0e 100644 --- a/source/gameengine/Ketsji/KX_PolyProxy.cpp +++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp @@ -242,7 +242,7 @@ KX_PYMETHODDEF_DOC(KX_PolyProxy, getVertexIndex, } if (index < 0 || index > 3) { - PyErr_SetString(PyExc_AttributeError, "Valid range for index is 0-3"); + PyErr_SetString(PyExc_AttributeError, "poly.getVertexIndex(int): KX_PolyProxy, expected an index between 0-3"); return NULL; } if (index < m_polygon->VertexCount()) diff --git a/source/gameengine/Ketsji/KX_PyMath.h b/source/gameengine/Ketsji/KX_PyMath.h index 39c9c358792..4a64063aaa1 100644 --- a/source/gameengine/Ketsji/KX_PyMath.h +++ b/source/gameengine/Ketsji/KX_PyMath.h @@ -92,18 +92,35 @@ bool PyMatTo(PyObject* pymat, T& mat) } /** - * Converts a python list to a MT class. + * Converts a python sequence to a MT class. */ template bool PyVecTo(PyObject* pyval, T& vec) { - if (PySequence_Check(pyval)) + + if(PyTuple_Check(pyval)) + { + unsigned int numitems = PyTuple_GET_SIZE(pyval); + if (numitems != Size(vec)) { + PyErr_Format(PyExc_AttributeError, "error setting vector, %d args, should be %d", numitems, Size(vec)); + return false; + } + + for (unsigned int x = 0; x < numitems; x++) + vec[x] = PyFloat_AsDouble(PyTuple_GET_ITEM(pyval, x)); /* borrow ref */ + + if (PyErr_Occurred()) { + PyErr_SetString(PyExc_AttributeError, "one or more of the items in the sequence was not a float"); + return false; + } + + return true; + } + else if (PySequence_Check(pyval)) { unsigned int numitems = PySequence_Size(pyval); if (numitems != Size(vec)) { - char err[128]; - sprintf(err, "error setting vector, %d args, should be %d", numitems, Size(vec)); - PyErr_SetString(PyExc_AttributeError, err); + PyErr_Format(PyExc_AttributeError, "error setting vector, %d args, should be %d", numitems, Size(vec)); return false; } @@ -122,9 +139,7 @@ bool PyVecTo(PyObject* pyval, T& vec) return true; } else { - char err[128]; - sprintf(err, "not a sequence type, expected a sequence of numbers size %d", Size(vec)); - PyErr_SetString(PyExc_AttributeError, err); + PyErr_Format(PyExc_AttributeError, "not a sequence type, expected a sequence of numbers size %d", Size(vec)); } return false; diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 2227072d2e7..097d20fe0e5 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -553,7 +553,7 @@ static PyObject* gPySetEyeSeparation(PyObject*, PyObject* args) return NULL; if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer not available"); + PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setEyeSeparation(float), Rasterizer not available"); return NULL; } @@ -565,7 +565,7 @@ static PyObject* gPySetEyeSeparation(PyObject*, PyObject* args) static PyObject* gPyGetEyeSeparation(PyObject*) { if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer not available"); + PyErr_SetString(PyExc_RuntimeError, "Rasterizer.getEyeSeparation(), Rasterizer not available"); return NULL; } @@ -579,7 +579,7 @@ static PyObject* gPySetFocalLength(PyObject*, PyObject* args) return NULL; if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer not available"); + PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setFocalLength(float), Rasterizer not available"); return NULL; } @@ -591,7 +591,7 @@ static PyObject* gPySetFocalLength(PyObject*, PyObject* args) static PyObject* gPyGetFocalLength(PyObject*, PyObject*, PyObject*) { if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer not available"); + PyErr_SetString(PyExc_RuntimeError, "Rasterizer.getFocalLength(), Rasterizer not available"); return NULL; } @@ -624,7 +624,7 @@ static PyObject* gPySetMistColor(PyObject*, PyObject* value) return NULL; if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer not available"); + PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setMistColor(color), Rasterizer not available"); return NULL; } gp_Rasterizer->SetFogColor(vec[0], vec[1], vec[2]); @@ -642,7 +642,7 @@ static PyObject* gPySetMistStart(PyObject*, PyObject* args) return NULL; if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer not available"); + PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setMistStart(float), Rasterizer not available"); return NULL; } @@ -661,7 +661,7 @@ static PyObject* gPySetMistEnd(PyObject*, PyObject* args) return NULL; if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer not available"); + PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setMistEnd(float), Rasterizer not available"); return NULL; } @@ -679,7 +679,7 @@ static PyObject* gPySetAmbientColor(PyObject*, PyObject* value) return NULL; if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer not available"); + PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setAmbientColor(color), Rasterizer not available"); return NULL; } gp_Rasterizer->SetAmbientColor(vec[0], vec[1], vec[2]); @@ -711,7 +711,7 @@ static PyObject* gPyEnableMotionBlur(PyObject*, PyObject* args) return NULL; if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer not available"); + PyErr_SetString(PyExc_RuntimeError, "Rasterizer.enableMotionBlur(float), Rasterizer not available"); return NULL; } @@ -723,7 +723,7 @@ static PyObject* gPyEnableMotionBlur(PyObject*, PyObject* args) static PyObject* gPyDisableMotionBlur(PyObject*, PyObject* args) { if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer not available"); + PyErr_SetString(PyExc_RuntimeError, "Rasterizer.disableMotionBlur(), Rasterizer not available"); return NULL; } @@ -763,7 +763,7 @@ static PyObject* gPySetGLSLMaterialSetting(PyObject*, flag = getGLSLSettingFlag(setting); if (flag==-1) { - PyErr_SetString(PyExc_ValueError, "glsl setting is not known"); + PyErr_SetString(PyExc_ValueError, "Rasterizer.setGLSLMaterialSetting(string): glsl setting is not known"); return NULL; } @@ -804,7 +804,7 @@ static PyObject* gPyGetGLSLMaterialSetting(PyObject*, flag = getGLSLSettingFlag(setting); if (flag==-1) { - PyErr_SetString(PyExc_ValueError, "glsl setting is not known"); + PyErr_SetString(PyExc_ValueError, "Rasterizer.getGLSLMaterialSetting(string): glsl setting is not known"); return NULL; } @@ -832,7 +832,7 @@ static PyObject* gPySetMaterialType(PyObject*, else if(type == KX_TEXFACE_MATERIAL) flag = 0; else { - PyErr_SetString(PyExc_ValueError, "material type is not known"); + PyErr_SetString(PyExc_ValueError, "Rasterizer.setMaterialType(int): material type is not known"); return NULL; } @@ -863,7 +863,7 @@ static PyObject* gPyDrawLine(PyObject*, PyObject* args) PyObject* ob_color; if (!gp_Rasterizer) { - PyErr_SetString(PyExc_RuntimeError, "Rasterizer not available"); + PyErr_SetString(PyExc_RuntimeError, "Rasterizer.drawLine(obFrom, obTo, color): Rasterizer not available"); return NULL; } @@ -1270,7 +1270,7 @@ PyObject *KXpy_reload(PyObject *self, PyObject *args) { return newmodule; if (found==0) /* if its found but could not import then it has its own error */ - PyErr_SetString(PyExc_ImportError, "failed to reload from blenders internal text"); + PyErr_SetString(PyExc_ImportError, "reload(module): failed to reload from blenders internal text"); return newmodule; } @@ -1517,7 +1517,7 @@ static PyObject* gPyEventToString(PyObject*, PyObject* value) PyErr_Clear(); // incase there was an error clearing Py_DECREF(mod); - if (!ret) PyErr_SetString(PyExc_ValueError, "expected a valid int keyboard event"); + if (!ret) PyErr_SetString(PyExc_ValueError, "GameKeys.EventToString(int): expected a valid int keyboard event"); else Py_INCREF(ret); return ret; diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index 44dedb38429..53067e94cd8 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -121,7 +121,7 @@ int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYAT } else if (PyString_Check(value)) { void* mesh = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(PyString_AsString(value))); if (mesh==NULL) { - PyErr_SetString(PyExc_ValueError, "The mesh name given does not exist"); + PyErr_SetString(PyExc_ValueError, "actuator.mesh = string: Replace Mesh Actuator, mesh name given does not exist"); return 1; } actuator->m_mesh= (class RAS_MeshObject*)mesh; @@ -129,7 +129,7 @@ int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYAT KX_MeshProxy* proxy = (KX_MeshProxy*)value; actuator->m_mesh= proxy->GetMesh(); } else { - PyErr_SetString(PyExc_ValueError, "Expected the name of a mesh, a mesh proxy or None"); + PyErr_SetString(PyExc_ValueError, "actuator.mesh = value: Replace Mesh Actuator, expected the mesh name, a KX_MeshProxy or None"); return 1; } return 0; diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 96f2f3e8ed3..0e1572da679 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1678,7 +1678,7 @@ PyObject* KX_Scene::py_getattro(PyObject *attr) Py_INCREF(object); } else { - PyErr_Format(PyExc_AttributeError, "KX_Scene attribute \"%s\" not found", PyString_AsString(attr)); + PyErr_Format(PyExc_AttributeError, "value = scene.myAttr: KX_Scene, attribute \"%s\" not found", PyString_AsString(attr)); } } @@ -1696,7 +1696,7 @@ int KX_Scene::py_setattro(PyObject *attr, PyObject *value) ret= PY_SET_ATTR_SUCCESS; } else { - PyErr_SetString(PyExc_AttributeError, "failed assigning value to KX_Scenes internal dictionary"); + PyErr_SetString(PyExc_AttributeError, "scene.UserAttr = value: KX_Scenes, failed assigning value to internal dictionary"); ret= PY_SET_ATTR_FAIL; } } diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index eb1d91d760f..b9edd7436df 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -355,7 +355,7 @@ PyObject* KX_SoundActuator::pyattr_get_filename(void *self, const struct KX_PYAT char* name = objectname.Ptr(); if (!name) { - PyErr_SetString(PyExc_RuntimeError, "Unable to get sound filename"); + PyErr_SetString(PyExc_RuntimeError, "value = actuator.filename: KX_SoundActuator, unable to get sound filename"); return NULL; } else return PyString_FromString(name); @@ -541,7 +541,7 @@ int KX_SoundActuator::pyattr_set_orientation(void *self, const struct KX_PYATTRI KX_SoundActuator * actuator = static_cast (self); if (!PySequence_Check(value)) { - PyErr_SetString(PyExc_AttributeError, "'orientation' attribute needs to be a sequence"); + PyErr_SetString(PyExc_AttributeError, "value = actuator.orientation: KX_SoundActuator, expected a sequence"); return 1; } diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index e7f8acbd1a8..5a6e8e6f501 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -369,7 +369,7 @@ const char KX_TouchSensor::GetTouchMaterial_doc[] = "\tKX_FALSE if it looks for a specific property.\n" ; PyObject* KX_TouchSensor::PyGetTouchMaterial() { - ShowDeprecationWarning("getTouchMaterial()", "the materialCheck property"); + ShowDeprecationWarning("getTouchMaterial()", "the useMaterial property"); return PyInt_FromLong(m_bFindMaterial); } @@ -382,6 +382,7 @@ const char KX_TouchSensor::SetTouchMaterial_doc[] = "\tKX_FALSE to switch off positive pulse mode.\n" ; PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject *value) { + ShowDeprecationWarning("setTouchMaterial()", "the useMaterial property"); int pulseArg = PyInt_AsLong(value); if(pulseArg ==-1 && PyErr_Occurred()) { diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp index 8be125011bb..88f63334285 100644 --- a/source/gameengine/Ketsji/KX_VertexProxy.cpp +++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp @@ -398,7 +398,7 @@ PyObject* KX_VertexProxy::PySetRGBA(PyObject* value) } } - PyErr_SetString(PyExc_TypeError, "expected a 4D vector or an int"); + PyErr_SetString(PyExc_TypeError, "vert.setRGBA(value): KX_VertexProxy, expected a 4D vector or an int"); return NULL; } diff --git a/source/gameengine/VideoTexture/FilterNormal.cpp b/source/gameengine/VideoTexture/FilterNormal.cpp index 03a79c1c8ce..a7266967efb 100644 --- a/source/gameengine/VideoTexture/FilterNormal.cpp +++ b/source/gameengine/VideoTexture/FilterNormal.cpp @@ -74,7 +74,7 @@ static int setColor (PyFilter * self, PyObject * value, void * closure) // check validity of parameter if (value == NULL || !PyInt_Check(value)) { - PyErr_SetString(PyExc_TypeError, "The value must be a int"); + PyErr_SetString(PyExc_TypeError, "filt.colorIdx = int: VideoTexture.FilterNormal, expected the value must be a int"); return -1; } // set color index @@ -94,15 +94,20 @@ static PyObject * getDepth (PyFilter * self, void * closure) static int setDepth (PyFilter * self, PyObject * value, void * closure) { // check validity of parameter - if (value == NULL || !PyFloat_Check(value)) + if (value) { - PyErr_SetString(PyExc_TypeError, "The value must be a float"); - return -1; + float depth= (float)PyFloat_AsDouble(value); + if ((depth==-1 && PyErr_Occurred()) == 0) /* no error converting to a float? */ + { + // set depth + getFilter(self)->setDepth(depth); + // success + return 0; + } } - // set depth - getFilter(self)->setDepth(float(PyFloat_AsDouble(value))); - // success - return 0; + + PyErr_SetString(PyExc_TypeError, "filt.depth = float: VideoTexture.FilterNormal, expected the value must be a float"); + return -1; } diff --git a/source/gameengine/VideoTexture/blendVideoTex.cpp b/source/gameengine/VideoTexture/blendVideoTex.cpp index ec066811a52..c11e7fffecd 100644 --- a/source/gameengine/VideoTexture/blendVideoTex.cpp +++ b/source/gameengine/VideoTexture/blendVideoTex.cpp @@ -1,6 +1,6 @@ /* $Id$ ----------------------------------------------------------------------------- -This source file is part of VideoTexure library +This source file is part of VideoTexture library Copyright (c) 2006 The Zdeno Ash Miklas @@ -49,14 +49,14 @@ static PyObject * getMaterialID (PyObject *self, PyObject *args) char * matName; // get parameters - if (!PyArg_ParseTuple(args, "Os", &obj, &matName)) + if (!PyArg_ParseTuple(args, "Os:materialID", &obj, &matName)) return NULL; // get material id short matID = getMaterialID(obj, matName); // if material was not found, report errot if (matID < 0) { - PyErr_SetString(PyExc_RuntimeError, "object doesn't have material with given name"); + PyErr_SetString(PyExc_RuntimeError, "VideoTexture.materialID(ob, string): Object doesn't have material with given name"); return NULL; } // return material ID @@ -67,7 +67,7 @@ static PyObject * getMaterialID (PyObject *self, PyObject *args) // get last error description static PyObject * getLastError (PyObject *self, PyObject *args) { - return Py_BuildValue("s", Exception::m_lastError.c_str()); + return PyString_FromString(Exception::m_lastError.c_str()); } // set log file @@ -89,7 +89,7 @@ static PyObject * imageToArray (PyObject * self, PyObject *args) if (!PyArg_ParseTuple(args, "O", &pyImg) || !pyImageTypes.in(pyImg->ob_type)) { // if object is incorect, report error - PyErr_SetString(PyExc_TypeError, "The value must be a image source object"); + PyErr_SetString(PyExc_TypeError, "VideoTexture.imageToArray(image): The value must be a image source object"); return NULL; } // get image structure -- cgit v1.2.3 From fcdbbee208fb64e9f0696843a69726de3c0d36b8 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Sun, 19 Apr 2009 21:26:29 +0000 Subject: SCons / epydoc support * properly detect if epydoc is installed. patch by Brandano --- source/gameengine/PyDoc/SConscript | 40 +++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/PyDoc/SConscript b/source/gameengine/PyDoc/SConscript index ac0b163d7bd..ab1fda8fa85 100644 --- a/source/gameengine/PyDoc/SConscript +++ b/source/gameengine/PyDoc/SConscript @@ -3,26 +3,22 @@ Import ('env') from optparse import OptionParser -try: - import epydoc -except ImportError: - print "No epydoc install detected, Python API Docs will not be generated " -if epydoc: - from epydoc.docbuilder import build_doc_index - from epydoc import cli - names = env.Glob("source/gameengine/PyDoc/*.py") - docindex = build_doc_index(names) - optvalues = cli.OPTION_DEFAULTS - optvalues["verbose"] = 1 - optvalues["target"] = env["BF_DOCDIR"]+"/BGE_API/" - optvalues["url"] = "http://www.blender.org" - optvalues["top"] = "Game Engine API" - optvalues["name"] = "Blender" - optvalues["noprivate"] = 1 - optvalues["noframes"] = 1 - optvalues["names"] = names - optparser = OptionParser() - optparser.set_defaults(**optvalues) - (options, args) = optparser.parse_args([]) - cli.write_html(docindex, options) +import epydoc +from epydoc.docbuilder import build_doc_index +from epydoc import cli +names = env.Glob("source/gameengine/PyDoc/*.py") +docindex = build_doc_index(names) +optvalues = cli.OPTION_DEFAULTS +optvalues["verbose"] = 1 +optvalues["target"] = env["BF_DOCDIR"]+"/BGE_API/" +optvalues["url"] = "http://www.blender.org" +optvalues["top"] = "Game Engine API" +optvalues["name"] = "Blender" +optvalues["noprivate"] = 1 +optvalues["noframes"] = 1 +optvalues["names"] = names +optparser = OptionParser() +optparser.set_defaults(**optvalues) +(options, args) = optparser.parse_args([]) +cli.write_html(docindex, options) -- cgit v1.2.3 From 9078ce5da209bcfd31c60b55118076359ce7244f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 19 Apr 2009 22:02:48 +0000 Subject: Scons epydos changed options - no source code since this is only useful if the epydocs contain code, ours are only docstrings. - set inheritance to included so you dont have to search up the classes to find available functions. - SConstruct, isolate the exception for importing epydoc. - Added a print to the SConscript files otherwise it looks like nothings happening. --- source/gameengine/PyDoc/SConscript | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source/gameengine') diff --git a/source/gameengine/PyDoc/SConscript b/source/gameengine/PyDoc/SConscript index ab1fda8fa85..ed9712ba273 100644 --- a/source/gameengine/PyDoc/SConscript +++ b/source/gameengine/PyDoc/SConscript @@ -10,6 +10,10 @@ names = env.Glob("source/gameengine/PyDoc/*.py") docindex = build_doc_index(names) optvalues = cli.OPTION_DEFAULTS optvalues["verbose"] = 1 +optvalues["quiet"] = 0 +optvalues["include_source_code"] = 0 +optvalues["inheritance"] = "included" +optvalues["show_private"] = 0 optvalues["target"] = env["BF_DOCDIR"]+"/BGE_API/" optvalues["url"] = "http://www.blender.org" optvalues["top"] = "Game Engine API" @@ -20,5 +24,6 @@ optvalues["names"] = names optparser = OptionParser() optparser.set_defaults(**optvalues) (options, args) = optparser.parse_args([]) +print "Writing Game Engine epydocs to \"%s\"" % optvalues["target"] cli.write_html(docindex, options) -- cgit v1.2.3 From dee32d0b3f409007f5a392668068b92c3810026a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 20 Apr 2009 09:13:59 +0000 Subject: BGE Python API - initialize pythons sys.argv in the blenderplayer - ignore all arguments after a single " - " in the blenderplayer (like in blender), so args can be passed to the game. - add a utility function PyOrientationTo() - to take a Py euler, quat or 3x3 matrix and convert into a C++ MT_Matrix3x3. - add utility function ConvertPythonToMesh to get a RAS_MeshObject from a KX_MeshProxy or a name. - Added error prefix arguments to ConvertPythonToGameObject, ConvertPythonToMesh and PyOrientationTo so the error messages can include what function they came from. - deprecated brick.getOwner() for the "owner" attribute. --- source/gameengine/GameLogic/SCA_ILogicBrick.cpp | 20 ++++- source/gameengine/GameLogic/SCA_ILogicBrick.h | 2 + .../GamePlayer/ghost/GPG_Application.cpp | 8 +- .../gameengine/GamePlayer/ghost/GPG_Application.h | 6 +- source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 13 +++- source/gameengine/Ketsji/KX_CameraActuator.cpp | 4 +- source/gameengine/Ketsji/KX_GameObject.cpp | 90 ++++++---------------- source/gameengine/Ketsji/KX_GameObject.h | 2 +- source/gameengine/Ketsji/KX_MeshProxy.cpp | 55 +++++++++++++ source/gameengine/Ketsji/KX_MeshProxy.h | 3 + source/gameengine/Ketsji/KX_ParentActuator.cpp | 4 +- source/gameengine/Ketsji/KX_PyMath.cpp | 34 ++++++++ source/gameengine/Ketsji/KX_PyMath.h | 2 + source/gameengine/Ketsji/KX_PythonInit.cpp | 7 +- source/gameengine/Ketsji/KX_PythonInit.h | 2 +- .../gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp | 4 +- .../Ketsji/KX_SCA_ReplaceMeshActuator.cpp | 41 +++------- source/gameengine/Ketsji/KX_Scene.cpp | 4 +- source/gameengine/Ketsji/KX_SoundActuator.cpp | 50 ++---------- source/gameengine/Ketsji/KX_TrackToActuator.cpp | 4 +- source/gameengine/Ketsji/KX_VehicleWrapper.cpp | 5 +- source/gameengine/PyDoc/KX_VehicleWrapper.py | 20 +++-- source/gameengine/PyDoc/SCA_ILogicBrick.py | 6 +- 23 files changed, 215 insertions(+), 171 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index b3045402c2c..3cd750ff63b 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -246,8 +246,8 @@ PyParentObject SCA_ILogicBrick::Parents[] = { PyMethodDef SCA_ILogicBrick::Methods[] = { + // --> Deprecated {"getOwner", (PyCFunction) SCA_ILogicBrick::sPyGetOwner, METH_NOARGS}, - // --> Deprecated {"getExecutePriority", (PyCFunction) SCA_ILogicBrick::sPyGetExecutePriority, METH_NOARGS}, {"setExecutePriority", (PyCFunction) SCA_ILogicBrick::sPySetExecutePriority, METH_VARARGS}, // <-- Deprecated @@ -255,6 +255,7 @@ PyMethodDef SCA_ILogicBrick::Methods[] = { }; PyAttributeDef SCA_ILogicBrick::Attributes[] = { + KX_PYATTRIBUTE_RO_FUNCTION("owner", SCA_ILogicBrick, pyattr_get_owner), KX_PYATTRIBUTE_INT_RW("executePriority",0,100000,false,SCA_ILogicBrick,m_Execute_Ueber_Priority), {NULL} //Sentinel }; @@ -291,6 +292,8 @@ int SCA_ILogicBrick::py_setattro(PyObject *attr, PyObject *value) PyObject* SCA_ILogicBrick::PyGetOwner() { + ShowDeprecationWarning("getOwner()", "the owner property"); + CValue* parent = GetParent(); if (parent) { @@ -327,6 +330,19 @@ PyObject* SCA_ILogicBrick::PyGetExecutePriority() } +/*Attribute functions */ +PyObject* SCA_ILogicBrick::pyattr_get_owner(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_ILogicBrick* self= static_cast(self_v); + CValue* parent = self->GetParent(); + + if (parent) + return parent->GetProxy(); + + Py_RETURN_NONE; +} + + /* Conversions for making life better. */ bool SCA_ILogicBrick::PyArgToBool(int boolArg) @@ -338,8 +354,6 @@ bool SCA_ILogicBrick::PyArgToBool(int boolArg) } } - - PyObject* SCA_ILogicBrick::BoolToPyArg(bool boolarg) { return PyInt_FromLong(boolarg? KX_TRUE: KX_FALSE); diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h index c0ff0fd633f..e59d05ea051 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.h +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h @@ -90,6 +90,8 @@ public: KX_PYMETHOD_NOARGS(SCA_ILogicBrick,GetOwner); KX_PYMETHOD_VARARGS(SCA_ILogicBrick,SetExecutePriority); KX_PYMETHOD_NOARGS(SCA_ILogicBrick,GetExecutePriority); + + static PyObject* pyattr_get_owner(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); // check that attribute is a property static int CheckProperty(void *self, const PyAttributeDef *attrdef); diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index 0ecbbea3af6..907ba99e63b 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -151,7 +151,7 @@ GPG_Application::~GPG_Application(void) -bool GPG_Application::SetGameEngineData(struct Main* maggie, Scene *scene) +bool GPG_Application::SetGameEngineData(struct Main* maggie, Scene *scene, int argc, char **argv) { bool result = false; @@ -163,6 +163,10 @@ bool GPG_Application::SetGameEngineData(struct Main* maggie, Scene *scene) m_startScene = scene; result = true; } + + /* Python needs these */ + m_argc= argc; + m_argv= argv; return result; } @@ -681,7 +685,7 @@ bool GPG_Application::startEngine(void) // some python things - PyObject* dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest, m_maggie); + PyObject* dictionaryobject = initGamePlayerPythonScripting("Ketsji", psl_Lowest, m_maggie, m_argc, m_argv); m_ketsjiengine->SetPythonDictionary(dictionaryobject); initRasterizer(m_rasterizer, m_canvas); PyObject *gameLogic = initGameLogic(m_ketsjiengine, startscene); diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.h b/source/gameengine/GamePlayer/ghost/GPG_Application.h index 38408f919b4..845686f5770 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.h +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.h @@ -58,7 +58,7 @@ public: GPG_Application(GHOST_ISystem* system); ~GPG_Application(void); - bool SetGameEngineData(struct Main* maggie, struct Scene* scene); + bool SetGameEngineData(struct Main* maggie, struct Scene* scene, int argc, char** argv); bool startWindow(STR_String& title, int windowLeft, int windowTop, int windowWidth, int windowHeight, const bool stereoVisual, const int stereoMode); bool startFullScreen(int width, int height, int bpp, int frequency, const bool stereoVisual, const int stereoMode); @@ -154,5 +154,9 @@ protected: */ char* m_pyGlobalDictString; int m_pyGlobalDictString_Length; + + /* argc and argv need to be passed on to python */ + int m_argc; + char** m_argv; }; diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index a41446ad88c..64e70ce37c3 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -206,6 +206,8 @@ void usage(const char* program) printf(" blender_material 0 Enable material settings\n"); printf(" ignore_deprecation_warnings 1 Ignore deprecation warnings\n"); printf("\n"); + printf(" - : all arguments after this are ignored, allowing python to access them from sys.argv\n"); + printf("\n"); 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); } @@ -293,6 +295,7 @@ static BlendFileData *load_game_data(char *progname, char *filename = NULL, char int main(int argc, char** argv) { int i; + int argc_py_clamped= argc; /* use this so python args can be added after ' - ' */ bool error = false; SYS_SystemHandle syshandle = SYS_GetSystem(); bool fullScreen = false; @@ -393,6 +396,12 @@ int main(int argc, char** argv) #endif if (argv[i][0] == '-') { + /* ignore all args after " - ", allow python to have own args */ + if (argv[i][1]=='\0') { + argc_py_clamped= i; + break; + } + switch (argv[i][1]) { case 'g': @@ -596,7 +605,7 @@ int main(int argc, char** argv) char pathname[FILE_MAXDIR + FILE_MAXFILE]; char *titlename; - get_filename(argc, argv, filename); + get_filename(argc_py_clamped, argv, filename); if(filename[0]) BLI_convertstringcwd(filename); @@ -691,7 +700,7 @@ int main(int argc, char** argv) } // GPG_Application app (system, maggie, startscenename); - app.SetGameEngineData(maggie, scene); + app.SetGameEngineData(maggie, scene, argc, argv); /* this argc cant be argc_py_clamped, since python uses it */ BLI_strncpy(pathname, maggie->name, sizeof(pathname)); BLI_strncpy(G.sce, maggie->name, sizeof(G.sce)); diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 6cc48856a94..355cdbb6263 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -462,7 +462,7 @@ PyObject* KX_CameraActuator::PySetObject(PyObject* value) ShowDeprecationWarning("setObject()", "the object property"); - if (!ConvertPythonToGameObject(value, &gameobj, true)) + if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.setObject(value): KX_CameraActuator")) return NULL; // ConvertPythonToGameObject sets the error if (m_ob != NULL) @@ -589,7 +589,7 @@ int KX_CameraActuator::pyattr_set_object(void *self_v, const KX_PYATTRIBUTE_DEF KX_CameraActuator* self= static_cast(self_v); KX_GameObject *gameobj; - if (!ConvertPythonToGameObject(value, &gameobj, true)) + if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_CameraActuator")) return 1; // ConvertPythonToGameObject sets the error if (self->m_ob) diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index af1dc7f67b2..bea0fcff2af 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1182,22 +1182,12 @@ bool KX_GameObject::ConvertPythonVectorArgs(PyObject* args, PyObject* KX_GameObject::PyReplaceMesh(PyObject* value) { KX_Scene *scene = KX_GetActiveScene(); - char* meshname; - void* mesh_pt; - - meshname = PyString_AsString(value); - if (meshname==NULL) { - PyErr_SetString(PyExc_ValueError, "gameOb.replaceMesh(value): KX_GameObject, expected a mesh name"); - return NULL; - } - mesh_pt = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(meshname)); + RAS_MeshObject* new_mesh; - if (mesh_pt==NULL) { - PyErr_SetString(PyExc_ValueError, "gameOb.replaceMesh(value): KX_GameObject, the mesh name given does not exist"); + if (!ConvertPythonToMesh(value, &new_mesh, false, "gameOb.replaceMesh(value): KX_GameObject")) return NULL; - } - scene->ReplaceMesh(this, (class RAS_MeshObject*)mesh_pt); + scene->ReplaceMesh(this, new_mesh); Py_RETURN_NONE; } @@ -1568,49 +1558,15 @@ PyObject* KX_GameObject::pyattr_get_localOrientation(void *self_v, const KX_PYAT int KX_GameObject::pyattr_set_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_GameObject* self= static_cast(self_v); - if (!PySequence_Check(value)) { - PyErr_SetString(PyExc_AttributeError, "gameOb.orientation = [...]: KX_GameObject, expected a sequence"); - return 1; - } - + + /* if value is not a sequence PyOrientationTo makes an error */ MT_Matrix3x3 rot; + if (!PyOrientationTo(value, rot, "gameOb.orientation = sequence: KX_GameObject, ")) + return NULL; - if (PyMatTo(value, rot)) - { - self->NodeSetLocalOrientation(rot); - self->NodeUpdateGS(0.f); - return 0; - } - PyErr_Clear(); - - if (PySequence_Size(value) == 4) - { - MT_Quaternion qrot; - if (PyVecTo(value, qrot)) - { - rot.setRotation(qrot); - self->NodeSetLocalOrientation(rot); - self->NodeUpdateGS(0.f); - return 0; - } - return 1; - } - - if (PySequence_Size(value) == 3) - { - MT_Vector3 erot; - if (PyVecTo(value, erot)) - { - rot.setEuler(erot); - self->NodeSetLocalOrientation(rot); - self->NodeUpdateGS(0.f); - return 0; - } - return 1; - } - - PyErr_SetString(PyExc_AttributeError, "gameOb.orientation = [...]: KX_GameObject, could not set the orientation from a 3x3 matrix, quaternion or euler sequence"); - return 1; + self->NodeSetLocalOrientation(rot); + self->NodeUpdateGS(0.f); + return 0; } PyObject* KX_GameObject::pyattr_get_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) @@ -2127,7 +2083,7 @@ PyObject* KX_GameObject::PyGetParent() PyObject* KX_GameObject::PySetParent(PyObject* value) { KX_GameObject *obj; - if (!ConvertPythonToGameObject(value, &obj, false)) + if (!ConvertPythonToGameObject(value, &obj, false, "gameOb.setParent(value): KX_GameObject")) return NULL; this->SetParent(KX_GetActiveScene(), obj); @@ -2362,7 +2318,7 @@ KX_PYMETHODDEF_DOC_O(KX_GameObject, getDistanceTo, PyErr_Clear(); KX_GameObject *other; - if (ConvertPythonToGameObject(value, &other, false)) + if (ConvertPythonToGameObject(value, &other, false, "gameOb.getDistanceTo(value): KX_GameObject")) { return PyFloat_FromDouble(NodeGetWorldPosition().distance(other->NodeGetWorldPosition())); } @@ -2385,7 +2341,7 @@ KX_PYMETHODDEF_DOC_O(KX_GameObject, getVectTo, PyErr_Clear(); KX_GameObject *other; - if (ConvertPythonToGameObject(value, &other, false)) + if (ConvertPythonToGameObject(value, &other, false, "")) /* error will be overwritten */ { toPoint = other->NodeGetWorldPosition(); } else @@ -2479,7 +2435,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo, KX_GameObject *other; PyErr_Clear(); - if (ConvertPythonToGameObject(pyarg, &other, false)) + if (ConvertPythonToGameObject(pyarg, &other, false, "")) /* error will be overwritten */ { toPoint = other->NodeGetWorldPosition(); } else @@ -2555,7 +2511,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, { PyErr_Clear(); - if (ConvertPythonToGameObject(pyto, &other, false)) + if (ConvertPythonToGameObject(pyto, &other, false, "")) /* error will be overwritten */ { toPoint = other->NodeGetWorldPosition(); } else @@ -2572,7 +2528,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, { PyErr_Clear(); - if (ConvertPythonToGameObject(pyfrom, &other, false)) + if (ConvertPythonToGameObject(pyfrom, &other, false, "")) /* error will be overwritten */ { fromPoint = other->NodeGetWorldPosition(); } else @@ -2685,10 +2641,10 @@ void KX_GameObject::Relink(GEN_Map *map_parameter) } } -bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok) +bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok, const char *error_prefix) { if (value==NULL) { - PyErr_SetString(PyExc_TypeError, "Error in ConvertPythonToGameObject, python pointer NULL, should never happen"); + PyErr_Format(PyExc_TypeError, "%s, python pointer NULL, should never happen", error_prefix); *object = NULL; return false; } @@ -2699,7 +2655,7 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py if (py_none_ok) { return true; } else { - PyErr_SetString(PyExc_TypeError, "Expected KX_GameObject or a string for a name of a KX_GameObject, None is invalid"); + PyErr_Format(PyExc_TypeError, "%s, expected KX_GameObject or a KX_GameObject name, None is invalid", error_prefix); return false; } } @@ -2710,7 +2666,7 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py if (*object) { return true; } else { - PyErr_SetString(PyExc_ValueError, "Requested name did not match any KX_GameObject"); + PyErr_Format(PyExc_ValueError, "%s, requested name \"%s\" did not match any KX_GameObject in this scene", error_prefix, PyString_AsString(value)); return false; } } @@ -2720,7 +2676,7 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py /* sets the error */ if (*object==NULL) { - PyErr_SetString(PyExc_RuntimeError, BGE_PROXY_ERROR_MSG); + PyErr_Format(PyExc_RuntimeError, "%s, " BGE_PROXY_ERROR_MSG, error_prefix); return false; } @@ -2730,9 +2686,9 @@ bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py *object = NULL; if (py_none_ok) { - PyErr_SetString(PyExc_TypeError, "Expect a KX_GameObject, a string or None"); + PyErr_Format(PyExc_TypeError, "%s, expect a KX_GameObject, a string or None", error_prefix); } else { - PyErr_SetString(PyExc_TypeError, "Expect a KX_GameObject or a string"); + PyErr_Format(PyExc_TypeError, "%s, expect a KX_GameObject or a string", error_prefix); } return false; diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 89517bd76ce..ec02dc17b75 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -61,7 +61,7 @@ class PHY_IPhysicsEnvironment; struct Object; /* utility conversion function */ -bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok); +bool ConvertPythonToGameObject(PyObject * value, KX_GameObject **object, bool py_none_ok, const char *error_prefix); /** * KX_GameObject is the main class for dynamic objects. diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index e2c59ab4242..6be1da55ff8 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -304,3 +304,58 @@ PyObject * KX_MeshProxy::pyattr_get_numPolygons(void * selfv, const KX_PYATTRIBU KX_MeshProxy * self = static_cast (selfv); return PyInt_FromLong(self->m_meshobj->NumPolygons()); } + +/* a close copy of ConvertPythonToGameObject but for meshes */ +bool ConvertPythonToMesh(PyObject * value, RAS_MeshObject **object, bool py_none_ok, const char *error_prefix) +{ + if (value==NULL) { + PyErr_Format(PyExc_TypeError, "%s, python pointer NULL, should never happen", error_prefix); + *object = NULL; + return false; + } + + if (value==Py_None) { + *object = NULL; + + if (py_none_ok) { + return true; + } else { + PyErr_Format(PyExc_TypeError, "%s, expected KX_MeshProxy or a KX_MeshProxy name, None is invalid", error_prefix); + return false; + } + } + + if (PyString_Check(value)) { + *object = (RAS_MeshObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String( PyString_AsString(value) )); + + if (*object) { + return true; + } else { + PyErr_Format(PyExc_ValueError, "%s, requested name \"%s\" did not match any KX_MeshProxy in this scene", error_prefix, PyString_AsString(value)); + return false; + } + } + + if (PyObject_TypeCheck(value, &KX_MeshProxy::Type)) { + KX_MeshProxy *kx_mesh = static_castBGE_PROXY_REF(value); + + /* sets the error */ + if (*object==NULL) { + PyErr_Format(PyExc_RuntimeError, "%s, " BGE_PROXY_ERROR_MSG, error_prefix); + return false; + } + + *object = kx_mesh->GetMesh(); + return true; + } + + *object = NULL; + + if (py_none_ok) { + PyErr_Format(PyExc_TypeError, "%s, expect a KX_MeshProxy, a string or None", error_prefix); + } else { + PyErr_Format(PyExc_TypeError, "%s, expect a KX_MeshProxy or a string", error_prefix); + } + + return false; +} diff --git a/source/gameengine/Ketsji/KX_MeshProxy.h b/source/gameengine/Ketsji/KX_MeshProxy.h index dfc498801a7..aeecefc09e6 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.h +++ b/source/gameengine/Ketsji/KX_MeshProxy.h @@ -31,6 +31,9 @@ #include "SCA_IObject.h" +/* utility conversion function */ +bool ConvertPythonToMesh(PyObject * value, class RAS_MeshObject **object, bool py_none_ok, const char *error_prefix); + class KX_MeshProxy : public SCA_IObject { Py_Header; diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index 69c0a3cd510..0093cf5f313 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -192,7 +192,7 @@ int KX_ParentActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE KX_ParentActuator* actuator = static_cast(self); KX_GameObject *gameobj; - if (!ConvertPythonToGameObject(value, &gameobj, true)) + if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_ParentActuator")) return 1; // ConvertPythonToGameObject sets the error if (actuator->m_ob != NULL) @@ -226,7 +226,7 @@ PyObject* KX_ParentActuator::PySetObject(PyObject* value) { ShowDeprecationWarning("setObject()", "the object property"); - if (!ConvertPythonToGameObject(value, &gameobj, true)) + if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.setObject(value): KX_ParentActuator")) return NULL; // ConvertPythonToGameObject sets the error if (m_ob != NULL) diff --git a/source/gameengine/Ketsji/KX_PyMath.cpp b/source/gameengine/Ketsji/KX_PyMath.cpp index cceb7a12446..0093a72808e 100644 --- a/source/gameengine/Ketsji/KX_PyMath.cpp +++ b/source/gameengine/Ketsji/KX_PyMath.cpp @@ -44,6 +44,7 @@ #include "ListValue.h" #include "KX_Python.h" +#include "KX_PyMath.h" bool PyObject_IsMT_Matrix(PyObject *pymat, unsigned int rank) { @@ -74,6 +75,39 @@ bool PyObject_IsMT_Matrix(PyObject *pymat, unsigned int rank) return false; } +bool PyOrientationTo(PyObject* pyval, MT_Matrix3x3 &mat, const char *error_prefix) +{ + MT_Matrix3x3 rot; + int size= PySequence_Size(pyval); + + if (size == 4) + { + MT_Quaternion qrot; + if (PyVecTo(pyval, qrot)) + { + rot.setRotation(qrot); + return true; + } + } + else if (size == 3) { + /* 3x3 matrix or euler */ + MT_Vector3 erot; + if (PyVecTo(pyval, erot)) + { + rot.setEuler(erot); + return true; + } + PyErr_Clear(); + + if (PyMatTo(pyval, rot)) + { + return true; + } + } + + PyErr_Format(PyExc_TypeError, "%s, could not set the orientation from a 3x3 matrix, quaternion or euler sequence", error_prefix); + return false; +} PyObject* PyObjectFrom(const MT_Matrix4x4 &mat) { diff --git a/source/gameengine/Ketsji/KX_PyMath.h b/source/gameengine/Ketsji/KX_PyMath.h index 4a64063aaa1..00f7c5cad93 100644 --- a/source/gameengine/Ketsji/KX_PyMath.h +++ b/source/gameengine/Ketsji/KX_PyMath.h @@ -145,6 +145,8 @@ bool PyVecTo(PyObject* pyval, T& vec) return false; } +bool PyOrientationTo(PyObject* pyval, MT_Matrix3x3 &mat, const char *error_prefix); + /** * 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 097d20fe0e5..9649e50a98b 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1357,14 +1357,17 @@ void setSandbox(TPythonSecurityLevel level) /** * Python is not initialised. */ -PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level, Main *maggie) +PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level, Main *maggie, int argc, char** argv) { STR_String pname = progname; Py_SetProgramName(pname.Ptr()); Py_NoSiteFlag=1; Py_FrozenFlag=1; Py_Initialize(); - + + if(argv) /* browser plugins dont currently set this */ + PySys_SetArgv(argc, argv); + //importBlenderModules() setSandbox(level); diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h index 97d23fe391c..11360197b95 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.h +++ b/source/gameengine/Ketsji/KX_PythonInit.h @@ -43,7 +43,7 @@ extern bool gUseVisibilityTemp; PyObject* initGameLogic(class KX_KetsjiEngine *engine, class KX_Scene* ketsjiscene); PyObject* initGameKeys(); PyObject* initRasterizer(class RAS_IRasterizer* rasty,class RAS_ICanvas* canvas); -PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level, struct Main *maggie); +PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level, struct Main *maggie, int argc, char** argv); PyObject* initMathutils(); PyObject* initBGL(); PyObject* initVideoTexture(void); diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index f1c7b757579..56d94a8d226 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -231,7 +231,7 @@ int KX_SCA_AddObjectActuator::pyattr_set_object(void *self, const struct KX_PYAT KX_SCA_AddObjectActuator* actuator = static_cast(self); KX_GameObject *gameobj; - if (!ConvertPythonToGameObject(value, &gameobj, true)) + if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_SCA_AddObjectActuator")) return 1; // ConvertPythonToGameObject sets the error if (actuator->m_OriginalObject != NULL) @@ -277,7 +277,7 @@ PyObject* KX_SCA_AddObjectActuator::PySetObject(PyObject* value) ShowDeprecationWarning("setObject()", "the object property"); - if (!ConvertPythonToGameObject(value, &gameobj, true)) + if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.setObject(value): KX_SCA_AddObjectActuator")) return NULL; // ConvertPythonToGameObject sets the error if (m_OriginalObject != NULL) diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index 53067e94cd8..38f8d581d55 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -116,22 +116,12 @@ PyObject* KX_SCA_ReplaceMeshActuator::pyattr_get_mesh(void *self, const struct K int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_SCA_ReplaceMeshActuator* actuator = static_cast(self); - if (value == Py_None) { - actuator->m_mesh = NULL; - } else if (PyString_Check(value)) { - void* mesh = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(PyString_AsString(value))); - if (mesh==NULL) { - PyErr_SetString(PyExc_ValueError, "actuator.mesh = string: Replace Mesh Actuator, mesh name given does not exist"); - return 1; - } - actuator->m_mesh= (class RAS_MeshObject*)mesh; - } else if PyObject_TypeCheck(value, &KX_MeshProxy::Type) { - KX_MeshProxy* proxy = (KX_MeshProxy*)value; - actuator->m_mesh= proxy->GetMesh(); - } else { - PyErr_SetString(PyExc_ValueError, "actuator.mesh = value: Replace Mesh Actuator, expected the mesh name, a KX_MeshProxy or None"); + RAS_MeshObject* new_mesh; + + if (!ConvertPythonToMesh(value, &new_mesh, true, "actuator.mesh = value: KX_SCA_ReplaceMeshActuator")) return 1; - } + + actuator->m_mesh = new_mesh; return 0; } @@ -144,23 +134,12 @@ const char KX_SCA_ReplaceMeshActuator::SetMesh_doc[] = PyObject* KX_SCA_ReplaceMeshActuator::PySetMesh(PyObject* value) { ShowDeprecationWarning("setMesh()", "the mesh property"); - if (value == Py_None) { - m_mesh = NULL; - } else { - char* meshname = PyString_AsString(value); - if (!meshname) { - PyErr_SetString(PyExc_ValueError, "Expected the name of a mesh or None"); - return NULL; - } - void* mesh = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(meshname)); - - if (mesh==NULL) { - PyErr_SetString(PyExc_ValueError, "The mesh name given does not exist"); - return NULL; - } - m_mesh= (class RAS_MeshObject*)mesh; - } + RAS_MeshObject* new_mesh; + + if (!ConvertPythonToMesh(value, &new_mesh, true, "actuator.mesh = value: KX_SCA_ReplaceMeshActuator")) + return NULL; + m_mesh = new_mesh; Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 0e1572da679..aa7bd65f240 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1747,8 +1747,8 @@ KX_PYMETHODDEF_DOC(KX_Scene, addObject, if (!PyArg_ParseTuple(args, "OO|i:addObject", &pyob, &pyother, &time)) return NULL; - if (!ConvertPythonToGameObject(pyob, &ob, false) - || !ConvertPythonToGameObject(pyother, &other, false)) + if ( !ConvertPythonToGameObject(pyob, &ob, false, "scene.addObject(object, other, time): KX_Scene (first argument)") || + !ConvertPythonToGameObject(pyother, &other, false, "scene.addObject(object, other, time): KX_Scene (second argument)") ) return NULL; diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index b9edd7436df..412be497c5a 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -540,50 +540,16 @@ int KX_SoundActuator::pyattr_set_orientation(void *self, const struct KX_PYATTRI MT_Matrix3x3 rot; KX_SoundActuator * actuator = static_cast (self); - if (!PySequence_Check(value)) { - PyErr_SetString(PyExc_AttributeError, "value = actuator.orientation: KX_SoundActuator, expected a sequence"); - return 1; - } - + /* if value is not a sequence PyOrientationTo makes an error */ + if (!PyOrientationTo(value, rot, "actuator.orientation = value: KX_SoundActuator")) + return NULL; + if (!actuator->m_soundObject) return 0; /* Since not having m_soundObject didn't do anything in the old version, - * it probably should be kept that way */ - - if (PyMatTo(value, rot)) - { - actuator->m_soundObject->SetOrientation(rot); - return 0; - } - PyErr_Clear(); - - - if (PySequence_Size(value) == 4) - { - MT_Quaternion qrot; - if (PyVecTo(value, qrot)) - { - rot.setRotation(qrot); - actuator->m_soundObject->SetOrientation(rot); - return 0; - } - return 1; - } - - if (PySequence_Size(value) == 3) - { - MT_Vector3 erot; - if (PyVecTo(value, erot)) - { - rot.setEuler(erot); - actuator->m_soundObject->SetOrientation(rot); - return 0; - } - return 1; - } - - PyErr_SetString(PyExc_AttributeError, "could not set the orientation from a 3x3 matrix, quaternion or euler sequence"); - return 1; - + * it probably should be kept that way */ + + actuator->m_soundObject->SetOrientation(rot); + return 0; } // Deprecated -----> diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index c89d88389c4..fbf43de6cf4 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -489,7 +489,7 @@ int KX_TrackToActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUT KX_TrackToActuator* actuator = static_cast(self); KX_GameObject *gameobj; - if (!ConvertPythonToGameObject(value, &gameobj, true)) + if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_TrackToActuator")) return 1; // ConvertPythonToGameObject sets the error if (actuator->m_object != NULL) @@ -525,7 +525,7 @@ PyObject* KX_TrackToActuator::PySetObject(PyObject* value) ShowDeprecationWarning("setObject()", "the object property"); - if (!ConvertPythonToGameObject(value, &gameobj, true)) + if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.setObject(value): KX_TrackToActuator")) return NULL; // ConvertPythonToGameObject sets the error if (m_object != NULL) diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp index f77c135e994..1a6fb196db5 100644 --- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp +++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp @@ -47,14 +47,15 @@ PyObject* KX_VehicleWrapper::PyAddWheel(PyObject* args) if (PyArg_ParseTuple(args,"OOOOffi:addWheel",&wheelGameObject,&pylistPos,&pylistDir,&pylistAxleDir,&suspensionRestLength,&wheelRadius,&hasSteering)) { KX_GameObject *gameOb; - if (!ConvertPythonToGameObject(wheelGameObject, &gameOb, false)) + if (!ConvertPythonToGameObject(wheelGameObject, &gameOb, false, "vehicle.addWheel(...): KX_VehicleWrapper (first argument)")) return NULL; if (gameOb->GetSGNode()) { PHY_IMotionState* motionState = new KX_MotionState(gameOb->GetSGNode()); - + + /* TODO - no error checking here! - bad juju */ MT_Vector3 attachPos,attachDir,attachAxle; PyVecTo(pylistPos,attachPos); PyVecTo(pylistDir,attachDir); diff --git a/source/gameengine/PyDoc/KX_VehicleWrapper.py b/source/gameengine/PyDoc/KX_VehicleWrapper.py index 68240e15622..087aa167475 100644 --- a/source/gameengine/PyDoc/KX_VehicleWrapper.py +++ b/source/gameengine/PyDoc/KX_VehicleWrapper.py @@ -5,15 +5,23 @@ class KX_VehicleWrapper: # (PyObjectPlus) All placeholders have a __ prefix """ - def __addWheel(val): + def addWheel(wheel, attachPos, attachDir, axleDir, suspensionRestLength, wheelRadius, hasSteering): + """ TODO - Description - @param val: the starting frame of the animation - @type val: float - - @rtype: integer - @return: TODO Description + @param wheel: The object to use as a wheel. + @type wheel: L{KX_GameObject} or a KX_GameObject name + @param attachPos: The position that this wheel will attach to. + @type attachPos: vector of 3 floats + @param attachDir: The direction this wheel points. + @type attachDir: vector of 3 floats + @param axleDir: The direction of this wheels axle. + @type axleDir: vector of 3 floats + @param suspensionRestLength: TODO - Description + @type suspensionRestLength: float + @param wheelRadius: The size of the wheel. + @type wheelRadius: float """ def __applyBraking(val): diff --git a/source/gameengine/PyDoc/SCA_ILogicBrick.py b/source/gameengine/PyDoc/SCA_ILogicBrick.py index 18cb900f28d..4688ba12bb6 100644 --- a/source/gameengine/PyDoc/SCA_ILogicBrick.py +++ b/source/gameengine/PyDoc/SCA_ILogicBrick.py @@ -8,13 +8,17 @@ class SCA_ILogicBrick: @ivar executePriority: This determines the order controllers are evaluated, and actuators are activated (lower priority is executed first). @type executePriority: int + @ivar owner: The game object this logic brick is attached to (read only). + @type owner: L{KX_GameObject} or None in exceptional cases. """ def getOwner(): """ Gets the game object associated with this logic brick. - @rtype: L{KX_GameObject} + Deprecated: Use the "owner" property instead. + + @rtype: L{KX_GameObject} """ #--The following methods are deprecated-- -- cgit v1.2.3