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 21, 2024
1 parent 995f989 commit 17dde78
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 124 deletions.
36 changes: 0 additions & 36 deletions Common/ac/gamesetupstruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,12 @@
using namespace AGS::Common;

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

// CHECKME: not sure if this is needed, as likely will be rewritten by loading game data
intrVars[0] = InteractionVariable("Global 1", 0, 0);
numIntrVars = 1;
}

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

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

intrChar.clear();
charScripts.clear();

// TODO: find out if it really needs to begin with 1 here?
for (size_t i = 1; i < (size_t)MAX_INV; i++)
intrInv[i].reset();
invScripts.clear();
numinvitems = 0;

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

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

charProps.clear();
viewNames.clear();
}

// Assigns font info parameters using legacy flags value read from the game data
void SetFontInfoFromLegacyFlags(FontInfo &finfo, const uint8_t data)
{
Expand Down
18 changes: 8 additions & 10 deletions Common/ac/gamesetupstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ struct GameSetupStruct : public GameSetupStructBase
InventoryItemInfo invinfo[MAX_INV]{};
std::vector<MouseCursor> mcurs;
// These are old-style interaction variables created by the Interaction editor
InteractionVariable intrVars[MAX_INTERACTION_VARIABLES];
InteractionVariable intrVars[MAX_INTERACTION_VARIABLES]{};
int numIntrVars = 0;
std::vector<UInteraction> intrChar;
UInteraction intrInv[MAX_INV];
std::vector<UInteractionEvents> charScripts;
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 @@ -66,19 +66,19 @@ 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;
std::vector<AudioClipType> audioClipTypes;
// A clip to play when player gains score in game
// NOTE: this stores an internal audio clip index, which may or not correspond
// to the OPT_SCORESOUND, and also depends on whether the game was upgraded from <3.2 data.
int scoreClipID;
int scoreClipID = -1;
// number of accessible game audio channels (the ones under direct user control)
int numGameChannels = 0;
// backward-compatible channel limit that may be exported to script and reserved by audiotypes
Expand All @@ -102,12 +102,10 @@ struct GameSetupStruct : public GameSetupStructBase

GameSetupStruct();
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
46 changes: 0 additions & 46 deletions Common/ac/gamesetupstructbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,52 +21,6 @@

using namespace AGS::Common;

GameSetupStructBase::GameSetupStructBase()
: numviews(0)
, numcharacters(0)
, playercharacter(-1)
, totalscore(0)
, 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)
, _resolutionType(kGameResolution_Undefined)
, _dataUpscaleMult(1)
, _screenUpscaleMult(1)
{
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()
{
for (int i = 0; i < MAXGLOBALMES; ++i)
{
messages[i].Free();
}
dict.reset();
chars.clear();

numcharacters = 0;
}

void GameSetupStructBase::SetDefaultResolution(GameResolutionType type)
{
SetDefaultResolution(type, Size());
Expand Down
60 changes: 29 additions & 31 deletions Common/ac/gamesetupstructbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,45 +40,43 @@ struct GameSetupStructBase
static const int NUM_INTS_RESERVED = 16;

Common::String gamename;
int options[MAX_OPTIONS];
uint8_t paluses[256];
RGB defpal[256];
int numviews;
int numcharacters;
int playercharacter;
int totalscore;
int numinvitems;
int numdialog;
int numdlgmessage; // [DEPRECATED]
int numfonts;
int color_depth; // in bytes per pixel (ie. 1 or 2)
int target_win;
int dialog_bullet; // 0 for none, otherwise slot num of bullet point
int hotdot; // inv cursor hotspot dot color
int hotdotouter;
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];
Common::String messages[MAXGLOBALMES];
int options[MAX_OPTIONS] = { 0 };
uint8_t paluses[256] = { 0 };
RGB defpal[256] = {};
int numviews = 0;
int numcharacters = 0;
int playercharacter = -1;
int totalscore = 0;
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 };
Common::String messages[MAXGLOBALMES] = {};
std::unique_ptr<WordsDictionary> dict;
std::vector<CharacterInfo> chars;
std::vector<CharacterInfo2> chars2; // extended character fields

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

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

void Free();
void SetDefaultResolution(GameResolutionType type);
void SetDefaultResolution(Size game_res);
void SetGameResolution(GameResolutionType type);
void SetGameResolution(Size game_res);

// Tells whether the serialized game data contains certain components
struct SerializeInfo
{
Expand Down Expand Up @@ -226,7 +224,7 @@ struct GameSetupStructBase
void OnResolutionSet();

// Game's native resolution ID, used to init following values.
GameResolutionType _resolutionType;
GameResolutionType _resolutionType = kGameResolution_Undefined;

// Determines game's default screen resolution. Use for the reference
// when comparing with actual screen resolution, which may be modified
Expand All @@ -242,11 +240,11 @@ struct GameSetupStructBase
Size _letterboxSize;

// Game logic to game resolution coordinate factor
int _dataUpscaleMult;
int _dataUpscaleMult = 1;
// Multiplier for various UI drawin sizes, meant to keep UI elements readable
int _relativeUIMult;
int _relativeUIMult = 1;
// Game default resolution to actual game resolution factor
int _screenUpscaleMult;
int _screenUpscaleMult = 1;
};

#endif // __AGS_CN_AC__GAMESETUPSTRUCTBASE_H
2 changes: 1 addition & 1 deletion Editor/AGS.Native/agsnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ void free_old_game_data()
free_script_modules();

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

// remap the scene, from its current palette oldpale to palette
Expand Down

0 comments on commit 17dde78

Please sign in to comment.