mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-10 20:05:47 -04:00
Move controller creation to System class, switch shared_ptr to unique_ptr
This commit is contained in:
@ -23,7 +23,7 @@ bool Controller::Transfer(const u8 data_in, u8* data_out)
|
||||
|
||||
void Controller::SetButtonState(s32 button_code, bool pressed) {}
|
||||
|
||||
std::shared_ptr<Controller> Controller::Create(std::string_view type_name)
|
||||
std::unique_ptr<Controller> Controller::Create(std::string_view type_name)
|
||||
{
|
||||
if (type_name == "DigitalController")
|
||||
return DigitalController::Create();
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
virtual void SetButtonState(s32 button_code, bool pressed);
|
||||
|
||||
/// Creates a new controller of the specified type.
|
||||
static std::shared_ptr<Controller> Create(std::string_view type_name);
|
||||
static std::unique_ptr<Controller> Create(std::string_view type_name);
|
||||
|
||||
/// Gets the integer code for a button in the specified controller type.
|
||||
static std::optional<s32> GetButtonCodeByName(std::string_view type_name, std::string_view button_name);
|
||||
|
@ -76,9 +76,9 @@ bool DigitalController::Transfer(const u8 data_in, u8* data_out)
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<DigitalController> DigitalController::Create()
|
||||
std::unique_ptr<DigitalController> DigitalController::Create()
|
||||
{
|
||||
return std::make_shared<DigitalController>();
|
||||
return std::make_unique<DigitalController>();
|
||||
}
|
||||
|
||||
std::optional<s32> DigitalController::GetButtonCodeByName(std::string_view button_name)
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
DigitalController();
|
||||
~DigitalController() override;
|
||||
|
||||
static std::shared_ptr<DigitalController> Create();
|
||||
static std::unique_ptr<DigitalController> Create();
|
||||
static std::optional<s32> GetButtonCodeByName(std::string_view button_name);
|
||||
|
||||
void SetButtonState(Button button, bool pressed);
|
||||
|
@ -66,7 +66,6 @@ bool HostInterface::BootSystem(const char* filename, const char* state_filename)
|
||||
return false;
|
||||
|
||||
m_paused = m_settings.start_paused;
|
||||
ConnectControllers();
|
||||
UpdateSpeedLimiterState();
|
||||
|
||||
if (state_filename && !LoadState(state_filename))
|
||||
@ -208,8 +207,6 @@ std::optional<std::vector<u8>> HostInterface::GetBIOSImage(ConsoleRegion region)
|
||||
return BIOS::LoadImageFromFile(m_settings.bios_path);
|
||||
}
|
||||
|
||||
void HostInterface::ConnectControllers() {}
|
||||
|
||||
void HostInterface::Throttle()
|
||||
{
|
||||
// Allow variance of up to 40ms either way.
|
||||
|
@ -60,9 +60,6 @@ protected:
|
||||
float duration;
|
||||
};
|
||||
|
||||
/// Connects controllers. TODO: Clean this up later...
|
||||
virtual void ConnectControllers();
|
||||
|
||||
/// Throttles the system, i.e. sleeps until it's time to execute the next frame.
|
||||
void Throttle();
|
||||
|
||||
|
@ -230,16 +230,16 @@ bool MemoryCard::Transfer(const u8 data_in, u8* data_out)
|
||||
return ack;
|
||||
}
|
||||
|
||||
std::shared_ptr<MemoryCard> MemoryCard::Create(System* system)
|
||||
std::unique_ptr<MemoryCard> MemoryCard::Create(System* system)
|
||||
{
|
||||
auto mc = std::make_shared<MemoryCard>(system);
|
||||
std::unique_ptr<MemoryCard> mc = std::make_unique<MemoryCard>(system);
|
||||
mc->Format();
|
||||
return mc;
|
||||
}
|
||||
|
||||
std::shared_ptr<MemoryCard> MemoryCard::Open(System* system, std::string_view filename)
|
||||
std::unique_ptr<MemoryCard> MemoryCard::Open(System* system, std::string_view filename)
|
||||
{
|
||||
auto mc = std::make_shared<MemoryCard>(system);
|
||||
std::unique_ptr<MemoryCard> mc = std::make_unique<MemoryCard>(system);
|
||||
mc->m_filename = filename;
|
||||
if (!mc->LoadFromFile())
|
||||
{
|
||||
|
@ -21,8 +21,8 @@ public:
|
||||
MemoryCard(System* system);
|
||||
~MemoryCard();
|
||||
|
||||
static std::shared_ptr<MemoryCard> Create(System* system);
|
||||
static std::shared_ptr<MemoryCard> Open(System* system, std::string_view filename);
|
||||
static std::unique_ptr<MemoryCard> Create(System* system);
|
||||
static std::unique_ptr<MemoryCard> Open(System* system, std::string_view filename);
|
||||
|
||||
void Reset();
|
||||
bool DoState(StateWrapper& sw);
|
||||
|
@ -95,6 +95,16 @@ bool Pad::DoState(StateWrapper& sw)
|
||||
return !sw.HasError();
|
||||
}
|
||||
|
||||
void Pad::SetController(u32 slot, std::unique_ptr<Controller> dev)
|
||||
{
|
||||
m_controllers[slot] = std::move(dev);
|
||||
}
|
||||
|
||||
void Pad::SetMemoryCard(u32 slot, std::unique_ptr<MemoryCard> dev)
|
||||
{
|
||||
m_memory_cards[slot] = std::move(dev);
|
||||
}
|
||||
|
||||
u32 Pad::ReadRegister(u32 offset)
|
||||
{
|
||||
switch (offset)
|
||||
@ -289,8 +299,8 @@ void Pad::DoTransfer()
|
||||
{
|
||||
Log_DebugPrintf("Transferring slot %d", m_JOY_CTRL.SLOT.GetValue());
|
||||
|
||||
const std::shared_ptr<Controller>& controller = m_controllers[m_JOY_CTRL.SLOT];
|
||||
const std::shared_ptr<MemoryCard>& memory_card = m_memory_cards[m_JOY_CTRL.SLOT];
|
||||
Controller* const controller = m_controllers[m_JOY_CTRL.SLOT].get();
|
||||
MemoryCard* const memory_card = m_memory_cards[m_JOY_CTRL.SLOT].get();
|
||||
|
||||
// set rx?
|
||||
m_JOY_CTRL.RXEN = true;
|
||||
|
@ -22,11 +22,11 @@ public:
|
||||
void Reset();
|
||||
bool DoState(StateWrapper& sw);
|
||||
|
||||
Controller* GetController(u32 slot) { return m_controllers[slot].get(); }
|
||||
void SetController(u32 slot, std::shared_ptr<Controller> dev) { m_controllers[slot] = dev; }
|
||||
Controller* GetController(u32 slot) const { return m_controllers[slot].get(); }
|
||||
void SetController(u32 slot, std::unique_ptr<Controller> dev);
|
||||
|
||||
MemoryCard* GetMemoryCard(u32 slot) { return m_memory_cards[slot].get(); }
|
||||
void SetMemoryCard(u32 slot, std::shared_ptr<MemoryCard> dev) { m_memory_cards[slot] = dev; }
|
||||
void SetMemoryCard(u32 slot, std::unique_ptr<MemoryCard> dev);
|
||||
|
||||
u32 ReadRegister(u32 offset);
|
||||
void WriteRegister(u32 offset, u32 value);
|
||||
@ -106,8 +106,8 @@ private:
|
||||
System* m_system = nullptr;
|
||||
InterruptController* m_interrupt_controller = nullptr;
|
||||
|
||||
std::array<std::shared_ptr<Controller>, NUM_SLOTS> m_controllers;
|
||||
std::array<std::shared_ptr<MemoryCard>, NUM_SLOTS> m_memory_cards;
|
||||
std::array<std::unique_ptr<Controller>, NUM_SLOTS> m_controllers;
|
||||
std::array<std::unique_ptr<MemoryCard>, NUM_SLOTS> m_memory_cards;
|
||||
|
||||
State m_state = State::Idle;
|
||||
TickCount m_ticks_remaining = 0;
|
||||
|
@ -146,6 +146,7 @@ bool System::Boot(const char* filename)
|
||||
|
||||
// Component setup.
|
||||
InitializeComponents();
|
||||
UpdateControllers();
|
||||
UpdateMemoryCards();
|
||||
Reset();
|
||||
|
||||
@ -451,9 +452,21 @@ void System::StallCPU(TickCount ticks)
|
||||
m_cpu->AddPendingTicks(ticks);
|
||||
}
|
||||
|
||||
void System::SetController(u32 slot, std::shared_ptr<Controller> dev)
|
||||
Controller* System::GetController(u32 slot) const
|
||||
{
|
||||
m_pad->SetController(slot, std::move(dev));
|
||||
return m_pad->GetController(slot);
|
||||
}
|
||||
|
||||
void System::UpdateControllers()
|
||||
{
|
||||
m_pad->SetController(0, nullptr);
|
||||
m_pad->SetController(1, nullptr);
|
||||
|
||||
{
|
||||
std::unique_ptr<Controller> controller = Controller::Create("DigitalController");
|
||||
if (controller)
|
||||
m_pad->SetController(0, std::move(controller));
|
||||
}
|
||||
}
|
||||
|
||||
void System::UpdateMemoryCards()
|
||||
@ -464,14 +477,14 @@ void System::UpdateMemoryCards()
|
||||
const Settings& settings = m_host_interface->GetSettings();
|
||||
if (!settings.memory_card_a_path.empty())
|
||||
{
|
||||
std::shared_ptr<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_a_path);
|
||||
std::unique_ptr<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_a_path);
|
||||
if (card)
|
||||
m_pad->SetMemoryCard(0, std::move(card));
|
||||
}
|
||||
|
||||
if (!settings.memory_card_b_path.empty())
|
||||
{
|
||||
std::shared_ptr<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_b_path);
|
||||
std::unique_ptr<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_b_path);
|
||||
if (card)
|
||||
m_pad->SetMemoryCard(1, std::move(card));
|
||||
}
|
||||
|
@ -79,7 +79,9 @@ public:
|
||||
// Adds ticks to the global tick counter, simulating the CPU being stalled.
|
||||
void StallCPU(TickCount ticks);
|
||||
|
||||
void SetController(u32 slot, std::shared_ptr<Controller> dev);
|
||||
// Access controllers for simulating input.
|
||||
Controller* GetController(u32 slot) const;
|
||||
void UpdateControllers();
|
||||
void UpdateMemoryCards();
|
||||
void UpdateCPUExecutionMode();
|
||||
|
||||
|
Reference in New Issue
Block a user