mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 05:57:08 +01:00
Merge MaSzyna-EU07/maszyna master into feat/vat-people
master as of 9fecba82: the test mode (--test, null renderer), the AI braking
and passenger stops, the ESt3 brake, the SOD lamp, the 401Da oil pump lamp,
smoke of vehicles taken off the tracks, text displays with national
characters, the scenario picker drag and drop, the log written to the end of
the closing, unit and scenario tests, and the small fixes.
How the conflicts went:
- the OpenGL 3.3 and legacy renderers stay removed; what master changed in
them is carried over where this branch has a counterpart: the opaque
characters of text displays in scene_walk::Render_text(). The instancing
range of master is covered by the instance records of this branch, the
sizes of the sun and the moon are its own.
- test mode: the null backend picked in select_gfx_backend(), the window
hidden, no crash gui; settings of the removed renderers left out.
- materials: the matte and tinted copies of this branch (the tint in the
slot of the weathering), made again on a change of the season or the
weather (update_variants), before the track blends.
- tracks: this branch's Segment, Track and TrackUneven, with master's
replaced_shake(), uneven_underway(), rail_joints_moved(),
switch_followers() and the editor's add_followers(); tributary and unknown
track types stay as this branch loads them.
- the log service stops by StopLogService(), the exit paths of EU07.cpp too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GXgG7F4L42c2F9sDSAJbT2
This commit is contained in:
+83
-38
@@ -16,6 +16,8 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "utilities/Logs.h"
|
||||
#include "scene/sn_utils.h"
|
||||
#include "utilities/Globals.h"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
opengl_material::path_data opengl_material::paths;
|
||||
|
||||
@@ -683,6 +685,57 @@ variant_of( opengl_material const &Source, std::string const &Suffix ) {
|
||||
return variant;
|
||||
}
|
||||
|
||||
// the highlights of a copy of a material damped and its weathering on
|
||||
void
|
||||
make_matte( opengl_material &Variant ) {
|
||||
|
||||
Variant.glossiness = 0.1f;
|
||||
if( !Variant.shader ) {
|
||||
return;
|
||||
}
|
||||
for( auto const &[ key, value ] : std::vector<std::pair<std::string, glm::vec4>>{ { "weathering", glm::vec4{ 1.f } } } ) {
|
||||
auto const entry { Variant.shader->param_conf.find( key ) };
|
||||
if( entry == Variant.shader->param_conf.end() ) {
|
||||
continue;
|
||||
}
|
||||
for( std::size_t i = 0; i < entry->second.size; ++i ) {
|
||||
Variant.params[ entry->second.location ][ entry->second.offset + i ] = value[ static_cast<glm::length_t>( i ) ];
|
||||
}
|
||||
std::erase_if(
|
||||
Variant.params_state,
|
||||
[ &entry ]( gfx::shader_param_entry const &State ) {
|
||||
return State.location == entry->second.location && State.offset == entry->second.offset; } );
|
||||
}
|
||||
}
|
||||
|
||||
// the colour in the rgb of the slot of the weathering of a copy of a material, which tells the shader to tint by its sign. returns:
|
||||
// whether the shader can tint it, the weathering alone in that slot
|
||||
bool
|
||||
make_tinted( opengl_material &Variant, glm::vec3 const &Colour, float const Glossiness ) {
|
||||
|
||||
if( !Variant.shader ) {
|
||||
return false;
|
||||
}
|
||||
auto const &conf { Variant.shader->param_conf };
|
||||
auto const weathering { conf.find( "weathering" ) };
|
||||
if( weathering == conf.end()
|
||||
|| weathering->second.offset != 3
|
||||
|| std::ranges::any_of(
|
||||
conf,
|
||||
[ &weathering ]( auto const &Entry ) {
|
||||
return Entry.first != weathering->first && Entry.second.location == weathering->second.location; } ) ) {
|
||||
return false;
|
||||
}
|
||||
Variant.glossiness = Glossiness;
|
||||
auto const location { weathering->second.location };
|
||||
Variant.params[ location ] = glm::vec4{ Colour, -1.f };
|
||||
std::erase_if(
|
||||
Variant.params_state,
|
||||
[ location ]( gfx::shader_param_entry const &State ) {
|
||||
return State.location == location; } );
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
material_handle
|
||||
@@ -691,29 +744,11 @@ material_manager::create_matte( material_handle const Material ) {
|
||||
if( Material == null_handle || Material >= m_materials.size() ) {
|
||||
return Material;
|
||||
}
|
||||
auto const lookup { m_mattes.find( Material ) };
|
||||
if( lookup != m_mattes.end() ) {
|
||||
if( auto const lookup { m_mattes.find( Material ) }; lookup != m_mattes.end() ) {
|
||||
return lookup->second;
|
||||
}
|
||||
auto matte { variant_of( m_materials[ Material ], ":matte" ) };
|
||||
matte.glossiness = 0.1f;
|
||||
if( matte.shader ) {
|
||||
for( auto const &[ key, value ] : std::vector<std::pair<std::string, glm::vec4>>{ { "weathering", glm::vec4{ 1.f } } } ) {
|
||||
auto const entry { matte.shader->param_conf.find( key ) };
|
||||
if( entry == matte.shader->param_conf.end() ) {
|
||||
continue;
|
||||
}
|
||||
for( std::size_t i = 0; i < entry->second.size; ++i ) {
|
||||
matte.params[ entry->second.location ][ entry->second.offset + i ] = value[ static_cast<glm::length_t>( i ) ];
|
||||
}
|
||||
matte.params_state.erase(
|
||||
std::remove_if(
|
||||
std::begin( matte.params_state ), std::end( matte.params_state ),
|
||||
[&]( gfx::shader_param_entry const &State ) {
|
||||
return State.location == entry->second.location && State.offset == entry->second.offset; } ),
|
||||
std::end( matte.params_state ) );
|
||||
}
|
||||
}
|
||||
make_matte( matte );
|
||||
auto const mattehandle { static_cast<material_handle>( m_materials.size() ) };
|
||||
m_materials.emplace_back( std::move( matte ) );
|
||||
m_mattes.emplace( Material, mattehandle );
|
||||
@@ -730,32 +765,40 @@ material_manager::create_tinted( material_handle const Material, glm::vec3 const
|
||||
if( auto const lookup { m_tints.find( key ) }; lookup != m_tints.end() ) {
|
||||
return lookup->second;
|
||||
}
|
||||
auto const &conf { m_materials[ Material ].shader->param_conf };
|
||||
auto const weathering { conf.find( "weathering" ) };
|
||||
if( weathering == conf.end()
|
||||
|| weathering->second.offset != 3
|
||||
|| std::any_of(
|
||||
std::begin( conf ), std::end( conf ),
|
||||
[&]( auto const &Entry ) {
|
||||
return Entry.first != weathering->first && Entry.second.location == weathering->second.location; } ) ) {
|
||||
auto tinted { variant_of( m_materials[ Material ], ":tinted" ) };
|
||||
if( false == make_tinted( tinted, Colour, m_materials[ Material ].glossiness ) ) {
|
||||
return Material;
|
||||
}
|
||||
auto tinted { variant_of( m_materials[ Material ], ":tinted" ) };
|
||||
tinted.glossiness = m_materials[ Material ].glossiness;
|
||||
auto const location { weathering->second.location };
|
||||
tinted.params[ location ] = glm::vec4{ Colour, -1.f };
|
||||
tinted.params_state.erase(
|
||||
std::remove_if(
|
||||
std::begin( tinted.params_state ), std::end( tinted.params_state ),
|
||||
[&]( gfx::shader_param_entry const &State ) {
|
||||
return State.location == location; } ),
|
||||
std::end( tinted.params_state ) );
|
||||
auto const tintedhandle { static_cast<material_handle>( m_materials.size() ) };
|
||||
m_materials.emplace_back( std::move( tinted ) );
|
||||
m_tints.emplace( key, tintedhandle );
|
||||
return tintedhandle;
|
||||
}
|
||||
|
||||
void
|
||||
material_manager::update_variants( bool const Weather ) {
|
||||
|
||||
// the copies don't update themselves, their names aren't files to read again
|
||||
auto const changed = [ this, Weather ]( material_handle const Source ) {
|
||||
auto const &source { m_materials[ Source ] };
|
||||
return Weather ? source.update_on_weather_change : source.update_on_season_change; };
|
||||
for( auto const &[ source, matte ] : m_mattes ) {
|
||||
if( changed( source ) ) {
|
||||
auto variant { variant_of( m_materials[ source ], ":matte" ) };
|
||||
make_matte( variant );
|
||||
m_materials[ matte ] = std::move( variant );
|
||||
}
|
||||
}
|
||||
for( auto const &[ key, tinted ] : m_tints ) {
|
||||
auto const source { std::get<0>( key ) };
|
||||
if( changed( source ) ) {
|
||||
auto variant { variant_of( m_materials[ source ], ":tinted" ) };
|
||||
make_tinted( variant, glm::vec3 { std::get<1>( key ), std::get<2>( key ), std::get<3>( key ) }, m_materials[ source ].glossiness );
|
||||
m_materials[ tinted ] = std::move( variant );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// the shaders a material is lit by which the blending shaders can light the same way, by the names they're fetched by, in the
|
||||
@@ -967,6 +1010,7 @@ material_manager::on_weather_change() {
|
||||
for( auto &material : m_materials ) {
|
||||
if( material.update_on_weather_change ) { material.update(); }
|
||||
}
|
||||
update_variants( true );
|
||||
rebuild_blends();
|
||||
}
|
||||
|
||||
@@ -976,6 +1020,7 @@ material_manager::on_season_change() {
|
||||
for( auto &material : m_materials ) {
|
||||
if( material.update_on_season_change ) { material.update(); }
|
||||
}
|
||||
update_variants( false );
|
||||
rebuild_blends();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user