mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-28 17:24:06 +01:00
* feat(editor): dirt road type with looser layout limits in the road tool Every road shared the limits of a built road, so the road tool refused field tracks that bend tight, kink, have very short straights and fork at sharp angles (#347). Roads now have a type, paved (the default, with the limits as they were) or dirt, chosen in the road settings and saved with each piece as "surfacetype dirt". A dirt road bends down to a 3 m radius instead of 6 m, can be 1 m long instead of 2 m, leaves other roads at 15 degrees instead of 30, may lead off square to the far end when both ends are tied, and may turn up to 240 degrees in a hairpin. The limits come from one table, editor/editorRoadLimits.hpp, whose paved row holds the old constants. A paved road writes nothing new, so existing sceneries load and save byte for byte as before. Switching a road to dirt turns the default asphalt into the field road texture droga_polna from the game data and drops the white markings; a material picked by hand stays. * fix(editor): no bend of a road tighter than the road is wide, pi from <numbers>, the type's name as a string_view
53 lines
2.1 KiB
C++
53 lines
2.1 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "world/RoadSurfaceType.h"
|
|
|
|
#include <algorithm>
|
|
#include <numbers>
|
|
|
|
// how tight a road the road editor lays out, by what the road is made of
|
|
struct road_limits
|
|
{
|
|
double tightest_radius; // smallest radius of a bend [m]
|
|
double shortest_road; // shortest road, and shortest piece left of a road cut for a junction [m]
|
|
double sharpest_branch; // smallest angle between two roads leaving a junction [rad]
|
|
// a road with both ends tied to a direction: the least part of the distance between the ends each end has to lead towards the other
|
|
double tied_lead;
|
|
double widest_turn; // a road with its start tied to a direction: the largest turn of the arc leading to the target [rad]
|
|
};
|
|
|
|
namespace editor_road_limits
|
|
{
|
|
|
|
inline constexpr double degree{std::numbers::pi / 180.0};
|
|
// a paved road: the limits the editor had for every road before the types
|
|
inline constexpr road_limits paved{6.0, 2.0, 30.0 * degree, 0.1, 170.0 * degree};
|
|
// a dirt road follows the ground between the fields: a tractor's bend, short stretches between the bends, a fork at a sharp angle,
|
|
// a hairpin, an end leading off square to the way to the other end
|
|
inline constexpr road_limits dirt{3.0, 1.0, 15.0 * degree, 0.0, 240.0 * degree};
|
|
// room the inner edge of a bend keeps from the centre of the bend, as on a roundabout [m]
|
|
inline constexpr double inner_edge_room{1.0};
|
|
|
|
// smallest radius of a bend of a road with these limits, Halfwidth [m] wide on each side of its axis: the limit, and no less than
|
|
// leaves the inner edge of the road short of the centre of the bend, where the surface would fold over itself
|
|
inline double tightest_bend(road_limits const &Limits, double const Halfwidth)
|
|
{
|
|
return std::max(Limits.tightest_radius, Halfwidth + inner_edge_room);
|
|
}
|
|
|
|
} // namespace editor_road_limits
|
|
|
|
inline constexpr road_limits road_limits_for(road_surface_type const Type)
|
|
{
|
|
return Type == road_surface_type::dirt ? editor_road_limits::dirt : editor_road_limits::paved;
|
|
}
|