ScummVM API documentation
actor.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_ACTOR_H
23 #define MEDIASTATION_ACTOR_H
24 
25 #include "common/events.h"
26 #include "common/keyboard.h"
27 
28 #include "mediastation/datafile.h"
29 #include "mediastation/mediascript/scriptresponse.h"
30 #include "mediastation/mediascript/scriptconstants.h"
31 #include "mediastation/mediascript/scriptvalue.h"
32 
33 namespace MediaStation {
34 
35 class DisplayContext;
36 class SpatialEntity;
37 class StageActor;
38 
39 enum ActorType {
40  kActorTypeEmpty = 0x0000,
41  kActorTypeScreen = 0x0001, // SCR
42  kActorTypeStage = 0x0002, // STG
43  kActorTypePath = 0x0004, // PTH
44  kActorTypeSound = 0x0005, // SND
45  kActorTypeTimer = 0x0006, // TMR
46  kActorTypeImage = 0x0007, // IMG
47  kActorTypeHotspot = 0x000b, // HSP
48  kActorTypeSprite = 0x000e, // SPR
49  kActorTypeLKZazu = 0x000f,
50  kActorTypeLKConstellations = 0x0010,
51  kActorTypeDocument = 0x0011,
52  kActorTypeImageSet = 0x001d,
53  kActorTypeCursor = 0x000c, // CSR
54  kActorTypePrinter = 0x0019, // PRT
55  kActorTypeMovie = 0x0016, // MOV
56  kActorTypePalette = 0x0017,
57  kActorTypeStreamMovieProxy = 0x18,
58  kActorTypeText = 0x001a, // TXT
59  kActorTypeFont = 0x001b, // FON
60  kActorTypeCamera = 0x001c, // CAM
61  kActorTypeDiskImageActor = 0x001d,
62  kActorTypeCanvas = 0x001e, // CVS
63  kActorTypeXsnd = 0x001f,
64  kActorTypeXsndMidi = 0x0020,
65  kActorTypeRecorder = 0x0021,
66  kActorTypeFunction = 0x0069 // FUN
67 };
68 const char *actorTypeToStr(ActorType type);
69 
70 enum ActorHeaderSectionType {
71  kActorHeaderEmptySection = 0x0000,
72  kActorHeaderScriptResponse = 0x0017,
73  kActorHeaderChildActorId = 0x0019,
74  kActorHeaderActorId = 0x001a,
75  kActorHeaderChannelIdent = 0x001b,
76  kActorHeaderMovieAnimationChannelIdent = 0x06a4,
77  kActorHeaderMovieAudioChannelIdent = 0x06a5,
78  kActorHeaderActorReference = 0x077b,
79  kActorHeaderBoundingBox = 0x001c,
80  kActorHeaderMouseActiveArea = 0x001d,
81  kActorHeaderZIndex = 0x001e,
82  kActorHeaderStartup = 0x001f,
83  kActorHeaderTransparency = 0x0020,
84  kActorHeaderDiscardAfterUse = 0x0021,
85  kActorHeaderCursorResourceId = 0x0022,
86  kActorHeaderFrameRate = 0x0024,
87  kActorHeaderLoadType = 0x0032,
88  kActorHeaderSoundInfo = 0x0033,
89  kActorHeaderCachingEnabled = 0x0034,
90  kActorHeaderInstallType = 0x0037,
91  kActorHeaderSpriteChunkCount = 0x03e8,
92  kActorHeaderPalette = 0x05aa,
93  kActorHeaderDissolveFactor = 0x05dc,
94  kActorHeaderGetOffstageEvents = 0x05dd,
95  kActorHeaderX = 0x05de,
96  kActorHeaderY = 0x05df,
97  kActorHeaderScaleXAndY = 0x77a,
98  kActorHeaderScaleX = 0x77c,
99  kActorHeaderScaleY = 0x77d,
100  kActorHeaderActorName = 0x0bb8,
101  kStreamMovieProxyInfo = 0x06ac,
102 
103  // PATH FIELDS.
104  kActorHeaderStartPoint = 0x060e,
105  kActorHeaderEndPoint = 0x060f,
106  kActorHeaderPathTotalSteps = 0x0610,
107  kActorHeaderStepRate = 0x0611,
108  kActorHeaderDuration = 0x0612,
109 
110  // CAMERA FIELDS.
111  kActorHeaderCameraViewportOrigin = 0x076f,
112  kActorHeaderCameraLensOpen = 0x0770,
113  kActorHeaderCameraImageActor = 0x77b,
114 
115  // CANVAS FIELDS.
116  kActorHeaderCanvasDissolveFactor = 0x493,
117  kActorHeaderCanvasTransparency = 0x7d0,
118 
119  // STAGE FIELDS.
120  kActorHeaderStageExtent = 0x0771,
121  kActorHeaderCylindricalX = 0x0772,
122  kActorHeaderCylindricalY = 0x0773,
123 
124  // TEXT FIELDS.
125  kActorHeaderEditable = 0x03eb,
126  kActorHeaderFontActorId = 0x0258,
127  kActorHeaderInitialText = 0x0259,
128  kActorHeaderTextMaxLength = 0x25a,
129  kActorHeaderTextJustification = 0x025b,
130  kActorHeaderTextPosition = 0x25f,
131  kActorHeaderTextCursorIsVisible = 0x262,
132  kActorHeaderTextConstrainToWidth = 0x263,
133  kActorHeaderTextOverwriteMode = 0x264,
134  kActorHeaderTextAcceptedCharRange = 0x265,
135  kActorHeaderTextAcceptedCharRangeWithOffset = 0x0266,
136 
137  // SPRITE FIELDS.
138  kActorHeaderSpriteClip = 0x03e9,
139  kActorHeaderDefaultSpriteClip = 0x03ea
140 };
141 
142 enum CylindricalWrapMode : int;
143 
145  SpatialEntity *keyDown = nullptr;
146  // There is no key up event.
147  SpatialEntity *mouseDown = nullptr;
148  SpatialEntity *mouseUp = nullptr;
149  SpatialEntity *mouseMoved = nullptr;
150  SpatialEntity *mouseExit = nullptr;
151  SpatialEntity *mouseEnter = nullptr;
152  SpatialEntity *mouseOutOfFocus = nullptr;
153 };
154 
155 enum MouseEventFlag {
156  kNoFlag = 0x00,
157  kMouseDownFlag = 0x01,
158  kMouseUpFlag = 0x02,
159  kMouseMovedFlag = 0x04,
160  kMouseExitFlag = 0x10,
161  kMouseEnterFlag = 0x08,
162  kMouseUnk1Flag = 0x20,
163  kMouseOutOfFocusFlag = 0x40,
164  kKeyDownFlag = 0x80,
165  // There is no key up event.
166 };
167 
168 // Argument count validation macros for built-in script methods.
169 // For exact argument count.
170 #define ARGCOUNTCHECK(n) \
171  if (args.size() != (n)) { \
172  warning("%s: Expected %d arguments, got %d", builtInMethodToStr(methodId), (n), args.size()); \
173  }
174 
175 // For a range of valid argument counts (min to max).
176 #define ARGCOUNTRANGE(min, max) \
177  if ((int64)(min) > args.size() || args.size() > (int64)(max)) { \
178  warning("%s: Expected %d to %d arguments, got %d", builtInMethodToStr(methodId), (min), (max), args.size()); \
179  }
180 
181 // For minimum argument count (no maximum).
182 #define ARGCOUNTMIN(min) \
183  if (args.size() < (min)) { \
184  warning("%s: Expected at least %d arguments, got %d", builtInMethodToStr(methodId), (min), args.size()); \
185  }
186 
187 class Actor {
188 public:
189  Actor(ActorType type) : _type(type) {};
190  virtual ~Actor();
191 
192  // Does any needed frame drawing, audio playing, script responses, etc.
193  virtual void process() { return; }
194 
195  // Runs built-in bytecode methods.
196  virtual ScriptValue callMethod(BuiltInMethod methodId, Common::Array<ScriptValue> &args);
197 
198  virtual bool isSpatialActor() const { return false; }
199 
200  virtual void initFromParameterStream(Chunk &chunk);
201  virtual void readParameter(Chunk &chunk, ActorHeaderSectionType paramType);
202  virtual void loadIsComplete();
203 
204  void processTimeScriptResponses();
205  void runScriptResponseIfExists(EventType eventType, const ScriptValue &arg);
206  void runScriptResponseIfExists(EventType eventType);
207 
208  ActorType type() const { return _type; }
209  uint id() const { return _id; }
210  uint contextId() const { return _contextId; }
211  void setId(uint id);
212  void setContextId(uint id) { _contextId = id; }
213  const char *debugName() const;
214  void updateDebugName();
215 
216 protected:
217  ActorType _type = kActorTypeEmpty;
218  bool _loadIsComplete = false;
219  uint _id = 0;
220  uint _contextId = 0;
221  Common::String _debugName;
222 
223  uint _startTime = 0;
224  uint _lastProcessedTime = 0;
225  uint _duration = 0;
227 };
228 
229 class SpatialEntity : public Actor {
230 public:
231  SpatialEntity(ActorType type) : Actor(type) {};
232  ~SpatialEntity();
233 
234  virtual void draw(DisplayContext &displayContext) { return; }
235  virtual ScriptValue callMethod(BuiltInMethod methodId, Common::Array<ScriptValue> &args) override;
236  virtual void readParameter(Chunk &chunk, ActorHeaderSectionType paramType) override;
237  virtual void loadIsComplete() override;
238  virtual void preload(const Common::Rect &rect) {};
239  virtual bool isRectInMemory(const Common::Rect &rect) { return true; }
240  virtual bool isLoading() { return false; }
241 
242  virtual bool isSpatialActor() const override { return true; }
243  virtual bool isVisible() const { return _isVisible; }
244  virtual Common::Rect getBbox() const { return _boundingBox; }
245  int zIndex() const { return _zIndex; }
246  void moveTo(int16 x, int16 y);
247 
248  virtual void currentMousePosition(Common::Point &point);
249  virtual void invalidateMouse();
250  virtual bool interactsWithMouse() const { return false; }
251 
252  virtual uint16 findActorToAcceptMouseEvents(
253  const Common::Point &point,
254  uint16 eventMask,
255  MouseActorState &state,
256  bool inBounds) { return kNoFlag; }
257  virtual uint16 findActorToAcceptKeyboardEvents(
258  uint16 asciiCode,
259  uint16 eventMask,
260  MouseActorState &state) { return kNoFlag; }
261 
262  virtual void mouseDownEvent(const Common::Event &event) { return; }
263  virtual void mouseUpEvent(const Common::Event &event) { return; }
264  virtual void mouseEnteredEvent(const Common::Event &event) { return; }
265  virtual void mouseExitedEvent(const Common::Event &event) { return; }
266  virtual void mouseMovedEvent(const Common::Event &event) { return; }
267  virtual void mouseOutOfFocusEvent(const Common::Event &event) { return; }
268  virtual void keyboardEvent(const Common::Event &event) { return; }
269 
270  void setParentStage(StageActor *parentStage) { _parentStage = parentStage; }
271  void setToNoParentStage() { _parentStage = nullptr; }
272  StageActor *getParentStage() const { return _parentStage; }
273 
274  virtual void invalidateLocalBounds();
275  virtual void setAdjustedBounds(CylindricalWrapMode alignmentMode);
276 
277 protected:
278  uint _stageId = 0;
279  int _zIndex = 0;
280  double _dissolveFactor = 1.0;
281  double _scaleX = 0.0;
282  double _scaleY = 0.0;
283  Common::Rect _boundingBox;
284  Common::Rect _originalBoundingBox;
285  bool _isVisible = false;
286  bool _hasTransparency = false;
287  bool _getOffstageEvents = false;
288  StageActor *_parentStage = nullptr;
289 
290  void moveToCentered(int16 x, int16 y);
291  void setBounds(const Common::Rect &bounds);
292  void setZIndex(int zIndex);
293  virtual void setMousePosition(int16 x, int16 y);
294 
295  virtual void setDissolveFactor(double dissolveFactor);
296  virtual void invalidateLocalZIndex();
297 };
298 
299 } // End of namespace MediaStation
300 
301 #endif
Definition: str.h:59
Definition: actor.h:144
Definition: actor.h:229
Definition: actor.h:33
Definition: datafile.h:102
Definition: stage.h:49
Definition: rect.h:524
Definition: graphics.h:100
Definition: hashmap.h:85
Definition: events.h:210
Definition: rect.h:144
Definition: actor.h:187
Definition: scriptvalue.h:35