ScummVM API documentation
alcachofa.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 ALCACHOFA_H
23 #define ALCACHOFA_H
24 
25 #include "common/system.h"
26 #include "common/error.h"
27 #include "common/fs.h"
28 #include "common/hash-str.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 #include "graphics/screen.h"
35 
36 #include "alcachofa/detection.h"
37 #include "alcachofa/camera.h"
38 #include "alcachofa/input.h"
39 #include "alcachofa/sounds.h"
40 #include "alcachofa/player.h"
41 #include "alcachofa/scheduler.h"
42 #include "alcachofa/console.h"
43 #include "alcachofa/game.h"
44 
45 namespace Alcachofa {
46 
47 class IDebugHandler;
48 class IRenderer;
49 class DrawQueue;
50 class World;
51 class Script;
52 class GlobalUI;
53 class Menu;
54 class Game;
55 struct AlcachofaGameDescription;
56 
57 constexpr int16 kSmallThumbnailWidth = 160; // for ScummVM
58 constexpr int16 kSmallThumbnailHeight = 120;
59 // the in-game save thumbnail size is determined by engine verison
60 
61 namespace SaveVersion {
62  static constexpr const Common::Serializer::Version kInitial = 0;
63  static constexpr const Common::Serializer::Version kWithEngineV10 = 1;
64 };
65 static constexpr const Common::Serializer::Version kCurrentSaveVersion = SaveVersion::kWithEngineV10;
66 
68 public:
70 
71  Common::SeekableReadStream &readStream() {
72  assert(isLoading() && _loadStream != nullptr);
73  return *_loadStream;
74  }
75 
76  Common::WriteStream &writeStream() {
77  assert(isSaving() && _saveStream != nullptr);
78  return *_saveStream;
79  }
80 };
81 
82 class Config {
83 public:
84  inline bool &subtitles() { return _subtitles; }
85  inline bool &highQuality() { return _highQuality; }
86  inline bool &bits32() { return _bits32; }
87  inline bool &texFilter() { return _texFilter; }
88  inline uint8 &musicVolume() { return _musicVolume; }
89  inline uint8 &speechVolume() { return _speechVolume; }
90 
91  static void registerDefaults();
92  void loadFromScummVM();
93  void saveToScummVM();
94 
95 private:
96  bool
97  _subtitles = true,
98  _highQuality = true,
99  _bits32 = true,
100  _texFilter = true;
101  uint8
102  _musicVolume = 255,
103  _speechVolume = 255;
104 };
105 
106 class AlcachofaEngine : public Engine {
107 protected:
108  // Engine APIs
109  Common::Error run() override;
110 public:
111  AlcachofaEngine(OSystem *syst, const AlcachofaGameDescription *gameDesc);
112  ~AlcachofaEngine() override;
113 
114  inline EngineVersion version() const { return gameDescription().engineVersion; }
115  inline bool isV1() const { return gameDescription().isVersionBetween(10, 19); }
116  inline bool isV2() const { return gameDescription().isVersionBetween(20, 29); }
117  inline bool isV3() const { return gameDescription().isVersionBetween(30, 39); }
118 
119  inline const AlcachofaGameDescription &gameDescription() const { return *_gameDescription; }
120  inline IRenderer &renderer() { return *_renderer; }
121  inline DrawQueue &drawQueue() { return *_drawQueue; }
122  inline Camera &camera() { return *_camera; }
123  inline Input &input() { return _input; }
124  inline Sounds &sounds() { return _sounds; }
125  inline Player &player() { return *_player; }
126  inline World &world() { return _world; }
127  inline Script &script() { return *_script; }
128  inline GlobalUI &globalUI() { return *_globalUI; }
129  inline Menu &menu() { return *_menu; }
130  inline Scheduler &scheduler() { return _scheduler; }
131  inline Console &console() { return *_console; }
132  inline Game &game() { return *_game; }
133  inline Config &config() { return _config; }
134  inline bool isDebugModeActive() const { return _debugHandler != nullptr; }
135 
136  template<class T> inline T &cameraAs() {
137  auto result = dynamic_cast<T *>(_camera.get());
138  scumm_assert(result != nullptr);
139  return *result;
140  }
141  inline CameraV1 &cameraV1() { return cameraAs<CameraV1>(); }
142  inline CameraV3 &cameraV3() { return cameraAs<CameraV3>(); }
143 
144  uint32 getMillis() const;
145  void setMillis(uint32 newMillis);
146  void pauseEngineIntern(bool pause) override;
147  void playVideo(int32 videoId);
148  void fadeExit();
149  void setDebugMode(DebugMode debugMode, int32 param);
150 
151  uint32 getFeatures() const;
152  Common::String getGameId() const;
153 
154  bool hasFeature(EngineFeature f) const override {
155  return
156  (f == kSupportsLoadingDuringRuntime) ||
157  (f == kSupportsSavingDuringRuntime) ||
158  (f == kSupportsReturnToLauncher);
159  };
160 
161  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
162  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override {
163  return canLoadGameStateCurrently(msg);
164  }
165 
166  Common::String getSaveStatePattern();
167  Common::Error syncGame(MySerializer &s);
168  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override {
169  assert(stream != nullptr);
170  MySerializer s(nullptr, stream);
171  return syncGame(s);
172  }
174  assert(stream != nullptr);
175  MySerializer s(stream, nullptr);
176  return syncGame(s);
177  }
178  bool syncThumbnail(MySerializer &s, Graphics::ManagedSurface *thumbnail);
179  void getSavegameThumbnail(Graphics::Surface &thumbnail);
180 
181 private:
182  bool tryLoadFromLauncher();
183 
184  const AlcachofaGameDescription *_gameDescription;
185  Console *_console = new Console();
186  Common::ScopedPtr<IDebugHandler> _debugHandler;
188  Common::ScopedPtr<DrawQueue> _drawQueue;
191  Common::ScopedPtr<GlobalUI> _globalUI;
195  World _world;
196  Input _input;
197  Sounds _sounds;
198  Scheduler _scheduler;
199  Config _config;
200 
201  FakeSemaphore _eventLoopSemaphore; // for special states like playVideo and fadeExit
202  uint32 _timeNegOffset = 0, _timePosOffset = 0;
203  uint32 _timeBeforePause = 0;
204 };
205 
206 extern AlcachofaEngine *g_engine;
207 #define SHOULD_QUIT ::Alcachofa::g_engine->shouldQuit()
208 
209 } // End of namespace Alcachofa
210 
211 #endif // ALCACHOFA_H
Definition: managed_surface.h:51
Definition: alcachofa.h:45
Definition: str.h:59
Definition: alcachofa.h:67
Definition: surface.h:67
EngineFeature
Definition: engine.h:258
Definition: stream.h:77
Definition: error.h:81
Definition: script.h:154
Definition: alcachofa.h:106
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: alcachofa.h:162
Definition: stream.h:745
Engine * g_engine
Definition: ptr.h:572
Definition: serializer.h:79
Definition: graphics.h:74
Definition: global-ui.h:29
Definition: console.h:39
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
Definition: alcachofa.h:168
Definition: camera.h:106
Definition: ustr.h:57
Definition: player.h:29
Definition: graphics.h:498
Provides functionality specific to a game title / engine version. Also includes all exemptions to inc...
Definition: game.h:47
bool hasFeature(EngineFeature f) const override
Definition: alcachofa.h:154
Definition: sounds.h:34
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Definition: alcachofa.h:173
Definition: camera.h:75
Definition: scheduler.h:193
Definition: menu.h:61
Definition: input.h:33
Definition: system.h:164
This fake semaphore does not work in multi-threaded scenarios It is used as a safer option for a simp...
Definition: common.h:93
Definition: camera.h:38
Definition: rooms.h:171
Definition: engine.h:144
Definition: detection.h:44
Definition: alcachofa.h:82