ScummVM API documentation
animation.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 DRACI_ANIMATION_H
23 #define DRACI_ANIMATION_H
24 
25 #include "common/array.h"
26 #include "common/list.h"
27 #include "common/rect.h"
28 #include "draci/sprite.h"
29 
30 namespace Draci {
31 
36 enum {
37  kOverlayImage = -1,
38  kWalkingMapOverlay = -2,
39  kWalkingShortestPathOverlay = -3,
40  kWalkingObliquePathOverlay = -4,
41  kTitleText = -5,
42  kSpeechText = -6,
43  kInventorySprite = -7,
44  kDialogueLinesID = -8,
45  kUnused = -12,
46  kInventoryItemsID = -13
47 };
48 
53 enum { kIgnoreIndex = -2 };
54 
55 class DraciEngine;
56 class Surface;
57 struct SoundSample;
58 
59 class Animation {
60 
61 typedef void (Animation::* AnimationCallback)();
62 
63 public:
64  Animation(DraciEngine *v, int id, uint z, bool playing);
65  ~Animation();
66 
67  uint getZ() const { return _z; }
68  void setZ(uint z) { _z = z; }
69 
70  void setID(int id) { _id = id; }
71  int getID() const { return _id; }
72 
73  void nextFrame(bool force);
74  void drawFrame(Surface *surface);
75 
76  void addFrame(Drawable *frame, const SoundSample *sample);
77  void replaceFrame(int i, Drawable *frame, const SoundSample *sample);
78  const Drawable *getConstCurrentFrame() const;
79  Drawable *getCurrentFrame();
80  Drawable *getFrame(int frameNum);
81  void setCurrentFrame(uint frame);
82  uint currentFrameNum() const { return _currentFrame; }
83  uint getFrameCount() const { return _frames.size(); }
84  void makeLastFrameRelative(int x, int y);
85  void clearShift();
86 
87  bool isPlaying() const { return _playing; }
88  void setPlaying(bool playing);
89 
90  bool isPaused() const { return _paused; }
91  void setPaused(bool paused) { _paused = paused; }
92 
93  bool isLooping() const { return _looping; }
94  void setLooping(bool looping);
95 
96  void setIsRelative(bool value) { _isRelative = value; }
97  bool isRelative() const { return _isRelative; }
98  void setRelative(int relx, int rely);
99  int getRelativeX() const { return _displacement.relX; }
100  int getRelativeY() const { return _displacement.relY; }
101  const Displacement &getDisplacement() const { return _displacement; } // displacement of the whole animation
102  Displacement getCurrentFrameDisplacement() const; // displacement of the current frame (includes _shift)
103  Common::Point getCurrentFramePosition() const; // with displacement and shift applied
104 
105  void supportsQuickAnimation(bool val) { _canBeQuick = val; }
106 
107  int getIndex() const { return _index; }
108  void setIndex(int index) { _index = index; }
109 
110  void setScaleFactors(double scaleX, double scaleY);
111  double getScaleX() const { return _displacement.extraScaleX; }
112  double getScaleY() const { return _displacement.extraScaleY; }
113 
114  void markDirtyRect(Surface *surface) const;
115 
116  // Animation callbacks. They can only do simple things, such as
117  // setting the value of some variable or stopping an animation. In
118  // particular, they cannot run sub-loops or anything like that, because
119  // the callback is called at an arbitrary time without much control
120  // over what the state of the rest of the program is.
121  void registerCallback(AnimationCallback callback) { _callback = callback; }
122 
123  void doNothing() {}
124  void exitGameLoop();
125  void tellWalkingState();
126 
127  void play();
128  void stop();
129  void del();
130 
131 private:
132  uint nextFrameNum() const;
133  void deleteFrames();
134 
138  int _id;
139 
143  int _index;
144 
145  uint _currentFrame;
146  uint _z;
147  Common::Point _shift; // partial sum of _relativeShifts from the beginning of the animation until the current frame
148  bool _hasChangedFrame;
149 
150  Displacement _displacement;
151  bool _isRelative;
152 
153  uint _tick;
154  bool _playing;
155  bool _looping;
156  bool _paused;
157 
158  bool _canBeQuick;
159 
163  Common::Array<Common::Point> _relativeShifts;
169 
170  AnimationCallback _callback;
171 
172  DraciEngine *_vm;
173 };
174 
175 
177 
178 public:
179  AnimationManager(DraciEngine *vm) : _vm(vm), _lastIndex(-1), _animationPauseCounter(0) {}
180  ~AnimationManager() { deleteAll(); }
181 
182  void insert(Animation *anim, bool allocateIndex);
183  Animation *load(uint animNum);
184 
185  void pauseAnimations();
186  void unpauseAnimations();
187 
188  void deleteAnimation(Animation *anim);
189  void deleteOverlays();
190  void deleteAll();
191 
192  void drawScene(Surface *surf);
193 
194  Animation *getAnimation(int id);
195 
196  int getLastIndex() const { return _lastIndex; }
197  void deleteAfterIndex(int index);
198 
199  const Animation *getTopAnimation(int x, int y) const;
200 
201 private:
202  void sortAnimations();
203 
204  DraciEngine *_vm;
205 
209  Common::List<Animation *> _animations;
210 
214  int _lastIndex;
215 
220  int _animationPauseCounter;
221 };
222 
223 } // End of namespace Draci
224 
225 #endif // DRACI_ANIMATION_H
Definition: draci.h:68
Definition: animation.h:59
Definition: array.h:52
Definition: animation.h:176
Definition: list.h:44
Definition: sound.h:42
Definition: surface.h:31
Definition: rect.h:45
Definition: animation.h:30
Definition: sprite.h:45
Definition: sprite.h:35