diff options
author | Bastien Montagne <bastien@blender.org> | 2021-01-21 16:52:40 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-01-22 18:05:17 +0300 |
commit | 131a758b6f88a2be816e9351d216bcfb9c965c4b (patch) | |
tree | 436143ecac78e41dcc3b590f0f9197778492be3c /source/blender/blenkernel/BKE_main.h | |
parent | be7106a974646483f4b087539c62603fe53560cf (diff) |
Refactor BMain relations temp data.
`bmain.relations` is used to store temp data of relations between IDs,
to speed-up some complex processes heavily relying on such information.
Previous implementation was failry unclear/confusing, and required a
not-so-nice hack to 'tag' some ID as processed.
New code changes as such:
* Using `from`/`to` naming (instead of `user`/`used`).
* More clear separation between `to` `id_pointer` and `from` one,
using an union instead of hacking around difference between `ID *` and
`ID **` pointers.
* Adds storage of `session_uuid` informations (mainly useful as
debug/ensuring proper consistency of data currently).
* Adds a structure per ID in the mapping. This enables possibility of
storing tags (and potentially more data in the future) per-ID,
without polluting the IDs themselves with very short-life info.
Differential Revision: https://developer.blender.org/D10164
Diffstat (limited to 'source/blender/blenkernel/BKE_main.h')
-rw-r--r-- | source/blender/blenkernel/BKE_main.h | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h index 8106607572b..0768423fc5f 100644 --- a/source/blender/blenkernel/BKE_main.h +++ b/source/blender/blenkernel/BKE_main.h @@ -60,22 +60,52 @@ typedef struct BlendThumbnail { } BlendThumbnail; /* Structs caching relations between data-blocks in a given Main. */ +typedef struct MainIDRelationsEntryItem { + struct MainIDRelationsEntryItem *next; + + union { + /* For `from_ids` list, a user of the hashed ID. */ + struct ID *from; + /* For `to_ids` list, an ID used by the hashed ID. */ + struct ID **to; + } id_pointer; + /* Session uuid of the `id_pointer`. */ + uint session_uuid; + + int usage_flag; /* Using IDWALK_ enums, defined in BKE_lib_query.h */ +} MainIDRelationsEntryItem; + typedef struct MainIDRelationsEntry { - struct MainIDRelationsEntry *next; - /* WARNING! for user_to_used, - * that pointer is really an ID** one, but for used_to_user, it’s only an ID* one! */ - struct ID **id_pointer; - int usage_flag; /* Using IDWALK_ enums, in BKE_lib_query.h */ + /* Linked list of IDs using that ID. */ + struct MainIDRelationsEntryItem *from_ids; + /* Linked list of IDs used by that ID. */ + struct MainIDRelationsEntryItem *to_ids; + + /* Session uuid of the ID matching that entry. */ + uint session_uuid; + + /* Runtime tags, users should ensure those are reset after usage. */ + uint tags; } MainIDRelationsEntry; +/* MainIDRelationsEntry.tags */ +typedef enum MainIDRelationsEntryTags { + /* Generic tag marking the entry as to be processed. */ + MAINIDRELATIONS_ENTRY_TAGS_DOIT = 1 << 0, + /* Generic tag marking the entry as processed. */ + MAINIDRELATIONS_ENTRY_TAGS_PROCESSED = 1 << 1, +} MainIDRelationsEntryTags; + typedef struct MainIDRelations { - struct GHash *id_user_to_used; - struct GHash *id_used_to_user; + /* Mapping from an ID pointer to all of its parents (IDs using it) and children (IDs it uses). + * Values are `MainIDRelationsEntry` pointers. */ + struct GHash *relations_from_pointers; + /* Note: we could add more mappings when needed (e.g. from session uuid?). */ short flag; /* Private... */ - struct BLI_mempool *entry_pool; + struct BLI_mempool *entry_items_pool; } MainIDRelations; enum { @@ -172,7 +202,6 @@ void BKE_main_unlock(struct Main *bmain); void BKE_main_relations_create(struct Main *bmain, const short flag); void BKE_main_relations_free(struct Main *bmain); -void BKE_main_relations_ID_remove(struct Main *bmain, struct ID *id); struct GSet *BKE_main_gset_create(struct Main *bmain, struct GSet *gset); |