forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcInterval.h
More file actions
209 lines (174 loc) · 5.98 KB
/
cInterval.h
File metadata and controls
209 lines (174 loc) · 5.98 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file cInterval.h
* @author drose
* @date 2002-08-27
*/
#ifndef CINTERVAL_H
#define CINTERVAL_H
#include "directbase.h"
#include "typedReferenceCount.h"
#include "pvector.h"
#include "config_interval.h"
#include "pStatCollector.h"
class CIntervalManager;
/**
* The base class for timeline components. A CInterval represents a single
* action, event, or collection of nested intervals that will be performed at
* some specific time or over a period of time.
*
* This is essentially similar to the Python "Interval" class, but it is
* implemented in C++ (hence the name). Intervals that may be implemented in
* C++ will inherit from this class; Intervals that must be implemented in
* Python will inherit from the similar Python class.
*/
class EXPCL_DIRECT_INTERVAL CInterval : public TypedReferenceCount {
public:
CInterval(const std::string &name, double duration, bool open_ended);
virtual ~CInterval();
PUBLISHED:
INLINE const std::string &get_name() const;
INLINE double get_duration() const;
INLINE bool get_open_ended() const;
enum EventType {
ET_initialize,
ET_instant,
ET_step,
ET_finalize,
ET_reverse_initialize,
ET_reverse_instant,
ET_reverse_finalize,
ET_interrupt
};
enum State {
S_initial,
S_started,
S_paused,
S_final
};
INLINE State get_state() const;
INLINE bool is_stopped() const;
INLINE void set_done_event(const std::string &event);
INLINE const std::string &get_done_event() const;
void set_t(double t);
INLINE double get_t() const;
INLINE void set_auto_pause(bool auto_pause);
INLINE bool get_auto_pause() const;
INLINE void set_auto_finish(bool auto_finish);
INLINE bool get_auto_finish() const;
INLINE void set_wants_t_callback(bool wants_t_callback);
INLINE bool get_wants_t_callback() const;
INLINE void set_manager(CIntervalManager *manager);
INLINE CIntervalManager *get_manager() const;
void start(double start_t = 0.0, double end_t = -1.0, double play_rate = 1.0);
void loop(double start_t = 0.0, double end_t = -1.0, double play_rate = 1.0);
double pause();
void resume();
void resume(double start_t);
void resume_until(double end_t);
void finish();
void clear_to_initial();
bool is_playing() const;
double get_play_rate() const;
void set_play_rate(double play_rate);
// These functions control the actual playback of the interval. Don't call
// them directly; they're intended to be called from a supervising object,
// e.g. the Python start() .. finish() interface.
// These cannot be declared private because they must be accessible to
// Python, but the method names are prefixed with priv_ to remind you that
// you probably don't want to be using them directly.
void priv_do_event(double t, EventType event);
virtual void priv_initialize(double t);
virtual void priv_instant();
virtual void priv_step(double t);
virtual void priv_finalize();
virtual void priv_reverse_initialize(double t);
virtual void priv_reverse_instant();
virtual void priv_reverse_finalize();
virtual void priv_interrupt();
virtual void output(std::ostream &out) const;
virtual void write(std::ostream &out, int indent_level) const;
void setup_play(double start_time, double end_time, double play_rate,
bool do_loop);
void setup_resume();
void setup_resume_until(double end_t);
bool step_play();
PUBLISHED:
MAKE_PROPERTY(name, get_name);
MAKE_PROPERTY(duration, get_duration);
MAKE_PROPERTY(open_ended, get_open_ended);
MAKE_PROPERTY(state, get_state);
MAKE_PROPERTY(stopped, is_stopped);
MAKE_PROPERTY(done_event, get_done_event, set_done_event);
MAKE_PROPERTY(t, get_t, set_t);
MAKE_PROPERTY(auto_pause, get_auto_pause, set_auto_pause);
MAKE_PROPERTY(auto_finish, get_auto_finish, set_auto_finish);
MAKE_PROPERTY(manager, get_manager, set_manager);
MAKE_PROPERTY(play_rate, get_play_rate, set_play_rate);
MAKE_PROPERTY(playing, is_playing);
public:
void mark_dirty();
INLINE bool check_t_callback();
protected:
void interval_done();
INLINE void recompute() const;
virtual void do_recompute();
INLINE void check_stopped(TypeHandle type, const char *method_name) const;
INLINE void check_started(TypeHandle type, const char *method_name) const;
State _state;
double _curr_t;
std::string _name;
std::string _pname;
std::string _done_event;
double _duration;
bool _auto_pause;
bool _auto_finish;
bool _wants_t_callback;
double _last_t_callback;
CIntervalManager *_manager;
// For setup_play() and step_play().
double _clock_start;
double _start_t;
double _end_t;
bool _end_t_at_end;
bool _start_t_at_start;
double _play_rate;
bool _do_loop;
int _loop_count;
private:
bool _open_ended;
bool _dirty;
// We keep a record of the "parent" intervals (that is, any CMetaInterval
// objects that keep a pointer to this one) strictly so we can mark all of
// our parents dirty when this interval gets dirty.
typedef pvector<CInterval *> Parents;
Parents _parents;
static PStatCollector _root_pcollector;
PStatCollector _ival_pcollector;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TypedReferenceCount::init_type();
register_type(_type_handle, "CInterval",
TypedReferenceCount::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
friend class CMetaInterval;
};
INLINE std::ostream &operator << (std::ostream &out, const CInterval &ival);
EXPCL_DIRECT_INTERVAL std::ostream &operator << (std::ostream &out, CInterval::State state);
#include "cInterval.I"
#endif