[Bf-blender-cvs] [0649e637162] master: Refactor: move Camera .blend I/O to IDTypeInfo callbacks

Jacques Lucke noreply at git.blender.org
Thu Sep 10 16:58:35 CEST 2020


Commit: 0649e6371629507c201310f7ece628a926d846d5
Author: Jacques Lucke
Date:   Thu Sep 10 16:57:47 2020 +0200
Branches: master
https://developer.blender.org/rB0649e6371629507c201310f7ece628a926d846d5

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

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

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

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

diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index eef2ab94078..4fe3ddc81a1 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -24,6 +24,9 @@
 #include <stddef.h>
 #include <stdlib.h>
 
+/* Allow using deprecated functionality for .blend file I/O. */
+#define DNA_DEPRECATED_ALLOW
+
 #include "DNA_ID.h"
 #include "DNA_camera_types.h"
 #include "DNA_defaults.h"
@@ -38,6 +41,7 @@
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
 
+#include "BKE_anim_data.h"
 #include "BKE_camera.h"
 #include "BKE_idtype.h"
 #include "BKE_layer.h"
@@ -54,6 +58,8 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLO_read_write.h"
+
 /* -------------------------------------------------------------------- */
 /** \name Camera Data-Block
  * \{ */
@@ -113,6 +119,67 @@ static void camera_foreach_id(ID *id, LibraryForeachIDData *data)
   }
 }
 
+static void camera_blend_write(BlendWriter *writer, ID *id, const void *id_address)
+{
+  Camera *cam = (Camera *)id;
+  if (cam->id.us > 0 || BLO_write_is_undo(writer)) {
+    /* write LibData */
+    BLO_write_id_struct(writer, Camera, id_address, &cam->id);
+    BKE_id_blend_write(writer, &cam->id);
+
+    if (cam->adt) {
+      BKE_animdata_blend_write(writer, cam->adt);
+    }
+
+    LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) {
+      BLO_write_struct(writer, CameraBGImage, bgpic);
+    }
+  }
+}
+
+static void camera_blend_read_data(BlendDataReader *reader, ID *id)
+{
+  Camera *ca = (Camera *)id;
+  BLO_read_data_address(reader, &ca->adt);
+  BKE_animdata_blend_read_data(reader, ca->adt);
+
+  BLO_read_list(reader, &ca->bg_images);
+
+  LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
+    bgpic->iuser.ok = 1;
+    bgpic->iuser.scene = NULL;
+  }
+}
+
+static void camera_blend_read_lib(BlendLibReader *reader, ID *id)
+{
+  Camera *ca = (Camera *)id;
+  BLO_read_id_address(reader, ca->id.lib, &ca->ipo); /* deprecated, for versioning */
+
+  BLO_read_id_address(reader, ca->id.lib, &ca->dof_ob); /* deprecated, for versioning */
+  BLO_read_id_address(reader, ca->id.lib, &ca->dof.focus_object);
+
+  LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
+    BLO_read_id_address(reader, ca->id.lib, &bgpic->ima);
+    BLO_read_id_address(reader, ca->id.lib, &bgpic->clip);
+  }
+}
+
+static void camera_blend_read_expand(BlendExpander *expander, ID *id)
+{
+  Camera *ca = (Camera *)id;
+  BLO_expand(expander, ca->ipo);  // XXX deprecated - old animation system
+
+  LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
+    if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) {
+      BLO_expand(expander, bgpic->ima);
+    }
+    else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) {
+      BLO_expand(expander, bgpic->ima);
+    }
+  }
+}
+
 IDTypeInfo IDType_ID_CA = {
     .id_code = ID_CA,
     .id_filter = FILTER_ID_CA,
@@ -130,10 +197,10 @@ IDTypeInfo IDType_ID_CA = {
     .foreach_id = camera_foreach_id,
     .foreach_cache = NULL,
 
-    .blend_write = NULL,
-    .blend_read_data = NULL,
-    .blend_read_lib = NULL,
-    .blend_read_expand = NULL,
+    .blend_write = camera_blend_write,
+    .blend_read_data = camera_blend_read_data,
+    .blend_read_lib = camera_blend_read_lib,
+    .blend_read_expand = camera_blend_read_expand,
 };
 
 /** \} */
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index b3816588daa..a5d72084b76 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2844,38 +2844,6 @@ static void direct_link_armature(BlendDataReader *reader, bArmature *arm)
 
 /** \} */
 
-/* -------------------------------------------------------------------- */
-/** \name Read ID: Camera
- * \{ */
-
-static void lib_link_camera(BlendLibReader *reader, Camera *ca)
-{
-  BLO_read_id_address(reader, ca->id.lib, &ca->ipo); /* deprecated, for versioning */
-
-  BLO_read_id_address(reader, ca->id.lib, &ca->dof_ob); /* deprecated, for versioning */
-  BLO_read_id_address(reader, ca->id.lib, &ca->dof.focus_object);
-
-  LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
-    BLO_read_id_address(reader, ca->id.lib, &bgpic->ima);
-    BLO_read_id_address(reader, ca->id.lib, &bgpic->clip);
-  }
-}
-
-static void direct_link_camera(BlendDataReader *reader, Camera *ca)
-{
-  BLO_read_data_address(reader, &ca->adt);
-  BKE_animdata_blend_read_data(reader, ca->adt);
-
-  BLO_read_list(reader, &ca->bg_images);
-
-  LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
-    bgpic->iuser.ok = 1;
-    bgpic->iuser.scene = NULL;
-  }
-}
-
-/** \} */
-
 /* -------------------------------------------------------------------- */
 /** \name Read ID: Shape Keys
  * \{ */
