ScummVM API documentation
phoenixvr.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 PHOENIXVR_H
23#define PHOENIXVR_H
24
25#include "audio/mixer.h"
26#include "common/error.h"
27#include "common/fs.h"
28#include "common/hash-str.h"
29#include "common/keyboard.h"
30#include "common/ptr.h"
31#include "common/random.h"
32#include "common/scummsys.h"
33#include "common/serializer.h"
34#include "common/system.h"
35#include "common/util.h"
36#include "engines/engine.h"
37#include "engines/savestate.h"
38#include "graphics/framelimiter.h"
39#include "graphics/screen.h"
40#include "video/video_decoder.h"
41
42#include "phoenixvr/angle.h"
43#include "phoenixvr/detection.h"
44#include "phoenixvr/region_set.h"
45#include "phoenixvr/script.h"
46#include "phoenixvr/variables.h"
47#include "phoenixvr/vr.h"
48
49namespace Common {
50struct Event;
51}
52
53namespace Graphics {
54class Font;
55}
56
57namespace PhoenixVR {
58
59class ARN;
60class Subtitles;
61struct PhoenixVRGameDescription;
62struct GameState;
63
64enum struct RolloverType : uint8 {
65 Default,
66 Malette,
67 Secretaire
68};
69
70class PhoenixVREngine : public Engine {
71 friend class ARN;
72
73private:
74 static constexpr uint kFPSLimit = 60;
75 static constexpr float kMaxTick = 4.0f / kFPSLimit;
76
77 Graphics::FrameLimiter _frameLimiter;
78 Graphics::Screen *_screen = nullptr;
79 Common::Point _screenCenter;
80 const ADGameDescription *_gameDescription;
81 Common::RandomSource _randomSource;
82 Graphics::PixelFormat _pixelFormat;
84 Graphics::ManagedSurface _thumbnail;
86
87 // Engine APIs
88 Common::Error run() override;
89
90public:
91 PhoenixVREngine(OSystem *syst, const ADGameDescription *gameDesc);
92 ~PhoenixVREngine() override;
93
94 uint32 getFeatures() const;
95
96 int version() const;
97
98 bool gameIdMatches(const char *gameId) const;
99
103 uint32 getRandomNumber(uint maxNum) {
104 return _randomSource.getRandomNumber(maxNum);
105 }
106
107 bool hasFeature(EngineFeature f) const override {
108 return (f == kSupportsLoadingDuringRuntime) ||
112 };
113
114 // disable autosave
115 int getAutosaveSlot() const override { return -1; }
116
117 bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override {
118 return true;
119 }
120 bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override {
121 return false;
122 }
123
124 void syncSoundSettings() override;
125
126 // Script API
127 void setNextScript(const Common::String &path);
128 bool goToWarp(const Common::String &warp, bool savePrev = false);
129 void goToLevel(const Common::String &name);
130 void returnToWarp();
131 void loadCursor(int idx, const Common::String &path, int offsetX, int offsetY);
132 void setCursorDefault(int idx, const Common::String &path);
133 void setCursorDefault(int idx, int cursorIdx);
134 void setCursor(const Common::String &path, const Common::String &warp, int idx);
135 void hideCursor(const Common::String &warp, int idx);
136
137 void playSound(const Common::String &sound, Audio::Mixer::SoundType type, uint8 volume, int loops, bool spatial = false, float angle = 0);
138 void playRandomSound(const Common::String &sound, Audio::Mixer::SoundType type, uint8 volume, int probability, int loops);
139 void stopSound(const Common::String &sound);
140 void stopAllSounds();
141 void playMovie(const Common::String &movie);
142
143 void declareVariable(const Common::String &name);
144 bool hasVariable(const Common::String &name) const;
145 void setVariable(const Common::String &name, int value);
146 int getVariable(const Common::String &name) const;
147
148 void executeTest(int idx);
149 void scheduleTest(int idx);
150 void end();
151 void wait(float seconds);
152 void until(const Common::String &var, int value);
153
154 const Region *getRegion(int idx) const;
155
156 void resetLockKey();
157 void lockKey(int idx, const Common::String &warp);
158 void startTimer(float seconds, bool showTimer);
159 void startTimer(float seconds, bool showTimer, const Common::String &warp);
160 void pauseTimer(bool pause, bool deactivate);
161 void killTimer();
162 void playAnimation(const Common::String &name, const Common::String &var, int varValue, float speed);
163 void stopAnimation(const Common::String &name);
164 void setZoom(float fov) {
165 _fov = fov;
166 }
167 void interpolateAngle(float x, float y, float speed, float zoom);
168 void fade(int start, int stop, int speed);
169 void transFade(int speed);
170
171 void setXMax(float max) {
172 _angleY.setRange(-max, max);
173 }
174 void limitView(float min, float max) {
175 _angleY.setRange(kPi2 - max, kPi2 - min);
176 }
177
178 // this is set to large values and effectively useless
179 void setYMax(float min, float max) {
180 _angleX.setRange(min, max);
181 }
182
183 void resetYMax() {
184 _angleX.resetRange();
185 }
186
187 void setAngle(float x, float y) {
188 _angleX.set(y);
189 _angleY.set(kPi2 - x);
190 }
191
192 void setNord(float a) {
193 _angleX.add(a);
194 }
195
196 bool testSaveSlot(int idx) const;
198 Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
199 void drawSlot(int idx, int face, int x, int y);
200 void drawSaveCard(int idx);
201 void loadSaveCardSprite(int idx, const Common::String &name);
202 void captureContext();
203
204 void setContextLabel(const Common::String &contextLabel) {
205 _contextLabel = contextLabel;
206 }
207 bool enterScript();
208 bool isLoading() const { return !_loadedState.empty(); }
209
210 bool wasRestarted() const { return _restarted; }
211 bool wasLoaded() const { return _loaded; }
212 uint currentLevel() const;
213
214 void saveVariables();
215 void loadVariables();
216
217 void rollover(int textId, RolloverType type);
218 void clearText();
219 void showWaves();
220 void restart();
221 bool setNextLevel();
222
223 void setGlobalVolume(int vol);
224 void setGlobalPan(int pan);
225 void drawArchiveImage(const Common::String &image, int x, int y);
226 void drawArchiveText(int textId, const Common::Rect &dstRect, int size, bool bold, uint16 color);
227 void clearArchiveText(const Common::Rect &dstRect);
228 void showImageOverlay(const Common::String &image, int x, int y);
229 void stopImageOverlay();
230 void updateStage();
231 void startCible(const Common::String &name, int periodSeconds, const Common::Array<int> &bounds);
232 void stopCible();
233 void testCible(const Common::String &insideVar, const Common::String &outsideVar);
234
235 int retrieveState(int index) const;
236 void storeState(int index, int value);
237
238 void spriteLoad(const Common::String &name, const Common::String &path);
239 void spriteScreen(int index, const Common::String &name, int x, int y);
240 void setLens(int index, const Common::String &name, float size);
241 void resetLensflare();
242 void setLensflare(float x, float y);
243 void startLight(const Common::String &path);
244 void stopLight();
245
246private:
247 struct ArchiveImage {
248 Common::String image;
249 Common::Point pos;
250 };
251
252 struct TextState {
253 TextState() : textId(-1), size(0), bold(false), color(0) {}
254 TextState(int textId_, const Common::Rect &rect_, int size_, bool bold_, uint16 color_) : textId(textId_), rect(rect_), size(size_), bold(bold_), color(color_) {}
255
256 int textId;
257 Common::Rect rect;
258 int size;
259 bool bold;
260 uint16 color;
261 };
262
263 struct Level {
264 Common::String path;
265 Common::String name;
266 };
267
268 struct CachedCursor {
270 Common::Point offset;
271 };
272
273 static Common::String removeDrive(const Common::String &path);
274 Common::SeekableReadStream *open(const Common::String &name, Common::String *origName = nullptr);
275 Common::SeekableReadStream *tryOpen(const Common::Path &name, Common::String *origName);
276
277 Graphics::ManagedSurface *loadSurface(const Common::String &path);
278 CachedCursor *loadCursor(const Common::String &path, int offsetX = -1, int offsetY = -1);
279 PointF currentVRPos() const {
280 return RectF::transform(_angleX.angle(), _angleY.angle(), _fov);
281 }
282 void tick(float dt);
283 void tickTimer(float dt);
284 void loadNextScript();
285 const Graphics::Surface *findArchiveImage(const Common::String &image) const;
286 void renderVR(float dt);
287 void renderArchiveImages();
288 void renderArchiveTexts();
289 void paintText(const TextState &textState);
290 void renderImageOverlay();
291 void renderTimer();
292 void renderFade(int color);
293 void renderSprites();
294 void renderLensflare();
295 void renderLightEffect();
296 void resetState();
297 const Graphics::Font *getFont(int size, bool bold) const;
298 Common::Path getSubtitlePath(const Common::String &path) const;
299 Common::SharedPtr<Subtitles> loadSubtitles(const Common::String &path) const;
300 void setupSubtitles(Subtitles &subtitles) const;
301 void drawAudioSubtitles();
302
303 void processGenericEvents(const Common::Event &event);
304 void pauseEngineIntern(bool pause) override;
305 Common::String getLevelLabel(const Common::String &script) const;
306 Common::String getLevelScript(const Level &level) const;
307 void saveThumbnail();
308
309private:
310 bool _hasFocus = true;
311 Common::Point _mousePos, _mouseRel;
312 Common::String _nextScript;
313 Common::Path _currentScriptPath;
314 int _warpIdx = -1;
315 int _vrWarpIdx = -1; // temporary v2 hack
316 Script::ConstWarpPtr _warp;
317 int _nextWarp = -1;
318 int _prevWarp = -1;
319 Common::List<int> _prevWarpHistory; // V2 stack of warps
320 int _hoverIndex = -1;
321 int _hoverLeaveIndex = -1;
322 int _messengerInventoryHover = -1;
323 int _nextTest = -1;
324
325 struct KeyCodeHash : public Common::UnaryFunction<Common::KeyCode, uint> {
326 uint operator()(Common::KeyCode val) const { return static_cast<uint>(val); }
327 };
328
330
331 Variables _variables;
332 Common::Array<int> _state;
333
334 struct Sound {
335 Audio::SoundHandle handle;
336 bool spatial;
337 float angle;
338 uint8 volume;
339 int loops;
341 };
343
344 struct RandomSound {
345 Common::String sound;
347 int volume;
348 int probability;
349 int loops;
350 };
351 Common::Array<RandomSound> _randomSounds;
352
354
356
357 struct PreloadedCursor {
358 Common::String path;
359 };
360 Common::Array<PreloadedCursor> _loadedCursors;
361
364 struct Sprite {
365 Common::String name;
366 int x = 0;
367 int y = 0;
368 };
369 Common::Array<Sprite> _sprites;
370 struct Lens {
371 Common::String name;
372 float scale = 0.0f;
373 };
374 Common::Array<Lens> _lenses;
375 bool _lensflareActive = false;
376 float _lensflareX = 0.0f;
377 float _lensflareY = 0.0f;
378 Common::Array<uint32> _lightEffect;
379
380 struct WarpCursorState {
381 Common::String name;
382 bool hidden = false;
383 };
385 Common::String _defaultCursor[2];
386 Common::String _currentMusic;
387 int _currentMusicVolume = 0;
388 int _globalPan = 128;
389
390 VR _vr;
391 float _fov;
392 AngleX _angleX;
393 AngleY _angleY;
394 Audio::Mixer *_mixer;
395 bool _showRegions = false;
396
397 static constexpr byte kPaused = 2;
398 static constexpr byte kActive = 4;
399 byte _timerFlags = 0;
400 bool _showTimer = false;
401 float _timer = 0, _initialTimer = 0;
402 Common::String _timerWarp;
403
404 Common::String _contextScript;
405 Common::String _contextLabel;
406 Common::Array<byte> _capturedState;
407 Common::Array<byte> _loadedState;
408
410
411 static const int kFontSizeCount = 6;
412 Common::ScopedPtr<Graphics::Font> _regularFonts[kFontSizeCount];
413 Common::ScopedPtr<Graphics::Font> _boldFonts[kFontSizeCount];
414
415 TextState _rolloverText;
417 Common::Point _imageOverlayPos;
418 Common::Array<ArchiveImage> _archiveImages;
419 Common::Array<TextState> _archiveTexts;
420 bool _cibleActive = false;
421 uint32 _cibleStartMillis = 0;
422 int _ciblePeriodSeconds = 0;
423 Common::Array<int> _cibleBounds;
424
425 Common::Array<Level> _levels;
426 uint _nextLevel = 0;
427
428 bool _restarted = false;
429 bool _loaded = false;
430
431 Video::VideoDecoder *_currentDecoder = nullptr;
432};
433
434extern PhoenixVREngine *g_engine;
435#define SHOULD_QUIT ::PhoenixVR::g_engine->shouldQuit()
436
437} // End of namespace PhoenixVR
438
439#endif // PHOENIXVR_H
Definition: mixer.h:70
SoundType
Definition: mixer.h:73
Definition: mixer.h:49
bool empty() const
Definition: array.h:352
Definition: error.h:81
Definition: path.h:52
Definition: random.h:44
uint getRandomNumber(uint max)
Definition: ptr.h:572
Definition: stream.h:745
Definition: ptr.h:159
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
@ kSupportsSubtitleOptions
Definition: engine.h:287
Definition: font.h:83
Definition: framelimiter.h:40
Definition: managed_surface.h:51
Definition: screen.h:47
Definition: system.h:166
Definition: arn.h:32
Definition: phoenixvr.h:70
int getAutosaveSlot() const override
Definition: phoenixvr.h:115
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: phoenixvr.h:120
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: phoenixvr.h:117
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
uint32 getRandomNumber(uint maxNum)
Definition: phoenixvr.h:103
bool hasFeature(EngineFeature f) const override
Definition: phoenixvr.h:107
void syncSoundSettings() override
Definition: video_decoder.h:53
Engine * g_engine
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: advancedDetector.h:164
Definition: events.h:218
Definition: hash-str.h:45
Definition: hash-str.h:49
Definition: rect.h:144
Definition: rect.h:536
Definition: func.h:43
Definition: pixelformat.h:138
Definition: surface.h:67
Definition: region_set.h:34