[Bf-blender-cvs] [f92590e] particles_refactor: Implemented a simple iterator API for particle systems using a plain index and the ID attribute for determining the state size. Have to see how this plays out in terms of performance ...

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


Commit: f92590e39662c59bb931fea8ae846ca9ae39d78b
Author: Lukas Tönne
Date:   Mon Dec 16 10:12:40 2013 +0100
https://developer.blender.org/rBf92590e39662c59bb931fea8ae846ca9ae39d78b

Implemented a simple iterator API for particle systems using a plain
index and the ID attribute for determining the state size. Have to see
how this plays out in terms of performance ...

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

M	source/blender/blenkernel/BKE_nparticle.h
M	source/blender/blenkernel/intern/nparticle.c

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

diff --git a/source/blender/blenkernel/BKE_nparticle.h b/source/blender/blenkernel/BKE_nparticle.h
index f5130ec..5a51eae 100644
--- a/source/blender/blenkernel/BKE_nparticle.h
+++ b/source/blender/blenkernel/BKE_nparticle.h
@@ -54,15 +54,13 @@ struct NParticleAttribute *BKE_nparticle_attribute_copy(struct NParticleSystem *
 int BKE_nparticle_find_index(struct NParticleSystem *psys, NParticleID id);
 bool BKE_nparticle_exists(struct NParticleSystem *psys, NParticleID id);
 
-typedef struct ParticleIterator {
+typedef struct NParticleIterator {
 	int index;
-	NParticleID pid;
-} ParticleIterator;
+} NParticleIterator;
 
-void BKE_nparticle_iter_next(struct ParticleIterator *it);
-bool BKE_nparticle_iter_valid(struct ParticleIterator *it);
-
-struct ParticleIterator BKE_nparticle_state_begin(void);
+void BKE_nparticle_iter_init(struct NParticleSystem *psys, struct NParticleIterator *it);
+void BKE_nparticle_iter_next(struct NParticleSystem *psys, struct NParticleIterator *it);
+bool BKE_nparticle_iter_valid(struct NParticleSystem *psys, struct NParticleIterator *it);
 
 float BKE_nparticle_state_get_float(struct NParticleState *state, NParticleID pid, const char *attr);
 void BKE_nparticle_state_set_float(struct NParticleState *state, NParticleID pid, const char *attr, float value);
diff --git a/source/blender/blenkernel/intern/nparticle.c b/source/blender/blenkernel/intern/nparticle.c
index 6a75576..7442d08 100644
--- a/source/blender/blenkernel/intern/nparticle.c
+++ b/source/blender/blenkernel/intern/nparticle.c
@@ -228,6 +228,23 @@ bool BKE_nparticle_exists(NParticleSystem *psys, NParticleID id)
 	return BKE_nparticle_find_index(psys, id) != -1;
 }
 
+void BKE_nparticle_iter_init(NParticleSystem *UNUSED(psys), NParticleIterator *it)
+{
+	it->index = 0;
+}
+
+void BKE_nparticle_iter_next(NParticleSystem *UNUSED(psys), NParticleIterator *it)
+{
+	++it->index;
+}
+
+bool BKE_nparticle_iter_valid(NParticleSystem *psys, NParticleIterator *it)
+{
+	NParticleAttribute *attr_id = psys->attribute_id;
+	BLI_assert(attr_id);
+	return attr_id->state ? it->index < attr_id->state->data.totelem : false;
+}
+
 
 #if 0 /* old code */
 #include <assert.h>




More information about the Bf-blender-cvs mailing list