1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
|
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2004 Blender Foundation.
* All rights reserved.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/blenkernel/intern/depsgraph.c
* \ingroup bke
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "MEM_guardedalloc.h"
#ifdef WIN32
# include "BLI_winstuff.h"
#endif
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
#include "BLI_ghash.h"
#include "BLI_threads.h"
#include "DNA_anim_types.h"
#include "DNA_camera_types.h"
#include "DNA_cachefile_types.h"
#include "DNA_group_types.h"
#include "DNA_lamp_types.h"
#include "DNA_lattice_types.h"
#include "DNA_key_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_object_force.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_windowmanager_types.h"
#include "DNA_movieclip_types.h"
#include "DNA_mask_types.h"
#include "DNA_modifier_types.h"
#include "DNA_rigidbody_types.h"
#include "BKE_anim.h"
#include "BKE_animsys.h"
#include "BKE_action.h"
#include "BKE_DerivedMesh.h"
#include "BKE_collision.h"
#include "BKE_effect.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "BKE_idcode.h"
#include "BKE_image.h"
#include "BKE_key.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_material.h"
#include "BKE_mball.h"
#include "BKE_modifier.h"
#include "BKE_object.h"
#include "BKE_paint.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_tracking.h"
#include "GPU_buffers.h"
#include "atomic_ops.h"
#include "depsgraph_private.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_debug.h"
#include "DEG_depsgraph_query.h"
#ifdef WITH_LEGACY_DEPSGRAPH
static SpinLock threaded_update_lock;
void DAG_init(void)
{
BLI_spin_init(&threaded_update_lock);
DEG_register_node_types();
}
void DAG_exit(void)
{
BLI_spin_end(&threaded_update_lock);
DEG_free_node_types();
}
/* Queue and stack operations for dag traversal
*
* the queue store a list of freenodes to avoid successive alloc/dealloc
*/
DagNodeQueue *queue_create(int slots)
{
DagNodeQueue *queue;
DagNodeQueueElem *elem;
int i;
queue = MEM_mallocN(sizeof(DagNodeQueue), "DAG queue");
queue->freenodes = MEM_mallocN(sizeof(DagNodeQueue), "DAG queue");
queue->count = 0;
queue->maxlevel = 0;
queue->first = queue->last = NULL;
elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem3");
elem->node = NULL;
elem->next = NULL;
queue->freenodes->first = queue->freenodes->last = elem;
for (i = 1; i < slots; i++) {
elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem4");
elem->node = NULL;
elem->next = NULL;
queue->freenodes->last->next = elem;
queue->freenodes->last = elem;
}
queue->freenodes->count = slots;
return queue;
}
void queue_raz(DagNodeQueue *queue)
{
DagNodeQueueElem *elem;
elem = queue->first;
if (queue->freenodes->last)
queue->freenodes->last->next = elem;
else
queue->freenodes->first = queue->freenodes->last = elem;
elem->node = NULL;
queue->freenodes->count++;
while (elem->next) {
elem = elem->next;
elem->node = NULL;
queue->freenodes->count++;
}
queue->freenodes->last = elem;
queue->count = 0;
}
void queue_delete(DagNodeQueue *queue)
{
DagNodeQueueElem *elem;
DagNodeQueueElem *temp;
elem = queue->first;
while (elem) {
temp = elem;
elem = elem->next;
MEM_freeN(temp);
}
elem = queue->freenodes->first;
while (elem) {
temp = elem;
elem = elem->next;
MEM_freeN(temp);
}
MEM_freeN(queue->freenodes);
MEM_freeN(queue);
}
/* insert in queue, remove in front */
void push_queue(DagNodeQueue *queue, DagNode *node)
{
DagNodeQueueElem *elem;
int i;
if (node == NULL) {
fprintf(stderr, "pushing null node\n");
return;
}
/*fprintf(stderr, "BFS push : %s %d\n", ((ID *) node->ob)->name, queue->count);*/
elem = queue->freenodes->first;
if (elem != NULL) {
queue->freenodes->first = elem->next;
if (queue->freenodes->last == elem) {
queue->freenodes->last = NULL;
queue->freenodes->first = NULL;
}
queue->freenodes->count--;
}
else { /* alllocating more */
elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem1");
elem->node = NULL;
elem->next = NULL;
queue->freenodes->first = queue->freenodes->last = elem;
for (i = 1; i < DAGQUEUEALLOC; i++) {
elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem2");
elem->node = NULL;
elem->next = NULL;
queue->freenodes->last->next = elem;
queue->freenodes->last = elem;
}
queue->freenodes->count = DAGQUEUEALLOC;
elem = queue->freenodes->first;
queue->freenodes->first = elem->next;
}
elem->next = NULL;
elem->node = node;
if (queue->last != NULL)
queue->last->next = elem;
queue->last = elem;
if (queue->first == NULL) {
queue->first = elem;
}
queue->count++;
}
/* insert in front, remove in front */
void push_stack(DagNodeQueue *queue, DagNode *node)
{
DagNodeQueueElem *elem;
int i;
elem = queue->freenodes->first;
if (elem != NULL) {
queue->freenodes->first = elem->next;
if (queue->freenodes->last == elem) {
queue->freenodes->last = NULL;
queue->freenodes->first = NULL;
}
queue->freenodes->count--;
}
else { /* alllocating more */
elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem1");
elem->node = NULL;
elem->next = NULL;
queue->freenodes->first = queue->freenodes->last = elem;
for (i = 1; i < DAGQUEUEALLOC; i++) {
elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem2");
elem->node = NULL;
elem->next = NULL;
queue->freenodes->last->next = elem;
queue->freenodes->last = elem;
}
queue->freenodes->count = DAGQUEUEALLOC;
elem = queue->freenodes->first;
queue->freenodes->first = elem->next;
}
elem->next = queue->first;
elem->node = node;
queue->first = elem;
if (queue->last == NULL)
queue->last = elem;
queue->count++;
}
DagNode *pop_queue(DagNodeQueue *queue)
{
DagNodeQueueElem *elem;
DagNode *node;
elem = queue->first;
if (elem) {
queue->first = elem->next;
if (queue->last == elem) {
queue->last = NULL;
queue->first = NULL;
}
queue->count--;
if (queue->freenodes->last)
queue->freenodes->last->next = elem;
queue->freenodes->last = elem;
if (queue->freenodes->first == NULL)
queue->freenodes->first = elem;
node = elem->node;
elem->node = NULL;
elem->next = NULL;
queue->freenodes->count++;
return node;
}
else {
fprintf(stderr, "return null\n");
return NULL;
}
}
DagNode *get_top_node_queue(DagNodeQueue *queue)
{
return queue->first->node;
}
DagForest *dag_init(void)
{
DagForest *forest;
/* use callocN to init all zero */
forest = MEM_callocN(sizeof(DagForest), "DAG root");
forest->ugly_hack_sorry = true;
return forest;
}
/* isdata = object data... */
/* XXX this needs to be extended to be more flexible (so that not only objects are evaluated via depsgraph)... */
static void dag_add_driver_relation(AnimData *adt, DagForest *dag, DagNode *node, int isdata)
{
FCurve *fcu;
DagNode *node1;
for (fcu = adt->drivers.first; fcu; fcu = fcu->next) {
ChannelDriver *driver = fcu->driver;
DriverVar *dvar;
int isdata_fcu = (isdata) || (fcu->rna_path && strstr(fcu->rna_path, "modifiers["));
/* loop over variables to get the target relationships */
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
/* only used targets */
DRIVER_TARGETS_USED_LOOPER(dvar)
{
if (dtar->id) {
/* FIXME: other data types need to be added here so that they can work! */
if (GS(dtar->id->name) == ID_OB) {
Object *ob = (Object *)dtar->id;
/* normal channel-drives-channel */
node1 = dag_get_node(dag, dtar->id);
/* check if bone... */
if ((ob->type == OB_ARMATURE) &&
( ((dtar->rna_path) && strstr(dtar->rna_path, "pose.bones[")) ||
((dtar->flag & DTAR_FLAG_STRUCT_REF) && (dtar->pchan_name[0])) ))
{
dag_add_relation(dag, node1, node, isdata_fcu ? DAG_RL_DATA_DATA : DAG_RL_DATA_OB, "Driver");
}
/* check if ob data */
else if (dtar->rna_path && strstr(dtar->rna_path, "data."))
dag_add_relation(dag, node1, node, isdata_fcu ? DAG_RL_DATA_DATA : DAG_RL_DATA_OB, "Driver");
/* normal */
else
dag_add_relation(dag, node1, node, isdata_fcu ? DAG_RL_OB_DATA : DAG_RL_OB_OB, "Driver");
}
}
}
DRIVER_TARGETS_LOOPER_END
}
}
}
/* XXX: forward def for material driver handling... */
static void dag_add_material_driver_relations(DagForest *dag, DagNode *node, Material *ma);
/* recursive handling for shader nodetree drivers */
static void dag_add_shader_nodetree_driver_relations(DagForest *dag, DagNode *node, bNodeTree *ntree)
{
bNode *n;
/* nodetree itself */
if (ntree->adt) {
dag_add_driver_relation(ntree->adt, dag, node, 1);
}
/* nodetree's nodes... */
for (n = ntree->nodes.first; n; n = n->next) {
if (n->id) {
if (GS(n->id->name) == ID_MA) {
dag_add_material_driver_relations(dag, node, (Material *)n->id);
}
else if (n->type == NODE_GROUP) {
dag_add_shader_nodetree_driver_relations(dag, node, (bNodeTree *)n->id);
}
}
}
}
/* recursive handling for material drivers */
static void dag_add_material_driver_relations(DagForest *dag, DagNode *node, Material *ma)
{
/* Prevent infinite recursion by checking (and tagging the material) as having been visited
* already (see build_dag()). This assumes ma->id.tag & LIB_TAG_DOIT isn't set by anything else
* in the meantime... [#32017]
*/
if (ma->id.tag & LIB_TAG_DOIT)
return;
ma->id.tag |= LIB_TAG_DOIT;
/* material itself */
if (ma->adt)
dag_add_driver_relation(ma->adt, dag, node, 1);
/* textures */
// TODO...
//dag_add_texture_driver_relations(DagForest *dag, DagNode *node, ID *id);
/* material's nodetree */
if (ma->nodetree)
dag_add_shader_nodetree_driver_relations(dag, node, ma->nodetree);
ma->id.tag &= ~LIB_TAG_DOIT;
}
/* recursive handling for lamp drivers */
static void dag_add_lamp_driver_relations(DagForest *dag, DagNode *node, Lamp *la)
{
/* Prevent infinite recursion by checking (and tagging the lamp) as having been visited
* already (see build_dag()). This assumes la->id.tag & LIB_TAG_DOIT isn't set by anything else
* in the meantime... [#32017]
*/
if (la->id.tag & LIB_TAG_DOIT)
return;
la->id.tag |= LIB_TAG_DOIT;
/* lamp itself */
if (la->adt)
dag_add_driver_relation(la->adt, dag, node, 1);
/* textures */
// TODO...
//dag_add_texture_driver_relations(DagForest *dag, DagNode *node, ID *id);
/* lamp's nodetree */
if (la->nodetree)
dag_add_shader_nodetree_driver_relations(dag, node, la->nodetree);
la->id.tag &= ~LIB_TAG_DOIT;
}
static void create_collision_relation(DagForest *dag, DagNode *node, Object *ob1, const char *name)
{
DagNode *node2 = dag_get_node(dag, ob1);
dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, name);
}
void dag_add_collision_relations(DagForest *dag, Scene *scene, Object *ob, DagNode *node, Group *group, int layer, unsigned int modifier_type, DagCollobjFilterFunction fn, bool dupli, const char *name)
{
unsigned int numcollobj;
Object **collobjs = get_collisionobjects_ext(scene, ob, group, layer, &numcollobj, modifier_type, dupli);
for (unsigned int i = 0; i < numcollobj; i++) {
Object *ob1 = collobjs[i];
if (!fn || fn(ob1, modifiers_findByType(ob1, modifier_type))) {
create_collision_relation(dag, node, ob1, name);
}
}
if (collobjs)
MEM_freeN(collobjs);
}
void dag_add_forcefield_relations(DagForest *dag, Scene *scene, Object *ob, DagNode *node, EffectorWeights *effector_weights, bool add_absorption, int skip_forcefield, const char *name)
{
ListBase *effectors = pdInitEffectors(scene, ob, effector_weights, false);
if (effectors) {
for (EffectorCache *eff = effectors->first; eff; eff = eff->next) {
if (eff->ob != ob && eff->pd->forcefield != skip_forcefield) {
create_collision_relation(dag, node, eff->ob, name);
if (eff->pd->forcefield == PFIELD_SMOKEFLOW && eff->pd->f_source) {
create_collision_relation(dag, node, eff->pd->f_source, "Smoke Force Domain");
}
if (add_absorption && (eff->pd->flag & PFIELD_VISIBILITY)) {
/* Actual code uses get_collider_cache */
dag_add_collision_relations(dag, scene, ob, node, NULL, eff->ob->lay, eModifierType_Collision, NULL, true, "Force Absorption");
}
}
}
}
pdEndEffectors(&effectors);
}
static void build_dag_object(DagForest *dag, DagNode *scenenode, Main *bmain, Scene *scene, Object *ob, int mask)
{
bConstraint *con;
DagNode *node;
DagNode *node2;
DagNode *node3;
Key *key;
int addtoroot = 1;
node = dag_get_node(dag, ob);
if ((ob->data) && (mask & DAG_RL_DATA)) {
node2 = dag_get_node(dag, ob->data);
dag_add_relation(dag, node, node2, DAG_RL_DATA, "Object-Data Relation");
node2->first_ancestor = ob;
node2->ancestor_count += 1;
}
/* also build a custom data mask for dependencies that need certain layers */
if (ob->type == OB_ARMATURE) {
if (ob->pose) {
bPoseChannel *pchan;
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
for (con = pchan->constraints.first; con; con = con->next) {
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
ListBase targets = {NULL, NULL};
bConstraintTarget *ct;
if (cti && cti->get_constraint_targets) {
cti->get_constraint_targets(con, &targets);
for (ct = targets.first; ct; ct = ct->next) {
if (ct->tar && ct->tar != ob) {
// fprintf(stderr, "armature %s target :%s\n", ob->id.name, target->id.name);
node3 = dag_get_node(dag, ct->tar);
if (ct->subtarget[0]) {
dag_add_relation(dag, node3, node, DAG_RL_OB_DATA | DAG_RL_DATA_DATA, cti->name);
if (ct->tar->type == OB_MESH)
node3->customdata_mask |= CD_MASK_MDEFORMVERT;
}
else if (ELEM(con->type, CONSTRAINT_TYPE_FOLLOWPATH, CONSTRAINT_TYPE_CLAMPTO, CONSTRAINT_TYPE_SPLINEIK))
dag_add_relation(dag, node3, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, cti->name);
else
dag_add_relation(dag, node3, node, DAG_RL_OB_DATA, cti->name);
}
}
if (cti->flush_constraint_targets)
cti->flush_constraint_targets(con, &targets, 1);
}
}
}
}
}
/* driver dependencies, nla modifiers */
#if 0 // XXX old animation system
if (ob->nlastrips.first) {
bActionStrip *strip;
bActionChannel *chan;
for (strip = ob->nlastrips.first; strip; strip = strip->next) {
if (strip->modifiers.first) {
bActionModifier *amod;
for (amod = strip->modifiers.first; amod; amod = amod->next) {
if (amod->ob) {
node2 = dag_get_node(dag, amod->ob);
dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "NLA Strip Modifier");
}
}
}
}
}
#endif // XXX old animation system
if (ob->adt)
dag_add_driver_relation(ob->adt, dag, node, (ob->type == OB_ARMATURE)); // XXX isdata arg here doesn't give an accurate picture of situation
key = BKE_key_from_object(ob);
if (key && key->adt)
dag_add_driver_relation(key->adt, dag, node, 1);
if (ob->modifiers.first) {
ModifierData *md;
for (md = ob->modifiers.first; md; md = md->next) {
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
if (mti->updateDepgraph) mti->updateDepgraph(md, dag, bmain, scene, ob, node);
}
}
if (ob->parent) {
node2 = dag_get_node(dag, ob->parent);
switch (ob->partype) {
case PARSKEL:
dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Parent");
break;
case PARVERT1: case PARVERT3:
dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, "Vertex Parent");
node2->customdata_mask |= CD_MASK_ORIGINDEX;
break;
case PARBONE:
dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, "Bone Parent");
break;
default:
if (ob->parent->type == OB_LATTICE)
dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Lattice Parent");
else if (ob->parent->type == OB_CURVE) {
Curve *cu = ob->parent->data;
if (cu->flag & CU_PATH)
dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, "Curve Parent");
else
dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Curve Parent");
}
else
dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Parent");
break;
}
/* exception case: parent is duplivert */
if (ob->type == OB_MBALL && (ob->parent->transflag & OB_DUPLIVERTS)) {
dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Duplivert");
}
addtoroot = 0;
}
if (ob->proxy) {
node2 = dag_get_node(dag, ob->proxy);
dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Proxy");
/* inverted relation, so addtoroot shouldn't be set to zero */
}
if (ob->transflag & OB_DUPLI) {
if ((ob->transflag & OB_DUPLIGROUP) && ob->dup_group) {
GroupObject *go;
for (go = ob->dup_group->gobject.first; go; go = go->next) {
if (go->ob) {
node2 = dag_get_node(dag, go->ob);
/* node2 changes node1, this keeps animations updated in groups?? not logical? */
dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Dupligroup");
}
}
}
}
/* rigidbody force fields */
if ((ob->type == OB_MESH) || (ob->type == OB_CURVE) || (ob->type == OB_LATTICE)) {
if (ob->rigidbody_object && scene->rigidbody_world) {
dag_add_forcefield_relations(dag, scene, ob, node, scene->rigidbody_world->effector_weights, true, 0, "Force Field");
}
}
/* object data drivers */
if (ob->data) {
AnimData *adt = BKE_animdata_from_id((ID *)ob->data);
if (adt)
dag_add_driver_relation(adt, dag, node, 1);
}
/* object type/data relationships */
switch (ob->type) {
case OB_CAMERA:
{
Camera *cam = (Camera *)ob->data;
if (cam->dof_ob) {
node2 = dag_get_node(dag, cam->dof_ob);
dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Camera DoF");
}
break;
}
case OB_MBALL:
{
Object *mom = BKE_mball_basis_find(scene, ob);
if (mom != ob) {
node2 = dag_get_node(dag, mom);
dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Metaball"); /* mom depends on children! */
}
break;
}
case OB_CURVE:
case OB_FONT:
{
Curve *cu = ob->data;
if (cu->bevobj) {
node2 = dag_get_node(dag, cu->bevobj);
dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Curve Bevel");
}
if (cu->taperobj) {
node2 = dag_get_node(dag, cu->taperobj);
dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Curve Taper");
}
if (ob->type == OB_FONT) {
/* Really rather dirty hack. needs to support font family to work
* reliably on render export.
*
* This totally mimics behavior of regular verts duplication with
* parenting. The only tricky thing here is to get list of objects
* used for the custom "font".
*
* This shouldn't harm so much because this code only runs on DAG
* rebuild and this feature is not that commonly used.
*
* - sergey -
*/
if (cu->family[0] != '\n') {
ListBase *duplilist;
DupliObject *dob;
duplilist = object_duplilist(G.main->eval_ctx, scene, ob);
for (dob = duplilist->first; dob; dob = dob->next) {
node2 = dag_get_node(dag, dob->ob);
dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Object Font");
}
free_object_duplilist(duplilist);
}
if (cu->textoncurve) {
node2 = dag_get_node(dag, cu->textoncurve);
/* Text on curve requires path to be evaluated for the target curve. */
node2->eval_flags |= DAG_EVAL_NEED_CURVE_PATH;
dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Texture On Curve");
}
}
break;
}
}
/* material drivers */
if (ob->totcol) {
int a;
for (a = 1; a <= ob->totcol; a++) {
Material *ma = give_current_material(ob, a);
if (ma) {
/* recursively figure out if there are drivers, and hook these up to this object */
dag_add_material_driver_relations(dag, node, ma);
}
}
}
else if (ob->type == OB_LAMP) {
dag_add_lamp_driver_relations(dag, node, ob->data);
}
/* object constraints */
for (con = ob->constraints.first; con; con = con->next) {
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
ListBase targets = {NULL, NULL};
bConstraintTarget *ct;
if (!cti)
continue;
/* special case for camera tracking -- it doesn't use targets to define relations */
if (ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER, CONSTRAINT_TYPE_OBJECTSOLVER)) {
int depends_on_camera = 0;
if (cti->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
bFollowTrackConstraint *data = (bFollowTrackConstraint *)con->data;
if ((data->clip || data->flag & FOLLOWTRACK_ACTIVECLIP) && data->track[0])
depends_on_camera = 1;
if (data->depth_ob) {
node2 = dag_get_node(dag, data->depth_ob);
dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, cti->name);
}
}
else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER)
depends_on_camera = 1;
if (depends_on_camera && scene->camera) {
node2 = dag_get_node(dag, scene->camera);
dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, cti->name);
}
dag_add_relation(dag, scenenode, node, DAG_RL_SCENE, "Scene Relation");
addtoroot = 0;
}
else if (cti->get_constraint_targets) {
cti->get_constraint_targets(con, &targets);
for (ct = targets.first; ct; ct = ct->next) {
Object *obt;
if (ct->tar)
obt = ct->tar;
else
continue;
node2 = dag_get_node(dag, obt);
if (ELEM(con->type, CONSTRAINT_TYPE_FOLLOWPATH, CONSTRAINT_TYPE_CLAMPTO))
dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, cti->name);
else {
if (ELEM(obt->type, OB_ARMATURE, OB_MESH, OB_LATTICE) && (ct->subtarget[0])) {
dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, cti->name);
if (obt->type == OB_MESH)
node2->customdata_mask |= CD_MASK_MDEFORMVERT;
}
else
dag_add_relation(dag, node2, node, DAG_RL_OB_OB, cti->name);
}
addtoroot = 0;
}
if (cti->flush_constraint_targets)
cti->flush_constraint_targets(con, &targets, 1);
}
}
if (addtoroot == 1)
dag_add_relation(dag, scenenode, node, DAG_RL_SCENE, "Scene Relation");
}
static void build_dag_group(DagForest *dag, DagNode *scenenode, Main *bmain, Scene *scene, Group *group, short mask)
{
GroupObject *go;
if (group->id.tag & LIB_TAG_DOIT)
return;
group->id.tag |= LIB_TAG_DOIT;
for (go = group->gobject.first; go; go = go->next) {
build_dag_object(dag, scenenode, bmain, scene, go->ob, mask);
if (go->ob->dup_group)
build_dag_group(dag, scenenode, bmain, scene, go->ob->dup_group, mask);
}
}
DagForest *build_dag(Main *bmain, Scene *sce, short mask)
{
Base *base;
Object *ob;
DagNode *node;
DagNode *scenenode;
DagForest *dag;
DagAdjList *itA;
dag = sce->theDag;
if (dag)
free_forest(dag);
else {
dag = dag_init();
sce->theDag = dag;
}
dag->need_update = false;
BKE_main_id_tag_idcode(bmain, ID_OB, LIB_TAG_DOIT, false);
/* clear "LIB_TAG_DOIT" flag from all materials, to prevent infinite recursion problems later [#32017] */
BKE_main_id_tag_idcode(bmain, ID_MA, LIB_TAG_DOIT, false);
BKE_main_id_tag_idcode(bmain, ID_LA, LIB_TAG_DOIT, false);
BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
/* add base node for scene. scene is always the first node in DAG */
scenenode = dag_add_node(dag, sce);
/* add current scene objects */
for (base = sce->base.first; base; base = base->next) {
ob = base->object;
ob->id.tag |= LIB_TAG_DOIT;
build_dag_object(dag, scenenode, bmain, sce, ob, mask);
if (ob->proxy)
build_dag_object(dag, scenenode, bmain, sce, ob->proxy, mask);
if (ob->dup_group)
build_dag_group(dag, scenenode, bmain, sce, ob->dup_group, mask);
}
/* There might be situations when object from current scene depends on
* objects form other scene AND objects from other scene has own
* dependencies on objects from other scene.
*
* This is really important to include such indirect dependencies in order
* to keep threaded update safe but since we don't really know if object is
* coming from current scene or another scene we do rather stupid tag-based
* check here: all the objects for which build_dag_object() was called are
* getting tagged with LIB_TAG_DOIT. This way if some node has untagged
* object we know it's an object from other scene.
*
* It should be enough to to it once, because if there's longer chain of
* indirect dependencies, all the new nodes will be added to the end of the
* list, meaning we'll keep covering them in this for loop.
*/
for (node = sce->theDag->DagNode.first; node != NULL; node = node->next) {
if (node->type == ID_OB) {
ob = node->ob;
if ((ob->id.tag & LIB_TAG_DOIT) == 0) {
ob->id.tag |= LIB_TAG_DOIT;
build_dag_object(dag, scenenode, bmain, sce, ob, mask);
if (ob->proxy)
build_dag_object(dag, scenenode, bmain, sce, ob->proxy, mask);
if (ob->dup_group)
build_dag_group(dag, scenenode, bmain, sce, ob->dup_group, mask);
}
}
}
BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
/* Now all relations were built, but we need to solve 1 exceptional case;
* When objects have multiple "parents" (for example parent + constraint working on same object)
* the relation type has to be synced. One of the parents can change, and should give same event to child */
/* nodes were callocced, so we can use node->color for temporal storage */
for (node = sce->theDag->DagNode.first; node; node = node->next) {
if (node->type == ID_OB) {
for (itA = node->child; itA; itA = itA->next) {
if (itA->node->type == ID_OB) {
itA->node->color |= itA->type;
}
}
/* also flush custom data mask */
((Object *)node->ob)->customdata_mask = node->customdata_mask;
if (node->parent == NULL) {
dag_add_relation(dag, scenenode, node, DAG_RL_SCENE, "Scene Relation");
}
}
}
/* now set relations equal, so that when only one parent changes, the correct recalcs are found */
for (node = sce->theDag->DagNode.first; node; node = node->next) {
if (node->type == ID_OB) {
for (itA = node->child; itA; itA = itA->next) {
if (itA->node->type == ID_OB) {
itA->type |= itA->node->color;
}
}
}
}
/* cycle detection and solving */
// solve_cycles(dag);
return dag;
}
void free_forest(DagForest *Dag)
{ /* remove all nodes and deps */
DagNode *tempN;
DagAdjList *tempA;
DagAdjList *itA;
DagNode *itN = Dag->DagNode.first;
while (itN) {
itA = itN->child;
while (itA) {
tempA = itA;
itA = itA->next;
MEM_freeN(tempA);
}
itA = itN->parent;
while (itA) {
tempA = itA;
itA = itA->next;
MEM_freeN(tempA);
}
tempN = itN;
itN = itN->next;
MEM_freeN(tempN);
}
BLI_ghash_free(Dag->nodeHash, NULL, NULL);
Dag->nodeHash = NULL;
Dag->DagNode.first = NULL;
Dag->DagNode.last = NULL;
Dag->numNodes = 0;
}
DagNode *dag_find_node(DagForest *forest, void *fob)
{
if (forest->nodeHash)
return BLI_ghash_lookup(forest->nodeHash, fob);
return NULL;
}
static int dag_print_dependencies = 0; /* debugging */
/* no checking of existence, use dag_find_node first or dag_get_node */
DagNode *dag_add_node(DagForest *forest, void *fob)
{
DagNode *node;
node = MEM_callocN(sizeof(DagNode), "DAG node");
if (node) {
node->ob = fob;
node->color = DAG_WHITE;
if (forest->ugly_hack_sorry) node->type = GS(((ID *) fob)->name); /* sorry, done for pose sorting */
if (forest->numNodes) {
((DagNode *) forest->DagNode.last)->next = node;
forest->DagNode.last = node;
forest->numNodes++;
}
else {
forest->DagNode.last = node;
forest->DagNode.first = node;
forest->numNodes = 1;
}
if (!forest->nodeHash)
forest->nodeHash = BLI_ghash_ptr_new("dag_add_node gh");
BLI_ghash_insert(forest->nodeHash, fob, node);
}
return node;
}
DagNode *dag_get_node(DagForest *forest, void *fob)
{
DagNode *node;
node = dag_find_node(forest, fob);
if (!node)
node = dag_add_node(forest, fob);
return node;
}
DagNode *dag_get_sub_node(DagForest *forest, void *fob)
{
DagNode *node;
DagAdjList *mainchild, *prev = NULL;
mainchild = ((DagNode *) forest->DagNode.first)->child;
/* remove from first node (scene) adj list if present */
while (mainchild) {
if (mainchild->node == fob) {
if (prev) {
prev->next = mainchild->next;
MEM_freeN(mainchild);
break;
}
else {
((DagNode *) forest->DagNode.first)->child = mainchild->next;
MEM_freeN(mainchild);
break;
}
}
prev = mainchild;
mainchild = mainchild->next;
}
node = dag_find_node(forest, fob);
if (!node)
node = dag_add_node(forest, fob);
return node;
}
static void dag_add_parent_relation(DagForest *UNUSED(forest), DagNode *fob1, DagNode *fob2, short rel, const char *name)
{
DagAdjList *itA = fob2->parent;
while (itA) { /* search if relation exist already */
if (itA->node == fob1) {
itA->type |= rel;
itA->count += 1;
return;
}
itA = itA->next;
}
/* create new relation and insert at head. MALLOC alert! */
itA = MEM_mallocN(sizeof(DagAdjList), "DAG adj list");
itA->node = fob1;
itA->type = rel;
itA->count = 1;
itA->next = fob2->parent;
itA->name = name;
fob2->parent = itA;
}
void dag_add_relation(DagForest *forest, DagNode *fob1, DagNode *fob2, short rel, const char *name)
{
DagAdjList *itA = fob1->child;
/* parent relation is for cycle checking */
dag_add_parent_relation(forest, fob1, fob2, rel, name);
/* TODO(sergey): Find a better place for this. */
#ifdef WITH_OPENSUBDIV
if ((rel & (DAG_RL_DATA_DATA | DAG_RL_DATA_OB)) != 0) {
if (fob1->type == ID_OB) {
if ((fob1->eval_flags & DAG_EVAL_NEED_CPU) == 0) {
Object *ob2 = fob2->ob;
if (ob2->recalc & OB_RECALC_ALL) {
/* Make sure object has all the data on CPU. */
Object *ob1 = fob1->ob;
ob1->recalc |= OB_RECALC_DATA;
}
fob1->eval_flags |= DAG_EVAL_NEED_CPU;
}
}
}
#endif
while (itA) { /* search if relation exist already */
if (itA->node == fob2) {
itA->type |= rel;
itA->count += 1;
return;
}
itA = itA->next;
}
/* create new relation and insert at head. MALLOC alert! */
itA = MEM_mallocN(sizeof(DagAdjList), "DAG adj list");
itA->node = fob2;
itA->type = rel;
itA->count = 1;
itA->next = fob1->child;
itA->name = name;
fob1->child = itA;
}
static const char *dag_node_name(DagForest *dag, DagNode *node)
{
if (node->ob == NULL)
return "null";
else if (dag->ugly_hack_sorry)
return ((ID *)(node->ob))->name + 2;
else
return ((bPoseChannel *)(node->ob))->name;
}
static void dag_node_print_dependencies(DagForest *dag, DagNode *node)
{
DagAdjList *itA;
printf("%s depends on:\n", dag_node_name(dag, node));
for (itA = node->parent; itA; itA = itA->next)
printf(" %s through %s\n", dag_node_name(dag, itA->node), itA->name);
printf("\n");
}
static int dag_node_print_dependency_recurs(DagForest *dag, DagNode *node, DagNode *endnode)
{
DagAdjList *itA;
if (node->color == DAG_BLACK)
return 0;
node->color = DAG_BLACK;
if (node == endnode)
return 1;
for (itA = node->parent; itA; itA = itA->next) {
if (dag_node_print_dependency_recurs(dag, itA->node, endnode)) {
printf(" %s depends on %s through %s.\n", dag_node_name(dag, node), dag_node_name(dag, itA->node), itA->name);
return 1;
}
}
return 0;
}
static void dag_node_print_dependency_cycle(DagForest *dag, DagNode *startnode, DagNode *endnode, const char *name)
{
DagNode *node;
for (node = dag->DagNode.first; node; node = node->next)
node->color = DAG_WHITE;
printf(" %s depends on %s through %s.\n", dag_node_name(dag, endnode), dag_node_name(dag, startnode), name);
dag_node_print_dependency_recurs(dag, startnode, endnode);
printf("\n");
}
static int dag_node_recurs_level(DagNode *node, int level)
{
DagAdjList *itA;
int newlevel;
node->color = DAG_BLACK; /* done */
newlevel = ++level;
for (itA = node->parent; itA; itA = itA->next) {
if (itA->node->color == DAG_WHITE) {
itA->node->ancestor_count = dag_node_recurs_level(itA->node, level);
newlevel = MAX2(newlevel, level + itA->node->ancestor_count);
}
else
newlevel = MAX2(newlevel, level + itA->node->ancestor_count);
}
return newlevel;
}
static void dag_check_cycle(DagForest *dag)
{
DagNode *node;
DagAdjList *itA;
dag->is_acyclic = true;
/* debugging print */
if (dag_print_dependencies)
for (node = dag->DagNode.first; node; node = node->next)
dag_node_print_dependencies(dag, node);
/* tag nodes unchecked */
for (node = dag->DagNode.first; node; node = node->next)
node->color = DAG_WHITE;
for (node = dag->DagNode.first; node; node = node->next) {
if (node->color == DAG_WHITE) {
node->ancestor_count = dag_node_recurs_level(node, 0);
}
}
/* check relations, and print errors */
for (node = dag->DagNode.first; node; node = node->next) {
for (itA = node->parent; itA; itA = itA->next) {
if (itA->node->ancestor_count > node->ancestor_count) {
if (node->ob && itA->node->ob) {
dag->is_acyclic = false;
printf("Dependency cycle detected:\n");
dag_node_print_dependency_cycle(dag, itA->node, node, itA->name);
}
}
}
}
/* parent relations are only needed for cycle checking, so free now */
for (node = dag->DagNode.first; node; node = node->next) {
while (node->parent) {
itA = node->parent->next;
MEM_freeN(node->parent);
node->parent = itA;
}
}
}
/* debug test functions */
void graph_print_queue(DagNodeQueue *nqueue)
{
DagNodeQueueElem *queueElem;
queueElem = nqueue->first;
while (queueElem) {
fprintf(stderr, "** %s %i %i-%i ", ((ID *) queueElem->node->ob)->name, queueElem->node->color, queueElem->node->DFS_dvtm, queueElem->node->DFS_fntm);
queueElem = queueElem->next;
}
fprintf(stderr, "\n");
}
void graph_print_queue_dist(DagNodeQueue *nqueue)
{
DagNodeQueueElem *queueElem;
int count;
queueElem = nqueue->first;
count = 0;
while (queueElem) {
fprintf(stderr, "** %25s %2.2i-%2.2i ", ((ID *) queueElem->node->ob)->name, queueElem->node->DFS_dvtm, queueElem->node->DFS_fntm);
while (count < queueElem->node->DFS_dvtm - 1) { fputc(' ', stderr); count++; }
fputc('|', stderr);
while (count < queueElem->node->DFS_fntm - 2) { fputc('-', stderr); count++; }
fputc('|', stderr);
fputc('\n', stderr);
count = 0;
queueElem = queueElem->next;
}
fprintf(stderr, "\n");
}
void graph_print_adj_list(DagForest *dag)
{
DagNode *node;
DagAdjList *itA;
node = dag->DagNode.first;
while (node) {
fprintf(stderr, "node : %s col: %i", ((ID *) node->ob)->name, node->color);
itA = node->child;
while (itA) {
fprintf(stderr, "-- %s ", ((ID *) itA->node->ob)->name);
itA = itA->next;
}
fprintf(stderr, "\n");
node = node->next;
}
}
/* ************************ API *********************** */
/* mechanism to allow editors to be informed of depsgraph updates,
* to do their own updates based on changes... */
static void (*EditorsUpdateIDCb)(Main *bmain, ID *id) = NULL;
static void (*EditorsUpdateSceneCb)(Main *bmain, Scene *scene, int updated) = NULL;
static void (*EditorsUpdateScenePreCb)(Main *bmain, Scene *scene, bool time) = NULL;
void DAG_editors_update_cb(void (*id_func)(Main *bmain, ID *id),
void (*scene_func)(Main *bmain, Scene *scene, int updated),
void (*scene_pre_func)(Main *bmain, Scene *scene, bool time))
{
if (DEG_depsgraph_use_legacy()) {
EditorsUpdateIDCb = id_func;
EditorsUpdateSceneCb = scene_func;
EditorsUpdateScenePreCb = scene_pre_func;
}
else {
/* New dependency graph. */
DEG_editors_set_update_cb(id_func, scene_func, scene_pre_func);
}
}
void DAG_editors_update_pre(Main *bmain, Scene *scene, bool time)
{
if (DEG_depsgraph_use_legacy()) {
if (EditorsUpdateScenePreCb != NULL) {
EditorsUpdateScenePreCb(bmain, scene, time);
}
}
else {
DEG_editors_update_pre(bmain, scene, time);
}
}
static void dag_editors_id_update(Main *bmain, ID *id)
{
if (EditorsUpdateIDCb)
EditorsUpdateIDCb(bmain, id);
}
static void dag_editors_scene_update(Main *bmain, Scene *scene, int updated)
{
if (EditorsUpdateSceneCb)
EditorsUpdateSceneCb(bmain, scene, updated);
}
/* groups with objects in this scene need to be put in the right order as well */
static void scene_sort_groups(Main *bmain, Scene *sce)
{
Base *base;
Group *group;
GroupObject *go;
Object *ob;
/* test; are group objects all in this scene? */
for (ob = bmain->object.first; ob; ob = ob->id.next) {
ob->id.tag &= ~LIB_TAG_DOIT;
ob->id.newid = NULL; /* newid abuse for GroupObject */
}
for (base = sce->base.first; base; base = base->next)
base->object->id.tag |= LIB_TAG_DOIT;
for (group = bmain->group.first; group; group = group->id.next) {
for (go = group->gobject.first; go; go = go->next) {
if ((go->ob->id.tag & LIB_TAG_DOIT) == 0)
break;
}
/* this group is entirely in this scene */
if (go == NULL) {
ListBase listb = {NULL, NULL};
for (go = group->gobject.first; go; go = go->next)
go->ob->id.newid = (ID *)go;
/* in order of sorted bases we reinsert group objects */
for (base = sce->base.first; base; base = base->next) {
if (base->object->id.newid) {
go = (GroupObject *)base->object->id.newid;
base->object->id.newid = NULL;
BLI_remlink(&group->gobject, go);
BLI_addtail(&listb, go);
}
}
/* copy the newly sorted listbase */
group->gobject = listb;
}
}
}
static void dag_scene_tag_rebuild(Scene *sce)
{
if (sce->theDag) {
sce->theDag->need_update = true;
}
}
/* free the depency graph */
static void dag_scene_free(Scene *sce)
{
if (sce->theDag) {
free_forest(sce->theDag);
MEM_freeN(sce->theDag);
sce->theDag = NULL;
}
}
/* Check whether object data needs to be evaluated before it
* might be used by others.
*
* Means that mesh object needs to have proper derivedFinal,
* curves-typed objects are to have proper curve cache.
*
* Other objects or objects which are tagged for data update are
* not considered to be in need of evaluation.
*/
static bool check_object_needs_evaluation(Object *object)
{
if (object->recalc & OB_RECALC_ALL) {
/* Object is tagged for update anyway, no need to re-tag it. */
return false;
}
if (object->type == OB_MESH) {
return object->derivedFinal == NULL;
}
else if (ELEM(object->type, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE)) {
return object->curve_cache == NULL;
}
return false;
}
/* Check whether object data is tagged for update. */
static bool check_object_tagged_for_update(Object *object)
{
if (object->recalc & OB_RECALC_ALL) {
return true;
}
if (ELEM(object->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE)) {
ID *data_id = object->data;
return (data_id->tag & (LIB_TAG_ID_RECALC_DATA | LIB_TAG_ID_RECALC)) != 0;
}
return false;
}
/* Flush changes from tagged objects in the scene to their
* dependencies which are not evaluated yet.
*
* This is needed to ensure all the dependencies are met
* before objects gets handled by object_handle_update(),
*
* This is needed when visible layers are changed or changing
* scene graph layout which involved usage of objects which
* aren't in the scene or weren't visible yet.
*/
static void dag_invisible_dependencies_flush(Scene *scene)
{
DagNode *root_node = scene->theDag->DagNode.first, *node;
DagNodeQueue *queue;
for (node = root_node; node != NULL; node = node->next) {
node->color = DAG_WHITE;
}
queue = queue_create(DAGQUEUEALLOC);
for (node = root_node; node != NULL; node = node->next) {
if (node->color == DAG_WHITE) {
push_stack(queue, node);
node->color = DAG_GRAY;
while (queue->count) {
DagNode *current_node = get_top_node_queue(queue);
DagAdjList *itA;
bool skip = false;
for (itA = current_node->child; itA; itA = itA->next) {
if (itA->node->color == DAG_WHITE) {
itA->node->color = DAG_GRAY;
push_stack(queue, itA->node);
skip = true;
break;
}
}
if (!skip) {
current_node = pop_queue(queue);
if (current_node->type == ID_OB) {
Object *current_object = current_node->ob;
if (check_object_needs_evaluation(current_object)) {
for (itA = current_node->child; itA; itA = itA->next) {
if (itA->node->type == ID_OB) {
Object *object = itA->node->ob;
if (check_object_tagged_for_update(object)) {
current_object->recalc |= OB_RECALC_OB | OB_RECALC_DATA;
}
}
}
}
}
node->color = DAG_BLACK;
}
}
}
}
queue_delete(queue);
}
static void dag_invisible_dependencies_check_flush(Main *bmain, Scene *scene)
{
if (DAG_id_type_tagged(bmain, ID_OB) ||
DAG_id_type_tagged(bmain, ID_ME) || /* Mesh */
DAG_id_type_tagged(bmain, ID_CU) || /* Curve */
DAG_id_type_tagged(bmain, ID_MB) || /* MetaBall */
DAG_id_type_tagged(bmain, ID_LT)) /* Lattice */
{
dag_invisible_dependencies_flush(scene);
}
}
/* sort the base list on dependency order */
static void dag_scene_build(Main *bmain, Scene *sce)
{
DagNode *node, *rootnode;
DagNodeQueue *nqueue;
DagAdjList *itA;
int time;
int skip = 0;
ListBase tempbase;
Base *base;
BLI_listbase_clear(&tempbase);
build_dag(bmain, sce, DAG_RL_ALL_BUT_DATA);
dag_check_cycle(sce->theDag);
nqueue = queue_create(DAGQUEUEALLOC);
for (node = sce->theDag->DagNode.first; node; node = node->next) {
node->color = DAG_WHITE;
}
time = 1;
rootnode = sce->theDag->DagNode.first;
rootnode->color = DAG_GRAY;
time++;
push_stack(nqueue, rootnode);
while (nqueue->count) {
skip = 0;
node = get_top_node_queue(nqueue);
itA = node->child;
while (itA != NULL) {
if (itA->node->color == DAG_WHITE) {
itA->node->DFS_dvtm = time;
itA->node->color = DAG_GRAY;
time++;
push_stack(nqueue, itA->node);
skip = 1;
break;
}
itA = itA->next;
}
if (!skip) {
if (node) {
node = pop_queue(nqueue);
if (node->ob == sce) /* we are done */
break;
node->color = DAG_BLACK;
time++;
base = sce->base.first;
while (base && base->object != node->ob)
base = base->next;
if (base) {
BLI_remlink(&sce->base, base);
BLI_addhead(&tempbase, base);
}
}
}
}
/* temporal correction for circular dependencies */
base = sce->base.first;
while (base) {
BLI_remlink(&sce->base, base);
BLI_addhead(&tempbase, base);
//if (G.debug & G_DEBUG)
printf("cyclic %s\n", base->object->id.name);
base = sce->base.first;
}
sce->base = tempbase;
queue_delete(nqueue);
/* all groups with objects in this scene gets resorted too */
scene_sort_groups(bmain, sce);
if (G.debug & G_DEBUG) {
printf("\nordered\n");
for (base = sce->base.first; base; base = base->next) {
printf(" %s\n", base->object->id.name);
}
}
/* Make sure that new dependencies which came from invisible layers
* are tagged for update (if they're needed for objects which were
* tagged for update).
*/
dag_invisible_dependencies_check_flush(bmain, sce);
}
/* clear all dependency graphs */
void DAG_relations_tag_update(Main *bmain)
{
if (DEG_depsgraph_use_legacy()) {
Scene *sce;
for (sce = bmain->scene.first; sce; sce = sce->id.next) {
dag_scene_tag_rebuild(sce);
}
}
else {
/* New dependency graph. */
DEG_relations_tag_update(bmain);
}
}
/* rebuild dependency graph only for a given scene */
void DAG_scene_relations_rebuild(Main *bmain, Scene *sce)
{
if (DEG_depsgraph_use_legacy()) {
dag_scene_free(sce);
DAG_scene_relations_update(bmain, sce);
}
else {
/* New dependency graph. */
DEG_scene_relations_rebuild(bmain, sce);
}
}
/* create dependency graph if it was cleared or didn't exist yet */
void DAG_scene_relations_update(Main *bmain, Scene *sce)
{
if (DEG_depsgraph_use_legacy()) {
if (!sce->theDag || sce->theDag->need_update)
dag_scene_build(bmain, sce);
}
else {
/* New dependency graph. */
DEG_scene_relations_update(bmain, sce);
}
}
void DAG_scene_relations_validate(Main *bmain, Scene *sce)
{
if (!DEG_depsgraph_use_legacy()) {
DEG_debug_scene_relations_validate(bmain, sce);
}
}
void DAG_scene_free(Scene *sce)
{
if (DEG_depsgraph_use_legacy()) {
if (sce->theDag) {
free_forest(sce->theDag);
MEM_freeN(sce->theDag);
sce->theDag = NULL;
}
}
else {
if (sce->depsgraph) {
DEG_graph_free(sce->depsgraph);
sce->depsgraph = NULL;
}
}
}
static void lib_id_recalc_tag(Main *bmain, ID *id)
{
id->tag |= LIB_TAG_ID_RECALC;
DAG_id_type_tag(bmain, GS(id->name));
}
static void lib_id_recalc_data_tag(Main *bmain, ID *id)
{
id->tag |= LIB_TAG_ID_RECALC_DATA;
DAG_id_type_tag(bmain, GS(id->name));
}
/* node was checked to have lasttime != curtime and is if type ID_OB */
static void flush_update_node(Main *bmain, DagNode *node, unsigned int layer, int curtime)
{
DagAdjList *itA;
Object *ob, *obc;
int oldflag;
bool changed = false;
unsigned int all_layer;
node->lasttime = curtime;
ob = node->ob;
if (ob && (ob->recalc & OB_RECALC_ALL)) {
all_layer = node->scelay;
/* got an object node that changes, now check relations */
for (itA = node->child; itA; itA = itA->next) {
all_layer |= itA->lay;
/* the relationship is visible */
if ((itA->lay & layer)) { // XXX || (itA->node->ob == obedit)
if (itA->node->type == ID_OB) {
obc = itA->node->ob;
oldflag = obc->recalc;
/* got a ob->obc relation, now check if flag needs flush */
if (ob->recalc & OB_RECALC_OB) {
if (itA->type & DAG_RL_OB_OB) {
//printf("ob %s changes ob %s\n", ob->id.name, obc->id.name);
obc->recalc |= OB_RECALC_OB;
lib_id_recalc_tag(bmain, &obc->id);
}
if (itA->type & DAG_RL_OB_DATA) {
//printf("ob %s changes obdata %s\n", ob->id.name, obc->id.name);
obc->recalc |= OB_RECALC_DATA;
lib_id_recalc_data_tag(bmain, &obc->id);
}
}
if (ob->recalc & OB_RECALC_DATA) {
if (itA->type & DAG_RL_DATA_OB) {
//printf("obdata %s changes ob %s\n", ob->id.name, obc->id.name);
obc->recalc |= OB_RECALC_OB;
lib_id_recalc_tag(bmain, &obc->id);
}
if (itA->type & DAG_RL_DATA_DATA) {
//printf("obdata %s changes obdata %s\n", ob->id.name, obc->id.name);
obc->recalc |= OB_RECALC_DATA;
lib_id_recalc_data_tag(bmain, &obc->id);
}
}
if (oldflag != obc->recalc) changed = 1;
}
}
}
/* even nicer, we can clear recalc flags... */
if ((all_layer & layer) == 0) { // XXX && (ob != obedit)) {
/* but existing displaylists or derivedmesh should be freed */
if (ob->recalc & OB_RECALC_DATA)
BKE_object_free_derived_caches(ob);
ob->recalc &= ~OB_RECALC_ALL;
}
}
/* check case where child changes and parent forcing obdata to change */
/* should be done regardless if this ob has recalc set */
/* could merge this in with loop above...? (ton) */
for (itA = node->child; itA; itA = itA->next) {
/* the relationship is visible */
if ((itA->lay & layer)) { // XXX || (itA->node->ob == obedit)
if (itA->node->type == ID_OB) {
obc = itA->node->ob;
/* child moves */
if ((obc->recalc & OB_RECALC_ALL) == OB_RECALC_OB) {
/* parent has deforming info */
if (itA->type & (DAG_RL_OB_DATA | DAG_RL_DATA_DATA)) {
// printf("parent %s changes ob %s\n", ob->id.name, obc->id.name);
obc->recalc |= OB_RECALC_DATA;
lib_id_recalc_data_tag(bmain, &obc->id);
}
}
}
}
}
/* we only go deeper if node not checked or something changed */
for (itA = node->child; itA; itA = itA->next) {
if (changed || itA->node->lasttime != curtime)
flush_update_node(bmain, itA->node, layer, curtime);
}
}
/* node was checked to have lasttime != curtime, and is of type ID_OB */
static unsigned int flush_layer_node(Scene *sce, DagNode *node, int curtime)
{
DagAdjList *itA;
node->lasttime = curtime;
node->lay = node->scelay;
for (itA = node->child; itA; itA = itA->next) {
if (itA->node->type == ID_OB) {
if (itA->node->lasttime != curtime) {
itA->lay = flush_layer_node(sce, itA->node, curtime); /* lay is only set once for each relation */
}
else {
itA->lay = itA->node->lay;
}
node->lay |= itA->lay;
}
}
return node->lay;
}
/* flush layer flags to dependencies */
static void dag_scene_flush_layers(Scene *sce, int lay)
{
DagNode *node, *firstnode;
DagAdjList *itA;
Base *base;
int lasttime;
firstnode = sce->theDag->DagNode.first; /* always scene node */
for (itA = firstnode->child; itA; itA = itA->next)
itA->lay = 0;
sce->theDag->time++; /* so we know which nodes were accessed */
lasttime = sce->theDag->time;
/* update layer flags in nodes */
for (base = sce->base.first; base; base = base->next) {
node = dag_get_node(sce->theDag, base->object);
node->scelay = base->object->lay;
}
/* ensure cameras are set as if they are on a visible layer, because
* they ared still used for rendering or setting the camera view
*
* XXX, this wont work for local view / unlocked camera's */
if (sce->camera) {
node = dag_get_node(sce->theDag, sce->camera);
node->scelay |= lay;
}
#ifdef DURIAN_CAMERA_SWITCH
{
TimeMarker *m;
for (m = sce->markers.first; m; m = m->next) {
if (m->camera) {
node = dag_get_node(sce->theDag, m->camera);
node->scelay |= lay;
}
}
}
#endif
/* flush layer nodes to dependencies */
for (itA = firstnode->child; itA; itA = itA->next)
if (itA->node->lasttime != lasttime && itA->node->type == ID_OB)
flush_layer_node(sce, itA->node, lasttime);
}
static void dag_tag_renderlayers(Scene *sce, unsigned int lay)
{
if (sce->nodetree) {
bNode *node;
Base *base;
unsigned int lay_changed = 0;
for (base = sce->base.first; base; base = base->next)
if (base->lay & lay)
if (base->object->recalc)
lay_changed |= base->lay;
for (node = sce->nodetree->nodes.first; node; node = node->next) {
if (node->id == (ID *)sce) {
SceneRenderLayer *srl = BLI_findlink(&sce->r.layers, node->custom1);
if (srl && (srl->lay & lay_changed))
nodeUpdate(sce->nodetree, node);
}
}
}
}
/* flushes all recalc flags in objects down the dependency tree */
void DAG_scene_flush_update(Main *bmain, Scene *sce, unsigned int lay, const short time)
{
DagNode *firstnode;
DagAdjList *itA;
int lasttime;
if (!DEG_depsgraph_use_legacy()) {
return;
}
if (sce->theDag == NULL || sce->theDag->need_update) {
printf("DAG zero... not allowed to happen!\n");
DAG_scene_relations_update(bmain, sce);
}
firstnode = sce->theDag->DagNode.first; /* always scene node */
/* first we flush the layer flags */
dag_scene_flush_layers(sce, lay);
/* then we use the relationships + layer info to flush update events */
sce->theDag->time++; /* so we know which nodes were accessed */
lasttime = sce->theDag->time;
for (itA = firstnode->child; itA; itA = itA->next)
if (itA->node->lasttime != lasttime && itA->node->type == ID_OB)
flush_update_node(bmain, itA->node, lay, lasttime);
/* if update is not due to time change, do pointcache clears */
if (!time) {
sce->theDag->time++; /* so we know which nodes were accessed */
lasttime = sce->theDag->time;
}
dag_tag_renderlayers(sce, lay);
}
static bool modifier_nlastrips_use_time(ListBase *strips)
{
NlaStrip *strip;
if (strips) {
for (strip = strips->first; strip; strip = strip->next) {
if (modifier_nlastrips_use_time(&strip->strips)) {
return true;
}
else if (strip->act) {
FCurve *fcu;
for (fcu = strip->act->curves.first; fcu; fcu = fcu->next) {
if (fcu->rna_path && strstr(fcu->rna_path, "modifiers["))
return true;
}
}
}
}
return false;
}
static bool object_modifiers_use_time(Object *ob)
{
ModifierData *md;
/* check if a modifier in modifier stack needs time input */
for (md = ob->modifiers.first; md; md = md->next) {
if (modifier_dependsOnTime(md))
return true;
}
/* check whether any modifiers are animated */
if (ob->adt) {
AnimData *adt = ob->adt;
NlaTrack *nlt;
FCurve *fcu;
/* action - check for F-Curves with paths containing 'modifiers[' */
if (adt->action) {
for (fcu = adt->action->curves.first; fcu; fcu = fcu->next) {
if (fcu->rna_path && strstr(fcu->rna_path, "modifiers["))
return true;
}
}
/* This here allows modifier properties to get driven and still update properly
*
* Workaround to get [#26764] (e.g. subsurf levels not updating when animated/driven)
* working, without the updating problems ([#28525] [#28690] [#28774] [#28777]) caused
* by the RNA updates cache introduced in r.38649
*/
for (fcu = adt->drivers.first; fcu; fcu = fcu->next) {
if (fcu->rna_path && strstr(fcu->rna_path, "modifiers["))
return true;
}
/* Also check NLA Strips... [#T45938] */
for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) {
if (modifier_nlastrips_use_time(&nlt->strips))
return true;
}
}
return false;
}
static short animdata_use_time(AnimData *adt)
{
NlaTrack *nlt;
if (adt == NULL) return 0;
/* check action - only if assigned, and it has anim curves */
if (adt->action && adt->action->curves.first)
return 1;
/* check NLA tracks + strips */
for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) {
if (nlt->strips.first)
return 1;
}
/* If we have drivers, more likely than not, on a frame change
* they'll need updating because their owner changed
*
* This is kindof a hack to get around a whole host of problems
* involving drivers using non-object datablock data (which the
* depsgraph currently has no way of representing let alone correctly
* dependency sort+tagging). By doing this, at least we ensure that
* some commonly attempted drivers (such as scene -> current frame;
* see "Driver updates fail" thread on Bf-committers dated July 2)
* will work correctly, and that other non-object datablocks will have
* their drivers update at least on frame change.
*
* -- Aligorith, July 4 2011
*/
if (adt->drivers.first)
return 1;
return 0;
}
static void dag_object_time_update_flags(Main *bmain, Scene *scene, Object *ob)
{
if (ob->constraints.first) {
bConstraint *con;
for (con = ob->constraints.first; con; con = con->next) {
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
ListBase targets = {NULL, NULL};
bConstraintTarget *ct;
if (cti) {
/* special case for camera tracking -- it doesn't use targets to define relations */
if (ELEM(cti->type,
CONSTRAINT_TYPE_FOLLOWTRACK,
CONSTRAINT_TYPE_CAMERASOLVER,
CONSTRAINT_TYPE_OBJECTSOLVER,
CONSTRAINT_TYPE_TRANSFORM_CACHE))
{
ob->recalc |= OB_RECALC_OB;
}
else if (cti->get_constraint_targets) {
cti->get_constraint_targets(con, &targets);
for (ct = targets.first; ct; ct = ct->next) {
if (ct->tar) {
ob->recalc |= OB_RECALC_OB;
break;
}
}
if (cti->flush_constraint_targets)
cti->flush_constraint_targets(con, &targets, 1);
}
}
}
}
if (ob->parent) {
/* motion path or bone child */
if (ob->parent->type == OB_CURVE || ob->parent->type == OB_ARMATURE) ob->recalc |= OB_RECALC_OB;
}
#if 0 // XXX old animation system
if (ob->nlastrips.first) {
if (ob->dup_group) {
bActionStrip *strip;
/* this case is for groups with nla, whilst nla target has no action or nla */
for (strip = ob->nlastrips.first; strip; strip = strip->next) {
if (strip->object)
strip->object->recalc |= OB_RECALC_ALL;
}
}
}
#endif // XXX old animation system
if (animdata_use_time(ob->adt)) {
ob->recalc |= OB_RECALC_OB;
ob->adt->recalc |= ADT_RECALC_ANIM;
}
if ((ob->adt) && (ob->type == OB_ARMATURE)) ob->recalc |= OB_RECALC_DATA;
if (object_modifiers_use_time(ob)) ob->recalc |= OB_RECALC_DATA;
if ((ob->pose) && (ob->pose->flag & POSE_CONSTRAINTS_TIMEDEPEND)) ob->recalc |= OB_RECALC_DATA;
// XXX: scene here may not be the scene that contains the rigidbody world affecting this!
if (ob->rigidbody_object && BKE_scene_check_rigidbody_active(scene))
ob->recalc |= OB_RECALC_OB;
{
AnimData *adt = BKE_animdata_from_id((ID *)ob->data);
Mesh *me;
Curve *cu;
Lattice *lt;
switch (ob->type) {
case OB_MESH:
me = ob->data;
if (me->key) {
if (!(ob->shapeflag & OB_SHAPE_LOCK)) {
ob->recalc |= OB_RECALC_DATA;
}
}
break;
case OB_CURVE:
case OB_SURF:
cu = ob->data;
if (cu->key) {
if (!(ob->shapeflag & OB_SHAPE_LOCK)) {
ob->recalc |= OB_RECALC_DATA;
}
}
break;
case OB_FONT:
cu = ob->data;
if (BLI_listbase_is_empty(&cu->nurb) && cu->str && cu->vfont)
ob->recalc |= OB_RECALC_DATA;
break;
case OB_LATTICE:
lt = ob->data;
if (lt->key) {
if (!(ob->shapeflag & OB_SHAPE_LOCK)) {
ob->recalc |= OB_RECALC_DATA;
}
}
break;
case OB_MBALL:
if (ob->transflag & OB_DUPLI) ob->recalc |= OB_RECALC_DATA;
break;
case OB_EMPTY:
/* update animated images */
if (ob->empty_drawtype == OB_EMPTY_IMAGE && ob->data)
if (BKE_image_is_animated(ob->data))
ob->recalc |= OB_RECALC_DATA;
break;
}
if (animdata_use_time(adt)) {
ob->recalc |= OB_RECALC_DATA;
adt->recalc |= ADT_RECALC_ANIM;
}
}
if (ob->recalc & OB_RECALC_OB)
lib_id_recalc_tag(bmain, &ob->id);
if (ob->recalc & OB_RECALC_DATA)
lib_id_recalc_data_tag(bmain, &ob->id);
}
/* recursively update objects in groups, each group is done at most once */
static void dag_group_update_flags(Main *bmain, Scene *scene, Group *group, const bool do_time)
{
GroupObject *go;
if (group->id.tag & LIB_TAG_DOIT)
return;
group->id.tag |= LIB_TAG_DOIT;
for (go = group->gobject.first; go; go = go->next) {
if (do_time)
dag_object_time_update_flags(bmain, scene, go->ob);
if (go->ob->dup_group)
dag_group_update_flags(bmain, scene, go->ob->dup_group, do_time);
}
}
/* flag all objects that need recalc, for changes in time for example */
/* do_time: make this optional because undo resets objects to their animated locations without this */
void DAG_scene_update_flags(Main *bmain, Scene *scene, unsigned int lay, const bool do_time, const bool do_invisible_flush)
{
Base *base;
Object *ob;
Group *group;
GroupObject *go;
Scene *sce_iter;
BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
/* set ob flags where animated systems are */
for (SETLOOPER(scene, sce_iter, base)) {
ob = base->object;
if (do_time) {
/* now if DagNode were part of base, the node->lay could be checked... */
/* we do all now, since the scene_flush checks layers and clears recalc flags even */
/* NOTE: "sce_iter" not "scene" so that rigidbodies in background scenes work
* (i.e. muting + rbw availability can be checked and tagged properly) [#33970]
*/
dag_object_time_update_flags(bmain, sce_iter, ob);
}
/* recursively tag groups with LIB_TAG_DOIT, and update flags for objects */
if (ob->dup_group)
dag_group_update_flags(bmain, scene, ob->dup_group, do_time);
}
for (sce_iter = scene; sce_iter; sce_iter = sce_iter->set)
DAG_scene_flush_update(bmain, sce_iter, lay, 1);
if (do_time) {
/* test: set time flag, to disable baked systems to update */
for (SETLOOPER(scene, sce_iter, base)) {
ob = base->object;
if (ob->recalc & OB_RECALC_ALL)
ob->recalc |= OB_RECALC_TIME;
}
/* hrmf... an exception to look at once, for invisible camera object we do it over */
if (scene->camera)
dag_object_time_update_flags(bmain, scene, scene->camera);
}
/* and store the info in groupobject */
for (group = bmain->group.first; group; group = group->id.next) {
if (group->id.tag & LIB_TAG_DOIT) {
for (go = group->gobject.first; go; go = go->next) {
go->recalc = go->ob->recalc;
// printf("ob %s recalc %d\n", go->ob->id.name, go->recalc);
}
group->id.tag &= ~LIB_TAG_DOIT;
}
}
if (do_invisible_flush) {
dag_invisible_dependencies_check_flush(bmain, scene);
}
}
/* struct returned by DagSceneLayer */
typedef struct DagSceneLayer {
struct DagSceneLayer *next, *prev;
Scene *scene;
unsigned int layer;
} DagSceneLayer;
/* returns visible scenes with valid DAG */
static void dag_current_scene_layers(Main *bmain, ListBase *lb)
{
wmWindowManager *wm;
wmWindow *win;
BLI_listbase_clear(lb);
/* if we have a windowmanager, look into windows */
if ((wm = bmain->wm.first)) {
BKE_main_id_flag_listbase(&bmain->scene, LIB_TAG_DOIT, 1);
for (win = wm->windows.first; win; win = win->next) {
if (win->screen && win->screen->scene->theDag) {
Scene *scene = win->screen->scene;
DagSceneLayer *dsl;
if (scene->id.tag & LIB_TAG_DOIT) {
dsl = MEM_mallocN(sizeof(DagSceneLayer), "dag scene layer");
BLI_addtail(lb, dsl);
dsl->scene = scene;
dsl->layer = BKE_screen_visible_layers(win->screen, scene);
scene->id.tag &= ~LIB_TAG_DOIT;
}
else {
/* It is possible that multiple windows shares the same scene
* and have different layers visible.
*
* Here we deal with such cases by squashing layers bits from
* multiple windoew to the DagSceneLayer.
*
* TODO(sergey): Such a lookup could be optimized perhaps,
* however should be fine for now since we usually have only
* few open windows.
*/
for (dsl = lb->first; dsl; dsl = dsl->next) {
if (dsl->scene == scene) {
dsl->layer |= BKE_screen_visible_layers(win->screen, scene);
break;
}
}
}
}
}
}
else {
/* if not, use the first sce */
DagSceneLayer *dsl = MEM_mallocN(sizeof(DagSceneLayer), "dag scene layer");
BLI_addtail(lb, dsl);
dsl->scene = bmain->scene.first;
dsl->layer = dsl->scene->lay;
/* XXX for background mode, we should get the scene
* from somewhere, for the -S option, but it's in
* the context, how to get it here? */
}
}
static void dag_group_on_visible_update(Scene *scene, Group *group)
{
GroupObject *go;
if (group->id.tag & LIB_TAG_DOIT)
return;
group->id.tag |= LIB_TAG_DOIT;
for (go = group->gobject.first; go; go = go->next) {
if (ELEM(go->ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE)) {
go->ob->recalc |= OB_RECALC_DATA;
go->ob->id.tag |= LIB_TAG_DOIT;
lib_id_recalc_tag(G.main, &go->ob->id);
}
if (go->ob->proxy_from) {
go->ob->recalc |= OB_RECALC_OB;
go->ob->id.tag |= LIB_TAG_DOIT;
lib_id_recalc_tag(G.main, &go->ob->id);
}
if (go->ob->dup_group)
dag_group_on_visible_update(scene, go->ob->dup_group);
}
}
void DAG_on_visible_update(Main *bmain, const bool do_time)
{
ListBase listbase;
DagSceneLayer *dsl;
if (!DEG_depsgraph_use_legacy()) {
/* Inform new dependnecy graphs about visibility changes. */
DEG_on_visible_update(bmain, do_time);
return;
}
/* get list of visible scenes and layers */
dag_current_scene_layers(bmain, &listbase);
for (dsl = listbase.first; dsl; dsl = dsl->next) {
Scene *scene = dsl->scene;
Scene *sce_iter;
Base *base;
Object *ob;
DagNode *node;
unsigned int lay = dsl->layer, oblay;
/* derivedmeshes and displists are not saved to file so need to be
* remade, tag them so they get remade in the scene update loop,
* note armature poses or object matrices are preserved and do not
* require updates, so we skip those */
for (sce_iter = scene; sce_iter; sce_iter = sce_iter->set)
dag_scene_flush_layers(sce_iter, lay);
BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
for (SETLOOPER(scene, sce_iter, base)) {
ob = base->object;
node = (sce_iter->theDag) ? dag_get_node(sce_iter->theDag, ob) : NULL;
oblay = (node) ? node->lay : ob->lay;
if ((oblay & lay) & ~scene->lay_updated) {
/* TODO(sergey): Why do we need armature here now but didn't need before? */
if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE, OB_ARMATURE)) {
ob->recalc |= OB_RECALC_DATA;
lib_id_recalc_tag(bmain, &ob->id);
}
/* This should not be needed here, but in some cases, like after a redo, we can end up with
* a wrong final matrix (see T42472).
* Quoting Sergey, this comes from BKE_object_handle_update_ex, which is calling
* BKE_object_where_is_calc_ex when it shouldn't, but that issue is not easily fixable.
*/
else {
ob->recalc |= OB_RECALC_OB;
lib_id_recalc_tag(bmain, &ob->id);
}
if (ob->proxy && (ob->proxy_group == NULL)) {
ob->proxy->recalc |= OB_RECALC_DATA;
lib_id_recalc_tag(bmain, &ob->id);
}
if (ob->dup_group)
dag_group_on_visible_update(scene, ob->dup_group);
}
}
BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
/* now tag update flags, to ensure deformers get calculated on redraw */
DAG_scene_update_flags(bmain, scene, lay, do_time, true);
scene->lay_updated |= lay;
}
BLI_freelistN(&listbase);
/* hack to get objects updating on layer changes */
DAG_id_type_tag(bmain, ID_OB);
/* so masks update on load */
if (bmain->mask.first) {
Mask *mask;
for (mask = bmain->mask.first; mask; mask = mask->id.next) {
DAG_id_tag_update(&mask->id, 0);
}
}
}
static void dag_id_flush_update__isDependentTexture(
void *userData, Object *UNUSED(ob), ID **idpoin, int UNUSED(cd_flag))
{
struct { ID *id; bool is_dependent; } *data = userData;
if (*idpoin && GS((*idpoin)->name) == ID_TE) {
if (data->id == (*idpoin))
data->is_dependent = 1;
}
}
static void dag_id_flush_update(Main *bmain, Scene *sce, ID *id)
{
Object *obt, *ob = NULL;
short idtype;
/* here we flush a few things before actual scene wide flush, mostly
* due to only objects and not other datablocks being in the depsgraph */
/* set flags & pointcache for object */
if (GS(id->name) == ID_OB) {
ob = (Object *)id;
/* So if someone tagged object recalc directly,
* id_tag_update bit-field stays relevant
*/
if (ob->recalc & OB_RECALC_ALL) {
DAG_id_type_tag(bmain, GS(id->name));
}
if (ob->recalc & OB_RECALC_DATA) {
/* all users of this ob->data should be checked */
id = ob->data;
/* no point in trying in this cases */
if (id && id->us <= 1) {
dag_editors_id_update(bmain, id);
id = NULL;
}
}
}
/* set flags & pointcache for object data */
if (id) {
idtype = GS(id->name);
if (OB_DATA_SUPPORT_ID(idtype)) {
for (obt = bmain->object.first; obt; obt = obt->id.next) {
if (!(ob && obt == ob) && obt->data == id) {
obt->recalc |= OB_RECALC_DATA;
lib_id_recalc_data_tag(bmain, &obt->id);
}
}
}
else if (idtype == ID_VF) {
for (obt = bmain->object.first; obt; obt = obt->id.next) {
if (obt->type == OB_FONT) {
Curve *cu = obt->data;
if (ELEM((struct VFont *)id, CURVE_VFONT_ANY(cu))) {
obt->recalc |= OB_RECALC_DATA;
lib_id_recalc_data_tag(bmain, &obt->id);
}
}
}
}
/* set flags based on textures - can influence depgraph via modifiers */
if (idtype == ID_TE) {
for (obt = bmain->object.first; obt; obt = obt->id.next) {
struct { ID *id; bool is_dependent; } data;
data.id = id;
data.is_dependent = 0;
modifiers_foreachIDLink(obt, dag_id_flush_update__isDependentTexture, &data);
if (data.is_dependent) {
obt->recalc |= OB_RECALC_DATA;
lib_id_recalc_data_tag(bmain, &obt->id);
}
}
}
/* set flags based on ShapeKey */
if (idtype == ID_KE) {
for (obt = bmain->object.first; obt; obt = obt->id.next) {
Key *key = BKE_key_from_object(obt);
if (!(ob && obt == ob) && ((ID *)key == id)) {
obt->flag |= (OB_RECALC_OB | OB_RECALC_DATA);
lib_id_recalc_tag(bmain, &obt->id);
lib_id_recalc_data_tag(bmain, &obt->id);
}
}
}
if (ELEM(idtype, ID_MA, ID_TE)) {
obt = sce->basact ? sce->basact->object : NULL;
if (obt && obt->mode & OB_MODE_TEXTURE_PAINT) {
BKE_texpaint_slots_refresh_object(sce, obt);
BKE_paint_proj_mesh_data_check(sce, obt, NULL, NULL, NULL, NULL);
GPU_drawobject_free(obt->derivedFinal);
}
}
if (idtype == ID_MC) {
MovieClip *clip = (MovieClip *) id;
BKE_tracking_dopesheet_tag_update(&clip->tracking);
for (obt = bmain->object.first; obt; obt = obt->id.next) {
bConstraint *con;
for (con = obt->constraints.first; con; con = con->next) {
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
if (ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER,
CONSTRAINT_TYPE_OBJECTSOLVER))
{
obt->recalc |= OB_RECALC_OB;
lib_id_recalc_tag(bmain, &obt->id);
break;
}
}
}
if (sce->nodetree) {
bNode *node;
for (node = sce->nodetree->nodes.first; node; node = node->next) {
if (node->id == id) {
nodeUpdate(sce->nodetree, node);
}
}
}
}
/* Not pretty to iterate all the nodes here, but it's as good as it
* could be with the current depsgraph design/
*/
if (idtype == ID_IM) {
FOREACH_NODETREE(bmain, ntree, parent_id) {
if (ntree->type == NTREE_SHADER) {
bNode *node;
for (node = ntree->nodes.first; node; node = node->next) {
if (node->id == id) {
lib_id_recalc_tag(bmain, &ntree->id);
break;
}
}
}
} FOREACH_NODETREE_END
}
if (idtype == ID_MSK) {
if (sce->nodetree) {
bNode *node;
for (node = sce->nodetree->nodes.first; node; node = node->next) {
if (node->id == id) {
nodeUpdate(sce->nodetree, node);
}
}
}
}
/* camera's matrix is used to orient reconstructed stuff,
* so it should happen tracking-related constraints recalculation
* when camera is changing (sergey) */
if (sce->camera && &sce->camera->id == id) {
MovieClip *clip = BKE_object_movieclip_get(sce, sce->camera, true);
if (clip)
dag_id_flush_update(bmain, sce, &clip->id);
}
/* update editors */
dag_editors_id_update(bmain, id);
}
}
void DAG_ids_flush_tagged(Main *bmain)
{
ListBase listbase;
DagSceneLayer *dsl;
ListBase *lbarray[MAX_LIBARRAY];
int a;
bool do_flush = false;
if (!DEG_depsgraph_use_legacy()) {
DEG_ids_flush_tagged(bmain);
return;
}
/* get list of visible scenes and layers */
dag_current_scene_layers(bmain, &listbase);
if (BLI_listbase_is_empty(&listbase))
return;
/* loop over all ID types */
a = set_listbasepointers(bmain, lbarray);
while (a--) {
ListBase *lb = lbarray[a];
ID *id = lb->first;
if (id && bmain->id_tag_update[BKE_idcode_to_index(GS(id->name))]) {
for (; id; id = id->next) {
if (id->tag & (LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA)) {
for (dsl = listbase.first; dsl; dsl = dsl->next)
dag_id_flush_update(bmain, dsl->scene, id);
do_flush = true;
}
}
}
}
/* flush changes to other objects */
if (do_flush) {
for (dsl = listbase.first; dsl; dsl = dsl->next)
DAG_scene_flush_update(bmain, dsl->scene, dsl->layer, 0);
}
BLI_freelistN(&listbase);
}
void DAG_ids_check_recalc(Main *bmain, Scene *scene, bool time)
{
ListBase *lbarray[MAX_LIBARRAY];
int a;
bool updated = false;
if (!DEG_depsgraph_use_legacy()) {
DEG_ids_check_recalc(bmain, scene, time);
return;
}
/* loop over all ID types */
a = set_listbasepointers(bmain, lbarray);
while (a--) {
ListBase *lb = lbarray[a];
ID *id = lb->first;
if (id && bmain->id_tag_update[BKE_idcode_to_index(GS(id->name))]) {
updated = true;
break;
}
}
dag_editors_scene_update(bmain, scene, (updated || time));
}
/* It is possible that scene_update_post and frame_update_post handlers
* will modify objects. The issue is that DAG_ids_clear_recalc is called
* just after callbacks, which leaves objects with recalc flags but no
* corresponding bit in ID recalc bitfield. This leads to some kind of
* regression when using ID type tag fields to check whether there objects
* to be updated internally comparing threaded DAG with legacy one.
*
* For now let's have a workaround which will preserve tag for ID_OB
* if there're objects with OB_RECALC_ALL bits. This keeps behavior
* unchanged comparing with 2.69 release.
*
* TODO(sergey): Need to get rid of such a workaround.
*
* - sergey -
*/
#define POST_UPDATE_HANDLER_WORKAROUND
void DAG_ids_clear_recalc(Main *bmain)
{
ListBase *lbarray[MAX_LIBARRAY];
bNodeTree *ntree;
int a;
#ifdef POST_UPDATE_HANDLER_WORKAROUND
bool have_updated_objects = false;
if (DAG_id_type_tagged(bmain, ID_OB)) {
ListBase listbase;
DagSceneLayer *dsl;
/* We need to check all visible scenes, otherwise resetting
* OB_ID changed flag will only work fine for first scene of
* multiple visible and all the rest will skip update.
*
* This could also lead to wrong behavior scene update handlers
* because of missing ID datablock changed flags.
*
* This is a bit of a bummer to allocate list here, but likely
* it wouldn't become too much bad because it only happens when
* objects were actually changed.
*/
dag_current_scene_layers(bmain, &listbase);
for (dsl = listbase.first; dsl; dsl = dsl->next) {
Scene *scene = dsl->scene;
DagNode *node;
for (node = scene->theDag->DagNode.first;
node != NULL && have_updated_objects == false;
node = node->next)
{
if (node->type == ID_OB) {
Object *object = (Object *) node->ob;
if (object->recalc & OB_RECALC_ALL) {
have_updated_objects = true;
break;
}
}
}
}
BLI_freelistN(&listbase);
}
#endif
/* loop over all ID types */
a = set_listbasepointers(bmain, lbarray);
while (a--) {
ListBase *lb = lbarray[a];
ID *id = lb->first;
if (id && bmain->id_tag_update[BKE_idcode_to_index(GS(id->name))]) {
for (; id; id = id->next) {
if (id->tag & (LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA))
id->tag &= ~(LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA);
/* some ID's contain semi-datablock nodetree */
ntree = ntreeFromID(id);
if (ntree && (ntree->id.tag & (LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA)))
ntree->id.tag &= ~(LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA);
}
}
}
memset(bmain->id_tag_update, 0, sizeof(bmain->id_tag_update));
#ifdef POST_UPDATE_HANDLER_WORKAROUND
if (have_updated_objects) {
DAG_id_type_tag(bmain, ID_OB);
}
#endif
}
void DAG_id_tag_update_ex(Main *bmain, ID *id, short flag)
{
if (!DEG_depsgraph_use_legacy()) {
DEG_id_tag_update_ex(bmain, id, flag);
return;
}
if (id == NULL) return;
if (G.debug & G_DEBUG_DEPSGRAPH) {
printf("%s: id=%s flag=%d\n", __func__, id->name, flag);
}
/* tag ID for update */
if (flag) {
if (flag & OB_RECALC_OB)
lib_id_recalc_tag(bmain, id);
if (flag & OB_RECALC_DATA)
lib_id_recalc_data_tag(bmain, id);
}
else
lib_id_recalc_tag(bmain, id);
/* flag is for objects and particle systems */
if (flag) {
Object *ob;
short idtype = GS(id->name);
if (idtype == ID_OB) {
/* only quick tag */
ob = (Object *)id;
ob->recalc |= (flag & OB_RECALC_ALL);
}
else {
/* disable because this is called on various ID types automatically.
* where printing warning is not useful. for now just ignore */
/* BLI_assert(!"invalid flag for this 'idtype'"); */
}
}
else if (GS(id->name) == ID_CF) {
for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
ModifierData *md = modifiers_findByType(ob, eModifierType_MeshSequenceCache);
if (md) {
MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md;
if (mcmd->cache_file && (&mcmd->cache_file->id == id)) {
ob->recalc |= OB_RECALC_ALL;
continue;
}
}
for (bConstraint *con = ob->constraints.first; con; con = con->next) {
if (con->type != CONSTRAINT_TYPE_TRANSFORM_CACHE) {
continue;
}
bTransformCacheConstraint *data = con->data;
if (data->cache_file && (&data->cache_file->id == id)) {
ob->recalc |= OB_RECALC_ALL;
break;
}
}
}
}
}
void DAG_id_tag_update(ID *id, short flag)
{
DAG_id_tag_update_ex(G.main, id, flag);
}
void DAG_id_type_tag(Main *bmain, short idtype)
{
if (idtype == ID_NT) {
/* stupid workaround so parent datablocks of nested nodetree get looped
* over when we loop over tagged datablock types */
DAG_id_type_tag(bmain, ID_MA);
DAG_id_type_tag(bmain, ID_TE);
DAG_id_type_tag(bmain, ID_LA);
DAG_id_type_tag(bmain, ID_WO);
DAG_id_type_tag(bmain, ID_SCE);
}
bmain->id_tag_update[BKE_idcode_to_index(idtype)] = 1;
}
int DAG_id_type_tagged(Main *bmain, short idtype)
{
return bmain->id_tag_update[BKE_idcode_to_index(idtype)];
}
#if 0 // UNUSED
/* recursively descends tree, each node only checked once */
/* node is checked to be of type object */
static int parent_check_node(DagNode *node, int curtime)
{
DagAdjList *itA;
node->lasttime = curtime;
if (node->color == DAG_GRAY)
return DAG_GRAY;
for (itA = node->child; itA; itA = itA->next) {
if (itA->node->type == ID_OB) {
if (itA->node->color == DAG_GRAY)
return DAG_GRAY;
/* descend if not done */
if (itA->node->lasttime != curtime) {
itA->node->color = parent_check_node(itA->node, curtime);
if (itA->node->color == DAG_GRAY)
return DAG_GRAY;
}
}
}
return DAG_WHITE;
}
#endif
/* ******************* DAG FOR ARMATURE POSE ***************** */
/* we assume its an armature with pose */
void DAG_pose_sort(Object *ob)
{
bPose *pose = ob->pose;
bPoseChannel *pchan;
bConstraint *con;
DagNode *node;
DagNode *node2, *node3;
DagNode *rootnode;
DagForest *dag;
DagNodeQueue *nqueue;
DagAdjList *itA;
ListBase tempbase;
int skip = 0;
dag = dag_init();
dag->ugly_hack_sorry = false; /* no ID structs */
rootnode = dag_add_node(dag, NULL); /* node->ob becomes NULL */
/* we add the hierarchy and the constraints */
for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
int addtoroot = 1;
node = dag_get_node(dag, pchan);
if (pchan->parent) {
node2 = dag_get_node(dag, pchan->parent);
dag_add_relation(dag, node2, node, 0, "Parent Relation");
addtoroot = 0;
}
for (con = pchan->constraints.first; con; con = con->next) {
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
ListBase targets = {NULL, NULL};
bConstraintTarget *ct;
if (cti && cti->get_constraint_targets) {
cti->get_constraint_targets(con, &targets);
for (ct = targets.first; ct; ct = ct->next) {
if (ct->tar == ob && ct->subtarget[0]) {
bPoseChannel *target = BKE_pose_channel_find_name(ob->pose, ct->subtarget);
if (target) {
node2 = dag_get_node(dag, target);
dag_add_relation(dag, node2, node, 0, "Pose Constraint");
if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
bKinematicConstraint *data = (bKinematicConstraint *)con->data;
bPoseChannel *parchan;
int segcount = 0;
/* exclude tip from chain? */
if (!(data->flag & CONSTRAINT_IK_TIP))
parchan = pchan->parent;
else
parchan = pchan;
/* Walk to the chain's root */
while (parchan) {
node3 = dag_get_node(dag, parchan);
dag_add_relation(dag, node2, node3, 0, "IK Constraint");
segcount++;
if (segcount == data->rootbone || segcount > 255) break; /* 255 is weak */
parchan = parchan->parent;
}
}
}
}
}
if (cti->flush_constraint_targets)
cti->flush_constraint_targets(con, &targets, 1);
}
}
if (addtoroot == 1) {
dag_add_relation(dag, rootnode, node, 0, "Root Bone Relation");
}
}
dag_check_cycle(dag);
/* now we try to sort... */
BLI_listbase_clear(&tempbase);
nqueue = queue_create(DAGQUEUEALLOC);
/* tag nodes unchecked */
for (node = dag->DagNode.first; node; node = node->next)
node->color = DAG_WHITE;
rootnode->color = DAG_GRAY;
push_stack(nqueue, rootnode);
while (nqueue->count) {
skip = 0;
node = get_top_node_queue(nqueue);
itA = node->child;
while (itA != NULL) {
if (itA->node->color == DAG_WHITE) {
itA->node->color = DAG_GRAY;
push_stack(nqueue, itA->node);
skip = 1;
break;
}
itA = itA->next;
}
if (!skip) {
if (node) {
node = pop_queue(nqueue);
if (node->ob == NULL) /* we are done */
break;
node->color = DAG_BLACK;
/* put node in new list */
BLI_remlink(&pose->chanbase, node->ob);
BLI_addhead(&tempbase, node->ob);
}
}
}
/* temporal correction for circular dependencies */
while (pose->chanbase.first) {
pchan = pose->chanbase.first;
BLI_remlink(&pose->chanbase, pchan);
BLI_addhead(&tempbase, pchan);
printf("cyclic %s\n", pchan->name);
}
pose->chanbase = tempbase;
queue_delete(nqueue);
// printf("\nordered\n");
// for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
// printf(" %s\n", pchan->name);
// }
free_forest(dag);
MEM_freeN(dag);
}
/* ************************ DAG FOR THREADED UPDATE ********************* */
/* Initialize run-time data in the graph needed for traversing it
* from multiple threads and start threaded tree traversal by adding
* the root node to the queue.
*
* This will mark DAG nodes as object/non-object and will calculate
* num_pending_parents of nodes (which is how many non-updated parents node
* have, which helps a lot checking whether node could be scheduled
* already or not).
*/
void DAG_threaded_update_begin(Scene *scene,
void (*func)(void *node, void *user_data),
void *user_data)
{
DagNode *node;
/* We reset num_pending_parents to zero first and tag node as not scheduled yet... */
for (node = scene->theDag->DagNode.first; node; node = node->next) {
node->num_pending_parents = 0;
node->scheduled = false;
}
/* ... and then iterate over all the nodes and
* increase num_pending_parents for node childs.
*/
for (node = scene->theDag->DagNode.first; node; node = node->next) {
DagAdjList *itA;
for (itA = node->child; itA; itA = itA->next) {
if (itA->node != node) {
itA->node->num_pending_parents++;
}
}
}
/* Add root nodes to the queue. */
BLI_spin_lock(&threaded_update_lock);
for (node = scene->theDag->DagNode.first; node; node = node->next) {
if (node->num_pending_parents == 0) {
node->scheduled = true;
func(node, user_data);
}
}
BLI_spin_unlock(&threaded_update_lock);
}
/* This function is called when handling node is done.
*
* This function updates num_pending_parents for all childs and
* schedules them if they're ready.
*/
void DAG_threaded_update_handle_node_updated(void *node_v,
void (*func)(void *node, void *user_data),
void *user_data)
{
DagNode *node = node_v;
DagAdjList *itA;
for (itA = node->child; itA; itA = itA->next) {
DagNode *child_node = itA->node;
if (child_node != node) {
atomic_sub_uint32(&child_node->num_pending_parents, 1);
if (child_node->num_pending_parents == 0) {
bool need_schedule;
BLI_spin_lock(&threaded_update_lock);
need_schedule = child_node->scheduled == false;
child_node->scheduled = true;
BLI_spin_unlock(&threaded_update_lock);
if (need_schedule) {
func(child_node, user_data);
}
}
}
}
}
/* ************************ DAG DEBUGGING ********************* */
void DAG_print_dependencies(Main *bmain, Scene *scene, Object *ob)
{
/* utility for debugging dependencies */
dag_print_dependencies = 1;
if (ob && (ob->mode & OB_MODE_POSE)) {
printf("\nDEPENDENCY RELATIONS for %s\n\n", ob->id.name + 2);
DAG_pose_sort(ob);
}
else {
printf("\nDEPENDENCY RELATIONS for %s\n\n", scene->id.name + 2);
DAG_scene_relations_rebuild(bmain, scene);
}
dag_print_dependencies = 0;
}
/* ************************ DAG querying ********************* */
/* Will return Object ID if node represents Object,
* and will return NULL otherwise.
*/
Object *DAG_get_node_object(void *node_v)
{
DagNode *node = node_v;
if (node->type == ID_OB) {
return node->ob;
}
return NULL;
}
/* Returns node name, used for debug output only, atm. */
const char *DAG_get_node_name(Scene *scene, void *node_v)
{
DagNode *node = node_v;
return dag_node_name(scene->theDag, node);
}
short DAG_get_eval_flags_for_object(Scene *scene, void *object)
{
DagNode *node;
if (!DEG_depsgraph_use_legacy()) {
return DEG_get_eval_flags_for_id(scene->depsgraph, (ID *)object);
}
if (scene->theDag == NULL) {
/* Happens when converting objects to mesh from a python script
* after modifying scene graph.
*
* Currently harmless because it's only called for temporary
* objects which are out of the DAG anyway.
*/
return 0;
}
node = dag_find_node(scene->theDag, object);
if (node) {
return node->eval_flags;
}
else {
/* Happens when external render engine exports temporary objects
* which are not in the DAG.
*/
/* TODO(sergey): Doublecheck objects with Curve Deform exports all fine. */
/* TODO(sergey): Weak but currently we can't really access proper DAG from
* the modifiers stack. This is because in most cases modifier is to use
* the foreground scene, but to access evaluation flags we need to know
* active background scene, which we don't know.
*/
if (scene->set) {
return DAG_get_eval_flags_for_object(scene->set, object);
}
return 0;
}
}
bool DAG_is_acyclic(Scene *scene)
{
return scene->theDag->is_acyclic;
}
#else
/* *********************************************************************
* Stubs to avoid linking issues and make sure legacy crap is not used *
* *********************************************************************
*/
DagNodeQueue *queue_create(int UNUSED(slots))
{
BLI_assert(!"Should not be used with new dependnecy graph");
return NULL;
}
void queue_raz(DagNodeQueue *UNUSED(queue))
{
BLI_assert(!"Should not be used with new dependnecy graph");
}
void queue_delete(DagNodeQueue *UNUSED(queue))
{
BLI_assert(!"Should not be used with new dependnecy graph");
}
void push_queue(DagNodeQueue *UNUSED(queue), DagNode *UNUSED(node))
{
BLI_assert(!"Should not be used with new dependnecy graph");
}
void push_stack(DagNodeQueue *UNUSED(queue), DagNode *UNUSED(node))
{
BLI_assert(!"Should not be used with new dependnecy graph");
}
DagNode *pop_queue(DagNodeQueue *UNUSED(queue))
{
BLI_assert(!"Should not be used with new dependnecy graph");
return NULL;
}
DagNode *get_top_node_queue(DagNodeQueue *UNUSED(queue))
{
BLI_assert(!"Should not be used with new dependnecy graph");
return NULL;
}
DagForest *dag_init(void)
{
BLI_assert(!"Should not be used with new dependnecy graph");
return NULL;
}
DagForest *build_dag(Main *UNUSED(bmain),
Scene *UNUSED(sce),
short UNUSED(mask))
{
BLI_assert(!"Should not be used with new dependnecy graph");
return NULL;
}
void free_forest(DagForest *UNUSED(Dag))
{
BLI_assert(!"Should not be used with new dependnecy graph");
}
DagNode *dag_find_node(DagForest *UNUSED(forest), void *UNUSED(fob))
{
BLI_assert(!"Should not be used with new dependnecy graph");
return NULL;
}
DagNode *dag_add_node(DagForest *UNUSED(forest), void *UNUSED(fob))
{
BLI_assert(!"Should not be used with new dependnecy graph");
return NULL;
}
DagNode *dag_get_node(DagForest *UNUSED(forest), void *UNUSED(fob))
{
BLI_assert(!"Should not be used with new dependnecy graph");
return NULL;
}
DagNode *dag_get_sub_node(DagForest *UNUSED(forest), void *UNUSED(fob))
{
BLI_assert(!"Should not be used with new dependnecy graph");
return NULL;
}
void dag_add_relation(DagForest *UNUSED(forest),
DagNode *UNUSED(fob1),
DagNode *UNUSED(fob2),
short UNUSED(rel),
const char *UNUSED(name))
{
BLI_assert(!"Should not be used with new dependnecy graph");
}
/* debug test functions */
void graph_print_queue(DagNodeQueue *UNUSED(nqueue))
{
BLI_assert(!"Should not be used with new dependnecy graph");
}
void graph_print_queue_dist(DagNodeQueue *UNUSED(nqueue))
{
BLI_assert(!"Should not be used with new dependnecy graph");
}
void graph_print_adj_list(DagForest *UNUSED(dag))
{
BLI_assert(!"Should not be used with new dependnecy graph");
}
void DAG_scene_flush_update(Main *UNUSED(bmain),
Scene *UNUSED(sce),
unsigned int UNUSED(lay),
const short UNUSED(time))
{
BLI_assert(!"Should not be used with new dependnecy graph");
}
void DAG_scene_update_flags(Main *UNUSED(bmain),
Scene *UNUSED(scene),
unsigned int UNUSED(lay),
const bool UNUSED(do_time),
const bool UNUSED(do_invisible_flush))
{
BLI_assert(!"Should not be used with new dependnecy graph");
}
/* ******************* DAG FOR ARMATURE POSE ***************** */
void DAG_pose_sort(Object *UNUSED(ob))
{
BLI_assert(!"Should not be used with new dependnecy graph");
}
/* ************************ DAG FOR THREADED UPDATE ********************* */
void DAG_threaded_update_begin(Scene *UNUSED(scene),
void (*func)(void *node, void *user_data),
void *UNUSED(user_data))
{
BLI_assert(!"Should not be used with new dependnecy graph");
(void)func;
}
void DAG_threaded_update_handle_node_updated(void *UNUSED(node_v),
void (*func)(void *node, void *user_data),
void *UNUSED(user_data))
{
BLI_assert(!"Should not be used with new dependnecy graph");
(void)func;
}
/* ************************ DAG querying ********************* */
Object *DAG_get_node_object(void *UNUSED(node_v))
{
BLI_assert(!"Should not be used with new dependnecy graph");
return NULL;
}
const char *DAG_get_node_name(Scene *UNUSED(scene), void *UNUSED(node_v))
{
BLI_assert(!"Should not be used with new dependnecy graph");
return "INVALID";
}
bool DAG_is_acyclic(Scene *UNUSED(scene))
{
BLI_assert(!"Should not be used with new dependnecy graph");
return false;
}
/* ************************************
* This functions are to be supported *
* ************************************
*/
void DAG_init(void)
{
DEG_register_node_types();
}
void DAG_exit(void)
{
DEG_free_node_types();
}
/* ************************ API *********************** */
void DAG_editors_update_cb(DEG_EditorUpdateIDCb id_func,
DEG_EditorUpdateSceneCb scene_func,
DEG_EditorUpdateScenePreCb scene_func_pre)
{
DEG_editors_set_update_cb(id_func, scene_func, scene_func_pre);
}
void DAG_editors_update_pre(Main *bmain, Scene *scene, bool time)
{
DEG_editors_update_pre(bmain, scene, time);
}
/* Tag all relations for update. */
void DAG_relations_tag_update(Main *bmain)
{
DEG_relations_tag_update(bmain);
}
/* Rebuild dependency graph only for a given scene. */
void DAG_scene_relations_rebuild(Main *bmain, Scene *scene)
{
DEG_scene_relations_rebuild(bmain, scene);
}
/* Create dependency graph if it was cleared or didn't exist yet. */
void DAG_scene_relations_update(Main *bmain, Scene *scene)
{
DEG_scene_relations_update(bmain, scene);
}
void DAG_scene_relations_validate(Main *bmain, Scene *scene)
{
DEG_debug_scene_relations_validate(bmain, scene);
}
void DAG_scene_free(Scene *scene)
{
DEG_scene_graph_free(scene);
}
void DAG_on_visible_update(Main *bmain, const bool do_time)
{
DEG_on_visible_update(bmain, do_time);
}
void DAG_ids_check_recalc(Main *bmain, Scene *scene, bool time)
{
DEG_ids_check_recalc(bmain, scene, time);
}
void DAG_id_tag_update(ID *id, short flag)
{
DEG_id_tag_update_ex(G.main, id, flag);
}
void DAG_id_tag_update_ex(Main *bmain, ID *id, short flag)
{
DEG_id_tag_update_ex(bmain, id, flag);
}
void DAG_id_type_tag(Main *bmain, short idtype)
{
DEG_id_type_tag(bmain, idtype);
}
int DAG_id_type_tagged(Main *bmain, short idtype)
{
return DEG_id_type_tagged(bmain, idtype);
}
void DAG_ids_clear_recalc(Main *bmain)
{
DEG_ids_clear_recalc(bmain);
}
short DAG_get_eval_flags_for_object(Scene *scene, void *object)
{
return DEG_get_eval_flags_for_id(scene->depsgraph, (ID *)object);
}
void DAG_ids_flush_tagged(Main *bmain)
{
DEG_ids_flush_tagged(bmain);
}
/* ************************ DAG DEBUGGING ********************* */
void DAG_print_dependencies(Main *UNUSED(bmain),
Scene *scene,
Object *UNUSED(ob))
{
DEG_debug_graphviz(scene->depsgraph, stdout, "Depsgraph", false);
}
#endif
|