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:
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_asset_engine.h65
-rw-r--r--source/blender/blenkernel/CMakeLists.txt2
-rw-r--r--source/blender/blenkernel/intern/asset_engine.c127
-rw-r--r--source/blender/blenkernel/intern/lib_id_delete.c2
-rw-r--r--source/blender/blenkernel/intern/lib_remap.c1
5 files changed, 197 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_asset_engine.h b/source/blender/blenkernel/BKE_asset_engine.h
new file mode 100644
index 00000000000..6ad9de6918d
--- /dev/null
+++ b/source/blender/blenkernel/BKE_asset_engine.h
@@ -0,0 +1,65 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2015 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file BKE_asset_engine.h
+ * \ingroup bke
+ */
+
+#ifndef __BKE_ASSET_ENGINE_H__
+#define __BKE_ASSET_ENGINE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct AssetUUID;
+struct Main;
+
+#define ASSETUUID_SUB_EQUAL(_uuida, _uuidb, _member) \
+ (memcmp((_uuida)->_member, (_uuidb)->_member, sizeof((_uuida)->_member)) == 0)
+
+#define ASSETUUID_EQUAL(_uuida, _uuidb) \
+ (ASSETUUID_SUB_EQUAL(_uuida, _uuidb, uuid_repository) && \
+ ASSETUUID_SUB_EQUAL(_uuida, _uuidb, uuid_asset) && \
+ ASSETUUID_SUB_EQUAL(_uuida, _uuidb, uuid_variant) && \
+ ASSETUUID_SUB_EQUAL(_uuida, _uuidb, uuid_revision) && \
+ ASSETUUID_SUB_EQUAL(_uuida, _uuidb, uuid_view))
+
+/* Various helpers */
+void BKE_asset_uuid_runtime_reset(struct AssetUUID *uuid);
+
+unsigned int BKE_asset_uuid_hash(const void *key);
+bool BKE_asset_uuid_cmp(const void *a, const void *b);
+void BKE_asset_uuid_print(const struct AssetUUID *uuid);
+
+void BKE_asset_main_search(struct Main *bmain, struct AssetUUID *uuid);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BKE_ASSET_ENGINE_H__ */
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index b9054d29752..92e0904c568 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -76,6 +76,7 @@ set(SRC
intern/armature.c
intern/armature_deform.c
intern/armature_update.c
+ intern/asset_engine.c
intern/autoexec.c
intern/blender.c
intern/blender_copybuffer.c
@@ -266,6 +267,7 @@ set(SRC
BKE_animsys.h
BKE_appdir.h
BKE_armature.h
+ BKE_asset_engine.h
BKE_autoexec.h
BKE_blender.h
BKE_blender_copybuffer.h
diff --git a/source/blender/blenkernel/intern/asset_engine.c b/source/blender/blenkernel/intern/asset_engine.c
new file mode 100644
index 00000000000..b309db81f88
--- /dev/null
+++ b/source/blender/blenkernel/intern/asset_engine.c
@@ -0,0 +1,127 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2015 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/asset_engine.c
+ * \ingroup bke
+ */
+
+#include <string.h>
+
+#include "BLI_utildefines.h"
+#include "BLI_hash_mm2a.h"
+#include "BLI_listbase.h"
+
+#include "BKE_asset_engine.h"
+#include "BKE_main.h"
+
+#include "IMB_imbuf.h"
+
+#include "DNA_ID.h"
+
+#include "MEM_guardedalloc.h"
+
+#ifdef WITH_PYTHON
+# include "BPY_extern.h"
+#endif
+
+/* Various helpers */
+void BKE_asset_uuid_runtime_reset(AssetUUID *uuid) {
+ uuid->preview_image_buffer = NULL;
+ uuid->preview_width = uuid->preview_height = 0;
+ uuid->tag = 0;
+ uuid->id = NULL;
+}
+
+unsigned int BKE_asset_uuid_hash(const void *key)
+{
+ BLI_HashMurmur2A mm2a;
+ const AssetUUID *uuid = key;
+ BLI_hash_mm2a_init(&mm2a, 0);
+ BLI_hash_mm2a_add(&mm2a, (const uchar *)uuid->uuid_repository, sizeof(uuid->uuid_repository));
+ BLI_hash_mm2a_add(&mm2a, (const uchar *)uuid->uuid_asset, sizeof(uuid->uuid_asset));
+ BLI_hash_mm2a_add(&mm2a, (const uchar *)uuid->uuid_variant, sizeof(uuid->uuid_variant));
+ BLI_hash_mm2a_add(&mm2a, (const uchar *)uuid->uuid_revision, sizeof(uuid->uuid_revision));
+ BLI_hash_mm2a_add(&mm2a, (const uchar *)uuid->uuid_view, sizeof(uuid->uuid_view));
+ return BLI_hash_mm2a_end(&mm2a);
+}
+
+bool BKE_asset_uuid_cmp(const void *a, const void *b)
+{
+ const AssetUUID *uuid1 = a;
+ const AssetUUID *uuid2 = b;
+ return !ASSETUUID_EQUAL(uuid1, uuid2); /* Expects false when compared equal. */
+}
+
+void BKE_asset_uuid_print(const AssetUUID *uuid)
+{
+ /* TODO print nicer (as 128bit hexadecimal?). */
+ printf("[%.10d,%.10d,%.10d,%.10d]"
+ "[%.10d,%.10d,%.10d,%.10d]"
+ "[%.10d,%.10d,%.10d,%.10d]"
+ "[%.10d,%.10d,%.10d,%.10d]"
+ "[%.10d,%.10d,%.10d,%.10d]\n",
+ uuid->uuid_repository[0],
+ uuid->uuid_repository[1],
+ uuid->uuid_repository[2],
+ uuid->uuid_repository[3],
+ uuid->uuid_asset[0],
+ uuid->uuid_asset[1],
+ uuid->uuid_asset[2],
+ uuid->uuid_asset[3],
+ uuid->uuid_variant[0],
+ uuid->uuid_variant[1],
+ uuid->uuid_variant[2],
+ uuid->uuid_variant[3],
+ uuid->uuid_revision[0],
+ uuid->uuid_revision[1],
+ uuid->uuid_revision[2],
+ uuid->uuid_revision[3],
+ uuid->uuid_view[0],
+ uuid->uuid_view[1],
+ uuid->uuid_view[2],
+ uuid->uuid_view[3]);
+}
+
+/** Search the whole Main for a given asset uuid.
+ *
+ * \note if found, ID is put into uuid->id pointer. */
+void BKE_asset_main_search(Main *bmain, AssetUUID *uuid)
+{
+ uuid->id = NULL;
+
+ ID *id;
+ FOREACH_MAIN_ID_BEGIN (bmain, id) {
+ if (id->uuid == NULL) {
+ continue;
+ }
+ if (ASSETUUID_EQUAL(id->uuid, uuid)) {
+ uuid->id = id;
+ return;
+ }
+ }
+ FOREACH_MAIN_ID_END;
+}
diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c
index b4f2caac861..9d7671322ea 100644
--- a/source/blender/blenkernel/intern/lib_id_delete.c
+++ b/source/blender/blenkernel/intern/lib_id_delete.c
@@ -63,6 +63,8 @@ void BKE_libblock_free_data(ID *id, const bool do_id_user)
}
BKE_animdata_free(id, do_id_user);
+
+ MEM_SAFE_FREE(id->uuid);
}
void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag))
diff --git a/source/blender/blenkernel/intern/lib_remap.c b/source/blender/blenkernel/intern/lib_remap.c
index d4246056efe..777a4fb9dfa 100644
--- a/source/blender/blenkernel/intern/lib_remap.c
+++ b/source/blender/blenkernel/intern/lib_remap.c
@@ -29,6 +29,7 @@
#include "BKE_armature.h"
#include "BKE_collection.h"
#include "BKE_curve.h"
+#include "BKE_idprop.h"
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"