From 7e928fc6559e89b64f49aea30d796dbfe75c4912 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sun, 25 Jan 2009 03:36:13 +0100 Subject: Fixed performance hickups caused by animations due to buggy tick timer. A tad less performant than the intended solution but at least it is constantly so. --- src/engine.cpp | 1 + src/map.cpp | 23 ++++++++++++----------- src/map.h | 6 +++++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/engine.cpp b/src/engine.cpp index 563ec627..7a76e1b0 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -139,5 +139,6 @@ void Engine::logic() { beingManager->logic(); particleEngine->update(); + mCurrentMap->update(); gui->logic(); } diff --git a/src/map.cpp b/src/map.cpp index 2ee6c35e..f0c84159 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -64,7 +64,6 @@ struct Location TileAnimation::TileAnimation(Animation *ani): mAnimation(ani), - mLastUpdate(tick_time), mLastImage(NULL) { } @@ -72,8 +71,7 @@ TileAnimation::TileAnimation(Animation *ani): void TileAnimation::update() { //update animation - mAnimation.update(tick_time - mLastUpdate); - mLastUpdate = tick_time; + mAnimation.update(1); // exchange images Image *img = mAnimation.getCurrentImage(); @@ -230,6 +228,17 @@ bool spriteCompare(const Sprite *a, const Sprite *b) return a->getPixelY() < b->getPixelY(); } +void Map::update() +{ + //update animated tiles + for (std::map::iterator iAni = mTileAnimations.begin(); + iAni != mTileAnimations.end(); + iAni++) + { + iAni->second->update(); + } +} + void Map::draw(Graphics *graphics, int scrollX, int scrollY) { int endPixelY = graphics->getHeight() + scrollY + mTileHeight - 1; @@ -245,14 +254,6 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) // Make sure sprites are sorted mSprites.sort(spriteCompare); - //update animated tiles - for (std::map::iterator iAni = mTileAnimations.begin(); - iAni != mTileAnimations.end(); - iAni++) - { - iAni->second->update(); - } - // draw the game world Layers::const_iterator layeri = mLayers.begin(); for (; layeri != mLayers.end(); ++layeri) { diff --git a/src/map.h b/src/map.h index 88a1008b..1bd93008 100644 --- a/src/map.h +++ b/src/map.h @@ -78,7 +78,6 @@ class TileAnimation private: std::list > mAffected; SimpleAnimation mAnimation; - int mLastUpdate; Image* mLastImage; }; @@ -159,6 +158,11 @@ class Map : public Properties */ void initializeOverlays(); + /** + * Updates animations. Called every game tick. + */ + void update(); + /** * Draws the map to the given graphics output. This method draws all * layers, sprites and overlay effects. -- cgit v1.2.3-60-g2f50