ScummVM API documentation
runtime.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 MTROPOLIS_RUNTIME_H
23 #define MTROPOLIS_RUNTIME_H
24 
25 #include "common/archive.h"
26 #include "common/array.h"
27 #include "common/events.h"
28 #include "common/language.h"
29 #include "common/platform.h"
30 #include "common/ptr.h"
31 #include "common/stream.h"
32 #include "common/hashmap.h"
33 #include "common/hash-str.h"
34 
35 #include "graphics/pixelformat.h"
36 
37 #include "mtropolis/actions.h"
38 #include "mtropolis/core.h"
39 #include "mtropolis/coroutine_protos.h"
40 #include "mtropolis/data.h"
41 #include "mtropolis/debug.h"
42 #include "mtropolis/hacks.h"
43 #include "mtropolis/miniscript_protos.h"
44 #include "mtropolis/subtitles.h"
45 #include "mtropolis/vthread.h"
46 
47 class OSystem;
48 
49 namespace Audio {
50 
51 class Mixer;
52 
53 } // End of namespace Audio
54 
55 namespace Common {
56 
57 class RandomSource;
58 
59 } // End of namespace Common
60 
61 namespace Graphics {
62 
63 struct WinCursorGroup;
64 class MacCursor;
65 class MacFontManager;
66 class ManagedSurface;
67 class Cursor;
68 struct PixelFormat;
69 struct Surface;
70 
71 } // End of namespace Graphics
72 
73 namespace MTropolis {
74 
75 class Asset;
76 class AssetManagerInterface;
77 class CoroutineManager;
78 class CursorGraphic;
79 class CursorGraphicCollection;
80 class Element;
81 class GraphicModifier;
82 class KeyboardInputEvent;
83 class MessageDispatch;
84 class MiniscriptThread;
85 class Modifier;
86 class ObjectLinkingScope;
87 class PlugInModifier;
88 class RuntimeObject;
89 class PlugIn;
90 class Project;
91 class Runtime;
92 class Structural;
93 class SystemInterface;
94 class VisualElement;
95 class Window;
96 class WorldManagerInterface;
97 struct DynamicValue;
98 struct DynamicValueWriteProxy;
99 struct IBoundaryDetector;
100 struct ICollider;
101 struct ILoadUIProvider;
102 struct IMessageConsumer;
103 struct IModifierContainer;
104 struct IPlugInModifierFactory;
105 struct IPlugInModifierFactoryAndDataFactory;
106 struct IPostEffect;
107 struct ISaveUIProvider;
108 struct ISaveWriter;
109 struct IStructuralReferenceVisitor;
110 struct MessageProperties;
111 struct ModifierLoaderContext;
112 struct PlugInModifierLoaderContext;
113 struct SIModifierFactory;
114 template<typename TElement, typename TElementData> class ElementFactory;
115 
116 #ifdef MTROPOLIS_DEBUG_ENABLE
118 #endif
119 
120 char invariantToLower(char c);
121 Common::String toCaseInsensitive(const Common::String &str);
122 bool caseInsensitiveEqual(const Common::String &str1, const Common::String &str2);
123 size_t caseInsensitiveFind(const Common::String &stringToSearch, const Common::String &stringToFind);
124 
125 enum ColorDepthMode {
126  kColorDepthMode1Bit,
127  kColorDepthMode2Bit,
128  kColorDepthMode4Bit,
129  kColorDepthMode8Bit,
130  kColorDepthMode16Bit,
131  kColorDepthMode32Bit,
132 
133  kColorDepthModeCount,
134 
135  kColorDepthModeInvalid,
136 };
137 
138 namespace SceneTransitionTypes {
139 
140 enum SceneTransitionType {
141  kNone,
142  kPatternDissolve,
143  kRandomDissolve, // No steps
144  kFade,
145  kSlide, // Directional
146  kPush, // Directional
147  kZoom,
148  kWipe, // Directional
149 };
150 
151 bool loadFromData(SceneTransitionType &transType, int32 data);
152 
153 } // End of namespace SceneTransitionTypes
154 
155 namespace SceneTransitionDirections {
156 
157 enum SceneTransitionDirection {
158  kUp,
159  kDown,
160  kLeft,
161  kRight,
162 };
163 
164 bool loadFromData(SceneTransitionDirection &transDir, int32 data);
165 
166 } // End of namespace SceneTransitionDirections
167 
168 enum ConstraintDirection {
169  kConstraintDirectionNone,
170  kConstraintDirectionHorizontal,
171  kConstraintDirectionVertical,
172 };
173 
174 enum MouseInteractivityTestType {
175  kMouseInteractivityTestAnything,
176  kMouseInteractivityTestMouseClick,
177 };
178 
179 namespace DynamicValueSourceTypes {
180  enum DynamicValueSourceType {
181  kInvalid,
182 
183  kConstant,
184  kVariableReference,
185  kIncomingData,
186  };
187 }
188 
189 namespace DynamicValueTypes {
190 
191 // These values are stored in the saved game format, so they must be stable
192 enum DynamicValueType {
193  kInvalid = 0,
194 
195  kNull = 1,
196  kInteger = 2,
197  kFloat = 3,
198  kPoint = 4,
199  kIntegerRange = 5,
200  kBoolean = 6,
201  kVector = 7,
202  kLabel = 8,
203  kEvent = 9,
204 
205  kString = 12,
206  kList = 13,
207  kObject = 14,
208  kWriteProxy = 15,
209 
210  kUnspecified = 16,
211 };
212 
213 } // End of namespace DynamicValuesTypes
214 
215 namespace AttributeIDs {
216 
217 enum AttributeID {
218  kAttribCache = 55,
219  kAttribDirect = 56,
220  kAttribVisible = 58,
221  kAttribLayer = 24,
222  kAttribPaused = 25,
223  kAttribLoop = 57,
224  kAttribPosition = 1,
225  kAttribWidth = 2,
226  kAttribHeight = 3,
227  kAttribRate = 4,
228  kAttribRange = 5,
229  kAttribCel = 6,
230  kAttribLoopBackForth = 59,
231  kAttribPlayEveryFrame = 60,
232  kAttribTimeValue = 16,
233  kAttribTrackDisable = 51,
234  kAttribTrackEnable = 50,
235  kAttribVolume = 13,
236  kAttribBalance = 26,
237  kAttribText = 7,
238  kAttribMasterVolume = 18,
239  kAttribUserTimeout = 19,
240 };
241 
242 } // End of namespace AttributeIDs
243 
244 namespace EventIDs {
245 
246 enum EventID {
247  kNothing = 0,
248 
249  kElementEnableEdit = 207,
250  kElementDisableEdit = 220,
251  kElementSelect = 209,
252  kElementDeselect = 210,
253  kElementToggleSelect = 213,
254  kElementUpdatedCalculated = 219,
255  kElementShow = 222,
256  kElementHide = 223,
257 
258  kElementScrollUp = 1001,
259  kElementScrollDown = 1002,
260  kElementScrollRight = 1005,
261  kElementScrollLeft = 1006,
262 
263  kMotionStarted = 501,
264  kMotionEnded = 502,
265 
266  kTransitionStarted = 503,
267  kTransitionEnded = 504,
268 
269  kMouseDown = 301,
270  kMouseUp = 302,
271  kMouseOver = 303,
272  kMouseOutside = 304,
273  kMouseTrackedInside = 305,
274  kMouseTrackedOutside = 306,
275  kMouseTracking = 307,
276  kMouseUpInside = 309,
277  kMouseUpOutside = 310,
278 
279  kSceneStarted = 101,
280  kSceneEnded = 102,
281  kSceneDeactivated = 103,
282  kSceneReactivated = 104,
283  kSceneTransitionEnded = 506,
284 
285  kSharedSceneReturnedToScene = 401,
286  kSharedSceneSceneChanged = 402,
287  kSharedSceneNoNextScene = 403,
288  kSharedSceneNoPrevScene = 404,
289 
290  kParentEnabled = 2001,
291  kParentDisabled = 2002,
292  kParentChanged = 227,
293 
294  kPreloadMedia = 1701,
295  kFlushMedia = 1703,
296  kPrerollMedia = 1704,
297 
298  kCloseProject = 1601,
299 
300  kUserTimeout = 1801,
301  kProjectStarted = 1802,
302  kProjectEnded = 1803,
303  kFlushAllMedia = 1804,
304 
305  kAttribGet = 1300,
306  kAttribSet = 1200,
307 
308  kClone = 226,
309  kKill = 228,
310 
311  kPlay = 201,
312  kStop = 202,
313  kPause = 801,
314  kUnpause = 802,
315  kTogglePause = 803,
316  kAtFirstCel = 804,
317  kAtLastCel = 805,
318 
319 
320  kAuthorMessage = 900,
321 };
322 
323 bool isCommand(EventID eventID);
324 
325 } // End of namespace EventIDs
326 
327 MiniscriptInstructionOutcome pointWriteRefAttrib(Common::Point &point, MiniscriptThread *thread, DynamicValueWriteProxy &proxy, const Common::String &attrib);
328 Common::String pointToString(const Common::Point &point);
329 
330 struct IntRange {
331  IntRange();
332  IntRange(int32 pmin, int32 pmax);
333 
334  int32 min;
335  int32 max;
336 
337  bool load(const Data::IntRange &range);
338 
339  inline bool operator==(const IntRange &other) const {
340  return min == other.min && max == other.max;
341  }
342 
343  inline bool operator!=(const IntRange &other) const {
344  return !((*this) == other);
345  }
346 
347  MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, const Common::String &attrib);
348  Common::String toString() const;
349 };
350 
351 struct Label {
352  Label();
353  Label(int32 psuperGroupID, int32 pid);
354 
355  uint32 superGroupID;
356  uint32 id;
357 
358  bool load(const Data::Label &label);
359 
360  inline bool operator==(const Label &other) const {
361  return superGroupID == other.superGroupID && id == other.id;
362  }
363 
364  inline bool operator!=(const Label &other) const {
365  return !((*this) == other);
366  }
367 };
368 
369 struct Event {
370  Event();
371  Event(EventIDs::EventID peventType, uint32 peventInfo);
372 
373  EventIDs::EventID eventType;
374  uint32 eventInfo;
375 
376  // Returns true if this event, interpreted as a filter, recognizes another event.
377  // Handles cases where eventInfo is ignored (hopefully).
378  bool respondsTo(const Event &otherEvent) const;
379 
380  bool load(const Data::Event &data);
381 
382  inline bool operator==(const Event &other) const {
383  return eventType == other.eventType && eventInfo == other.eventInfo;
384  }
385 
386  inline bool operator!=(const Event &other) const {
387  return !((*this) == other);
388  }
389 };
390 
391 struct VarReference {
392  VarReference();
393  VarReference(uint32 pguid, const Common::String &psource);
394 
395  uint32 guid;
396  Common::String source;
397  Common::WeakPtr<Modifier> resolution; // NOTE: This may not be a variable
398 
399  inline bool operator==(const VarReference &other) const {
400  return guid == other.guid && source == other.source;
401  }
402 
403  inline bool operator!=(const VarReference &other) const {
404  return !((*this) == other);
405  }
406 
407  bool resolve(Structural *structuralScope, Common::WeakPtr<RuntimeObject> &outObject) const;
408  bool resolve(Modifier *modifierScope, Common::WeakPtr<RuntimeObject> &outObject) const;
409 
410  void linkInternalReferences(ObjectLinkingScope *scope);
411  void visitInternalReferences(IStructuralReferenceVisitor *visitor);
412 
413 private:
414  bool resolveContainer(IModifierContainer *modifierContainer, Common::WeakPtr<RuntimeObject> &outObject) const;
415  bool resolveSingleModifier(Modifier *modifier, Common::WeakPtr<RuntimeObject> &outObject) const;
416 };
417 
420 
421  inline ObjectReference() {
422  }
423 
424  inline explicit ObjectReference(const Common::WeakPtr<RuntimeObject> &objectPtr) : object(objectPtr) {
425  }
426 
427  inline bool operator==(const ObjectReference &other) const {
428  return !object.owner_before(other.object) && !other.object.owner_before(object);
429  }
430 
431  inline bool operator!=(const ObjectReference &other) const {
432  return !((*this) == other);
433  }
434 
435  inline void reset() {
436  object.reset();
437  }
438 };
439 
441  AngleMagVector();
442 
443  double angleDegrees; // These are stored as radians in the data but scripts treat them as degrees so it's just pointless constantly doing conversion...
444  double magnitude;
445 
446  inline bool operator==(const AngleMagVector &other) const {
447  return angleDegrees == other.angleDegrees && magnitude == other.magnitude;
448  }
449 
450  inline bool operator!=(const AngleMagVector &other) const {
451  return !((*this) == other);
452  }
453 
454  inline static AngleMagVector createRadians(double angleRadians, double magnitude) {
455  return AngleMagVector(angleRadians * (180.0 / M_PI), magnitude);
456  }
457 
458  inline static AngleMagVector createDegrees(double angleDegrees, double magnitude) {
459  return AngleMagVector(angleDegrees, magnitude);
460  }
461 
462  MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, const Common::String &attrib);
463  Common::String toString() const;
464 
465 private:
466  AngleMagVector(double angleDegrees, double magnitude);
467 };
468 
469 struct ColorRGB8 {
470  ColorRGB8();
471  ColorRGB8(uint8 pr, uint8 pg, uint8 pb);
472 
473  uint8 r;
474  uint8 g;
475  uint8 b;
476 
477  bool load(const Data::ColorRGB16 &color);
478 
479  inline bool operator==(const ColorRGB8 &other) const {
480  return r == other.r && g == other.g && b == other.b;
481  }
482 
483  inline bool operator!=(const ColorRGB8 &other) const {
484  return !((*this) == other);
485  }
486 };
487 
488 struct MessageFlags {
489  MessageFlags();
490 
491  bool relay : 1;
492  bool cascade : 1;
493  bool immediate : 1;
494 };
495 
496 struct DynamicValue;
497 struct DynamicList;
498 
499 // This should be an interface, but since this exists to make global singletons that JUST supply a vtable,
500 // GCC complains about there being a global destructor, unless we delete the destructor, in which case
501 // it complains about a class having virtual functions but not having a virtual destructor, so we have to
502 // do this dispatch table stuff just to make GCC be quiet.
504  typedef MiniscriptInstructionOutcome (*writeFunc_t)(MiniscriptThread *thread, const DynamicValue &dest, void *objectRef, uintptr ptrOrOffset);
505  typedef MiniscriptInstructionOutcome (*refAttribFunc_t)(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib);
506  typedef MiniscriptInstructionOutcome (*refAttribIndexedFunc_t)(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib, const DynamicValue &index);
507 
508  writeFunc_t write;
509  refAttribFunc_t refAttrib;
510  refAttribIndexedFunc_t refAttribIndexed;
511 };
512 
513 template<class T>
515 public:
516  static const DynamicValueWriteInterface *getInstance();
517 
518 private:
519  static DynamicValueWriteInterface _instance;
520 };
521 
522 template<class T>
524  return &_instance;
525 }
526 
527 template<class T>
529  static_cast<DynamicValueWriteInterface::writeFunc_t>(T::write),
530  static_cast<DynamicValueWriteInterface::refAttribFunc_t>(T::refAttrib),
531  static_cast<DynamicValueWriteInterface::refAttribIndexedFunc_t>(T::refAttribIndexed),
532 };
533 
534 
535 
537  uintptr ptrOrOffset;
538  void *objectRef;
539  const DynamicValueWriteInterface *ifc;
540 
541  static DynamicValueWriteProxyPOD createDefault();
542 };
543 
546 
548  Common::SharedPtr<DynamicList> containerList;
549 };
550 
551 struct Point16POD {
552  int16 x;
553  int16 y;
554 
555  Common::Point toScummVMPoint() const;
556 };
557 
558 
560 public:
561  virtual ~DynamicListContainerBase();
562  virtual bool setAtIndex(size_t index, const DynamicValue &dynValue) = 0;
563  virtual bool getAtIndex(size_t index, DynamicValue &dynValue) const = 0;
564  virtual void truncateToSize(size_t sz) = 0;
565  virtual bool expandToMinimumSize(size_t sz) = 0;
566  virtual void setFrom(const DynamicListContainerBase &other) = 0; // Only supports setting same type!
567  virtual const void *getConstArrayPtr() const = 0;
568  virtual void *getArrayPtr() = 0;
569  virtual size_t getSize() const = 0;
570  virtual bool compareEqual(const DynamicListContainerBase &other) const = 0;
571  virtual DynamicListContainerBase *clone() const = 0;
572 };
573 
575  static void defaultSet(int32 &value);
576  static void defaultSet(double &value);
577  static void defaultSet(Common::Point &value);
578  static void defaultSet(IntRange &value);
579  static void defaultSet(bool &value);
580  static void defaultSet(AngleMagVector &value);
581  static void defaultSet(Label &value);
582  static void defaultSet(Event &value);
583  static void defaultSet(Common::String &value);
584  static void defaultSet(Common::SharedPtr<DynamicList> &value);
585  static void defaultSet(ObjectReference &value);
586 };
587 
588 template<class T>
590  typedef T DynamicValuePODType_t;
591 
592  static const T &dereference(const T *source) { return *source; }
593 };
594 
596  static bool importValue(const DynamicValue &dynValue, const int32 *&outPtr);
597  static bool importValue(const DynamicValue &dynValue, const double *&outPtr);
598  static bool importValue(const DynamicValue &dynValue, const Common::Point *&outPtr);
599  static bool importValue(const DynamicValue &dynValue, const IntRange *&outPtr);
600  static bool importValue(const DynamicValue &dynValue, const bool *&outPtr);
601  static bool importValue(const DynamicValue &dynValue, const AngleMagVector *&outPtr);
602  static bool importValue(const DynamicValue &dynValue, const Label *&outPtr);
603  static bool importValue(const DynamicValue &dynValue, const Event *&outPtr);
604  static bool importValue(const DynamicValue &dynValue, const Common::String *&outPtr);
605  static bool importValue(const DynamicValue &dynValue, const Common::SharedPtr<DynamicList> *&outPtr);
606  static bool importValue(const DynamicValue &dynValue, const ObjectReference *&outPtr);
607 };
608 
610  static void exportValue(DynamicValue &dynValue, const int32 &value);
611  static void exportValue(DynamicValue &dynValue, const double &value);
612  static void exportValue(DynamicValue &dynValue, const Common::Point &value);
613  static void exportValue(DynamicValue &dynValue, const IntRange &value);
614  static void exportValue(DynamicValue &dynValue, const bool &value);
615  static void exportValue(DynamicValue &dynValue, const AngleMagVector &value);
616  static void exportValue(DynamicValue &dynValue, const Label &value);
617  static void exportValue(DynamicValue &dynValue, const Event &value);
618  static void exportValue(DynamicValue &dynValue, const Common::String &value);
619  static void exportValue(DynamicValue &dynValue, const Common::SharedPtr<DynamicList> &value);
620  static void exportValue(DynamicValue &dynValue, const ObjectReference &value);
621 };
622 
623 template<class T>
625 public:
626  bool setAtIndex(size_t index, const DynamicValue &dynValue) override;
627  bool getAtIndex(size_t index, DynamicValue &dynValue) const override;
628  void truncateToSize(size_t sz) override;
629  bool expandToMinimumSize(size_t sz) override;
630  void setFrom(const DynamicListContainerBase &other) override;
631  const void *getConstArrayPtr() const override;
632  void *getArrayPtr() override;
633  size_t getSize() const override;
634  bool compareEqual(const DynamicListContainerBase &other) const override;
635  DynamicListContainerBase *clone() const override;
636 
637 private:
638  Common::Array<T> _array;
639 };
640 
641 template<>
643 public:
645 
646  bool setAtIndex(size_t index, const DynamicValue &dynValue) override;
647  bool getAtIndex(size_t index, DynamicValue &dynValue) const override;
648  void truncateToSize(size_t sz) override;
649  bool expandToMinimumSize(size_t sz) override;
650  void setFrom(const DynamicListContainerBase &other) override;
651  const void *getConstArrayPtr() const override;
652  void *getArrayPtr() override;
653  size_t getSize() const override;
654  bool compareEqual(const DynamicListContainerBase &other) const override;
655  DynamicListContainerBase *clone() const override;
656 
657 public:
658  size_t _size;
659 };
660 
661 template<class T>
662 bool DynamicListContainer<T>::setAtIndex(size_t index, const DynamicValue &dynValue) {
663  const typename DynamicListValueConverter<T>::DynamicValuePODType_t *valuePtr = nullptr;
664  if (!DynamicListValueImporter::importValue(dynValue, valuePtr))
665  return false;
666 
667  _array.reserve(index + 1);
668  if (_array.size() <= index) {
669  if (_array.size() < index) {
670  T defaultValue;
671  DynamicListDefaultSetter::defaultSet(defaultValue);
672  while (_array.size() < index) {
673  _array.push_back(defaultValue);
674  }
675  }
676  _array.push_back(DynamicListValueConverter<T>::dereference(valuePtr));
677  } else {
678  _array[index] = DynamicListValueConverter<T>::dereference(valuePtr);
679  }
680 
681  return true;
682 }
683 
684 template<class T>
686  if (_array.size() > sz)
687  _array.resize(sz);
688 }
689 
690 template<class T>
692  _array.reserve(sz);
693  if (_array.size() < sz) {
694  T defaultValue;
695  DynamicListDefaultSetter::defaultSet(defaultValue);
696  while (_array.size() < sz) {
697  _array.push_back(defaultValue);
698  }
699  }
700 
701  return true;
702 }
703 
704 template<class T>
705 bool DynamicListContainer<T>::getAtIndex(size_t index, DynamicValue &dynValue) const {
706  if (index >= _array.size())
707  return false;
708 
709  DynamicListValueExporter::exportValue(dynValue, _array[index]);
710  return true;
711 }
712 
713 template<class T>
715  _array = static_cast<const DynamicListContainer<T> &>(other)._array;
716 }
717 
718 template<class T>
719 const void *DynamicListContainer<T>::getConstArrayPtr() const {
720  return &_array;
721 }
722 
723 template<class T>
725  return &_array;
726 }
727 
728 template<class T>
729 size_t DynamicListContainer<T>::getSize() const {
730  return _array.size();
731 }
732 
733 template<class T>
735  const DynamicListContainer<T> &otherTyped = static_cast<const DynamicListContainer<T> &>(other);
736  return _array == otherTyped._array;
737 }
738 
739 template<class T>
741  return new DynamicListContainer<T>(*this);
742 }
743 
744 struct DynamicList {
745  DynamicList();
746  DynamicList(const DynamicList &other);
747  ~DynamicList();
748 
749  DynamicValueTypes::DynamicValueType getType() const;
750 
751  const Common::Array<int32> &getInt() const;
752  const Common::Array<double> &getFloat() const;
753  const Common::Array<Common::Point> &getPoint() const;
754  const Common::Array<IntRange> &getIntRange() const;
755  const Common::Array<AngleMagVector> &getVector() const;
756  const Common::Array<Label> &getLabel() const;
757  const Common::Array<Event> &getEvent() const;
758  const Common::Array<Common::String> &getString() const;
759  const Common::Array<bool> &getBool() const;
760  const Common::Array<Common::SharedPtr<DynamicList> > &getList() const;
761  const Common::Array<ObjectReference> &getObjectReference() const;
762 
763  Common::Array<int32> &getInt();
764  Common::Array<double> &getFloat();
765  Common::Array<Common::Point> &getPoint();
766  Common::Array<IntRange> &getIntRange();
767  Common::Array<AngleMagVector> &getVector();
768  Common::Array<Label> &getLabel();
769  Common::Array<Event> &getEvent();
770  Common::Array<Common::String> &getString();
771  Common::Array<bool> &getBool();
773  Common::Array<ObjectReference> &getObjectReference();
774 
775  bool getAtIndex(size_t index, DynamicValue &value) const;
776  bool setAtIndex(size_t index, const DynamicValue &value);
777  void deleteAtIndex(size_t index);
778  void truncateToSize(size_t sz);
779  void expandToMinimumSize(size_t sz);
780  size_t getSize() const;
781 
782  void forceType(DynamicValueTypes::DynamicValueType type);
783 
784  static bool dynamicValueToIndex(size_t &outIndex, const DynamicValue &value);
785 
786  DynamicList &operator=(const DynamicList &other);
787 
788  bool operator==(const DynamicList &other) const;
789  inline bool operator!=(const DynamicList &other) const {
790  return !((*this) == other);
791  }
792 
793  void swap(DynamicList &other);
794 
795  Common::SharedPtr<DynamicList> clone() const;
796 
797  void createWriteProxyForIndex(size_t index, DynamicValueWriteProxy &proxy);
798 
799 private:
800  struct WriteProxyInterface {
801  static MiniscriptInstructionOutcome write(MiniscriptThread *thread, const DynamicValue &dest, void *objectRef, uintptr ptrOrOffset);
802  static MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib);
803  static MiniscriptInstructionOutcome refAttribIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib, const DynamicValue &index);
804  };
805 
806  void initFromOther(const DynamicList &other);
807  void destroyContainer();
808  bool createContainerAndSetType(DynamicValueTypes::DynamicValueType type);
809 
810  DynamicValueTypes::DynamicValueType _type;
811  DynamicListContainerBase *_container;
812 };
813 
814 // Dynamic value container. Somewhat importantly, lists stored in dynamic values
815 // are BY REFERENCE and must be cloned as necessary.
816 struct DynamicValue {
817  DynamicValue();
818  DynamicValue(const DynamicValue &other);
819  ~DynamicValue();
820 
821  bool loadConstant(const Data::InternalTypeTaggedValue &data, const Common::String &varString);
822  bool loadConstant(const Data::PlugInTypeTaggedValue &data);
823 
824  DynamicValueTypes::DynamicValueType getType() const;
825 
826  const int32 &getInt() const;
827  const double &getFloat() const;
828  const Common::Point &getPoint() const;
829  const IntRange &getIntRange() const;
830  const AngleMagVector &getVector() const;
831  const Label &getLabel() const;
832  const Event &getEvent() const;
833  const Common::String &getString() const;
834  const bool &getBool() const;
835  const Common::SharedPtr<DynamicList> &getList() const;
836  const ObjectReference &getObject() const;
837  const DynamicValueWriteProxy &getWriteProxy() const;
838 
839  void clear();
840 
841  void setInt(int32 value);
842  void setFloat(double value);
843  void setPoint(const Common::Point &value);
844  void setIntRange(const IntRange &value);
845  void setVector(const AngleMagVector &value);
846  void setLabel(const Label &value);
847  void setEvent(const Event &value);
848  void setString(const Common::String &value);
849  void setBool(bool value);
850  void setList(const Common::SharedPtr<DynamicList> &value);
851  void setObject(const ObjectReference &value);
852  void setObject(const Common::WeakPtr<RuntimeObject> &value);
853  void setWriteProxy(const DynamicValueWriteProxy &writeProxy);
854 
855  bool roundToInt(int32 &outInt) const;
856 
857  bool convertToType(DynamicValueTypes::DynamicValueType targetType, DynamicValue &result) const;
858 
859  DynamicValue dereference() const;
860 
861  DynamicValue &operator=(const DynamicValue &other);
862 
863  bool operator==(const DynamicValue &other) const;
864  inline bool operator!=(const DynamicValue &other) const {
865  return !((*this) == other);
866  }
867 
868 private:
869  union ValueUnion {
870  ValueUnion();
871  ~ValueUnion();
872 
873  double asFloat;
874  int32 asInt;
875  IntRange asIntRange;
876  AngleMagVector asVector;
877  Label asLabel;
878  Event asEvent;
879  Common::Point asPoint;
880  bool asBool;
881  DynamicValueWriteProxy asWriteProxy;
882  Common::String asString;
884  ObjectReference asObj;
885 
886  uint64 asUnset;
887 
888  template<class T, T(ValueUnion::*TMember)>
889  void construct(const T &value);
890 
891  template<class T, T(ValueUnion::*TMember)>
892  void construct(T &&value);
893 
894  template<class T, T(ValueUnion::*TMember)>
895  void assign(const T &value);
896 
897  template<class T, T(ValueUnion::*TMember)>
898  void assign(T &&value);
899 
900  template<class T, T(ValueUnion::*TMember)>
901  void destruct();
902  };
903 
904  template<class T>
905  void internalSwap(T &a, T &b) {
906  T temp = a;
907  a = b;
908  b = temp;
909  }
910 
911  bool convertIntToType(DynamicValueTypes::DynamicValueType targetType, DynamicValue &result) const;
912  bool convertFloatToType(DynamicValueTypes::DynamicValueType targetType, DynamicValue &result) const;
913  bool convertBoolToType(DynamicValueTypes::DynamicValueType targetType, DynamicValue &result) const;
914  bool convertStringToType(DynamicValueTypes::DynamicValueType targetType, DynamicValue &result) const;
915 
916  bool convertToTypeNoDereference(DynamicValueTypes::DynamicValueType targetType, DynamicValue &result) const;
917 
918  void setFromOther(const DynamicValue &other);
919  void setFromOther(DynamicValue &&other);
920 
921  DynamicValueTypes::DynamicValueType _type;
922  ValueUnion _value;
923 };
924 
930 
931  DynamicValueSource &operator=(const DynamicValueSource &other);
932  DynamicValueSource &operator=(DynamicValueSource &&other);
933 
934  DynamicValueSourceTypes::DynamicValueSourceType getSourceType() const;
935  const DynamicValue &getConstant() const;
936  const VarReference &getVarReference() const;
937 
938  bool load(const Data::InternalTypeTaggedValue &data, const Common::String &varSource, const Common::String &varString);
939  bool load(const Data::PlugInTypeTaggedValue &data);
940 
941  void linkInternalReferences(ObjectLinkingScope *scope);
942  void visitInternalReferences(IStructuralReferenceVisitor *visitor);
943 
944  DynamicValue produceValue(const DynamicValue &incomingData) const;
945 
946 private:
947  union ValueUnion {
948  ValueUnion();
949  ~ValueUnion();
950 
951  DynamicValue _constValue;
952  VarReference _varReference;
953  };
954 
955  void destructValue();
956  void initFromOther(const DynamicValueSource &other);
957  void initFromOther(DynamicValueSource &&other);
958 
959  DynamicValueSourceTypes::DynamicValueSourceType _sourceType;
960  ValueUnion _valueUnion;
961 };
962 
963 template<class TFloat>
965  static MiniscriptInstructionOutcome write(MiniscriptThread *thread, const DynamicValue &value, void *objectRef, uintptr ptrOrOffset) {
966  DynamicValue derefValue = value.dereference();
967 
968  TFloat &dest = *static_cast<TFloat *>(objectRef);
969  switch (derefValue.getType()) {
970  case DynamicValueTypes::kFloat:
971  dest = static_cast<TFloat>(derefValue.getFloat());
972  return kMiniscriptInstructionOutcomeContinue;
973  case DynamicValueTypes::kInteger:
974  dest = static_cast<TFloat>(derefValue.getInt());
975  return kMiniscriptInstructionOutcomeContinue;
976  default:
977  return kMiniscriptInstructionOutcomeFailed;
978  }
979  }
980  static MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib) {
981  return kMiniscriptInstructionOutcomeFailed;
982  }
983  static MiniscriptInstructionOutcome refAttribIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib, const DynamicValue &index) {
984  return kMiniscriptInstructionOutcomeFailed;
985  }
986 
987  static void create(TFloat *floatValue, DynamicValueWriteProxy &proxy) {
988  proxy.pod.ptrOrOffset = 0;
989  proxy.pod.objectRef = floatValue;
991  }
992 };
993 
994 template<class TInteger>
996  static MiniscriptInstructionOutcome write(MiniscriptThread *thread, const DynamicValue &value, void *objectRef, uintptr ptrOrOffset) {
997  DynamicValue derefValue = value.dereference();
998 
999  TInteger &dest = *static_cast<TInteger *>(objectRef);
1000  switch (derefValue.getType()) {
1001  case DynamicValueTypes::kFloat:
1002  dest = static_cast<TInteger>(floor(derefValue.getFloat() + 0.5));
1003  return kMiniscriptInstructionOutcomeContinue;
1004  case DynamicValueTypes::kInteger:
1005  dest = static_cast<TInteger>(derefValue.getInt());
1006  return kMiniscriptInstructionOutcomeContinue;
1007  default:
1008  return kMiniscriptInstructionOutcomeFailed;
1009  }
1010  }
1011  static MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib) {
1012  return kMiniscriptInstructionOutcomeFailed;
1013  }
1014  static MiniscriptInstructionOutcome refAttribIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib, const DynamicValue &index) {
1015  return kMiniscriptInstructionOutcomeFailed;
1016  }
1017 
1018  static void create(TInteger *intValue, DynamicValueWriteProxy &proxy) {
1019  proxy.pod.ptrOrOffset = 0;
1020  proxy.pod.objectRef = intValue;
1022  }
1023 };
1024 
1026  static MiniscriptInstructionOutcome write(MiniscriptThread *thread, const DynamicValue &value, void *objectRef, uintptr ptrOrOffset);
1027  static MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib);
1028  static MiniscriptInstructionOutcome refAttribIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib, const DynamicValue &index);
1029 
1030  static void create(Common::Point *pointValue, DynamicValueWriteProxy &proxy);
1031 };
1032 
1034  static MiniscriptInstructionOutcome write(MiniscriptThread *thread, const DynamicValue &value, void *objectRef, uintptr ptrOrOffset);
1035  static MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib);
1036  static MiniscriptInstructionOutcome refAttribIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib, const DynamicValue &index);
1037 
1038  static void create(bool *boolValue, DynamicValueWriteProxy &proxy);
1039 };
1040 
1042  static MiniscriptInstructionOutcome write(MiniscriptThread *thread, const DynamicValue &value, void *objectRef, uintptr ptrOrOffset);
1043  static MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib);
1044  static MiniscriptInstructionOutcome refAttribIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib, const DynamicValue &index);
1045 
1046  static void create(Common::String *strValue, DynamicValueWriteProxy &proxy);
1047 };
1048 
1050  static MiniscriptInstructionOutcome write(MiniscriptThread *thread, const DynamicValue &value, void *objectRef, uintptr ptrOrOffset);
1051  static MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib);
1052  static MiniscriptInstructionOutcome refAttribIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib, const DynamicValue &index);
1053 
1054  static void create(DynamicValueWriteProxy &proxy);
1055 };
1056 
1057 template<class TClass, MiniscriptInstructionOutcome (TClass::*TWriteMethod)(MiniscriptThread *thread, const DynamicValue &dest), MiniscriptInstructionOutcome (TClass::*TRefAttribMethod)(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, const Common::String &attrib)>
1059  static MiniscriptInstructionOutcome write(MiniscriptThread *thread, const DynamicValue &dest, void *objectRef, uintptr ptrOrOffset) {
1060  DynamicValue derefValue = dest.dereference();
1061 
1062  return (static_cast<TClass *>(objectRef)->*TWriteMethod)(thread, derefValue);
1063  }
1064  static MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib) {
1065  return (static_cast<TClass *>(objectRef)->*TRefAttribMethod)(thread, proxy, attrib);
1066  }
1067  static MiniscriptInstructionOutcome refAttribIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib, const DynamicValue &index) {
1068  return kMiniscriptInstructionOutcomeFailed;
1069  }
1070 
1071  static void create(TClass *obj, DynamicValueWriteProxy &proxy) {
1072  proxy.pod.ptrOrOffset = 0;
1073  proxy.pod.objectRef = obj;
1075  }
1076 };
1077 
1078 template<class TClass, MiniscriptInstructionOutcome (TClass::*TWriteMethod)(MiniscriptThread *thread, const DynamicValue &dest), bool TDereference>
1080  static MiniscriptInstructionOutcome write(MiniscriptThread *thread, const DynamicValue &dest, void *objectRef, uintptr ptrOrOffset) {
1081  if (TDereference) {
1082  return (static_cast<TClass *>(objectRef)->*TWriteMethod)(thread, dest.dereference());
1083  } else
1084  return (static_cast<TClass *>(objectRef)->*TWriteMethod)(thread, dest);
1085  }
1086  static MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib) {
1087  return kMiniscriptInstructionOutcomeFailed;
1088  }
1089  static MiniscriptInstructionOutcome refAttribIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib, const DynamicValue &index) {
1090  return kMiniscriptInstructionOutcomeFailed;
1091  }
1092 
1093  static void create(TClass *obj, DynamicValueWriteProxy &proxy) {
1094  proxy.pod.ptrOrOffset = 0;
1095  proxy.pod.objectRef = obj;
1097  }
1098 };
1099 
1101  static MiniscriptInstructionOutcome write(MiniscriptThread *thread, const DynamicValue &value, void *objectRef, uintptr ptrOrOffset);
1102  static MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib);
1103  static MiniscriptInstructionOutcome refAttribIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib, const DynamicValue &index);
1104 
1105  static void create(RuntimeObject *obj, DynamicValueWriteProxy &proxy);
1106 };
1107 
1110 
1111  bool load(const Data::Event &dataEvent, uint32 dataMessageFlags, const Data::InternalTypeTaggedValue &dataLocator, const Common::String &dataWithSource, const Common::String &dataWithString, uint32 dataDestination);
1112  bool load(const Data::PlugInTypeTaggedValue &dataEvent, const MessageFlags &dataMessageFlags, const Data::PlugInTypeTaggedValue &dataWith, uint32 dataDestination);
1113 
1114  void linkInternalReferences(ObjectLinkingScope *outerScope);
1115  void visitInternalReferences(IStructuralReferenceVisitor *visitor);
1116 
1117  void resolveDestination(Runtime *runtime, Modifier *sender, RuntimeObject *triggerSource, Common::WeakPtr<Structural> &outStructuralDest, Common::WeakPtr<Modifier> &outModifierDest, RuntimeObject *customDestination) const;
1118 
1119  static void resolveVariableObjectType(RuntimeObject *obj, Common::WeakPtr<Structural> &outStructuralDest, Common::WeakPtr<Modifier> &outModifierDest);
1120 
1121  void sendFromMessenger(Runtime *runtime, Modifier *sender, RuntimeObject *triggerSource, const DynamicValue &incomingData, RuntimeObject *customDestination) const;
1122  void sendFromMessengerWithCustomData(Runtime *runtime, Modifier *sender, RuntimeObject *triggerSource, const DynamicValue &data, RuntimeObject *customDestination) const;
1123 
1124  enum LinkType {
1125  kLinkTypeNotYetLinked,
1126  kLinkTypeStructural,
1127  kLinkTypeModifier,
1128  kLinkTypeCoded,
1129  kLinkTypeUnresolved,
1130  };
1131 
1132  Event send;
1133  MessageFlags messageFlags;
1134  DynamicValueSource with;
1135  uint32 destination; // May be a MessageDestination or GUID
1136 
1137  LinkType _linkType;
1138  Common::WeakPtr<Structural> _resolvedStructuralDest;
1139  Common::WeakPtr<Modifier> _resolvedModifierDest;
1140  Common::WeakPtr<Modifier> _resolvedVarSource;
1141 
1142 private:
1143  void resolveHierarchyStructuralDestination(Runtime *runtime, Modifier *sender, Common::WeakPtr<Structural> &outStructuralDest, Common::WeakPtr<Modifier> &outModifierDest, bool (*compareFunc)(Structural *structural)) const;
1144  static bool isSceneFilter(Structural *section);
1145  static bool isSectionFilter(Structural *section);
1146  static bool isSubsectionFilter(Structural *section);
1147  static bool isElementFilter(Structural *section);
1148 };
1149 
1150 enum MessageDestination {
1151  kMessageDestNone = 0,
1152 
1153  kMessageDestSharedScene = 0x65,
1154  kMessageDestScene = 0x66,
1155  kMessageDestSection = 0x67,
1156  kMessageDestProject = 0x68,
1157  kMessageDestActiveScene = 0x69,
1158  kMessageDestElementsParent = 0x6a,
1159  kMessageDestChildren = 0x6b, // Saw this somewhere but can't find it any more?
1160  kMessageDestModifiersParent = 0x6c,
1161  kMessageDestSubsection = 0x6d,
1162 
1163  kMessageDestElement = 0xc9,
1164  kMessageDestSourcesParent = 0xcf,
1165 
1166  kMessageDestBehavior = 0xd4,
1167  kMessageDestNextElement = 0xd1,
1168  kMessageDestPrevElement = 0xd2,
1169  kMessageDestBehaviorsParent = 0xd3,
1170 };
1171 
1174 
1175  int volumeID;
1176  Common::String filePath;
1178 };
1179 
1181  virtual void registerPlugInModifier(const char *name, const Data::IPlugInModifierDataFactory *loader, const IPlugInModifierFactory *factory) = 0;
1182  void registerPlugInModifier(const char *name, const IPlugInModifierFactoryAndDataFactory *loaderFactory);
1183 };
1184 
1185 class PlugIn {
1186 public:
1187  virtual ~PlugIn();
1188 
1189  virtual void registerModifiers(IPlugInModifierRegistrar *registrar) const = 0;
1190 };
1191 
1193 public:
1194  virtual ~ProjectPersistentResource();
1195 };
1196 
1198  virtual ~ProjectResources();
1199 
1201 };
1202 
1204 public:
1205  virtual ~CursorGraphic();
1206 
1207  virtual Graphics::Cursor *getCursor() const = 0;
1208 };
1209 
1211 public:
1212  explicit MacCursorGraphic(const Common::SharedPtr<Graphics::MacCursor> &macCursor);
1213 
1214  Graphics::Cursor *getCursor() const override;
1215 
1216 private:
1218 };
1219 
1221 public:
1222  explicit WinCursorGraphic(const Common::SharedPtr<Graphics::WinCursorGroup> &winCursorGroup, Graphics::Cursor *cursor);
1223 
1224  Graphics::Cursor *getCursor() const override;
1225 
1226 private:
1228  Graphics::Cursor *_cursor;
1229 };
1230 
1232 public:
1235 
1236  void addWinCursorGroup(uint32 cursorGroupID, const Common::SharedPtr<Graphics::WinCursorGroup> &cursorGroup);
1237  void addMacCursor(uint32 cursorID, const Common::SharedPtr<Graphics::MacCursor> &cursor);
1238 
1239  Common::SharedPtr<CursorGraphic> getGraphicByID(uint32 id) const;
1240 
1241 private:
1243 };
1244 
1245 // The project platform is the platform that the project is running on (not the format of the project)
1246 enum ProjectPlatform {
1247  kProjectPlatformUnknown,
1248 
1249  kProjectPlatformWindows,
1250  kProjectPlatformMacintosh,
1251 };
1252 
1254 public:
1255  ProjectDescription(ProjectPlatform platform, RuntimeVersion runtimeVersion, bool autoDetectVersion, Common::Archive *rootArchive, const Common::Path &projectRootDir);
1256  ~ProjectDescription();
1257 
1258  void addSegment(int volumeID, const char *filePath);
1259  void addSegment(int volumeID, Common::SeekableReadStream *stream);
1260  const Common::Array<SegmentDescription> &getSegments() const;
1261 
1262  void addPlugIn(const Common::SharedPtr<PlugIn> &plugIn);
1263  const Common::Array<Common::SharedPtr<PlugIn> > &getPlugIns() const;
1264 
1265  void setResources(const Common::SharedPtr<ProjectResources> &resources);
1266  const Common::SharedPtr<ProjectResources> &getResources() const;
1267 
1268  void setCursorGraphics(const Common::SharedPtr<CursorGraphicCollection> &cursorGraphics);
1269  const Common::SharedPtr<CursorGraphicCollection> &getCursorGraphics() const;
1270 
1271  void setLanguage(const Common::Language &language);
1272  const Common::Language &getLanguage() const;
1273 
1274  ProjectPlatform getPlatform() const;
1275  RuntimeVersion getRuntimeVersion() const;
1276  bool isRuntimeVersionAuto() const;
1277 
1278  Common::Archive *getRootArchive() const;
1279  const Common::Path &getProjectRootDir() const;
1280 
1281  const SubtitleTables &getSubtitles() const;
1282  void setSubtitles(const SubtitleTables &subs);
1283 
1284 private:
1289  Common::Language _language;
1290  SubtitleTables _subtitles;
1291  ProjectPlatform _platform;
1292  RuntimeVersion _runtimeVersion;
1293  bool _isRuntimeVersionAuto;
1294 
1295  Common::Archive *_rootArchive;
1296  Common::Path _projectRootDir;
1297 };
1298 
1299 struct VolumeState {
1300  VolumeState();
1301 
1302  Common::String name;
1303  int volumeID;
1304  bool isMounted;
1305 };
1306 
1308 public:
1310  ~ObjectLinkingScope();
1311 
1312  void setParent(ObjectLinkingScope *parent);
1313  void addObject(uint32 guid, const Common::String &name, const Common::WeakPtr<RuntimeObject> &object);
1314  Common::WeakPtr<RuntimeObject> resolve(uint32 staticGUID) const;
1315  Common::WeakPtr<RuntimeObject> resolve(const Common::String &name, bool isNameAlreadyInsensitive) const;
1316  Common::WeakPtr<RuntimeObject> resolve(uint32 staticGUID, const Common::String &name, bool isNameAlreadyInsensitive) const;
1317 
1318  void reset();
1319 
1320 private:
1323  ObjectLinkingScope *_parent;
1324 };
1325 
1327  enum ActionType {
1328  kLoad,
1329  kUnload,
1330  kSendMessage,
1331  kAutoResetCursor,
1332  kHideAllElements,
1333  kShowDefaultVisibleElements,
1334  };
1335 
1337  explicit LowLevelSceneStateTransitionAction(ActionType actionType);
1339  LowLevelSceneStateTransitionAction(const Common::SharedPtr<Structural> &scene, ActionType actionType);
1340 
1341  ActionType getActionType() const;
1342  const Common::SharedPtr<Structural> &getScene() const;
1343  const Common::SharedPtr<MessageDispatch> &getMessage() const;
1344 
1346 
1347 private:
1348  ActionType _actionType;
1351 };
1352 
1354  explicit ObjectParentChange(const Common::WeakPtr<RuntimeObject> &object, const Common::WeakPtr<RuntimeObject> &newParent);
1355 
1357  Common::WeakPtr<RuntimeObject> _newParent;
1358 };
1359 
1361  enum Type {
1362  kTypeChangeToScene,
1363  kTypeChangeSharedScene,
1364  kTypeForceLoadScene,
1365  kTypeRequestUnloadScene,
1366  };
1367 
1368  HighLevelSceneTransition(const Common::SharedPtr<Structural> &hlst_scene, Type hlst_type, bool hlst_addToDestinationScene, bool hlst_addToReturnList);
1369 
1371  Type type;
1372  bool addToDestinationScene;
1373  bool addToReturnList;
1374 };
1375 
1378 
1379  uint32 _duration; // 6000000 is maximum
1380  uint16 _steps;
1381  SceneTransitionTypes::SceneTransitionType _transitionType;
1382  SceneTransitionDirections::SceneTransitionDirection _transitionDirection;
1383 };
1384 
1386 public:
1387  MessageDispatch(const Common::SharedPtr<MessageProperties> &msgProps, Structural *root, bool cascade, bool relay, bool couldBeCommand);
1388  MessageDispatch(const Common::SharedPtr<MessageProperties> &msgProps, Modifier *root, bool cascade, bool relay, bool couldBeCommand);
1389 
1390  bool isTerminated() const;
1391  VThreadState continuePropagating(Runtime *runtime);
1392 
1393  const Common::SharedPtr<MessageProperties> &getMsg() const;
1394  RuntimeObject *getRootPropagator() const;
1395 
1396  bool isCascade() const;
1397  bool isRelay() const;
1398 
1399 private:
1400  struct PropagationStack {
1401  union Ptr {
1402  Structural *structural;
1403  Modifier *modifier;
1404  IModifierContainer *modifierContainer;
1405  };
1406 
1407  enum PropagationStage {
1408  kStageSendToModifier,
1409  kStageSendToModifierContainer,
1410 
1411  kStageSendToStructuralSelf,
1412  kStageSendToStructuralModifiers,
1413  kStageSendToStructuralChildren,
1414 
1415  kStageCheckAndSendToModifier,
1416  kStageCheckAndSendToStructural,
1417  kStageCheckAndSendCommand,
1418 
1419  kStageSendCommand,
1420  };
1421 
1422  PropagationStage propagationStage;
1423  size_t index;
1424  Ptr ptr;
1425  };
1426 
1427  Common::Array<PropagationStack> _propagationStack;
1429 
1431 
1432  bool _cascade; // Traverses structure tree
1433  bool _relay; // Fire on multiple modifiers
1434  bool _terminated;
1435  bool _isCommand;
1436 };
1437 
1439 public:
1441 
1442  Common::Array<Common::WeakPtr<RuntimeObject> > &getKeyboardMessengerArray();
1443  static bool keyboardMessengerFilterFunc(void *userData, RuntimeObject *object);
1444 
1445  bool isTerminated() const;
1446  VThreadState continuePropagating(Runtime *runtime);
1447 
1448 private:
1449  Common::Array<Common::WeakPtr<RuntimeObject> > _keyboardMessengers;
1450  size_t _dispatchIndex;
1452 };
1453 
1454 class Scheduler;
1455 
1457  friend class Scheduler;
1458 
1459 public:
1460  void cancel();
1461  uint64 getScheduledTime() const;
1462  void activate(Runtime *runtime) const;
1463 
1464 private:
1465  ScheduledEvent(void *obj, void (*activateFunc)(void *, Runtime *), uint64 scheduledTime, Scheduler *scheduler);
1466 
1467  void *_obj;
1468  void (*_activateFunc)(void *obj, Runtime *runtime);
1469 
1470  uint64 _scheduledTime;
1471  Scheduler *_scheduler;
1472 };
1473 
1474 class Scheduler {
1475  friend class ScheduledEvent;
1476 
1477 public:
1478  Scheduler();
1479  ~Scheduler();
1480 
1481  template<class T, void (T::*TMethodPtr)(Runtime *)>
1482  Common::SharedPtr<ScheduledEvent> scheduleMethod(uint64 scheduledTime, T* obj) {
1483  Common::SharedPtr<ScheduledEvent> evt(new ScheduledEvent(obj, Scheduler::methodActivateHelper<T, TMethodPtr>, scheduledTime, this));
1484  insertEvent(evt);
1485  return evt;
1486  }
1487 
1488  Common::SharedPtr<ScheduledEvent> getFirstEvent() const;
1489  void descheduleFirstEvent();
1490 
1491 private:
1492  template<class T, void (T::*TMethodPtr)(Runtime *)>
1493  static void methodActivateHelper(void *obj, Runtime *runtime) {
1494  (static_cast<T *>(obj)->*TMethodPtr)(runtime);
1495  }
1496 
1497  void insertEvent(const Common::SharedPtr<ScheduledEvent> &evt);
1498  void removeEvent(const ScheduledEvent *evt);
1499 
1501 };
1502 
1503 enum OSEventType {
1504  kOSEventTypeMouseDown,
1505  kOSEventTypeMouseUp,
1506  kOSEventTypeMouseMove,
1507 
1508  kOSEventTypeKeyboard,
1509 
1510  kOSEventTypeAction,
1511 };
1512 
1513 class OSEvent {
1514 public:
1515  explicit OSEvent(OSEventType eventType);
1516  virtual ~OSEvent();
1517 
1518  OSEventType getEventType() const;
1519 
1520 private:
1521  OSEventType _eventType;
1522 };
1523 
1524 class MouseInputEvent : public OSEvent {
1525 public:
1526  explicit MouseInputEvent(OSEventType eventType, int32 x, int32 y, Actions::MouseButton button);
1527 
1528  int32 getX() const;
1529  int32 getY() const;
1530  Actions::MouseButton getButton() const;
1531 
1532 private:
1533  int32 _x;
1534  int32 _y;
1535  Actions::MouseButton _button;
1536 };
1537 
1538 class KeyboardInputEvent : public OSEvent {
1539 public:
1540  explicit KeyboardInputEvent(OSEventType osEventType, Common::EventType keyEventType, bool repeat, const Common::KeyState &keyEvt);
1541 
1542  Common::EventType getKeyEventType() const;
1543  bool isRepeat() const;
1544  const Common::KeyState &getKeyState() const;
1545 
1546 private:
1547  Common::EventType _keyEventType;
1548  bool _repeat;
1549  const Common::KeyState _keyEvt;
1550 };
1551 
1552 class ActionEvent : public OSEvent {
1553 public:
1554  explicit ActionEvent(OSEventType osEventType, Actions::Action action);
1555 
1556  Actions::Action getAction() const;
1557 
1558 private:
1559  Actions::Action _action;
1560 };
1561 
1564 
1565  ConstraintDirection constraintDirection;
1566  Common::Rect constraintMargin;
1567  bool constrainToParent;
1568 };
1569 
1571 public:
1572  virtual ~SceneTransitionHooks();
1573 
1574  virtual void onSceneTransitionSetup(Runtime *runtime, const Common::WeakPtr<Structural> &oldScene, const Common::WeakPtr<Structural> &newScene);
1575  virtual void onSceneTransitionEnded(Runtime *runtime, const Common::WeakPtr<Structural> &newScene);
1576  virtual void onProjectStarted(Runtime *runtime);
1577 };
1578 
1579 class Palette {
1580 public:
1581  Palette();
1582  explicit Palette(const ColorRGB8 *colors);
1583 
1584  void initDefaultPalette(int version);
1585 
1586  const byte *getPalette() const;
1587 
1588  static const uint kNumColors = 256;
1589 
1590 private:
1591  byte _colors[kNumColors * 3];
1592 };
1593 
1594 class Runtime {
1595 public:
1596  explicit Runtime(OSystem *system, Audio::Mixer *mixer, ISaveUIProvider *saveProvider, ILoadUIProvider *loadProvider, const Common::SharedPtr<SubtitleRenderer> &subRenderer);
1597  ~Runtime();
1598 
1599  bool runFrame();
1600  void drawFrame();
1601 
1602  void queueProject(const Common::SharedPtr<ProjectDescription> &desc);
1603  void closeProject();
1604 
1605  void addVolume(int volumeID, const char *name, bool isMounted);
1606  bool getVolumeState(const Common::String &name, int &outVolumeID, bool &outIsMounted) const;
1607 
1608  void addSceneReturn();
1609  void addSceneStateTransition(const HighLevelSceneTransition &transition);
1610 
1611  void setSceneTransitionEffect(bool isInDestinationScene, SceneTransitionEffect *effect);
1612 
1613  Project *getProject() const;
1614 
1615  void postConsumeMessageTask(IMessageConsumer *msgConsumer, const Common::SharedPtr<MessageProperties> &msg);
1616  void postConsumeCommandTask(Structural *structural, const Common::SharedPtr<MessageProperties> &msg);
1617 
1618  uint32 allocateRuntimeGUID();
1619 
1620  void addWindow(const Common::SharedPtr<Window> &window);
1621  void removeWindow(Window *window);
1622 
1623  // Sets up a supported display mode
1624  void setupDisplayMode(ColorDepthMode displayMode, const Graphics::PixelFormat &pixelFormat);
1625 
1626  bool isDisplayModeSupported(ColorDepthMode displayMode) const;
1627 
1628  // Switches to a specified display mode. Returns true if the mode was actually changed. If so, all windows will need
1629  // to be recreated.
1630  bool switchDisplayMode(ColorDepthMode realDisplayMode, ColorDepthMode fakeDisplayMode);
1631 
1632  void setDisplayResolution(uint16 width, uint16 height);
1633  void getDisplayResolution(uint16 &outWidth, uint16 &outHeight) const;
1634 
1635  ColorDepthMode getRealColorDepth() const;
1636  ColorDepthMode getFakeColorDepth() const; // Fake color depth that will be reported to scripts
1637 
1638  const Graphics::PixelFormat &getRenderPixelFormat() const;
1639 
1640  const Common::SharedPtr<Graphics::MacFontManager> &getMacFontManager() const;
1641 
1642  const Common::SharedPtr<Structural> &getActiveMainScene() const;
1643  const Common::SharedPtr<Structural> &getActiveSharedScene() const;
1644  void getSceneStack(Common::Array<Common::SharedPtr<Structural> > &sceneStack) const;
1645 
1646  bool mustDraw() const;
1647 
1648  uint64 getRealTime() const;
1649  uint64 getPlayTime() const;
1650 
1651  VThread &getVThread() const;
1652 
1653  // Sending a message on the VThread means "immediately"
1654  void sendMessageOnVThread(const Common::SharedPtr<MessageDispatch> &dispatch);
1655 
1657  CORO_DEFINE_RETURN_TYPE(void);
1658  CORO_DEFINE_PARAMS_2(Runtime *, runtime, Common::SharedPtr<MessageDispatch>, dispatch);
1659  };
1660 
1661  void queueMessage(const Common::SharedPtr<MessageDispatch> &dispatch);
1662 
1663  void queueOSEvent(const Common::SharedPtr<OSEvent> &osEvent);
1664 
1665  Scheduler &getScheduler();
1666 
1667  void getScenesInRenderOrder(Common::Array<Structural *> &scenes) const;
1668 
1669  void instantiateIfAlias(Common::SharedPtr<Modifier> &modifier, const Common::WeakPtr<RuntimeObject> &relinkParent);
1670 
1671  Common::SharedPtr<Window> findTopWindow(int32 x, int32 y) const;
1672 
1673  void setVolume(double volume);
1674 
1675  void onMouseDown(int32 x, int32 y, Actions::MouseButton mButton);
1676  void onMouseMove(int32 x, int32 y);
1677  void onMouseUp(int32 x, int32 y, Actions::MouseButton mButton);
1678  void onKeyboardEvent(const Common::EventType evtType, bool repeat, const Common::KeyState &keyEvt);
1679  void onAction(MTropolis::Actions::Action action);
1680 
1681  const Common::Point &getCachedMousePosition() const;
1682  void setModifierCursorOverride(uint32 cursorID);
1683  void clearModifierCursorOverride();
1684  void forceCursorRefreshOnce();
1685  void setAutoResetCursor(bool enabled);
1686 
1687  uint getMultiClickCount() const;
1688 
1689  bool isAwaitingSceneTransition() const;
1690 
1691  Common::RandomSource *getRandom() const;
1692  WorldManagerInterface *getWorldManagerInterface() const;
1693  AssetManagerInterface *getAssetManagerInterface() const;
1694  SystemInterface *getSystemInterface() const;
1695 
1696  ISaveUIProvider *getSaveProvider() const;
1697  ILoadUIProvider *getLoadProvider() const;
1698 
1699  Audio::Mixer *getAudioMixer() const;
1700 
1701  Hacks &getHacks();
1702  const Hacks &getHacks() const;
1703 
1704  void setSceneGraphDirty();
1705  void clearSceneGraphDirty();
1706  bool isSceneGraphDirty() const;
1707 
1708  void addCollider(ICollider *collider);
1709  void removeCollider(ICollider *collider);
1710  void checkCollisions(ICollider *optRestrictToCollider);
1711 
1712  void setCursorElement(const Common::WeakPtr<VisualElement> &element);
1713  void updateCursorElementPosition();
1714 
1715  void addBoundaryDetector(IBoundaryDetector *boundaryDetector);
1716  void removeBoundaryDetector(IBoundaryDetector *boundaryDetector);
1717  void checkBoundaries();
1718 
1719  void addPostEffect(IPostEffect *postEffect);
1720  void removePostEffect(IPostEffect *postEffect);
1721  const Common::Array<IPostEffect *> &getPostEffects() const;
1722 
1723  const Palette &getGlobalPalette() const;
1724  void setGlobalPalette(const Palette &palette);
1725 
1726  void addMouseBlocker();
1727  void removeMouseBlocker();
1728 
1729  const Common::String *resolveAttributeIDName(uint32 attribID) const;
1730 
1731  const Common::WeakPtr<Window> &getMainWindow() const;
1732 
1733  const Common::SharedPtr<Graphics::ManagedSurface> &getSaveScreenshotOverride() const;
1734  void setSaveScreenshotOverride(const Common::SharedPtr<Graphics::ManagedSurface> &screenshot);
1735 
1736  bool isIdle() const;
1737 
1738  const Common::SharedPtr<SubtitleRenderer> &getSubtitleRenderer() const;
1739 
1740  void queueCloneObject(const Common::WeakPtr<RuntimeObject> &obj);
1741  void queueKillObject(const Common::WeakPtr<RuntimeObject> &obj);
1742  void queueChangeObjectParent(const Common::WeakPtr<RuntimeObject> &obj, const Common::WeakPtr<RuntimeObject> &newParent);
1743 
1744  void hotLoadScene(Structural *structural);
1745 
1746 #ifdef MTROPOLIS_DEBUG_ENABLE
1747  void debugSetEnabled(bool enabled);
1748  void debugBreak();
1749  Debugger *debugGetDebugger() const;
1750 
1751  void debugGetPrimaryTaskList(Common::Array<Common::SharedPtr<DebugPrimaryTaskList> > &primaryTaskLists);
1752 #endif
1753 
1754 private:
1755  enum SceneTransitionState {
1756  kSceneTransitionStateNotTransitioning,
1757  kSceneTransitionStateWaitingForDraw,
1758  kSceneTransitionStateTransitioning,
1759  };
1760 
1761  struct SceneStackEntry {
1762  SceneStackEntry();
1763 
1765  };
1766 
1767  struct Teardown {
1768  Teardown();
1769 
1770  Common::WeakPtr<Structural> structural;
1771  Common::WeakPtr<Modifier> modifier;
1772  bool onlyRemoveChildren;
1773  };
1774 
1775  struct SceneReturnListEntry {
1776  SceneReturnListEntry();
1777 
1779  bool isAddToDestinationSceneTransition;
1780  };
1781 
1782  struct DispatchMethodTaskData {
1784  };
1785 
1786  struct DispatchKeyTaskData {
1788  };
1789 
1790  struct DispatchActionTaskData {
1791  DispatchActionTaskData();
1792 
1793  Actions::Action action;
1794  };
1795 
1796  struct ConsumeMessageTaskData {
1797  ConsumeMessageTaskData();
1798 
1799  IMessageConsumer *consumer;
1801  };
1802 
1803  struct ConsumeCommandTaskData {
1804  ConsumeCommandTaskData();
1805 
1806  Structural *structural;
1808  };
1809 
1810  struct ApplyDefaultVisibilityTaskData {
1811  ApplyDefaultVisibilityTaskData();
1812 
1813  VisualElement *element;
1814  bool targetVisibility;
1815  };
1816 
1817  struct UpdateMouseStateTaskData {
1818  UpdateMouseStateTaskData();
1819 
1820  bool mouseDown;
1821  };
1822 
1823  struct UpdateMousePositionTaskData {
1824  UpdateMousePositionTaskData();
1825 
1826  int32 x;
1827  int32 y;
1828  };
1829 
1830  struct CollisionCheckState {
1831  CollisionCheckState();
1832 
1834  ICollider *collider;
1835  };
1836 
1837  struct BoundaryCheckState {
1838  BoundaryCheckState();
1839 
1840  IBoundaryDetector *detector;
1841  uint currentContacts;
1842  Common::Point position;
1843  bool positionResolved;
1844  };
1845 
1846  struct ColliderInfo {
1847  ColliderInfo();
1848 
1849  size_t sceneStackDepth;
1850  uint16 layer;
1851  VisualElement *element;
1852  Common::Rect absRect;
1853  };
1854 
1855  static Common::SharedPtr<Structural> findDefaultSharedSceneForScene(Structural *scene);
1856  void executeTeardown(const Teardown &teardown);
1857  void executeLowLevelSceneStateTransition(const LowLevelSceneStateTransitionAction &transitionAction);
1858  void executeHighLevelSceneReturn();
1859  void executeHighLevelSceneTransition(const HighLevelSceneTransition &transition);
1860  void executeCompleteTransitionToScene(const Common::SharedPtr<Structural> &scene);
1861  void executeSharedScenePostSceneChangeActions();
1862  void executeSceneChangeRecursiveVisibilityChange(Structural *structural, bool showing);
1863  void executeChangeObjectParent(RuntimeObject *object, RuntimeObject *newParent);
1864  void executeCloneObject(RuntimeObject *object);
1865  void executeKillObject(RuntimeObject *object);
1866 
1867  void recursiveAutoPlayMedia(Structural *structural);
1868  void recursiveDeactivateStructural(Structural *structural);
1869  void recursiveActivateStructural(Structural *structural);
1870 
1871  static bool isStructuralMouseInteractive(Structural *structural, MouseInteractivityTestType testType);
1872  static bool isModifierMouseInteractive(Modifier *modifier, MouseInteractivityTestType testType);
1873  static void recursiveFindMouseCollision(Structural *&bestResult, int32 &bestLayer, int32 &bestStackHeight, bool &bestDirect, Structural *candidate, int32 stackHeight, int32 relativeX, int32 relativeY, MouseInteractivityTestType testType);
1874 
1875  void queueEventAsLowLevelSceneStateTransitionAction(const Event &evt, Structural *root, bool cascade, bool relay);
1876 
1877  void loadScene(const Common::SharedPtr<Structural> &scene);
1878 
1879  void ensureMainWindowExists();
1880 
1881  void unloadProject();
1882  void refreshPlayTime(); // Updates play time to be in sync with the system clock. Used so that events occurring after storage access don't skip.
1883 
1884  VThreadState dispatchMessageTask(const DispatchMethodTaskData &data);
1885  VThreadState dispatchKeyTask(const DispatchKeyTaskData &data);
1886  VThreadState dispatchActionTask(const DispatchActionTaskData &data);
1887  VThreadState consumeMessageTask(const ConsumeMessageTaskData &data);
1888  VThreadState consumeCommandTask(const ConsumeCommandTaskData &data);
1889  VThreadState updateMouseStateTask(const UpdateMouseStateTaskData &data);
1890  VThreadState updateMousePositionTask(const UpdateMousePositionTaskData &data);
1891  VThreadState applyDefaultVisibility(const ApplyDefaultVisibilityTaskData &data);
1892 
1893  void updateMainWindowCursor();
1894 
1895  static void recursiveFindColliders(Structural *structural, size_t sceneStackDepth, Common::Array<ColliderInfo> &colliders, int32 parentOriginX, int32 parentOriginY, bool isRoot);
1896  static bool sortColliderPredicate(const ColliderInfo &a, const ColliderInfo &b);
1897 
1899 
1900  Common::Array<VolumeState> _volumes;
1901  Common::SharedPtr<ProjectDescription> _queuedProjectDesc;
1902  Common::SharedPtr<Project> _project;
1903  Common::ScopedPtr<VThread> _vthread;
1906  ObjectLinkingScope _rootLinkingScope;
1907 
1908  Common::Array<Teardown> _pendingTeardowns;
1909  Common::Array<LowLevelSceneStateTransitionAction> _pendingLowLevelTransitions;
1912  Common::Array<Common::WeakPtr<Structural> > _pendingPostCloneShowChecks;
1913  Common::Array<Common::WeakPtr<Structural> > _pendingShowClonedObject;
1914  Common::Array<ObjectParentChange> _pendingParentChanges;
1915  uint _pendingSceneReturnCount;
1916  Common::Array<HighLevelSceneTransition> _pendingSceneTransitions;
1917  Common::Array<SceneStackEntry> _sceneStack;
1918  Common::SharedPtr<Structural> _activeMainScene;
1919  Common::SharedPtr<Structural> _activeSharedScene;
1920  Common::Array<SceneReturnListEntry> _sceneReturnList;
1921 
1922  SceneTransitionState _sceneTransitionState;
1923  SceneTransitionEffect _sourceSceneTransitionEffect;
1924  SceneTransitionEffect _destinationSceneTransitionEffect;
1925  SceneTransitionEffect *_activeSceneTransitionEffect;
1926  Common::SharedPtr<Graphics::ManagedSurface> _sceneTransitionOldFrame;
1927  Common::SharedPtr<Graphics::ManagedSurface> _sceneTransitionNewFrame;
1928  uint32 _sceneTransitionStartTime;
1929  uint32 _sceneTransitionEndTime;
1930  bool _sharedSceneWasSetExplicitly;
1931 
1932  Common::WeakPtr<Window> _mainWindow;
1934 
1936 
1938 
1939  uint32 _nextRuntimeGUID;
1940 
1941  bool _displayModeSupported[kColorDepthModeCount];
1942  Graphics::PixelFormat _displayModePixelFormats[kColorDepthModeCount];
1943  ColorDepthMode _realDisplayMode;
1944  ColorDepthMode _fakeDisplayMode;
1945  uint16 _displayWidth;
1946  uint16 _displayHeight;
1947 
1948  uint64 _realTimeBase;
1949  uint64 _playTimeBase;
1950 
1951  uint32 _realTime;
1952  uint32 _playTime;
1953 
1954  Scheduler _scheduler;
1955  OSystem *_system;
1956  Audio::Mixer *_mixer;
1957 
1958  ISaveUIProvider *_saveProvider;
1959  ILoadUIProvider *_loadProvider;
1960  Common::SharedPtr<Graphics::ManagedSurface> _saveScreenshotOverride;
1961 
1962  Common::SharedPtr<CursorGraphic> _lastFrameCursor;
1963  Common::SharedPtr<CursorGraphic> _defaultCursor;
1964  bool _lastFrameMouseVisible;
1965 
1966  Common::WeakPtr<Window> _mouseFocusWindow;
1967  bool _mouseFocusFlags[Actions::kMouseButtonCount];
1968 
1969  Common::WeakPtr<Window> _keyFocusWindow;
1970 
1971  Common::SharedPtr<SystemInterface> _systemInterface;
1972  Common::SharedPtr<WorldManagerInterface> _worldManagerInterface;
1973  Common::SharedPtr<AssetManagerInterface> _assetManagerInterface;
1974 
1975  // The cached mouse position is updated at frame end
1976  Common::Point _cachedMousePosition;
1977 
1978  // The real mouse position is updated all the time (even when suspended)
1979  Common::Point _realMousePosition;
1980 
1981  // Mouse control is tracked in two ways: Mouse over is detected with mouse movement AND when
1982  // "refreshCursor" is set on the world manager, it indicates the frontmost object that
1983  // responds to any mouse event. The mouse tracking object is the object that was clicked.
1984  // These can differ if the user holds down the mouse and moves it to a spot where the tracked
1985  // object is either not clickable, or is behind another object with mouse collision.
1986  // Note that mouseOverObject is also NOT necessarily what will receive mouse down events.
1987  Common::WeakPtr<Structural> _mouseOverObject;
1988  Common::WeakPtr<Structural> _mouseTrackingObject;
1989  Common::Point _mouseTrackingDragStart;
1990  Common::Point _mouseTrackingObjectInitialOrigin;
1991  bool _trackedMouseOutside;
1992  bool _forceCursorRefreshOnce;
1993  bool _autoResetCursor;
1994 
1995  uint32 _modifierOverrideCursorID;
1996  bool _haveModifierOverrideCursor;
1997  bool _haveCursorElement;
1998 
1999  uint32 _multiClickStartTime;
2000  uint32 _multiClickInterval;
2001  uint _multiClickCount;
2002 
2003  uint _numMouseBlockers;
2004 
2005  bool _defaultVolumeState;
2006 
2007  // True if any elements were added to the scene, removed from the scene, or reparented since last draw
2008  bool _sceneGraphChanged;
2009 
2010  bool _isQuitting;
2011 
2013  Common::Array<BoundaryCheckState> _boundaryChecks;
2014  uint32 _collisionCheckTime;
2015 
2016  Common::WeakPtr<VisualElement> _elementTrackedToCursor;
2017  //uint32 _elementCursorUpdateTime;
2018 
2019  Common::Array<IPostEffect *> _postEffects;
2020 
2021  Palette _globalPalette;
2022 
2023  Common::SharedPtr<SubtitleRenderer> _subtitleRenderer;
2024 
2025  Hacks _hacks;
2026 
2027  Common::HashMap<uint32, Common::String> _getSetAttribIDsToAttribName;
2028 
2029 #ifdef MTROPOLIS_DEBUG_ENABLE
2030  Common::SharedPtr<Debugger> _debugger;
2031 #endif
2032 };
2033 
2035  virtual const Common::Array<Common::SharedPtr<Modifier> > &getModifiers() const = 0;
2036  virtual void appendModifier(const Common::SharedPtr<Modifier> &modifier) = 0;
2037  virtual void removeModifier(const Modifier *modifier) = 0;
2038 };
2039 
2041 public:
2042  const Common::Array<Common::SharedPtr<Modifier> > &getModifiers() const override;
2043  void appendModifier(const Common::SharedPtr<Modifier> &modifier) override;
2044  void removeModifier(const Modifier *modifier) override;
2045 
2046  void clear();
2047 
2048 private:
2050 };
2051 
2053  template<typename TElement, typename TElementData>
2054  friend class ElementFactory;
2055 
2056 public:
2057  RuntimeObject();
2058  virtual ~RuntimeObject();
2059 
2060  uint32 getStaticGUID() const;
2061  uint32 getRuntimeGUID() const;
2062 
2063  void setRuntimeGUID(uint32 runtimeGUID);
2064 
2065  void setSelfReference(const Common::WeakPtr<RuntimeObject> &selfReference);
2066  const Common::WeakPtr<RuntimeObject> &getSelfReference() const;
2067 
2068  virtual bool isStructural() const;
2069  virtual bool isProject() const;
2070  virtual bool isSection() const;
2071  virtual bool isSubsection() const;
2072  virtual bool isModifier() const;
2073  virtual bool isElement() const;
2074 
2075  virtual bool readAttribute(MiniscriptThread *thread, DynamicValue &result, const Common::String &attrib);
2076  virtual bool readAttributeIndexed(MiniscriptThread *thread, DynamicValue &result, const Common::String &attrib, const DynamicValue &index);
2077  virtual MiniscriptInstructionOutcome writeRefAttribute(MiniscriptThread *thread, DynamicValueWriteProxy &result, const Common::String &attrib);
2078  virtual MiniscriptInstructionOutcome writeRefAttributeIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &result, const Common::String &attrib, const DynamicValue &index);
2079 
2080 protected:
2081  MiniscriptInstructionOutcome scriptSetClone(MiniscriptThread *thread, const DynamicValue &value);
2082  MiniscriptInstructionOutcome scriptSetKill(MiniscriptThread *thread, const DynamicValue &value);
2083  MiniscriptInstructionOutcome scriptSetParent(MiniscriptThread *thread, const DynamicValue &value);
2084 
2085  // This is the static GUID stored in the data, it is not guaranteed
2086  // to be globally unique at runtime. In particular, cloning an object
2087  // and using aliased modifiers will cause multiple objects with the same
2088  // static GUID to exist with separate runtime GUIDs.
2089  uint32 _guid;
2090  uint32 _runtimeGUID;
2091  Common::WeakPtr<RuntimeObject> _selfReference;
2092 
2094  static MiniscriptInstructionOutcome write(MiniscriptThread *thread, const DynamicValue &dest, void *objectRef, uintptr ptrOrOffset);
2095  static MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib);
2096  static MiniscriptInstructionOutcome refAttribIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib, const DynamicValue &index);
2097 
2098  private:
2099  static RuntimeObject *resolveObjectParent(RuntimeObject *obj);
2100  };
2101 };
2102 
2104  MessageProperties(const Event &evt, const DynamicValue &value, const Common::WeakPtr<RuntimeObject> &source);
2105 
2106  const Event &getEvent() const;
2107  const DynamicValue &getValue() const;
2108  const Common::WeakPtr<RuntimeObject> &getSource() const;
2109 
2110  void setValue(const DynamicValue &value);
2111 
2112 private:
2113  Event _evt;
2114  DynamicValue _value;
2116 };
2117 
2119  virtual void visitChildStructuralRef(Common::SharedPtr<Structural> &structural) = 0;
2120  virtual void visitChildModifierRef(Common::SharedPtr<Modifier> &modifier) = 0;
2121  virtual void visitWeakStructuralRef(Common::WeakPtr<Structural> &structural) = 0;
2122  virtual void visitWeakModifierRef(Common::WeakPtr<Modifier> &modifier) = 0;
2123 };
2124 
2126  // These should only be implemented as direct responses - child traversal is handled by the message propagation process
2127  virtual bool respondsToEvent(const Event &evt) const = 0;
2128  virtual VThreadState consumeMessage(Runtime *runtime, const Common::SharedPtr<MessageProperties> &msg) = 0;
2129 };
2130 
2132 public:
2134 
2135  bool readAttribute(MiniscriptThread *thread, DynamicValue &result, const Common::String &attrib) override;
2136  MiniscriptInstructionOutcome writeRefAttribute(MiniscriptThread *thread, DynamicValueWriteProxy &result, const Common::String &attrib) override;
2137 
2138 private:
2139  MiniscriptInstructionOutcome setCurrentScene(MiniscriptThread *thread, const DynamicValue &value);
2140  MiniscriptInstructionOutcome setRefreshCursor(MiniscriptThread *thread, const DynamicValue &value);
2141  MiniscriptInstructionOutcome setAutoResetCursor(MiniscriptThread *thread, const DynamicValue &value);
2142  MiniscriptInstructionOutcome setWinSndBufferSize(MiniscriptThread *thread, const DynamicValue &value);
2143  MiniscriptInstructionOutcome setCursor(MiniscriptThread *thread, const DynamicValue &value);
2144 
2145  int32 _opInt;
2146  bool _gameMode;
2147  bool _combineRedraws;
2148  bool _postponeRedraws;
2149 };
2150 
2152 public:
2154 
2155  bool readAttribute(MiniscriptThread *thread, DynamicValue &result, const Common::String &attrib) override;
2156  MiniscriptInstructionOutcome writeRefAttribute(MiniscriptThread *thread, DynamicValueWriteProxy &result, const Common::String &attrib) override;
2157 
2158 private:
2159  Common::String _opString;
2160 };
2161 
2163 public:
2164  const int kFullVolume = 7;
2165 
2166  SystemInterface();
2167 
2168  bool readAttribute(MiniscriptThread *thread, DynamicValue &result, const Common::String &attrib) override;
2169  bool readAttributeIndexed(MiniscriptThread *thread, DynamicValue &result, const Common::String &attrib, const DynamicValue &index) override;
2170  MiniscriptInstructionOutcome writeRefAttribute(MiniscriptThread *thread, DynamicValueWriteProxy &result, const Common::String &attrib) override;
2171 
2172 private:
2173  MiniscriptInstructionOutcome setEjectCD(MiniscriptThread *thread, const DynamicValue &value);
2174  MiniscriptInstructionOutcome setGameMode(MiniscriptThread *thread, const DynamicValue &value);
2175  MiniscriptInstructionOutcome setMasterVolume(MiniscriptThread *thread, const DynamicValue &value);
2176  MiniscriptInstructionOutcome setMonitorBitDepth(MiniscriptThread *thread, const DynamicValue &value);
2177  MiniscriptInstructionOutcome setVolumeName(MiniscriptThread *thread, const DynamicValue &value);
2178 
2179  Common::String _volumeName;
2180  Common::String _opString;
2181  int _masterVolume;
2182 };
2183 
2185 public:
2186  virtual ~StructuralHooks();
2187 
2188  virtual void onCreate(Structural *structural);
2189  virtual void onPostActivate(Structural *structural);
2190  virtual void onSetPosition(Runtime *runtime, Structural *structural, const Common::Point &oldPt, Common::Point &pt);
2191  virtual void onStopPlayingMToon(Structural *structural, bool &visible, bool &stopped, Graphics::ManagedSurface *lastSurf);
2192  virtual void onHidden(Structural *structural, bool &visible);
2193 };
2194 
2196 public:
2197  enum class SceneLoadState {
2198  kNotAScene,
2199  kSceneNotLoaded,
2200  kSceneLoaded,
2201  };
2202 
2203  Structural();
2204  explicit Structural(Runtime *runtime);
2205  virtual ~Structural();
2206 
2207  bool isStructural() const override;
2208  SceneLoadState getSceneLoadState() const;
2209  void setSceneLoadState(SceneLoadState sceneLoadState);
2210 
2211  bool readAttribute(MiniscriptThread *thread, DynamicValue &result, const Common::String &attrib) override;
2212  bool readAttributeIndexed(MiniscriptThread *thread, DynamicValue &result, const Common::String &attrib, const DynamicValue &index) override;
2213  MiniscriptInstructionOutcome writeRefAttribute(MiniscriptThread *thread, DynamicValueWriteProxy &result, const Common::String &attrib) override;
2214 
2215  const Common::Array<Common::SharedPtr<Structural> > &getChildren() const;
2216  void addChild(const Common::SharedPtr<Structural> &child);
2217  void removeAllChildren();
2218  void removeAllModifiers();
2219  void removeChild(Structural *child);
2220  void removeAllAssets();
2221 
2222  void holdAssets(const Common::Array<Common::SharedPtr<Asset> > &assets);
2223 
2224  Structural *getParent() const;
2225  Structural *findNextSibling() const;
2226  Structural *findPrevSibling() const;
2227  void setParent(Structural *parent);
2228 
2229  // Helper that finds the scene containing the structural object, or itself if it is the scene
2230  VisualElement *findScene();
2231 
2232  const Common::String &getName() const;
2233 
2234  const Common::Array<Common::SharedPtr<Modifier> > &getModifiers() const override;
2235  void appendModifier(const Common::SharedPtr<Modifier> &modifier) override;
2236  void removeModifier(const Modifier *modifier) override;
2237 
2238  bool respondsToEvent(const Event &evt) const override;
2239  VThreadState consumeMessage(Runtime *runtime, const Common::SharedPtr<MessageProperties> &msg) override;
2240 
2241  void materializeSelfAndDescendents(Runtime *runtime, ObjectLinkingScope *outerScope);
2242  void materializeDescendents(Runtime *runtime, ObjectLinkingScope *outerScope);
2243 
2245  CORO_DEFINE_RETURN_TYPE(void);
2246  CORO_DEFINE_PARAMS_3(Structural *, self, Runtime *, runtime, Common::SharedPtr<MessageProperties>, msg);
2247  };
2248 
2249  virtual VThreadState asyncConsumeCommand(Runtime *runtime, const Common::SharedPtr<MessageProperties> &msg);
2250 
2251  virtual void activate();
2252  virtual void deactivate();
2253 
2254  void recursiveCollectObjectsMatchingCriteria(Common::Array<Common::WeakPtr<RuntimeObject> > &results, bool (*evalFunc)(void *userData, RuntimeObject *object), void *userData, bool onlyEnabled);
2255 
2256  void setHooks(const Common::SharedPtr<StructuralHooks> &hooks);
2257  const Common::SharedPtr<StructuralHooks> &getHooks() const;
2258 
2259  // Shallow clones only need to copy the object. Descendent copies are done using visitInternalReferences.
2260  virtual Common::SharedPtr<Structural> shallowClone() const = 0;
2261 
2262  virtual void visitInternalReferences(IStructuralReferenceVisitor *visitor);
2263 
2264 #ifdef MTROPOLIS_DEBUG_ENABLE
2265  SupportStatus debugGetSupportStatus() const override;
2266  const Common::String &debugGetName() const override;
2267  void debugInspect(IDebugInspectionReport *report) const override;
2268 
2269  virtual void debugSkipMovies();
2270 #endif
2271 
2272 protected:
2273  explicit Structural(const Structural &other);
2274 
2275  virtual ObjectLinkingScope *getPersistentStructuralScope();
2276  virtual ObjectLinkingScope *getPersistentModifierScope();
2277 
2278  MiniscriptInstructionOutcome scriptSetPaused(MiniscriptThread *thread, const DynamicValue &value);
2279  MiniscriptInstructionOutcome scriptSetLoop(MiniscriptThread *thread, const DynamicValue &value);
2280  MiniscriptInstructionOutcome scriptSetDebug(MiniscriptThread *thread, const DynamicValue &value);
2281  MiniscriptInstructionOutcome scriptSetUnload(MiniscriptThread *thread, const DynamicValue &value);
2282 
2283  // If you override this, you must override visitInternalReferences too.
2284  virtual void linkInternalReferences(ObjectLinkingScope *outerScope);
2285 
2286  virtual void onPauseStateChanged();
2287 
2288  Runtime *getRuntime() const;
2289 
2290  Structural *_parent;
2293  Common::String _name;
2294 
2296 
2297  // "paused" attrib is available for ALL structural types, even when it doesn't do anything.
2298  // Changing it does not affect modifiers on the object that play media, but does fire
2299  // "Paused"/"Unpaused" events.
2300  bool _paused;
2301 
2302  // "loop" appears to have been made available on everything in 1.2. Obsidian depends on it
2303  // being available for sound indexes to be properly set up.
2304  bool _loop;
2305 
2306  int32 _flushPriority;
2307  SceneLoadState _sceneLoadState;
2308 
2310 
2311 private:
2312  Runtime *_runtime;
2313 };
2314 
2317 
2318  uint16 width;
2319  uint16 height;
2320  uint32 bitsPerPixel;
2321 };
2322 
2325 };
2326 
2328  enum Type {
2329  kTypeUnknown,
2330  kTypeCountedModifierList,
2331  kTypeFlagTerminatedModifierList,
2332  kTypeProject,
2333  kTypeSection,
2334  kTypeFilteredElements,
2335  };
2336 
2338  Structural *structural;
2339  bool (*filterFunc)(Data::DataObjectTypes::DataObjectType dataObjectType);
2340  };
2341 
2343  IModifierContainer *modifierContainer;
2344  Structural *structural;
2345  FilteredElements filteredElements;
2346  };
2347 
2349 
2350  uint remainingCount;
2351  Type type;
2352  ContainerUnion containerUnion;
2353 };
2354 
2357 };
2358 
2360 public:
2362 
2363  void registerPlugInModifier(const char *name, const Data::IPlugInModifierDataFactory *dataFactory, const IPlugInModifierFactory *factory) override;
2364 
2365  const Data::PlugInModifierRegistry &getDataLoaderRegistry() const;
2366  const IPlugInModifierFactory *findPlugInModifierFactory(const char *name) const;
2367 
2368 private:
2369  Data::PlugInModifierRegistry _dataLoaderRegistry;
2371 };
2372 
2374  virtual void playMedia(Runtime *runtime, Project *project) = 0;
2375 };
2376 
2378 public:
2380  ~PlayMediaSignaller();
2381 
2382  void playMedia(Runtime *runtime, Project *project);
2383  void addReceiver(IPlayMediaSignalReceiver *receiver);
2384  void removeReceiver(IPlayMediaSignalReceiver *receiver);
2385 
2386 private:
2388 };
2389 
2391  virtual void onSegmentUnloaded(int segmentIndex) = 0;
2392 };
2393 
2395 public:
2396  explicit SegmentUnloadSignaller(Project *project, int segmentIndex);
2398 
2399  void onSegmentUnloaded();
2400  void addReceiver(ISegmentUnloadSignalReceiver *receiver);
2401  void removeReceiver(ISegmentUnloadSignalReceiver *receiver);
2402 
2403 private:
2404  Project *_project;
2405  int _segmentIndex;
2407 };
2408 
2410  virtual void onKeyboardEvent(Runtime *runtime, const KeyboardInputEvent &keyEvt) = 0;
2411 };
2412 
2414 public:
2417 
2418  void onKeyboardEvent(Runtime *runtime, const KeyboardInputEvent &keyEvt);
2419  void addReceiver(IKeyboardEventReceiver *receiver);
2420  void removeReceiver(IKeyboardEventReceiver *receiver);
2421 
2422 private:
2425 };
2426 
2427 struct ICollider : public IInterfaceBase {
2428  virtual void getCollisionProperties(Modifier *&modifier, bool &collideInFront, bool &collideBehind, bool &excludeParents) const = 0;
2429  virtual void triggerCollision(Runtime *runtime, Structural *collidingElement, bool wasInContact, bool isInContact, bool &outShouldStop) = 0;
2430 };
2431 
2433  enum EdgeFlags {
2434  kEdgeTop = 0x1,
2435  kEdgeBottom = 0x2,
2436  kEdgeLeft = 0x4,
2437  kEdgeRight = 0x8,
2438  };
2439 
2440  virtual void getCollisionProperties(Modifier *&modifier, uint &edgeFlags, bool &mustBeCompletelyOutside, bool &continuous) const = 0;
2441  virtual void triggerCollision(Runtime *runtime) = 0;
2442 };
2443 
2444 struct IPostEffect : public IInterfaceBase {
2445  virtual void renderPostEffect(Graphics::ManagedSurface &surface) const = 0;
2446 };
2447 
2449  virtual Modifier *getMediaCueModifier() = 0;
2450  virtual Common::WeakPtr<Modifier> getMediaCueTriggerSource() const = 0;
2451 };
2452 
2454  enum TriggerTiming {
2455  kTriggerTimingStart = 0,
2456  kTriggerTimingDuring = 1,
2457  kTriggerTimingEnd = 2,
2458  };
2459 
2460  int32 minTime;
2461  int32 maxTime;
2462 
2463  IMediaCueModifier *sourceModifier;
2464  TriggerTiming triggerTiming;
2465  MessengerSendSpec send;
2466  DynamicValue incomingData;
2467 
2468  MediaCueState();
2469  void checkTimestampChange(Runtime *runtime, uint32 oldTS, uint32 newTS, bool continuousTimestamps, bool canTriggerDuring);
2470 };
2471 
2472 class Project : public Structural {
2473 public:
2474  explicit Project(Runtime *runtime);
2475  ~Project();
2476 
2477  VThreadState asyncConsumeCommand(Runtime *runtime, const Common::SharedPtr<MessageProperties> &msg) override;
2478 
2479  MiniscriptInstructionOutcome writeRefAttribute(MiniscriptThread *thread, DynamicValueWriteProxy &result, const Common::String &attrib) override;
2480 
2481  void loadFromDescription(const ProjectDescription &desc, const Hacks &hacks);
2482  void loadSceneFromStream(const Common::SharedPtr<Structural> &structural, uint32 streamID, const Hacks &hacks);
2483 
2484  Common::SharedPtr<Modifier> resolveAlias(uint32 aliasID) const;
2485  Common::SharedPtr<Modifier> findGlobalVarWithName(const Common::String &name) const;
2486  void materializeGlobalVariables(Runtime *runtime, ObjectLinkingScope *scope);
2487 
2488  const ProjectPresentationSettings &getPresentationSettings() const;
2489 
2490  bool isProject() const override;
2491 
2492  Common::String getAssetNameByID(uint32 assetID) const;
2493  Common::WeakPtr<Asset> getAssetByID(uint32 assetID) const;
2494  bool getAssetIDByName(const Common::String &assetName, uint32 &outAssetID) const;
2495  void forceLoadAsset(uint32 assetID, Common::Array<Common::SharedPtr<Asset> > &outHoldAssets);
2496 
2497  size_t getSegmentForStreamIndex(size_t streamIndex) const;
2498  void openSegmentStream(int segmentIndex);
2499  void closeSegmentStream(int segmentIndex);
2500  Common::SeekableReadStream *getStreamForSegment(int segmentIndex);
2501 
2502  const Common::String *findNameOfLabel(const Label &label) const;
2503 
2504  void onPostRender();
2505  void onKeyboardEvent(Runtime *runtime, const KeyboardInputEvent &keyEvt);
2506 
2507  Common::SharedPtr<SegmentUnloadSignaller> notifyOnSegmentUnload(int segmentIndex, ISegmentUnloadSignalReceiver *receiver);
2508  Common::SharedPtr<KeyboardEventSignaller> notifyOnKeyboardEvent(IKeyboardEventReceiver *receiver);
2510 
2511  const char *findAuthorMessageName(uint32 id) const;
2512 
2513  const Common::SharedPtr<CursorGraphicCollection> &getCursorGraphics() const;
2514 
2515  const SubtitleTables &getSubtitles() const;
2516 
2517  RuntimeVersion getRuntimeVersion() const;
2518  ProjectPlatform getPlatform() const;
2519 
2520  void visitInternalReferences(IStructuralReferenceVisitor *visitor) override;
2521  Common::SharedPtr<Structural> shallowClone() const override;
2522 
2523 #ifdef MTROPOLIS_DEBUG_ENABLE
2524  const char *debugGetTypeName() const override { return "Project"; }
2525 #endif
2526 
2527 private:
2528  struct LabelSuperGroup {
2529  LabelSuperGroup();
2530 
2531  size_t firstRootNodeIndex;
2532  size_t numRootNodes;
2533  size_t numTotalNodes;
2534 
2535  uint32 superGroupID;
2536  Common::String name;
2537  };
2538 
2539  struct LabelTree {
2540  LabelTree();
2541 
2542  size_t firstChildIndex;
2543  size_t numChildren;
2544 
2545  uint32 id;
2546  Common::String name;
2547  };
2548 
2549  struct Segment {
2550  Segment();
2551 
2552  SegmentDescription desc;
2554 
2555  Common::SeekableReadStream *weakStream;
2557  };
2558 
2559  enum StreamType {
2560  kStreamTypeUnknown,
2561 
2562  kStreamTypeAsset,
2563  kStreamTypeBoot,
2564  kStreamTypeScene,
2565  };
2566 
2567  struct StreamDesc {
2568  StreamDesc();
2569 
2570  StreamType streamType;
2571  uint16 segmentIndex;
2572  uint32 size;
2573  uint32 pos;
2574  };
2575 
2576  struct AssetDesc {
2577  AssetDesc();
2578 
2579  uint32 typeCode;
2580  uint32 streamID;
2581  uint32 filePosition;
2582  size_t id;
2583  Common::String name;
2584 
2585  // If the asset is live, this will be its asset info
2586  Common::WeakPtr<Asset> asset;
2587  };
2588 
2589  void loadBootStream(size_t streamIndex, const Hacks &hacks);
2590 
2591  void loadPresentationSettings(const Data::PresentationSettings &presentationSettings);
2592  void loadAssetCatalog(const Data::AssetCatalog &assetCatalog);
2593  void loadGlobalObjectInfo(ChildLoaderStack &loaderStack, const Data::GlobalObjectInfo &globalObjectInfo);
2594  void loadAssetDef(size_t streamIndex, AssetDefLoaderContext &context, const Data::DataObject &dataObject);
2595  void loadContextualObject(size_t streamIndex, ChildLoaderStack &stack, const Data::DataObject &dataObject);
2596  Common::SharedPtr<Modifier> loadModifierObject(ModifierLoaderContext &loaderContext, const Data::DataObject &dataObject);
2597  void loadLabelMap(const Data::ProjectLabelMap &projectLabelMap);
2598  static size_t recursiveCountLabels(const Data::ProjectLabelMap::LabelTree &tree);
2599 
2600  ObjectLinkingScope *getPersistentStructuralScope() override;
2601  ObjectLinkingScope *getPersistentModifierScope() override;
2602 
2603  void assignAssets(const Common::Array<Common::SharedPtr<Asset> > &assets, const Hacks &hacks);
2604 
2605  void initAdditionalSegments(const Common::String &projectName);
2606 
2607  Common::Array<Segment> _segments;
2608  Common::Array<StreamDesc> _streams;
2609  Common::Array<LabelTree> _labelTree;
2610  Common::Array<LabelSuperGroup> _labelSuperGroups;
2611  Data::ProjectFormat _projectFormat;
2612 
2613  Common::Array<AssetDesc *> _assetsByID;
2614  Common::Array<AssetDesc> _realAssets;
2615 
2617 
2618  ProjectPresentationSettings _presentationSettings;
2619 
2620  bool _haveGlobalObjectInfo;
2621  bool _haveProjectStructuralDef;
2622  SimpleModifierContainer _globalModifiers;
2623 
2624  ProjectPlugInRegistry _plugInRegistry;
2625 
2629 
2630  ObjectLinkingScope _structuralScope;
2631  ObjectLinkingScope _modifierScope;
2632 
2633  Common::SharedPtr<PlayMediaSignaller> _playMediaSignaller;
2634  Common::SharedPtr<KeyboardEventSignaller> _keyboardEventSignaller;
2635 
2636  SubtitleTables _subtitles;
2637 
2638  ProjectPlatform _platform;
2639 
2640  Common::Archive *_rootArchive;
2641  Common::Path _projectRootDir;
2642 
2643  RuntimeVersion _runtimeVersion;
2644  bool _isRuntimeVersionAutoDetect;
2645 };
2646 
2647 class Section : public Structural {
2648 public:
2649  bool load(const Data::SectionStructuralDef &data);
2650 
2651  bool isSection() const override;
2652 
2653  Common::SharedPtr<Structural> shallowClone() const override;
2654  void visitInternalReferences(IStructuralReferenceVisitor *visitor) override;
2655 
2656 #ifdef MTROPOLIS_DEBUG_ENABLE
2657  const char *debugGetTypeName() const override { return "Section"; }
2658 #endif
2659 
2660 private:
2661  ObjectLinkingScope *getPersistentStructuralScope() override;
2662  ObjectLinkingScope *getPersistentModifierScope() override;
2663 
2664  ObjectLinkingScope _structuralScope;
2665  ObjectLinkingScope _modifierScope;
2666 };
2667 
2668 class Subsection : public Structural {
2669 public:
2670  bool load(const Data::SubsectionStructuralDef &data);
2671 
2672  bool readAttribute(MiniscriptThread *thread, DynamicValue &result, const Common::String &attrib) override;
2673 
2674  ObjectLinkingScope *getSceneLoadMaterializeScope();
2675 
2676  bool isSubsection() const override;
2677 
2678  Common::SharedPtr<Structural> shallowClone() const override;
2679  void visitInternalReferences(IStructuralReferenceVisitor *visitor) override;
2680 
2681 #ifdef MTROPOLIS_DEBUG_ENABLE
2682  const char *debugGetTypeName() const override { return "Subsection"; }
2683 #endif
2684 
2685 private:
2686  ObjectLinkingScope *getPersistentStructuralScope() override;
2687  ObjectLinkingScope *getPersistentModifierScope() override;
2688 
2689  ObjectLinkingScope _structuralScope;
2690  ObjectLinkingScope _modifierScope;
2691 };
2692 
2693 class Element : public Structural {
2694 public:
2695  Element();
2696 
2697  virtual bool isVisual() const = 0;
2698  virtual bool canAutoPlay() const;
2699  virtual void queueAutoPlayEvents(Runtime *runtime, bool isAutoPlaying);
2700 
2701  bool isElement() const override;
2702 
2703  uint32 getStreamLocator() const;
2704 
2705  void addMediaCue(MediaCueState *mediaCue);
2706  void removeMediaCue(const MediaCueState *mediaCue);
2707 
2708  void triggerAutoPlay(Runtime *runtime);
2709  virtual void tryAutoSetName(Runtime *runtime, Project *project);
2710 
2711  virtual bool resolveMediaMarkerLabel(const Label &label, int32 &outResolution) const;
2712 
2713  void visitInternalReferences(IStructuralReferenceVisitor *visitor) override;
2714 
2716 
2717 protected:
2718  Element(const Element &other);
2719 
2720  uint32 _streamLocator;
2721  uint16 _sectionID;
2722 
2723  Common::Array<MediaCueState *> _mediaCues;
2724 
2725  bool _haveCheckedAutoPlay;
2726 };
2727 
2729 public:
2731 
2732  uint8 getAlpha() const;
2733  void setAlpha(uint8 alpha);
2734 
2735  bool isDirty() const;
2736  void clearDirty();
2737 
2738 private:
2739  uint8 _alpha;
2740  bool _isDirty;
2741 };
2742 
2744 public:
2747 
2748  enum InkMode {
2749  kInkModeCopy = 0x0,
2750  kInkModeTransparent = 0x1, // src*dest
2751  kInkModeGhost = 0x3, // (1-src)+dest
2752  kInkModeReverseCopy = 0x4, // 1-src
2753  kInkModeReverseGhost = 0x7, // src+dest
2754  kInkModeReverseTransparent = 0x9, // (1-src)*dest
2755  kInkModeBlend = 0x20, // (src*bgcolor)+(dest*(1-bgcolor)
2756  kInkModeBackgroundTransparent = 0x24, // BG color is transparent
2757  kInkModeChameleonDark = 0x25, // src+dest
2758  kInkModeChameleonLight = 0x27, // src*dest
2759  kInkModeBackgroundMatte = 0x224, // BG color is transparent and non-interactive
2760  kInkModeInvisible = 0xffff, // Not drawn, but interactive
2761 
2762  kInkModeXor = 0x7ffffff0, // Fake ink mode for Obsidian canvas puzzle, not a valid value from data
2763  kInkModeDefault = 0x7fffffff, // Not a valid value from data
2764  };
2765 
2766  enum Shape {
2767  kShapeRect = 0x1,
2768  kShapeRoundedRect = 0x2,
2769  kShapeOval = 0x3,
2770  kShapePolygon = 0x9,
2771  kShapeStar = 0xb, // 5-point star, horizontal arms are at (top+bottom*2)/3
2772 
2773  // Fake shapes for Obsidian canvas puzzle, not a valid from data
2774  kShapeObsidianCanvasPuzzleTri1 = 0x7ffffff1,
2775  kShapeObsidianCanvasPuzzleTri2 = 0x7ffffff2,
2776  kShapeObsidianCanvasPuzzleTri3 = 0x7ffffff3,
2777  kShapeObsidianCanvasPuzzleTri4 = 0x7ffffff4,
2778  };
2779 
2780  InkMode getInkMode() const;
2781  void setInkMode(InkMode inkMode);
2782 
2783  Shape getShape() const;
2784  void setShape(Shape shape);
2785 
2786  const ColorRGB8 &getForeColor() const;
2787  void setForeColor(const ColorRGB8 &color);
2788 
2789  const ColorRGB8 &getBackColor() const;
2790  void setBackColor(const ColorRGB8 &color);
2791 
2792  const ColorRGB8 &getBorderColor() const;
2793  void setBorderColor(const ColorRGB8 &color);
2794 
2795  const ColorRGB8 &getShadowColor() const;
2796  void setShadowColor(const ColorRGB8 &color);
2797 
2798  uint16 getBorderSize() const;
2799  void setBorderSize(uint16 size);
2800 
2801  uint16 getShadowSize() const;
2802  void setShadowSize(uint16 size);
2803 
2804  const Common::Array<Common::Point> &getPolyPoints() const;
2805  Common::Array<Common::Point> &modifyPolyPoints();
2806 
2807  bool isDirty() const;
2808  void clearDirty();
2809 
2811 
2812 private:
2813  InkMode _inkMode;
2814  Shape _shape;
2815  ColorRGB8 _foreColor;
2816  ColorRGB8 _backColor;
2817  uint16 _borderSize;
2818  ColorRGB8 _borderColor;
2819  uint16 _shadowSize;
2820  ColorRGB8 _shadowColor;
2821 
2822  Common::Array<Common::Point> _polyPoints;
2823 
2824  bool _isDirty;
2825 };
2826 
2827 class VisualElement : public Element {
2828 public:
2829  VisualElement();
2830 
2831  bool isVisual() const override;
2832  virtual bool isTextLabel() const;
2833 
2835  CORO_DEFINE_RETURN_TYPE(void);
2836  CORO_DEFINE_PARAMS_3(VisualElement *, self, Runtime *, runtime, Common::SharedPtr<MessageProperties>, msg);
2837  };
2838 
2839  VThreadState asyncConsumeCommand(Runtime *runtime, const Common::SharedPtr<MessageProperties> &msg) override;
2840 
2841  bool respondsToEvent(const Event &evt) const override;
2842  VThreadState consumeMessage(Runtime *runtime, const Common::SharedPtr<MessageProperties> &msg) override;
2843 
2844  bool isVisible() const;
2845  bool isVisibleByDefault() const;
2846  void setVisible(Runtime *runtime, bool visible);
2847 
2848  bool isDirectToScreen() const;
2849  void setDirectToScreen(bool directToScreen);
2850 
2851  uint16 getLayer() const;
2852  void setLayer(uint16 layer);
2853 
2854  bool isMouseInsideDrawableArea(int32 relativeX, int32 relativeY) const;
2855 
2856  // Returns true if there is mouse collision at a specified point, assuming it has already passed isMouseInsideBox
2857  virtual bool isMouseCollisionAtPoint(int32 relativeX, int32 relativeY) const;
2858 
2859  bool readAttribute(MiniscriptThread *thread, DynamicValue &result, const Common::String &attrib) override;
2860  MiniscriptInstructionOutcome writeRefAttribute(MiniscriptThread *thread, DynamicValueWriteProxy &writeProxy, const Common::String &attrib) override;
2861 
2862  Common::Point getParentOrigin() const;
2863  Common::Point getGlobalPosition() const;
2864  const Common::Rect &getRelativeRect() const;
2865  virtual Common::Rect getRelativeCollisionRect() const;
2866 
2867  void setRelativeRect(const Common::Rect &rect);
2868 
2869  // The cached absolute origin is from the last time the element was rendered.
2870  // Do not rely on it mid-frame.
2871  const Common::Point &getCachedAbsoluteOrigin() const;
2872  void setCachedAbsoluteOrigin(const Common::Point &absOrigin);
2873 
2874  void setDragMotionProperties(const Common::SharedPtr<DragMotionProperties> &dragProps);
2875  const Common::SharedPtr<DragMotionProperties> &getDragMotionProperties() const;
2876 
2877  void handleDragMotion(Runtime *runtime, const Common::Point &initialOrigin, const Common::Point &targetOrigin);
2878 
2880  OffsetTranslateTaskData() : dx(0), dy(0) {}
2881 
2882  int32 dx;
2883  int32 dy;
2884  };
2885 
2886  VThreadState offsetTranslateTask(const OffsetTranslateTaskData &data);
2887 
2888  void setRenderProperties(const VisualElementRenderProperties &props, const Common::WeakPtr<GraphicModifier> &primaryGraphicModifier);
2889  const VisualElementRenderProperties &getRenderProperties() const;
2890  const Common::WeakPtr<GraphicModifier> &getPrimaryGraphicModifier() const;
2891 
2892  void setShading(int16 topLeftBevelShading, int16 bottomRightBevelShading, int16 interiorShading, uint32 bevelSize);
2893 
2894  void setTransitionProperties(const VisualElementTransitionProperties &props);
2895  const VisualElementTransitionProperties &getTransitionProperties() const;
2896 
2897  bool needsRender() const;
2898  virtual void render(Window *window) = 0;
2899  void finalizeRender();
2900 
2901  void setPalette(const Common::SharedPtr<Palette> &palette);
2902  const Common::SharedPtr<Palette> &getPalette() const;
2903 
2904  void visitInternalReferences(IStructuralReferenceVisitor *visitor) override;
2905 
2906  void pushVisibilityChangeTask(Runtime *runtime, bool desiredVisibility);
2907 
2908 #ifdef MTROPOLIS_DEBUG_ENABLE
2909  void debugInspect(IDebugInspectionReport *report) const override;
2910 #endif
2911 
2912 protected:
2913  VisualElement(const VisualElement &other);
2914 
2915  bool loadCommon(const Common::String &name, uint32 guid, const Data::Rect &rect, uint32 elementFlags, uint16 layer, uint32 streamLocator, uint16 sectionID);
2916 
2917  MiniscriptInstructionOutcome scriptSetDirect(MiniscriptThread *thread, const DynamicValue &dest);
2918  MiniscriptInstructionOutcome scriptSetPosition(MiniscriptThread *thread, const DynamicValue &dest);
2919  MiniscriptInstructionOutcome scriptSetPositionX(MiniscriptThread *thread, const DynamicValue &dest);
2920  MiniscriptInstructionOutcome scriptSetPositionY(MiniscriptThread *thread, const DynamicValue &dest);
2921  MiniscriptInstructionOutcome scriptSetCenterPosition(MiniscriptThread *thread, const DynamicValue &dest);
2922  MiniscriptInstructionOutcome scriptSetCenterPositionX(MiniscriptThread *thread, const DynamicValue &dest);
2923  MiniscriptInstructionOutcome scriptSetCenterPositionY(MiniscriptThread *thread, const DynamicValue &dest);
2924  MiniscriptInstructionOutcome scriptSetVisibility(MiniscriptThread *thread, const DynamicValue &result);
2925  MiniscriptInstructionOutcome scriptSetSize(MiniscriptThread *thread, const DynamicValue &dest);
2926  MiniscriptInstructionOutcome scriptSetWidth(MiniscriptThread *thread, const DynamicValue &dest);
2927  MiniscriptInstructionOutcome scriptSetHeight(MiniscriptThread *thread, const DynamicValue &dest);
2928  MiniscriptInstructionOutcome scriptSetLayer(MiniscriptThread *thread, const DynamicValue &dest);
2929 
2930  MiniscriptInstructionOutcome scriptWriteRefPositionAttribute(MiniscriptThread *thread, DynamicValueWriteProxy &writeProxy, const Common::String &attrib);
2931  MiniscriptInstructionOutcome scriptWriteRefSizeAttribute(MiniscriptThread *thread, DynamicValueWriteProxy &writeProxy, const Common::String &attrib);
2932  MiniscriptInstructionOutcome scriptWriteRefCenterPositionAttribute(MiniscriptThread *thread, DynamicValueWriteProxy &writeProxy, const Common::String &attrib);
2933 
2934  void offsetTranslate(int32 xDelta, int32 yDelta, bool cachedOriginOnly);
2935  void resize(int32 width, int32 height);
2936 
2937  Common::Point getCenterPosition() const;
2938 
2940  CORO_DEFINE_RETURN_TYPE(void);
2941  CORO_DEFINE_PARAMS_3(VisualElement *, self, Runtime *, runtime, bool, desiredFlag);
2942  };
2943 
2945  ChangeFlagTaskData() : desiredFlag(false), runtime(nullptr) {}
2946 
2947  bool desiredFlag;
2948  Runtime *runtime;
2949  };
2950 
2951  VThreadState changeVisibilityTask(const ChangeFlagTaskData &taskData);
2952 
2953  static VisualElement *recursiveFindItemWithLayer(VisualElement *element, int32 layer);
2954 
2955  void renderShading(Graphics::Surface &surf) const;
2956 
2957  static uint32 quantizeShading(uint32 mask, int16 shading);
2958 
2959  static void renderShadingScanlineDynamic(void *data, size_t numElements, uint32 rMask, uint32 rAdd, uint32 gMask, uint32 gAdd, uint32 bMask, uint32 bAdd, bool isBrighten, byte bytesPerPixel);
2960 
2961  template<class TElement>
2962  static void renderBrightenScanline(TElement *element, size_t numElements, TElement rMask, TElement rAdd, TElement gMask, TElement gAdd, TElement bMask, TElement bAdd);
2963 
2964  template<class TElement>
2965  static void renderDarkenScanline(TElement *element, size_t numElements, TElement rMask, TElement rSub, TElement gMask, TElement gSub, TElement bMask, TElement bSub);
2966 
2967  bool _directToScreen;
2968  bool _visible;
2969  bool _visibleByDefault;
2970  Common::Rect _rect;
2971  Common::Point _cachedAbsoluteOrigin;
2972  uint16 _layer;
2973 
2974  int16 _topLeftBevelShading;
2975  int16 _bottomRightBevelShading;
2976  int16 _interiorShading;
2977  uint32 _bevelSize;
2978 
2980 
2981  // Quirk: When a graphic modifier is applied, it becomes the primary graphic modifier, and disabling it
2982  // will only take effect if it's the primary graphic modifier.
2983  VisualElementRenderProperties _renderProps;
2984  Common::WeakPtr<GraphicModifier> _primaryGraphicModifier;
2985 
2986  VisualElementTransitionProperties _transitionProps;
2987 
2988  Common::SharedPtr<Palette> _palette;
2989 
2990  Common::Rect _prevRect;
2991  bool _contentsDirty;
2992 };
2993 
2994 class NonVisualElement : public Element {
2995 public:
2996  bool isVisual() const override;
2997 
2998  bool loadCommon(const Common::String &name, uint32 guid, uint32 elementFlags);
2999 
3001 };
3002 
3004  ModifierFlags();
3005  bool load(const uint32 dataModifierFlags);
3006 
3007  bool isLastModifier : 1;
3008  bool flagsWereLoaded : 1;
3009 };
3010 
3012 public:
3013  virtual ~ModifierSaveLoad();
3014 
3015  void save(Modifier *modifier, Common::WriteStream *stream);
3016  bool load(Modifier *modifier, Common::ReadStream *stream, uint32 saveFileVersion);
3017  virtual void commitLoad() const = 0;
3018 
3019 protected:
3020  // Saves the modifier state to a stream
3021  virtual void saveInternal(Common::WriteStream *stream) const = 0;
3022 
3023  // Loads the modifier state from a stream into the save/load state and returns true
3024  // if successful. This will not trigger any actual changes until "commit" is called.
3025  virtual bool loadInternal(Common::ReadStream *stream, uint32 saveFileVersion) = 0;
3026 };
3027 
3029 public:
3030  virtual ~ModifierHooks();
3031 
3032  virtual void onCreate(Modifier *modifier);
3033 };
3034 
3035 class Modifier : public RuntimeObject, public IMessageConsumer, public Debuggable {
3036 public:
3037  Modifier();
3038  virtual ~Modifier();
3039 
3040  bool readAttribute(MiniscriptThread *thread, DynamicValue &result, const Common::String &attrib) override;
3041  MiniscriptInstructionOutcome writeRefAttribute(MiniscriptThread *thread, DynamicValueWriteProxy &writeProxy, const Common::String &attrib) override;
3042 
3043  void materialize(Runtime *runtime, ObjectLinkingScope *outerScope);
3044 
3045  virtual bool isAlias() const;
3046  virtual bool isVariable() const;
3047  virtual bool isBehavior() const;
3048  virtual bool isCompoundVariable() const;
3049  virtual bool isKeyboardMessenger() const;
3050  virtual Common::SharedPtr<ModifierSaveLoad> getSaveLoad(Runtime *runtime);
3051 
3052  bool isModifier() const override;
3053 
3054  // This should only return a propagation container if messages should actually be propagated (i.e. NOT switched-off behaviors!)
3055  virtual IModifierContainer *getMessagePropagationContainer();
3056  virtual IModifierContainer *getChildContainer();
3057 
3058  const Common::WeakPtr<RuntimeObject> &getParent() const;
3059  void setParent(const Common::WeakPtr<RuntimeObject> &parent);
3060 
3061  Modifier *findNextSibling() const;
3062  Modifier *findPrevSibling() const;
3063 
3064  bool respondsToEvent(const Event &evt) const override;
3065  VThreadState consumeMessage(Runtime *runtime, const Common::SharedPtr<MessageProperties> &msg) override;
3066 
3067  void setName(const Common::String &name);
3068  const Common::String &getName() const;
3069 
3070  const ModifierFlags &getModifierFlags() const;
3071 
3072  // Shallow clones only need to copy the object. Descendent copies are done using visitInternalReferences.
3073  virtual Common::SharedPtr<Modifier> shallowClone() const = 0;
3074 
3075  // Returns the default name of the modifier. This isn't optional: It can cause behavioral changes, e.g.
3076  // Obsidian depends on this working properly to resolve the TextWork modifier in the Piazza.
3077  virtual const char *getDefaultName() const = 0;
3078 
3079  // Visits any internal references in the object.
3080  // Any references to other elements owned by the object MUST be SharedPtr, any references to non-owned objects
3081  // MUST be WeakPtr, in order for the cloning and materialization logic to work correctly.
3082  virtual void visitInternalReferences(IStructuralReferenceVisitor *visitor);
3083 
3084  bool loadPlugInHeader(const PlugInModifierLoaderContext &plugInContext);
3085 
3086  void recursiveCollectObjectsMatchingCriteria(Common::Array<Common::WeakPtr<RuntimeObject> > &results, bool (*evalFunc)(void *userData, RuntimeObject *object), void *userData, bool onlyEnabled);
3087 
3088  Structural *findStructuralOwner() const;
3089 
3090  void setHooks(const Common::SharedPtr<ModifierHooks> &hooks);
3091  const Common::SharedPtr<ModifierHooks> &getHooks() const;
3092 
3093  // Recursively disable due to containing behavior being disabled
3094  virtual void disable(Runtime *runtime) = 0;
3095 
3096 #ifdef MTROPOLIS_DEBUG_ENABLE
3097  SupportStatus debugGetSupportStatus() const override;
3098  const Common::String &debugGetName() const override;
3099  void debugInspect(IDebugInspectionReport *report) const override;
3100 #endif
3101 
3102 protected:
3103  bool loadTypicalHeader(const Data::TypicalModifierHeader &typicalHeader);
3104 
3105  // Links any references contained in the object, resolving static GUIDs to runtime object references.
3106  // If you override this, you should override visitInternalReferences too
3107  virtual void linkInternalReferences(ObjectLinkingScope *scope);
3108 
3109  Common::String _name;
3110  ModifierFlags _modifierFlags;
3112 
3114 };
3115 
3117 public:
3118  virtual ~VariableStorage();
3119  virtual Common::SharedPtr<ModifierSaveLoad> getSaveLoad(Runtime *runtime) = 0;
3120 
3121  virtual Common::SharedPtr<VariableStorage> clone() const = 0;
3122 };
3123 
3124 class VariableModifier : public Modifier {
3125 public:
3126  explicit VariableModifier(const Common::SharedPtr<VariableStorage> &storage);
3127  VariableModifier(const VariableModifier &other);
3128 
3129  virtual bool isVariable() const override;
3130  virtual bool isListVariable() const;
3131 
3132  virtual Common::SharedPtr<ModifierSaveLoad> getSaveLoad(Runtime *runtime) override final;
3133 
3134  const Common::SharedPtr<VariableStorage> &getStorage() const;
3135  void setStorage(const Common::SharedPtr<VariableStorage> &storage);
3136 
3137  virtual bool varSetValue(MiniscriptThread *thread, const DynamicValue &value) = 0;
3138  virtual void varGetValue(DynamicValue &dest) const = 0;
3139 
3140  bool readAttribute(MiniscriptThread *thread, DynamicValue &result, const Common::String &attrib) override;
3141 
3142  void disable(Runtime *runtime) override;
3143 
3144  virtual DynamicValueWriteProxy createWriteProxy();
3145 
3146 #ifdef MTROPOLIS_DEBUG_ENABLE
3147  void debugInspect(IDebugInspectionReport *report) const override;
3148 #endif
3149 
3150 private:
3151  VariableModifier() = delete;
3152 
3153  struct WriteProxyInterface {
3154  static MiniscriptInstructionOutcome write(MiniscriptThread *thread, const DynamicValue &dest, void *objectRef, uintptr ptrOrOffset);
3155  static MiniscriptInstructionOutcome refAttrib(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib);
3156  static MiniscriptInstructionOutcome refAttribIndexed(MiniscriptThread *thread, DynamicValueWriteProxy &proxy, void *objectRef, uintptr ptrOrOffset, const Common::String &attrib, const DynamicValue &index);
3157  };
3158 
3159 protected:
3161 };
3162 
3163 enum AssetType {
3164  kAssetTypeNone,
3165 
3166  kAssetTypeMovie,
3167  kAssetTypeAudio,
3168  kAssetTypeColorTable,
3169  kAssetTypeImage,
3170  kAssetTypeText,
3171  kAssetTypeMToon,
3172  kAssetTypeAVIMovie,
3173 };
3174 
3175 class AssetHooks {
3176 public:
3177  virtual ~AssetHooks();
3178 
3179  virtual void onLoaded(Asset *asset, const Common::String &name);
3180 };
3181 
3182 class Asset {
3183 public:
3184  Asset();
3185  virtual ~Asset();
3186 
3187  uint32 getAssetID() const;
3188 
3189  virtual AssetType getAssetType() const = 0;
3190 
3191 protected:
3192  uint32 _assetID;
3193 };
3194 
3195 
3196 } // End of namespace MTropolis
3197 
3198 #endif
Definition: managed_surface.h:51
Definition: runtime.h:1353
Definition: runtime.h:816
Definition: runtime.h:418
Definition: runtime.h:1299
Definition: runtime.h:2151
Definition: runtime.h:2034
Definition: runtime.h:3028
Definition: runtime.h:1172
Definition: str.h:59
Definition: runtime.h:469
Definition: data.h:599
Definition: surface.h:67
Definition: runtime.h:2359
Definition: runtime.h:2413
Definition: runtime.h:1474
Definition: runtime.h:330
Definition: modifier_factory.h:30
Definition: runtime.h:3003
Definition: ptr.h:115
Definition: runtime.h:925
Definition: stream.h:77
Definition: runtime.h:2453
Definition: runtime.h:1562
Definition: runtime.h:1192
Definition: array.h:52
Definition: pixelformat.h:138
Definition: runtime.h:2315
EventType
Definition: events.h:49
Definition: runtime.h:1203
Definition: debug.h:145
Definition: modifier_factory.h:44
Definition: random.h:44
Definition: runtime.h:2195
Definition: data.h:534
Definition: runtime.h:2409
Definition: runtime.h:2444
Definition: runtime.h:440
Definition: rect.h:144
Definition: runtime.h:1594
Definition: runtime.h:488
Definition: runtime.h:503
Definition: path.h:52
Definition: runtime.h:2373
Definition: runtime.h:2693
Definition: runtime.h:2052
Definition: stream.h:745
Definition: runtime.h:1185
Definition: runtime.h:3035
Definition: runtime.h:2040
Definition: debug.h:83
Definition: runtime.h:2647
Definition: runtime.h:2390
Definition: ptr.h:572
Definition: miniscript.h:421
Definition: runtime.h:2827
Definition: runtime.h:544
Definition: render.h:93
Definition: archive.h:141
Definition: runtime.h:1197
Definition: runtime.h:1231
Definition: modifier_factory.h:48
Definition: noncopyable.h:39
Definition: runtime.h:1524
Definition: runtime.h:369
Definition: runtime.h:2131
Definition: runtime.h:351
Definition: runtime.h:1079
Definition: runtime.h:1456
Definition: runtime.h:1579
Definition: mixer.h:59
Definition: runtime.h:1307
Definition: runtime.h:609
Definition: runtime.h:2432
Definition: runtime.h:1210
Definition: runtime.h:2355
Definition: runtime.h:574
Definition: runtime.h:2118
Definition: hashmap.h:85
Definition: runtime.h:624
Definition: runtime.h:2668
Definition: data.h:399
Definition: atari-cursor.h:38
Definition: runtime.h:2377
Definition: cursor.h:42
Definition: runtime.h:1180
Definition: debug.h:59
Definition: subtitles.h:123
Definition: runtime.h:3182
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: rect.h:45
Definition: runtime.h:1108
Definition: runtime.h:3124
Definition: data.h:929
Definition: runtime.h:2162
Definition: data.h:356
Definition: runtime.h:1220
Definition: runtime.h:1552
Definition: saveload.h:59
Definition: debug.h:110
Definition: runtime.h:3175
Definition: data.h:332
Definition: runtime.h:589
Definition: runtime.h:2994
Definition: data.h:365
Definition: vthread.h:133
Definition: runtime.h:114
Definition: runtime.h:744
Definition: actions.h:25
Definition: runtime.h:1033
Definition: runtime.h:559
Definition: modifier_factory.h:40
Definition: hacks.h:40
Definition: saveload.h:54
Definition: runtime.h:2323
Definition: keyboard.h:294
Definition: runtime.h:1570
Definition: runtime.h:2125
Definition: stream.h:385
Definition: runtime.h:1360
Definition: runtime.h:2327
Definition: runtime.h:2184
Definition: data.h:505
Definition: runtime.h:391
Definition: system.h:161
Definition: runtime.h:3011
Definition: runtime.h:2103
Definition: ptr.h:159
Definition: runtime.h:2427
Definition: runtime.h:1513
Definition: runtime.h:1538
Definition: runtime.h:551
Definition: data.h:375
Definition: runtime.h:1253
Definition: runtime.h:1438
Definition: runtime.h:2472
Definition: runtime.h:2394
Definition: runtime.h:1025
Definition: runtime.h:1376
Definition: system.h:38
Definition: runtime.h:1385
Definition: runtime.h:536
Definition: runtime.h:2448
Definition: runtime.h:595
Definition: runtime.h:3116
Language
Definition: language.h:45
Definition: core.h:33