Improved support for Clang.

Fixed most of the new warnings.
master
Quentin Bazin 2021-06-10 02:04:14 +02:00
parent 54b0bdcaba
commit 669cbf70f9
24 changed files with 42 additions and 48 deletions

1
.gitignore vendored
View File

@ -57,6 +57,7 @@ build_win32
build_win64 build_win64
build_msvc build_msvc
build_mingw build_mingw
build_clang
build_debug build_debug
deploy deploy
openminer openminer

View File

@ -41,6 +41,14 @@ set(RELWITHDEB_GCC_FLAGS
-Wfatal-errors -Wfatal-errors
) )
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CLANG_FLAGS
-Wno-sign-conversion
-Wno-implicit-int-float-conversion
-Wno-nested-anon-types
)
endif()
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

2
external/gamekit vendored

@ -1 +1 @@
Subproject commit 1de5e4c3fe1ee4694bbee3acf86f72633018bc53 Subproject commit d770f48928abaacd23f186c307a865688d7edb50

View File

@ -27,6 +27,7 @@ if (NOT MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:DEBUG>:${DEBUG_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:DEBUG>:${DEBUG_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:RELEASE>:${RELEASE_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:RELEASE>:${RELEASE_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:RELWITHDEBINFO>:${RELWITHDEB_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:RELWITHDEBINFO>:${RELWITHDEB_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME} PRIVATE ${CLANG_FLAGS})
endif () endif ()
target_compile_options(${PROJECT_NAME} PRIVATE -DGLM_FORCE_RADIANS) target_compile_options(${PROJECT_NAME} PRIVATE -DGLM_FORCE_RADIANS)

View File

@ -43,8 +43,8 @@ void CelestialObject::setTexture(const std::string &textureName) {
} }
void CelestialObject::updateVertexBuffer() const { void CelestialObject::updateVertexBuffer() const {
if (!m_width || !m_height) { if (m_width <= 0.f || m_height <= 0.f) {
gkError() << "Can't update vertex buffer for celestial object of size 0"; gkError() << "Trying to update vertex buffer for celestial object of invalid size";
return; return;
} }

View File

@ -44,7 +44,7 @@ void ChunkRenderer::draw(gk::RenderTarget &target, gk::RenderStates states, cons
glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL,
(layer == ChunkMeshLayer::NoMipMap || layer == ChunkMeshLayer::Flora) ? 0 : Config::mipmapLevels)); (layer == ChunkMeshLayer::NoMipMap || layer == ChunkMeshLayer::Flora) ? 0 : Config::mipmapLevels));
if (layer == ChunkMeshLayer::Flora) if (layer == ChunkMeshLayer::Flora || layer == ChunkMeshLayer::Liquid)
glCheck(glDisable(GL_CULL_FACE)); glCheck(glDisable(GL_CULL_FACE));
else else
glCheck(glEnable(GL_CULL_FACE)); glCheck(glEnable(GL_CULL_FACE));

View File

@ -131,13 +131,13 @@ void Skybox::draw(gk::RenderTarget &target, gk::RenderStates states) const {
trans[3].z = SKYBOX_OFFSET_Z; trans[3].z = SKYBOX_OFFSET_Z;
states.transform = trans * states.transform; states.transform = trans * states.transform;
if (m_sun.width() && m_sun.height()) if (m_sun.width() > 0.f && m_sun.height() > 0.f)
target.draw(m_sun, states); target.draw(m_sun, states);
if (m_moon.width() && m_moon.height()) if (m_moon.width() > 0.f && m_moon.height() > 0.f)
target.draw(m_moon, states); target.draw(m_moon, states);
if (Config::isStarRenderingEnabled && skyColor != starColor && m_world.sky()->starsDefinition().size) { if (Config::isStarRenderingEnabled && skyColor != starColor && m_world.sky()->starsDefinition().size > 0.f) {
for (auto &it : m_stars) for (auto &it : m_stars)
target.draw(it, states); target.draw(it, states);
} }

View File

@ -224,7 +224,7 @@ void GameState::draw(gk::RenderTarget &target, gk::RenderStates states) const {
gk::Shader::bind(&m_shader); gk::Shader::bind(&m_shader);
if (m_world.sky()) { if (m_world.sky()) {
if (m_world.sky()->daylightCycleSpeed()) { if (m_world.sky()->daylightCycleSpeed() > 0.f) {
float time = GameTime::getCurrentTime(0, m_world.sky()->daylightCycleSpeed()); float time = GameTime::getCurrentTime(0, m_world.sky()->daylightCycleSpeed());
const gk::Color &color = GameTime::getSkyColorFromTime(*m_world.sky(), time); const gk::Color &color = GameTime::getSkyColorFromTime(*m_world.sky(), time);
glClearColor(color.r, color.g, color.b, color.a); glClearColor(color.r, color.g, color.b, color.a);

View File

@ -424,7 +424,7 @@ inline u8 ChunkMeshBuilder::getLightForVertex(Light light, s8f x, s8f y, s8f z,
getLight(chunk, surroundingBlocks[3].x, surroundingBlocks[3].y, surroundingBlocks[3].z), getLight(chunk, surroundingBlocks[3].x, surroundingBlocks[3].y, surroundingBlocks[3].z),
}; };
float count = 0, total = 0; u8 count = 0, total = 0;
for (u8 i = 0 ; i < 4 ; ++i) { for (u8 i = 0 ; i < 4 ; ++i) {
// Fix light approximation // Fix light approximation
// if (i == 3 && lightValues[i] > lightValues[0] && !lightValues[1] && !lightValues[2]) // if (i == 3 && lightValues[i] > lightValues[0] && !lightValues[1] && !lightValues[2])
@ -433,7 +433,7 @@ inline u8 ChunkMeshBuilder::getLightForVertex(Light light, s8f x, s8f y, s8f z,
// If the chunk is initialized, add the light value to the total // If the chunk is initialized, add the light value to the total
// But only add dark blocks if AO is set on Smooth Lighting // But only add dark blocks if AO is set on Smooth Lighting
if (lightValues[i] != -1 && (Config::ambientOcclusion == 2 || lightValues[i] != 0)) { if (lightValues[i] != -1 && (Config::ambientOcclusion == 2 || lightValues[i] != 0)) {
total += lightValues[i]; total += (u8)lightValues[i];
++count; ++count;
} }
} }

View File

@ -39,9 +39,8 @@ class TextureAtlas;
class ClientChunk : public Chunk { class ClientChunk : public Chunk {
public: public:
ClientChunk(s32 x, s32 y, s32 z, const Dimension &dimension, ClientWorld &world, TextureAtlas &textureAtlas) ClientChunk(s32 x, s32 y, s32 z, const Dimension &dimension, ClientWorld &world)
: Chunk(x, y, z, (World &)world), m_world(world), m_dimension(dimension), : Chunk(x, y, z, (World &)world), m_world(world), m_dimension(dimension) {}
m_textureAtlas(textureAtlas) {}
void update() final; void update() final;
void process() final; void process() final;
@ -79,8 +78,6 @@ class ClientChunk : public Chunk {
const Dimension &m_dimension; const Dimension &m_dimension;
TextureAtlas &m_textureAtlas;
std::array<gk::VertexBuffer, ChunkMeshLayer::Count> m_vbo{}; std::array<gk::VertexBuffer, ChunkMeshLayer::Count> m_vbo{};
std::array<std::size_t, ChunkMeshLayer::Count> m_verticesCount{}; std::array<std::size_t, ChunkMeshLayer::Count> m_verticesCount{};

View File

@ -101,7 +101,7 @@ void ClientWorld::checkPlayerChunk(double playerX, double playerY, double player
ClientChunk *chunk = (ClientChunk *)getChunk(pcx, pcy, pcz); ClientChunk *chunk = (ClientChunk *)getChunk(pcx, pcy, pcz);
if (!chunk) { if (!chunk) {
m_chunks.emplace(gk::Vector3i{pcx, pcy, pcz}, new ClientChunk(pcx, pcy, pcz, *m_dimension, *this, m_textureAtlas)); m_chunks.emplace(gk::Vector3i{pcx, pcy, pcz}, new ClientChunk(pcx, pcy, pcz, *m_dimension, *this));
} }
} }
@ -131,7 +131,7 @@ void ClientWorld::receiveChunkData(Network::Packet &packet) {
// Get the chunk from the map or create it if it doesn't exist // Get the chunk from the map or create it if it doesn't exist
ClientChunk *chunk = (ClientChunk *)getChunk(cx, cy, cz); ClientChunk *chunk = (ClientChunk *)getChunk(cx, cy, cz);
if (!chunk) { if (!chunk) {
auto it = m_chunks.emplace(gk::Vector3i{cx, cy, cz}, new ClientChunk(cx, cy, cz, *m_dimension, *this, m_textureAtlas)); auto it = m_chunks.emplace(gk::Vector3i{cx, cy, cz}, new ClientChunk(cx, cy, cz, *m_dimension, *this));
chunk = it.first->second.get(); chunk = it.first->second.get();
} }

View File

@ -36,6 +36,7 @@ if (NOT MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:DEBUG>:${DEBUG_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:DEBUG>:${DEBUG_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:RELEASE>:${RELEASE_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:RELEASE>:${RELEASE_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:RELWITHDEBINFO>:${RELWITHDEB_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:RELWITHDEBINFO>:${RELWITHDEB_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME} PRIVATE ${CLANG_FLAGS})
endif () endif ()
target_compile_options(${PROJECT_NAME} PRIVATE -DGLM_FORCE_RADIANS) target_compile_options(${PROJECT_NAME} PRIVATE -DGLM_FORCE_RADIANS)

View File

@ -32,10 +32,12 @@ if (NOT MSVC)
target_compile_options(${PROJECT_NAME}_lib PRIVATE "$<$<CONFIG:DEBUG>:${DEBUG_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME}_lib PRIVATE "$<$<CONFIG:DEBUG>:${DEBUG_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME}_lib PRIVATE "$<$<CONFIG:RELEASE>:${RELEASE_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME}_lib PRIVATE "$<$<CONFIG:RELEASE>:${RELEASE_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME}_lib PRIVATE "$<$<CONFIG:RELWITHDEBINFO>:${RELWITHDEB_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME}_lib PRIVATE "$<$<CONFIG:RELWITHDEBINFO>:${RELWITHDEB_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME}_lib PRIVATE ${CLANG_FLAGS})
target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:DEBUG>:${DEBUG_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:DEBUG>:${DEBUG_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:RELEASE>:${RELEASE_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:RELEASE>:${RELEASE_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:RELWITHDEBINFO>:${RELWITHDEB_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$<CONFIG:RELWITHDEBINFO>:${RELWITHDEB_GCC_FLAGS}>")
target_compile_options(${PROJECT_NAME} PRIVATE ${CLANG_FLAGS})
endif () endif ()
target_compile_options(${PROJECT_NAME}_lib PRIVATE -DGLM_FORCE_RADIANS) target_compile_options(${PROJECT_NAME}_lib PRIVATE -DGLM_FORCE_RADIANS)

View File

@ -70,11 +70,11 @@ class ServerApplication {
std::string m_worldName; std::string m_worldName;
WorldController m_worldController{m_registry, m_clock}; WorldController m_worldController{m_registry};
PlayerList m_players; PlayerList m_players;
ScriptEngine m_scriptEngine; ScriptEngine m_scriptEngine;
ServerModLoader m_modLoader{m_scriptEngine, m_registry, m_worldController, m_players}; ServerModLoader m_modLoader{m_scriptEngine, m_worldController};
Server m_server; Server m_server;
ServerCommandHandler m_serverCommandHandler{m_scriptEngine, m_server, m_worldController, m_players, m_registry}; ServerCommandHandler m_serverCommandHandler{m_scriptEngine, m_server, m_worldController, m_players, m_registry};

View File

@ -52,8 +52,8 @@ class WorldController;
// This class is meant to be used ONLY in Lua // This class is meant to be used ONLY in Lua
class LuaMod { class LuaMod {
public: public:
LuaMod(const std::string &id, Registry &registry, WorldController &worldController, PlayerList &players) LuaMod(const std::string &id, WorldController &worldController)
: m_id(id), m_registry(registry), m_worldController(worldController), m_players(players) {} : m_id(id), m_worldController(worldController) {}
void commit(); void commit();
@ -86,10 +86,7 @@ class LuaMod {
std::string m_id; std::string m_id;
// TODO: Add registry instance to loaders in order to avoid using singleton
Registry &m_registry;
WorldController &m_worldController; WorldController &m_worldController;
PlayerList &m_players;
LuaBlockLoader m_blockLoader{*this}; LuaBlockLoader m_blockLoader{*this};
LuaItemLoader m_itemLoader{*this}; LuaItemLoader m_itemLoader{*this};

View File

@ -202,7 +202,7 @@ LuaMod &ServerModLoader::registerMod(const std::string &name) {
m_mods.emplace( m_mods.emplace(
std::piecewise_construct, std::piecewise_construct,
std::forward_as_tuple(name), std::forward_as_tuple(name),
std::forward_as_tuple(name, m_registry, m_worldController, m_players) std::forward_as_tuple(name, m_worldController)
); );
return m_mods.at(name); return m_mods.at(name);

View File

@ -39,8 +39,8 @@ class WorldController;
class ServerModLoader { class ServerModLoader {
public: public:
ServerModLoader(ScriptEngine &scriptEngine, Registry &registry, WorldController &worldController, PlayerList &players) ServerModLoader(ScriptEngine &scriptEngine, WorldController &worldController)
: m_scriptEngine(scriptEngine), m_registry(registry), m_worldController(worldController), m_players(players) {} : m_scriptEngine(scriptEngine), m_worldController(worldController) {}
void loadMods(); void loadMods();
@ -50,9 +50,7 @@ class ServerModLoader {
private: private:
ScriptEngine &m_scriptEngine; ScriptEngine &m_scriptEngine;
Registry &m_registry;
WorldController &m_worldController; WorldController &m_worldController;
PlayerList &m_players;
std::unordered_map<std::string, LuaMod> m_mods; std::unordered_map<std::string, LuaMod> m_mods;
}; };

View File

@ -105,7 +105,7 @@ inline void LuaBlockLoader::loadProperties(BlockState &state, const sol::table &
if (table["fog_depth"].get_type() == sol::type::number) if (table["fog_depth"].get_type() == sol::type::number)
state.fogDepth(table["fog_depth"].get<float>()); state.fogDepth(table["fog_depth"].get<float>());
if (state.fogDepth()) { if (state.fogDepth() > 0.f) {
sol::optional<sol::table> fogColor = table["fog_color"]; sol::optional<sol::table> fogColor = table["fog_color"];
if (fogColor != sol::nullopt) { if (fogColor != sol::nullopt) {
state.fogColor(gk::Color::fromRGBA32( state.fogColor(gk::Color::fromRGBA32(

View File

@ -39,8 +39,8 @@ class ChatCommandHandler {
using CommandCallback = void (ChatCommandHandler::*)(const std::vector<std::string> &command, ClientInfo &client) const; using CommandCallback = void (ChatCommandHandler::*)(const std::vector<std::string> &command, ClientInfo &client) const;
public: public:
ChatCommandHandler(ServerCommandHandler &server, WorldController &worldController) ChatCommandHandler(ServerCommandHandler &server)
: m_server(server), m_worldController(worldController) {} : m_server(server) {}
void parseCommand(const std::string &str, ClientInfo &client) const; void parseCommand(const std::string &str, ClientInfo &client) const;
@ -53,7 +53,6 @@ class ChatCommandHandler {
void tpsCommand(const std::vector<std::string> &command, ClientInfo &client) const; void tpsCommand(const std::vector<std::string> &command, ClientInfo &client) const;
ServerCommandHandler &m_server; ServerCommandHandler &m_server;
WorldController &m_worldController;
std::map<std::string, CommandCallback> m_commands = { std::map<std::string, CommandCallback> m_commands = {
{"help", &ChatCommandHandler::helpCommand}, {"help", &ChatCommandHandler::helpCommand},

View File

@ -95,7 +95,7 @@ class ServerCommandHandler {
Registry &m_registry; Registry &m_registry;
ChatCommandHandler m_chatCommandHandler{*this, m_worldController}; ChatCommandHandler m_chatCommandHandler{*this};
}; };
#endif // SERVERCOMMANDHANDLER_HPP_ #endif // SERVERCOMMANDHANDLER_HPP_

View File

@ -36,12 +36,11 @@
#include "ServerPlayer.hpp" #include "ServerPlayer.hpp"
#include "ServerWorld.hpp" #include "ServerWorld.hpp"
ServerWorld::ServerWorld(PlayerList &players, const Dimension &dimension, gk::GameClock &clock, s32 seed) ServerWorld::ServerWorld(PlayerList &players, const Dimension &dimension, s32 seed)
: m_players(players), : m_players(players),
m_dimension(dimension), m_dimension(dimension),
m_heightmap(seed), m_heightmap(seed),
m_terrainGenerator(m_heightmap, dimension, seed), m_terrainGenerator(m_heightmap, dimension, seed),
m_clock(clock),
m_scene(players), m_scene(players),
m_seed(seed) m_seed(seed)
{ {

View File

@ -48,7 +48,7 @@ class ServerWorld : public World {
using ChunkMap = std::unordered_map<gk::Vector3i, std::unique_ptr<ServerChunk>>; using ChunkMap = std::unordered_map<gk::Vector3i, std::unique_ptr<ServerChunk>>;
public: public:
ServerWorld(PlayerList &players, const Dimension &dimension, gk::GameClock &clock, s32 seed); ServerWorld(PlayerList &players, const Dimension &dimension, s32 seed);
void update(bool doTick); void update(bool doTick);
@ -91,8 +91,6 @@ class ServerWorld : public World {
ServerCommandHandler *m_server = nullptr; ServerCommandHandler *m_server = nullptr;
gk::GameClock &m_clock;
ServerScene m_scene; ServerScene m_scene;
s32 m_seed = 0; s32 m_seed = 0;

View File

@ -30,7 +30,7 @@
void WorldController::init(PlayerList &players, s32 seed) { void WorldController::init(PlayerList &players, s32 seed) {
for (const Dimension &dimension : m_registry.dimensions()) { for (const Dimension &dimension : m_registry.dimensions()) {
m_worldList.emplace_back(players, dimension, m_clock, seed); m_worldList.emplace_back(players, dimension, seed);
m_worldList.back().setServer(m_server); m_worldList.back().setServer(m_server);
} }

View File

@ -32,16 +32,11 @@
#include "ServerWorld.hpp" #include "ServerWorld.hpp"
#include "WorldSaveBackend.hpp" #include "WorldSaveBackend.hpp"
namespace gk {
class GameClock;
}
class Registry; class Registry;
class WorldController { class WorldController {
public: public:
WorldController(Registry &registry, gk::GameClock &clock) WorldController(Registry &registry) : m_registry(registry) {}
: m_registry(registry), m_clock(clock) {}
void init(PlayerList &players, s32 seed); void init(PlayerList &players, s32 seed);
@ -62,8 +57,6 @@ class WorldController {
Registry &m_registry; Registry &m_registry;
gk::GameClock &m_clock;
ServerCommandHandler *m_server = nullptr; ServerCommandHandler *m_server = nullptr;
std::unique_ptr<WorldSaveBackend> m_worldSaveBackend{nullptr}; std::unique_ptr<WorldSaveBackend> m_worldSaveBackend{nullptr};