mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-28 14:37:29 +01:00
feat(editor): ballast and rails blending lengths apart, as sliders
This commit is contained in:
@@ -701,16 +701,21 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin)
|
||||
m_timber_model_name = modelpath;
|
||||
m_timber_skin_name = ( skinpath == "none" ? std::string{} : skinpath );
|
||||
}
|
||||
else if( str == "blend" ) {
|
||||
// blend <end> <length>: how far from the end 1 (p1), 2 (p2) or 3 (p4 of a switch) the rails and the ballast blend into those
|
||||
// of the track joined there, where their textures differ; 0: not at all
|
||||
else if( str == "blendrails" || str == "blendballast" || str == "blend" ) {
|
||||
// blendrails/blendballast <end> <length>: how far from the end 1 (p1), 2 (p2) or 3 (p4 of a switch) the rails or the ballast
|
||||
// blend into those of the track joined there, where their textures differ; 0: not at all. blend: both of them
|
||||
auto const end { parser->getToken<int>() };
|
||||
auto const length { parser->getToken<double>() };
|
||||
if( end >= 1 && end <= static_cast<int>( m_blend.size() ) ) {
|
||||
m_blend[ end - 1 ] = static_cast<float>( std::max( 0.0, length ) );
|
||||
auto const length { static_cast<float>( std::max( 0.0, parser->getToken<double>() ) ) };
|
||||
if( end >= 1 && end <= static_cast<int>( m_blend[ 0 ].size() ) ) {
|
||||
if( str != "blendballast" ) {
|
||||
m_blend[ static_cast<int>( track_blend::kind::rails ) ][ end - 1 ] = length;
|
||||
}
|
||||
if( str != "blendrails" ) {
|
||||
m_blend[ static_cast<int>( track_blend::kind::ballast ) ][ end - 1 ] = length;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ErrorLog( "Bad track: blend at end " + std::to_string( end ) + " of track \"" + m_name + "\" which has no such end" );
|
||||
ErrorLog( "Bad track: " + str + " at end " + std::to_string( end ) + " of track \"" + m_name + "\" which has no such end" );
|
||||
}
|
||||
}
|
||||
else if( str == "friction" ) {
|
||||
@@ -2748,9 +2753,12 @@ TTrack::export_as_text_( std::ostream &Output ) const {
|
||||
<< m_timber_model_name << ' '
|
||||
<< ( m_timber_skin_name.empty() ? std::string{ "none" } : m_timber_skin_name ) << ' ';
|
||||
}
|
||||
for( std::size_t end = 0; end < m_blend.size(); ++end ) {
|
||||
if( m_blend[ end ] != track_blend::default_length ) {
|
||||
Output << "blend " << end + 1 << ' ' << m_blend[ end ] << ' ';
|
||||
for( auto const kind : { track_blend::kind::rails, track_blend::kind::ballast } ) {
|
||||
auto const &lengths { m_blend[ static_cast<int>( kind ) ] };
|
||||
for( std::size_t end = 0; end < lengths.size(); ++end ) {
|
||||
if( lengths[ end ] != track_blend::default_length ) {
|
||||
Output << ( kind == track_blend::kind::rails ? "blendrails " : "blendballast " ) << end + 1 << ' ' << lengths[ end ] << ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
// footer
|
||||
|
||||
@@ -238,8 +238,11 @@ public:
|
||||
// timbermodel <model> <skin>
|
||||
std::string m_timber_model_name;
|
||||
std::string m_timber_skin_name; // replacable skin, empty for the textures of the model
|
||||
// how far from its ends p1, p2 (and p4 of a switch) the rails and the ballast blend into those of the tracks joined there (blend)
|
||||
std::array<float, 3> m_blend { track_blend::default_length, track_blend::default_length, track_blend::default_length };
|
||||
// how far from its ends p1, p2 (and p4 of a switch) the rails and the ballast blend into those of the tracks joined there
|
||||
// (blendrails, blendballast), by the kind (track_blend::kind)
|
||||
std::array<std::array<float, 3>, 2> m_blend { {
|
||||
{ track_blend::default_length, track_blend::default_length, track_blend::default_length },
|
||||
{ track_blend::default_length, track_blend::default_length, track_blend::default_length } } };
|
||||
// the materials the blending is drawn with, null where nothing's blended: the rails of a plain track, its ballast, the trackbed of a switch
|
||||
material_handle m_blendmaterial1 { null_handle };
|
||||
material_handle m_blendmaterial2 { null_handle };
|
||||
|
||||
@@ -150,7 +150,7 @@ bool blends( TTrack const &Track, kind const Kind, int const End, TTrack const *
|
||||
if( Kind == kind::rails && Track.eType != tt_Normal ) {
|
||||
return false;
|
||||
}
|
||||
if( Track.m_blend[ End ] <= 0.f ) {
|
||||
if( Track.m_blend[ static_cast<int>( Kind ) ][ End ] <= 0.f ) {
|
||||
return false;
|
||||
}
|
||||
auto const own { material_of( Track, Kind, End ) };
|
||||
@@ -219,7 +219,7 @@ blending setup( TTrack const &Track, kind const Kind ) {
|
||||
auto &blend { result.ends[ end ] };
|
||||
end_frame( Track, end, blend.point, blend.inward );
|
||||
blend.point -= Track.m_origin;
|
||||
blend.length = Track.m_blend[ end ];
|
||||
blend.length = Track.m_blend[ static_cast<int>( Kind ) ][ end ];
|
||||
// where both tracks blend they meet half way at the joint, otherwise this one goes all the way to the other one there
|
||||
blend.peak = ( blends( *other, Kind, otherend ) ? 0.5f : 1.f );
|
||||
blend.active = true;
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace track_blend {
|
||||
// how far from an end the textures blend, by default
|
||||
float constexpr default_length { 3.f };
|
||||
|
||||
// the order of the lengths of TTrack::m_blend
|
||||
enum class kind {
|
||||
rails,
|
||||
ballast
|
||||
|
||||
Reference in New Issue
Block a user