-
Notifications
You must be signed in to change notification settings - Fork 0
/
MeTimelineEvent.h
executable file
·163 lines (128 loc) · 4.06 KB
/
MeTimelineEvent.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#pragma once
#include "MeFoundation/MeRefObject.h"
/**
* @brief Base class for timeline
*/
class MEFOUNDATION_ENTRY MeTimelineEventBase : public MeRefObject
{
// Defines.
public:
/// event status
enum EEventStates
{
EES_Ready,
EES_Running,
EES_Pause,
EES_End,
EES_Count
};
/// invalide event time
enum { InvalidEventTime = 0xffffffff };
/// callback
typedef void (*DataCallback)( MeTimelineEventBase* );
// Construction.
public:
/// Constructor.
MeTimelineEventBase(){
m_eEventState = EES_Count;
m_kStartTime = InvalidEventTime;
m_kEndTime = InvalidEventTime;
m_pfResetEventWithDataCallback = NULL;
m_pfDoFirstInRunning = NULL;
m_pfUpdateEventInReady = NULL;
m_pfUpdateEventInRunning = NULL;
m_pfUpdateEventInEnd = NULL;
m_bFirstInRunning = true;
}
/// Copy constructor.
MeTimelineEventBase( const MeTimelineEventBase& kClass ){}
// Overload operator.
public:
/// Assignment operator.
const MeTimelineEventBase& operator=( const MeTimelineEventBase& kClass ){ return *this; }
// Virtual Methods.
public:
/// Destructor.
virtual ~MeTimelineEventBase(){}
/// Initialize.
virtual void InitializeEvent() = 0;
/// Reset states.
virtual void ResetEvent(){
if( m_pfResetEventWithDataCallback )
{ m_pfResetEventWithDataCallback( this ); }
}
/// Destroy.
virtual void DestroyEvent() = 0;
/// Update event when a event has been triggered
/// @return allowed to update
virtual bool UpdateEvent( const int64& kTime ){
if( kTime <= GetStartTime() )
{
SetEventState( EES_Ready );
if( m_pfUpdateEventInReady )
{ m_pfUpdateEventInReady( this ); }
UpdateEventInReady( kTime );
IsFirstInRunning( true );
return false;
}
else if( kTime > GetEndTime() )
{
SetEventState( EES_End );
if( m_pfUpdateEventInEnd )
{ m_pfUpdateEventInEnd( this ); }
UpdateEventInEnd( kTime );
}
else
{
SetEventState( EES_Running );
if( IsFirstInRunning() )
{
if( m_pfDoFirstInRunning )
{ m_pfDoFirstInRunning( this ); }
DoFirstInRunning( kTime );
IsFirstInRunning( false );
}
if( m_pfUpdateEventInRunning )
{ m_pfUpdateEventInRunning( this ); }
UpdateEventInRunning( kTime );
}
return true;
}
/// Render.
virtual void RenderEvent(){}
// Override.
protected:
virtual void UpdateEventInReady( const int64& kTime ){}
virtual void UpdateEventInRunning( const int64& kTime ){}
virtual void UpdateEventInEnd( const int64& kTime ){}
/// execute when first running
virtual void DoFirstInRunning( const int64& kTime ){}
// Methods.
public:
void SetEventState( MeTimelineEventBase::EEventStates eState ){ m_eEventState = eState; }
EEventStates GetEventState() const { return m_eEventState; }
void SetStartTime( const int64& kTime ) { m_kStartTime = kTime; }
const int64& GetStartTime() const { return m_kStartTime; }
const int64& GetEndTime() const { return m_kEndTime; }
void SetEndTime( const int64& val ){ m_kEndTime = val; }
void SetResetEventWithDataCallbackFunc( DataCallback pfCallback ){ m_pfResetEventWithDataCallback = pfCallback; }
void SetDoFirstInRunningCallbackFunc( DataCallback pfCallback ){ m_pfDoFirstInRunning = pfCallback; }
void SetUpdateEventInReadyCallbackFunc( DataCallback pfCallback ){ m_pfUpdateEventInReady = pfCallback; }
void SetUpdateEventInRunningCallbackFunc( DataCallback pfCallback ){ m_pfUpdateEventInRunning = pfCallback; }
void SetUpdateEventInEndCallbackFunc( DataCallback pfCallback ){ m_pfUpdateEventInEnd = pfCallback; }
// Methods.
protected:
void IsFirstInRunning( bool bFirst ) { m_bFirstInRunning = bFirst; }
bool IsFirstInRunning() const { return m_bFirstInRunning; }
// Members.
protected:
DataCallback m_pfResetEventWithDataCallback;
DataCallback m_pfDoFirstInRunning;
DataCallback m_pfUpdateEventInReady;
DataCallback m_pfUpdateEventInRunning;
DataCallback m_pfUpdateEventInEnd;
EEventStates m_eEventState;
int64 m_kStartTime;
int64 m_kEndTime;
bool m_bFirstInRunning;
};