From 218e9e76a8b7a737ac9277e54de009461b43ecf8 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Fri, 11 Sep 2020 11:46:26 +0200 Subject: Refactor: move Simulation .blend I/O to IDTypeInfo callbacks --- source/blender/blenloader/intern/readfile.c | 49 +----------------------- source/blender/blenloader/intern/writefile.c | 56 +--------------------------- 2 files changed, 3 insertions(+), 102 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index f32168092eb..c6217b56565 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -6238,37 +6238,6 @@ static void lib_link_sound(BlendLibReader *reader, bSound *sound) /** \} */ -/* -------------------------------------------------------------------- */ -/** \name Read ID: Simulation - * \{ */ - -static void lib_link_simulation(BlendLibReader *reader, Simulation *simulation) -{ - LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) { - BLO_read_id_address(reader, simulation->id.lib, &dependency->id); - } -} - -static void direct_link_simulation(BlendDataReader *reader, Simulation *simulation) -{ - BLO_read_data_address(reader, &simulation->adt); - BKE_animdata_blend_read_data(reader, simulation->adt); - - BLO_read_list(reader, &simulation->states); - LISTBASE_FOREACH (SimulationState *, state, &simulation->states) { - BLO_read_data_address(reader, &state->name); - BLO_read_data_address(reader, &state->type); - if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_SIMULATION)) { - ParticleSimulationState *particle_state = (ParticleSimulationState *)state; - CustomData_blend_read(reader, &particle_state->attributes, particle_state->tot_particles); - } - } - - BLO_read_list(reader, &simulation->dependencies); -} - -/** \} */ - /* -------------------------------------------------------------------- */ /** \name Read Library Data Block * \{ */ @@ -6449,9 +6418,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_WS: direct_link_workspace(&reader, (WorkSpace *)id, main); break; - case ID_SIM: - direct_link_simulation(&reader, (Simulation *)id); - break; case ID_ME: case ID_LT: case ID_AC: @@ -6480,6 +6446,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_HA: case ID_PT: case ID_VO: + case ID_SIM: /* Do nothing. Handled by IDTypeInfo callback. */ break; } @@ -7115,9 +7082,6 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_CF: lib_link_cachefiles(&reader, (CacheFile *)id); break; - case ID_SIM: - lib_link_simulation(&reader, (Simulation *)id); - break; case ID_IP: /* XXX deprecated... still needs to be maintained for version patches still. */ lib_link_ipo(&reader, (Ipo *)id); @@ -7153,6 +7117,7 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_HA: case ID_PT: case ID_VO: + case ID_SIM: /* Do nothing. Handled by IDTypeInfo callback. */ break; } @@ -8096,13 +8061,6 @@ static void expand_workspace(BlendExpander *expander, WorkSpace *workspace) } } -static void expand_simulation(BlendExpander *expander, Simulation *simulation) -{ - LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) { - BLO_expand(expander, dependency->id); - } -} - /** * Set the callback func used over all ID data found by \a BLO_expand_main func. * @@ -8170,9 +8128,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) case ID_WS: expand_workspace(&expander, (WorkSpace *)id); break; - case ID_SIM: - expand_simulation(&expander, (Simulation *)id); - break; default: break; } diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 8390838163d..8bbdee78381 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2104,58 +2104,6 @@ static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const voi } } -static void write_simulation(BlendWriter *writer, Simulation *simulation, const void *id_address) -{ - if (simulation->id.us > 0 || BLO_write_is_undo(writer)) { - BLO_write_id_struct(writer, Simulation, id_address, &simulation->id); - BKE_id_blend_write(writer, &simulation->id); - - if (simulation->adt) { - BKE_animdata_blend_write(writer, simulation->adt); - } - - /* nodetree is integral part of simulation, no libdata */ - if (simulation->nodetree) { - BLO_write_struct(writer, bNodeTree, simulation->nodetree); - ntreeBlendWrite(writer, simulation->nodetree); - } - - LISTBASE_FOREACH (SimulationState *, state, &simulation->states) { - BLO_write_string(writer, state->name); - BLO_write_string(writer, state->type); - /* TODO: Decentralize this part. */ - if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_SIMULATION)) { - ParticleSimulationState *particle_state = (ParticleSimulationState *)state; - - CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; - CustomData_blend_write_prepare( - &particle_state->attributes, &players, players_buff, ARRAY_SIZE(players_buff)); - - BLO_write_struct(writer, ParticleSimulationState, particle_state); - - CustomData_blend_write(writer, - &particle_state->attributes, - players, - particle_state->tot_particles, - CD_MASK_ALL, - &simulation->id); - - /* Remove temporary data. */ - if (players && players != players_buff) { - MEM_freeN(players); - } - } - else if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_MESH_EMITTER)) { - ParticleMeshEmitterSimulationState *emitter_state = (ParticleMeshEmitterSimulationState *) - state; - BLO_write_struct(writer, ParticleMeshEmitterSimulationState, emitter_state); - } - } - - BLO_write_struct_list(writer, SimulationDependency, &simulation->dependencies); - } -} - /* Keep it last of write_foodata functions. */ static void write_libraries(WriteData *wd, Main *main) { @@ -2441,9 +2389,6 @@ static bool write_file_handle(Main *mainvar, case ID_CF: write_cachefile(&writer, (CacheFile *)id_buffer, id); break; - case ID_SIM: - write_simulation(&writer, (Simulation *)id_buffer, id); - break; case ID_ME: case ID_LT: case ID_AC: @@ -2472,6 +2417,7 @@ static bool write_file_handle(Main *mainvar, case ID_HA: case ID_PT: case ID_VO: + case ID_SIM: /* Do nothing, handled in IDTypeInfo callback. */ break; case ID_LI: -- cgit v1.2.3