summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2017-04-03 05:39:48 -0400
committerLioncash <mathew1800@gmail.com>2017-04-03 06:34:36 -0400
commitc457ee499511f1cfd74f2cbb954f562ddba613a8 (patch)
tree874c952ef89bca1902d1374f0cd74ab04445e388 /Source/Core
parentee0e6fa09c085877ef1d0af5399278b0d10efcdb (diff)
Frame: Remove callback function prototypes from header
Gets rid of more direct usages of the main_frame global, keeping the callbacks internal to the frame itself.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/Core.cpp4
-rw-r--r--Source/Core/Core/Core.h2
-rw-r--r--Source/Core/Core/State.cpp10
-rw-r--r--Source/Core/Core/State.h5
-rw-r--r--Source/Core/DolphinWX/Frame.cpp40
-rw-r--r--Source/Core/DolphinWX/Frame.h4
6 files changed, 27 insertions, 38 deletions
diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp
index e268c66bfd..9a96bb5e1a 100644
--- a/Source/Core/Core/Core.cpp
+++ b/Source/Core/Core/Core.cpp
@@ -104,7 +104,7 @@ static Common::Flag s_is_booting;
static void* s_window_handle = nullptr;
static std::string s_state_filename;
static std::thread s_emu_thread;
-static StoppedCallbackFunc s_on_stopped_callback = nullptr;
+static StoppedCallbackFunc s_on_stopped_callback;
static std::thread s_cpu_thread;
static bool s_request_refresh_info = false;
@@ -938,7 +938,7 @@ void Shutdown()
void SetOnStoppedCallback(StoppedCallbackFunc callback)
{
- s_on_stopped_callback = callback;
+ s_on_stopped_callback = std::move(callback);
}
void UpdateWantDeterminism(bool initial)
diff --git a/Source/Core/Core/Core.h b/Source/Core/Core/Core.h
index ace543a153..ee8b6d6434 100644
--- a/Source/Core/Core/Core.h
+++ b/Source/Core/Core/Core.h
@@ -84,7 +84,7 @@ void UpdateTitle();
bool PauseAndLock(bool doLock, bool unpauseOnUnlock = true);
// for calling back into UI code without introducing a dependency on it in core
-typedef void (*StoppedCallbackFunc)(void);
+using StoppedCallbackFunc = std::function<void()>;
void SetOnStoppedCallback(StoppedCallbackFunc callback);
// Run on the Host thread when the factors change. [NOT THREADSAFE]
diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp
index 209afb1865..28d41b5961 100644
--- a/Source/Core/Core/State.cpp
+++ b/Source/Core/Core/State.cpp
@@ -57,7 +57,7 @@ static HEAP_ALLOC(wrkmem, LZO1X_1_MEM_COMPRESS);
static std::string g_last_filename;
-static CallbackFunc g_onAfterLoadCb = nullptr;
+static AfterLoadCallbackFunc s_on_after_load_callback;
// Temporary undo state buffer
static std::vector<u8> g_undo_load_buffer;
@@ -607,8 +607,8 @@ void LoadAs(const std::string& filename)
}
}
- if (g_onAfterLoadCb)
- g_onAfterLoadCb();
+ if (s_on_after_load_callback)
+ s_on_after_load_callback();
g_loadDepth--;
@@ -616,9 +616,9 @@ void LoadAs(const std::string& filename)
Core::PauseAndLock(false, wasUnpaused);
}
-void SetOnAfterLoadCallback(CallbackFunc callback)
+void SetOnAfterLoadCallback(AfterLoadCallbackFunc callback)
{
- g_onAfterLoadCb = callback;
+ s_on_after_load_callback = std::move(callback);
}
void VerifyAt(const std::string& filename)
diff --git a/Source/Core/Core/State.h b/Source/Core/Core/State.h
index 5818cd4830..de601e595c 100644
--- a/Source/Core/Core/State.h
+++ b/Source/Core/Core/State.h
@@ -6,6 +6,7 @@
#pragma once
+#include <functional>
#include <string>
#include <vector>
@@ -61,6 +62,6 @@ void UndoLoadState();
void Flush();
// for calling back into UI code without introducing a dependency on it in core
-typedef void (*CallbackFunc)(void);
-void SetOnAfterLoadCallback(CallbackFunc callback);
+using AfterLoadCallbackFunc = std::function<void()>;
+void SetOnAfterLoadCallback(AfterLoadCallbackFunc callback);
}
diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp
index 0675d4ad32..465eac734e 100644
--- a/Source/Core/DolphinWX/Frame.cpp
+++ b/Source/Core/DolphinWX/Frame.cpp
@@ -392,9 +392,7 @@ CFrame::CFrame(wxFrame* parent, wxWindowID id, const wxString& title, wxRect geo
m_LogWindow->Disable();
InitializeTASDialogs();
-
- State::SetOnAfterLoadCallback(OnAfterLoadCallback);
- Core::SetOnStoppedCallback(OnStoppedCallback);
+ InitializeCoreCallbacks();
// Setup perspectives
if (g_pCodeWindow)
@@ -515,6 +513,20 @@ void CFrame::InitializeTASDialogs()
});
}
+void CFrame::InitializeCoreCallbacks()
+{
+ // Warning: this gets called from the CPU thread, so we should
+ // only queue things to do on the proper thread
+ State::SetOnAfterLoadCallback([this] {
+ AddPendingEvent(wxCommandEvent{wxEVT_HOST_COMMAND, IDM_UPDATE_GUI});
+ });
+
+ // Warning: this gets called from the EmuThread
+ Core::SetOnStoppedCallback([this] {
+ AddPendingEvent(wxCommandEvent{wxEVT_HOST_COMMAND, IDM_STOPPED});
+ });
+}
+
bool CFrame::RendererIsFullscreen()
{
bool fullscreen = false;
@@ -1025,28 +1037,6 @@ static int GetMenuIDFromHotkey(unsigned int key)
return -1;
}
-void OnAfterLoadCallback()
-{
- // warning: this gets called from the CPU thread, so we should only queue things to do on the
- // proper thread
- if (main_frame)
- {
- wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATE_GUI);
- main_frame->GetEventHandler()->AddPendingEvent(event);
- }
-}
-
-void OnStoppedCallback()
-{
- // warning: this gets called from the EmuThread, so we should only queue things to do on the
- // proper thread
- if (main_frame)
- {
- wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_STOPPED);
- main_frame->GetEventHandler()->AddPendingEvent(event);
- }
-}
-
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 ea76cc360b..d3dddde38b 100644
--- a/Source/Core/DolphinWX/Frame.h
+++ b/Source/Core/DolphinWX/Frame.h
@@ -174,6 +174,7 @@ private:
wxMenuBar* CreateMenuBar() const;
void InitializeTASDialogs();
+ void InitializeCoreCallbacks();
// Utility
wxWindow* GetNotebookPageFromId(wxWindowID Id);
@@ -337,6 +338,3 @@ private:
// Event table
DECLARE_EVENT_TABLE();
};
-
-void OnAfterLoadCallback();
-void OnStoppedCallback();