mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-08 18:50:34 +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:
@@ -684,17 +684,20 @@ variant_of( opengl_material const &Source, std::string const &Suffix ) {
|
|||||||
return variant;
|
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
|
// 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
|
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 ) };
|
auto const own { Conf.find( Name ) };
|
||||||
if( own == Conf.end() ) {
|
if( own == Conf.end() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return std::any_of(
|
return std::ranges::any_of(
|
||||||
std::begin( Conf ), std::end( Conf ),
|
Conf,
|
||||||
[&]( auto const &Entry ) {
|
[ &Name, &own ]( auto const &Entry ) {
|
||||||
return Entry.first != Name
|
return Entry.first != Name
|
||||||
&& Entry.second.location == own->second.location
|
&& Entry.second.location == own->second.location
|
||||||
&& Entry.second.offset < own->second.offset + own->second.size
|
&& 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 ) ) {
|
|| shares_slot( Variant.shader->param_conf, key ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for( std::size_t i = 0; i < entry->second.size; ++i ) {
|
auto &slot { Variant.params[ entry->second.location ] };
|
||||||
Variant.params[ entry->second.location ][ entry->second.offset + i ] = value[ static_cast<glm::length_t>( i ) ];
|
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::erase_if(
|
||||||
std::remove_if(
|
Variant.params_state,
|
||||||
std::begin( Variant.params_state ), std::end( Variant.params_state ),
|
[ &entry ]( gl::shader::param_entry const &State ) {
|
||||||
[&]( gl::shader::param_entry const &State ) {
|
return State.location == entry->second.location && State.offset == entry->second.offset; } );
|
||||||
return State.location == entry->second.location && State.offset == entry->second.offset; } ),
|
|
||||||
std::end( Variant.params_state ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -737,26 +741,24 @@ make_tinted( opengl_material &Variant, glm::vec3 const &Colour ) {
|
|||||||
}
|
}
|
||||||
auto const &conf { Variant.shader->param_conf };
|
auto const &conf { Variant.shader->param_conf };
|
||||||
auto const weathering { conf.find( "weathering" ) };
|
auto const weathering { conf.find( "weathering" ) };
|
||||||
auto const tint { conf.find( "tint" ) };
|
if( auto const tint { conf.find( "tint" ) };
|
||||||
if( weathering == conf.end()
|
weathering == conf.end()
|
||||||
|| tint == conf.end()
|
|| tint == conf.end()
|
||||||
|| weathering->second.offset != 3
|
|| weathering->second.offset != 3
|
||||||
|| tint->second.location != weathering->second.location
|
|| tint->second.location != weathering->second.location
|
||||||
|| tint->second.offset != 0
|
|| tint->second.offset != 0
|
||||||
|| std::any_of(
|
|| std::ranges::any_of(
|
||||||
std::begin( conf ), std::end( conf ),
|
conf,
|
||||||
[&]( auto const &Entry ) {
|
[ &weathering, &tint ]( auto const &Entry ) {
|
||||||
return Entry.first != weathering->first && Entry.first != tint->first && Entry.second.location == weathering->second.location; } ) ) {
|
return Entry.first != weathering->first && Entry.first != tint->first && Entry.second.location == weathering->second.location; } ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto const location { weathering->second.location };
|
auto const location { weathering->second.location };
|
||||||
Variant.params[ location ] = glm::vec4{ Colour, -1.f };
|
Variant.params[ location ] = glm::vec4{ Colour, -1.f };
|
||||||
Variant.params_state.erase(
|
std::erase_if(
|
||||||
std::remove_if(
|
Variant.params_state,
|
||||||
std::begin( Variant.params_state ), std::end( Variant.params_state ),
|
[ location ]( gl::shader::param_entry const &State ) {
|
||||||
[&]( gl::shader::param_entry const &State ) {
|
return State.location == location; } );
|
||||||
return State.location == location; } ),
|
|
||||||
std::end( Variant.params_state ) );
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -768,8 +770,7 @@ material_manager::create_matte( material_handle const Material ) {
|
|||||||
if( Material == null_handle || Material >= m_materials.size() ) {
|
if( Material == null_handle || Material >= m_materials.size() ) {
|
||||||
return Material;
|
return Material;
|
||||||
}
|
}
|
||||||
auto const lookup { m_mattes.find( Material ) };
|
if( auto const lookup { m_mattes.find( Material ) }; lookup != m_mattes.end() ) {
|
||||||
if( lookup != m_mattes.end() ) {
|
|
||||||
return lookup->second;
|
return lookup->second;
|
||||||
}
|
}
|
||||||
auto matte { variant_of( m_materials[ Material ], ":matte" ) };
|
auto matte { variant_of( m_materials[ Material ], ":matte" ) };
|
||||||
|
|||||||
@@ -60,7 +60,9 @@ public:
|
|||||||
// adds supplied vertex data at the end of specified chunk
|
// 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;
|
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
|
// 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
|
// provides direct access to index data of specfied chunk
|
||||||
virtual auto Indices( gfx::geometry_handle const &Geometry ) const->gfx::index_array const & = 0;
|
virtual auto Indices( gfx::geometry_handle const &Geometry ) const->gfx::index_array const & = 0;
|
||||||
// provides direct access to vertex data of specfied chunk
|
// provides direct access to vertex data of specfied chunk
|
||||||
|
|||||||
Reference in New Issue
Block a user