summaryrefslogtreecommitdiff
path: root/game/network
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-10-13 20:04:05 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-10-13 20:04:05 +0100
commitc0709b8c03cc9368bd4769d58de298e31041bca3 (patch)
tree4a3f1fc0344ab2ff8384f2b349d7082a8b25880a /game/network
parentSupport searching node network by vec3 position (diff)
downloadilt-c0709b8c03cc9368bd4769d58de298e31041bca3.tar.bz2
ilt-c0709b8c03cc9368bd4769d58de298e31041bca3.tar.xz
ilt-c0709b8c03cc9368bd4769d58de298e31041bca3.zip
Search node network without creating temporary nodes on the heap
Diffstat (limited to 'game/network')
-rw-r--r--game/network/network.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/game/network/network.cpp b/game/network/network.cpp
index aff1aa4..9683143 100644
--- a/game/network/network.cpp
+++ b/game/network/network.cpp
@@ -16,20 +16,23 @@ Network::Network(const std::string & tn) : texture {Texture::cachedTexture.get(t
NodePtr
Network::nodeAt(glm::vec3 pos)
{
- return *nodes.insert(std::make_shared<Node>(pos)).first;
+ return newNodeAt(pos).first;
}
std::pair<NodePtr, bool>
Network::newNodeAt(glm::vec3 pos)
{
- const auto i = nodes.insert(std::make_shared<Node>(pos));
- return {*i.first, i.second};
+ const auto [n, i] = candidateNodeAt(pos);
+ if (!i) {
+ nodes.insert(n);
+ }
+ return {n, !i};
}
NodePtr
Network::findNodeAt(glm::vec3 pos) const
{
- if (const auto n = nodes.find(std::make_shared<Node>(pos)); n != nodes.end()) {
+ if (const auto n = nodes.find(pos); n != nodes.end()) {
return *n;
}
return {};
@@ -38,7 +41,7 @@ Network::findNodeAt(glm::vec3 pos) const
std::pair<NodePtr, bool>
Network::candidateNodeAt(glm::vec3 pos) const
{
- if (const auto n = nodes.find(std::make_shared<Node>(pos)); n != nodes.end()) {
+ if (const auto n = nodes.find(pos); n != nodes.end()) {
return {*n, true};
}
return {std::make_shared<Node>(pos), false};