Skip to content

Commit bc3c449

Browse files
Merge pull request #634 from novelrt/feature/sprite-rendering-system
Re-introduce sprite rendering to the ECS.
2 parents c153a4f + 0aa414c commit bc3c449

50 files changed

Lines changed: 1318 additions & 797 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Ecs/Core/EcsDefaultsBuilder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
// for more information.
33

44
#include <NovelRT/Ecs/EcsDefaultsBuilder.hpp>
5+
#include <NovelRT/Maths/GeoVector2F.hpp>
6+
#include <NovelRT/Maths/GeoVector3F.hpp>
57

68
using namespace NovelRT::Ecs;
79

810
EcsDefaultsBuilder::EcsDefaultsBuilder()
911
: _defaultEntityGraphComponent{false, std::numeric_limits<EntityId>::max(), std::numeric_limits<EntityId>::max()},
1012
_defaultLinkedEntityListNodeComponent{false, std::numeric_limits<EntityId>::max(),
1113
std::numeric_limits<EntityId>::max()},
12-
_defaultTransformComponent{Maths::GeoVector3F::Uniform(NAN), Maths::GeoVector2F::Uniform(NAN), NAN} {};
14+
_defaultTransformComponent{Maths::GeoVector2F::Uniform(NAN), Maths::GeoVector2F::Uniform(NAN), NAN} {};
1315

1416
EcsDefaultsBuilder& NovelRT::Ecs::EcsDefaultsBuilder::WithDefaultEntityGraphComponent(
1517
const Components::EntityGraphComponent& defaultGraphComponent)

Ecs/Core/SystemScheduler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ namespace NovelRT::Ecs
262262
});
263263
}
264264

