Skip to content

Commit

Permalink
Engine: cleanup some mentions of AlignedStream
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Oct 23, 2023
1 parent 3a2fb4d commit 636cbd5
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 96 deletions.
19 changes: 7 additions & 12 deletions Common/game/interactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,18 +315,15 @@ void Interaction::ReadFromSavedgame_v321(Stream *in)
quit("Can't deserialize interaction: too many events");

Events.resize(evt_count);
// Read required amount and skip the remaining placeholders
for (size_t i = 0; i < evt_count; ++i)
{
Events[i].Type = in->ReadInt32();
}
const size_t dummy_count = (MAX_NEWINTERACTION_EVENTS - evt_count);
for (size_t i = 0; i < dummy_count; ++i)
in->ReadInt32(); // cannot skip when reading aligned structs
in->Seek((MAX_NEWINTERACTION_EVENTS - evt_count) * sizeof(int32_t));
ReadTimesRunFromSave_v321(in);

// Skip an array of dummy 32-bit pointers
for (size_t i = 0; i < MAX_NEWINTERACTION_EVENTS; ++i)
in->ReadInt32();
// Skip an array of dummy 32-bit pointers (nasty legacy format)
in->Seek(MAX_NEWINTERACTION_EVENTS * sizeof(int32_t));
}

void Interaction::WriteToSavedgame_v321(Stream *out) const
Expand All @@ -340,21 +337,19 @@ void Interaction::WriteToSavedgame_v321(Stream *out) const
}
out->WriteByteCount(0, (MAX_NEWINTERACTION_EVENTS - evt_count) * sizeof(int32_t));
WriteTimesRunToSave_v321(out);

// Array of dummy 32-bit pointers
// Array of dummy 32-bit pointers (nasty legacy format)
out->WriteByteCount(0, MAX_NEWINTERACTION_EVENTS * sizeof(int32_t));
}

void Interaction::ReadTimesRunFromSave_v321(Stream *in)
{
const size_t evt_count = Events.size();
// Read required amount and skip the remaining placeholders
for (size_t i = 0; i < evt_count; ++i)
{
Events[i].TimesRun = in->ReadInt32();
}
const size_t padding = (MAX_NEWINTERACTION_EVENTS - evt_count);
for (size_t i = 0; i < padding; ++i)
in->ReadInt32(); // cannot skip when reading aligned structs
in->Seek((MAX_NEWINTERACTION_EVENTS - evt_count) * sizeof(int32_t));
}

void Interaction::WriteTimesRunToSave_v321(Stream *out) const
Expand Down
16 changes: 5 additions & 11 deletions Common/game/main_game_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,6 @@ HGameFileError ReadScriptModules(std::vector<PScript> &sc_mods, Stream *in, Game
return HGameFileError::None();
}

void ReadViewStruct272_Aligned(std::vector<ViewStruct272> &oldv, Stream *in, size_t count)
{
oldv.resize(count);
for (size_t i = 0; i < count; ++i)
{
oldv[i].ReadFromFile(in);
}
}

void ReadViews(GameSetupStruct &game, std::vector<ViewStruct> &views, Stream *in, GameDataVersion data_ver)
{
views.resize(game.numviews);
Expand All @@ -274,8 +265,11 @@ void ReadViews(GameSetupStruct &game, std::vector<ViewStruct> &views, Stream *in
}
else // 2.x views
{
std::vector<ViewStruct272> oldv;
ReadViewStruct272_Aligned(oldv, in, game.numviews);
std::vector<ViewStruct272> oldv(game.numviews);
for (size_t i = 0; i < game.numviews; ++i)
{
oldv[i].ReadFromFile(in);
}
Convert272ViewsToNew(oldv, views);
}
}
Expand Down
13 changes: 4 additions & 9 deletions Engine/ac/gamestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,10 @@ void GameState::ReadFromSavegame(Stream *in, GameDataVersion data_ver, GameState
if (old_save)
{
in->ReadInt16(); // alignment padding to int32 (before array of structs)
ReadQueuedAudioItems_Aligned(in);
for (int i = 0; i < MAX_QUEUED_MUSIC; ++i)
{
new_music_queue[i].ReadFromSavegame_v321(in);
}
}

in->Read(takeover_from, 50);
Expand Down Expand Up @@ -883,14 +886,6 @@ void GameState::WriteForSavegame(Stream *out) const
out->WriteInt32(voice_speech_flags);
}

void GameState::ReadQueuedAudioItems_Aligned(Stream *in)
{
for (int i = 0; i < MAX_QUEUED_MUSIC; ++i)
{
new_music_queue[i].ReadFromSavegame_v321(in);
}
}

