[Bf-blender-cvs] [e756127] particles_refactor: More restructuring ... Putting state into attributes, otherwise mapping between declared attributes in psys and attribute states becomes very complicated.
Lukas Tönne
noreply at git.blender.org
Tue Apr 22 12:05:37 CEST 2014
Commit: e7561274d7e9e4c7e7a2fafb8df83c8710ad5bcc
Author: Lukas Tönne
Date: Sat Dec 14 10:13:42 2013 +0100
https://developer.blender.org/rBe7561274d7e9e4c7e7a2fafb8df83c8710ad5bcc
More restructuring ... Putting state into attributes, otherwise mapping
between declared attributes in psys and attribute states becomes very
complicated.
===================================================================
M source/blender/blenkernel/BKE_nparticle.h
M source/blender/blenkernel/intern/nparticle.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
M source/blender/makesdna/DNA_nparticle_types.h
M source/blender/makesrna/intern/rna_nparticle.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_nparticle.h b/source/blender/blenkernel/BKE_nparticle.h
index 6d5669d..f914418 100644
--- a/source/blender/blenkernel/BKE_nparticle.h
+++ b/source/blender/blenkernel/BKE_nparticle.h
@@ -29,9 +29,15 @@
* \ingroup bke
*/
+#include "BLI_sys_types.h"
+
struct NParticleSystem;
+struct NParticleState;
struct NParticleAttribute;
+/* XXX where to put this? */
+typedef uint32_t ParticleID;
+
struct NParticleSystem *BKE_nparticle_system_new(void);
void BKE_nparticle_system_free(struct NParticleSystem *psys);
struct NParticleSystem *BKE_nparticle_system_copy(struct NParticleSystem *psys);
@@ -41,6 +47,21 @@ struct NParticleAttribute *BKE_nparticle_attribute_new(struct NParticleSystem *p
void BKE_nparticle_attribute_remove(struct NParticleSystem *psys, struct NParticleAttribute *attr);
void BKE_nparticle_attribute_remove_all(struct NParticleSystem *psys);
void BKE_nparticle_attribute_move(struct NParticleSystem *psys, int from_index, int to_index);
+struct NParticleAttribute *BKE_nparticle_attribute_copy(struct NParticleSystem *to_psys,
+ struct NParticleSystem *from_psys, struct NParticleAttribute *from_attr);
+
+typedef struct ParticleIterator {
+ int index;
+ ParticleID pid;
+} ParticleIterator;
+
+void BKE_nparticle_iter_next(struct ParticleIterator *it);
+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);
#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 cb27482..3050993 100644
--- a/source/blender/blenkernel/intern/nparticle.c
+++ b/source/blender/blenkernel/intern/nparticle.c
@@ -60,6 +60,22 @@ static size_t nparticle_elem_bytes(int datatype)
}
}
+static void nparticle_attribute_state_init(NParticleAttribute *attr, NParticleAttributeState *state)
+{
+ BLI_pbuf_init(&state->data, PAGE_BYTES, nparticle_elem_bytes(attr->desc.datatype));
+}
+
+static void nparticle_attribute_state_free(NParticleAttributeState *state)
+{
+ BLI_pbuf_free(&state->data);
+}
+
+static void nparticle_attribute_state_copy(NParticleAttributeState *to, NParticleAttributeState *from)
+{
+ BLI_pbuf_copy(&to->data, &from->data);
+}
+
+
NParticleSystem *BKE_nparticle_system_new(void)
{
NParticleSystem *psys = MEM_callocN(sizeof(NParticleSystem), "nparticle system");
@@ -68,12 +84,20 @@ NParticleSystem *BKE_nparticle_system_new(void)
void BKE_nparticle_system_free(NParticleSystem *psys)
{
+ BKE_nparticle_attribute_remove_all(psys);
MEM_freeN(psys);
}
NParticleSystem *BKE_nparticle_system_copy(NParticleSystem *psys)
{
NParticleSystem *npsys = MEM_dupallocN(psys);
+ NParticleAttribute *attr;
+
+ npsys->attributes.first = npsys->attributes.last = NULL;
+ for (attr = psys->attributes.first; attr; attr = attr->next) {
+ BKE_nparticle_attribute_copy(npsys, psys, attr);
+ }
+
return npsys;
}
@@ -101,9 +125,11 @@ NParticleAttribute *BKE_nparticle_attribute_new(NParticleSystem *psys, const cha
attr = MEM_callocN(sizeof(NParticleAttribute), "particle system attribute");
BLI_strncpy(attr->desc.name, name, sizeof(attr->desc.name));
attr->desc.datatype = datatype;
- BLI_pbuf_init(&attr->state.data, PAGE_BYTES, nparticle_elem_bytes(datatype));
-
+
BLI_addtail(&psys->attributes, attr);
+
+ attr->state = MEM_callocN(sizeof(NParticleAttributeState), "particle attribute state");
+ nparticle_attribute_state_init(attr, attr->state);
}
return attr;
@@ -111,24 +137,43 @@ NParticleAttribute *BKE_nparticle_attribute_new(NParticleSystem *psys, const cha
void BKE_nparticle_attribute_remove(NParticleSystem *psys, NParticleAttribute *attr)
{
- BLI_remlink(&psys->attributes, attr);
+ if (attr->state) {
+ nparticle_attribute_state_free(attr->state);
+ MEM_freeN(attr->state);
+ }
- BLI_pbuf_free(&attr->state.data);
+ BLI_remlink(&psys->attributes, attr);
MEM_freeN(attr);
}
void BKE_nparticle_attribute_remove_all(NParticleSystem *psys)
{
NParticleAttribute *attr, *attr_next;
+
for (attr = psys->attributes.first; attr; attr = attr_next) {
attr_next = attr->next;
- BLI_pbuf_free(&attr->state.data);
+ if (attr->state) {
+ nparticle_attribute_state_free(attr->state);
+ MEM_freeN(attr->state);
+ }
+
MEM_freeN(attr);
}
psys->attributes.first = psys->attributes.last = NULL;
}
+NParticleAttribute *BKE_nparticle_attribute_copy(NParticleSystem *to_psys, NParticleSystem *UNUSED(from_psys), NParticleAttribute *from_attr)
+{
+ NParticleAttribute *to_attr = MEM_dupallocN(from_attr);
+
+ to_attr->state = MEM_callocN(sizeof(NParticleAttributeState), "particle attribute state");
+ nparticle_attribute_state_init(to_attr, to_attr->state);
+
+ BLI_addtail(&to_psys->attributes, to_attr);
+ return to_attr;
+}
+
void BKE_nparticle_attribute_move(NParticleSystem *psys, int from_index, int to_index)
{
NParticleAttribute *attr;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 4b5630f..d42be7f 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4263,7 +4263,9 @@ static void direct_link_nparticle_system(FileData *fd, NParticleSystem *psys)
link_list(fd, &psys->attributes);
for (attr = psys->attributes.first; attr; attr = attr->next) {
- direct_link_pagedbuffer(fd, &attr->state.data);
+ attr->state = newdataadr(fd, attr->state);
+ if (attr->state)
+ direct_link_pagedbuffer(fd, &attr->state->data);
}
}
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index d8a6790..46ad8c2 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1380,7 +1380,8 @@ static void write_nparticle_system(WriteData *wd, NParticleSystem *psys)
writestruct(wd, DATA, "NParticleSystem", 1, psys);
for (attr = psys->attributes.first; attr; attr = attr->next) {
writestruct(wd, DATA, "NParticleAttribute", 1, attr);
- write_pagedbuffer(wd, &attr->state.data);
+ if (attr->state)
+ write_pagedbuffer(wd, &attr->state->data);
}
}
diff --git a/source/blender/makesdna/DNA_nparticle_types.h b/source/blender/makesdna/DNA_nparticle_types.h
index 37926a4..7f6ebe9 100644
--- a/source/blender/makesdna/DNA_nparticle_types.h
+++ b/source/blender/makesdna/DNA_nparticle_types.h
@@ -55,16 +55,15 @@ typedef struct NParticleAttributeState {
bPagedBuffer data;
} NParticleAttributeState;
-/* Attribute data in a system */
typedef struct NParticleAttribute {
struct NParticleAttribute *next, *prev;
NParticleAttributeDescription desc; /* attribute descriptor */
- NParticleAttributeState state; /* current state data */
+ NParticleAttributeState *state;
} NParticleAttribute;
typedef struct NParticleSystem {
- ListBase attributes; /* NParticleAttribute list, definition of available attributes */
+ ListBase attributes; /* definition of available attributes */
} NParticleSystem;
#endif
diff --git a/source/blender/makesrna/intern/rna_nparticle.c b/source/blender/makesrna/intern/rna_nparticle.c
index 110b7b3..7c4e96a 100644
--- a/source/blender/makesrna/intern/rna_nparticle.c
+++ b/source/blender/makesrna/intern/rna_nparticle.c
@@ -69,11 +69,12 @@ static StructRNA *rna_NParticleAttribute_refine(PointerRNA *ptr)
}
}
+#if 0
/* Returns the RNA type used for data elements in the attribute buffer.
* This is mirrors the collection type (see rna_NParticleAttribute_refine),
* which must also be specified since each collection has a fixed data type.
*/
-static StructRNA *rna_NParticleAttribute_data_srna(NParticleAttribute *attr)
+static StructRNA *rna_NParticleAttributeState_data_srna(NParticleAttribute *attr)
{
switch (attr->desc.datatype) {
case PAR_ATTR_DATATYPE_FLOAT:
@@ -98,6 +99,7 @@ static StructRNA *rna_NParticleAttribute_data_srna(NParticleAttribute *attr)
return &RNA_NParticleDataVoid;
}
}
+#endif
static void rna_NParticleAttribute_datatype_set(PointerRNA *ptr, int value)
{
@@ -106,60 +108,56 @@ static void rna_NParticleAttribute_datatype_set(PointerRNA *ptr, int value)
BLI_assert(false);
}
-static void rna_NParticleAttribute_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+static void rna_NParticleAttributeState_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
- NParticleAttribute *attr = ptr->data;
+ NParticleAttributeState *state = ptr->data;
bPagedBufferIterator *internal = MEM_callocN(sizeof(bPagedBufferIterator), "particle data iterator");
- BLI_pbuf_iter_init(&attr->state.data, internal);
+ BLI_pbuf_iter_init(&state->data, internal);
iter->internal = internal;
- iter->valid = BLI_pbuf_iter_valid(&attr->state.data, internal);
+ iter->valid = BLI_pbuf_iter_valid(&state->data, internal);
}
-static void rna_NParticleAttribute_data_next(CollectionPropertyIterator *iter)
+static void rna_NParticleAttributeState_data_next(CollectionPropertyIterator *iter)
{
- NParticleAttribute *attr = iter->ptr.data;
+ NParticleAttributeState *state = iter->ptr.data;
bPagedBufferIterator *internal = iter->internal;
- BLI_pbuf_iter_next(&attr->state.data, internal);
- iter->valid = BLI_pbuf_iter_valid(&attr->state.data, internal);
+ BLI_pbuf_iter_next(&state->data, internal);
+ iter->valid = BLI_pbuf_iter_valid(&state->data, internal);
}
-static void rna_NParticleAttribute_data_end(CollectionPropertyIterator *iter)
+static void rna_NParticleAttributeState_data_end(CollectionPropertyIterator *iter)
{
MEM_freeN(iter->internal);
iter->internal = NULL;
}
-static PointerRNA rna_NParticleAttribute_data_get(CollectionPropertyIterator *iter)
+static PointerRNA rna_NParticleAttributeState_data_get(CollectionPropertyIterator *iter, StructRNA *data_srna)
{
- NParticleAttribute *attr = iter->ptr.data;
bPagedBufferIterator *internal = iter->internal;
- S
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list