Skip to content

Commit

Permalink
Move render stats to render thread
Browse files Browse the repository at this point in the history
Refactor ECO_RENDER
  • Loading branch information
Xottab-DUTY committed Apr 1, 2018
1 parent 6a99c19 commit 21a9e92
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 45 deletions.
1 change: 0 additions & 1 deletion src/Common/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

/* Visual */
#define DETAIL_RADIUS // detail draw radius (by K.D.)
#define ECO_RENDER // limit FPS in menu to prevent video card overheat (by alpet)
#define TREE_WIND_EFFECT // configurable tree sway, can be used to have trees sway more during storms or lightly on clear days.

/* Tweaks: */
Expand Down
80 changes: 36 additions & 44 deletions src/xrEngine/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,23 @@ void CRenderDevice::RenderThreadProc(void* context)
return;
}

device.seqRender.Process(rp_Render);
if (!GEnv.isDedicatedServer)
{
// all rendering is done here
CStatTimer renderTotalReal;
renderTotalReal.FrameStart();
renderTotalReal.Begin();
if (device.b_is_Active && device.Begin())
{
device.seqRender.Process(rp_Render);
device.CalcFrameStats();
device.Statistic->Show();
device.End(); // Present goes here
}
renderTotalReal.End();
renderTotalReal.FrameEnd();
device.stats.RenderTotal.accum = renderTotalReal.accum;
}
device.renderFrameDone.Set();
}
}
Expand Down Expand Up @@ -209,22 +225,26 @@ void CRenderDevice::on_idle()
return;
}

const auto FrameStartTime = TimerGlobal.GetElapsed_ms();

if (psDeviceFlags.test(rsStatistic))
g_bEnableStatGather = TRUE; // XXX: why not use either rsStatistic or g_bEnableStatGather?
else
g_bEnableStatGather = FALSE;

if (g_loading_events.size())
{
if (g_loading_events.front()())
g_loading_events.pop_front();
pApp->LoadDraw();
return;
}

const auto frameStartTime = TimerGlobal.GetElapsed_ms();

if (!Device.dwPrecacheFrame && !g_SASH.IsBenchmarkRunning() && g_bLoaded)
g_SASH.StartBenchmark();

FrameMove();

// Precache
if (dwPrecacheFrame)
{
Expand All @@ -244,51 +264,23 @@ void CRenderDevice::on_idle()
mFullTransform_saved = mFullTransform;
mView_saved = mView;
mProject_saved = mProject;
syncProcessFrame.Set(); // allow secondary thread to do its job

#ifdef ECO_RENDER // ECO_RENDER START
static u32 time_frame = 0;
u32 time_curr = timeGetTime();
u32 time_diff = time_curr - time_frame;
time_frame = time_curr;
u32 optimal = 10;
if (Device.Paused() || IGame_Persistent::IsMainMenuActive())
optimal = 32;
if (time_diff < optimal)
Sleep(optimal - time_diff);
#else
Sleep(0);
#endif // ECO_RENDER END

if (!GEnv.isDedicatedServer)
{
// all rendering is done here
CStatTimer renderTotalReal;
renderTotalReal.FrameStart();
renderTotalReal.Begin();
if (b_is_Active && Begin())
{
renderProcessFrame.Set(); // allow render thread to do its job
renderFrameDone.Wait(); // wait until render thread finish its job
CalcFrameStats();
Statistic->Show();
End(); // Present goes here
}
renderTotalReal.End();
renderTotalReal.FrameEnd();
stats.RenderTotal.accum = renderTotalReal.accum;
}
renderProcessFrame.Set(); // allow render thread to do its job
syncProcessFrame.Set(); // allow secondary thread to do its job

syncFrameDone.Wait(); // wait until secondary thread finish its job
const auto frameEndTime = TimerGlobal.GetElapsed_ms();
const auto frameTime = frameEndTime - frameStartTime;

// Eco render (by alpet)
u32 updateDelta = 10;
if (GEnv.isDedicatedServer)
{
const auto FrameEndTime = TimerGlobal.GetElapsed_ms();
const auto FrameTime = (FrameEndTime - FrameStartTime);
const auto DSUpdateDelta = 1000 / g_svDedicateServerUpdateReate;
if (FrameTime < DSUpdateDelta)
Sleep(DSUpdateDelta - FrameTime);
}
updateDelta = 1000 / g_svDedicateServerUpdateReate;

if (frameTime < updateDelta)
Sleep(updateDelta - frameTime);

syncFrameDone.Wait(); // wait until secondary thread finish its job
renderFrameDone.Wait(); // wait until render thread finish its job

if (!b_is_Active)
Sleep(1);
Expand Down

0 comments on commit 21a9e92

Please sign in to comment.