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