Skip to content

Commit

Permalink
xrEngine/pure.h: renamed CRegistrator to MessageRegistry
Browse files Browse the repository at this point in the history
Code update and cleanup
  • Loading branch information
Xottab-DUTY committed Apr 2, 2018
1 parent 21a9e92 commit 6cee0e7
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 90 deletions.
16 changes: 8 additions & 8 deletions src/xrEngine/Device_destroy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 9 additions & 9 deletions src/xrEngine/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ class ENGINE_API CRenderDeviceData

public:
// Registrators
CRegistrator<pureRender> seqRender;
CRegistrator<pureAppActivate> seqAppActivate;
CRegistrator<pureAppDeactivate> seqAppDeactivate;
CRegistrator<pureAppStart> seqAppStart;
CRegistrator<pureAppEnd> seqAppEnd;
CRegistrator<pureFrame> seqFrame;
CRegistrator<pureScreenResolutionChanged> seqResolutionChanged;
MessageRegistry<pureRender> seqRender;
MessageRegistry<pureAppActivate> seqAppActivate;
MessageRegistry<pureAppDeactivate> seqAppDeactivate;
MessageRegistry<pureAppStart> seqAppStart;
MessageRegistry<pureAppEnd> seqAppEnd;
MessageRegistry<pureFrame> seqFrame;
MessageRegistry<pureScreenResolutionChanged> seqResolutionChanged;

HWND m_hWnd;
};
Expand Down Expand Up @@ -197,8 +197,8 @@ class ENGINE_API CRenderDevice : public CRenderDeviceBase

void DumpResourcesMemoryUsage() { GEnv.Render->ResourcesDumpMemoryUsage(); }

CRegistrator<pureFrame> seqFrameMT;
CRegistrator<pureDeviceReset> seqDeviceReset;
MessageRegistry<pureFrame> seqFrameMT;
MessageRegistry<pureDeviceReset> seqDeviceReset;
xr_vector<fastdelegate::FastDelegate0<>> seqParallel;
CSecondVPParams m_SecondViewport; //--#SM+#-- +SecondVP+

Expand Down
9 changes: 0 additions & 9 deletions src/xrEngine/pure.cpp
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
128 changes: 64 additions & 64 deletions src/xrEngine/pure.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#pragma once
#ifndef _PURE_H_AAA_
#define _PURE_H_AAA_
#include "xrCommon/xr_vector.h"

// messages
Expand All @@ -10,16 +8,17 @@
#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; \
}

#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);
Expand All @@ -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 T>
class CRegistrator // the registrator itself
template<class T>
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<MessageObject> 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

0 comments on commit 6cee0e7

Please sign in to comment.