Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1330 add active component for all kinds of disabling purposes #1357

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ set(CUBOS_ENGINE_SOURCE
"src/render/shadow_atlas_rasterizer/shadow_atlas_rasterizer.cpp"
"src/render/cascaded_shadow_maps/plugin.cpp"
"src/render/cascaded_shadow_maps_rasterizer/plugin.cpp"
"src/render/active/plugin.cpp"
"src/render/active/active.cpp"

"src/tools/settings_inspector/plugin.cpp"
"src/tools/selection/plugin.cpp"
Expand Down
20 changes: 20 additions & 0 deletions engine/include/cubos/engine/render/active/active.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// @file
/// @brief Component @ref cubos::engine::Active
/// @ingroup render-active-plugin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this plugin should be a render-plugin. It is also relevant outside it. We'll use it for audio, and probably for collisions too later on. So, it would be better to put it in engine-plugin, and move to active dir to cubos/engine/

#pragma once

#include <cubos/core/reflection/reflect.hpp>

namespace cubos::engine
{
/// @brief Component which stores the active state for an entity.
/// @note Added automatically once a specific camera or light is added.
RodrigoVintem marked this conversation as resolved.
Show resolved Hide resolved
/// @ingroup render-active-plugin
struct Active
{
CUBOS_REFLECT;

/// @brief Whether the entity is active.
bool active = true;
};
} // namespace cubos::engine
10 changes: 10 additions & 0 deletions engine/include/cubos/engine/render/active/plugin.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once
RodrigoVintem marked this conversation as resolved.
Show resolved Hide resolved

#include <cubos/engine/api.hpp>
#include <cubos/engine/prelude.hpp>
#include <cubos/engine/render/active/active.hpp>

namespace cubos::engine
{
CUBOS_ENGINE_API void activePlugin(Cubos& cubos);
RodrigoVintem marked this conversation as resolved.
Show resolved Hide resolved
}
3 changes: 0 additions & 3 deletions engine/include/cubos/engine/render/camera/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ namespace cubos::engine
{
CUBOS_REFLECT;

/// @brief Whether the camera is drawing to a target.
bool active{true};

/// @brief Projection matrix of the camera.
glm::mat4 projection{};

Expand Down
9 changes: 9 additions & 0 deletions engine/src/render/active/active.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <cubos/core/ecs/reflection.hpp>
#include <cubos/core/reflection/external/primitives.hpp>

#include <cubos/engine/render/active/active.hpp>

CUBOS_REFLECT_IMPL(cubos::engine::Active)

Check warning on line 6 in engine/src/render/active/active.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/active/active.cpp#L6

Added line #L6 was not covered by tests
{
return core::ecs::TypeBuilder<Active>("cubos::engine::Active").withField("active", &Active::active).build();

Check warning on line 8 in engine/src/render/active/active.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/active/active.cpp#L8

Added line #L8 was not covered by tests
}
7 changes: 7 additions & 0 deletions engine/src/render/active/plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <cubos/engine/render/active/active.hpp>
#include <cubos/engine/render/active/plugin.hpp>

void cubos::engine::activePlugin(Cubos& cubos)

Check warning on line 4 in engine/src/render/active/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/active/plugin.cpp#L4

Added line #L4 was not covered by tests
{
cubos.component<Active>();
}

Check warning on line 7 in engine/src/render/active/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/active/plugin.cpp#L6-L7

Added lines #L6 - L7 were not covered by tests
1 change: 0 additions & 1 deletion engine/src/render/camera/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
CUBOS_REFLECT_IMPL(cubos::engine::Camera)
{
return core::ecs::TypeBuilder<Camera>("cubos::engine::Camera")
.withField("active", &Camera::active)
.withField("projection", &Camera::projection)
.withField("zNear", &Camera::zNear)
.withField("zFar", &Camera::zFar)
Expand Down
13 changes: 13 additions & 0 deletions engine/src/render/camera/plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <glm/gtc/matrix_transform.hpp>

#include <cubos/engine/render/active/active.hpp>
#include <cubos/engine/render/active/plugin.hpp>
#include <cubos/engine/render/camera/camera.hpp>
#include <cubos/engine/render/camera/draws_to.hpp>
#include <cubos/engine/render/camera/orthographic.hpp>
Expand All @@ -13,13 +15,24 @@
void cubos::engine::cameraPlugin(Cubos& cubos)
{
cubos.depends(renderTargetPlugin);
cubos.depends(activePlugin);

Check warning on line 18 in engine/src/render/camera/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/camera/plugin.cpp#L18

Added line #L18 was not covered by tests

cubos.component<Camera>();
cubos.component<PerspectiveCamera>();
cubos.component<OrthographicCamera>();

cubos.relation<DrawsTo>();

cubos.observer("add active component on add Camera")
.onAdd<Camera>()
.without<Active>()
.call([](Commands cmds, Query<Entity> query) {

Check warning on line 29 in engine/src/render/camera/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/camera/plugin.cpp#L26-L29

Added lines #L26 - L29 were not covered by tests
for (auto [ent] : query)
{
cmds.add(ent, Active{});

Check warning on line 32 in engine/src/render/camera/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/camera/plugin.cpp#L32

Added line #L32 was not covered by tests
}
});

Check warning on line 34 in engine/src/render/camera/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/camera/plugin.cpp#L34

Added line #L34 was not covered by tests

cubos.observer("add Camera on add PerspectiveCamera")
.onAdd<PerspectiveCamera>()
.without<Camera>()
Expand Down
18 changes: 12 additions & 6 deletions engine/src/render/cascaded_shadow_maps/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cubos/core/io/window.hpp>
#include <cubos/core/reflection/external/primitives.hpp>

#include <cubos/engine/render/active/plugin.hpp>
#include <cubos/engine/render/camera/camera.hpp>
#include <cubos/engine/render/camera/plugin.hpp>
#include <cubos/engine/render/cascaded_shadow_maps/plugin.hpp>
Expand All @@ -26,9 +27,14 @@

cubos.system("create cascaded shadow maps")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you also need to add cubos.depends(cameraPlugin) here, and the same goes for the other plugins.
Have you tested running the shadows sample? It probably crashes

.tagged(createCascadedShadowMapsTag)
.call([](const Window& window, Query<DirectionalShadowCaster&> query, Query<Entity, const Camera&> cameras) {
for (auto [caster] : query)
.call([](const Window& window, Query<DirectionalShadowCaster&, const Active&> query,

Check warning on line 30 in engine/src/render/cascaded_shadow_maps/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/cascaded_shadow_maps/plugin.cpp#L30

Added line #L30 was not covered by tests
Query<Entity, const Camera&, const Active&> cameras) {
for (auto [caster, active] : query)
{
if (!active.active)
{
continue;

Check warning on line 36 in engine/src/render/cascaded_shadow_maps/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/cascaded_shadow_maps/plugin.cpp#L36

Added line #L36 was not covered by tests
}
// Remove shadow maps for cameras that no longer exist
std::vector<Entity> removedCameras;
for (auto& [cameraEntity, shadowMap] : caster.shadowMaps)
Expand All @@ -38,9 +44,9 @@
removedCameras.push_back(cameraEntity);
}
}
for (auto [entity, camera] : cameras)
for (auto [entity, camera, cameraActive] : cameras)
{
if (!camera.active && caster.shadowMaps.contains(entity))
if (!cameraActive.active && caster.shadowMaps.contains(entity))
{
removedCameras.push_back(entity);
}
Expand All @@ -53,9 +59,9 @@
caster.updateShadowMaps(window->renderDevice());

// Create shadow maps for new cameras
for (auto [entity, camera] : cameras)
for (auto [entity, camera, cameraActive] : cameras)
{
if (camera.active && !caster.shadowMaps.contains(entity))
if (cameraActive.active && !caster.shadowMaps.contains(entity))
{
caster.shadowMaps[entity] = std::make_shared<DirectionalShadowCaster::ShadowMap>();
caster.shadowMaps[entity]->resize(window->renderDevice(), caster.size,
Expand Down
Loading
Loading