From 873ef1436e233b5b4c542f35838a7cd73432ede6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 22 Oct 2022 19:06:14 +0100 Subject: Tidy network node insertion/searching --- game/network/network.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'game/network/network.cpp') diff --git a/game/network/network.cpp b/game/network/network.cpp index d78f672..ad501b5 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -19,14 +19,15 @@ Network::nodeAt(glm::vec3 pos) return newNodeAt(pos).first; } -std::pair +Network::NodeInsertion Network::newNodeAt(glm::vec3 pos) { - const auto [n, i] = candidateNodeAt(pos); - if (!i) { - nodes.insert(n); + if (const auto [n, i] = candidateNodeAt(pos); i == NodeIs::NotInNetwork) { + return {*nodes.insert(std::move(n)).first, i}; + } + else { + return {n, NodeIs::InNetwork}; } - return {n, !i}; } Node::Ptr @@ -38,13 +39,13 @@ Network::findNodeAt(glm::vec3 pos) const return {}; } -std::pair +Network::NodeInsertion Network::candidateNodeAt(glm::vec3 pos) const { if (const auto n = nodes.find(pos); n != nodes.end()) { - return {*n, true}; + return {*n, NodeIs::InNetwork}; } - return {std::make_shared(pos), false}; + return {std::make_shared(pos), NodeIs::NotInNetwork}; } Node::Ptr -- cgit v1.2.3