summaryrefslogtreecommitdiff
path: root/src/map.h
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-04-08 18:43:44 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-04-08 18:43:44 +0000
commit720f716ba8d98a85266b8e81a534737c6fcdcf5f (patch)
tree192c702c463db0661f42fa34addf8f957e19e169 /src/map.h
parentf25d5640eba5b1a0bbbc050a858aa4cdbdffdc7f (diff)
downloadmana-client-720f716ba8d98a85266b8e81a534737c6fcdcf5f.tar.gz
mana-client-720f716ba8d98a85266b8e81a534737c6fcdcf5f.tar.bz2
mana-client-720f716ba8d98a85266b8e81a534737c6fcdcf5f.tar.xz
mana-client-720f716ba8d98a85266b8e81a534737c6fcdcf5f.zip
Implemented support for an arbitrary number of map layers. The only layer
requirement for map layers are now that the fringe layer is called "Fringe" and that the collision layer is called "Collision".
Diffstat (limited to 'src/map.h')
-rw-r--r--src/map.h110
1 files changed, 73 insertions, 37 deletions
diff --git a/src/map.h b/src/map.h
index 126cb70b..31c6be00 100644
--- a/src/map.h
+++ b/src/map.h
@@ -32,6 +32,7 @@
class AmbientOverlay;
class Graphics;
class Image;
+class MapLayer;
class Particle;
class Sprite;
class Tileset;
@@ -41,8 +42,7 @@ struct PATH_NODE;
typedef std::vector<Tileset*> Tilesets;
typedef std::list<Sprite*> Sprites;
typedef Sprites::iterator SpriteIterator;
-
-extern volatile int tick_time;
+typedef std::vector<MapLayer*> Layers;
/**
* A meta tile stores additional information about a location on a tile map.
@@ -67,6 +67,56 @@ struct MetaTile
};
/**
+ * A map layer. Stores a grid of tiles and their offset, and implements layer
+ * rendering.
+ */
+class MapLayer
+{
+ public:
+ /**
+ * Constructor, taking layer origin, size and whether this layer is the
+ * fringe layer. The fringe layer is the layer that draws the sprites.
+ * There can be only one fringe layer per map.
+ */
+ MapLayer(int x, int y, int width, int height, bool isFringeLayer);
+
+ /**
+ * Destructor.
+ */
+ ~MapLayer();
+
+ /**
+ * Set tile image, with x and y in layer coordinates.
+ */
+ void setTile(int x, int y, Image *img);
+
+ /**
+ * Get tile image, with x and y in layer coordinates.
+ */
+ Image *getTile(int x, int y) const;
+
+ /**
+ * Draws this layer to the given graphics context. The coordinates are
+ * expected to be in map range and will be translated to local layer
+ * coordinates and clipped to the layer's dimensions.
+ *
+ * The given sprites are only drawn when this layer is the fringe
+ * layer.
+ */
+ void draw(Graphics *graphics,
+ int startX, int startY,
+ int endX, int endY,
+ int scrollX, int scrollY,
+ const Sprites &sprites) const;
+
+ private:
+ int mX, mY;
+ int mWidth, mHeight;
+ bool mIsFringeLayer; /**< Whether the sprites are drawn. */
+ Image **mTiles;
+};
+
+/**
* A tile map.
*/
class Map : public Properties
@@ -98,9 +148,14 @@ class Map : public Properties
void initializeOverlays();
/**
- * Draws a map layer to the given graphics output.
+ * Draws the map to the given graphics output. This method draws all
+ * layers, sprites and overlay effects.
+ *
+ * TODO: For efficiency reasons, this method could take into account
+ * the clipping rectangle set on the Graphics object. However,
+ * currently the map is always drawn full-screen.
*/
- void draw(Graphics *graphics, int scrollX, int scrollY, int layer);
+ void draw(Graphics *graphics, int scrollX, int scrollY);
/**
* Visualizes collision layer for debugging
@@ -108,34 +163,20 @@ class Map : public Properties
void drawCollision(Graphics *graphics, int scrollX, int scrollY);
/**
- * Draws the overlay graphic to the given graphics output.
- */
- void
- drawOverlay(Graphics *graphics, float scrollX, float scrollY,
- int detail);
-
- /**
- * Adds a tileset to this map.
- */
- void
- addTileset(Tileset *tileset);
-
- /**
- * Sets a tile using a global tile id. Used by the layer loading
- * routine.
+ * Adds a layer to this map. The map takes ownership of the layer.
*/
- void
- setTileWithGid(int x, int y, int layer, int gid);
+ void addLayer(MapLayer *layer);
/**
- * Set tile ID.
+ * Adds a tileset to this map. The map takes ownership of the tileset.
*/
- void setTile(int x, int y, int layer, Image *img);
+ void addTileset(Tileset *tileset);
/**
- * Get tile ID.
+ * Finds the tile set that a tile with the given global id is part of.
*/
- Image *getTile(int x, int y, int layer) const;
+ Tileset*
+ getTilesetWithGid(int gid) const;
/**
* Get tile reference.
@@ -203,7 +244,7 @@ class Map : public Properties
/**
* Adds a particle effect
*/
- void addParticleEffect (std::string effectFile, int x, int y);
+ void addParticleEffect(const std::string &effectFile, int x, int y);
/**
* Initializes all added particle effects
@@ -213,15 +254,11 @@ class Map : public Properties
private:
/**
- * Converts a global tile id to the Image* pointing to the associated
- * tile image.
- */
- Image* getTileWithGid(int gid) const;
-
- /**
- * Finds the tile set that a tile with the given global id is part of.
+ * Draws the overlay graphic to the given graphics output.
*/
- Tileset* getTilesetWithGid(int gid) const;
+ void
+ drawOverlay(Graphics *graphics, float scrollX, float scrollY,
+ int detail);
/**
* Tells whether the given coordinates fall within the map boundaries.
@@ -243,15 +280,14 @@ class Map : public Properties
int mTileWidth, mTileHeight;
int mMaxTileHeight;
MetaTile *mMetaTiles;
- Image **mTiles;
-
+ Layers mLayers;
Tilesets mTilesets;
Sprites mSprites;
// Pathfinding members
int mOnClosedList, mOnOpenList;
- // Overlay Data
+ // Overlay data
std::list<AmbientOverlay*> mOverlays;
float mLastScrollX;
float mLastScrollY;