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
+3 -3
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;
+2 -4
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++) {
+1 -2
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);
+2 -2
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
);
}
+2 -2
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}
+9 -10
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);
}
}
+1 -3
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;
+3 -5
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) {
+1 -1
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();
+1 -1
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);
+2 -2
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);
+1 -1
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;
+1 -1
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);
+1 -1
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();
+2 -2
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;
+2 -1
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});
+4 -5
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();
+2 -2
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;
+1 -1
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;
}
+1 -20
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();
}
+2 -15
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);
+1 -1
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);
};