10
10
*****************************************************************************/
11
11
12
12
#include " StdInc.h"
13
+ #include < SharedUtil.Misc.h>
13
14
#include " CModManager.h"
14
15
#define DECLARE_PROFILER_SECTION_CModManager
15
16
#include " profiler/SharedUtil.Profiler.h"
@@ -55,30 +56,39 @@ bool CModManager::TriggerCommand(const char* commandName, size_t commandNameLeng
55
56
56
57
void CModManager::DoPulsePreFrame ()
57
58
{
59
+ TIMING_GRAPH (" +DoPulsePreFrame" );
60
+ CCore::GetSingleton ().GetFPSLimiter ()->OnFrameStart (); // Prepare FPS limiting for this frame
61
+
58
62
if (m_client)
59
63
{
60
64
m_client->PreFrameExecutionHandler ();
61
65
}
66
+ TIMING_GRAPH (" -DoPulsePreFrame" );
62
67
}
63
68
64
69
void CModManager::DoPulsePreHUDRender (bool bDidUnminimize, bool bDidRecreateRenderTargets)
65
70
{
71
+ TIMING_GRAPH (" +DoPulsePreHUDRender" );
66
72
if (m_client)
67
73
{
68
74
m_client->PreHUDRenderExecutionHandler (bDidUnminimize, bDidRecreateRenderTargets);
69
75
}
76
+ TIMING_GRAPH (" -DoPulsePreHUDRender" );
70
77
}
71
78
72
79
void CModManager::DoPulsePostFrame ()
73
80
{
74
- if (m_state == State::PendingStart)
75
- {
76
- Start ();
77
- }
78
- else if (m_state == State::PendingStop)
81
+ auto handleStateChange = [&]()
79
82
{
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
82
92
83
93
if (m_client)
84
94
{
@@ -89,20 +99,15 @@ void CModManager::DoPulsePostFrame()
89
99
CCore::GetSingleton ().GetNetwork ()->DoPulse ();
90
100
}
91
101
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
97
103
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 (" " );
106
111
}
107
112
108
113
bool CModManager::Load (const char * arguments)
@@ -182,16 +187,16 @@ bool CModManager::TryStart()
182
187
return false ;
183
188
}
184
189
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) )
188
193
{
189
194
CCore::GetSingleton ().GetConsole ()->Printf (" Unable to initialize deathmatch's DLL (missing init)" );
190
195
FreeLibrary (library);
191
196
return false ;
192
197
}
193
198
194
- CClientBase* client = InitClient ();
199
+ CClientBase* client = initClient ();
195
200
196
201
if (client == nullptr || client->ClientInitialize (m_arguments.c_str (), CCore::GetSingletonPtr ()) != 0 )
197
202
{
@@ -283,3 +288,4 @@ void CModManager::TryStop()
283
288
CLocalGUI::GetSingleton ().GetMainMenu ()->SetIsIngame (false );
284
289
CLocalGUI::GetSingleton ().GetMainMenu ()->SetVisible (true , false );
285
290
}
291
+
0 commit comments