From b26126e0fba77b51a3877e0b54061e8a920ce9aa Mon Sep 17 00:00:00 2001 From: Auri Date: Thu, 23 Sep 2021 23:16:23 -0700 Subject: [PATCH] Remove cute_headers --- .gitmodules | 4 - CMakeLists.txt | 2 +- lib/CMakeLists.txt | 10 -- lib/cute_headers | 1 - src/Main.cpp | 2 - src/client/Client.cpp | 7 +- src/client/menu/MenuSandbox.cpp | 4 +- src/client/scene/ConnectScene.cpp | 1 - src/client/scene/LuaErrorScene.cpp | 1 - src/client/scene/MainMenuScene.cpp | 117 ++++++------------ src/client/scene/MainMenuScene.h | 5 +- src/game/LocalSubgame.cpp | 1 - src/game/ServerSubgame.cpp | 10 +- src/game/ServerSubgame.h | 2 +- src/game/atlas/TextureAtlas.cpp | 25 +--- src/game/atlas/TextureAtlas.h | 2 +- src/lua/Mod.cpp | 1 - src/world/dim/file/FileManipulator.cpp | 3 +- src/world/dim/file/FileManipulator.h | 1 - .../mods/zeus_world/script/biomes/plains.lua | 4 +- 20 files changed, 57 insertions(+), 146 deletions(-) delete mode 160000 lib/cute_headers diff --git a/.gitmodules b/.gitmodules index cb5ffd71..dd828762 100644 --- a/.gitmodules +++ b/.gitmodules @@ -37,10 +37,6 @@ path = lib/gzip-hpp url = git@github.com:mapbox/gzip-hpp.git branch = master -[submodule "cute_headers"] - path = lib/cute_headers - url = git@github.com:RandyGaul/cute_headers.git - branch = master [submodule "FastNoise2"] path = lib/FastNoise2 url = git@github.com:Auburn/FastNoise2.git diff --git a/CMakeLists.txt b/CMakeLists.txt index c0eeff9c..ef19280c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ add_executable(${MAIN_EXEC_NAME} ${SOURCE_FILES}) target_include_directories(${MAIN_EXEC_NAME} PUBLIC src) -target_link_libraries(${MAIN_EXEC_NAME} PUBLIC glfw glm enet glad assimp FastNoise nothings-stb gzip cute_headers nlohmann_json stdc++fs) +target_link_libraries(${MAIN_EXEC_NAME} PUBLIC glfw glm enet glad assimp FastNoise nothings-stb gzip nlohmann_json stdc++fs) target_link_libraries(${MAIN_EXEC_NAME} PUBLIC lua sol2) if(WIN32) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index c6b9eeef..4b21852a 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -204,16 +204,6 @@ if(NOT TARGET gzip) target_include_directories(gzip INTERFACE gzip-hpp/include) endif() -#------------------------------ -# cute_headers -# Collection of cross-platform one-file C/C++ libraries with no dependencies, primarily used for games -#------------------------------ -if(NOT TARGET cute_headers) - project(cute_headers) - add_library(cute_headers INTERFACE) - target_include_directories(cute_headers INTERFACE cute_headers) -endif() - #-------------------------------- # nlohmann JSON # JSON for Modern C++ diff --git a/lib/cute_headers b/lib/cute_headers deleted file mode 160000 index 2daadfc0..00000000 --- a/lib/cute_headers +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2daadfc0b64491c040d5b9cb011b38dd8d768b6d diff --git a/src/Main.cpp b/src/Main.cpp index cdc002e7..6b882425 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -3,11 +3,9 @@ #pragma ide diagnostic ignored "OCUnusedMacroInspection" #define STB_IMAGE_IMPLEMENTATION -#define CUTE_FILES_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION #include -#include #pragma clang diagnostic pop diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 2461c9f4..18433e48 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -1,13 +1,8 @@ - #include #include "Client.h" -//#include "LocalServerInstance.h" - #include "util/Types.h" -#include "util/Timer.h" -//#include "scene/GameScene.h" #include "scene/ConnectScene.h" #include "scene/MainMenuScene.h" @@ -44,5 +39,7 @@ void Client::loop() { scene.update(); renderer.update(delta); + game->textures.update(); + renderer.swapBuffers(); } \ No newline at end of file diff --git a/src/client/menu/MenuSandbox.cpp b/src/client/menu/MenuSandbox.cpp index 4707d0ca..7e8c44f0 100644 --- a/src/client/menu/MenuSandbox.cpp +++ b/src/client/menu/MenuSandbox.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include "MenuSandbox.h" @@ -114,7 +113,6 @@ sol::protected_function_result MenuSandbox::require(sol::this_environment thisEn } sol::protected_function_result MenuSandbox::loadFile(const string& path) { - std::cout << "load " << path << std::endl; let it = mod.files.find(path); if (it == mod.files.end()) throw sol::error("Error opening '" + path + "', file not found."); let& file = it->second; @@ -134,7 +132,7 @@ void MenuSandbox::loadMod(const std::filesystem::path& path) { mod = { path, true }; if (std::filesystem::exists(path / "textures")) - menuAssets = client.game->textures.loadDirectory((path / "textures").string(), false, true); + menuAssets = client.game->textures.loadDirectory((path / "textures").string(), false); loadFile("/main"); } diff --git a/src/client/scene/ConnectScene.cpp b/src/client/scene/ConnectScene.cpp index b1b6e756..942e3cde 100644 --- a/src/client/scene/ConnectScene.cpp +++ b/src/client/scene/ConnectScene.cpp @@ -30,7 +30,6 @@ ConnectScene::ConnectScene(Client& client, Address addr) : Scene(client), } void ConnectScene::update() { - client.game->textures.update(); root.update(); switch (state) { diff --git a/src/client/scene/LuaErrorScene.cpp b/src/client/scene/LuaErrorScene.cpp index d92a4b4a..92f551bb 100644 --- a/src/client/scene/LuaErrorScene.cpp +++ b/src/client/scene/LuaErrorScene.cpp @@ -27,7 +27,6 @@ LuaErrorScene::LuaErrorScene(Client& client, const std::string& err) : Scene(cli } void LuaErrorScene::update() { - client.game->textures.update(); root.update(); } diff --git a/src/client/scene/MainMenuScene.cpp b/src/client/scene/MainMenuScene.cpp index feba8df8..782a9c6f 100644 --- a/src/client/scene/MainMenuScene.cpp +++ b/src/client/scene/MainMenuScene.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include "MainMenuScene.h" @@ -79,8 +78,46 @@ MainMenuScene::MainMenuScene(Client& client) : Scene(client), { Gui::Prop::SIZE, array { Expr("1dp"), Expr("10dp") } }, { Gui::Prop::MARGIN, array { Expr("2dp"), Expr("3dp"), Expr("2dp"), Expr("3dp") } } }}); - - findSubgames(); + + let subgamesPath = std::filesystem::path("..") / "subgames"; + std::filesystem::directory_iterator iter(subgamesPath); + + for (let& file : iter) { + if (!file.is_directory()) continue; + + try { + if (!std::filesystem::exists(file.path() / "conf.json")) throw std::runtime_error("Missing a conf.json"); + if (!std::filesystem::exists(file.path() / "mods")) throw std::runtime_error("Missing a mods folder"); + + nlohmann::json json {}; + try { + std::ifstream(file.path() / "conf.json") >> json; + } + catch (...) { + throw std::runtime_error("conf.json has a syntax error"); + } + + if (!json.is_object()) + throw std::runtime_error("conf.json has a syntax error."); + if (!json["name"].is_string() || json["name"] == "") + throw std::runtime_error("conf.json is missing 'name'"); + if (!json["version"].is_string() || json["version"] == "") + throw std::runtime_error("conf.json is missing 'version'"); + + const let icon = std::filesystem::exists(file.path() / "icon.png") + ? client.game->textures.loadImage((file.path() / "icon.png").string(), json["name"]) + : client.game->textures["menu_flag_missing"]; + + subgames.push_back({ icon, { json["name"], json["description"], json["version"] }, file.path().string() }); + } + catch(const std::runtime_error& e) { + std::cout << Log::err << "Failed to load subgame '" + << file.path().filename().string() << "', " << e.what() << "." << std::endl; + } + } + + std::sort(subgames.begin(), subgames.end(), + [](SubgameDef& a, SubgameDef& b) { return a.config.name < b.config.name; }); for (usize i = 0; i < subgames.size(); i++) { let& subgame = subgames[i]; @@ -123,82 +160,8 @@ MainMenuScene::MainMenuScene(Client& client) : Scene(client), }); } -void MainMenuScene::findSubgames() { - string subgamesPath = "../subgames"; - - cf_dir_t subgamesDir; - cf_dir_open(&subgamesDir, subgamesPath.data()); - while (subgamesDir.has_next) { - cf_file_t subgameFolder; - cf_read_file(&subgamesDir, &subgameFolder); - if (!subgameFolder.is_dir || strncmp(subgameFolder.name, ".", 1) == 0) { - cf_dir_next(&subgamesDir); - continue; - } - - try { - bool hasConf = false, hasIcon = false, hasMods = false; - - cf_dir_t subgame; - cf_dir_open(&subgame, subgameFolder.path); - while (subgame.has_next) { - cf_file_t file; - cf_read_file(&subgame, &file); - - if (!file.is_dir && strncmp(file.name, "icon.png\0", 9) == 0) hasIcon = true; - if (!file.is_dir && strncmp(file.name, "conf.json\0", 10) == 0) hasConf = true; - if (file.is_dir && strncmp(file.name, "mods\0", 5) == 0) hasMods = true; - - cf_dir_next(&subgame); - } - 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."); - - nlohmann::json j{}; - try { - std::ifstream(string(subgameFolder.path) + "/conf.json") >> j; - } - catch (...) { - throw std::runtime_error(string(subgameFolder.name) + "/conf.json is not a valid JSON object."); - } - - if (!j.is_object()) - throw std::runtime_error(string(subgameFolder.name) + "/conf.json is not a valid JSON object."); - if (!j["name"].is_string() || j["name"] == "") - throw std::runtime_error( - "The 'name' property in " + string(subgameFolder.name) + "/conf.json is missing or invalid."); - if (!j["version"].is_string() || j["version"] == "") - throw std::runtime_error("The 'version' property in " + string(subgameFolder.name) + - "/conf.json is missing or invalid."); - - string name = j["name"]; - string description = (j["description"].is_string() ? j["description"] : ""); - string version = j["version"]; - - std::shared_ptr icon = client.game->textures["menu_flag_missing"]; - if (hasIcon) icon = client.game->textures.loadImage(string(subgameFolder.path) + "/icon.png", name); - - subgames.push_back({ icon, { name, description, version }, subgameFolder.path }); - } - catch (const std::runtime_error& e) { - std::cout << Log::err << "Encountered an error while loading subgames:\n\t" << e.what() << Log::endl; - } - - cf_dir_next(&subgamesDir); - } - cf_dir_close(&subgamesDir); - - std::sort(subgames.begin(), subgames.end(), - [](SubgameDef& a, SubgameDef& b) { return a.config.name < b.config.name; }); -} - void MainMenuScene::update() { root.update(); - client.game->textures.update(); sandbox.update(client.getDelta()); } diff --git a/src/client/scene/MainMenuScene.h b/src/client/scene/MainMenuScene.h index 761b2fb1..7af2b47f 100644 --- a/src/client/scene/MainMenuScene.h +++ b/src/client/scene/MainMenuScene.h @@ -3,7 +3,6 @@ #include "Scene.h" #include "util/Types.h" -#include "client/Window.h" #include "client/gui/Root.h" #include "client/menu/SubgameDef.h" #include "client/menu/MenuSandbox.h" @@ -24,9 +23,7 @@ public: void draw() override; private: - /** Find valid subgames in the subgames folder. */ - void findSubgames(); - + /** The GUI root. */ Gui::Root root; diff --git a/src/game/LocalSubgame.cpp b/src/game/LocalSubgame.cpp index f9e3d627..ed74a311 100644 --- a/src/game/LocalSubgame.cpp +++ b/src/game/LocalSubgame.cpp @@ -41,5 +41,4 @@ void LocalSubgame::init(WorldPtr world, PlayerPtr player, Client& client) { void LocalSubgame::update(double delta) { lua->update(delta); - textures.update(); } diff --git a/src/game/ServerSubgame.cpp b/src/game/ServerSubgame.cpp index 371e1085..bd274214 100644 --- a/src/game/ServerSubgame.cpp +++ b/src/game/ServerSubgame.cpp @@ -1,9 +1,3 @@ -// -// Created by aurailus on 10/06/19. -// - -#include - #include "ServerSubgame.h" #include "server/ServerClients.h" @@ -15,7 +9,7 @@ ServerSubgame::ServerSubgame(const string& subgame, usize seed) : lua(make_unique(*this)) { if (subgame.empty()) throw std::runtime_error("No subgame specified."); - if (!cf_file_exists(subgamePath.data())) throw std::runtime_error("Subgame does not exist."); + if (!std::filesystem::exists(subgamePath)) throw std::runtime_error("Subgame does not exist."); } void ServerSubgame::init(WorldPtr world) { @@ -25,5 +19,3 @@ void ServerSubgame::init(WorldPtr world) { void ServerSubgame::update(double delta) { lua->update(delta); } - -ServerSubgame::~ServerSubgame() {} diff --git a/src/game/ServerSubgame.h b/src/game/ServerSubgame.h index 6ce9ef2f..e973adcd 100644 --- a/src/game/ServerSubgame.h +++ b/src/game/ServerSubgame.h @@ -23,7 +23,7 @@ public: ServerSubgame(const string& subgame, usize seed); - ~ServerSubgame(); + ~ServerSubgame() {}; void init(WorldPtr world); diff --git a/src/game/atlas/TextureAtlas.cpp b/src/game/atlas/TextureAtlas.cpp index 774b2b2a..19ec9f87 100644 --- a/src/game/atlas/TextureAtlas.cpp +++ b/src/game/atlas/TextureAtlas.cpp @@ -1,6 +1,6 @@ #include +#include #include -#include #include "TextureAtlas.h" @@ -81,27 +81,12 @@ TextureAtlas::TextureAtlas(uvec2 size) : createMissingTexture(); } -vec> TextureAtlas::loadDirectory(const string& path, bool base, bool recurse) { +vec> TextureAtlas::loadDirectory(const string& path, bool base) { vec> refs {}; - cf_dir_t dir; - cf_dir_open(&dir, (path).c_str()); - - while (dir.has_next) { - cf_file_t file; - cf_read_file(&dir, &file); - std::string_view name = file.name; - - if (!file.is_dir && strcmp(file.ext, ".png") == 0) - refs.push_back(loadImage(file.path, string(name.substr(0, name.size() - 4)), base)); - - if (recurse && file.is_dir && name.data()[0] != '.') { - let vec = loadDirectory(file.path, base, true); - refs.insert(refs.end(), vec.begin(), vec.end()); - } - cf_dir_next(&dir); - } - cf_dir_close(&dir); + for (let file : std::filesystem::recursive_directory_iterator(path)) + if (file.path().extension() == ".png") refs.push_back( + loadImage(file.path().string(), file.path().stem().string(), base)); return refs; } diff --git a/src/game/atlas/TextureAtlas.h b/src/game/atlas/TextureAtlas.h index ce1ee65e..b0fead6c 100644 --- a/src/game/atlas/TextureAtlas.h +++ b/src/game/atlas/TextureAtlas.h @@ -21,7 +21,7 @@ public: void update(); - vec> loadDirectory(const string& path, bool base = true, bool recurse = true); + vec> loadDirectory(const string& path, bool base = true); sptr loadImage(const string& path, const string& name, bool base = false); diff --git a/src/lua/Mod.cpp b/src/lua/Mod.cpp index 5205c283..b2f917b4 100644 --- a/src/lua/Mod.cpp +++ b/src/lua/Mod.cpp @@ -12,7 +12,6 @@ Mod::Mod(const std::filesystem::path& path, bool noConfig) { nlohmann::json json {}; - std::ifstream(path / "conf.json") >> json; rawPath = path; diff --git a/src/world/dim/file/FileManipulator.cpp b/src/world/dim/file/FileManipulator.cpp index 3289a018..683ed08a 100644 --- a/src/world/dim/file/FileManipulator.cpp +++ b/src/world/dim/file/FileManipulator.cpp @@ -13,6 +13,7 @@ #include #include +#include #include "FileManipulator.h" @@ -104,7 +105,7 @@ void FileManipulator::createRegionFileIfNotExists(glm::ivec3 pos) { std::string fileName = std::to_string(pos.x) + "_" + std::to_string(pos.y) + "_" + std::to_string(pos.z); std::string filePath = path + fileName; - if (cf_file_exists(filePath.data())) return; + if (std::filesystem::exists(filePath.data())) return; std::fstream file(filePath, std::ios::out | std::ios::binary); if (!file.is_open()) throw std::runtime_error("Couldn't open file."); diff --git a/src/world/dim/file/FileManipulator.h b/src/world/dim/file/FileManipulator.h index f6534bf8..0e0ce9a0 100644 --- a/src/world/dim/file/FileManipulator.h +++ b/src/world/dim/file/FileManipulator.h @@ -8,7 +8,6 @@ #include #include #include -#include class Chunk; diff --git a/subgames/zeus/mods/zeus_world/script/biomes/plains.lua b/subgames/zeus/mods/zeus_world/script/biomes/plains.lua index 40386d69..d339c117 100644 --- a/subgames/zeus/mods/zeus_world/script/biomes/plains.lua +++ b/subgames/zeus/mods/zeus_world/script/biomes/plains.lua @@ -124,14 +124,14 @@ table.insert(structures, zepha.create_structure({ for i = 1, 5 do table.insert(structures, zepha.create_structure({ origin = V(), - probability = 0.025, + probability = 0.05, layout = {{{ "zeus:default:tall_grass_" .. tostring(i) }}} })) end table.insert(structures, zepha.create_structure({ origin = V(), - probability = 0.35, + probability = 0.55, layout = {{{ "zeus:flowers:clover" }}} })) table.insert(structures, zepha.create_structure({