Add initial ECS support

This commit is contained in:
Jérôme Leclercq
2021-06-20 13:33:10 +02:00
parent 6f87a01fb2
commit c1a9a22177
17 changed files with 423 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
// Copyright (C) 2021 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_GRAPHICSCOMPONENT_HPP
#define NAZARA_GRAPHICSCOMPONENT_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ECS.hpp>
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Graphics/WorldInstance.hpp>
#include <memory>
#include <vector>
namespace Nz
{
class NAZARA_GRAPHICS_API GraphicsComponent
{
public:
GraphicsComponent() = default;
GraphicsComponent(const GraphicsComponent&) = default;
GraphicsComponent(GraphicsComponent&&) = default;
~GraphicsComponent() = default;
inline void AttachRenderable(std::shared_ptr<InstancedRenderable> renderable);
inline void DetachRenderable(const std::shared_ptr<InstancedRenderable>& renderable);
inline const std::vector<std::shared_ptr<InstancedRenderable>>& GetRenderables() const;
inline WorldInstance& GetWorldInstance();
inline const WorldInstance& GetWorldInstance() const;
GraphicsComponent& operator=(const GraphicsComponent&) = default;
GraphicsComponent& operator=(GraphicsComponent&&) = default;
private:
std::vector<std::shared_ptr<InstancedRenderable>> m_renderables;
WorldInstance m_worldInstance;
};
}
#include <Nazara/Graphics/Components/GraphicsComponent.inl>
#endif

View File

@@ -0,0 +1,37 @@
// Copyright (C) 2021 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <Nazara/Utility/Components/NodeComponent.hpp>
#include <Nazara/Utility/Debug.hpp>
#include "GraphicsComponent.hpp"
namespace Nz
{
inline void GraphicsComponent::AttachRenderable(std::shared_ptr<InstancedRenderable> renderable)
{
m_renderables.push_back(std::move(renderable));
}
inline void GraphicsComponent::DetachRenderable(const std::shared_ptr<InstancedRenderable>& renderable)
{
auto it = std::find(m_renderables.begin(), m_renderables.end(), renderable);
if (it != m_renderables.end())
m_renderables.erase(it);
}
inline const std::vector<std::shared_ptr<InstancedRenderable>>& GraphicsComponent::GetRenderables() const
{
return m_renderables;
}
inline WorldInstance& GraphicsComponent::GetWorldInstance()
{
return m_worldInstance;
}
inline const WorldInstance& GraphicsComponent::GetWorldInstance() const
{
return m_worldInstance;
}
}