X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Ftilemap.cc;h=4a55c65eef9f7fa7871507b9dad8808a05e362d6;hp=0852f98e846af7a4be83ed55257157bbd288cef8;hb=87bc17e55b0c1dc73ecc66df856d3f08fd7a7724;hpb=838bc00015eb7f583c7cf4b3b1007697bf047da1 diff --git a/src/tilemap.cc b/src/tilemap.cc index 0852f98..4a55c65 100644 --- a/src/tilemap.cc +++ b/src/tilemap.cc @@ -26,13 +26,10 @@ *******************************************************************************/ -#include - -#include "mippleton.hh" -#include "serializable.hh" #include "deserializer.hh" - +#include "mippleton.hh" #include "opengl.hh" +#include "serializable.hh" #include "tilemap.hh" @@ -154,9 +151,10 @@ tilemap::tilemap(const std::string& name) : } -void tilemap::getTileCoords(unsigned index, scalar coords[8]) +bool tilemap::getTileCoords(unsigned index, scalar coords[8]) { - assert(index < impl->tilesU_ * impl->tilesV_); + // make sure the index represents a real tile + if (index >= impl->tilesU_ * impl->tilesV_) return false; scalar w = 1.0 / scalar(impl->tilesU_); scalar h = 1.0 / scalar(impl->tilesV_); @@ -169,26 +167,35 @@ void tilemap::getTileCoords(unsigned index, scalar coords[8]) coords[5] = coords[1] + h; coords[6] = coords[0]; coords[7] = coords[5]; + + return true; } -void tilemap::getTileCoords(unsigned index, scalar coords[8], orientation what) +bool tilemap::getTileCoords(unsigned index, scalar coords[8], orientation what) { - getTileCoords(index, coords); - - if (what & flip) + if (getTileCoords(index, coords)) { - coords[1] = coords[5]; - coords[5] = coords[3]; - coords[3] = coords[7]; - coords[7] = coords[5]; - } - if (what & reverse) - { - coords[0] = coords[2]; - coords[2] = coords[6]; - coords[4] = coords[6]; - coords[6] = coords[0]; + if (what & flip) + { + // this looks kinda weird, but it's just swapping in a way that + // doesn't require an intermediate variable + coords[1] = coords[5]; + coords[5] = coords[3]; + coords[3] = coords[7]; + coords[7] = coords[5]; + } + if (what & reverse) + { + coords[0] = coords[2]; + coords[2] = coords[6]; + coords[4] = coords[6]; + coords[6] = coords[0]; + } + + return true; } + + return false; }