summaryrefslogtreecommitdiff
path: root/game/network/network.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-10-22 19:06:14 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-10-22 19:06:14 +0100
commit873ef1436e233b5b4c542f35838a7cd73432ede6 (patch)
treead5b0f0bba71c5da5791471216855a1af221c26e /game/network/network.cpp
parentMove -Wold-style-cast to gcc only list, clang triggers in some SDL headers (diff)
downloadilt-873ef1436e233b5b4c542f35838a7cd73432ede6.tar.bz2
ilt-873ef1436e233b5b4c542f35838a7cd73432ede6.tar.xz
ilt-873ef1436e233b5b4c542f35838a7cd73432ede6.zip
Tidy network node insertion/searching
Diffstat (limited to 'game/network/network.cpp')
-rw-r--r--game/network/network.cpp17
1 files changed, 9 insertions, 8 deletions
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<Node::Ptr, bool>
+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<Node::Ptr, bool>
+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<Node>(pos), false};
+ return {std::make_shared<Node>(pos), NodeIs::NotInNetwork};
}
Node::Ptr