X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgameview%2Fplayerinput.h;fp=source%2Fgameview%2Fplayerinput.h;h=16f3c4ee9b8067b20cbda16485e6e4dfa5a0a444;hb=86c345922f02587d6c49e637535adf5494819652;hp=0000000000000000000000000000000000000000;hpb=391f1ab3c7ca52a9990f516f4cdd7094f60350df;p=libs%2Fgame.git diff --git a/source/gameview/playerinput.h b/source/gameview/playerinput.h new file mode 100644 index 0000000..16f3c4e --- /dev/null +++ b/source/gameview/playerinput.h @@ -0,0 +1,74 @@ +#ifndef MSP_GAMEVIEW_PLAYERINPUT_H_ +#define MSP_GAMEVIEW_PLAYERINPUT_H_ + +#include +#include +#include +#include +#include +#include +#include +#include "events.h" + +namespace Msp::GameView { + +class PlayerInput: public NonCopyable +{ +public: + using EventSource = Game::EventSource; + + enum Mode + { + ONE_LOCAL_PLAYER, + LOCAL_MULTIPLAYER + }; + +private: + struct Player + { + Input::Device *device = nullptr; + std::unique_ptr controls = nullptr; + }; + + using SchemeFactoryFunc = std::unique_ptr(); + + EventSource event_source; + Input::Keyboard keyboard; + Input::Mouse mouse; + Input::Hub kbm_hub; + std::vector bindings; + SchemeFactoryFunc *scheme_factory = nullptr; + std::vector players; + Mode mode = ONE_LOCAL_PLAYER; + +public: + PlayerInput(Game::Director &, Graphics::Window &); + + template + requires std::is_base_of_v + void set_control_scheme_type(Mode = ONE_LOCAL_PLAYER); + +private: + void init_players(); + void add_player(Input::Device &); + +public: + void synthesize_initial_events(Game::EventObserver &); +}; + + +template + requires std::is_base_of_v +void PlayerInput::set_control_scheme_type(Mode m) +{ + if(scheme_factory) + throw std::logic_error("scheme type already set"); + + mode = m; + scheme_factory = +[]() -> std::unique_ptr { return std::make_unique(); }; + init_players(); +} + +} // namespace Msp::GameView + +#endif