]> git.localhorst.tv Git - blank.git/blobdiff - src/block.hpp
added ability to get seperate information about block face obstruction
[blank.git] / src / block.hpp
index 56f9eace671193c3a9376a0912a9e7b822893b12..3af80a854f29cc8945201b6af8d9babfd855c60a 100644 (file)
@@ -42,11 +42,15 @@ struct Block {
 
        const glm::mat4 &Transform() const;
 
-       Face GetFace() const { return Face(orient / 4); }
+       Face GetFace() const { return Face(orient / TURN_COUNT); }
        void SetFace(Face face) { orient = face * TURN_COUNT + GetTurn(); }
-       Turn GetTurn() const { return Turn(orient % 4); }
+       Turn GetTurn() const { return Turn(orient % TURN_COUNT); }
        void SetTurn(Turn turn) { orient = GetFace() * TURN_COUNT + turn; }
 
+       static Face Opposite(Face f) {
+               return Face(f ^ 1);
+       }
+
        static glm::tvec3<int> FaceNormal(Face face) {
                switch (face) {
                        case FACE_UP:
@@ -83,6 +87,43 @@ struct Block {
                }
        }
 
+       struct FaceSet {
+
+               explicit FaceSet(unsigned char v = 0)
+               : value(v) { }
+
+               bool IsSet(Face f) const {
+                       return value & Mask(f);
+               }
+               void Set(Face f) {
+                       value |= Mask(f);
+               }
+               void Unset(Face f) {
+                       value |= ~Mask(f);
+               }
+
+               void Clear() {
+                       value = 0;
+               }
+               void Fill() {
+                       value = Mask(FACE_COUNT) - 1;
+               }
+
+               bool Empty() const {
+                       return value == 0;
+               }
+               bool All() const {
+                       return value == Mask(FACE_COUNT) - 1;
+               }
+
+               unsigned char Mask(Face f) const {
+                       return 1 << f;
+               }
+
+               unsigned char value;
+
+       };
+
 };