fix: optimization: PVS-Studio warning V821
Creating variables in a more localized scope can enhance performance and make the code easier to understand. Reported by: PVS-Studio Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
parent
e9a5f18bc3
commit
6b3146f98a
@ -406,9 +406,9 @@ void Hud::add(const HudElement& element) {
|
||||
using namespace dynamic;
|
||||
|
||||
gui->add(element.getNode());
|
||||
auto invview = std::dynamic_pointer_cast<InventoryView>(element.getNode());
|
||||
auto document = element.getDocument();
|
||||
if (document) {
|
||||
auto invview = std::dynamic_pointer_cast<InventoryView>(element.getNode());
|
||||
auto inventory = invview ? invview->getInventory() : nullptr;
|
||||
std::vector<Value> args;
|
||||
args.emplace_back(inventory ? inventory.get()->getId() : 0);
|
||||
|
||||
@ -243,13 +243,13 @@ void WorldRenderer::renderBlockSelection() {
|
||||
void WorldRenderer::renderLines(
|
||||
Camera* camera, Shader* linesShader, const DrawContext& pctx
|
||||
) {
|
||||
auto ctx = pctx.sub(lineBatch.get());
|
||||
linesShader->use();
|
||||
linesShader->uniformMatrix("u_projview", camera->getProjView());
|
||||
if (player->selection.vox.id != BLOCK_VOID) {
|
||||
renderBlockSelection();
|
||||
}
|
||||
if (player->debug && showEntitiesDebug) {
|
||||
auto ctx = pctx.sub(lineBatch.get());
|
||||
level->entities->renderDebug(*lineBatch, *frustumCulling, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@ -324,8 +324,6 @@ static int l_gui_getattr(lua::State* L) {
|
||||
auto docname = lua::require_string(L, 1);
|
||||
auto element = lua::require_string(L, 2);
|
||||
auto attr = lua::require_string(L, 3);
|
||||
auto docnode = getDocumentNode(L, docname, element);
|
||||
auto node = docnode.node;
|
||||
|
||||
static const std::unordered_map<std::string_view, std::function<int(UINode*,lua::State*)>> getters {
|
||||
{"color", p_get_color},
|
||||
@ -367,6 +365,8 @@ static int l_gui_getattr(lua::State* L) {
|
||||
};
|
||||
auto func = getters.find(attr);
|
||||
if (func != getters.end()) {
|
||||
auto docnode = getDocumentNode(L, docname, element);
|
||||
auto node = docnode.node;
|
||||
return func->second(node.get(), L);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@ -240,8 +240,8 @@ void scripting::on_block_placed(Player* player, const Block* block, int x, int y
|
||||
}
|
||||
|
||||
void scripting::on_block_broken(Player* player, const Block* block, int x, int y, int z) {
|
||||
std::string name = block->name + ".broken";
|
||||
if (block->rt.funcsset.onbroken) {
|
||||
std::string name = block->name + ".broken";
|
||||
lua::emit_event(lua::get_main_thread(), name, [x, y, z, player] (auto L) {
|
||||
lua::pushivec3_stack(L, x, y, z);
|
||||
lua::pushinteger(L, player ? player->getId() : -1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user