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-str.h"
31 #include "common/random.h"
32 #include "common/serializer.h"
33 #include "common/events.h"
34 #include "common/util.h"
35 #include "engines/engine.h"
36 #include "engines/savestate.h"
37 
38 #include "mediastation/clients.h"
39 #include "mediastation/detection.h"
40 #include "mediastation/datafile.h"
41 #include "mediastation/boot.h"
42 #include "mediastation/context.h"
43 #include "mediastation/actor.h"
44 #include "mediastation/cursors.h"
45 #include "mediastation/graphics.h"
46 #include "mediastation/profile.h"
47 #include "mediastation/mediascript/function.h"
48 #include "mediastation/actors/stage.h"
49 
50 namespace MediaStation {
51 
52 struct MediaStationGameDescription;
53 class HotspotActor;
54 class RootStage;
55 class PixMapImage;
56 
57 // Most Media Station titles follow this file structure from the root directory
58 // of the CD-ROM:
59 // - [TITLE].EXE (main game executable, name vares based on game)
60 // - DATA/ (subdirectory that holds actual game data including bytecode)
61 // - 100.CXT
62 // - ... other CXTs, varies per title
63 static const char *const directoryGlobs[] = {
64  "DATA", // For most titles
65  "program", // For D.W. the Picky Eater
66  "PZDATA", // For Puzzle Castle demo
67  nullptr
68 };
69 
70 // As this is currently structured, some of the methods in the main engine class are from
71 // the RT_ImtGod class in the original, and others are from the RT_App class in the original.
72 // In the interest of avoiding more indirection than is already present in the original, we will
73 // just keep these together for now.
74 class MediaStationEngine : public Engine, public ChannelClient {
75 public:
76  MediaStationEngine(OSystem *syst, const ADGameDescription *gameDesc);
77  ~MediaStationEngine() override;
78 
79  uint32 getFeatures() const;
80  Common::String getGameId() const;
81  Common::Platform getPlatform() const;
82  const char *getAppName() const;
83  bool hasFeature(EngineFeature f) const override {
84  return
86  };
87 
88  bool isFirstGenerationEngine();
89  void dispatchSystemEvents();
90  void draw(bool dirtyOnly = true);
91 
92  void registerActor(Actor *actorToAdd);
93  void destroyActor(uint actorId);
94  void destroyContext(uint contextId, bool eraseFromLoadedContexts = true);
95  bool contextIsLocked(uint contextId);
96 
97  void readUnrecognizedFromStream(Chunk &chunk, uint sectionType);
98  void readHeaderSections(Subfile &subfile, Chunk &chunk);
99 
100  Actor *getActorById(uint actorId);
101  Actor *getActorByIdAndType(uint actorId, ActorType expectedType);
102  SpatialEntity *getSpatialEntityById(uint spatialEntityId);
103  ChannelClient *getChannelClientByChannelIdent(uint channelIdent);
104  ScriptValue *getVariable(uint variableId);
105  VideoDisplayManager *getDisplayManager() { return _displayManager; }
106  CursorManager *getCursorManager() { return _cursorManager; }
107  FunctionManager *getFunctionManager() { return _functionManager; }
108  RootStage *getRootStage() { return _stageDirector->getRootStage(); }
109  StreamFeedManager *getStreamFeedManager() { return _streamFeedManager; }
110  Document *getDocument() { return _document; }
111 
112  Common::String formatActorName(uint actorId, bool attemptToGetType = false) { return _profile->formatActorName(actorId, attemptToGetType); }
113  Common::String formatActorName(const Actor *actor) { return _profile->formatActorName(actor); }
114  Common::String formatFunctionName(uint functionId) { return _profile->formatFunctionName(functionId); }
115  Common::String formatFileName(uint fileId) { return _profile->formatFileName(fileId); }
116  Common::String formatVariableName(uint variableId) { return _profile->formatVariableName(variableId); }
117  Common::String formatParamTokenName(uint paramToken) { return _profile->formatParamTokenName(paramToken); }
118  Common::String formatAssetNameForChannelIdent(uint channelIdent) { return _profile->formatAssetNameForChannelIdent(channelIdent); }
119 
120  const FileInfo &fileInfoForIdent(uint fileId) { return _fileMap.getValOrDefault(fileId); }
121  const StreamInfo &streamInfoForIdent(uint streamId) { return _streamMap.getValOrDefault(streamId); }
122  const ScreenReference &screenRefWithId(uint screenActorId) { return _screenReferences.getValOrDefault(screenActorId); }
123  const ContextReference &contextRefWithId(uint contextId) { return _contextReferences.getValOrDefault(contextId); }
124 
125  Common::Array<ParameterClient *> _parameterClients;
126  Common::HashMap<uint, Context *> _loadedContexts;
127 
128  SpatialEntity *getMouseInsideHotspot() { return _mouseInsideHotspot; }
129  void setMouseInsideHotspot(SpatialEntity *entity) { _mouseInsideHotspot = entity; }
130  void clearMouseInsideHotspot() { _mouseInsideHotspot = nullptr; }
131 
132  SpatialEntity *getMouseDownHotspot() { return _mouseDownHotspot; }
133  void setMouseDownHotspot(SpatialEntity *entity) { _mouseDownHotspot = entity; }
134  void clearMouseDownHotspot() { _mouseDownHotspot = nullptr; }
135 
136  Common::RandomSource _randomSource;
137 
138  static const uint SCREEN_WIDTH = 640;
139  static const uint SCREEN_HEIGHT = 480;
140  static const uint BOOT_STREAM_ID = 1;
141 
142 protected:
143  Common::Error run() override;
144 
145 private:
146  Common::Event _event;
147  Common::FSNode _gameDataDir;
148  const ADGameDescription *_gameDescription;
149 
150  VideoDisplayManager *_displayManager = nullptr;
151  CursorManager *_cursorManager = nullptr;
152  FunctionManager *_functionManager = nullptr;
153  Document *_document = nullptr;
154  DeviceOwner *_deviceOwner = nullptr;
155  StageDirector *_stageDirector = nullptr;
156  StreamFeedManager *_streamFeedManager = nullptr;
157  Profile *_profile = nullptr;
158 
160  SpatialEntity *_mouseInsideHotspot = nullptr;
161  SpatialEntity *_mouseDownHotspot = nullptr;
162 
163  Common::String _gameTitle;
164  VersionInfo _versionInfo;
165  Common::String _engineInfo;
166  Common::String _sourceString;
167  Common::HashMap<uint, ContextReference> _contextReferences;
168  Common::HashMap<uint, ScreenReference> _screenReferences;
171  Common::HashMap<uint, EngineResourceDeclaration> _engineResourceDeclarations;
172  uint _unk1 = 0;
173  uint _functionTableSize = 0;
174  uint _unk3 = 0;
175 
176  void initDisplayManager();
177  void initCursorManager();
178  void initFunctionManager();
179  void initDocument();
180  void initDeviceOwner();
181  void initStageDirector();
182  void initStreamFeedManager();
183  void initProfile();
184  void setupInitialStreamMap();
185 
186  void runEventLoop();
187 
188  virtual void readChunk(Chunk &chunk) override;
189  void readDocumentDef(Chunk &chunk);
190  void readDocumentInfoFromStream(Chunk &chunk, BootSectionType sectionType);
191  void readVersionInfoFromStream(Chunk &chunk);
192  void readContextReferencesFromStream(Chunk &chunk);
193  void readScreenReferencesFromStream(Chunk &chunk);
194  void readAndAddFileMaps(Chunk &chunk);
195  void readAndAddStreamMaps(Chunk &chunk);
196 
197  void readControlCommands(Chunk &chunk);
198  void readCommandFromStream(Chunk &chunk, ContextSectionType sectionType);
199  void readCreateContextData(Chunk &chunk);
200  void readDestroyContextData(Chunk &chunk);
201  void readCreateActorData(Chunk &chunk);
202  void readDestroyActorData(Chunk &chunk);
203  void readActorLoadComplete(Chunk &chunk);
204  void readCreateVariableData(Chunk &chunk);
205  void readContextNameData(Chunk &chunk);
206 
207  void destroyActorsInContext(uint contextId);
208 };
209 
211 #define SHOULD_QUIT ::MediaStation::g_engine->shouldQuit()
212 
213 } // End of namespace MediaStation
214 
215 #endif // MEDIASTATION_H
Definition: datafile.h:35
Definition: str.h:59
Definition: stage.h:166
EngineFeature
Definition: engine.h:258
Definition: actor.h:229
Definition: graphics.h:127
Definition: actor.h:33
Definition: error.h:81
Definition: profile.h:72
Definition: array.h:52
Definition: advancedDetector.h:164
Definition: random.h:44
Definition: datafile.h:102
Definition: stage.h:137
Definition: datafile.h:163
Definition: cursors.h:51
Definition: function.h:54
Definition: datafile.h:211
Engine * g_engine
Definition: engine.h:272
bool hasFeature(EngineFeature f) const override
Definition: mediastation.h:83
Definition: boot.h:61
Definition: boot.h:42
Definition: clients.h:56
Definition: hashmap.h:85
Definition: events.h:210
Definition: fs.h:69
Definition: mediastation.h:74
Definition: datafile.h:129
Definition: boot.h:112
Definition: boot.h:92
Definition: system.h:164
Definition: actor.h:187
Definition: engine.h:144
Common::Error run() override
Definition: scriptvalue.h:35
Platform
Definition: platform.h:93
Definition: clients.h:42