My simple idea for a game engine so far is this:
Code: Select all
// Enter the main message loop
while(_pIrrDevice->run())
{
// Make sure the game engine isn't sleeping
if (!_pGameEngine->Sleep())
{
// Check the tick count to see if a game cycle has elapsed
iTickCount = _pTimer->getTime();
if (iTickCount > iTickTrigger)
{
iTickTrigger = iTickCount + _pGameEngine->FrameDelay();
//HandleKeys();
pGameEngine->HandleJoystick();
GameCycle();
_pVideoDriver->beginScene(true, true, irr::video::SColor(255,100,101,140));
// Call game paint function
GamePaint();
_pVideoDriver->endScene();
}
}
}
The
GameCycle,
HandleJoystick and
HandleKeys functions are game specific.
The
GameCycle is game specific, it takes care of state management and could use something like Brainsaw's example game state manager.
You'd have to manage game states uniquely for every game anyway.
Obviously need to tie in an event manager with this
In the event manager collect keyboard, joystick and mouse events and call the game specific event handlers which will also include:
MouseDown(), MouseUp(), MouseMove(), MouseWheel() functions.
Calling the game specific Handle Keyboard function can just be handled automatically in the event manager as I am doing at the moment (it's commented out of the loop)
Same as the Mouse is handled.