diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-10-04 11:32:15 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-10-08 21:03:44 +0200 |
commit | 573df67919ec5f65a6b2ad51ed8aed31c9cfe4a6 (patch) | |
tree | e50500d452fdb3a503d3257477facc38017f7e10 /src/gui | |
parent | 7de0b165f196cb0c1f983b6d2ab26ef9791a2d36 (diff) | |
download | mana-573df67919ec5f65a6b2ad51ed8aed31c9cfe4a6.tar.gz mana-573df67919ec5f65a6b2ad51ed8aed31c9cfe4a6.tar.bz2 mana-573df67919ec5f65a6b2ad51ed8aed31c9cfe4a6.tar.xz mana-573df67919ec5f65a6b2ad51ed8aed31c9cfe4a6.zip |
Smoother being movement
There was a slight stutter in being movement, since each time a being
reached the next position along its path, it would only continue to the
following position with the next logic tick.
Now the logic has been adjusted to keep moving until all the time for
the current frame was used up, or the path was exhausted.
A slight stutter remains for keyboard movement, as well as broken walk
animation playback, since it will only set a new path once the current
one is finished (see e554d9b2be1ec2fcb15065ae70151302adeef602).
Also simplified some logic in Viewport::draw and removed some obsolete
code in LocalPlayer::startWalking.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/viewport.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 8dbdf7c7..6c8016dc 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -41,6 +41,7 @@ #include "utils/stringutils.h" +#include <algorithm> #include <cmath> Viewport::Viewport() @@ -166,24 +167,21 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) }; // Don't move camera so that the end of the map is on screen + // Center camera on map if the map is smaller than the screen const int mapWidthPixels = mMap->getWidth() * mMap->getTileWidth(); const int mapHeightPixels = mMap->getHeight() * mMap->getTileHeight(); const int viewXmax = mapWidthPixels - graphics->getWidth(); const int viewYmax = mapHeightPixels - graphics->getHeight(); - if (mPixelViewX < 0) - mPixelViewX = 0; - if (mPixelViewY < 0) - mPixelViewY = 0; - if (mPixelViewX > viewXmax) - mPixelViewX = viewXmax; - if (mPixelViewY > viewYmax) - mPixelViewY = viewYmax; - // Center camera on map if the map is smaller than the screen - if (mapWidthPixels < graphics->getWidth()) - mPixelViewX = (mapWidthPixels - graphics->getWidth()) / 2; - if (mapHeightPixels < graphics->getHeight()) - mPixelViewY = (mapHeightPixels - graphics->getHeight()) / 2; + if (viewXmax > 0) + mPixelViewX = std::clamp<float>(mPixelViewX, 0, viewXmax); + else + mPixelViewX = viewXmax / 2; + + if (viewYmax > 0) + mPixelViewY = std::clamp<float>(mPixelViewY, 0, viewYmax); + else + mPixelViewY = viewYmax / 2; // Draw black background if map is smaller than the screen if ( mapWidthPixels < graphics->getWidth() |