ScummVM API documentation
kyra_v1.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 KYRA_KYRA_V1_H
23#define KYRA_KYRA_V1_H
24
25#include "engines/engine.h"
26
27#include "common/array.h"
28#include "common/error.h"
29#include "common/events.h"
30#include "common/hashmap.h"
31#include "common/random.h"
32#include "common/rendermode.h"
33
34#include "audio/mixer.h"
35
36#include "kyra/script/script.h"
37#include "kyra/engine/item.h"
38#include "kyra/detection.h"
39
40namespace Common {
41class OutSaveFile;
42class SeekableReadStream;
43class WriteStream;
44} // End of namespace Common
45
46namespace Graphics {
47struct Surface;
48}
49
50class KyraMetaEngine;
51
87namespace Kyra {
88
89struct KeyCodeHash : public Common::UnaryFunction<Common::KeyCode, uint> {
90 uint operator()(Common::KeyCode val) const { return (uint)val; }
91};
92
93// TODO: this is just the start of makeing the debug output of the kyra engine a bit more useable
94// in the future we maybe merge some flags and/or create new ones
107};
108
109enum AudioResourceSet {
110 kMusicIntro = 0,
111 kMusicIngame,
112 kMusicFinale
113};
114
115class Screen;
116class Resource;
117class Sound;
118class TextDisplayer;
119class StaticResource;
120class TimerManager;
121class Debugger;
122class GUI;
123
124struct Button;
125
126class KyraEngine_v1 : public Engine {
127friend class Debugger;
128friend class ::KyraMetaEngine;
129friend class GUI;
130friend class GUI_v1;
131friend class GUI_EoB;
132friend class GUI_EoB_SegaCD;
133friend class SoundMidiPC; // For _eventMan
134friend class SeqPlayer_HOF; // For skipFlag()
135friend class TransferPartyWiz; // For save state API
136public:
137 KyraEngine_v1(OSystem *system, const GameFlags &flags);
138 ~KyraEngine_v1() override;
139
140 uint8 game() const { return _flags.gameID; }
141 const GameFlags &gameFlags() const { return _flags; }
142
143 // access to Kyra specific functionallity
144 Resource *resource() { return _res; }
145 virtual Screen *screen() = 0;
146 virtual TextDisplayer *text() { return _text; }
147 virtual GUI *gui() const { return 0; }
148 Sound *sound() { return _sound; }
149 StaticResource *staticres() { return _staticres; }
150 TimerManager *timer() { return _timer; }
151
152 uint32 tickLength() const { return _tickLength; }
153
155
156 // input
157 void setMousePos(int x, int y);
158 Common::Point getMousePos();
159
160 // config specific
161 bool speechEnabled();
162 bool textEnabled();
163
164 enum kVolumeEntry {
165 kVolumeMusic = 0,
166 kVolumeSfx = 1,
167 kVolumeSpeech = 2
168 };
169
170 // volume reaches per default from 2 to 97
171 void setVolume(kVolumeEntry vol, uint8 value);
172 uint8 getVolume(kVolumeEntry vol);
173
174 void syncSoundSettings() override;
175
176 // game flag handling
177 int setGameFlag(int flag);
178 int queryGameFlag(int flag) const;
179 int resetGameFlag(int flag);
180
181 // sound
182 virtual void snd_playTheme(int file, int track);
183 virtual void snd_playSoundEffect(int id, int volume=0xFF);
184 virtual void snd_playWanderScoreViaMap(int command, int restart);
185 virtual void snd_playVoiceFile(int id) = 0;
186 virtual bool snd_voiceIsPlaying();
187 virtual void snd_stopVoice();
188
189 // delay functionallity
190 virtual void delayUntil(uint32 timestamp, bool updateGameTimers = false, bool update = false, bool isMainLoop = false);
191 virtual void delay(uint32 millis, bool update = false, bool isMainLoop = false);
192 virtual void delayWithTicks(int ticks);
193
194protected:
195 // Engine APIs
196 virtual Common::Error init();
197 virtual Common::Error go() = 0;
198
199 Common::Error run() override {
200 Common::Error err;
201 registerDefaultSettings();
202 err = init();
203 if (err.getCode() != Common::kNoError)
204 return err;
205 return go();
206 }
207
208 bool hasFeature(EngineFeature f) const override;
209 void pauseEngineIntern(bool pause) override;
210
211 // intern
212 Resource *_res;
213 Sound *_sound;
214 TextDisplayer *_text;
215 StaticResource *_staticres;
216 TimerManager *_timer;
217 EMCInterpreter *_emc;
218
219 // input
220 void setupKeyMap();
221 void updateInput();
222 int checkInput(Button *buttonList, bool mainLoop = false, int eventFlag = 0x8000);
223 void removeInputTop();
224
225 int _mouseX, _mouseY;
226
227 // This is a somewhat hacky but probably least invasive way to move
228 // the whole ingame screen output down a couple of lines for EOB SegaCD.
229 void transposeScreenOutputY(int yAdd);
230 int _transOffsY;
231
232 struct Event {
233 Common::Event event;
234 bool causedSkip;
235
236 Event() : event(), causedSkip(false) {}
237 Event(Common::Event e) : event(Common::move(e)), causedSkip(false) {}
238 Event(Common::Event e, bool skip) : event(Common::move(e)), causedSkip(skip) {}
239
240 operator Common::Event() const { return event; }
241 };
242 Common::List<Event> _eventList;
244 KeyMap _keyMap;
245 bool _asciiCodeEvents;
246 bool _kbEventSkip;
247
248 // config specific
249 virtual void registerDefaultSettings();
250 virtual void readSettings();
251 virtual void writeSettings();
252
253 uint8 _configWalkspeed;
254
255 int _configMusic;
256 bool _configSounds;
257 uint8 _configVoice;
258 bool _configNullSound;
259
260 Common::RenderMode _configRenderMode;
261
262 // game speed
263 virtual bool skipFlag() const;
264 virtual void resetSkipFlag(bool removeEvent = true);
265
266 uint16 _tickLength;
267 uint16 _gameSpeed;
268
269 // run
270 int8 _deathHandler;
271
272 // timer
273 virtual void setupTimers() = 0;
274
275 virtual void setWalkspeed(uint8 speed) = 0;
276
277 // detection
278 GameFlags _flags;
279
280 // opcode
281 virtual void setupOpcodeTable() = 0;
283
284 int o1_queryGameFlag(EMCState *script);
285 int o1_setGameFlag(EMCState *script);
286 int o1_resetGameFlag(EMCState *script);
287 int o1_getRand(EMCState *script);
288 int o1_hideMouse(EMCState *script);
289 int o1_showMouse(EMCState *script);
290 int o1_setMousePos(EMCState *script);
291 int o1_setHandItem(EMCState *script);
292 int o1_removeHandItem(EMCState *script);
293 int o1_getMouseState(EMCState *script);
294 int o1_setDeathHandler(EMCState *script);
295 int o1_playWanderScoreViaMap(EMCState *script);
296 int o1_fillRect(EMCState *script);
297 int o1_blockInWalkableRegion(EMCState *script);
298 int o1_blockOutWalkableRegion(EMCState *script);
299 int o1_playSoundEffect(EMCState *script);
300
301 // script debug
302#ifndef RELEASE_BUILD
303 int16 emcSafeReadStack(EMCState *s, int x, int line, const char *file) {
304 if (s->sp+x > EMCState::kStackLastEntry) {
305 //assert(sp+x < kStackSize);
306 warning("Invalid EMC stack read attempt from: '%s', line %d", file, line);
307 return 0;
308 }
309 return s->stack[s->sp+x];
310 }
311#endif
312
313 // items
314 int _mouseState;
315
316 virtual void setHandItem(Item item) = 0;
317 virtual void removeHandItem() = 0;
318
319 // game flags
320 uint8 _flagsTable[100]; // TODO: check this value
321
322 // sound
323 Audio::SoundHandle _speechHandle;
324
325 int _curMusicTheme;
326 int _curSfxFile;
327 int16 _lastMusicCommand;
328
329 const int8 *_trackMap;
330 int _trackMapSize;
331
332 bool _preventScriptSfx;
333
334 virtual int convertVolumeToMixer(int value);
335 virtual int convertVolumeFromMixer(int value);
336
337 // pathfinder
338 virtual int findWay(int x, int y, int toX, int toY, int *moveTable, int moveTableSize);
339 int findSubPath(int x, int y, int toX, int toY, int *moveTable, int start, int end);
340 int getFacingFromPointToPoint(int x, int y, int toX, int toY);
341 int getOppositeFacingDirection(int dir);
342 void changePosTowardsFacing(int &x, int &y, int facing);
343 int getMoveTableSize(int *moveTable);
344 virtual bool lineIsPassable(int x, int y) = 0;
345
346 static const int8 _addXPosTable[];
347 static const int8 _addYPosTable[];
348
349 // Character
350
351 static const int8 _charAddXPosTable[];
352 static const int8 _charAddYPosTable[];
353
354 // save/load
355 int _gameToLoad;
356
357 bool _isSaveAllowed;
358
359 bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return _isSaveAllowed; }
360 bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override { return _isSaveAllowed; }
361 int getAutosaveSlot() const override { return 999; }
362
363 const char *getSavegameFilename(int num);
364 Common::String _savegameFilename;
365 static Common::String getSavegameFilename(const Common::String &target, int num);
366 bool saveFileLoadable(int slot);
367
368 struct SaveHeader {
369 Common::String description;
370 uint32 version;
371 byte gameID;
372 uint32 flags;
373
374 bool originalSave; // savegame from original interpreter
375 bool oldHeader; // old scummvm save header
376
377 Graphics::Surface *thumbnail;
378
379 TimeDate timeDate;
380 uint32 totalPlaySecs;
381 };
382
383 enum ReadSaveHeaderError {
384 kRSHENoError = 0,
385 kRSHEInvalidType = 1,
386 kRSHEInvalidVersion = 2,
387 kRSHEIoError = 3
388 };
389
390 WARN_UNUSED_RESULT static ReadSaveHeaderError readSaveHeader(Common::SeekableReadStream *file, SaveHeader &header, bool skipThumbnail = true);
391
392 void loadGameStateCheck(int slot);
393 Common::Error loadGameState(int slot) override = 0;
394 Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override {
395 return saveGameStateIntern(slot, desc.c_str(), 0);
396 }
397 virtual Common::Error saveGameStateIntern(int slot, const char *saveName, const Graphics::Surface *thumbnail) = 0;
398
399 Common::SeekableReadStream *openSaveForReading(const char *filename, SaveHeader &header, bool checkID = true);
400 Common::OutSaveFile *openSaveForWriting(const char *filename, const char *saveName, const Graphics::Surface *thumbnail) const;
401
402 // TODO: Consider moving this to Screen
403 virtual Graphics::Surface *generateSaveThumbnail() const { return 0; }
404
405 // Officially used in EOB SegaCD (appears in the final stats), but we also use this for the savegame metadata for all games.
406 void updatePlayTimer();
407 void restartPlayTimerAt(uint32 totalPlaySecs);
408 void pausePlayTimer(bool pause);
409
410 uint32 _lastSecTick;
411 uint32 _lastSecTickAtPauseStart;
412 uint32 _totalPlaySecs;
413};
414
415} // End of namespace Kyra
416
417#endif
Definition: mixer.h:49
Definition: input.h:69
Definition: error.h:81
ErrorCode getCode() const
Definition: error.h:112
Definition: list.h:44
Definition: savefile.h:54
Definition: random.h:44
Definition: stream.h:745
Definition: str.h:59
Definition: ustr.h:57
Definition: engine.h:149
EngineFeature
Definition: engine.h:282
Definition: debugger.h:34
Definition: script.h:113
Definition: gui_v1.h:82
Definition: gui.h:98
Definition: kyra_v1.h:126
void syncSoundSettings() override
Common::Error loadGameState(int slot) override=0
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: kyra_v1.h:360
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: kyra_v1.h:359
void pauseEngineIntern(bool pause) override
bool hasFeature(EngineFeature f) const override
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave=false) override
Definition: kyra_v1.h:394
int getAutosaveSlot() const override
Definition: kyra_v1.h:361
Common::Error run() override
Definition: kyra_v1.h:199
Definition: resource.h:48
Definition: screen.h:587
Definition: sound.h:91
Definition: sound_intern.h:59
Definition: resource.h:1250
Definition: text.h:32
Definition: timer.h:48
Definition: system.h:166
Out move(In first, In last, Out dst)
Definition: algorithm.h:109
@ kNoError
No error occurred.
Definition: error.h:48
RenderMode
Definition: rendermode.h:48
void warning(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
bool skipThumbnail(Common::SeekableReadStream &in)
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: detection.h:27
DebugLevels
Definition: kyra_v1.h:95
@ kDebugLevelAnimator
debug level for "ScreenAnimator" functions
Definition: kyra_v1.h:101
@ kDebugLevelSequence
debug level for "SeqPlayer" functions
Definition: kyra_v1.h:104
@ kDebugLevelMovie
debug level for movie specific funtions
Definition: kyra_v1.h:105
@ kDebugLevelScript
debug level for "EMCInterpreter" functions
Definition: kyra_v1.h:97
@ kDebugLevelScreen
debug level for "Screen" functions
Definition: kyra_v1.h:99
@ kDebugLevelMain
debug level for common "KyraEngine(_v#)" functions && "TextDisplayer" functions
Definition: kyra_v1.h:102
@ kDebugLevelGUI
debug level for "KyraEngine*" gui functions
Definition: kyra_v1.h:103
@ kDebugLevelSound
debug level for "Sound" functions
Definition: kyra_v1.h:100
@ kDebugLevelTimer
debug level for "TimerManager" functions
Definition: kyra_v1.h:106
@ kDebugLevelScriptFuncs
debug level for o::_* functions
Definition: kyra_v1.h:96
@ kDebugLevelSprites
debug level for "Sprites" functions
Definition: kyra_v1.h:98
Definition: events.h:218
Definition: rect.h:144
Definition: func.h:43
Definition: surface.h:67
Definition: gui.h:38
Definition: script.h:47
Definition: detection.h:38
Definition: kyra_v1.h:89
Definition: kyra_v1.h:232
Definition: kyra_v1.h:368
Definition: atari-screen.h:58
Definition: system.h:111