EightBit/Gaming/inc/GameController.h
Adrian Conlon 89fae1cb6f Tidy the Gaming library a little:
*) Add an SDLWrapper class to control the lifetime of SDL_Init/SDL_Quit
*) Pass FPS as a float, rather than int
*) Allow the key and button handlers to show whether an event was handled or not
*) Add a full screen render option (F12)
*) Use smart pointers in the GameController class

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
2019-10-01 23:54:48 +01:00

38 lines
805 B
C++

#pragma once
#include <memory>
#include <SDL.h>
namespace Gaming {
class GameController final {
public:
GameController(int index);
virtual ~GameController();
void startRumble() noexcept;
void stopRumble() noexcept;
static auto buildJoystickId(SDL_GameController* controller) noexcept {
auto joystick = ::SDL_GameControllerGetJoystick(controller);
return ::SDL_JoystickInstanceID(joystick);
}
auto getJoystickId() const noexcept {
return buildJoystickId(m_gameController.get());
}
private:
int m_index;
std::shared_ptr<SDL_GameController> m_gameController;
void open();
void close() noexcept;
std::shared_ptr<SDL_Haptic> m_hapticController;
bool m_hapticRumbleSupported = false;
void openHapticController();
void closeHapticController() noexcept;
};
}