ECS/ECS.hpp is now beautiful !
This commit is contained in:
parent
a2e70e3184
commit
aaaa21f73a
|
@ -1,34 +1,4 @@
|
|||
# ---> C++
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
2D_Engine
|
|
@ -32,8 +32,8 @@ $(sdl2-config --cflags --libs)
|
|||
-Woverloaded-virtual
|
||||
|
||||
# Debug
|
||||
-DDEBUG_MODE
|
||||
-g
|
||||
#-DDEBUG_MODE
|
||||
#-g
|
||||
|
||||
# Release
|
||||
#-O2
|
||||
-O2
|
||||
|
|
28
ECS/ECS.hpp
28
ECS/ECS.hpp
|
@ -45,8 +45,7 @@ constexpr std::size_t maxComponents = 32;
|
|||
using ComponentBitSet = bitset<maxComponents>;
|
||||
using ComponentArray = array<Component*, maxComponents>;
|
||||
|
||||
class Component {
|
||||
public:
|
||||
struct Component {
|
||||
Entity *entity;
|
||||
|
||||
virtual void init() {}
|
||||
|
@ -98,16 +97,20 @@ class Entity {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
bool hasComponent() const {
|
||||
bool hasComponent() const
|
||||
{
|
||||
// Vérifier d'abord si un type exact est présent
|
||||
ComponentID id = getComponentTypeID<T>();
|
||||
if (m_componentBitSet[id]) {
|
||||
if(m_componentBitSet[id])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Si non, vérifier dynamiquement tous les composants pour un type dérivé
|
||||
for (const auto& c : m_components) {
|
||||
if (dynamic_cast<T*>(c.get())) {
|
||||
for(const auto& c : m_components)
|
||||
{
|
||||
if (dynamic_cast<T*>(c.get()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -115,19 +118,24 @@ class Entity {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
T& getComponent() const {
|
||||
T& getComponent() const
|
||||
{
|
||||
// Vérification rapide via le BitSet et l'accès direct au composant via l'array
|
||||
ComponentID id = getComponentTypeID<T>();
|
||||
if (m_componentBitSet[id]) {
|
||||
if (m_componentBitSet[id])
|
||||
{
|
||||
return *static_cast<T*>(m_componentArray[id]);
|
||||
}
|
||||
|
||||
// Vérification polymorphique avec dynamic_cast
|
||||
for (const auto& c : m_components) {
|
||||
if (T* t = dynamic_cast<T*>(c.get())) {
|
||||
for (const auto& c : m_components)
|
||||
{
|
||||
if (T* t = dynamic_cast<T*>(c.get()))
|
||||
{
|
||||
return *t;
|
||||
}
|
||||
}
|
||||
|
||||
throw runtime_error("Composant non trouvé.\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -190,7 +190,11 @@
|
|||
|
||||
"CurrentFrame": 0,
|
||||
|
||||
<<<<<<< HEAD
|
||||
"FrameDelay": 60,
|
||||
=======
|
||||
"FrameDelay": 30,
|
||||
>>>>>>> stash
|
||||
|
||||
"PlayAnimation": false
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue