X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Ftilemap.hh;h=f2f76ab5fc8849f9b89e02b98ed69a48ef0b8acc;hp=50e5c3dd72d7620358713cafe8748c457ac29581;hb=7d15b919681bb9ec0088b4b27c6abf62d6dfb9b1;hpb=0fffd0097d7b496454413e57b398c903ecc252e4 diff --git a/src/tilemap.hh b/src/tilemap.hh index 50e5c3d..f2f76ab 100644 --- a/src/tilemap.hh +++ b/src/tilemap.hh @@ -34,34 +34,15 @@ * Small subclass to give some basic tile-mapping functionality to textures. */ -#include - #include -#include "opengl.hh" #include "texture.hh" +#include "math.hh" namespace dc { -namespace tile { - -/** - * Possible orientations for texture coordinates. - */ - -typedef enum -{ - normal = 0, ///< Normal orientation. - flip = 1, ///< Flip over a horizontal axis. - reverse = 2, ///< Flip over a vertical axis. - flip_and_reverse = 3 ///< Flip over both. -} orientation; - -} // namespace tile - - /** * A tilemap is a texture which is meant to be divided into smaller sprites. * This class provides all the functionality of a texture and adds some methods @@ -72,52 +53,34 @@ typedef enum class tilemap : public texture { public: - tilemap(const std::string& filePath, bool keepInMemory = false, - unsigned tilesU = 1, unsigned tilesV = 1) - : texture(filePath, keepInMemory), tilesU_(tilesU), tilesV_(tilesV) {} - - /** - * Set the number of rows and columns of square tiles. - * @param tilesU Columns of tiles. - * @param tilesV Rows of tiles. + * Possible orientations for texture coordinates. */ - void setTileDimensions(unsigned tilesU, unsigned tilesV) + typedef enum { - assert(tilesU != 0 && tilesV != 0); - tilesU_ = tilesU; - tilesV_ = tilesV; - } + normal = 0, ///< Normal orientation. + flip = 1, ///< Flip over a horizontal axis. + reverse = 2, ///< Flip over a vertical axis. + flip_and_reverse = 3 ///< Flip over both. + } orientation; + + tilemap(const std::string& name); /** * Calculate texture coordinates for a tile at a certain index. Tiles are * indexed start with zero as the to-left tile and moving across, then down. * @param index The tile index. - * @param coords An array of floats where the texture coordinates will be + * @param coords An array of scalars where the texture coordinates will be * stored after this call. The first coordinate (u,v) will be in the first * two places and so on until all four coordinates are stored, therefore - * requiring enough room for an array of eight floats. The winding of the + * requiring enough room for an array of eight scalars. The winding of the * coordinates is always counter-clockwise (the GL default). */ - void getTileCoords(unsigned index, float coords[8]) - { - assert(index < tilesU_ * tilesV_); - - float w = 1.0 / float(tilesU_); - float h = 1.0 / float(tilesV_); + void getTileCoords(unsigned index, scalar coords[8]); - coords[0] = float(index % tilesU_) * w; - coords[1] = (float(tilesV_ - 1) - float(index / tilesU_)) * h; - coords[2] = coords[0] + w; - coords[3] = coords[1]; - coords[4] = coords[2]; - coords[5] = coords[1] + h; - coords[6] = coords[0]; - coords[7] = coords[5]; - } /** * This version let's you specify an orientation that will be reflected in @@ -126,29 +89,14 @@ public: * @param what The orientation; can be flip, reverse, or flip_and_reverse. */ - void getTileCoords(unsigned index, float coords[8], tile::orientation what) - { - getTileCoords(index, coords); - - if (what & tile::flip) - { - coords[1] = coords[5]; - coords[5] = coords[3]; - coords[3] = coords[7]; - coords[7] = coords[5]; - } - if (what & tile::reverse) - { - coords[0] = coords[2]; - coords[2] = coords[6]; - coords[4] = coords[6]; - coords[6] = coords[0]; - } - } + void getTileCoords(unsigned index, scalar coords[8], orientation what); + + + static std::string getPathToResource(const std::string& name); private: - unsigned tilesU_; - unsigned tilesV_; + class tilemap_impl; + boost::shared_ptr impl; }; @@ -156,3 +104,5 @@ private: #endif // _TILEMAP_HH_ +/** vim: set ts=4 sw=4 tw=80: *************************************************/ +