Game Development Reference
In-Depth Information
function Update( float deltaTime )
// Clear out any active bindings from last
frame
activeBindings .Clear()
// KeyValuePair has a .key and .value member
for the
// key and value from the map, respectively.
foreach KeyValuePair k in keyBindings
// Use previously-defined GetKeyState to
grab the state
// of this particular key code.
if GetKeyState( k . value . keyCode ) ==
k . value . stateType
// If this matches, this binding is
active
activeBindings .Add( k . key , k . value )
end
end
// If there are any active bindings, send it
to the UI first
if activeBindings .Count() != 0
// Send active bindings to UI
...
// Send active bindings to rest of game
...
end
end
end
One inefficiency of this system is that if there are multiple bindings that use the
same key, their state will be checked multiple times every frame. This could def-
initely be optimized, but I chose not to for the purposes of simplicity and ease of
implementation.
Search WWH ::




Custom Search