summaryrefslogtreecommitdiff
path: root/game/network/network.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-05-12 12:50:57 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2025-05-12 12:50:57 +0100
commit55c2a0f45d55e404494614c0f45a6bbc8985b0a8 (patch)
treed292b3ea9053fe9278db955ba38bd61b2719e252 /game/network/network.cpp
parentRename terrainSplitAt to connectAt (diff)
downloadilt-55c2a0f45d55e404494614c0f45a6bbc8985b0a8.tar.bz2
ilt-55c2a0f45d55e404494614c0f45a6bbc8985b0a8.tar.xz
ilt-55c2a0f45d55e404494614c0f45a6bbc8985b0a8.zip
Standard interface for creating link definitions
2 positions and, 0, 1 or 2 angles; always returns a GenLinksDef collection.
Diffstat (limited to 'game/network/network.cpp')
-rw-r--r--game/network/network.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/game/network/network.cpp b/game/network/network.cpp
index 5afac7e..70c4e21 100644
--- a/game/network/network.cpp
+++ b/game/network/network.cpp
@@ -166,21 +166,27 @@ Network::terrainSplit(const GeoData * geoData, const GenCurveDef & def) const
return out;
}
-GenCurveDef
-Network::genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & end, float startDir)
+GenLinksDef
+Network::genDef(const GlobalPosition3D & start, const GlobalPosition3D & end)
+{
+ return {GenStraightDef {start, end}};
+}
+
+GenLinksDef
+Network::genDef(const GlobalPosition3D & start, const GlobalPosition3D & end, Angle startDir)
{
const auto dir = pi + startDir;
const auto flatStart = start.xy(), flatEnd = end.xy();
const auto centre = find_arc_centre(flatStart, dir, flatEnd);
if (centre.second) { // right hand arc
- return {end, start, centre.first};
+ return {GenCurveDef {end, start, centre.first}};
}
- return {start, end, centre.first};
+ return {GenCurveDef {start, end, centre.first}};
}
-std::pair<GenCurveDef, GenCurveDef>
-Network::genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & end, float startDir, float endDir)
+GenLinksDef
+Network::genDef(const GlobalPosition3D & start, const GlobalPosition3D & end, Angle startDir, Angle endDir)
{
// Based on formula/code from https://www.ryanjuckett.com/biarc-interpolation/
const auto startVec = -sincos(startDir);
@@ -194,7 +200,7 @@ Network::genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & en
if (equalTangents && perpT1) {
const auto joint = start + (diff * 0.5F);
- return {genCurveDef(start, joint, startDir), genCurveDef(end, joint, endDir)};
+ return genDef(start, joint, startDir) + genDef(end, joint, endDir);
}
const auto vDotT = glm::dot(diff.xy(), endsVecTotal);
@@ -210,7 +216,7 @@ Network::genCurveDef(const GlobalPosition3D & start, const GlobalPosition3D & en
const auto joint = (start + end + ((difference(startVec, endVec) * extLen1) || 0.F)) / 2;
- return {genCurveDef(start, joint, startDir), genCurveDef(end, joint, endDir)};
+ return genDef(start, joint, startDir) + genDef(end, joint, endDir);
}
Link::Collection
@@ -228,15 +234,13 @@ Network::create(const GeoData * geoData, const CreationDefinition & def)
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};
+ return genDef(def.fromEnd.position, def.toEnd.position, *def.fromEnd.direction, *def.toEnd.direction);
}
// One specific direction, single curve from there
- return {genCurveDef(def.fromEnd.position, def.toEnd.position, *def.fromEnd.direction)};
+ return genDef(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)};
+ return genDef(def.toEnd.position, def.fromEnd.position, *def.toEnd.direction);
};
const auto splitDefs = [&linkDefs, this, geoData]() {
return std::ranges::fold_left(linkDefs(), GenLinksDef {}, [this, geoData](auto && existing, const auto & def) {