#pragma once #include #include #include #include "InputMap.hpp" #include template class InputTarget { public: InputTarget(const InputTarget&) = delete; InputTarget& operator=(const InputTarget&) = delete; InputTarget(const InputMap& map): _inputMap(map) {} bool think(const sf::Event& event) const { for(auto& pair: _eventsPoll) { if(_inputMap.get(pair.first) == event) { pair.second(event, 1.f); return true; } } return false; } void think() const { for(auto& pair: _eventsRealTime) { const Input& input = _inputMap.get(pair.first); float power = input.test(); if(power != 0.f) pair.second(input._event, power); } } void bind(const T& key, const std::function& callback) { const Input& input = _inputMap.get(key); if(input._type & Input::Type::RealTime) _eventsRealTime.emplace_back(key, callback); else _eventsPoll.emplace_back(key, callback); } void unbind(const T& key) { auto remove_func = [&key](const std::pair>& pair) -> bool { return pair.first == key; }; if(_inputMap.get(key)._type & Input::Type::RealTime) _eventsRealTime.remove_if(remove_func); else _eventsPoll.remove_if(remove_func); } private: std::list>> _eventsRealTime; std::list>> _eventsPoll; const InputMap& _inputMap; };