Skip to content

Commit

Permalink
ECO RENDER
Browse files Browse the repository at this point in the history
ECO RENDER rip from KD/alpet SOC repo:

https://xp-dev.com/sc/change/204486/122

Caps intro video (200 fps) and main menu (60 fps) FPS to avoid video
card coil noise/overheating.
  • Loading branch information
Bangalore1010 authored and Xottab-DUTY committed Aug 18, 2017
1 parent 294d821 commit a06ab10
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Common/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
//#define KEY_HOLD_CALLBACK // expose key hold callback to scripts (configure in bind_stalker)
//#define FP_DEATH // first person death view
#define DETAIL_RADIUS // detail draw radius (by K.D.)
#define ECO_RENDER //ECO_RENDER adds a small delay between rendering, reduce FPS in main menu or in videos
10 changes: 6 additions & 4 deletions src/Layers/xrRender/HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ CHW HW;
IDirect3DStateBlock9* dwDebugSB = nullptr;
#endif

CHW::CHW() : hD3D(nullptr), pD3D(nullptr), pDevice(nullptr), pBaseRT(nullptr), pBaseZB(nullptr), m_move_window(true) { ; }
CHW::~CHW() { ; }
CHW::CHW() : hD3D(nullptr), pD3D(nullptr), pDevice(nullptr), pBaseRT(nullptr), pBaseZB(nullptr), m_move_window(true), maxRefreshRate(200)/*ECO_RENDER*/ {}
CHW::~CHW() {}
void CHW::Reset(HWND hwnd)
{
#ifdef DEBUG
Expand Down Expand Up @@ -504,8 +504,10 @@ u32 CHW::selectRefresh(u32 dwWidth, u32 dwHeight, D3DFORMAT fmt)
pD3D->EnumAdapterModes(DevAdapter, fmt, I, &Mode);
if (Mode.Width == dwWidth && Mode.Height == dwHeight)
{
if (Mode.RefreshRate > selected)
selected = Mode.RefreshRate;
//if (Mode.RefreshRate > selected)
// selected = Mode.RefreshRate;
if (Mode.RefreshRate <= maxRefreshRate && Mode.RefreshRate>selected)
selected = Mode.RefreshRate; //ECO_RENDER modif.
}
}
return selected;
Expand Down
2 changes: 2 additions & 0 deletions src/Layers/xrRender/HW.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class CHW
virtual void OnAppDeactivate();
#endif // USE_DX10

int maxRefreshRate; //ECO_RENDER add

private:
bool m_move_window;
};
Expand Down
6 changes: 6 additions & 0 deletions src/xrEngine/IGame_Persistent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ bool g_dedicated_server = false;

ENGINE_API IGame_Persistent* g_pGamePersistent = nullptr;

//ECO_RENDER add
bool IGame_Persistent::IsMainMenuActive()
{
return g_pGamePersistent && g_pGamePersistent->m_pMainMenu && g_pGamePersistent->m_pMainMenu->IsActive();
}

IGame_Persistent::IGame_Persistent()
{
RDEVICE.seqAppStart.Add(this);
Expand Down
1 change: 1 addition & 0 deletions src/xrEngine/IGame_Persistent.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class ENGINE_API IGame_Persistent :
void Prefetch();
#endif
IMainMenu* m_pMainMenu;
static bool IsMainMenuActive();

ParticleStatistics stats;

Expand Down
15 changes: 15 additions & 0 deletions src/xrEngine/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "IGame_Persistent.h"
#include "xrScriptEngine/ScriptExporter.hpp"

#include "Common/Config.hpp"

ENGINE_API CRenderDevice Device;
ENGINE_API CLoadScreenRenderer load_screen_renderer;

Expand Down Expand Up @@ -231,7 +233,20 @@ void CRenderDevice::on_idle()
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

#ifndef DEDICATED_SERVER
// all rendering is done here
Expand Down

0 comments on commit a06ab10

Please sign in to comment.