17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-08 02:58:37 +01:00

refactor: the Sonar remarks on the material copies taken care of

- the params of a shader named by the type the shader keeps them in
- ranges::any_of and erase_if, with explicit captures
- the weathering set component by component with an index of the
  type of the vector
- the lookups declared in the ifs that use them
- the empty Erase of the base renderer told why it is empty
This commit is contained in:
maj00r
2026-11-06 19:58:24 +01:00
parent 48af69cbf1
commit d232cd0a69
2 changed files with 29 additions and 26 deletions

View File

@@ -684,17 +684,20 @@ variant_of( opengl_material const &Source, std::string const &Suffix ) {
return variant;
}
// the params of a shader, as the shader keeps them
using param_confs = decltype( gl::shader::param_conf );
// whether another param of the shader lies on a component of the named one, which a value set for that one would change too
bool
shares_slot( std::unordered_map<std::string, gl::shader::param_entry> const &Conf, std::string const &Name ) {
shares_slot( param_confs const &Conf, std::string const &Name ) {
auto const own { Conf.find( Name ) };
if( own == Conf.end() ) {
return false;
}
return std::any_of(
std::begin( Conf ), std::end( Conf ),
[&]( auto const &Entry ) {
return std::ranges::any_of(
Conf,
[ &Name, &own ]( auto const &Entry ) {
return Entry.first != Name
&& Entry.second.location == own->second.location
&& Entry.second.offset < own->second.offset + own->second.size
@@ -715,15 +718,16 @@ make_matte( opengl_material &Variant ) {
|| shares_slot( Variant.shader->param_conf, key ) ) {
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 ) ];
auto &slot { Variant.params[ entry->second.location ] };
auto const offset { static_cast<glm::length_t>( entry->second.offset ) };
auto const size { static_cast<glm::length_t>( entry->second.size ) };
for( glm::length_t i = 0; i < size; ++i ) {
slot[ offset + i ] = value[ i ];
}
Variant.params_state.erase(
std::remove_if(
std::begin( Variant.params_state ), std::end( Variant.params_state ),
[&]( gl::shader::param_entry const &State ) {
return State.location == entry->second.location && State.offset == entry->second.offset; } ),
std::end( Variant.params_state ) );
std::erase_if(
Variant.params_state,
[ &entry ]( gl::shader::param_entry const &State ) {
return State.location == entry->second.location && State.offset == entry->second.offset; } );
}
}
@@ -737,26 +741,24 @@ make_tinted( opengl_material &Variant, glm::vec3 const &Colour ) {
}
auto const &conf { Variant.shader->param_conf };
auto const weathering { conf.find( "weathering" ) };
auto const tint { conf.find( "tint" ) };
if( weathering == conf.end()
if( auto const tint { conf.find( "tint" ) };
weathering == conf.end()
|| tint == conf.end()
|| weathering->second.offset != 3
|| tint->second.location != weathering->second.location
|| tint->second.offset != 0
|| std::any_of(
std::begin( conf ), std::end( conf ),
[&]( auto const &Entry ) {
|| std::ranges::any_of(
conf,
[ &weathering, &tint ]( auto const &Entry ) {
return Entry.first != weathering->first && Entry.first != tint->first && Entry.second.location == weathering->second.location; } ) ) {
return false;
}
auto const location { weathering->second.location };
Variant.params[ location ] = glm::vec4{ Colour, -1.f };
Variant.params_state.erase(
std::remove_if(
std::begin( Variant.params_state ), std::end( Variant.params_state ),
[&]( gl::shader::param_entry const &State ) {
return State.location == location; } ),
std::end( Variant.params_state ) );
std::erase_if(
Variant.params_state,
[ location ]( gl::shader::param_entry const &State ) {
return State.location == location; } );
return true;
}
@@ -768,8 +770,7 @@ 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" ) };

View File

@@ -60,7 +60,9 @@ public:
// adds supplied vertex data at the end of specified chunk
virtual auto Append(gfx::vertex_array &Vertices, gfx::userdata_array &Userdata, gfx::geometry_handle const &Geometry, int const Type) -> bool = 0;
// empties specified chunk, its handle stays valid to be filled again
virtual void Erase( gfx::geometry_handle const &Geometry ) {}
virtual void Erase( gfx::geometry_handle const & /*Geometry*/ ) {
// a renderer which keeps no chunks of its own has none to empty
}
// provides direct access to index data of specfied chunk
virtual auto Indices( gfx::geometry_handle const &Geometry ) const->gfx::index_array const & = 0;
// provides direct access to vertex data of specfied chunk