diff options
author | Bastien Montagne <bastien@blender.org> | 2021-03-04 20:39:07 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-03-04 20:43:30 +0300 |
commit | 63b7ff9f4e5f5b0ff5d6bdb726fcd4e1d118e141 (patch) | |
tree | 815da9f2cad39c07d27f14613fbe4b9283e59739 /source/blender/makesdna/DNA_ID.h | |
parent | f951aa063f7a002f4378d3f916750c5d917f4520 (diff) |
Cleanup: Main `foreach ID` code: Remove `MAX_LIBARRAY` and improve comments.
The `MAX_LIBARRAY` define was an annoying doublon to the `INDEX_ID_MAX` enum value
now defined in `DNA_ID.h`, and it is no more useful.
And comments were somewhat outdated. Also added an explanation about
chosen order for the `INDEX_ID_<IDTYPE>` order.
Diffstat (limited to 'source/blender/makesdna/DNA_ID.h')
-rw-r--r-- | source/blender/makesdna/DNA_ID.h | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h index 67e33366199..b985ba1ed5f 100644 --- a/source/blender/makesdna/DNA_ID.h +++ b/source/blender/makesdna/DNA_ID.h @@ -722,8 +722,36 @@ typedef enum IDRecalcFlag { FILTER_ID_TE | FILTER_ID_TXT | FILTER_ID_VF | FILTER_ID_WO | FILTER_ID_CF | FILTER_ID_WS | \ FILTER_ID_LP | FILTER_ID_HA | FILTER_ID_PT | FILTER_ID_VO | FILTER_ID_SIM) -/* IMPORTANT: this enum matches the order currently use in set_listbasepointers, - * keep them in sync! */ +/** + * This enum defines the index assigned to each type of IDs in the array returned by + * #set_listbasepointers, and by extension, controls the default order in which each ID type is + * processed during standard 'foreach' looping over all IDs of a #Main data-base. + * + * About Order: + * ------------ + * + * This is (losely) defined with a relationship order in mind, from lowest level (ID types using, + * referencing almost no other ID types) to highest level (ID types potentially using many other ID + * types). + * + * So e.g. it ensures that this dependency chain is respected: + * #Material <- #Mesh <- #Object <- #Collection <- #Scene + * + * Default order of processing of IDs in 'foreach' macros (#FOREACH_MAIN_ID_BEGIN and the like), + * built on top of #set_listbasepointers, is actually reversed compared to the order defined here, + * since processing usually needs to happen on users before it happens on used IDs (when freeing + * e.g.). + * + * DO NOT rely on this order as being full-proofed dependency order, there are many cases were it + * can be violated (most obvious cases being custom properties and drivers, which can reference any + * other ID types). + * + * However, this order can be considered as an optimization heuristic, especially when processing + * relationships in a non-recursive pattern: in typical cases, a vast majority of those + * relationships can be processed fine in the first pass, and only few additional passes are + * required to address all remaining relationship cases. + * See e.g. how #BKE_library_unused_linked_data_set_tag is doing this. + */ enum { INDEX_ID_LI = 0, INDEX_ID_IP, @@ -763,6 +791,8 @@ enum { INDEX_ID_SCE, INDEX_ID_WS, INDEX_ID_WM, + /* TODO: This should probably be tweaked, #Mask and #Simulation are rather low-level types that + * should most likely be defined //before// #Object and geometry type indices? */ INDEX_ID_MSK, INDEX_ID_SIM, INDEX_ID_NULL, |