From e1e4f68d64ceee9dd342428d5e8c8ef9044b93f5 Mon Sep 17 00:00:00 2001 From: Ivan Mogilko Date: Sat, 21 Dec 2024 00:23:04 +0300 Subject: [PATCH] Common: init GameSetupStruct in declaration --- Common/ac/gamesetupstruct.cpp | 35 ---------------------- Common/ac/gamesetupstruct.h | 16 +++++------ Common/ac/gamesetupstructbase.cpp | 37 ------------------------ Common/ac/gamesetupstructbase.h | 48 +++++++++++++++---------------- Editor/AGS.Native/agsnative.cpp | 2 +- 5 files changed, 31 insertions(+), 107 deletions(-) diff --git a/Common/ac/gamesetupstruct.cpp b/Common/ac/gamesetupstruct.cpp index a24eb8b30f1..92f309249fa 100644 --- a/Common/ac/gamesetupstruct.cpp +++ b/Common/ac/gamesetupstruct.cpp @@ -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) { diff --git a/Common/ac/gamesetupstruct.h b/Common/ac/gamesetupstruct.h index 3085fd0b0bb..7ab468152dc 100644 --- a/Common/ac/gamesetupstruct.h +++ b/Common/ac/gamesetupstruct.h @@ -48,9 +48,9 @@ struct GameSetupStruct : public GameSetupStructBase std::vector 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 charProps; AGS::Common::StringIMap invProps[MAX_INV]; @@ -64,11 +64,11 @@ struct GameSetupStruct : public GameSetupStructBase std::vector viewNames; Common::String invScriptNames[MAX_INV]; std::vector 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 roomNumbers; std::vector roomNames; std::vector audioClips; @@ -95,14 +95,12 @@ struct GameSetupStruct : public GameSetupStructBase std::vector 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. diff --git a/Common/ac/gamesetupstructbase.cpp b/Common/ac/gamesetupstructbase.cpp index 1409e04da15..6fa1aa75aab 100644 --- a/Common/ac/gamesetupstructbase.cpp +++ b/Common/ac/gamesetupstructbase.cpp @@ -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) { diff --git a/Common/ac/gamesetupstructbase.h b/Common/ac/gamesetupstructbase.h index d1427c007f7..ab2e6727076 100644 --- a/Common/ac/gamesetupstructbase.h +++ b/Common/ac/gamesetupstructbase.h @@ -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 dict; std::vector 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 { diff --git a/Editor/AGS.Native/agsnative.cpp b/Editor/AGS.Native/agsnative.cpp index 772924a82f1..a6e35485bc6 100644 --- a/Editor/AGS.Native/agsnative.cpp +++ b/Editor/AGS.Native/agsnative.cpp @@ -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) {