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
45namespace Alcachofa {
46
47class IDebugHandler;
48class IRenderer;
49class DrawQueue;
50class World;
51class Script;
52class GlobalUI;
53class Menu;
54class Game;
55struct AlcachofaGameDescription;
56
57constexpr int16 kSmallThumbnailWidth = 160; // for ScummVM
58constexpr int16 kSmallThumbnailHeight = 120;
59// the in-game save thumbnail size is determined by engine verison
60
61namespace SaveVersion {
62 static constexpr const Common::Serializer::Version kInitial = 0;
63 static constexpr const Common::Serializer::Version kWithEngineV10 = 1;
64}
65static constexpr const Common::Serializer::Version kCurrentSaveVersion = SaveVersion::kWithEngineV10;
66
68public:
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
82class Config {
83public:
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
98private:
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
110class AlcachofaEngine : public Engine {
111protected:
112 // Engine APIs
113 Common::Error run() override;
114public:
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 isV20() const { return gameDescription().isVersionBetween(20, 20); }
122 inline bool isV3() const { return gameDescription().isVersionBetween(30, 39); }
123
124 inline const AlcachofaGameDescription &gameDescription() const { return *_gameDescription; }
125 inline IRenderer &renderer() { return *_renderer; }
126 inline DrawQueue &drawQueue() { return *_drawQueue; }
127 inline Camera &camera() { return *_camera; }
128 inline Input &input() { return _input; }
129 inline Sounds &sounds() { return _sounds; }
130 inline Player &player() { return *_player; }
131 inline World &world() { return _world; }
132 inline Script &script() { return *_script; }
133 inline GlobalUI &globalUI() { return *_globalUI; }
134 inline Menu &menu() { return *_menu; }
135 inline Scheduler &scheduler() { return _scheduler; }
136 inline Console &console() { return *_console; }
137 inline Game &game() { return *_game; }
138 inline Config &config() { return _config; }
139 inline bool isDebugModeActive() const { return _debugHandler != nullptr; }
140
141 template<class T> inline T &cameraAs() {
142 auto result = dynamic_cast<T *>(_camera.get());
143 scumm_assert(result != nullptr);
144 return *result;
145 }
146 inline CameraV1 &cameraV1() { return cameraAs<CameraV1>(); }
147 inline CameraV3 &cameraV3() { return cameraAs<CameraV3>(); }
148
149 uint32 getMillis() const;
150 void setMillis(uint32 newMillis);
151 void pauseEngineIntern(bool pause) override;
152 void playVideo(int32 videoId);
153 void fadeExit();
154 void setDebugMode(DebugMode debugMode, int32 param);
155
156 uint32 getFeatures() const;
157 Common::String getGameId() const;
158
159 bool hasFeature(EngineFeature f) const override {
160 return
164 };
165
166 bool isInSpecialGameLoop() const { return !_eventLoopSemaphore.isReleased(); }
167 bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
168 bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override {
169 return canLoadGameStateCurrently(msg);
170 }
171
172 Common::String getSaveStatePattern();
173 Common::Error syncGame(MySerializer &s);
174 Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override {
175 assert(stream != nullptr);
176 MySerializer s(nullptr, stream);
177 return syncGame(s);
178 }
180 assert(stream != nullptr);
181 MySerializer s(stream, nullptr);
182 return syncGame(s);
183 }
184 bool syncThumbnail(MySerializer &s, Graphics::ManagedSurface *thumbnail);
185 void getSavegameThumbnail(Graphics::Surface &thumbnail);
186
187private:
188 bool tryLoadFromLauncher();
189
190 const AlcachofaGameDescription *_gameDescription;
191 Console *_console = new Console();
201 World _world;
202 Input _input;
203 Sounds _sounds;
204 Scheduler _scheduler;
205 Config _config;
206
207 FakeSemaphore _eventLoopSemaphore; // for special states like playVideo and fadeExit
208 uint32 _timeNegOffset = 0, _timePosOffset = 0;
209 uint32 _timeBeforePause = 0;
210};
211
212extern AlcachofaEngine *g_engine;
213#define SHOULD_QUIT ::Alcachofa::g_engine->shouldQuit()
214
215} // End of namespace Alcachofa
216
217#endif // ALCACHOFA_H
Definition: alcachofa.h:110
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: alcachofa.h:168
void pauseEngineIntern(bool pause) override
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
Definition: alcachofa.h:174
bool hasFeature(EngineFeature f) const override
Definition: alcachofa.h:159
Common::Error run() override
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Definition: alcachofa.h:179
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: alcachofa.h:82
Definition: console.h:39
Definition: input.h:33
Definition: alcachofa.h:67
Definition: scheduler.h:193
Definition: sounds.h:34
Definition: rooms.h:176
Definition: error.h:81
Definition: ptr.h:572
Definition: stream.h:745
Definition: serializer.h:80
Definition: str.h:59
Definition: ustr.h:57
Definition: stream.h:77
Definition: engine.h:149
EngineFeature
Definition: engine.h:282
@ kSupportsReturnToLauncher
Definition: engine.h:296
@ kSupportsSavingDuringRuntime
Definition: engine.h:314
@ kSupportsLoadingDuringRuntime
Definition: engine.h:305
Definition: managed_surface.h:51
Definition: system.h:166
Engine * g_engine
Definition: detection.h:45
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: surface.h:67