mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-24 19:41:04 +00:00
Finalize input shutdown in the core
Eliminate trailing whitespace Review changes 1 Review changes 2 Review changes 3 Review change 4 Review changes 5
This commit is contained in:
parent
1703988f00
commit
f87056289a
@ -28,7 +28,7 @@ void Init(EmuWindow* emu_window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown() {
|
void Shutdown() {
|
||||||
//InputCommon::Shutdown();
|
InputCommon::Shutdown();
|
||||||
VideoCore::Shutdown();
|
VideoCore::Shutdown();
|
||||||
HLE::Shutdown();
|
HLE::Shutdown();
|
||||||
Kernel::Shutdown();
|
Kernel::Shutdown();
|
||||||
|
@ -3,7 +3,10 @@
|
|||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include "input_common/input_common.h"
|
#include "input_common/input_common.h"
|
||||||
#include "input_common/sdl_input/sdl_input.h"
|
|
||||||
|
#ifdef _SDL_H
|
||||||
|
#include "input_common/sdl_input/sdl_input.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
@ -19,11 +22,11 @@ static int input_event;
|
|||||||
//Ticks for CoreTiming event, same as VBlank in GPU
|
//Ticks for CoreTiming event, same as VBlank in GPU
|
||||||
static u64 frame_ticks;
|
static u64 frame_ticks;
|
||||||
|
|
||||||
///Callback for CoreTiming
|
/// Callback for CoreTiming
|
||||||
static void InputCallback(u64 userdata, int cycles_late) {
|
static void InputCallback(u64 userdata, int cycles_late) {
|
||||||
|
|
||||||
//Call user input plugin Poll()
|
//Call user input plugin Poll()
|
||||||
if(g_user_input != nullptr) {
|
if (g_user_input != nullptr) {
|
||||||
g_user_input->Poll();
|
g_user_input->Poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,17 +38,18 @@ std::string ControllerBase::GetDeviceName() const {
|
|||||||
return device_name;
|
return device_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Service::HID::PadState ControllerBase::GetPadState() const {
|
const Service::HID::PadState ControllerBase::GetPadState() const {
|
||||||
return controller.pad_state;
|
return controller.pad_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init(ControllerBackends backend) {
|
void Init(ControllerBackends backend) {
|
||||||
switch(backend) {
|
switch (backend) {
|
||||||
//SDL2 backend selected
|
#ifdef _SDL_H
|
||||||
case SDL2_JOY:
|
//SDL2 backend selected
|
||||||
g_user_input = new SDLController();
|
case SDL2_JOY:
|
||||||
break;
|
g_user_input = new SDLController();
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
//No backend selected
|
//No backend selected
|
||||||
case NO_JOY:
|
case NO_JOY:
|
||||||
@ -57,8 +61,8 @@ void Init(ControllerBackends backend) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Shutdown immediately if backend failed to initialize
|
//Shutdown immediately if backend failed to initialize
|
||||||
if((g_user_input != nullptr) && (!g_user_input->activated)) {
|
if (g_user_input != nullptr && !g_user_input->activated) {
|
||||||
ShutDown();
|
Shutdown();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,8 +73,8 @@ void Init(ControllerBackends backend) {
|
|||||||
CoreTiming::ScheduleEvent(frame_ticks, input_event);
|
CoreTiming::ScheduleEvent(frame_ticks, input_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShutDown() {
|
void Shutdown() {
|
||||||
if((g_user_input != nullptr)
|
if (g_user_input != nullptr) {
|
||||||
delete g_user_input;
|
delete g_user_input;
|
||||||
g_user_input = nullptr;
|
g_user_input = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace InputCommon {
|
namespace InputCommon {
|
||||||
|
|
||||||
///Enum defining available backends
|
/// Enum defining available backends
|
||||||
enum ControllerBackends {
|
enum ControllerBackends {
|
||||||
NO_JOY,
|
NO_JOY,
|
||||||
SDL2_JOY
|
SDL2_JOY
|
||||||
@ -20,43 +20,41 @@ public:
|
|||||||
ControllerBase() {}
|
ControllerBase() {}
|
||||||
virtual ~ControllerBase() {}
|
virtual ~ControllerBase() {}
|
||||||
|
|
||||||
///Initializes input based on specific backends
|
/// Initializes input based on specific backends
|
||||||
virtual bool Init() = 0;
|
virtual bool Init() = 0;
|
||||||
|
|
||||||
///Grabs a list of devices supported by the backend
|
/// Grabs a list of devices supported by the backend
|
||||||
virtual void DiscoverDevices() = 0;
|
virtual void DiscoverDevices() = 0;
|
||||||
|
|
||||||
///Grab and process input
|
/// Grab and process input
|
||||||
virtual void Poll() = 0;
|
virtual void Poll() = 0;
|
||||||
|
|
||||||
///Shuts down all backend related data
|
/// Shuts down all backend related data
|
||||||
virtual void ShutDown() = 0;
|
virtual void Shutdown() = 0;
|
||||||
|
|
||||||
///Returns internal name of currently selected device. Expose this to the UI
|
/// Returns internal name of currently selected device. Expose this to the UI
|
||||||
std::string GetDeviceName() const;
|
std::string GetDeviceName() const;
|
||||||
|
|
||||||
///Returns internal pad state
|
/// Returns internal pad state
|
||||||
const Service::HID::PadState GetPadState() const;
|
const Service::HID::PadState GetPadState() const;
|
||||||
|
|
||||||
bool activated;
|
bool activated;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///Internal name of currently selected device
|
/// Internal name of currently selected device
|
||||||
std::string device_name;
|
std::string device_name;
|
||||||
|
|
||||||
///Internal view this specific object will have of 3DS input states
|
/// Internal view this specific object will have of 3DS input states
|
||||||
ControllerState controller;
|
ControllerState controller;
|
||||||
};
|
};
|
||||||
|
|
||||||
///Initialize the user input system
|
/// Initialize the user input system
|
||||||
void Init(ControllerBackends backend);
|
void Init(ControllerBackends backend);
|
||||||
|
|
||||||
///Deactive the user input system
|
/// Deactive the user input system
|
||||||
void ShutDown();
|
void Shutdown();
|
||||||
|
|
||||||
///InputCommon 'plugin'
|
/// InputCommon 'plugin'
|
||||||
extern ControllerBase* g_user_input;
|
extern ControllerBase* g_user_input;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,13 +22,13 @@ SDLController::SDLController() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDLController::~SDLController() {
|
SDLController::~SDLController() {
|
||||||
ShutDown();
|
Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SDLController::Init() {
|
bool SDLController::Init() {
|
||||||
|
|
||||||
//Attempt to initialize SDL with joystick only
|
//Attempt to initialize SDL with joystick only
|
||||||
if(SDL_Init(SDL_INIT_JOYSTICK) != 0) {
|
if (SDL_Init(SDL_INIT_JOYSTICK) != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ bool SDLController::Init() {
|
|||||||
//TODO - Use DiscoverDevice to generate a list of available joysticks, then open the correct index
|
//TODO - Use DiscoverDevice to generate a list of available joysticks, then open the correct index
|
||||||
jpad = SDL_JoystickOpen(index);
|
jpad = SDL_JoystickOpen(index);
|
||||||
|
|
||||||
if(jpad == nullptr) {
|
if (jpad == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,17 +55,17 @@ bool SDLController::Init() {
|
|||||||
|
|
||||||
void SDLController::DiscoverDevices() {}
|
void SDLController::DiscoverDevices() {}
|
||||||
|
|
||||||
void SDLController::ShutDown() {
|
void SDLController::Shutdown() {
|
||||||
//Attempt to close joystick with SDL
|
//Attempt to close joystick with SDL
|
||||||
if(jpad != nullptr) {
|
if (jpad != nullptr) {
|
||||||
SDL_JoystickClose(jpad);
|
SDL_JoystickClose(jpad);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLController::Poll() {
|
void SDLController::Poll() {
|
||||||
if(SDL_PollEvent(&input_event)) {
|
if (SDL_PollEvent(&input_event)) {
|
||||||
if((input_event.type == SDL_JOYBUTTONDOWN) || (input_event.type == SDL_JOYBUTTONUP)
|
if (input_event.type == SDL_JOYBUTTONDOWN || input_event.type == SDL_JOYBUTTONUP
|
||||||
|| (input_event.type == SDL_JOYAXISMOTION) || (input_event.type == SDL_JOYHATMOTION)) {
|
|| input_event.type == SDL_JOYAXISMOTION || input_event.type == SDL_JOYHATMOTION) {
|
||||||
ProcessInput();
|
ProcessInput();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ void SDLController::ProcessInput() {
|
|||||||
int val = 0;
|
int val = 0;
|
||||||
|
|
||||||
//Generate the id based on input from an event
|
//Generate the id based on input from an event
|
||||||
switch(input_event.type) {
|
switch (input_event.type) {
|
||||||
//Joystick button press events
|
//Joystick button press events
|
||||||
case SDL_JOYBUTTONDOWN:
|
case SDL_JOYBUTTONDOWN:
|
||||||
pad_id = 100;
|
pad_id = 100;
|
||||||
@ -100,19 +100,19 @@ void SDLController::ProcessInput() {
|
|||||||
pad_id += (input_event.jaxis.axis * 2);
|
pad_id += (input_event.jaxis.axis * 2);
|
||||||
val = input_event.jaxis.value;
|
val = input_event.jaxis.value;
|
||||||
|
|
||||||
if(val > 0) {
|
if (val > 0) {
|
||||||
pad_id += 1;
|
pad_id += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//If analog input is beyond dead zone, set it
|
//If analog input is beyond dead zone, set it
|
||||||
if(CheckDeadZone(val)) {
|
if (CheckDeadZone(val)) {
|
||||||
controller.pad_state.hex |= KeyMap::GetPadKey({pad_id, joypad_id}).hex;
|
controller.pad_state.hex |= KeyMap::GetPadKey({pad_id, joypad_id}).hex;
|
||||||
} else {
|
} else {
|
||||||
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex;
|
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Release opposite axis
|
//Release opposite axis
|
||||||
if(pad_id % 2 == 0) {
|
if (pad_id % 2 == 0) {
|
||||||
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+1, joypad_id}).hex;
|
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+1, joypad_id}).hex;
|
||||||
} else {
|
} else {
|
||||||
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id-1, joypad_id}).hex;
|
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id-1, joypad_id}).hex;
|
||||||
@ -125,7 +125,7 @@ void SDLController::ProcessInput() {
|
|||||||
pad_id = 300;
|
pad_id = 300;
|
||||||
pad_id += input_event.jhat.hat * 4;
|
pad_id += input_event.jhat.hat * 4;
|
||||||
|
|
||||||
switch(input_event.jhat.value) {
|
switch (input_event.jhat.value) {
|
||||||
case SDL_HAT_CENTERED:
|
case SDL_HAT_CENTERED:
|
||||||
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex;
|
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex;
|
||||||
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+1, joypad_id}).hex;
|
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+1, joypad_id}).hex;
|
||||||
@ -228,9 +228,9 @@ void SDLController::SetDeadZone(int range) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SDLController::CheckDeadZone(int range) {
|
bool SDLController::CheckDeadZone(int range) {
|
||||||
if((range < -dead_zone) || (range > dead_zone)) {
|
if ((range < -dead_zone) || (range > dead_zone)) {
|
||||||
return true;
|
return true;
|
||||||
} else if((range > -dead_zone) && (range < dead_zone)) {
|
} else if ((range > -dead_zone) && (range < dead_zone)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,50 +10,48 @@
|
|||||||
|
|
||||||
namespace InputCommon {
|
namespace InputCommon {
|
||||||
|
|
||||||
class SDLController : virtual public ControllerBase {
|
class SDLController final : public ControllerBase {
|
||||||
public:
|
public:
|
||||||
SDLController();
|
SDLController();
|
||||||
~SDLController();
|
~SDLController();
|
||||||
|
|
||||||
///Initializes input via SDL2
|
/// Initializes input via SDL2
|
||||||
bool Init();
|
bool Init() override;
|
||||||
|
|
||||||
///Grabs a list of devices supported by the backend
|
/// Grabs a list of devices supported by the backend
|
||||||
void DiscoverDevices();
|
void DiscoverDevices() override;
|
||||||
|
|
||||||
///Grab and process input via SDL2
|
/// Grab and process input via SDL2
|
||||||
void Poll();
|
void Poll() override;
|
||||||
|
|
||||||
///Shuts down all joysticks opened by SDL2
|
/// Shuts down all joysticks opened by SDL2
|
||||||
void ShutDown();
|
void Shutdown() override;
|
||||||
|
|
||||||
///Processes input when polling
|
/// Processes input when polling
|
||||||
void ProcessInput();
|
void ProcessInput();
|
||||||
|
|
||||||
///Sets up keymaps from input configuration
|
/// Sets up keymaps from input configuration
|
||||||
void SetupKeyMaps();
|
void SetupKeyMaps();
|
||||||
|
|
||||||
///Sets analog deadzones
|
/// Sets analog deadzones
|
||||||
void SetDeadZone(int range);
|
void SetDeadZone(int range);
|
||||||
|
|
||||||
///Checks if analog input is within the dead zone
|
/// Checks if analog input is within the dead zone
|
||||||
bool CheckDeadZone(int range);
|
bool CheckDeadZone(int range);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDL_Joystick* jpad;
|
SDL_Joystick* jpad;
|
||||||
|
|
||||||
///SDL event used for polling
|
/// SDL event used for polling
|
||||||
SDL_Event input_event;
|
SDL_Event input_event;
|
||||||
|
|
||||||
///Index of joystick, used for opening/closing a joystick
|
/// Index of joystick, used for opening/closing a joystick
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
///Keymap id for this controller
|
/// Keymap id for this controller
|
||||||
int joypad_id;
|
int joypad_id;
|
||||||
|
|
||||||
int dead_zone;
|
int dead_zone;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace
|
} //namespace
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user