@@ -6927,9 +6895,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
     case ID_LI:
       direct_link_library(fd, (Library *)id, main);
       break;
-    case ID_CA:
-      direct_link_camera(&reader, (Camera *)id);
-      break;
     case ID_SPK:
       direct_link_speaker(&reader, (Speaker *)id);
       break;
@@ -6988,6 +6953,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
     case ID_MA:
     case ID_MB:
     case ID_CU:
+    case ID_CA:
       /* Do nothing. Handled by IDTypeInfo callback. */
       break;
   }
@@ -7632,9 +7598,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
       case ID_SO:
         lib_link_sound(&reader, (bSound *)id);
         break;
-      case ID_CA:
-        lib_link_camera(&reader, (Camera *)id);
-        break;
       case ID_CF:
         lib_link_cachefiles(&reader, (CacheFile *)id);
         break;
@@ -7685,6 +7648,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
       case ID_MA:
       case ID_MB:
       case ID_CU:
+      case ID_CA:
         /* Do nothing. Handled by IDTypeInfo callback. */
         break;
     }
@@ -8644,20 +8608,6 @@ static void expand_scene(BlendExpander *expander, Scene *sce)
   }
 }
 
-static void expand_camera(BlendExpander *expander, Camera *ca)
-{
-  BLO_expand(expander, ca->ipo);  // XXX deprecated - old animation system
-
-  LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) {
-    if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) {
-      BLO_expand(expander, bgpic->ima);
-    }
-    else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) {
-      BLO_expand(expander, bgpic->ima);
-    }
-  }
-}
-
 static void expand_cachefile(BlendExpander *UNUSED(expander), CacheFile *UNUSED(cache_file))
 {
 }
@@ -8801,9 +8751,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
             case ID_KE:
               expand_key(&expander, (Key *)id);
               break;
-            case ID_CA:
-              expand_camera(&expander, (Camera *)id);
-              break;
             case ID_SPK:
               expand_speaker(&expander, (Speaker *)id);
               break;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index dd307da40fd..7861af88785 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1414,23 +1414,6 @@ static void write_key(BlendWriter *writer, Key *key, const void *id_address)
   }
 }
 
-static void write_camera(BlendWriter *writer, Camera *cam, const void *id_address)
-{
-  if (cam->id.us > 0 || BLO_write_is_undo(writer)) {
-    /* write LibData */
-    BLO_write_id_struct(writer, Camera, id_address, &cam->id);
-    BKE_id_blend_write(writer, &cam->id);
-
-    if (cam->adt) {
-      BKE_animdata_blend_write(writer, cam->adt);
-    }
-
-    LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) {
-      BLO_write_struct(writer, CameraBGImage, bgpic);
-    }
-  }
-}
-
 static void write_texture(BlendWriter *writer, Tex *tex, const void *id_address)
 {
   if (tex->id.us > 0 || BLO_write_is_undo(writer)) {
@@ -2754,9 +2737,6 @@ static bool write_file_handle(Main *mainvar,
           case ID_SCE:
             write_scene(&writer, (Scene *)id_buffer, id);
             break;
-          case ID_CA:
-            write_camera(&writer, (Camera *)id_buffer, id);
-            break;
           case ID_KE:
             write_key(&writer, (Key *)id_buffer, id);
             break;
@@ -2821,6 +2801,7 @@ static bool write_file_handle(Main *mainvar,
           case ID_MA:
           case ID_MB:
           case ID_CU:
+          case ID_CA:
             /* Do nothing, handled in IDTypeInfo callback. */
             break;
           case ID_LI:



More information about the Bf-blender-cvs mailing list