Merge pull request #6072 from JosJuice/eject-disc

Add an option to eject the disc
This commit is contained in:
Leo Lam 2017-09-18 12:47:47 +02:00 committed by GitHub
commit c9f790dca4
12 changed files with 30 additions and 20 deletions

View File

@ -19,7 +19,6 @@
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/CoreTiming.h" #include "Core/CoreTiming.h"
#include "Core/HW/AudioInterface.h" #include "Core/HW/AudioInterface.h"
#include "Core/HW/DVD/DVDMath.h" #include "Core/HW/DVD/DVDMath.h"
@ -451,10 +450,6 @@ bool IsDiscInside()
return DVDThread::HasDisc(); return DVDThread::HasDisc();
} }
// Take care of all logic of "swapping discs"
// We want this in the "backend", NOT the gui
// any !empty string will be deleted to ensure
// that the userdata string exists when called
static void EjectDiscCallback(u64 userdata, s64 cyclesLate) static void EjectDiscCallback(u64 userdata, s64 cyclesLate)
{ {
SetDisc(nullptr); SetDisc(nullptr);
@ -473,14 +468,14 @@ static void InsertDiscCallback(u64 userdata, s64 cyclesLate)
s_disc_path_to_insert.clear(); s_disc_path_to_insert.clear();
} }
// Can only be called by the host thread // Must only be called on the CPU thread
void ChangeDiscAsHost(const std::string& new_path) void EjectDisc()
{ {
Core::RunAsCPUThread([&] { ChangeDiscAsCPU(new_path); }); CoreTiming::ScheduleEvent(0, s_eject_disc);
} }
// Can only be called by the CPU thread // Must only be called on the CPU thread
void ChangeDiscAsCPU(const std::string& new_path) void ChangeDisc(const std::string& new_path)
{ {
if (!s_disc_path_to_insert.empty()) if (!s_disc_path_to_insert.empty())
{ {
@ -488,10 +483,10 @@ void ChangeDiscAsCPU(const std::string& new_path)
return; return;
} }
s_disc_path_to_insert = new_path; EjectDisc();
CoreTiming::ScheduleEvent(0, s_eject_disc);
CoreTiming::ScheduleEvent(SystemTimers::GetTicksPerSecond(), s_insert_disc);
s_disc_path_to_insert = new_path;
CoreTiming::ScheduleEvent(SystemTimers::GetTicksPerSecond(), s_insert_disc);
Movie::SignalDiscChange(new_path); Movie::SignalDiscChange(new_path);
} }

View File

@ -113,8 +113,8 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base);
void SetDisc(std::unique_ptr<DiscIO::Volume> disc); void SetDisc(std::unique_ptr<DiscIO::Volume> disc);
bool IsDiscInside(); bool IsDiscInside();
void ChangeDiscAsHost(const std::string& new_path); // Can only be called by the host thread void EjectDisc(); // Must only be called on the CPU thread
void ChangeDiscAsCPU(const std::string& new_path); // Can only be called by the CPU thread void ChangeDisc(const std::string& new_path); // Must only be called on the CPU thread
// This function returns true and calls SConfig::SetRunningGameMetadata(Volume&, Partition&) // This function returns true and calls SConfig::SetRunningGameMetadata(Volume&, Partition&)
// if both of the following conditions are true: // if both of the following conditions are true:

View File

