ScummVM API documentation
zvision.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 
23 #ifndef ZVISION_ZVISION_H
24 #define ZVISION_ZVISION_H
25 
26 #include "common/events.h"
27 #include "common/random.h"
28 #include "common/system.h"
29 #include "engines/engine.h"
30 #include "graphics/pixelformat.h"
31 #include "gui/debugger.h"
32 #include "zvision/detection.h"
33 #include "zvision/core/clock.h"
34 
35 namespace Common {
36 class Keymap;
37 }
38 
39 namespace Video {
40 class VideoDecoder;
41 }
42 
53 namespace ZVision {
54 
55 struct ZvisionGameDescription;
56 
57 class Console;
58 class ScriptManager;
59 class RenderManager;
60 class CursorManager;
61 class StringManager;
62 class FileManager;
63 class SaveManager;
64 class RLFDecoder;
65 class MenuManager;
66 class SubtitleManager;
67 class TextRenderer;
68 class Subtitle;
69 class MidiManager;
70 class VolumeManager;
71 
72 struct ScreenLayout {
73  Common::Rect screenArea; // Original screen resolution
74  Common::Rect menuArea; // Menu display area, relative to original screen
75  Common::Rect workingArea; // Playfield & video playback area, relative to original screen
76  Common::Rect textArea; // Subtitle & message area, relative to original screen
77 };
78 
79 // NB Footage of original DOS Nemesis engine indicates playfield was centrally placed on screen.
80 // Subtitle scripts, however, suggest playfield was higher up, otherwise they run off the bottom of the screen.
81 // This could just be an error in the scripts or an artefact of the original game's development, so we will continue to use as-released central placement.
82 
83 static const ScreenLayout nemesisLayout {
84  Common::Rect(640, 480), // Screen
85  Common::Rect(Common::Point(64, 0), 512, 32), // Menu
86  Common::Rect(Common::Point(64, 80), 512, 320), // Working; aspect ratio 1.6
87  Common::Rect(Common::Point(64, 420), 512, 60) // Text
88 };
89 
90 static const ScreenLayout zgiLayout {
91  Common::Rect(640, 480), // Screen
92  Common::Rect(Common::Point(0, 0), 640, 32), // Menu
93  Common::Rect(Common::Point(0, 68), 640, 344), // Working; aspect ratio 1.86
94  Common::Rect(Common::Point(0, 412), 640, 68) // Text
95 };
96 
97 enum {
98 
99  ROTATION_SCREEN_EDGE_OFFSET = 60,
100  MAX_ROTATION_SPEED = 400, // Pixels per second
101 
102  KEYBUF_SIZE = 20
103 };
104 
105 enum ZVisionAction {
106  kZVisionActionNone,
107  kZVisionActionUp,
108  kZVisionActionDown,
109  kZVisionActionLeft,
110  kZVisionActionRight,
111  kZVisionActionSave,
112  kZVisionActionRestore,
113  kZVisionActionQuit,
114  kZVisionActionPreferences,
115  kZVisionActionShowFPS,
116  kZVisionActionSkipCutscene,
117 
118  kZVisionActionCount
119 };
120 
121 extern const char *mainKeymapId;
122 extern const char *gameKeymapId;
123 extern const char *cutscenesKeymapId;
124 
125 class ZVision : public Engine {
126 public:
127  ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc);
128  ~ZVision() override;
129 
130 public:
131  const Graphics::PixelFormat _resourcePixelFormat;
132  const Graphics::PixelFormat _screenPixelFormat;
133 
134 private:
135  const ZVisionGameDescription *_gameDescription;
136 
137 
138  // We need random numbers
139  Common::RandomSource *_rnd;
140 
141  // Managers
142  ScriptManager *_scriptManager;
143  RenderManager *_renderManager;
144  CursorManager *_cursorManager;
145  StringManager *_stringManager;
146  TextRenderer *_textRenderer;
147  MidiManager *_midiManager;
148  FileManager *_fileManager;
149  SaveManager *_saveManager;
150  MenuManager *_menu;
151  SubtitleManager *_subtitleManager;
152  VolumeManager *_volumeManager;
153 
154  // Clock
155  Clock _clock;
156 
157  // Audio ID
158  int _audioId;
159 
160  // To prevent allocation every time we process events
161  Common::Event _event;
162 
163  Common::Keymap *_gameKeymap, *_cutscenesKeymap;
164 
165  int _frameRenderDelay;
166  int _renderedFrameCount;
167  int _fps;
168  int16 _mouseVelocity;
169  int16 _keyboardVelocity;
170  bool _doubleFPS;
171  bool _widescreen;
172  bool _videoIsPlaying;
173  bool _breakMainLoop = false;
174 
175  uint8 _cheatBuffer[KEYBUF_SIZE];
176 
177 public:
178  Common::Error run() override;
179  void pauseEngineIntern(bool pause) override;
180 
181  ZVisionGameId getGameId() const;
182  Common::Language getLanguage() const;
183  uint32 getFeatures() const;
184 
185  ScriptManager *getScriptManager() const {
186  return _scriptManager;
187  }
188  RenderManager *getRenderManager() const {
189  return _renderManager;
190  }
191  CursorManager *getCursorManager() const {
192  return _cursorManager;
193  }
194  FileManager *getFileManager() const {
195  return _fileManager;
196  }
197  SaveManager *getSaveManager() const {
198  return _saveManager;
199  }
200  StringManager *getStringManager() const {
201  return _stringManager;
202  }
203  TextRenderer *getTextRenderer() const {
204  return _textRenderer;
205  }
206  MidiManager *getMidiManager() const {
207  return _midiManager;
208  }
209  MenuManager *getMenuManager() const {
210  return _menu;
211  }
212  SubtitleManager *getSubtitleManager() const {
213  return _subtitleManager;
214  }
215  VolumeManager *getVolumeManager() const {
216  return _volumeManager;
217  }
218  Common::Keymap *getGameKeymap() const {
219  return _gameKeymap;
220  }
221  Common::RandomSource *getRandomSource() const {
222  return _rnd;
223  }
224  int16 getKeyboardVelocity() const {
225  return _keyboardVelocity;
226  }
227  int16 getMouseVelocity() const {
228  return _mouseVelocity;
229  }
230 
231  uint8 getZvisionKey(Common::KeyCode scummKeyCode);
232 
233  void startClock() {
234  _clock.start();
235  }
236 
237  void stopClock() {
238  _clock.stop();
239  }
240 
241  void initScreen(bool hiRes = false);
242 
253  void playVideo(Video::VideoDecoder &videoDecoder, Common::Rect destRect = Common::Rect(0, 0, 0, 0), bool skippable = true, uint16 sub = 0, Common::Rect srcRect = Common::Rect(0, 0, 0, 0));
254  Video::VideoDecoder *loadAnimation(const Common::Path &fileName);
255 
256  void setRenderDelay(uint);
257  bool canRender();
258  static void fpsTimerCallback(void *refCon);
259  void fpsTimer();
260  int getFPS() const {
261  return _fps;
262  }
263 
264  bool isWidescreen() {
265  return _widescreen;
266  }
267 
268  void syncSoundSettings() override;
269 
270  void loadSettings();
271  void saveSettings();
272 
273  bool quit(bool askFirst = true, bool streaming = false);
274 
275  // Engine features
276  bool hasFeature(EngineFeature f) const override;
277  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
278  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
279  Common::Error loadGameState(int slot) override;
280  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
281 
282  // Used to update cursor on a location change
283  void onMouseMove() {
284  onMouseMove(_system->getEventManager()->getMousePos());
285  }
286 
287 private:
288  void initialize();
289  void initFonts();
290 
291  void initializePath(const Common::FSNode &gamePath) override;
292 
293  void parseStrFile(const Common::String &fileName);
294 
296  void processEvents();
297 
298  void onMouseMove(const Common::Point &pos);
299 
300  void registerDefaultSettings();
301 
302  void cheatCodes(uint8 key);
303  void pushKeyToCheatBuf(uint8 key);
304  bool checkCode(const char *code);
305  uint8 getBufferedKey(uint8 pos);
306 };
307 
308 } // End of namespace ZVision
309 
310 #endif
Definition: detection.h:52
Definition: keymap.h:66
Definition: str.h:59
EngineFeature
Definition: engine.h:260
Definition: error.h:81
Definition: clock.h:32
Definition: pixelformat.h:138
Definition: random.h:44
Definition: script_manager.h:143
Definition: rect.h:524
Definition: path.h:52
Definition: zvision.h:72
Definition: focus_list.h:27
Definition: file_manager.h:31
Definition: string_manager.h:35
Definition: ustr.h:57
Definition: video_decoder.h:53
Definition: events.h:210
Definition: algorithm.h:29
Definition: fs.h:69
Definition: rect.h:144
Definition: midi.h:29
Definition: cursor_manager.h:57
Definition: menu.h:86
Definition: volume_manager.h:41
Definition: save_manager.h:49
Definition: subtitle_manager.h:78
Definition: render_manager.h:48
Definition: system.h:163
Definition: avi_frames.h:36
Definition: engine.h:146
Language
Definition: language.h:45
Definition: text.h:73