Skip to content

Commit

Permalink
Common: init GameSetupStruct in declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Dec 20, 2024
1 parent 63f5307 commit e1e4f68
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 107 deletions.
35 changes: 0 additions & 35 deletions Common/ac/gamesetupstruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,6 @@

using namespace AGS::Common;

GameSetupStruct::GameSetupStruct()
: filever(0)
, roomCount(0)
{
memset(lipSyncFrameLetters, 0, sizeof(lipSyncFrameLetters));
memset(guid, 0, sizeof(guid));
memset(saveGameFileExtension, 0, sizeof(saveGameFileExtension));
}

GameSetupStruct::~GameSetupStruct()
{
Free();
}

void GameSetupStruct::Free()
{
GameSetupStructBase::Free();

charScripts.clear();
invScripts.clear();
numinvitems = 0;

roomNames.clear();
roomNumbers.clear();
roomCount = 0;

audioClips.clear();
audioClipTypes.clear();

audioclipProps.clear();
charProps.clear();
guiProps.clear();
dialogProps.clear();
viewNames.clear();
}

void AdjustFontInfoUsingFlags(FontInfo &finfo, const uint32_t flags)
{
Expand Down
16 changes: 7 additions & 9 deletions Common/ac/gamesetupstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ struct GameSetupStruct : public GameSetupStructBase
std::vector<UInteractionEvents> invScripts;
// TODO: why we do not use this in the engine instead of
// loaded_game_file_version?
int filever; // just used by editor
int filever = 0; // just used by editor
Common::String compiled_with; // version of AGS this data was created by
char lipSyncFrameLetters[MAXLIPSYNCFRAMES][50];
char lipSyncFrameLetters[MAXLIPSYNCFRAMES][50] = { 0 };
AGS::Common::PropertySchema propSchema;
std::vector<AGS::Common::StringIMap> charProps;
AGS::Common::StringIMap invProps[MAX_INV];
Expand All @@ -64,11 +64,11 @@ struct GameSetupStruct : public GameSetupStructBase
std::vector<Common::String> viewNames;
Common::String invScriptNames[MAX_INV];
std::vector<Common::String> dialogScriptNames;
char guid[MAX_GUID_LENGTH];
char saveGameFileExtension[MAX_SG_EXT_LENGTH];
char guid[MAX_GUID_LENGTH] = { 0 };
char saveGameFileExtension[MAX_SG_EXT_LENGTH] = { 0 };
// NOTE: saveGameFolderName is generally used to create game subdirs in common user directories
Common::String saveGameFolderName;
int roomCount;
int roomCount = 0;
std::vector<int> roomNumbers;
std::vector<Common::String> roomNames;
std::vector<ScriptAudioClip> audioClips;
Expand All @@ -95,14 +95,12 @@ struct GameSetupStruct : public GameSetupStructBase
std::vector<SpriteInfo> SpriteInfos;


GameSetupStruct();
GameSetupStruct() = default;
GameSetupStruct(GameSetupStruct &&gss) = default;
~GameSetupStruct();
~GameSetupStruct() = default;

GameSetupStruct &operator =(GameSetupStruct &&gss) = default;

void Free();

// [IKM] Game struct loading code is moved here from Engine's load_game_file
// function; for now it is not supposed to be called by Editor; although it
// is possible that eventually will be.
Expand Down
37 changes: 0 additions & 37 deletions Common/ac/gamesetupstructbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,6 @@

using namespace AGS::Common;

GameSetupStructBase::GameSetupStructBase()
: numviews(0)
, numcharacters(0)
, playercharacter(-1)
, numinvitems(0)
, numdialog(0)
, numdlgmessage(0)
, numfonts(0)
, color_depth(0)
, target_win(0)
, dialog_bullet(0)
, hotdot(0)
, hotdotouter(0)
, uniqueid(0)
, numgui(0)
, numcursors(0)
, default_lipsync_frame(0)
, invhotdotsprite(0)
{
memset(options, 0, sizeof(options));
memset(paluses, 0, sizeof(paluses));
memset(defpal, 0, sizeof(defpal));
memset(reserved, 0, sizeof(reserved));
}

GameSetupStructBase::~GameSetupStructBase()
{
Free();
}

void GameSetupStructBase::Free()
{
dict.reset();
chars.clear();

numcharacters = 0;
}

void GameSetupStructBase::SetGameResolution(Size game_res)
{
Expand Down
48 changes: 23 additions & 25 deletions Common/ac/gamesetupstructbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,36 @@ struct GameSetupStructBase
static const int NUM_LEGACY_GLOBALMES = 500;

Common::String gamename;
int options[MAX_OPTIONS];
uint8_t paluses[256];
RGB defpal[256];
int numviews;
int numcharacters;
int playercharacter;
int numinvitems;
int numdialog;
int numdlgmessage; // [DEPRECATED]
int numfonts;
int color_depth; // in bytes per pixel (ie. 1, 2, 4)
int target_win;
int dialog_bullet; // 0 for none, otherwise slot num of bullet point
int hotdot; // inv cursor hotspot dot color
int hotdotouter; // inv cursor hotspot cross color
int uniqueid; // random key identifying the game
int numgui;
int numcursors;
int default_lipsync_frame; // used for unknown chars
int invhotdotsprite;
int reserved[NUM_INTS_RESERVED];
int options[MAX_OPTIONS] = { 0 };
uint8_t paluses[256] = { 0 };
RGB defpal[256] = {};
int numviews = 0;
int numcharacters = 0;
int playercharacter = -1;
int numinvitems = 0;
int numdialog = 0;
int numdlgmessage = 0; // [DEPRECATED]
int numfonts = 0;
int color_depth = 0; // in bytes per pixel (ie. 1, 2, 4)
int target_win = 0;
int dialog_bullet = 0; // 0 for none, otherwise slot num of bullet point
int hotdot = 0; // inv cursor hotspot dot color
int hotdotouter = 0; // inv cursor hotspot cross color
int uniqueid = 0; // random key identifying the game
int numgui = 0;
int numcursors = 0;
int default_lipsync_frame = 0; // used for unknown chars
int invhotdotsprite = 0;
int reserved[NUM_INTS_RESERVED] = { 0 };
std::unique_ptr<WordsDictionary> dict;
std::vector<CharacterInfo> chars;

GameSetupStructBase();
GameSetupStructBase() = default;
GameSetupStructBase(GameSetupStructBase &&gss) = default;
~GameSetupStructBase();
~GameSetupStructBase() = default;

GameSetupStructBase &operator =(GameSetupStructBase &&gss) = default;

void Free();

// Tells whether the serialized game data contains certain components
struct SerializeInfo
{
Expand Down
2 changes: 1 addition & 1 deletion Editor/AGS.Native/agsnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ void free_old_game_data()
dialog.clear();

// free game struct last because it contains object counts
thisgame.Free();
thisgame = {};
}

void validate_mask(Common::Bitmap *toValidate, const char *name, int maxColour) {
Expand Down

0 comments on commit e1e4f68

Please sign in to comment.