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