ScummVM API documentation
m4.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 M4_H
23 #define M4_H
24 
25 #include "common/scummsys.h"
26 #include "common/system.h"
27 #include "common/error.h"
28 #include "common/fs.h"
29 #include "common/random.h"
30 #include "common/serializer.h"
31 #include "common/util.h"
32 #include "engines/engine.h"
33 #include "engines/savestate.h"
34 
35 #include "m4/detection.h"
36 #include "m4/vars.h"
37 #include "m4/core/rooms.h"
38 #include "m4/subtitles.h"
39 
40 namespace M4 {
41 
42 struct M4GameDescription;
43 
44 class M4Engine : public Engine, public Sections {
45 private:
46  const M4GameDescription *_gameDescription;
47  Common::RandomSource _randomSource;
48  M4Subtitles _subtitles;
49 
53  void m4_inflight();
54 
59  Common::InSaveFile *getOriginalSave(int slot) const;
60 
61 protected:
62  bool _useOriginalSaveLoad = false;
63 
64  // Engine APIs
65  Common::Error run() override;
66 
70  virtual Vars *createVars() = 0;
71 
75  virtual void setupConsole() = 0;
76 
77  void pauseEngineIntern(bool pause) override;
78 
79 public:
80  M4Engine(OSystem *syst, const M4GameDescription *gameDesc);
81  ~M4Engine() override = default;
82 
83  uint32 getFeatures() const;
84 
85  bool useOriginalSaveLoad() const {
86  return _useOriginalSaveLoad;
87  }
88 
92  Common::String getGameId() const;
93 
97  int getGameType() const;
98 
103 
107  int isDemo() const;
108 
112  uint32 getRandomNumber(uint maxNum) {
113  return _randomSource.getRandomNumber(maxNum);
114  }
115 
116  void initializePath(const Common::FSNode &gamePath) override;
117 
118  bool hasFeature(EngineFeature f) const override {
119  return
123  };
124 
125  bool canLoadGameStateCurrently(Common::U32String * msg = nullptr) override;
126  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
127  void syncSoundSettings() override;
128 
129  Common::Error loadGameState(int slot) override;
130  Common::Error loadGameStateDoIt(int slot);
131 
137 
138  virtual void syncFlags(Common::Serializer &s) = 0;
139 
140  Common::Error saveGameStream(Common::WriteStream* stream, bool isAutosave = false) override;
141 
143 
147  bool autosaveExists() const;
148 
152  bool savesExist() const;
153 
157  SaveStateList listSaves() const;
158 
162  bool loadSaveThumbnail(int slotNum, M4sprite *thumbnail) const;
163 
167  bool saveGameFromMenu(int slotNum, const Common::String &desc,
168  Graphics::Surface &thumbnail);
169 
173  virtual void showSaveScreen();
174 
175  enum LoadDialogSource { kLoadFromMainMenu, kLoadFromGameDialog, kLoadFromHotkey };
179  virtual void showLoadScreen(LoadDialogSource fromMainMenu);
180 
184  virtual void showEngineInfo() = 0;
185 
186  void drawSubtitle(const Common::String &soundId) const {
187  _subtitles.drawSubtitle(soundId);
188  }
189 
190  void clearSubtitle() const {
191  _subtitles.clearSubtitle();
192  }
193 
194  void updateSubtitleOverlay() const {
195  _subtitles.updateSubtitleOverlay();
196  }
197 };
198 
199 extern M4Engine *g_engine;
200 #define SHOULD_QUIT ::M4::g_engine->shouldQuit()
201 #define IS_BURGER (g_engine->getGameType() == GType_Burger)
202 #define IS_RIDDLE (g_engine->getGameType() == GType_Riddle)
203 
204 } // End of namespace M4
205 
206 #endif // M4_H
Definition: detection.h:53
Definition: subtitles.h:34
Definition: str.h:59
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
bool saveGameFromMenu(int slotNum, const Common::String &desc, Graphics::Surface &thumbnail)
Definition: surface.h:67
EngineFeature
Definition: engine.h:258
int getGameType() const
Definition: stream.h:77
Definition: vars.h:68
Definition: error.h:81
virtual Vars * createVars()=0
virtual void showSaveScreen()
bool hasFeature(EngineFeature f) const override
Definition: m4.h:118
Common::String getGameId() const
Definition: random.h:44
virtual void setupConsole()=0
Common::Error run() override
int isDemo() const
uint getRandomNumber(uint max)
void initializePath(const Common::FSNode &gamePath) override
Definition: stream.h:745
Common::Error syncGame(Common::Serializer &s)
Definition: serializer.h:79
Definition: engine.h:272
bool loadSaveThumbnail(int slotNum, M4sprite *thumbnail) const
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
Common::Language getLanguage() const
Definition: ustr.h:57
void pauseEngineIntern(bool pause) override
virtual void showLoadScreen(LoadDialogSource fromMainMenu)
virtual void showEngineInfo()=0
Definition: fs.h:69
Definition: database.h:28
Definition: gui.h:31
uint32 getRandomNumber(uint maxNum)
Definition: m4.h:112
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
bool autosaveExists() const
bool savesExist() const
Definition: system.h:164
Definition: engine.h:290
Definition: rooms.h:85
void syncSoundSettings() override
Definition: m4.h:44
Definition: engine.h:144
Common::Error loadGameState(int slot) override
SaveStateList listSaves() const
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Language
Definition: language.h:45