MCPcopy Create free account
hub / github.com/OGSR/OGSR-Engine / End

Method End

ogsr_engine/Layers/xrRenderPC_R4/r4.cpp:924–1006  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

922}
923
924void CRender::End()
925{
926 r_main.sync();
927
928 // DoAsyncScreenshot();
929
930 R_ASSERT(HW.pDevice);
931
932 {
933 ZoneScopedN("Cleanup");
934
935 for (auto& id : contexts_pool)
936 {
937 id.cmd_list.OnFrameEnd();
938 }
939
940 cleanup_contexts();
941 }
942
943 {
944 ZoneScopedN("PresentWait");
945
946 HW.WaitOnSwapChain(); // wait for prev Present to finish. not sure that it is best place to wait, but it works
947 }
948
949 {
950 ZoneScopedN("fps_lock");
951
952 const auto now = std::chrono::high_resolution_clock::now();
953 static auto s_LastPresentTime = now;
954
955 constexpr long long menuFPSlimit{60ll}, pauseFPSlimit{60ll};
956 const long long curFPSLimit = IsMainMenuActive() ? menuFPSlimit : Device.Paused() ? pauseFPSlimit : g_dwFPSlimit;
957
958 if (curFPSLimit > 0ll)
959 {
960 const auto frameTime = std::chrono::duration_cast<std::chrono::microseconds>(now - s_LastPresentTime).count();
961 // конверсия лимита фпс в микросекунды
962 const auto targetFrameTime = 1000000ll / curFPSLimit;
963
964 if (frameTime < targetFrameTime)
965 {
966 // считаем сколько спать
967 const auto remainingTime = targetFrameTime - frameTime;
968 const auto sleepTime = remainingTime / 1000ll;
969
970 if (sleepTime > 2ll)
971 {
972 Sleep(static_cast<DWORD>(sleepTime - 2ll)); // поспать на 2мс меньше, чтоб не переспать
973 }
974
975 // spinwait оставшееся время
976 const auto spinWaitEnd = now + std::chrono::microseconds(targetFrameTime - frameTime);
977 while (std::chrono::high_resolution_clock::now() < spinWaitEnd)
978 {
979 YieldProcessor();
980 }
981 }

Callers 13

calculate_dynamicMethod · 0.45
occq_getMethod · 0.45
CalculateBonesMethod · 0.45
UpdateVisibleMMethod · 0.45
RenderMethod · 0.45
MT_CALCMethod · 0.45
RenderMethod · 0.45
EndQueryFunction · 0.45
CalculateMethod · 0.45
visibleMethod · 0.45
PIXEventsPushEventFunction · 0.45

Calls 8

IsMainMenuActiveFunction · 0.85
WaitOnSwapChainMethod · 0.80
PausedMethod · 0.80
syncMethod · 0.45
OnFrameEndMethod · 0.45
countMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected