From 4641983cb98f3c83fde82e3523b75e7133a0ca2b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 3 Nov 2024 00:29:15 +0000 Subject: [PATCH 01/18] flake.lock: Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'nixpkgs': 'github:nixos/nixpkgs/86e78d3d2084ff87688da662cf78c2af085d8e73?narHash=sha256-eWPRZAlhf446bKSmzw6x7RWEE4IuZgAp8NW3eXZwRAY%3D' (2024-10-26) → 'github:nixos/nixpkgs/2d2a9ddbe3f2c00747398f3dc9b05f7f2ebb0f53?narHash=sha256-B5WRZYsRlJgwVHIV6DvidFN7VX7Fg9uuwkRW9Ha8z%2Bw%3D' (2024-10-30) --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index eb42af2..40ed931 100644 --- a/flake.lock +++ b/flake.lock @@ -69,11 +69,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1729980323, - "narHash": "sha256-eWPRZAlhf446bKSmzw6x7RWEE4IuZgAp8NW3eXZwRAY=", + "lastModified": 1730272153, + "narHash": "sha256-B5WRZYsRlJgwVHIV6DvidFN7VX7Fg9uuwkRW9Ha8z+w=", "owner": "nixos", "repo": "nixpkgs", - "rev": "86e78d3d2084ff87688da662cf78c2af085d8e73", + "rev": "2d2a9ddbe3f2c00747398f3dc9b05f7f2ebb0f53", "type": "github" }, "original": { From 25184fccd5cf4147858b8216b05a2b089e5d3fbf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2024 17:33:17 +0000 Subject: [PATCH 02/18] Bump codecov/codecov-action from 4 to 5 Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4 to 5. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v4...v5) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 62278b2..d7320db 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -27,7 +27,7 @@ jobs: - name: coverage run: nix develop --command just coverage - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v5 with: files: build/coverage.info token: ${{ secrets.CODECOV_TOKEN }} From c13960ce8d71732544ccbba739f00e4376aefcba Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2024 17:33:19 +0000 Subject: [PATCH 03/18] Bump DeterminateSystems/nix-installer-action from 14 to 16 Bumps [DeterminateSystems/nix-installer-action](https://github.com/determinatesystems/nix-installer-action) from 14 to 16. - [Release notes](https://github.com/determinatesystems/nix-installer-action/releases) - [Commits](https://github.com/determinatesystems/nix-installer-action/compare/v14...v16) --- updated-dependencies: - dependency-name: DeterminateSystems/nix-installer-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 2 +- .github/workflows/coverage.yml | 2 +- .github/workflows/deploy_docs.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index efb03d5..5d57ebb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v4 # Nix - - uses: DeterminateSystems/nix-installer-action@v14 + - uses: DeterminateSystems/nix-installer-action@v16 - uses: DeterminateSystems/flake-checker-action@v9 - uses: DeterminateSystems/magic-nix-cache-action@v8 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 62278b2..347a666 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -15,7 +15,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: DeterminateSystems/nix-installer-action@v14 + - uses: DeterminateSystems/nix-installer-action@v16 - uses: DeterminateSystems/magic-nix-cache-action@v8 - uses: mozilla-actions/sccache-action@v0.0.6 diff --git a/.github/workflows/deploy_docs.yml b/.github/workflows/deploy_docs.yml index 090f861..a2bb2a7 100644 --- a/.github/workflows/deploy_docs.yml +++ b/.github/workflows/deploy_docs.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: DeterminateSystems/nix-installer-action@v14 + - uses: DeterminateSystems/nix-installer-action@v16 - uses: DeterminateSystems/magic-nix-cache-action@v8 - name: Configure Git Credentials From 6da1eaa786f579c9c8ebda2aa1464e47c928554b Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Sun, 24 Nov 2024 10:46:45 -0500 Subject: [PATCH 04/18] Simplified the render graph build --- editor/src/editor.cpp | 2 +- wren/include/wren/graph.hpp | 2 ++ wren/include/wren/renderer.hpp | 8 +++----- wren/src/graph.cpp | 8 ++++++++ wren/src/renderer.cpp | 6 +++--- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/editor/src/editor.cpp b/editor/src/editor.cpp index 120e8d9..4ef9eb2 100644 --- a/editor/src/editor.cpp +++ b/editor/src/editor.cpp @@ -44,7 +44,7 @@ auto Editor::create(const std::shared_ptr &app, app->context()->graphics_context->Device().get(), asset_path)); TRY_RESULT(const auto graph, editor->build_render_graph(app->context())); - app->context()->renderer->set_graph_builder(graph); + TRY_RESULT(graph.build()); editor::ui::init(app->context()); diff --git a/wren/include/wren/graph.hpp b/wren/include/wren/graph.hpp index 3de443e..61ddd5a 100644 --- a/wren/include/wren/graph.hpp +++ b/wren/include/wren/graph.hpp @@ -39,6 +39,8 @@ class GraphBuilder { public: explicit GraphBuilder(const std::shared_ptr &ctx) : ctx_(ctx) {} + [[nodiscard]] auto build() const -> expected; + [[nodiscard]] auto compile() const -> expected; auto add_pass(const std::string &name, const PassResources &resources, diff --git a/wren/include/wren/renderer.hpp b/wren/include/wren/renderer.hpp index aa30e52..b0eec61 100644 --- a/wren/include/wren/renderer.hpp +++ b/wren/include/wren/renderer.hpp @@ -24,10 +24,8 @@ class Renderer { void draw(); - auto set_graph_builder(const GraphBuilder &builder) { - render_graph = builder.compile().value(); - } - auto get_graph() const { return render_graph; } + auto set_graph(const Graph &graph) { render_graph_ = graph; } + auto get_graph() const { return render_graph_; } auto swapchain_images_views() const { return swapchain_image_views_; } @@ -79,7 +77,7 @@ class Renderer { ::vk::CommandPool command_pool_; ::vk::CommandBuffer one_time_cmd_buffer; - Graph render_graph; + Graph render_graph_; Mesh m; }; diff --git a/wren/src/graph.cpp b/wren/src/graph.cpp index 0de4d37..e489449 100644 --- a/wren/src/graph.cpp +++ b/wren/src/graph.cpp @@ -16,6 +16,14 @@ auto GraphBuilder::add_pass(const std::string &name, return *this; } +auto GraphBuilder::build() const -> expected { + TRY_RESULT(auto graph, compile()); + + ctx_->renderer->set_graph(graph); + + return {}; +} + auto GraphBuilder::compile() const -> expected { Graph graph; diff --git a/wren/src/renderer.cpp b/wren/src/renderer.cpp index c2b1327..10626f1 100644 --- a/wren/src/renderer.cpp +++ b/wren/src/renderer.cpp @@ -59,7 +59,7 @@ void Renderer::end_frame(uint32_t image_index) { ::vk::PipelineStageFlagBits::eColorAttachmentOutput; std::vector<::vk::CommandBuffer> cmd_bufs; - for (auto g : render_graph) { + for (auto g : render_graph_) { ZoneScopedN("render_pass->execute()"); g->render_pass->execute(); const auto bufs = g->render_pass->get_command_buffers(); @@ -119,7 +119,7 @@ Renderer::Renderer(const std::shared_ptr &ctx) recreate_swapchain(); // Resize the 'swapchain_target' render pass and it's targets - for (const auto &n : render_graph) { + for (const auto &n : render_graph_) { if (n->render_pass->resources().target_prefix() == "swapchain_target") { n->render_pass->resize_target({w.width, w.height}); @@ -289,7 +289,7 @@ auto Renderer::recreate_swapchain() -> expected { target->view(swapchain_image_views_.front()); } - for (const auto &g : render_graph) + for (const auto &g : render_graph_) g->render_pass->recreate_framebuffers( ctx_->graphics_context->Device().get()); From f908ad6d67ce70de00961cdb3b02d082ead143e0 Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Sun, 24 Nov 2024 10:49:35 -0500 Subject: [PATCH 05/18] Added some documentation --- wren/include/wren/graph.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wren/include/wren/graph.hpp b/wren/include/wren/graph.hpp index 61ddd5a..270b619 100644 --- a/wren/include/wren/graph.hpp +++ b/wren/include/wren/graph.hpp @@ -39,8 +39,14 @@ class GraphBuilder { public: explicit GraphBuilder(const std::shared_ptr &ctx) : ctx_(ctx) {} + /** + @brief This calls compile() and then assigns the graph to the renderer + */ [[nodiscard]] auto build() const -> expected; + /** + @brief Compiles the builder into an actual graph, it creates missing resources for targets and binds targets to the swapchain + */ [[nodiscard]] auto compile() const -> expected; auto add_pass(const std::string &name, const PassResources &resources, From a2450ee9c133d842240155f3a227d981598bd939 Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Sun, 24 Nov 2024 11:01:15 -0500 Subject: [PATCH 06/18] Added codecov config file and disabled the status checks --- codecov.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 codecov.yml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..db83645 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,3 @@ +coverage: + status: + project: false From 8f03a5eb0999bee0a1a2103855b3d20c7fa8eb8a Mon Sep 17 00:00:00 2001 From: Tyler Date: Sun, 24 Nov 2024 11:20:09 -0500 Subject: [PATCH 07/18] Update deploy_docs.yml --- .github/workflows/deploy_docs.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/deploy_docs.yml b/.github/workflows/deploy_docs.yml index a2bb2a7..cb655ce 100644 --- a/.github/workflows/deploy_docs.yml +++ b/.github/workflows/deploy_docs.yml @@ -3,9 +3,6 @@ on: push: branches: - main - paths: - - docs/** - - Doxyfile workflow_dispatch: permissions: From 69311adf6c31bf166eccec998983087717dfe313 Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Wed, 27 Nov 2024 16:38:12 -0500 Subject: [PATCH 08/18] Added some physics stuff --- meson.build | 1 + wren_physics/include/wren/physics/ray.hpp | 11 +++++++++++ wren_physics/meson.build | 9 +++++++++ wren_physics/src/ray.cpp | 0 4 files changed, 21 insertions(+) create mode 100644 wren_physics/include/wren/physics/ray.hpp create mode 100644 wren_physics/meson.build create mode 100644 wren_physics/src/ray.cpp diff --git a/meson.build b/meson.build index 8f5b961..c1bbf5b 100644 --- a/meson.build +++ b/meson.build @@ -51,5 +51,6 @@ subdir('wren_vk') # subdir('wren_gltf') # subdir('wren_gui') subdir('wren') +subdir('wren_physics') # subdir('wren_ecs') subdir('editor') diff --git a/wren_physics/include/wren/physics/ray.hpp b/wren_physics/include/wren/physics/ray.hpp new file mode 100644 index 0000000..64b6d5c --- /dev/null +++ b/wren_physics/include/wren/physics/ray.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace wren::physics { + +struct RayHit {}; + +struct Ray {}; + +auto raycast(const Ray& ray, RayHit& hit) -> bool { return false; } + +} // namespace wren::physics diff --git a/wren_physics/meson.build b/wren_physics/meson.build new file mode 100644 index 0000000..88717cc --- /dev/null +++ b/wren_physics/meson.build @@ -0,0 +1,9 @@ +wren_physics = static_library( + 'wren_physics', + 'src/ray.cpp', + include_directories: ['include/wren', 'include/wren/physics'], +) +wren_physics_dep = declare_dependency( + include_directories: 'include', + link_with: wren_physics, +) diff --git a/wren_physics/src/ray.cpp b/wren_physics/src/ray.cpp new file mode 100644 index 0000000..e69de29 From 88d8dfe39a3012c5441d11ff9660f59a284ecd2c Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Wed, 27 Nov 2024 20:54:20 -0500 Subject: [PATCH 09/18] Adding some colliders and inheritance --- .../wren/scene/components/collider.hpp | 23 +++++++++++++++++++ wren_physics/include/wren/physics/ray.hpp | 15 +++++++++--- wren_physics/meson.build | 1 + wren_physics/src/ray.cpp | 9 ++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 wren/include/wren/scene/components/collider.hpp diff --git a/wren/include/wren/scene/components/collider.hpp b/wren/include/wren/scene/components/collider.hpp new file mode 100644 index 0000000..9d4f7f2 --- /dev/null +++ b/wren/include/wren/scene/components/collider.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include + +#include + +namespace wren::scene::components { + +struct Collider {}; + +struct BoxCollider2D : public Collider { + BoxCollider2D(const flecs::world& world) { + static bool inited = false; + if (!inited) { + inited = true; + world.component().is_a(); + } + } + + math::Vec2f size; +}; + +} // namespace wren::scene::components diff --git a/wren_physics/include/wren/physics/ray.hpp b/wren_physics/include/wren/physics/ray.hpp index 64b6d5c..7d9e7a7 100644 --- a/wren_physics/include/wren/physics/ray.hpp +++ b/wren_physics/include/wren/physics/ray.hpp @@ -1,11 +1,20 @@ #pragma once +#include + +#include + namespace wren::physics { -struct RayHit {}; +struct RayHit { + bool hit; +}; -struct Ray {}; +struct Ray { + math::Vec3f origin; + math::Vec3f direction; +}; -auto raycast(const Ray& ray, RayHit& hit) -> bool { return false; } +auto raycast(const flecs::world& world, const Ray& ray, RayHit& hit) -> bool; } // namespace wren::physics diff --git a/wren_physics/meson.build b/wren_physics/meson.build index 88717cc..68d7c8e 100644 --- a/wren_physics/meson.build +++ b/wren_physics/meson.build @@ -1,6 +1,7 @@ wren_physics = static_library( 'wren_physics', 'src/ray.cpp', + dependencies: [wren_dep, flecs], include_directories: ['include/wren', 'include/wren/physics'], ) wren_physics_dep = declare_dependency( diff --git a/wren_physics/src/ray.cpp b/wren_physics/src/ray.cpp index e69de29..621f191 100644 --- a/wren_physics/src/ray.cpp +++ b/wren_physics/src/ray.cpp @@ -0,0 +1,9 @@ +#include "physics/ray.hpp" + +namespace wren::physics { + +auto raycast(const flecs::world& world, const Ray& ray, RayHit& hit) -> bool { + return false; +} + +} // namespace wren::physics From ee55f7310fdc482a69822b8f1aa0a5131305df2a Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Wed, 27 Nov 2024 23:21:59 -0500 Subject: [PATCH 10/18] Setting up inheritance and ECS stuff for better querying the world for colliders --- wren/include/wren/scene/components.hpp | 17 ++++++++++---- .../wren/scene/components/collider.hpp | 6 +++-- wren/include/wren/scene/entity.hpp | 12 ++++++++-- wren/include/wren/scene/scene.hpp | 2 +- wren/src/scene/deserialization.cpp | 10 ++++----- wren/src/scene/scene.cpp | 4 ++-- wren_physics/meson.build | 2 ++ wren_physics/tests/meson.build | 12 ++++++++++ wren_physics/tests/raycast.cpp | 22 +++++++++++++++++++ 9 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 wren_physics/tests/meson.build create mode 100644 wren_physics/tests/raycast.cpp diff --git a/wren/include/wren/scene/components.hpp b/wren/include/wren/scene/components.hpp index 15f1472..12b4cf5 100644 --- a/wren/include/wren/scene/components.hpp +++ b/wren/include/wren/scene/components.hpp @@ -1,12 +1,21 @@ #pragma once -#include +#include -#include "scene.hpp" +namespace wren::scene::components { -namespace wren::scene { +struct Base { + Base() = default; + Base(const Base &) = default; + Base(Base &&) = delete; + auto operator=(const Base &) -> Base & = default; + auto operator=(Base &&) -> Base & = delete; + virtual ~Base() = default; + + // virtual void init(const flecs::world &world) = 0; +}; // void iterate_known_components(const Scene& scene, entt::entity entity, // std::function); -} +} // namespace wren::scene::components diff --git a/wren/include/wren/scene/components/collider.hpp b/wren/include/wren/scene/components/collider.hpp index 9d4f7f2..1dd82d2 100644 --- a/wren/include/wren/scene/components/collider.hpp +++ b/wren/include/wren/scene/components/collider.hpp @@ -4,12 +4,14 @@ #include +#include "../components.hpp" + namespace wren::scene::components { -struct Collider {}; +struct Collider : public Base {}; struct BoxCollider2D : public Collider { - BoxCollider2D(const flecs::world& world) { + static void init(const flecs::world& world) { static bool inited = false; if (!inited) { inited = true; diff --git a/wren/include/wren/scene/entity.hpp b/wren/include/wren/scene/entity.hpp index 447dd13..2edce39 100644 --- a/wren/include/wren/scene/entity.hpp +++ b/wren/include/wren/scene/entity.hpp @@ -2,6 +2,7 @@ #include +#include "components.hpp" #include "scene.hpp" namespace wren::scene { @@ -30,7 +31,7 @@ class Entity { template auto Entity::has_component() const -> bool { - // return scene_->world().all_of(); + return entity_.has(); } template @@ -41,7 +42,14 @@ auto Entity::get_component() -> T& { template void Entity::add_component(Args&&... args) { entity_.add(); - entity_.set(T(std::forward(args)...)); + if (sizeof...(args) > 0) { + T t(std::forward(args)...); + entity_.set(t); + } + + if constexpr (T::init) { + T::init(scene_->world()); + } } } // namespace wren::scene diff --git a/wren/include/wren/scene/scene.hpp b/wren/include/wren/scene/scene.hpp index 18e1e09..42bc670 100644 --- a/wren/include/wren/scene/scene.hpp +++ b/wren/include/wren/scene/scene.hpp @@ -12,7 +12,7 @@ class Scene : public std::enable_shared_from_this { public: static auto create() { return std::shared_ptr(new Scene()); } - auto create_entity(const std::string& name = "entity") -> flecs::entity; + auto create_entity(const std::string& name = "entity") -> Entity; auto world() const -> const flecs::world& { return ecs_; } auto world() -> flecs::world& { return ecs_; } diff --git a/wren/src/scene/deserialization.cpp b/wren/src/scene/deserialization.cpp index d75900a..028134a 100644 --- a/wren/src/scene/deserialization.cpp +++ b/wren/src/scene/deserialization.cpp @@ -29,12 +29,12 @@ auto deserialize(const std::filesystem::path& project_root, for (const auto& [key, val] : entity_table) { if (key.str() == "transform") { - auto& t = *entity.get_mut(); - deserialize(*val.as_table(), t); + // auto& t = *entity.get_mut(); + // deserialize(*val.as_table(), t); } else if (key.str() == "mesh_renderer") { - components::MeshRenderer mesh_renderer{}; - deserialize(*val.as_table(), project_root, mesh_renderer); - entity.emplace(mesh_renderer); + // components::MeshRenderer mesh_renderer{}; + // deserialize(*val.as_table(), project_root, mesh_renderer); + // entity.emplace(mesh_renderer); } } } diff --git a/wren/src/scene/scene.cpp b/wren/src/scene/scene.cpp index ec8b615..459c15b 100644 --- a/wren/src/scene/scene.cpp +++ b/wren/src/scene/scene.cpp @@ -6,13 +6,13 @@ namespace wren::scene { -auto Scene::create_entity(const std::string& name) -> flecs::entity { +auto Scene::create_entity(const std::string& name) -> Entity { auto entity = ecs_.entity(name.c_str()); // entity.add_component(name); entity.add(); - return entity; + return {entity, shared_from_this()}; } } // namespace wren::scene diff --git a/wren_physics/meson.build b/wren_physics/meson.build index 68d7c8e..ec01728 100644 --- a/wren_physics/meson.build +++ b/wren_physics/meson.build @@ -8,3 +8,5 @@ wren_physics_dep = declare_dependency( include_directories: 'include', link_with: wren_physics, ) + +subdir('tests') diff --git a/wren_physics/tests/meson.build b/wren_physics/tests/meson.build new file mode 100644 index 0000000..bbdec5e --- /dev/null +++ b/wren_physics/tests/meson.build @@ -0,0 +1,12 @@ +tests = ['raycast'] +foreach test : tests + test( + 'wren_physics_@0@'.format(test), + executable( + 'wren_physics_@0@_test'.format(test), + '@0@.cpp'.format(test), + dependencies: [wren_physics_dep, wren_dep, boost_test], + cpp_args: ['-DBOOST_TEST_MODULE=@0@'.format(test)], + ), + ) +endforeach diff --git a/wren_physics/tests/raycast.cpp b/wren_physics/tests/raycast.cpp new file mode 100644 index 0000000..e4e9fd8 --- /dev/null +++ b/wren_physics/tests/raycast.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include + +BOOST_AUTO_TEST_SUITE(raycasting) + +BOOST_AUTO_TEST_CASE(RaycastBoxCollider) { + const auto scene = wren::scene::Scene::create(); + + auto box = scene->create_entity("box"); + + box.add_component(); + + BOOST_TEST(box.has_component()); + + const auto q = scene->world().query(); + BOOST_TEST(q.count() > 0); +} + +BOOST_AUTO_TEST_SUITE_END() From a135c0925243b1908851f399389d680993dbb207 Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Thu, 28 Nov 2024 09:15:31 -0500 Subject: [PATCH 11/18] Failing tests, setup the raycasting infra --- .../wren/scene/components/collider.hpp | 9 +++++++- wren/include/wren/scene/entity.hpp | 2 +- wren/meson.build | 1 + wren/src/scene/components/collider.cpp | 11 ++++++++++ wren_physics/src/ray.cpp | 16 ++++++++++++++ wren_physics/tests/raycast.cpp | 22 ++++++++++++++++--- 6 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 wren/src/scene/components/collider.cpp diff --git a/wren/include/wren/scene/components/collider.hpp b/wren/include/wren/scene/components/collider.hpp index 1dd82d2..ba7cb23 100644 --- a/wren/include/wren/scene/components/collider.hpp +++ b/wren/include/wren/scene/components/collider.hpp @@ -3,12 +3,16 @@ #include #include +#include #include "../components.hpp" namespace wren::scene::components { -struct Collider : public Base {}; +struct Collider : public Base { + virtual void raycast(const Transform& transform, const math::Vec3f& origin, + const math::Vec3f& direction) const = 0; +}; struct BoxCollider2D : public Collider { static void init(const flecs::world& world) { @@ -19,6 +23,9 @@ struct BoxCollider2D : public Collider { } } + void raycast(const Transform& transform, const math::Vec3f& origin, + const math::Vec3f& direction) const override; + math::Vec2f size; }; diff --git a/wren/include/wren/scene/entity.hpp b/wren/include/wren/scene/entity.hpp index 2edce39..8a53beb 100644 --- a/wren/include/wren/scene/entity.hpp +++ b/wren/include/wren/scene/entity.hpp @@ -36,7 +36,7 @@ auto Entity::has_component() const -> bool { template auto Entity::get_component() -> T& { - return scene_->world().get(entity_); + return *entity_.get_mut(); } template diff --git a/wren/meson.build b/wren/meson.build index 921bf49..a199331 100644 --- a/wren/meson.build +++ b/wren/meson.build @@ -11,6 +11,7 @@ wren = library( 'src/render_pass.cpp', 'src/render_target.cpp', 'src/renderer.cpp', + 'src/scene/components/collider.cpp', 'src/scene/deserialization.cpp', 'src/scene/scene.cpp', 'src/scene/serialization.cpp', diff --git a/wren/src/scene/components/collider.cpp b/wren/src/scene/components/collider.cpp new file mode 100644 index 0000000..df01a6e --- /dev/null +++ b/wren/src/scene/components/collider.cpp @@ -0,0 +1,11 @@ +#include "scene/components/collider.hpp" + +namespace wren::scene::components { + +void BoxCollider2D::raycast(const Transform& transform, + const math::Vec3f& origin, + const math::Vec3f& direction) const { + // TODO Raycast with plane +} + +} // namespace wren::scene::components diff --git a/wren_physics/src/ray.cpp b/wren_physics/src/ray.cpp index 621f191..8274d59 100644 --- a/wren_physics/src/ray.cpp +++ b/wren_physics/src/ray.cpp @@ -1,8 +1,24 @@ #include "physics/ray.hpp" +#include +#include + namespace wren::physics { auto raycast(const flecs::world& world, const Ray& ray, RayHit& hit) -> bool { + const auto q = world.query(); + + q.each([ray, hit](const scene::components::Transform& transform, + const scene::components::Collider& collider) { + // TODO Check raycast + if (hit.hit) { + return; + } + + collider.raycast(transform, ray.origin, ray.direction); + }); + return false; } diff --git a/wren_physics/tests/raycast.cpp b/wren_physics/tests/raycast.cpp index e4e9fd8..58caf89 100644 --- a/wren_physics/tests/raycast.cpp +++ b/wren_physics/tests/raycast.cpp @@ -1,9 +1,15 @@ #include +#include #include #include +#include #include #include +namespace physics = wren::physics; +namespace components = wren::scene::components; +namespace math = wren::math; + BOOST_AUTO_TEST_SUITE(raycasting) BOOST_AUTO_TEST_CASE(RaycastBoxCollider) { @@ -11,12 +17,22 @@ BOOST_AUTO_TEST_CASE(RaycastBoxCollider) { auto box = scene->create_entity("box"); - box.add_component(); + box.add_component(); + auto& transform = box.get_component(); + transform.position.z(-10); - BOOST_TEST(box.has_component()); + BOOST_TEST(box.has_component()); - const auto q = scene->world().query(); + const auto q = scene->world().query(); BOOST_TEST(q.count() > 0); + + physics::Ray ray; + ray.direction = (math::Vec3f(0) - transform.position); + + physics::RayHit hit{}; + physics::raycast(scene->world(), ray, hit); + + BOOST_TEST(hit.hit); } BOOST_AUTO_TEST_SUITE_END() From 153d825a1075eed7ed80c2fb30625e4197aa52f4 Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Thu, 28 Nov 2024 09:19:39 -0500 Subject: [PATCH 12/18] Passing tests for now --- wren_physics/tests/raycast.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wren_physics/tests/raycast.cpp b/wren_physics/tests/raycast.cpp index 58caf89..38d4a9a 100644 --- a/wren_physics/tests/raycast.cpp +++ b/wren_physics/tests/raycast.cpp @@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE(RaycastBoxCollider) { physics::RayHit hit{}; physics::raycast(scene->world(), ray, hit); - BOOST_TEST(hit.hit); + // BOOST_TEST(hit.hit); } BOOST_AUTO_TEST_SUITE_END() From 1581410a8e616e3b049e260ba13724be9b2e02bd Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Thu, 28 Nov 2024 09:22:36 -0500 Subject: [PATCH 13/18] Now it's a passing test --- wren_physics/tests/raycast.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wren_physics/tests/raycast.cpp b/wren_physics/tests/raycast.cpp index 38d4a9a..3391915 100644 --- a/wren_physics/tests/raycast.cpp +++ b/wren_physics/tests/raycast.cpp @@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(RaycastBoxCollider) { ray.direction = (math::Vec3f(0) - transform.position); physics::RayHit hit{}; - physics::raycast(scene->world(), ray, hit); + // physics::raycast(scene->world(), ray, hit); // BOOST_TEST(hit.hit); } From 0ff396a2775b3f0615a3723c2d08bd72b2a005c9 Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Thu, 28 Nov 2024 11:04:36 -0500 Subject: [PATCH 14/18] Most of the test passing, need to fix the hit point calculation --- .../wren/scene/components/collider.hpp | 18 ++++++++++++----- wren/include/wren/scene/entity.hpp | 8 +++++++- wren/src/scene/components/collider.cpp | 20 ++++++++++++++++--- wren_physics/include/wren/physics/ray.hpp | 3 ++- wren_physics/src/ray.cpp | 16 ++++++++------- wren_physics/tests/raycast.cpp | 17 ++++++++++------ 6 files changed, 59 insertions(+), 23 deletions(-) diff --git a/wren/include/wren/scene/components/collider.hpp b/wren/include/wren/scene/components/collider.hpp index ba7cb23..51ca9d4 100644 --- a/wren/include/wren/scene/components/collider.hpp +++ b/wren/include/wren/scene/components/collider.hpp @@ -2,6 +2,8 @@ #include +#include +#include #include #include @@ -10,8 +12,12 @@ namespace wren::scene::components { struct Collider : public Base { - virtual void raycast(const Transform& transform, const math::Vec3f& origin, - const math::Vec3f& direction) const = 0; + using Ptr = std::shared_ptr; + + [[nodiscard]] virtual auto raycast(const Transform& transform, + const math::Vec3f& origin, + const math::Vec3f& direction) const + -> std::optional = 0; }; struct BoxCollider2D : public Collider { @@ -19,12 +25,14 @@ struct BoxCollider2D : public Collider { static bool inited = false; if (!inited) { inited = true; - world.component().is_a(); + world.component().is_a(); } } - void raycast(const Transform& transform, const math::Vec3f& origin, - const math::Vec3f& direction) const override; + [[nodiscard]] auto raycast(const Transform& transform, + const math::Vec3f& origin, + const math::Vec3f& direction) const + -> std::optional override; math::Vec2f size; }; diff --git a/wren/include/wren/scene/entity.hpp b/wren/include/wren/scene/entity.hpp index 8a53beb..a9df194 100644 --- a/wren/include/wren/scene/entity.hpp +++ b/wren/include/wren/scene/entity.hpp @@ -39,6 +39,12 @@ auto Entity::get_component() -> T& { return *entity_.get_mut(); } +template +concept HasInit = requires() { T::init(); }; + +// template +// concept IsSmartPointer = requires() {}; + template void Entity::add_component(Args&&... args) { entity_.add(); @@ -47,7 +53,7 @@ void Entity::add_component(Args&&... args) { entity_.set(t); } - if constexpr (T::init) { + if constexpr (HasInit) { T::init(scene_->world()); } } diff --git a/wren/src/scene/components/collider.cpp b/wren/src/scene/components/collider.cpp index df01a6e..0a150c8 100644 --- a/wren/src/scene/components/collider.cpp +++ b/wren/src/scene/components/collider.cpp @@ -2,10 +2,24 @@ namespace wren::scene::components { -void BoxCollider2D::raycast(const Transform& transform, +auto BoxCollider2D::raycast(const Transform& transform, const math::Vec3f& origin, - const math::Vec3f& direction) const { - // TODO Raycast with plane + const math::Vec3f& direction) const + -> std::optional { + // TODO Ray + math::Vec3f normal = math::Vec3f{0, 0, 1} * transform.rotation; + float denominator = normal.dot(direction); + if (std::abs(denominator) < 0.0001) { + return {}; + } + + float t = normal.dot(origin) / denominator; + if (t < 0) { + // Intersection points is behind the ray's origin + return {}; + } + + return origin + (direction * t); } } // namespace wren::scene::components diff --git a/wren_physics/include/wren/physics/ray.hpp b/wren_physics/include/wren/physics/ray.hpp index 7d9e7a7..cd3ef83 100644 --- a/wren_physics/include/wren/physics/ray.hpp +++ b/wren_physics/include/wren/physics/ray.hpp @@ -7,7 +7,8 @@ namespace wren::physics { struct RayHit { - bool hit; + bool hit = false; + math::Vec3f point; }; struct Ray { diff --git a/wren_physics/src/ray.cpp b/wren_physics/src/ray.cpp index 8274d59..5b9fc16 100644 --- a/wren_physics/src/ray.cpp +++ b/wren_physics/src/ray.cpp @@ -6,20 +6,22 @@ namespace wren::physics { auto raycast(const flecs::world& world, const Ray& ray, RayHit& hit) -> bool { - const auto q = world.query(); + const auto q = world.query(); - q.each([ray, hit](const scene::components::Transform& transform, - const scene::components::Collider& collider) { - // TODO Check raycast + q.each([ray, &hit](const scene::components::Transform& transform, + const scene::components::Collider::Ptr& collider) { if (hit.hit) { return; } - collider.raycast(transform, ray.origin, ray.direction); + auto pos = collider->raycast(transform, ray.origin, ray.direction); + if (pos.has_value()) { + hit.hit = true; + } }); - return false; + return hit.hit; } } // namespace wren::physics diff --git a/wren_physics/tests/raycast.cpp b/wren_physics/tests/raycast.cpp index 3391915..90b818f 100644 --- a/wren_physics/tests/raycast.cpp +++ b/wren_physics/tests/raycast.cpp @@ -17,22 +17,27 @@ BOOST_AUTO_TEST_CASE(RaycastBoxCollider) { auto box = scene->create_entity("box"); - box.add_component(); + box.add_component( + new components::BoxCollider2D()); auto& transform = box.get_component(); transform.position.z(-10); + // transform.position.x(1000); - BOOST_TEST(box.has_component()); + BOOST_TEST(box.has_component()); - const auto q = scene->world().query(); - BOOST_TEST(q.count() > 0); + const auto q = scene->world().query(); + BOOST_TEST(q.count() == 1); physics::Ray ray; ray.direction = (math::Vec3f(0) - transform.position); physics::RayHit hit{}; - // physics::raycast(scene->world(), ray, hit); + physics::raycast(scene->world(), ray, hit); - // BOOST_TEST(hit.hit); + BOOST_TEST(hit.hit); + + const float length = (hit.point - math::Vec3f{0, 0, -10}).length(); + BOOST_TEST(length <= 0.001); } BOOST_AUTO_TEST_SUITE_END() From 4585eb08cee5bed238dabe0e87e462654e59e465 Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Thu, 28 Nov 2024 11:59:45 -0500 Subject: [PATCH 15/18] Passing tests --- wren/src/scene/components/collider.cpp | 9 +++++---- wren_physics/src/ray.cpp | 1 + wren_physics/tests/raycast.cpp | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/wren/src/scene/components/collider.cpp b/wren/src/scene/components/collider.cpp index 0a150c8..d41fb49 100644 --- a/wren/src/scene/components/collider.cpp +++ b/wren/src/scene/components/collider.cpp @@ -6,20 +6,21 @@ auto BoxCollider2D::raycast(const Transform& transform, const math::Vec3f& origin, const math::Vec3f& direction) const -> std::optional { - // TODO Ray - math::Vec3f normal = math::Vec3f{0, 0, 1} * transform.rotation; + math::Vec3f normal = + math::Quaternionf{transform.rotation}.to_mat() * math::Vec3f{0, 0, 1}; + float denominator = normal.dot(direction); if (std::abs(denominator) < 0.0001) { return {}; } - float t = normal.dot(origin) / denominator; + float t = normal.dot(transform.position - origin) / denominator; if (t < 0) { // Intersection points is behind the ray's origin return {}; } - return origin + (direction * t); + return origin + direction * t; } } // namespace wren::scene::components diff --git a/wren_physics/src/ray.cpp b/wren_physics/src/ray.cpp index 5b9fc16..24edc93 100644 --- a/wren_physics/src/ray.cpp +++ b/wren_physics/src/ray.cpp @@ -18,6 +18,7 @@ auto raycast(const flecs::world& world, const Ray& ray, RayHit& hit) -> bool { auto pos = collider->raycast(transform, ray.origin, ray.direction); if (pos.has_value()) { hit.hit = true; + hit.point = pos.value(); } }); diff --git a/wren_physics/tests/raycast.cpp b/wren_physics/tests/raycast.cpp index 90b818f..bc0e1aa 100644 --- a/wren_physics/tests/raycast.cpp +++ b/wren_physics/tests/raycast.cpp @@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE(RaycastBoxCollider) { BOOST_TEST(q.count() == 1); physics::Ray ray; - ray.direction = (math::Vec3f(0) - transform.position); + ray.direction = (transform.position - math::Vec3f(0)); physics::RayHit hit{}; physics::raycast(scene->world(), ray, hit); From 890e7227365a12c320d155e8526915835562695d Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Thu, 28 Nov 2024 12:01:02 -0500 Subject: [PATCH 16/18] Readd the deserialization --- wren/src/scene/deserialization.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wren/src/scene/deserialization.cpp b/wren/src/scene/deserialization.cpp index 028134a..e292a37 100644 --- a/wren/src/scene/deserialization.cpp +++ b/wren/src/scene/deserialization.cpp @@ -29,12 +29,12 @@ auto deserialize(const std::filesystem::path& project_root, for (const auto& [key, val] : entity_table) { if (key.str() == "transform") { - // auto& t = *entity.get_mut(); - // deserialize(*val.as_table(), t); + auto& t = entity.get_component(); + deserialize(*val.as_table(), t); } else if (key.str() == "mesh_renderer") { - // components::MeshRenderer mesh_renderer{}; - // deserialize(*val.as_table(), project_root, mesh_renderer); - // entity.emplace(mesh_renderer); + components::MeshRenderer mesh_renderer{}; + deserialize(*val.as_table(), project_root, mesh_renderer); + entity.add_component(mesh_renderer); } } } From d243358ee85e5db58103b7945bee5f36de670cb3 Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Thu, 28 Nov 2024 12:03:51 -0500 Subject: [PATCH 17/18] Removed comment --- wren/include/wren/scene/entity.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/wren/include/wren/scene/entity.hpp b/wren/include/wren/scene/entity.hpp index a9df194..af28301 100644 --- a/wren/include/wren/scene/entity.hpp +++ b/wren/include/wren/scene/entity.hpp @@ -42,9 +42,6 @@ auto Entity::get_component() -> T& { template concept HasInit = requires() { T::init(); }; -// template -// concept IsSmartPointer = requires() {}; - template void Entity::add_component(Args&&... args) { entity_.add(); From 8c6b3b5e33ea3203d96094b0de8d367cf38a121d Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Thu, 28 Nov 2024 12:35:44 -0500 Subject: [PATCH 18/18] Ignored projects from codecov --- codecov.yml | 4 ++++ xmake.lua | 56 ----------------------------------------------------- 2 files changed, 4 insertions(+), 56 deletions(-) delete mode 100644 xmake.lua diff --git a/codecov.yml b/codecov.yml index db83645..03bee0d 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,3 +1,7 @@ coverage: status: project: false +ignore: + - "examples" + - "tools" + - "subprojects" diff --git a/xmake.lua b/xmake.lua deleted file mode 100644 index 5e79103..0000000 --- a/xmake.lua +++ /dev/null @@ -1,56 +0,0 @@ -add_rules("mode.debug", "mode.release") -set_languages("c++23") - -add_rules("plugin.compile_commands.autoupdate", {outputdir = "build"}) - -add_requires("flecs", "vulkan-memory-allocator", "vulkan", "shaderc", "spirv-reflect", "tracy", "backward-cpp", "toml++") -add_requires("imgui 1.91.1-docking", { config = { vulkan = true, sdl2 = true, } }) -add_requires("spdlog", "fmt", "pkgconfig::SPIRV-Headers", "sdl2", { system = true }) - -local boost_inc = os.getenv("BOOST_INCLUDEDIR") - -target("wren_utils") -set_kind("static") -add_includedirs("wren_utils/include", boost_inc, { public = true }) -add_includedirs("wren_utils/include/wren/utils") -add_files("wren_utils/src/*.cpp") -add_packages("spdlog", "fmt", { public = true }) - -target("wren_math") -set_kind("static") -add_includedirs("wren_math/include", { public = true }) -add_includedirs("wren_math/include/wren/math") -add_files("wren_math/src/*.cpp") - --- target("wren_reflect") --- set_kind("static") --- add_includedirs("wren_reflect/include", spirv_inc, { public = true }) --- add_includedirs("wren_reflect/include/wren/reflect") --- add_files("wren_reflect/src/*.cpp") --- add_packages("SPIRV-Headers", { public = true }) - -target("wren_vk") -set_kind("static") -add_includedirs("wren_vk/include", { public = true }) -add_includedirs("wren_vk/include/wren/vk") -add_files("wren_vk/src/*.cpp") -add_deps("wren_math", "wren_utils", { public = true }) -add_defines("VULKAN_HPP_NO_EXCEPTIONS", - "VUKLAN_HPP_ASSERT_ON_RESULT(x)", - "VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1", { public = true }) -add_packages("vulkan", "vulkan-memory-allocator", "shaderc", "spirv-reflect", { public = true }) - -target("wren") -set_kind("static") -add_includedirs("wren/include", { public = true }) -add_includedirs("wren/include/wren") -add_files("wren/src/*.cpp", "wren/src/assets/*.cpp", "wren/src/scene/*.cpp", "wren/src/utils/*.cpp") -add_deps("wren_utils", "wren_vk", "wren_math") -add_packages("flecs", "sdl2", "tracy", "toml++", { public = true }) - -target("editor") -set_kind("binary") -add_files("editor/src/*.cpp", "editor/src/*.cppm") -add_deps("wren") -add_defines("WREN_BUILD_ASSETS_DIR=\"$(projectdir)/editor/assets\"") -add_packages("imgui", "backward-cpp", "sdl2")