diff --git a/conanfile.py b/conanfile.py index dbb02e6..a59cd41 100644 --- a/conanfile.py +++ b/conanfile.py @@ -50,20 +50,20 @@ def layout(self): def requirements(self): self.requires("glm/cci.20230113") - self.requires("entt/[>=3.12.0 <3.13]") - self.requires("sdl_image/[>=2.0.0 <2.1]") - self.requires("fmt/10.1.1") - self.requires("spdlog/1.12.0") + self.requires("entt/[~3.12]") + self.requires("sdl_image/[~2.0]") + self.requires("fmt/[~10.1]") + self.requires("spdlog/[~1.12]") self.requires("rapidjson/cci.20220822") - self.requires("imgui/[>=1.89.0 <1.90]") - self.requires("boost/[>=1.83.0 <1.84]") - self.requires("sdl/[>=2.28.0 <2.29]", override=True) + self.requires("imgui/[~1.90]") + self.requires("boost/[~1.83]") + self.requires("sdl/[~2]") if self.options.with_opengl: - self.requires("glad/[>=0.1.0 <0.2.0]") + self.requires("glad/[~0.1]") if self.options.with_vulkan: - sdk_version = "1.3.243.0" + sdk_version = "[~1.3]" self.requires(f"vulkan-headers/{sdk_version}") self.requires(f"volk/{sdk_version}") diff --git a/include/engine/ecs/system.hpp b/include/engine/ecs/system.hpp new file mode 100644 index 0000000..25f1e56 --- /dev/null +++ b/include/engine/ecs/system.hpp @@ -0,0 +1,59 @@ +#pragma once + +#include +#include + +namespace engine::ecs { + struct System { + entt::hashed_string name; + void (*pfn_execute)(entt::registry ®istry); + }; + + struct SystemDependencies { + entt::hashed_string name; + std::span dependencies; + }; + + template + System make_system(entt::hashed_string name, T func) + { + return System { + .name = name, + .pfn_execute = func, + }; + } + + template + class View; + + template + class View, entt::exclude_t> { + template + static decltype(auto) get(entt::basic_registry ®istry) + { + return registry.template view(entt::exclude); + } + }; + + template + class Res { + template + static decltype(auto) get(entt::basic_registry ®istry) + { + return registry.ctx().template get(); + } + }; + + extern std::span const systems; + extern std::span const systems_dependencies; +} // namespace engine::ecs + +#define CONCAT(a, b) a##b +#define ECS_SYSTEM(name) \ + namespace { \ + __attribute__((section("system_array"), used)) static auto CONCAT(name, _system) = engine::ecs::make_system(#name, &name); \ + } +#define ECS_SYSTEM_DEPENDS(name, ...) \ + namespace { \ + __attribute__((section("system_dependencies_array"), used)) static auto const CONCAT(name, _system_dependencies) = engine::ecs::SystemDependencies { #name, { __VA_ARGS__ } }; \ + } diff --git a/include/engine/ecs/systems/localplayer_camera.hpp b/include/engine/ecs/systems/localplayer_camera.hpp deleted file mode 100644 index f7055e9..0000000 --- a/include/engine/ecs/systems/localplayer_camera.hpp +++ /dev/null @@ -1,9 +0,0 @@ - -#include -#include - -namespace engine::systems { - - void localplayer_camera(entt::registry ®, std::chrono::duration delta); - -} // namespace engine::systems diff --git a/src/engine/ecs/system.cpp b/src/engine/ecs/system.cpp new file mode 100644 index 0000000..809ad3a --- /dev/null +++ b/src/engine/ecs/system.cpp @@ -0,0 +1,15 @@ +#include + +// these arrays are populated at link time thanks to the macros which use the section attribute +extern "C" engine::ecs::System const __start_system_array[]; +extern "C" engine::ecs::System const __stop_system_array[]; +extern "C" engine::ecs::SystemDependencies const __start_system_dependencies_array[]; +extern "C" engine::ecs::SystemDependencies const __stop_system_dependencies_array[]; + +std::span const engine::ecs::systems = std::span( + &__start_system_array[0], + &__stop_system_array[0]); + +std::span const engine::ecs::systems_dependencies = std::span( + &__start_system_dependencies_array[0], + &__stop_system_dependencies_array[0]); \ No newline at end of file diff --git a/src/engine/ecs/systems/localplayer_camera.cpp b/src/engine/ecs/systems/localplayer_camera.cpp index a618871..f7b69f9 100644 --- a/src/engine/ecs/systems/localplayer_camera.cpp +++ b/src/engine/ecs/systems/localplayer_camera.cpp @@ -1,33 +1,43 @@ +#include + #include #include -#include #include #include #include constexpr float camera_speed = 25.0f; +#include + +struct Delta { + std::chrono::duration delta; +}; -void engine::systems::localplayer_camera(entt::registry ®istry, std::chrono::duration delta) +void localplayer_camera(entt::registry ®istry) { auto const keyboard_state = SDL_GetKeyboardState(nullptr); auto &renderer = registry.ctx().get>(); + auto const delta = static_cast(registry.ctx().get().delta.count()); (void)renderer; auto view = registry.view(); view.each([&](engine::components::Camera &camera) { const glm::vec3 right = -glm::cross(camera.up, camera.forward); if (keyboard_state[SDL_SCANCODE_W]) - camera.position += glm::normalize(glm::vec3 { -camera.forward.x, 0.0f, camera.forward.z }) * camera_speed * static_cast(delta.count()); + camera.position += glm::normalize(glm::vec3 { -camera.forward.x, 0.0f, camera.forward.z }) * camera_speed * delta; if (keyboard_state[SDL_SCANCODE_S]) - camera.position -= glm::normalize(glm::vec3 { -camera.forward.x, 0.0f, camera.forward.z }) * camera_speed * static_cast(delta.count()); + camera.position -= glm::normalize(glm::vec3 { -camera.forward.x, 0.0f, camera.forward.z }) * camera_speed * delta; if (keyboard_state[SDL_SCANCODE_D]) - camera.position += glm::vec3 { -right.x, 0.0f, right.z } * camera_speed * static_cast(delta.count()); + camera.position += glm::vec3 { -right.x, 0.0f, right.z } * camera_speed * delta; if (keyboard_state[SDL_SCANCODE_A]) - camera.position -= glm::vec3 { -right.x, 0.0f, right.z } * camera_speed * static_cast(delta.count()); + camera.position -= glm::vec3 { -right.x, 0.0f, right.z } * camera_speed * delta; if (keyboard_state[SDL_SCANCODE_SPACE]) - camera.position.y += camera_speed * static_cast(delta.count()); + camera.position.y += camera_speed * delta; if (keyboard_state[SDL_SCANCODE_LSHIFT]) - camera.position.y -= camera_speed * static_cast(delta.count()); + camera.position.y -= camera_speed * delta; }); -} \ No newline at end of file +} + +ECS_SYSTEM(localplayer_camera) +ECS_SYSTEM_DEPENDS(localplayer_camera) \ No newline at end of file diff --git a/src/game/shared.cpp b/src/game/shared.cpp index 1d5cd04..c773552 100644 --- a/src/game/shared.cpp +++ b/src/game/shared.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -16,7 +17,7 @@ engine::Camera g_camera; void engine::Game::start() { constexpr int width = 640, height = 480; - m_renderer = std::make_unique(*this); + m_renderer = std::make_unique(*this); m_window = m_renderer->create_window( "VGame", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, diff --git a/src/game/update.cpp b/src/game/update.cpp index c352634..8e7fd4c 100644 --- a/src/game/update.cpp +++ b/src/game/update.cpp @@ -5,12 +5,6 @@ #include #include -#include -#include -#include - -#include - extern engine::Camera g_camera; static glm::vec3 previous_camera_position {}; diff --git a/tools/build_unix.sh b/tools/build_unix.sh index e01796a..e097fe0 100755 --- a/tools/build_unix.sh +++ b/tools/build_unix.sh @@ -1,3 +1,36 @@ -#!/bin/sh +#!/bin/bash -exec conan build . -pr:h default -s:h compiler.cppstd=20 -b missing +set -e -o pipefail + +case "$1" in + "debug") + declare -r build_type="Debug"; + ;; + "release") + declare -r build_type="Release"; + ;; + *) + echo "Unkown build_type $build_type" > /dev/stderr; + exit 1; + ;; +esac; + +declare -r build_directory="$PWD/build/$build_type"; +declare -r generators_directory="$build_directory/generators"; + +if [[ ! -e "$generators_directory" ]]; then + conan install . -pr:h default -s:h compiler.cppstd=20 -b missing -s "build_type=$build_type" -u; +fi; + + +# shellcheck source=/dev/null +source "$generators_directory/conanbuild.sh"; +if [[ ! -e "$build_directory/CMakeCache.txt" ]]; then + cmake --preset "conan-$1" +fi; + +cmake --build --preset "conan-$1" --parallel; + +# shellcheck source=/dev/null +source "$generators_directory/conanrun.sh"; +cmake --install "$build_directory" --prefix "$PWD/install";