timehandling.h

来自「我对他如何控制准星、显示敌友很好奇」· C头文件 代码 · 共 78 行

H
78
字号
#ifndef TIMEHANDLING_H
#define TIMEHANDLING_H

//===============================================================
// class ClientTime:
//      provides a stable time base, independent of map changes.
//===============================================================
class ClientTime 
{
public:
	static void   reportMapTime(float newMapTime);
	static float  mapTime;  // how long did the current map run?

	static void   updateCurrentTime();
	static double current;    // seconds counter
	static DWORD  current_ms; // ms counter

protected:
//	static double timeoffset;
};

//===============================================================
// class StopTimer
//      
//===============================================================
class StopTimer
{
public:
	StopTimer() :expirationTime(0)       {}

	void  countdown( double seconds ) { expirationTime = ClientTime::current + seconds; }
	bool  running () { return (ClientTime::current<=expirationTime); }
	bool  expired () { return (ClientTime::current> expirationTime); }
	float timeleft() { return float(expirationTime-ClientTime::current);  }
	void  setExpired() { expirationTime=0;                           }
	void  setRunning() { expirationTime=1000000;                     }

protected:
	double expirationTime;
};

//===============================================================
// class RunningStopTimer
//      
//===============================================================
class RunningStopTimer : public StopTimer { public: RunningStopTimer(){expirationTime=1000000;} };


//===============================================================
// class EventCounter
//      
//===============================================================
template < float Interval, int MaxEvents = 12 >
class EventCounter
{
public:
	// returns number of events since last call, maximal 12
	int  get()
	{
		register int n = 0;
		while(reftime<ClientTime::current)
		{
			reftime += Interval;
			++n;
			if(n>MaxEvents) { reset(); return 1; }
		}
		return n;
	}

	EventCounter()  {reset();}

protected:
	void   reset() {reftime = ClientTime::current;}
	double reftime;
};

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?