[Bf-blender-cvs] [94c533ac35d] master: Refactor: move Light .blend I/O to IDTypeInfo callbacks

Jacques Lucke noreply at git.blender.org
Thu Sep 10 16:13:40 CEST 2020


Commit: 94c533ac35d4ad5d944c214d4809011b61be4a94
Author: Jacques Lucke
Date:   Thu Sep 10 16:13:18 2020 +0200
Branches: master
https://developer.blender.org/rB94c533ac35d4ad5d944c214d4809011b61be4a94

Refactor: move Light .blend I/O to IDTypeInfo callbacks

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

M	source/blender/blenkernel/intern/light.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenkernel/intern/light.c b/source/blender/blenkernel/intern/light.c
index 976fa010057..1ce079b006e 100644
--- a/source/blender/blenkernel/intern/light.c
+++ b/source/blender/blenkernel/intern/light.c
@@ -25,6 +25,9 @@
 
 #include "MEM_guardedalloc.h"
 
+/* Allow using deprecated functionality for .blend file I/O. */
+#define DNA_DEPRECATED_ALLOW
+
 #include "DNA_anim_types.h"
 #include "DNA_defaults.h"
 #include "DNA_light_types.h"
@@ -37,6 +40,7 @@
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 
+#include "BKE_anim_data.h"
 #include "BKE_colortools.h"
 #include "BKE_icons.h"
 #include "BKE_idtype.h"
@@ -50,6 +54,8 @@
 
 #include "DEG_depsgraph.h"
 
+#include "BLO_read_write.h"
+
 static void light_init_data(ID *id)
 {
   Light *la = (Light *)id;
@@ -119,6 +125,59 @@ static void light_foreach_id(ID *id, LibraryForeachIDData *data)
   }
 }
 
+static void light_blend_write(BlendWriter *writer, ID *id, const void *id_address)
+{
+  Light *la = (Light *)id;
+  if (la->id.us > 0 || BLO_write_is_undo(writer)) {
+    /* write LibData */
+    BLO_write_id_struct(writer, Light, id_address, &la->id);
+    BKE_id_blend_write(writer, &la->id);
+
+    if (la->adt) {
+      BKE_animdata_blend_write(writer, la->adt);
+    }
+
+    if (la->curfalloff) {
+      BKE_curvemapping_blend_write(writer, la->curfalloff);
+    }
+
+    /* Node-tree is integral part of lights, no libdata. */
+    if (la->nodetree) {
+      BLO_write_struct(writer, bNodeTree, la->nodetree);
+      ntreeBlendWrite(writer, la->nodetree);
+    }
+
+    BKE_previewimg_blend_write(writer, la->preview);
+  }
+}
+
+static void light_blend_read_data(BlendDataReader *reader, ID *id)
+{
+  Light *la = (Light *)id;
+  BLO_read_data_address(reader, &la->adt);
+  BKE_animdata_blend_read_data(reader, la->adt);
+
+  BLO_read_data_address(reader, &la->curfalloff);
+  if (la->curfalloff) {
+    BKE_curvemapping_blend_read(reader, la->curfalloff);
+  }
+
+  BLO_read_data_address(reader, &la->preview);
+  BKE_previewimg_blend_read(reader, la->preview);
+}
+
+static void light_blend_read_lib(BlendLibReader *reader, ID *id)
+{
+  Light *la = (Light *)id;
+  BLO_read_id_address(reader, la->id.lib, &la->ipo);  // XXX deprecated - old animation system
+}
+
+static void light_blend_read_expand(BlendExpander *expander, ID *id)
+{
+  Light *la = (Light *)id;
+  BLO_expand(expander, la->ipo);  // XXX deprecated - old animation system
+}
+
 IDTypeInfo IDType_ID_LA = {
     .id_code = ID_LA,
     .id_filter = FILTER_ID_LA,
@@ -136,10 +195,10 @@ IDTypeInfo IDType_ID_LA = {
     .foreach_id = light_foreach_id,
     .foreach_cache = NULL,
 
-    .blend_write = NULL,
-    .blend_read_data = NULL,
-    .blend_read_lib = NULL,
-    .blend_read_expand = NULL,
+    .blend_write = light_blend_write,
+    .blend_read_data = light_blend_read_data,
+    .blend_read_lib = light_blend_read_lib,
+    .blend_read_expand = light_blend_read_expand,
 };
 
 Light *BKE_light_add(Main *bmain, const char *name)
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index ff29ebd9e95..85b7c1e5623 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2876,31 +2876,6 @@ static void direct_link_camera(BlendDataReader *reader, Camera *ca)
 
 /** \} */
 
-/* -------------------------------------------------------------------- */
-/** \name Read ID: Light
- * \{ */
-
-static void lib_link_light(BlendLibReader *reader, Light *la)
-{
-  BLO_read_id_address(reader, la->id.lib, &la->ipo);  // XXX deprecated - old animation system
-}
-
-static void direct_link_light(BlendDataReader *reader, Light *la)
-{
-  BLO_read_data_address(reader, &la->adt);
-  BKE_animdata_blend_read_data(reader, la->adt);
-
-  BLO_read_data_address(reader, &la->curfalloff);
-  if (la->curfalloff) {
-    BKE_curvemapping_blend_read(reader, la->curfalloff);
-  }
-
-  BLO_read_data_address(reader, &la->preview);
-  BKE_previewimg_blend_read(reader, la->preview);
-}
-
-/** \} */
-
 /* -------------------------------------------------------------------- */
 /** \name Read ID: Shape Keys
  * \{ */
@@ -7110,9 +7085,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
     case ID_TE:
       direct_link_texture(&reader, (Tex *)id);
       break;
-    case ID_LA:
-      direct_link_light(&reader, (Light *)id);
-      break;
     case ID_IP:
       direct_link_ipo(&reader, (Ipo *)id);
       break;
@@ -7182,6 +7154,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
     case ID_PC:
     case ID_BR:
     case ID_IM:
+    case ID_LA:
       /* Do nothing. Handled by IDTypeInfo callback. */
       break;
   }
