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/hash-str.h"
30 #include "common/random.h"
31 #include "common/serializer.h"
32 #include "common/util.h"
33 #include "engines/engine.h"
34 #include "engines/savestate.h"
35 #include "graphics/screen.h"
36 
37 #include "m4/detection.h"
38 #include "m4/vars.h"
39 #include "m4/core/rooms.h"
40 #include "m4/subtitles.h"
41 
42 namespace M4 {
43 
44 struct M4GameDescription;
45 
46 class M4Engine : public Engine, public Sections {
47 private:
48  const M4GameDescription *_gameDescription;
49  Common::RandomSource _randomSource;
50  M4Subtitles _subtitles;
51 
55  void m4_inflight();
56 
61  Common::InSaveFile *getOriginalSave(int slot) const;
62 
63 protected:
64  bool _useOriginalSaveLoad = false;
65 
66  // Engine APIs
67  Common::Error run() override;
68 
72  virtual Vars *createVars() = 0;
73 
77  virtual void setupConsole() = 0;
78 
79  void pauseEngineIntern(bool pause) override;
80 
81 public:
82  M4Engine(OSystem *syst, const M4GameDescription *gameDesc);
83  ~M4Engine() override = default;
84 
85  uint32 getFeatures() const;
86 
87  bool useOriginalSaveLoad() const {
88  return _useOriginalSaveLoad;
89  }
90 
94  Common::String getGameId() const;
95 
99  int getGameType() const;
100 
105 
109  int isDemo() const;
110 
114  uint32 getRandomNumber(uint maxNum) {
115  return _randomSource.getRandomNumber(maxNum);
116  }
117 
118  void initializePath(const Common::FSNode &gamePath) override;
119 
120  bool hasFeature(EngineFeature f) const override {
121  return
125  };
126 
127  bool canLoadGameStateCurrently(Common::U32String * msg = nullptr) override;
128  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
129  void syncSoundSettings() override;
130 
131  Common::Error loadGameState(int slot) override;
132  Common::Error loadGameStateDoIt(int slot);
133 
139 
140  virtual void syncFlags(Common::Serializer &s) = 0;
141 
142  Common::Error saveGameStream(Common::WriteStream* stream, bool isAutosave = false) override;
143 
145 
149  bool autosaveExists() const;
150 
154  bool savesExist() const;
155 
159  SaveStateList listSaves() const;
160 
164  bool loadSaveThumbnail(int slotNum, M4sprite *thumbnail) const;
165 
169  bool saveGameFromMenu(int slotNum, const Common::String &desc,
170  Graphics::Surface &thumbnail);
171 
175  virtual void showSaveScreen();
176 
177  enum LoadDialogSource { kLoadFromMainMenu, kLoadFromGameDialog, kLoadFromHotkey };
181  virtual void showLoadScreen(LoadDialogSource fromMainMenu);
182 
186  virtual void showEngineInfo() = 0;
187 
188  void drawSubtitle(const Common::String &soundId) const {
189  _subtitles.drawSubtitle(soundId);
190  }
191 
192  void clearSubtitle() const {
193  _subtitles.clearSubtitle();
194  }
195 
196  void updateSubtitleOverlay() const {
197  _subtitles.updateSubtitleOverlay();
198  }
199 };
200 
201 extern M4Engine *g_engine;
202 #define SHOULD_QUIT ::M4::g_engine->shouldQuit()
203 #define IS_BURGER (g_engine->getGameType() == GType_Burger)
204 #define IS_RIDDLE (g_engine->getGameType() == GType_Riddle)
205 
206 } // End of namespace M4
207 
208 #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:120
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:114
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
bool autosaveExists() const
bool savesExist() const
Definition: system.h:163
Definition: engine.h:290
Definition: rooms.h:87
void syncSoundSettings() override
Definition: m4.h:46
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