Merge branch 'master' into blender2.8
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 16 Jan 2018 15:40:05 +0000 (16:40 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 16 Jan 2018 15:40:05 +0000 (16:40 +0100)
1  2 
source/blender/blenkernel/intern/anim_sys.c
source/blender/makesrna/intern/rna_depsgraph.c

index 82bce6e346d907fe10acdf386044c4b5b0a906e7,21fb29ff06d5518c842153a22d4b174ecacd7ed4..58b476d3da5d63ab4a900edea0eda53d81dc4287
@@@ -60,6 -60,7 +60,6 @@@
  #include "BKE_animsys.h"
  #include "BKE_action.h"
  #include "BKE_context.h"
 -#include "BKE_depsgraph.h"
  #include "BKE_fcurve.h"
  #include "BKE_nla.h"
  #include "BKE_global.h"
@@@ -69,8 -70,6 +69,8 @@@
  #include "BKE_report.h"
  #include "BKE_texture.h"
  
 +#include "DEG_depsgraph.h"
 +
  #include "RNA_access.h"
  
  #include "nla_private.h"
@@@ -96,7 -95,6 +96,7 @@@ bool id_type_can_have_animdata(const sh
                case ID_MA: case ID_TE: case ID_NT:
                case ID_LA: case ID_CA: case ID_WO:
                case ID_LS:
 +              case ID_LP:
                case ID_SPK:
                case ID_SCE:
                case ID_MC:
@@@ -1565,6 -1563,12 +1565,6 @@@ static bool animsys_write_rna_setting(P
        /* caller must ensure this is animatable */
        BLI_assert(RNA_property_animateable(ptr, prop) || ptr->id.data == NULL);
  
 -      /* set value for animatable numerical values only
 -       * HACK: some local F-Curves (e.g. those on NLA Strips) are evaluated
 -       *       without an ID provided, which causes the animateable test to fail!
 -       */
 -      bool written = false;
 -
        switch (RNA_property_type(prop)) {
                case PROP_BOOLEAN:
                {
                        if (array_index != -1) {
                                if (RNA_property_boolean_get_index(ptr, prop, array_index) != value_coerce) {
                                        RNA_property_boolean_set_index(ptr, prop, array_index, value_coerce);
 -                                      written = true;
                                }
                        }
                        else {
                                if (RNA_property_boolean_get(ptr, prop) != value_coerce) {
                                        RNA_property_boolean_set(ptr, prop, value_coerce);
 -                                      written = true;
                                }
                        }
                        break;
                        if (array_index != -1) {
                                if (RNA_property_int_get_index(ptr, prop, array_index) != value_coerce) {
                                        RNA_property_int_set_index(ptr, prop, array_index, value_coerce);
 -                                      written = true;
                                }
                        }
                        else {
                                if (RNA_property_int_get(ptr, prop) != value_coerce) {
                                        RNA_property_int_set(ptr, prop, value_coerce);
 -                                      written = true;
                                }
                        }
                        break;
                        if (array_index != -1) {
                                if (RNA_property_float_get_index(ptr, prop, array_index) != value_coerce) {
                                        RNA_property_float_set_index(ptr, prop, array_index, value_coerce);
 -                                      written = true;
                                }
                        }
                        else {
                                if (RNA_property_float_get(ptr, prop) != value_coerce) {
                                        RNA_property_float_set(ptr, prop, value_coerce);
 -                                      written = true;
                                }
                        }
                        break;
                        const int value_coerce = (int)value;
                        if (RNA_property_enum_get(ptr, prop) != value_coerce) {
                                RNA_property_enum_set(ptr, prop, value_coerce);
 -                              written = true;
                        }
                        break;
                }
        }
  #endif
  
 -      /* as long as we don't do property update, we still tag datablock
 -       * as having been updated. this flag does not cause any updates to
 -       * be run, it's for e.g. render engines to synchronize data */
 -      if (written && ptr->id.data) {
 -              ID *id = ptr->id.data;
 -
 -              /* for cases like duplifarmes it's only a temporary so don't
 -               * notify anyone of updates */
 -              if (!(id->recalc & ID_RECALC_SKIP_ANIM_TAG)) {
 -                      /* NOTE: This is a bit annoying to use atomic API here, but this
 -                       * code is at it's EOL and removed already in 2.8 branch.
 -                       */
 -                      atomic_fetch_and_or_int32(&id->recalc, ID_RECALC);
 -                      DAG_id_type_tag(G.main, GS(id->name));
 -              }
 -      }
 -
        /* successful */
        return true;
  }
@@@ -2589,6 -2617,17 +2589,6 @@@ static void animsys_evaluate_nla(ListBa
                
        /* 3. free temporary evaluation data that's not used elsewhere */
        BLI_freelistN(&estrips);
 -
 -      /* Tag ID as updated so render engines will recognize changes in data
 -       * which is animated but doesn't have actions.
 -       */
 -      if (ptr->id.data != NULL) {
 -              ID *id = ptr->id.data;
 -              if (!(id->recalc & ID_RECALC_SKIP_ANIM_TAG)) {
 -                      id->recalc |= ID_RECALC;
 -                      DAG_id_type_tag(G.main, GS(id->name));
 -              }
 -      }
  }
  
  /* NLA Evaluation function (mostly for use through do_animdata) 
@@@ -2881,17 -2920,17 +2881,17 @@@ void BKE_animsys_evaluate_all_animation
  
  #define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH) printf
  
 -void BKE_animsys_eval_animdata(EvaluationContext *eval_ctx, ID *id)
 +void BKE_animsys_eval_animdata(const EvaluationContext *eval_ctx, ID *id)
  {
        AnimData *adt = BKE_animdata_from_id(id);
        Scene *scene = NULL; /* XXX: this is only needed for flushing RNA updates,
-                             * which should get handled as part of the graph instead...
+                             * which should get handled as part of the dependency graph instead...
                              */
        DEBUG_PRINT("%s on %s, time=%f\n\n", __func__, id->name, (double)eval_ctx->ctime);
        BKE_animsys_evaluate_animdata(scene, id, adt, eval_ctx->ctime, ADT_RECALC_ANIM);
  }
  
 -void BKE_animsys_eval_driver(EvaluationContext *eval_ctx,
 +void BKE_animsys_eval_driver(const EvaluationContext *eval_ctx,
                               ID *id,
                               FCurve *fcu)
  {
index 706fb23ab56a4dc087de2cf4947ecba3a297c6ca,c6b18d8d387c23298a2c70d2d95e105a3c12bb43..e6e1c714008ef9e06bf20aab93003da41ca52c29
  
  #include "DEG_depsgraph.h"
  
 -#include "BKE_depsgraph.h"
 +#include "DNA_object_types.h"
  
  #define STATS_MAX_SIZE 16384
  
  #ifdef RNA_RUNTIME
  
 +#include "BLI_iterator.h"
 +
  #include "DEG_depsgraph_build.h"
  #include "DEG_depsgraph_debug.h"
 +#include "DEG_depsgraph_query.h"
 +
 +#include "MEM_guardedalloc.h"
 +
 +/* **************** Depsgraph **************** */
 +
 +static PointerRNA rna_DepsgraphIter_object_get(PointerRNA *ptr)
 +{
 +      BLI_Iterator *iterator = ptr->data;
 +      return rna_pointer_inherit_refine(ptr, &RNA_Object, iterator->current);
 +}
 +
 +static PointerRNA rna_DepsgraphIter_instance_object_get(PointerRNA *ptr)
 +{
 +      BLI_Iterator *iterator = ptr->data;
 +      DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
 +      Object *instance_object = NULL;
 +      if (deg_iter->dupli_object_current != NULL) {
 +              instance_object = deg_iter->dupli_object_current->ob;
 +      }
 +      return rna_pointer_inherit_refine(ptr, &RNA_Object, instance_object);
 +}
 +
 +static PointerRNA rna_DepsgraphIter_parent_get(PointerRNA *ptr)
 +{
 +      BLI_Iterator *iterator = ptr->data;
 +      DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
 +      Object *dupli_parent = NULL;
 +      if (deg_iter->dupli_object_current != NULL) {
 +              dupli_parent = deg_iter->dupli_parent;
 +      }
 +      return rna_pointer_inherit_refine(ptr, &RNA_Object, dupli_parent);
 +}
 +
 +static void rna_DepsgraphIter_persistent_id_get(PointerRNA *ptr, int *persistent_id)
 +{
 +      BLI_Iterator *iterator = ptr->data;
 +      DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
 +      memcpy(persistent_id, deg_iter->dupli_object_current->persistent_id,
 +             sizeof(deg_iter->dupli_object_current->persistent_id));
 +}
 +
 +static void rna_DepsgraphIter_orco_get(PointerRNA *ptr, float *orco)
 +{
 +      BLI_Iterator *iterator = ptr->data;
 +      DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
 +      memcpy(orco, deg_iter->dupli_object_current->orco,
 +             sizeof(deg_iter->dupli_object_current->orco));
 +}
 +
 +static unsigned int rna_DepsgraphIter_random_id_get(PointerRNA *ptr)
 +{
 +      BLI_Iterator *iterator = ptr->data;
 +      DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
 +      return deg_iter->dupli_object_current->random_id;
 +}
 +
 +static void rna_DepsgraphIter_uv_get(PointerRNA *ptr, float *uv)
 +{
 +      BLI_Iterator *iterator = ptr->data;
 +      DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
 +      memcpy(uv, deg_iter->dupli_object_current->uv,
 +             sizeof(deg_iter->dupli_object_current->uv));
 +}
 +
 +static int rna_DepsgraphIter_is_instance_get(PointerRNA *ptr)
 +{
 +      BLI_Iterator *iterator = ptr->data;
 +      DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
 +      return (deg_iter->dupli_object_current != NULL);
 +}
 +
 +/* **************** Depsgraph **************** */
  
- static void rna_Depsgraph_debug_relations_graphviz(Depsgraph *graph,
+ static void rna_Depsgraph_debug_relations_graphviz(Depsgraph *depsgraph,
                                                     const char *filename)
  {
        FILE *f = fopen(filename, "w");
        if (f == NULL) {
                return;
        }
-       DEG_debug_relations_graphviz(graph, f, "Depsgraph");
+       DEG_debug_relations_graphviz(depsgraph, f, "Depsgraph");
        fclose(f);
  }
  
- static void rna_Depsgraph_debug_stats_gnuplot(Depsgraph *graph,
+ static void rna_Depsgraph_debug_stats_gnuplot(Depsgraph *depsgraph,
                                                const char *filename,
                                                const char *output_filename)
  {
        if (f == NULL) {
                return;
        }
-       DEG_debug_stats_gnuplot(graph, f, "Timing Statistics", output_filename);
+       DEG_debug_stats_gnuplot(depsgraph, f, "Timing Statistics", output_filename);
        fclose(f);
  }
  
- static void rna_Depsgraph_debug_tag_update(Depsgraph *graph)
+ static void rna_Depsgraph_debug_tag_update(Depsgraph *depsgraph)
  {
-       DEG_graph_tag_relations_update(graph);
+       DEG_graph_tag_relations_update(depsgraph);
  }
  
- static void rna_Depsgraph_debug_stats(Depsgraph *graph, char *result)
+ static void rna_Depsgraph_debug_stats(Depsgraph *depsgraph, char *result)
  {
        size_t outer, ops, rels;
-       DEG_stats_simple(graph, &outer, &ops, &rels);
+       DEG_stats_simple(depsgraph, &outer, &ops, &rels);
        BLI_snprintf(result, STATS_MAX_SIZE,
                    "Approx %lu Operations, %lu Relations, %lu Outer Nodes",
 -                  ops, rels, outer);
 +                   ops, rels, outer);
 +}
 +
 +/* Iteration over objects, simple version */
 +
 +static void rna_Depsgraph_objects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 +{
 +      iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
 +      DEGObjectIterData *data = MEM_callocN(sizeof(DEGObjectIterData), __func__);
 +
 +      data->graph = (Depsgraph *)ptr->data;
 +      data->flag = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
 +                   DEG_ITER_OBJECT_FLAG_VISIBLE |
 +                   DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET;
 +      data->mode = DEG_ITER_OBJECT_MODE_RENDER;
 +
 +      ((BLI_Iterator *)iter->internal.custom)->valid = true;
 +      DEG_iterator_objects_begin(iter->internal.custom, data);
 +      iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
 +}
 +
 +static void rna_Depsgraph_objects_next(CollectionPropertyIterator *iter)
 +{
 +      DEG_iterator_objects_next(iter->internal.custom);
 +      iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
 +}
 +
 +static void rna_Depsgraph_objects_end(CollectionPropertyIterator *iter)
 +{
 +      DEG_iterator_objects_end(iter->internal.custom);
 +      MEM_freeN(((BLI_Iterator *)iter->internal.custom)->data);
 +      MEM_freeN(iter->internal.custom);
 +}
 +
 +static PointerRNA rna_Depsgraph_objects_get(CollectionPropertyIterator *iter)
 +{
 +      Object *ob = ((BLI_Iterator *)iter->internal.custom)->current;
 +      return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ob);
 +}
 +
 +/* Iteration over objects, extended version
 + *
 + * Contains extra information about duplicator and persistent ID.
 + */
 +
 +static void rna_Depsgraph_duplis_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 +{
 +      iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
 +      DEGObjectIterData *data = MEM_callocN(sizeof(DEGObjectIterData), __func__);
 +
 +      data->graph = (Depsgraph *)ptr->data;
 +      data->flag = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
 +                   DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |
 +                   DEG_ITER_OBJECT_FLAG_VISIBLE |
 +                   DEG_ITER_OBJECT_FLAG_DUPLI;
 +      data->mode = DEG_ITER_OBJECT_MODE_RENDER;
 +
 +      ((BLI_Iterator *)iter->internal.custom)->valid = true;
 +      DEG_iterator_objects_begin(iter->internal.custom, data);
 +      iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
 +}
 +
 +static void rna_Depsgraph_duplis_next(CollectionPropertyIterator *iter)
 +{
 +      DEG_iterator_objects_next(iter->internal.custom);
 +      iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
 +}
 +
 +static void rna_Depsgraph_duplis_end(CollectionPropertyIterator *iter)
 +{
 +      DEG_iterator_objects_end(iter->internal.custom);
 +      MEM_freeN(((BLI_Iterator *)iter->internal.custom)->data);
 +      MEM_freeN(iter->internal.custom);
 +}
 +
 +static PointerRNA rna_Depsgraph_duplis_get(CollectionPropertyIterator *iter)
 +{
 +      BLI_Iterator *iterator = (BLI_Iterator *)iter->internal.custom;
 +      return rna_pointer_inherit_refine(&iter->parent, &RNA_DepsgraphIter, iterator);
 +}
 +
 +static ID *rna_Depsgraph_evaluated_id_get(Depsgraph *depsgraph, ID *id_orig)
 +{
 +      return DEG_get_evaluated_id(depsgraph, id_orig);
  }
  
  #else
  
 +static void rna_def_depsgraph_iter(BlenderRNA *brna)
 +{
 +      StructRNA *srna;
 +      PropertyRNA *prop;
 +
 +      srna = RNA_def_struct(brna, "DepsgraphIter", NULL);
 +      RNA_def_struct_ui_text(srna, "Dependency Graph Iterator",
 +                             "Extended information about dependency graph object iterator");
 +
 +      prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_struct_type(prop, "Object");
 +      RNA_def_property_ui_text(prop, "Object", "Object the iterator points to");
 +      RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
 +      RNA_def_property_pointer_funcs(prop, "rna_DepsgraphIter_object_get", NULL, NULL, NULL);
 +
 +      prop = RNA_def_property(srna, "instance_object", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_struct_type(prop, "Object");
 +      RNA_def_property_ui_text(prop, "Instance Object", "Object which is being instanced by this iterator");
 +      RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
 +      RNA_def_property_pointer_funcs(prop, "rna_DepsgraphIter_instance_object_get", NULL, NULL, NULL);
 +
 +      prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
 +      RNA_def_property_struct_type(prop, "Object");
 +      RNA_def_property_ui_text(prop, "Parent", "Parent of the duplication list");
 +      RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
 +      RNA_def_property_pointer_funcs(prop, "rna_DepsgraphIter_parent_get", NULL, NULL, NULL);
 +
 +      prop = RNA_def_property(srna, "persistent_id", PROP_INT, PROP_NONE);
 +      RNA_def_property_ui_text(prop, "Persistent ID",
 +                               "Persistent identifier for inter-frame matching of objects with motion blur");
 +      RNA_def_property_array(prop, 2 * MAX_DUPLI_RECUR);
 +      RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
 +      RNA_def_property_int_funcs(prop, "rna_DepsgraphIter_persistent_id_get", NULL, NULL);
 +
 +      prop = RNA_def_property(srna, "orco", PROP_FLOAT, PROP_TRANSLATION);
 +      RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
 +      /* Seems system is not smart enough to figure that getter function should return
 +       * array for PROP_TRANSLATION.
 +       */
 +      RNA_def_property_array(prop, 3);
 +      RNA_def_property_ui_text(prop, "Generated Coordinates", "Generated coordinates in parent object space");
 +      RNA_def_property_float_funcs(prop, "rna_DepsgraphIter_orco_get", NULL, NULL);
 +
 +      prop = RNA_def_property(srna, "random_id", PROP_INT, PROP_UNSIGNED);
 +      RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
 +      RNA_def_property_ui_text(prop, "Dupli random id", "Random id for this dupli object");
 +      RNA_def_property_int_funcs(prop, "rna_DepsgraphIter_random_id_get", NULL, NULL);
 +
 +      prop = RNA_def_property(srna, "uv", PROP_FLOAT, PROP_NONE);
 +      RNA_def_property_ui_text(prop, "UV Coordinates", "UV coordinates in parent object space");
 +      RNA_def_property_array(prop, 2);
 +      RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
 +      RNA_def_property_float_funcs(prop, "rna_DepsgraphIter_uv_get", NULL, NULL);
 +
 +      prop = RNA_def_property(srna, "is_instance", PROP_BOOLEAN, PROP_NONE);
 +      RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
 +      RNA_def_property_ui_text(prop, "Is Instance", "Denotes whether the object is ocming from dupli-list");
 +      RNA_def_property_boolean_funcs(prop, "rna_DepsgraphIter_is_instance_get", NULL);
 +}
 +
  static void rna_def_depsgraph(BlenderRNA *brna)
  {
        StructRNA *srna;
        FunctionRNA *func;
        PropertyRNA *parm;
 +      PropertyRNA *prop;
  
        srna = RNA_def_struct(brna, "Depsgraph", NULL);
        RNA_def_struct_ui_text(srna, "Dependency Graph", "");
        parm = RNA_def_string(func, "result", NULL, STATS_MAX_SIZE, "result", "");
        RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0); /* needed for string return value */
        RNA_def_function_output(func, parm);
 +
 +      prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
 +      RNA_def_property_struct_type(prop, "Object");
 +      RNA_def_property_collection_funcs(prop,
 +                                        "rna_Depsgraph_objects_begin",
 +                                        "rna_Depsgraph_objects_next",
 +                                        "rna_Depsgraph_objects_end",
 +                                        "rna_Depsgraph_objects_get",
 +                                        NULL, NULL, NULL, NULL);
 +
 +      func = RNA_def_function(srna, "evaluated_id_get", "rna_Depsgraph_evaluated_id_get");
 +      parm = RNA_def_pointer(func, "id", "ID", "", "Original ID to get evaluated complementary part for");
 +      RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
 +      parm = RNA_def_pointer(func, "evaluated_id", "ID", "", "Evaluated ID for the given original one");
 +      RNA_def_function_return(func, parm);
 +
 +      /* TODO(sergey): Find a better name. */
 +      prop = RNA_def_property(srna, "duplis", PROP_COLLECTION, PROP_NONE);
 +      RNA_def_property_struct_type(prop, "DepsgraphIter");
 +      RNA_def_property_collection_funcs(prop,
 +                                        "rna_Depsgraph_duplis_begin",
 +                                        "rna_Depsgraph_duplis_next",
 +                                        "rna_Depsgraph_duplis_end",
 +                                        "rna_Depsgraph_duplis_get",
 +                                        NULL, NULL, NULL, NULL);
  }
  
  void RNA_def_depsgraph(BlenderRNA *brna)
  {
 +      rna_def_depsgraph_iter(brna);
        rna_def_depsgraph(brna);
  }