diff options
author | mobserveur <mobserveur@gmail.com> | 2024-06-15 14:43:01 +0200 |
---|---|---|
committer | mobserveur <mobserveur@gmail.com> | 2024-06-15 14:43:01 +0200 |
commit | 4f4ad7dfcaeefd8bdaa59da57e54f9a30e04ad9e (patch) | |
tree | 0c0feb93d641250fc677b841708d82cd88fa3287 | |
parent | 8c527302b9724195d3ee7390856462922e9aaa80 (diff) |
added fps limiter
added an fps limiter, set by the MaxFPS debug setting
-rw-r--r-- | indra/newview/llappviewer.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index b3c2f3c108..326ffa917a 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -389,6 +389,8 @@ static std::string gLaunchFileOnQuit; // Used on Win32 for other apps to identify our window (eg, win_setup) const char* const VIEWER_WINDOW_CLASSNAME = "Second Life"; +U64 fpsLimitSleepUntil = 0; // fps limiter : time until to render the frame again + //---------------------------------------------------------------------------- // List of entries from strings.xml to always replace @@ -1363,6 +1365,22 @@ bool LLAppViewer::frame() bool LLAppViewer::doFrame() { + + // FPS Limit + + U64 fpsLimitNow = LLTrace::BlockTimer::getCPUClockCount64(); + U64 fpsLimitFrameStartTime = fpsLimitNow; + if(fpsLimitSleepUntil > 0) + { + if(fpsLimitSleepUntil > fpsLimitNow) return 0; + } + else + { + fpsLimitSleepUntil = 0; + } + + + LL_RECORD_BLOCK_TIME(FTM_FRAME); { // and now adjust the visuals from previous frame. @@ -1533,6 +1551,24 @@ bool LLAppViewer::doFrame() } } + // fps limiter + + fpsLimitNow = LLTrace::BlockTimer::getCPUClockCount64(); + U64 fpsLimitFrameTime = fpsLimitNow - fpsLimitFrameStartTime; + static LLCachedControl<U32> fpsLimitMaxFps(gSavedSettings, "MaxFPS", 0); + + if(fpsLimitMaxFps > 0) + { + U64 desired_time_ns = (U32)(1000000.f / fpsLimitMaxFps); + + if(fpsLimitFrameTime < desired_time_ns) + { + U64 fpsLimitSleepUntil_for = desired_time_ns - fpsLimitFrameTime; + fpsLimitSleepUntil = LLTrace::BlockTimer::getCPUClockCount64() + fpsLimitSleepUntil_for; + } + } + + { LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df pauseMainloopTimeout" ) pingMainloopTimeout("Main:Sleep"); |