Panda3D
Loading...
Searching...
No Matches
cMetaInterval.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 cMetaInterval.h
10 * @author drose
11 * @date 2002-08-27
12 */
13
14#ifndef CMETAINTERVAL_H
15#define CMETAINTERVAL_H
16
17#include "directbase.h"
18#include "cInterval.h"
19#include "pointerTo.h"
20
21#include "pdeque.h"
22#include "pvector.h"
23#include "plist.h"
24#include "pset.h"
25#include <math.h>
26
27/**
28 * This interval contains a list of nested intervals, each of which has its
29 * own begin and end times. Some of them may overlap and some of them may
30 * not.
31 */
32class EXPCL_DIRECT_INTERVAL CMetaInterval : public CInterval {
33PUBLISHED:
34 explicit CMetaInterval(const std::string &name);
35 virtual ~CMetaInterval();
36
37 enum RelativeStart {
38 RS_previous_end,
39 RS_previous_begin,
40 RS_level_begin,
41 };
42
43 INLINE void set_precision(double precision);
44 INLINE double get_precision() const;
45
46 void clear_intervals();
47 int push_level(const std::string &name,
48 double rel_time, RelativeStart rel_to);
49 int add_c_interval(CInterval *c_interval,
50 double rel_time = 0.0f,
51 RelativeStart rel_to = RS_previous_end);
52 int add_ext_index(int ext_index, const std::string &name,
53 double duration, bool open_ended,
54 double rel_time, RelativeStart rel_to);
55 int pop_level(double duration = -1.0);
56
57 bool set_interval_start_time(const std::string &name, double rel_time,
58 RelativeStart rel_to = RS_level_begin);
59 double get_interval_start_time(const std::string &name) const;
60 double get_interval_end_time(const std::string &name) const;
61
62 enum DefType {
63 DT_c_interval,
64 DT_ext_index,
65 DT_push_level,
66 DT_pop_level
67 };
68
69 INLINE int get_num_defs() const;
70 INLINE DefType get_def_type(int n) const;
71 INLINE CInterval *get_c_interval(int n) const;
72 INLINE int get_ext_index(int n) const;
73
74 virtual void priv_initialize(double t);
75 virtual void priv_instant();
76 virtual void priv_step(double t);
77 virtual void priv_finalize();
78 virtual void priv_reverse_initialize(double t);
79 virtual void priv_reverse_instant();
80 virtual void priv_reverse_finalize();
81 virtual void priv_interrupt();
82
83 INLINE bool is_event_ready();
84 INLINE int get_event_index() const;
85 INLINE double get_event_t() const;
86 INLINE EventType get_event_type() const;
87 void pop_event();
88
89 virtual void write(std::ostream &out, int indent_level) const;
90 void timeline(std::ostream &out) const;
91
92protected:
93 virtual void do_recompute();
94
95private:
96 class IntervalDef {
97 public:
98 DefType _type;
99 PT(CInterval) _c_interval;
100 int _ext_index;
101 std::string _ext_name;
102 double _ext_duration;
103 bool _ext_open_ended;
104 double _rel_time;
105 RelativeStart _rel_to;
106 int _actual_begin_time;
107 };
108
109 enum PlaybackEventType {
110 PET_begin,
111 PET_end,
112 PET_instant
113 };
114
115 class PlaybackEvent {
116 public:
117 INLINE PlaybackEvent(int time, int n, PlaybackEventType type);
118 INLINE bool operator < (const PlaybackEvent &other) const;
119 int _time;
120 int _n;
121 PlaybackEventType _type;
122 PlaybackEvent *_begin_event;
123 };
124
125 class EventQueueEntry {
126 public:
127 INLINE EventQueueEntry(int n, EventType event_type, int time);
128 int _n;
129 EventType _event_type;
130 int _time;
131 };
132
135 // ActiveEvents must be either a list or a vector--something that preserves
136 // order--so we can call priv_step() on the currently active intervals in
137 // the order they were encountered.
140
141 INLINE int double_to_int_time(double t) const;
142 INLINE double int_to_double_time(int time) const;
143
144 void clear_events();
145 void do_event_forward(PlaybackEvent *event, ActiveEvents &new_active,
146 bool is_initial);
147 void finish_events_forward(int now, ActiveEvents &new_active);
148 void do_event_reverse(PlaybackEvent *event, ActiveEvents &new_active,
149 bool is_initial);
150 void finish_events_reverse(int now, ActiveEvents &new_active);
151
152 void enqueue_event(int n, CInterval::EventType event_type, bool is_initial,
153 int time = 0);
154 void enqueue_self_event(CInterval::EventType event_type, double t = 0.0);
155 void enqueue_done_event();
156 bool service_event_queue();
157
158 int recompute_level(int n, int level_begin, int &level_end);
159 int get_begin_time(const IntervalDef &def, int level_begin,
160 int previous_begin, int previous_end);
161
162 void write_event_desc(std::ostream &out, const IntervalDef &def,
163 int &extra_indent_level) const;
164
165
166 double _precision;
167 Defs _defs;
168 int _current_nesting_level;
169
170 PlaybackEvents _events;
171 ActiveEvents _active;
172 int _end_time;
173
174 size_t _next_event_index;
175 bool _processing_events;
176
177 // This is the queue of events that have occurred due to a recent
178 // priv_initialize(), priv_step(), etc., but have not yet been serviced, due
179 // to an embedded external (e.g. Python) interval that the scripting
180 // language must service. This queue should be considered precious, and
181 // should never be arbitrarily flushed without servicing all of its events.
182 EventQueue _event_queue;
183
184public:
185 static TypeHandle get_class_type() {
186 return _type_handle;
187 }
188 static void init_type() {
189 CInterval::init_type();
190 register_type(_type_handle, "CMetaInterval",
191 CInterval::get_class_type());
192 }
193 virtual TypeHandle get_type() const {
194 return get_class_type();
195 }
196 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
197
198private:
199 static TypeHandle _type_handle;
200};
201
202#include "cMetaInterval.I"
203
204#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The base class for timeline components.
Definition cInterval.h:36
virtual void priv_reverse_finalize()
Called generally following a priv_reverse_initialize(), this indicates the interval should set itself...
virtual void priv_step(double t)
Advances the time on the interval.
virtual void priv_initialize(double t)
This replaces the first call to priv_step(), and indicates that the interval has just begun.
virtual void priv_reverse_initialize(double t)
Similar to priv_initialize(), but this is called when the interval is being played backwards; it indi...
virtual void priv_finalize()
This is called to stop an interval, forcing it to whatever state it would be after it played all the ...
virtual void priv_reverse_instant()
This is called in lieu of priv_reverse_initialize() .
virtual void priv_interrupt()
This is called while the interval is playing to indicate that it is about to be interrupted; that is,...
virtual void priv_instant()
This is called in lieu of priv_initialize() .
This interval contains a list of nested intervals, each of which has its own begin and end times.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
This is our own Panda specialization on the default STL deque.
Definition pdeque.h:36
This is our own Panda specialization on the default STL list.
Definition plist.h:35
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.
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(),...