ScummVM API documentation
mads.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 MADS_ENGINE_H
23#define MADS_ENGINE_H
24
25#include "audio/mixer.h"
26#include "common/events.h"
27#include "common/serializer.h"
28#include "common/stack.h"
29#include "common/random.h"
30#include "common/util.h"
31#include "engines/engine.h"
32#include "mads/detection.h"
33#include "graphics/screen.h"
34#include "mads/core/sound_manager.h"
35#include "mads/core/game.h"
36#include "mads/core/speech.h"
37
38namespace MADS {
39
40#define DEBUG_BASIC 1
41#define DEBUG_INTERMEDIATE 2
42#define DEBUG_DETAILED 3
43
44enum MADSDebugChannels {
45 kDebugPath = 1,
46 kDebugScripts,
47 kDebugGraphics,
48 kDebugConversations
49};
50
51enum MADSActions {
52 kActionNone,
53 kActionEscape,
54 kActionGameMenu,
55 kActionSave,
56 kActionRestore,
57 kActionScrollUp,
58 kActionScrollDown,
59 kActionStartGame,
60 kActionResumeGame,
61 kActionShowIntro,
62 kActionCredits,
63 kActionQuotes,
64 kActionRestartAnimation
65};
66
67typedef void (*TimerFunction)();
68
69class MADSEngine : public Engine {
70private:
71 uint16 _shakeRandom = 0x4D2;
72
73 void initGlobals();
74 void syncGame(Common::Serializer &s);
75 bool isSpecialKey(Common::KeyCode key) const;
76 void updateScreen();
77
78protected:
79 const MADSGameDescription *_gameDescription;
80 Common::RandomSource _randomSource;
81 Graphics::Screen *_screen = nullptr;
83 uint32 _nextFrameTime = 0;
84 Common::Point _mousePos;
85 int _mouseButtons = 0;
86 Audio::SoundHandle _speechHandle;
87 TimerFunction _timerFunction = nullptr;
88 uint32 _nextTimerTime = 0;
89 Graphics::Surface _savegameThumbnail;
90
91 virtual Common::Point screenToGame(const Common::Point &point) const;
92 virtual Common::Point gameToScreen(const Common::Point &point) const;
93 virtual void presentScreen(int shakeOffset);
94
95 virtual bool handleMacEvent(Common::Event &event) { return false; }
96 virtual void serviceMacintoshUI() {}
97 virtual void serviceMacintoshSound() {}
98
99 bool hasFeature(EngineFeature f) const override;
100
101 void pollEvents(bool presentScreen = true);
102 void checkForTimerFunction();
103
104public:
105 MADS::SoundManager *_soundManager = nullptr;
106 bool _musicFlag = true;
107 bool _soundFlag = true;
108 bool &_speechFlag = speech_on;
109
110public:
111 MADSEngine(OSystem *syst, const MADSGameDescription *gameDesc);
112 ~MADSEngine() override;
113 void initializePath(const Common::FSNode &gamePath) override;
114
115 uint32 getFeatures() const;
116 Common::Language getLanguage() const;
117 Common::Platform getPlatform() const;
118 uint16 getVersion() const;
119 uint32 getGameID() const;
120 uint32 getGameFeatures() const;
121 bool isDemo() const;
122 bool isCDROM() const;
123
124 void readConfigFile();
125 int getRandomNumber(int maxNumber);
126 int getRandomNumber(int minNumber, int maxNumber);
127
128 Graphics::Screen *getScreen() const {
129 return _screen;
130 }
131
132 bool hasPendingKey(bool presentScreen = true);
133 int getKey();
134 void flushKeys();
135
136 int getMouseState(int &x, int &y);
137 void warpMouse(int x, int y);
138 void updateDisplay();
139
140 void pauseEngineIntern(bool pause) override;
141
142 const Graphics::Surface &getSavegameThumbnail() const {
143 return _savegameThumbnail;
144 }
145 void setSavegameThumbnail();
146 void clearSavegameThumbnail();
147
151 uint32 getMillis();
152
153 /* Callback routines in game-specific MAIN module */
154 int main_cheating_key(int mykey) const {
155 return mykey;
156 }
157 int main_normal_key(int mykey) const {
158 return mykey;
159 }
160 virtual int main_copy_verify() {
161 return COPY_SUCCEED;
162 }
163
166 return canLoadGameStateCurrently(msg);
167 }
168 Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave) override;
170 virtual void syncRoom(Common::Serializer &s) = 0;
171 SaveStateList listSaves() const;
172
173 virtual void global_init_code() = 0;
174 virtual void section_music(int section_num) = 0;
175 virtual void global_section_constructor() = 0;
176 virtual void global_daemon_code() = 0;
177 virtual void global_pre_parser_code() = 0;
178 virtual void global_parser_code() = 0;
179 virtual void global_error_code() = 0;
180 virtual void global_room_init() = 0;
181 virtual void global_sound_driver() = 0;
182 virtual void global_game_main_loop() {}
183 virtual void global_verb_filter() {}
184
185 int getMessageTextWidth(FontPtr font, const char *text, int spacing) const;
186
187 // Optional Macintosh presentation hooks. Defaults preserve the shared
188 // MADS rendering path used by DOS releases.
189 virtual bool hasInterfaceAnimations() const { return true; }
190 virtual bool drawPopup() { return false; }
191 virtual int editMacintoshPopup(char *, int) { return -1; }
192 virtual void onPopupDestroyed() {}
193 virtual int getMacintoshTextWidth(FontPtr, const char *, int) const {
194 return -1;
195 }
196 virtual bool drawMacintoshText(FontPtr, Buffer *, const char *, int,
197 int, int, int) const { return false; }
198 virtual bool getInterfaceSentenceColor(byte &) const {
199 return false;
200 }
201 virtual bool hasMacintoshInterface() const { return false; }
202 virtual bool setMacintoshPalette(const RGBcolor *, int, int) {
203 return false;
204 }
205 virtual bool getMacintoshPalette(RGBcolor *, int, int) const {
206 return false;
207 }
208
209 virtual void player_keep_walking();
210
211 void playSpeech(Audio::AudioStream *stream);
212 void stopSpeech();
213 bool isSpeechPlaying() const;
214 void syncSoundSettings() override;
215
219 void setTimerFunction(TimerFunction fn) {
220 _timerFunction = fn;
221 }
222};
223
224extern MADSEngine *g_engine;
225
226} // namespace MADS
227
228#endif
Definition: audiostream.h:50
Definition: mixer.h:49
Definition: display_client.h:113
Definition: error.h:81
Definition: fs.h:69
Definition: random.h:44
Definition: stream.h:745
Definition: serializer.h:80
Definition: ustr.h:57
Definition: stream.h:77
Definition: engine.h:149
EngineFeature
Definition: engine.h:282
Definition: screen.h:47
Definition: mads.h:69
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
void initializePath(const Common::FSNode &gamePath) override
bool hasFeature(EngineFeature f) const override
void syncSoundSettings() override
void pauseEngineIntern(bool pause) override
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave) override
bool canSaveGameStateCurrently(Common::U32String *msg) override
Definition: mads.h:165
bool canLoadGameStateCurrently(Common::U32String *msg) override
uint32 getMillis()
void setTimerFunction(TimerFunction fn)
Definition: mads.h:219
Definition: sound_manager.h:105
Definition: system.h:166
Language
Definition: language.h:45
Platform
Definition: platform.h:93
Engine * g_engine
Definition: events.h:218
Definition: rect.h:144
Definition: surface.h:67
Definition: detection.h:42