Commit: aacff413637026eff608560c7218ed93a275674f
Author: Lukas Tönne
Date:   Tue Dec 22 17:18:15 2015 +0100
Branches: object_nodes
https://developer.blender.org/rBaacff413637026eff608560c7218ed93a275674f

Use a std::vector for storing Dupli instances in bvm for efficiency.

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

M       source/blender/blenvm/bvm/bvm_eval.cc
M       source/blender/blenvm/bvm/bvm_eval_common.h
M       source/blender/blenvm/compile/bvm_nodegraph.cc
M       source/blender/blenvm/intern/bvm_api.cc
M       source/blender/blenvm/util/bvm_util_typedesc.h

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

diff --git a/source/blender/blenvm/bvm/bvm_eval.cc 
b/source/blender/blenvm/bvm/bvm_eval.cc
index 2c31475..1a231f8 100644
--- a/source/blender/blenvm/bvm/bvm_eval.cc
+++ b/source/blender/blenvm/bvm/bvm_eval.cc
@@ -145,8 +145,8 @@ static void eval_op_value_mesh(float *stack, StackIndex 
offset)
  */
 static void eval_op_value_duplis(float *stack, StackIndex offset)
 {
-       static ListBase lb = {0};
-       stack_store_duplis(stack, offset, &lb);
+       static DupliList duplis;
+       stack_store_duplis(stack, offset, &duplis);
 }
 
 static void eval_op_float_to_int(float *stack, StackIndex offset_from, 
StackIndex offset_to)
diff --git a/source/blender/blenvm/bvm/bvm_eval_common.h 
b/source/blender/blenvm/bvm/bvm_eval_common.h
index c0ea48f..5482741 100644
--- a/source/blender/blenvm/bvm/bvm_eval_common.h
+++ b/source/blender/blenvm/bvm/bvm_eval_common.h
@@ -94,7 +94,7 @@ inline static duplis_ptr stack_load_duplis_ptr(float *stack, 
StackIndex offset)
        return *(duplis_ptr *)(&stack[offset]);
 }
 
-inline static ListBase *stack_load_duplis(float *stack, StackIndex offset)
+inline static DupliList *stack_load_duplis(float *stack, StackIndex offset)
 {
        return ((duplis_ptr *)(&stack[offset]))->get();
 }
@@ -151,7 +151,7 @@ inline static void stack_store_duplis_ptr(float *stack, 
StackIndex offset, dupli
        *(duplis_ptr *)(&stack[offset]) = p;
 }
 
-inline static void stack_store_duplis(float *stack, StackIndex offset, 
ListBase *lb)
+inline static void stack_store_duplis(float *stack, StackIndex offset, 
DupliList *lb)
 {
        ((duplis_ptr *)(&stack[offset]))->set(lb);
 }
diff --git a/source/blender/blenvm/compile/bvm_nodegraph.cc 
b/source/blender/blenvm/compile/bvm_nodegraph.cc
index 7727a8d..f2cb4be 100644
--- a/source/blender/blenvm/compile/bvm_nodegraph.cc
+++ b/source/blender/blenvm/compile/bvm_nodegraph.cc
@@ -890,8 +890,6 @@ OpCode get_opcode_from_node_type(const string &node)
 }
 
 static mesh_ptr __empty_mesh__;
