[Bf-blender-cvs] [eeaa4379aae] master: Simulation: cleanup dna data

Jacques Lucke noreply at git.blender.org
Sat Jul 25 11:54:21 CEST 2020


Commit: eeaa4379aaeb17adf8df168baeb2617d8af506ed
Author: Jacques Lucke
Date:   Sat Jul 25 11:54:06 2020 +0200
Branches: master
https://developer.blender.org/rBeeaa4379aaeb17adf8df168baeb2617d8af506ed

Simulation: cleanup dna data

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

M	source/blender/blenkernel/intern/simulation.cc
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M	source/blender/makesdna/DNA_simulation_types.h
M	source/blender/simulation/intern/simulation_update.cc

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

diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc
index b1c7f50a2af..c0fc8fcb464 100644
--- a/source/blender/blenkernel/intern/simulation.cc
+++ b/source/blender/blenkernel/intern/simulation.cc
@@ -112,9 +112,8 @@ static void simulation_copy_data(Main *bmain, ID *id_dst, const ID *id_src, cons
     BKE_simulation_state_copy_data(state_src, state_dst);
   }
 
-  BLI_listbase_clear(&simulation_dst->persistent_data_handles);
-  BLI_duplicatelist(&simulation_dst->persistent_data_handles,
-                    &simulation_src->persistent_data_handles);
+  BLI_listbase_clear(&simulation_dst->dependencies);
+  BLI_duplicatelist(&simulation_dst->dependencies, &simulation_src->dependencies);
 }
 
 static void simulation_free_data(ID *id)
@@ -131,7 +130,7 @@ static void simulation_free_data(ID *id)
 
   BKE_simulation_state_remove_all(simulation);
 
-  BLI_freelistN(&simulation->persistent_data_handles);
+  BLI_freelistN(&simulation->dependencies);
 }
 
 static void simulation_foreach_id(ID *id, LibraryForeachIDData *data)
@@ -141,9 +140,8 @@ static void simulation_foreach_id(ID *id, LibraryForeachIDData *data)
     /* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
     BKE_library_foreach_ID_embedded(data, (ID **)&simulation->nodetree);
   }
-  LISTBASE_FOREACH (
-      PersistentDataHandleItem *, handle_item, &simulation->persistent_data_handles) {
-    BKE_LIB_FOREACHID_PROCESS_ID(data, handle_item->id, IDWALK_CB_USER);
+  LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) {
+    BKE_LIB_FOREACHID_PROCESS_ID(data, dependency->id, IDWALK_CB_USER);
   }
 }
 
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index db6d5136391..b37029726f4 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8677,9 +8677,8 @@ static void direct_link_volume(BlendDataReader *reader, Volume *volume)
 
 static void lib_link_simulation(BlendLibReader *reader, Simulation *simulation)
 {
-  LISTBASE_FOREACH (
-      PersistentDataHandleItem *, handle_item, &simulation->persistent_data_handles) {
-    BLO_read_id_address(reader, simulation->id.lib, &handle_item->id);
+  LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) {
+    BLO_read_id_address(reader, simulation->id.lib, &dependency->id);
   }
 }
 
@@ -8698,7 +8697,7 @@ static void direct_link_simulation(BlendDataReader *reader, Simulation *simulati
     }
   }
 
-  BLO_read_list(reader, &simulation->persistent_data_handles);
+  BLO_read_list(reader, &simulation->dependencies);
 }
 
 /** \} */
@@ -11107,9 +11106,8 @@ static void expand_simulation(BlendExpander *expander, Simulation *simulation)
   if (simulation->adt) {
     expand_animdata(expander, simulation->adt);
   }
-  LISTBASE_FOREACH (
-      PersistentDataHandleItem *, handle_item, &simulation->persistent_data_handles) {
-    BLO_expand(expander, handle_item->id);
+  LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) {
+    BLO_expand(expander, dependency->id);
   }
 }
 
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 7f3fbee81e3..3db2fada85f 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3862,7 +3862,7 @@ static void write_simulation(BlendWriter *writer, Simulation *simulation, const
       }
     }
 
-    BLO_write_struct_list(writer, PersistentDataHandleItem, &simulation->persistent_data_handles);
+    BLO_write_struct_list(writer, SimulationDependency, &simulation->dependencies);
   }
 }
 
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index b8c98676ea6..d0e8246caa9 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -2636,19 +2636,18 @@ void DepsgraphRelationBuilder::build_simulation(Simulation *simulation)
       &simulation->nodetree->id, NodeType::PARAMETERS, OperationCode::PARAMETERS_EXIT);
   add_relation(nodetree_key, simulation_eval_key, "NodeTree -> Simulation", 0);
 
