#pragma once #include #include #include #include "Controllers.h" #include "GamePad.h" #include "KActionBind.h" #include "KPlayer.h" namespace KapitanGame { struct KControllerAxisMapping { KControllerAxisMapping(const Controllers controller, const SDL_GameControllerAxis axis, const float scale) : Controller(controller), Axis(axis), Scale(scale) {} Controllers Controller; SDL_GameControllerAxis Axis; float Scale; }; class KInput { std::vector ConnectedControllers; std::vector ControllerInputs; std::vector LastControllerInputs; std::vector KeyboardInputs; std::vector LastKeyboardInputs; std::vector Actions; std::vector Axes; std::unordered_multimap KeyBinds[static_cast(KPlayer::Player2) + 1]; std::unordered_multimap> ButtonBinds[static_cast(KPlayer::Player2) + 1]; std::unordered_multimap ControllerAxisBinds[static_cast(KPlayer::Player2) + 1]; std::unordered_multimap> KeyAxisBinds[static_cast(KPlayer::Player2) + 1]; int GamePadsCount; bool Initialized; void ProcessActions(); void ProcessAxes(); public: KInput(); void Init(); void Free(); void HandleInputPreEvents(); void HandleInputPostEvents(bool processInput); void HandleEvent(const SDL_Event& event); void BindAction(const std::string& name, InputState expectedInputState, const std::shared_ptr& controllerObject, KPlayerCommand command, KPlayer player); void BindAxis(const std::string& name, const std::shared_ptr& controllerObject, KPlayerAxisCommand command, KPlayer player); bool CheckAction(const std::string& name, InputState expectedInputState, KPlayer player); void AddAxisMapping(const std::string& name, const float& scale, const std::string& key, const KPlayer& player); void AddActionMapping(const std::string& name, const std::string& key, const KPlayer& player); bool IsControllerButtonPressed(Controllers controllerId, SDL_GameControllerButton button) const; bool IsControllerButtonReleased(Controllers controllerId, SDL_GameControllerButton button) const; bool IsControllerButtonHeld(Controllers controllerId, SDL_GameControllerButton button) const; float GetControllerAxis(Controllers controllerId, SDL_GameControllerAxis axis) const; bool IsKeyboardButtonHeld(Uint8 scanCode) const; bool IsKeyboardButtonPressed(Uint8 scanCode) const; bool IsKeyboardButtonReleased(Uint8 scanCode) const; float GetAxisValue(const std::string& name, const KPlayer& player) const; }; }