-static ListBase __empty_listbase__ = {0};
-static duplis_ptr __empty_duplis__ = duplis_ptr(&__empty_listbase__);
 
 static void register_opcode_node_types()
 {
@@ -938,7 +936,7 @@ static void register_opcode_node_types()
        nt->add_output("value", TYPE_MESH);
        
        nt = NodeGraph::add_pass_node_type("PASS_DUPLIS");
-       nt->add_input("value", TYPE_DUPLIS, __empty_duplis__);
+       nt->add_input("value", TYPE_DUPLIS, duplis_ptr(new DupliList()));
        nt->add_output("value", TYPE_DUPLIS);
        
        nt = NodeGraph::add_pass_node_type("PASS_FLOAT_ARRAY");
@@ -1037,7 +1035,7 @@ static void register_opcode_node_types()
        nt->add_output("value", TYPE_MESH);
        
        nt = NodeGraph::add_function_node_type("VALUE_DUPLIS");
-       nt->add_input("value", TYPE_DUPLIS, __empty_duplis__, INPUT_CONSTANT);
+       nt->add_input("value", TYPE_DUPLIS, duplis_ptr(new DupliList()), 
INPUT_CONSTANT);
        nt->add_output("value", TYPE_DUPLIS);
        
        nt = NodeGraph::add_function_node_type("GET_ELEM_FLOAT3");
diff --git a/source/blender/blenvm/intern/bvm_api.cc 
b/source/blender/blenvm/intern/bvm_api.cc
index 5da2581..30d0b56 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -65,8 +65,8 @@ extern "C" {
 
 namespace bvm {
 static mesh_ptr __empty_mesh__;
-static ListBase __empty_listbase__ = {0};
-static duplis_ptr __empty_duplis__ = duplis_ptr(&__empty_listbase__);
+static DupliList __empty_dupli_list__ = DupliList();
+static duplis_ptr __empty_duplis__ = duplis_ptr(&__empty_dupli_list__);
 }
 
 void BVM_init(void)
@@ -1094,17 +1094,19 @@ void BVM_eval_dupli(struct BVMEvalGlobals *globals,
        RNA_id_pointer_create((ID *)object, &object_ptr);
        const void *args[] = { &object_ptr };
        
-       duplis_ptr duplis;
-       void *results[] = { &duplis };
+       duplis_ptr result;
+       void *results[] = { &result };
        
        _CTX(ctx)->eval_function(_GLOBALS(globals), _FUNC(fn), args, results);
        
-       ListBase *lb = duplis.get();
-       if (lb) {
-               for (DupliObject *dob = (DupliObject *)lb->first; dob; dob = 
dob->next) {
-                       BKE_dupli_add_instance(duplicont, dob->ob, dob->mat, 
dob->persistent_id[0],
-                               dob->animated, dob->no_draw, false);
+       DupliList *duplis = result.get();
+       if (duplis) {
+               for (DupliList::const_iterator it = duplis->begin(); it != 
duplis->end(); ++it) {
+                       const Dupli &dupli = *it;
+                       BKE_dupli_add_instance(duplicont, dupli.object, (float 
(*)[4])dupli.transform.data, dupli.index,
+                                              false, dupli.hide, 
dupli.recursive);
                }
-               BLI_freelistN(lb);
+               
+//             delete duplis;
        }
 }
diff --git a/source/blender/blenvm/util/bvm_util_typedesc.h 
b/source/blender/blenvm/util/bvm_util_typedesc.h
index c3abd44..ee0034f 100644
--- a/source/blender/blenvm/util/bvm_util_typedesc.h
+++ b/source/blender/blenvm/util/bvm_util_typedesc.h
@@ -33,6 +33,9 @@
 #define __BVM_TYPE_TRAITS_H__
 
 #include <cassert>
+#include <vector>
+
+#include "MEM_guardedalloc.h"
 
 extern "C" {
 #include "BLI_listbase.h"
@@ -299,13 +302,15 @@ struct DerivedMeshDestructor {
 };
 typedef node_data_ptr<DerivedMesh, DerivedMeshDestructor> mesh_ptr;
 
-struct DuplisDestructor {
-       static void destroy(ListBase *lb)
-       {
-               BLI_freelistN(lb);
-       }
+struct Dupli {
+       Object *object;
+       matrix44 transform;
+       int index;
+       bool hide;
+       bool recursive;
 };
-typedef node_data_ptr<ListBase, DuplisDestructor> duplis_ptr;
+typedef std::vector<Dupli> DupliList;
+typedef node_data_ptr<DupliList> duplis_ptr;
 
 inline void create_empty_mesh(mesh_ptr &p)
 {

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to