[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20596] trunk/blender: BGE PyAPI fixes
Campbell Barton
ideasman42 at gmail.com
Wed Jun 3 06:12:59 CEST 2009
Revision: 20596
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20596
Author: campbellbarton
Date: 2009-06-03 06:12:59 +0200 (Wed, 03 Jun 2009)
Log Message:
-----------
BGE PyAPI fixes
- CValue warning ShowDeprecationWarning("val = ob.attr", "val = ob['attr']"); had false positives because of python using getattr() internally. Only show the wanring now when a CValue is found.
- Py functions that accepted a vector and a GameObject were slowed down by PySequence_Check() first called on the GameObject, though this would fail it would try and get attributes from the game object - ending up in ~8 attribute lookups each time. Avoiding PySequence_Check() makes ob.getDistanceTo(otherOb) over twice as fast.
- Joystick hat events could crash the BGE for joysticks with more then 4 hats.
- PLY Import failed on PLY files from Carve, added some extra types.
Modified Paths:
--------------
trunk/blender/release/scripts/ply_import.py
trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
trunk/blender/source/gameengine/Expressions/Value.cpp
trunk/blender/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
trunk/blender/source/gameengine/Ketsji/KX_PyMath.h
Modified: trunk/blender/release/scripts/ply_import.py
===================================================================
--- trunk/blender/release/scripts/ply_import.py 2009-06-03 02:06:45 UTC (rev 20595)
+++ trunk/blender/release/scripts/ply_import.py 2009-06-03 04:12:59 UTC (rev 20596)
@@ -149,6 +149,7 @@
'uint8': 'B',
'int16': 'h',
'uint16': 'H',
+ 'ushort': 'H',
'int': 'i',
'int32': 'i',
'uint': 'I',
@@ -156,6 +157,7 @@
'float': 'f',
'float32': 'f',
'float64': 'd',
+ 'double': 'd',
'string': 's'}
obj_spec = object_spec()
Modified: trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
===================================================================
--- trunk/blender/source/gameengine/Expressions/PyObjectPlus.h 2009-06-03 02:06:45 UTC (rev 20595)
+++ trunk/blender/source/gameengine/Expressions/PyObjectPlus.h 2009-06-03 04:12:59 UTC (rev 20596)
@@ -141,7 +141,7 @@
#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 == py_base_dealloc)
+#define BGE_PROXY_CHECK_TYPE(_self) ((_self)->ob_type->tp_dealloc == PyObjectPlus::py_base_dealloc)
// This must be the first line of each
Modified: trunk/blender/source/gameengine/Expressions/Value.cpp
===================================================================
--- trunk/blender/source/gameengine/Expressions/Value.cpp 2009-06-03 02:06:45 UTC (rev 20595)
+++ trunk/blender/source/gameengine/Expressions/Value.cpp 2009-06-03 04:12:59 UTC (rev 20596)
@@ -555,15 +555,16 @@
PyObject* CValue::py_getattro(PyObject *attr)
-{
- ShowDeprecationWarning("val = ob.attr", "val = ob['attr']");
-
+{
char *attr_str= PyString_AsString(attr);
CValue* resultattr = GetProperty(attr_str);
if (resultattr)
{
+ /* only show the wanting here because python inspects for __class__ and KX_MeshProxy uses CValues name attr */
+ ShowDeprecationWarning("val = ob.attr", "val = ob['attr']");
+
PyObject* pyconvert = resultattr->ConvertValueToPython();
-
+
if (pyconvert)
return pyconvert;
else
Modified: trunk/blender/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp 2009-06-03 02:06:45 UTC (rev 20595)
+++ trunk/blender/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp 2009-06-03 04:12:59 UTC (rev 20596)
@@ -45,7 +45,7 @@
/* See notes below in the event loop */
void SCA_Joystick::OnHatMotion(SDL_Event* sdl_event)
{
- if(sdl_event->jhat.hat >= JOYAXIS_MAX)
+ if(sdl_event->jhat.hat >= JOYHAT_MAX)
return;
m_hat_array[sdl_event->jhat.hat]= sdl_event->jhat.value;
Modified: trunk/blender/source/gameengine/Ketsji/KX_PyMath.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PyMath.h 2009-06-03 02:06:45 UTC (rev 20595)
+++ trunk/blender/source/gameengine/Ketsji/KX_PyMath.h 2009-06-03 04:12:59 UTC (rev 20596)
@@ -40,6 +40,7 @@
#include "MT_Matrix4x4.h"
#include "KX_Python.h"
+#include "PyObjectPlus.h"
inline unsigned int Size(const MT_Matrix4x4&) { return 4; }
inline unsigned int Size(const MT_Matrix3x3&) { return 3; }
@@ -116,6 +117,19 @@
return true;
}
+ else if (BGE_PROXY_CHECK_TYPE(pyval))
+ { /* note, include this check because PySequence_Check does too much introspection
+ * on the PyObject (like getting its __class__, on a BGE type this means searching up
+ * the parent list each time only to discover its not a sequence.
+ * GameObjects are often used as an alternative to vectors so this is a common case
+ * better to do a quick check for it, likely the error below will be ignored.
+ *
+ * This is not 'correct' since we have proxy type CListValues's which could
+ * contain floats/ints but there no cases of CValueLists being this way
+ */
+ PyErr_Format(PyExc_AttributeError, "expected a sequence type");
+ return false;
+ }
else if (PySequence_Check(pyval))
{
unsigned int numitems = PySequence_Size(pyval);
More information about the Bf-blender-cvs
mailing list