From 6cee0e7fc3ccebcb225e076886896056e4e5625f Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Mon, 2 Apr 2018 23:31:11 +0500 Subject: [PATCH] xrEngine/pure.h: renamed CRegistrator to MessageRegistry Code update and cleanup --- src/xrEngine/Device_destroy.cpp | 16 ++-- src/xrEngine/device.h | 18 ++--- src/xrEngine/pure.cpp | 9 --- src/xrEngine/pure.h | 128 ++++++++++++++++---------------- 4 files changed, 81 insertions(+), 90 deletions(-) diff --git a/src/xrEngine/Device_destroy.cpp b/src/xrEngine/Device_destroy.cpp index 3f0fbeb78ee..20f51650dc6 100644 --- a/src/xrEngine/Device_destroy.cpp +++ b/src/xrEngine/Device_destroy.cpp @@ -18,14 +18,14 @@ void CRenderDevice::Destroy() GEnv.Render->OnDeviceDestroy(false); Memory.mem_compact(); GEnv.Render->DestroyHW(); - seqRender.R.clear(); - seqAppActivate.R.clear(); - seqAppDeactivate.R.clear(); - seqAppStart.R.clear(); - seqAppEnd.R.clear(); - seqFrame.R.clear(); - seqFrameMT.R.clear(); - seqDeviceReset.R.clear(); + seqRender.Clear(); + seqAppActivate.Clear(); + seqAppDeactivate.Clear(); + seqAppStart.Clear(); + seqAppEnd.Clear(); + seqFrame.Clear(); + seqFrameMT.Clear(); + seqDeviceReset.Clear(); seqParallel.clear(); xr_delete(Statistic); } diff --git a/src/xrEngine/device.h b/src/xrEngine/device.h index ace296f5f0c..906eb060e4b 100644 --- a/src/xrEngine/device.h +++ b/src/xrEngine/device.h @@ -107,13 +107,13 @@ class ENGINE_API CRenderDeviceData public: // Registrators - CRegistrator seqRender; - CRegistrator seqAppActivate; - CRegistrator seqAppDeactivate; - CRegistrator seqAppStart; - CRegistrator seqAppEnd; - CRegistrator seqFrame; - CRegistrator seqResolutionChanged; + MessageRegistry seqRender; + MessageRegistry seqAppActivate; + MessageRegistry seqAppDeactivate; + MessageRegistry seqAppStart; + MessageRegistry seqAppEnd; + MessageRegistry seqFrame; + MessageRegistry seqResolutionChanged; HWND m_hWnd; }; @@ -197,8 +197,8 @@ class ENGINE_API CRenderDevice : public CRenderDeviceBase void DumpResourcesMemoryUsage() { GEnv.Render->ResourcesDumpMemoryUsage(); } - CRegistrator seqFrameMT; - CRegistrator seqDeviceReset; + MessageRegistry seqFrameMT; + MessageRegistry seqDeviceReset; xr_vector> seqParallel; CSecondVPParams m_SecondViewport; //--#SM+#-- +SecondVP+ diff --git a/src/xrEngine/pure.cpp b/src/xrEngine/pure.cpp index e645d0a9dbe..e479a398644 100644 --- a/src/xrEngine/pure.cpp +++ b/src/xrEngine/pure.cpp @@ -1,15 +1,6 @@ #include "stdafx.h" -#pragma hdrstop - #include "pure.h" -// ENGINE_API int __cdecl _REG_Compare(const void *e1, const void *e2) -//{ -// _REG_INFO *p1 = (_REG_INFO *)e1; -// _REG_INFO *p2 = (_REG_INFO *)e2; -// return (p2->Prio - p1->Prio); -//} - DECLARE_RP(Frame); DECLARE_RP(FrameEnd); DECLARE_RP(Render); diff --git a/src/xrEngine/pure.h b/src/xrEngine/pure.h index 81a10a20e91..1e2dedc09bb 100644 --- a/src/xrEngine/pure.h +++ b/src/xrEngine/pure.h @@ -1,6 +1,4 @@ #pragma once -#ifndef _PURE_H_AAA_ -#define _PURE_H_AAA_ #include "xrCommon/xr_vector.h" // messages @@ -10,9 +8,9 @@ #define REG_PRIORITY_CAPTURE 0x7ffffffful #define REG_PRIORITY_INVALID 0xfffffffful -typedef void __fastcall RP_FUNC(void* obj); +using MessageFunction = void __fastcall(void* obj); #define DECLARE_MESSAGE(name) \ - extern ENGINE_API RP_FUNC rp_##name; \ + extern ENGINE_API MessageFunction rp_##name; \ struct ENGINE_API pure##name \ { \ virtual void On##name() = 0; \ @@ -20,6 +18,7 @@ typedef void __fastcall RP_FUNC(void* obj); #define DECLARE_RP(name) \ void __fastcall rp_##name(void* p) { ((pure##name*)p)->On##name(); } + DECLARE_MESSAGE(Frame); // XXX: rename to FrameStart DECLARE_MESSAGE(FrameEnd); DECLARE_MESSAGE(Render); @@ -30,100 +29,101 @@ DECLARE_MESSAGE(AppEnd); DECLARE_MESSAGE(DeviceReset); DECLARE_MESSAGE(ScreenResolutionChanged); -//----------------------------------------------------------------------------- -struct _REG_INFO +struct MessageObject { void* Object; int Prio; u32 Flags; }; -// ENGINE_API extern int __cdecl _REG_Compare(const void *, const void *); - -template -class CRegistrator // the registrator itself +template +class MessageRegistry { - // friend ENGINE_API int __cdecl _REG_Compare(const void *, const void *); - static int __cdecl _REG_Compare(const void* e1, const void* e2) + bool changed, inProcess; + xr_vector messages; + + static int __cdecl compare(const void* e1, const void* e2) { - _REG_INFO* p1 = (_REG_INFO*)e1; - _REG_INFO* p2 = (_REG_INFO*)e2; - return (p2->Prio - p1->Prio); + MessageObject* p1 = (MessageObject*)e1; + MessageObject* p2 = (MessageObject*)e2; + return p2->Prio - p1->Prio; } public: - xr_vector<_REG_INFO> R; - // constructor - struct - { - u32 in_process : 1; - u32 changed : 1; - }; - CRegistrator() + MessageRegistry() : changed(false), inProcess(false) {} + + void Clear() { messages.clear(); } + + void Add(T* object, const int priority = REG_PRIORITY_NORMAL, const u32 flags = 0) { - in_process = false; - changed = false; + Add({ object, priority, flags }); } - // - void Add(T* obj, int priority = REG_PRIORITY_NORMAL, u32 flags = 0) + void Add(MessageObject newMessage) { #ifdef DEBUG - VERIFY(priority != REG_PRIORITY_INVALID); - VERIFY(obj); - for (u32 i = 0; i < R.size(); i++) - VERIFY(!((R[i].Prio != REG_PRIORITY_INVALID) && (R[i].Object == (void*)obj))); + VERIFY(newMessage.Object); + VERIFY(newMessage.Prio != REG_PRIORITY_INVALID); + + // Verify that we don't already have the same object with valid priority + for (auto& message : messages) + VERIFY(!(message.Prio != REG_PRIORITY_INVALID && message.Object == newMessage.Object)); #endif - _REG_INFO I; - I.Object = obj; - I.Prio = priority; - I.Flags = flags; - R.push_back(I); + messages.emplace_back(newMessage); - if (in_process) + if (inProcess) changed = true; else Resort(); - }; - void Remove(T* obj) + } + + void Remove(T* object) { - for (u32 i = 0; i < R.size(); i++) + for (auto& it : messages) { - if (R[i].Object == obj) - R[i].Prio = REG_PRIORITY_INVALID; + if (it.Object == object) + it.Prio = REG_PRIORITY_INVALID; } - if (in_process) + + if (inProcess) changed = true; else Resort(); - }; - void Process(RP_FUNC* f) + } + + void Process(MessageFunction* func) { - in_process = true; - if (R.empty()) + if (messages.empty()) return; - if (R[0].Prio == REG_PRIORITY_CAPTURE) - f(R[0].Object); + + inProcess = true; + + if (messages[0].Prio == REG_PRIORITY_CAPTURE) + func(messages[0].Object); else { - for (u32 i = 0; i < R.size(); i++) - if (R[i].Prio != REG_PRIORITY_INVALID) - f(R[i].Object); + for (auto& message : messages) + if (message.Prio != REG_PRIORITY_INVALID) + func(message.Object); } + if (changed) Resort(); - in_process = false; - }; - void Resort(void) + + inProcess = false; + } + + void Resort() { - if (R.size()) - qsort(&*R.begin(), R.size(), sizeof(_REG_INFO), _REG_Compare); - while ((R.size()) && (R[R.size() - 1].Prio == REG_PRIORITY_INVALID)) - R.pop_back(); - if (R.empty()) - R.clear(); + if (!messages.empty()) + qsort(&messages.front(), messages.size(), sizeof(MessageObject), compare); + + while (!messages.empty() && messages.back().Prio == REG_PRIORITY_INVALID) + messages.pop_back(); + + if (messages.empty()) + messages.clear(); + changed = false; - }; + } }; - -#endif