]> git.localhorst.tv Git - blank.git/blobdiff - src/world/Block.hpp
try to cleanly destruct world
[blank.git] / src / world / Block.hpp
index 74af3e4ab4bbf025e342674e6bc7eff986bf2d7a..ea3de59b206e3ad7b90b9033db7506037bd24692 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef BLANK_WORLD_BLOCK_HPP_
 #define BLANK_WORLD_BLOCK_HPP_
 
+#include <iosfwd>
 #include <glm/glm.hpp>
 
 
@@ -10,7 +11,6 @@ namespace blank {
 struct Block {
 
        using Type = unsigned short;
-       using Pos = glm::vec3;
 
        enum Face {
                FACE_UP,
@@ -65,7 +65,23 @@ struct Block {
                }
        }
 
-       static glm::tvec3<int> FaceNormal(Face face) noexcept {
+       /// returns 1 for pro-axis, -1 for retro-axis, 0 for invalid faces
+       static int Direction(Face f) noexcept {
+               switch (f) {
+                       case FACE_RIGHT:
+                       case FACE_UP:
+                       case FACE_FRONT:
+                               return 1;
+                       case FACE_LEFT:
+                       case FACE_DOWN:
+                       case FACE_BACK:
+                               return -1;
+                       default:
+                               return 0;
+               }
+       }
+
+       static glm::ivec3 FaceNormal(Face face) noexcept {
                return face2normal[face];
        }
 
@@ -98,7 +114,7 @@ struct Block {
                        value |= Mask(f);
                }
                void Unset(Face f) {
-                       value |= ~Mask(f);
+                       value &= ~Mask(f);
                }
 
                void Clear() {
@@ -124,12 +140,24 @@ struct Block {
        };
 
 private:
-       static const glm::tvec3<int> face2normal[6];
+       static const glm::ivec3 face2normal[6];
        static const glm::mat4 orient2transform[ORIENT_COUNT];
        static const Face orient2face[ORIENT_COUNT][FACE_COUNT];
 
 };
 
+inline bool operator ==(const Block &a, const Block &b) {
+       return a.type == b.type && a.orient == b.orient;
+}
+
+inline bool operator !=(const Block &a, const Block &b) {
+       return !(a == b);
+}
+
+std::ostream &operator <<(std::ostream &, const Block &);
+std::ostream &operator <<(std::ostream &, const Block::Face &);
+std::ostream &operator <<(std::ostream &, const Block::Turn &);
+
 }
 
 #endif