Navigation Menu

Skip to content

Commit

Permalink
Engine: implemented new save/load data routines
Browse files Browse the repository at this point in the history
This implements the data save and restoration routines for new save format. They are based on old ones, but have better data grouping, no redundant data saved (such as static data that never changes during the course of the game) and additional assertions to help with debugging in case of future format updates.
  • Loading branch information
ivan-mogilko committed Oct 14, 2017
1 parent 223edcb commit f195a66
Show file tree
Hide file tree
Showing 45 changed files with 1,484 additions and 482 deletions.
12 changes: 12 additions & 0 deletions Common/ac/audiocliptype.cpp
Expand Up @@ -34,3 +34,15 @@ void AudioClipType::WriteToFile(Stream *out)
out->WriteInt32(crossfadeSpeed);
out->WriteInt32(reservedForFuture);
}

void AudioClipType::ReadFromSavegame(Common::Stream *in)
{
volume_reduction_while_speech_playing = in->ReadInt32();
crossfadeSpeed = in->ReadInt32();
}

void AudioClipType::WriteToSavegame(Common::Stream *out) const
{
out->WriteInt32(volume_reduction_while_speech_playing);
out->WriteInt32(crossfadeSpeed);
}
2 changes: 2 additions & 0 deletions Common/ac/audiocliptype.h
Expand Up @@ -32,6 +32,8 @@ struct AudioClipType {

void ReadFromFile(Common::Stream *in);
void WriteToFile(Common::Stream *out);
void ReadFromSavegame(Common::Stream *in);
void WriteToSavegame(Common::Stream *out) const;
};

#endif // __AC_AUDIOCLIPTYPE_H
12 changes: 11 additions & 1 deletion Common/ac/dialogtopic.cpp
Expand Up @@ -29,4 +29,14 @@ void DialogTopic::ReadFromFile(Stream *in)
codesize = in->ReadInt16();
numoptions = in->ReadInt32();
topicFlags = in->ReadInt32();
}
}

void DialogTopic::ReadFromSavegame(Common::Stream *in)
{
in->ReadArrayOfInt32(optionflags, MAXTOPICOPTIONS);
}

void DialogTopic::WriteToSavegame(Common::Stream *out) const
{
out->WriteArrayOfInt32(optionflags, MAXTOPICOPTIONS);
}
3 changes: 3 additions & 0 deletions Common/ac/dialogtopic.h
Expand Up @@ -59,6 +59,9 @@ struct DialogTopic {
int topicFlags;

void ReadFromFile(Common::Stream *in);

void ReadFromSavegame(Common::Stream *in);
void WriteToSavegame(Common::Stream *out) const;
};


Expand Down
48 changes: 28 additions & 20 deletions Common/ac/gamesetupstruct.cpp
Expand Up @@ -369,26 +369,6 @@ void GameSetupStruct::ReadFromSaveGame_v321(Stream *in, char* gswas, ccScript* c
ReadCharacters_Aligned(in);
}

void GameSetupStruct::WriteForSaveGame_v321(Stream *out)
{
WriteInvInfo_Aligned(out);
WriteMouseCursors_Aligned(out);

if (invScripts == NULL)
{
int bb;
for (bb = 0; bb < numinvitems; bb++)
intrInv[bb]->WriteTimesRunToSavedgame(out);
for (bb = 0; bb < numcharacters; bb++)
intrChar[bb]->WriteTimesRunToSavedgame(out);
}

out->WriteArrayOfInt32 (&options[0], OPT_HIGHESTOPTION_321 + 1);
out->WriteInt8 (options[OPT_LIPSYNCTEXT]);

WriteCharacters_Aligned(out);
}

//=============================================================================

