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