Skip to content

Commit 21a9e92

Browse files
committed
Move render stats to render thread
Refactor ECO_RENDER
1 parent 6a99c19 commit 21a9e92

File tree

2 files changed

+36
-45
lines changed

2 files changed

+36
-45
lines changed

src/Common/Config.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

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

2726
/* Tweaks: */

src/xrEngine/device.cpp

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,23 @@ void CRenderDevice::RenderThreadProc(void* context)
125125
return;
126126
}
127127

128-
device.seqRender.Process(rp_Render);
128+
if (!GEnv.isDedicatedServer)
129+
{
130+
// all rendering is done here
131+
CStatTimer renderTotalReal;
132+
renderTotalReal.FrameStart();
133+
renderTotalReal.Begin();
134+
if (device.b_is_Active && device.Begin())
135+
{
136+
device.seqRender.Process(rp_Render);
137+
device.CalcFrameStats();
138+
device.Statistic->Show();
139+
device.End(); // Present goes here
140+
}
141+
renderTotalReal.End();
142+
renderTotalReal.FrameEnd();
143+
device.stats.RenderTotal.accum = renderTotalReal.accum;
144+
}
129145
device.renderFrameDone.Set();
130146
}
131147
}
@@ -209,22 +225,26 @@ void CRenderDevice::on_idle()
209225
return;
210226
}
211227

212-
const auto FrameStartTime = TimerGlobal.GetElapsed_ms();
213-
214228
if (psDeviceFlags.test(rsStatistic))
215229
g_bEnableStatGather = TRUE; // XXX: why not use either rsStatistic or g_bEnableStatGather?
216230
else
217231
g_bEnableStatGather = FALSE;
232+
218233
if (g_loading_events.size())
219234
{
220235
if (g_loading_events.front()())
221236
g_loading_events.pop_front();
222237
pApp->LoadDraw();
223238
return;
224239
}
240+
241+
const auto frameStartTime = TimerGlobal.GetElapsed_ms();
242+
225243
if (!Device.dwPrecacheFrame && !g_SASH.IsBenchmarkRunning() && g_bLoaded)
226244
g_SASH.StartBenchmark();
245+
227246
FrameMove();
247+
228248
// Precache
229249
if (dwPrecacheFrame)
230250
{
@@ -244,51 +264,23 @@ void CRenderDevice::on_idle()
244264
mFullTransform_saved = mFullTransform;
245265
mView_saved = mView;
246266
mProject_saved = mProject;
247-
syncProcessFrame.Set(); // allow secondary thread to do its job
248267

249-
#ifdef ECO_RENDER // ECO_RENDER START
250-
static u32 time_frame = 0;
251-
u32 time_curr = timeGetTime();
252-
u32 time_diff = time_curr - time_frame;
253-
time_frame = time_curr;
254-
u32 optimal = 10;
255-
if (Device.Paused() || IGame_Persistent::IsMainMenuActive())
256-
optimal = 32;
257-
if (time_diff < optimal)
258-
Sleep(optimal - time_diff);
259-
#else
260-
Sleep(0);
261-
#endif // ECO_RENDER END
262-
263-
if (!GEnv.isDedicatedServer)
264-
{
265-
// all rendering is done here
266-
CStatTimer renderTotalReal;
267-
renderTotalReal.FrameStart();
268-
renderTotalReal.Begin();
269-
if (b_is_Active && Begin())
270-
{
271-
renderProcessFrame.Set(); // allow render thread to do its job
272-
renderFrameDone.Wait(); // wait until render thread finish its job
273-
CalcFrameStats();
274-
Statistic->Show();
275-
End(); // Present goes here
276-
}
277-
renderTotalReal.End();
278-
renderTotalReal.FrameEnd();
279-
stats.RenderTotal.accum = renderTotalReal.accum;
280-
}
268+
renderProcessFrame.Set(); // allow render thread to do its job
269+
syncProcessFrame.Set(); // allow secondary thread to do its job
281270

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

274+
// Eco render (by alpet)
275+
u32 updateDelta = 10;
284276
if (GEnv.isDedicatedServer)
285-
{
286-
const auto FrameEndTime = TimerGlobal.GetElapsed_ms();
287-
const auto FrameTime = (FrameEndTime - FrameStartTime);
288-
const auto DSUpdateDelta = 1000 / g_svDedicateServerUpdateReate;
289-
if (FrameTime < DSUpdateDelta)
290-
Sleep(DSUpdateDelta - FrameTime);
291-
}
277+
updateDelta = 1000 / g_svDedicateServerUpdateReate;
278+
279+
if (frameTime < updateDelta)
280+
Sleep(updateDelta - frameTime);
281+
282+
syncFrameDone.Wait(); // wait until secondary thread finish its job
283+
renderFrameDone.Wait(); // wait until render thread finish its job
292284

293285
if (!b_is_Active)
294286
Sleep(1);

0 commit comments

Comments
 (0)