fix: optimization: PVS-Studio warning V807

Created references to avoid using repeated expressions, improving performance across multiple instances.

Reported by: PVS-Studio
Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
Vyacheslav Ivanov 2024-08-02 06:07:50 +03:00 committed by MihailRis
parent 52905ff27b
commit c858913a2f
4 changed files with 18 additions and 14 deletions

View File

@ -176,9 +176,10 @@ void ContentLoader::loadBlock(Block& def, const std::string& name, const fs::pat
def.hitboxes.resize(boxarr->size());
for (uint i = 0; i < boxarr->size(); i++) {
auto box = boxarr->list(i);
def.hitboxes[i].a = glm::vec3(box->num(0), box->num(1), box->num(2));
def.hitboxes[i].b = glm::vec3(box->num(3), box->num(4), box->num(5));
def.hitboxes[i].b += def.hitboxes[i].a;
auto& hitboxesIndex = def.hitboxes[i];
hitboxesIndex.a = glm::vec3(box->num(0), box->num(1), box->num(2));
hitboxesIndex.b = glm::vec3(box->num(3), box->num(4), box->num(5));
hitboxesIndex.b += hitboxesIndex.a;
}
} else if ((boxarr = root->list("hitbox"))){
AABB aabb;

View File

@ -73,11 +73,12 @@ std::shared_ptr<Task> WorldConverter::startTask(
[=](){return std::make_shared<ConverterWorker>(converter);},
[=](int&) {}
);
while (!converter->tasks.empty()) {
const convert_task& task = converter->tasks.front();
auto& converterTasks = converter->tasks;
while (!converterTasks.empty()) {
const convert_task& task = converterTasks.front();
auto ptr = std::make_shared<convert_task>(task);
pool->enqueueJob(ptr);
converter->tasks.pop();
converterTasks.pop();
}
pool->setOnComplete([=]() {
converter->write();

View File

@ -113,21 +113,22 @@ bool ChunksController::buildLights(const std::shared_ptr<Chunk>& chunk) {
void ChunksController::createChunk(int x, int z) {
auto chunk = level->chunksStorage->create(x, z);
chunks->putChunk(chunk);
auto& chunkFlags = chunk->flags;
if (!chunk->flags.loaded) {
if (!chunkFlags.loaded) {
generator->generate(
chunk->voxels, x, z,
level->getWorld()->getSeed()
);
chunk->flags.unsaved = true;
chunkFlags.unsaved = true;
}
chunk->updateHeights();
if (!chunk->flags.loadedLights) {
if (!chunkFlags.loadedLights) {
Lighting::prebuildSkyLight(
chunk.get(), level->content->getIndices()
);
}
chunk->flags.loaded = true;
chunk->flags.ready = true;
chunkFlags.loaded = true;
chunkFlags.ready = true;
}

View File

@ -47,11 +47,12 @@ void LevelController::update(float delta, bool input, bool pause) {
player->postUpdate(delta, input, pause);
// erease null pointers
level->objects.erase(
auto& objects = level->objects;
objects.erase(
std::remove_if(
level->objects.begin(), level->objects.end(),
objects.begin(), objects.end(),
[](auto obj) { return obj == nullptr; }),
level->objects.end()
objects.end()
);
}