From 51ca49ad8345a35fd0ecbfd461a80481a659738e Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 22 Jun 2017 22:05:22 +0200 Subject: [PATCH] [Renderer] Implement single backend frame handler --- src/Components/Modules/Renderer.cpp | 17 +++++++++++++++-- src/Components/Modules/Renderer.hpp | 2 ++ src/Utils/Utils.hpp | 12 ++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Components/Modules/Renderer.cpp b/src/Components/Modules/Renderer.cpp index 4a373e5b..7002e193 100644 --- a/src/Components/Modules/Renderer.cpp +++ b/src/Components/Modules/Renderer.cpp @@ -3,6 +3,7 @@ namespace Components { Utils::Signal Renderer::BackendFrameSignal; + Utils::Signal Renderer::SingleBackendFrameSignal; Utils::Signal Renderer::EndRecoverDeviceSignal; Utils::Signal Renderer::BeginRecoverDeviceSignal; @@ -41,11 +42,22 @@ namespace Components if (device) { device->AddRef(); + Renderer::BackendFrameSignal(device); + + Utils::Signal copy(Renderer::SingleBackendFrameSignal); + Renderer::SingleBackendFrameSignal.clear(); + copy(device); + device->Release(); } } + void Renderer::OnNextBackendFrame(Utils::Slot callback) + { + Renderer::SingleBackendFrameSignal.connect(callback); + } + void Renderer::OnBackendFrame(Utils::Slot callback) { Renderer::BackendFrameSignal.connect(callback); @@ -63,12 +75,12 @@ namespace Components int Renderer::Width() { - return Utils::Hook::Get(0x66E1C68); + return reinterpret_cast(0x66E1C68)->x; } int Renderer::Height() { - return Utils::Hook::Get(0x66E1C6C); + return reinterpret_cast(0x66E1C68)->y; } void Renderer::PreVidRestart() @@ -155,6 +167,7 @@ namespace Components Renderer::~Renderer() { Renderer::BackendFrameSignal.clear(); + Renderer::SingleBackendFrameSignal.clear(); Renderer::EndRecoverDeviceSignal.clear(); Renderer::BeginRecoverDeviceSignal.clear(); diff --git a/src/Components/Modules/Renderer.hpp b/src/Components/Modules/Renderer.hpp index 50b8c338..070f9381 100644 --- a/src/Components/Modules/Renderer.hpp +++ b/src/Components/Modules/Renderer.hpp @@ -14,6 +14,7 @@ namespace Components static int Height(); static void OnBackendFrame(Utils::Slot callback); + static void OnNextBackendFrame(Utils::Slot callback); static void OnDeviceRecoveryEnd(Utils::Slot callback); static void OnDeviceRecoveryBegin(Utils::Slot callback); @@ -32,5 +33,6 @@ namespace Components static Utils::Signal BeginRecoverDeviceSignal; static Utils::Signal BackendFrameSignal; + static Utils::Signal SingleBackendFrameSignal; }; } diff --git a/src/Utils/Utils.hpp b/src/Utils/Utils.hpp index 065f607d..afcb1a0b 100644 --- a/src/Utils/Utils.hpp +++ b/src/Utils/Utils.hpp @@ -68,16 +68,23 @@ namespace Utils public: Signal() { + std::lock_guard _(this->mutex); + this->slots.clear(); } Signal(Signal& obj) : Signal() { + std::lock_guard _(this->mutex); + std::lock_guard __(obj.mutex); + Utils::Merge(&this->slots, obj.getSlots()); } void connect(Slot slot) { + std::lock_guard _(this->mutex); + if (slot) { this->slots.push_back(slot); @@ -86,6 +93,8 @@ namespace Utils void clear() { + std::lock_guard _(this->mutex); + this->slots.clear(); } @@ -97,6 +106,8 @@ namespace Utils template void operator()(Args&&... args) const { + std::lock_guard _(this->mutex); + std::vector> copiedSlots; Utils::Merge(&copiedSlots, this->slots); @@ -110,6 +121,7 @@ namespace Utils } private: + mutable std::recursive_mutex mutex; std::vector> slots; }; }