[Bf-blender-cvs] [80130465a3f] uuid-id: Add an session-wise uuid integer to IDs.
Bastien Montagne
noreply at git.blender.org
Fri Feb 28 17:41:42 CET 2020
Commit: 80130465a3f4888b4f69b32123959c1619eb5203
Author: Bastien Montagne
Date: Fri Feb 28 17:39:22 2020 +0100
Branches: uuid-id
https://developer.blender.org/rB80130465a3f4888b4f69b32123959c1619eb5203
Add an session-wise uuid integer to IDs.
This is intended to provide undo with a way to find IDs across several
'memory realms' (undo speedup project).
===================================================================
M source/blender/blenkernel/BKE_lib_id.h
M source/blender/blenkernel/intern/lib_id.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/versioning_250.c
M source/blender/makesdna/DNA_ID.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_lib_id.h b/source/blender/blenkernel/BKE_lib_id.h
index d9d99d607c5..1980f53ddbd 100644
--- a/source/blender/blenkernel/BKE_lib_id.h
+++ b/source/blender/blenkernel/BKE_lib_id.h
@@ -67,6 +67,13 @@ void *BKE_libblock_alloc(struct Main *bmain, short type, const char *name, const
ATTR_WARN_UNUSED_RESULT;
void BKE_libblock_init_empty(struct ID *id) ATTR_NONNULL(1);
+/* *** ID's session_uuid management. *** */
+
+/* When an ID's uuid is of that value, it is unset/invalid (e.g. for runtime IDs, etc.). */
+#define BKE_MAIN_ID_UUID_UNSET 0
+
+void BKE_lib_libblock_uuid_generate(struct ID *id);
+
void *BKE_id_new(struct Main *bmain, const short type, const char *name);
void *BKE_id_new_nomain(const short type, const char *name);
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 051b43a177e..5e7300b1e28 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -953,6 +953,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_uuid_generate(id);
}
/** Remove a data-block from given main (set it to 'NO_MAIN' status). */
@@ -1239,6 +1241,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_uuid_generate(id);
+
/* TODO to be removed from here! */
if ((flag & LIB_ID_CREATE_NO_DEG_TAG) == 0) {
DEG_id_type_tag(bmain, type);
@@ -1373,6 +1377,13 @@ void BKE_libblock_init_empty(ID *id)
}
}
+static uint64_t session_uuid = 0;
+/** Generate a session-wise uuid for the given \a id. */
+void BKE_lib_libblock_uuid_generate(ID *id)
+{
+ id->session_uuid = ++session_uuid;
+}
+
/**
* Generic helper to create a new empty data-block of given type in given \a bmain database.
*
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 4adce2d796c..7da84475a51 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8801,6 +8801,8 @@ static ID *create_placeholder(Main *mainvar, const short idcode, const char *idn
BLI_addtail(lb, ph_id);
id_sort_by_name(lb, ph_id, NULL);
+ BKE_lib_libblock_uuid_generate(ph_id);
+
return ph_id;
}
@@ -9013,6 +9015,8 @@ static BHead *read_libblock(FileData *fd,
oldnewmap_insert(fd->libmap, bhead->old, id, bhead->code);
BLI_addtail(lb, id);
+
+ BKE_lib_libblock_uuid_generate(id);
}
else {
/* unknown ID type */
diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c
index a4b51f91be4..2ded8f09306 100644
--- a/source/blender/blenloader/intern/versioning_250.c
+++ b/source/blender/blenloader/intern/versioning_250.c
@@ -446,6 +446,8 @@ static void versions_gpencil_add_main(ListBase *lb, ID *id, const char *name)
BKE_id_new_name_validate(lb, id, name);
/* alphabetic insertion: is in BKE_id_new_name_validate */
+ BKE_lib_libblock_uuid_generate(id);
+
if (G.debug & G_DEBUG) {
printf("Converted GPencil to ID: %s\n", id->name + 2);
}
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index d0ba2b0c4e5..23d16b0b7f6 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -31,6 +31,8 @@
extern "C" {
#endif
+#include "DNA_defs.h"
+
struct FileData;
struct GHash;
struct GPUTexture;
@@ -249,6 +251,12 @@ typedef struct ID {
/** Reference linked ID which this one overrides. */
IDOverrideLibrary *override_library;
+ /**
+ * A session-wide unique identifier for a given ID, that remain the same across potential
+ * re-allocations (e.g. due to undo/redo steps).
+ */
+ uint64_t session_uuid;
+
/**
* Only set for data-blocks which are coming from copy-on-write, points to
* the original version of it.
More information about the Bf-blender-cvs
mailing list