changeset 31:9a9f4447af7c

add animation renderer
author spq@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 11 Jul 2008 14:35:31 +0000
parents 9c3f37432a28
children 75b6394ced14
files engine/core/view/renderers/genericrenderer.cpp engine/core/view/renderers/genericrenderer.h
diffstat 2 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/engine/core/view/renderers/genericrenderer.cpp	Fri Jul 11 13:08:44 2008 +0000
+++ b/engine/core/view/renderers/genericrenderer.cpp	Fri Jul 11 14:35:31 2008 +0000
@@ -36,6 +36,7 @@
 #include "util/math/fife_math.h"
 #include "util/log/logger.h"
 #include "model/metamodel/grids/cellgrid.h"
+#include "model/metamodel/timeprovider.h"
 #include "model/structures/instance.h"
 #include "model/structures/layer.h"
 #include "model/structures/location.h"
@@ -244,10 +245,21 @@
 	GenericRendererAnimationInfo::GenericRendererAnimationInfo(GenericRendererNode anchor, int animation):
 		GenericRendererElementInfo(),
 		m_anchor(anchor),
-		m_animation(animation) {
+		m_animation(animation),
+		m_start_time(SDL_GetTicks()),
+		m_time_scale(1.0) {
 	}
 	void GenericRendererAnimationInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
-		return;
+		Point p = m_anchor.getCalculatedPoint(cam, layer, instances);
+		Animation& animation = animpool->getAnimation(m_animation);
+		int animtime = scaleTime(m_time_scale, SDL_GetTicks() - m_start_time) % animation.getDuration();
+		Image* img = animation.getFrameByTimestamp(animtime);
+		Rect r;
+		r.x = p.x-img->getWidth()/2;
+		r.y = p.y-img->getHeight()/2;
+		r.w = img->getWidth();
+		r.h = img->getHeight();
+		img->render(r);
 	}
 	
 	GenericRendererTextInfo::GenericRendererTextInfo(GenericRendererNode anchor, AbstractFont* font, std::string text):
--- a/engine/core/view/renderers/genericrenderer.h	Fri Jul 11 13:08:44 2008 +0000
+++ b/engine/core/view/renderers/genericrenderer.h	Fri Jul 11 14:35:31 2008 +0000
@@ -135,6 +135,8 @@
 	private:
 		GenericRendererNode m_anchor;
 		int m_animation;
+		unsigned int m_start_time;
+		float m_time_scale;
 	};
 	class GenericRendererTextInfo : public GenericRendererElementInfo {
 	public: