fix: optimization: PVS-Studio warning V813

Passing large objects by const reference avoids unnecessary copying and enhances efficiency.

Reported by: PVS-Studio
Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
Vyacheslav Ivanov
2024-08-02 05:35:55 +03:00
committed by Pugemon
parent 5b325ac2bc
commit 2c1103307f
42 changed files with 173 additions and 144 deletions
+8 -5
View File
@@ -35,7 +35,7 @@ struct DecomposedMat4 {
glm::vec4 perspective;
};
static glm::mat4 extract_rotation(glm::mat4 matrix) {
static glm::mat4 extract_rotation(const glm::mat4& matrix) {
DecomposedMat4 decomposed = {};
glm::quat rotation;
glm::decompose(
@@ -66,8 +66,10 @@ ModelBatch::ModelBatch(size_t capacity, Assets* assets, Chunks* chunks)
ModelBatch::~ModelBatch() = default;
void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix,
const glm::mat3& rotation, glm::vec3 tint,
void ModelBatch::draw(const model::Mesh& mesh,
const glm::mat4& matrix,
const glm::mat3& rotation,
const glm::vec3& tint,
const texture_names_map* varTextures) {
glm::vec3 gpos = matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
light_t light = chunks->getLight(floor(gpos.x), floor(gpos.y), floor(gpos.z));
@@ -94,8 +96,9 @@ void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix,
}
}
void ModelBatch::draw(glm::mat4 matrix,
glm::vec3 tint,
void ModelBatch::draw(
const glm::mat4& matrix,
const glm::vec3& tint,
const model::Model* model,
const texture_names_map* varTextures) {
for (const auto& mesh : model->meshes) {
+9 -5
View File
@@ -37,7 +37,10 @@ class ModelBatch {
static inline glm::vec3 SUN_VECTOR {0.411934f, 0.863868f, -0.279161f};
inline void vertex(
glm::vec3 pos, glm::vec2 uv, glm::vec4 light, glm::vec3 tint
const glm::vec3& pos,
const glm::vec2& uv,
const glm::vec4& light,
const glm::vec3& tint
) {
float* buffer = this->buffer.get();
buffer[index++] = pos.x;
@@ -64,8 +67,8 @@ class ModelBatch {
void draw(const model::Mesh& mesh,
const glm::mat4& matrix,
const glm::mat3& rotation,
glm::vec3 tint,
const glm::mat3& rotation,
const glm::vec3& tint,
const texture_names_map* varTextures);
void setTexture(const std::string& name,
const texture_names_map* varTextures);
@@ -84,8 +87,9 @@ public:
ModelBatch(size_t capacity, Assets* assets, Chunks* chunks);
~ModelBatch();
void draw(glm::mat4 matrix,
glm::vec3 tint,
void draw(
const glm::mat4& matrix,
const glm::vec3& tint,
const model::Model* model,
const texture_names_map* varTextures);
void render();
+5 -3
View File
@@ -230,10 +230,12 @@ void WorldRenderer::renderBlockSelection() {
: block->hitboxes;
lineBatch->lineWidth(2.0f);
constexpr auto boxOffset = glm::vec3(0.02);
constexpr auto boxColor = glm::vec4(0.f, 0.f, 0.f, 0.5f);
for (auto& hitbox: hitboxes) {
const glm::vec3 center = glm::vec3(pos) + hitbox.center();
const glm::vec3 size = hitbox.size();
lineBatch->box(center, size + glm::vec3(0.02), glm::vec4(0.f, 0.f, 0.f, 0.5f));
lineBatch->box(center, size + boxOffset, boxColor);
if (player->debug) {
lineBatch->line(point, point+norm*0.5f, glm::vec4(1.0f, 0.0f, 1.0f, 1.0f));
}
@@ -340,12 +342,12 @@ void WorldRenderer::draw(
ctx.setDepthTest(true);
ctx.setCullFace(true);
renderLevel(ctx, camera, settings, delta, pause);
// Debug lines
if (hudVisible){
renderLines(camera, linesShader, ctx);
}
}
// Debug lines
if (hudVisible && player->debug) {
renderDebugLines(wctx, camera, linesShader);
}