-
Notifications
You must be signed in to change notification settings - Fork 0
/
MeCycleTimer.h
58 lines (47 loc) · 1.21 KB
/
MeCycleTimer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include "MeFoundation/MeClockTimer.h"
/**
* @brief Cycled timer, a cycle could be hour, day or week,
millseconds is a unit
*/
template< MeTimeValue kCycle, class Timer = MeClockTimer >
class MEFOUNDATION_ENTRY MeCycleTimer : public Timer
{
// typedefs.
public:
typedef MeCycleTimer<kCycle,Timer> ClassType;
// Construction.
public:
/// Constructor.
MeCycleTimer(){
m_fRatio = 1.f;
}
/// Destructor.
virtual ~MeCycleTimer(){}
/// Copy constructor.
MeCycleTimer( const ClassType& kClass ){}
// Overload operator.
public:
/// Assignment operator.
const MeCycleTimer& operator=( const ClassType& kClass ){ return *this; }
// Override.
public:
virtual void UpdateElapsedTime(){
Timer::UpdateElapsedTime();
m_kElapsed = GetElapsed() % kCycle;
}
virtual MeTimeValue GetElapsed() const{
return Timer::GetElapsed() * GetTimeRatio();
}
// Methods.
public:
float GetTimeRatio() const { return m_fRatio; }
void SetTimeRatio( float fRatio ){ m_fRatio = fRatio; }
// Members.
protected:
float m_fRatio;
};
// Hour
typedef MeCycleTimer<3600000, MeClockTimer> MeHourTimer;
// Day
typedef MeCycleTimer<3600000 * 24, MeClockTimer> MeDayTimer;