From be7f316c50f4565e2ecb9cf14b14e0d29f8bc9fd Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 29 Feb 2016 13:37:53 -0500 Subject: [PATCH] Reduce usage of g_Instance --- input.cpp | 6 +++--- main.cpp | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/input.cpp b/input.cpp index e9ca6bc..616dc3a 100644 --- a/input.cpp +++ b/input.cpp @@ -30,7 +30,7 @@ void MoonlightInstance::DidLockMouse(int32_t result) { if (m_MouseLocked) { // Request an IDR frame to dump the frame queue that may have // built up from the GL pipeline being stalled. - g_Instance->m_RequestIdrFrame = true; + m_RequestIdrFrame = true; } } @@ -75,7 +75,7 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) { case PP_INPUTEVENT_TYPE_MOUSEDOWN: { // Lock the mouse cursor when the user clicks on the stream if (!m_MouseLocked) { - g_Instance->LockMouse(g_Instance->m_CallbackFactory.NewCallback(&MoonlightInstance::DidLockMouse)); + LockMouse(m_CallbackFactory.NewCallback(&MoonlightInstance::DidLockMouse)); // Assume it worked until we get a callback telling us otherwise m_MouseLocked = true; @@ -173,7 +173,7 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) { // Check if all modifiers are up now if (m_WaitingForAllModifiersUp && m_KeyModifiers == 0) { - g_Instance->UnlockMouse(); + UnlockMouse(); m_MouseLocked = false; m_WaitingForAllModifiersUp = false; } diff --git a/main.cpp b/main.cpp index 8631b7f..dd0fd3c 100644 --- a/main.cpp +++ b/main.cpp @@ -31,29 +31,30 @@ class MoonlightModule : public pp::Module { void MoonlightInstance::OnConnectionStarted(uint32_t unused) { // Tell the front end pp::Var response("Connection Established"); - g_Instance->PostMessage(response); + PostMessage(response); + // Start receiving input events - g_Instance->RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); - g_Instance->RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD); + RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); + RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD); } void MoonlightInstance::OnConnectionStopped(uint32_t error) { // Not running anymore - g_Instance->m_Running = false; + m_Running = false; // Stop receiving input events - g_Instance->ClearInputEventRequest(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD); + ClearInputEventRequest(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD); // Unlock the mouse - g_Instance->UnlockMouse(); + UnlockMouse(); // Join threads - pthread_join(g_Instance->m_ConnectionThread, NULL); - pthread_join(g_Instance->m_GamepadThread, NULL); + pthread_join(m_ConnectionThread, NULL); + pthread_join(m_GamepadThread, NULL); // Notify the JS code that the stream has ended pp::Var response(MSG_STREAM_TERMINATED); - g_Instance->PostMessage(response); + PostMessage(response); } void MoonlightInstance::StopConnection() {