void ConvertOldGameStruct (OldGameSetupStruct *ogss, GameSetupStruct *gss) {
Expand Down Expand Up @@ -426,3 +406,31 @@ void ConvertOldGameStruct (OldGameSetupStruct *ogss, GameSetupStruct *gss) {
gss->compiled_script = ogss->compiled_script;
gss->numcursors = 10;
}

void GameSetupStruct::ReadFromSavegame(PStream in)
{
// of GameSetupStruct
in->ReadArrayOfInt32(options, OPT_HIGHESTOPTION_321 + 1);
options[OPT_LIPSYNCTEXT] = in->ReadInt32();
// of GameSetupStructBase
playercharacter = in->ReadInt32();
dialog_bullet = in->ReadInt32();
hotdot = in->ReadInt16();
hotdotouter = in->ReadInt16();
invhotdotsprite = in->ReadInt32();
default_lipsync_frame = in->ReadInt32();
}

void GameSetupStruct::WriteForSavegame(PStream out)
{
// of GameSetupStruct
out->WriteArrayOfInt32(options, OPT_HIGHESTOPTION_321 + 1);
out->WriteInt32(options[OPT_LIPSYNCTEXT]);
// of GameSetupStructBase
out->WriteInt32(playercharacter);
out->WriteInt32(dialog_bullet);
out->WriteInt16(hotdot);
out->WriteInt16(hotdotouter);
out->WriteInt32(invhotdotsprite);
out->WriteInt32(default_lipsync_frame);
}
4 changes: 3 additions & 1 deletion Common/ac/gamesetupstruct.h
Expand Up @@ -128,7 +128,9 @@ struct GameSetupStruct: public GameSetupStructBase {
// Functions for reading and writing appropriate data from/to save game
void ReadFromSaveGame_v321(Common::Stream *in, char* gswas, ccScript* compsc, CharacterInfo* chwas,
WordsDictionary *olddict, char** mesbk);
void WriteForSaveGame_v321(Common::Stream *out);

void ReadFromSavegame(Common::PStream in);
void WriteForSavegame(Common::PStream out);
};

//=============================================================================
Expand Down
17 changes: 16 additions & 1 deletion Common/ac/inventoryiteminfo.cpp
Expand Up @@ -14,8 +14,9 @@

#include "ac/inventoryiteminfo.h"
#include "util/stream.h"
#include "util/string_utils.h"

using AGS::Common::Stream;
using namespace AGS::Common;

void InventoryItemInfo::ReadFromFile(Stream *in)
{
Expand All @@ -38,3 +39,17 @@ void InventoryItemInfo::WriteToFile(Stream *out)
out->WriteArrayOfInt32(reserved, 5);
out->WriteInt8(flags);
}

void InventoryItemInfo::ReadFromSavegame(Stream *in)
{
StrUtil::ReadString(name, in, 25);
pic = in->ReadInt32();
cursorPic = in->ReadInt32();
}

void InventoryItemInfo::WriteToSavegame(Stream *out) const
{
StrUtil::WriteString(name, out);
out->WriteInt32(pic);
out->WriteInt32(cursorPic);
}
2 changes: 2 additions & 0 deletions Common/ac/inventoryiteminfo.h
Expand Up @@ -28,6 +28,8 @@ struct InventoryItemInfo {

void ReadFromFile(Common::Stream *in);
void WriteToFile(Common::Stream *out);
void ReadFromSavegame(Common::Stream *in);
void WriteToSavegame(Common::Stream *out) const;
};

#endif // __AC_INVENTORYITEMINFO_H
18 changes: 18 additions & 0 deletions Common/ac/mousecursor.cpp
Expand Up @@ -39,3 +39,21 @@ void MouseCursor::WriteToFile(Stream *out)
out->Write(name, 10);
out->WriteInt8(flags);
}

void MouseCursor::ReadFromSavegame(Stream *in)
{
pic = in->ReadInt32();
hotx = in->ReadInt32();
hoty = in->ReadInt32();
view = in->ReadInt32();
flags = in->ReadInt32();
}

void MouseCursor::WriteToSavegame(Stream *out) const
{
out->WriteInt32(pic);
out->WriteInt32(hotx);
out->WriteInt32(hoty);
out->WriteInt32(view);
out->WriteInt32(flags);
}
2 changes: 2 additions & 0 deletions Common/ac/mousecursor.h
Expand Up @@ -33,6 +33,8 @@ struct MouseCursor {

void ReadFromFile(Common::Stream *in);
void WriteToFile(Common::Stream *out);
void ReadFromSavegame(Common::Stream *in);
void WriteToSavegame(Common::Stream *out) const;
};

