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