diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-03-03 23:28:59 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-03-03 23:28:59 +0300 |
commit | 0b8f87cd8cf8020c97e10a979b6aba8d7cafa704 (patch) | |
tree | 2d6271ea9198c606b1e33957ad5d5f22b239693b /src/gui | |
parent | f0f135493b2951af8661c8d7e7396c713164a723 (diff) | |
download | plus-0b8f87cd8cf8020c97e10a979b6aba8d7cafa704.tar.gz plus-0b8f87cd8cf8020c97e10a979b6aba8d7cafa704.tar.bz2 plus-0b8f87cd8cf8020c97e10a979b6aba8d7cafa704.tar.xz plus-0b8f87cd8cf8020c97e10a979b6aba8d7cafa704.zip |
Improve a bit calculations in viewport.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/viewport.cpp | 28 | ||||
-rw-r--r-- | src/gui/viewport.h | 4 |
2 files changed, 22 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(); } 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. */ |