-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeTimeLine.h
145 lines (125 loc) · 3.6 KB
/
MeTimeLine.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#pragma once
#include "MeFoundation/MeTimelineEvent.h"
/**
* @brief A time trigger
* @template Timer: timer type
*/
template< class Timer >
class MEFOUNDATION_ENTRY MeTimeline : public MeRefObject
{
// Defines.
public:
typedef MeTimeline< Timer > ThisClass;
typedef std::vector<MeTimelineEventBase*> TimelineEvents;
typedef TimelineEvents::iterator TimelineEventsIterator;
typedef TimelineEvents::const_iterator TimelineEventsConstIterator;
// Construction.
public:
/// Constructor.
MeTimeline(){}
/// Destructor.
~MeTimeline(){}
/// Copy constructor.
MeTimeline( const ThisClass& kClass ){
m_akEvents = kClass.m_akEvents;
m_kTimer = kClass.m_kTimer;
}
// Overload operator.
public:
/// Assignment operator.
const MeTimeline& operator=( const ThisClass& kClass ){
m_akEvents = kClass.m_akEvents;
m_kTimer = kClass.m_kTimer;
return *this;
}
// Methods.
public:
/// add time event
void PushEvent( MeTimelineEventBase* pEvent );
/// sort all events by time
void SortEventsByTime();
/// clear events
void ClearAllEvents();
/// update time line
void UpdateTimeline();
/// render event
void RenderTimeline();
/// get timer
const Timer& GetTimer() const{ return m_kTimer; }
Timer* GetTimer(){ return &m_kTimer; }
/// get evetns
const TimelineEvents& GetEvents() const { return m_akEvents; }
TimelineEvents& GetEvents() { return m_akEvents; }
/// start
void StartTime( const MeTimeValue& kTimePassed );
// Static Methods.
protected:
static bool EventsSortAlgorism( MeTimelineEventBase* pEvent1, MeTimelineEventBase* pEvent2 )
{
return pEvent1->GetStartTime() < pEvent2->GetStartTime();
}
// Members.
protected:
Timer m_kTimer;
TimelineEvents m_akEvents;
};
//////////////////////////////////////////////////////////////////////////
template< class Timer >
void MeTimeline< Timer >::PushEvent( MeTimelineEventBase* pEvent )
{
m_akEvents.push_back( pEvent );
}
//////////////////////////////////////////////////////////////////////////
template< class Timer >
void MeTimeline< Timer >::SortEventsByTime()
{
std::sort( m_akEvents.begin(), m_akEvents.end(), EventsSortAlgorism );
}
//////////////////////////////////////////////////////////////////////////
template< class Timer >
void MeTimeline< Timer >::ClearAllEvents()
{
TimelineEventsConstIterator kIter = m_akEvents.begin();
for( ; kIter != m_akEvents.end(); ++ kIter )
{
( *kIter )->DestroyEvent();
MeDelete ( *kIter );
}
m_akEvents.clear();
}
//////////////////////////////////////////////////////////////////////////
template< class Timer >
void MeTimeline< Timer >::UpdateTimeline()
{
if( !m_kTimer.IsStarted() )
{ return; }
m_kTimer.UpdateElapsedTime();
if( m_akEvents.empty() )
return;
TimelineEventsConstIterator kIter = m_akEvents.begin();
for( ; kIter != m_akEvents.end(); ++ kIter )
{
( *kIter )->UpdateEvent( m_kTimer.GetElapsed() );
}
}
//////////////////////////////////////////////////////////////////////////
template< class Timer >
void MeTimeline< Timer >::RenderTimeline()
{
if( !m_kTimer.IsStarted() )
{ return; }
if( m_akEvents.empty() )
return;
TimelineEventsConstIterator kIter = m_akEvents.begin();
for( ; kIter != m_akEvents.end(); ++ kIter )
{
( *kIter )->RenderEvent();
}
}
//////////////////////////////////////////////////////////////////////////
template< class Timer >
void MeTimeline< Timer >::StartTime( const MeTimeValue& kTimePassed )
{
m_kTimer.Start( kTimePassed );
}
//////////////////////////////////////////////////////////////////////////