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 "zvision/core/clock.h"
27 #include "zvision/file/search_manager.h"
28 #include "zvision/detection.h"
29 
30 #include "common/random.h"
31 #include "common/events.h"
32 
33 #include "engines/engine.h"
34 
35 #include "graphics/pixelformat.h"
36 
37 #include "gui/debugger.h"
38 
39 namespace Common {
40 class Keymap;
41 }
42 
43 namespace Video {
44 class VideoDecoder;
45 }
46 
57 namespace ZVision {
58 
59 class Console;
60 class ScriptManager;
61 class RenderManager;
62 class CursorManager;
63 class StringManager;
64 class SaveManager;
65 class RLFDecoder;
66 class MenuHandler;
67 class TextRenderer;
68 class Subtitle;
69 class MidiManager;
70 
71 enum {
72  WINDOW_WIDTH = 640,
73  WINDOW_HEIGHT = 480,
74 
75  HIRES_WINDOW_WIDTH = 800,
76  HIRES_WINDOW_HEIGHT = 600,
77 
78  // Zork Nemesis working window sizes
79  ZNM_WORKING_WINDOW_WIDTH = 512,
80  ZNM_WORKING_WINDOW_HEIGHT = 320,
81 
82  // ZGI working window sizes
83  ZGI_WORKING_WINDOW_WIDTH = 640,
84  ZGI_WORKING_WINDOW_HEIGHT = 344,
85 
86  ROTATION_SCREEN_EDGE_OFFSET = 60,
87  MAX_ROTATION_SPEED = 400, // Pixels per second
88 
89  KEYBUF_SIZE = 20
90 };
91 
92 enum ZVisionAction {
93  kZVisionActionNone,
94  kZVisionActionUp,
95  kZVisionActionDown,
96  kZVisionActionLeft,
97  kZVisionActionRight,
98  kZVisionActionSave,
99  kZVisionActionRestore,
100  kZVisionActionQuit,
101  kZVisionActionPreferences,
102  kZVisionActionShowFPS,
103  kZVisionActionSkipCutscene,
104 
105  kZVisionActionCount
106 };
107 
108 extern const char *mainKeymapId;
109 extern const char *gameKeymapId;
110 extern const char *cutscenesKeymapId;
111 
112 class ZVision : public Engine {
113 public:
114  ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc);
115  ~ZVision() override;
116 
117 public:
124  const Graphics::PixelFormat _resourcePixelFormat;
125  const Graphics::PixelFormat _screenPixelFormat;
126 
127 private:
128  const ZVisionGameDescription *_gameDescription;
129 
130  const int _desiredFrameTime;
131 
132  // We need random numbers
133  Common::RandomSource *_rnd;
134 
135  // Managers
136  ScriptManager *_scriptManager;
137  RenderManager *_renderManager;
138  CursorManager *_cursorManager;
139  StringManager *_stringManager;
140  SearchManager *_searchManager;
141  TextRenderer *_textRenderer;
142  MidiManager *_midiManager;
143  SaveManager *_saveManager;
144  MenuHandler *_menu;
145 
146  // Clock
147  Clock _clock;
148 
149  // Audio ID
150  int _audioId;
151 
152  // To prevent allocation every time we process events
153  Common::Event _event;
154 
155  Common::Keymap *_gameKeymap, *_cutscenesKeymap;
156 
157  int _frameRenderDelay;
158  int _renderedFrameCount;
159  int _fps;
160  int16 _mouseVelocity;
161  int16 _keyboardVelocity;
162  bool _doubleFPS;
163  bool _videoIsPlaying;
164 
165  uint8 _cheatBuffer[KEYBUF_SIZE];
166 
167 public:
168  Common::Error run() override;
169  void pauseEngineIntern(bool pause) override;
170 
171  ZVisionGameId getGameId() const;
172  Common::Language getLanguage() const;
173  uint32 getFeatures() const;
174 
175  ScriptManager *getScriptManager() const {
176  return _scriptManager;
177  }
178  RenderManager *getRenderManager() const {
179  return _renderManager;
180  }
181  CursorManager *getCursorManager() const {
182  return _cursorManager;
183  }
184  SaveManager *getSaveManager() const {
185  return _saveManager;
186  }
187  StringManager *getStringManager() const {
188  return _stringManager;
189  }
190  SearchManager *getSearchManager() const {
191  return _searchManager;
192  }
193  TextRenderer *getTextRenderer() const {
194  return _textRenderer;
195  }
196  MidiManager *getMidiManager() const {
197  return _midiManager;
198  }
199  MenuHandler *getMenuHandler() const {
200  return _menu;
201  }
202 
203  Common::Keymap *getGameKeymap() const {
204  return _gameKeymap;
205  }
206  Common::RandomSource *getRandomSource() const {
207  return _rnd;
208  }
209  int16 getKeyboardVelocity() const {
210  return _keyboardVelocity;
211  }
212  int16 getMouseVelocity() const {
213  return _mouseVelocity;
214  }
215 
216  uint8 getZvisionKey(Common::KeyCode scummKeyCode);
217 
218  void startClock() {
219  _clock.start();
220  }
221 
222  void stopClock() {
223  _clock.stop();
224  }
225 
226  void initScreen();
227  void initHiresScreen();
228 
238  void playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &destRect = Common::Rect(0, 0, 0, 0), bool skippable = true, Subtitle *sub = NULL);
239  Video::VideoDecoder *loadAnimation(const Common::Path &fileName);
240 
241  void setRenderDelay(uint);
242  bool canRender();
243  static void fpsTimerCallback(void *refCon);
244  void fpsTimer();
245  int getFPS() const {
246  return _fps;
247  }
248 
249  void syncSoundSettings() override;
250 
251  void loadSettings();
252  void saveSettings();
253 
254  bool ifQuit();
255 
256  // Engine features
257  bool hasFeature(EngineFeature f) const override;
258  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
259  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
260  Common::Error loadGameState(int slot) override;
261  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
262 
263 private:
264  void initialize();
265  void initFonts();
266 
267  void parseStrFile(const Common::String fileName);
268 
270  void processEvents();
271 
272  void onMouseMove(const Common::Point &pos);
273 
274  void registerDefaultSettings();
275 
276  void cheatCodes(uint8 key);
277  void pushKeyToCheatBuf(uint8 key);
278  bool checkCode(const char *code);
279  uint8 getBufferedKey(uint8 pos);
280 
281  double getVobAmplification(Common::String fileName) const;
282 };
283 
284 } // End of namespace ZVision
285 
286 #endif
Definition: detection.h:39
Definition: keymap.h:66
Definition: str.h:59
EngineFeature
Definition: engine.h:250
Definition: error.h:84
Common::Rect _workingWindow
Definition: zvision.h:123
Definition: clock.h:32
Definition: pixelformat.h:138
Definition: menu.h:42
Definition: random.h:44
Definition: script_manager.h:144
Definition: rect.h:144
Definition: path.h:52
Definition: clock.h:29
Definition: search_manager.h:34
Definition: string_manager.h:35
Definition: subtitles.h:31
Definition: ustr.h:57
Definition: video_decoder.h:52
Definition: events.h:198
Definition: algorithm.h:29
Definition: rect.h:45
Definition: midi.h:29
Definition: cursor_manager.h:58
Definition: save_manager.h:49
Definition: render_manager.h:48
Definition: system.h:167
Definition: avi_frames.h:36
Definition: engine.h:143
Language
Definition: language.h:45
Definition: text.h:73