From 125e19e0bed9ea70b759418a57e2294e318eed5d Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Sun, 2 Jul 2023 21:17:03 +0200 Subject: [PATCH] Restore compatibility with Windows --- CMakeLists.txt | 25 +++++++++- src/CMakeLists.txt | 4 +- src/bin/controller.cpp | 2 +- src/core/glad.cpp | 2 +- src/core/shader.cpp | 1 - src/scene/gltf_loader.cpp | 99 +-------------------------------------- 6 files changed, 28 insertions(+), 105 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ffd1a5..087a442 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,14 @@ FetchContent_Declare( URL https://github.com/glfw/glfw/releases/download/3.3.8/glfw-3.3.8.zip ) +# nlohmann-json +FetchContent_Declare( + json + URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz +) + +FetchContent_MakeAvailable(json) + option(GLFW_BUILD_DOCS "" OFF) option(GLFW_BUILD_EXAMPLES "" OFF) option(GLFW_BUILD_TESTS "" OFF) @@ -47,8 +55,21 @@ option(FX_GLTF_BUILD_TESTS "" OFF) option(FX_GLTF_INSTALL "" OFF) FetchContent_MakeAvailable(fx-gltf) -find_package(glm REQUIRED) -find_package(spdlog REQUIRED) +# glm +FetchContent_Declare( + glm + URL https://github.com/g-truc/glm/archive/refs/tags/0.9.9.8.tar.gz +) + +FetchContent_MakeAvailable(glm) + +# glm +FetchContent_Declare( + spdlog + URL https://github.com/gabime/spdlog/archive/refs/tags/v1.11.0.tar.gz +) + +FetchContent_MakeAvailable(spdlog) add_subdirectory(${PROJECT_SOURCE_DIR}/lib) add_subdirectory(${PROJECT_SOURCE_DIR}/src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f871741..70e4964 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,17 +20,17 @@ add_library(fever_engine target_compile_features(fever_engine PUBLIC cxx_std_20) target_include_directories(fever_engine PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_compile_definitions(fever_engine PRIVATE SPDLOG_FMT_EXTERNAL) target_link_libraries( fever_engine PUBLIC glad glfw EnTT::EnTT - fmt pthread spdlog + glm fx-gltf::fx-gltf + nlohmann_json::nlohmann_json stb ) diff --git a/src/bin/controller.cpp b/src/bin/controller.cpp index 8777ed5..c89ea77 100644 --- a/src/bin/controller.cpp +++ b/src/bin/controller.cpp @@ -10,7 +10,7 @@ using namespace entt::literals; Controller::Controller() { std::filesystem::path document_path("WaterBottle/glTF-Binary/WaterBottle.glb"); - entt::hashed_string document_hash(document_path.c_str()); + entt::hashed_string document_hash(document_path.string().c_str()); entt::resource gltf_document = gltf_cache.load(document_hash, document_path).first->second; diff --git a/src/core/glad.cpp b/src/core/glad.cpp index 462324f..d7600fa 100644 --- a/src/core/glad.cpp +++ b/src/core/glad.cpp @@ -128,7 +128,7 @@ void init_glad() // Initialize GLAD if (gladLoadGL(glfwGetProcAddress) == 0) { spdlog::critical("Failed to initialize GLAD"); - std::quick_exit(-1); + std::abort(); } #ifndef NDEBUG diff --git a/src/core/shader.cpp b/src/core/shader.cpp index 2619747..9fc8c4e 100644 --- a/src/core/shader.cpp +++ b/src/core/shader.cpp @@ -1,6 +1,5 @@ #include "shader.h" -#include #include #include #include diff --git a/src/scene/gltf_loader.cpp b/src/scene/gltf_loader.cpp index a91e4d4..9c98223 100644 --- a/src/scene/gltf_loader.cpp +++ b/src/scene/gltf_loader.cpp @@ -78,7 +78,7 @@ static auto load_texture(fx::gltf::Texture const& texture, std::istreambuf_iterator(), std::back_inserter(image_data)); - entt::hashed_string const image_hash(image_path.c_str()); + entt::hashed_string const image_hash(image_path.string().c_str()); return image_cache.load(image_hash, image_data, colorFormat).first->second; } @@ -389,103 +389,6 @@ auto GltfLoader::operator()(std::filesystem::path const& document_path) -> resul nodes.push_back(node.second); } - // // Load scenes - // std::vector> scenes; - // for (auto const& gltf_scene : gltf.scenes) { - // // Get nodes by hash - // std::vector> nodes; - // nodes.reserve(gltf_scene.nodes.size()); - - // for (auto node_id : gltf_scene.nodes) { - // auto const& node = gltf.nodes.at(node_id); - // entt::hashed_string node_hash(node.name.c_str()); - // nodes.push_back(gltf_node_cache[node_hash]); - // } - - // if (gltf_scene.name.empty()) { - // spdlog::warn("glTF scene has no name."); - // } - - // // Spawn an entity for every node in scene - // for (auto const& node : nodes) { - // std::function)> spawn_node = - // [this, &spawn_node](GltfNode const& node, std::optional parent) { - // auto entity = registry.create(); - // registry.emplace(entity, node.name); - // registry.emplace(entity, node.transform); - // registry.emplace(entity, GlobalTransform{}); - - // if (parent.has_value()) { - // registry.emplace(entity, Parent{.parent = parent.value()}); - // } - - // std::vector child_entities; - - // auto mesh = node.mesh; - // if (mesh.has_value()) { - // for (auto const& primitive : mesh.value()->primitives) { - // auto mesh_entity = registry.create(); - // registry.emplace(mesh_entity, Parent{.parent = entity}); - // registry.emplace(mesh_entity, Transform{}); - // registry.emplace(mesh_entity, GlobalTransform{}); - // registry.emplace>(mesh_entity, primitive.mesh); - // registry.emplace>(mesh_entity, - // primitive.material); - - // child_entities.push_back(mesh_entity); - // } - // } - - // auto camera = node.camera; - // if (camera.has_value()) { - // auto perspective = - // std::get(camera.value().projection); - // Camera::Perspective camera_perspective{.fov = perspective.yfov, - // .aspect_ratio = - // perspective.aspectRatio, - // .near = perspective.znear, - // .far = perspective.zfar}; - // registry.emplace(entity, Camera{.projection = camera_perspective}); - // } - - // // Spawn child nodes - // for (auto const& child : node.children) { - // auto child_entity = spawn_node(child, entity); - // child_entities.push_back(child_entity); - // } - - // registry.emplace(entity, Children{.children = child_entities}); - // return entity; - // }; - - // spawn_node(node, {}); - // } - - // auto camera_view = registry.view(); - // if (camera_view.empty()) { - // // Spawn default camera - // auto entity = registry.create(); - // registry.emplace(entity, "Camera"); - // registry.emplace(entity, Transform{.translation = Camera::DEFAULT_POSITION}); - // registry.emplace(entity, GlobalTransform{}); - // registry.emplace(entity, Camera{.projection = Camera::Perspective{}}); - // } - - // entt::hashed_string scene_hash(gltf_scene.name.c_str()); - // entt::resource scene_resource = - // scene_cache.load(scene_hash, Scene{}).first->second; - // scenes.push_back(scene_resource); - // } - - // // Default scene - // auto default_scene = [&gltf, &scenes]() -> std::optional> { - // if (gltf.scene != -1) { - // return scenes.at(gltf.scene); - // } - - // return {}; - // }(); - return std::make_shared(Gltf{.materials = std::move(materials), .meshes = std::move(gltf_meshes), .nodes = std::move(nodes),