[Bf-blender-cvs] [5e90d3e] particles_refactor: Added 2 functions for looking up particles by their ID in the psys.
Lukas Tönne
noreply at git.blender.org
Tue Apr 22 12:05:44 CEST 2014
Commit: 5e90d3e803760c11fea6fdf377d482a0d2d1021a
Author: Lukas Tönne
Date: Mon Dec 16 09:57:02 2013 +0100
https://developer.blender.org/rB5e90d3e803760c11fea6fdf377d482a0d2d1021a
Added 2 functions for looking up particles by their ID in the psys.
===================================================================
M source/blender/blenkernel/BKE_nparticle.h
M source/blender/blenkernel/intern/nparticle.c
M source/blender/blenlib/BLI_pagedbuffer.h
M source/blender/blenloader/intern/readfile.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_nparticle.h b/source/blender/blenkernel/BKE_nparticle.h
index f914418..f5130ec 100644
--- a/source/blender/blenkernel/BKE_nparticle.h
+++ b/source/blender/blenkernel/BKE_nparticle.h
@@ -36,7 +36,7 @@ struct NParticleState;
struct NParticleAttribute;
/* XXX where to put this? */
-typedef uint32_t ParticleID;
+typedef uint32_t NParticleID;
struct NParticleSystem *BKE_nparticle_system_new(void);
void BKE_nparticle_system_free(struct NParticleSystem *psys);
@@ -50,9 +50,13 @@ void BKE_nparticle_attribute_move(struct NParticleSystem *psys, int from_index,
struct NParticleAttribute *BKE_nparticle_attribute_copy(struct NParticleSystem *to_psys,
struct NParticleSystem *from_psys, struct NParticleAttribute *from_attr);
+
+int BKE_nparticle_find_index(struct NParticleSystem *psys, NParticleID id);
+bool BKE_nparticle_exists(struct NParticleSystem *psys, NParticleID id);
+
typedef struct ParticleIterator {
int index;
- ParticleID pid;
+ NParticleID pid;
} ParticleIterator;
void BKE_nparticle_iter_next(struct ParticleIterator *it);
@@ -60,8 +64,8 @@ bool BKE_nparticle_iter_valid(struct ParticleIterator *it);
struct ParticleIterator BKE_nparticle_state_begin(void);
-float BKE_nparticle_state_get_float(struct NParticleState *state, ParticleID pid, const char *attr);
-void BKE_nparticle_state_set_float(struct NParticleState *state, ParticleID pid, const char *attr, float value);
+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);
#if 0 /* old code */
#include "BLI_math.h"
diff --git a/source/blender/blenkernel/intern/nparticle.c b/source/blender/blenkernel/intern/nparticle.c
index 16f06ca..6a75576 100644
--- a/source/blender/blenkernel/intern/nparticle.c
+++ b/source/blender/blenkernel/intern/nparticle.c
@@ -208,6 +208,27 @@ void BKE_nparticle_attribute_move(NParticleSystem *psys, int from_index, int to_
}
+int BKE_nparticle_find_index(NParticleSystem *psys, NParticleID id)
+{
+ NParticleAttribute *attr_id = psys->attribute_id;
+ bPagedBuffer *pbuf;
+ bPagedBufferIterator it;
+ BLI_assert(attr_id && attr_id->state);
+
+ pbuf = &attr_id->state->data;
+ for (BLI_pbuf_iter_init(pbuf, &it); BLI_pbuf_iter_valid(pbuf, &it); BLI_pbuf_iter_next(pbuf, &it)) {
+ if (*(int*)it.data == id)
+ return it.index;
+ }
+ return -1;
+}
+
+bool BKE_nparticle_exists(NParticleSystem *psys, NParticleID id)
+{
+ return BKE_nparticle_find_index(psys, id) != -1;
+}
+
+
#if 0 /* old code */
#include <assert.h>
#include <stdlib.h>
diff --git a/source/blender/blenlib/BLI_pagedbuffer.h b/source/blender/blenlib/BLI_pagedbuffer.h
index 8d91aa3..ec70e43 100644
--- a/source/blender/blenlib/BLI_pagedbuffer.h
+++ b/source/blender/blenlib/BLI_pagedbuffer.h
@@ -55,7 +55,6 @@ typedef struct bPagedBufferIterator
void BLI_pbuf_iter_init(struct bPagedBuffer *pbuf, struct bPagedBufferIterator *iter);
void BLI_pbuf_iter_next(struct bPagedBuffer *pbuf, struct bPagedBufferIterator *iter);
bool BLI_pbuf_iter_valid(struct bPagedBuffer *pbuf, struct bPagedBufferIterator *iter);
-
void BLI_pbuf_iter_at(struct bPagedBuffer *pbuf, struct bPagedBufferIterator *iter, int index);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index d42be7f..18399ac 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4267,6 +4267,8 @@ static void direct_link_nparticle_system(FileData *fd, NParticleSystem *psys)
if (attr->state)
direct_link_pagedbuffer(fd, &attr->state->data);
}
+
+ psys->attribute_id = newdataadr(fd, psys->attribute_id);
}
More information about the Bf-blender-cvs
mailing list