ScummVM API documentation
sword2.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 * Additional copyright for this file:
8 * Copyright (C) 1994-1998 Revolution Software Ltd.
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#ifndef SWORD2_SWORD2_H
25#define SWORD2_SWORD2_H
26
27#define FRAMES_PER_SECOND 12
28
29// Enable this to make it possible to clear the mouse cursor luggage by
30// right-clicking. The original didn't do this, but it feels natural to me.
31// However, I'm afraid that it'll interfer badly with parts of the game, so
32// for now I'll keep it disabled.
33
34#define RIGHT_CLICK_CLEARS_LUGGAGE 0
35
36#include "engines/engine.h"
37
38#include "common/events.h"
39#include "common/util.h"
40#include "common/random.h"
41#include "sword2/detection.h"
42
43#define MAX_starts 100
44#define MAX_description 100
45
46class OSystem;
47
56namespace Sword2 {
57
58class MemoryManager;
59class ResourceManager;
60class Sound;
61class Screen;
62class Mouse;
63class Logic;
64class FontRenderer;
65class Gui;
66class Debugger;
67
68enum {
69 RD_LEFTBUTTONDOWN = 0x01,
70 RD_LEFTBUTTONUP = 0x02,
71 RD_RIGHTBUTTONDOWN = 0x04,
72 RD_RIGHTBUTTONUP = 0x08,
73 RD_WHEELUP = 0x10,
74 RD_WHEELDOWN = 0x20,
75 RD_KEYDOWN = 0x40
76};
77
78struct MouseEvent {
79 bool pending;
80 uint16 buttons;
81};
82
84 bool pending;
86};
87
88struct StartUp {
89 char description[MAX_description];
90
91 // id of screen manager object
92 uint32 start_res_id;
93
94 // Tell the manager which startup you want (if there are more than 1)
95 // (i.e more than 1 entrance to a screen and/or separate game boots)
96 uint32 key;
97};
98
99class Sword2Engine : public Engine {
100private:
101 uint32 _inputEventFilter;
102
103 // The event "buffers"
104 MouseEvent _mouseEvent;
105 KeyboardEvent _keyboardEvent;
106
107 uint32 _bootParam;
108 int32 _saveSlot;
109
110 void getPlayerStructures();
111 void putPlayerStructures();
112
113 uint32 saveData(uint16 slotNo, byte *buffer, uint32 bufferSize);
114 uint32 restoreData(uint16 slotNo, byte *buffer, uint32 bufferSize);
115
116 uint32 calcChecksum(byte *buffer, uint32 size);
117
118 uint32 _totalStartups;
119 uint32 _totalScreenManagers;
120 uint32 _startRes;
121
122 bool _useSubtitles;
123 int _gameSpeed;
124
125 // Used to trigger GMM Loading
126 int _gmmLoadSlot;
127
128 StartUp _startList[MAX_starts];
129
130 // We need these to fetch data from SCREENS.CLU, which is
131 // a resource file with custom format keeping background and
132 // parallax data (which is removed from multiscreen files).
133 byte *fetchPsxBackground(uint32 location);
134 byte *fetchPsxParallax(uint32 location, uint8 level); // level: 0 -> bg, 1 -> fg
135
136 // Original game platform (PC/PSX)
137 static Common::Platform _platform;
138
139 PauseToken _gamePauseToken;
140
141protected:
142 // Engine APIs
143 Common::Error run() override;
144 bool hasFeature(EngineFeature f) const override;
145 void syncSoundSettings() override;
146 void pauseEngineIntern(bool pause) override;
147
148public:
149 Sword2Engine(OSystem *syst, const ADGameDescription *gameDesc);
150 ~Sword2Engine() override;
151
152 int getFramesPerSecond();
153
154 void registerDefaultSettings();
155 void readSettings();
156 void writeSettings();
157
158 void setupPersistentResources();
159
160 bool getSubtitles() { return _useSubtitles; }
161 void setSubtitles(bool b) { _useSubtitles = b; }
162
163 // GMM Loading/Saving
164 Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
165 bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
166 Common::Error loadGameState(int slot) override;
167 bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
168
169 uint32 _features;
170
171 MemoryManager *_memory;
172 ResourceManager *_resman;
173 Sound *_sound;
174 Screen *_screen;
175 Mouse *_mouse;
176 Logic *_logic;
177 FontRenderer *_fontRenderer;
178
179 bool _isRTL;
180
181 Debugger *_debugger;
182
184
185 uint32 _speechFontId;
186 uint32 _controlsFontId;
187 uint32 _redFontId;
188
189 uint32 setInputEventFilter(uint32 filter);
190
191 void parseInputEvents();
192
193 bool checkForMouseEvents();
194 MouseEvent *mouseEvent();
195 KeyboardEvent *keyboardEvent();
196
197 bool _wantSfxDebug;
198
199 int32 _gameCycle;
200
201 bool _isKorTrs;
202
203#if RIGHT_CLICK_CLEARS_LUGGAGE
204 bool heldIsInInventory();
205#endif
206
207 void fetchPalette(byte *screenFile, byte *palBuffer);
208 byte *fetchScreenHeader(byte *screenFile);
209 byte *fetchLayerHeader(byte *screenFile, uint16 layerNo);
210 byte *fetchShadingMask(byte *screenFile);
211
212 byte *fetchAnimHeader(byte *animFile);
213 byte *fetchCdtEntry(byte *animFile, uint16 frameNo);
214 byte *fetchFrameHeader(byte *animFile, uint16 frameNo);
215 byte *fetchBackgroundParallaxLayer(byte *screenFile, int layer);
216 byte *fetchBackgroundLayer(byte *screenFile);
217 byte *fetchForegroundParallaxLayer(byte *screenFile, int layer);
218 byte *fetchTextLine(byte *file, uint32 text_line);
219 bool checkTextLine(byte *file, uint32 text_line);
220 byte *fetchPaletteMatchTable(byte *screenFile);
221
222 uint32 saveGame(uint16 slotNo, const byte *description);
223 uint32 restoreGame(uint16 slotNo);
224 uint32 getSaveDescription(uint16 slotNo, byte *description);
225 bool saveExists();
226 bool saveExists(uint16 slotNo);
227 uint32 restoreFromBuffer(byte *buffer, uint32 size);
228 Common::String getSaveStateName(int slot) const override;
229 uint32 findBufferSize();
230
231 void startGame();
232 void gameCycle();
233 void restartGame();
234
235 void sleepUntil(uint32 time);
236
237 void initializeFontResourceFlags();
238 void initializeFontResourceFlags(uint8 language);
239
240 bool initStartMenu();
241 void registerStartPoint(int32 key, char *name);
242
243 uint32 getNumStarts() { return _totalStartups; }
244 uint32 getNumScreenManagers() { return _totalScreenManagers; }
245 StartUp *getStartList() { return _startList; }
246
247 void runStart(int start);
248
249 // Convenience alias for OSystem::getMillis().
250 // This is a bit hackish, of course :-).
251 uint32 getMillis();
252
253 // Used to check whether we are running PSX version
254 static bool isPsx() { return _platform == Common::kPlatformPSX; }
255};
256
257} // End of namespace Sword2
258
259#endif
Definition: error.h:81
Definition: random.h:44
Definition: str.h:59
Definition: ustr.h:57
Definition: engine.h:155
EngineFeature
Definition: engine.h:293
Definition: system.h:166
Definition: engine.h:111
Definition: console.h:32
Definition: maketext.h:80
Definition: logic.h:52
Definition: memory.h:40
Definition: mouse.h:136
Definition: resman.h:52
Definition: screen.h:195
Definition: sound.h:175
Definition: sword2.h:99
Common::String getSaveStateName(int slot) const override
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Common::Error run() override
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
void pauseEngineIntern(bool pause) override
Common::Error loadGameState(int slot) override
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave=false) override
bool hasFeature(EngineFeature f) const override
void syncSoundSettings() override
Platform
Definition: platform.h:93
Definition: animation.h:37
Definition: advancedDetector.h:164
Definition: keyboard.h:294
Definition: atari-screen.h:58
Definition: sword2.h:83
Definition: sword2.h:78
Definition: sword2.h:88