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 12:54:00 +0300
committerBastien Montagne <b.mont29@gmail.com>2020-03-05 12:58:58 +0300
commitc328049535a4bc9453f5e93365a00759347e3a05 (patch)
treea6a058f3887e81e653c93400ecd163755796bddc /source/blender/blenkernel/intern/idtype.c
parent6665ce8951b2110e5dbd7126aae3c120bb6205e5 (diff)
Initial step for IDTypeInfo refactor 'cleanup' project.
Introduce new IDTypeInfo structure. Each ID type will have its own, with some minimal basic common info, and ID management callbacks. This patch only does it for Object type, for demo/testing purpose. Moving all existing IDs is a goal of next "cleanup Friday". Note that BKE_idcode features should then be merged back into BKE_idtype - but this will have to be done later, once all ID types have been properly converted to the new system. Another later TODO might be to try and add callbacks for file read/write, and lib_query ID usages looper. This is part of T73719. Thanks to @brecht for initial idea, and reviewing the patch. Differential Revision: https://developer.blender.org/D6966
Diffstat (limited to 'source/blender/blenkernel/intern/idtype.c')
-rw-r--r--source/blender/blenkernel/intern/idtype.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c
new file mode 100644
index 00000000000..494d83535b4
--- /dev/null
+++ b/source/blender/blenkernel/intern/idtype.c
@@ -0,0 +1,81 @@
+/*
+ * 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) 2005 by the Blender Foundation.
+ * All rights reserved.
+ * Modifier stack implementation.
+ *
+ * BKE_modifier.h contains the function prototypes for this file.
+ */
+
+/** \file
+ * \ingroup bke
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+
+#include "CLG_log.h"
+
+#include "BLT_translation.h"
+
+#include "DNA_ID.h"
+
+#include "BKE_idcode.h"
+
+#include "BKE_idtype.h"
+
+// static CLG_LogRef LOG = {"bke.idtype"};
+
+static IDTypeInfo *id_types[INDEX_ID_MAX] = {NULL};
+
+static void id_type_init(void)
+{
+#define INIT_TYPE(_id_code) \
+ { \
+ BLI_assert(IDType_##_id_code.main_listbase_index == INDEX_##_id_code); \
+ id_types[INDEX_##_id_code] = &IDType_##_id_code; \
+ } \
+ (void)0
+
+ INIT_TYPE(ID_OB);
+
+#undef INIT_TYPE
+}
+
+void BKE_idtype_init(void)
+{
+ /* Initialize data-block types. */
+ id_type_init();
+}
+
+const IDTypeInfo *BKE_idtype_get_info_from_idcode(const short id_code)
+{
+ int id_index = BKE_idcode_to_index(id_code);
+
+ if (id_index >= 0 && id_index < INDEX_ID_MAX && id_types[id_index] != NULL &&
+ id_types[id_index]->name[0] != '\0') {
+ return id_types[id_index];
+ }
+ else {
+ return NULL;
+ }
+}
+
+const IDTypeInfo *BKE_idtype_get_info_from_id(const ID *id)
+{
+ return BKE_idtype_get_info_from_idcode(GS(id->name));
+}