#endif // __AC_MOUSECURSOR_H
2 changes: 1 addition & 1 deletion Common/ac/roomstruct.h
Expand Up @@ -159,7 +159,7 @@ struct roomstruct {
char *message[MAXMESS];
MessageInfo msgi[MAXMESS];
short wasversion; // when loaded from file
short flagstates[MAX_FLAGS];
short flagstates[MAX_FLAGS]; // unused!
FullAnimation anims[MAXANIMS];
short numanims;
short shadinginfo[16]; // walkable area-specific view number
Expand Down
29 changes: 29 additions & 0 deletions Common/gui/guibutton.cpp
Expand Up @@ -17,6 +17,7 @@
#include "gui/guibutton.h"
#include "gui/guimain.h"
#include "util/stream.h"
#include "util/string_utils.h"

std::vector<AGS::Common::GUIButton> guibuts;
int numguibuts = 0;
Expand Down Expand Up @@ -224,6 +225,34 @@ void GUIButton::ReadFromFile(Stream *in, GuiVersion gui_version)
Flags |= kGUICtrl_Translated;
}

void GUIButton::ReadFromSavegame(Stream *in)
{
GUIObject::ReadFromSavegame(in);
// Properties
Image = in->ReadInt32();
MouseOverImage = in->ReadInt32();
PushedImage = in->ReadInt32();
Font = in->ReadInt32();
TextColor = in->ReadInt32();
SetText(StrUtil::ReadString(in));
// Dynamic state
Image = in->ReadInt32();
}

void GUIButton::WriteToSavegame(Stream *out) const
{
// Properties
GUIObject::WriteToSavegame(out);
out->WriteInt32(Image);
out->WriteInt32(MouseOverImage);
out->WriteInt32(PushedImage);
out->WriteInt32(Font);
out->WriteInt32(TextColor);
StrUtil::WriteString(GetText(), out);
// Dynamic state
out->WriteInt32(Image);
}

void GUIButton::DrawImageButton(Bitmap *ds, bool draw_disabled)
{
// NOTE: the CLIP flag only clips the image, not the text
Expand Down
2 changes: 2 additions & 0 deletions Common/gui/guibutton.h
Expand Up @@ -73,6 +73,8 @@ class GUIButton : public GUIObject
// Serialization
virtual void WriteToFile(Stream *out) override;
virtual void ReadFromFile(Stream *in, GuiVersion gui_version) override;
virtual void ReadFromSavegame(Common::Stream *in);
virtual void WriteToSavegame(Common::Stream *out) const;

// TODO: these members are currently public; hide them later
public:
Expand Down
19 changes: 19 additions & 0 deletions Common/gui/guiinv.cpp
Expand Up @@ -100,6 +100,25 @@ void GUIInvWindow::ReadFromFile(Stream *in, GuiVersion gui_version)
CalculateNumCells();
}

void GUIInvWindow::ReadFromSavegame(Stream *in)
{
GUIObject::ReadFromSavegame(in);
ItemWidth = in->ReadInt32();
ItemHeight = in->ReadInt32();
CharId = in->ReadInt32();
TopItem = in->ReadInt32();
CalculateNumCells();
}

void GUIInvWindow::WriteToSavegame(Stream *out) const
{
GUIObject::WriteToSavegame(out);
out->WriteInt32(ItemWidth);
out->WriteInt32(ItemHeight);
out->WriteInt32(CharId);
out->WriteInt32(TopItem);
}

