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  static constexpr const uint8 kMaxCursor = 3;
85 
86  inline bool &subtitles() { return _subtitles; }
87  inline bool &highQuality() { return _highQuality; }
88  inline bool &bits32() { return _bits32; }
89  inline bool &texFilter() { return _texFilter; }
90  inline uint8 &musicVolume() { return _musicVolume; }
91  inline uint8 &speechVolume() { return _speechVolume; }
92  inline uint8 &cursor() { return _cursor; } // only used in V2
93 
94  static void registerDefaults();
95  void loadFromScummVM();
96  void saveToScummVM();
97 
98 private:
99  bool
100  _subtitles = true,
101  _highQuality = true,
102  _bits32 = true,
103  _texFilter = true;
104  uint8
105  _musicVolume = 255,
106  _speechVolume = 255,
107  _cursor = 0;
108 };
109 
110 class AlcachofaEngine : public Engine {
111 protected:
112  // Engine APIs
113  Common::Error run() override;
114 public:
115  AlcachofaEngine(OSystem *syst, const AlcachofaGameDescription *gameDesc);
116  ~AlcachofaEngine() override;
117 
118  inline EngineVersion version() const { return gameDescription().engineVersion; }
119  inline bool isV1() const { return gameDescription().isVersionBetween(10, 19); }
120  inline bool isV2() const { return gameDescription().isVersionBetween(20, 29); }
121  inline bool isV3() const { return gameDescription().isVersionBetween(30, 39); }
122 
123  inline const AlcachofaGameDescription &gameDescription() const { return *_gameDescription; }
124  inline IRenderer &renderer() { return *_renderer; }
125  inline DrawQueue &drawQueue() { return *_drawQueue; }
126  inline Camera &camera() { return *_camera; }
127  inline Input &input() { return _input; }
128  inline Sounds &sounds() { return _sounds; }
129  inline Player &player() { return *_player; }
130  inline World &world() { return _world; }
131  inline Script &script() { return *_script; }
132  inline GlobalUI &globalUI() { return *_globalUI; }
133  inline Menu &menu() { return *_menu; }
134  inline Scheduler &scheduler() { return _scheduler; }
135  inline Console &console() { return *_console; }
136  inline Game &game() { return *_game; }
137  inline Config &config() { return _config; }
138  inline bool isDebugModeActive() const { return _debugHandler != nullptr; }
139 
140  template<class T> inline T &cameraAs() {
141  auto result = dynamic_cast<T *>(_camera.get());
142  scumm_assert(result != nullptr);
143  return *result;
144  }
145  inline CameraV1 &cameraV1() { return cameraAs<CameraV1>(); }
146  inline CameraV3 &cameraV3() { return cameraAs<CameraV3>(); }
147 
148  uint32 getMillis() const;
149  void setMillis(uint32 newMillis);
150  void pauseEngineIntern(bool pause) override;
151  void playVideo(int32 videoId);
152  void fadeExit();
153  void setDebugMode(DebugMode debugMode, int32 param);
154 
155  uint32 getFeatures() const;
156  Common::String getGameId() const;
157 
158  bool hasFeature(EngineFeature f) const override {
159  return
160  (f == kSupportsLoadingDuringRuntime) ||
161  (f == kSupportsSavingDuringRuntime) ||
162  (f == kSupportsReturnToLauncher);
163  };
164 
165  bool isInSpecialGameLoop() const { return !_eventLoopSemaphore.isReleased(); }
166  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
167  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override {
168  return canLoadGameStateCurrently(msg);
169  }
170 
171  Common::String getSaveStatePattern();
172  Common::Error syncGame(MySerializer &s);
173  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override {
174  assert(stream != nullptr);
175  MySerializer s(nullptr, stream);
176  return syncGame(s);
177  }
179  assert(stream != nullptr);
180  MySerializer s(stream, nullptr);
181  return syncGame(s);
182  }
183  bool syncThumbnail(MySerializer &s, Graphics::ManagedSurface *thumbnail);
184  void getSavegameThumbnail(Graphics::Surface &thumbnail);
185 
186 private:
187  bool tryLoadFromLauncher();
188 
189  const AlcachofaGameDescription *_gameDescription;
190  Console *_console = new Console();
191  Common::ScopedPtr<IDebugHandler> _debugHandler;
193  Common::ScopedPtr<DrawQueue> _drawQueue;
196  Common::ScopedPtr<GlobalUI> _globalUI;
200  World _world;
201  Input _input;
202  Sounds _sounds;
203  Scheduler _scheduler;
204  Config _config;
205 
206  FakeSemaphore _eventLoopSemaphore; // for special states like playVideo and fadeExit
207  uint32 _timeNegOffset = 0, _timePosOffset = 0;
208  uint32 _timeBeforePause = 0;
209 };
210 
211 extern AlcachofaEngine *g_engine;
212 #define SHOULD_QUIT ::Alcachofa::g_engine->shouldQuit()
213 
214 } // End of namespace Alcachofa
215 
216 #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:153
Definition: alcachofa.h:110
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: alcachofa.h:167
Definition: stream.h:745
Engine * g_engine
Definition: ptr.h:572
Definition: serializer.h:80
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:173
Definition: camera.h:120
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:158
Definition: sounds.h:34
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Definition: alcachofa.h:178
Definition: camera.h:76
Definition: scheduler.h:193
Definition: menu.h:73
Definition: input.h:33
Definition: system.h:165
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:176
Definition: engine.h:144
Definition: detection.h:45
Definition: alcachofa.h:82