Move the mouse/keyboard/pad handlers over to using unique_ptr as the underlying base.

This commit is contained in:
Lioncash 2014-03-31 20:02:27 -04:00
parent c5a7946a24
commit 3c5e3fa853
10 changed files with 51 additions and 39 deletions

View file

@ -15,14 +15,20 @@ KeyboardManager::~KeyboardManager()
void KeyboardManager::Init(const u32 max_connect) void KeyboardManager::Init(const u32 max_connect)
{ {
if(m_inited) return; if(m_inited)
return;
// NOTE: Change these to std::make_unique assignments when C++14 comes out.
switch(Ini.KeyboardHandlerMode.GetValue()) switch(Ini.KeyboardHandlerMode.GetValue())
{ {
case 1: m_keyboard_handler = new WindowsKeyboardHandler(); break; case 1:
m_keyboard_handler.reset(new WindowsKeyboardHandler());
break;
default: default:
case 0: m_keyboard_handler = new NullKeyboardHandler(); break; case 0:
m_keyboard_handler.reset(new NullKeyboardHandler());
break;
} }
m_keyboard_handler->Init(max_connect); m_keyboard_handler->Init(max_connect);

View file

@ -1,12 +1,13 @@
#pragma once #pragma once
#include <memory>
#include <vector> #include <vector>
#include "KeyboardHandler.h" #include "KeyboardHandler.h"
class KeyboardManager //: public wxWindow class KeyboardManager //: public wxWindow
{ {
bool m_inited; bool m_inited;
KeyboardHandlerBase* m_keyboard_handler; std::unique_ptr<KeyboardHandlerBase> m_keyboard_handler;
public: public:
KeyboardManager(); KeyboardManager();

View file

@ -257,10 +257,6 @@ struct Keyboard
, m_config() , m_config()
{ {
} }
~Keyboard()
{
}
}; };
class KeyboardHandlerBase class KeyboardHandlerBase
@ -287,10 +283,10 @@ public:
if (pressed) if (pressed)
{ {
// Meta Keys
if (code == 308 || code == 307 || code == 306 || if (code == 308 || code == 307 || code == 306 ||
code == 393 || code == 396 || code == 394) code == 393 || code == 396 || code == 394)
{ // Meta Keys {
data.mkey |= button.m_outKeyCode; data.mkey |= button.m_outKeyCode;
} }
else else
@ -316,9 +312,10 @@ public:
if (!pressed) if (!pressed)
{ {
// Meta Keys
if (code == 308 || code == 307 || code == 306 || if (code == 308 || code == 307 || code == 306 ||
code == 393 || code == 396 || code == 394) code == 393 || code == 396 || code == 394)
{ // Meta Keys {
data.mkey &= ~button.m_outKeyCode; data.mkey &= ~button.m_outKeyCode;
} }
} }

View file

@ -15,14 +15,20 @@ MouseManager::~MouseManager()
void MouseManager::Init(const u32 max_connect) void MouseManager::Init(const u32 max_connect)
{ {
if(m_inited) return; if(m_inited)
return;
// NOTE: Change these to std::make_unique assignments when C++14 is available.
switch(Ini.MouseHandlerMode.GetValue()) switch(Ini.MouseHandlerMode.GetValue())
{ {
case 1: m_mouse_handler = new WindowsMouseHandler(); break; case 1:
m_mouse_handler.reset(new WindowsMouseHandler());
break;
default: default:
case 0: m_mouse_handler = new NullMouseHandler(); break; case 0:
m_mouse_handler.reset(new NullMouseHandler());
break;
} }
m_mouse_handler->Init(max_connect); m_mouse_handler->Init(max_connect);

View file

@ -1,12 +1,13 @@
#pragma once #pragma once
#include <memory>
#include <vector> #include <vector>
#include "MouseHandler.h" #include "MouseHandler.h"
class MouseManager //: public wxWindow class MouseManager //: public wxWindow
{ {
bool m_inited; bool m_inited;
MouseHandlerBase* m_mouse_handler; std::unique_ptr<MouseHandlerBase> m_mouse_handler;
public: public:
MouseManager(); MouseManager();

View file

@ -15,14 +15,20 @@ PadManager::~PadManager()
void PadManager::Init(const u32 max_connect) void PadManager::Init(const u32 max_connect)
{ {
if(m_inited) return; if(m_inited)
return;
// NOTE: Change these to std::make_unique assignments when C++14 is available.
switch(Ini.PadHandlerMode.GetValue()) switch(Ini.PadHandlerMode.GetValue())
{ {
case 1: m_pad_handler = new WindowsPadHandler(); break; case 1:
m_pad_handler.reset(new WindowsPadHandler());
break;
default: default:
case 0: m_pad_handler = new NullPadHandler(); break; case 0:
m_pad_handler.reset(new NullPadHandler());
break;
} }
m_pad_handler->Init(max_connect); m_pad_handler->Init(max_connect);

View file

@ -1,12 +1,13 @@
#pragma once #pragma once
#include <memory>
#include <vector> #include <vector>
#include "PadHandler.h" #include "PadHandler.h"
class PadManager //: public wxWindow class PadManager //: public wxWindow
{ {
bool m_inited; bool m_inited;
PadHandlerBase* m_pad_handler; std::unique_ptr<PadHandlerBase> m_pad_handler;
public: public:
PadManager(); PadManager();

View file

@ -186,10 +186,6 @@ struct Pad
, m_sensor_g(0) , m_sensor_g(0)
{ {
} }
~Pad()
{
}
}; };
struct PadInfo struct PadInfo

View file

@ -30,7 +30,7 @@ public:
LoadSettings(); LoadSettings();
memset(&m_info, 0, sizeof(KbInfo)); memset(&m_info, 0, sizeof(KbInfo));
m_info.max_connect = max_connect; m_info.max_connect = max_connect;
m_info.now_connect = std::min(m_keyboards.size(), (size_t)max_connect); m_info.now_connect = std::min<size_t>(m_keyboards.size(), max_connect);
m_info.info = 0; // Ownership of keyboard data: 0=Application, 1=System m_info.info = 0; // Ownership of keyboard data: 0=Application, 1=System
m_info.status[0] = CELL_KB_STATUS_CONNECTED; // (TODO: Support for more keyboards) m_info.status[0] = CELL_KB_STATUS_CONNECTED; // (TODO: Support for more keyboards)
} }

View file

@ -86,25 +86,24 @@ int cellPadGetData(u32 port_no, u32 data_addr)
u16 d1 = 0; u16 d1 = 0;
u16 d2 = 0; u16 d2 = 0;
std::vector<Button>& buttons = pads[port_no].m_buttons; pad.m_port_status &= ~CELL_PAD_STATUS_ASSIGN_CHANGES;
pads[port_no].m_port_status &= ~CELL_PAD_STATUS_ASSIGN_CHANGES;
s32 len = 0; s32 len = 0;
for(uint i=0; i<buttons.size(); ++i) for(Button& button : pads[port_no].m_buttons)
{ {
if(!buttons[i].m_pressed) if(!button.m_pressed)
continue; continue;
switch(buttons[i].m_offset) switch(button.m_offset)
{ {
case CELL_PAD_BTN_OFFSET_DIGITAL1: if(!(d1 & buttons[i].m_outKeyCode)){d1 |= buttons[i].m_outKeyCode; len++;} break; case CELL_PAD_BTN_OFFSET_DIGITAL1: if(!(d1 & button.m_outKeyCode)){d1 |= button.m_outKeyCode; len++;} break;
case CELL_PAD_BTN_OFFSET_DIGITAL2: if(!(d2 & buttons[i].m_outKeyCode)){d2 |= buttons[i].m_outKeyCode; len++;} break; case CELL_PAD_BTN_OFFSET_DIGITAL2: if(!(d2 & button.m_outKeyCode)){d2 |= button.m_outKeyCode; len++;} break;
} }
if(buttons[i].m_flush) if(button.m_flush)
{ {
buttons[i].m_pressed = false; button.m_pressed = false;
buttons[i].m_flush = false; button.m_flush = false;
} }
} }
@ -112,11 +111,10 @@ int cellPadGetData(u32 port_no, u32 data_addr)
u16 ly = 128; u16 ly = 128;
u16 rx = 128; u16 rx = 128;
u16 ry = 128; u16 ry = 128;
const std::vector<AnalogStick>& sticks = pads[port_no].m_sticks; for (const AnalogStick& stick : pads[port_no].m_sticks)
for (u32 s = 0; s < sticks.size(); s++)
{ {
u16* res; u16* res;
switch (sticks[s].m_offset) switch (stick.m_offset)
{ {
case CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X: res = &lx; break; case CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X: res = &lx; break;
case CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y: res = &ly; break; case CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y: res = &ly; break;
@ -125,9 +123,9 @@ int cellPadGetData(u32 port_no, u32 data_addr)
default: continue; default: continue;
} }
if (sticks[s].m_max_pressed && !sticks[s].m_min_pressed) if (stick.m_max_pressed && !stick.m_min_pressed)
*res = 255; *res = 255;
if (sticks[s].m_min_pressed && !sticks[s].m_max_pressed) if (stick.m_min_pressed && !stick.m_max_pressed)
*res = 0; *res = 0;
} }