[Bf-blender-cvs] [f3d1522] particles_refactor: Basic submodule 'types' in bparticles, defining a PyObject type for the particle state.

Lukas Tönne noreply at git.blender.org
Tue Apr 22 12:06:10 CEST 2014


Commit: f3d1522272cfeaaca3f43563882315e0957b1561
Author: Lukas Tönne
Date:   Wed Dec 18 17:49:01 2013 +0100
https://developer.blender.org/rBf3d1522272cfeaaca3f43563882315e0957b1561

Basic submodule 'types' in bparticles, defining a PyObject type for
the particle state.

===================================================================

M	source/blender/blenkernel/BKE_nparticle.h
M	source/blender/blenkernel/intern/nparticle.c
M	source/blender/makesdna/DNA_nparticle_types.h
M	source/blender/python/bparticles/CMakeLists.txt
M	source/blender/python/bparticles/bparticles_py_api.c
A	source/blender/python/bparticles/bparticles_py_types.c
A	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 5529864..bcd337f 100644
--- a/source/blender/blenkernel/BKE_nparticle.h
+++ b/source/blender/blenkernel/BKE_nparticle.h
@@ -44,6 +44,10 @@ struct NParticleSystem *BKE_nparticle_system_new(void);
 void BKE_nparticle_system_free(struct NParticleSystem *psys);
 struct NParticleSystem *BKE_nparticle_system_copy(struct NParticleSystem *psys);
 
+struct NParticleState *BKE_nparticle_state_new(struct NParticleSystem *psys);
+struct NParticleState *BKE_nparticle_state_copy(struct NParticleState *state);
+void BKE_nparticle_state_free(struct NParticleState *state);
+
 struct NParticleAttribute *BKE_nparticle_attribute_find(struct NParticleSystem *psys, const char *name);
 struct NParticleAttribute *BKE_nparticle_attribute_new(struct NParticleSystem *psys, const char *name, int datatype, int flag);
 void BKE_nparticle_attribute_remove(struct NParticleSystem *psys, struct NParticleAttribute *attr);
diff --git a/source/blender/blenkernel/intern/nparticle.c b/source/blender/blenkernel/intern/nparticle.c
index 4bc6f5e..d44d8d3 100644
--- a/source/blender/blenkernel/intern/nparticle.c
+++ b/source/blender/blenkernel/intern/nparticle.c
@@ -82,41 +82,12 @@ static void nparticle_attribute_state_copy(NParticleAttributeState *to, NParticl
 }
 
 
-static NParticleState *nparticle_state_new(NParticleSystem *UNUSED(psys))
-{
-	NParticleState *state = MEM_callocN(sizeof(NParticleState), "particle state");
-	return state;
-}
-
-static void nparticle_state_free(NParticleState *state)
-{
-	NParticleAttributeState *attrstate;
-	for (attrstate = state->attributes.first; attrstate; attrstate = attrstate->next)
-		nparticle_attribute_state_free(attrstate);
-	BLI_freelistN(&state->attributes);
-	MEM_freeN(state);
-}
-
-static NParticleState *nparticle_state_copy(NParticleState *state)
-{
-	NParticleState *nstate = MEM_dupallocN(state);
-	NParticleAttributeState *attrstate, *nattrstate;
-	
-	BLI_duplicatelist(&state->attributes, &nstate->attributes);
-	
-	for (attrstate = state->attributes.first, nattrstate = nstate->attributes.first;
-	     attrstate;
-	     attrstate = attrstate->next, nattrstate = nattrstate->next)
-		nparticle_attribute_state_copy(nattrstate, attrstate);
-	
-	return nstate;
-}
-
-static void nparticle_state_add_attribute(NParticleState *state, NParticleAttribute *attr)
+static NParticleAttributeState *nparticle_state_add_attribute(NParticleState *state, NParticleAttribute *attr)
 {
 	NParticleAttributeState *attrstate = MEM_callocN(sizeof(NParticleAttributeState), "particle attribute state");
 	nparticle_attribute_state_init(attr, attrstate);
 	BLI_addtail(&state->attributes, attrstate);
+	return attrstate;
 }
 
 static void nparticle_state_remove_attribute(NParticleState *state, const char *name)
