#include "Area.hpp"

#include "Chunk.hpp"

using namespace world::server;

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;
}

std::optional<double> Area::GetCurvature(const world::generator::params& params) {
    if (auto planet = std::get_if<world::generator::CubicPlanet::Params>(&params)) {
        return planet->height * (1.1 + planet->surface_roughness);
    }
    return {};
}