From df9b9bc264e0bf12e99b447be7903050c822692d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 10 May 2025 13:50:08 +0100 Subject: Add new network building interface Imperfect, matches some legacy interface in places, has some TODO notes. --- game/network/network.impl.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'game/network/network.impl.h') diff --git a/game/network/network.impl.h b/game/network/network.impl.h index e339922..54a5f4b 100644 --- a/game/network/network.impl.h +++ b/game/network/network.impl.h @@ -143,3 +143,39 @@ NetworkOf::addExtend(const GeoData * geoData, GlobalPosition3D star { return addCurve(geoData, genCurveDef(start, end, findNodeDirection(nodeAt(start)))); } + +template +Link::Ptr +NetworkOf::create(const GenStraightDef & def) +{ + return std::make_shared( + *this, candidateNodeAt(std::get<0>(def)).first, candidateNodeAt(std::get<1>(def)).first); +} + +template +Link::Ptr +NetworkOf::create(const GenCurveDef & def) +{ + return std::make_shared( + *this, candidateNodeAt(std::get<0>(def)).first, candidateNodeAt(std::get<1>(def)).first, std::get<2>(def)); +} + +template +void +NetworkOf::add(const GeoData *, const Link::Ptr & link) +{ + const auto addIf = [this](auto && lptr) { + if (lptr) { + links.emplace(lptr); + return true; + } + return false; + }; + for (auto & end : link->ends) { + end.node = nodeAt(end.node->pos); + } + if (!(addIf(std::dynamic_pointer_cast(link)) || ...)) { + throw std::logic_error("Unsupported link type for network"); + } + joinLinks(link); +} -- cgit v1.2.3