summary refs log tree commit diff
path: root/src/World/ChunkRegistry.cpp
blob: 97896fe51f2b669deef09627bfecc6f7219b86b0 (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
#include "ChunkRegistry.hpp"

namespace MC::World {

ChunkRegistry::Data& ChunkRegistry::get(ChunkIndex index) {
    auto entry = m_chunks.find(index);
    if (entry == m_chunks.end()) {
        Data data{index, Status::Empty};

        m_chunks.insert({index, std::move(data)});
        return m_chunks.at(index);
    }

    return entry->second;
}

ChunkRegistry::Data& ChunkRegistry::find(Position::BlockWorld pos) {
    return get(ChunkIndex::from_position(pos));
}

ChunkRegistry::Data& ChunkRegistry::find(Position::World pos) {
    return find(pos.round_to_block());
}

}