Game Development Reference
bool game::OnInput(std::shared_ptr<input_device> device)
if ( device->Active(eInput::Forward) )
// move forward
And of course, we need to install our function pointer at some point during initialization,
or during construction, where we do this may depend on many factors.
Finally, we are able to invoke the callback whenever an input from the user is received.
if ( keyboard->IsKeyPressed() )
if (m_inputCallback != nullptr )
Notice that we check if the pointer is valid, it's doesn't always need to be required, as the
system should be able to run even if we are not interested in providing a callback.
Thebiggest problem withthisexample isthat itisapplying asolution toageneral problem
within a specific feature, the danger of doing this is that we can end up applying the same
To find a more general way to solve this problem, we can draw inspiration from the way
C# implements delegates to create reusable, general purpose callbacks.