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 static constexpr int16 kBigThumbnailWidth = 341; // for in-game
60 static constexpr int16 kBigThumbnailHeight = 256;
61 
62 
63 enum class SaveVersion : Common::Serializer::Version {
64  Initial = 0
65 };
66 static constexpr SaveVersion kCurrentSaveVersion = SaveVersion::Initial;
67 
69 public:
71 
72  Common::SeekableReadStream &readStream() {
73  assert(isLoading() && _loadStream != nullptr);
74  return *_loadStream;
75  }
76 
77  Common::WriteStream &writeStream() {
78  assert(isSaving() && _saveStream != nullptr);
79  return *_saveStream;
80  }
81 };
82 
83 class Config {
84 public:
85  Config();
86 
87  inline bool &subtitles() { return _subtitles; }
88  inline bool &highQuality() { return _highQuality; }
89  inline bool &bits32() { return _bits32; }
90  inline uint8 &musicVolume() { return _musicVolume; }
91  inline uint8 &speechVolume() { return _speechVolume; }
92 
93  void loadFromScummVM();
94  void saveToScummVM();
95 
96 private:
97  bool
98  _subtitles = true,
99  _highQuality = true,
100  _bits32 = 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  uint32 getMillis() const;
137  void setMillis(uint32 newMillis);
138  void pauseEngineIntern(bool pause) override;
139  void playVideo(int32 videoId);
140  void fadeExit();
141  void setDebugMode(DebugMode debugMode, int32 param);
142 
143  uint32 getFeatures() const;
144  Common::String getGameId() const;
145 
146  bool hasFeature(EngineFeature f) const override {
147  return
148  (f == kSupportsLoadingDuringRuntime) ||
149  (f == kSupportsSavingDuringRuntime) ||
150  (f == kSupportsReturnToLauncher);
151  };
152 
153  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
154  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override {
155  return canLoadGameStateCurrently(msg);
156  }
157 
158  Common::String getSaveStatePattern();
159  Common::Error syncGame(MySerializer &s);
160  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override {
161  assert(stream != nullptr);
162  MySerializer s(nullptr, stream);
163  return syncGame(s);
164  }
166  assert(stream != nullptr);
167  MySerializer s(stream, nullptr);
168  return syncGame(s);
169  }
170  bool syncThumbnail(MySerializer &s, Graphics::ManagedSurface *thumbnail);
171  void getSavegameThumbnail(Graphics::Surface &thumbnail);
172 
173 private:
174  bool tryLoadFromLauncher();
175 
176  const AlcachofaGameDescription *_gameDescription;
177  Console *_console = new Console();
178  Common::ScopedPtr<IDebugHandler> _debugHandler;
180  Common::ScopedPtr<DrawQueue> _drawQueue;
184  Common::ScopedPtr<GlobalUI> _globalUI;
187  Camera _camera;
188  Input _input;
189  Sounds _sounds;
190  Scheduler _scheduler;
191  Config _config;
192 
193  FakeSemaphore _eventLoopSemaphore; // for special states like playVideo and fadeExit
194  uint32 _timeNegOffset = 0, _timePosOffset = 0;
195  uint32 _timeBeforePause = 0;
196 };
197 
198 extern AlcachofaEngine *g_engine;
199 #define SHOULD_QUIT ::Alcachofa::g_engine->shouldQuit()
200 
201 } // End of namespace Alcachofa
202 
203 #endif // ALCACHOFA_H
Definition: managed_surface.h:51
Definition: alcachofa.h:45
Definition: str.h:59
Definition: alcachofa.h:68
Definition: surface.h:67
EngineFeature
Definition: engine.h:258
Definition: stream.h:77
Definition: error.h:81
Definition: script.h:153
Definition: alcachofa.h:106
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: alcachofa.h:154
Definition: stream.h:745
Engine * g_engine
Definition: ptr.h:572
Definition: serializer.h:79
Definition: graphics.h:74
Definition: global-ui.h:32
Definition: console.h:39
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
Definition: alcachofa.h:160
Definition: ustr.h:57
Definition: player.h:29
Definition: graphics.h:458
Provides functionality specific to a game title. Also includes all exemptions to inconsistencies in t...
Definition: game.h:46
bool hasFeature(EngineFeature f) const override
Definition: alcachofa.h:146
Definition: sounds.h:34
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Definition: alcachofa.h:165
Definition: scheduler.h:190
Definition: menu.h:59
Definition: input.h:30
Definition: system.h:163
This fake semaphore does not work in multi-threaded scenarios It is used as a safer option for a simp...
Definition: common.h:85
Definition: camera.h:37
Definition: rooms.h:153
Definition: engine.h:144
Definition: detection.h:44
Definition: alcachofa.h:83