From 1fc415b8b9ab0bb785658c50e81af55e969ee206 Mon Sep 17 00:00:00 2001 From: NigthLier Date: Sun, 28 Jan 2024 17:28:53 +0300 Subject: [PATCH 1/3] fix dependency load order + minor cmake change --- CMakeLists.txt | 10 ++++---- src/engine.cpp | 63 +++++++++++++++++--------------------------------- 2 files changed, 25 insertions(+), 48 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ec5691b..1b83113e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,8 @@ endif() find_package(OpenGL REQUIRED) find_package(GLEW REQUIRED) +find_package(glfw3 REQUIRED) +find_package(glm REQUIRED) find_package(OpenAL REQUIRED) find_package(ZLIB REQUIRED) @@ -86,15 +88,11 @@ if (WIN32) if(VOXELENGINE_BUILD_WINDOWS_VCPKG) set(LUA_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/packages/luajit_x64-windows/lib/lua51.lib") set(LUA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/packages/luajit_x64-windows/include/luajit") - find_package(glfw3 REQUIRED) - find_package(spng REQUIRED) - find_package(glm REQUIRED) - set(PNGLIB spng::spng) else() find_package(Lua REQUIRED) - set(PNGLIB spng) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/glfw) endif() + find_package(spng REQUIRED) + set(PNGLIB spng::spng) else() # luajit has no CMakeLists.txt to use it as subdirectory, so install it manually find_package(Lua REQUIRED) diff --git a/src/engine.cpp b/src/engine.cpp index 4ef3a243..ac6958c6 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #define GLEW_STATIC #include "audio/Audio.h" @@ -134,33 +135,9 @@ Engine::~Engine() { std::cout << "-- engine finished" << std::endl; } -size_t npos = std::numeric_limits::max(); - -inline size_t findPack(const std::string& id, const std::vector& packs) { - for (size_t i = 0; i < packs.size(); i++) { - if (packs[i].id == id) { - return i; - } - } - return npos; -} - -inline void addPack( - const ContentPack& pack, - const std::vector& srcPacks, - std::vector& contentPacks -) { - if (findPack(pack.id, contentPacks) != npos) { - return; - } - for (auto& dependecy : pack.dependencies) { - size_t index = findPack(dependecy, srcPacks); - if (index == npos) - throw contentpack_error(pack.id, pack.folder, - "missing dependency '"+dependecy+"'"); - addPack(srcPacks[index], srcPacks, contentPacks); - } - contentPacks.push_back(pack); +inline const std::string checkPacks(const std::unordered_set& packs, const std::vector& dependencies) { + for (const std::string& str : dependencies) if (packs.find(str) == packs.end()) return str; + return ""; } void Engine::loadContent() { @@ -173,21 +150,23 @@ void Engine::loadContent() { std::vector srcPacks = contentPacks; contentPacks.clear(); - for (auto& pack : srcPacks) { - if (pack.dependencies.empty()) - continue; - ContentLoader loader(&pack); - loader.load(&contentBuilder); - resRoots.push_back(pack.folder); - addPack(pack, srcPacks, contentPacks); - } - for (auto& pack : srcPacks) { - if (!pack.dependencies.empty()) - continue; - ContentLoader loader(&pack); - loader.load(&contentBuilder); - resRoots.push_back(pack.folder); - addPack(pack, srcPacks, contentPacks); + std::string missingDependency; + std::unordered_set loadedPacks, existingPacks; + for (const auto& item : srcPacks) { existingPacks.insert(item.id); } + + while(existingPacks.size() > loadedPacks.size()) { + for (auto& pack : srcPacks) { + if(loadedPacks.find(pack.id) != loadedPacks.end()) continue; + missingDependency = checkPacks(existingPacks, pack.dependencies); + if(!missingDependency.empty()) throw contentpack_error(pack.id, pack.folder, "missing dependency '"+missingDependency+"'"); + if(pack.dependencies.empty() || checkPacks(loadedPacks, pack.dependencies).empty()) { + loadedPacks.insert(pack.id); + resRoots.push_back(pack.folder); + contentPacks.push_back(pack); + ContentLoader loader(&pack); + loader.load(&contentBuilder); + } + } } content.reset(contentBuilder.build()); From f2cd749dc1cb4dbbd0072468a213e2ac035f7604 Mon Sep 17 00:00:00 2001 From: NigthLier Date: Mon, 29 Jan 2024 00:25:56 +0300 Subject: [PATCH 2/3] Update CMakeLists.txt --- CMakeLists.txt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b83113e..5877e416 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,29 @@ else() find_package(Lua REQUIRED) find_package(PNG REQUIRED) set(PNGLIB PNG::PNG) +endif()find_package(OpenGL REQUIRED) +find_package(GLEW REQUIRED) +find_package(OpenAL REQUIRED) +find_package(ZLIB REQUIRED) + +if (WIN32) + if(VOXELENGINE_BUILD_WINDOWS_VCPKG) + set(LUA_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/packages/luajit_x64-windows/lib/lua51.lib") + set(LUA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/packages/luajit_x64-windows/include/luajit") + find_package(glfw3 REQUIRED) + find_package(spng REQUIRED) + find_package(glm REQUIRED) + set(PNGLIB spng::spng) + else() + find_package(Lua REQUIRED) + set(PNGLIB spng) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/glfw) + endif() +else() + # luajit has no CMakeLists.txt to use it as subdirectory, so install it manually + find_package(Lua REQUIRED) + find_package(PNG REQUIRED) + set(PNGLIB PNG::PNG) endif() if (APPLE) From b9ecf82730171d63bdb32817033a649de0a460eb Mon Sep 17 00:00:00 2001 From: NigthLier Date: Mon, 29 Jan 2024 00:26:54 +0300 Subject: [PATCH 3/3] Update CMakeLists.txt --- CMakeLists.txt | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5877e416..7ec5691b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,27 +79,6 @@ endif() find_package(OpenGL REQUIRED) find_package(GLEW REQUIRED) -find_package(glfw3 REQUIRED) -find_package(glm REQUIRED) -find_package(OpenAL REQUIRED) -find_package(ZLIB REQUIRED) - -if (WIN32) - if(VOXELENGINE_BUILD_WINDOWS_VCPKG) - set(LUA_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/packages/luajit_x64-windows/lib/lua51.lib") - set(LUA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/packages/luajit_x64-windows/include/luajit") - else() - find_package(Lua REQUIRED) - endif() - find_package(spng REQUIRED) - set(PNGLIB spng::spng) -else() - # luajit has no CMakeLists.txt to use it as subdirectory, so install it manually - find_package(Lua REQUIRED) - find_package(PNG REQUIRED) - set(PNGLIB PNG::PNG) -endif()find_package(OpenGL REQUIRED) -find_package(GLEW REQUIRED) find_package(OpenAL REQUIRED) find_package(ZLIB REQUIRED)