265+
_ecsTasks->wait();
266+
265267
for (SystemId systemId : layer)
266268
{
267269
_ecsTasks->run(

Ecs/Core/include/NovelRT/Ecs/Catalogue.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ namespace NovelRT::Ecs
118118
* callback that is executed on the next iteration of the ECS once the work is done.
119119
*
120120
* The work functor is executed asynchronously on a separate thread pool and must not interact
121-
* with the ECS or capture any references to a Catalogue instance, as the behaviour is undefined.
121+
* with ECS memory regions or capture any references to a Catalogue instance, as the behaviour is undefined.
122+
* Capturing the this pointer of an IEcsSystem instance is safe and OK to do.
122123
* The completion functor is executed on the ECS thread pool in the next available iteration,
123124
* and receives a fresh Catalogue instance with the correct threading context, the current delta time,
124125
* and the result of the work functor.

Ecs/Core/include/NovelRT/Ecs/ComponentView.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ namespace NovelRT::Ecs
9292
PushComponentUpdateInstruction(entity, _componentBuffer.GetDeleteInstructionState());
9393
}
9494

95+
/**
96+
* @brief Removes all components of the given type from the ECS simulation.
97+
*
98+
* @param entity The EntityId to remove the component from.
99+
*
100+
* @exception Exceptions::DuplicateKeyException when multiple update instructions are pushed to this buffer on
101+
* the same thread.
102+
*/
103+
void RemoveAllComponents()
104+
{
105+
for (auto&& [entity, component] : *this)
106+
{
107+
RemoveComponent(entity);
108+
}
109+
}
110+
95111
/**
96112
* @brief Gets the immutable component state for a delete instruction.
97113
*

Ecs/Core/include/NovelRT/Ecs/Components/TransformComponent.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ namespace NovelRT::Ecs::Components
1414
{
1515
struct TransformComponent
1616
{
17-
Maths::GeoVector3F positionAndLayer = Maths::GeoVector3F::Zero();
17+
Maths::GeoVector2F position = Maths::GeoVector2F::Zero();
1818
Maths::GeoVector2F scale = Maths::GeoVector2F::One();
1919
float rotationInRadians = 0.0f;
2020

2121
inline TransformComponent& operator+=(const TransformComponent& other)
2222
{
23-
positionAndLayer += other.positionAndLayer;
23+
position += other.position;
2424
rotationInRadians += other.rotationInRadians;
2525
scale += other.scale;
2626

@@ -38,7 +38,7 @@ namespace NovelRT::Ecs::Components
3838

3939
friend inline bool operator==(const TransformComponent& lhs, const TransformComponent& rhs) noexcept
4040
{
41-
return lhs.positionAndLayer == rhs.positionAndLayer && lhs.scale == rhs.scale &&
41+
return lhs.position == rhs.position && lhs.scale == rhs.scale &&
4242
lhs.rotationInRadians == rhs.rotationInRadians;
4343
}
4444

Ecs/Core/include/NovelRT/Ecs/MiscTemplateImpls.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ namespace NovelRT::Ecs
2525
[&]()
2626
{
2727
_asyncTasks->run(
28-
[work = std::forward<TWork>(work), completion = std::forward<TCompletion>(completion),
29-
this]() mutable
28+
[work = std::make_shared<std::decay_t<TWork>>(std::forward<TWork>(work)),
29+
completion = std::make_shared<std::decay_t<TCompletion>>(std::forward<TCompletion>(completion)),
30+
this]()
3031
{
31-
auto result = work();
32-
_pendingCompletions.push([completion = std::move(completion), result = std::move(result)](
33-
Timing::Timestamp delta, Catalogue cat) mutable
34-
{ completion(delta, cat, std::move(result)); });
32+
auto result = (*work)();
33+
_pendingCompletions.push(
34+
[completion, result = std::move(result)](Timing::Timestamp delta, Catalogue cat) mutable
35+
{ (*completion)(delta, cat, std::move(result)); });
3536
});
3637
});
3738
}

Ecs/Graphics/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ NovelRTBuildSystem_DeclareModule(LIBRARY NovelRT::Ecs::Graphics
44
DEPENDS
55
NovelRT::Ecs::Core
66
NovelRT::Graphics
7+
NovelRT::ResourceManagement::Desktop
78

89
SOURCES
910
PRIVATE
@@ -17,4 +18,7 @@ NovelRTBuildSystem_DeclareModule(LIBRARY NovelRT::Ecs::Graphics
1718
include/NovelRT/Ecs/Graphics/EcsGraphicsBuilder.hpp
1819
include/NovelRT/Ecs/Graphics/RenderOrchestratorSystem.hpp
1920
include/NovelRT/Ecs/Graphics/SpriteRendererSystem.hpp
21+
include/NovelRT/Ecs/Graphics/Components/TrackedSemaphore.hpp
22+
include/NovelRT/Ecs/Graphics/Components/Camera.hpp
23+
include/NovelRT/Ecs/Graphics/Components/Viewport.hpp
2024
)

Ecs/Graphics/include/NovelRT/Ecs/Graphics/Components/BuiltCommandList.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ namespace NovelRT::Ecs::Graphics::Components
1818
inline BuiltCommandList& operator+=(const BuiltCommandList& other)
1919
{
2020
if (commandList != nullptr)
21+
{
2122
delete commandList;
23+
}
24+
2225
*this = other;
2326
return *this;
2427
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
3+
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
4+
// for more information.
5+
6+
namespace NovelRT::Ecs::Graphics::Components
7+
{
8+
struct Camera
9+
{
10+
float left = -1.0f;
11+
float right = 1.0f;
12+
float bottom = -1.0f;
13+
float top = 1.0f;
14+
float nearPlane = 0.0f;
15+
float farPlane = 1.0f;
16+
int32_t referenceResolutionWidth = 100;
17+
int32_t referenceResolutionHeight = 100;
18+
19+
bool isScreenSpace = false;
20+
21+
inline Camera& operator+=(const Camera& other)
22+
{
23+
*this = other;
24+
return *this;
25+
}
26+
27+
[[nodiscard]] inline bool operator==(const Camera& other) const noexcept
28+
{
29+
// normally I would care more about floating point comparison but this is basically only here to handle
30+
// deletion, where it'll always be zero. - Matt J.
31+
return left == other.left && right == other.right && bottom == other.bottom && top == other.top &&
32+
nearPlane == other.nearPlane && farPlane == other.farPlane && isScreenSpace == other.isScreenSpace &&
33+
referenceResolutionWidth == other.referenceResolutionWidth &&
34+
referenceResolutionHeight == other.referenceResolutionHeight;
35+
}
36+
37+
[[nodiscard]] inline bool operator!=(const Camera& other) const noexcept
38+
{
39+
return !(*this == other);
40+
}
41+
};
42+
}

Ecs/Graphics/include/NovelRT/Ecs/Graphics/Components/RenderPass.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@ namespace NovelRT::Ecs::Graphics::Components
1515
struct RenderPass
1616
{
1717
RenderPassId renderPassIndex;
18-
19-
std::shared_ptr<NovelRT::Graphics::GraphicsDescriptorSet<TGraphicsBackend>>* descriptorSet;
18+
std::shared_ptr<NovelRT::Graphics::GraphicsDescriptorSet<TGraphicsBackend>>* descriptorSets;
19+
size_t descriptorSetCount = 0;
2020

2121
inline RenderPass& operator+=(const RenderPass& other)
2222
{
23-
if (descriptorSet != nullptr)
24-
delete descriptorSet;
23+
if (descriptorSets != nullptr)
24+
{
25+
delete[] descriptorSets;
26+
}
27+
2528
*this = other;
2629
return *this;
2730
}
2831

2932
[[nodiscard]] inline bool operator==(const RenderPass& other) const noexcept
3033
{
31-
return renderPassIndex == other.renderPassIndex;
34+
return renderPassIndex == other.renderPassIndex && descriptorSets == other.descriptorSets &&
35+
descriptorSetCount == other.descriptorSetCount;
3236
}
3337

3438
[[nodiscard]] inline bool operator!=(const RenderPass& other) const noexcept

0 commit comments

Comments
 (0)