Skip to content

Commit

Permalink
xrEngine/pure.h: refactor pure processing
Browse files Browse the repository at this point in the history
This gives increased debuggability
  • Loading branch information
Xottab-DUTY committed May 20, 2018
1 parent e2651d9 commit 3291f1a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 37 deletions.
6 changes: 5 additions & 1 deletion src/TypeHelper.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,9 @@

<Type Name="Shader">
<DisplayString>{cName.p_->value, s}, $(Type)</DisplayString>
</Type>
</Type>

<Type Name="MessageObject">
<DisplayString>{Object}</DisplayString>
</Type>
</AutoVisualizer>
4 changes: 2 additions & 2 deletions src/xrEngine/Device_destroy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ void CRenderDevice::Reset(bool precache)
// TODO: Remove this! It may hide crash
Memory.mem_compact();

seqDeviceReset.Process(rp_DeviceReset);
seqDeviceReset.Process();
if (dwWidth_before != dwWidth || dwHeight_before != dwHeight)
seqResolutionChanged.Process(rp_ScreenResolutionChanged);
seqResolutionChanged.Process();

if (!GEnv.isDedicatedServer)
pInput->ClipCursor(true);
Expand Down
3 changes: 0 additions & 3 deletions src/xrEngine/Stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
int g_ErrorLineCount = 15;
Flags32 g_stats_flags = {0};

// stats
DECLARE_RP(Stats);

class optimizer
{
float average_;
Expand Down
16 changes: 8 additions & 8 deletions src/xrEngine/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void CRenderDevice::RenderThreadProc(void* context)
renderTotalReal.Begin();
if (device.b_is_Active && device.Begin())
{
device.seqRender.Process(rp_Render);
device.seqRender.Process();
device.CalcFrameStats();
device.Statistic->Show();
device.End(); // Present goes here
Expand Down Expand Up @@ -162,7 +162,7 @@ void CRenderDevice::SecondaryThreadProc(void* context)
for (u32 pit = 0; pit < device.seqParallel.size(); pit++)
device.seqParallel[pit]();
device.seqParallel.clear();
device.seqFrameMT.Process(rp_Frame);
device.seqFrameMT.Process();
device.syncFrameDone.Set();
}
}
Expand Down Expand Up @@ -285,7 +285,7 @@ void CRenderDevice::on_idle()
renderTotalReal.Begin();
if (b_is_Active && Begin())
{
seqRender.Process(rp_Render);
seqRender.Process();
CalcFrameStats();
Statistic->Show();
End(); // Present goes here
Expand Down Expand Up @@ -364,13 +364,13 @@ void CRenderDevice::Run()
thread_spawn(SecondaryThreadProc, "X-RAY Secondary thread", 0, this);
//thread_spawn(RenderThreadProc, "X-RAY Render thread", 0, this);
// Message cycle
seqAppStart.Process(rp_AppStart);
seqAppStart.Process();
GEnv.Render->ClearTarget();
splash::hide();
ShowWindow(m_hWnd, SW_SHOWNORMAL);
pInput->ClipCursor(true);
message_loop();
seqAppEnd.Process(rp_AppEnd);
seqAppEnd.Process();
// Stop Balance-Thread
mt_bMustExit = TRUE;
//renderProcessFrame.Set();
Expand Down Expand Up @@ -428,7 +428,7 @@ void CRenderDevice::FrameMove()
stats.EngineTotal.Begin();
// TODO: HACK to test loading screen.
// if(!g_bLoaded)
Device.seqFrame.Process(rp_Frame);
Device.seqFrame.Process();
g_bLoaded = TRUE;
// else
// seqFrame.Process(rp_Frame);
Expand Down Expand Up @@ -506,13 +506,13 @@ void CRenderDevice::OnWM_Activate(WPARAM wParam, LPARAM /*lParam*/)
Device.b_is_Active = isGameActive;
if (Device.b_is_Active)
{
Device.seqAppActivate.Process(rp_AppActivate);
Device.seqAppActivate.Process();
app_inactive_time += TimerMM.GetElapsed_ms() - app_inactive_time_start;
}
else
{
app_inactive_time_start = TimerMM.GetElapsed_ms();
Device.seqAppDeactivate.Process(rp_AppDeactivate);
Device.seqAppDeactivate.Process();
}
}
}
Expand Down
10 changes: 0 additions & 10 deletions src/xrEngine/pure.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
#include "stdafx.h"
#include "pure.h"

DECLARE_RP(Frame);
DECLARE_RP(FrameEnd);
DECLARE_RP(Render);
DECLARE_RP(AppActivate);
DECLARE_RP(AppDeactivate);
DECLARE_RP(AppStart);
DECLARE_RP(AppEnd);
DECLARE_RP(DeviceReset);
DECLARE_RP(ScreenResolutionChanged);
29 changes: 16 additions & 13 deletions src/xrEngine/pure.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
#define REG_PRIORITY_CAPTURE 0x7ffffffful
#define REG_PRIORITY_INVALID 0xfffffffful

using MessageFunction = void __fastcall(void* obj);
#define DECLARE_MESSAGE(name) \
extern ENGINE_API MessageFunction rp_##name; \
struct ENGINE_API pure##name \
{ \
virtual void On##name() = 0; \
}
struct IPure
{
virtual ~IPure() = default;
virtual void OnPure() = 0;
};

#define DECLARE_RP(name) \
void __fastcall rp_##name(void* p) { ((pure##name*)p)->On##name(); }
#define DECLARE_MESSAGE(name)\
struct pure##name : IPure\
{\
virtual void On##name() = 0;\
private:\
void OnPure() override { On##name(); }\
};

DECLARE_MESSAGE(Frame); // XXX: rename to FrameStart
DECLARE_MESSAGE(FrameEnd);
Expand All @@ -31,7 +34,7 @@ DECLARE_MESSAGE(ScreenResolutionChanged);

struct MessageObject
{
void* Object;
IPure* Object;
int Prio;
u32 Flags;
};
Expand Down Expand Up @@ -91,20 +94,20 @@ class MessageRegistry
Resort();
}

void Process(MessageFunction* func)
void Process()
{
if (messages.empty())
return;

inProcess = true;

if (messages[0].Prio == REG_PRIORITY_CAPTURE)
func(messages[0].Object);
messages[0].Object->OnPure();
else
{
for (auto& message : messages)
if (message.Prio != REG_PRIORITY_INVALID)
func(message.Object);
message.Object->OnPure();
}

if (changed)
Expand Down

0 comments on commit 3291f1a

Please sign in to comment.