Commit: 4b77fb30759d1b62224033fc92c55eef7f3e414a
Author: Dalai Felinto
Date:   Fri Apr 21 11:42:59 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB4b77fb30759d1b62224033fc92c55eef7f3e414a

Move DEG_OBJECT_ITER inside depsgraph

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

M       source/blender/blenkernel/BKE_layer.h
M       source/blender/depsgraph/DEG_depsgraph_query.h
M       source/blender/depsgraph/intern/depsgraph_query.cc
M       source/blender/draw/intern/draw_manager.c
M       source/blender/makesrna/intern/rna_scene.c

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

diff --git a/source/blender/blenkernel/BKE_layer.h 
b/source/blender/blenkernel/BKE_layer.h
index b91ff82dc9f..f19f9a65bb5 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -215,33 +215,6 @@ void BKE_visible_bases_Iterator_end(Iterator *iter);
        ITER_END                                                                
  \
 }
 
-/* temporary hacky solution waiting for CoW depsgraph implementation */
-#define DEG_OBJECT_ITER(graph_, instance_)                                    \
-{                                                                             \
-       Scene *sce_, *scene_ = DAG_get_scene(graph_);                           
  \
-       SceneLayer *sl_ = DAG_get_scene_layer(graph_);                          
  \
-       int flag_ = ~(BASE_FROM_SET);                                           
  \
-                                                                              \
-       /* flush all the depsgraph data to objects */                           
  \
-       Object *instance_;                                                      
  \
-       Base *base_;                                                            
  \
-       for(sce_ = scene_; sce_; sce_ = sce_->set) {                            
  \
-               for (base_ = (sl_)->object_bases.first; base_; base_ = 
base_->next) { \
-                       if ((base_->flag & BASE_VISIBLED) != 0) {               
          \
-                               instance_ = base_->object;                      
              \
-                               instance_->base_flag = (base_->flag | 
BASE_FROM_SET) & flag_; \
-                               instance_->base_collection_properties = 
base_->collection_properties;
-
-#define DEG_OBJECT_ITER_END                                                   \
-                       }                                                       
          \
-               }                                                               
      \
-               if (sce_->set) {                                                
      \
-                       sl_ = BKE_scene_layer_render_active(sce_->set);         
          \
-                       flag_ = ~(BASE_SELECTED | BASE_SELECTABLED);            
          \
-               }                                                               
      \
-       }                                                                       
  \
-}
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/depsgraph/DEG_depsgraph_query.h 
b/source/blender/depsgraph/DEG_depsgraph_query.h
index 430398c113f..9960a1e45e2 100644
--- a/source/blender/depsgraph/DEG_depsgraph_query.h
+++ b/source/blender/depsgraph/DEG_depsgraph_query.h
@@ -36,6 +36,7 @@
 struct ID;
 
 struct Depsgraph;
+struct Iterator;
 struct SceneLayer;
 
 #ifdef __cplusplus
@@ -57,6 +58,22 @@ struct SceneLayer *DAG_get_scene_layer(struct Depsgraph 
*graph);
 /* Get the object as properly evaluated by depsgraph. */
 struct Object *DAG_get_object(struct Depsgraph *depsgraph, struct Object *ob);
 
+/* ************************ DAG iterators ********************* */
+
+void DAG_objects_iterator_begin(struct Iterator *iter, void *data_in);
+void DAG_objects_iterator_next(struct Iterator *iter);
+void DAG_objects_iterator_end(struct Iterator *iter);
+
+/* Temporary hacky solution waiting for cow depsgrpah implementation. */
+#define DEG_OBJECT_ITER(graph_, instance_)                                    \
+       ITER_BEGIN(DAG_objects_iterator_begin,                                  
  \
+                  DAG_objects_iterator_next,                                   
  \
+                  DAG_objects_iterator_end,                                    
  \
+                  graph_, Object *, instance_)
+
+#define DEG_OBJECT_ITER_END                                                   \
+       ITER_END
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/source/blender/depsgraph/intern/depsgraph_query.cc 
b/source/blender/depsgraph/intern/depsgraph_query.cc
index 0fe2d2be396..2fe10766bba 100644
--- a/source/blender/depsgraph/intern/depsgraph_query.cc
+++ b/source/blender/depsgraph/intern/depsgraph_query.cc
@@ -37,6 +37,7 @@ extern "C" {
 #include "BKE_layer.h"
 #include "BKE_main.h"
 
+#include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 
 #include "DEG_depsgraph_query.h"
@@ -99,3 +100,78 @@ Object *DAG_get_object(Depsgraph * /*depsgraph*/, Object 
*ob)
        /* XXX TODO */
        return ob;
 }
