Review Changes 12 - unique_ptr for InputBase

This commit is contained in:
Daniel Stuart Baxter 2015-05-31 12:58:47 -05:00
parent 5dbd3c53f7
commit 1be629b345
2 changed files with 7 additions and 10 deletions

View File

@ -13,8 +13,8 @@
namespace InputCommon {
// Set to nullptr until initialized by a backend
InputBase* g_user_input = nullptr;
// User input system
std::unique_ptr<InputBase> g_user_input;
// Event id for CoreTiming
static int input_event;
@ -26,7 +26,7 @@ static u64 frame_ticks;
static void InputCallback(u64 userdata, int cycles_late) {
// Call user input plugin Poll()
if (g_user_input != nullptr) g_user_input->Poll();
if (g_user_input) g_user_input->Poll();
// Reschedule recurrent event
CoreTiming::ScheduleEvent(frame_ticks - cycles_late, input_event);
@ -45,7 +45,7 @@ void Init(InputBackends backend) {
#ifdef HAS_SDL
// SDL2 backend selected
case InputBackends::SDL2:
g_user_input = new SDLController();
g_user_input.reset(new SDLController);
break;
#endif
@ -60,7 +60,7 @@ void Init(InputBackends backend) {
}
// Shutdown immediately if backend failed to initialize
if (g_user_input != nullptr && !g_user_input->activated) {
if (!g_user_input && !g_user_input->activated) {
Shutdown();
return;
}
@ -73,10 +73,7 @@ void Init(InputBackends backend) {
}
void Shutdown() {
if (g_user_input != nullptr) {
delete g_user_input;
g_user_input = nullptr;
}
if (g_user_input) g_user_input.release();
}
} // namespace

View File

@ -55,6 +55,6 @@ void Init(InputBackends backend);
void Shutdown();
/// InputCommon 'plugin'
extern InputBase* g_user_input;
extern std::unique_ptr<InputBase> g_user_input;
} // namespace