[Bf-blender-cvs] [7dd76329e11] master: Refactor: move PointCache .blend I/O to blenkernel
Jacques Lucke
noreply at git.blender.org
Fri Nov 6 14:42:15 CET 2020
Commit: 7dd76329e11cd5dc13b5804670bee0efe4d51fa6
Author: Jacques Lucke
Date: Fri Nov 6 14:40:49 2020 +0100
Branches: master
https://developer.blender.org/rB7dd76329e11cd5dc13b5804670bee0efe4d51fa6
Refactor: move PointCache .blend I/O to blenkernel
Ref T76372.
===================================================================
M source/blender/blenkernel/BKE_pointcache.h
M source/blender/blenkernel/intern/pointcache.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index a45b134f825..470d53f6655 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -91,6 +91,8 @@ struct RigidBodyWorld;
struct Scene;
struct SoftBody;
struct ViewLayer;
+struct BlendWriter;
+struct BlendDataReader;
/* temp structure for read/write */
typedef struct PTCacheData {
@@ -374,6 +376,14 @@ void BKE_ptcache_validate(struct PointCache *cache, int framenr);
/* Set correct flags after unsuccessful simulation step */
void BKE_ptcache_invalidate(struct PointCache *cache);
+/********************** .blend File I/O *********************/
+
+void BKE_ptcache_blend_write(struct BlendWriter *writer, struct ListBase *ptcaches);
+void BKE_ptcache_blend_read_data(struct BlendDataReader *reader,
+ struct ListBase *ptcaches,
+ struct PointCache **ocache,
+ int force_disk);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 6a93245d995..5c60b39e9c8 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -44,6 +44,7 @@
#include "DNA_simulation_types.h"
#include "BLI_blenlib.h"
+#include "BLI_endian_switch.h"
#include "BLI_math.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@@ -67,6 +68,8 @@
#include "BKE_scene.h"
#include "BKE_softbody.h"
+#include "BLO_read_write.h"
+
#include "BIK_api.h"
#ifdef WITH_BULLET
@@ -3779,3 +3782,124 @@ void BKE_ptcache_invalidate(PointCache *cache)
cache->last_exact = MIN2(cache->startframe, 0);
}
}
+
+static const char *ptcache_data_struct[] = {
+ "", // BPHYS_DATA_INDEX
+ "", // BPHYS_DATA_LOCATION
+ "", // BPHYS_DATA_VELOCITY
+ "", // BPHYS_DATA_ROTATION
+ "", // BPHYS_DATA_AVELOCITY / BPHYS_DATA_XCONST */
+ "", // BPHYS_DATA_SIZE:
+ "", // BPHYS_DATA_TIMES:
+ "BoidData", // case BPHYS_DATA_BOIDS:
+};
+static const char *ptcache_extra_struct[] = {
+ "",
+ "ParticleSpring",
+ "vec3f",
+};
+void BKE_ptcache_blend_write(BlendWriter *writer, ListBase *ptcaches)
+{
+ LISTBASE_FOREACH (PointCache *, cache, ptcaches) {
+ BLO_write_struct(writer, PointCache, cache);
+
+ if ((cache->flag & PTCACHE_DISK_CACHE) == 0) {
+ LISTBASE_FOREACH (PTCacheMem *, pm, &cache->mem_cache) {
+ BLO_write_struct(writer, PTCacheMem, pm);
+
+ for (int i = 0; i < BPHYS_TOT_DATA; i++) {
+ if (pm->data[i] && pm->data_types & (1 << i)) {
+ if (ptcache_data_struct[i][0] == '\0') {
+ BLO_write_raw(writer, MEM_allocN_len(pm->data[i]), pm->data[i]);
+ }
+ else {
+ BLO_write_struct_array_by_name(
+ writer, ptcache_data_struct[i], pm->totpoint, pm->data[i]);
+ }
+ }
+ }
+
+ LISTBASE_FOREACH (PTCacheExtra *, extra, &pm->extradata) {
+ if (ptcache_extra_struct[extra->type][0] == '\0') {
+ continue;
+ }
+ BLO_write_struct(writer, PTCacheExtra, extra);
+ BLO_write_struct_array_by_name(
+ writer, ptcache_extra_struct[extra->type], extra->totdata, extra->data);
+ }
+ }
+ }
+ }
+}
+
+static void direct_link_pointcache_cb(BlendDataReader *reader, void *data)
+{
+ PTCacheMem *pm = data;
+ for (int i = 0; i < BPHYS_TOT_DATA; i++) {
+ BLO_read_data_address(reader, &pm->data[i]);
+
+ /* the cache saves non-struct data without DNA */
+ if (pm->data[i] && ptcache_data_struct[i][0] == '\0' &&
+ BLO_read_requires_endian_switch(reader)) {
+ /* data_size returns bytes. */
+ int tot = (BKE_ptcache_data_size(i) * pm->totpoint) / sizeof(int);
+
+ int *poin = pm->data[i];
+
+ BLI_endian_switch_int32_array(poin, tot);
+ }
+ }
+
+ BLO_read_list(reader, &pm->extradata);
+
+ LISTBASE_FOREACH (PTCacheExtra *, extra, &pm->extradata) {
+ BLO_read_data_address(reader, &extra->data);
+ }
+}
+
+static void direct_link_pointcache(BlendDataReader *reader, PointCache *cache)
+{
+ if ((cache->flag & PTCACHE_DISK_CACHE) == 0) {
+ BLO_read_list_cb(reader, &cache->mem_cache, direct_link_pointcache_cb);
+ }
+ else {
+ BLI_listbase_clear(&cache->mem_cache);
+ }
+
+ cache->flag &= ~PTCACHE_SIMULATION_VALID;
+ cache->simframe = 0;
+ cache->edit = NULL;
+ cache->free_edit = NULL;
+ cache->cached_frames = NULL;
+ cache->cached_frames_len = 0;
+}
+
+void BKE_ptcache_blend_read_data(BlendDataReader *reader,
+ ListBase *ptcaches,
+ PointCache **ocache,
+ int force_disk)
+{
+ if (ptcaches->first) {
+ BLO_read_list(reader, ptcaches);
+ LISTBASE_FOREACH (PointCache *, cache, ptcaches) {
+ direct_link_pointcache(reader, cache);
+ if (force_disk) {
+ cache->flag |= PTCACHE_DISK_CACHE;
+ cache->step = 1;
+ }
+ }
+
+ BLO_read_data_address(reader, ocache);
+ }
+ else if (*ocache) {
+ /* old "single" caches need to be linked too */
+ BLO_read_data_address(reader, ocache);
+ direct_link_pointcache(reader, *ocache);
+ if (force_disk) {
+ (*ocache)->flag |= PTCACHE_DISK_CACHE;
+ (*ocache)->step = 1;
+ }
+
+ ptcaches->first = ptcaches->last = *ocache;
+ }
+}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 727c2c02d2e..da7adad590e 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2746,90 +2746,6 @@ void blo_do_versions_key_uidgen(Key *key)
/** \name Read ID: Particle Settings
* \{ */
-/* update this also to writefile.c */
-static const char *ptcache_data_struct[] = {
- "", /* BPHYS_DATA_INDEX */
- "", /* BPHYS_DATA_LOCATION */
- "", /* BPHYS_DATA_VELOCITY */
- "", /* BPHYS_DATA_ROTATION */
- "", /* BPHYS_DATA_AVELOCITY / BPHYS_DATA_XCONST */
- "", /* BPHYS_DATA_SIZE: */
- "", /* BPHYS_DATA_TIMES: */
- "BoidData", /* case BPHYS_DATA_BOIDS: */
-};
-
-static void direct_link_pointcache_cb(BlendDataReader *reader, void *data)
-{
- PTCacheMem *pm = data;
- for (int i = 0; i < BPHYS_TOT_DATA; i++) {
- BLO_read_data_address(reader, &pm->data[i]);
-
- /* the cache saves non-struct data without DNA */
- if (pm->data[i] && ptcache_data_struct[i][0] == '\0' &&
- BLO_read_requires_endian_switch(reader)) {
- /* data_size returns bytes. */
- int tot = (BKE_ptcache_data_size(i) * pm->totpoint) / sizeof(int);
-
- int *poin = pm->data[i];
-
- BLI_endian_switch_int32_array(poin, tot);
- }
- }
-
- BLO_read_list(reader, &pm->extradata);
-
- LISTBASE_FOREACH (PTCacheExtra *, extra, &pm->extradata) {
- BLO_read_data_address(reader, &extra->data);
- }
-}
-
-static void direct_link_pointcache(BlendDataReader *reader, PointCache *cache)
-{
- if ((cache->flag & PTCACHE_DISK_CACHE) == 0) {
- BLO_read_list_cb(reader, &cache->mem_cache, direct_link_pointcache_cb);
- }
- else {
- BLI_listbase_clear(&cache->mem_cache);
- }
-
- cache->flag &= ~PTCACHE_SIMULATION_VALID;
- cache->simframe = 0;
- cache->edit = NULL;
- cache->free_edit = NULL;
- cache->cached_frames = NULL;
- cache->cached_frames_len = 0;
-}
-
-static void direct_link_pointcache_list(BlendDataReader *reader,
- ListBase *ptcaches,
- PointCache **ocache,
- int force_disk)
-{
- if (ptcaches->first) {
- BLO_read_list(reader, ptcaches);
- LISTBASE_FOREACH (PointCache *, cache, ptcaches) {
- direct_link_pointcache(reader, cache);
- if (force_disk) {
- cache->flag |= PTCACHE_DISK_CACHE;
- cache->step = 1;
- }
- }
-
- BLO_read_data_address(reader, ocache);
- }
- else if (*ocache) {
- /* old "single" caches need to be linked too */
- BLO_read_data_address(reader, ocache);
- direct_link_pointcache(reader, *ocache);
- if (force_disk) {
- (*ocache)->flag |= PTCACHE_DISK_CACHE;
- (*ocache)->step = 1;
- }
-
- ptcaches->first = ptcaches->last = *ocache;
- }
-}
-
static void lib_link_particlesystems(BlendLibReader *reader,
Object *ob,
ID *id,
@@ -2941,7 +2857,7 @@ static void direct_link_particlesystems(BlendDataReader *reader, ListBase *parti
psys->clmd->solver_result = NULL;
}
- direct_link_pointcache_list(reader, &psys->ptcaches, &psys->pointcache, 0);
+ BKE_ptcache_blend_read_data(reader, &psys->ptcaches, &psys->pointcache, 0);
if (psys->clmd) {
psys->clmd->point_cache = psys->pointcache;
}
@@ -3411,7 +3327,7 @@ static void direct_link_modifiers(BlendDataReader *reader, ListBase *lb, Object
BLO_read_data_address(reader, &clmd->sim_parms);
BLO_read_data_address(reader, &clmd->coll_parms);
- direct_link_pointcache_list(reader, &clmd->ptcaches, &clmd->point_cache, 0);
+ BKE_ptcache_blend_read_data(reader, &clmd->ptcaches, &clmd->point_cache, 0);
if (clmd->sim_parms) {
if (clmd->sim_parms->presets > 10) {
@@ -3460,7 +3376,7 @@ static void direct_link_modifiers(BlendDataReader *reader, ListBase *lb, Object
fmd->domain->effector_weights = BKE_effector_add_weights(NULL);
}
- direct_link_pointcache_list(
+ BKE_ptcache_blend_read_data(
reader, &(fmd->domain->ptcaches[0]), &(fmd->domain->point_cache[0]), 1);
/* Manta sim uses only one cache from now on, so store pointer convert */
@@ -3523,7 +3439,7 @@ static void direct_link_modifiers(BlendDataReader *reader, ListBase *lb, Object
LISTBASE_FOREACH (DynamicPaintSurface *, surface, &pmd->canvas->surfaces) {
surface->canvas = pmd->canvas;
surface->data = NULL;
- direct
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list