Cleanup: rename IDCacheKey.offset_in_ID to identifier

The name `offset_in_ID` is very misleading since it does not have to be an offset at all,
it just has to be some unique value. Often it's also a hash or a constant value depending
on the use.

Pull Request: https://projects.blender.org/blender/blender/pulls/117306
This commit is contained in:
Jacques Lucke
2024-01-18 22:50:40 +01:00
parent 4aad32bcfe
commit d25274ee63
8 changed files with 16 additions and 17 deletions

View File

@@ -55,7 +55,7 @@ typedef struct IDCacheKey {
unsigned int id_session_uuid;
/* Value uniquely identifying the cache within its ID.
* Typically the offset of its member in the data-block struct, but can be anything. */
size_t offset_in_ID;
size_t identifier;
} IDCacheKey;
uint BKE_idtype_cache_key_hash(const void *key_v);

View File

@@ -33,7 +33,7 @@ uint BKE_idtype_cache_key_hash(const void *key_v)
{
const IDCacheKey *key = static_cast<const IDCacheKey *>(key_v);
size_t hash = BLI_ghashutil_uinthash(key->id_session_uuid);
hash = BLI_ghashutil_combine_hash(hash, BLI_ghashutil_uinthash(uint(key->offset_in_ID)));
hash = BLI_ghashutil_combine_hash(hash, BLI_ghashutil_uinthash(uint(key->identifier)));
return uint(hash);
}
@@ -42,7 +42,7 @@ bool BKE_idtype_cache_key_cmp(const void *key_a_v, const void *key_b_v)
const IDCacheKey *key_a = static_cast<const IDCacheKey *>(key_a_v);
const IDCacheKey *key_b = static_cast<const IDCacheKey *>(key_b_v);
return (key_a->id_session_uuid != key_b->id_session_uuid) ||
(key_a->offset_in_ID != key_b->offset_in_ID);
(key_a->identifier != key_b->identifier);
}
static IDTypeInfo *id_types[INDEX_ID_MAX] = {nullptr};

View File

@@ -237,12 +237,12 @@ static void image_foreach_cache(ID *id,
Image *image = (Image *)id;
IDCacheKey key;
key.id_session_uuid = id->session_uuid;
key.offset_in_ID = offsetof(Image, cache);
key.identifier = offsetof(Image, cache);
function_callback(id, &key, (void **)&image->cache, 0, user_data);
key.offset_in_ID = offsetof(Image, anims.first);
key.identifier = offsetof(Image, anims.first);
function_callback(id, &key, (void **)&image->anims.first, 0, user_data);
key.offset_in_ID = offsetof(Image, anims.last);
key.identifier = offsetof(Image, anims.last);
function_callback(id, &key, (void **)&image->anims.last, 0, user_data);
auto gputexture_offset = [image](int target, int eye) {
@@ -258,16 +258,16 @@ static void image_foreach_cache(ID *id,
if (texture == nullptr) {
continue;
}
key.offset_in_ID = gputexture_offset(a, eye);
key.identifier = gputexture_offset(a, eye);
function_callback(id, &key, (void **)&image->gputexture[a][eye], 0, user_data);
}
}
key.offset_in_ID = offsetof(Image, rr);
key.identifier = offsetof(Image, rr);
function_callback(id, &key, (void **)&image->rr, 0, user_data);
LISTBASE_FOREACH (RenderSlot *, slot, &image->renderslots) {
key.offset_in_ID = size_t(BLI_ghashutil_strhash_p(slot->name));
key.identifier = size_t(BLI_ghashutil_strhash_p(slot->name));
function_callback(id, &key, (void **)&slot->render, 0, user_data);
}
}

View File

@@ -142,10 +142,10 @@ static void movie_clip_foreach_cache(ID *id,
MovieClip *movie_clip = (MovieClip *)id;
IDCacheKey key{};
key.id_session_uuid = id->session_uuid;
key.offset_in_ID = offsetof(MovieClip, cache);
key.identifier = offsetof(MovieClip, cache);
function_callback(id, &key, (void **)&movie_clip->cache, 0, user_data);
key.offset_in_ID = offsetof(MovieClip, tracking.camera.intrinsics);
key.identifier = offsetof(MovieClip, tracking.camera.intrinsics);
function_callback(id, &key, (void **)&movie_clip->tracking.camera.intrinsics, 0, user_data);
}

View File

@@ -400,7 +400,7 @@ static void node_foreach_cache(ID *id,
bNodeTree *nodetree = reinterpret_cast<bNodeTree *>(id);
IDCacheKey key = {0};
key.id_session_uuid = id->session_uuid;
key.offset_in_ID = offsetof(bNodeTree, previews);
key.identifier = offsetof(bNodeTree, previews);
/* TODO: see also `direct_link_nodetree()` in `readfile.cc`. */
#if 0
@@ -410,7 +410,7 @@ static void node_foreach_cache(ID *id,
if (nodetree->type == NTREE_COMPOSIT) {
for (bNode *node : nodetree->all_nodes()) {
if (node->type == CMP_NODE_MOVIEDISTORTION) {
key.offset_in_ID = size_t(BLI_ghashutil_strhash_p(node->name));
key.identifier = size_t(BLI_ghashutil_strhash_p(node->name));
function_callback(id, &key, static_cast<void **>(&node->storage), 0, user_data);
}
}

View File

@@ -966,7 +966,7 @@ static void scene_foreach_cache(ID *id,
Scene *scene = (Scene *)id;
IDCacheKey key{};
key.id_session_uuid = id->session_uuid;
key.offset_in_ID = offsetof(Scene, eevee.light_cache_data);
key.identifier = offsetof(Scene, eevee.light_cache_data);
function_callback(id,
&key,

View File

@@ -122,7 +122,7 @@ static void sound_foreach_cache(ID *id,
bSound *sound = (bSound *)id;
IDCacheKey key{};
key.id_session_uuid = id->session_uuid;
key.offset_in_ID = offsetof(bSound, waveform);
key.identifier = offsetof(bSound, waveform);
function_callback(id, &key, &sound->waveform, 0, user_data);
}

View File

@@ -203,8 +203,7 @@ static void volume_foreach_cache(ID *id,
Volume *volume = (Volume *)id;
IDCacheKey key = {
/*id_session_uuid*/ id->session_uuid,
/* This is just some identifier and does not have to be an actual offset. */
/*offset_in_ID*/ 1,
/*identifier*/ 1,
};
function_callback(id, &key, (void **)&volume->runtime->grids, 0, user_data);