MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / findAllUsableTrackInNetwork

Function findAllUsableTrackInNetwork

src/OpenLoco/src/Vehicles/Routing.cpp:615–668  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

613 // 0x004A2FE6 & 0x004A3462
614 template<typename FilterFunction>
615 static void findAllUsableTrackInNetwork(LocationOfInterestQueue& additionalTrackToCheck, const TrackNetworkSearchFlags searchFlags, const LocationOfInterest& initialInterest, FilterFunction&& filterFunction, RoutingResults& results)
616 {
617 const auto [trackEndLoc, trackEndRotation] = World::Track::getTrackConnectionEnd(initialInterest.loc, initialInterest.tad()._data);
618 auto tc = World::Track::getTrackConnections(trackEndLoc, trackEndRotation, initialInterest.company, initialInterest.trackType, 0, 0);
619
620 if (!tc.connections.empty())
621 {
622 for (auto c : tc.connections)
623 {
624 uint16_t trackAndDirection2 = c & World::Track::AdditionalTaDFlags::basicTaDWithSignalMask;
625 LocationOfInterest interest{ trackEndLoc, trackAndDirection2, initialInterest.company, initialInterest.trackType };
626 if (results.reachableLocs.tryAdd(interest))
627 {
628 if (!filterFunction(interest))
629 {
630 findAllUsableTrackPieces(additionalTrackToCheck, searchFlags, interest, filterFunction, results);
631 additionalTrackToCheck.push_back(interest);
632 }
633 }
634 }
635 }
636 else
637 {
638 results.hasDeadEnd = true;
639 }
640
641 if ((searchFlags & TrackNetworkSearchFlags::excludeReverseDirection) == TrackNetworkSearchFlags::none)
642 {
643 // odd logic here clearing a flag in a branch that can never hit
644 auto nextLoc = initialInterest.loc;
645 auto& trackSize = World::TrackData::getUnkTrack(initialInterest.tad()._data);
646 nextLoc += trackSize.pos;
647 if (trackSize.rotationEnd < 12)
648 {
649 nextLoc -= World::Pos3{ World::kRotationOffset[trackSize.rotationEnd], 0 };
650 }
651
652 const auto rotation = World::kReverseRotation[trackSize.rotationEnd];
653 auto tc2 = World::Track::getTrackConnections(nextLoc, rotation, initialInterest.company, initialInterest.trackType, 0, 0);
654 for (auto c : tc2.connections)
655 {
656 uint16_t trackAndDirection2 = c & World::Track::AdditionalTaDFlags::basicTaDWithSignalMask;
657 LocationOfInterest interest{ nextLoc, trackAndDirection2, initialInterest.company, initialInterest.trackType };
658 if (results.reachableLocs.tryAdd(interest))
659 {
660 if (!filterFunction(interest))
661 {
662 findAllUsableTrackPieces(additionalTrackToCheck, searchFlags, interest, filterFunction, results);
663 additionalTrackToCheck.push_back(interest);
664 }
665 }
666 }
667 }
668 }
669
670 constexpr size_t kSignalHashSetSize = 0x400;
671 constexpr size_t kTrackModHashSetSize = 0x1000;

Callers 1

Calls 7

getTrackConnectionEndFunction · 0.85
getTrackConnectionsFunction · 0.85
findAllUsableTrackPiecesFunction · 0.85
tadMethod · 0.80
tryAddMethod · 0.80
push_backMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected