refactor: PVS-Studio warnings fixes

This commit is contained in:
MihailRis
2024-08-04 01:12:42 +03:00
parent 7bc96affbb
commit 245b39be62
22 changed files with 311 additions and 302 deletions
+23 -21
View File
@@ -208,8 +208,10 @@ void PlayerController::onFootstep(const Hitbox& hitbox) {
int z = std::floor(pos.z + half.z * offsetZ);
auto vox = level->chunks->get(x, y, z);
if (vox) {
auto def = level->content->getIndices()->blocks.get(vox->id); //FIXME: Potentional null pointer
if (!def->obstacle) continue; //-V522
auto& def = level->content->getIndices()->blocks.require(vox->id);
if (!def.obstacle) {
continue;
}
blocksController->onBlockInteraction(
player.get(),
glm::ivec3(x, y, z),
@@ -299,7 +301,7 @@ void PlayerController::updatePlayer(float delta) {
}
static int determine_rotation(
Block* def, const glm::ivec3& norm, glm::vec3& camDir
const Block* def, const glm::ivec3& norm, glm::vec3& camDir
) {
if (def && def->rotatable) {
const std::string& name = def->rotations.name;
@@ -396,7 +398,7 @@ voxel* PlayerController::updateSelection(float maxDistance) {
selection.vox = *vox;
if (selectedState.segment) {
selection.position = chunks->seekOrigin(
iend, indices->blocks.get(selection.vox.id), selectedState
iend, indices->blocks.require(selection.vox.id), selectedState
);
auto origin = chunks->get(selection.position);
if (origin && origin->id != vox->id) {
@@ -411,15 +413,15 @@ voxel* PlayerController::updateSelection(float maxDistance) {
return vox;
}
void PlayerController::processRightClick(Block* def, Block* target) {
void PlayerController::processRightClick(const Block& def, const Block& target) {
const auto& selection = player->selection;
auto chunks = level->chunks.get();
auto camera = player->camera.get();
blockstate state {};
state.rotation = determine_rotation(def, selection.normal, camera->dir);
state.rotation = determine_rotation(&def, selection.normal, camera->dir);
if (!input.shift && target->rt.funcsset.oninteract) {
if (!input.shift && target.rt.funcsset.oninteract) {
if (scripting::on_block_interact(
player.get(), target, selection.position
)) {
@@ -427,17 +429,17 @@ void PlayerController::processRightClick(Block* def, Block* target) {
}
}
auto coord = selection.actualPosition;
if (!target->replaceable) {
if (!target.replaceable) {
coord += selection.normal;
} else if (def->rotations.name == BlockRotProfile::PIPE_NAME) {
} else if (def.rotations.name == BlockRotProfile::PIPE_NAME) {
state.rotation = BLOCK_DIR_UP;
}
blockid_t chosenBlock = def->rt.id;
blockid_t chosenBlock = def.rt.id;
AABB blockAABB(coord, coord + 1);
bool blocked = level->entities->hasBlockingInside(blockAABB);
if (def->obstacle && blocked) {
if (def.obstacle && blocked) {
return;
}
auto vox = chunks->get(coord);
@@ -447,7 +449,7 @@ void PlayerController::processRightClick(Block* def, Block* target) {
if (!chunks->checkReplaceability(def, state, coord)) {
return;
}
if (def->grounded) {
if (def.grounded) {
const auto& vec = get_ground_direction(def, state.rotation);
if (!chunks->isSolidBlock(
coord.x + vec.x, coord.y + vec.y, coord.z + vec.z
@@ -492,11 +494,11 @@ void PlayerController::updateInteraction() {
auto inventory = player->getInventory();
const ItemStack& stack = inventory->getSlot(player->getChosenSlot());
ItemDef* item = indices->items.get(stack.getItemId()); //FIXME: Potentional null pointer
auto& item = indices->items.require(stack.getItemId());
auto vox = updateSelection(maxDistance);
if (vox == nullptr) {
if (rclick && item->rt.funcsset.on_use) { //-V522
if (rclick && item.rt.funcsset.on_use) {
scripting::on_item_use(player.get(), item);
}
if (selection.entity) {
@@ -506,35 +508,35 @@ void PlayerController::updateInteraction() {
}
auto iend = selection.position;
if (lclick && !input.shift && item->rt.funcsset.on_block_break_by) {
if (lclick && !input.shift && item.rt.funcsset.on_block_break_by) {
if (scripting::on_item_break_block(
player.get(), item, iend.x, iend.y, iend.z
)) {
return;
}
}
auto target = indices->blocks.get(vox->id); //FIXME: Potentional null pointer
if (lclick && target->breakable) { //-V522
auto& target = indices->blocks.require(vox->id);
if (lclick && target.breakable) {
blocksController->breakBlock(
player.get(), target, iend.x, iend.y, iend.z
);
}
if (rclick && !input.shift) {
bool preventDefault = false;
if (item->rt.funcsset.on_use_on_block) {
if (item.rt.funcsset.on_use_on_block) {
preventDefault = scripting::on_item_use_on_block(
player.get(), item, iend, selection.normal
);
} else if (item->rt.funcsset.on_use) {
} else if (item.rt.funcsset.on_use) {
preventDefault = scripting::on_item_use(player.get(), item);
}
if (preventDefault) {
return;
}
}
auto def = indices->blocks.get(item->rt.placingBlock);
auto def = indices->blocks.get(item.rt.placingBlock);
if (def && rclick) {
processRightClick(def, target);
processRightClick(*def, target);
}
if (Events::jactive(BIND_PLAYER_PICK)) {
auto coord = selection.actualPosition;