@ -23,6 +23,7 @@
const std::string hotkey_labels[] = { const std::string hotkey_labels[] = {
_trans("Open"), _trans("Open"),
_trans("Change Disc"), _trans("Change Disc"),
_trans("Eject Disc"),
_trans("Refresh List"), _trans("Refresh List"),
_trans("Toggle Pause"), _trans("Toggle Pause"),
_trans("Stop"), _trans("Stop"),

View File

@ -21,6 +21,7 @@ enum Hotkey
{ {
HK_OPEN, HK_OPEN,
HK_CHANGE_DISC, HK_CHANGE_DISC,
HK_EJECT_DISC,
HK_REFRESH_LIST, HK_REFRESH_LIST,
HK_PLAY_PAUSE, HK_PLAY_PAUSE,
HK_STOP, HK_STOP,

View File

@ -1180,7 +1180,7 @@ void PlayController(GCPadStatus* PadStatus, int controllerID)
} }
if (found) if (found)
{ {
DVDInterface::ChangeDiscAsCPU(path); Core::RunAsCPUThread([&path] { DVDInterface::ChangeDisc(path); });
} }
else else
{ {

View File

@ -417,7 +417,8 @@ void GameList::DeleteFile()
void GameList::ChangeDisc() void GameList::ChangeDisc()
{ {
DVDInterface::ChangeDiscAsHost(GetSelectedGame()->GetFilePath().toStdString()); Core::RunAsCPUThread(
[this] { DVDInterface::ChangeDisc(GetSelectedGame()->GetFilePath().toStdString()); });
} }
QSharedPointer<GameFile> GameList::GetSelectedGame() const QSharedPointer<GameFile> GameList::GetSelectedGame() const

View File

@ -143,7 +143,7 @@ void CRenderFrame::OnDropFiles(wxDropFilesEvent& event)
} }
else else
{ {
DVDInterface::ChangeDiscAsHost(filepath); Core::RunAsCPUThread([&filepath] { DVDInterface::ChangeDisc(filepath); });
} }
} }
@ -961,6 +961,8 @@ static int GetMenuIDFromHotkey(unsigned int key)
return wxID_OPEN; return wxID_OPEN;
case HK_CHANGE_DISC: case HK_CHANGE_DISC:
return IDM_CHANGE_DISC; return IDM_CHANGE_DISC;
case HK_EJECT_DISC:
return IDM_EJECT_DISC;
case HK_REFRESH_LIST: case HK_REFRESH_LIST:
return wxID_REFRESH; return wxID_REFRESH;
case HK_PLAY_PAUSE: case HK_PLAY_PAUSE:
@ -1305,6 +1307,7 @@ void CFrame::ParseHotkeys()
{ {
case HK_OPEN: case HK_OPEN:
case HK_CHANGE_DISC: case HK_CHANGE_DISC:
case HK_EJECT_DISC:
case HK_REFRESH_LIST: case HK_REFRESH_LIST:
case HK_RESET: case HK_RESET:
case HK_START_RECORDING: case HK_START_RECORDING:

View File

@ -299,6 +299,7 @@ private:
void OnShowInputDisplay(wxCommandEvent& event); void OnShowInputDisplay(wxCommandEvent& event);
void OnShowRTCDisplay(wxCommandEvent& event); void OnShowRTCDisplay(wxCommandEvent& event);
void OnChangeDisc(wxCommandEvent& event); void OnChangeDisc(wxCommandEvent& event);
void OnEjectDisc(wxCommandEvent& event);
void OnScreenshot(wxCommandEvent& event); void OnScreenshot(wxCommandEvent& event);
void OnActive(wxActivateEvent& event); void OnActive(wxActivateEvent& event);
void OnClose(wxCloseEvent& event); void OnClose(wxCloseEvent& event);

View File

@ -127,6 +127,7 @@ void CFrame::BindMenuBarEvents()
// File menu // File menu
Bind(wxEVT_MENU, &CFrame::OnOpen, this, wxID_OPEN); Bind(wxEVT_MENU, &CFrame::OnOpen, this, wxID_OPEN);
Bind(wxEVT_MENU, &CFrame::OnChangeDisc, this, IDM_CHANGE_DISC); Bind(wxEVT_MENU, &CFrame::OnChangeDisc, this, IDM_CHANGE_DISC);
Bind(wxEVT_MENU, &CFrame::OnEjectDisc, this, IDM_EJECT_DISC);
Bind(wxEVT_MENU, &CFrame::OnBootDrive, this, IDM_DRIVE1, IDM_DRIVE24); Bind(wxEVT_MENU, &CFrame::OnBootDrive, this, IDM_DRIVE1, IDM_DRIVE24);
Bind(wxEVT_MENU, &CFrame::OnRefresh, this, wxID_REFRESH); Bind(wxEVT_MENU, &CFrame::OnRefresh, this, wxID_REFRESH);
Bind(wxEVT_MENU, &CFrame::OnQuit, this, wxID_EXIT); Bind(wxEVT_MENU, &CFrame::OnQuit, this, wxID_EXIT);
@ -369,7 +370,7 @@ void CFrame::DoOpen(bool Boot)
} }
else else
{ {
DVDInterface::ChangeDiscAsHost(WxStrToStr(path)); Core::RunAsCPUThread([&path] { DVDInterface::ChangeDisc(WxStrToStr(path)); });
} }
} }
@ -459,6 +460,11 @@ void CFrame::OnChangeDisc(wxCommandEvent& WXUNUSED(event))
DoOpen(false); DoOpen(false);
} }
void CFrame::OnEjectDisc(wxCommandEvent& WXUNUSED(event))
{
Core::RunAsCPUThread(DVDInterface::EjectDisc);
}
void CFrame::OnRecord(wxCommandEvent& WXUNUSED(event)) void CFrame::OnRecord(wxCommandEvent& WXUNUSED(event))
{ {
if ((!Core::IsRunningAndStarted() && Core::IsRunning()) || Movie::IsRecordingInput() || if ((!Core::IsRunningAndStarted() && Core::IsRunning()) || Movie::IsRecordingInput() ||

View File

@ -1557,7 +1557,7 @@ void GameListCtrl::OnChangeDisc(wxCommandEvent& WXUNUSED(event))
const GameListItem* iso = GetSelectedISO(); const GameListItem* iso = GetSelectedISO();
if (!iso || !Core::IsRunning()) if (!iso || !Core::IsRunning())
return; return;
DVDInterface::ChangeDiscAsHost(WxStrToStr(iso->GetFileName())); Core::RunAsCPUThread([&iso] { DVDInterface::ChangeDisc(WxStrToStr(iso->GetFileName())); });
} }
void GameListCtrl::OnSize(wxSizeEvent& event) void GameListCtrl::OnSize(wxSizeEvent& event)

View File

@ -94,6 +94,7 @@ enum
IDM_CHEATS, IDM_CHEATS,
IDM_NETPLAY, IDM_NETPLAY,
IDM_RESTART, IDM_RESTART,
IDM_EJECT_DISC,
IDM_CHANGE_DISC, IDM_CHANGE_DISC,
IDM_LIST_CHANGE_DISC, IDM_LIST_CHANGE_DISC,
IDM_PROPERTIES, IDM_PROPERTIES,

View File

@ -79,6 +79,7 @@ wxMenu* MainMenuBar::CreateFileMenu() const
auto* const file_menu = new wxMenu; auto* const file_menu = new wxMenu;
file_menu->Append(wxID_OPEN, _("&Open...")); file_menu->Append(wxID_OPEN, _("&Open..."));
file_menu->Append(IDM_CHANGE_DISC, _("Change &Disc...")); file_menu->Append(IDM_CHANGE_DISC, _("Change &Disc..."));
file_menu->Append(IDM_EJECT_DISC, _("Eject Disc"));
file_menu->Append(IDM_DRIVES, _("&Boot from DVD Backup"), external_drive_menu); file_menu->Append(IDM_DRIVES, _("&Boot from DVD Backup"), external_drive_menu);
file_menu->AppendSeparator(); file_menu->AppendSeparator();
file_menu->Append(wxID_REFRESH, _("&Refresh Game List")); file_menu->Append(wxID_REFRESH, _("&Refresh Game List"));