Panda3D
Loading...
Searching...
No Matches
cInterval.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file cInterval.h
10 * @author drose
11 * @date 2002-08-27
12 */
13
14#ifndef CINTERVAL_H
15#define CINTERVAL_H
16
17#include "directbase.h"
18#include "typedReferenceCount.h"
19#include "pvector.h"
20#include "config_interval.h"
21#include "pStatCollector.h"
22#include "extension.h"
23
25
26/**
27 * The base class for timeline components. A CInterval represents a single
28 * action, event, or collection of nested intervals that will be performed at
29 * some specific time or over a period of time.
30 *
31 * This is essentially similar to the Python "Interval" class, but it is
32 * implemented in C++ (hence the name). Intervals that may be implemented in
33 * C++ will inherit from this class; Intervals that must be implemented in
34 * Python will inherit from the similar Python class.
35 */
36class EXPCL_DIRECT_INTERVAL CInterval : public TypedReferenceCount {
37public:
38 CInterval(const std::string &name, double duration, bool open_ended);
39 virtual ~CInterval();
40
41PUBLISHED:
42 INLINE const std::string &get_name() const;
43 INLINE double get_duration() const;
44 INLINE bool get_open_ended() const;
45
46 enum EventType {
47 ET_initialize,
48 ET_instant,
49 ET_step,
50 ET_finalize,
51 ET_reverse_initialize,
52 ET_reverse_instant,
53 ET_reverse_finalize,
54 ET_interrupt
55 };
56
57 enum State {
58 S_initial,
59 S_started,
60 S_paused,
61 S_final
62 };
63
64 INLINE State get_state() const;
65 INLINE bool is_stopped() const;
66
67 INLINE void set_done_event(const std::string &event);
68 INLINE const std::string &get_done_event() const;
69
70 void set_t(double t);
71 INLINE double get_t() const;
72
73 INLINE void set_auto_pause(bool auto_pause);
74 INLINE bool get_auto_pause() const;
75 INLINE void set_auto_finish(bool auto_finish);
76 INLINE bool get_auto_finish() const;
77
78 INLINE void set_wants_t_callback(bool wants_t_callback);
79 INLINE bool get_wants_t_callback() const;
80
81 INLINE void set_manager(CIntervalManager *manager);
82 INLINE CIntervalManager *get_manager() const;
83
84 void start(double start_t = 0.0, double end_t = -1.0, double play_rate = 1.0);
85 void loop(double start_t = 0.0, double end_t = -1.0, double play_rate = 1.0);
86 double pause();
87 void resume();
88 void resume(double start_t);
89 void resume_until(double end_t);
90 void finish();
91 void clear_to_initial();
92 bool is_playing() const;
93
94 double get_play_rate() const;
95 void set_play_rate(double play_rate);
96
97 // These functions control the actual playback of the interval. Don't call
98 // them directly; they're intended to be called from a supervising object,
99 // e.g. the Python start() .. finish() interface.
100
101 // These cannot be declared private because they must be accessible to
102 // Python, but the method names are prefixed with priv_ to remind you that
103 // you probably don't want to be using them directly.
104 void priv_do_event(double t, EventType event);
105 virtual void priv_initialize(double t);
106 virtual void priv_instant();
107 virtual void priv_step(double t);
108 virtual void priv_finalize();
109 virtual void priv_reverse_initialize(double t);
110 virtual void priv_reverse_instant();
111 virtual void priv_reverse_finalize();
112 virtual void priv_interrupt();
113
114 virtual void output(std::ostream &out) const;
115 virtual void write(std::ostream &out, int indent_level) const;
116
117 void setup_play(double start_time, double end_time, double play_rate,
118 bool do_loop);
119 void setup_resume();
120 void setup_resume_until(double end_t);
121 bool step_play();
122
123PUBLISHED:
124 EXTENSION(PyObject *__await__(PyObject *self));
125
126 MAKE_PROPERTY(name, get_name);
127 MAKE_PROPERTY(duration, get_duration);
128 MAKE_PROPERTY(open_ended, get_open_ended);
129 MAKE_PROPERTY(state, get_state);
130 MAKE_PROPERTY(stopped, is_stopped);
131 MAKE_PROPERTY(done_event, get_done_event, set_done_event);
132 MAKE_PROPERTY(t, get_t, set_t);
133 MAKE_PROPERTY(auto_pause, get_auto_pause, set_auto_pause);
134 MAKE_PROPERTY(auto_finish, get_auto_finish, set_auto_finish);
135 MAKE_PROPERTY(manager, get_manager, set_manager);
136 MAKE_PROPERTY(play_rate, get_play_rate, set_play_rate);
137 MAKE_PROPERTY(playing, is_playing);
138
139public:
140 void mark_dirty();
141 INLINE bool check_t_callback();
142
143protected:
144 void interval_done();
145
146 INLINE void recompute() const;
147 virtual void do_recompute();
148 INLINE void check_stopped(TypeHandle type, const char *method_name) const;
149 INLINE void check_started(TypeHandle type, const char *method_name) const;
150
151 State _state;
152 double _curr_t;
153 std::string _name;
154 std::string _pname;
155 std::string _done_event;
156 double _duration;
157
158 bool _auto_pause;
159 bool _auto_finish;
160 bool _wants_t_callback;
161 double _last_t_callback;
162 CIntervalManager *_manager;
163
164 // For setup_play() and step_play().
165 double _clock_start;
166 double _start_t;
167 double _end_t;
168 bool _end_t_at_end;
169 bool _start_t_at_start;
170 double _play_rate;
171 bool _do_loop;
172 int _loop_count;
173
174private:
175 bool _open_ended;
176 bool _dirty;
177
178 // We keep a record of the "parent" intervals (that is, any CMetaInterval
179 // objects that keep a pointer to this one) strictly so we can mark all of
180 // our parents dirty when this interval gets dirty.
182 Parents _parents;
183
184 static PStatCollector _root_pcollector;
185 PStatCollector _ival_pcollector;
186
187public:
188 static TypeHandle get_class_type() {
189 return _type_handle;
190 }
191 static void init_type() {
192 TypedReferenceCount::init_type();
193 register_type(_type_handle, "CInterval",
194 TypedReferenceCount::get_class_type());
195 }
196 virtual TypeHandle get_type() const {
197 return get_class_type();
198 }
199 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
200
201private:
202 static TypeHandle _type_handle;
203
204 friend class CMetaInterval;
205};
206
207INLINE std::ostream &operator << (std::ostream &out, const CInterval &ival);
208EXPCL_DIRECT_INTERVAL std::ostream &operator << (std::ostream &out, CInterval::State state);
209
210#include "cInterval.I"
211
212#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This object holds a number of currently-playing intervals and is responsible for advancing them each ...
The base class for timeline components.
Definition cInterval.h:36
This interval contains a list of nested intervals, each of which has its own begin and end times.
A lightweight class that represents a single element that may be timed and/or counted via stats.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.