summaryrefslogtreecommitdiff
path: root/src/gui/viewport.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-03-03 23:28:59 +0300
committerAndrei Karas <akaras@inbox.ru>2016-03-03 23:28:59 +0300
commit0b8f87cd8cf8020c97e10a979b6aba8d7cafa704 (patch)
tree2d6271ea9198c606b1e33957ad5d5f22b239693b /src/gui/viewport.cpp
parentf0f135493b2951af8661c8d7e7396c713164a723 (diff)
downloadmv-0b8f87cd8cf8020c97e10a979b6aba8d7cafa704.tar.gz
mv-0b8f87cd8cf8020c97e10a979b6aba8d7cafa704.tar.bz2
mv-0b8f87cd8cf8020c97e10a979b6aba8d7cafa704.tar.xz
mv-0b8f87cd8cf8020c97e10a979b6aba8d7cafa704.zip
Improve a bit calculations in viewport.
Diffstat (limited to 'src/gui/viewport.cpp')
-rw-r--r--src/gui/viewport.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 8855c651f..157815811 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -79,6 +79,8 @@ Viewport::Viewport() :
mPixelViewY(0),
mMidTileX(0),
mMidTileY(0),
+ mViewXmax(0),
+ mViewYmax(0),
mLocalWalkTime(-1),
mCameraRelativeX(0),
mCameraRelativeY(0),
@@ -116,6 +118,7 @@ void Viewport::setMap(Map *const map)
if (mMap && map)
map->setDrawLayersFlags(mMap->getDrawLayersFlags());
mMap = map;
+ updateMaxVars();
}
void Viewport::draw(Graphics *const graphics)
@@ -208,20 +211,14 @@ void Viewport::draw(Graphics *const graphics)
mPixelViewY = player_y;
}
- // Don't move camera so that the end of the map is on screen
- const int viewXmax =
- mMap->getWidth() * mMap->getTileWidth() - graphics->mWidth;
- const int viewYmax =
- mMap->getHeight() * mMap->getTileHeight() - graphics->mHeight;
-
if (mPixelViewX < 0)
mPixelViewX = 0;
if (mPixelViewY < 0)
mPixelViewY = 0;
- if (mPixelViewX > viewXmax)
- mPixelViewX = viewXmax;
- if (mPixelViewY > viewYmax)
- mPixelViewY = viewYmax;
+ if (mPixelViewX > mViewXmax)
+ mPixelViewX = mViewXmax;
+ if (mPixelViewY > mViewYmax)
+ mPixelViewY = mViewYmax;
// Draw tiles and sprites
mMap->draw(graphics, mPixelViewX, mPixelViewY);
@@ -1041,7 +1038,18 @@ void Viewport::updateMidVars()
- mCameraRelativeY;
}
+void Viewport::updateMaxVars()
+{
+ if (!mMap)
+ return;
+ mViewXmax = mMap->getWidth() * mMap->getTileWidth()
+ - mainGraphics->mWidth;
+ mViewYmax = mMap->getHeight() * mMap->getTileHeight()
+ - mainGraphics->mHeight;
+}
+
void Viewport::videoResized()
{
updateMidVars();
+ updateMaxVars();
}