quick check with linters

This commit is contained in:
MihailRis 2024-05-10 12:34:05 +03:00
parent 92f185ab51
commit 9522aedeec
55 changed files with 129 additions and 184 deletions

View File

@ -475,5 +475,5 @@ void ALAudio::setListener(glm::vec3 position, glm::vec3 velocity, glm::vec3 at,
AL_CHECK(alListenerf(AL_GAIN, get_channel(0)->getVolume()));
}
void ALAudio::update(double delta) {
void ALAudio::update(double) {
}

View File

@ -72,9 +72,6 @@ size_t PCMStream::readFully(char* buffer, size_t bufferSize, bool loop) {
if (loop) {
seek(0);
}
if (bufferSize == 0) {
return size;
}
} while (loop);
return size;
}
@ -94,7 +91,7 @@ public:
seekable(seekable)
{}
size_t read(char* buffer, size_t bufferSize) override {
size_t read(char*, size_t bufferSize) override {
if (closed) {
return 0;
}

View File

@ -95,9 +95,7 @@ Content* ContentBuilder::build() {
}
blockDefsIndices.push_back(def);
if (groups->find(def->drawGroup) == groups->end()) {
groups->insert(def->drawGroup);
}
groups->insert(def->drawGroup);
}
std::vector<ItemDef*> itemDefsIndices;

View File

@ -228,15 +228,15 @@ void ContentLoader::loadCustomBlockModel(Block& def, dynamic::Map* primitives) {
def.modelBoxes.push_back(modelbox);
if (boxarr->size() == 7)
for (uint i = 6; i < 12; i++) {
for (uint j = 6; j < 12; j++) {
def.modelTextures.push_back(boxarr->str(6));
}
else if (boxarr->size() == 12)
for (uint i = 6; i < 12; i++) {
def.modelTextures.push_back(boxarr->str(i));
for (uint j = 6; j < 12; j++) {
def.modelTextures.push_back(boxarr->str(j));
}
else
for (uint i = 6; i < 12; i++) {
for (uint j = 6; j < 12; j++) {
def.modelTextures.push_back("notfound");
}
}

View File

@ -74,7 +74,7 @@ static bool resolve_dependencies (
const ContentPack* pack,
const std::unordered_map<std::string, ContentPack>& packs,
std::vector<std::string>& allNames,
std::vector<std::string>& added,
const std::vector<std::string>& added,
std::queue<const ContentPack*>& queue,
bool resolveWeaks
) {

View File

@ -82,9 +82,6 @@ bool List::flag(size_t index) const {
}
Value* List::getValueWriteable(size_t index) {
if (index > values.size()) {
throw std::runtime_error("index error");
}
return &values.at(index);
}

View File

@ -70,7 +70,7 @@ std::shared_ptr<Task> WorldConverter::startTask(
auto pool = std::make_shared<util::ThreadPool<convert_task, int>>(
"converter-pool",
[=](){return std::make_shared<ConverterWorker>(converter);},
[=](int& _) {}
[=](int&) {}
);
while (!converter->tasks.empty()) {
const convert_task& task = converter->tasks.front();

View File

@ -114,9 +114,9 @@ WorldRegion* WorldRegions::getRegion(int x, int z, int layer) {
}
WorldRegion* WorldRegions::getOrCreateRegion(int x, int z, int layer) {
RegionsLayer& regions = layers[layer];
WorldRegion* region = getRegion(x, z, layer);
if (region == nullptr) {
RegionsLayer& regions = layers[layer];
std::lock_guard lock(regions.mutex);
region = new WorldRegion();
regions.regions[glm::ivec2(x, z)].reset(region);

View File

@ -416,7 +416,7 @@ void Hud::add(HudElement element) {
elements.push_back(element);
}
void Hud::onRemove(HudElement& element) {
void Hud::onRemove(const HudElement& element) {
auto document = element.getDocument();
if (document) {
Inventory* inventory = nullptr;

View File

@ -162,7 +162,7 @@ public:
void openPermanent(UiDocument* doc);
void add(HudElement element);
void onRemove(HudElement& element);
void onRemove(const HudElement& element);
void remove(std::shared_ptr<gui::UINode> node);
Player* getPlayer() const;

View File

@ -38,7 +38,7 @@ LevelScreen::LevelScreen(Engine* engine, Level* level) : Screen(engine) {
worldRenderer = std::make_unique<WorldRenderer>(engine, frontend.get(), controller->getPlayer());
hud = std::make_unique<Hud>(engine, frontend.get(), controller->getPlayer());
keepAlive(settings.graphics.backlight.observe([=](bool flag) {
keepAlive(settings.graphics.backlight.observe([=](bool) {
controller->getLevel()->chunks->saveAndClear();
}));
keepAlive(settings.camera.fov.observe([=](double value) {
@ -137,7 +137,7 @@ void LevelScreen::update(float delta) {
hud->update(hudVisible);
}
void LevelScreen::draw(float delta) {
void LevelScreen::draw(float) {
auto camera = controller->getPlayer()->currentCamera;
Viewport viewport(Window::width, Window::height);

View File

@ -6,9 +6,9 @@
Framebuffer::Framebuffer(uint fbo, uint depth, std::unique_ptr<Texture> texture)
: fbo(fbo), depth(depth), texture(std::move(texture))
{
if (texture) {
width = texture->getWidth();
height = texture->getHeight();
if (this->texture) {
width = this->texture->getWidth();
height = this->texture->getHeight();
} else {
width = 0;
height = 0;

View File

@ -35,11 +35,10 @@ ImageData::~ImageData() {
}
void ImageData::flipX() {
uint size;
switch (format) {
case ImageFormat::rgb888:
case ImageFormat::rgba8888: {
size = (format == ImageFormat::rgba8888) ? 4 : 3;
uint size = (format == ImageFormat::rgba8888) ? 4 : 3;
ubyte* pixels = (ubyte*)data;
for (uint y = 0; y < height; y++) {
for (uint x = 0; x < width/2; x++) {
@ -58,11 +57,10 @@ void ImageData::flipX() {
}
void ImageData::flipY() {
uint size;
switch (format) {
case ImageFormat::rgb888:
case ImageFormat::rgba8888: {
size = (format == ImageFormat::rgba8888) ? 4 : 3;
uint size = (format == ImageFormat::rgba8888) ? 4 : 3;
ubyte* pixels = (ubyte*)data;
for (uint y = 0; y < height/2; y++) {
for (uint x = 0; x < width; x++) {

View File

@ -38,8 +38,7 @@ void TextureAnimator::update(float delta) {
uint elemDstId = elem.dstTexture->getId();
uint elemSrcId = elem.srcTexture->getId();
if (changedTextures.find(elemDstId) == changedTextures.end())
changedTextures.insert(elemDstId);
changedTextures.insert(elemDstId);
glBindFramebuffer(GL_FRAMEBUFFER, fboD);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, elemDstId, 0);

View File

@ -64,7 +64,7 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
offset.y += (1.0f - hitbox).y * 0.5f;
shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
for (size_t i = 0; i < def->modelBoxes.size(); i++) {
const UVRegion (&texfaces)[6] = {
const UVRegion (&boxtexfaces)[6] = {
def->modelUVs[i * 6],
def->modelUVs[i * 6 + 1],
def->modelUVs[i * 6 + 2],
@ -75,7 +75,7 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
batch->cube(
def->modelBoxes[i].a * glm::vec3(1.0f, 1.0f, -1.0f) * pmul,
def->modelBoxes[i].size() * pmul,
texfaces, glm::vec4(1.0f), !def->rt.emissive
boxtexfaces, glm::vec4(1.0f), !def->rt.emissive
);
}

View File

@ -210,10 +210,10 @@ void BlocksRenderer::blockXSprite(int x, int y, int z,
face(vec3(x + xs, y, z + zs),
w, size.y, 0, vec3(1, 0, -1), vec3(0, 1, 0), vec3(),
texface1, lights, vec4(tint));
texface2, lights, vec4(tint));
face(vec3(x + xs, y, z + zs),
w, size.y, 0, vec3(-1, 0, 1), vec3(0, 1, 0), vec3(),
texface1, lights, vec4(tint));
texface2, lights, vec4(tint));
}
// HINT: texture faces order: {east, west, bottom, top, south, north}

View File

@ -42,10 +42,10 @@ bool WorldRenderer::showChunkBorders = false;
WorldRenderer::WorldRenderer(Engine* engine, LevelFrontend* frontend, Player* player)
: engine(engine),
level(frontend->getLevel()),
player(player)
player(player),
frustumCulling(std::make_unique<Frustum>()),
lineBatch(std::make_unique<LineBatch>())
{
frustumCulling = std::make_unique<Frustum>();
lineBatch = std::make_unique<LineBatch>();
renderer = std::make_unique<ChunksRenderer>(
level,
frontend->getContentGfxCache(),
@ -55,7 +55,7 @@ WorldRenderer::WorldRenderer(Engine* engine, LevelFrontend* frontend, Player* pl
auto& settings = engine->getSettings();
level->events->listen(EVT_CHUNK_HIDDEN,
[this](lvl_event_type type, Chunk* chunk) {
[this](lvl_event_type, Chunk* chunk) {
renderer->unload(chunk);
}
);
@ -142,7 +142,7 @@ void WorldRenderer::drawChunks(Chunks* chunks, Camera* camera, Shader* shader) {
}
void WorldRenderer::renderLevel(
const DrawContext& ctx,
const DrawContext&,
Camera* camera,
const EngineSettings& settings
) {
@ -196,7 +196,7 @@ void WorldRenderer::renderBlockSelection(Camera* camera, Shader* linesShader) {
const glm::vec3 point = PlayerController::selectedPointPosition;
const glm::vec3 norm = PlayerController::selectedBlockNormal;
std::vector<AABB>& hitboxes = block->rotatable
const std::vector<AABB>& hitboxes = block->rotatable
? block->rt.hitboxes[PlayerController::selectedBlockStates]
: block->hitboxes;
@ -217,8 +217,7 @@ void WorldRenderer::renderBlockSelection(Camera* camera, Shader* linesShader) {
void WorldRenderer::renderDebugLines(
const DrawContext& pctx,
Camera* camera,
Shader* linesShader,
const EngineSettings& settings
Shader* linesShader
) {
DrawContext ctx = pctx.sub();
const auto& viewport = ctx.getViewport();
@ -276,7 +275,7 @@ void WorldRenderer::draw(
const Viewport& vp = pctx.getViewport();
camera->aspect = vp.getWidth() / static_cast<float>(vp.getHeight());
EngineSettings& settings = engine->getSettings();
const EngineSettings& settings = engine->getSettings();
skybox->refresh(pctx, level->getWorld()->daytime, 1.0f+fog*2.0f, 4);
Assets* assets = engine->getAssets();
@ -305,7 +304,7 @@ void WorldRenderer::draw(
}
if (hudVisible && player->debug) {
renderDebugLines(wctx, camera, linesShader, settings);
renderDebugLines(wctx, camera, linesShader);
}
}

View File

@ -48,12 +48,10 @@ class WorldRenderer {
/// @param context graphics context
/// @param camera active camera
/// @param linesShader shader used
/// @param settings engine settings
void renderDebugLines(
const DrawContext& context,
Camera* camera,
Shader* linesShader,
const EngineSettings& settings
Shader* linesShader
);
public:
static bool showChunkBorders;

View File

@ -44,10 +44,8 @@ void GUI::onAssetsLoad(Assets* assets) {
), "core:root");
}
/** Mouse related input and logic handling
* @param delta delta time
*/
void GUI::actMouse(float delta) {
// @brief Mouse related input and logic handling
void GUI::actMouse() {
auto hover = container->getAt(Events::cursor, nullptr);
if (this->hover && this->hover != hover) {
this->hover->setHover(false);
@ -125,7 +123,7 @@ void GUI::act(float delta, const Viewport& vp) {
auto prevfocus = focus;
if (!Events::_cursor_locked) {
actMouse(delta);
actMouse();
}
if (focus) {

View File

@ -62,7 +62,7 @@ namespace gui {
std::unique_ptr<Camera> uicamera;
std::shared_ptr<Menu> menu;
std::queue<runnable> postRunnables;
void actMouse(float delta);
void actMouse();
void actFocused();
public:
GUI();

View File

@ -75,7 +75,7 @@ void Button::refresh() {
}
}
void Button::drawBackground(const DrawContext* pctx, Assets* assets) {
void Button::drawBackground(const DrawContext* pctx, Assets*) {
glm::vec2 pos = calcPos();
auto batch = pctx->getBatch2D();
batch->texture(nullptr);

View File

@ -10,7 +10,7 @@ CheckBox::CheckBox(bool checked) : UINode(glm::vec2(32.0f)), checked(checked) {
setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));
}
void CheckBox::draw(const DrawContext* pctx, Assets* assets) {
void CheckBox::draw(const DrawContext* pctx, Assets*) {
if (supplier) {
checked = supplier();
}
@ -21,7 +21,7 @@ void CheckBox::draw(const DrawContext* pctx, Assets* assets) {
batch->rect(pos.x, pos.y, size.x, size.y);
}
void CheckBox::mouseRelease(GUI*, int x, int y) {
void CheckBox::mouseRelease(GUI*, int, int) {
checked = !checked;
if (consumer) {
consumer(checked);

View File

@ -93,7 +93,7 @@ void Container::draw(const DrawContext* pctx, Assets* assets) {
}
}
void Container::drawBackground(const DrawContext* pctx, Assets* assets) {
void Container::drawBackground(const DrawContext* pctx, Assets*) {
glm::vec4 color = calcColor();
if (color.a <= 0.001f)
return;

View File

@ -15,7 +15,7 @@ InputBindBox::InputBindBox(Binding& binding, glm::vec4 padding)
setScrollable(false);
}
void InputBindBox::drawBackground(const DrawContext* pctx, Assets* assets) {
void InputBindBox::drawBackground(const DrawContext* pctx, Assets*) {
glm::vec2 pos = calcPos();
auto batch = pctx->getBatch2D();
batch->texture(nullptr);

View File

@ -116,7 +116,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
const int slotSize = InventoryView::SLOT_SIZE;
ItemStack& stack = *bound;
const ItemStack& stack = *bound;
glm::vec4 tint(1.0f);
glm::vec2 pos = calcPos();
glm::vec4 color = getColor();

View File

@ -47,7 +47,7 @@ namespace gui {
};
class SlotView : public gui::UINode {
const Content* content;
const Content* content = nullptr;
SlotLayout layout;
bool highlighted = false;
@ -77,7 +77,7 @@ namespace gui {
};
class InventoryView : public gui::Container {
const Content* content;
const Content* content = nullptr;
std::shared_ptr<Inventory> inventory;

View File

@ -26,8 +26,9 @@ void LabelCache::update(const std::wstring& text, bool multiline, bool wrap) {
if (font == nullptr) {
wrap = false;
}
size_t len = 0;
if (multiline) {
size_t len = 0;
for (size_t i = 0; i < text.length(); i++, len++) {
if (text[i] == L'\n') {
lines.push_back(LineScheme {i+1, false});

View File

@ -56,13 +56,12 @@ void TextBox::draw(const DrawContext* pctx, Assets* assets) {
batch->setColor(glm::vec4(0.8f, 0.9f, 1.0f, 0.25f));
int start = font->calcWidth(input, selectionStart-label->getTextLineOffset(startLine));
int end = font->calcWidth(input, selectionEnd-label->getTextLineOffset(endLine));
int startY = label->getLineYOffset(startLine);
int endY = label->getLineYOffset(startLine);
int lineY = label->getLineYOffset(startLine);
if (startLine == endLine) {
batch->rect(lcoord.x + start, lcoord.y+startY, end-start, lineHeight);
batch->rect(lcoord.x + start, lcoord.y+lineY, end-start, lineHeight);
} else {
batch->rect(lcoord.x + start, lcoord.y+endY, label->getSize().x-start-padding.z-padding.x-2, lineHeight);
batch->rect(lcoord.x + start, lcoord.y+lineY, label->getSize().x-start-padding.z-padding.x-2, lineHeight);
for (uint i = startLine+1; i < endLine; i++) {
batch->rect(lcoord.x, lcoord.y+label->getLineYOffset(i), label->getSize().x-padding.z-padding.x-2, lineHeight);
}
@ -71,7 +70,7 @@ void TextBox::draw(const DrawContext* pctx, Assets* assets) {
}
}
void TextBox::drawBackground(const DrawContext* pctx, Assets* assets) {
void TextBox::drawBackground(const DrawContext* pctx, Assets*) {
glm::vec2 pos = calcPos();
auto batch = pctx->getBatch2D();

View File

@ -23,7 +23,7 @@ TrackBar::TrackBar(
setHoverColor(glm::vec4(0.01f, 0.02f, 0.03f, 0.5f));
}
void TrackBar::draw(const DrawContext* pctx, Assets* assets) {
void TrackBar::draw(const DrawContext* pctx, Assets*) {
if (supplier) {
value = supplier();
}
@ -48,7 +48,7 @@ void TrackBar::setConsumer(doubleconsumer consumer) {
this->consumer = consumer;
}
void TrackBar::mouseMove(GUI*, int x, int y) {
void TrackBar::mouseMove(GUI*, int x, int) {
glm::vec2 pos = calcPos();
value = x - trackWidth/2;
value -= pos.x;

View File

@ -64,7 +64,7 @@ UINode* UINode::listenAction(onaction action) {
return this;
}
void UINode::click(GUI*, int x, int y) {
void UINode::click(GUI*, int, int) {
pressed = true;
}

View File

@ -14,25 +14,6 @@
using namespace gui;
std::shared_ptr<Button> guiutil::backButton(std::shared_ptr<Menu> menu) {
return std::dynamic_pointer_cast<Button>(create(
"<button padding='10' onclick='menu:back()'>@Back</button>"
));
}
std::shared_ptr<Button> guiutil::gotoButton(
std::wstring text,
const std::string& page,
std::shared_ptr<Menu> menu
) {
text = langs::get(text, L"menu");
return std::dynamic_pointer_cast<Button>(create(
"<button onclick='menu.page=\""+page+"\"' padding='10'>"+
util::wstr2str_utf8(text)+
"</button>"
));
}
std::shared_ptr<gui::UINode> guiutil::create(const std::string& source, scriptenv env) {
if (env == nullptr) {
env = scripting::get_root_environment();
@ -52,7 +33,7 @@ void guiutil::alert(GUI* gui, const std::wstring& text, runnable on_hidden) {
panel->add(label);
panel->add(std::make_shared<Button>(
langs::get(L"Ok"), glm::vec4(10.f),
[=](GUI* gui) {
[=](GUI*) {
if (on_hidden) {
on_hidden();
}

View File

@ -1,27 +1,14 @@
#ifndef FRONTEND_GUI_GUI_UTIL_HPP_
#define FRONTEND_GUI_GUI_UTIL_HPP_
#include <memory>
#include <string>
#include "GUI.hpp"
#include "../../typedefs.hpp"
#include "../../delegates.hpp"
namespace gui {
class Button;
}
#include <memory>
#include <string>
namespace guiutil {
std::shared_ptr<gui::Button> backButton(
std::shared_ptr<gui::Menu> menu
);
std::shared_ptr<gui::Button> gotoButton(
std::wstring text,
const std::string& page,
std::shared_ptr<gui::Menu> menu
);
/// @brief Create element from XML
/// @param source XML
std::shared_ptr<gui::UINode> create(const std::string& source, scriptenv env=0);

View File

@ -395,7 +395,7 @@ static slotcallback readSlotFunc(InventoryView* view, UiXmlReader& reader, xml::
reader.getEnvironment(),
element->attr(attr).getText()
);
return [=](uint slot, ItemStack& stack) {
return [=](uint slot, ItemStack&) {
int args[] {int(view->getInventory()->getId()), int(slot)};
consumer(args, 2);
};

View File

@ -24,7 +24,7 @@ std::unique_ptr<ubyte[]> Lightmap::encode() const {
return buffer;
}
std::unique_ptr<light_t[]> Lightmap::decode(ubyte* buffer) {
std::unique_ptr<light_t[]> Lightmap::decode(const ubyte* buffer) {
auto lights = std::make_unique<light_t[]>(CHUNK_VOL);
for (uint i = 0; i < CHUNK_VOL; i+=2) {
ubyte b = buffer[i/2];

View File

@ -84,7 +84,7 @@ public:
}
std::unique_ptr<ubyte[]> encode() const;
static std::unique_ptr<light_t[]> decode(ubyte* buffer);
static std::unique_ptr<light_t[]> decode(const ubyte* buffer);
};
#endif /* LIGHTING_LIGHTMAP_HPP_ */

View File

@ -44,7 +44,6 @@ void ChunksController::update(int64_t maxDuration) {
mcstotal += mcs;
continue;
}
mcstotal += mcs;
}
break;
}

View File

@ -68,7 +68,6 @@ void show_convert_request(
static void show_content_missing(
Engine* engine,
const Content* content,
std::shared_ptr<ContentLUT> lut
) {
using namespace dynamic;
@ -135,7 +134,7 @@ void EngineController::openWorld(std::string name, bool confirmConvert) {
if (lut) {
if (lut->hasMissingContent()) {
engine->setScreen(std::make_shared<MenuScreen>(engine));
show_content_missing(engine, content, lut);
show_content_missing(engine, lut);
} else {
if (confirmConvert) {
menus::show_process_panel(engine, create_converter(engine, folder, content, lut, [=]() {

View File

@ -348,7 +348,7 @@ void PlayerController::updateInteraction(){
maxDistance *= 20.0f;
}
auto inventory = player->getInventory();
ItemStack& stack = inventory->getSlot(player->getChosenSlot());
const ItemStack& stack = inventory->getSlot(player->getChosenSlot());
ItemDef* item = indices->getItemDef(stack.getItemId());
glm::vec3 end;

View File

@ -48,8 +48,8 @@ inline audio::speakerid_t play_sound(
),
relative,
volume,
pitch,
false,
pitch,
loop,
audio::PRIORITY_NORMAL,
channel
);

View File

@ -39,7 +39,7 @@ static int l_open_world(lua_State* L) {
return 0;
}
static int l_reopen_world(lua_State* L) {
static int l_reopen_world(lua_State*) {
auto controller = scripting::engine->getController();
controller->reopenWorld(scripting::level->getWorld());
return 0;
@ -151,7 +151,7 @@ static int l_get_setting_info(lua_State* L) {
return 0;
}
static int l_quit(lua_State* L) {
static int l_quit(lua_State*) {
Window::setShouldClose(true);
return 0;
}

View File

@ -242,7 +242,7 @@ static int p_is_visible(UINode* node) {
static int p_is_enabled(UINode* node) {
return state->pushboolean(node->isEnabled());
}
static int p_move_into(UINode* node) {
static int p_move_into(UINode*) {
return state->pushcfunction(l_uinode_move_into);
}

View File

@ -23,14 +23,14 @@ namespace scripting {
extern Hud* hud;
}
static int l_hud_open_inventory(lua_State* L) {
static int l_hud_open_inventory(lua_State*) {
if (!scripting::hud->isInventoryOpen()) {
scripting::hud->openInventory();
}
return 0;
}
static int l_hud_close_inventory(lua_State* L) {
static int l_hud_close_inventory(lua_State*) {
if (scripting::hud->isInventoryOpen()) {
scripting::hud->closeInventory();
}
@ -99,12 +99,12 @@ static int l_hud_close(lua_State* L) {
return 0;
}
static int l_hud_pause(lua_State* L) {
static int l_hud_pause(lua_State*) {
scripting::hud->setPause(true);
return 0;
}
static int l_hud_resume(lua_State* L) {
static int l_hud_resume(lua_State*) {
scripting::hud->setPause(false);
return 0;
}

View File

@ -24,7 +24,7 @@ static int l_inventory_get(lua_State* L) {
if (slotid < 0 || uint64_t(slotid) >= inv->size()) {
luaL_error(L, "slot index is out of range [0, inventory.size(invid)]");
}
ItemStack& item = inv->getSlot(slotid);
const ItemStack& item = inv->getSlot(slotid);
lua_pushinteger(L, item.getItemId());
lua_pushinteger(L, item.getCount());
return 2;

View File

@ -50,7 +50,7 @@ static int l_pack_get_available(lua_State* L) {
auto manager = scripting::engine->createPacksManager(worldFolder);
manager.scan();
auto& installed = scripting::engine->getContentPacks();
const auto& installed = scripting::engine->getContentPacks();
for (auto& pack : installed) {
manager.exclude(pack.id);
}
@ -130,7 +130,7 @@ static int l_pack_get_info(lua_State* L) {
auto content = scripting::engine->getContent();
auto& packs = scripting::engine->getContentPacks();
auto found = std::find_if(packs.begin(), packs.end(), [packid](auto& pack) {
auto found = std::find_if(packs.begin(), packs.end(), [packid](const auto& pack) {
return pack.id == packid;
});
if (found == packs.end()) {

View File

@ -9,9 +9,7 @@
const double E = 0.03;
const double MAX_FIX = 0.1;
using glm::vec3;
PhysicsSolver::PhysicsSolver(vec3 gravity) : gravity(gravity) {
PhysicsSolver::PhysicsSolver(glm::vec3 gravity) : gravity(gravity) {
}
void PhysicsSolver::step(
@ -30,9 +28,9 @@ void PhysicsSolver::step(
bool prevGrounded = hitbox->grounded;
hitbox->grounded = false;
for (uint i = 0; i < substeps; i++) {
vec3& pos = hitbox->position;
vec3& half = hitbox->halfsize;
vec3& vel = hitbox->velocity;
glm::vec3& pos = hitbox->position;
glm::vec3& half = hitbox->halfsize;
glm::vec3& vel = hitbox->velocity;
float px = pos.x;
float pz = pos.z;
@ -77,13 +75,13 @@ void PhysicsSolver::step(
}
void PhysicsSolver::colisionCalc(
Chunks* chunks,
Hitbox* hitbox,
vec3& vel,
vec3& pos,
const vec3 half,
float stepHeight)
{
Chunks* chunks,
Hitbox* hitbox,
glm::vec3& vel,
glm::vec3& pos,
const glm::vec3 half,
float stepHeight
) {
// step size (smaller - more accurate, but slower)
float s = 2.0f/BLOCK_AABB_GRID;
@ -212,29 +210,29 @@ void PhysicsSolver::colisionCalc(
}
bool PhysicsSolver::isBlockInside(int x, int y, int z, Hitbox* hitbox) {
vec3& pos = hitbox->position;
vec3& half = hitbox->halfsize;
const glm::vec3& pos = hitbox->position;
const glm::vec3& half = hitbox->halfsize;
return x >= floor(pos.x-half.x) && x <= floor(pos.x+half.x) &&
z >= floor(pos.z-half.z) && z <= floor(pos.z+half.z) &&
y >= floor(pos.y-half.y) && y <= floor(pos.y+half.y);
}
bool PhysicsSolver::isBlockInside(int x, int y, int z, Block* def, blockstate_t states, Hitbox* hitbox) {
vec3& pos = hitbox->position;
vec3& half = hitbox->halfsize;
voxel v;
v.states = states;
const auto& boxes = def->rotatable
const glm::vec3& pos = hitbox->position;
const glm::vec3& half = hitbox->halfsize;
voxel v {};
v.states = states;
const auto& boxes = def->rotatable
? def->rt.hitboxes[v.rotation()]
: def->hitboxes;
for (const auto& block_hitbox : boxes) {
vec3 min = block_hitbox.min();
vec3 max = block_hitbox.max();
// 0.00001 - inaccuracy
if (min.x < pos.x+half.x-x-0.00001 && max.x > pos.x-half.x-x+0.00001 &&
min.z < pos.z+half.z-z-0.00001 && max.z > pos.z-half.z-z+0.00001 &&
min.y < pos.y+half.y-y-0.00001 && max.y > pos.y-half.y-y+0.00001)
return true;
}
for (const auto& block_hitbox : boxes) {
glm::vec3 min = block_hitbox.min();
glm::vec3 max = block_hitbox.max();
// 0.00001 - inaccuracy
if (min.x < pos.x+half.x-x-0.00001 && max.x > pos.x-half.x-x+0.00001 &&
min.z < pos.z+half.z-z-0.00001 && max.z > pos.z-half.z-z+0.00001 &&
min.y < pos.y+half.y-y-0.00001 && max.y > pos.y-half.y-y+0.00001)
return true;
}
return false;
}

View File

@ -47,7 +47,7 @@ class ThreadPool : public Task {
runnable onComplete = nullptr;
std::atomic<int> busyWorkers = 0;
std::atomic<uint> jobsDone = 0;
bool working = true;
std::atomic<bool> working = true;
bool failed = false;
bool standaloneResults = true;
bool stopOnFail = true;
@ -170,7 +170,7 @@ public:
onJobFailed(entry.job);
}
if (stopOnFail) {
std::lock_guard<std::mutex> lock(jobsMutex);
std::lock_guard<std::mutex> jobsLock(jobsMutex);
failed = true;
complete = false;
}
@ -184,7 +184,7 @@ public:
}
if (onComplete && busyWorkers == 0) {
std::lock_guard<std::mutex> lock(jobsMutex);
std::lock_guard<std::mutex> jobsLock(jobsMutex);
if (jobs.empty()) {
onComplete();
complete = true;

View File

@ -269,7 +269,6 @@ std::string util::mangleid(uint64_t value) {
// todo: use base64
std::stringstream ss;
ss << std::hex << value;
std::string result(ss.str());
return ss.str();
}
@ -434,7 +433,7 @@ std::string util::format_data_size(size_t size) {
" B", " KiB", " MiB", " GiB", " TiB", " EiB", " PiB"
};
int group = 0;
size_t remainder;
size_t remainder = 0;
while (size >= 1024) {
group++;
remainder = size % 1024;

View File

@ -40,13 +40,13 @@ const BlockRotProfile BlockRotProfile::PANE {"pane", {
Block::Block(std::string name)
: name(name),
caption(util::id_to_caption(name)),
textureFaces {TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,
TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND} {
rotations = BlockRotProfile::PIPE;
caption = util::id_to_caption(name);
}
TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND},
rotations(BlockRotProfile::PIPE)
{}
Block::Block(std::string name, std::string texture) : name(name),
textureFaces{texture,texture,texture,texture,texture,texture} {
rotations = BlockRotProfile::PIPE;
}
textureFaces{texture,texture,texture,texture,texture,texture},
rotations(BlockRotProfile::PIPE)
{}

View File

@ -423,9 +423,7 @@ void Chunks::translate(int32_t dx, int32_t dz) {
continue;
if (nx < 0 || nz < 0 || nx >= int(w) || nz >= int(d)){
events->trigger(EVT_CHUNK_HIDDEN, chunk.get());
if (worldFiles) {
regions.put(chunk.get());
}
regions.put(chunk.get());
chunksCount--;
continue;
}

View File

@ -25,7 +25,7 @@ public:
std::vector<std::shared_ptr<Chunk>> chunksSecond;
size_t volume;
size_t chunksCount;
size_t visible;
size_t visible = 0;
uint32_t w, d;
int32_t ox, oz;
WorldFiles* worldFiles;

View File

@ -98,19 +98,19 @@ void Events::pollEvents() {
}
}
void Events::bind(std::string name, inputtype type, keycode code) {
void Events::bind(const std::string& name, inputtype type, keycode code) {
bind(name, type, static_cast<int>(code));
}
void Events::bind(std::string name, inputtype type, mousecode code) {
void Events::bind(const std::string& name, inputtype type, mousecode code) {
bind(name, type, static_cast<int>(code));
}
void Events::bind(std::string name, inputtype type, int code) {
void Events::bind(const std::string& name, inputtype type, int code) {
bindings[name] = Binding(type, code);
}
bool Events::active(std::string name) {
bool Events::active(const std::string& name) {
const auto& found = bindings.find(name);
if (found == bindings.end()) {
return false;
@ -118,7 +118,7 @@ bool Events::active(std::string name) {
return found->second.active();
}
bool Events::jactive(std::string name) {
bool Events::jactive(const std::string& name) {
const auto& found = bindings.find(name);
if (found == bindings.end()) {
return false;

View File

@ -38,11 +38,11 @@ public:
static void toggleCursor();
static void bind(std::string name, inputtype type, keycode code);
static void bind(std::string name, inputtype type, mousecode code);
static void bind(std::string name, inputtype type, int code);
static bool active(std::string name);
static bool jactive(std::string name);
static void bind(const std::string& name, inputtype type, keycode code);
static void bind(const std::string& name, inputtype type, mousecode code);
static void bind(const std::string& name, inputtype type, int code);
static bool active(const std::string& name);
static bool jactive(const std::string& name);
static void setKey(int key, bool b);
static void setButton(int button, bool b);

View File

@ -32,7 +32,7 @@ void mouse_button_callback(GLFWwindow*, int button, int action, int) {
Events::setButton(button, action == GLFW_PRESS);
}
void key_callback(GLFWwindow*, int key, int scancode, int action, int /*mode*/) {
void key_callback(GLFWwindow*, int key, int /*scancode*/, int action, int /*mode*/) {
if (key == GLFW_KEY_UNKNOWN) return;
if (action == GLFW_PRESS) {
Events::setKey(key, true);
@ -79,7 +79,7 @@ void window_size_callback(GLFWwindow*, int width, int height) {
Window::resetScissor();
}
void character_callback(GLFWwindow* window, unsigned int codepoint){
void character_callback(GLFWwindow*, unsigned int codepoint){
Events::codepoints.push_back(codepoint);
}

View File

@ -36,7 +36,7 @@ Level::Level(World* world, const Content* content, EngineSettings& settings)
);
lighting = std::make_unique<Lighting>(content, chunks.get());
events->listen(EVT_CHUNK_HIDDEN, [this](lvl_event_type type, Chunk* chunk) {
events->listen(EVT_CHUNK_HIDDEN, [this](lvl_event_type, Chunk* chunk) {
this->chunksStorage->remove(chunk->x, chunk->z);
});

View File

@ -9,7 +9,7 @@ void LevelEvents::listen(lvl_event_type type, chunk_event_func func) {
}
void LevelEvents::trigger(lvl_event_type type, Chunk* chunk) {
auto& callbacks = chunk_callbacks[type];
const auto& callbacks = chunk_callbacks[type];
for (chunk_event_func func : callbacks) {
func(type, chunk);
}