comparison engine/core/view/renderers/genericrenderer.cpp @ 181:56ac89189bc4

fixed time handling in fife: - the time scaling method was unreliable when changing the time factors (jumping in the moment of the change) - replaced much calls to SDL_GetTicks with TimerManager::instance()->getTime() - some other time related cleanup
author spq@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 31 Jan 2009 04:15:43 +0000
parents 2241b0d5379e
children ad1f09d954f9
comparison
equal deleted inserted replaced
180:66bd7f8c541e 181:56ac89189bc4
33 #include "video/animationpool.h" 33 #include "video/animationpool.h"
34 #include "video/fonts/abstractfont.h" 34 #include "video/fonts/abstractfont.h"
35 #include "video/image.h" 35 #include "video/image.h"
36 #include "util/math/fife_math.h" 36 #include "util/math/fife_math.h"
37 #include "util/log/logger.h" 37 #include "util/log/logger.h"
38 #include "util/time/timemanager.h"
38 #include "model/metamodel/grids/cellgrid.h" 39 #include "model/metamodel/grids/cellgrid.h"
39 #include "model/metamodel/timeprovider.h" 40 #include "model/metamodel/timeprovider.h"
40 #include "model/structures/instance.h" 41 #include "model/structures/instance.h"
41 #include "model/structures/layer.h" 42 #include "model/structures/layer.h"
42 #include "model/structures/location.h" 43 #include "model/structures/location.h"
244 245
245 GenericRendererAnimationInfo::GenericRendererAnimationInfo(GenericRendererNode anchor, int animation): 246 GenericRendererAnimationInfo::GenericRendererAnimationInfo(GenericRendererNode anchor, int animation):
246 GenericRendererElementInfo(), 247 GenericRendererElementInfo(),
247 m_anchor(anchor), 248 m_anchor(anchor),
248 m_animation(animation), 249 m_animation(animation),
249 m_start_time(SDL_GetTicks()), 250 m_start_time(TimeManager::instance()->getTime()),
250 m_time_scale(1.0) { 251 m_time_scale(1.0) {
251 } 252 }
252 void GenericRendererAnimationInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { 253 void GenericRendererAnimationInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) {
253 Point p = m_anchor.getCalculatedPoint(cam, layer, instances); 254 Point p = m_anchor.getCalculatedPoint(cam, layer, instances);
254 Animation& animation = animpool->getAnimation(m_animation); 255 Animation& animation = animpool->getAnimation(m_animation);
255 int animtime = scaleTime(m_time_scale, SDL_GetTicks() - m_start_time) % animation.getDuration(); 256 int animtime = scaleTime(m_time_scale, TimeManager::instance()->getTime() - m_start_time) % animation.getDuration();
256 Image* img = animation.getFrameByTimestamp(animtime); 257 Image* img = animation.getFrameByTimestamp(animtime);
257 Rect r; 258 Rect r;
258 r.x = p.x-img->getWidth()/2; 259 r.x = p.x-img->getWidth()/2;
259 r.y = p.y-img->getHeight()/2; 260 r.y = p.y-img->getHeight()/2;
260 r.w = img->getWidth(); 261 r.w = img->getWidth();