[Bf-blender-cvs] [ff86d468050] blenloader-api: move point cache reading to blenkernel

Jacques Lucke noreply at git.blender.org
Sat Mar 7 16:24:17 CET 2020


Commit: ff86d46805038fc796a5e6a93d64f5eb1ba0b0ed
Author: Jacques Lucke
Date:   Sat Mar 7 16:06:15 2020 +0100
Branches: blenloader-api
https://developer.blender.org/rBff86d46805038fc796a5e6a93d64f5eb1ba0b0ed

move point cache reading to blenkernel

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

M	source/blender/blenkernel/BKE_pointcache.h
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/blenloader/BLO_callback_api.h
M	source/blender/blenloader/intern/readfile.c

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

diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index 1d9f18e4eef..aa68de4684c 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -343,6 +343,10 @@ int BKE_ptcache_read(PTCacheID *pid, float cfra, bool no_extrapolate_old);
 int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra);
 
 void BKE_ptcache_file_write(struct BloWriter *writer, struct ListBase *ptcaches);
+void BKE_ptcache_file_read(struct BloReader *reader,
+                           struct ListBase *ptcaches,
+                           struct PointCache **ocache,
+                           int force_disk);
 
 /******************* Allocate & free ***************/
 struct PointCache *BKE_ptcache_add(struct ListBase *ptcaches);
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 47b26193962..1d33aeee5c6 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -43,6 +43,7 @@
 #include "DNA_fluid_types.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_endian_switch.h"
 #include "BLI_math.h"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
@@ -3347,7 +3348,6 @@ int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra)
  * mode - PTCACHE_CLEAR_ALL,
  */
 
-/* also update in readfile.c */
 static const char *ptcache_data_struct[] = {
     "",          // BPHYS_DATA_INDEX
     "",          // BPHYS_DATA_LOCATION
@@ -3404,6 +3404,81 @@ void BKE_ptcache_file_write(BloWriter *writer, ListBase *ptcaches)
   }
 }
 
+static void file_read_pointcache_cb(BloReader *reader, void *data)
+{
+  PTCacheMem *pm = data;
+  PTCacheExtra *extra;
+  int i;
+  for (i = 0; i < BPHYS_TOT_DATA; i++) {
+    BLO_read_update_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, NULL);
+
+  for (extra = pm->extradata.first; extra; extra = extra->next) {
+    BLO_read_update_address(reader, extra->data);
+  }
+}
+
+static void file_read_pointcache(BloReader *reader, PointCache *cache)
+{
+  if ((cache->flag & PTCACHE_DISK_CACHE) == 0) {
+    BLO_read_list(reader, &cache->mem_cache, file_read_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_file_read(struct BloReader *reader,
+                           struct ListBase *ptcaches,
+                           struct PointCache **ocache,
+                           int force_disk)
+{
+  if (ptcaches->first) {
+    PointCache *cache = NULL;
+    BLO_read_list(reader, ptcaches, NULL);
+    for (cache = ptcaches->first; cache; cache = cache->next) {
+      file_read_pointcache(reader, cache);
+      if (force_disk) {
+        cache->flag |= PTCACHE_DISK_CACHE;
+        cache->step = 1;
+      }
+    }
+
+    BLO_read_update_address(reader, *ocache);
+  }
+  else if (*ocache) {
+    /* old "single" caches need to be linked too */
+    BLO_read_update_address(reader, *ocache);
+    file_read_pointcache(reader, *ocache);
+    if (force_disk) {
+      (*ocache)->flag |= PTCACHE_DISK_CACHE;
+      (*ocache)->step = 1;
+    }
+
+    ptcaches->first = ptcaches->last = *ocache;
+  }
+}
+
 /* Clears & resets */
 void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra)
 {
diff --git a/source/blender/blenloader/BLO_callback_api.h b/source/blender/blenloader/BLO_callback_api.h
index 47378e2c707..5257ca0ef33 100644
--- a/source/blender/blenloader/BLO_callback_api.h
+++ b/source/blender/blenloader/BLO_callback_api.h
@@ -39,6 +39,9 @@ void *BLO_read_new_address(BloReader *reader, const void *old_address);
 bool BLO_read_requires_endian_switch(BloReader *reader);
 #define BLO_read_update_address(reader, ptr) ptr = BLO_read_new_address(reader, ptr)
 
+typedef void (*BloLinkListFn)(BloReader *reader, void *data);
+void BLO_read_list(BloReader *reader, struct ListBase *list, BloLinkListFn callback);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 27564e788fc..b6028da0ea9 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4330,92 +4330,6 @@ static void direct_link_material(FileData *fd, Material *ma)
 /** \name Read ID: Particle Settings
  * \{ */
 
-/* update this also to pointcache.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(FileData *fd, void *data)
-{
-  PTCacheMem *pm = data;
-  PTCacheExtra *extra;
-  int i;
-  for (i = 0; i < BPHYS_TOT_DATA; i++) {
-    pm->data[i] = newdataadr(fd, pm->data[i]);
-
-    /* the cache saves non-struct data without DNA */
-    if (pm->data[i] && ptcache_data_struct[i][0] == '\0' && (fd->flags & FD_FLAGS_SWITCH_ENDIAN)) {
-      /* 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);
-    }
-  }
-
-  link_list(fd, &pm->extradata);
-
-  for (extra = pm->extradata.first; extra; extra = extra->next) {
-    extra->data = newdataadr(fd, extra->data);
-  }
-}
-
-static void direct_link_pointcache(FileData *fd, PointCache *cache)
-{
-  if ((cache->flag & PTCACHE_DISK_CACHE) == 0) {
-    link_list_ex(fd, &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(FileData *fd,
-                                        ListBase *ptcaches,
-                                        PointCache **ocache,
-                                        int force_disk)
-{
-  if (ptcaches->first) {
-    PointCache *cache = NULL;
-    link_list(fd, ptcaches);
-    for (cache = ptcaches->first; cache; cache = cache->next) {
-      direct_link_pointcache(fd, cache);
-      if (force_disk) {
-        cache->flag |= PTCACHE_DISK_CACHE;
-        cache->step = 1;
-      }
-    }
-
-    *ocache = newdataadr(fd, *ocache);
-  }
-  else if (*ocache) {
-    /* old "single" caches need to be linked too */
-    *ocache = newdataadr(fd, *ocache);
-    direct_link_pointcache(fd, *ocache);
-    if (force_disk) {
-      (*ocache)->flag |= PTCACHE_DISK_CACHE;
-      (*ocache)->step = 1;
-    }
-
-    ptcaches->first = ptcaches->last = *ocache;
-  }
-}
-
 static void lib_link_partdeflect(FileData *fd, ID *id, PartDeflect *pd)
 {
   if (pd && pd->tex) {
@@ -4661,7 +4575,7 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles)
       psys->clmd->solver_result = NULL;
     }
 
-    direct_link_pointcache_list(fd, &psys->ptcaches, &psys->pointcache, 0);
+    BKE_ptcache_file_read(wrap_reader(fd), &psys->ptcaches, &psys->pointcache, 0);
     if (psys->clmd) {
       psys->clmd->point_cache = psys->pointcache;
     }
@@ -5394,7 +5308,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb, Object *ob)
       clmd->sim_parms = newdataadr(fd, clmd->sim_parms);
       clmd->coll_parms = newdataadr(fd, clmd->coll_parms);
 
-      direct_link_pointcache_list(fd, &clmd->ptcaches, &clmd->point_cache, 0);
+      BKE_ptcache_file_read(wrap_reader(fd), &clmd->ptcaches, &clmd->point_cache, 0);
 
       if (clmd->sim_parms) {
         if (clmd->sim_parms->presets > 10) {
@@ -5442,8 +5356,8 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb, Object *ob)
           mmd->domain->effector_weights = BKE_effector_add_weights(NULL);
         }
 
-        direct_link_pointcache_list(
-            fd, &(mmd->domain->ptcaches[0]), &(mmd->domain->point_cache[0]), 1);
+        BKE_ptcache_file_read(
+            wrap_reader(fd), &(mmd->domain->ptcaches[0]), &(mmd->domain->point_cache[0]), 1);
 
         /* Manta sim uses only one cache from now on, so store pointer convert */
         if (mmd->domain->ptcaches[1].first || mmd->domain->point_cache[1]) {
@@ -5506,7 +5420,8 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb, Object *ob)
           for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) {
             surface->canvas = pmd->canvas;
             surface->data = NULL;
-            direct_link_pointcache_list(fd, &(surface->ptcaches), &(surface->pointcache), 1);
+            BKE_ptcache_file_read(
+                wrap_reader(fd), &(surface->ptcaches), &(surface->pointcache), 1);
 
             if (!(surface->effector_weights = newdataadr(fd, surface->effector_weights))) {
               surface->effector_weights = BKE_effector_add_weights(NULL);
@@ -5896,11 +5811,12 @@ static void direct_link_object(FileData *fd, Object *ob)
        * We should only do this when sb->shared == NULL, because those pointers
        * are always set (for compatibility with older Blenders). We mustn't link
        * the same pointcache twice. */
-      direct_link_pointcache_list(fd, &sb->ptcaches, &sb->pointcache, false);
+      BKE_ptcache_file_read(wrap_reader(fd), &sb->ptcaches, &sb->pointcache, false);
     }
     else {
       /* link caches */
-      direct_link_pointcache_list(fd, &sb->shared->ptcaches, &sb->shared->pointcache, false);
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list