1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup depsgraph
22  *
23  * Evaluation engine entry-points for Depsgraph Engine.
24  */
25 
26 #include "MEM_guardedalloc.h"
27 
28 #include "BLI_listbase.h"
29 #include "BLI_utildefines.h"
30 
31 #include "BKE_scene.h"
32 
33 #include "DNA_object_types.h"
34 #include "DNA_scene_types.h"
35 
36 #include "DEG_depsgraph.h"
37 #include "DEG_depsgraph_query.h"
38 
39 #include "intern/eval/deg_eval.h"
40 #include "intern/eval/deg_eval_flush.h"
41 
42 #include "intern/node/deg_node.h"
43 #include "intern/node/deg_node_operation.h"
44 #include "intern/node/deg_node_time.h"
45 
46 #include "intern/depsgraph.h"
47 
48 namespace deg = blender::deg;
49 
deg_flush_updates_and_refresh(deg::Depsgraph * deg_graph)50 static void deg_flush_updates_and_refresh(deg::Depsgraph *deg_graph)
51 {
52   /* Update the time on the cow scene. */
53   if (deg_graph->scene_cow) {
54     BKE_scene_frame_set(deg_graph->scene_cow, deg_graph->ctime);
55   }
56 
57   deg::deg_graph_flush_updates(deg_graph);
58   deg::deg_evaluate_on_refresh(deg_graph);
59 }
60 
61 /* Evaluate all nodes tagged for updating. */
DEG_evaluate_on_refresh(Depsgraph * graph)62 void DEG_evaluate_on_refresh(Depsgraph *graph)
63 {
64   deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(graph);
65   const Scene *scene = DEG_get_input_scene(graph);
66   const float ctime = BKE_scene_frame_get(scene);
67 
68   if (ctime != deg_graph->ctime) {
69     deg_graph->tag_time_source();
70     deg_graph->ctime = ctime;
71   }
72 
73   deg_flush_updates_and_refresh(deg_graph);
74 }
75 
76 /* Frame-change happened for root scene that graph belongs to. */
DEG_evaluate_on_framechange(Depsgraph * graph,float ctime)77 void DEG_evaluate_on_framechange(Depsgraph *graph, float ctime)
78 {
79   deg::Depsgraph *deg_graph = reinterpret_cast<deg::Depsgraph *>(graph);
80   deg_graph->tag_time_source();
81   deg_graph->ctime = ctime;
82   deg_flush_updates_and_refresh(deg_graph);
83 }
84