summaryrefslogtreecommitdiff
path: root/src/map.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/map.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/map.cpp')
-rw-r--r--src/map.cpp87
1 files changed, 53 insertions, 34 deletions
diff --git a/src/map.cpp b/src/map.cpp
index 6eec4865..463a8c8e 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -171,54 +171,73 @@ Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY)
{
std::list<AmbientOverlay>::iterator i;
+ static int lastTick = tick_time;
+
+ // Avoid freaking out when tick_time overflows
+ if (tick_time < lastTick)
+ {
+ lastTick = tick_time;
+ }
+
if (mLastScrollX == 0.0f && mLastScrollY == 0.0f)
{
+ // first call - initialisation
mLastScrollX = scrollX;
mLastScrollY = scrollY;
}
- for (i = mOverlays.begin(); i != mOverlays.end(); i++)
+ //update Overlays
+ while (lastTick < tick_time)
{
-
- if ((*i).image != NULL)
+ for (i = mOverlays.begin(); i != mOverlays.end(); i++)
{
- //apply self scrolling
- (*i).scrollX -= (*i).scrollSpeedX;
- (*i).scrollY -= (*i).scrollSpeedY;
+ if ((*i).image != NULL)
+ {
+ //apply self scrolling
+ (*i).scrollX -= (*i).scrollSpeedX;
+ (*i).scrollY -= (*i).scrollSpeedY;
- //apply parallaxing
- (*i).scrollX += (scrollX - mLastScrollX) * (*i).parallax;
- (*i).scrollY += (scrollY - mLastScrollY) * (*i).parallax;
+ //apply parallaxing
+ (*i).scrollX += (scrollX - mLastScrollX) * (*i).parallax;
+ (*i).scrollY += (scrollY - mLastScrollY) * (*i).parallax;
- //keep the image pattern on the screen
- while ((*i).scrollX > (*i).image->getWidth())
- {
- (*i).scrollX -= (*i).image->getWidth();
- }
- while ((*i).scrollY > (*i).image->getHeight())
- {
- (*i).scrollY -= (*i).image->getHeight();
- }
- while ((*i).scrollX < 0)
- {
- (*i).scrollX += (*i).image->getWidth();
- }
- while ((*i).scrollY < 0)
- {
- (*i).scrollY += (*i).image->getHeight();
+ //keep the image pattern on the screen
+ while ((*i).scrollX > (*i).image->getWidth())
+ {
+ (*i).scrollX -= (*i).image->getWidth();
+ }
+ while ((*i).scrollY > (*i).image->getHeight())
+ {
+ (*i).scrollY -= (*i).image->getHeight();
+ }
+ while ((*i).scrollX < 0)
+ {
+ (*i).scrollX += (*i).image->getWidth();
+ }
+ while ((*i).scrollY < 0)
+ {
+ (*i).scrollY += (*i).image->getHeight();
+ }
}
-
- graphics->drawImagePattern ( (*i).image,
- 0 - (int)(*i).scrollX,
- 0 - (int)(*i).scrollY,
- graphics->getWidth() + (int)(*i).scrollX,
- graphics->getHeight() + (int)(*i).scrollY
- );
}
+ mLastScrollX = scrollX;
+ mLastScrollY = scrollY;
+ lastTick++;
}
- mLastScrollX = scrollX;
- mLastScrollY = scrollY;
+ //draw overlays
+ for (i = mOverlays.begin(); i != mOverlays.end(); i++)
+ {
+ if ((*i).image != NULL)
+ {
+ graphics->drawImagePattern ( (*i).image,
+ 0 - (int)(*i).scrollX,
+ 0 - (int)(*i).scrollY,
+ graphics->getWidth() + (int)(*i).scrollX,
+ graphics->getHeight() + (int)(*i).scrollY
+ );
+ };
+ };
}
void