Blender V5.0
deg_builder_cache.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2018 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "DNA_anim_types.h"
12
13#include "BKE_anim_data.hh"
14
15#include "RNA_access.hh"
16#include "RNA_path.hh"
17
18namespace blender::deg {
19
20/* Animated property storage. */
21
23
29
35
36AnimatedPropertyID::AnimatedPropertyID(const ID *id, StructRNA *type, const char *property_name)
37 : data(id)
38{
39 property_rna = RNA_struct_type_find_property(type, property_name);
40}
41
43 StructRNA *type,
44 void *data,
45 const char *property_name)
46 : data(data)
47{
48 property_rna = RNA_struct_type_find_property(type, property_name);
49}
50
52{
53 return a.data == b.data && a.property_rna == b.property_rna;
54}
55
57{
58 uintptr_t ptr1 = uintptr_t(data);
59 uintptr_t ptr2 = uintptr_t(property_rna);
60 return uint64_t(((ptr1 >> 4) * 33) ^ (ptr2 >> 4));
61}
62
64
66{
67 PointerRNA own_pointer_rna = RNA_id_pointer_create(const_cast<ID *>(id));
68 BKE_fcurves_id_cb(const_cast<ID *>(id), [&](ID * /*id*/, FCurve *fcurve) {
69 if (fcurve->rna_path == nullptr || fcurve->rna_path[0] == '\0') {
70 return;
71 }
72 /* Resolve property. */
73 PointerRNA pointer_rna;
74 PropertyRNA *property_rna = nullptr;
76 &own_pointer_rna, fcurve->rna_path, &pointer_rna, &property_rna))
77 {
78 return;
79 }
80 /* Get storage for the ID.
81 * This is needed to deal with cases when nested datablock is animated by its parent. */
82 AnimatedPropertyStorage *animated_property_storage = this;
83 if (pointer_rna.owner_id != own_pointer_rna.owner_id) {
84 animated_property_storage = builder_cache->ensureAnimatedPropertyStorage(
85 pointer_rna.owner_id);
86 }
87 /* Set the property as animated. */
88 animated_property_storage->tagPropertyAsAnimated(&pointer_rna, property_rna);
89 });
90}
91
93{
94 animated_objects_set.add(property_id.data);
95 animated_properties_set.add(property_id);
96}
97
99 const PropertyRNA *property_rna)
100{
101 tagPropertyAsAnimated(AnimatedPropertyID(pointer_rna, property_rna));
102}
103
105{
106 return animated_properties_set.contains(property_id);
107}
108
110 const PropertyRNA *property_rna)
111{
112 return isPropertyAnimated(AnimatedPropertyID(pointer_rna, property_rna));
113}
114
116{
117 return animated_objects_set.contains(pointer_rna->data);
118}
119
120/* Builder cache itself. */
121
123{
124 for (AnimatedPropertyStorage *animated_property_storage :
126 {
127 delete animated_property_storage;
128 }
129}
130
136
138 const ID *id)
139{
140 AnimatedPropertyStorage *animated_property_storage = ensureAnimatedPropertyStorage(id);
141 if (!animated_property_storage->is_fully_initialized) {
142 animated_property_storage->initializeFromID(this, id);
143 animated_property_storage->is_fully_initialized = true;
144 }
145 return animated_property_storage;
146}
147
148} // namespace blender::deg
void BKE_fcurves_id_cb(struct ID *id, blender::FunctionRef< void(ID *, FCurve *)> func)
unsigned long long int uint64_t
Set< AnimatedPropertyID > animated_properties_set
void initializeFromID(DepsgraphBuilderCache *builder_cache, const ID *id)
bool isAnyPropertyAnimated(const PointerRNA *pointer_rna)
bool isPropertyAnimated(const AnimatedPropertyID &property_id)
void tagPropertyAsAnimated(const AnimatedPropertyID &property_id)
Map< const ID *, AnimatedPropertyStorage * > animated_property_storage_map_
AnimatedPropertyStorage * ensureInitializedAnimatedPropertyStorage(const ID *id)
AnimatedPropertyStorage * ensureAnimatedPropertyStorage(const ID *id)
bool operator==(const AnimatedPropertyID &a, const AnimatedPropertyID &b)
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
PointerRNA RNA_id_pointer_create(ID *id)
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:560
char * rna_path
Definition DNA_ID.h:414
ID * owner_id
Definition RNA_types.hh:51
void * data
Definition RNA_types.hh:53