28 _next_event_index = 0;
37 nassertv(_name_index.empty());
59 NameIndex::iterator ni = _name_index.find(interval->
get_name());
60 if (ni != _name_index.end()) {
61 int old_index = (*ni).second;
62 nassertr(old_index >= 0 && old_index < (
int)_intervals.size(), -1)
63 CInterval *old_interval = _intervals[old_index]._interval;
64 if (old_interval == interval) {
69 finish_interval(old_interval);
70 remove_index(old_index);
71 _name_index.erase(ni);
76 if (_first_slot >= (
int)_intervals.size()) {
78 nassertr(_first_slot == (
int)_intervals.size(), -1);
79 slot = (int)_intervals.size();
80 _intervals.push_back(IntervalDef());
81 _first_slot = (int)_intervals.size();
86 nassertr(slot >= 0 && slot < (
int)_intervals.size(), -1);
87 _first_slot = _intervals[slot]._next_slot;
90 IntervalDef &def = _intervals[slot];
91 def._interval = interval;
94 def._flags |= F_external;
96 if (interval->
is_of_type(CMetaInterval::get_class_type())) {
97 def._flags |= F_meta_interval;
101 _name_index[interval->
get_name()] = slot;
102 nassertr(_first_slot >= 0, slot);
114 NameIndex::const_iterator ni = _name_index.find(name);
115 if (ni != _name_index.end()) {
128 nassertr(index >= 0 && index < (
int)_intervals.size(),
nullptr);
129 return _intervals[index]._interval;
141 nassertv(index >= 0 && index < (
int)_intervals.size());
142 IntervalDef &def = _intervals[index];
143 nassertv(def._interval !=
nullptr);
145 NameIndex::iterator ni = _name_index.find(def._interval->get_name());
146 nassertv(ni != _name_index.end());
147 nassertv((*ni).second == index);
148 _name_index.erase(ni);
150 def._interval =
nullptr;
151 def._next_slot = _first_slot;
169 NameIndex::iterator ni;
170 ni = _name_index.begin();
171 while (ni != _name_index.end()) {
172 int index = (*ni).second;
173 const IntervalDef &def = _intervals[index];
174 nassertr(def._interval !=
nullptr, num_paused);
175 if (def._interval->get_auto_pause() || def._interval->get_auto_finish()) {
177 if (def._interval->get_auto_pause()) {
179 if (interval_cat.is_debug()) {
181 <<
"Auto-pausing " << def._interval->get_name() <<
"\n";
183 if (def._interval->get_state() == CInterval::S_started) {
184 def._interval->priv_interrupt();
189 if (interval_cat.is_debug()) {
191 <<
"Auto-finishing " << def._interval->get_name() <<
"\n";
193 switch (def._interval->get_state()) {
194 case CInterval::S_initial:
195 def._interval->priv_instant();
198 case CInterval::S_final:
202 def._interval->priv_finalize();
207 NameIndex::iterator prev;
210 _name_index.erase(prev);
230 return _name_index.size();
243 return _intervals.size();
260 NameIndex::iterator ni;
261 ni = _name_index.begin();
262 while (ni != _name_index.end()) {
263 int index = (*ni).second;
264 const IntervalDef &def = _intervals[index];
265 nassertv(def._interval !=
nullptr);
266 if (!def._interval->step_play()) {
269 NameIndex::iterator prev;
272 _name_index.erase(prev);
281 _next_event_index = 0;
300 while (_next_event_index < (
int)_intervals.size()) {
301 IntervalDef &def = _intervals[_next_event_index];
302 if (def._interval !=
nullptr) {
303 if ((def._flags & F_external) != 0 &&
304 def._interval->check_t_callback()) {
305 return _next_event_index;
307 if ((def._flags & F_meta_interval) != 0) {
309 DCAST_INTO_R(meta_interval, def._interval, -1);
311 nassertr((def._flags & F_external) != 0, -1);
312 return _next_event_index;
335 if (!_removed.empty()) {
336 int index = _removed.back();
339 nassertr(index >= 0 && index < (
int)_intervals.size(), -1);
340 IntervalDef &def = _intervals[index];
341 def._interval =
nullptr;
342 def._next_slot = _first_slot;
353 void CIntervalManager::
354 output(std::ostream &out)
const {
357 out <<
"CIntervalManager, " << (int)_name_index.size() <<
" intervals.";
363 void CIntervalManager::
364 write(std::ostream &out)
const {
369 out << (int)_name_index.size() <<
" intervals.\n";
371 NameIndex::const_iterator ni;
372 for (ni = _name_index.begin(); ni != _name_index.end(); ++ni) {
373 int index = (*ni).second;
374 nassertv(index >= 0 && index < (
int)_intervals.size());
375 const IntervalDef &def = _intervals[index];
376 nassertv(def._interval !=
nullptr);
377 out << *def._interval <<
"\n";
380 if (!_removed.empty()) {
381 out <<
"\nRemoved:\n";
382 Removed::const_iterator ri;
383 for (ri = _removed.begin(); ri != _removed.end(); ++ri) {
385 nassertv(index >= 0 && index < (
int)_intervals.size());
386 const IntervalDef &def = _intervals[index];
387 nassertv(def._interval !=
nullptr);
388 out <<
"(R)" << *def._interval <<
"\n";
398 if (_global_ptr ==
nullptr) {
408 void CIntervalManager::
411 case CInterval::S_initial:
415 case CInterval::S_final:
428 void CIntervalManager::
429 remove_index(
int index) {
431 nassertv(index >= 0 && index < (
int)_intervals.size());
432 IntervalDef &def = _intervals[index];
433 if ((def._flags & F_external) != 0) {
434 _removed.push_back(index);
436 def._interval =
nullptr;
437 def._next_slot = _first_slot;
int interrupt()
Pauses or finishes (removes from the active queue) all intervals tagged with auto_pause or auto_finis...
virtual void priv_instant()
This is called in lieu of priv_initialize() .
int get_max_index() const
Returns one more than the largest interval index number in the manager.
get_state
Indicates the state the interval believes it is in: whether it has been started, is currently in the ...
The base class for timeline components.
int get_next_event()
This should be called by the scripting language after each call to step().
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
static EventQueue * get_global_event_queue()
Returns a pointer to the one global EventQueue object.
virtual void priv_finalize()
This is called to stop an interval, forcing it to whatever state it would be after it played all the ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_name
Returns the interval's name.
static CIntervalManager * get_global_ptr()
Returns the pointer to the one global CIntervalManager object.
void remove_c_interval(int index)
Removes the indicated interval from the queue immediately.
bool debug_is_locked() const
Returns true if the current thread has locked the Mutex, false otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CInterval * get_c_interval(int index) const
Returns the interval associated with the given index.
This object holds a number of currently-playing intervals and is responsible for advancing them each ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int find_c_interval(const std::string &name) const
Returns the index associated with the named interval, if there is such an interval,...
int get_num_intervals() const
Returns the number of currently active intervals.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
int get_next_removal()
This should be called by the scripting language after each call to step().
int add_c_interval(CInterval *interval, bool external)
Adds the interval to the manager, and returns a unique index for the interval.
void step()
This should be called every frame to do the processing for all the active intervals.