Fixes for windows.
[Tsunagari.git] / src / area.h
blob8767d68837dd32409dd7a226ea084bbb1bebfc59
1 /******************************
2 ** Tsunagari Tile Engine **
3 ** area.h **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
7 #ifndef AREA_H
8 #define AREA_H
10 #include <map>
11 #include <string>
12 #include <vector>
14 #include <boost/scoped_ptr.hpp>
15 #include <boost/shared_ptr.hpp>
17 #include "common.h"
18 #include "config.h"
19 #include "music.h"
20 #include "player.h"
21 #include "resourcer.h"
22 #include "tile.h"
23 #include "viewport.h"
24 #include "xml.h"
26 namespace Gosu {
27 class Bitmap;
28 class Button;
29 class Image;
32 class Area;
33 class Entity;
34 class GameWindow;
35 class Music;
36 class Resourcer;
37 class Sprite;
38 class World;
40 typedef boost::shared_ptr<Area> AreaPtr;
42 //! This class is responsible for each map, or area in a Tsunagari World.
43 /*!
44 The Area class handles the parsing of TMX-format Area descriptor files,
45 the initialization, placement, and drawing of tiles, and various
46 Area-related functionality.
48 class Area
50 public:
51 //! Area Constructor
52 Area(Resourcer* rc, World* world, Viewport* view, Player* player,
53 Music* music, const std::string& filename);
55 //! Area Destructor
56 ~Area();
58 //! Function that must be called after the constructor.
59 bool init();
61 //! Gosu Callback
62 void buttonDown(const Gosu::Button btn);
63 void buttonUp(const Gosu::Button btn);
65 //! Gosu Callback
66 void draw();
68 //! Gosu Callback
69 bool needsRedraw() const;
71 //! Gosu Callback
72 void update(unsigned long dt);
74 icoord getDimensions() const;
75 ivec2 getTileDimensions() const;
76 int depthIndex(double depth) const;
77 double indexDepth(int idx) const;
78 const Tile& getTile(icoord c) const;
79 Tile& getTile(icoord c);
80 bool tileExists(icoord c) const;
81 icube_t visibleTiles() const;
83 bool loopsInX() const;
84 bool loopsInY() const;
86 private:
87 //! Calculate frame to show for each type of tile
88 void updateTileAnimations();
89 bool inBounds(int x, int y, int z) const;
90 void drawTiles() const;
91 void drawTile(const Tile& tile, int x, int y, double depth) const;
92 void drawEntities();
95 //! XML descriptor parsing function.
96 bool processDescriptor();
98 //! Allocate all Tile objects for one layer in 'dim' sized map.
99 void allocateMapLayer();
101 //! XML descriptor parsing function.
102 bool processMapProperties(XMLNode node);
104 //! XML descriptor parsing function.
105 bool processTileSet(XMLNode node);
107 //! XML descriptor parsing function.
108 bool processTileType(XMLNode node, TiledImage& img, int id);
110 //! XML descriptor parsing function.
111 bool processLayer(XMLNode node);
113 //! XML descriptor parsing function.
114 bool processLayerProperties(XMLNode node, double* depth);
116 //! XML descriptor parsing function.
117 bool processLayerData(XMLNode node, int z);
119 //! XML descriptor parsing function.
120 bool processObjectGroup(XMLNode node);
122 //! XML descriptor parsing function.
123 bool processObjectGroupProperties(XMLNode node, double* depth);
125 //! XML descriptor parsing function.
126 bool processObject(XMLNode node, int z);
128 //! Split a tile's flags into individuals.
129 unsigned splitTileFlags(const std::string strOfFlags);
131 //! Process a door convenience trigger.
132 Door parseDoor(const std::string dest);
135 Resourcer* rc;
136 World* world;
137 Viewport* view;
138 Player* player;
139 Music* music;
140 const std::string descriptor;
142 typedef std::vector<Tile> row_t;
143 typedef std::vector<row_t> grid_t;
144 typedef std::vector<grid_t> tilematrix_t;
146 //! 3-dimensional array of the tiles that make up the map.
147 tilematrix_t map;
149 //! 3-dimensional length of map.
150 icoord dim;
152 //! Pixel size for each tile in area. All tiles in an Area must be the
153 //! same size.
154 ivec2 tileDim;
156 //! Properties shared by all tiles of a type.
157 std::vector<TileType> tileTypes;
159 //! Maps virtual float-point depths to an index in our map array.
160 std::map<double, int> depth2idx;
162 //! Maps an index in our map array to a virtual float-point depth.
163 std::vector<double> idx2depth;
166 bool loopX, loopY;
168 std::string name;
169 std::string author;
170 std::string scripts;
171 std::string onLoadEvents;
174 #endif