@@ -7829,9 +7802,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
       case ID_CA:
         lib_link_camera(&reader, (Camera *)id);
         break;
-      case ID_LA:
-        lib_link_light(&reader, (Light *)id);
-        break;
       case ID_MB:
         lib_link_mball(&reader, (MetaBall *)id);
         break;
@@ -7887,6 +7857,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
       case ID_PC:
       case ID_BR:
       case ID_IM:
+      case ID_LA:
         /* Do nothing. Handled by IDTypeInfo callback. */
         break;
     }
@@ -8594,11 +8565,6 @@ static void expand_material(BlendExpander *expander, Material *ma)
   }
 }
 
-static void expand_light(BlendExpander *expander, Light *la)
-{
-  BLO_expand(expander, la->ipo);  // XXX deprecated - old animation system
-}
-
 static void expand_world(BlendExpander *expander, World *wrld)
 {
   BLO_expand(expander, wrld->ipo);  // XXX deprecated - old animation system
@@ -9049,9 +9015,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
             case ID_WO:
               expand_world(&expander, (World *)id);
               break;
-            case ID_LA:
-              expand_light(&expander, (Light *)id);
-              break;
             case ID_KE:
               expand_key(&expander, (Key *)id);
               break;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 6cab51dd03d..24ca503b895 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1585,31 +1585,6 @@ static void write_world(BlendWriter *writer, World *wrld, const void *id_address
   }
 }
 
-static void write_light(BlendWriter *writer, Light *la, const void *id_address)
-{
-  if (la->id.us > 0 || BLO_write_is_undo(writer)) {
-    /* write LibData */
-    BLO_write_id_struct(writer, Light, id_address, &la->id);
-    BKE_id_blend_write(writer, &la->id);
-
-    if (la->adt) {
-      BKE_animdata_blend_write(writer, la->adt);
-    }
-
-    if (la->curfalloff) {
-      BKE_curvemapping_blend_write(writer, la->curfalloff);
-    }
-
-    /* Node-tree is integral part of lights, no libdata. */
-    if (la->nodetree) {
-      BLO_write_struct(writer, bNodeTree, la->nodetree);
-      ntreeBlendWrite(writer, la->nodetree);
-    }
-
-    BKE_previewimg_blend_write(writer, la->preview);
-  }
-}
-
 static void write_collection_nolib(BlendWriter *writer, Collection *collection)
 {
   /* Shared function for collection data-blocks and scene master collection. */
@@ -2892,9 +2867,6 @@ static bool write_file_handle(Main *mainvar,
           case ID_CA:
             write_camera(&writer, (Camera *)id_buffer, id);
             break;
-          case ID_LA:
-            write_light(&writer, (Light *)id_buffer, id);
-            break;
           case ID_KE:
             write_key(&writer, (Key *)id_buffer, id);
             break;
@@ -2958,6 +2930,7 @@ static bool write_file_handle(Main *mainvar,
           case ID_PAL:
           case ID_BR:
           case ID_IM:
+          case ID_LA:
             /* Do nothing, handled in IDTypeInfo callback. */
             break;
           case ID_LI:



More information about the Bf-blender-cvs mailing list