Bladeren bron

Animator should be faster now

Eiyeron Fulmincendii 10 jaren geleden
bovenliggende
commit
da44436684
1 gewijzigde bestanden met toevoegingen van 16 en 0 verwijderingen
  1. 16 0
      src/render/Animator.cpp

+ 16 - 0
src/render/Animator.cpp

@@ -6,8 +6,24 @@ using namespace WalrusRPG;
 
 namespace
 {
+	unsigned get_animation_duration(const WalrusRPG::Animation &anim) {
+		unsigned duration = 0;
+		for (unsigned index = 0; index < anim.stripe.size(); index++) {
+			duration += anim.stripe[index].duration;
+		}
+		return duration;
+	}
+	
     unsigned find_frame(const WalrusRPG::Animation &anim, signed frame_time)
     {
+		unsigned duration = get_animation_duration(anim);
+		if (frame_time >= duration && !anim.looping) {
+			// simple looping checking
+			// Also, a flag to detect if the animation ended could be an option
+			return anim.stripe[anim.stripe.size() - 1].frame;
+		}
+		frame_time %= duration;
+
         unsigned index = 0;
         do
         {