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 ADGameDescription *gameDesc);
112  ~AlcachofaEngine() override;
113 
114  inline const ADGameDescription &gameDescription() const { return *_gameDescription; }
115  inline IRenderer &renderer() { return *_renderer; }
116  inline DrawQueue &drawQueue() { return *_drawQueue; }
117  inline Camera &camera() { return _camera; }
118  inline Input &input() { return _input; }
119  inline Sounds &sounds() { return _sounds; }
120  inline Player &player() { return *_player; }
121  inline World &world() { return *_world; }
122  inline Script &script() { return *_script; }
123  inline GlobalUI &globalUI() { return *_globalUI; }
124  inline Menu &menu() { return *_menu; }
125  inline Scheduler &scheduler() { return _scheduler; }
126  inline Console &console() { return *_console; }
127  inline Game &game() { return *_game; }
128  inline Config &config() { return _config; }
129  inline bool isDebugModeActive() const { return _debugHandler != nullptr; }
130 
131  uint32 getMillis() const;
132  void setMillis(uint32 newMillis);
133  void pauseEngineIntern(bool pause) override;
134  void playVideo(int32 videoId);
135  void fadeExit();
136  void setDebugMode(DebugMode debugMode, int32 param);
137 
138  uint32 getFeatures() const;
139  Common::String getGameId() const;
140 
141  bool hasFeature(EngineFeature f) const override {
142  return
143  (f == kSupportsLoadingDuringRuntime) ||
144  (f == kSupportsSavingDuringRuntime) ||
145  (f == kSupportsReturnToLauncher);
146  };
147 
148  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
149  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override {
150  return canLoadGameStateCurrently(msg);
151  }
152 
153  Common::String getSaveStatePattern();
154  Common::Error syncGame(MySerializer &s);
155  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override {
156  assert(stream != nullptr);
157  MySerializer s(nullptr, stream);
158  return syncGame(s);
159  }
161  assert(stream != nullptr);
162  MySerializer s(stream, nullptr);
163  return syncGame(s);
164  }
165  bool syncThumbnail(MySerializer &s, Graphics::ManagedSurface *thumbnail);
166  void getSavegameThumbnail(Graphics::Surface &thumbnail);
167 
168 private:
169  bool tryLoadFromLauncher();
170 
171  const ADGameDescription *_gameDescription;
172  Console *_console = new Console();
173  Common::ScopedPtr<IDebugHandler> _debugHandler;
175  Common::ScopedPtr<DrawQueue> _drawQueue;
179  Common::ScopedPtr<GlobalUI> _globalUI;
182  Camera _camera;
183  Input _input;
184  Sounds _sounds;
185  Scheduler _scheduler;
186  Config _config;
187 
188  FakeSemaphore _eventLoopSemaphore; // for special states like playVideo and fadeExit
189  uint32 _timeNegOffset = 0, _timePosOffset = 0;
190  uint32 _timeBeforePause = 0;
191 };
192 
193 extern AlcachofaEngine *g_engine;
194 #define SHOULD_QUIT ::Alcachofa::g_engine->shouldQuit()
195 
196 } // End of namespace Alcachofa
197 
198 #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: advancedDetector.h:164
Definition: script.h:155
Definition: alcachofa.h:106
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: alcachofa.h:149
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:155
Definition: ustr.h:57
Definition: player.h:29
Definition: graphics.h:456
Provides functionality specific to a game title. Also includes all exemptions to inconsistencies in t...
Definition: game.h:44
bool hasFeature(EngineFeature f) const override
Definition: alcachofa.h:141
Definition: sounds.h:34
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Definition: alcachofa.h:160
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:84
Definition: camera.h:37
Definition: rooms.h:153
Definition: engine.h:144
Definition: alcachofa.h:83