From e296cef9becef7e890cd1ce33d1b0ae23007a784 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Fri, 25 Sep 2009 09:48:43 +0000 Subject: [PATCH] Created a macro for lround(), for non-C99 compilers, and used that in places where lround() is used svn-id: r44337 --- engines/draci/draci.h | 3 +++ engines/draci/game.cpp | 4 ++-- engines/draci/sprite.cpp | 8 ++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/engines/draci/draci.h b/engines/draci/draci.h index e2b5390c44a..168d48733f6 100644 --- a/engines/draci/draci.h +++ b/engines/draci/draci.h @@ -88,6 +88,9 @@ enum { kDraciAnimationDebugLevel = 1 << 4 }; +// Macro to simulate lround() for non-C99 compilers +static inline long scummvm_lround(double val) { return (long)floor(val + 0.5); } + } // End of namespace Draci #endif // DRACI_H diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index 6ebfb2729c4..5348b7c7fcb 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -1045,8 +1045,8 @@ void Game::walkHero(int x, int y) { uint height = frame->getHeight(); uint width = frame->getWidth(); - _persons[kDragonObject]._x = x + (floor(scaleX) * width) / 2; - _persons[kDragonObject]._y = y - floor(scaleY) * height; + _persons[kDragonObject]._x = x + (scummvm_lround(scaleX) * width) / 2; + _persons[kDragonObject]._y = y - scummvm_lround(scaleY) * height; // Set the per-animation scaling factor anim->setScaleFactors(scaleX, scaleY); diff --git a/engines/draci/sprite.cpp b/engines/draci/sprite.cpp index 69465307a4f..d256d9ffae2 100644 --- a/engines/draci/sprite.cpp +++ b/engines/draci/sprite.cpp @@ -140,8 +140,8 @@ int Sprite::getPixel(int x, int y) const { double scaleX = double(_scaledWidth) / _width; double scaleY = double(_scaledHeight) / _height; - int sy = floor(dy * scaleY); - int sx = floor(dx * scaleX); + int sy = scummvm_lround(dy * scaleY); + int sx = scummvm_lround(dx * scaleX); if (_mirror) return _data[sy * _width + (_width - sx)]; @@ -190,11 +190,11 @@ void Sprite::drawScaled(Surface *surface, bool markDirty) const { // Precalculate pixel indexes for (int i = 0; i < rows; ++i) { - rowIndices[i] = floor(i / scaleY); + rowIndices[i] = scummvm_lround(i / scaleY); } for (int j = 0; j < columns; ++j) { - columnIndices[j] = floor(j / scaleX); + columnIndices[j] = scummvm_lround(j / scaleX); } // Blit the sprite to the surface