diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-06-22 08:26:48 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-06-22 08:26:48 +0400 |
commit | bce3f7e019c174947a0f98063f39533eb59ab03e (patch) | |
tree | bb66802258a156dec4a39f20c900a750fd7b6b55 /source/blender/python/generic/Mathutils.h | |
parent | 1efffc1f564af0597512699890d7be9f41a6aee2 (diff) |
PyAPI Mathutils Vector callbacks, referencing other PyObjects rather then thin wrapping vectors which is crash prone.
in short, vectors can work as if they are thin wrapped but not crash blender if the original data is removed.
* RNA vector's return Mathutils vector types.
* BGE vectors for GameObject's localPosition, worldPosition, localPosition, localScale, worldScale, localInertia.
* Comment USE_MATHUTILS define to disable returning vectors.
Example...
* 2.49... *
loc = gameOb.worldPosition
loc[1] = 0
gameOb.worldPosition = loc
* With vectors... *
gameOb.worldPosition[1] = 0
* But this wont crash... *
loc = gameOb.worldPosition
gameOb.endObject()
loc[1] = 0 # will raise an error that the objects removed.
This breaks games which assume return values are lists.
Will add this to eulers, matrix and quaternion types later.
Diffstat (limited to 'source/blender/python/generic/Mathutils.h')
-rw-r--r-- | source/blender/python/generic/Mathutils.h | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/source/blender/python/generic/Mathutils.h b/source/blender/python/generic/Mathutils.h index e8882c3dac2..07cf029b77c 100644 --- a/source/blender/python/generic/Mathutils.h +++ b/source/blender/python/generic/Mathutils.h @@ -40,8 +40,6 @@ PyObject *Mathutils_Init( const char * from ); -PyObject *row_vector_multiplication(VectorObject* vec, MatrixObject * mat); -PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* vec); PyObject *quat_rotation(PyObject *arg1, PyObject *arg2); int EXPP_FloatsAreEqual(float A, float B, int floatSteps); @@ -49,8 +47,9 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps); #define Py_PI 3.14159265358979323846 -#define Py_WRAP 1024 -#define Py_NEW 2048 + +#define Py_NEW 1 +#define Py_WRAP 2 /* Mathutils is used by the BGE and Blender so have to define @@ -65,4 +64,20 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps); #define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True #endif +typedef struct Mathutils_Callback Mathutils_Callback; +struct Mathutils_Callback { + int (*check)(PyObject *user); /* checks the user is still valid */ + int (*get)(PyObject *user, int subtype, float *vec_from); /* gets the vector from the user */ + int (*set)(PyObject *user, int subtype, float *vec_to); /* sets the users vector values once the vector is modified */ + int (*get_index)(PyObject *user, int subtype, float *vec_from, int index); /* same as above but only for an index */ + int (*set_index)(PyObject *user, int subtype, float *vec_to, int index); /* same as above but only for an index */ +}; + +int Mathutils_RegisterCallback(Mathutils_Callback *cb); + +int Vector_ReadCallback(VectorObject *self); +int Vector_WriteCallback(VectorObject *self); +int Vector_ReadIndexCallback(VectorObject *self, int index); +int Vector_WriteIndexCallback(VectorObject *self, int index); + #endif /* EXPP_Mathutils_H */ |