clang warnings fix

This commit is contained in:
MihailRis 2024-02-02 20:42:49 +03:00
parent 4a22e8d57b
commit f25677d6d2
20 changed files with 37 additions and 45 deletions

View File

@ -45,7 +45,7 @@ if(MSVC)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /source-charset:UTF-8")
else()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -lstdc++fs
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra
# additional warnings
-Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wundef
@ -114,7 +114,7 @@ if(UNIX)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie -lstdc++fs")
endif()
include_directories(${LUA_INCLUDE_DIR})

View File

@ -135,7 +135,6 @@ bool assetload::animation(Assets* assets,
auto frameArr = root->list("frames");
Frame temp;
float frameDuration = DEFAULT_FRAME_DURATION;
std::string frameName;

View File

@ -34,7 +34,7 @@ std::vector<ubyte> gzip::compress(const ubyte* src, size_t size) {
std::vector<ubyte> gzip::decompress(const ubyte* src, size_t size) {
// getting uncompressed data length from gzip footer
size_t decompressed_size = *(uint32_t*)(src+size-4);
size_t decompressed_size = *reinterpret_cast<const uint32_t*>(src+size-4);
std::vector<ubyte> buffer;
buffer.resize(decompressed_size);

View File

@ -74,7 +74,7 @@ void ContentLoader::fixPackIndices() {
std::unique_ptr<dynamic::Map> root;
if (fs::is_regular_file(indexFile)) {
root = std::move(files::read_json(indexFile));
root = files::read_json(indexFile);
} else {
root.reset(new dynamic::Map());
}

View File

@ -8,7 +8,7 @@ namespace fs = std::filesystem;
class Block;
class ItemDef;
class ContentPack;
struct ContentPack;
class ContentBuilder;
namespace dynamic {

View File

@ -120,8 +120,6 @@ class InventoryView : public gui::Container {
InventoryInteraction* interaction;
std::vector<SlotView*> slots;
int scroll = 0;
public:
InventoryView(
const Content* content,

View File

@ -106,7 +106,7 @@ void WorldRenderer::drawChunks(Chunks* chunks,
}
float px = camera->position.x / (float)CHUNK_W;
float pz = camera->position.z / (float)CHUNK_D;
std::sort(indices.begin(), indices.end(), [this, chunks, px, pz](size_t i, size_t j) {
std::sort(indices.begin(), indices.end(), [chunks, px, pz](size_t i, size_t j) {
auto a = chunks->chunks[i];
auto b = chunks->chunks[j];
return ((a->x + 0.5f - px)*(a->x + 0.5f - px) +

View File

@ -39,7 +39,7 @@ Skybox::Skybox(uint size, Shader* shader)
-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f
};
vattr attrs[] {2, 0};
vattr attrs[] {{2}, {0}};
mesh = std::make_unique<Mesh>(vertices, 6, attrs);
sprites.push_back(skysprite {

View File

@ -89,6 +89,7 @@ Button::Button(std::shared_ptr<UINode> content, glm::vec4 padding)
padding[1]+padding[3]+margin[1]+margin[3]));
add(content);
scrollable(false);
setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f));
}
Button::Button(std::wstring text, glm::vec4 padding, onaction action)
@ -102,6 +103,7 @@ Button::Button(std::wstring text, glm::vec4 padding, onaction action)
label = std::make_shared<Label>(text);
label->setAlign(Align::center);
add(label);
setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f));
}
void Button::setText(std::wstring text) {
@ -124,10 +126,6 @@ Button* Button::textSupplier(wstringsupplier supplier) {
return this;
}
void Button::setHoverColor(glm::vec4 color) {
hoverColor = color;
}
void Button::drawBackground(const GfxContext* pctx, Assets* assets) {
vec2 coord = calcCoord();
auto batch = pctx->getBatch2D();
@ -163,6 +161,7 @@ void Button::textAlign(Align align) {
// ============================== RichButton ==================================
RichButton::RichButton(vec2 size) : Container(vec2(), size) {
setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f));
}
void RichButton::mouseRelease(GUI* gui, int x, int y) {
@ -179,10 +178,6 @@ RichButton* RichButton::listenAction(onaction action) {
return this;
}
void RichButton::setHoverColor(glm::vec4 color) {
hoverColor = color;
}
void RichButton::drawBackground(const GfxContext* pctx, Assets* assets) {
vec2 coord = calcCoord();
auto batch = pctx->getBatch2D();
@ -198,6 +193,7 @@ TextBox::TextBox(std::wstring placeholder, vec4 padding)
placeholder(placeholder) {
label = std::make_shared<Label>(L"");
add(label);
setHoverColor(glm::vec4(0.05f, 0.1f, 0.2f, 0.75f));
}
void TextBox::drawBackground(const GfxContext* pctx, Assets* assets) {

View File

@ -57,7 +57,6 @@ namespace gui {
class Button : public Panel {
protected:
glm::vec4 hoverColor {0.05f, 0.1f, 0.15f, 0.75f};
glm::vec4 pressedColor {0.0f, 0.0f, 0.0f, 0.95f};
std::vector<onaction> actions;
std::shared_ptr<Label> label = nullptr;
@ -82,13 +81,11 @@ namespace gui {
virtual std::wstring getText() const;
virtual Button* textSupplier(wstringsupplier supplier);
virtual void setHoverColor(glm::vec4 color);
};
class RichButton : public Container {
protected:
glm::vec4 hoverColor {0.05f, 0.1f, 0.15f, 0.75f};
glm::vec4 pressedColor {0.0f, 0.0f, 0.0f, 0.95f};
std::vector<onaction> actions;
public:
@ -98,13 +95,10 @@ namespace gui {
virtual void mouseRelease(GUI*, int x, int y) override;
virtual RichButton* listenAction(onaction action);
virtual void setHoverColor(glm::vec4 color);
};
class TextBox : public Panel {
protected:
glm::vec4 hoverColor {0.05f, 0.1f, 0.2f, 0.75f};
glm::vec4 focusedColor {0.0f, 0.0f, 0.0f, 1.0f};
glm::vec4 invalidColor {0.1f, 0.05f, 0.03f, 1.0f};
std::shared_ptr<Label> label;

View File

@ -11,17 +11,17 @@ using glm::vec2;
using glm::vec3;
using glm::vec4;
Batch2D::Batch2D(size_t capacity) : capacity(capacity), offset(0), color(1.0f, 1.0f, 1.0f, 1.0f){
Batch2D::Batch2D(size_t capacity) : capacity(capacity), color(1.0f){
const vattr attrs[] = {
{2}, {2}, {4}, {0}
};
buffer = new float[capacity * B2D_VERTEX_SIZE];
mesh = new Mesh(buffer, 0, attrs);
mesh = std::make_unique<Mesh>(buffer, 0, attrs);
index = 0;
unsigned char pixels[] = {
255, 255, 255, 255,
ubyte pixels[] = {
0xFF, 0xFF, 0xFF, 0xFF
};
blank = new Texture(pixels, 1, 1, GL_RGBA);
_texture = nullptr;
@ -30,7 +30,6 @@ Batch2D::Batch2D(size_t capacity) : capacity(capacity), offset(0), color(1.0f, 1
Batch2D::~Batch2D(){
delete blank;
delete[] buffer;
delete mesh;
}
void Batch2D::begin(){

View File

@ -1,6 +1,7 @@
#ifndef SRC_GRAPHICS_BATCH2D_H_
#define SRC_GRAPHICS_BATCH2D_H_
#include <memory>
#include <stdlib.h>
#include <glm/glm.hpp>
@ -13,8 +14,7 @@ class Sprite;
class Batch2D {
float* buffer;
size_t capacity;
size_t offset;
Mesh* mesh;
std::unique_ptr<Mesh> mesh;
size_t index;
Texture* blank;

View File

@ -13,8 +13,7 @@ using glm::vec3;
using glm::vec4;
Batch3D::Batch3D(size_t capacity)
: capacity(capacity),
offset(0) {
: capacity(capacity) {
const vattr attrs[] = {
{3}, {2}, {4}, {0}
};

View File

@ -12,7 +12,6 @@ class Texture;
class Batch3D {
float* buffer;
size_t capacity;
size_t offset;
Mesh* mesh;
size_t index;

View File

@ -8,17 +8,23 @@ const uint LB_VERTEX_SIZE = (3+4);
LineBatch::LineBatch(size_t capacity) : capacity(capacity) {
const vattr attrs[] = { {3},{4}, {0} };
buffer = new float[capacity * LB_VERTEX_SIZE * 2];
mesh = new Mesh(buffer, 0, attrs);
mesh = std::make_unique<Mesh>(buffer, 0, attrs);
index = 0;
}
LineBatch::~LineBatch(){
delete[] buffer;
delete mesh;
}
void LineBatch::line(float x1, float y1, float z1, float x2, float y2, float z2,
float r, float g, float b, float a) {
void LineBatch::line(
float x1, float y1,
float z1, float x2,
float y2, float z2,
float r, float g, float b, float a
) {
if (index + LB_VERTEX_SIZE * 2 >= capacity) {
render();
}
buffer[index] = x1;
buffer[index+1] = y1;
buffer[index+2] = z1;

View File

@ -1,13 +1,14 @@
#ifndef GRAPHICS_LINEBATCH_H_
#define GRAPHICS_LINEBATCH_H_
#include <memory>
#include <stdlib.h>
#include <glm/glm.hpp>
class Mesh;
class LineBatch {
Mesh* mesh;
std::unique_ptr<Mesh> mesh;
float* buffer;
size_t index;
size_t capacity;

View File

@ -19,9 +19,6 @@ private:
uint padding;
std::unique_ptr<WorldGenerator> generator;
/* Average measured microseconds duration of loadVisible call */
int64_t avgDurationMcs = 1000;
/* Process one chunk: load it or calculate lights for it */
bool loadVisible();
bool buildLights(std::shared_ptr<Chunk> chunk);

View File

@ -13,7 +13,7 @@ struct AABB;
class Content;
class ContentIndices;
class Chunk;
class voxel;
struct voxel;
class WorldFiles;
class LevelEvents;

View File

@ -3,7 +3,7 @@
#include "../typedefs.h"
class voxel;
struct voxel;
class Content;
class WorldGenerator {

View File

@ -84,6 +84,10 @@ public:
uint getNextInventoryId() {
return nextInventoryId++;
}
const Content* getContent() const {
return content;
}
};
#endif /* WORLD_WORLD_H_ */