+
+/* ************************ DAG ITERATORS ********************* */
+
+typedef struct DAGObjectsIteratorData {
+       Depsgraph *graph;
+       Scene *scene;
+       SceneLayer *scene_layer;
+       Base *base;
+       int flag;
+} DAGObjectsIteratorData;
+
+void DAG_objects_iterator_begin(Iterator *iter, void *data_in)
+{
+       SceneLayer *scene_layer;
+       Depsgraph *graph = (Depsgraph *) data_in;
+       DAGObjectsIteratorData *data = (DAGObjectsIteratorData *)
+                                      
MEM_callocN(sizeof(DAGObjectsIteratorData), __func__);
+       iter->data = data;
+       iter->valid = true;
+
+       data->graph = graph;
+       data->scene = DAG_get_scene(graph);
+       scene_layer = DAG_get_scene_layer(graph);
+       data->flag = ~(BASE_FROM_SET);
+
+       Base base = {(Base *)scene_layer->object_bases.first, NULL};
+       data->base = &base;
+       DAG_objects_iterator_next(iter);
+}
+
+void DAG_objects_iterator_next(Iterator *iter)
+{
+       DAGObjectsIteratorData *data = (DAGObjectsIteratorData *)iter->data;
+       Base *base = data->base->next;
+
+       while (base) {
+               if ((base->flag & data->flag) != BASE_VISIBLED) {
+                       Object *ob = DAG_get_object(data->graph, base->object);
+                       iter->current = ob;
+
+                       /* Flushing depsgraph data. */
+                       ob->base_flag = (base->flag | BASE_FROM_SET) & 
data->flag;
+                       ob->base_collection_properties = 
base->collection_properties;
+                       data->base = base;
+                       return;
+               }
+               base = base->next;
+       }
+
+       /* Look for an object in the next set. */
+       if (data->scene->set) {
+               SceneLayer *scene_layer;
+               data->scene = data->scene->set;
+               data->flag = ~(BASE_SELECTED | BASE_SELECTABLED);
+
+               /* For the sets we use the layer used for rendering. */
+               scene_layer = BKE_scene_layer_render_active(data->scene);
+
+               Base base = {(Base *)scene_layer->object_bases.first, NULL};
+               data->base = &base;
+               DAG_objects_iterator_next(iter);
+               return;
+       }
+
+       iter->current = NULL;
+       iter->valid = false;
+}
+
+void DAG_objects_iterator_end(Iterator *iter)
+{
+       DAGObjectsIteratorData *data = (DAGObjectsIteratorData *)iter->data;
+       if (data) {
+               MEM_freeN(data);
+       }
+}
diff --git a/source/blender/draw/intern/draw_manager.c 
b/source/blender/draw/intern/draw_manager.c
index 3ef317f9c8a..bac64020309 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -32,6 +32,7 @@
 
 #include "BIF_glutil.h"
 
+#include "BKE_depsgraph.h"
 #include "BKE_global.h"
 
 #include "BLT_translation.h"
@@ -1853,8 +1854,8 @@ void DRW_draw_view(const bContext *C)
        if (cache_is_dirty) {
                DRW_engines_cache_init();
 
-               Depsgraph *depsgraph = CTX_data_depsgraph(C);
-               DEG_OBJECT_ITER(depsgraph, ob);
+               Depsgraph *graph = CTX_data_depsgraph(C);
+               DEG_OBJECT_ITER(graph, ob);
                {
                        DRW_engines_cache_populate(ob);
                }
diff --git a/source/blender/makesrna/intern/rna_scene.c 
b/source/blender/makesrna/intern/rna_scene.c
index 72bf65f1671..7f1b291d6f4 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2852,6 +2852,7 @@ static void rna_SceneLayer_update_tagged(SceneLayer 
*UNUSED(sl), bContext *C)
        {
                /* Don't do anything, we just need to run the iterator to flush
                 * the base info to the objects. */
+               UNUSED_VARS(ob);
        }
        DEG_OBJECT_ITER_END
 }

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

Reply via email to