mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-28 23:13:23 +01:00
Merge staging into feat/gl46-migration
origin/staging7ac2472c3into feat/gl46-migrationdb26a33ed, so that #468 merges into staging. Merge base037158104. Staging carries master up to571487612(squashed in #514); this branch had merged master up to7c12b83ba. Conflicts, file by file: - README.md: WITH_BETTER_RENDERER row dropped (gl46), USE_SYSTEM_JSON row kept (staging) - CMakeLists.txt: gl46 lists, plus staging's new core sources (hardwareinfo, sn_utils, regionfile, inionlysettings, fieldshunting, gaugewrap, drivingaid, signalpassing, brakereleaser, crew, brakecharge); none listed twice - tests/unit/CMakeLists.txt: both (texturealpha, freecameramotion; editorSwitchDrives, Camera) - vehicle/brakingcurve.{h,cpp}, tests/unit/test_braking_curve.cpp (add/add): staging (#479 brake_acting on the same #409 code) - editor/editorHttp.cpp: staging (it has gl46's #432 and certificate fixes, plus #439 libcurl loaded at run time) - tests/unit/test_editor_http.cpp (add/add): staging (adds the available() case of #439) - utilities/Globals.h: gl46 crashdump_full (staging's CrashDumpFull is #425, replaced here by utilities/crashdump.cpp); fmradio and staging's OpenAL options both; gfx_headlights_beamwidth (#481) not taken - utilities/Globals.cpp: both (odometer.expiry, OpenAL keys, fmradio, gl46 gfx keys); gfx.headlights.beamwidth (#481) not taken - utilities/Logs.cpp: staging's log_file_name() for both files, with gl46's crashdump_set_log_file() for both - utilities/utilities.h: gl46 set_thread_random_engine(); Random(int, int) gone on both sides - tests/unit/test_utilities.cpp: staging's includes - simulation/simulationtest.cpp: gl46 (no NvRenderer, LegacyRenderer, BasicRenderer here) - ci_shadervalidator/* (incl. add/add utilities/Logs.h): gl46's validator of shaders/ogl46 and shaders/vk14; staging's #437 fixed the GL 3.3 one - gl/shader.cpp, gl/glsl_common.cpp: gl46 (shaders come from rendering/common/shadersource.cpp); HEADLIGHT_BEAM_WIDTH (#481) not taken - shaders/mat_wire.frag: gl46. Rename detection paired staging's mat_colored.frag (#481) with it - lang/editor_pl.po: union; the 12 camera speed / orthophoto entries staging adds are here already (master #312) - audio/audiorenderer.{h,cpp}: both (fmradio; startsample and the low-pass filter); the destructor releases the radio, then the filter - application/editormode.h, application/editormodeswitchdrive.cpp: staging (#509 on #330, which is all this side had) - application/application.cpp: gl46's start sequence (no init_ogl, ANGLE or NvRenderer; crash window after init_ui) with staging's hardware::log_system() (#389) - EU07.cpp: gl46 (crash reports of utilities/crashdump.cpp); staging's side was #425's handler, replaced here - model/Texture.{h,cpp}: gl46 (texture_source); staging's side is master #399/#411/#362/#386, merged here before - world/Track.h, world/TrackSleepers.h: both (TrackBlend, lay(Fastened)/fasten; TrackBuckle, pack_models) - world/Segment.cpp: staging's track buckling on the split stray factors both sides have - vehicle/Driver.h: staging's additions (#444, #494, #473, #346, timetable flags) - vehicle/Driver.cpp: staging's file, with this branch'sf4f8c75e4(road orders measured along the lane) and8fbf05674(a holding road order blocks the ones past it) applied again; #409's SeenAheadTolerance gives way to #473 - vehicle/DynObj.h: friend opengl46_renderer and friend class vehicle_table - vehicle/DynObj.cpp: gl46's vehicle_table::update() with staging's update_off_track_contacts() and update_brake_pipes() - McZapkie/Mover.cpp: staging's function splits (#239) and hose exchange (#388); every line this branch added to Mover.cpp/MOVER.h is kept - .github/workflows/build_bin.yml: staging's apt-install step (#497) and pinned download-artifact (#331) Modify/delete, kept deleted: - rendering/opengl33renderer.{cpp,h}, rendering/openglparticles.cpp, rendering/openglrenderer.{cpp,h}: staging's versions are master's, and every master change to them is in this branch's history already - shaders/light_common.glsl, shaders/mat_sunlessnormalmap_specgloss.frag: see below Carried into this branch's code: - the hose exchange after each sub-step (#387/#388) also in update_steps_parallel(), per group of vehicles, as update() does it single-threaded - physics.pipewake (pipe_wakes(), wake_cause::scndpipe) in staging's GetScndDVc(), where the main reservoir hose exchange went - hardware::log_gl_context() (#389) in after_window() of the GL 4.6 backend, init_ogl() being gone Taken back out of the auto-merge (renderers this branch removed): - shaders/vk14/tonemapping.glsl: #481's switch to ACES, applied there by rename detection - environment/skydome.cpp, simulation/simulationenvironment.cpp: #415, the sky of the legacy renderer - application/application.cpp: #384's fallback of an unknown gfxrenderer, which this branch had dropped Not carried from staging (renderer files removed here): - master #481 (571487612): old assets drawn as in 26.05 (metal diffuse, sun highlight tint, ACES, SUN_DIFFUSE_SCALE 2.5, untinted Diffuse, mat_colored base) and gfx.headlights.beamwidth. Made for the GL 3.3 shaders; the PBR shaders of shaders/ogl46 and vk14 (and their SPIR-V binaries) are the author's call - #437: the unique temporary file of the shader validator (Sonar S5443); gl46's validator still writes /tmp/shader* Unit tests: 1133 of 1137 cases pass. Four staging tests fail (derailment: a repaired vehicle is back on the rails; three pullee cases): the vehicle stands, and with physics.sleepheld (on by default here) its physics sleeps with the Fb / FStand of before. With physics.sleepheld off they pass. Left to the author.
This commit is contained in:
@@ -10,6 +10,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "stdafx.h"
|
||||
#include "editor/editorRoad.hpp"
|
||||
#include "editor/editorFormat.hpp"
|
||||
#include "editor/editorRingRoom.hpp"
|
||||
|
||||
#include "editor/editorTrack.hpp"
|
||||
#include "world/Track.h"
|
||||
@@ -19,6 +20,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "utilities/Globals.h"
|
||||
#include "utilities/utilities.h"
|
||||
#include "utilities/translation.h"
|
||||
#include "editor/editorRoadLimits.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -29,10 +31,8 @@ namespace
|
||||
double const kSamePoint{0.25}; // ends of two pieces this close are taken for joined
|
||||
double const kPieceLength{50.0}; // longest piece the planner makes
|
||||
double const kPieceTurn{glm::radians(30.0)}; // largest turn of a single piece
|
||||
double const kShortestRoad{2.0};
|
||||
double const kTightestRadius{6.0};
|
||||
// the shortest road, the tightest bend and the sharpest angle between roads go by what the road is made of: road_limits_for()
|
||||
double const kCornerRoom{4.0}; // length of an arm of a junction past the point where its edge meets the edge of the next one, taken by the rounded corner
|
||||
double const kSharpestBranch{glm::radians(30.0)}; // smallest angle between two roads leaving a junction
|
||||
double const kWidestCorner{glm::radians(120.0)}; // arms further apart than this don't have to make room for each other
|
||||
double const kTransitionLength{30.0}; // length of the road taken by a change of its lanes
|
||||
|
||||
@@ -274,7 +274,9 @@ bool follow(road_node &Road, double const T, bool const Forward, double const Di
|
||||
auto const lengths{stations(state)};
|
||||
auto const here{station_at(lengths, from)};
|
||||
auto const available{forward ? lengths.back() - here : here};
|
||||
if (remaining <= 0.0 || available >= remaining + kShortestRoad)
|
||||
// what's left of a piece of a roundabout carries on round, so it can be shorter than a road of its own
|
||||
auto const shortest{state.roundabout ? editor_ring::shortest_piece : road_limits_for(state.surfacetype).shortest_road};
|
||||
if (remaining <= 0.0 || available >= remaining + shortest)
|
||||
{
|
||||
// the cut is put here; with nothing left to go the piece is kept whole
|
||||
Cut.road = piece;
|
||||
@@ -339,6 +341,27 @@ double edge_reach(double const Halfwidth, double const Otherhalfwidth, double co
|
||||
return (Otherhalfwidth + Halfwidth * std::cos(Angle)) / std::sin(Angle);
|
||||
}
|
||||
|
||||
// the circle the axis of a piece bends along at specified value of its curve parameter, seen from above. returns: false if it's straight there
|
||||
bool ring_circle(road_node::state const &State, double const T, glm::dvec2 &Centre, double &Radius)
|
||||
{
|
||||
auto const points{curve_points(State.axis)};
|
||||
auto const u{1.0 - T};
|
||||
auto const first{3.0 * u * u * (points[1] - points[0]) + 6.0 * u * T * (points[2] - points[1]) + 3.0 * T * T * (points[3] - points[2])};
|
||||
auto const second{6.0 * u * (points[2] - 2.0 * points[1] + points[0]) + 6.0 * T * (points[3] - 2.0 * points[2] + points[1])};
|
||||
glm::dvec2 const velocity{first.x, first.z};
|
||||
auto const speed{glm::length(velocity)};
|
||||
if (speed < 1e-9)
|
||||
return false;
|
||||
auto const curvature{(velocity.x * second.z - velocity.y * second.x) / (speed * speed * speed)};
|
||||
if (std::abs(curvature) < 1e-5)
|
||||
return false;
|
||||
auto const point{curve_point(points, T)};
|
||||
auto const tangent{velocity / speed};
|
||||
Centre = glm::dvec2{point.x, point.z} + glm::dvec2{-tangent.y, tangent.x} / curvature;
|
||||
Radius = 1.0 / std::abs(curvature);
|
||||
return true;
|
||||
}
|
||||
|
||||
// the look of a junction goes after the road it's made on
|
||||
void dress(junction_node::state &Junction, road_node::state const &Road)
|
||||
{
|
||||
@@ -1363,12 +1386,15 @@ editor_road::loose_end editor_road::find_end(glm::dvec3 const &Point, double con
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<segment_data> editor_road::plan(glm::dvec3 const &Start, glm::dvec2 const *Direction, glm::dvec3 const &Target, glm::dvec2 const *Enddirection, bool const Straight, std::string &Error)
|
||||
std::vector<segment_data> editor_road::plan(glm::dvec3 const &Start, glm::dvec2 const *Direction, glm::dvec3 const &Target, glm::dvec2 const *Enddirection, bool const Straight,
|
||||
road_surface_type const Type, double const Halfwidth, std::string &Error)
|
||||
{
|
||||
std::vector<segment_data> pieces;
|
||||
glm::dvec2 const chord{Target.x - Start.x, Target.z - Start.z};
|
||||
auto const span{glm::length(chord)};
|
||||
if (span < kShortestRoad)
|
||||
auto const limits{road_limits_for(Type)};
|
||||
auto const tightest{editor_road_limits::tightest_bend(limits, Halfwidth)};
|
||||
if (span < limits.shortest_road)
|
||||
{
|
||||
Error = "Too short";
|
||||
return pieces;
|
||||
@@ -1388,7 +1414,7 @@ std::vector<segment_data> editor_road::plan(glm::dvec3 const &Start, glm::dvec2
|
||||
if (Direction != nullptr && Enddirection != nullptr)
|
||||
{
|
||||
// both ends are tied, which leaves a single curve with the tangents set
|
||||
if (glm::dot(*Direction, chord) < 0.1 * span || glm::dot(*Enddirection, chord) < 0.1 * span)
|
||||
if (glm::dot(*Direction, chord) < limits.tied_lead * span || glm::dot(*Enddirection, chord) < limits.tied_lead * span)
|
||||
{
|
||||
Error = "The road would have to turn back to meet the end";
|
||||
return pieces;
|
||||
@@ -1406,7 +1432,7 @@ std::vector<segment_data> editor_road::plan(glm::dvec3 const &Start, glm::dvec2
|
||||
straight(Target);
|
||||
return pieces;
|
||||
}
|
||||
if (radius < kTightestRadius)
|
||||
if (radius < tightest)
|
||||
{
|
||||
Error = "The bend is too tight";
|
||||
return pieces;
|
||||
@@ -1419,7 +1445,7 @@ std::vector<segment_data> editor_road::plan(glm::dvec3 const &Start, glm::dvec2
|
||||
{
|
||||
// only the far end is tied: the same road as the one leading back from there, turned around
|
||||
glm::dvec2 const back{-*Enddirection};
|
||||
auto reversed{plan(Target, &back, Start, nullptr, Straight, Error)};
|
||||
auto reversed{plan(Target, &back, Start, nullptr, Straight, Type, Halfwidth, Error)};
|
||||
for (auto &piece : reversed)
|
||||
{
|
||||
std::swap(piece.points[segment_data::point::start], piece.points[segment_data::point::end]);
|
||||
@@ -1441,7 +1467,7 @@ std::vector<segment_data> editor_road::plan(glm::dvec3 const &Start, glm::dvec2
|
||||
auto const side{glm::dot(chord, left)};
|
||||
if (Straight || std::abs(side) < 0.02 * span)
|
||||
{
|
||||
if (along < kShortestRoad)
|
||||
if (along < limits.shortest_road)
|
||||
{
|
||||
Error = "The target is behind the start";
|
||||
return pieces;
|
||||
@@ -1451,12 +1477,12 @@ std::vector<segment_data> editor_road::plan(glm::dvec3 const &Start, glm::dvec2
|
||||
}
|
||||
auto const turn{2.0 * std::atan2(side, along)}; // positive to the left
|
||||
auto const radius{span * span / (2.0 * side)}; // likewise
|
||||
if (std::abs(turn) > glm::radians(170.0))
|
||||
if (std::abs(turn) > limits.widest_turn)
|
||||
{
|
||||
Error = "The road would have to turn back to reach the target";
|
||||
return pieces;
|
||||
}
|
||||
if (std::abs(radius) < kTightestRadius)
|
||||
if (std::abs(radius) < tightest)
|
||||
{
|
||||
Error = "The bend is too tight";
|
||||
return pieces;
|
||||
@@ -1817,7 +1843,8 @@ bool editor_road::lane_width(road_node::state const &State, double const T, floa
|
||||
return true;
|
||||
}
|
||||
|
||||
bool editor_road::branch_from(road_node &Road, double const T, glm::dvec2 const &Direction, int const Incoming, int const Outgoing, float const Width, branch &Result, std::string &Error)
|
||||
bool editor_road::branch_from(road_node &Road, double const T, glm::dvec2 const &Direction, int const Incoming, int const Outgoing, float const Width, road_surface_type const Type, branch &Result,
|
||||
std::string &Error)
|
||||
{
|
||||
Result = branch{};
|
||||
auto const &layout{Road.definition()};
|
||||
@@ -1826,7 +1853,7 @@ bool editor_road::branch_from(road_node &Road, double const T, glm::dvec2 const
|
||||
auto const direction{glm::length(Direction) > 1e-9 ? glm::normalize(Direction) : glm::dvec2{0.0, 1.0}};
|
||||
// the sharper the angle the road leaves at, the further from the centre the edges of the roads part
|
||||
auto const angle{std::acos(std::clamp(std::abs(glm::dot(direction, along)), 0.0, 1.0))};
|
||||
if (angle < kSharpestBranch)
|
||||
if (angle < road_limits_for(Type).sharpest_branch)
|
||||
{
|
||||
Error = "The road would leave at too sharp an angle";
|
||||
return false;
|
||||
@@ -1846,11 +1873,27 @@ bool editor_road::branch_from(road_node &Road, double const T, glm::dvec2 const
|
||||
auto const branchhalfwidth{0.5 * (Incoming + Outgoing) * Width};
|
||||
auto const reach{edge_reach(halfwidth, branchhalfwidth, angle) + kCornerRoom};
|
||||
auto const branchreach{edge_reach(branchhalfwidth, halfwidth, angle) + kCornerRoom};
|
||||
// how far the junction takes the road back along it and ahead of the centre
|
||||
std::array<double, 2> reaches{reach, reach};
|
||||
glm::dvec2 ringcentre{0.0};
|
||||
double ringradius{0.0};
|
||||
if (layout.roundabout && ring_circle(layout, T, ringcentre, ringradius))
|
||||
{
|
||||
// the ring bends away from a road leaving it to the outside, so their edges meet sooner than on a straight road; and a road
|
||||
// leaving at a slant meets the edge of the ring sooner on the side it leans away from. the room of a straight road, measured
|
||||
// on the side the road leans towards, is the most a side takes
|
||||
for (int side = 0; side < 2; ++side)
|
||||
{
|
||||
auto const room{editor_ring::edge_room(ringcentre, ringradius, glm::dvec2{centre.x, centre.z}, direction, side == 0 ? -along : along, halfwidth, branchhalfwidth)};
|
||||
if (room >= 0.0)
|
||||
reaches[side] = std::min(reach, room + kCornerRoom);
|
||||
}
|
||||
}
|
||||
|
||||
// where the road is cut on both sides of the centre
|
||||
road_cut cuts[2];
|
||||
std::vector<road_node *> consumed;
|
||||
if (false == follow(Road, T, false, reach, cuts[0], consumed, Error) || false == follow(Road, T, true, reach, cuts[1], consumed, Error))
|
||||
if (false == follow(Road, T, false, reaches[0], cuts[0], consumed, Error) || false == follow(Road, T, true, reaches[1], cuts[1], consumed, Error))
|
||||
return false;
|
||||
if (cuts[0].road == cuts[1].road && cuts[0].road != &Road)
|
||||
{
|
||||
@@ -1928,7 +1971,8 @@ bool editor_road::branch_from(road_node &Road, double const T, glm::dvec2 const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool editor_road::branch_from(junction_node &Junction, glm::dvec2 const &Direction, int const Incoming, int const Outgoing, float const Width, branch &Result, std::string &Error)
|
||||
bool editor_road::branch_from(junction_node &Junction, glm::dvec2 const &Direction, int const Incoming, int const Outgoing, float const Width, road_surface_type const Type, branch &Result,
|
||||
std::string &Error)
|
||||
{
|
||||
Result = branch{};
|
||||
auto const &layout{Junction.definition()};
|
||||
@@ -1951,7 +1995,7 @@ bool editor_road::branch_from(junction_node &Junction, glm::dvec2 const &Directi
|
||||
{
|
||||
auto const &other{layout.arms[idx]};
|
||||
auto const angle{std::acos(std::clamp(glm::dot(direction, other.direction), -1.0, 1.0))};
|
||||
if (angle < kSharpestBranch)
|
||||
if (angle < road_limits_for(Type).sharpest_branch)
|
||||
{
|
||||
Error = "The road would leave too close to another road of the junction";
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user