ScummVM API documentation
anim.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 STARK_RESOURCES_ANIM_H
23 #define STARK_RESOURCES_ANIM_H
24 
25 #include "common/path.h"
26 #include "common/rect.h"
27 #include "common/str.h"
28 
29 #include "engines/stark/resources/object.h"
30 
31 namespace Common {
32 class SeekableReadStream;
33 }
34 
35 namespace Stark {
36 
37 class SkeletonAnim;
38 class VisualActor;
39 class VisualProp;
40 class VisualSmacker;
41 class Visual;
42 namespace Formats {
43 class XRCReadStream;
44 }
45 
46 namespace Resources {
47 
48 class Direction;
49 class Image;
50 class Item;
51 class ItemVisual;
52 
58 class Anim : public Object {
59 public:
60  static const Type::ResourceType TYPE = Type::kAnim;
61 
62  enum SubType {
63  kAnimImages = 1,
64  kAnimProp = 2,
65  kAnimVideo = 3,
66  kAnimSkeleton = 4
67  };
68 
69  enum ActionUsage {
70  kActionUsagePassive = 1,
71  kActionUsageActive = 2
72  };
73 
74  enum UIUsage {
75  kUIUsageInventory = 1,
76  kUIUsageUseCursorPassive = 4,
77  kUIUsageUseCursorActive = 5
78  };
79 
80  enum ActorActivity {
81  kActorActivityIdle = 1,
82  kActorActivityWalk = 2,
83  kActorActivityTalk = 3,
84  kActorActivityRun = 6,
85  kActorActivityIdleAction = 10
86  };
87 
89  static Object *construct(Object *parent, byte subType, uint16 index, const Common::String &name);
90 
91  Anim(Object *parent, byte subType, uint16 index, const Common::String &name);
92  ~Anim() override;
93 
94  // Resource API
95  void readData(Formats::XRCReadStream *stream) override;
96 
98  uint32 getCurrentFrame() { return _currentFrame; }
99 
101  virtual void selectFrame(uint32 frameIndex);
102 
104  virtual Visual *getVisual() = 0;
105 
107  virtual void applyToItem(Item *item);
108 
110  virtual void removeFromItem(Item *item);
111 
113  bool isInUse() const;
114 
116  uint32 getActivity() const;
117 
119  virtual int getPointHotspotIndex(const Common::Point &point) const;
120 
122  virtual Common::Point getHotspotPosition(uint index) const { return Common::Point(-1, -1); }
123 
129  virtual void playAsAction(ItemVisual *item);
130 
132  virtual bool isAtTime(uint32 time) const;
133 
135  virtual uint32 getMovementSpeed() const;
136 
138  virtual uint32 getIdleActionFrequency() const;
139 
148  virtual void shouldResetItem(bool resetItem);
149 
154  virtual void resetItem();
155 
161  virtual bool isDone() const;
162 
163 protected:
164  void printData() override;
165 
166  uint32 _activity;
167  uint32 _currentFrame;
168  uint32 _numFrames;
169  int32 _refCount;
170 };
171 
175 class AnimImages : public Anim {
176 public:
177  AnimImages(Object *parent, byte subType, uint16 index, const Common::String &name);
178  ~AnimImages() override;
179 
180  // Resource API
181  void readData(Formats::XRCReadStream *stream) override;
182  void onAllLoaded() override;
183  void saveLoad(ResourceSerializer *serializer) override;
184 
185  // Anim API
186  void selectFrame(uint32 frameIndex) override;
187  Visual *getVisual() override;
188  int getPointHotspotIndex(const Common::Point &point) const override;
189  Common::Point getHotspotPosition(uint index) const override;
190 
191 protected:
192  void printData() override;
193 
194  float _field_3C;
195 
196  uint32 _currentDirection;
197  Common::Array<Direction *> _directions;
198 
199  Image *_currentFrameImage;
200 };
201 
202 class AnimProp : public Anim {
203 public:
204  AnimProp(Object *parent, byte subType, uint16 index, const Common::String &name);
205  ~AnimProp() override;
206 
207  // Resource API
208  void readData(Formats::XRCReadStream *stream) override;
209  void onPostRead() override;
210 
211  // Anim API
212  Visual *getVisual() override;
213  uint32 getMovementSpeed() const override;
214 
215 protected:
216  void printData() override;
217 
218  Common::String _field_3C;
219  Common::Array<Common::Path> _meshFilenames;
220  Common::Path _textureFilename;
221  uint32 _movementSpeed;
222  Common::Path _archiveName;
223 
224  VisualProp *_visual;
225 };
226 
230 class AnimVideo : public Anim {
231 public:
232  AnimVideo(Object *parent, byte subType, uint16 index, const Common::String &name);
233  ~AnimVideo() override;
234 
235  // Resource API
236  void readData(Formats::XRCReadStream *stream) override;
237  void onAllLoaded() override;
238  void onGameLoop() override;
239  void onEnginePause(bool pause) override;
240  void saveLoadCurrent(ResourceSerializer *serializer) override;
241 
242  // Anim API
243  Visual *getVisual() override;
244  void playAsAction(ItemVisual *item) override;
245  void shouldResetItem(bool resetItem) override;
246  void resetItem() override;
247  bool isAtTime(uint32 time) const override;
248  bool isDone() const override { return _done || !isInUse(); }
249 
250 protected:
253 
254  void printData() override;
255  Common::SeekableReadStream *openOverrideFile(const Common::String &extension) const;
256 
258  void updateSmackerPosition();
259 
260  Common::Path _smackerFile;
261  Common::Path _archiveName;
262 
263  VisualSmacker *_smacker;
264 
265  uint32 _width;
266  uint32 _height;
267 
268  PointArray _positions;
269  RectArray _sizes;
270 
271  int32 _frameRateOverride;
272  bool _preload;
273  bool _loop;
274  bool _done;
275 
276  ItemVisual *_actionItem;
277  bool _shouldResetItem;
278 };
279 
283 class AnimSkeleton : public Anim {
284 public:
285  AnimSkeleton(Object *parent, byte subType, uint16 index, const Common::String &name);
286  ~AnimSkeleton() override;
287 
288  // Resource API
289  void readData(Formats::XRCReadStream *stream) override;
290  void onPostRead() override;
291  void onAllLoaded() override;
292  void onGameLoop() override;
293  void onPreDestroy() override;
294 
295  // Anim API
296  void applyToItem(Item *item) override;
297  void removeFromItem(Item *item) override;
298  Visual *getVisual() override;
299  void playAsAction(ItemVisual *item) override;
300  bool isAtTime(uint32 time) const override;
301  bool isDone() const override { return _done || !isInUse(); }
302  uint32 getMovementSpeed() const override;
303  uint32 getIdleActionFrequency() const override;
304  void shouldResetItem(bool resetItem) override;
305  void resetItem() override;
306 
308  uint32 getRemainingTime() const;
309 
311  uint32 getCurrentTime() const;
312 
313 protected:
314  void printData() override;
315 
316  bool _castsShadow;
317  Common::Path _archiveName;
318  Common::Path _animFilename;
319  bool _loop;
320  uint32 _movementSpeed;
321  uint32 _idleActionFrequency;
322 
323  uint32 _totalTime;
324  uint32 _currentTime;
325  bool _done;
326 
327  SkeletonAnim *_skeletonAnim;
328  VisualActor *_visual;
329 
330  ItemVisual *_actionItem;
331  bool _shouldResetItem;
332 };
333 
334 } // End of namespace Resources
335 } // End of namespace Stark
336 
337 #endif // STARK_RESOURCES_ANIM_H
Definition: str.h:59
Definition: visual.h:29
Definition: array.h:52
Definition: item.h:62
Definition: anim.h:58
virtual Common::Point getHotspotPosition(uint index) const
Definition: anim.h:122
Definition: path.h:52
Definition: stream.h:745
uint32 getCurrentFrame()
Definition: anim.h:98
Definition: item.h:139
Definition: smacker.h:46
Definition: anim.h:175
Definition: actor.h:50
Definition: console.h:27
Definition: object.h:143
bool isDone() const override
Definition: anim.h:301
Definition: algorithm.h:29
Definition: rect.h:45
Definition: skeleton_anim.h:36
bool isDone() const override
Definition: anim.h:248
Definition: movie_decoder.h:32
Definition: xrc.h:45
Definition: anim.h:230
Definition: prop.h:42
Definition: anim.h:202
Definition: stateprovider.h:51
Definition: anim.h:283