summaryrefslogtreecommitdiff
path: root/src/map.h
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-07-01 17:41:30 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-07-01 17:41:30 +0000
commit4ca8675700dfae625376c4afdd30b8590d68087e (patch)
tree7f661baf3d566fcf5d0318da13e29c13098cf21a /src/map.h
parentcf5cfbcb8ff63005b1e08f9718ce3f80f919271e (diff)
downloadmana-4ca8675700dfae625376c4afdd30b8590d68087e.tar.gz
mana-4ca8675700dfae625376c4afdd30b8590d68087e.tar.bz2
mana-4ca8675700dfae625376c4afdd30b8590d68087e.tar.xz
mana-4ca8675700dfae625376c4afdd30b8590d68087e.zip
Merged revisions 4044-4067 via svnmerge from
https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/trunk ........ r4044 | b_lindeijer | 2008-04-07 11:02:38 +0200 (Mon, 07 Apr 2008) | 2 lines Added support for basing one sprite definition on another by including it. ........ r4057 | b_lindeijer | 2008-04-08 20:43:44 +0200 (Tue, 08 Apr 2008) | 4 lines 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". ........ r4067 | b_lindeijer | 2008-04-11 00:03:57 +0200 (Fri, 11 Apr 2008) | 3 lines Fixed some compiler warnings and don't try to load particle effects when no file is set. ........
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 fab7bfb7..95532eb3 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
@@ -89,39 +139,30 @@ class Map : public Properties
void initializeOverlays();
/**
- * Draws a map layer to the given graphics output.
- */
- void draw(Graphics *graphics, int scrollX, int scrollY, int layer);
-
- /**
- * 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.
+ * 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
- addTileset(Tileset *tileset);
+ void draw(Graphics *graphics, int scrollX, int scrollY);
/**
- * 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);
+ Tileset*
+ getTilesetWithGid(int gid) const;
/**
* Get tile reference.
@@ -183,7 +224,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
@@ -193,15 +234,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 a tile is occupied by a being.
@@ -217,15 +254,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;