Skip to content

Commit

Permalink
Merge branch 'main' into libfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
tmayoff authored Nov 29, 2024
2 parents 85f2437 + 8d9abb1 commit 1183b98
Show file tree
Hide file tree
Showing 25 changed files with 253 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand All @@ -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 }}
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/deploy_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ on:
push:
branches:
- main
paths:
- docs/**
- Doxyfile
workflow_dispatch:

permissions:
Expand All @@ -21,7 +18,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
Expand Down
7 changes: 7 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
coverage:
status:
project: false
ignore:
- "examples"
- "tools"
- "subprojects"
2 changes: 1 addition & 1 deletion editor/src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ auto Editor::create(const std::shared_ptr<wren::Application> &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());

Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ subdir('wren_vk')
# subdir('wren_gltf')
# subdir('wren_gui')
subdir('wren')
subdir('wren_physics')
# subdir('wren_ecs')
subdir('editor')
8 changes: 8 additions & 0 deletions wren/include/wren/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class GraphBuilder {
public:
explicit GraphBuilder(const std::shared_ptr<Context> &ctx) : ctx_(ctx) {}

/**
@brief This calls compile() and then assigns the graph to the renderer
*/
[[nodiscard]] auto build() const -> expected<void>;

/**
@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<Graph>;

auto add_pass(const std::string &name, const PassResources &resources,
Expand Down
8 changes: 3 additions & 5 deletions wren/include/wren/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }

Expand Down Expand Up @@ -79,7 +77,7 @@ class Renderer {
::vk::CommandPool command_pool_;
::vk::CommandBuffer one_time_cmd_buffer;

Graph render_graph;
Graph render_graph_;

Mesh m;
};
Expand Down
17 changes: 13 additions & 4 deletions wren/include/wren/scene/components.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#pragma once

#include <functional>
#include <flecs.h>

#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<void()>);

}
} // namespace wren::scene::components
40 changes: 40 additions & 0 deletions wren/include/wren/scene/components/collider.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <flecs.h>

#include <memory>
#include <optional>
#include <wren/math/vector.hpp>
#include <wren/scene/components/transform.hpp>

#include "../components.hpp"

namespace wren::scene::components {

struct Collider : public Base {
using Ptr = std::shared_ptr<Collider>;

[[nodiscard]] virtual auto raycast(const Transform& transform,
const math::Vec3f& origin,
const math::Vec3f& direction) const
-> std::optional<math::Vec3f> = 0;
};

struct BoxCollider2D : public Collider {
static void init(const flecs::world& world) {
static bool inited = false;
if (!inited) {
inited = true;
world.component<BoxCollider2D::Ptr>().is_a<Collider>();
}
}

[[nodiscard]] auto raycast(const Transform& transform,
const math::Vec3f& origin,
const math::Vec3f& direction) const
-> std::optional<math::Vec3f> override;

math::Vec2f size;
};

} // namespace wren::scene::components
17 changes: 14 additions & 3 deletions wren/include/wren/scene/entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <flecs.h>

#include "components.hpp"
#include "scene.hpp"

namespace wren::scene {
Expand Down Expand Up @@ -30,18 +31,28 @@ class Entity {

template <typename T>
auto Entity::has_component() const -> bool {
// return scene_->world().all_of<T>();
return entity_.has<T>();
}

template <typename T>
auto Entity::get_component() -> T& {
return scene_->world().get<T>(entity_);
return *entity_.get_mut<T>();
}

template <typename T>
concept HasInit = requires() { T::init(); };

template <typename T, typename... Args>
void Entity::add_component(Args&&... args) {
entity_.add<T>();
entity_.set<T>(T(std::forward<Args>(args)...));
if (sizeof...(args) > 0) {
T t(std::forward<Args...>(args)...);
entity_.set<T>(t);
}

if constexpr (HasInit<T>) {
T::init(scene_->world());
}
}

} // namespace wren::scene
2 changes: 1 addition & 1 deletion wren/include/wren/scene/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Scene : public std::enable_shared_from_this<Scene> {
public:
static auto create() { return std::shared_ptr<Scene>(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_; }
Expand Down
1 change: 1 addition & 0 deletions wren/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions wren/src/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ auto GraphBuilder::add_pass(const std::string &name,
return *this;
}

auto GraphBuilder::build() const -> expected<void> {
TRY_RESULT(auto graph, compile());

ctx_->renderer->set_graph(graph);

return {};
}

auto GraphBuilder::compile() const -> expected<Graph> {
Graph graph;

Expand Down
6 changes: 3 additions & 3 deletions wren/src/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -119,7 +119,7 @@ Renderer::Renderer(const std::shared_ptr<Context> &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});
Expand Down Expand Up @@ -289,7 +289,7 @@ auto Renderer::recreate_swapchain() -> expected<void> {
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());

Expand Down
26 changes: 26 additions & 0 deletions wren/src/scene/components/collider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "scene/components/collider.hpp"

namespace wren::scene::components {

auto BoxCollider2D::raycast(const Transform& transform,
const math::Vec3f& origin,
const math::Vec3f& direction) const
-> std::optional<math::Vec3f> {
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(transform.position - origin) / denominator;
if (t < 0) {
// Intersection points is behind the ray's origin
return {};
}

return origin + direction * t;
}

} // namespace wren::scene::components
4 changes: 2 additions & 2 deletions wren/src/scene/deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<components::Transform>();
auto& t = entity.get_component<components::Transform>();
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<components::MeshRenderer>(mesh_renderer);
entity.add_component<components::MeshRenderer>(mesh_renderer);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions wren/src/scene/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<components::Tag>(name);
entity.add<components::Transform>();

return entity;
return {entity, shared_from_this()};
}

} // namespace wren::scene
21 changes: 21 additions & 0 deletions wren_physics/include/wren/physics/ray.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <flecs.h>

#include <wren/math/vector.hpp>

namespace wren::physics {

struct RayHit {
bool hit = false;
math::Vec3f point;
};

struct Ray {
math::Vec3f origin;
math::Vec3f direction;
};

auto raycast(const flecs::world& world, const Ray& ray, RayHit& hit) -> bool;

} // namespace wren::physics
12 changes: 12 additions & 0 deletions wren_physics/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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(
include_directories: 'include',
link_with: wren_physics,
)

subdir('tests')
Loading

0 comments on commit 1183b98

Please sign in to comment.