ScummVM API documentation
bcb.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 BCB_H
23#define BCB_H
24
25#include "audio/mixer.h"
26#include "common/archive.h"
27#include "common/array.h"
28#include "common/events.h"
29#include "common/fs.h"
30#include "common/rect.h"
31#include "common/str-enc.h"
32#include "common/ustr.h"
33#include "engines/engine.h"
34#include "harold/bcb/ui.h"
35#include "harold/detection.h"
36
37namespace Graphics {
38class Font;
39class FontSJIS;
40class Screen;
41struct Surface;
42} // namespace Graphics
43
44namespace Video {
45class AVIDecoder;
46}
47
48namespace BCB {
49
50enum {
51 kBCBDebugGeneral = 1
52};
53
54enum BCBAction {
55 kBCBActionInteract,
56 kBCBActionEscape,
57 kBCBActionSkip,
58 kBCBActionChoice1,
59 kBCBActionChoice2,
60 kBCBActionChoice3,
61 kBCBActionChoice4,
62 kBCBActionChoice5,
63 kBCBActionChoice6,
64 kBCBActionChoice7,
65 kBCBActionChoice8,
66 kBCBActionChoice9
67};
68
69class Debugger;
70
71class BCBEngine : public Engine {
72 friend class Debugger;
73
74public:
75 BCBEngine(OSystem *syst, const HaroldGameDescription *desc);
76 ~BCBEngine();
77
78 Common::Error run() override;
79 bool hasFeature(EngineFeature f) const override;
80 Common::Error loadGameState(int slot) override;
81 bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
82 Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
83 bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
84 bool canSaveAutosaveCurrently() override;
85
86private:
87 void loadFonts();
88 bool initializeSearchPaths();
89 bool showInitialLogoScreen();
90 bool showTitleScreen();
91 bool transitionFromLogoToTitle();
92 bool startNewGameFromTitle();
93 bool playNumberedMovie(int movieId, bool blankScreenMovie = false);
94 Common::SeekableReadStream *createMovieReadStream(int movieId) const;
95 bool switchActiveMediaDisc(int discNumber);
96 void stopActiveMovie();
97 void playUiSound();
98 void startMenuBackgroundMusic();
99 void updateMenuBackgroundMusic();
100 void stopMenuBackgroundMusic();
101 void startGameOverMusic();
102 void stopGameOverMusic();
103 void startSceneIdleMovie();
104 void stopSceneIdleMovie();
105 void enterSystemMenu();
106 bool showSystemScreen();
107 void restoreTitleScreenRegion(const Common::Rect &rect, bool present = true);
108 void drawSystemSaveLoadSlots(bool present = true);
109 void drawSystemSubmodeButtons(bool present = true);
110 void drawSystemSubmodeButton(uint buttonIndex, bool selected, bool present = true);
111 void drawSystemWaveVolumeIndicator(bool present = true);
112 void syncSystemWaveVolumeFromMixer();
113 void applySystemWaveVolume();
114 bool handleSystemWaveVolumeClick(const Common::Point &mousePosition);
115 bool handleSystemClick(const Common::Point &mousePosition);
116 void activateSystemExitButton();
117 bool readSaveSlotHeader(int slot, int &savedDay, int &savedClockTicks);
118 bool isSaveSlotOccupied(int slot);
119 void writeContinueState();
120 bool showSystemConfirmationDialog(const Common::U32String &message, bool showCancelButton);
121 void returnFromSystemMenuToPreviousState();
122 bool handleSaveLoadSlotClick(const Common::Point &mousePosition);
123 bool openMapMoveMovie();
124 void startMapMoveMovie();
125 void stopMapMoveMovie();
126 void resetGameState();
127 void resetTransientRuntimeStateAfterLoad();
128 bool loadScriptData();
129 bool loadExecutableDataTables();
130 bool loadByteFile(const char *fileName, Common::Array<byte> &data) const;
131 void processGameStateDispatcher(bool runScriptBeforeDispatch);
132 bool dispatchGameStateControlCode(uint32 dispatcherControlCode);
133 bool dispatchGameStateNoOp();
134 bool dispatchSceneChoiceControls();
135 bool dispatchMapMoveControls();
136 bool dispatchComputerMainControls();
137 bool dispatchComputerDetailControls();
138 bool dispatchGameOverScreen();
139 bool dispatchEndingStillDisplayState();
140 const Graphics::Surface *getComputerBitmap();
141 bool showComputerScreen();
142 void drawComputerChoiceGroupControls();
143 void drawComputerConditionalChoiceControls(const ButtonControlRecord *choiceButtonRecords, int firstStateIndex, int stateCount);
144 void drawComputerButton(const ButtonControlRecord &sourceButton, const ButtonControlRecord &destButton);
145 void drawComputerButtonPressed(const ButtonControlRecord &button, int sourceX, int sourceY);
146 void drawComputerDetailButtonNormal(const ButtonControlRecord &button);
147 void drawComputerUnavailableMarker(const ButtonControlRecord &destButton);
148 void drawXorRectangleBorder(const Common::Rect &rect);
149 void processXorRectangleBorderAnimation(bool expand, const Common::Rect &sourceRect, const Common::Rect &targetRect);
150 bool showComputerDetailScreen(int compositeIndex);
151 void checkCurrentMediaPathReady();
152 void clearDisplayAndResetState();
153 void executeCurrentScriptSequence();
154 uint32 executeScriptExpression(uint32 &scriptPc, int &branchTokenSeen);
155 bool pushScriptValue(uint32 value);
156 uint32 popScriptValue();
157 void popScriptOperands(uint32 &leftValue, uint32 &rightValue);
158 uint32 dereferenceScriptValue(uint32 value);
159 uint32 &scriptOperandDword(uint32 encodedOperand);
160 uint32 &stateDword(uint byteOffset);
161 uint32 stateDword(uint byteOffset) const;
162 bool processPendingMovieRequest();
163 void loadTimedCaptionRecord(int movieId);
164 void loadNextTimedCaptionText();
165 bool readTimedCaptionLine(Common::String &line);
166 const byte *findAllBinRecordData(const Common::String &recordName, uint32 &recordSize) const;
167 bool drawTimedVideoTextOverlay();
168 void restoreActiveCaptionBackingRect();
169 Common::Rect getCaptionBackingRect(const Common::String &sjisText, const Common::U32String &unicodeText, const Common::Rect &nativeRect) const;
170 void drawCaptionTextBlock(const Common::String &sjisText, const Common::U32String &unicodeText, const Common::Rect &rect, uint32 color);
171 void restoreCaptionBackingRect(const Common::Rect &rect);
172 Common::Point getActiveMoviePosition() const;
173 bool shouldDrawMovieControlStrip() const;
174 void drawMapSubmodeMovieBackdrop(bool present = true);
175 void drawSceneChoiceControlStrip(int sourceX = 0, bool present = true);
176 void drawMovieControlStrip(int sourceX = 0, bool present = true);
177 void stopActiveMovieAndDispatch();
178 void processQueuedMovieSequence();
179 bool isMapButtonEnabled(uint buttonIndex) const;
180 void drawMapButtonPressed(uint buttonIndex, bool present = true);
181 void composeMapControlsToSurface(Graphics::Surface &surface, const Graphics::Surface &mapArt);
182 void drawMapControls(bool present = true);
183 bool handleMapControlClick(const Common::Point &mousePosition);
184 bool showPendingStillImageScreen();
185 void completePendingStillImageScreen();
186 bool showMainSceneScreen();
187 bool drawMainSceneScreen(bool lineReveal);
188 bool showMapScreen();
189 bool showActiveSceneChoiceControls();
190 void captureSceneChoiceBacking();
191 void restoreSceneChoiceBacking(bool present = true);
192 void freeSceneChoiceBacking();
193 void clearSceneChoiceAfterSelection();
194 bool isSceneChoiceButtonVisible(int buttonIndex) const;
195 void drawSceneChoiceButtons(int sceneChoiceUiSetToShowId, bool present = true, int pressedButtonIndex = -1);
196 void handleSceneChoiceClick(const Common::Point &mousePosition);
197 void handleSceneChoiceSelection(int buttonIndex);
198 bool handleComputerClick(const Common::Point &mousePosition);
199 bool handleComputerKey(Common::KeyCode keycode);
200 void applyPendingClockTickDelta();
201 void notifyGameClockTicksChanged();
202 void drawClockAndChipIndicator(bool present = true);
203 void drawAnalogClockAndChip(int baseHourOffset, int gameClockTicks, bool present = true);
204 void renderClockAndChipToSurface(Graphics::Surface &surface, int baseHourOffset, int gameClockTicks);
205 Graphics::Surface *loadBitmap(const char *fileName);
206 const Graphics::Surface *getUiBitmap(const char *fileName);
207 Graphics::Surface *loadBitmapFromStream(Common::SeekableReadStream *stream, const char *debugName) const;
208 Graphics::Surface *loadDiscBitmap(const char *relativePath) const;
209 Graphics::Surface *loadDiscBitmapFromAnyDisc(const char *relativePath) const;
210 Common::SeekableReadStream *createProgramReadStream(const char *relativePath) const;
211 Common::SeekableReadStream *createDiscReadStream(int discNumber, const char *relativePath) const;
212 Common::SeekableReadStream *createActiveDiscReadStream(const char *relativePath) const;
213 Common::SeekableReadStream *createActiveDiscHighColorReadStream(const char *relativePath) const;
214 void blitScreenWithLineReveal(const Graphics::Surface &surface, bool presentFinalFrame = true);
215 void drawTitleButton(uint buttonIndex, bool pressed);
216 void handleLeftButtonDown(const Common::Point &mousePosition);
217 void handleKeymapperAction(Common::CustomEventType action);
218 bool handleEscapeAction();
219 void handleSkipKey();
220 void handleSceneChoiceKeyboardSelection(int choiceNumber);
221 bool parseCheatNumber(const Common::String &text, uint32 &value) const;
222 void addCheatTime(int minutes);
223 void jumpToCheatSequence(uint sequenceId);
224 bool pollEvents();
225 bool pollEvents(bool handleClicks);
226 void serviceCursorRefresh(bool screenUpdated = false);
227 void delayWithEventPolling(uint32 millis);
228 void delayWithEventPolling(uint32 millis, bool handleClicks);
229 Common::U32String decodeExecutableTextForDisplay(const Common::String &text) const;
230 Common::U32String formatSystemTextForDisplay(const Common::String &originalFormat, int slot) const;
231 Common::U32String formatSystemClockTextForDisplay(const Common::String &originalFormat, int slot, int savedDay, int savedClockTicks) const;
232 void mainLoop();
233
234 const HaroldGameDescription *_gameDescription;
235 Graphics::Screen *_screen = nullptr;
236 Common::SearchSet _programFiles;
237 Common::SearchSet _discFiles[5];
238 Common::Array<byte> _scriptData;
239 Common::Array<byte> _locationTableData;
240 Common::Array<byte> _locationTimingData;
241 Common::Array<byte> _allBinData;
242 Common::Array<byte> _timedCaptionRecordData;
244 Common::CodePage _executableTextEncoding = Common::kWindows932;
245 Common::String _sceneChoiceMoveTextSjis;
246 Common::U32String _sceneChoiceMoveText;
247 Common::Array<Common::String> _mapButtonTextSjis;
250 Common::U32String _titleExitConfirmText;
251 Common::String _saveSlotOccupiedTextFormatSjis;
252 Common::String _saveSlotEmptyTextFormatSjis;
253 Common::String _loadSlotConfirmTextFormatSjis;
254 Common::String _saveSlotOverwriteConfirmTextFormatSjis;
255 Common::String _saveSlotEmptyConfirmTextFormatSjis;
256 Common::String _noSaveDataMessageSjis;
257 Common::String _returnToTitleConfirmTextSjis;
258 Graphics::FontSJIS *_sjisFont = nullptr;
259 const Graphics::Font *_captionTextFont = nullptr;
260 const Graphics::Font *_gameOverTextFont = nullptr;
261 const Graphics::Font *_ownerDrawUiTextFont = nullptr;
262 Video::AVIDecoder *_menuBackgroundVideo = nullptr;
263 Video::AVIDecoder *_gameOverVideo = nullptr;
264 Video::AVIDecoder *_sceneIdleVideo = nullptr;
265 Video::AVIDecoder *_mapMoveVideo = nullptr;
266 Video::AVIDecoder *_activeMovieVideo = nullptr;
267 Graphics::Surface *_titleBitmap = nullptr;
268 Graphics::Surface *_uiBitmap = nullptr;
269 Common::String _uiBitmapName;
270 Graphics::Surface *_chipBitmap = nullptr;
271 Graphics::Surface *_sceneChoiceBacking = nullptr;
272 Common::Rect _sceneChoiceBackingRect;
273 Graphics::Surface *_computerBitmap = nullptr;
274 Graphics::Surface *_computerDetailBacking = nullptr;
275 Audio::SoundHandle _uiSoundHandle;
276 uint32 _gameState[0x100] = {};
277 uint32 _scriptValueStack[0x100] = {};
278 int _scriptStackDepth = 0;
279 bool _scriptStopFlag = false;
280 int _currentDisplayState = 0;
281 int _initialLogoElapsedTimerTicks = 0;
282 int _pendingStillElapsedTimerTicks = 0;
283 int _gameOverElapsedTimerTicks = 0;
284 int _pendingStillDurationIndex = 0;
285 int _pendingClockTickDelta = 0;
286 int _sceneIdleMovieTimerTicks = 0;
287 int _activeMediaDiscNumber = 1;
288 uint _timedCaptionCursorOffset = 0;
289 int _nextTimedCaptionThreshold = 99999;
290 int _queuedMoviePlaybackIndex = 0;
291 int _previousDisplayStateBeforeSystem = 0;
292 int _computerChoiceGroupIndex = 0;
293 int _computerDetailVariantIndex = 0;
294 int _sceneChoiceTerminatorButtonIndex = 0;
295 int _sceneChoiceEnabledButtonLimit = 0;
296 bool _computerControlsActive = false;
297 bool _computerDetailControlsActive = false;
298 bool _computerDetailNextVariantEnabled = false;
299 Common::Array<int> _computerActiveChoiceIds;
300 Common::Array<Common::Rect> _computerActiveChoiceRects;
301 Common::Rect _computerSelectionXorRect;
302 Common::U32String _timedCaptionText;
303 Common::String _timedCaptionTextSjis;
304 Common::Rect _activeCaptionBackingRect;
305 uint32 _lastTimerTick = 0;
306 int _lastLoggedGameClockTicks = -1;
307 uint32 _lastCursorRefreshMillis = 0;
308 Common::Point _mousePosition;
309 bool _activeMovieDispatchOnFinish = false;
310 bool _activeMovieOnBlankScreen = false;
311 bool _activeMoviePaused = false;
312 bool _sceneChoiceActive = false;
313 bool _mapControlsActive = false;
314 bool _suppressClickHandling = false;
315 bool _titleButtonsActive = false;
316 bool _systemButtonsVisible = false;
317 int _systemSaveLoadSlotActionMode = 0;
318 int _systemWaveVolume = 0xffff;
319 bool _titleLoadSlotsActive = false;
320};
321
322} // End of namespace BCB
323
324#endif // BCB_H
Definition: mixer.h:49
Definition: bcb.h:71
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Common::Error loadGameState(int slot) override
Common::Error run() override
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave=false) override
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
bool canSaveAutosaveCurrently() override
bool hasFeature(EngineFeature f) const override
Definition: debugger.h:31
Definition: error.h:81
Definition: archive.h:330
Definition: stream.h:745
Definition: str.h:59
Definition: ustr.h:57
Definition: engine.h:149
EngineFeature
Definition: engine.h:282
Definition: font.h:83
Definition: screen.h:47
Definition: system.h:166
Definition: avi_decoder.h:65
uint32 CustomEventType
Definition: events.h:212
Definition: formatinfo.h:28
Definition: ui.h:46
Definition: detection.h:33
Definition: rect.h:144
Definition: rect.h:536
Definition: surface.h:67
Definition: atari-screen.h:58