I have started create a lightweight game engine with Ogre and C++. I have a abstract component class and an abstract entity class.
#ifndef ENTITY_HPP_
#define ENTITY_HPP_
#include <string>
#include <vector>
#include "Component.hpp"
class Entity
{
public:
Entity(int uniqueId) { m_UniqueId = uniqueId; };
~Entity();
void AddComponent(Component *comp);
void RemoveComponent(Component *comp);
Component *GetComponent(m_ComponentTypes type);
int GetID() { return m_UniqueId; };
protected:
std::vector<Component*> m_Components;
int m_UniqueId;
};
#endif /* ENTITY_HPP_ */
Component:
/*
* Component.hpp
*
* Created on: Jul 15, 2013
* Author: dominik
*/
#ifndef COMPONENT_HPP_
#define COMPONENT_HPP_
#include <string>
class Entity;
typedef enum
{
MESH_COMPONENT,
POSITION_COMPONENT,
} m_ComponentTypes;
class Component
{
public:
Component(m_ComponentTypes type) { m_Type = type; m_pParent = NULL; };
virtual ~Component();
void SetParent(Entity *entity) { m_pParent = entity; };
Entity *GetParent() const { return m_pParent; };
m_ComponentTypes GetType() const { return m_Type; };
protected:
Entity *m_pParent;
m_ComponentTypes m_Type;
};
#endif /* COMPONENT_HPP_ */
After this I created an EntityManager where I manage all entities in the game world, an a rendersystem where I render all entities and initialize Ogre. Now I have a window, but I need the escape button managed -> so I implement an inputsystem and here is the problem. My InputSystem works with OIS which needs a handle to the window, the handle to the window is available in the RenderSystem but not in the InputSystem, how can I get this data?
Here is my engine class:
/*
* Engine.hpp
*
* Created on: Jul 15, 2013
* Author: dominik
*/
#ifndef ENGINE_HPP_
#define ENGINE_HPP_
#include "EntityManager.hpp"
#include "RenderSystem.hpp"
#include <vector>
class Engine
{
public:
static Engine *GetInstancePtr()
{
if (!instance)
instance = new Engine();
return instance;
}
EntityManager *m_pEntityManager;
void update(double timeSinceLastFrame);
void loop();
void Shutdown() { m_bShutdown = true; };
private:
static Engine *instance;
Engine()
{
m_pEntityManager = new EntityManager();
m_Systems.push_back(new RenderSystem());
m_bShutdown = false;
}
Engine(const Engine&);
~Engine()
{
delete m_pEntityManager;
while(!m_Systems.empty())
{
System *sys = m_Systems.back();
delete sys;
m_Systems.pop_back();
}
}
std::vector<System*> m_Systems;
bool m_bShutdown;
};
#endif /* CORE_HPP_ */
In my Engine singleton I have only the abstract system class, so I can't get the window handle. Is there a nice solution?
Any suggestions? Is my approach correct, or is it limitated in any way?
How should I implement the input manager, should he handle all the clicks on keyboard and mouse and send events, or should I create a component with the input manager fields and react on this in this entities which have this component added?