17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-18 18:29:40 +02:00

fix(sonar): addressing reliability/security issues

This commit is contained in:
jerrrrycho
2026-10-03 20:21:28 +02:00
parent 51521a135a
commit d88fa5d8e2
32 changed files with 189 additions and 162 deletions

View File

@@ -22,30 +22,14 @@ cFrustum::calculate() {
void
cFrustum::calculate( glm::mat4 const &Projection, glm::mat4 const &Modelview ) {
float const *proj = glm::value_ptr( Projection );
float const *modl = glm::value_ptr( Modelview );
// multiply the matrices to retrieve clipping planes (column-major, same layout as the old float[16] form)
auto const clipmatrix { Projection * Modelview };
float clip[ 16 ];
// multiply the matrices to retrieve clipping planes
clip[ 0 ] = modl[ 0 ] * proj[ 0 ] + modl[ 1 ] * proj[ 4 ] + modl[ 2 ] * proj[ 8 ] + modl[ 3 ] * proj[ 12 ];
clip[ 1 ] = modl[ 0 ] * proj[ 1 ] + modl[ 1 ] * proj[ 5 ] + modl[ 2 ] * proj[ 9 ] + modl[ 3 ] * proj[ 13 ];
clip[ 2 ] = modl[ 0 ] * proj[ 2 ] + modl[ 1 ] * proj[ 6 ] + modl[ 2 ] * proj[ 10 ] + modl[ 3 ] * proj[ 14 ];
clip[ 3 ] = modl[ 0 ] * proj[ 3 ] + modl[ 1 ] * proj[ 7 ] + modl[ 2 ] * proj[ 11 ] + modl[ 3 ] * proj[ 15 ];
clip[ 4 ] = modl[ 4 ] * proj[ 0 ] + modl[ 5 ] * proj[ 4 ] + modl[ 6 ] * proj[ 8 ] + modl[ 7 ] * proj[ 12 ];
clip[ 5 ] = modl[ 4 ] * proj[ 1 ] + modl[ 5 ] * proj[ 5 ] + modl[ 6 ] * proj[ 9 ] + modl[ 7 ] * proj[ 13 ];
clip[ 6 ] = modl[ 4 ] * proj[ 2 ] + modl[ 5 ] * proj[ 6 ] + modl[ 6 ] * proj[ 10 ] + modl[ 7 ] * proj[ 14 ];
clip[ 7 ] = modl[ 4 ] * proj[ 3 ] + modl[ 5 ] * proj[ 7 ] + modl[ 6 ] * proj[ 11 ] + modl[ 7 ] * proj[ 15 ];
clip[ 8 ] = modl[ 8 ] * proj[ 0 ] + modl[ 9 ] * proj[ 4 ] + modl[ 10 ] * proj[ 8 ] + modl[ 11 ] * proj[ 12 ];
clip[ 9 ] = modl[ 8 ] * proj[ 1 ] + modl[ 9 ] * proj[ 5 ] + modl[ 10 ] * proj[ 9 ] + modl[ 11 ] * proj[ 13 ];
clip[ 10 ] = modl[ 8 ] * proj[ 2 ] + modl[ 9 ] * proj[ 6 ] + modl[ 10 ] * proj[ 10 ] + modl[ 11 ] * proj[ 14 ];
clip[ 11 ] = modl[ 8 ] * proj[ 3 ] + modl[ 9 ] * proj[ 7 ] + modl[ 10 ] * proj[ 11 ] + modl[ 11 ] * proj[ 15 ];
clip[ 12 ] = modl[ 12 ] * proj[ 0 ] + modl[ 13 ] * proj[ 4 ] + modl[ 14 ] * proj[ 8 ] + modl[ 15 ] * proj[ 12 ];
clip[ 13 ] = modl[ 12 ] * proj[ 1 ] + modl[ 13 ] * proj[ 5 ] + modl[ 14 ] * proj[ 9 ] + modl[ 15 ] * proj[ 13 ];
clip[ 14 ] = modl[ 12 ] * proj[ 2 ] + modl[ 13 ] * proj[ 6 ] + modl[ 14 ] * proj[ 10 ] + modl[ 15 ] * proj[ 14 ];
clip[ 15 ] = modl[ 12 ] * proj[ 3 ] + modl[ 13 ] * proj[ 7 ] + modl[ 14 ] * proj[ 11 ] + modl[ 15 ] * proj[ 15 ];
for( int column = 0; column < 4; ++column ) {
for( int row = 0; row < 4; ++row ) {
clip[ column * 4 + row ] = clipmatrix[ column ][ row ];
}
}
// get the sides of the frustum.
m_frustum[ side_RIGHT ][ plane_A ] = clip[ 3 ] - clip[ 0 ];

View File

@@ -18,7 +18,7 @@ public:
int index{ -1 }; // 0: front lights, 1: rear lights
glm::dvec3 position; // position of the light in 3d scene
glm::vec3 direction; // direction of the light in 3d scene
glm::vec3 color{ 255.0f / 255.0f, 241.0f / 255.0f, 224.0f / 255.0f }; // color of the light, default is halogen light
glm::vec3 color{ 1.0f, 241.0f / 255.0f, 224.0f / 255.0f }; // color of the light, default is halogen light
float intensity{ 0.0f }; // (combined) intensity of the light(s)
int count{ 0 }; // number (or pattern) of active light(s)
glm::vec3 state{ 0.f }; // state of individual lights

View File

@@ -28,6 +28,23 @@ http://mozilla.org/MPL/2.0/.
int constexpr EU07_PICKBUFFERSIZE{ 1024 }; // size of (square) textures bound with the pick framebuffer
int constexpr EU07_REFLECTIONFIDELITYOFFSET { 250 }; // artificial increase of range for reflection pass detail reduction
namespace {
// returns material assigned to the submodel, resolving replacable skins. null_handle if no skin set is bound
material_handle
submodel_material( TSubModel const *Submodel ) {
if( Submodel->m_material >= 0 ) {
return Submodel->m_material;
}
return (
TSubModel::ReplacableSkinId != nullptr ?
TSubModel::ReplacableSkinId[ -Submodel->m_material ] :
null_handle );
}
} // namespace
void GLAPIENTRY
ErrorCallback( GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam ) {
/*
@@ -1935,7 +1952,7 @@ bool opengl33_renderer::Render(world_environment *Environment)
auto const fogfactor{std::clamp(Global.fFogEnd / 2000.f, 0.f, 1.f)}; // stronger fog reduces opacity of the celestial bodies
float const duskfactor = 1.0f - std::clamp(std::abs(Environment->m_sun.getAngle()), 0.0f, 12.0f) / 12.0f;
glm::vec3 suncolor = glm::mix(glm::vec3(255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f), glm::vec3(235.0f / 255.0f, 140.0f / 255.0f, 36.0f / 255.0f), duskfactor);
glm::vec3 suncolor = glm::mix(glm::vec3(1.0f, 242.0f / 255.0f, 231.0f / 255.0f), glm::vec3(235.0f / 255.0f, 140.0f / 255.0f, 36.0f / 255.0f), duskfactor);
// sun
{
@@ -2341,8 +2358,7 @@ opengl_material &opengl33_renderer::Material(material_handle const Material)
opengl_material const & opengl33_renderer::Material( TSubModel const * Submodel ) const {
auto const material { Submodel->m_material >= 0 ? Submodel->m_material : Submodel->ReplacableSkinId[ -Submodel->m_material ] };
return m_materials.material( material );
return m_materials.material( submodel_material( Submodel ) );
}
texture_handle opengl33_renderer::Fetch_Texture(std::string const &Filename, bool const Loadnow, GLint format_hint)
@@ -3767,7 +3783,7 @@ void opengl33_renderer::Render(TSubModel *Submodel)
// textures...
if (Submodel->m_material < 0)
{ // zmienialne skóry
Bind_Material(Submodel->ReplacableSkinId[-Submodel->m_material], Submodel);
Bind_Material(submodel_material(Submodel), Submodel);
}
else
{
@@ -3804,7 +3820,7 @@ void opengl33_renderer::Render(TSubModel *Submodel)
if (Submodel->m_material < 0)
{ // zmienialne skóry
Bind_Material_Shadow(Submodel->ReplacableSkinId[-Submodel->m_material]);
Bind_Material_Shadow(submodel_material(Submodel));
}
else
{
@@ -4689,7 +4705,7 @@ void opengl33_renderer::Render_Alpha(TSubModel *Submodel)
// textures...
if (Submodel->m_material < 0)
{ // zmienialne skóry
Bind_Material(Submodel->ReplacableSkinId[-Submodel->m_material], Submodel);
Bind_Material(submodel_material(Submodel), Submodel);
}
else
{
@@ -4721,7 +4737,7 @@ void opengl33_renderer::Render_Alpha(TSubModel *Submodel)
if (Submodel->m_material < 0)
{ // zmienialne skóry
Bind_Material_Shadow(Submodel->ReplacableSkinId[-Submodel->m_material]);
Bind_Material_Shadow(submodel_material(Submodel));
}
else
{

View File

@@ -1588,7 +1588,7 @@ opengl_renderer::Render( world_environment *Environment ) {
auto const fogfactor { std::clamp( Global.fFogEnd / 2000.f, 0.f, 1.f ) }; // closer/denser fog reduces opacity of the celestial bodies
float const duskfactor = 1.0f - std::clamp( std::abs( Environment->m_sun.getAngle() ), 0.0f, 12.0f ) / 12.0f;
glm::vec3 suncolor = glm::mix(
glm::vec3( 255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f ),
glm::vec3( 1.0f, 242.0f / 255.0f, 231.0f / 255.0f ),
glm::vec3( 235.0f / 255.0f, 140.0f / 255.0f, 36.0f / 255.0f ),
duskfactor );
// sun

View File

@@ -31,7 +31,7 @@ basic_precipitation::init() {
void
basic_precipitation::update() {
auto const timedelta { static_cast<float>( ( DebugModeFlag ? Timer::GetDeltaTime() : Timer::GetDeltaTime() ) ) };
auto const timedelta { static_cast<float>( Timer::GetDeltaTime() ) };
if( timedelta == 0.0 ) { return; }