mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-09-09 11:55:52 -05:00
HW/HSP: Ensure an IHSPDevice object always exists to remove null checks as a micro optimization.
This commit is contained in:
@@ -16,54 +16,49 @@ HSPManager::~HSPManager() = default;
|
||||
|
||||
void HSPManager::Init()
|
||||
{
|
||||
AddDevice(Config::Get(Config::MAIN_HSP_DEVICE));
|
||||
SetDevice(Config::Get(Config::MAIN_HSP_DEVICE));
|
||||
}
|
||||
|
||||
void HSPManager::Shutdown()
|
||||
{
|
||||
RemoveDevice();
|
||||
m_device.reset();
|
||||
}
|
||||
|
||||
u64 HSPManager::Read(u32 address)
|
||||
{
|
||||
DEBUG_LOG_FMT(HSP, "HSP read from 0x{:08x}", address);
|
||||
if (m_device)
|
||||
return m_device->Read(address);
|
||||
return 0;
|
||||
|
||||
return m_device->Read(address);
|
||||
}
|
||||
|
||||
void HSPManager::Write(u32 address, u64 value)
|
||||
{
|
||||
DEBUG_LOG_FMT(HSP, "HSP write to 0x{:08x}: 0x{:016x}", address, value);
|
||||
if (m_device)
|
||||
m_device->Write(address, value);
|
||||
|
||||
m_device->Write(address, value);
|
||||
}
|
||||
|
||||
void HSPManager::DoState(PointerWrap& p)
|
||||
{
|
||||
HSPDeviceType type = m_device->GetDeviceType();
|
||||
p.Do(type);
|
||||
const HSPDeviceType current_type = m_device->GetDeviceType();
|
||||
auto state_type = current_type;
|
||||
p.Do(state_type);
|
||||
|
||||
// If the type doesn't match, switch to the right device type
|
||||
if (type != m_device->GetDeviceType())
|
||||
AddDevice(type);
|
||||
if (state_type != current_type)
|
||||
SetDevice(state_type);
|
||||
|
||||
m_device->DoState(p);
|
||||
}
|
||||
|
||||
void HSPManager::AddDevice(std::unique_ptr<IHSPDevice> device)
|
||||
void HSPManager::SetDevice(std::unique_ptr<IHSPDevice> device)
|
||||
{
|
||||
// Set the new one
|
||||
m_device = std::move(device);
|
||||
}
|
||||
|
||||
void HSPManager::AddDevice(const HSPDeviceType device)
|
||||
void HSPManager::SetDevice(const HSPDeviceType device)
|
||||
{
|
||||
AddDevice(HSPDevice_Create(device));
|
||||
SetDevice(HSPDevice_Create(device));
|
||||
}
|
||||
|
||||
void HSPManager::RemoveDevice()
|
||||
{
|
||||
m_device.reset();
|
||||
}
|
||||
} // namespace HSP
|
||||
|
||||
@@ -32,9 +32,8 @@ public:
|
||||
|
||||
void DoState(PointerWrap& p);
|
||||
|
||||
void RemoveDevice();
|
||||
void AddDevice(std::unique_ptr<IHSPDevice> device);
|
||||
void AddDevice(HSPDeviceType device);
|
||||
void SetDevice(std::unique_ptr<IHSPDevice> device);
|
||||
void SetDevice(HSPDeviceType device);
|
||||
|
||||
private:
|
||||
std::unique_ptr<IHSPDevice> m_device;
|
||||
|
||||
Reference in New Issue
Block a user