ScummVM API documentation
game_setup_struct_base.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 #ifndef AGS_SHARED_AC_GAME_SETUP_STRUCT_BASE_H
23 #define AGS_SHARED_AC_GAME_SETUP_STRUCT_BASE_H
24 
25 #include "ags/lib/allegro.h" // RGB
26 #include "ags/shared/ac/game_version.h"
27 #include "ags/shared/ac/game_struct_defines.h"
28 #include "ags/shared/util/string.h"
29 #include "ags/globals.h"
30 
31 namespace AGS3 {
32 
33 // Forward declaration
34 namespace AGS {
35 namespace Shared {
36 class Stream;
37 } // namespace Shared
38 } // namespace AGS
39 
40 using namespace AGS; // FIXME later
41 
42 struct WordsDictionary;
43 struct CharacterInfo;
44 struct ccScript;
45 
46 
48  static const int GAME_NAME_LENGTH = 50;
49  static const int MAX_OPTIONS = 100;
50  static const int NUM_INTS_RESERVED = 17;
51 
52  char gamename[GAME_NAME_LENGTH];
53  int32_t options[MAX_OPTIONS];
54  unsigned char paluses[256];
55  RGB defpal[256];
56  int numviews;
57  int numcharacters;
58  int playercharacter;
59  int totalscore;
60  short numinvitems;
61  int numdialog, numdlgmessage;
62  int numfonts;
63  int color_depth; // in bytes per pixel (ie. 1 or 2)
64  int target_win;
65  int dialog_bullet; // 0 for none, otherwise slot num of bullet point
66  unsigned short hotdot, hotdotouter; // inv cursor hotspot dot color
67  int uniqueid; // random key identifying the game
68  int numgui;
69  int numcursors;
70  int default_lipsync_frame; // used for unknown chars
71  int invhotdotsprite;
72  int32_t reserved[NUM_INTS_RESERVED];
73  String messages[MAXGLOBALMES];
74  WordsDictionary *dict;
75  char *globalscript;
76  CharacterInfo *chars;
77  ccScript *compiled_script;
78 
79  // TODO: refactor to not have this as struct members
80  int32_t *load_messages;
81  bool load_dictionary;
82  bool load_compiled_script;
83  // [IKM] 2013-03-30
84  // NOTE: it looks like nor 'globalscript', not 'compiled_script' are used
85  // to store actual script data anytime; 'ccScript* _GP(gamescript)' global
86  // pointer is used for that instead.
87 
90  void Free();
91  void SetDefaultResolution(GameResolutionType type);
92  void SetDefaultResolution(Size game_res);
93  void SetGameResolution(GameResolutionType type);
94  void SetGameResolution(Size game_res);
95  void ReadFromFile(Shared::Stream *in, GameDataVersion game_ver);
96  void WriteToFile(Shared::Stream *out) const;
97 
98  //
99  // ** On game resolution.
100  //
101  // Game resolution is a size of a native game screen in pixels.
102  // This is the "game resolution" that developer sets up in AGS Editor.
103  // It is in the same units in which sprite and font sizes are defined.
104  //
105  // Graphic renderer may scale and stretch game's frame as requested by
106  // player or system, which will not affect native coordinates in any way.
107  //
108  // ** Legacy upscale mode.
109  //
110  // In the past engine had a separation between logical and native screen
111  // coordinates and supported running games "upscaled". E.g. 320x200 games
112  // could be run as 640x400. This was not done by simply stretching final
113  // game's drawn frame to the larger window, but by multiplying all data
114  // containing coordinates and graphics either on load or real-time.
115  // Games of 640x400 and above were scripted and set up in coordinate units
116  // that were always x2 times smaller than the one developer chose.
117  // For example, choosing a 640x400 resolution would make game draw itself
118  // as 640x400, but all the game logic (object properties, script commands)
119  // would work in 320x200 (this also let run 640x400 downscaled to 320x200).
120  // Ignoring the obvious complications, the known benefit from such approach
121  // was that developers could supply separate sets of fonts and sprites for
122  // low-res and high-res modes.
123  // The 3rd generation of AGS still allows to achieve same effect by using
124  // backwards-compatible option (although it is not recommended except when
125  // importing and continuing old projects).
126  //
127  // In order to support this legacy behavior we have a set of functions for
128  // coordinate conversion. They are required to move from "data" resolution
129  // to "final game" resolution and back.
130  //
131  // Some of the script commands, as well as some internal engine data use
132  // coordinates in "game resolution" instead (this should be documented).
133  // In such case there's another conversion which translates these from
134  // default to actual resolution; e.g. when 320x200 game is run as 640x400
135  // they should be multiplied by 2.
136  //
137  // ** TODO.
138  //
139  // Truth be told, all this is still implemented incorrectly, because no one
140  // found time to rewrite the thing. The correct way would perhaps be:
141  // 1) treat old games as x2 lower resolution than they say.
142  // 2) support drawing particular sprites and texts in x2 higher resolution
143  // (assuming display resolution allows). The latter is potentially enabled
144  // by "sprite batches" system in the engine and will benefit new games too.
145 
146  inline GameResolutionType GetResolutionType() const {
147  return _resolutionType;
148  }
149 
150  // Get actual game's resolution
151  const Size &GetGameRes() const {
152  return _gameResolution;
153  }
154  // Get default resolution the game was created for;
155  // this is usually equal to GetGameRes except for legacy modes.
156  const Size &GetDefaultRes() const {
157  return _defGameResolution;
158  }
159  // Get data & script resolution;
160  // this is usually equal to GetGameRes except for legacy modes.
161  const Size &GetDataRes() const {
162  return _dataResolution;
163  }
164  // Get game data-->final game resolution coordinate multiplier
165  inline int GetDataUpscaleMult() const {
166  return _dataUpscaleMult;
167  }
168  // Get multiplier for various default UI sizes, meant to keep UI looks
169  // more or less readable in any game resolution.
170  // TODO: find a better solution for UI sizes, perhaps make variables.
171  inline int GetRelativeUIMult() const {
172  return _relativeUIMult;
173  }
174  // Get game default res-->final game resolution coordinate multiplier;
175  // used to convert coordinates from original game res to actual one
176  inline int GetScreenUpscaleMult() const {
177  return _screenUpscaleMult;
178  }
179  // Tells if game allows assets defined in relative resolution;
180  // that is - have to be converted to this game resolution type
181  inline bool AllowRelativeRes() const {
182  return options[OPT_RELATIVEASSETRES] != 0;
183  }
184  // Legacy definition of high and low game resolution.
185  // Used to determine certain hardcoded coordinate conversion logic, but
186  // does not make much sense today when the resolution is arbitrary.
187  inline bool IsLegacyHiRes() const {
188  if (_resolutionType == kGameResolution_Custom)
189  return (_gameResolution.Width * _gameResolution.Height) > (320 * 240);
190  return ::AGS3::IsLegacyHiRes(_resolutionType);
191  }
192  // Tells if data has coordinates in default game resolution
193  inline bool IsDataInNativeCoordinates() const {
194  return options[OPT_NATIVECOORDINATES] != 0;
195  }
196 
197  // Tells if game runs in native letterbox mode (legacy option)
198  inline bool IsLegacyLetterbox() const {
199  return options[OPT_LETTERBOX] != 0;
200  }
201  // Get letterboxed frame size
202  const Size &GetLetterboxSize() const {
203  return _letterboxSize;
204  }
205 
206  // Room region/hotspot masks are traditionally 1:1 of the room's size in
207  // low-resolution games and 1:2 of the room size in high-resolution games.
208  // This also means that mask relation to data resolution is 1:1 if the
209  // game uses low-res coordinates in script and 1:2 if high-res.
210 
211  // Test if the game is built around old audio system
212  inline bool IsLegacyAudioSystem() const {
213  return _G(loaded_game_file_version) < kGameVersion_320;
214  }
215 
216  // Returns the expected filename of a digital audio package
217  inline AGS::Shared::String GetAudioVOXName() const {
218  return IsLegacyAudioSystem() ? "music.vox" : "audio.vox";
219  }
220 
221  // Returns a list of game options that are forbidden to change at runtime
222  inline static Common::Array<int> GetRestrictedOptions() {
223  return Common::Array<int> {{
224  OPT_DEBUGMODE, OPT_LETTERBOX, OPT_HIRES_FONTS, OPT_SPLITRESOURCES,
225  OPT_STRICTSCRIPTING, OPT_LEFTTORIGHTEVAL, OPT_COMPRESSSPRITES, OPT_STRICTSTRINGS,
226  OPT_NATIVECOORDINATES, OPT_SAFEFILEPATHS, OPT_DIALOGOPTIONSAPI, OPT_BASESCRIPTAPI,
227  OPT_SCRIPTCOMPATLEV, OPT_RELATIVEASSETRES, OPT_GAMETEXTENCODING, OPT_KEYHANDLEAPI,
228  OPT_CUSTOMENGINETAG
229  }};
230  }
231 
232 private:
233  void SetDefaultResolution(GameResolutionType type, Size game_res);
234  void SetNativeResolution(GameResolutionType type, Size game_res);
235  void OnResolutionSet();
236 
237  // Game's native resolution ID, used to init following values.
238  GameResolutionType _resolutionType;
239 
240  // Determines game's default screen resolution. Use for the reference
241  // when comparing with actual screen resolution, which may be modified
242  // by certain overriding game modes.
243  Size _defGameResolution;
244  // Determines game's actual resolution.
245  Size _gameResolution;
246  // Determines resolution in which loaded data and script define coordinates
247  // and sizes (with very little exception).
248  Size _dataResolution;
249  // Letterboxed frame size. Used when old game is run in native letterbox
250  // mode. In all other situations is equal to game's resolution.
251  Size _letterboxSize;
252 
253  // Game logic to game resolution coordinate factor
254  int _dataUpscaleMult;
255  // Multiplier for various UI drawin sizes, meant to keep UI elements readable
256  int _relativeUIMult;
257  // Game default resolution to actual game resolution factor
258  int _screenUpscaleMult;
259 };
260 
261 } // namespace AGS3
262 
263 #endif
Definition: achievements_tables.h:27
Definition: words_dictionary.h:41
Definition: game_setup_struct_base.h:47
Definition: color.h:49
Definition: character_info.h:74
Definition: string.h:62
Definition: geometry.h:144
Definition: cc_script.h:37
Definition: stream.h:52
Definition: ags.h:40