1.1 --- a/core/sourcemod.cpp Wed May 02 21:00:13 2007 +0000
1.2 +++ b/core/sourcemod.cpp Wed May 02 22:35:51 2007 +0000
1.3 @@ -47,6 +47,8 @@
1.4 IForward *g_pOnGameFrame = NULL;
1.5 IForward *g_pOnMapEnd = NULL;
1.6 bool g_Loaded = false;
1.7 +int g_StillFrames = 0;
1.8 +float g_StillTime = 0.0f;
1.9
1.10 typedef int (*GIVEENGINEPOINTER)(ISourcePawnEngine *);
1.11 typedef unsigned int (*GETEXPORTCOUNT)();
1.12 @@ -263,6 +265,10 @@
1.13 m_ExecPluginReload = true;
1.14 g_LastTime = 0.0f;
1.15 g_LastAuthCheck = 0.0f;
1.16 + g_SimTicks.ticking = true;
1.17 + g_SimTicks.tickcount = 0;
1.18 + g_StillTime = 0.0f;
1.19 + g_StillFrames = 0;
1.20
1.21 /* Notify! */
1.22 SMGlobalClass *pBase = SMGlobalClass::head;
1.23 @@ -297,6 +303,27 @@
1.24 RETURN_META_VALUE(MRES_IGNORED, true);
1.25 }
1.26
1.27 +void StartTickSimulation()
1.28 +{
1.29 + g_SimTicks.ticking = false;
1.30 + g_SimTicks.tickcount = 0;
1.31 + g_SimTicks.ticktime = gpGlobals->curtime;
1.32 +}
1.33 +
1.34 +void StopTickSimulation()
1.35 +{
1.36 + g_SimTicks.ticking = true;
1.37 + g_Timers.MapChange();
1.38 + g_StillFrames = 0;
1.39 + g_LastTime = gpGlobals->curtime;
1.40 +}
1.41 +
1.42 +void SimulateTick()
1.43 +{
1.44 + g_SimTicks.tickcount++;
1.45 + g_SimTicks.ticktime = g_StillTime + (g_SimTicks.tickcount * gpGlobals->interval_per_tick);
1.46 +}
1.47 +
1.48 void SourceModBase::GameFrame(bool simulating)
1.49 {
1.50 /**
1.51 @@ -304,6 +331,46 @@
1.52 * precious CPU cycles.
1.53 */
1.54 float curtime = gpGlobals->curtime;
1.55 + int framecount = gpGlobals->framecount;
1.56 +
1.57 + /* Verify that we're still ticking */
1.58 + if (g_SimTicks.ticking)
1.59 + {
1.60 + if (g_StillFrames == 0)
1.61 + {
1.62 + g_StillFrames = framecount;
1.63 + g_StillTime = curtime;
1.64 + } else {
1.65 + /* Try to detect when we've stopped ticking.
1.66 + * We do this once 10 frames pass and there have been no ticks.
1.67 + */
1.68 + if (g_StillTime == curtime)
1.69 + {
1.70 + if (framecount - g_StillFrames >= 5)
1.71 + {
1.72 + StartTickSimulation();
1.73 + return;
1.74 + }
1.75 + } else {
1.76 + /* We're definitely ticking we get here,
1.77 + * but update everything as a precaution */
1.78 + g_StillFrames = framecount;
1.79 + g_StillTime = curtime;
1.80 + }
1.81 + }
1.82 + } else {
1.83 + /* We need to make sure we should still be simulating. */
1.84 + if (g_StillTime != curtime)
1.85 + {
1.86 + /* Wow, we're ticking again! It's time to revert. */
1.87 + StopTickSimulation();
1.88 + return;
1.89 + }
1.90 + /* Nope, not ticking. Simulate! */
1.91 + SimulateTick();
1.92 + curtime = g_SimTicks.ticktime;
1.93 + }
1.94 +
1.95 if (curtime - g_LastTime >= 0.1f)
1.96 {
1.97 if (m_CheckingAuth