Add ecs ComponentListener

- Add ecs ComponentListener which listens to Component addition and
  removal
- Add RefCounter class used to keep track of moves and copies
This commit is contained in:
Thraix
2023-05-29 17:49:37 +02:00
parent 5a615ecc4e
commit 3ec9bcd152
24 changed files with 351 additions and 70 deletions
+1 -8
View File
@@ -77,7 +77,7 @@ namespace Copium
Vulkan::GetSwapChain().SubmitToGraphicsQueue(*commandBuffer);
Vulkan::GetSwapChain().EndPresent();
return !glfwWindowShouldClose(Vulkan::GetWindow().GetWindow());
return !Vulkan::GetWindow().ShouldClose();
}
EventResult Application::OnEvent(const Event& event)
@@ -100,13 +100,6 @@ namespace Copium
return EventResult::Focus;
}
case EventType::KeyPress:
{
const KeyPressEvent& keyPressEvent = static_cast<const KeyPressEvent&>(event);
CP_INFO("%d", keyPressEvent.GetButton());
return EventResult::Handled;
}
case EventType::MouseScroll:
{
const MouseScrollEvent& mouseScrollEvent = static_cast<const MouseScrollEvent&>(event);
+9 -2
View File
@@ -7,14 +7,17 @@
#include "copium/ecs/Entity.h"
#include "copium/ecs/System.h"
#include "copium/event/MouseMoveEvent.h"
#include "copium/example/CameraFollowPlayerSystem.h"
#include "copium/example/CameraUpdateSystem.h"
#include "copium/example/Components.h"
#include "copium/example/FrameCountSystem.h"
#include "copium/example/HealthChangeSystem.h"
#include "copium/example/HealthComponentListener.h"
#include "copium/example/HealthDisplaySystem.h"
#include "copium/example/MouseFollowSystem.h"
#include "copium/example/RenderSystem.h"
#include "copium/example/PhysicsSystem.h"
#include "copium/example/PlayerControllerSystem.h"
#include "copium/example/CameraFollowPlayerSystem.h"
#include "copium/example/RenderSystem.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
@@ -30,11 +33,14 @@ namespace Copium
ecs->AddSystem<PlayerControllerSystem>();
ecs->AddSystem<PhysicsSystem>();
ecs->AddSystem<HealthChangeSystem>();
ecs->AddSystem<HealthDisplaySystem>();
ecs->AddSystem<CameraFollowPlayerSystem>();
ecs->AddSystem<CameraUpdateSystem>(&viewMatrix, &projectionMatrix, &invPvMatrix);
ecs->AddSystem<MouseFollowSystem>(&invPvMatrix);
ecs->AddSystem<FrameCountSystem>();
ecs->AddSystem<RenderSystem>(renderer.get(), descriptorSetRenderer.get(), &commandBuffer, &viewMatrix, &projectionMatrix); // better way to store the RenderSystem data?
ecs->SetComponentListener<HealthComponentListener>();
// TODO: Load from scene file
for (int y = 0; y < 10; y++)
@@ -72,6 +78,7 @@ namespace Copium
Entity entityPlayer = Entity::Create(ecs.get());
entityPlayer.AddComponent<PlayerC>(entityCamera);
entityPlayer.AddComponent<HealthC>(10, 10);
entityPlayer.AddComponent<PhysicsC>(0.1f, glm::vec2{0.0f, 0.0f}, glm::vec2{0.0f, 0.0f});
entityPlayer.AddComponent<TransformC>(glm::vec2{0.0f}, glm::vec2{1.0f});
entityPlayer.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("fox2.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{1.0f, 1.0f});
@@ -4,6 +4,8 @@
#include "copium/core/Vulkan.h"
#include "copium/sampler/Image.h"
#include <GLFW/glfw3.h>
namespace Copium
{
SwapChainSupportDetails::SwapChainSupportDetails(VkSurfaceKHR surface, VkPhysicalDevice physicalDevice)
+18
View File
@@ -12,6 +12,8 @@
#include "copium/event/WindowResizeEvent.h"
#include "copium/event/WindowFocusEvent.h"
#include <GLFW/glfw3.h>
namespace Copium
{
Window::Window(const std::string& windowName, int width, int height, WindowMode mode)
@@ -27,6 +29,22 @@ namespace Copium
glfwDestroyWindow(window);
}
bool Window::ShouldClose() const
{
return glfwWindowShouldClose(window);
}
int Window::GetWidth() const
{
return width;
}
int Window::GetHeight() const
{
return height;
}
VkSurfaceKHR Window::GetSurface() const
{
return surface;
+12 -2
View File
@@ -3,11 +3,17 @@
#include "copium/util/Common.h"
#include "copium/util/Enum.h"
#include <GLFW/glfw3.h>
#include <vulkan/vulkan.hpp>
#define CP_WINDOW_MODE_ENUMS \
Fullscreen, \
BorderlessWindowed, \
Windowed
#define CP_WINDOW_MODE_ENUMS Fullscreen, BorderlessWindowed, Windowed
CP_ENUM_CREATOR(Copium, WindowMode, CP_WINDOW_MODE_ENUMS);
struct GLFWwindow;
namespace Copium
{
class Window final
@@ -24,6 +30,10 @@ namespace Copium
Window(const std::string& windowName, int width, int height, WindowMode mode);
~Window();
bool ShouldClose() const;
int GetWidth() const;
int GetHeight() const;
VkSurfaceKHR GetSurface() const;
GLFWwindow* GetWindow();