diff --git a/server/src/board/tile/rail/blockrailtile.cpp b/server/src/board/tile/rail/blockrailtile.cpp index 8760d6d4..8c71f6dc 100644 --- a/server/src/board/tile/rail/blockrailtile.cpp +++ b/server/src/board/tile/rail/blockrailtile.cpp @@ -463,7 +463,7 @@ void BlockRailTile::updatePaths() m_paths.clear(); // make sure it is empty, it problably is after the move auto found = BlockPath::find(*this); - while(!current.empty()) + while(!current.empty()) // handle existing paths { auto it = std::find_if(found.begin(), found.end(), [¤tPath=*current.front()](const auto& foundPath) @@ -479,8 +479,18 @@ void BlockRailTile::updatePaths() current.erase(current.begin()); } - for(auto& path : found) + for(auto& path : current) // no longer existing paths { + auto& pathsIn = path->toBlock()->m_pathsIn; + if(auto it = std::find(pathsIn.begin(), pathsIn.end(), path); it != pathsIn.end()) + { + pathsIn.erase(it); + } + } + + for(auto& path : found) // new paths + { + path->toBlock()->m_pathsIn.emplace_back(path); m_paths.emplace_back(std::move(path)); } } diff --git a/server/src/board/tile/rail/blockrailtile.hpp b/server/src/board/tile/rail/blockrailtile.hpp index 61f605d4..329dd775 100644 --- a/server/src/board/tile/rail/blockrailtile.hpp +++ b/server/src/board/tile/rail/blockrailtile.hpp @@ -46,8 +46,11 @@ class BlockRailTile : public RailTile CREATE_DEF(BlockRailTile) private: + using Paths = std::vector>; + Node m_node; - std::vector> m_paths; + Paths m_paths; //!< Paths from this block to other block + Paths m_pathsIn; //!< Paths from other blocks to this block std::array, 2> m_reservedPaths; // index is BlockSide void updatePaths();