Add initial ECS support
This commit is contained in:
46
include/Nazara/Core/ECS.hpp
Normal file
46
include/Nazara/Core/ECS.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ECS_HPP
|
||||
#define NAZARA_ECS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class GraphicsComponent;
|
||||
class NodeComponent;
|
||||
class RigidBody3DComponent;
|
||||
|
||||
class ECS : public ModuleBase<ECS>
|
||||
{
|
||||
friend ModuleBase;
|
||||
friend class Audio;
|
||||
friend class Graphics;
|
||||
friend class Physics2D;
|
||||
friend class Physics3D;
|
||||
friend class Utility;
|
||||
|
||||
public:
|
||||
using Dependencies = TypeList<Core>;
|
||||
|
||||
struct Config {};
|
||||
|
||||
inline ECS(Config /*config*/);
|
||||
~ECS() = default;
|
||||
|
||||
private:
|
||||
static inline void RegisterComponents();
|
||||
|
||||
NAZARA_CORE_API static ECS* s_instance;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/ECS.inl>
|
||||
|
||||
#endif
|
||||
35
include/Nazara/Core/ECS.inl
Normal file
35
include/Nazara/Core/ECS.inl
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/ECS.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::ECS
|
||||
* \brief Core class that represents the ECS module
|
||||
*/
|
||||
inline ECS::ECS(Config /*config*/) :
|
||||
ModuleBase("ECS", this)
|
||||
{
|
||||
RegisterComponents();
|
||||
}
|
||||
|
||||
inline void ECS::RegisterComponents()
|
||||
{
|
||||
if (entt::type_seq<NodeComponent>() != 0)
|
||||
throw std::runtime_error("NodeComponent has wrong index, please initialize Nazara ECS before instancing your own components");
|
||||
|
||||
if (entt::type_seq<GraphicsComponent>() != 1)
|
||||
throw std::runtime_error("GraphicsComponent has wrong index, please initialize Nazara ECS before instancing your own components");
|
||||
|
||||
if (entt::type_seq<RigidBody3DComponent>() != 2)
|
||||
throw std::runtime_error("GraphicsComponent has wrong index, please initialize Nazara ECS before instancing your own components");
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user