From a08af1b2606387a9cad300d331111f5ff8673e69 Mon Sep 17 00:00:00 2001 From: Auri Date: Fri, 3 Sep 2021 14:22:58 -0700 Subject: [PATCH] Bump to C++ 20 --- .idea/vcs.xml | 30 ------------------------ CMakeLists.txt | 2 +- src/client/Callback.h | 2 +- src/client/scene/MainMenuScene.cpp | 10 ++++---- src/game/atlas/LocalDefinitionAtlas.cpp | 4 ++-- src/game/atlas/ServerDefinitionAtlas.cpp | 4 ++-- src/game/def/BlockDef.h | 2 +- src/game/def/CraftItemDef.cpp | 2 +- src/game/def/CraftItemDef.h | 2 +- src/game/def/ItemDef.h | 16 +++++++------ src/lua/register/RegisterBlock.h | 2 +- src/world/inv/InventoryList.cpp | 6 ++--- 12 files changed, 26 insertions(+), 56 deletions(-) diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 57bf306a..94a25f7f 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,35 +2,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 053720bd..675ff5a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.19) cmake_policy(SET CMP0077 NEW) # set() overrides option() -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/src/client/Callback.h b/src/client/Callback.h index 7170ef88..88230440 100644 --- a/src/client/Callback.h +++ b/src/client/Callback.h @@ -36,7 +36,7 @@ public: CallbackRef bind(const CB_TYPE& cb) { usize cID = next++; callbacks.emplace(cID, InvalidatableCB(cb)); - return CallbackRef([=]() { unbind(cID); }); + return CallbackRef([cID, this]() { unbind(cID); }); }; void unbind(usize ind) { diff --git a/src/client/scene/MainMenuScene.cpp b/src/client/scene/MainMenuScene.cpp index 7775b313..feba8df8 100644 --- a/src/client/scene/MainMenuScene.cpp +++ b/src/client/scene/MainMenuScene.cpp @@ -153,12 +153,10 @@ void MainMenuScene::findSubgames() { } cf_dir_close(&subgame); - if (!hasConf) - throw std::runtime_error( - string("Subgame ") + string(subgameFolder.name) + " is missing a conf.json."); - if (!hasMods) - throw std::runtime_error( - string("Subgame ") + string(subgameFolder.name) + " is missing a 'mods' directory."); + if (!hasConf) throw std::runtime_error( + string("Subgame ") + string(subgameFolder.name) + " is missing a conf.json."); + if (!hasMods) throw std::runtime_error( + string("Subgame ") + string(subgameFolder.name) + " is missing a 'mods' directory."); nlohmann::json j{}; try { diff --git a/src/game/atlas/LocalDefinitionAtlas.cpp b/src/game/atlas/LocalDefinitionAtlas.cpp index a8445106..d13bd4f5 100644 --- a/src/game/atlas/LocalDefinitionAtlas.cpp +++ b/src/game/atlas/LocalDefinitionAtlas.cpp @@ -13,7 +13,7 @@ LocalDefinitionAtlas::LocalDefinitionAtlas(TextureAtlas& atlas) { BlockDef* invalid = new BlockDef(); invalid->identifier = "invalid"; invalid->name = "INVALID"; - invalid->maxStackSize = 64; + invalid->maxStack = 64; invalid->model = invalidModel; invalid->farModel = invalidModel; invalid->sBoxes = {{{ 0, 0, 0 }, { 1, 1, 1 }}}; @@ -28,7 +28,7 @@ LocalDefinitionAtlas::LocalDefinitionAtlas(TextureAtlas& atlas) { air->identifier = "air"; air->index = 1; air->name = "Air"; - air->maxStackSize = 64; + air->maxStack = 64; air->model = nullModel; air->farModel = nullModel; air->solid = false; diff --git a/src/game/atlas/ServerDefinitionAtlas.cpp b/src/game/atlas/ServerDefinitionAtlas.cpp index 633d1311..535cd5c4 100644 --- a/src/game/atlas/ServerDefinitionAtlas.cpp +++ b/src/game/atlas/ServerDefinitionAtlas.cpp @@ -12,7 +12,7 @@ ServerDefinitionAtlas::ServerDefinitionAtlas() { BlockDef* invalid = new BlockDef(); invalid->identifier = "invalid"; invalid->name = "INVALID"; - invalid->maxStackSize = 64; + invalid->maxStack = 64; invalid->model = invalidModel; invalid->farModel = invalidModel; invalid->sBoxes = {{{ 0, 0, 0 }, { 1, 1, 1 }}}; @@ -26,7 +26,7 @@ ServerDefinitionAtlas::ServerDefinitionAtlas() { air->identifier = "air"; air->index = 1; air->name = "Air"; - air->maxStackSize = 64; + air->maxStack = 64; air->model = nullModel; air->farModel = nullModel; air->solid = false; diff --git a/src/game/def/BlockDef.h b/src/game/def/BlockDef.h index edc1c7a5..2d99da6f 100644 --- a/src/game/def/BlockDef.h +++ b/src/game/def/BlockDef.h @@ -30,7 +30,7 @@ public: HIT, HIT_CLIENT }; - BlockDef() : ItemDef{ "", "", 0, 0, ItemDef::Type::BLOCK } {}; + BlockDef() : ItemDef(ItemDef::Type::BLOCK) {}; void createModel(); diff --git a/src/game/def/CraftItemDef.cpp b/src/game/def/CraftItemDef.cpp index 16575243..98ec0a8e 100644 --- a/src/game/def/CraftItemDef.cpp +++ b/src/game/def/CraftItemDef.cpp @@ -15,7 +15,7 @@ CraftItemDef::CraftItemDef(const std::string& identifier, unsigned int index, co unsigned short maxStackSize, const std::vector& textures, const std::vector>& textureRefs) : - ItemDef{ identifier, name, index, maxStackSize, ItemDef::Type::CRAFTITEM }, + ItemDef(ItemDef::Type::CRAFTITEM, identifier, name, index, maxStackSize), textures(textures), textureRefs(textureRefs) {} diff --git a/src/game/def/CraftItemDef.h b/src/game/def/CraftItemDef.h index 9d610621..ef10014b 100644 --- a/src/game/def/CraftItemDef.h +++ b/src/game/def/CraftItemDef.h @@ -20,7 +20,7 @@ public: HIT, HIT_CLIENT }; - CraftItemDef() : ItemDef{ "", "", 0, 0, ItemDef::Type::CRAFTITEM } {}; + CraftItemDef(): ItemDef(ItemDef::Type::CRAFTITEM) {}; CraftItemDef(const std::string& identifier, const std::string& name, unsigned short maxStackSize, const std::vector& textures, const std::vector>& textureRefs); diff --git a/src/game/def/ItemDef.h b/src/game/def/ItemDef.h index 1e3d194a..f3fa529c 100644 --- a/src/game/def/ItemDef.h +++ b/src/game/def/ItemDef.h @@ -11,22 +11,24 @@ class ItemDef { public: - ItemDef(const ItemDef& o) = delete; - enum class Type { INVALID, BLOCK, CRAFTITEM }; - std::string identifier = ""; - std::string name = ""; - unsigned int index = 0; + ItemDef(const ItemDef& o) = delete; + ItemDef(Type type): type(type) {} + ItemDef(Type type, string identifier, string name, u16 index, u16 maxStack): + type(type), identifier(identifier), name(name), index(index), maxStack(maxStack) {} - unsigned short maxStackSize; + string identifier {}; + string name {}; + u16 index = 0; + u16 maxStack = 0; Type type = Type::INVALID; - std::shared_ptr entityModel = std::make_shared(); + sptr entityModel = make_shared(); }; diff --git a/src/lua/register/RegisterBlock.h b/src/lua/register/RegisterBlock.h index bc8f0454..250e5699 100644 --- a/src/lua/register/RegisterBlock.h +++ b/src/lua/register/RegisterBlock.h @@ -375,7 +375,7 @@ namespace RegisterBlock { def->health = health; def->defense = defense; - def->maxStackSize = maxStack; + def->maxStack = maxStack; def->model = models.first; def->farModel = models.second; diff --git a/src/world/inv/InventoryList.cpp b/src/world/inv/InventoryList.cpp index a7005392..1757b2ae 100644 --- a/src/world/inv/InventoryList.cpp +++ b/src/world/inv/InventoryList.cpp @@ -67,7 +67,7 @@ ItemStack InventoryList::placeStack(unsigned short i, const ItemStack& stack, bo else { if (otherStack.count) { if (otherStack.id == stack.id) { - unsigned short maxStack = game->getDefs().fromId(stack.id).maxStackSize; + unsigned short maxStack = game->getDefs().fromId(stack.id).maxStack; if (allowedPut >= stack.count && allowedPut + otherStack.count < maxStack) { setStack(i, { stack.id, static_cast(otherStack.count + allowedPut) }); // if (on_put) on_put(i+1, LuaItemStack(otherStack, defs)); @@ -126,7 +126,7 @@ ItemStack InventoryList::splitStack(unsigned short i, bool playerInitiated) { } ItemStack InventoryList::addStack(ItemStack stack, bool playerInitiated) { - unsigned short maxStack = game->getDefs().fromId(stack.id).maxStackSize; + unsigned short maxStack = game->getDefs().fromId(stack.id).maxStack; unsigned short i = 0; while (i < items.size() && stack.count > 0) { @@ -162,7 +162,7 @@ ItemStack InventoryList::addStack(ItemStack stack, bool playerInitiated) { } unsigned short InventoryList::stackFits(const ItemStack& stack) { - unsigned short maxStack = game->getDefs().fromId(stack.id).maxStackSize; + unsigned short maxStack = game->getDefs().fromId(stack.id).maxStack; unsigned short i = 0; unsigned short fits = 0;