+void Animation::CreateTypeDescription() {
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Animation"));
+ td.SetDescription("Abstract base type for animations.");
+ td.SetSize(sizeof(Animation));
+}
+
+void Animation::AddFields(TypeDescription &td, const Animation &a, std::ptrdiff_t offset) {
+ td.AddField("sprite", FieldDescription(((char *)&a.sprite) - ((char *)&a) - offset, Sprite::TYPE_ID).SetReferenced().SetDescription("the sprite used for cutting out frames"));
+ td.AddField("frametime", FieldDescription(((char *)&a.frameTime) - ((char *)&a) - offset, Interpreter::NUMBER_ID).SetDescription("duration of a frame in miliseconds"));
+ td.AddField("repeat", FieldDescription(((char *)&a.repeat) - ((char *)&a) - offset, Interpreter::BOOLEAN_ID).SetDescription("whether the animation should start over at the beginning after reaching the last frame"));
+}
+
+
+void AnimationRunner::Start(app::State &ctrl) {
+ assert(animation);
+ timer = ctrl.GraphicsTimers().StartInterval(animation->FrameTime());
+}
+
+void AnimationRunner::Start(app::Application &ctrl) {
+ assert(animation);
+ timer = ctrl.GlobalTimers().StartInterval(animation->FrameTime());
+}
+
+void AnimationRunner::Stop() {
+ timer = app::Timer<Uint32>();
+}
+
+bool AnimationRunner::Started() const {
+ return timer.Started();
+}
+
+bool AnimationRunner::Running() const {
+ return animation
+ && timer.Running()
+ && (animation->Repeat()
+ || timer.Iteration() < animation->NumFrames());
+}
+
+bool AnimationRunner::Finished() const {
+ return Started() && !Running();
+}
+
+bool AnimationRunner::JustFinished() const {
+ return animation
+ && timer.JustHit()
+ && timer.Iteration() == animation->NumFrames();
+}
+
+
+void AnimationRunner::Draw(SDL_Surface *dest, math::Vector<int> position) const {
+ GetSprite()->Draw(dest,
+ position + animation->Offset(Frame()),
+ animation->Col(Frame()) + ColOffset(),
+ animation->Row(Frame()) + RowOffset());
+}