So, I've been continuing to slowly work on this project in my spare time. I've completed a simple scene management system as well as re-factored some of the base Game class into an Application class which contains most of the high-level engine components such as rendering and window setup.
Also, I've put together an input system which I think should be somewhat easy to deal with as I continue to add more functionality.
I decided to use a combination of the Observer pattern and the Command pattern so that I could have one central object that actually deals with the raw inputs and then passes friendly commands to interested parties.
Here's how it should all work:
1. InputController listens each frame for any new keys that we are particularly interested in.
class InputController : public IGameComponent
{
private:
CL_InputDevice m_keyboard;
vector m_keysThisFrame;
vector; m_commandObservers;
virtual void Initialize();
void notifyObservers();
public:
~InputController();
void Initialize(CL_InputDevice);
virtual void Update(unsigned int);
virtual void Draw(CL_GraphicContext& graphicsContext);
void registerObserver(ICommandController*);
void removeObserver(const ICommandController&);
};
class Game;
class SystemCommandController : public ICommandController
{
public:
SystemCommandController(Game&);
~SystemCommandController();
void Notify(vector);
private:
Game& m_gameObject;
};
class Game;
class SystemCommand : public ICommand
{
public:
enum SystemCommands {EXITGAME};
SystemCommand(Game&, SystemCommands);
~SystemCommand();
void Execute();
private:
Game& m_gameObject;
SystemCommands m_commandToExecute;
};
And the actual implementation of the SystemCommand class so you can see how the commands are handled: #include "SystemCommand.h"
SystemCommand::SystemCommand(Game& gameObj, SystemCommand::SystemCommands command) : m_gameObject(gameObj)
{
m_commandToExecute = command;
}
SystemCommand::~SystemCommand()
{
}
void SystemCommand::Execute()
{
switch (m_commandToExecute)
{
case EXITGAME:
m_gameObject.ExitGame();
break;
}
}