2010-07-09 19:21:04 +00:00
|
|
|
#ifndef OENGINE_INPUT_DISPATCHER_H
|
|
|
|
#define OENGINE_INPUT_DISPATCHER_H
|
2010-07-04 12:28:51 +00:00
|
|
|
|
|
|
|
#include "dispatch_map.hpp"
|
|
|
|
#include "func_binder.hpp"
|
|
|
|
#include <mangle/input/event.hpp>
|
|
|
|
|
2010-07-10 11:41:43 +00:00
|
|
|
namespace OEngine {
|
2010-07-04 12:28:51 +00:00
|
|
|
namespace Input {
|
|
|
|
|
|
|
|
struct Dispatcher : Mangle::Input::Event
|
|
|
|
{
|
|
|
|
DispatchMap map;
|
|
|
|
FuncBinder funcs;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructor. Takes the number of actions and passes it to
|
|
|
|
FuncBinder.
|
|
|
|
*/
|
|
|
|
Dispatcher(int actions) : funcs(actions) {}
|
|
|
|
|
|
|
|
void bind(int action, int key) { map.bind(key, action); }
|
|
|
|
void unbind(int action, int key) { map.unbind(key, action); }
|
|
|
|
bool isBound(int key) const { return map.isBound(key); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Instigate an event. It is translated through the dispatch map and
|
|
|
|
sent to the function bindings.
|
|
|
|
*/
|
|
|
|
typedef DispatchMap::OutList _O;
|
|
|
|
void event(Type type, int index, const void* p)
|
|
|
|
{
|
|
|
|
// No bindings, nothing happens
|
|
|
|
if(!isBound(index))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Get the mapped actions and execute them
|
|
|
|
const _O &list = map.getList(index);
|
|
|
|
_O::const_iterator it;
|
|
|
|
for(it = list.begin(); it != list.end(); it++)
|
|
|
|
funcs.call(*it, p);
|
|
|
|
}
|
|
|
|
};
|
2010-07-16 12:25:19 +00:00
|
|
|
|
|
|
|
// This helps us play nice with Mangle's EventPtr, but it should
|
|
|
|
// really be defined for all the classes in OEngine.
|
|
|
|
typedef boost::shared_ptr<Dispatcher> DispatcherPtr;
|
|
|
|
|
2010-07-10 11:41:43 +00:00
|
|
|
}}
|
2010-07-04 12:28:51 +00:00
|
|
|
#endif
|