forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcMetaInterval.I
More file actions
172 lines (157 loc) · 4.54 KB
/
cMetaInterval.I
File metadata and controls
172 lines (157 loc) · 4.54 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
/**
* 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 cMetaInterval.I
* @author drose
* @date 2002-08-27
*/
/**
* Indicates the precision with which time measurements are compared. For
* numerical accuracy, all floating-point time values are converted to integer
* values internally by scaling by the precision factor. The larger the
* number given here, the smaller the delta of time that can be
* differentiated; the limit is the maximum integer that can be represented in
* the system.
*/
INLINE void CMetaInterval::
set_precision(double precision) {
_precision = precision;
mark_dirty();
}
/**
* Returns the precision with which time measurements are compared. See
* set_precision().
*/
INLINE double CMetaInterval::
get_precision() const {
return _precision;
}
/**
* Returns the number of interval and push/pop definitions that have been
* added to the meta interval.
*/
INLINE int CMetaInterval::
get_num_defs() const {
return (int)_defs.size();
}
/**
* Returns the type of the nth interval definition that has been added.
*/
INLINE CMetaInterval::DefType CMetaInterval::
get_def_type(int n) const {
nassertr(n >= 0 && n < (int)_defs.size(), DT_c_interval);
return _defs[n]._type;
}
/**
* Return the CInterval pointer associated with the nth interval definition.
* It is only valid to call this if get_def_type(n) returns DT_c_interval.
*/
INLINE CInterval *CMetaInterval::
get_c_interval(int n) const {
nassertr(n >= 0 && n < (int)_defs.size(), nullptr);
nassertr(_defs[n]._type == DT_c_interval, nullptr);
return _defs[n]._c_interval;
}
/**
* Return the external interval index number associated with the nth interval
* definition. It is only valid to call this if get_def_type(n) returns
* DT_ext_index.
*/
INLINE int CMetaInterval::
get_ext_index(int n) const {
nassertr(n >= 0 && n < (int)_defs.size(), -1);
nassertr(_defs[n]._type == DT_ext_index, -1);
return _defs[n]._ext_index;
}
/**
* Returns true if a recent call to priv_initialize(), priv_step(), or
* priv_finalize() has left some external intervals ready to play. If this
* returns true, call get_event_index(), get_event_t(), and pop_event() to
* retrieve the relevant information.
*/
INLINE bool CMetaInterval::
is_event_ready() {
return service_event_queue();
}
/**
* If a previous call to is_event_ready() returned true, this returns the
* index number (added via add_event_index()) of the external interval that
* needs to be played.
*/
INLINE int CMetaInterval::
get_event_index() const {
nassertr(!_event_queue.empty(), -1);
const EventQueueEntry &entry = _event_queue.front();
const IntervalDef &def = _defs[entry._n];
nassertr(def._type == DT_ext_index, -1);
return def._ext_index;
}
/**
* If a previous call to is_event_ready() returned true, this returns the t
* value that should be fed to the given interval.
*/
INLINE double CMetaInterval::
get_event_t() const {
nassertr(!_event_queue.empty(), 0.0f);
return int_to_double_time(_event_queue.front()._time);
}
/**
* If a previous call to is_event_ready() returned true, this returns the type
* of the event (initialize, step, finalize, etc.) for the given interval.
*/
INLINE CInterval::EventType CMetaInterval::
get_event_type() const {
nassertr(!_event_queue.empty(), ET_step);
return _event_queue.front()._event_type;
}
/**
* Converts from an external double time value or offset in seconds to an
* internal integer value or offset.
*/
INLINE int CMetaInterval::
double_to_int_time(double t) const {
// Use floor() just in case there are negative values involved.
return (int)floor(t * _precision + 0.5);
}
/**
* Converts from an internal integer time value or offset to an external
* double time value or offset in seconds.
*/
INLINE double CMetaInterval::
int_to_double_time(int time) const {
return (double)time / _precision;
}
/**
*
*/
INLINE CMetaInterval::PlaybackEvent::
PlaybackEvent(int time, int n,
CMetaInterval::PlaybackEventType type) :
_time(time),
_n(n),
_type(type)
{
_begin_event = this;
}
/**
*
*/
INLINE bool CMetaInterval::PlaybackEvent::
operator < (const CMetaInterval::PlaybackEvent &other) const {
return _time < other._time;
}
/**
*
*/
INLINE CMetaInterval::EventQueueEntry::
EventQueueEntry(int n, CInterval::EventType event_type, int time) :
_n(n),
_event_type(event_type),
_time(time)
{
}