diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2006-08-24 00:58:21 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2006-08-24 00:58:21 +0000 |
commit | 9581f6556ac1646b4d30c676403aba544e4edaec (patch) | |
tree | 31e0ddc101f677f9fa19436f7a74d63325a43f9c /src/engine.cpp | |
parent | b842eb4e7a21b8cb8b60cff840a82abdb5791f92 (diff) | |
download | mana-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.cpp | 43 |
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 |