3
*************************************************************************
5
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
Copyright (C) 2000 Manuel Moos (manuel@moosnet.de)
8
**************************************************************************
10
This program is free software; you can redistribute it and/or
11
modify it under the terms of the GNU General Public License
12
as published by the Free Software Foundation; either version 2
13
of the License, or (at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
***************************************************************************
28
#ifndef ArmageTron_TIMER_H
29
#define ArmageTron_TIMER_H
33
#include "nNetObject.h"
35
class eTimer:public nNetObject{
37
REAL speed; // the time acceleration
42
virtual void WriteSync(nMessage &m);
43
virtual void ReadSync(nMessage &m);
44
virtual nDescriptor &CreatorDescriptor() const;
47
REAL TimeNoSync(){return REAL(Time()+(tSysTimeFloat()-lastTime_)*speed);}
54
REAL AverageFPS(){return 1/(averageSpf_.GetAverage()+EPS);}
55
REAL AverageFrameTime(){return averageSpf_.GetAverage();}
56
REAL FrameTime(){return spf_;}
58
bool IsSynced() const; //!< returns whether the timer is synced sufficiently well to allow rendering
61
mutable double creationSystemTime_; //!< the rough system time this timer was created at
62
double smoothedSystemTime_; //!< the smoothed system time
63
double startTime_; //!< when was the last game started?
64
nAverager startTimeOffset_; //!< the smoothed average of this averager is added to the start time on the client
65
REAL startTimeSmoothedOffset_; //!< the smoothed average of startTimeOffset_
66
nAverager qualityTester_; //!< averager that tells us about the quality of the sync messages
68
// the current game time is always smoothedSystemTime_ - ( startTime_ + startTimeSmoothedOffset_ ).
70
REAL spf_; //!< last frame time
71
nAverager averageSpf_; //!< averager over seconds per frame
73
double lastTime_; //!< the smoothed system time of the last update
74
double nextSync_; //!< system time of the next sync to the clients
78
REAL se_GameTimeNoSync();
79
void se_SyncGameTimer();
81
void se_ResetGameTimer(REAL t=0);
82
void se_MakeGameTimer();
83
void se_KillGameTimer();
84
void se_PauseGameTimer(bool p);
86
REAL se_PredictTime();
87
REAL se_AverageFrameTime();
90
extern eTimer *se_mainGameTimer;