Panda3D
Loading...
Searching...
No Matches
cMetaInterval.I
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.I
10 * @author drose
11 * @date 2002-08-27
12 */
13
14/**
15 * Indicates the precision with which time measurements are compared. For
16 * numerical accuracy, all floating-point time values are converted to integer
17 * values internally by scaling by the precision factor. The larger the
18 * number given here, the smaller the delta of time that can be
19 * differentiated; the limit is the maximum integer that can be represented in
20 * the system.
21 */
22INLINE void CMetaInterval::
23set_precision(double precision) {
24 _precision = precision;
25 mark_dirty();
26}
27
28/**
29 * Returns the precision with which time measurements are compared. See
30 * set_precision().
31 */
32INLINE double CMetaInterval::
33get_precision() const {
34 return _precision;
35}
36
37/**
38 * Returns the number of interval and push/pop definitions that have been
39 * added to the meta interval.
40 */
42get_num_defs() const {
43 return (int)_defs.size();
44}
45
46/**
47 * Returns the type of the nth interval definition that has been added.
48 */
49INLINE CMetaInterval::DefType CMetaInterval::
50get_def_type(int n) const {
51 nassertr(n >= 0 && n < (int)_defs.size(), DT_c_interval);
52 return _defs[n]._type;
53}
54
55/**
56 * Return the CInterval pointer associated with the nth interval definition.
57 * It is only valid to call this if get_def_type(n) returns DT_c_interval.
58 */
60get_c_interval(int n) const {
61 nassertr(n >= 0 && n < (int)_defs.size(), nullptr);
62 nassertr(_defs[n]._type == DT_c_interval, nullptr);
63 return _defs[n]._c_interval;
64}
65
66/**
67 * Return the external interval index number associated with the nth interval
68 * definition. It is only valid to call this if get_def_type(n) returns
69 * DT_ext_index.
70 */
72get_ext_index(int n) const {
73 nassertr(n >= 0 && n < (int)_defs.size(), -1);
74 nassertr(_defs[n]._type == DT_ext_index, -1);
75 return _defs[n]._ext_index;
76}
77
78/**
79 * Returns true if a recent call to priv_initialize(), priv_step(), or
80 * priv_finalize() has left some external intervals ready to play. If this
81 * returns true, call get_event_index(), get_event_t(), and pop_event() to
82 * retrieve the relevant information.
83 */
84INLINE bool CMetaInterval::
86 return service_event_queue();
87}
88
89/**
90 * If a previous call to is_event_ready() returned true, this returns the
91 * index number (added via add_event_index()) of the external interval that
92 * needs to be played.
93 */
95get_event_index() const {
96 nassertr(!_event_queue.empty(), -1);
97 const EventQueueEntry &entry = _event_queue.front();
98 const IntervalDef &def = _defs[entry._n];
99 nassertr(def._type == DT_ext_index, -1);
100 return def._ext_index;
101}
102
103/**
104 * If a previous call to is_event_ready() returned true, this returns the t
105 * value that should be fed to the given interval.
106 */
107INLINE double CMetaInterval::
108get_event_t() const {
109 nassertr(!_event_queue.empty(), 0.0f);
110 return int_to_double_time(_event_queue.front()._time);
111}
112
113/**
114 * If a previous call to is_event_ready() returned true, this returns the type
115 * of the event (initialize, step, finalize, etc.) for the given interval.
116 */
117INLINE CInterval::EventType CMetaInterval::
118get_event_type() const {
119 nassertr(!_event_queue.empty(), ET_step);
120 return _event_queue.front()._event_type;
121}
122
123/**
124 * Converts from an external double time value or offset in seconds to an
125 * internal integer value or offset.
126 */
127INLINE int CMetaInterval::
128double_to_int_time(double t) const {
129 // Use floor() just in case there are negative values involved.
130 return (int)floor(t * _precision + 0.5);
131}
132
133/**
134 * Converts from an internal integer time value or offset to an external
135 * double time value or offset in seconds.
136 */
137INLINE double CMetaInterval::
138int_to_double_time(int time) const {
139 return (double)time / _precision;
140}
141
142/**
143 *
144 */
145INLINE CMetaInterval::PlaybackEvent::
146PlaybackEvent(int time, int n,
147 CMetaInterval::PlaybackEventType type) :
148 _time(time),
149 _n(n),
150 _type(type)
151{
152 _begin_event = this;
153}
154
155/**
156 *
157 */
158INLINE bool CMetaInterval::PlaybackEvent::
159operator < (const CMetaInterval::PlaybackEvent &other) const {
160 return _time < other._time;
161}
162
163/**
164 *
165 */
166INLINE CMetaInterval::EventQueueEntry::
167EventQueueEntry(int n, CInterval::EventType event_type, int time) :
168 _n(n),
169 _event_type(event_type),
170 _time(time)
171{
172}
The base class for timeline components.
Definition cInterval.h:36
void mark_dirty()
Called by a derived class to indicate the interval has been changed internally and must be recomputed...
EventType get_event_type() const
If a previous call to is_event_ready() returned true, this returns the type of the event (initialize,...
int get_num_defs() const
Returns the number of interval and push/pop definitions that have been added to the meta interval.
double get_event_t() const
If a previous call to is_event_ready() returned true, this returns the t value that should be fed to ...
int get_ext_index(int n) const
Return the external interval index number associated with the nth interval definition.
DefType get_def_type(int n) const
Returns the type of the nth interval definition that has been added.
bool is_event_ready()
Returns true if a recent call to priv_initialize(), priv_step(), or priv_finalize() has left some ext...
CInterval * get_c_interval(int n) const
Return the CInterval pointer associated with the nth interval definition.
double get_precision() const
Returns the precision with which time measurements are compared.
int get_event_index() const
If a previous call to is_event_ready() returned true, this returns the index number (added via add_ev...
void set_precision(double precision)
Indicates the precision with which time measurements are compared.