ScummVM API documentation
mediastation.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 MEDIASTATION_H
23#define MEDIASTATION_H
24
25#include "audio/mixer.h"
26#include "common/scummsys.h"
27#include "common/system.h"
28#include "common/error.h"
29#include "common/fs.h"
30#include "common/hash-ptr.h"
31#include "common/hash-str.h"
32#include "common/random.h"
33#include "common/serializer.h"
34#include "common/events.h"
35#include "common/util.h"
36#include "engines/engine.h"
37#include "engines/savestate.h"
38
39#include "mediastation/actor.h"
40#include "mediastation/actors/stage.h"
41#include "mediastation/boot.h"
42#include "mediastation/clients.h"
43#include "mediastation/context.h"
44#include "mediastation/cursors.h"
45#include "mediastation/datafile.h"
46#include "mediastation/debugger.h"
47#include "mediastation/detection.h"
48#include "mediastation/events.h"
49#include "mediastation/graphics.h"
50#include "mediastation/mediascript/function.h"
51#include "mediastation/profile.h"
52
53namespace MediaStation {
54
55struct MediaStationGameDescription;
56class AudioSequence;
57class HotspotActor;
58class RootStage;
59class PixMapImage;
60class ImtGod;
61class ImtDeviceOwner;
62class EventLoop;
63class Debugger;
64
65// Most Media Station titles follow this file structure from the root directory
66// of the CD-ROM:
67// - [TITLE].EXE (main game executable, name vares based on game)
68// - DATA/ (subdirectory that holds actual game data including bytecode)
69// - 100.CXT
70// - ... other CXTs, varies per title
71static const char *const directoryGlobs[] = {
72 "DATA", // For most titles
73 "program", // For D.W. the Picky Eater
74 "PZDATA", // For Puzzle Castle demo
75 nullptr
76};
77
78class MediaStationEngine : public Engine {
79friend class ImtGod;
80
81public:
82 MediaStationEngine(OSystem *syst, const ADGameDescription *gameDesc);
83 ~MediaStationEngine() override;
84
85 uint32 getFeatures() const;
86 Common::String getGameId() const;
87 Common::Platform getPlatform() const;
88 const char *getAppName() const;
89 bool hasFeature(EngineFeature f) const override;
90 void dispatchOneSystemEvent(const Common::Event &event);
91 void generateMouseUpdateEvent();
92 uint currentTimeInSeconds();
93
94 VideoDisplayManager *getDisplayManager() { return _displayManager; }
95 DisplayUpdateManager *getDisplayUpdateManager() { return _displayUpdateManager; }
96 PrintManager *getPrintManager() { return _printManager; }
97 CursorManager *getCursorManager() { return _cursorManager; }
98 FunctionManager *getFunctionManager() { return _functionManager; }
99 RootStage *getRootStage() { return _stageDirector->getRootStage(); }
100 StageDirector *getStageDirector() { return _stageDirector; }
101 StreamFeedManager *getStreamFeedManager() { return _streamFeedManager; }
102 EventLoop *getEventLoop() { return _eventLoop; }
103 Document *getDocument() { return _document; }
104 TimerService *getTimerService() { return _timerService; }
105 ImtGod *getImtGod() { return _imtGod; }
106 ImtDeviceOwner *getDeviceOwner() { return _deviceOwner; }
107
108 void registerAudioSequence(AudioSequence *sequence);
109 void unregisterAudioSequence(AudioSequence *sequence);
110 void serviceSounds();
111
112 Common::String formatActorName(uint actorId, bool attemptToGetType = false, bool includeDefaultName = true) { return _profile->formatActorName(actorId, attemptToGetType, includeDefaultName); }
113 Common::String formatActorName(const Actor *actor, bool includeDefaultName = true) { return _profile->formatActorName(actor, includeDefaultName); }
114 Common::String formatFunctionName(uint functionId, bool includeDefaultName = true) { return _profile->formatFunctionName(functionId, includeDefaultName); }
115 Common::String formatFileName(uint fileId, bool includeDefaultName = true) { return _profile->formatFileName(fileId, includeDefaultName); }
116 Common::String formatVariableName(uint variableId, bool includeDefaultName = true) { return _profile->formatVariableName(variableId, includeDefaultName); }
117 Common::String formatParamTokenName(uint paramToken, bool includeDefaultName = true) { return _profile->formatParamTokenName(paramToken, includeDefaultName); }
118 Common::String formatAssetNameForChannelIdent(uint channelIdent, bool includeDefaultName = true) { return _profile->formatAssetNameForChannelIdent(channelIdent, includeDefaultName); }
119
120 SpatialEntity *getMouseInsideHotspot() { return _mouseInsideHotspot; }
121 void setMouseInsideHotspot(SpatialEntity *entity) { _mouseInsideHotspot = entity; }
122 void clearMouseInsideHotspot() { _mouseInsideHotspot = nullptr; }
123
124 SpatialEntity *getMouseDownHotspot() { return _mouseDownHotspot; }
125 void setMouseDownHotspot(SpatialEntity *entity) { _mouseDownHotspot = entity; }
126 void clearMouseDownHotspot() { _mouseDownHotspot = nullptr; }
127
128 static const uint SCREEN_WIDTH = 640;
129 static const uint SCREEN_HEIGHT = 480;
130 static const uint BOOT_STREAM_ID = 1;
131 Common::RandomSource _randomSource;
132
133protected:
134 Common::Error run() override;
135
136private:
137 Common::FSNode _gameDataDir;
138 const ADGameDescription *_gameDescription;
139
140 SpatialEntity *_mouseInsideHotspot = nullptr;
141 SpatialEntity *_mouseDownHotspot = nullptr;
142
143 Debugger *_debugger = nullptr;
144 EventLoop *_eventLoop = nullptr;
145 TimerService *_timerService = nullptr;
146 StreamFeedManager *_streamFeedManager = nullptr;
147 // CacheManager *_cacheManager = nullptr;
148 // StreamProfiler *_streamProfiler = nullptr;
149 ImtGod *_imtGod = nullptr;
150 ImtDeviceOwner *_deviceOwner = nullptr;
151 FunctionManager *_functionManager = nullptr;
152 DisplayUpdateManager *_displayUpdateManager = nullptr;
153 VideoDisplayManager *_displayManager = nullptr;
154 PrintManager *_printManager = nullptr;
155 Document *_document = nullptr;
156 CursorManager *_cursorManager = nullptr;
157 StageDirector *_stageDirector = nullptr;
158 Profile *_profile = nullptr;
159
161
162 void initCursorManager();
163 void queueMouseEvent(EventType type, const Common::Point &point);
164};
165
166class ImtGod : public ChannelClient {
167friend class EventLoop;
168friend class Debugger;
169
170public:
172 virtual ~ImtGod() override;
173
174 void addConstructedActor(Actor *actorToAdd);
175 void destroyActor(uint actorId);
176 void registerParameterClient(ParameterClient *client);
177 void unregisterParameterClient(ParameterClient *client);
178 void destroyContext(uint contextId, bool eraseFromLoadedContexts = true);
179 void destroyAllContexts();
180 void lockContext(uint contextId);
181 bool contextIsLocked(uint contextId);
182 void clearAllContextLocks();
183
184 void readUnrecognizedFromStream(Chunk &chunk, uint sectionType);
185 void readHeaderSections(Subfile &subfile, Chunk &chunk);
186
187 const FileInfo &fileInfoForIdent(uint fileId) { return _fileMap.getValOrDefault(fileId); }
188 const StreamInfo &streamInfoForIdent(uint streamId) { return _streamMap.getValOrDefault(streamId); }
189 const ScreenReference &screenRefWithId(uint screenActorId) { return _screenReferences.getValOrDefault(screenActorId); }
190 const ContextReference &contextRefWithId(uint contextId) { return _contextReferences.getValOrDefault(contextId); }
191
192 Actor *getActorById(uint actorId);
193 Actor *getActorByIdAndType(uint actorId, ActorType expectedType);
194 SpatialEntity *getSpatialEntityById(uint spatialEntityId);
195 ChannelClient *getChannelClientByChannelIdent(uint channelIdent);
196 ScriptValue *getVariable(uint variableId);
197 Context *getContextById(uint contextId);
198
199 bool isFirstGenerationEngine() const;
200 void setupInitialStreamMap();
201
202private:
203 MediaStationEngine *_vm = nullptr;
204
205 Common::String _gameTitle;
206 VersionInfo _versionInfo;
207 Common::String _engineInfo;
208 Common::String _sourceString;
214 Common::HashMap<Common::String, ScriptValue> _paramTokenDeclarations;
215 Common::HashMap<uint, bool> _lockedContextIds;
217 Common::HashMap<uint, Context *> _loadedContexts;
218 uint _unk1 = 0;
219 uint _functionTableSize = 0;
220 uint _unk3 = 0;
221
222 virtual void readChunk(Chunk &chunk) override;
223 void readDocumentDef(Chunk &chunk);
224 void readDocumentInfoFromStream(Chunk &chunk, BootSectionType sectionType);
225 void readVersionInfoFromStream(Chunk &chunk);
226 void readContextReferencesFromStream(Chunk &chunk);
227 void readScreenReferencesFromStream(Chunk &chunk);
228 void readAndAddFileMaps(Chunk &chunk);
229 void readAndAddStreamMaps(Chunk &chunk);
230
231 void readControlCommands(Chunk &chunk);
232 void readCommandFromStream(Chunk &chunk, ContextSectionType sectionType);
233 void readCreateContextData(Chunk &chunk);
234 void readDestroyContextData(Chunk &chunk);
235 void readCreateActorData(Chunk &chunk);
236 void readDestroyActorData(Chunk &chunk);
237 void readActorLoadComplete(Chunk &chunk);
238 void readCreateVariableData(Chunk &chunk);
239 void readSetContextName(Chunk &chunk);
240
241 void destroyActorsInContext(uint contextId);
242};
243
245#define SHOULD_QUIT ::MediaStation::g_engine->shouldQuit()
246
247} // End of namespace MediaStation
248
249#endif // MEDIASTATION_H
Definition: error.h:81
Definition: fs.h:69
Definition: hashmap.h:85
Definition: random.h:44
Definition: str.h:59
Definition: engine.h:149
EngineFeature
Definition: engine.h:282
Definition: actor.h:226
Definition: datafile.h:160
Definition: datafile.h:99
Definition: context.h:54
Definition: boot.h:42
Definition: cursors.h:51
Definition: debugger.h:31
Definition: graphics.h:166
Definition: clients.h:93
Definition: events.h:178
Definition: boot.h:92
Definition: function.h:65
Definition: clients.h:65
Definition: mediastation.h:166
Definition: mediastation.h:78
Common::Error run() override
bool hasFeature(EngineFeature f) const override
Definition: clients.h:34
Definition: graphics.h:150
Definition: profile.h:72
Definition: boot.h:61
Definition: scriptvalue.h:35
Definition: actor.h:278
Definition: stage.h:172
Definition: datafile.h:208
Definition: boot.h:112
Definition: datafile.h:126
Definition: events.h:235
Definition: graphics.h:185
Definition: system.h:166
Platform
Definition: platform.h:93
Engine * g_engine
Definition: advancedDetector.h:164
Definition: events.h:218
Definition: rect.h:144
Definition: datafile.h:35