~swag/armagetronad/0.2.9-sty+ct+ap-fork

« back to all changes in this revision

Viewing changes to src/engine/eTimer.h

  • Committer: luke-jr
  • Date: 2006-05-29 01:55:42 UTC
  • Revision ID: svn-v3-list-QlpoOTFBWSZTWZvbKhsAAAdRgAAQABK6798QIABURMgAAaeoNT1TxT1DQbKaeobXKiyAmlWT7Y5MkdJOtXDtB7w7DOGFBHiOBxaUIu7HQyyQSvxdyRThQkJvbKhs:7d95bf1e-0414-0410-9756-b78462a59f44:armagetronad%2Fbranches%2F0.2.8%2Farmagetronad:4612
Unify tags/branches of modules released together

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
*************************************************************************
 
4
 
 
5
ArmageTron -- Just another Tron Lightcycle Game in 3D.
 
6
Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
 
7
 
 
8
**************************************************************************
 
9
 
 
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.
 
14
 
 
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.
 
19
 
 
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.
 
23
  
 
24
***************************************************************************
 
25
 
 
26
*/
 
27
 
 
28
#ifndef ArmageTron_TIMER_H
 
29
#define ArmageTron_TIMER_H
 
30
 
 
31
//#include <time>
 
32
#include "tSysTime.h"
 
33
#include "nNetObject.h"
 
34
 
 
35
class eTimer:public nNetObject{
 
36
public:
 
37
    REAL speed; // the time acceleration
 
38
 
 
39
    eTimer();
 
40
    eTimer(nMessage &m);
 
41
    virtual ~eTimer();
 
42
    virtual void WriteSync(nMessage &m);
 
43
    virtual void ReadSync(nMessage &m);
 
44
    virtual nDescriptor &CreatorDescriptor() const;
 
45
 
 
46
    REAL Time();
 
47
    REAL TimeNoSync(){return REAL(Time()+(tSysTimeFloat()-lastTime_)*speed);}
 
48
 
 
49
    void pause(bool p);
 
50
 
 
51
    void SyncTime();
 
52
    void Reset(REAL t=0);
 
53
 
 
54
    REAL AverageFPS(){return 1/(averageSpf_.GetAverage()+EPS);}
 
55
    REAL AverageFrameTime(){return averageSpf_.GetAverage();}
 
56
    REAL FrameTime(){return spf_;}
 
57
 
 
58
    bool IsSynced() const; //!< returns whether the timer is synced sufficiently well to allow rendering
 
59
 
 
60
private:
 
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
 
67
 
 
68
    // the current game time is always smoothedSystemTime_ - ( startTime_ + startTimeSmoothedOffset_ ).
 
69
 
 
70
    REAL spf_;               //!< last frame time
 
71
    nAverager averageSpf_;   //!< averager over seconds per frame
 
72
 
 
73
    double lastTime_;        //!< the smoothed system time of the last update
 
74
    double nextSync_;        //!< system time of the next sync to the clients
 
75
};
 
76
 
 
77
REAL se_GameTime();
 
78
REAL se_GameTimeNoSync();
 
79
void se_SyncGameTimer();
 
80
 
 
81
void se_ResetGameTimer(REAL t=0);
 
82
void se_MakeGameTimer();
 
83
void se_KillGameTimer();
 
84
void se_PauseGameTimer(bool p);
 
85
 
 
86
REAL se_PredictTime();
 
87
REAL se_AverageFrameTime();
 
88
REAL se_AverageFPS();
 
89
 
 
90
extern eTimer *se_mainGameTimer;
 
91
#endif
 
92
 
 
93