[Renderer] Implement single backend frame handler

This commit is contained in:
momo5502 2017-06-22 22:05:22 +02:00
parent f1ed2f4cab
commit 51ca49ad83
3 changed files with 29 additions and 2 deletions

View File

@ -3,6 +3,7 @@
namespace Components
{
Utils::Signal<Renderer::BackendCallback> Renderer::BackendFrameSignal;
Utils::Signal<Renderer::BackendCallback> Renderer::SingleBackendFrameSignal;
Utils::Signal<Scheduler::Callback> Renderer::EndRecoverDeviceSignal;
Utils::Signal<Scheduler::Callback> Renderer::BeginRecoverDeviceSignal;
@ -41,11 +42,22 @@ namespace Components
if (device)
{
device->AddRef();
Renderer::BackendFrameSignal(device);
Utils::Signal<Renderer::BackendCallback> copy(Renderer::SingleBackendFrameSignal);
Renderer::SingleBackendFrameSignal.clear();
copy(device);
device->Release();
}
}
void Renderer::OnNextBackendFrame(Utils::Slot<Renderer::BackendCallback> callback)
{
Renderer::SingleBackendFrameSignal.connect(callback);
}
void Renderer::OnBackendFrame(Utils::Slot<Renderer::BackendCallback> callback)
{
Renderer::BackendFrameSignal.connect(callback);
@ -63,12 +75,12 @@ namespace Components
int Renderer::Width()
{
return Utils::Hook::Get<int>(0x66E1C68);
return reinterpret_cast<LPPOINT>(0x66E1C68)->x;
}
int Renderer::Height()
{
return Utils::Hook::Get<int>(0x66E1C6C);
return reinterpret_cast<LPPOINT>(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();

View File

@ -14,6 +14,7 @@ namespace Components
static int Height();
static void OnBackendFrame(Utils::Slot<BackendCallback> callback);
static void OnNextBackendFrame(Utils::Slot<BackendCallback> callback);
static void OnDeviceRecoveryEnd(Utils::Slot<Scheduler::Callback> callback);
static void OnDeviceRecoveryBegin(Utils::Slot<Scheduler::Callback> callback);
@ -32,5 +33,6 @@ namespace Components
static Utils::Signal<Scheduler::Callback> BeginRecoverDeviceSignal;
static Utils::Signal<BackendCallback> BackendFrameSignal;
static Utils::Signal<BackendCallback> SingleBackendFrameSignal;
};
}

View File

@ -68,16 +68,23 @@ namespace Utils
public:
Signal()
{
std::lock_guard<std::recursive_mutex> _(this->mutex);
this->slots.clear();
}
Signal(Signal& obj) : Signal()
{
std::lock_guard<std::recursive_mutex> _(this->mutex);
std::lock_guard<std::recursive_mutex> __(obj.mutex);
Utils::Merge(&this->slots, obj.getSlots());
}
void connect(Slot<T> slot)
{
std::lock_guard<std::recursive_mutex> _(this->mutex);
if (slot)
{
this->slots.push_back(slot);
@ -86,6 +93,8 @@ namespace Utils
void clear()
{
std::lock_guard<std::recursive_mutex> _(this->mutex);
this->slots.clear();
}
@ -97,6 +106,8 @@ namespace Utils
template <class ...Args>
void operator()(Args&&... args) const
{
std::lock_guard<std::recursive_mutex> _(this->mutex);
std::vector<Slot<T>> copiedSlots;
Utils::Merge(&copiedSlots, this->slots);
@ -110,6 +121,7 @@ namespace Utils
}
private:
mutable std::recursive_mutex mutex;
std::vector<Slot<T>> slots;
};
}