void GameState::FreeProperties()
{
for (auto &p : charProps)
Expand Down
1 change: 0 additions & 1 deletion Engine/ac/gamestate.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ struct GameState
//
// Serialization
//
void ReadQueuedAudioItems_Aligned(Common::Stream *in);
void ReadCustomProperties_v340(Common::Stream *in, GameDataVersion data_ver);
void WriteCustomProperties_v340(Common::Stream *out, GameDataVersion data_ver) const;
void ReadFromSavegame(Common::Stream *in, GameDataVersion data_ver, GameStateSvgVersion svg_ver, AGS::Engine::RestoredData &r_data);
Expand Down
17 changes: 6 additions & 11 deletions Engine/ac/roomstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ void RoomStatus::ReadFromSavegame_v321(Stream *in, GameDataVersion data_ver)

beenhere = in->ReadInt32();
numobj = in->ReadInt32();
ReadRoomObjects_Aligned(in);
// NOTE: legacy format always contained max object slots
for (auto &o : obj)
{
o.ReadFromSavegame(in, -1 /* legacy save with padding */);
}

int16_t dummy[MAX_LEGACY_ROOM_FLAGS]; // cannot seek with AlignedStream
in->ReadArrayOfInt16(dummy, MAX_LEGACY_ROOM_FLAGS); // flagstates (OBSOLETE)
in->Seek(MAX_LEGACY_ROOM_FLAGS * sizeof(int16_t)); // flagstates (OBSOLETE)
in->ReadInt16(); // alignment padding to int32
tsdatasize = static_cast<uint32_t>(in->ReadInt32());
in->ReadInt32(); // tsdata
Expand Down Expand Up @@ -125,14 +128,6 @@ void RoomStatus::ReadFromSavegame_v321(Stream *in, GameDataVersion data_ver)
}
}

void RoomStatus::ReadRoomObjects_Aligned(Common::Stream *in)
{
for (auto &o : obj)
{
o.ReadFromSavegame(in, -1 /* legacy save with padding */);
}
}

void RoomStatus::ReadFromSavegame(Stream *in, GameDataVersion data_ver, RoomStatSvgVersion save_ver)
{
FreeScriptData();
Expand Down
1 change: 0 additions & 1 deletion Engine/ac/roomstatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ struct RoomStatus
void FreeProperties();

void ReadFromSavegame_v321(Common::Stream *in, GameDataVersion data_ver);
void ReadRoomObjects_Aligned(Common::Stream *in);
void ReadFromSavegame(Common::Stream *in, GameDataVersion data_ver, RoomStatSvgVersion save_ver);
void WriteToSavegame(Common::Stream *out, GameDataVersion data_ver) const;
};
Expand Down
2 changes: 2 additions & 0 deletions Engine/game/savegame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// http://www.opensource.org/licenses/artistic-license-2.0.php
//
//=============================================================================
#include "ac/button.h"
#include "ac/character.h"
#include "ac/common.h"
#include "ac/draw.h"
Expand Down Expand Up @@ -409,6 +410,7 @@ void DoBeforeRestore(PreservedParams &pp)
play.FreeViewportsAndCameras();
free_do_once_tokens();

