18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-29 12:46:37 +01:00

Merge staging into feat/gl46-migration

origin/staging 7ac2472c3 into feat/gl46-migration db26a33ed, so that #468
merges into staging. Merge base 037158104. Staging carries master up to
571487612 (squashed in #514); this branch had merged master up to 7c12b83ba.

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's f4f8c75e4 (road orders measured along the lane) and 8fbf05674 (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:
jerrrrycho
2026-11-27 05:26:13 +01:00
397 changed files with 48215 additions and 5231 deletions

View File

@@ -19,9 +19,13 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/Timer.h"
#include "utilities/Logs.h"
#include "scene/sn_utils.h"
#include "scene/regionfile.h"
#include "scene/sceneterrain.h"
#include "rendering/renderer.h"
#include "widgets/map_objects.h"
#include "vehicle/aiwire.h"
#include <format>
namespace scene {
@@ -29,6 +33,57 @@ std::string const EU07_FILEEXTENSION_REGION { ".sbt" };
std::uint32_t const EU07_FILEHEADER { MAKE_ID4( 'E','U','0','7' ) };
std::uint32_t const EU07_FILEVERSION_REGION { MAKE_ID4( 'S', 'B', 'T', '2' ) };
std::map<std::string, basic_node *> Hierarchy;
namespace {
// name of the region file kept for specified scenario file
std::string
region_file_name( std::string const &Scenariofile ) {
auto filename { Scenariofile };
while( filename[ 0 ] == '$' ) {
// trim leading $ char rainsted utility may add to the base name for modified .scn files
filename.erase( 0, 1 );
}
erase_extension( filename );
filename = Global.asCurrentSceneryPath + filename;
filename += EU07_FILEEXTENSION_REGION;
return filename;
}
// reads the next section of a region file into the provided list. returns: the empty string on success, the reason
// of the failure otherwise
std::string
read_region_section( std::istream &Input, std::uint32_t const Sectionlimit, std::vector<std::pair<std::uint32_t, std::unique_ptr<basic_section>>> &Sections ) {
// section index, followed by section data size (counted from the start of the index), followed by section data
std::uint32_t sectionindex;
std::uint32_t sectionsize;
if( auto const error { region_file::read_section_header( Input, Sectionlimit, sectionindex, sectionsize ) }; false == error.empty() ) {
return error;
}
// the section is read out of its own data, it can't reach into the next one
std::string data( sectionsize - region_file::section_header_size, '\0' );
Input.read( data.data(), static_cast<std::streamsize>( data.size() ) );
if( false == Input.good() ) {
return std::format( "ends inside section {}", sectionindex );
}
std::istringstream sectioninput { std::move( data ) };
auto section { std::make_unique<basic_section>() };
section->deserialize( sectioninput );
std::string error;
if( true == sectioninput.fail() ) {
error = std::format( "has section {} shorter than its content", sectionindex );
}
else if( sectioninput.peek() != std::char_traits<char>::eof() ) {
error = std::format( "has section {} longer than its content", sectionindex );
}
Sections.emplace_back( sectionindex, std::move( section ) );
return error;
}
} // namespace
// potentially activates event handler with the same name as provided node, and within handler activation range
void
@@ -57,25 +112,15 @@ basic_cell::update_traction( TDynamicObject *Vehicle, int const Pantographindex
for( auto *traction : m_directories.traction ) {
// współczynniki równania parametrycznego
auto const paramfrontdot = glm::dot( traction->vParametric, vFront );
auto const fRaParam =
-( glm::dot( traction->pPoint1, vFront ) - glm::dot( pantographposition, vFront ) )
/ ( paramfrontdot != 0.0 ?
paramfrontdot :
0.001 ); // div0 trap
if( fRaParam < -0.001
|| fRaParam > 1.001 ) { continue; }
// the span against the pantograph, the geometry the AI uses to find the wire as well
auto const contact = ai_wire::span_contact(
traction->pPoint1, traction->vParametric, pantographposition, vFront, vUp, vLeft, pantograph->fWidth );
// jeśli tylko jest w przedziale, wyznaczyć odległość wzdłuż wektorów vUp i vLeft
// punkt styku płaszczyzny z drutem (dla generatora łuku el.)
auto const vStyk = traction->pPoint1 + fRaParam * traction->vParametric;
// wektor musi się mieścić w przedziale ruchu pantografu
auto const vGdzie = vStyk - pantographposition;
auto fVertical = glm::dot( vGdzie, vUp );
if( false == contact.within ) { continue; }
auto fVertical = contact.vertical;
if( fVertical >= 0.0 ) {
// jeśli ponad pantografem (bo może łapać druty spod wiaduktu)
auto const fHorizontal = std::abs( glm::dot( vGdzie, vLeft ) ) - pantograph->fWidth;
auto const fHorizontal = contact.horizontal;
if (Global.bEnableTraction
&& fVertical < pantograph->PantWys - 0.15 ) {
@@ -120,6 +165,24 @@ basic_cell::update_traction( TDynamicObject *Vehicle, int const Pantographindex
}
}
// checks whether a wire of the cell, not broken, is within reach of a pantograph at specified point
bool
basic_cell::wire_over( glm::dvec3 const &Point, glm::dvec3 const &Front, glm::dvec3 const &Up, glm::dvec3 const &Left, double const Halfwidth, double const Minheight, double const Maxheight ) const {
for( auto const *traction : m_directories.traction ) {
if( ( traction->DamageFlag & 128 ) != 0 ) {
// a broken wire powers nothing
continue;
}
if( ai_wire::reaches(
ai_wire::span_contact( traction->pPoint1, traction->vParametric, Point, Front, Up, Left, Halfwidth ),
Minheight, Maxheight ) ) {
return true;
}
}
return false;
}
// legacy method, updates sounds and polls event launchers within radius around specified point
void
basic_cell::update_events() {
@@ -232,22 +295,38 @@ basic_cell::deserialize( std::istream &Input ) {
m_area.deserialize( Input );
// cell shapes
// shape count followed by opaque shape data
// NOTE: a damaged count is cut short by the end of the data rather than followed
auto itemcount { sn_utils::ld_uint32( Input ) };
while( itemcount-- ) {
while( ( itemcount-- ) && ( true == Input.good() ) ) {
m_shapesopaque.emplace_back( shape_node().deserialize( Input ) );
}
itemcount = sn_utils::ld_uint32( Input );
while( itemcount-- ) {
while( ( itemcount-- ) && ( true == Input.good() ) ) {
m_shapestranslucent.emplace_back( shape_node().deserialize( Input ) );
}
itemcount = sn_utils::ld_uint32( Input );
while( itemcount-- ) {
while( ( itemcount-- ) && ( true == Input.good() ) ) {
m_lines.emplace_back( lines_node().deserialize( Input ) );
}
// cell activation flag
m_active = true == m_active || false == m_shapesopaque.empty() || false == m_shapestranslucent.empty() || false == m_lines.empty();
}
// takes over the content restored from a file into another cell, as deserialize() would have added it to this one
void
basic_cell::merge( basic_cell &&Other ) {
m_area.center = Other.m_area.center;
m_area.radius = std::max( m_area.radius, Other.m_area.radius );
m_shapesopaque.insert( m_shapesopaque.end(), std::make_move_iterator( Other.m_shapesopaque.begin() ), std::make_move_iterator( Other.m_shapesopaque.end() ) );
m_shapestranslucent.insert( m_shapestranslucent.end(), std::make_move_iterator( Other.m_shapestranslucent.begin() ), std::make_move_iterator( Other.m_shapestranslucent.end() ) );
m_lines.insert( m_lines.end(), std::make_move_iterator( Other.m_lines.begin() ), std::make_move_iterator( Other.m_lines.end() ) );
m_active = true == m_active || true == Other.m_active;
Other.m_shapesopaque.clear();
Other.m_shapestranslucent.clear();
Other.m_lines.clear();
}
// sends content of the class in legacy (text) format to provided stream
void
basic_cell::export_as_text( std::ostream &Output ) const {
@@ -782,6 +861,22 @@ basic_section::update_traction( TDynamicObject *Vehicle, int const Pantographind
}
}
// checks whether a wire of the section's cells around specified point is within reach of a pantograph at the point
bool
basic_section::wire_over( glm::dvec3 const &Point, glm::dvec3 const &Front, glm::dvec3 const &Up, glm::dvec3 const &Left, double const Halfwidth, double const Minheight, double const Maxheight ) const {
auto const radius { EU07_CELLSIZE * 0.5 }; // the same area of interest the pantographs look for their wire in
for( auto const &cell : m_cells ) {
// we reject early cells which aren't within our area of interest
if( glm::length2( cell.area().center - Point ) < sq( cell.area().radius + radius )
&& cell.wire_over( Point, Front, Up, Left, Halfwidth, Minheight, Maxheight ) ) {
return true;
}
}
return false;
}
// legacy method, polls event launchers within radius around specified point
void
basic_section::update_events( glm::dvec3 const &Location, float const Radius ) {
@@ -857,7 +952,7 @@ basic_section::deserialize( std::istream &Input ) {
m_area.deserialize( Input );
// section shapes: shape count followed by shape data
auto shapecount { sn_utils::ld_uint32( Input ) };
while( shapecount-- ) {
while( ( shapecount-- ) && ( true == Input.good() ) ) {
m_shapes.emplace_back( shape_node().deserialize( Input ) );
}
// partitioned data
@@ -866,6 +961,19 @@ basic_section::deserialize( std::istream &Input ) {
}
}
// takes over the content restored from a file into another section, as deserialize() would have added it to this one
void
basic_section::merge( basic_section &&Other ) {
m_area.center = Other.m_area.center;
m_area.radius = std::max( m_area.radius, Other.m_area.radius );
m_shapes.insert( m_shapes.end(), std::make_move_iterator( Other.m_shapes.begin() ), std::make_move_iterator( Other.m_shapes.end() ) );
Other.m_shapes.clear();
for( std::size_t index { 0 }; index < m_cells.size(); ++index ) {
m_cells[ index ].merge( std::move( Other.m_cells[ index ] ) );
}
}
// sends content of the class in legacy (text) format to provided stream
void
basic_section::export_as_text( std::ostream &Output ) const {
@@ -1165,30 +1273,44 @@ basic_region::update_traction( TDynamicObject *Vehicle, int const Pantographinde
}
}
// checks whether there's a contact wire over specified point, within reach of a pantograph there
bool
basic_region::wire_over( glm::dvec3 const &Point, glm::dvec3 const &Front, double const Halfwidth, double const Minheight, double const Maxheight ) const {
// the vertical up and the horizontal left of the heading. the tilt of the track in curves is left out
auto const up { glm::dvec3 { 0.0, 1.0, 0.0 } };
auto const left { glm::cross( up, Front ) };
auto const leftlength { glm::length( left ) };
if( leftlength <= 0.0 ) {
// no heading along the ground
return false;
}
// a list of its own, not the shared scratchpad of the region
std::vector<basic_section *> sectionlist;
sections( Point, EU07_CELLSIZE * 0.5, sectionlist );
for( auto const *section : sectionlist ) {
if( section->wire_over( Point, Front, up, left / leftlength, Halfwidth, Minheight, Maxheight ) ) {
return true;
}
}
return false;
}
// checks whether specified file is a valid region data file
bool
basic_region::is_scene( std::string const &Scenariofile ) const {
auto filename { Scenariofile };
while( filename[ 0 ] == '$' ) {
// trim leading $ char rainsted utility may add to the base name for modified .scn files
filename.erase( 0, 1 );
}
erase_extension( filename );
filename = Global.asCurrentSceneryPath + filename;
filename += EU07_FILEEXTENSION_REGION;
auto const filename { region_file_name( Scenariofile ) };
if( false == FileExists( filename ) ) {
return false;
}
// file type and version check
// file type and version check, and whether the sections add up to the whole file. a file cut short (by a write
// interrupted with an older version, or a copy) is caught here, while the scenery can still be loaded from the text
std::ifstream input( filename, std::ios::binary );
uint32_t headermain{ sn_utils::ld_uint32( input ) };
uint32_t headertype{ sn_utils::ld_uint32( input ) };
if( headermain != EU07_FILEHEADER || headertype != EU07_FILEVERSION_REGION ) {
// wrong file type
if( auto const layout { region_file::check_layout( input, EU07_FILEHEADER, EU07_FILEVERSION_REGION, static_cast<std::uint32_t>( m_sections.size() ) ) };
false == layout.empty() ) {
WriteLog( "Bad file: \"" + filename + "\" " + layout + ", ignored" );
return false;
}
@@ -1199,38 +1321,35 @@ basic_region::is_scene( std::string const &Scenariofile ) const {
void
basic_region::serialize( std::string const &Scenariofile ) const {
auto filename { Scenariofile };
while( filename[ 0 ] == '$' ) {
// trim leading $ char rainsted utility may add to the base name for modified .scn files
filename.erase( 0, 1 );
}
erase_extension( filename );
filename = Global.asCurrentSceneryPath + filename;
filename += EU07_FILEEXTENSION_REGION;
auto const filename { region_file_name( Scenariofile ) };
std::ofstream output { filename, std::ios::binary };
// region file version 1
// header: EU07SBT + version (0-255)
sn_utils::ls_uint32( output, EU07_FILEHEADER );
sn_utils::ls_uint32( output, EU07_FILEVERSION_REGION );
// sections
// TBD, TODO: build table of sections and file offsets, if we postpone section loading until they're within range
std::uint32_t sectioncount { 0 };
for( auto *section : m_sections ) {
if( section != nullptr ) {
++sectioncount;
// the file is written under a temporary name and takes the final one only when complete, so a write cut short
// (a crash, the process killed) leaves no partial file to be read on the next start
auto const error { region_file::write_through_temporary( filename, [ this ]( std::ostream &output ) {
// region file version 1
// header: EU07SBT + version (0-255)
sn_utils::ls_uint32( output, EU07_FILEHEADER );
sn_utils::ls_uint32( output, EU07_FILEVERSION_REGION );
// sections
// TBD, TODO: build table of sections and file offsets, if we postpone section loading until they're within range
std::uint32_t sectioncount { 0 };
for( auto *section : m_sections ) {
if( section != nullptr ) {
++sectioncount;
}
}
}
// section count, followed by section data
sn_utils::ls_uint32( output, sectioncount );
std::uint32_t sectionindex { 0 };
for( auto *section : m_sections ) {
// section data: section index, followed by length of section data, followed by section data
if( section != nullptr ) {
sn_utils::ls_uint32( output, sectionindex );
section->serialize( output ); }
++sectionindex;
// section count, followed by section data
sn_utils::ls_uint32( output, sectioncount );
std::uint32_t sectionindex { 0 };
for( auto *section : m_sections ) {
// section data: section index, followed by length of section data, followed by section data
if( section != nullptr ) {
sn_utils::ls_uint32( output, sectionindex );
section->serialize( output ); }
++sectionindex;
} } ) };
if( false == error.empty() ) {
ErrorLog( "Bad file: binary version of the scenery wasn't written, " + error );
}
}
@@ -1238,48 +1357,69 @@ basic_region::serialize( std::string const &Scenariofile ) const {
bool
basic_region::deserialize( std::string const &Scenariofile ) {
auto filename { Scenariofile };
while( filename[ 0 ] == '$' ) {
// trim leading $ char rainsted utility may add to the base name for modified .scn files
filename.erase( 0, 1 );
}
erase_extension( filename );
filename = Global.asCurrentSceneryPath + filename;
filename += EU07_FILEEXTENSION_REGION;
auto const filename { region_file_name( Scenariofile ) };
if( false == FileExists( filename ) ) {
Global.file_binary_terrain_state = false;
return false;
}
// region file version 1
// file type and version check
// file type and version check, and whether the sections add up to the whole file
std::ifstream input( filename, std::ios::binary );
uint32_t headermain { sn_utils::ld_uint32( input ) };
uint32_t headertype { sn_utils::ld_uint32( input ) };
if( headermain != EU07_FILEHEADER || headertype != EU07_FILEVERSION_REGION ) {
// wrong file type
WriteLog( "Bad file: \"" + filename + "\" is of either unrecognized type or version" );
auto const sectionlimit { static_cast<std::uint32_t>( m_sections.size() ) };
auto error { region_file::check_layout( input, EU07_FILEHEADER, EU07_FILEVERSION_REGION, sectionlimit ) };
if( false == error.empty() ) {
ErrorLog( "Bad file: \"" + filename + "\" " + error + ", the geometry it holds is missing" );
return false;
}
// sections
// TBD, TODO: build table of sections and file offsets, if we postpone section loading until they're within range
// section count
auto sectioncount { sn_utils::ld_uint32( input ) };
while( sectioncount-- ) {
// section index, followed by section data size, followed by section data
auto const sectionindex { sn_utils::ld_uint32( input ) };
auto const sectionsize { sn_utils::ld_uint32( input ) };
if( m_sections[ sectionindex ] == nullptr ) {
m_sections[ sectionindex ] = new basic_section();
// the sections are restored apart from the region, which takes them over only once the whole file was read
// without a fault: a damaged file leaves nothing of itself behind
std::vector<std::pair<std::uint32_t, std::unique_ptr<basic_section>>> sections;
try {
input.clear();
input.seekg( 2 * sizeof( std::uint32_t ), std::ios::beg );
// section count
auto sectioncount { sn_utils::ld_uint32( input ) };
sections.reserve( sectioncount );
while( ( sectioncount-- ) && ( true == error.empty() ) ) {
error = read_region_section( input, sectionlimit, sections );
}
}
catch( std::exception const &Exception ) {
error = std::string( "can't be read, " ) + Exception.what();
}
if( false == error.empty() ) {
ErrorLog( "Bad file: \"" + filename + "\" " + error + ", the geometry it holds is missing" );
return false;
}
for( auto &[ sectionindex, section ] : sections ) {
if( m_sections[ sectionindex ] == nullptr ) {
m_sections[ sectionindex ] = section.release();
}
else {
m_sections[ sectionindex ]->merge( std::move( *section ) );
}
m_sections[ sectionindex ]->deserialize( input );
}
return true;
}
// removes the region file of specified scenario file, which turned out to be damaged, so the next start writes it anew
void
basic_region::discard_scene( std::string const &Scenariofile ) const {
auto const filename { region_file_name( Scenariofile ) };
std::error_code error;
if( true == std::filesystem::remove( filename, error ) ) {
WriteLog( "Bad file: \"" + filename + "\" removed, it will be made anew from the scenery on the next start" );
}
else if( error ) {
ErrorLog( "Bad file: \"" + filename + "\" can't be removed, " + error.message() + ". Remove it to have it made anew from the scenery" );
}
}
// sends content of the class in legacy (text) format to provided stream
void
basic_region::export_as_text( std::ostream &Output ) const {