[Bf-blender-cvs] [f4344cd] particles_refactor: Added python type for particle attribute state in the bparticles module.
Lukas Tönne
noreply at git.blender.org
Tue Apr 22 12:06:12 CEST 2014
Commit: f4344cdfa5cdcf7b357f137b8958ef9a5b879d6c
Author: Lukas Tönne
Date: Thu Dec 19 12:29:34 2013 +0100
https://developer.blender.org/rBf4344cdfa5cdcf7b357f137b8958ef9a5b879d6c
Added python type for particle attribute state in the bparticles module.
===================================================================
M source/blender/blenkernel/BKE_nparticle.h
M source/blender/blenkernel/intern/nparticle.c
M source/blender/python/bparticles/bparticles_py_types.c
M source/blender/python/bparticles/bparticles_py_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_nparticle.h b/source/blender/blenkernel/BKE_nparticle.h
index bcd337f..f60d690 100644
--- a/source/blender/blenkernel/BKE_nparticle.h
+++ b/source/blender/blenkernel/BKE_nparticle.h
@@ -40,6 +40,8 @@ struct NParticleDisplay;
/* XXX where to put this? */
typedef uint32_t NParticleID;
+const char *BKE_nparticle_datatype_name(int datatype);
+
struct NParticleSystem *BKE_nparticle_system_new(void);
void BKE_nparticle_system_free(struct NParticleSystem *psys);
struct NParticleSystem *BKE_nparticle_system_copy(struct NParticleSystem *psys);
diff --git a/source/blender/blenkernel/intern/nparticle.c b/source/blender/blenkernel/intern/nparticle.c
index d44d8d3..f439cc2 100644
--- a/source/blender/blenkernel/intern/nparticle.c
+++ b/source/blender/blenkernel/intern/nparticle.c
@@ -43,6 +43,22 @@
/* XXX TODO make this configurable */
#define PAGE_BYTES 65536
+const char *BKE_nparticle_datatype_name(int datatype)
+{
+ switch (datatype) {
+ case PAR_ATTR_DATATYPE_INTERNAL: return "internal";
+ case PAR_ATTR_DATATYPE_FLOAT: return "float";
+ case PAR_ATTR_DATATYPE_INT: return "int";
+ case PAR_ATTR_DATATYPE_BOOL: return "bool";
+ case PAR_ATTR_DATATYPE_VECTOR: return "vector";
+ case PAR_ATTR_DATATYPE_POINT: return "point";
+ case PAR_ATTR_DATATYPE_NORMAL: return "normal";
+ case PAR_ATTR_DATATYPE_COLOR: return "color";
+ case PAR_ATTR_DATATYPE_MATRIX: return "matrix";
+ default: return "";
+ }
+}
+
static size_t nparticle_elem_bytes(int datatype)
{
switch (datatype) {
diff --git a/source/blender/python/bparticles/bparticles_py_types.c b/source/blender/python/bparticles/bparticles_py_types.c
index 878d126..0094d6c 100644
--- a/source/blender/python/bparticles/bparticles_py_types.c
+++ b/source/blender/python/bparticles/bparticles_py_types.c
@@ -46,6 +46,10 @@ PyDoc_STRVAR(bpy_nparticlestate_doc,
"Particle state data\n"
);
+PyDoc_STRVAR(bpy_nparticleattributestate_doc,
+"Particle attribute state data\n"
+);
+
static PyObject *bpy_nparticlestate_repr(BPy_NParticleState *self)
{
NParticleState *state = self->state;
@@ -59,19 +63,46 @@ static PyObject *bpy_nparticlestate_repr(BPy_NParticleState *self)
}
}
+static PyObject *bpy_nparticleattributestate_repr(BPy_NParticleAttributeState *self)
+{
+ NParticleAttributeState *attrstate = self->attrstate;
+
+ if (attrstate) {
+ return PyUnicode_FromFormat("<NParticleAttributeState(%p) name=%s, datatype=%s>",
+ attrstate, attrstate->desc.name,
+ BKE_nparticle_datatype_name(attrstate->desc.datatype));
+ }
+ else {
+ return PyUnicode_FromFormat("<NParticleAttributeState dead at %p>", self);
+ }
+}
+
static PyGetSetDef bpy_nparticlestate_getseters[] = {
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
+static PyGetSetDef bpy_nparticleattributestate_getseters[] = {
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+};
+
static struct PyMethodDef bpy_nparticlestate_methods[] = {
{NULL, NULL, 0, NULL}
};
+static struct PyMethodDef bpy_nparticleattributestate_methods[] = {
+ {NULL, NULL, 0, NULL}
+};
+
static Py_hash_t bpy_nparticlestate_hash(PyObject *self)
{
return _Py_HashPointer(((BPy_NParticleState *)self)->state);
}
+static Py_hash_t bpy_nparticleattributestate_hash(PyObject *self)
+{
+ return _Py_HashPointer(((BPy_NParticleAttributeState *)self)->attrstate);
+}
+
/* Dealloc Functions
* ================= */
@@ -88,32 +119,48 @@ static void bpy_nparticlestate_dealloc(BPy_NParticleState *self)
PyObject_DEL(self);
}
+static void bpy_nparticleattributestate_dealloc(BPy_NParticleAttributeState *self)
+{
+ PyObject_DEL(self);
+}
+
/* Types
* ===== */
PyTypeObject BPy_NParticleState_Type = {{{0}}};
+PyTypeObject BPy_NParticleAttributeState_Type = {{{0}}};
void BPy_BPAR_init_types(void)
{
- BPy_NParticleState_Type.tp_basicsize = sizeof(BPy_NParticleState);
+ BPy_NParticleState_Type.tp_basicsize = sizeof(BPy_NParticleState);
+ BPy_NParticleAttributeState_Type.tp_basicsize = sizeof(BPy_NParticleAttributeState);
- BPy_NParticleState_Type.tp_name = "NParticleState";
+ BPy_NParticleState_Type.tp_name = "NParticleState";
+ BPy_NParticleAttributeState_Type.tp_name = "NParticleAttributeState";
- BPy_NParticleState_Type.tp_doc = bpy_nparticlestate_doc;
+ BPy_NParticleState_Type.tp_doc = bpy_nparticlestate_doc;
+ BPy_NParticleAttributeState_Type.tp_doc = bpy_nparticleattributestate_doc;
- BPy_NParticleState_Type.tp_repr = (reprfunc)bpy_nparticlestate_repr;
+ BPy_NParticleState_Type.tp_repr = (reprfunc)bpy_nparticlestate_repr;
+ BPy_NParticleAttributeState_Type.tp_repr = (reprfunc)bpy_nparticleattributestate_repr;
- BPy_NParticleState_Type.tp_getset = bpy_nparticlestate_getseters;
+ BPy_NParticleState_Type.tp_getset = bpy_nparticlestate_getseters;
+ BPy_NParticleAttributeState_Type.tp_getset = bpy_nparticleattributestate_getseters;
- BPy_NParticleState_Type.tp_methods = bpy_nparticlestate_methods;
+ BPy_NParticleState_Type.tp_methods = bpy_nparticlestate_methods;
+ BPy_NParticleAttributeState_Type.tp_methods = bpy_nparticleattributestate_methods;
- BPy_NParticleState_Type.tp_hash = bpy_nparticlestate_hash;
+ BPy_NParticleState_Type.tp_hash = bpy_nparticlestate_hash;
+ BPy_NParticleAttributeState_Type.tp_hash = bpy_nparticleattributestate_hash;
- BPy_NParticleState_Type.tp_dealloc = (destructor)bpy_nparticlestate_dealloc;
+ BPy_NParticleState_Type.tp_dealloc = (destructor)bpy_nparticlestate_dealloc;
+ BPy_NParticleAttributeState_Type.tp_dealloc = (destructor)bpy_nparticleattributestate_dealloc;
- BPy_NParticleState_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_NParticleState_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ BPy_NParticleAttributeState_Type.tp_flags = Py_TPFLAGS_DEFAULT;
PyType_Ready(&BPy_NParticleState_Type);
+ PyType_Ready(&BPy_NParticleAttributeState_Type);
}
@@ -143,6 +190,7 @@ PyObject *BPyInit_bparticles_types(void)
/* bparticles_py_types.c */
MODULE_TYPE_ADD(submodule, BPy_NParticleState_Type);
+ MODULE_TYPE_ADD(submodule, BPy_NParticleAttributeState_Type);
#undef MODULE_TYPE_ADD
@@ -170,3 +218,11 @@ PyObject *BPy_NParticleState_CreatePyObject(NParticleState *state)
return (PyObject *)self;
}
+
+PyObject *BPy_NParticleAttributeState_CreatePyObject(NParticleState *state, NParticleAttributeState *attr)
+{
+ BPy_NParticleAttributeState *self = PyObject_New(BPy_NParticleAttributeState, &BPy_NParticleAttributeState_Type);
+ self->state = state;
+ self->attrstate = attr;
+ return (PyObject *)self;
+}
diff --git a/source/blender/python/bparticles/bparticles_py_types.h b/source/blender/python/bparticles/bparticles_py_types.h
index ad212ad..cc7f509 100644
--- a/source/blender/python/bparticles/bparticles_py_types.h
+++ b/source/blender/python/bparticles/bparticles_py_types.h
@@ -31,18 +31,27 @@
#define __BPARTICLES_PY_TYPES_H__
extern PyTypeObject BPy_NParticleState_Type;
+extern PyTypeObject BPy_NParticleAttributeState_Type;
-#define BPy_NParticleState_Check(v) (Py_TYPE(v) == &BPy_NParticleState_Type)
+#define BPy_NParticleState_Check(v) (Py_TYPE(v) == &BPy_NParticleState_Type)
+#define BPy_NParticleAttributeState_Check(v) (Py_TYPE(v) == &BPy_NParticleAttributeState_Type)
typedef struct BPy_NParticleState {
PyObject_VAR_HEAD
struct NParticleState *state; /* keep first */
} BPy_NParticleState;
+typedef struct BPy_NParticleAttributeState {
+ PyObject_VAR_HEAD
+ struct NParticleState *state; /* keep first */
+ struct NParticleAttributeState *attrstate;
+} BPy_NParticleAttributeState;
+
void BPy_BPAR_init_types(void);
PyObject *BPyInit_bparticles_types(void);
PyObject *BPy_NParticleState_CreatePyObject(NParticleState *state);
+PyObject *BPy_NParticleAttributeState_CreatePyObject(NParticleState *state, NParticleAttributeState *attr);
#endif /* __BPARTICLES_PY_TYPES_H__ */
More information about the Bf-blender-cvs
mailing list