Minor optimizations in cellPad

- Dont bother with shared_ptr since all pad_t management is going under the pad mutex.

- Change m_pads type into std::array since its size is known
This commit is contained in:
eladash 2019-03-11 09:30:00 +02:00 committed by Ivan
parent 6502d933df
commit 47ca1b1dda
3 changed files with 21 additions and 22 deletions

View File

@ -66,7 +66,7 @@ error_code cellPadClearBuf(u32 port_no)
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;
@ -110,7 +110,7 @@ error_code cellPadGetData(u32 port_no, vm::ptr<CellPadData> data)
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;
@ -363,7 +363,7 @@ error_code cellPadPeriphGetInfo(vm::ptr<CellPadPeriphInfo> info)
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;
@ -407,7 +407,7 @@ error_code cellPadPeriphGetData(u32 port_no, vm::ptr<CellPadPeriphData> data)
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;
@ -441,7 +441,7 @@ error_code cellPadGetRawData(u32 port_no, vm::ptr<CellPadData> data)
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;
@ -472,7 +472,7 @@ error_code cellPadGetDataExtra(u32 port_no, vm::ptr<u32> device_type, vm::ptr<Ce
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;
@ -513,7 +513,7 @@ error_code cellPadSetActDirect(u32 port_no, vm::ptr<CellPadActParam> param)
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;
@ -553,7 +553,7 @@ error_code cellPadGetInfo(vm::ptr<CellPadInfo> info)
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;
@ -608,7 +608,7 @@ error_code cellPadGetInfo2(vm::ptr<CellPadInfo2> info)
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;
@ -648,7 +648,7 @@ error_code cellPadGetCapabilityInfo(u32 port_no, vm::ptr<CellPadCapabilityInfo>
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;
@ -681,7 +681,7 @@ error_code cellPadSetPortSetting(u32 port_no, u32 port_setting)
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;
@ -708,7 +708,7 @@ s32 cellPadInfoPressMode(u32 port_no)
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;
@ -737,7 +737,7 @@ s32 cellPadInfoSensorMode(u32 port_no)
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;
@ -766,7 +766,7 @@ error_code cellPadSetPressMode(u32 port_no, u32 mode)
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;
@ -802,7 +802,7 @@ error_code cellPadSetSensorMode(u32 port_no, u32 mode)
std::lock_guard lock(pad::g_pad_mutex);
const auto config = fxm::get<pad_t>();
const auto config = fxm::check<pad_t>();
if (!config)
return CELL_PAD_ERROR_UNINITIALIZED;

View File

@ -48,7 +48,7 @@ void pad_thread::Init()
std::vector<pad_setting> pad_settings;
for (u32 i = 0; i < CELL_PAD_MAX_PORT_NUM; i++) // max 7 pads
{
if (i >= m_pads.size())
if (!m_pads[i])
{
pad_settings.push_back({ CELL_PAD_STATUS_DISCONNECTED, CELL_PAD_CAPABILITY_PS3_CONFORMITY | CELL_PAD_CAPABILITY_PRESS_MODE | CELL_PAD_CAPABILITY_ACTUATOR, CELL_PAD_DEV_TYPE_STANDARD });
}
@ -63,7 +63,6 @@ void pad_thread::Init()
m_info.now_connect = 0;
m_info.system_info |= system_info;
m_pads.clear();
handlers.clear();
g_cfg_input.load();
@ -120,13 +119,13 @@ void pad_thread::Init()
}
cur_pad_handler->Init();
m_pads.push_back(std::make_shared<Pad>(CELL_PAD_STATUS_DISCONNECTED, pad_settings[i].device_capability, pad_settings[i].device_type));
m_pads[i] = std::make_shared<Pad>(CELL_PAD_STATUS_DISCONNECTED, pad_settings[i].device_capability, pad_settings[i].device_type);
if (cur_pad_handler->bindPadToDevice(m_pads.back(), g_cfg_input.player[i]->device.to_string()) == false)
if (cur_pad_handler->bindPadToDevice(m_pads[i], g_cfg_input.player[i]->device.to_string()) == false)
{
// Failed to bind the device to cur_pad_handler so binds to NullPadHandler
LOG_ERROR(GENERAL, "Failed to bind device %s to handler %s", g_cfg_input.player[i]->device.to_string(), handler_type.to_string());
nullpad->bindPadToDevice(m_pads.back(), g_cfg_input.player[i]->device.to_string());
nullpad->bindPadToDevice(m_pads[i], g_cfg_input.player[i]->device.to_string());
}
}
}

View File

@ -20,7 +20,7 @@ public:
~pad_thread();
PadInfo& GetInfo() { return m_info; }
std::vector<std::shared_ptr<Pad>>& GetPads() { return m_pads; }
auto& GetPads() { return m_pads; }
void SetRumble(const u32 pad, u8 largeMotor, bool smallMotor);
void Init();
void Reset();
@ -38,7 +38,7 @@ protected:
void *curwindow;
PadInfo m_info{ 0, 0 };
std::vector<std::shared_ptr<Pad>> m_pads;
std::array<std::shared_ptr<Pad>, CELL_PAD_MAX_PORT_NUM> m_pads;
atomic_t<bool> active{ false };
atomic_t<bool> reset{ false };