diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-05-11 13:00:32 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-05-11 13:00:32 +0100 |
commit | 068681f599a0cb9ca57f2556632b7dc0e62fac9f (patch) | |
tree | bed492002dd2bd919455335e37a55830cfc4ce24 | |
parent | Build networks with new interface (diff) | |
download | ilt-068681f599a0cb9ca57f2556632b7dc0e62fac9f.tar.bz2 ilt-068681f599a0cb9ca57f2556632b7dc0e62fac9f.tar.xz ilt-068681f599a0cb9ca57f2556632b7dc0e62fac9f.zip |
Split definition creation from link creation
-rw-r--r-- | game/network/network.cpp | 41 | ||||
-rw-r--r-- | game/network/network.h | 4 |
2 files changed, 30 insertions, 15 deletions
diff --git a/game/network/network.cpp b/game/network/network.cpp index 295e6ec..561cafb 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -150,20 +150,31 @@ Network::create(const CreationDefinition & def) // Where to make a straight to join because angles align? // Where to drop part of S curve pair if a single curve works? - if (!def.fromEnd.direction && !def.toEnd.direction) { - // No specific directions at either end, straight link - return {create(GenStraightDef {def.fromEnd.position, def.toEnd.position})}; - } - if (def.fromEnd.direction) { - if (def.toEnd.direction) { - // Two specific directions at both ends, S curves - const auto curves = genCurveDef( - def.fromEnd.position, def.toEnd.position, *def.fromEnd.direction, *def.toEnd.direction); - return {create(curves.first), create(curves.second)}; + const auto linkDefs = [&def]() -> GenLinksDef { + if (!def.fromEnd.direction && !def.toEnd.direction) { + // No specific directions at either end, straight link + return {GenStraightDef {def.fromEnd.position, def.toEnd.position}}; } - // One specific direction, single curve from there - return {create(genCurveDef(def.fromEnd.position, def.toEnd.position, *def.fromEnd.direction))}; - } - // One specific direction, single curve from the other - return {create(genCurveDef(def.toEnd.position, def.fromEnd.position, *def.toEnd.direction))}; + if (def.fromEnd.direction) { + if (def.toEnd.direction) { + // Two specific directions at both ends, S curves + const auto curves = genCurveDef( + def.fromEnd.position, def.toEnd.position, *def.fromEnd.direction, *def.toEnd.direction); + return {curves.first, curves.second}; + } + // One specific direction, single curve from there + return {genCurveDef(def.fromEnd.position, def.toEnd.position, *def.fromEnd.direction)}; + } + // One specific direction, single curve from the other + return {genCurveDef(def.toEnd.position, def.fromEnd.position, *def.toEnd.direction)}; + }; + Link::Collection links; + std::ranges::transform(linkDefs(), std::back_inserter(links), [this](const auto & def) { + return std::visit( + [this](const auto & typedDef) { + return this->create(typedDef); + }, + def); + }); + return links; } diff --git a/game/network/network.h b/game/network/network.h index c1d3265..153b410 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -12,6 +12,8 @@ #include <set> #include <string> #include <utility> +#include <variant> +#include <vector> class SceneShader; struct Surface; @@ -21,6 +23,8 @@ template<typename> class Ray; template<size_t... N> using GenDef = std::tuple<glm::vec<N, GlobalDistance>...>; using GenStraightDef = GenDef<3, 3>; using GenCurveDef = GenDef<3, 3, 2>; +using GenLinkDef = std::variant<GenStraightDef, GenCurveDef>; +using GenLinksDef = std::vector<GenLinkDef>; struct CreationDefinitionEnd { GlobalPosition3D position; |