]> Dogcows Code - chaz/yoink/blobdiff - src/tilemap.cc
beginnings of scene rendering
[chaz/yoink] / src / tilemap.cc
index 0852f98e846af7a4be83ed55257157bbd288cef8..4a55c65eef9f7fa7871507b9dad8808a05e362d6 100644 (file)
 
 *******************************************************************************/
 
-#include <cassert>
-
-#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;
 }
 
 
This page took 0.021709 seconds and 4 git commands to generate.