26 lines
926 B
C++
26 lines
926 B
C++
#include "Area.hpp"
|
|
|
|
#include "Chunk.hpp"
|
|
|
|
using namespace world;
|
|
|
|
std::optional<std::shared_ptr<Chunk>> ChunkContainer::findInRange(const chunk_pos &pos) const {
|
|
const auto it = find(pos);
|
|
return it != end() ? std::make_optional(it->second) : std::nullopt;
|
|
}
|
|
std::optional<std::shared_ptr<const Chunk>> ChunkContainer::findOrEmpty(const chunk_pos &pos) const {
|
|
return inRange(pos) ? findInRange(pos) : std::make_optional(world::EMPTY_CHUNK);
|
|
}
|
|
|
|
std::shared_ptr<Region> Area::getRegion(const std::string& folderPath, const area_<region_pos>& pos) {
|
|
{ // Found
|
|
const auto shared = regions.lock_shared();
|
|
const auto it = shared->find(pos.second);
|
|
if(it != shared->end())
|
|
return it->second;
|
|
}
|
|
// Reading
|
|
const auto reg = std::make_shared<Region>(folderPath, pos);
|
|
const auto unique = regions.lock();
|
|
return unique->insert({pos.second, reg}).first->second;
|
|
} |