This has been asked for and debated in some form since Valve introduced hibernation into the Source engine. The changes here are based on quite a deep dive into the engine's frame/think logic (mainly in CS:GO which has "legacy" hibernation and TF2 which has modern "frameless" ticking) and all seem to be sane. I think I've managed to maintain all the oddities around time keeping, and the simulated bool (even though we don't really use it for anything) should have a sane value. There is a slight behaviour change for anything needing exact timings as we're now run earlier in the frame before gpGlobals are updated, this should generally be fine but it might affect some plugins such as bhop timers that are trying to be extremely precise (often more precise than the underlying data they're using). We'll probably want to add a native for plugins to detect if the server is not completely simulating so they can opt out of work, but I think defaulting to having things work like this makes more sense than adding a 2nd set of per-frame forwards and natives (#540), and this makes timers and any extension callbacks work automatically.
114 lines
3.7 KiB
C++
114 lines
3.7 KiB
C++
/**
|
|
* vim: set ts=4 :
|
|
* =============================================================================
|
|
* SourceMod
|
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
|
* =============================================================================
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
* Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
* details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
*
|
|
* Version: $Id$
|
|
*/
|
|
|
|
#ifndef _INCLUDE_SOURCEMOD_CTIMERSYS_H_
|
|
#define _INCLUDE_SOURCEMOD_CTIMERSYS_H_
|
|
|
|
#include <ITimerSystem.h>
|
|
#include <sh_stack.h>
|
|
#include <sh_list.h>
|
|
#include "sourcemm_api.h"
|
|
#include "sm_globals.h"
|
|
|
|
using namespace SourceHook;
|
|
using namespace SourceMod;
|
|
|
|
typedef List<ITimer *> TimerList;
|
|
typedef List<ITimer *>::iterator TimerIter;
|
|
|
|
class SourceMod::ITimer
|
|
{
|
|
public:
|
|
void Initialize(ITimedEvent *pCallbacks, float fInterval, float fToExec, void *pData, int flags);
|
|
ITimedEvent *m_Listener;
|
|
void *m_pData;
|
|
float m_Interval;
|
|
double m_ToExec;
|
|
int m_Flags;
|
|
bool m_InExec;
|
|
bool m_KillMe;
|
|
};
|
|
|
|
class TimerSystem :
|
|
public ITimerSystem,
|
|
public SMGlobalClass
|
|
{
|
|
public:
|
|
TimerSystem();
|
|
~TimerSystem();
|
|
public: //SMGlobalClass
|
|
void OnSourceModAllInitialized();
|
|
void OnSourceModLevelEnd();
|
|
void OnSourceModGameInitialized();
|
|
void OnSourceModShutdown();
|
|
public: //ITimerSystem
|
|
ITimer *CreateTimer(ITimedEvent *pCallbacks, float fInterval, void *pData, int flags);
|
|
void KillTimer(ITimer *pTimer);
|
|
void FireTimerOnce(ITimer *pTimer, bool delayExec=false);
|
|
void MapTimeLeftChanged();
|
|
IMapTimer *SetMapTimer(IMapTimer *pTimer);
|
|
float GetTickedTime();
|
|
void NotifyOfGameStart(float offset /* = 0.0f */);
|
|
bool GetMapTimeLeft(float *pTime);
|
|
IMapTimer *GetMapTimer();
|
|
public:
|
|
void RunFrame();
|
|
void RemoveMapChangeTimers();
|
|
void Think(bool unused);
|
|
void GameFrame(bool simulating);
|
|
private:
|
|
List<ITimer *> m_SingleTimers;
|
|
List<ITimer *> m_LoopTimers;
|
|
CStack<ITimer *> m_FreeTimers;
|
|
IMapTimer *m_pMapTimer;
|
|
|
|
/* This is stuff for our manual ticking escapades. */
|
|
bool m_bHasMapTickedYet; /** Has the map ticked yet? */
|
|
bool m_bHasMapSimulatedYet; /** Has the map simulated yet? */
|
|
bool m_bWasSimulating; /** Was the last GameFrame simulating */
|
|
unsigned m_uFramesAhead; /** Number of frames Think is ahead of GameFrame */
|
|
float m_fLastTickedTime; /** Last time that the game currently gave
|
|
us while ticking.
|
|
*/
|
|
|
|
IForward *m_pOnGameFrame;
|
|
IForward *m_pOnMapTimeLeftChanged;
|
|
};
|
|
|
|
time_t GetAdjustedTime(time_t *buf = NULL);
|
|
|
|
extern const double *g_pUniversalTime;
|
|
extern TimerSystem g_Timers;
|
|
extern int g_TimeLeftMode;
|
|
|
|
#endif //_INCLUDE_SOURCEMOD_CTIMERSYS_H_
|
|
|