summaryrefslogtreecommitdiff
path: root/src/map.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-02 21:26:57 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-02 21:26:57 +0000
commit19e15c87a1fc74f71fd6f9a743201a24ac582997 (patch)
treea615525476ef6bad8a2af4d8b90c8aea935f9109 /src/map.cpp
parent29f07d2f98b82674708f1185f26ed3c482992b04 (diff)
downloadmana-19e15c87a1fc74f71fd6f9a743201a24ac582997.tar.gz
mana-19e15c87a1fc74f71fd6f9a743201a24ac582997.tar.bz2
mana-19e15c87a1fc74f71fd6f9a743201a24ac582997.tar.xz
mana-19e15c87a1fc74f71fd6f9a743201a24ac582997.zip
Merged trunk changes from revision 2716 to 2756 into the 0.1.0 branch.
Diffstat (limited to 'src/map.cpp')
-rw-r--r--src/map.cpp137
1 files changed, 44 insertions, 93 deletions
diff --git a/src/map.cpp b/src/map.cpp
index 3ccaafc0..1cdc1077 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -27,13 +27,17 @@
#include <queue>
#include "beingmanager.h"
+#include "game.h"
#include "graphics.h"
#include "sprite.h"
#include "tileset.h"
+#include "resources/resourcemanager.h"
+#include "resources/ambientoverlay.h"
#include "resources/image.h"
#include "utils/dtor.h"
+#include "utils/tostring.h"
/**
* A location on a tile map. Used for pathfinding, open list.
@@ -79,27 +83,34 @@ Map::~Map()
for_each(mTilesets.begin(), mTilesets.end(), make_dtor(mTilesets));
mTilesets.clear();
// clean up overlays
- std::list<AmbientOverlay>::iterator i;
- for (i = mOverlays.begin(); i != mOverlays.end(); i++)
- {
- (*i).image->decRef();
- }
+ for_each(mOverlays.begin(), mOverlays.end(), make_dtor(mOverlays));
}
void
-Map::setSize(int width, int height)
+Map::initializeOverlays()
{
- delete[] mMetaTiles;
- delete[] mTiles;
+ ResourceManager *resman = ResourceManager::getInstance();
+
+ for (int i = 0;
+ hasProperty("overlay" + toString(i) + "image");
+ i++)
+ {
+ const std::string name = "overlay" + toString(i);
- mWidth = width;
- mHeight = height;
+ Image *img = resman->getImage(getProperty(name + "image"));
+ float speedX = getFloatProperty(name + "scrollX");
+ float speedY = getFloatProperty(name + "scrollY");
+ float parallax = getFloatProperty(name + "parallax");
- int size = width * height;
+ if (img)
+ {
+ mOverlays.push_back(
+ new AmbientOverlay(img, parallax, speedX, speedY));
- mMetaTiles = new MetaTile[size];
- mTiles = new Image*[size * 3];
- std::fill_n(mTiles, size * 3, (Image*)0);
+ // The AmbientOverlay takes control over the image.
+ img->decRef();
+ }
+ }
}
void
@@ -179,99 +190,39 @@ Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY, int detail)
{
static int lastTick = tick_time;
- // detail 0: no overlays
+ // Detail 0: no overlays
if (detail <= 0) return;
- std::list<AmbientOverlay>::iterator i;
-
- // Avoid freaking out when tick_time overflows
- if (tick_time < lastTick)
- {
- lastTick = tick_time;
- }
-
if (mLastScrollX == 0.0f && mLastScrollY == 0.0f)
{
- // first call - initialisation
+ // First call - initialisation
mLastScrollX = scrollX;
mLastScrollY = scrollY;
}
- //update Overlays
- while (lastTick < tick_time)
- {
- for (i = mOverlays.begin(); i != mOverlays.end(); i++)
- {
- 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;
-
- //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();
- }
- }
- }
- mLastScrollX = scrollX;
- mLastScrollY = scrollY;
- lastTick++;
-
- // detail 1: only one overlay, higher: all overlays
- if (detail == 1) break;
- }
+ // Update Overlays
+ int timePassed = get_elapsed_time(lastTick);
+ float dx = scrollX - mLastScrollX;
+ float dy = scrollY - mLastScrollY;
- //draw overlays
+ std::list<AmbientOverlay*>::iterator i;
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
- );
- };
- // detail 1: only one overlay, higher: all overlays
- if (detail == 1) break;
- };
-}
+ (*i)->update(timePassed, dx, dy);
+ }
+ mLastScrollX = scrollX;
+ mLastScrollY = scrollY;
+ lastTick = tick_time;
-void
-Map::setOverlay(Image *image, float speedX, float speedY, float parallax)
-{
- if (image != NULL)
+ // Draw overlays
+ for (i = mOverlays.begin(); i != mOverlays.end(); i++)
{
- AmbientOverlay newOverlay;
-
- newOverlay.image = image;
- newOverlay.parallax = parallax;
- newOverlay.scrollSpeedX = speedX;
- newOverlay.scrollSpeedY = speedY;
- newOverlay.scrollX = 0;
- newOverlay.scrollY = 0;
+ (*i)->draw(graphics, graphics->getWidth(), graphics->getHeight());
- mOverlays.push_back(newOverlay);
- }
+ // Detail 1: only one overlay, higher: all overlays
+ if (detail == 1)
+ break;
+ };
}
void