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:
Daniel Stuart Baxter 2015-05-30 15:24:09 -05:00
parent 1703988f00
commit f87056289a
5 changed files with 70 additions and 70 deletions

View File

@ -28,7 +28,7 @@ void Init(EmuWindow* emu_window) {
}
void Shutdown() {
//InputCommon::Shutdown();
InputCommon::Shutdown();
VideoCore::Shutdown();
HLE::Shutdown();
Kernel::Shutdown();

View File

@ -3,7 +3,10 @@
// Refer to the license.txt file included.
#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/settings.h"
@ -19,11 +22,11 @@ static int input_event;
//Ticks for CoreTiming event, same as VBlank in GPU
static u64 frame_ticks;
///Callback for CoreTiming
/// Callback for CoreTiming
static void InputCallback(u64 userdata, int cycles_late) {
//Call user input plugin Poll()
if(g_user_input != nullptr) {
if (g_user_input != nullptr) {
g_user_input->Poll();
}
@ -35,17 +38,18 @@ std::string ControllerBase::GetDeviceName() const {
return device_name;
}
const Service::HID::PadState ControllerBase::GetPadState() const {
return controller.pad_state;
}
void Init(ControllerBackends backend) {
switch(backend) {
//SDL2 backend selected
case SDL2_JOY:
g_user_input = new SDLController();
break;
switch (backend) {
#ifdef _SDL_H
//SDL2 backend selected
case SDL2_JOY:
g_user_input = new SDLController();
break;
#endif
//No backend selected
case NO_JOY:
@ -57,8 +61,8 @@ void Init(ControllerBackends backend) {
}
//Shutdown immediately if backend failed to initialize
if((g_user_input != nullptr) && (!g_user_input->activated)) {
ShutDown();
if (g_user_input != nullptr && !g_user_input->activated) {
Shutdown();
return;
}
@ -69,8 +73,8 @@ void Init(ControllerBackends backend) {
CoreTiming::ScheduleEvent(frame_ticks, input_event);
}
void ShutDown() {
if((g_user_input != nullptr)
void Shutdown() {
if (g_user_input != nullptr) {
delete g_user_input;
g_user_input = nullptr;
}

View File

@ -9,7 +9,7 @@
namespace InputCommon {
///Enum defining available backends
/// Enum defining available backends
enum ControllerBackends {
NO_JOY,
SDL2_JOY
@ -20,43 +20,41 @@ public:
ControllerBase() {}
virtual ~ControllerBase() {}
///Initializes input based on specific backends
/// Initializes input based on specific backends
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;
///Grab and process input
/// Grab and process input
virtual void Poll() = 0;
///Shuts down all backend related data
virtual void ShutDown() = 0;
/// Shuts down all backend related data
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;
///Returns internal pad state
/// Returns internal pad state
const Service::HID::PadState GetPadState() const;
bool activated;
protected:
///Internal name of currently selected device
/// Internal name of currently selected device
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;
};
///Initialize the user input system
/// Initialize the user input system
void Init(ControllerBackends backend);
///Deactive the user input system
void ShutDown();
/// Deactive the user input system
void Shutdown();
///InputCommon 'plugin'
/// InputCommon 'plugin'
extern ControllerBase* g_user_input;
} // namespace

View File

@ -22,13 +22,13 @@ SDLController::SDLController() {
}
SDLController::~SDLController() {
ShutDown();
Shutdown();
}
bool SDLController::Init() {
//Attempt to initialize SDL with joystick only
if(SDL_Init(SDL_INIT_JOYSTICK) != 0) {
if (SDL_Init(SDL_INIT_JOYSTICK) != 0) {
return false;
}
@ -36,7 +36,7 @@ bool SDLController::Init() {
//TODO - Use DiscoverDevice to generate a list of available joysticks, then open the correct index
jpad = SDL_JoystickOpen(index);
if(jpad == nullptr) {
if (jpad == nullptr) {
return false;
}
@ -55,17 +55,17 @@ bool SDLController::Init() {
void SDLController::DiscoverDevices() {}
void SDLController::ShutDown() {
void SDLController::Shutdown() {
//Attempt to close joystick with SDL
if(jpad != nullptr) {
if (jpad != nullptr) {
SDL_JoystickClose(jpad);
}
}
void SDLController::Poll() {
if(SDL_PollEvent(&input_event)) {
if((input_event.type == SDL_JOYBUTTONDOWN) || (input_event.type == SDL_JOYBUTTONUP)
|| (input_event.type == SDL_JOYAXISMOTION) || (input_event.type == SDL_JOYHATMOTION)) {
if (SDL_PollEvent(&input_event)) {
if (input_event.type == SDL_JOYBUTTONDOWN || input_event.type == SDL_JOYBUTTONUP
|| input_event.type == SDL_JOYAXISMOTION || input_event.type == SDL_JOYHATMOTION) {
ProcessInput();
}
}
@ -77,7 +77,7 @@ void SDLController::ProcessInput() {
int val = 0;
//Generate the id based on input from an event
switch(input_event.type) {
switch (input_event.type) {
//Joystick button press events
case SDL_JOYBUTTONDOWN:
pad_id = 100;
@ -100,19 +100,19 @@ void SDLController::ProcessInput() {
pad_id += (input_event.jaxis.axis * 2);
val = input_event.jaxis.value;
if(val > 0) {
if (val > 0) {
pad_id += 1;
}
//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;
} else {
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex;
}
//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;
} else {
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id-1, joypad_id}).hex;
@ -125,7 +125,7 @@ void SDLController::ProcessInput() {
pad_id = 300;
pad_id += input_event.jhat.hat * 4;
switch(input_event.jhat.value) {
switch (input_event.jhat.value) {
case SDL_HAT_CENTERED:
controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, 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) {
if((range < -dead_zone) || (range > dead_zone)) {
if ((range < -dead_zone) || (range > dead_zone)) {
return true;
} else if((range > -dead_zone) && (range < dead_zone)) {
} else if ((range > -dead_zone) && (range < dead_zone)) {
return false;
}
}

View File

@ -10,50 +10,48 @@
namespace InputCommon {
class SDLController : virtual public ControllerBase {
class SDLController final : public ControllerBase {
public:
SDLController();
~SDLController();
///Initializes input via SDL2
bool Init();
/// Initializes input via SDL2
bool Init() override;
///Grabs a list of devices supported by the backend
void DiscoverDevices();
/// Grabs a list of devices supported by the backend
void DiscoverDevices() override;
///Grab and process input via SDL2
void Poll();
/// Grab and process input via SDL2
void Poll() override;
///Shuts down all joysticks opened by SDL2
void ShutDown();
/// Shuts down all joysticks opened by SDL2
void Shutdown() override;
///Processes input when polling
/// Processes input when polling
void ProcessInput();
///Sets up keymaps from input configuration
/// Sets up keymaps from input configuration
void SetupKeyMaps();
///Sets analog deadzones
/// Sets analog deadzones
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);
private:
SDL_Joystick* jpad;
///SDL event used for polling
/// SDL event used for polling
SDL_Event input_event;
///Index of joystick, used for opening/closing a joystick
/// Index of joystick, used for opening/closing a joystick
int index;
///Keymap id for this controller
/// Keymap id for this controller
int joypad_id;
int dead_zone;
};
} //namespace