summary refs log tree commit diff
path: root/src/World/Position.hpp
blob: b603ee4adb78d9e6714dd48fdadcb68f148fee15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once

#include "array"
#include "../Math/Vector.hpp"

namespace MC::World::Position {

// Position within entire world.
using World = Vector<3>;

// Offset between block positions within single chunk.
class BlockOffset : public Vector<3, I16> {
public:
    BlockOffset(I16 x, I16 y, I16 z) : Vector(x, y, z) {}
    Bool fits_within_chunk() const {
        using namespace ChunkDimensions;
        return x() >= 0 && x() < Width && y() >= 0 && y() < Height && z() >= 0 && z() < Width;
    }
};

// Position of a block within entire world.
class BlockWorld : public Vector<3, I64> {
public:
    BlockWorld(I64 x, I64 y, I64 z) : Vector(x, y, z) {}
};

// Position of a block within single chunk.
class BlockLocal : public Vector<3, U8> {
public:
    BlockLocal(U8 x, U8 y, U8 z) : Vector(x, y, z) {}
    BlockLocal(BlockOffset offset) : BlockLocal(offset.x(), offset.y(), offset.z()) {}
    BlockOffset offset(BlockOffset by) {
        return {
            static_cast<I8>(x() + by.x()),
            static_cast<I8>(y() + by.y()),
            static_cast<I8>(z() + by.z())
        };
    }
};

const std::array<BlockOffset, 6> axis_directions = {{
    {1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1},
}};

}