summary refs log tree commit diff
path: root/src/World/ChunkIndex.hpp
blob: 7d6fdbf00a1c885d3d147dc26ba312f9cf26c839 (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
#pragma once

#include "../Common/Sizes.hpp"

namespace MC::World {

struct ChunkIndex {
    ChunkIndex() : x(0), y(0) {}
    ChunkIndex(I32 x, I32 y) : x(x), y(y) {}

    Vector<3> middle() const {
        return {(x + 0.5f) * Chunk::Width, Chunk::Height / 2.0f, (y + 0.5f) * Chunk::Width};
    }

    I32 x, y;
};

}

template<> struct std::equal_to<MC::World::ChunkIndex> {
    Bool operator()(const MC::World::ChunkIndex& i1, const MC::World::ChunkIndex& i2) const noexcept {
        return i1.x == i2.x && i1.y == i2.y;
    }
};

template<> struct std::hash<MC::World::ChunkIndex> {
    USize operator()(const MC::World::ChunkIndex& i) const noexcept {
        return (I64)i.x << 32 | i.y;
    }
};