*******************************************************************************/
-#include <cassert>
-
-#include "mippleton.hh"
-#include "serializable.hh"
#include "deserializer.hh"
-
+#include "mippleton.hh"
#include "opengl.hh"
+#include "serializable.hh"
#include "tilemap.hh"
}
-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_);
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;
}