1010 *****************************************************************************/
1111
1212#include " StdInc.h"
13+ #include < SharedUtil.Misc.h>
1314#include " CModManager.h"
1415#define DECLARE_PROFILER_SECTION_CModManager
1516#include " profiler/SharedUtil.Profiler.h"
@@ -55,30 +56,39 @@ bool CModManager::TriggerCommand(const char* commandName, size_t commandNameLeng
5556
5657void CModManager::DoPulsePreFrame ()
5758{
59+ TIMING_GRAPH (" +DoPulsePreFrame" );
60+ CCore::GetSingleton ().GetFPSLimiter ()->OnFrameStart (); // Prepare FPS limiting for this frame
61+
5862 if (m_client)
5963 {
6064 m_client->PreFrameExecutionHandler ();
6165 }
66+ TIMING_GRAPH (" -DoPulsePreFrame" );
6267}
6368
6469void CModManager::DoPulsePreHUDRender (bool bDidUnminimize, bool bDidRecreateRenderTargets)
6570{
71+ TIMING_GRAPH (" +DoPulsePreHUDRender" );
6672 if (m_client)
6773 {
6874 m_client->PreHUDRenderExecutionHandler (bDidUnminimize, bDidRecreateRenderTargets);
6975 }
76+ TIMING_GRAPH (" -DoPulsePreHUDRender" );
7077}
7178
7279void CModManager::DoPulsePostFrame ()
7380{
74- if (m_state == State::PendingStart)
75- {
76- Start ();
77- }
78- else if (m_state == State::PendingStop)
81+ auto handleStateChange = [&]()
7982 {
80- Stop ();
81- }
83+ if (m_state == State::PendingStart)
84+ Start ();
85+ else if (m_state == State::PendingStop)
86+ Stop ();
87+ };
88+
89+ TIMING_GRAPH (" +DoPulsePostFrame" );
90+
91+ handleStateChange (); // Handle state changes before pulse
8292
8393 if (m_client)
8494 {
@@ -89,20 +99,15 @@ void CModManager::DoPulsePostFrame()
8999 CCore::GetSingleton ().GetNetwork ()->DoPulse ();
90100 }
91101
92- // Make sure frame rate limit gets applied
93- if (m_client != nullptr )
94- CCore::GetSingleton ().EnsureFrameRateLimitApplied (); // Catch missed frames
95- else
96- CCore::GetSingleton ().ApplyFrameRateLimit (); // Limit when not connected
102+ CCore::GetSingleton ().DoReliablePulse (); // Do reliable pulse
97103
98- if (m_state == State::PendingStart)
99- {
100- Start ();
101- }
102- else if (m_state == State::PendingStop)
103- {
104- Stop ();
105- }
104+ handleStateChange (); // Handle state changes after pulse
105+
106+ // TODO: ENSURE "CModManager::DoPulsePostFrame" IS THE LAST THING BEFORE THE FRAME ENDS
107+ CCore::GetSingleton ().GetFPSLimiter ()->OnFrameEnd (); // Apply FPS limiting
108+
109+ TIMING_GRAPH (" -DoPulsePostFrame" );
110+ TIMING_GRAPH (" " );
106111}
107112
108113bool CModManager::Load (const char * arguments)
@@ -182,16 +187,16 @@ bool CModManager::TryStart()
182187 return false ;
183188 }
184189
185- CClientBase*(__cdecl * InitClient)() = reinterpret_cast < decltype (InitClient)>( GetProcAddress (library, " InitClient " ) );
186-
187- if (InitClient == nullptr )
190+ using InitClientFn = CClientBase* (__cdecl*)( );
191+ InitClientFn initClient = nullptr ;
192+ if (! SharedUtil::TryGetProcAddress (library, " InitClient" , initClient) )
188193 {
189194 CCore::GetSingleton ().GetConsole ()->Printf (" Unable to initialize deathmatch's DLL (missing init)" );
190195 FreeLibrary (library);
191196 return false ;
192197 }
193198
194- CClientBase* client = InitClient ();
199+ CClientBase* client = initClient ();
195200
196201 if (client == nullptr || client->ClientInitialize (m_arguments.c_str (), CCore::GetSingletonPtr ()) != 0 )
197202 {
@@ -283,3 +288,4 @@ void CModManager::TryStop()
283288 CLocalGUI::GetSingleton ().GetMainMenu ()->SetIsIngame (false );
284289 CLocalGUI::GetSingleton ().GetMainMenu ()->SetVisible (true , false );
285290}
291+
0 commit comments