-  LISTBASE_FOREACH (
-      PersistentDataHandleItem *, handle_item, &simulation->persistent_data_handles) {
-    if (handle_item->id == nullptr) {
+  LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) {
+    if (dependency->id == nullptr) {
       continue;
     }
-    build_id(handle_item->id);
-    if (GS(handle_item->id->name) == ID_OB) {
-      Object *object = (Object *)handle_item->id;
-      if (handle_item->flag & SIM_HANDLE_DEPENDS_ON_TRANSFORM) {
+    build_id(dependency->id);
+    if (GS(dependency->id->name) == ID_OB) {
+      Object *object = (Object *)dependency->id;
+      if (dependency->flag & SIM_DEPENDS_ON_TRANSFORM) {
         ComponentKey object_transform_key(&object->id, NodeType::TRANSFORM);
         add_relation(object_transform_key, simulation_eval_key, "Object Transform -> Simulation");
       }
-      if (handle_item->flag & SIM_HANDLE_DEPENDS_ON_GEOMETRY) {
+      if (dependency->flag & SIM_DEPENDS_ON_GEOMETRY) {
         ComponentKey object_geometry_key(&object->id, NodeType::GEOMETRY);
         add_relation(object_geometry_key, simulation_eval_key, "Object Geometry -> Simulation");
       }
diff --git a/source/blender/makesdna/DNA_simulation_types.h b/source/blender/makesdna/DNA_simulation_types.h
index c0be66dcb30..afc59b422c5 100644
--- a/source/blender/makesdna/DNA_simulation_types.h
+++ b/source/blender/makesdna/DNA_simulation_types.h
@@ -30,16 +30,21 @@ typedef struct Simulation {
 
   struct bNodeTree *nodetree;
 
-  int flag;
+  uint32_t flag;
+
+  /** This is the frame in scene time, that the states correspond to. */
   float current_frame;
+
+  /** Time since the start of the simulation in simulation time (which might differ from scene
+   * time). */
   float current_simulation_time;
   char _pad[4];
 
   /** List containing SimulationState objects. */
   struct ListBase states;
 
-  /** List containing PersistentDataHandleItem objects. */
-  struct ListBase persistent_data_handles;
+  /** List containing SimulationDependency objects. */
+  struct ListBase dependencies;
 } Simulation;
 
 typedef struct SimulationState {
@@ -54,8 +59,8 @@ typedef struct ParticleSimulationState {
   SimulationState head;
 
   /** Contains the state of the particles at time Simulation->current_frame. */
-  int tot_particles;
-  int next_particle_id;
+  int32_t tot_particles;
+  int32_t next_particle_id;
   struct CustomData attributes;
 } ParticleSimulationState;
 
@@ -66,24 +71,25 @@ typedef struct ParticleMeshEmitterSimulationState {
   char _pad[4];
 } ParticleMeshEmitterSimulationState;
 
-/** Stores a mapping between an integer handle and a corresponding ID data block. */
-typedef struct PersistentDataHandleItem {
-  struct PersistentDataHandleItem *next;
-  struct PersistentDataHandleItem *prev;
+/** Stores a reference to data that the simulation depends on. This is partially derived from the
+ * simulation node tree. */
+typedef struct SimulationDependency {
+  struct SimulationDependency *next;
+  struct SimulationDependency *prev;
   struct ID *id;
-  int handle;
-  int flag;
-} PersistentDataHandleItem;
+  int32_t handle;
+  uint32_t flag;
+} SimulationDependency;
 
 /* Simulation.flag */
 enum {
   SIM_DS_EXPAND = (1 << 0),
 };
 
-/* PersistentDataHandleItem.flag */
+/* SimulationDependency.flag */
 enum {
-  SIM_HANDLE_DEPENDS_ON_TRANSFORM = (1 << 0),
-  SIM_HANDLE_DEPENDS_ON_GEOMETRY = (1 << 1),
+  SIM_DEPENDS_ON_TRANSFORM = (1 << 0),
+  SIM_DEPENDS_ON_GEOMETRY = (1 << 1),
 };
 
 #define SIM_TYPE_NAME_PARTICLE_SIMULATION "Particle Simulation"
diff --git a/source/blender/simulation/intern/simulation_update.cc b/source/blender/simulation/intern/simulation_update.cc
index 3303145b891..e0eb9fa4a0f 100644
--- a/source/blender/simulation/intern/simulation_update.cc
+++ b/source/blender/simulation/intern/simulation_update.cc
@@ -115,10 +115,9 @@ void update_simulation_in_depsgraph(Depsgraph *depsgraph,
   collect_simulation_influences(*simulation_cow, resources, influences, required_states);
 
   bke::PersistentDataHandleMap handle_map;
-  LISTBASE_FOREACH (
-      PersistentDataHandleItem *, handle_item, &simulation_orig->persistent_data_handles) {
-    ID *id_cow = DEG_get_evaluated_id(depsgraph, handle_item->id);
-    handle_map.add(handle_item->handle, *id_cow);
+  LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation_orig->dependencies) {
+    ID *id_cow = DEG_get_evaluated_id(depsgraph, dependency->id);
+    handle_map.add(dependency->handle, *id_cow);
   }
 
   if (current_frame == 1) {
@@ -146,28 +145,28 @@ bool update_simulation_dependencies(Simulation *simulation)
   nodes::NodeTreeDependencies dependencies = nodes::find_node_tree_dependencies(
       *simulation->nodetree);
 
-  ListBase *handle_list = &simulation->persistent_data_handles;
+  ListBase *dependency_list = &simulation->dependencies;
 
   bool dependencies_changed = false;
 
-  Map<ID *, PersistentDataHandleItem *> handle_item_by_id;
-  Map<PersistentDataHandleItem *, int> old_flag_by_handle_item;
+  Map<ID *, SimulationDependency *> dependency_by_id;
+  Map<SimulationDependency *, int> old_flag_by_dependency;
   Set<int> used_handles;
 
   /* Remove unused handle items and clear flags that are reinitialized later. */
-  LISTBASE_FOREACH_MUTABLE (PersistentDataHandleItem *, handle_item, handle_list) {
-    if (dependencies.depends_on(handle_item->id)) {
-      handle_item_by_id.add_new(handle_item->id, handle_item);
-      used_handles.add_new(handle_item->handle);
-      old_flag_by_handle_item.add_new(handle_item, handle_item->flag);
-      handle_item->flag &= ~(SIM_HANDLE_DEPENDS_ON_TRANSFORM | SIM_HANDLE_DEPENDS_ON_GEOMETRY);
+  LISTBASE_FOREACH_MUTABLE (SimulationDependency *, dependency, dependency_list) {
+    if (dependencies.depends_on(dependency->id)) {
+      dependency_by_id.add_new(dependency->id, dependency);
+      used_handle

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list