ScummVM API documentation
tinsel.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 TINSEL_TINSEL_H
23 #define TINSEL_TINSEL_H
24 
25 #include "common/scummsys.h"
26 #include "common/system.h"
27 #include "common/error.h"
28 #include "common/events.h"
29 #include "common/keyboard.h"
30 #include "common/random.h"
31 #include "common/util.h"
32 
33 #include "engines/engine.h"
34 #include "gui/debugger.h"
35 
36 #include "tinsel/debugger.h"
37 #include "tinsel/graphics.h"
38 #include "tinsel/sound.h"
39 #include "tinsel/dw.h"
40 #include "tinsel/detection.h"
41 
51 namespace Tinsel {
52 
53 class BMVPlayer;
54 class Config;
55 class MidiDriver;
56 class MidiMusicPlayer;
57 class PCMMusicPlayer;
58 class Music;
59 class SoundManager;
60 class Background;
61 class Font;
62 class Cursor;
63 class Actor;
64 class Handle;
65 class Scroll;
66 class Dialogs;
67 class Notebook;
68 class SystemReel;
69 
70 typedef Common::List<Common::Rect> RectList;
71 
72 enum {
73  kTinselDebugAnimations = 1 << 0,
74  kTinselDebugActions = 1 << 1,
75  kTinselDebugSound = 1 << 2,
76  kTinselDebugMusic = 2 << 3
77 };
78 
79 #define DEBUG_BASIC 1
80 #define DEBUG_INTERMEDIATE 2
81 #define DEBUG_DETAILED 3
82 
83 enum TinselKeyDirection {
84  MSK_LEFT = 1, MSK_RIGHT = 2, MSK_UP = 4, MSK_DOWN = 8,
85  MSK_DIRECTION = MSK_LEFT | MSK_RIGHT | MSK_UP | MSK_DOWN
86 };
87 
88 typedef bool (*KEYFPTR)(const Common::KeyState &);
89 
90 #define SCREEN_WIDTH (_vm->screen().w) // PC screen dimensions
91 #define SCREEN_HEIGHT (_vm->screen().h)
92 #define SCRN_CENTER_X ((SCREEN_WIDTH - 1) / 2) // screen center x
93 #define SCRN_CENTER_Y ((SCREEN_HEIGHT - 1) / 2) // screen center y
94 #define UNUSED_LINES 48
95 #define EXTRA_UNUSED_LINES 3
96 //#define SCREEN_BOX_HEIGHT1 (SCREEN_HEIGHT - UNUSED_LINES)
97 //#define SCREEN_BOX_HEIGHT2 (SCREEN_BOX_HEIGHT1 - EXTRA_UNUSED_LINES)
98 #define SCREEN_BOX_HEIGHT1 SCREEN_HEIGHT
99 #define SCREEN_BOX_HEIGHT2 SCREEN_HEIGHT
100 
101 #define GAME_FRAME_DELAY (1000 / ONE_SECOND)
102 
103 #define TinselVersion (_vm->getVersion())
104 #define TinselV2Demo (TinselVersion == 2 && _vm->getIsADGFDemo())
105 #define TinselV1PSX (TinselVersion == 1 && _vm->getPlatform() == Common::kPlatformPSX)
106 #define TinselV1Mac (TinselVersion == 1 && _vm->getPlatform() == Common::kPlatformMacintosh)
107 #define TinselV1Saturn (TinselVersion == 1 && _vm->getPlatform() == Common::kPlatformSaturn)
108 
109 #define READ_16(v) (TinselV1Mac || TinselV1Saturn ? READ_BE_UINT16(v) : READ_LE_UINT16(v))
110 #define READ_32(v) (TinselV1Mac || TinselV1Saturn ? READ_BE_UINT32(v) : READ_LE_UINT32(v))
111 #define WRITE_32(p, v) (TinselV1Mac || TinselV1Saturn ? WRITE_BE_UINT32(p, v) : WRITE_LE_UINT32(p, v))
112 #define FROM_16(v) (TinselV1Mac || TinselV1Saturn ? FROM_BE_16(v) : FROM_LE_16(v))
113 #define FROM_32(v) (TinselV1Mac || TinselV1Saturn ? FROM_BE_32(v) : FROM_LE_32(v))
114 #define TO_32(v) (TinselV1Mac || TinselV1Saturn ? TO_BE_32(v) : TO_LE_32(v))
115 
116 // Global reference to the TinselEngine object
117 extern TinselEngine *_vm;
118 
119 class TinselEngine : public Engine {
120  int _gameId;
121  Common::KeyState _keyPressed;
122  Common::RandomSource _random;
123  Graphics::Surface _screenSurface;
124  Common::Point _mousePos;
125  uint8 _dosPlayerDir;
126 
127  static const char *const _sampleIndices[][3];
128  static const char *const _sampleFiles[][3];
129  static const char *const _textFiles[][3];
130  static const char *const _sceneFiles[];
131 
132 protected:
133 
134  // Engine APIs
135  void initializePath(const Common::FSNode &gamePath) override;
136  Common::Error run() override;
137  bool hasFeature(EngineFeature f) const override;
138  Common::Error loadGameState(int slot) override;
139 #if 0
140  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false);
141 #endif
142  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
143 #if 0
145 #endif
146 
147 public:
148  TinselEngine(OSystem *syst, const TinselGameDescription *gameDesc);
149  ~TinselEngine() override;
150  int getGameId() {
151  return _gameId;
152  }
153 
154  const TinselGameDescription *_gameDescription;
155  uint32 getGameID() const;
156  uint32 getFeatures() const;
157  Common::Language getLanguage() const;
158  uint16 getVersion() const;
159  Common::Platform getPlatform() const;
160  bool getIsADGFDemo() const;
161  bool isV1CD() const;
162 
163  const char *getSampleIndex(LANGUAGE lang);
164  const char *getSampleFile(LANGUAGE lang);
165  const char *getTextFile(LANGUAGE lang);
166  // Noir
167  const char *getSceneFile(LANGUAGE lang);
168 
169  MidiDriver *_driver;
170  SoundManager *_sound;
171  MidiMusicPlayer *_midiMusic;
172  PCMMusicPlayer *_pcmMusic;
173  Music *_music;
174  BMVPlayer *_bmv;
175  Background* _bg;
176  Font *_font;
177  Cursor *_cursor;
178  Actor *_actor;
179  Handle *_handle;
180  Config *_config;
181  Scroll *_scroll;
182  Dialogs *_dialogs;
183  Notebook *_notebook = nullptr;
184  SystemReel *_systemReel = nullptr;
185 
186  KEYFPTR _keyHandler;
187 
190 
193 
194 
196  RectList _clipRects;
197 
198 private:
199  void NextGameCycle();
200  void CreateConstProcesses();
201  void RestartGame();
202  void RestartDrivers();
203  void ChopDrivers();
204  void ProcessKeyEvent(const Common::Event &event);
205  bool pollEvent();
206 
207 public:
208  const Common::String getTargetName() const { return _targetName; }
209  Common::String getSavegameFilename(int16 saveNum) const;
210  Common::SaveFileManager *getSaveFileMan() { return _saveFileMan; }
211  Graphics::Surface &screen() { return _screenSurface; }
212 
213  Common::Point getMousePosition() const { return _mousePos; }
214  void setMousePosition(Common::Point pt) {
215  // Clip mouse position to be within the screen coordinates
216  pt.x = CLIP<int16>(pt.x, 0, SCREEN_WIDTH - 1);
217  pt.y = CLIP<int16>(pt.y, 0, SCREEN_HEIGHT - 1);
218 
219  int yOffset = (TinselVersion >= 2) ? (g_system->getHeight() - _screenSurface.h) / 2 : 0;
220  g_system->warpMouse(pt.x, pt.y + yOffset);
221  _mousePos = pt;
222  }
223  void divertKeyInput(KEYFPTR fptr) { _keyHandler = fptr; }
224  int getRandomNumber(int maxNumber) { return _random.getRandomNumber(maxNumber); }
225  uint8 getKeyDirection() const { return _dosPlayerDir; }
226 };
227 
228 // Externally available methods
229 void CuttingScene(bool bCutting);
230 void CDChangeForRestore(int cdNumber);
231 void CdHasChanged();
232 
233 } // End of namespace Tinsel
234 
235 #endif /* TINSEL_TINSEL_H */
Definition: bmv.h:48
Definition: str.h:59
Definition: sound.h:47
Definition: surface.h:66
EngineFeature
Definition: engine.h:250
RectList _clipRects
Definition: tinsel.h:196
Definition: error.h:84
Common::Error run() override
int16 h
Definition: surface.h:75
Definition: sysreel.h:51
Definition: random.h:44
Definition: handle.h:42
Definition: music.h:121
uint getRandomNumber(uint max)
Common::List< Common::EventType > _mouseButtons
Definition: tinsel.h:189
Definition: actors.h:92
Definition: background.h:81
Definition: music.h:95
virtual int16 getHeight()=0
OSystem * g_system
Definition: mididrv.h:299
Definition: tinsel.h:119
Definition: cursor.h:40
Definition: scroll.h:51
virtual Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave=false)
Definition: notebook.h:60
Definition: ustr.h:57
Definition: font.h:33
Definition: config.h:37
Definition: events.h:198
Definition: fs.h:69
Definition: actors.h:36
Definition: rect.h:45
Definition: cursor.h:27
bool hasFeature(EngineFeature f) const override
Common::Error loadGameState(int slot) override
const Common::String _targetName
Definition: engine.h:180
Definition: music.h:36
Definition: detection.h:69
Definition: dialogs.h:267
int16 x
Definition: rect.h:46
int16 y
Definition: rect.h:47
Definition: keyboard.h:294
Definition: savefile.h:142
virtual void warpMouse(int x, int y)=0
Definition: system.h:167
void initializePath(const Common::FSNode &gamePath) override
Common::List< Common::Event > _keypresses
Definition: tinsel.h:192
Definition: engine.h:143
Platform
Definition: platform.h:46
Common::SaveFileManager * _saveFileMan
Definition: engine.h:166
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Language
Definition: language.h:45
virtual bool canSaveGameStateCurrently(Common::U32String *msg=nullptr)