RemoveAllButtonAnimations();
// unregister gui controls from API exports
// CHECKME: find out why are we doing this here? why only to gui controls?
for (int i = 0; i < game.numgui; ++i)
Expand Down
1 change: 0 additions & 1 deletion Engine/game/savegame_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ HSaveError ReadGUI(Stream *in, int32_t cmp_ver, const PreservedParams& /*pp*/, R
// Animated buttons
if (!AssertFormatTagStrict(err, in, "AnimatedButtons"))
return err;
RemoveAllButtonAnimations();
int anim_count = in->ReadInt32();
for (int i = 0; i < anim_count; ++i)
{
Expand Down
71 changes: 21 additions & 50 deletions Engine/game/savegame_v321.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ static HSaveError restore_game_scripts(Stream *in, const PreservedParams &pp, Re
return HSaveError::None();
}

static void ReadRoomStatus_Aligned(RoomStatus *roomstat, Stream *in, GameDataVersion data_ver)
{
roomstat->ReadFromSavegame_v321(in, data_ver);
}

static void restore_game_room_state(Stream *in, GameDataVersion data_ver)
{
displayed_room = in->ReadInt32();
Expand All @@ -176,7 +171,7 @@ static void restore_game_room_state(Stream *in, GameDataVersion data_ver)

if (roomstat->beenhere)
{
ReadRoomStatus_Aligned(roomstat, in, data_ver);
roomstat->ReadFromSavegame_v321(in, data_ver);
if (roomstat->tsdatasize > 0)
{
roomstat->tsdata.resize(roomstat->tsdatasize);
Expand All @@ -187,17 +182,12 @@ static void restore_game_room_state(Stream *in, GameDataVersion data_ver)
}
}

static void ReadGameState_Aligned(Stream *in, GameDataVersion data_ver, RestoredData &r_data)
{
play.ReadFromSavegame(in, data_ver, kGSSvgVersion_OldFormat, r_data);
}

static void restore_game_play(Stream *in, GameDataVersion data_ver, RestoredData &r_data)
{
int screenfadedout_was = play.screen_is_faded_out;
int roomchanges_was = play.room_changes;

ReadGameState_Aligned(in, data_ver, r_data);
play.ReadFromSavegame(in, data_ver, kGSSvgVersion_OldFormat, r_data);
r_data.Cameras[0].Flags = r_data.Camera0_Flags;

play.screen_is_faded_out = screenfadedout_was;
Expand All @@ -214,27 +204,6 @@ static void restore_game_play(Stream *in, GameDataVersion data_ver, RestoredData
in->Seek(game.numgui * sizeof(int32_t));
}

static void ReadMoveList_Aligned(Stream *in)
{
for (int i = 0; i < game.numcharacters + MAX_ROOM_OBJECTS_v300 + 1; ++i)
{
mls[i].ReadFromSavegame_Legacy(in);
}
}

static void ReadGameSetupStructBase_Aligned(Stream *in, GameDataVersion data_ver, GameSetupStruct::SerializeInfo &info)
{
game.GameSetupStructBase::ReadFromFile(in, data_ver, info);
}

static void ReadCharacterExtras_Aligned(Stream *in)
{
for (int i = 0; i < game.numcharacters; ++i)
{
charextra[i].ReadFromSavegame(in, 0);
}
}

static void restore_game_palette(Stream *in)
{
in->ReadArray(&palette[0],sizeof(RGB),256);
Expand All @@ -255,16 +224,6 @@ static void restore_game_more_dynamic_values(Stream *in)
game_paused=in->ReadInt32();
}

void ReadAnimatedButtons_Aligned(Stream *in, int num_abuts)
{
for (int i = 0; i < num_abuts; ++i)
{
AnimatingGUIButton abtn;
abtn.ReadFromSavegame(in, 0);
AddButtonAnimation(abtn);
}
}

static HSaveError restore_game_gui(Stream *in)
{
// Legacy saves allowed to resize gui lists, and stored full gui data
Expand Down Expand Up @@ -294,11 +253,15 @@ static HSaveError restore_game_gui(Stream *in)
!AssertAndCopyGameContent(res_guitext, guitext, err, "GUI TextBoxes", warn_only))
return err;
GUI::RebuildGUI(); // rebuild guis in case they were copied from reserved game data

game.numgui = guis.size();
RemoveAllButtonAnimations();

int anim_count = in->ReadInt32();
ReadAnimatedButtons_Aligned(in, anim_count);
for (int i = 0; i < anim_count; ++i)
{
AnimatingGUIButton abtn;
abtn.ReadFromSavegame(in, 0);
AddButtonAnimation(abtn);
}
return HSaveError::None();
}

Expand Down Expand Up @@ -415,7 +378,7 @@ static void restore_game_displayed_room_status(Stream *in, GameDataVersion data_
raw_saved_screen.reset(read_serialized_bitmap(in));

// get the current troom, in case they save in room 600 or whatever
ReadRoomStatus_Aligned(&troom, in, data_ver);
troom.ReadFromSavegame_v321(in, data_ver);

if (troom.tsdatasize > 0) {
troom.tsdata.resize(troom.tsdatasize);
Expand Down Expand Up @@ -507,7 +470,11 @@ HSaveError restore_save_data_v321(Stream *in, GameDataVersion data_ver, const Pr
return err;
restore_game_room_state(in, data_ver);
restore_game_play(in, data_ver, r_data);
ReadMoveList_Aligned(in);
// Global character movelists
for (int i = 0; i < game.numcharacters + MAX_ROOM_OBJECTS_v300 + 1; ++i)
{
mls[i].ReadFromSavegame_Legacy(in);
}

// List of game objects, used to compare with the save contents
struct ObjectCounts
Expand All @@ -519,7 +486,7 @@ HSaveError restore_save_data_v321(Stream *in, GameDataVersion data_ver, const Pr
} objwas;

GameSetupStruct::SerializeInfo info;
ReadGameSetupStructBase_Aligned(in, data_ver, info);
game.GameSetupStructBase::ReadFromFile(in, data_ver, info);

if (!AssertGameContent(err, objwas.CharacterCount, game.numcharacters, "Characters") ||
!AssertGameContent(err, objwas.DialogCount, game.numdialog, "Dialogs") ||
Expand All @@ -532,7 +499,11 @@ HSaveError restore_save_data_v321(Stream *in, GameDataVersion data_ver, const Pr
// Modified custom properties are read separately to keep existing save format
play.ReadCustomProperties_v340(in, data_ver);

ReadCharacterExtras_Aligned(in);
// Character extras (runtime only data)
for (int i = 0; i < game.numcharacters; ++i)
{
charextra[i].ReadFromSavegame(in, 0);
}
restore_game_palette(in);
restore_game_dialogs(in);
restore_game_more_dynamic_values(in);
Expand Down

0 comments on commit 636cbd5

Please sign in to comment.