1 #ifndef MSP_GAMEVIEW_PLAYERINPUT_H_
2 #define MSP_GAMEVIEW_PLAYERINPUT_H_
5 #include <msp/input/bindings.h>
6 #include <msp/input/controlscheme.h>
7 #include <msp/input/hub.h>
8 #include <msp/input/keyboard.h>
9 #include <msp/input/mouse.h>
10 #include <msp/game/director.h>
13 namespace Msp::GameView {
15 class PlayerInput: public NonCopyable
18 using EventSource = Game::EventSource<Events::PlayerArrived, Events::PlayerDeparted>;
29 Input::Device *device = nullptr;
30 std::unique_ptr<Input::ControlScheme> controls = nullptr;
33 using SchemeFactoryFunc = std::unique_ptr<Input::ControlScheme>();
35 EventSource event_source;
36 Input::Keyboard keyboard;
39 std::vector<Input::Bindings *> bindings;
40 SchemeFactoryFunc *scheme_factory = nullptr;
41 std::vector<Player> players;
42 Mode mode = ONE_LOCAL_PLAYER;
45 PlayerInput(Game::Director &, Graphics::Window &);
48 requires std::is_base_of_v<Input::ControlScheme, T>
49 void set_control_scheme_type(Mode = ONE_LOCAL_PLAYER);
53 void add_player(Input::Device &);
56 void synthesize_initial_events(Game::EventObserver &);
61 requires std::is_base_of_v<Input::ControlScheme, T>
62 void PlayerInput::set_control_scheme_type(Mode m)
65 throw std::logic_error("scheme type already set");
68 scheme_factory = +[]() -> std::unique_ptr<Input::ControlScheme> { return std::make_unique<T>(); };
72 } // namespace Msp::GameView