unique_ptr'ing things and removing some XECLEANUP.

This commit is contained in:
Ben Vanik
2014-08-20 23:26:46 -07:00
parent 244e8a8745
commit c59d053404
43 changed files with 271 additions and 347 deletions

View File

@@ -10,15 +10,10 @@
#include <xenia/hid/hid.h>
#include <xenia/hid/hid-private.h>
using namespace xe;
using namespace xe::hid;
DEFINE_string(hid, "any",
"Input system. Use: [any, nop, winkey, xinput]");
DEFINE_string(hid, "any", "Input system. Use: [any, nop, winkey, xinput]");
#include <xenia/hid/nop/nop_hid.h>
#if XE_PLATFORM_WIN32
@@ -26,41 +21,40 @@ DEFINE_string(hid, "any",
#include <xenia/hid/xinput/xinput_hid.h>
#endif // WIN32
InputSystem* xe::hid::Create(Emulator* emulator) {
//return xe::hid::nop::Create(emulator);
InputSystem* input_system = new InputSystem(emulator);
std::unique_ptr<InputSystem> xe::hid::Create(Emulator* emulator) {
std::unique_ptr<InputSystem> input_system =
std::make_unique<InputSystem>(emulator);
if (FLAGS_hid.compare("nop") == 0) {
input_system->AddDriver(xe::hid::nop::Create(input_system));
input_system->AddDriver(xe::hid::nop::Create(input_system.get()));
#if XE_PLATFORM_WIN32
} else if (FLAGS_hid.compare("winkey") == 0) {
input_system->AddDriver(xe::hid::winkey::Create(input_system));
input_system->AddDriver(xe::hid::winkey::Create(input_system.get()));
} else if (FLAGS_hid.compare("xinput") == 0) {
input_system->AddDriver(xe::hid::xinput::Create(input_system));
input_system->AddDriver(xe::hid::xinput::Create(input_system.get()));
#endif // WIN32
} else {
// Create all available.
bool any_created = false;
// NOTE: in any mode we create as many as we can, falling back to nop.
// NOTE: in any mode we create as many as we can, falling back to nop.
#if XE_PLATFORM_WIN32
InputDriver* xinput_driver = xe::hid::xinput::Create(input_system);
auto xinput_driver = xe::hid::xinput::Create(input_system.get());
if (xinput_driver) {
input_system->AddDriver(xinput_driver);
input_system->AddDriver(std::move(xinput_driver));
any_created = true;
}
InputDriver* winkey_driver = xe::hid::winkey::Create(input_system);
auto winkey_driver = xe::hid::winkey::Create(input_system.get());
if (winkey_driver) {
input_system->AddDriver(winkey_driver);
input_system->AddDriver(std::move(winkey_driver));
any_created = true;
}
#endif // WIN32
// Fallback to nop if none created.
if (!any_created) {
input_system->AddDriver(xe::hid::nop::Create(input_system));
input_system->AddDriver(xe::hid::nop::Create(input_system.get()));
}
}

View File

@@ -10,6 +10,8 @@
#ifndef XENIA_HID_HID_H_
#define XENIA_HID_HID_H_
#include <memory>
#include <xenia/hid/input_system.h>
namespace xe {
@@ -19,7 +21,7 @@ class Emulator;
namespace xe {
namespace hid {
InputSystem* Create(Emulator* emulator);
std::unique_ptr<InputSystem> Create(Emulator* emulator);
} // namespace hid
} // namespace xe

View File

@@ -32,9 +32,9 @@ void InitializeIfNeeded() {
void CleanupOnShutdown() {}
InputDriver* xe::hid::nop::Create(InputSystem* input_system) {
std::unique_ptr<InputDriver> Create(InputSystem* input_system) {
InitializeIfNeeded();
return new NopInputDriver(input_system);
return std::make_unique<NopInputDriver>(input_system);
}
} // namespace nop

View File

@@ -10,6 +10,8 @@
#ifndef XENIA_HID_NOP_NOP_HID_H_
#define XENIA_HID_NOP_NOP_HID_H_
#include <memory>
#include <xenia/core.h>
namespace xe {
@@ -18,7 +20,7 @@ class InputDriver;
class InputSystem;
namespace nop {
InputDriver* Create(InputSystem* input_system);
std::unique_ptr<InputDriver> Create(InputSystem* input_system);
} // namespace nop
} // namespace hid

View File

@@ -32,9 +32,9 @@ void InitializeIfNeeded() {
void CleanupOnShutdown() {}
InputDriver* xe::hid::winkey::Create(InputSystem* input_system) {
std::unique_ptr<InputDriver> Create(InputSystem* input_system) {
InitializeIfNeeded();
return new WinKeyInputDriver(input_system);
return std::make_unique<WinKeyInputDriver>(input_system);
}
} // namespace winkey

View File

@@ -10,16 +10,17 @@
#ifndef XENIA_HID_WINKEY_WINKEY_HID_H_
#define XENIA_HID_WINKEY_WINKEY_HID_H_
#include <xenia/core.h>
#include <memory>
XEDECLARECLASS2(xe, hid, InputDriver);
XEDECLARECLASS2(xe, hid, InputSystem);
#include <xenia/core.h>
namespace xe {
namespace hid {
class InputDriver;
class InputSystem;
namespace winkey {
InputDriver* Create(InputSystem* input_system);
std::unique_ptr<InputDriver> Create(InputSystem* input_system);
} // namespace winkey
} // namespace hid

View File

@@ -32,9 +32,9 @@ void InitializeIfNeeded() {
void CleanupOnShutdown() {}
InputDriver* xe::hid::xinput::Create(InputSystem* input_system) {
std::unique_ptr<InputDriver> Create(InputSystem* input_system) {
InitializeIfNeeded();
return new XInputInputDriver(input_system);
return std::make_unique<XInputInputDriver>(input_system);
}
} // namespace xinput

View File

@@ -10,16 +10,17 @@
#ifndef XENIA_HID_XINPUT_XINPUT_HID_H_
#define XENIA_HID_XINPUT_XINPUT_HID_H_
#include <xenia/core.h>
#include <memory>
XEDECLARECLASS2(xe, hid, InputDriver);
XEDECLARECLASS2(xe, hid, InputSystem);
#include <xenia/core.h>
namespace xe {
namespace hid {
class InputDriver;
class InputSystem;
namespace xinput {
InputDriver* Create(InputSystem* input_system);
std::unique_ptr<InputDriver> Create(InputSystem* input_system);
} // namespace xinput
} // namespace hid