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/random.h"
31 #include "common/scummsys.h"
32 #include "common/serializer.h"
33 #include "common/system.h"
34 #include "common/util.h"
35 #include "engines/engine.h"
36 #include "engines/savestate.h"
37 #include "graphics/framelimiter.h"
38 #include "graphics/screen.h"
39 #include "video/video_decoder.h"
40 
41 #include "phoenixvr/angle.h"
42 #include "phoenixvr/detection.h"
43 #include "phoenixvr/region_set.h"
44 #include "phoenixvr/script.h"
45 #include "phoenixvr/vr.h"
46 
47 namespace Graphics {
48 class Font;
49 }
50 
51 namespace PhoenixVR {
52 
53 class ARN;
54 struct PhoenixVRGameDescription;
55 struct GameState;
56 
57 enum struct RolloverType : uint8 {
58  Default,
59  Malette,
60  Secretaire
61 };
62 
63 class PhoenixVREngine : public Engine {
64 private:
65  static constexpr uint kFPSLimit = 60;
66  static constexpr float kMaxTick = 4.0f / kFPSLimit;
67 
68  Graphics::FrameLimiter _frameLimiter;
69  Graphics::Screen *_screen = nullptr;
70  Common::Point _screenCenter;
71  const ADGameDescription *_gameDescription;
72  Common::RandomSource _randomSource;
73  Graphics::PixelFormat _pixelFormat;
74  Graphics::PixelFormat _rgb565;
75  Graphics::ManagedSurface _thumbnail;
77 
78  // Engine APIs
79  Common::Error run() override;
80 
81 public:
82  PhoenixVREngine(OSystem *syst, const ADGameDescription *gameDesc);
83  ~PhoenixVREngine() override;
84 
85  uint32 getFeatures() const;
86 
87  bool gameIdMatches(const char *gameId) const;
88 
92  uint32 getRandomNumber(uint maxNum) {
93  return _randomSource.getRandomNumber(maxNum);
94  }
95 
96  bool hasFeature(EngineFeature f) const override {
97  return (f == kSupportsLoadingDuringRuntime) ||
98  (f == kSupportsSavingDuringRuntime) ||
99  (f == kSupportsReturnToLauncher);
100  };
101 
102  // disable autosave
103  int getAutosaveSlot() const override { return -1; }
104 
105  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override {
106  return true;
107  }
108  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override {
109  return false;
110  }
111 
112  void syncSoundSettings() override;
113 
114  // Script API
115  void setNextScript(const Common::String &path);
116  bool goToWarp(const Common::String &warp, bool savePrev = false);
117  void returnToWarp();
118  void setCursorDefault(int idx, const Common::String &path);
119  void setCursor(const Common::String &path, const Common::String &warp, int idx);
120  void hideCursor(const Common::String &warp, int idx);
121 
122  void playSound(const Common::String &sound, Audio::Mixer::SoundType type, uint8 volume, int loops, bool spatial = false, float angle = 0);
123  void stopSound(const Common::String &sound);
124  void stopAllSounds();
125  void playMovie(const Common::String &movie);
126 
127  void declareVariable(const Common::String &name);
128  void setVariable(const Common::String &name, int value);
129  int getVariable(const Common::String &name) const;
130 
131  void executeTest(int idx);
132  void scheduleTest(int idx);
133  void end();
134  void wait(float seconds);
135  void until(const Common::String &var, int value);
136 
137  const Region *getRegion(int idx) const;
138 
139  void resetLockKey();
140  void lockKey(int idx, const Common::String &warp);
141  void startTimer(float seconds);
142  void pauseTimer(bool pause, bool deactivate);
143  void killTimer();
144  void playAnimation(const Common::String &name, const Common::String &var, int varValue, float speed);
145  void stopAnimation(const Common::String &name);
146  void setZoom(float fov) {
147  _fov = fov;
148  }
149  void interpolateAngle(float x, float y, float speed, float zoom);
150  void fade(int start, int stop, int speed);
151 
152  void setXMax(float max) {
153  _angleY.setRange(-max, max);
154  }
155 
156  // this is set to large values and effectively useless
157  void setYMax(float min, float max) {
158  _angleX.setRange(min, max);
159  }
160 
161  void resetYMax() {
162  _angleX.resetRange();
163  }
164 
165  void setAngle(float x, float y) {
166  _angleX.set(y);
167  _angleY.set(kPi2 - x);
168  }
169 
170  void setNord(float a) {
171  _angleX.add(a);
172  }
173 
174  bool testSaveSlot(int idx) const;
175  Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
176  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
177  void drawSlot(int idx, int face, int x, int y);
178  void captureContext();
179 
180  void setContextLabel(const Common::String &contextLabel) {
181  _contextLabel = contextLabel;
182  }
183  bool enterScript();
184  bool isLoading() const { return !_loadedState.empty(); }
185 
186  bool wasRestarted() const { return _restarted; }
187  bool wasLoaded() const { return _loaded; }
188 
189  void saveVariables();
190  void loadVariables();
191 
192  void rollover(int textId, RolloverType type);
193  void showWaves();
194  void restart();
195  bool setNextLevel();
196 
197  void setGlobalVolume(int vol);
198 
199 private:
200  static Common::String removeDrive(const Common::String &path);
201  Common::SeekableReadStream *open(const Common::String &name, Common::String *origName = nullptr);
202  Common::SeekableReadStream *tryOpen(const Common::Path &name, Common::String *origName);
203 
204  Graphics::Surface *loadSurface(const Common::String &path);
205  Graphics::Surface *loadCursor(const Common::String &path);
206  void paint(Graphics::Surface &src, Common::Point dst);
207  PointF currentVRPos() const {
208  return RectF::transform(_angleX.angle(), _angleY.angle(), _fov);
209  }
210  void tick(float dt);
211  void tickTimer(float dt);
212  void loadNextScript();
213  void renderVR(float dt);
214  void renderTimer();
215  void renderFade(int color);
216  void resetState();
217  const Graphics::Font *getFont(int size, bool bold) const;
218 
219 private:
220  bool _hasFocus = true;
221  Common::Point _mousePos, _mouseRel;
222  Common::String _nextScript;
223  Common::Path _currentScriptPath;
224  int _warpIdx = -1;
225  Script::ConstWarpPtr _warp;
226  int _nextWarp = -1;
227  int _prevWarp = -1;
228  int _hoverIndex = -1;
229  int _nextTest = -1;
230 
231  struct KeyCodeHash : public Common::UnaryFunction<Common::KeyCode, uint> {
232  uint operator()(Common::KeyCode val) const { return static_cast<uint>(val); }
233  };
234 
236  Common::Array<Common::String> _variableOrder;
237  Common::Array<int> _variableSnapshot;
239  struct Sound {
240  Audio::SoundHandle handle;
241  bool spatial;
242  float angle;
243  uint8 volume;
244  int loops;
245  };
248 
250 
252 
254  Common::String _defaultCursor[2];
255  Common::String _currentMusic;
256  int _currentMusicVolume = 0;
257 
258  VR _vr;
259  float _fov;
260  AngleX _angleX;
261  AngleY _angleY;
262  Audio::Mixer *_mixer;
263  bool _showRegions = false;
264 
265  static constexpr byte kPaused = 2;
266  static constexpr byte kActive = 4;
267  byte _timerFlags = 0;
268  float _timer = 0, _initialTimer = 0;
269 
270  Common::String _contextScript;
271  Common::String _contextLabel;
272  Common::Array<byte> _capturedState;
273  Common::Array<byte> _loadedState;
274 
276 
280 
282  Common::Rect _textRect;
283 
285  uint _currentLevel = 0;
286 
287  bool _restarted = false;
288  bool _loaded = false;
289 };
290 
291 extern PhoenixVREngine *g_engine;
292 #define SHOULD_QUIT ::PhoenixVR::g_engine->shouldQuit()
293 
294 } // End of namespace PhoenixVR
295 
296 #endif // PHOENIXVR_H
Definition: managed_surface.h:51
bool hasFeature(EngineFeature f) const override
Definition: phoenixvr.h:96
Definition: framelimiter.h:40
Definition: str.h:59
Definition: font.h:83
Definition: surface.h:67
EngineFeature
Definition: engine.h:258
Definition: stream.h:77
Definition: error.h:81
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: phoenixvr.h:105
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: phoenixvr.h:108
Definition: pixelformat.h:138
Definition: advancedDetector.h:164
Definition: random.h:44
Definition: angle.h:114
Definition: phoenixvr.h:63
Definition: rect.h:524
Definition: path.h:52
uint getRandomNumber(uint max)
Definition: stream.h:745
Definition: screen.h:47
Engine * g_engine
Definition: ptr.h:572
Definition: region_set.h:34
Definition: mixer.h:49
SoundType
Definition: mixer.h:73
Definition: mixer.h:70
Definition: angle.h:110
uint32 getRandomNumber(uint maxNum)
Definition: phoenixvr.h:92
Definition: angle.h:33
Definition: ustr.h:57
Definition: formatinfo.h:28
Definition: rect.h:144
Definition: vr.h:37
int getAutosaveSlot() const override
Definition: phoenixvr.h:103
Definition: system.h:164
Definition: engine.h:144
Definition: func.h:43