diff --git a/.gitignore b/.gitignore index 20366758..e604746b 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,7 @@ build_win32 build_win64 build_msvc build_mingw +build_clang build_debug deploy openminer diff --git a/CMakeLists.txt b/CMakeLists.txt index fae0342b..adc34ea8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,14 @@ set(RELWITHDEB_GCC_FLAGS -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) #------------------------------------------------------------------------------ diff --git a/external/gamekit b/external/gamekit index 1de5e4c3..d770f489 160000 --- a/external/gamekit +++ b/external/gamekit @@ -1 +1 @@ -Subproject commit 1de5e4c3fe1ee4694bbee3acf86f72633018bc53 +Subproject commit d770f48928abaacd23f186c307a865688d7edb50 diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index fda5d3a6..cef0fb4b 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -27,6 +27,7 @@ if (NOT MSVC) target_compile_options(${PROJECT_NAME} PRIVATE "$<$:${DEBUG_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$:${RELEASE_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$:${RELWITHDEB_GCC_FLAGS}>") + target_compile_options(${PROJECT_NAME} PRIVATE ${CLANG_FLAGS}) endif () target_compile_options(${PROJECT_NAME} PRIVATE -DGLM_FORCE_RADIANS) diff --git a/source/client/graphics/CelestialObject.cpp b/source/client/graphics/CelestialObject.cpp index 49e3c8c3..8599e102 100644 --- a/source/client/graphics/CelestialObject.cpp +++ b/source/client/graphics/CelestialObject.cpp @@ -43,8 +43,8 @@ void CelestialObject::setTexture(const std::string &textureName) { } void CelestialObject::updateVertexBuffer() const { - if (!m_width || !m_height) { - gkError() << "Can't update vertex buffer for celestial object of size 0"; + if (m_width <= 0.f || m_height <= 0.f) { + gkError() << "Trying to update vertex buffer for celestial object of invalid size"; return; } diff --git a/source/client/graphics/ChunkRenderer.cpp b/source/client/graphics/ChunkRenderer.cpp index ba287716..9cbbe75f 100644 --- a/source/client/graphics/ChunkRenderer.cpp +++ b/source/client/graphics/ChunkRenderer.cpp @@ -44,7 +44,7 @@ void ChunkRenderer::draw(gk::RenderTarget &target, gk::RenderStates states, cons glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, (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)); else glCheck(glEnable(GL_CULL_FACE)); diff --git a/source/client/graphics/Skybox.cpp b/source/client/graphics/Skybox.cpp index 4c2e239b..b5a2ad32 100644 --- a/source/client/graphics/Skybox.cpp +++ b/source/client/graphics/Skybox.cpp @@ -131,13 +131,13 @@ void Skybox::draw(gk::RenderTarget &target, gk::RenderStates states) const { trans[3].z = SKYBOX_OFFSET_Z; 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); - if (m_moon.width() && m_moon.height()) + if (m_moon.width() > 0.f && m_moon.height() > 0.f) 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) target.draw(it, states); } diff --git a/source/client/states/GameState.cpp b/source/client/states/GameState.cpp index 53dfe8b6..f83a3090 100644 --- a/source/client/states/GameState.cpp +++ b/source/client/states/GameState.cpp @@ -224,7 +224,7 @@ void GameState::draw(gk::RenderTarget &target, gk::RenderStates states) const { gk::Shader::bind(&m_shader); 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()); const gk::Color &color = GameTime::getSkyColorFromTime(*m_world.sky(), time); glClearColor(color.r, color.g, color.b, color.a); diff --git a/source/client/world/ChunkMeshBuilder.cpp b/source/client/world/ChunkMeshBuilder.cpp index 93aff838..510d3648 100644 --- a/source/client/world/ChunkMeshBuilder.cpp +++ b/source/client/world/ChunkMeshBuilder.cpp @@ -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), }; - float count = 0, total = 0; + u8 count = 0, total = 0; for (u8 i = 0 ; i < 4 ; ++i) { // Fix light approximation // 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 // But only add dark blocks if AO is set on Smooth Lighting if (lightValues[i] != -1 && (Config::ambientOcclusion == 2 || lightValues[i] != 0)) { - total += lightValues[i]; + total += (u8)lightValues[i]; ++count; } } diff --git a/source/client/world/ClientChunk.hpp b/source/client/world/ClientChunk.hpp index 7a89d367..ab04f7f2 100644 --- a/source/client/world/ClientChunk.hpp +++ b/source/client/world/ClientChunk.hpp @@ -39,9 +39,8 @@ class TextureAtlas; class ClientChunk : public Chunk { public: - ClientChunk(s32 x, s32 y, s32 z, const Dimension &dimension, ClientWorld &world, TextureAtlas &textureAtlas) - : Chunk(x, y, z, (World &)world), m_world(world), m_dimension(dimension), - m_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) {} void update() final; void process() final; @@ -79,8 +78,6 @@ class ClientChunk : public Chunk { const Dimension &m_dimension; - TextureAtlas &m_textureAtlas; - std::array m_vbo{}; std::array m_verticesCount{}; diff --git a/source/client/world/ClientWorld.cpp b/source/client/world/ClientWorld.cpp index 12368d3b..3d607869 100644 --- a/source/client/world/ClientWorld.cpp +++ b/source/client/world/ClientWorld.cpp @@ -101,7 +101,7 @@ void ClientWorld::checkPlayerChunk(double playerX, double playerY, double player ClientChunk *chunk = (ClientChunk *)getChunk(pcx, pcy, pcz); 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 ClientChunk *chunk = (ClientChunk *)getChunk(cx, cy, cz); 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(); } diff --git a/source/common/CMakeLists.txt b/source/common/CMakeLists.txt index 9886489b..bfba82b3 100644 --- a/source/common/CMakeLists.txt +++ b/source/common/CMakeLists.txt @@ -36,6 +36,7 @@ if (NOT MSVC) target_compile_options(${PROJECT_NAME} PRIVATE "$<$:${DEBUG_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$:${RELEASE_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$:${RELWITHDEB_GCC_FLAGS}>") + target_compile_options(${PROJECT_NAME} PRIVATE ${CLANG_FLAGS}) endif () target_compile_options(${PROJECT_NAME} PRIVATE -DGLM_FORCE_RADIANS) diff --git a/source/server/CMakeLists.txt b/source/server/CMakeLists.txt index b77e5d9f..e7b327bb 100644 --- a/source/server/CMakeLists.txt +++ b/source/server/CMakeLists.txt @@ -32,10 +32,12 @@ if (NOT MSVC) target_compile_options(${PROJECT_NAME}_lib PRIVATE "$<$:${DEBUG_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME}_lib PRIVATE "$<$:${RELEASE_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME}_lib PRIVATE "$<$:${RELWITHDEB_GCC_FLAGS}>") + target_compile_options(${PROJECT_NAME}_lib PRIVATE ${CLANG_FLAGS}) target_compile_options(${PROJECT_NAME} PRIVATE "$<$:${DEBUG_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$:${RELEASE_GCC_FLAGS}>") target_compile_options(${PROJECT_NAME} PRIVATE "$<$:${RELWITHDEB_GCC_FLAGS}>") + target_compile_options(${PROJECT_NAME} PRIVATE ${CLANG_FLAGS}) endif () target_compile_options(${PROJECT_NAME}_lib PRIVATE -DGLM_FORCE_RADIANS) diff --git a/source/server/core/ServerApplication.hpp b/source/server/core/ServerApplication.hpp index 50dca075..f2cf601a 100644 --- a/source/server/core/ServerApplication.hpp +++ b/source/server/core/ServerApplication.hpp @@ -70,11 +70,11 @@ class ServerApplication { std::string m_worldName; - WorldController m_worldController{m_registry, m_clock}; + WorldController m_worldController{m_registry}; PlayerList m_players; ScriptEngine m_scriptEngine; - ServerModLoader m_modLoader{m_scriptEngine, m_registry, m_worldController, m_players}; + ServerModLoader m_modLoader{m_scriptEngine, m_worldController}; Server m_server; ServerCommandHandler m_serverCommandHandler{m_scriptEngine, m_server, m_worldController, m_players, m_registry}; diff --git a/source/server/lua/LuaMod.hpp b/source/server/lua/LuaMod.hpp index a861e436..2c524b5b 100644 --- a/source/server/lua/LuaMod.hpp +++ b/source/server/lua/LuaMod.hpp @@ -52,8 +52,8 @@ class WorldController; // This class is meant to be used ONLY in Lua class LuaMod { public: - LuaMod(const std::string &id, Registry ®istry, WorldController &worldController, PlayerList &players) - : m_id(id), m_registry(registry), m_worldController(worldController), m_players(players) {} + LuaMod(const std::string &id, WorldController &worldController) + : m_id(id), m_worldController(worldController) {} void commit(); @@ -86,10 +86,7 @@ class LuaMod { std::string m_id; - // TODO: Add registry instance to loaders in order to avoid using singleton - Registry &m_registry; WorldController &m_worldController; - PlayerList &m_players; LuaBlockLoader m_blockLoader{*this}; LuaItemLoader m_itemLoader{*this}; diff --git a/source/server/lua/ServerModLoader.cpp b/source/server/lua/ServerModLoader.cpp index b3bd9bbd..436f5651 100644 --- a/source/server/lua/ServerModLoader.cpp +++ b/source/server/lua/ServerModLoader.cpp @@ -202,7 +202,7 @@ LuaMod &ServerModLoader::registerMod(const std::string &name) { m_mods.emplace( std::piecewise_construct, 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); diff --git a/source/server/lua/ServerModLoader.hpp b/source/server/lua/ServerModLoader.hpp index 9c639bfd..e935c66f 100644 --- a/source/server/lua/ServerModLoader.hpp +++ b/source/server/lua/ServerModLoader.hpp @@ -39,8 +39,8 @@ class WorldController; class ServerModLoader { public: - ServerModLoader(ScriptEngine &scriptEngine, Registry ®istry, WorldController &worldController, PlayerList &players) - : m_scriptEngine(scriptEngine), m_registry(registry), m_worldController(worldController), m_players(players) {} + ServerModLoader(ScriptEngine &scriptEngine, WorldController &worldController) + : m_scriptEngine(scriptEngine), m_worldController(worldController) {} void loadMods(); @@ -50,9 +50,7 @@ class ServerModLoader { private: ScriptEngine &m_scriptEngine; - Registry &m_registry; WorldController &m_worldController; - PlayerList &m_players; std::unordered_map m_mods; }; diff --git a/source/server/lua/loader/LuaBlockLoader.cpp b/source/server/lua/loader/LuaBlockLoader.cpp index 0d3fabb3..b6f01fdd 100644 --- a/source/server/lua/loader/LuaBlockLoader.cpp +++ b/source/server/lua/loader/LuaBlockLoader.cpp @@ -105,7 +105,7 @@ inline void LuaBlockLoader::loadProperties(BlockState &state, const sol::table & if (table["fog_depth"].get_type() == sol::type::number) state.fogDepth(table["fog_depth"].get()); - if (state.fogDepth()) { + if (state.fogDepth() > 0.f) { sol::optional fogColor = table["fog_color"]; if (fogColor != sol::nullopt) { state.fogColor(gk::Color::fromRGBA32( diff --git a/source/server/network/ChatCommandHandler.hpp b/source/server/network/ChatCommandHandler.hpp index 023095c8..c799e85d 100644 --- a/source/server/network/ChatCommandHandler.hpp +++ b/source/server/network/ChatCommandHandler.hpp @@ -39,8 +39,8 @@ class ChatCommandHandler { using CommandCallback = void (ChatCommandHandler::*)(const std::vector &command, ClientInfo &client) const; public: - ChatCommandHandler(ServerCommandHandler &server, WorldController &worldController) - : m_server(server), m_worldController(worldController) {} + ChatCommandHandler(ServerCommandHandler &server) + : m_server(server) {} void parseCommand(const std::string &str, ClientInfo &client) const; @@ -53,7 +53,6 @@ class ChatCommandHandler { void tpsCommand(const std::vector &command, ClientInfo &client) const; ServerCommandHandler &m_server; - WorldController &m_worldController; std::map m_commands = { {"help", &ChatCommandHandler::helpCommand}, diff --git a/source/server/network/ServerCommandHandler.hpp b/source/server/network/ServerCommandHandler.hpp index adf24061..4e30a7a3 100644 --- a/source/server/network/ServerCommandHandler.hpp +++ b/source/server/network/ServerCommandHandler.hpp @@ -95,7 +95,7 @@ class ServerCommandHandler { Registry &m_registry; - ChatCommandHandler m_chatCommandHandler{*this, m_worldController}; + ChatCommandHandler m_chatCommandHandler{*this}; }; #endif // SERVERCOMMANDHANDLER_HPP_ diff --git a/source/server/world/ServerWorld.cpp b/source/server/world/ServerWorld.cpp index ba6d28a8..8cf5311f 100644 --- a/source/server/world/ServerWorld.cpp +++ b/source/server/world/ServerWorld.cpp @@ -36,12 +36,11 @@ #include "ServerPlayer.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_dimension(dimension), m_heightmap(seed), m_terrainGenerator(m_heightmap, dimension, seed), - m_clock(clock), m_scene(players), m_seed(seed) { diff --git a/source/server/world/ServerWorld.hpp b/source/server/world/ServerWorld.hpp index 480761ae..d975d3a2 100644 --- a/source/server/world/ServerWorld.hpp +++ b/source/server/world/ServerWorld.hpp @@ -48,7 +48,7 @@ class ServerWorld : public World { using ChunkMap = std::unordered_map>; public: - ServerWorld(PlayerList &players, const Dimension &dimension, gk::GameClock &clock, s32 seed); + ServerWorld(PlayerList &players, const Dimension &dimension, s32 seed); void update(bool doTick); @@ -91,8 +91,6 @@ class ServerWorld : public World { ServerCommandHandler *m_server = nullptr; - gk::GameClock &m_clock; - ServerScene m_scene; s32 m_seed = 0; diff --git a/source/server/world/WorldController.cpp b/source/server/world/WorldController.cpp index ddf9b1ce..c9e2fc36 100644 --- a/source/server/world/WorldController.cpp +++ b/source/server/world/WorldController.cpp @@ -30,7 +30,7 @@ void WorldController::init(PlayerList &players, s32 seed) { 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); } diff --git a/source/server/world/WorldController.hpp b/source/server/world/WorldController.hpp index 29650136..8c754e22 100644 --- a/source/server/world/WorldController.hpp +++ b/source/server/world/WorldController.hpp @@ -32,16 +32,11 @@ #include "ServerWorld.hpp" #include "WorldSaveBackend.hpp" -namespace gk { - class GameClock; -} - class Registry; class WorldController { public: - WorldController(Registry ®istry, gk::GameClock &clock) - : m_registry(registry), m_clock(clock) {} + WorldController(Registry ®istry) : m_registry(registry) {} void init(PlayerList &players, s32 seed); @@ -62,8 +57,6 @@ class WorldController { Registry &m_registry; - gk::GameClock &m_clock; - ServerCommandHandler *m_server = nullptr; std::unique_ptr m_worldSaveBackend{nullptr};