void GUIInvWindow::CalculateNumCells()
{
if (loaded_game_file_version >= kGameVersion_270)
Expand Down
2 changes: 2 additions & 0 deletions Common/gui/guiinv.h
Expand Up @@ -44,6 +44,8 @@ class GUIInvWindow : public GUIObject
// Serialization
virtual void WriteToFile(Stream *out) override;
virtual void ReadFromFile(Stream *in, GuiVersion gui_version) override;
virtual void ReadFromSavegame(Common::Stream *in);
virtual void WriteToSavegame(Common::Stream *out) const;

// TODO: these members are currently public; hide them later
public:
Expand Down
17 changes: 17 additions & 0 deletions Common/gui/guilabel.cpp
Expand Up @@ -17,6 +17,7 @@
#include "gui/guilabel.h"
#include "gui/guimain.h"
#include "util/stream.h"
#include "util/string_utils.h"

std::vector<AGS::Common::GUILabel> guilabels;
int numguilabels = 0;
Expand Down Expand Up @@ -100,5 +101,21 @@ void GUILabel::ReadFromFile(Stream *in, GuiVersion gui_version)
Flags |= kGUICtrl_Translated;
}

void GUILabel::ReadFromSavegame(Stream *in)
{
GUIObject::ReadFromSavegame(in);
Font = in->ReadInt32();
TextColor = in->ReadInt32();
Text = StrUtil::ReadString(in);
}

void GUILabel::WriteToSavegame(Stream *out) const
{
GUIObject::WriteToSavegame(out);
out->WriteInt32(Font);
out->WriteInt32(TextColor);
StrUtil::WriteString(Text, out);
}

} // namespace Common
} // namespace AGS
2 changes: 2 additions & 0 deletions Common/gui/guilabel.h
Expand Up @@ -38,6 +38,8 @@ class GUILabel:public GUIObject
// Serialization
virtual void WriteToFile(Stream *out) override;
virtual void ReadFromFile(Stream *in, GuiVersion gui_version) override;
virtual void ReadFromSavegame(Common::Stream *in);
virtual void WriteToSavegame(Common::Stream *out) const;

// TODO: these members are currently public; hide them later
public:
Expand Down
33 changes: 33 additions & 0 deletions Common/gui/guilistbox.cpp
Expand Up @@ -16,6 +16,7 @@
#include "gui/guilistbox.h"
#include "gui/guimain.h"
#include "util/stream.h"
#include "util/string_utils.h"

std::vector<AGS::Common::GUIListBox> guilist;
int numguilist = 0;
Expand Down Expand Up @@ -329,5 +330,37 @@ void GUIListBox::ReadFromFile(Stream *in, GuiVersion gui_version)
TextColor = 16;
}

void GUIListBox::ReadFromSavegame(Stream *in)
{
GUIObject::ReadFromSavegame(in);
ListBoxFlags = in->ReadInt32();
Font = in->ReadInt32();

ItemCount = in->ReadInt32();
for (int i = 0; i < ItemCount; ++i)
Items[i] = StrUtil::ReadString(in);
if (ListBoxFlags & kListBox_SvgIndex)
for (int i = 0; i < ItemCount; ++i)
SavedGameIndex[i] = in->ReadInt16();
TopItem = in->ReadInt32();
SelectedItem = in->ReadInt32();
}

void GUIListBox::WriteToSavegame(Stream *out) const
{
GUIObject::WriteToSavegame(out);
out->WriteInt32(ListBoxFlags);
out->WriteInt32(Font);

out->WriteInt32(ItemCount);
for (int i = 0; i < ItemCount; ++i)
StrUtil::WriteString(Items[i], out);
if (ListBoxFlags & kListBox_SvgIndex)
for (int i = 0; i < ItemCount; ++i)
out->WriteInt16(SavedGameIndex[i]);
out->WriteInt32(TopItem);
out->WriteInt32(SelectedItem);
}

} // namespace Common
} // namespace AGS
2 changes: 2 additions & 0 deletions Common/gui/guilistbox.h
Expand Up @@ -49,6 +49,8 @@ class GUIListBox : public GUIObject
// Serialization
virtual void WriteToFile(Stream *out) override;
virtual void ReadFromFile(Stream *in, GuiVersion gui_version) override;
virtual void ReadFromSavegame(Common::Stream *in);
virtual void WriteToSavegame(Common::Stream *out) const;

// TODO: these members are currently public; hide them later
public:
Expand Down

0 comments on commit f195a66

Please sign in to comment.