[Bf-blender-cvs] [dfc52b6f6c4] idtype-refactor: Cleanup, more comments.

Bastien Montagne noreply at git.blender.org
Thu Mar 5 10:30:50 CET 2020


Commit: dfc52b6f6c4d0a8b05e3e0933c46bd5e769b9a34
Author: Bastien Montagne
Date:   Thu Mar 5 10:28:50 2020 +0100
Branches: idtype-refactor
https://developer.blender.org/rBdfc52b6f6c4d0a8b05e3e0933c46bd5e769b9a34

Cleanup, more comments.

===================================================================

M	source/blender/blenkernel/BKE_idtype.h
M	source/blender/blenkernel/intern/idtype.c
M	source/blender/blenkernel/intern/lib_id.c
M	source/blender/blenkernel/intern/lib_id_delete.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h
index 183d8c3a26d..ba0cf04dfc6 100644
--- a/source/blender/blenkernel/BKE_idtype.h
+++ b/source/blender/blenkernel/BKE_idtype.h
@@ -33,13 +33,18 @@ extern "C" {
 struct ID;
 struct Main;
 
+/** IDTypeInfo.flags. */
 enum {
-  /* Indicates that the given IDType does not support the matching feature. */
+  /** Indicates that the given IDType does not support copying. */
   IDTYPE_FLAGS_NO_COPY = 1 << 0,
+  /** Indicates that the given IDType does not support linking/appending from a library file. */
   IDTYPE_FLAGS_NO_LIBLINKING = 1 << 1,
+  /** Indicates that the given IDType does not support making a library-linked ID local. */
   IDTYPE_FLAGS_NO_MAKELOCAL = 1 << 2,
 };
 
+/* ********** Prototypes for IDTypeInfo callbacks. ********** */
+
 typedef void (*IDTypeInitDataFunction)(struct ID *id);
 
 /** \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more). */
@@ -54,30 +59,45 @@ typedef void (*IDTypeFreeDataFunction)(struct ID *id);
 typedef void (*IDTypeMakeLocalFunction)(struct Main *bmain, struct ID *id, const int flags);
 
 typedef struct IDTypeInfo {
-  /* Unique identifier of this type, either as a short or an array of two chars. */
+  /* ********** General IDType data. ********** */
+
+  /**
+   * Unique identifier of this type, either as a short or an array of two chars, see DNA_ID.h's
+   * ID_XX enums.
+   */
   short id_code;
-  /* Bitflag matching id_type, used for filtering (e.g. in file browser). */
+  /**
+   * Bitflag matching id_code, used for filtering (e.g. in file browser), see DNA_ID.h's
+   * FILTER_ID_XX enums.
+   */
   int id_filter;
 
-  /* Define the position of this data-block type in the virtual list of all data in a Main that is
+  /**
+   * Define the position of this data-block type in the virtual list of all data in a Main that is
    * returned by `set_listbasepointers()`.
-   * Very important, this has to be unique and below INDEX_ID_MAX, see DNA_ID.h. */
+   * Very important, this has to be unique and below INDEX_ID_MAX, see DNA_ID.h.
+   */
   short main_listbase_index;
 
-  /* Memory size of a data-block of that type. */
+  /** Memory size of a data-block of that type. */
   size_t struct_size;
 
-  /* The user visible name for this data-block. */
+  /** The user visible name for this data-block, also used as default name for a new data-block. */
   const char *name;
-  /* Plural version of the user-visble name. */
+  /** Plural version of the user-visble name. */
   const char *name_plural;
-  /* Translation context to use for UI messages related to that type of data-block. */
+  /** Translation context to use for UI messages related to that type of data-block. */
   const char *translation_context;
 
-  /* Generic info flags about that data-block type. */
+  /** Generic info flags about that data-block type. */
   int flags;
 
   /* ********** ID management callbacks ********** */
+
+  /* TODO: Note about callbacks: Ideally we could also handle here `BKE_lib_query`'s behavior, as
+   * well as read/write of files. However, this is a bit more involved than basic ID management
+   * callbacks, so we'll check on this later. */
+
   /**
    * Initialize a new, empty calloc'ed data-block. May be NULL if there is nothing to do.
    */
@@ -101,14 +121,20 @@ typedef struct IDTypeInfo {
   IDTypeMakeLocalFunction make_local;
 } IDTypeInfo;
 
+/* ********** Declaration of each IDTypeInfo. ********** */
+
+/* Those are defined in the respective BKE files. */
+extern IDTypeInfo IDType_ID_OB;
+
+/* ********** Helpers/Utils API. ********** */
+
 /* Module initialization. */
 void BKE_idtype_init(void);
 
+/* General helpers. */
 const struct IDTypeInfo *BKE_idtype_get_info_from_idcode(const short id_code);
 const struct IDTypeInfo *BKE_idtype_get_info_from_id(const struct ID *id);
 
-extern IDTypeInfo IDType_ID_OB;
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c
index b6b2d685ffb..494d83535b4 100644
--- a/source/blender/blenkernel/intern/idtype.c
+++ b/source/blender/blenkernel/intern/idtype.c
@@ -66,7 +66,7 @@ const IDTypeInfo *BKE_idtype_get_info_from_idcode(const short id_code)
 {
   int id_index = BKE_idcode_to_index(id_code);
 
-  if (id_index < INDEX_ID_MAX && id_types[id_index] != NULL &&
+  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];
   }
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 203ff22f5cb..416de844691 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -450,10 +450,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags
 
   const IDTypeInfo *idtype_info = BKE_idtype_get_info_from_id(id);
 
-  printf("%s: ", __func__);
-
   if (idtype_info != NULL) {
-    printf("Found IDTypeInfo for %c%c, using new code...\n", id->name[0], id->name[1]);
     if ((idtype_info->flags & IDTYPE_FLAGS_NO_MAKELOCAL) == 0) {
       if (!test) {
         if (idtype_info->make_local != NULL) {
@@ -468,8 +465,6 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags
     return false;
   }
 
-  printf("No IDTypeInfo for %c%c, using old code...\n", id->name[0], id->name[1]);
-
   switch ((ID_Type)GS(id->name)) {
     case ID_SCE:
       if (!test) {
@@ -715,11 +710,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag)
 
   const IDTypeInfo *idtype_info = BKE_idtype_get_info_from_id(id);
 
-  printf("%s: ", __func__);
-
   if (idtype_info != NULL) {
-    printf("Found IDTypeInfo for %c%c, using new code...\n", id->name[0], id->name[1]);
-
     if ((idtype_info->flags & IDTYPE_FLAGS_NO_COPY) != 0) {
       return false;
     }
@@ -731,8 +722,6 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag)
     }
   }
   else {
-    printf("No IDTypeInfo for %c%c, using old code...\n", id->name[0], id->name[1]);
-
     if (!BKE_id_copy_is_allowed(id)) {
       return false;
     }
@@ -1345,18 +1334,13 @@ void BKE_libblock_init_empty(ID *id)
 {
   const IDTypeInfo *idtype_info = BKE_idtype_get_info_from_id(id);
 
-  printf("%s: ", __func__);
-
   if (idtype_info != NULL) {
-    printf("Found IDTypeInfo for %c%c, using new code...\n", id->name[0], id->name[1]);
     if (idtype_info->init_data != NULL) {
       idtype_info->init_data(id);
     }
     return;
   }
 
-  printf("No IDTypeInfo for %c%c, using old code...\n", id->name[0], id->name[1]);
-
   /* Note that only ID types that are not valid when filled of zero should have a callback here. */
   switch ((ID_Type)GS(id->name)) {
     case ID_SCE:
diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c
index 3d47e564ab0..d47510ea9af 100644
--- a/source/blender/blenkernel/intern/lib_id_delete.c
+++ b/source/blender/blenkernel/intern/lib_id_delete.c
@@ -127,18 +127,13 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag))
 {
   const IDTypeInfo *idtype_info = BKE_idtype_get_info_from_id(id);
 
-  printf("%s: ", __func__);
-
   if (idtype_info != NULL) {
-    printf("Found IDTypeInfo for %c%c, using new code...\n", id->name[0], id->name[1]);
     if (idtype_info->free_data != NULL) {
       idtype_info->free_data(id);
     }
     return;
   }
 
-  printf("No IDTypeInfo for %c%c, using old code...\n", id->name[0], id->name[1]);
-
   const short type = GS(id->name);
   switch (type) {
     case ID_SCE:



More information about the Bf-blender-cvs mailing list