-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0d9a3b
commit 18b6dd4
Showing
8 changed files
with
139 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#pragma once | ||
|
||
#include <entt/entt.hpp> | ||
#include <span> | ||
|
||
namespace engine::ecs { | ||
struct System { | ||
entt::hashed_string name; | ||
void (*pfn_execute)(entt::registry ®istry); | ||
}; | ||
|
||
struct SystemDependencies { | ||
entt::hashed_string name; | ||
std::span<entt::hashed_string const> dependencies; | ||
}; | ||
|
||
template <typename T> | ||
System make_system(entt::hashed_string name, T func) | ||
{ | ||
return System { | ||
.name = name, | ||
.pfn_execute = func, | ||
}; | ||
} | ||
|
||
template <typename With, typename Without> | ||
class View; | ||
|
||
template <typename... With, typename... Without> | ||
class View<entt::get_t<With...>, entt::exclude_t<Without...>> { | ||
template <typename Entity, typename Allocator> | ||
static decltype(auto) get(entt::basic_registry<Entity, Allocator> ®istry) | ||
{ | ||
return registry.template view<With...>(entt::exclude<Without...>); | ||
} | ||
}; | ||
|
||
template <typename T> | ||
class Res { | ||
template <typename Entity, typename Allocator> | ||
static decltype(auto) get(entt::basic_registry<Entity, Allocator> ®istry) | ||
{ | ||
return registry.ctx().template get<T>(); | ||
} | ||
}; | ||
|
||
extern std::span<System const> const systems; | ||
extern std::span<SystemDependencies const> 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__ } }; \ | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <engine/ecs/system.hpp> | ||
|
||
// 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::System> const engine::ecs::systems = std::span<engine::ecs::System const>( | ||
&__start_system_array[0], | ||
&__stop_system_array[0]); | ||
|
||
std::span<engine::ecs::SystemDependencies const> const engine::ecs::systems_dependencies = std::span<engine::ecs::SystemDependencies const>( | ||
&__start_system_dependencies_array[0], | ||
&__stop_system_dependencies_array[0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,43 @@ | ||
#include <engine/ecs/system.hpp> | ||
|
||
#include <engine/ecs/components/Camera.hpp> | ||
#include <engine/ecs/components/LocalPlayer.hpp> | ||
#include <engine/ecs/systems/localplayer_camera.hpp> | ||
#include <engine/rendering/IRenderer.hpp> | ||
|
||
#include <SDL_keyboard.h> | ||
#include <entt/entt.hpp> | ||
|
||
constexpr float camera_speed = 25.0f; | ||
#include <chrono> | ||
|
||
struct Delta { | ||
std::chrono::duration<double> delta; | ||
}; | ||
|
||
void engine::systems::localplayer_camera(entt::registry ®istry, std::chrono::duration<double> delta) | ||
void localplayer_camera(entt::registry ®istry) | ||
{ | ||
auto const keyboard_state = SDL_GetKeyboardState(nullptr); | ||
auto &renderer = registry.ctx().get<std::unique_ptr<engine::rendering::IRenderer>>(); | ||
auto const delta = static_cast<float>(registry.ctx().get<Delta>().delta.count()); | ||
(void)renderer; | ||
|
||
auto view = registry.view<engine::components::LocalPlayer, engine::components::Camera>(); | ||
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<float>(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<float>(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<float>(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<float>(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<float>(delta.count()); | ||
camera.position.y += camera_speed * delta; | ||
if (keyboard_state[SDL_SCANCODE_LSHIFT]) | ||
camera.position.y -= camera_speed * static_cast<float>(delta.count()); | ||
camera.position.y -= camera_speed * delta; | ||
}); | ||
} | ||
} | ||
|
||
ECS_SYSTEM(localplayer_camera) | ||
ECS_SYSTEM_DEPENDS(localplayer_camera) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; |