Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/blender/blender_id_map.h
| Show All 29 Lines | |||||
| /* ID Map | /* ID Map | ||||
| * | * | ||||
| * Utility class to map between Blender datablocks and Cycles data structures, | * Utility class to map between Blender datablocks and Cycles data structures, | ||||
| * and keep track of recalc tags from the dependency graph. */ | * and keep track of recalc tags from the dependency graph. */ | ||||
| template<typename K, typename T> class id_map { | template<typename K, typename T> class id_map { | ||||
| public: | public: | ||||
| id_map() | id_map(Scene *scene_) : scene(scene_) | ||||
| { | { | ||||
| } | } | ||||
| ~id_map() | |||||
| { | |||||
| typename map<K, T *>::iterator jt; | |||||
| for (jt = b_map.begin(); jt != b_map.end(); jt++) { | |||||
| scene->delete_node(jt->second); | |||||
| } | |||||
brecht: This has quadratic time complexity, so it will be extremely slow when there are e.g. 100k… | |||||
| } | |||||
| T *find(const BL::ID &id) | T *find(const BL::ID &id) | ||||
| { | { | ||||
| return find(id.ptr.owner_id); | return find(id.ptr.owner_id); | ||||
| } | } | ||||
| T *find(const K &key) | T *find(const K &key) | ||||
| { | { | ||||
| if (b_map.find(key) != b_map.end()) { | if (b_map.find(key) != b_map.end()) { | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | bool update(T *data, const BL::ID &id, const BL::ID &parent) | ||||
| if (parent.ptr.data && parent.ptr.data != id.ptr.data) { | if (parent.ptr.data && parent.ptr.data != id.ptr.data) { | ||||
| recalc = recalc || (b_recalc.find(parent.ptr.data) != b_recalc.end()); | recalc = recalc || (b_recalc.find(parent.ptr.data) != b_recalc.end()); | ||||
| } | } | ||||
| used(data); | used(data); | ||||
| return recalc; | return recalc; | ||||
| } | } | ||||
| /* Combined add and update as needed. */ | /* Combined add and update as needed. */ | ||||
| bool add_or_update(Scene *scene, T **r_data, const BL::ID &id) | bool add_or_update(T **r_data, const BL::ID &id) | ||||
| { | { | ||||
| return add_or_update(scene, r_data, id, id, id.ptr.owner_id); | return add_or_update(r_data, id, id, id.ptr.owner_id); | ||||
| } | } | ||||
| bool add_or_update(Scene *scene, T **r_data, const BL::ID &id, const K &key) | bool add_or_update(T **r_data, const BL::ID &id, const K &key) | ||||
| { | { | ||||
| return add_or_update(scene, r_data, id, id, key); | return add_or_update(r_data, id, id, key); | ||||
| } | } | ||||
| bool add_or_update( | bool add_or_update(T **r_data, const BL::ID &id, const BL::ID &parent, const K &key) | ||||
| Scene *scene, T **r_data, const BL::ID &id, const BL::ID &parent, const K &key) | |||||
| { | { | ||||
| T *data = find(key); | T *data = find(key); | ||||
| bool recalc; | bool recalc; | ||||
| if (!data) { | if (!data) { | ||||
| /* Add data if it didn't exist yet. */ | /* Add data if it didn't exist yet. */ | ||||
| data = scene->create_node<T>(); | data = scene->create_node<T>(); | ||||
| add(key, data); | add(key, data); | ||||
| Show All 22 Lines | void used(T *data) | ||||
| used_set.insert(data); | used_set.insert(data); | ||||
| } | } | ||||
| void set_default(T *data) | void set_default(T *data) | ||||
| { | { | ||||
| b_map[NULL] = data; | b_map[NULL] = data; | ||||
| } | } | ||||
| void post_sync(Scene *scene, bool do_delete = true) | void post_sync(bool do_delete = true) | ||||
| { | { | ||||
| map<K, T *> new_map; | map<K, T *> new_map; | ||||
| typedef pair<const K, T *> TMapPair; | typedef pair<const K, T *> TMapPair; | ||||
| typename map<K, T *>::iterator jt; | typename map<K, T *>::iterator jt; | ||||
| for (jt = b_map.begin(); jt != b_map.end(); jt++) { | for (jt = b_map.begin(); jt != b_map.end(); jt++) { | ||||
| TMapPair &pair = *jt; | TMapPair &pair = *jt; | ||||
| Show All 14 Lines | public: | ||||
| { | { | ||||
| return b_map; | return b_map; | ||||
| } | } | ||||
| protected: | protected: | ||||
| map<K, T *> b_map; | map<K, T *> b_map; | ||||
| set<T *> used_set; | set<T *> used_set; | ||||
| set<void *> b_recalc; | set<void *> b_recalc; | ||||
| Scene *scene; | |||||
| }; | }; | ||||
| /* Object Key | /* Object Key | ||||
| * | * | ||||
| * To uniquely identify instances, we use the parent, object and persistent instance ID. | * To uniquely identify instances, we use the parent, object and persistent instance ID. | ||||
| * We also export separate object for a mesh and its particle hair. */ | * We also export separate object for a mesh and its particle hair. */ | ||||
| enum { OBJECT_PERSISTENT_ID_SIZE = 8 /* MAX_DUPLI_RECUR in Blender. */ }; | enum { OBJECT_PERSISTENT_ID_SIZE = 8 /* MAX_DUPLI_RECUR in Blender. */ }; | ||||
| ▲ Show 20 Lines • Show All 96 Lines • Show Last 20 Lines | |||||
This has quadratic time complexity, so it will be extremely slow when there are e.g. 100k object instances.
Can you find a way to avoid this?