block: added list of paths towards the block

(for detecting incoming trains without reservation)
Dieser Commit ist enthalten in:
Reinder Feenstra 2023-12-28 23:25:38 +01:00
Ursprung 81c7cde7dd
Commit 29eb8402ee
2 geänderte Dateien mit 16 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -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(),
[&currentPath=*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));
}
}

Datei anzeigen

@ -46,8 +46,11 @@ class BlockRailTile : public RailTile
CREATE_DEF(BlockRailTile)
private:
using Paths = std::vector<std::shared_ptr<BlockPath>>;
Node m_node;
std::vector<std::shared_ptr<BlockPath>> m_paths;
Paths m_paths; //!< Paths from this block to other block
Paths m_pathsIn; //!< Paths from other blocks to this block
std::array<std::weak_ptr<BlockPath>, 2> m_reservedPaths; // index is BlockSide
void updatePaths();