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

I could not easily move `direct_link_screen` yet, because it
has a return value. That has to be solved differently at some point.
This commit is contained in:
Jacques Lucke 2020-10-30 15:59:34 +01:00
parent e6f61a4a37
commit 12c92433d8
4 changed files with 55 additions and 43 deletions

View File

@ -56,6 +56,7 @@
#include "BKE_icons.h"
#include "BKE_idprop.h"
#include "BKE_idtype.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"
#include "BKE_node.h"
#include "BKE_screen.h"
@ -236,6 +237,40 @@ static void screen_foreach_id(ID *id, LibraryForeachIDData *data)
}
}
static void screen_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
bScreen *screen = (bScreen *)id;
/* Screens are reference counted, only saved if used by a workspace. */
if (screen->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
/* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
BLO_write_struct_at_address_with_filecode(writer, ID_SCRN, bScreen, id_address, screen);
BKE_id_blend_write(writer, &screen->id);
BKE_previewimg_blend_write(writer, screen->preview);
/* direct data */
BKE_screen_area_map_blend_write(writer, AREAMAP_FROM_SCREEN(screen));
}
}
/* note: file read without screens option G_FILE_NO_UI;
* check lib pointers in call below */
static void screen_blend_read_lib(BlendLibReader *reader, ID *id)
{
bScreen *screen = (bScreen *)id;
/* deprecated, but needed for versioning (will be NULL'ed then) */
BLO_read_id_address(reader, screen->id.lib, &screen->scene);
screen->animtimer = NULL; /* saved in rare cases */
screen->tool_tip = NULL;
screen->scrubbing = false;
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
BKE_screen_area_blend_read_lib(reader, &screen->id, area);
}
}
IDTypeInfo IDType_ID_SCR = {
.id_code = ID_SCR,
.id_filter = 0,
@ -253,9 +288,10 @@ IDTypeInfo IDType_ID_SCR = {
.foreach_id = screen_foreach_id,
.foreach_cache = NULL,
.blend_write = NULL,
.blend_write = screen_blend_write,
/* Cannot be used yet, because #direct_link_screen has a return value. */
.blend_read_data = NULL,
.blend_read_lib = NULL,
.blend_read_lib = screen_blend_read_lib,
.blend_read_expand = NULL,
};

View File

@ -106,6 +106,14 @@ void BLO_write_struct_at_address_by_id(BlendWriter *writer,
BLO_write_struct_at_address_by_id( \
writer, BLO_get_struct_id(writer, struct_name), address, data_ptr)
/* Write single struct at address and specify a filecode. */
void BLO_write_struct_at_address_by_id_with_filecode(
BlendWriter *writer, int filecode, int struct_id, const void *address, const void *data_ptr);
#define BLO_write_struct_at_address_with_filecode( \
writer, filecode, struct_name, address, data_ptr) \
BLO_write_struct_at_address_by_id_with_filecode( \
writer, filecode, BLO_get_struct_id(writer, struct_name), address, data_ptr)
/* Write struct array. */
void BLO_write_struct_array_by_name(BlendWriter *writer,
const char *struct_name,

View File

@ -4753,22 +4753,6 @@ static void lib_link_windowmanager(BlendLibReader *reader, wmWindowManager *wm)
/** \name Read ID: Screen
* \{ */
/* note: file read without screens option G_FILE_NO_UI;
* check lib pointers in call below */
static void lib_link_screen(BlendLibReader *reader, bScreen *screen)
{
/* deprecated, but needed for versioning (will be NULL'ed then) */
BLO_read_id_address(reader, screen->id.lib, &screen->scene);
screen->animtimer = NULL; /* saved in rare cases */
screen->tool_tip = NULL;
screen->scrubbing = false;
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
BKE_screen_area_blend_read_lib(reader, &screen->id, area);
}
}
/* how to handle user count on pointer restore */
typedef enum ePointerUserMode {
USER_IGNORE = 0, /* ignore user count */
@ -6158,11 +6142,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_OB:
lib_link_object(&reader, (Object *)id);
break;
case ID_SCR:
/* DO NOT skip screens here, 3D viewport may contains pointers
* to other ID data (like #View3D.ob_center)! See T41411. */
lib_link_screen(&reader, (bScreen *)id);
break;
case ID_IP:
/* XXX deprecated... still needs to be maintained for version patches still. */
lib_link_ipo(&reader, (Ipo *)id);
@ -6170,6 +6149,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_LI:
lib_link_library(&reader, (Library *)id); /* Only init users. */
break;
case ID_SCR:
case ID_PA:
case ID_GR:
case ID_ME:

View File

@ -1662,22 +1662,6 @@ static void write_windowmanager(BlendWriter *writer, wmWindowManager *wm, const
}
}
static void write_screen(BlendWriter *writer, bScreen *screen, const void *id_address)
{
/* Screens are reference counted, only saved if used by a workspace. */
if (screen->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */
/* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
writestruct_at_address(writer->wd, ID_SCRN, bScreen, 1, id_address, screen);
BKE_id_blend_write(writer, &screen->id);
BKE_previewimg_blend_write(writer, screen->preview);
/* direct data */
BKE_screen_area_map_blend_write(writer, AREAMAP_FROM_SCREEN(screen));
}
}
static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const void *id_address)
{
BLO_write_id_struct(writer, WorkSpace, id_address, &workspace->id);
@ -1957,15 +1941,13 @@ static bool write_file_handle(Main *mainvar,
case ID_WS:
write_workspace(&writer, (WorkSpace *)id_buffer, id);
break;
case ID_SCR:
write_screen(&writer, (bScreen *)id_buffer, id);
break;
case ID_SCE:
write_scene(&writer, (Scene *)id_buffer, id);
break;
case ID_OB:
write_object(&writer, (Object *)id_buffer, id);
break;
case ID_SCR:
case ID_PA:
case ID_GR:
case ID_ME:
@ -2302,7 +2284,13 @@ void BLO_write_struct_at_address_by_id(BlendWriter *writer,
const void *address,
const void *data_ptr)
{
writestruct_at_address_nr(writer->wd, DATA, struct_id, 1, address, data_ptr);
BLO_write_struct_at_address_by_id_with_filecode(writer, DATA, struct_id, address, data_ptr);
}
void BLO_write_struct_at_address_by_id_with_filecode(
BlendWriter *writer, int filecode, int struct_id, const void *address, const void *data_ptr)
{
writestruct_at_address_nr(writer->wd, filecode, struct_id, 1, address, data_ptr);
}
void BLO_write_struct_array_by_id(BlendWriter *writer,