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

View File

@ -135,7 +135,6 @@ bool assetload::animation(Assets* assets,
auto frameArr = root->list("frames"); auto frameArr = root->list("frames");
Frame temp;
float frameDuration = DEFAULT_FRAME_DURATION; float frameDuration = DEFAULT_FRAME_DURATION;
std::string frameName; 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) { std::vector<ubyte> gzip::decompress(const ubyte* src, size_t size) {
// getting uncompressed data length from gzip footer // 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; std::vector<ubyte> buffer;
buffer.resize(decompressed_size); buffer.resize(decompressed_size);

View File

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

View File

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

View File

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

View File

@ -106,7 +106,7 @@ void WorldRenderer::drawChunks(Chunks* chunks,
} }
float px = camera->position.x / (float)CHUNK_W; float px = camera->position.x / (float)CHUNK_W;
float pz = camera->position.z / (float)CHUNK_D; 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 a = chunks->chunks[i];
auto b = chunks->chunks[j]; auto b = chunks->chunks[j];
return ((a->x + 0.5f - px)*(a->x + 0.5f - px) + 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,
-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); mesh = std::make_unique<Mesh>(vertices, 6, attrs);
sprites.push_back(skysprite { 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])); padding[1]+padding[3]+margin[1]+margin[3]));
add(content); add(content);
scrollable(false); scrollable(false);
setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f));
} }
Button::Button(std::wstring text, glm::vec4 padding, onaction action) 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 = std::make_shared<Label>(text);
label->setAlign(Align::center); label->setAlign(Align::center);
add(label); add(label);
setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f));
} }
void Button::setText(std::wstring text) { void Button::setText(std::wstring text) {
@ -124,10 +126,6 @@ Button* Button::textSupplier(wstringsupplier supplier) {
return this; return this;
} }
void Button::setHoverColor(glm::vec4 color) {
hoverColor = color;
}
void Button::drawBackground(const GfxContext* pctx, Assets* assets) { void Button::drawBackground(const GfxContext* pctx, Assets* assets) {
vec2 coord = calcCoord(); vec2 coord = calcCoord();
auto batch = pctx->getBatch2D(); auto batch = pctx->getBatch2D();
@ -163,6 +161,7 @@ void Button::textAlign(Align align) {
// ============================== RichButton ================================== // ============================== RichButton ==================================
RichButton::RichButton(vec2 size) : Container(vec2(), size) { 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) { void RichButton::mouseRelease(GUI* gui, int x, int y) {
@ -179,10 +178,6 @@ RichButton* RichButton::listenAction(onaction action) {
return this; return this;
} }
void RichButton::setHoverColor(glm::vec4 color) {
hoverColor = color;
}
void RichButton::drawBackground(const GfxContext* pctx, Assets* assets) { void RichButton::drawBackground(const GfxContext* pctx, Assets* assets) {
vec2 coord = calcCoord(); vec2 coord = calcCoord();
auto batch = pctx->getBatch2D(); auto batch = pctx->getBatch2D();
@ -198,6 +193,7 @@ TextBox::TextBox(std::wstring placeholder, vec4 padding)
placeholder(placeholder) { placeholder(placeholder) {
label = std::make_shared<Label>(L""); label = std::make_shared<Label>(L"");
add(label); add(label);
setHoverColor(glm::vec4(0.05f, 0.1f, 0.2f, 0.75f));
} }
void TextBox::drawBackground(const GfxContext* pctx, Assets* assets) { void TextBox::drawBackground(const GfxContext* pctx, Assets* assets) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -19,9 +19,6 @@ private:
uint padding; uint padding;
std::unique_ptr<WorldGenerator> generator; 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 */ /* Process one chunk: load it or calculate lights for it */
bool loadVisible(); bool loadVisible();
bool buildLights(std::shared_ptr<Chunk> chunk); bool buildLights(std::shared_ptr<Chunk> chunk);

View File

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

View File

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

View File

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