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.
This commit is contained in:
2009-06-22 04:26:48 +00:00
parent 1efffc1f56
commit bce3f7e019
13 changed files with 682 additions and 189 deletions

View File

@@ -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 */