diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index b0de9e3faa..9e4ef23607 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 s_gc_manip_func; +static WiiManipFunction s_wii_manip_func; // 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; + s_gc_manip_func = std::move(func); } void SetWiiInputManip(WiiManipFunction func) { - wiimfunc = func; + s_wii_manip_func = std::move(func); } // NOTE: CPU Thread void CallGCInputManip(GCPadStatus* PadStatus, int controllerID) { - if (gcmfunc) - (*gcmfunc)(PadStatus, controllerID); + if (s_gc_manip_func) + s_gc_manip_func(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); + if (s_wii_manip_func) + s_wii_manip_func(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..0675d4ad32 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -4,6 +4,7 @@ #include "DolphinWX/Frame.h" +#include #include #include #include @@ -47,6 +48,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 +391,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 +500,21 @@ void CFrame::BindEvents() Bind(DOLPHIN_EVT_STOP_SOFTWARE, &CFrame::OnStop, this); } +void CFrame::InitializeTASDialogs() +{ + std::generate(m_tas_input_dialogs.begin(), m_tas_input_dialogs.end(), + [this] { return new TASInputDlg{this}; }); + + Movie::SetGCInputManip([this](GCPadStatus* pad_status, int controller_id) { + m_tas_input_dialogs[controller_id]->GetValues(pad_status); + }); + + Movie::SetWiiInputManip([this](u8* data, WiimoteEmu::ReportFeatures rptf, int controller_id, + int ext, wiimote_key key) { + m_tas_input_dialogs[controller_id + 4]->GetValues(data, rptf, ext, key); + }); +} + bool CFrame::RendererIsFullscreen() { bool fullscreen = false; @@ -1034,21 +1047,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..ea76cc360b 100644 --- a/Source/Core/DolphinWX/Frame.h +++ b/Source/Core/DolphinWX/Frame.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -16,9 +17,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 +87,6 @@ public: CCodeWindow* g_pCodeWindow = nullptr; NetPlaySetupFrame* g_NetPlaySetupDiag = nullptr; wxCheatsWindow* g_CheatsWindow = nullptr; - TASInputDlg* g_TASInputDlg[8]; void DoStop(); void UpdateGUI(); @@ -140,6 +138,7 @@ private: CLogWindow* m_LogWindow = nullptr; LogConfigWindow* m_LogConfigWindow = nullptr; FifoPlayerDlg* m_FifoPlayerDlg = nullptr; + std::array m_tas_input_dialogs{}; bool UseDebugger = false; bool m_bBatchMode = false; bool m_bEdit = false; @@ -174,6 +173,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 +340,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); diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index 58986f4fe0..218556d739 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -369,17 +369,18 @@ void CFrame::OnTASInput(wxCommandEvent& event) if (SConfig::GetInstance().m_SIDevice[i] != SerialInterface::SIDEVICE_NONE && SConfig::GetInstance().m_SIDevice[i] != SerialInterface::SIDEVICE_GC_GBA) { - g_TASInputDlg[i]->CreateGCLayout(); - g_TASInputDlg[i]->Show(); - g_TASInputDlg[i]->SetTitle(wxString::Format(_("TAS Input - GameCube Controller %d"), i + 1)); + m_tas_input_dialogs[i]->CreateGCLayout(); + m_tas_input_dialogs[i]->Show(); + m_tas_input_dialogs[i]->SetTitle( + wxString::Format(_("TAS Input - GameCube Controller %d"), i + 1)); } if (g_wiimote_sources[i] == WIIMOTE_SRC_EMU && !(Core::IsRunning() && !SConfig::GetInstance().bWii)) { - g_TASInputDlg[i + 4]->CreateWiiLayout(i); - g_TASInputDlg[i + 4]->Show(); - g_TASInputDlg[i + 4]->SetTitle(wxString::Format(_("TAS Input - Wii Remote %d"), i + 1)); + m_tas_input_dialogs[i + 4]->CreateWiiLayout(i); + m_tas_input_dialogs[i + 4]->Show(); + m_tas_input_dialogs[i + 4]->SetTitle(wxString::Format(_("TAS Input - Wii Remote %d"), i + 1)); } } } diff --git a/Source/Core/DolphinWX/Input/InputConfigDiag.cpp b/Source/Core/DolphinWX/Input/InputConfigDiag.cpp index 6e3ca5bb1b..46673ac478 100644 --- a/Source/Core/DolphinWX/Input/InputConfigDiag.cpp +++ b/Source/Core/DolphinWX/Input/InputConfigDiag.cpp @@ -407,7 +407,7 @@ bool ControlDialog::Validate() UpdateGUI(); const auto parse_status = control_reference->GetParseStatus(); - return parse_status == ParseStatus::Success || parse_status == ParseStatus::NoDevice; + return parse_status == ParseStatus::Successful || parse_status == ParseStatus::NoDevice; } void InputConfigDialog::SetDevice(wxCommandEvent&) diff --git a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp index 0cb70970d0..d520015cf3 100644 --- a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp +++ b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp @@ -203,7 +203,7 @@ public: if (tok.type == TOK_EOF) break; } - return ParseStatus::Success; + return ParseStatus::Successful; } }; @@ -373,11 +373,11 @@ public: { ExpressionNode* node; ParseStatus status = Toplevel(&node); - if (status != ParseStatus::Success) + if (status != ParseStatus::Successful) return status; *expr_out = new Expression(node); - return ParseStatus::Success; + return ParseStatus::Successful; } private: @@ -409,7 +409,7 @@ private: } *expr_out = new ControlExpression(tok.qualifier, device, control); - return ParseStatus::Success; + return ParseStatus::Successful; } case TOK_LPAREN: return Paren(expr_out); @@ -439,7 +439,7 @@ private: if (status == ParseStatus::SyntaxError) return status; *expr_out = new UnaryExpression(tok.type, atom_expr); - return ParseStatus::Success; + return ParseStatus::Successful; } return Atom(expr_out); @@ -478,7 +478,7 @@ private: *expr_out = new BinaryExpression(tok.type, *expr_out, unary_expr); } - return ParseStatus::Success; + return ParseStatus::Successful; } ParseStatus Paren(ExpressionNode** expr_out) @@ -486,7 +486,7 @@ private: ParseStatus status; // lparen already chewed - if ((status = Toplevel(expr_out)) != ParseStatus::Success) + if ((status = Toplevel(expr_out)) != ParseStatus::Successful) return status; if (!Expects(TOK_RPAREN)) @@ -495,7 +495,7 @@ private: return ParseStatus::SyntaxError; } - return ParseStatus::Success; + return ParseStatus::Successful; } ParseStatus Toplevel(ExpressionNode** expr_out) { return Binary(expr_out); } @@ -530,21 +530,21 @@ static ParseStatus ParseExpressionInner(const std::string& str, ControlFinder& f *expr_out = nullptr; if (str == "") - return ParseStatus::Success; + return ParseStatus::Successful; Lexer l(str); std::vector tokens; status = l.Tokenize(tokens); - if (status != ParseStatus::Success) + if (status != ParseStatus::Successful) return status; Parser p(tokens, finder); status = p.Parse(&expr); - if (status != ParseStatus::Success) + if (status != ParseStatus::Successful) return status; *expr_out = expr; - return ParseStatus::Success; + return ParseStatus::Successful; } ParseStatus ParseExpression(const std::string& str, ControlFinder& finder, Expression** expr_out) @@ -561,7 +561,7 @@ ParseStatus ParseExpression(const std::string& str, ControlFinder& finder, Expre if (control) { *expr_out = new Expression(new ControlExpression(qualifier, device, control)); - return ParseStatus::Success; + return ParseStatus::Successful; } return ParseExpressionInner(str, finder, expr_out); diff --git a/Source/Core/InputCommon/ControlReference/ExpressionParser.h b/Source/Core/InputCommon/ControlReference/ExpressionParser.h index 2681c551fc..f07c9a1326 100644 --- a/Source/Core/InputCommon/ControlReference/ExpressionParser.h +++ b/Source/Core/InputCommon/ControlReference/ExpressionParser.h @@ -61,7 +61,7 @@ public: enum class ParseStatus { - Success, + Successful, SyntaxError, NoDevice, };