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