summaryrefslogtreecommitdiff
path: root/src/engine.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2006-08-24 00:58:21 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2006-08-24 00:58:21 +0000
commit9581f6556ac1646b4d30c676403aba544e4edaec (patch)
tree31e0ddc101f677f9fa19436f7a74d63325a43f9c /src/engine.cpp
parentb842eb4e7a21b8cb8b60cff840a82abdb5791f92 (diff)
downloadMana-9581f6556ac1646b4d30c676403aba544e4edaec.tar.gz
Mana-9581f6556ac1646b4d30c676403aba544e4edaec.tar.bz2
Mana-9581f6556ac1646b4d30c676403aba544e4edaec.tar.xz
Mana-9581f6556ac1646b4d30c676403aba544e4edaec.zip
scrolling and overlays are no longer linked to the framerate
Diffstat (limited to 'src/engine.cpp')
-rw-r--r--src/engine.cpp43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 9a93b03e..a80351d4 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -161,6 +161,14 @@ void Engine::logic()
void Engine::draw(Graphics *graphics)
{
+ static int lastTick = tick_time;
+
+ // Avoid freaking out when tick_time overflows
+ if (tick_time < lastTick)
+ {
+ lastTick = tick_time;
+ }
+
// calculate viewpoint
int midTileX = graphics->getWidth() / 32 / 2;
int midTileY = graphics->getHeight() / 32 / 2;
@@ -174,22 +182,27 @@ void Engine::draw(Graphics *graphics)
if (scrollLaziness < 1)
scrollLaziness = 1; //avoids division by zero
- if (player_x > view_x + scrollRadius)
- {
- view_x += (player_x - view_x - scrollRadius) / scrollLaziness;
- };
- if (player_x < view_x - scrollRadius)
- {
- view_x += (player_x - view_x + scrollRadius) / scrollLaziness;
- };
- if (player_y > view_y + scrollRadius)
- {
- view_y += (player_y - view_y - scrollRadius) / scrollLaziness;
- };
- if (player_y < view_y - scrollRadius)
+ //apply lazy scrolling
+ while (lastTick < tick_time)
{
- view_y += (player_y - view_y + scrollRadius) / scrollLaziness;
- };
+ if (player_x > view_x + scrollRadius)
+ {
+ view_x += (player_x - view_x - scrollRadius) / scrollLaziness;
+ }
+ if (player_x < view_x - scrollRadius)
+ {
+ view_x += (player_x - view_x + scrollRadius) / scrollLaziness;
+ }
+ if (player_y > view_y + scrollRadius)
+ {
+ view_y += (player_y - view_y - scrollRadius) / scrollLaziness;
+ }
+ if (player_y < view_y - scrollRadius)
+ {
+ view_y += (player_y - view_y + scrollRadius) / scrollLaziness;
+ }
+ lastTick++;
+ }
//auto center when player is off screen
if ( player_x - view_x > graphics->getWidth() / 2