ScummVM API documentation
game_setup_struct.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22//=============================================================================
23//
24// GameSetupStruct is a contemporary main game data.
25//
26//=============================================================================
27
28#ifndef AGS_SHARED_AC_GAME_SETUP_STRUCT_H
29#define AGS_SHARED_AC_GAME_SETUP_STRUCT_H
30
31#include "common/std/array.h"
32#include "common/std/vector.h"
33#include "ags/shared/ac/audio_clip_type.h"
34#include "ags/shared/ac/character_info.h" // TODO: constants to separate header
35#include "ags/shared/ac/game_setup_struct_base.h"
36#include "ags/shared/ac/inventory_item_info.h"
37#include "ags/shared/ac/mouse_cursor.h"
38#include "ags/shared/ac/dynobj/script_audio_clip.h"
39#include "ags/shared/game/custom_properties.h"
40#include "ags/shared/game/main_game_file.h" // TODO: constants to separate header or split out reading functions
41
42namespace AGS3 {
43
44namespace AGS {
45namespace Shared {
46struct AssetLibInfo;
47struct Interaction;
48struct InteractionScripts;
49typedef std::shared_ptr<Interaction> PInteraction;
50typedef std::shared_ptr<InteractionScripts> PInteractionScripts;
51} // namespace Shared
52} // namespace AGS
53
54using AGS::Shared::PInteraction;
55using AGS::Shared::PInteractionScripts;
56using AGS::Shared::HGameFileError;
57
58
59// TODO: split GameSetupStruct into struct used to hold loaded game data, and actual runtime object
61 // This array is used only to read data into;
62 // font parameters are then put and queried in the fonts module
63 // TODO: split into installation params (used only when reading) and runtime params
65 InventoryItemInfo invinfo[MAX_INV]{};
68 PInteraction intrInv[MAX_INV];
71 // TODO: why we do not use this in the engine instead of
72 // _G(loaded_game_file_version)?
73 int filever; // just used by editor
74 Shared::String compiled_with; // version of AGS this data was created by
75 char lipSyncFrameLetters[MAXLIPSYNCFRAMES][50];
78 AGS::Shared::StringIMap invProps[MAX_INV];
79 // NOTE: although the view names are stored in game data, they are never
80 // used, nor registered as script exports; numeric IDs are used to
81 // reference views instead.
83 Shared::String invScriptNames[MAX_INV];
84 std::vector<Shared::String> dialogScriptNames;
85 char guid[MAX_GUID_LENGTH];
86 char saveGameFileExtension[MAX_SG_EXT_LENGTH];
87 // NOTE: saveGameFolderName is generally used to create game subdirs in common user directories
88 Shared::String saveGameFolderName;
89 int roomCount;
90 std::vector<int> roomNumbers;
93 std::vector<AudioClipType> audioClipTypes;
94 // A clip to play when player gains score in game
95 // TODO: find out why OPT_SCORESOUND option cannot be used to store this in >=3.2 games
96 int scoreClipID;
97 // number of accessible game audio channels (the ones under direct user control)
98 int numGameChannels = 0;
99 // backward-compatible channel limit that may be exported to script and reserved by audiotypes
100 int numCompatGameChannels = 0;
101
102 // TODO: I converted original array of sprite infos to vector here, because
103 // statistically in most games sprites go in long continious sequences with minimal
104 // gaps, and standard hash-map will have relatively big memory overhead compared.
105 // Of course vector will not behave very well if user has created e.g. only
106 // sprite #1 and sprite #1000000. For that reason I decided to still limit static
107 // sprite count to some reasonable number for the time being. Dynamic sprite IDs are
108 // added in sequence, so there won't be any issue with these.
109 // There could be other collection types, more optimal for this case. For example,
110 // we could use a kind of hash map containing fixed-sized arrays, where size of
111 // array is calculated based on key spread factor.
112 std::vector<SpriteInfo> SpriteInfos;
113
114 // Get game's native color depth (bits per pixel)
115 inline int GetColorDepth() const {
116 return color_depth * 8;
117 }
118
119
121 GameSetupStruct(GameSetupStruct &&gss) = default;
123
124 GameSetupStruct &operator=(GameSetupStruct &&gss) = default;
125
126 void Free();
127
128 // [IKM] Game struct loading code is moved here from Engine's load_game_file
129 // function; for now it is not supposed to be called by Editor; although it
130 // is possible that eventually will be.
131 //
132 // Since reading game data is made in a bit inconvenient way I had to
133 // a) divide process into three functions (there's some extra stuff
134 // being read between them;
135 // b) use a helper struct to pass some arguments
136 //
137 // I also had to move BuildAudioClipArray from the engine and make it
138 // GameSetupStruct member.
139
140 //--------------------------------------------------------------------
141 // Do not call these directly
142 //------------------------------
143 // Part 1
144 void read_savegame_info(Shared::Stream *in, GameDataVersion data_ver);
145 void read_font_infos(Shared::Stream *in, GameDataVersion data_ver);
146 HGameFileError read_cursors(Shared::Stream *in);
147 void read_interaction_scripts(Shared::Stream *in, GameDataVersion data_ver);
148 void read_words_dictionary(Shared::Stream *in);
149
150 void ReadInvInfo(Shared::Stream *in);
151 void WriteInvInfo(Shared::Stream *out);
152 void ReadMouseCursors(Shared::Stream *in);
153 void WriteMouseCursors(Shared::Stream *out);
154 //------------------------------
155 // Part 2
156 void read_characters(Shared::Stream *in);
157 void read_lipsync(Shared::Stream *in, GameDataVersion data_ver);
158 void read_messages(Shared::Stream *in, const std::array<int32_t> &load_messages, GameDataVersion data_ver);
159
160 void ReadCharacters(Shared::Stream *in);
161 void WriteCharacters(Shared::Stream *out);
162 //------------------------------
163 // Part 3
164 HGameFileError read_customprops(Shared::Stream *in, GameDataVersion data_ver);
165 HGameFileError read_audio(Shared::Stream *in, GameDataVersion data_ver);
166 void read_room_names(Shared::Stream *in, GameDataVersion data_ver);
167
168 void ReadAudioClips(Shared::Stream *in, size_t count);
169 //--------------------------------------------------------------------
170
171 // Functions for reading and writing appropriate data from/to save game
172 void ReadFromSaveGame_v321(Shared::Stream *in);
173
174 void ReadFromSavegame(Shared::Stream *in);
175 void WriteForSavegame(Shared::Stream *out);
176};
177
178//=============================================================================
179#if defined (OBSOLETE)
180struct OldGameSetupStruct;
181void ConvertOldGameStruct(OldGameSetupStruct *ogss, GameSetupStruct *gss);
182#endif // OBSOLETE
183
184// Finds an audio clip using legacy convention index
185ScriptAudioClip *GetAudioClipForOldStyleNumber(GameSetupStruct &game, bool is_music, int num);
186
187} // namespace AGS3
188
189#endif
Definition: error.h:110
Definition: stream.h:52
Definition: string.h:60
Definition: ptr.h:159
Definition: vector.h:39
Definition: game_setup_struct_base.h:57
Definition: game_setup_struct.h:60
Definition: inventory_item_info.h:41
Definition: script_audio_clip.h:52