Hello, I'm Junior Game Engine Dev. In this day, I'm tried to use Entity Component System for my project. So, the code like this ISystem.h
< ISystem.h >
#ifndef __ISYSTEM_H__
#define __ISYSTEM_H__
class ISystem
{
public :
ISystem() {};
virtual ~ISystem() {};
public :
virtual void Update( float DeltaTime ) = 0;
};
#endif __ISYSTEM_H__
< RenderSystem.h >
#ifndef __RENDERSYSTEM_H__
#define __RENDERSYSTEM_H__
#include "ISystem.h"
class RenderSystem : public ISystem
{
public :
RenderSystem() : ISystem() {};
virtual ~RenderSystem() {};
public :
virtual void Update( float DeltaTime )
{
// Rendering Logic ...
}
};
#endif __RENDERSYSTEM_H__
< PhysicsSystem.h >
#ifndef __PHYSICSSYSTEM_H__
#define __PHYSICSSYSTEM_H__
#include "ISystem.h"
class PhysicsSystem : public ISystem
{
public :
PhysicsSystem() : ISystem() {};
virtual ~PhysicsSystem() {};
public :
virtual void Update( float DeltaTime )
{
// Calculate Force, Velocity ...
}
};
#endif __PHYSICSSYSTEM_H__
And, SystemManager is the object that register, delete system and change system's running sequence.
< SystemManager.h >
#ifndef __SYSTEMMANAGER_H__
#define __SYSTEMMANAGER_H__
#include "ISystem.h"
class SystemManager
{
private :
SystemManager() {};
~SystemManager() {};
public :
void Register( ISystem*& Other )
{
m_Data.push_back( Other );
}
void Remove( ISystem*& Other )
{
// Logic for finding specific System and removing on m_Data;
}
void Move( ISystem*& Other, int Index )
{
// Logic for finding specific System of Index and switching Other System;
}
void Run( float DeltaTime)
{
for ( auto System : m_Data )
{
System->Update( DeltaTime );
}
}
private :
static SystemManager m_SystemManager;
std::vector< ISystem* > m_Data;
};
SystemManager SystemManager::m_SystemManager;
#endif __SYSTEMMANAGER_H__
But, I thought, the Other Systems are other type. So, they can not save near on memory.
I just make vector for ISystem*
< main.cpp >
#include "SystemManager.h"
#include "RenderSystem.h"
#include "PhysicsSystem.h"
int main()
{
// ... Some Logic other game module ... //
SystemManager::Register( new RenderSystem() );
SystemManager::Register( new PhysicsSystem() );
// ... Some Logic other game module ... //
return 0;
};
In this situation, the m_Data just save ISystem's pointer.
So, RenderSystem and PhysicsSystem are not saved near on memroy.
How to save each System that are differenct type and inheritance ISystem near on memory?