- void Start(app::State &ctrl) {
- timer = ctrl.GraphicsTimers().StartInterval(frameTime);
- }
- void Start(app::Application &ctrl) {
- timer = ctrl.GlobalTimers().StartInterval(frameTime);
- }
- void Stop() {
- timer = app::Timer<Uint32>();
- }
- bool Started() const {
- return timer.Started();
- }
- bool Running() const {
- return timer.Running() && (repeat || timer.Iteration() < NumFrames());
- }
- bool Finished() const {
- return Started() && !Running();
- }
- bool JustFinished() const {
- return timer.JustHit() && timer.Iteration() == NumFrames();
- }
+ const Sprite *GetSprite() const { return sprite; }
+ int FrameTime() const { return frameTime; }
+ bool Repeat() const { return repeat; }
+
+public:
+ void SetSprite(const Sprite *s) { sprite = s; }
+ void SetFrameTime(int t) { frameTime = t; }
+ void SetRepeat(bool r) { repeat = r; }
+
+public:
+ virtual int NumFrames() const = 0;
+ virtual int Col(int frame) const = 0;
+ virtual int Row(int frame) const = 0;
+ virtual math::Vector<int> Offset(int frame) const { return math::Vector<int>(); }
+
+ static void CreateTypeDescription();
+
+protected:
+ static void AddFields(loader::TypeDescription &, const Animation &, std::ptrdiff_t offset);
+
+private:
+ const Sprite *sprite;
+ int frameTime;
+ bool repeat;
+
+};
+
+
+class AnimationRunner {
+
+public:
+ explicit AnimationRunner(const Animation *a = 0, int colOffset = 0, int rowOffset = 0)
+ : animation(a), sprite(0), frameShift(0), colOffset(colOffset), rowOffset(rowOffset) { }
+
+public:
+ bool Valid() const { return animation; }
+ void Clear() { animation = 0; timer = app::Timer<Uint32>(); }
+
+ void Start(app::State &ctrl);
+ void Start(app::Application &ctrl);
+ void Synchronize(const AnimationRunner &other) { timer = other.timer; }
+ void Stop();
+ bool Started() const;
+ bool Running() const;
+ bool Finished() const;
+ bool JustFinished() const;