mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 11:15:23 +01:00
fix(editor): the roads across a track told by the track, not by its name; the paths far from the roads passed over first; a refusal of a crossing stays told
- roads_across() compares the track crossed by itself (rail_track::source), not by its name: every unnamed track (none, read with no name) and every track of a name another one has took the roads across all of them, laid again with an unrelated track edit. - A road whose axis lies far from every path of the track is passed over before the tracks of the scenery are gone through for it, and a path far from the roads is passed over at its start, before its points along it are worked out. - When one change affects several roads, the first refusal stays told with its fix: a road laid after it took the refusal and its window away, and the road refused stayed as it was with nothing told.
This commit is contained in:
@@ -373,7 +373,15 @@ void editor_mode::crossings_update()
|
||||
continue;
|
||||
level_crossing::design_result result;
|
||||
std::string reason;
|
||||
if (editor_road::settle_crossing(*road, record, result, reason))
|
||||
auto const laid{editor_road::settle_crossing(*road, record, result, reason)};
|
||||
// a road refused is told, with its fix, whatever comes of the roads after it: the last one's outcome told, a road laid after it
|
||||
// took the refusal and its window away, and the road refused stayed as it was with nothing told
|
||||
if (refusal)
|
||||
{
|
||||
WriteLog(format("Editor: crossing of %s %s, the refusal of another road told", road->name().c_str(), laid ? "laid" : "refused"));
|
||||
continue;
|
||||
}
|
||||
if (laid)
|
||||
{
|
||||
text = crossing_summary(result);
|
||||
refusal = false;
|
||||
|
||||
+39
-10
@@ -2146,6 +2146,33 @@ double outer_halfwidth(road_node::state const &State)
|
||||
return 0.5 * std::max(State.span(0.0), State.span(1.0)) + sides + kerbs;
|
||||
}
|
||||
|
||||
// none of the paths of the track starts within its own length of the box of the road's axis, as rails_crossing() takes them: the road
|
||||
// can't cross it, the paths of the scenery aren't gone through for it
|
||||
bool far_from_road(TTrack const &Track, segment_data const &Axis)
|
||||
{
|
||||
glm::dvec2 low{std::numeric_limits<double>::max()};
|
||||
glm::dvec2 high{-std::numeric_limits<double>::max()};
|
||||
// the curve within the box of its control points
|
||||
for (auto const &point : curve_points(Axis))
|
||||
{
|
||||
low = glm::min(low, glm::dvec2{point.x, point.z});
|
||||
high = glm::max(high, glm::dvec2{point.x, point.z});
|
||||
}
|
||||
for (int path = 0; path < track_rails::path_count(Track); ++path)
|
||||
{
|
||||
auto const &segment{track_rails::path_segment(Track, path)};
|
||||
auto const length{segment.GetLength()};
|
||||
if (length <= 0.0)
|
||||
continue;
|
||||
glm::dvec3 start;
|
||||
glm::dvec3 across;
|
||||
segment.plan_frame(0.0, start, across);
|
||||
if (start.x >= low.x - length && start.x <= high.x + length && start.z >= low.y - length && start.z <= high.y + length)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// the paths of the rail tracks the road crosses near the height of its axis, each as it lies where it's crossed
|
||||
std::vector<level_crossing::rail_track> rails_crossing(std::vector<level_crossing::road_piece> const &Pieces)
|
||||
{
|
||||
@@ -2179,15 +2206,19 @@ std::vector<level_crossing::rail_track> rails_crossing(std::vector<level_crossin
|
||||
continue;
|
||||
std::vector<glm::dvec3> rail;
|
||||
glm::dvec3 across;
|
||||
auto const far_from = [&](glm::dvec3 const &Point) { return Point.x < low.x - length || Point.x > high.x + length || Point.z < low.y - length || Point.z > high.y + length; };
|
||||
// tried at its start first: the points along a path far from the roads were worked out for nothing, for every path of the
|
||||
// scenery after every track edit
|
||||
glm::dvec3 start;
|
||||
segment.plan_frame(0.0, start, across);
|
||||
if (far_from(start))
|
||||
continue;
|
||||
for (int j = 0; j <= railpieces; ++j)
|
||||
{
|
||||
glm::dvec3 point;
|
||||
segment.plan_frame(length * j / railpieces, point, across);
|
||||
rail.push_back(point);
|
||||
}
|
||||
auto const far_from = [&](glm::dvec3 const &Point) { return Point.x < low.x - length || Point.x > high.x + length || Point.z < low.y - length || Point.z > high.y + length; };
|
||||
if (far_from(rail.front()))
|
||||
continue;
|
||||
for (int j = 1; j <= railpieces; ++j)
|
||||
for (auto const &line : lines)
|
||||
for (std::size_t i = 0; i + 1 < line.size(); ++i)
|
||||
@@ -2272,15 +2303,13 @@ std::vector<road_node *> editor_road::roads_across(TTrack const &Track)
|
||||
return result;
|
||||
for (auto *road : simulation::Roads.sequence())
|
||||
{
|
||||
if (road == nullptr || road->m_editorremoved)
|
||||
if (road == nullptr || road->m_editorremoved || far_from_road(Track, road->definition().axis))
|
||||
continue;
|
||||
std::vector<level_crossing::road_piece> pieces{{road->definition().axis, outer_halfwidth(road->definition())}};
|
||||
for (auto const &track : rails_crossing(pieces))
|
||||
if (track.name == Track.name())
|
||||
{
|
||||
result.push_back(road);
|
||||
break;
|
||||
}
|
||||
// the track itself: by its name, every road across an unnamed track (none, read as no name) was taken, or across another track
|
||||
// of the same name, and laid again with the edit of a track it doesn't cross
|
||||
if (std::ranges::any_of(rails_crossing(pieces), [&Track](level_crossing::rail_track const &Crossed) { return Crossed.source == &Track; }))
|
||||
result.push_back(road);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user