@@ -149,7 +120,7 @@ static void nparticle_system_sync_state_attributes(NParticleSystem *psys, NParti
 		
 		/* add missing attributes */
 		if (!attrstate) {
-			nparticle_state_add_attribute(state, attr);
+			attrstate = nparticle_state_add_attribute(state, attr);
 		}
 		
 		attrstate->flag |= PAR_ATTR_STATE_TEST;
@@ -181,9 +152,10 @@ NParticleSystem *BKE_nparticle_system_new(void)
 {
 	NParticleSystem *psys = MEM_callocN(sizeof(NParticleSystem), "nparticle system");
 	
-	psys->state = nparticle_state_new(psys);
 	nparticle_system_default_attributes(psys);
 	
+	psys->state = BKE_nparticle_state_new(psys);
+	
 	return psys;
 }
 
@@ -191,7 +163,7 @@ void BKE_nparticle_system_free(NParticleSystem *psys)
 {
 	BKE_nparticle_attribute_remove_all(psys);
 	
-	nparticle_state_free(psys->state);
+	BKE_nparticle_state_free(psys->state);
 	
 	MEM_freeN(psys);
 }
@@ -207,12 +179,46 @@ NParticleSystem *BKE_nparticle_system_copy(NParticleSystem *psys)
 	}
 	
 	if (psys->state)
-		npsys->state = nparticle_state_copy(psys->state);
+		npsys->state = BKE_nparticle_state_copy(psys->state);
 	
 	return npsys;
 }
 
 
+NParticleState *BKE_nparticle_state_new(NParticleSystem *psys)
+{
+	NParticleState *state = MEM_callocN(sizeof(NParticleState), "particle state");
+	
+	nparticle_system_sync_state_attributes(psys, state);
+	
+	return state;
+}
+
+NParticleState *BKE_nparticle_state_copy(NParticleState *state)
+{
+	NParticleState *nstate = MEM_dupallocN(state);
+	NParticleAttributeState *attrstate, *nattrstate;
+	
+	BLI_duplicatelist(&state->attributes, &nstate->attributes);
+	
+	for (attrstate = state->attributes.first, nattrstate = nstate->attributes.first;
+	     attrstate;
+	     attrstate = attrstate->next, nattrstate = nattrstate->next)
+		nparticle_attribute_state_copy(nattrstate, attrstate);
+	
+	return nstate;
+}
+
+void BKE_nparticle_state_free(NParticleState *state)
+{
+	NParticleAttributeState *attrstate;
+	for (attrstate = state->attributes.first; attrstate; attrstate = attrstate->next)
+		nparticle_attribute_state_free(attrstate);
+	BLI_freelistN(&state->attributes);
+	MEM_freeN(state);
+}
+
+
 NParticleAttribute *BKE_nparticle_attribute_find(NParticleSystem *psys, const char *name)
 {
 	NParticleAttribute *attr;
diff --git a/source/blender/makesdna/DNA_nparticle_types.h b/source/blender/makesdna/DNA_nparticle_types.h
index 985602b..e16010a 100644
--- a/source/blender/makesdna/DNA_nparticle_types.h
+++ b/source/blender/makesdna/DNA_nparticle_types.h
@@ -80,6 +80,8 @@ typedef struct NParticleState {
 	 * could use a GHash instead for O(1) lookup.
 	 */
 	ListBase attributes;
+	
+	void *py_handle;
 } NParticleState;
 
 typedef struct NParticleAttribute {
diff --git a/source/blender/python/bparticles/CMakeLists.txt b/source/blender/python/bparticles/CMakeLists.txt
index 0de2edc..a2b260b 100644
--- a/source/blender/python/bparticles/CMakeLists.txt
+++ b/source/blender/python/bparticles/CMakeLists.txt
@@ -32,8 +32,10 @@ set(INC_SYS
 
 set(SRC
 	bparticles_py_api.c
+	bparticles_py_types.c
 
 	bparticles_py_api.h
+	bparticles_py_types.h
 )
 
 blender_add_lib(bf_python_bparticles "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/python/bparticles/bparticles_py_api.c b/source/blender/python/bparticles/bparticles_py_api.c
index 8675428..9132f03 100644
--- a/source/blender/python/bparticles/bparticles_py_api.c
+++ b/source/blender/python/bparticles/bparticles_py_api.c
@@ -33,14 +33,40 @@
 
 #include "BLI_utildefines.h"
 
+#include "DNA_nparticle_types.h"
+
+#include "BKE_nparticle.h"
+
+#include "bparticles_py_types.h"
+
 #include "../generic/py_capi_utils.h"
 
 #include "bparticles_py_api.h" /* own include */
 
+PyDoc_STRVAR(bpy_bpar_new_doc,
+".. method:: new()\n"
+"\n"
+"   :arg psys: The particle system.\n"
+"   :type mesh: :class:`bpy.types.NParticleSystem`\n"
+"   :return: Return a new, empty NParticleState.\n"
+"   :rtype: :class:`bparticles.types.NParticleState`\n"
+);
+
+static PyObject *bpy_bpar_new(PyObject *UNUSED(self), PyObject *value)
+{
+	NParticleSystem *psys = PyC_RNA_AsPointer(value, "NParticleSystem");
+	NParticleState *state;
+
+	if (!psys)
+		return NULL;
+
+	state = BKE_nparticle_state_new(psys);
+
+	return BPy_NParticleState_CreatePyObject(state);
+}
+
 static struct PyMethodDef BPy_BPAR_methods[] = {
-//	{"new",            (PyCFunction)bpy_bm_new,            METH_NOARGS,  bpy_bm_new_doc},
-//	{"from_edit_mesh", (PyCFunction)bpy_bm_from_edit_mesh, METH_O,       bpy_bm_from_edit_mesh_doc},
-//	{"update_edit_mesh", (PyCFunction)bpy_bm_update_edit_mesh, METH_VARARGS | METH_KEYWORDS, bpy_bm_update_edit_mesh_doc},
+	{"new", (PyCFunction)bpy_bpar_new, METH_O, bpy_bpar_new_doc},
 	{NULL, NULL, 0, NULL}
 };
 
@@ -67,16 +93,16 @@ PyObject *BPyInit_bparticles(void)
 	PyObject *submodule;
 	PyObject *sys_modules = PyThreadState_GET()->interp->modules;
 
-//	BPy_BPAR_init_types();
+	BPy_BPAR_init_types();
 
 	mod = PyModule_Create(&BPy_BPAR_module_def);
 
-#if 0
 	/* bparticles.types */
-	PyModule_AddObject(mod, "types", (submodule = BPyInit_bmesh_types()));
+	PyModule_AddObject(mod, "types", (submodule = BPyInit_bparticles_types()));
 	PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
 	Py_INCREF(submodule);
 
+#if 0
 	PyModule_AddObject(mod, "ops", (submodule = BPyInit_bmesh_ops()));
 	/* PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); */
 	PyDict_SetItemString(sys_modules, "bmesh.ops", submodule); /* fake module */
diff --git a/source/blender/python/bparticles/bparticles_py_types.c b/source/blender/python/bparticles/bparticles_py_types.c
new file mode 100644
index 0000000..878d126
--- /dev/null
+++ b/source/blender/python/bparticles/bparticles_py_types.c
@@ -0,0 +1,172 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2013 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/bparticles/bparticles_py_types.c
+ *  \ingroup pybparticles
+ */
+
+#include <Python.h>
+
+#include "BLI_math.h"
+
+#include "DNA_nparticle_types.h"
+
+#include "BKE_nparticle.h"
+
+#include "../generic/py_capi_utils.h"
+
+#include "bparticles_py_types.h" /* own include */
+
+/* Type Docstrings
+ * =============== */
+
+PyDoc_STRVAR(bpy_nparticlestate_doc,
+"Particle state data\n"
+);
+
+static PyObject *bpy_nparticlestate_repr(BPy_NParticleState *self)
+{
+	NParticleState *state = self->state;
+
+	if (state) {
+		return PyUnicode_FromFormat("<NParticleState(%p)>",
+		                            state);
+	}
+	else {
+		return PyUnicode_FromFormat("<NParticleState dead at %

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list