[Bf-blender-cvs] [dd5c704ee11] temp-geometry-nodes-evaluator-refactor: add utility context stack builder

Jacques Lucke noreply at git.blender.org
Sun Sep 4 12:53:41 CEST 2022


Commit: dd5c704ee11940eb53de7c71338d9b8c65babdcf
Author: Jacques Lucke
Date:   Sun Sep 4 12:07:54 2022 +0200
Branches: temp-geometry-nodes-evaluator-refactor
https://developer.blender.org/rBdd5c704ee11940eb53de7c71338d9b8c65babdcf

add utility context stack builder

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

M	source/blender/blenlib/BLI_context_stack.hh
M	source/blender/editors/space_node/node_draw.cc

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

diff --git a/source/blender/blenlib/BLI_context_stack.hh b/source/blender/blenlib/BLI_context_stack.hh
index a55afd70817..5cb6d165c57 100644
--- a/source/blender/blenlib/BLI_context_stack.hh
+++ b/source/blender/blenlib/BLI_context_stack.hh
@@ -7,6 +7,7 @@
  */
 
 #include "BLI_array.hh"
+#include "BLI_linear_allocator.hh"
 #include "BLI_stack.hh"
 #include "BLI_string_ref.hh"
 
@@ -77,4 +78,32 @@ class ContextStack {
   friend std::ostream &operator<<(std::ostream &stream, const ContextStack &context_stack);
 };
 
+class ContextStackBuilder {
+ private:
+  LinearAllocator<> allocator_;
+  Vector<destruct_ptr<ContextStack>> contexts_;
+
+ public:
+  const ContextStack *current() const
+  {
+    if (contexts_.is_empty()) {
+      return nullptr;
+    }
+    return contexts_.last().get();
+  }
+
+  const ContextStackHash hash() const
+  {
+    BLI_assert(!contexts_.is_empty());
+    return this->current()->hash();
+  }
+
+  template<typename T, typename... Args> void push(Args &&...args)
+  {
+    const ContextStack *current = this->current();
+    destruct_ptr<T> context = allocator_.construct<T>(current, std::forward<Args>(args)...);
+    contexts_.append(std::move(context));
+  }
+};
+
 }  // namespace blender
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 1955d5e542c..ec7379a2de3 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -329,8 +329,7 @@ static GeoTreeLog *get_geo_tree_log(SpaceNode &snode)
   using namespace blender::nodes;
   using namespace blender::nodes::geo_eval_log;
 
-  LinearAllocator<> allocator;
-  Vector<destruct_ptr<ContextStack>> contexts;
+  ContextStackBuilder context_stack_builder;
 
   if (snode.id == nullptr) {
     return nullptr;
@@ -356,18 +355,17 @@ static GeoTreeLog *get_geo_tree_log(SpaceNode &snode)
     return nullptr;
   }
   GeoModifierLog &modifier_log = *static_cast<GeoModifierLog *>(nmd->runtime_eval_log);
-  contexts.append(allocator.construct<ModifierContextStack>(nullptr, nmd->modifier.name));
+  context_stack_builder.push<ModifierContextStack>(nmd->modifier.name);
   Vector<const bNodeTreePath *> tree_path_vec{snode.treepath};
   if (tree_path_vec.is_empty()) {
     return nullptr;
   }
   for (const bNodeTreePath *path : tree_path_vec.as_span().drop_front(1)) {
-    contexts.append(allocator.construct<NodeGroupContextStack>(
-        &*contexts.last(), path->node_name, path->nodetree->id.name + 2));
+    context_stack_builder.push<NodeGroupContextStack>(path->node_name,
+                                                      path->nodetree->id.name + 2);
   }
 
-  const ContextStack &final_context = *contexts.last();
-  return &modifier_log.get_tree_log(final_context.hash());
+  return &modifier_log.get_tree_log(context_stack_builder.hash());
 }
 
 struct SocketTooltipData {



More information about the Bf-blender-cvs mailing list