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>
12 #include "mspgameview_api.h"
14 namespace Msp::GameView {
16 class MSPGAMEVIEW_API PlayerInput: public NonCopyable
19 using EventSource = Game::EventSource<Events::PlayerArrived, Events::PlayerDeparted>;
30 Input::Device *device = nullptr;
31 std::unique_ptr<Input::ControlScheme> controls = nullptr;
34 using SchemeFactoryFunc = std::unique_ptr<Input::ControlScheme>();
36 EventSource event_source;
37 Input::Keyboard keyboard;
40 std::vector<Input::Bindings *> bindings;
41 SchemeFactoryFunc *scheme_factory = nullptr;
42 std::vector<Player> players;
43 Mode mode = ONE_LOCAL_PLAYER;
46 PlayerInput(Game::Director &, Graphics::Window &);
49 requires std::is_base_of_v<Input::ControlScheme, T>
50 void set_control_scheme_type(Mode = ONE_LOCAL_PLAYER);
54 void add_player(Input::Device &);
57 void synthesize_initial_events(Game::EventObserver &);
62 requires std::is_base_of_v<Input::ControlScheme, T>
63 void PlayerInput::set_control_scheme_type(Mode m)
66 throw std::logic_error("scheme type already set");
69 scheme_factory = +[]() -> std::unique_ptr<Input::ControlScheme> { return std::make_unique<T>(); };
73 } // namespace Msp::GameView