summary refs log tree commit diff
path: root/src/World/ChunkRegistry.cpp
blob: 95ae6bd6c2952d0aeabcd8c3d79470ec002e1c24 (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
#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) {
    if (!Chunk::is_valid_position(pos.to_local())) return nullptr;
    return &get(ChunkIndex::from_position(pos));
}

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

}