ScummVM API documentation
asset.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_ASSET_H
23 #define MEDIASTATION_ASSET_H
24 
25 #include "common/keyboard.h"
26 
27 #include "mediastation/datafile.h"
28 #include "mediastation/mediascript/eventhandler.h"
29 #include "mediastation/mediascript/scriptconstants.h"
30 #include "mediastation/mediascript/scriptvalue.h"
31 
32 namespace MediaStation {
33 
34 enum AssetType {
35  kAssetTypeEmpty = 0x0000,
36  kAssetTypeScreen = 0x0001, // SCR
37  kAssetTypeStage = 0x0002, // STG
38  kAssetTypePath = 0x0004, // PTH
39  kAssetTypeSound = 0x0005, // SND
40  kAssetTypeTimer = 0x0006, // TMR
41  kAssetTypeImage = 0x0007, // IMG
42  kAssetTypeHotspot = 0x000b, // HSP
43  kAssetTypeSprite = 0x000e, // SPR
44  kAssetTypeLKZazu = 0x000f,
45  kAssetTypeLKConstellations = 0x0010,
46  kAssetTypeDocument = 0x0011,
47  kAssetTypeImageSet = 0x001d,
48  kAssetTypeCursor = 0x000c, // CSR
49  kAssetTypePrinter = 0x0019, // PRT
50  kAssetTypeMovie = 0x0016, // MOV
51  kAssetTypePalette = 0x0017,
52  kAssetTypeText = 0x001a, // TXT
53  kAssetTypeFont = 0x001b, // FON
54  kAssetTypeCamera = 0x001c, // CAM
55  kAssetTypeCanvas = 0x001e, // CVS
56  kAssetTypeXsnd = 0x001f,
57  kAssetTypeXsndMidi = 0x0020,
58  kAssetTypeRecorder = 0x0021,
59  kAssetTypeFunction = 0x0069 // FUN
60 };
61 
62 enum AssetHeaderSectionType {
63  kAssetHeaderEmptySection = 0x0000,
64  kAssetHeaderEventHandler = 0x0017,
65  kAssetHeaderStageId = 0x0019,
66  kAssetHeaderAssetId = 0x001a,
67  kAssetHeaderChunkReference = 0x001b,
68  kAssetHeaderMovieAnimationChunkReference = 0x06a4,
69  kAssetHeaderMovieAudioChunkReference = 0x06a5,
70  kAssetHeaderAssetReference = 0x077b,
71  kAssetHeaderBoundingBox = 0x001c,
72  kAssetHeaderMouseActiveArea = 0x001d,
73  kAssetHeaderZIndex = 0x001e,
74  kAssetHeaderStartup = 0x001f,
75  kAssetHeaderTransparency = 0x0020,
76  kAssetHeaderHasOwnSubfile = 0x0021,
77  kAssetHeaderCursorResourceId = 0x0022,
78  kAssetHeaderFrameRate = 0x0024,
79  kAssetHeaderLoadType = 0x0032,
80  kAssetHeaderSoundInfo = 0x0033,
81  kAssetHeaderMovieLoadType = 0x0037,
82  kAssetHeaderSpriteChunkCount = 0x03e8,
83  kAssetHeaderPalette = 0x05aa,
84  kAssetHeaderDissolveFactor = 0x05dc,
85  kAssetHeaderGetOffstageEvents = 0x05dd,
86  kAssetHeaderX = 0x05de,
87  kAssetHeaderY = 0x05df,
88 
89  // PATH FIELDS.
90  kAssetHeaderStartPoint = 0x060e,
91  kAssetHeaderEndPoint = 0x060f,
92  kAssetHeaderPathTotalSteps = 0x0610,
93  kAssetHeaderStepRate = 0x0611,
94  kAssetHeaderDuration = 0x0612,
95 
96  // CAMERA FIELDS.
97  kAssetHeaderViewportOrigin = 0x076f,
98  kAssetHeaderLensOpen = 0x0770,
99 
100  // STAGE FIELDS.
101  kAssetHeaderStageUnk1 = 0x0771,
102  kAssetHeaderCylindricalX = 0x0772,
103  kAssetHeaderCylindricalY = 0x0773,
104  kAssetHeaderAssetName = 0x0bb8,
105 
106  // TEXT FIELDS.
107  kAssetHeaderEditable = 0x03eb,
108  kAssetHeaderFontId = 0x0258,
109  kAssetHeaderInitialText = 0x0259,
110  kAssetHeaderTextMaxLength = 0x25a,
111  kAssetHeaderTextJustification = 0x025b,
112  kAssetHeaderTextPosition = 0x25f,
113  kAssetHeaderTextUnk1 = 0x262,
114  kAssetHeaderTextUnk2 = 0x263,
115  kAssetHeaderTextCharacterClass = 0x0266,
116 
117  // SPRITE FIELDS.
118  kAssetHeaderSpriteClip = 0x03e9,
119  kAssetHeaderCurrentSpriteClip = 0x03ea
120 };
121 
122 class Asset {
123 public:
124  Asset(AssetType type) : _type(type) {};
125  virtual ~Asset();
126 
127  // Does any needed frame drawing, audio playing, event handlers, etc.
128  virtual void process() { return; }
129 
130  // Runs built-in bytecode methods.
131  virtual ScriptValue callMethod(BuiltInMethod methodId, Common::Array<ScriptValue> &args);
132 
133  virtual bool isSpatialActor() const { return false; }
134 
135  virtual void initFromParameterStream(Chunk &chunk);
136  virtual void readParameter(Chunk &chunk, AssetHeaderSectionType paramType);
137 
138  // These are not pure virtual so if an asset doesnʻt read any chunks or
139  // subfiles it doesnʻt need to just implement these with an error message.
140  virtual void readChunk(Chunk &chunk);
141  virtual void readSubfile(Subfile &subfile, Chunk &chunk);
142 
143  void processTimeEventHandlers();
144  void runEventHandlerIfExists(EventType eventType, const ScriptValue &arg);
145  void runEventHandlerIfExists(EventType eventType);
146 
147  AssetType type() const { return _type; }
148  uint id() const { return _id; }
149  uint contextId() const { return _contextId; }
150  void setId(uint id) { _id = id; }
151  void setContextId(uint id) { _contextId = id; }
152 
153  uint32 _chunkReference = 0;
154  uint _assetReference = 0;
155 
156 protected:
157  AssetType _type = kAssetTypeEmpty;
158  uint _id = 0;
159  uint _contextId = 0;
160 
161  uint _startTime = 0;
162  uint _lastProcessedTime = 0;
163  uint _duration = 0;
165 };
166 
167 class SpatialEntity : public Asset {
168 public:
169  SpatialEntity(AssetType type) : Asset(type) {};
170 
171  virtual void draw(const Common::Array<Common::Rect> &dirtyRegion) { return; }
172  virtual ScriptValue callMethod(BuiltInMethod methodId, Common::Array<ScriptValue> &args) override;
173  virtual void readParameter(Chunk &chunk, AssetHeaderSectionType paramType) override;
174 
175  virtual bool isSpatialActor() const override { return true; }
176  virtual bool isVisible() const { return _isVisible; }
177  virtual Common::Rect getBbox() const { return _boundingBox; }
178  int zIndex() const { return _zIndex; }
179 
180 protected:
181  uint _stageId = 0;
182  int _zIndex = 0;
183  double _dissolveFactor = 0.0;
184  Common::Rect _boundingBox;
185  bool _isVisible = false;
186  bool _hasTransparency = false;
187  bool _getOffstageEvents = false;
188 
189  void moveTo(int16 x, int16 y);
190  void moveToCentered(int16 x, int16 y);
191  void setBounds(const Common::Rect &bounds);
192  void setZIndex(int zIndex);
193 
194  virtual void setDissolveFactor(double dissolveFactor);
195  virtual void invalidateLocalBounds();
196  virtual void invalidateLocalZIndex();
197 };
198 
199 } // End of namespace MediaStation
200 
201 #endif
Definition: asset.h:167
Definition: asset.h:32
Definition: datafile.h:103
Definition: rect.h:524
Definition: asset.h:122
Definition: hashmap.h:85
Definition: datafile.h:129
Definition: scriptvalue.h:36