18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 06:55:02 +01:00

Merge branch 'master' into feat/renderers-cleanup

This commit is contained in:
2026-11-16 21:44:48 +01:00
264 changed files with 41203 additions and 10041 deletions

View File

@@ -18,6 +18,7 @@ http://mozilla.org/MPL/2.0/.
#include "world/SleeperWorker.h"
#include "world/Track.h"
#include "world/TrackRails.h"
#include "rendering/renderer.h"
#include "simulation/simulation.h"
#include "scene/scene.h"
#include "utilities/utilities.h"
@@ -25,6 +26,7 @@ http://mozilla.org/MPL/2.0/.
#include <glm/gtc/matrix_transform.hpp>
#include <algorithm>
#include <format>
#include <map>
#include <optional>
#include <set>
@@ -44,11 +46,14 @@ bool bedded( TTrack const &Track ) {
break;
}
case tt_Switch: {
// the switch trackbed takes the ballast of a plain track joined to it
auto const ballast = [&]( TTrack const *Other ) {
return Other != nullptr && Other->eType == tt_Normal && Other->m_material2 != null_handle; };
if( false == Global.CreateSwitchTrackbeds || Track.SwitchExtension == nullptr
|| ( Track.SwitchExtension->m_material3 == null_handle && false == ballast( Track.trPrev ) && false == ballast( Track.trNext ) ) ) {
// the switch trackbed takes the ballast of a plain track joined to it, as it's made at the load, the switch set straight.
// the tracks joined to the main path are asked, not the ends the switch is set to now: those change as it's thrown, also
// while the beams are worked out in the background
if( auto const ballast = []( TTrack const *Other ) {
return Other != nullptr && Other->eType == tt_Normal && Other->m_material2 != null_handle; };
false == Global.CreateSwitchTrackbeds || Track.SwitchExtension == nullptr
|| ( Track.SwitchExtension->m_material3 == null_handle && false == ballast( Track.SwitchExtension->pPrevs[ 0 ] )
&& false == ballast( Track.SwitchExtension->pNexts[ 0 ] ) ) ) {
return false;
}
break;
@@ -62,8 +67,9 @@ bool bedded( TTrack const &Track ) {
bool lays( TTrack const &Track ) {
// the model of the track itself (timbermodel) is enough, without sleepers3d in eu07.ini
return bedded( Track ) && timber_model( Track ) != nullptr;
// a renderer which doesn't draw them leaves the tracks their ballast, as they have it without the sleepers; the model of the track
// itself (timbermodel) is enough, without sleepers3d in eu07.ini
return GfxRenderer != nullptr && GfxRenderer->Draws_Timbers() && bedded( Track ) && timber_model( Track ) != nullptr;
}
double blade_rise( TTrack const &Track ) {
@@ -99,15 +105,15 @@ std::vector<std::pair<double, double>> shared_zones( TTrack const &Track, int co
if( false == bedded( Track ) || Path < 0 || Path >= path_count( Track ) ) {
return result;
}
auto const around { paths_around( const_cast<TTrack &>( Track ), true ) };
auto const found { std::find_if( around.begin(), around.end(), [&]( sampled_path const &Sampled ) { return Sampled.track == &Track && Sampled.path == Path; } ) };
auto const around { paths_around( Track, true ) };
auto const found { std::ranges::find_if( around, [ &Track, Path ]( sampled_path const &Sampled ) { return Sampled.track == &Track && Sampled.path == Path; } ) };
if( found == around.end() ) {
return result;
}
auto const &path { *found };
// where another path runs so near that the timbers carry both
for( auto const &stretch : stretches_where( path, [&]( glm::dvec3 const &Point, glm::dvec2 const &Direction ) {
return std::any_of( around.begin(), around.end(), [&]( sampled_path const &Other ) {
for( auto const &stretch : stretches_where( path, [ &around, &path ]( glm::dvec3 const &Point, glm::dvec2 const &Direction ) {
return std::ranges::any_of( around, [ &path, &Point, &Direction ]( sampled_path const &Other ) {
return &Other != &path && shares_with( path, Point, Direction, Other ); } ); } ) ) {
result.emplace_back( stretch.x, stretch.y );
}
@@ -128,6 +134,118 @@ namespace {
// the instances made so far, of all the tracks
std::uint64_t makings { 0 };
// the lengths along x of the parts of the model a timber is put together from
struct part_lengths {
double begin { 0.0 }; // of the end on the +x side
double piece { 0.0 }; // of the piece between the ends, at least a centimetre
double end { 0.0 }; // of the end on the -x side
};
// a run of beams of the track started at the instances laid so far
void open_run( laid const &Laid, chunk &Run ) {
for( int part = 0; part < part_count; ++part ) {
Run.first[ part ] = static_cast<std::uint32_t>( Laid.instances[ part ].size() );
}
Run.wholefirst = static_cast<std::uint32_t>( Laid.whole.size() );
Run.plainfirst = static_cast<std::uint32_t>( Laid.plain.size() );
}
// the run of beams of the track ended at the instances laid so far, by the sphere around the middles and half lengths of its beams
void close_run( laid &Laid, chunk &Run, std::vector<std::pair<glm::dvec3, double>> &Runbeams ) {
if( Runbeams.empty() ) {
return;
}
glm::dvec3 centre { 0.0 };
for( auto const &[ middle, half ] : Runbeams ) {
centre += middle;
}
centre /= static_cast<double>( Runbeams.size() );
auto radius { 0.0 };
for( auto const &[ middle, half ] : Runbeams ) {
radius = std::max( radius, glm::length( middle - centre ) + half );
}
Run.centre = glm::vec3 { centre };
Run.radius = static_cast<float>( radius + 0.3 );
for( int part = 0; part < part_count; ++part ) {
Run.last[ part ] = static_cast<std::uint32_t>( Laid.instances[ part ].size() );
}
Run.wholelast = static_cast<std::uint32_t>( Laid.whole.size() );
Run.plainlast = static_cast<std::uint32_t>( Laid.plain.size() );
Laid.chunks.push_back( Run );
Runbeams.clear();
}
// the instances of the beam in its frame: a plain sleeper whole, a timber stretched whole or put together of the parts of the model.
// a plain sleeper of the model of the track itself lifted as given, at the height it's drawn at without the 3D sleepers; the others
// with their seat at the top of the beam
void put_beam( laid &Laid, beam_model const &Parts, beam const &Beam, glm::mat4 const &Frame, double const Length, part_lengths const &Lengths, std::optional<float> const Plainlift ) {
// a part stretched along x by the scale, and moved so its x lands at the given place along the beam
auto const put = [ &Laid, &Parts, &Frame ]( int const Part, double const Scale, double const From, double const Place ) {
auto const shift { Place - Scale * From };
Laid.instances[ Part ].emplace_back(
glm::scale(
glm::translate( Frame, glm::vec3 { static_cast<float>( shift ), -Parts.seat, 0.F } ),
glm::vec3 { static_cast<float>( Scale ), 1.F, 1.F } ) );
};
auto const half { 0.5 * Length };
auto const between { Length - Lengths.begin - Lengths.end };
if( Beam.plain && Laid.plains != nullptr ) {
// the whole sleeper at its own length, its middle under the middle of the track
auto const &plain { *Laid.plains };
Laid.plain.emplace_back(
glm::translate( Frame, glm::vec3 { -0.5F * ( plain.span.x + plain.span.y ), Plainlift.value_or( -plain.seat ), 0.F } ) );
}
else if( false == Parts.stretchable ) {
// a timber of a model which can't be put together, the whole of it stretched to the length
auto const scale { Length / static_cast<double>( Parts.length() ) };
Laid.whole.emplace_back(
glm::scale(
glm::translate( Frame, glm::vec3 { static_cast<float>( -scale * 0.5 * ( Parts.span.x + Parts.span.y ) ), -Parts.seat, 0.F } ),
glm::vec3 { static_cast<float>( scale ), 1.F, 1.F } ) );
}
else if( between > 0.01 ) {
// the ends at their own size, and as many pieces between them as fit closest to their own size
put( part_end, 1.0, Parts.spans[ part_end ].x, -half );
put( part_begin, 1.0, Parts.spans[ part_begin ].y, half );
auto const pieces { std::max( 1, static_cast<int>( std::round( between / Lengths.piece ) ) ) };
auto const piece { between / pieces };
for( int index = 0; index < pieces; ++index ) {
put( part_main, piece / Lengths.piece, Parts.spans[ part_main ].x, -half + Lengths.end + index * piece );
}
}
else {
// a beam shorter than its ends: just the ends, squeezed
auto const scale { Length / std::max( 0.01, Lengths.begin + Lengths.end ) };
put( part_end, scale, Parts.spans[ part_end ].x, -half );
put( part_begin, scale, Parts.spans[ part_begin ].y, half );
}
}
// the fastenings of the rails lying on the timber, each square to its rail on the top of the timber, the plate under the foot of the
// rail; the rails around the track found at the first timber
void put_fastenings( TTrack &Track, beam_model const &Parts, beam const &Beam, glm::dvec3 const &Up, std::optional<fastened_rails> &Rails ) {
if( false == Rails.has_value() ) {
Rails.emplace( Track );
}
auto &laid { Track.m_sleepers3d };
for( auto const &fastening : Rails->on( Beam, Parts ) ) {
auto across { glm::dvec3 { fastening.across.x, 0.0, fastening.across.y } };
across = glm::normalize( across - Up * glm::dot( across, Up ) );
glm::mat4 frame { 1.f };
frame[ 0 ] = glm::vec4 { glm::vec3 { across }, 0.f };
frame[ 1 ] = glm::vec4 { glm::vec3 { Up }, 0.f };
frame[ 2 ] = glm::vec4 { glm::vec3 { glm::cross( across, Up ) }, 0.f };
frame[ 3 ] = glm::vec4 { glm::vec3 { fastening.point - Track.m_origin }, 1.f };
auto const pivot { glm::vec3 { fastening.pivot, Parts.heights[ fastening.part ].x, 0.f } };
laid.instances[ fastening.part ].emplace_back(
glm::translate( glm::scale( glm::translate( frame, glm::vec3 { fastening.shift, fastening.lift - Parts.seat, 0.f } + pivot ), glm::vec3 { fastening.scale, fastening.height, 1.f } ), -pivot ) );
}
}
// the beams as instances of the parts of the model of the track: those of the fastenings with them, or left for later and the beams
// kept for them meanwhile
void instance( TTrack &Track, std::vector<beam> &&Beams, bool const Fastened ) {
@@ -147,52 +265,27 @@ void instance( TTrack &Track, std::vector<beam> &&Beams, bool const Fastened ) {
}
// the sleepers of the model of the track itself (sleepermodel) at the height they're drawn at without the 3D sleepers: the
// origin of the model at the top of the rails, moved up by the sleeper shift, which the model was fitted to
auto const ownplains { laid.plains != nullptr && Track.m_sleeper_enabled && laid.plains != plain_model() };
auto const plainlift { ownplains ? Track.rail_height() + Track.m_sleeper_offset.z : 0.f };
std::optional<float> plainlift;
if( laid.plains != nullptr && Track.m_sleeper_enabled && laid.plains != plain_model() ) {
plainlift = Track.rail_height() + Track.m_sleeper_offset.z;
}
auto const &parts { *laid.timbers };
// the rails around, where they lie on the timbers, for the fastenings of the model; found at the first timber, none for plain sleepers
std::optional<fastened_rails> rails;
auto const partlength = [&]( int const Part ) {
auto const partlength = [ &parts ]( int const Part ) {
return static_cast<double>( parts.spans[ Part ].y - parts.spans[ Part ].x ); };
auto const beginlength { partlength( part_begin ) };
auto const mainlength { std::max( 0.01, partlength( part_main ) ) };
auto const endlength { partlength( part_end ) };
part_lengths const lengths {
.begin = partlength( part_begin ),
.piece = std::max( 0.01, partlength( part_main ) ),
.end = partlength( part_end ) };
chunk run;
std::vector<std::pair<glm::dvec3, double>> runbeams;
auto const close_run = [&]() {
if( runbeams.empty() ) {
return;
}
glm::dvec3 centre { 0.0 };
for( auto const &runbeam : runbeams ) {
centre += runbeam.first;
}
centre /= static_cast<double>( runbeams.size() );
auto radius { 0.0 };
for( auto const &runbeam : runbeams ) {
radius = std::max( radius, glm::length( runbeam.first - centre ) + runbeam.second );
}
run.centre = glm::vec3 { centre };
run.radius = static_cast<float>( radius + 0.3 );
for( int part = 0; part < part_count; ++part ) {
run.last[ part ] = static_cast<std::uint32_t>( laid.instances[ part ].size() );
}
run.wholelast = static_cast<std::uint32_t>( laid.whole.size() );
run.plainlast = static_cast<std::uint32_t>( laid.plain.size() );
laid.chunks.push_back( run );
runbeams.clear();
};
for( auto const &beam : Beams ) {
if( runbeams.empty() ) {
for( int part = 0; part < part_count; ++part ) {
run.first[ part ] = static_cast<std::uint32_t>( laid.instances[ part ].size() );
}
run.wholefirst = static_cast<std::uint32_t>( laid.whole.size() );
run.plainfirst = static_cast<std::uint32_t>( laid.plain.size() );
open_run( laid, run );
}
auto const length { glm::length( beam.to - beam.from ) };
if( length < 0.1 ) {
@@ -212,70 +305,16 @@ void instance( TTrack &Track, std::vector<beam> &&Beams, bool const Fastened ) {
frame[ 1 ] = glm::vec4 { glm::vec3 { y }, 0.f };
frame[ 2 ] = glm::vec4 { glm::vec3 { z }, 0.f };
frame[ 3 ] = glm::vec4 { glm::vec3 { middle }, 1.f };
// a part stretched along x by the scale, and moved so its x lands at the given place along the beam
auto const put = [&]( int const Part, double const Scale, double const From, double const Place ) {
auto const shift { Place - Scale * From };
laid.instances[ Part ].emplace_back(
glm::scale(
glm::translate( frame, glm::vec3 { static_cast<float>( shift ), -parts.seat, 0.f } ),
glm::vec3 { static_cast<float>( Scale ), 1.f, 1.f } ) );
};
auto const half { 0.5 * length };
auto const between { length - beginlength - endlength };
if( beam.plain && laid.plains != nullptr ) {
// the whole sleeper at its own length, its middle under the middle of the track
auto const &plain { *laid.plains };
laid.plain.emplace_back(
glm::translate( frame, glm::vec3 { -0.5f * ( plain.span.x + plain.span.y ), ( ownplains ? plainlift : -plain.seat ), 0.f } ) );
}
else if( false == parts.stretchable ) {
// a timber of a model which can't be put together, the whole of it stretched to the length
auto const scale { length / static_cast<double>( parts.length() ) };
laid.whole.emplace_back(
glm::scale(
glm::translate( frame, glm::vec3 { static_cast<float>( -scale * 0.5 * ( parts.span.x + parts.span.y ) ), -parts.seat, 0.f } ),
glm::vec3 { static_cast<float>( scale ), 1.f, 1.f } ) );
}
else if( between > 0.01 ) {
// the ends at their own size, and as many pieces between them as fit closest to their own size
put( part_end, 1.0, parts.spans[ part_end ].x, -half );
put( part_begin, 1.0, parts.spans[ part_begin ].y, half );
auto const pieces { std::max( 1, static_cast<int>( std::round( between / mainlength ) ) ) };
auto const piece { between / pieces };
for( int index = 0; index < pieces; ++index ) {
put( part_main, piece / mainlength, parts.spans[ part_main ].x, -half + endlength + index * piece );
}
}
else {
// a beam shorter than its ends: just the ends, squeezed
auto const scale { length / std::max( 0.01, beginlength + endlength ) };
put( part_end, scale, parts.spans[ part_end ].x, -half );
put( part_begin, scale, parts.spans[ part_begin ].y, half );
}
put_beam( laid, parts, beam, frame, length, lengths, plainlift );
if( Fastened && parts.fastened() && false == ( beam.plain && laid.plains != nullptr ) ) {
if( false == rails.has_value() ) {
rails.emplace( Track );
}
// each square to its rail on the top of the timber, the plate under the foot of the rail
for( auto const &fastening : rails->on( beam, parts ) ) {
auto across { glm::dvec3 { fastening.across.x, 0.0, fastening.across.y } };
across = glm::normalize( across - y * glm::dot( across, y ) );
glm::mat4 place { 1.f };
place[ 0 ] = glm::vec4 { glm::vec3 { across }, 0.f };
place[ 1 ] = glm::vec4 { glm::vec3 { y }, 0.f };
place[ 2 ] = glm::vec4 { glm::vec3 { glm::cross( across, y ) }, 0.f };
place[ 3 ] = glm::vec4 { glm::vec3 { fastening.point - Track.m_origin }, 1.f };
auto const pivot { glm::vec3 { fastening.pivot, parts.heights[ fastening.part ].x, 0.f } };
laid.instances[ fastening.part ].emplace_back(
glm::translate( glm::scale( glm::translate( place, glm::vec3 { fastening.shift, fastening.lift - parts.seat, 0.f } + pivot ), glm::vec3 { fastening.scale, fastening.height, 1.f } ), -pivot ) );
}
put_fastenings( Track, parts, beam, y, rails );
}
runbeams.emplace_back( middle, half );
runbeams.emplace_back( middle, 0.5 * length );
if( runbeams.size() >= chunk_beams ) {
close_run();
close_run( laid, run, runbeams );
}
}
close_run();
close_run( laid, run, runbeams );
// kept for as long as the track is near, without the room the vectors grew into
for( auto &instances : laid.instances ) {
instances.shrink_to_fit();
@@ -311,10 +350,10 @@ void lay( TTrack &Track, bool const Fastened ) {
instance( Track, {}, true );
return;
}
if( auto const panel { panel_off_plane( Track ) }; panel.first > coplanar_tolerance ) {
WriteLog(
"sleepers3d: switch \"" + Track.name() + "\" has its paths " + to_string( panel.first * 1000.0, 1 ) + " mm off one plane "
+ to_string( panel.second, 2 ) + " m along, where they share the timbers of its panel" );
if( auto const [ off, at ] { panel_off_plane( Track ) }; off > coplanar_tolerance ) {
WriteLog( std::format(
"sleepers3d: switch \"{}\" has its paths {} mm off one plane {} m along, where they share the timbers of its panel",
Track.name(), to_string( off * 1000.0, 1 ), to_string( at, 2 ) ) );
}
laid.laying = true;
auto beams { in_background() ? std::move( placed ) : place( Track ) };
@@ -359,7 +398,7 @@ void release_far( glm::dvec3 const &Camera, double const Range ) {
auto &laid { track->m_sleepers3d };
forget_layout( *track );
auto const holds { laid.chunks.capacity() > 0 || laid.whole.capacity() > 0 || laid.plain.capacity() > 0 || laid.beams.capacity() > 0
|| std::any_of( laid.instances.begin(), laid.instances.end(), []( std::vector<glm::mat4> const &Instances ) { return Instances.capacity() > 0; } ) };
|| std::ranges::any_of( laid.instances, []( std::vector<glm::mat4> const &Instances ) { return Instances.capacity() > 0; } ) };
if( false == holds ) {
continue;
}
@@ -374,47 +413,136 @@ void release_far( glm::dvec3 const &Camera, double const Range ) {
}
}
namespace {
// the digest of where the beams lie taken on by the beam: its ends, which way it lies and whether it's a plain sleeper
void digest_beam( std::uint64_t &Digest, beam const &Beam ) {
for( auto const &vector : { Beam.from, Beam.to, Beam.along } ) {
for( int axis = 0; axis < 3; ++axis ) {
Digest = ( Digest ^ static_cast<std::uint64_t>( std::llround( vector[ axis ] * 1e4 ) ) ) * 1099511628211ULL;
}
}
Digest = ( Digest ^ ( Beam.plain ? 1U : 2U ) ) * 1099511628211ULL;
}
// the beams of the track placed anew, as boxes in plan with the track they're laid with, counted into what's wrong with the layout
void box_beams( TTrack const &Track, std::vector<beam_box> &Boxes, std::vector<TTrack const *> &Owners, layout_check &Result ) {
if( auto const [ off, at ] { panel_off_plane( Track ) }; off > coplanar_tolerance ) {
++Result.panels;
if( Result.panels <= 4 ) {
Result.examples.push_back( std::format( "switch {} {} mm off one plane at {} m", Track.name(), to_string( off * 1000.0, 1 ), to_string( at, 2 ) ) );
}
}
for( auto const &beam : place( Track ) ) {
digest_beam( Result.digest, beam );
auto const span { plan( beam.to - beam.from ) };
auto const length { glm::length( span ) };
if( length < 0.1 ) {
continue;
}
Boxes.push_back( box_of( beam ) );
Owners.push_back( &Track );
Result.longest = std::max( Result.longest, length );
if( length > length_cap ) {
++Result.toolong;
}
}
}
// the beams of a cell of the grid which lie over each other, each pair of them counted once
void find_overlaps( std::vector<std::size_t> const &Indices, std::vector<beam_box> const &Boxes, std::vector<TTrack const *> const &Owners, std::set<std::pair<std::size_t, std::size_t>> &Overlaps, layout_check &Result ) {
for( std::size_t one = 0; one < Indices.size(); ++one ) {
for( std::size_t other = one + 1; other < Indices.size(); ++other ) {
auto const pair { std::minmax( Indices[ one ], Indices[ other ] ) };
if( Overlaps.contains( pair ) || apart( Boxes[ pair.first ], Boxes[ pair.second ] ) ) {
continue;
}
Overlaps.insert( pair );
if( Overlaps.size() <= 16 ) {
auto const &box { Boxes[ pair.first ] };
Result.examples.push_back( std::format(
"overlap {}/{} at {} {}", Owners[ pair.first ]->name(), Owners[ pair.second ]->name(), to_string( box.centre.x, 2 ), to_string( box.centre.y, 2 ) ) );
}
}
}
}
// the spacing of the beams under a rail at the distance along the path, kept where it's the widest, counted where it's too wide
void note_spacing( TTrack const &Track, int const Path, double const Spacing, double const Distance, layout_check &Result ) {
if( Spacing > Result.widest ) {
Result.widest = Spacing;
Result.widestat = std::format( "{} {}", Track.name(), to_string( Distance, 2 ) );
}
if( Spacing > 1.25 * 1.08 * pitch ) {
++Result.gaps;
if( Result.examples.size() < 24 ) {
Result.examples.push_back( std::format( "gap {} m under {} path {} at {}", to_string( Spacing, 2 ), Track.name(), Path, to_string( Distance, 2 ) ) );
}
}
}
// the rails of the path of the track followed for how far apart the beams under them are
void follow_rails( TTrack const &Track, int const Path, TSegment const &Segment, plan_grid<std::size_t> const &Grid, std::vector<beam_box> const &Boxes, layout_check &Result ) {
auto const length { Segment.GetLength() };
auto const steps { static_cast<int>( std::ceil( length / 0.05 ) ) };
for( auto const side : { -1.0, 1.0 } ) {
// from the first beam under the rail to the last, how long it runs with none under it
auto last { -1.0 };
auto first { -1.0 };
for( int step = 0; step <= steps; ++step ) {
auto const distance { length * step / std::max( 1, steps ) };
glm::dvec3 point;
glm::dvec3 across;
Segment.plan_frame( distance, point, across );
auto const rail { plan( point + across * ( side * 0.5 * std::abs( Track.fTrackWidth ) ) ) };
if( auto const *cell { Grid.at( rail ) };
cell == nullptr || std::ranges::none_of( *cell, [ &Boxes, &rail ]( std::size_t const Index ) { return holds( Boxes[ Index ], rail ); } ) ) {
continue;
}
if( last >= 0.0 && distance - last > 0.06 ) {
// the spacing of the beams, middle to middle, by the stretch without one
auto const spacing { distance - last + 2.0 * half_width };
note_spacing( Track, Path, spacing, distance, Result );
}
if( first < 0.0 ) {
first = distance;
}
last = distance;
}
if( first < 0.0 ) {
++Result.bare;
if( Result.examples.size() < 80 ) {
Result.examples.push_back( std::format( "no beams under {} path {}", Track.name(), Path ) );
}
}
}
}
} // namespace
layout_check check() {
layout_check result;
result.digest = 1469598103934665603ull;
result.digest = 1469598103934665603ULL;
settle_background();
faults() = {};
faults().reset();
// laid anew, for the counts of what's wrong with them
outdate_layouts();
// the beams of all the tracks in plan, as boxes, with the grid of where they are
std::vector<beam_box> boxes;
std::vector<TTrack const *> owners;
std::vector<TTrack *> tracks;
for( auto *track : simulation::Paths.sequence() ) {
std::vector<TTrack const *> tracks;
for( auto const *track : simulation::Paths.sequence() ) {
if( track == nullptr || track->m_editorremoved || false == track->m_sleepers3d.active ) {
continue;
}
tracks.push_back( track );
if( auto const panel { panel_off_plane( *track ) }; panel.first > coplanar_tolerance ) {
++result.panels;
if( result.panels <= 4 ) result.examples.push_back(
"switch " + track->name() + " " + to_string( panel.first * 1000.0, 1 ) + " mm off one plane at " + to_string( panel.second, 2 ) + " m" );
}
for( auto const &beam : place( *track ) ) {
for( auto const &vector : { beam.from, beam.to, beam.along } ) {
for( int axis = 0; axis < 3; ++axis ) {
result.digest = ( result.digest ^ static_cast<std::uint64_t>( std::llround( vector[ axis ] * 1e4 ) ) ) * 1099511628211ull;
}
}
result.digest = ( result.digest ^ ( beam.plain ? 1u : 2u ) ) * 1099511628211ull;
auto const span { plan( beam.to - beam.from ) };
auto const length { glm::length( span ) };
if( length < 0.1 ) {
continue;
}
boxes.push_back( box_of( beam ) );
owners.push_back( track );
result.longest = std::max( result.longest, length );
if( length > length_cap ) {
++result.toolong;
}
}
box_beams( *track, boxes, owners, result );
}
result.beams = boxes.size();
result.offplane = faults().offplane;
@@ -428,79 +556,29 @@ layout_check check() {
grid.insert( boxes[ index ].centre, boxes[ index ].half + half_width, index );
}
std::set<std::pair<std::size_t, std::size_t>> overlaps;
for( auto const &cell : grid.cells() ) {
auto const &indices { cell.second };
for( std::size_t left = 0; left < indices.size(); ++left ) {
for( std::size_t right = left + 1; right < indices.size(); ++right ) {
auto const pair { std::minmax( indices[ left ], indices[ right ] ) };
if( overlaps.count( pair ) || apart( boxes[ pair.first ], boxes[ pair.second ] ) ) {
continue;
}
overlaps.insert( pair );
if( overlaps.size() <= 16 ) {
auto const &box { boxes[ pair.first ] };
result.examples.push_back(
"overlap " + owners[ pair.first ]->name() + "/" + owners[ pair.second ]->name() + " at " + to_string( box.centre.x, 2 ) + " " + to_string( box.centre.y, 2 ) );
}
}
}
for( auto const &[ coordinates, indices ] : grid.cells() ) {
find_overlaps( indices, boxes, owners, overlaps, result );
}
result.overlaps = overlaps.size();
// the rails of the tracks, followed for how far apart the beams under them are
for( auto *track : tracks ) {
for( auto const *track : tracks ) {
for( int path = 0; path < path_count( *track ); ++path ) {
auto const *segment { path_segment( *track, path ) };
if( segment == nullptr ) {
continue;
}
auto const length { segment->GetLength() };
auto const steps { static_cast<int>( std::ceil( length / 0.05 ) ) };
for( auto const side : { -1.0, 1.0 } ) {
// from the first beam under the rail to the last, how long it runs with none under it
auto last { -1.0 };
auto first { -1.0 };
for( int step = 0; step <= steps; ++step ) {
auto const distance { length * step / std::max( 1, steps ) };
glm::dvec3 point, across;
segment->plan_frame( distance, point, across );
auto const rail { plan( point + across * ( side * 0.5 * std::abs( track->fTrackWidth ) ) ) };
auto const *cell { grid.at( rail ) };
if( cell == nullptr || std::none_of( cell->begin(), cell->end(), [&]( std::size_t const Index ) { return holds( boxes[ Index ], rail ); } ) ) {
continue;
}
if( last >= 0.0 && distance - last > 0.06 ) {
// the spacing of the beams, middle to middle, by the stretch without one
auto const spacing { distance - last + 2.0 * half_width };
if( spacing > result.widest ) {
result.widest = spacing;
result.widestat = track->name() + " " + to_string( distance, 2 );
}
if( spacing > 1.25 * 1.08 * pitch ) {
++result.gaps;
if( result.examples.size() < 24 ) {
result.examples.push_back( "gap " + to_string( spacing, 2 ) + " m under " + track->name() + " path " + std::to_string( path ) + " at " + to_string( distance, 2 ) );
}
}
}
if( first < 0.0 ) {
first = distance;
}
last = distance;
}
if( first < 0.0 ) {
++result.bare;
if( result.examples.size() < 80 ) {
result.examples.push_back( "no beams under " + track->name() + " path " + std::to_string( path ) );
}
}
}
follow_rails( *track, path, *segment, grid, boxes, result );
}
}
return result;
}
void unsettle_around( TTrack &Track ) {
void unsettle_around( TTrack const &Track ) {
if( GfxRenderer == nullptr || false == GfxRenderer->Draws_Timbers() ) {
// nothing laid, nothing to lay again; without sleepers3d in eu07.ini the tracks with a timbermodel of their own lay still
return;
}
outdate_layouts();
tracks_near( Track, []( TTrack *Other ) {
if( Other->m_sleepers3d.active ) {