summaryrefslogtreecommitdiff
path: root/src/resources/ambientlayer.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-04-15 01:32:12 +0300
committerAndrei Karas <akaras@inbox.ru>2013-04-15 01:32:12 +0300
commit23e39ef3eccab6b1297a00d3f8f199b54a7e9af9 (patch)
tree22ed6b2345703cb076f6ff2f627f6b98b46c5e6c /src/resources/ambientlayer.cpp
parent796f7e2c2ace55462acfa50e5085d4d048047e68 (diff)
downloadmv-23e39ef3eccab6b1297a00d3f8f199b54a7e9af9.tar.gz
mv-23e39ef3eccab6b1297a00d3f8f199b54a7e9af9.tar.bz2
mv-23e39ef3eccab6b1297a00d3f8f199b54a7e9af9.tar.xz
mv-23e39ef3eccab6b1297a00d3f8f199b54a7e9af9.zip
improve ambientlayer class.
Diffstat (limited to 'src/resources/ambientlayer.cpp')
-rw-r--r--src/resources/ambientlayer.cpp58
1 files changed, 29 insertions, 29 deletions
diff --git a/src/resources/ambientlayer.cpp b/src/resources/ambientlayer.cpp
index b32a93bf0..ba10cbdcc 100644
--- a/src/resources/ambientlayer.cpp
+++ b/src/resources/ambientlayer.cpp
@@ -40,29 +40,28 @@ AmbientLayer::AmbientLayer(Image *const img, const float parallax,
if (!mImage)
return;
- if (keepRatio && !imageHelper->useOpenGL()
- /*&& defaultScreenWidth != 0
- && defaultScreenHeight != 0*/
- && mainGraphics->mWidth != defaultScreenWidth
- && mainGraphics->mHeight != defaultScreenHeight)
+ if (keepRatio && !imageHelper->useOpenGL())
{
- // Rescale the overlay to keep the ratio as if we were on
- // the default resolution...
- Image *const rescaledOverlay = ResourceManager::getInstance()->
- getRescaled(mImage, static_cast<int>(mImage->mBounds.w)
- / defaultScreenWidth * mainGraphics->mWidth,
- static_cast<int>(mImage->mBounds.h)
- / defaultScreenHeight * mainGraphics->mHeight);
-
- if (rescaledOverlay)
- mImage = rescaledOverlay;
- else
- mImage->incRef();
- }
- else
- {
- mImage->incRef();
+ const int width = mainGraphics->mWidth;
+ const int height = mainGraphics->mHeight;
+ if (width != defaultScreenWidth && height != defaultScreenHeight)
+ {
+ // Rescale the overlay to keep the ratio as if we were on
+ // the default resolution...
+ Image *const rescaledOverlay = ResourceManager::getInstance()->
+ getRescaled(mImage, static_cast<int>(mImage->mBounds.w)
+ / defaultScreenWidth * width,
+ static_cast<int>(mImage->mBounds.h)
+ / defaultScreenHeight * height);
+
+ if (rescaledOverlay)
+ mImage = rescaledOverlay;
+ else
+ mImage->incRef();
+ return;
+ }
}
+ mImage->incRef();
}
AmbientLayer::~AmbientLayer()
@@ -79,27 +78,28 @@ void AmbientLayer::update(const int timePassed, const float dx, const float dy)
if (!mImage)
return;
+ const float time = static_cast<float>(timePassed) / 10;
// Self scrolling of the overlay
- mPosX -= mSpeedX * static_cast<float>(timePassed) / 10;
- mPosY -= mSpeedY * static_cast<float>(timePassed) / 10;
+ mPosX -= mSpeedX * time;
+ mPosY -= mSpeedY * time;
// Parallax scrolling
mPosX += dx * mParallax;
mPosY += dy * mParallax;
- const int imgW = mImage->mBounds.w;
- const int imgH = mImage->mBounds.h;
+ const float imgW = mImage->mBounds.w;
+ const float imgH = mImage->mBounds.h;
// Wrap values
while (mPosX > imgW)
- mPosX -= static_cast<float>(imgW);
+ mPosX -= imgW;
while (mPosX < 0)
- mPosX += static_cast<float>(imgW);
+ mPosX += imgW;
while (mPosY > imgH)
- mPosY -= static_cast<float>(imgH);
+ mPosY -= imgH;
while (mPosY < 0)
- mPosY += static_cast<float>(imgH);
+ mPosY += imgH;
}
void AmbientLayer::draw(Graphics *const graphics, const int x,