Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <b.mont29@gmail.com>2020-03-05 18:17:14 +0300
committerBastien Montagne <b.mont29@gmail.com>2020-03-05 18:30:12 +0300
commitc43725e1891bd8534ac4b668277cddae9762d524 (patch)
tree59e26be9adb639b82305ce0f6f4dc36490052f06 /source/blender/blenkernel/intern/lib_id.c
parent88db9a17ce70c4553be1922e3ecef091e8c1d039 (diff)
Add an session-wise uuid integer to IDs.
"session-wise" here mean while editing a same .blend file. So creating or opening a new one will reset the uuid counter. This should avoid any overflow in practice. Only IDs added to Main database get an uuid, runtime-only ones are not affected. This is intended to provide undo with a way to find IDs across several 'memory realms' (undo speedup project). No behavior change is expected from this commit itself. Part of T60695. Differential Revision: https://developer.blender.org/D7007
Diffstat (limited to 'source/blender/blenkernel/intern/lib_id.c')
-rw-r--r--source/blender/blenkernel/intern/lib_id.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 416de844691..92e9a7c6c79 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -1027,6 +1027,8 @@ void BKE_libblock_management_main_add(Main *bmain, void *idv)
id->tag &= ~(LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT);
bmain->is_memfile_undo_written = false;
BKE_main_unlock(bmain);
+
+ BKE_lib_libblock_session_uuid_ensure(id);
}
/** Remove a data-block from given main (set it to 'NO_MAIN' status). */
@@ -1313,6 +1315,8 @@ void *BKE_libblock_alloc(Main *bmain, short type, const char *name, const int fl
/* alphabetic insertion: is in new_id */
BKE_main_unlock(bmain);
+ BKE_lib_libblock_session_uuid_ensure(id);
+
/* TODO to be removed from here! */
if ((flag & LIB_ID_CREATE_NO_DEG_TAG) == 0) {
DEG_id_type_tag(bmain, type);
@@ -1456,6 +1460,33 @@ void BKE_libblock_init_empty(ID *id)
}
}
+/* ********** ID session-wise UUID management. ********** */
+static uint global_session_uuid = 0;
+
+/** Reset the session-wise uuid counter (used when reading a new file e.g.). */
+void BKE_lib_libblock_session_uuid_reset()
+{
+ global_session_uuid = 0;
+}
+
+/**
+ * Generate a session-wise uuid for the given \a id.
+ *
+ * \note "session-wise" here means while editing a given .blend file. Once a new .blend file is
+ * loaded or created, undo history is cleared/reset, and so is the uuid counter.
+ */
+void BKE_lib_libblock_session_uuid_ensure(ID *id)
+{
+ if (id->session_uuid == MAIN_ID_SESSION_UUID_UNSET) {
+ id->session_uuid = atomic_add_and_fetch_uint32(&global_session_uuid, 1);
+ /* In case overflow happens, still assign a valid ID. This way opening files many times works
+ * correctly. */
+ if (UNLIKELY(id->session_uuid == MAIN_ID_SESSION_UUID_UNSET)) {
+ id->session_uuid = atomic_add_and_fetch_uint32(&global_session_uuid, 1);
+ }
+ }
+}
+
/**
* Generic helper to create a new empty data-block of given type in given \a bmain database.
*