Revert "fix: optimization: Various PVS-Studio warnings"
This commit is contained in:
@@ -30,7 +30,8 @@ ChunksController::ChunksController(Level* level, uint padding)
|
||||
generator(WorldGenerators::createGenerator(level->getWorld()->getGenerator(), level->content)) {
|
||||
}
|
||||
|
||||
ChunksController::~ChunksController() = default;
|
||||
ChunksController::~ChunksController(){
|
||||
}
|
||||
|
||||
void ChunksController::update(int64_t maxDuration) {
|
||||
int64_t mcstotal = 0;
|
||||
@@ -112,22 +113,21 @@ 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 (!chunkFlags.loaded) {
|
||||
if (!chunk->flags.loaded) {
|
||||
generator->generate(
|
||||
chunk->voxels, x, z,
|
||||
level->getWorld()->getSeed()
|
||||
);
|
||||
chunkFlags.unsaved = true;
|
||||
chunk->flags.unsaved = true;
|
||||
}
|
||||
chunk->updateHeights();
|
||||
|
||||
if (!chunkFlags.loadedLights) {
|
||||
if (!chunk->flags.loadedLights) {
|
||||
Lighting::prebuildSkyLight(
|
||||
chunk.get(), level->content->getIndices()
|
||||
);
|
||||
}
|
||||
chunkFlags.loaded = true;
|
||||
chunkFlags.ready = true;
|
||||
chunk->flags.loaded = true;
|
||||
chunk->flags.ready = true;
|
||||
}
|
||||
|
||||
@@ -255,8 +255,8 @@ public:
|
||||
}
|
||||
|
||||
dynamic::Value applyRelative(
|
||||
Argument* arg,
|
||||
const dynamic::Value& value,
|
||||
Argument* arg,
|
||||
dynamic::Value value,
|
||||
const dynamic::Value& origin
|
||||
) {
|
||||
if (origin.index() == 0) {
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace cmd {
|
||||
std::string description;
|
||||
executor_func executor;
|
||||
public:
|
||||
Command() = default;
|
||||
Command() {}
|
||||
|
||||
Command(
|
||||
std::string name,
|
||||
|
||||
@@ -47,12 +47,11 @@ void LevelController::update(float delta, bool input, bool pause) {
|
||||
player->postUpdate(delta, input, pause);
|
||||
|
||||
// erease null pointers
|
||||
auto& objects = level->objects;
|
||||
objects.erase(
|
||||
level->objects.erase(
|
||||
std::remove_if(
|
||||
objects.begin(), objects.end(),
|
||||
level->objects.begin(), level->objects.end(),
|
||||
[](auto obj) { return obj == nullptr; }),
|
||||
objects.end()
|
||||
level->objects.end()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ glm::vec3 CameraControl::updateCameraShaking(const Hitbox& hitbox, float delta)
|
||||
}
|
||||
|
||||
void CameraControl::updateFovEffects(const Hitbox& hitbox,
|
||||
PlayerInput input, float delta) {
|
||||
const PlayerInput& input, float delta) {
|
||||
bool crouch = input.shift && hitbox.grounded && !input.sprint;
|
||||
|
||||
float dt = fmin(1.0f, delta * ZOOM_SPEED);
|
||||
@@ -146,7 +146,7 @@ void CameraControl::switchCamera() {
|
||||
}
|
||||
}
|
||||
|
||||
void CameraControl::update(PlayerInput input, float delta, Chunks* chunks) {
|
||||
void CameraControl::update(const PlayerInput& input, float delta, Chunks* chunks) {
|
||||
offset = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
if (auto hitbox = player->getHitbox()) {
|
||||
@@ -455,7 +455,7 @@ void PlayerController::updateEntityInteraction(entityid_t eid, bool lclick, bool
|
||||
if (!entityOpt.has_value()) {
|
||||
return;
|
||||
}
|
||||
auto entity = *entityOpt;
|
||||
auto entity = entityOpt.value();
|
||||
if (lclick) {
|
||||
scripting::on_attacked(entity, player.get(), player->getEntity());
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class CameraControl {
|
||||
/// @brief Update field-of-view effects
|
||||
/// @param input player inputs
|
||||
/// @param delta delta time
|
||||
void updateFovEffects(const Hitbox& hitbox, PlayerInput input,
|
||||
void updateFovEffects(const Hitbox& hitbox, const PlayerInput& input,
|
||||
float delta);
|
||||
|
||||
/// @brief Switch active player camera
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
CameraControl(const std::shared_ptr<Player>& player,
|
||||
const CameraSettings& settings);
|
||||
void updateMouse(PlayerInput& input);
|
||||
void update(PlayerInput input, float delta, Chunks* chunks);
|
||||
void update(const PlayerInput& input, float delta, Chunks* chunks);
|
||||
void refresh();
|
||||
};
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ static int l_get_command_info(lua::State* L) {
|
||||
|
||||
lua::createtable(L, args.size(), 0);
|
||||
for (size_t i = 0; i < args.size(); i++) {
|
||||
auto& arg = args[i];
|
||||
auto& arg = args.at(i);
|
||||
lua::createtable(L, 0, 2);
|
||||
|
||||
lua::pushstring(L, arg.name);
|
||||
|
||||
@@ -324,6 +324,8 @@ 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},
|
||||
@@ -365,8 +367,6 @@ 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;
|
||||
|
||||
@@ -95,7 +95,7 @@ static int l_pack_get_info(lua::State* L, const ContentPack& pack, const Content
|
||||
if (!pack.dependencies.empty()) {
|
||||
lua::createtable(L, pack.dependencies.size(), 0);
|
||||
for (size_t i = 0; i < pack.dependencies.size(); i++) {
|
||||
auto& dpack = pack.dependencies[i];
|
||||
auto& dpack = pack.dependencies.at(i);
|
||||
std::string prefix;
|
||||
switch (dpack.level) {
|
||||
case DependencyLevel::required: prefix = "!"; break;
|
||||
@@ -142,7 +142,7 @@ static int l_pack_get_info(lua::State* L) {
|
||||
manager.scan();
|
||||
auto vec = manager.getAll({packid});
|
||||
if (!vec.empty()) {
|
||||
return l_pack_get_info(L, vec[0], content);
|
||||
return l_pack_get_info(L, vec.at(0), content);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -151,20 +151,20 @@ namespace lua {
|
||||
return 3;
|
||||
}
|
||||
|
||||
inline int pushivec3_stack(lua::State* L, const glm::ivec3 &vec) {
|
||||
inline int pushivec3_stack(lua::State* L, glm::ivec3 vec) {
|
||||
pushinteger(L, vec.x);
|
||||
pushinteger(L, vec.y);
|
||||
pushinteger(L, vec.z);
|
||||
return 3;
|
||||
}
|
||||
|
||||
inline int pushvec3_stack(lua::State* L, const glm::vec3 &vec) {
|
||||
inline int pushvec3_stack(lua::State* L, glm::vec3 vec) {
|
||||
pushnumber(L, vec.x);
|
||||
pushnumber(L, vec.y);
|
||||
pushnumber(L, vec.z);
|
||||
return 3;
|
||||
}
|
||||
inline int pushvec4_stack(lua::State* L, const glm::vec4 &vec) {
|
||||
inline int pushvec4_stack(lua::State* L, glm::vec4 vec) {
|
||||
pushnumber(L, vec.x);
|
||||
pushnumber(L, vec.y);
|
||||
pushnumber(L, vec.z);
|
||||
@@ -179,15 +179,15 @@ namespace lua {
|
||||
lua_pushvalue(L, idx);
|
||||
return 1;
|
||||
}
|
||||
inline int pushvec2(lua::State* L, const glm::vec2 &vec) {
|
||||
inline int pushvec2(lua::State* L, glm::vec2 vec) {
|
||||
return pushvec(L, vec);
|
||||
}
|
||||
|
||||
inline int pushvec3(lua::State* L, const glm::vec3 &vec) {
|
||||
inline int pushvec3(lua::State* L, glm::vec3 vec) {
|
||||
return pushvec(L, vec);
|
||||
}
|
||||
|
||||
inline int pushvec4(lua::State* L, const glm::vec4 &vec) {
|
||||
inline int pushvec4(lua::State* L, glm::vec4 vec) {
|
||||
return pushvec(L, vec);
|
||||
}
|
||||
inline int pushcolor(lua::State* L, glm::vec4 vec) {
|
||||
@@ -210,7 +210,7 @@ namespace lua {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
inline int pushmat4(lua::State* L, const glm::mat4 &matrix) {
|
||||
inline int pushmat4(lua::State* L, glm::mat4 matrix) {
|
||||
createtable(L, 16, 0);
|
||||
for (uint y = 0; y < 4; y++) {
|
||||
for (uint x = 0; x < 4; x++) {
|
||||
@@ -222,7 +222,7 @@ namespace lua {
|
||||
return 1;
|
||||
}
|
||||
/// @brief pushes matrix table to the stack and updates it with glm matrix
|
||||
inline int setmat4(lua::State* L, int idx, const glm::mat4 &matrix) {
|
||||
inline int setmat4(lua::State* L, int idx, glm::mat4 matrix) {
|
||||
pushvalue(L, idx);
|
||||
for (uint y = 0; y < 4; y++) {
|
||||
for (uint x = 0; x < 4; x++) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -66,7 +66,7 @@ wstringsupplier scripting::create_wstring_supplier(
|
||||
auto str = lua::require_wstring(L, -1); lua::pop(L);
|
||||
return str;
|
||||
}
|
||||
return std::wstring();
|
||||
return std::wstring(L"");
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user