From 0b8f87cd8cf8020c97e10a979b6aba8d7cafa704 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 3 Mar 2016 23:28:59 +0300 Subject: Improve a bit calculations in viewport. --- src/gui/viewport.cpp | 28 ++++++++++++++++++---------- src/gui/viewport.h | 4 ++++ 2 files changed, 22 insertions(+), 10 deletions(-) (limited to 'src/gui') 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(); } diff --git a/src/gui/viewport.h b/src/gui/viewport.h index fa02f244b..d189b2415 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -184,6 +184,8 @@ class Viewport final : public WindowContainer, void updateMidVars(); + void updateMaxVars(); + static void validateSpeed(); private: @@ -233,6 +235,8 @@ class Viewport final : public WindowContainer, int mPixelViewY; /**< Current viewpoint in pixels. */ int mMidTileX; int mMidTileY; + int mViewXmax; + int mViewYmax; int mLocalWalkTime; /**< Timestamp before the next walk can be sent. */ -- cgit v1.2.3-70-g09d2