From 7f0203a5b0d61919c7e7513c2fd39c619490d392 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 2 Apr 2017 01:45:11 -0400 Subject: [PATCH] Frame: Make TAS dialogs private Amends the TAS callbacks to internally store functions using std::function instead of raw function pointers. This allows binding extra contextual state via lambda functions, as well as keeping the dialogs internal to the main frame (on top of being a more flexible interface). --- Source/Core/Core/Movie.cpp | 16 ++++---- Source/Core/Core/Movie.h | 6 ++- .../Debugger/CodeWindowFunctions.cpp | 2 + Source/Core/DolphinWX/Frame.cpp | 37 +++++++++---------- Source/Core/DolphinWX/Frame.h | 11 ++---- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index b0de9e3faa..bcd777357c 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "Core/Movie.h" + #include #include #include @@ -10,6 +12,7 @@ #include #include #include +#include #include #include "Common/Assert.h" @@ -34,7 +37,6 @@ #include "Core/HW/WiimoteEmu/WiimoteHid.h" #include "Core/IOS/USB/Bluetooth/BTEmu.h" #include "Core/IOS/USB/Bluetooth/WiimoteDevice.h" -#include "Core/Movie.h" #include "Core/NetPlayProto.h" #include "Core/PowerPC/PowerPC.h" #include "Core/State.h" @@ -91,8 +93,8 @@ static bool s_bPolled = false; static std::mutex s_input_display_lock; static std::string s_InputDisplay[8]; -static GCManipFunction gcmfunc = nullptr; -static WiiManipFunction wiimfunc = nullptr; +static GCManipFunction gcmfunc; +static WiiManipFunction wiimfunc; // NOTE: Host / CPU Thread static void EnsureTmpInputSize(size_t bound) @@ -1440,25 +1442,25 @@ void SaveRecording(const std::string& filename) void SetGCInputManip(GCManipFunction func) { - gcmfunc = func; + gcmfunc = std::move(func); } void SetWiiInputManip(WiiManipFunction func) { - wiimfunc = func; + wiimfunc = std::move(func); } // NOTE: CPU Thread void CallGCInputManip(GCPadStatus* PadStatus, int controllerID) { if (gcmfunc) - (*gcmfunc)(PadStatus, controllerID); + gcmfunc(PadStatus, controllerID); } // NOTE: CPU Thread void CallWiiInputManip(u8* data, WiimoteEmu::ReportFeatures rptf, int controllerID, int ext, const wiimote_key key) { if (wiimfunc) - (*wiimfunc)(data, rptf, controllerID, ext, key); + wiimfunc(data, rptf, controllerID, ext, key); } // NOTE: GPU Thread diff --git a/Source/Core/Core/Movie.h b/Source/Core/Core/Movie.h index e7da22d12e..30c93e2eec 100644 --- a/Source/Core/Core/Movie.h +++ b/Source/Core/Core/Movie.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "Common/CommonTypes.h" @@ -181,8 +182,9 @@ std::string GetInputDisplay(); std::string GetRTCDisplay(); // Done this way to avoid mixing of core and gui code -typedef void (*GCManipFunction)(GCPadStatus*, int); -typedef void (*WiiManipFunction)(u8*, WiimoteEmu::ReportFeatures, int, int, wiimote_key); +using GCManipFunction = std::function; +using WiiManipFunction = + std::function; void SetGCInputManip(GCManipFunction); void SetWiiInputManip(WiiManipFunction); diff --git a/Source/Core/DolphinWX/Debugger/CodeWindowFunctions.cpp b/Source/Core/DolphinWX/Debugger/CodeWindowFunctions.cpp index 4c125c26e9..df287220df 100644 --- a/Source/Core/DolphinWX/Debugger/CodeWindowFunctions.cpp +++ b/Source/Core/DolphinWX/Debugger/CodeWindowFunctions.cpp @@ -3,7 +3,9 @@ // Refer to the license.txt file included. #include +#include #include +#include #include #include #include diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index a62134b8ab..830003e6c5 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -47,6 +47,7 @@ #include "Core/HW/GCKeyboard.h" #include "Core/HW/GCPad.h" #include "Core/HW/Wiimote.h" +#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HotkeyManager.h" #include "Core/IOS/IPC.h" #include "Core/IOS/USB/Bluetooth/BTBase.h" @@ -389,11 +390,7 @@ CFrame::CFrame(wxFrame* parent, wxWindowID id, const wxString& title, wxRect geo m_LogWindow->Hide(); m_LogWindow->Disable(); - for (int i = 0; i < 8; ++i) - g_TASInputDlg[i] = new TASInputDlg(this); - - Movie::SetGCInputManip(GCTASManipFunction); - Movie::SetWiiInputManip(WiiTASManipFunction); + InitializeTASDialogs(); State::SetOnAfterLoadCallback(OnAfterLoadCallback); Core::SetOnStoppedCallback(OnStoppedCallback); @@ -502,6 +499,21 @@ void CFrame::BindEvents() Bind(DOLPHIN_EVT_STOP_SOFTWARE, &CFrame::OnStop, this); } +void CFrame::InitializeTASDialogs() +{ + for (int i = 0; i < 8; ++i) + g_TASInputDlg[i] = new TASInputDlg(this); + + Movie::SetGCInputManip([this](GCPadStatus* pad_status, int controller_id) { + g_TASInputDlg[controller_id]->GetValues(pad_status); + }); + + Movie::SetWiiInputManip([this](u8* data, WiimoteEmu::ReportFeatures rptf, int controller_id, + int ext, wiimote_key key) { + g_TASInputDlg[controller_id + 4]->GetValues(data, rptf, ext, key); + }); +} + bool CFrame::RendererIsFullscreen() { bool fullscreen = false; @@ -1034,21 +1046,6 @@ void OnStoppedCallback() } } -void GCTASManipFunction(GCPadStatus* PadStatus, int controllerID) -{ - if (main_frame) - main_frame->g_TASInputDlg[controllerID]->GetValues(PadStatus); -} - -void WiiTASManipFunction(u8* data, WiimoteEmu::ReportFeatures rptf, int controllerID, int ext, - const wiimote_key key) -{ - if (main_frame) - { - main_frame->g_TASInputDlg[controllerID + 4]->GetValues(data, rptf, ext, key); - } -} - void CFrame::OnKeyDown(wxKeyEvent& event) { // On OS X, we claim all keyboard events while diff --git a/Source/Core/DolphinWX/Frame.h b/Source/Core/DolphinWX/Frame.h index f32973d3af..b839512440 100644 --- a/Source/Core/DolphinWX/Frame.h +++ b/Source/Core/DolphinWX/Frame.h @@ -16,9 +16,7 @@ #include "Common/CommonTypes.h" #include "Common/Event.h" -#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "DolphinWX/Globals.h" -#include "InputCommon/GCPadStatus.h" #if defined(HAVE_X11) && HAVE_X11 #include "UICommon/X11Utils.h" @@ -88,7 +86,6 @@ public: CCodeWindow* g_pCodeWindow = nullptr; NetPlaySetupFrame* g_NetPlaySetupDiag = nullptr; wxCheatsWindow* g_CheatsWindow = nullptr; - TASInputDlg* g_TASInputDlg[8]; void DoStop(); void UpdateGUI(); @@ -140,6 +137,7 @@ private: CLogWindow* m_LogWindow = nullptr; LogConfigWindow* m_LogConfigWindow = nullptr; FifoPlayerDlg* m_FifoPlayerDlg = nullptr; + TASInputDlg* g_TASInputDlg[8]; bool UseDebugger = false; bool m_bBatchMode = false; bool m_bEdit = false; @@ -174,6 +172,8 @@ private: wxToolBar* OnCreateToolBar(long style, wxWindowID id, const wxString& name) override; wxMenuBar* CreateMenuBar() const; + void InitializeTASDialogs(); + // Utility wxWindow* GetNotebookPageFromId(wxWindowID Id); wxAuiNotebook* GetNotebookFromId(u32 NBId); @@ -339,8 +339,3 @@ private: void OnAfterLoadCallback(); void OnStoppedCallback(); - -// For TASInputDlg -void GCTASManipFunction(GCPadStatus* PadStatus, int controllerID); -void WiiTASManipFunction(u8* data, WiimoteEmu::ReportFeatures rptf, int controllerID, int ext, - const wiimote_key key);