Panda3D
 All Classes Functions Variables Enumerations
pStatFrameData.I
1 // Filename: pStatFrameData.I
2 // Created by: drose (10Jul00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: PStatFrameData::is_time_empty
18 // Access: Public
19 // Description: Returns true if there are no time events in the frame
20 // data, false otherwise.
21 ////////////////////////////////////////////////////////////////////
22 INLINE bool PStatFrameData::
23 is_time_empty() const {
24  return _time_data.empty();
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: PStatFrameData::is_level_empty
29 // Access: Public
30 // Description: Returns true if there are no levels indicated in the
31 // frame data, false otherwise.
32 ////////////////////////////////////////////////////////////////////
33 INLINE bool PStatFrameData::
34 is_level_empty() const {
35  return _level_data.empty();
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: PStatFrameData::is_empty
40 // Access: Public
41 // Description: Returns true if the FrameData has no time or level
42 // data.
43 ////////////////////////////////////////////////////////////////////
44 INLINE bool PStatFrameData::
45 is_empty() const {
46  return is_time_empty() && is_level_empty();
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: PStatFrameData::clear
51 // Access: Public
52 // Description: Removes all the data points from the frame data, in
53 // preparation for building up a new frame's worth.
54 ////////////////////////////////////////////////////////////////////
55 INLINE void PStatFrameData::
56 clear() {
57  _time_data.clear();
58  _level_data.clear();
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: PStatFrameData::swap
63 // Access: Public
64 // Description: Exchanges the data in this object with the data in
65 // the other.
66 ////////////////////////////////////////////////////////////////////
67 INLINE void PStatFrameData::
69  _time_data.swap(other._time_data);
70  _level_data.swap(other._level_data);
71 }
72 
73 ////////////////////////////////////////////////////////////////////
74 // Function: PStatFrameData::add_start
75 // Access: Public
76 // Description: Adds a 'start collector' data point to the frame
77 // data.
78 ////////////////////////////////////////////////////////////////////
79 INLINE void PStatFrameData::
80 add_start(int index, double time) {
81 #ifdef _DEBUG
82  nassertv((index & 0x7fff) == index);
83 #endif
84  DataPoint dp;
85  dp._index = index;
86  dp._value = time;
87  _time_data.push_back(dp);
88 }
89 
90 ////////////////////////////////////////////////////////////////////
91 // Function: PStatFrameData::add_stop
92 // Access: Public
93 // Description: Adds a 'stop collector' data point to the frame
94 // data.
95 ////////////////////////////////////////////////////////////////////
96 INLINE void PStatFrameData::
97 add_stop(int index, double time) {
98 #ifdef _DEBUG
99  nassertv((index & 0x7fff) == index);
100 #endif
101  DataPoint dp;
102  dp._index = index | 0x8000;
103  dp._value = time;
104  _time_data.push_back(dp);
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: PStatFrameData::add_level
109 // Access: Public
110 // Description: Adds a particular level value associated with a given
111 // collector to the frame data.
112 ////////////////////////////////////////////////////////////////////
113 INLINE void PStatFrameData::
114 add_level(int index, double level) {
115 #ifdef _DEBUG
116  nassertv((index & 0xffff) == index);
117 #endif
118  DataPoint dp;
119  dp._index = index;
120  dp._value = level;
121  _level_data.push_back(dp);
122 }
123 
124 ////////////////////////////////////////////////////////////////////
125 // Function: PStatFrameData::get_start
126 // Access: Public
127 // Description: Returns the time of the first data point in the frame
128 // data. This will generally be the time of the start
129 // of the frame.
130 ////////////////////////////////////////////////////////////////////
131 INLINE double PStatFrameData::
132 get_start() const {
133  if (is_empty()) {
134  return 0.0;
135  }
136 
137  return _time_data.front()._value;
138 }
139 
140 ////////////////////////////////////////////////////////////////////
141 // Function: PStatFrameData::get_end
142 // Access: Public
143 // Description: Returns the time of the last data point in the frame
144 // data. This will generally be the time of the end
145 // of the frame.
146 ////////////////////////////////////////////////////////////////////
147 INLINE double PStatFrameData::
148 get_end() const {
149  nassertr(!is_empty(), 0.0);
150 
151  return _time_data.back()._value;
152 }
153 
154 ////////////////////////////////////////////////////////////////////
155 // Function: PStatFrameData::get_net_time
156 // Access: Public
157 // Description: Returns the total time elapsed for the frame.
158 ////////////////////////////////////////////////////////////////////
159 INLINE double PStatFrameData::
160 get_net_time() const {
161  nassertr(!is_empty(), 0.0);
162 
163  return _time_data.back()._value - _time_data.front()._value;
164 }
165 
166 ////////////////////////////////////////////////////////////////////
167 // Function: PStatFrameData::get_num_events
168 // Access: Public
169 // Description: Returns the number of individual events stored in the
170 // FrameData.
171 ////////////////////////////////////////////////////////////////////
172 INLINE int PStatFrameData::
173 get_num_events() const {
174  return _time_data.size();
175 }
176 
177 ////////////////////////////////////////////////////////////////////
178 // Function: PStatFrameData::get_time_collector
179 // Access: Public
180 // Description: Returns the index of the collector associated with
181 // the nth event.
182 ////////////////////////////////////////////////////////////////////
183 INLINE int PStatFrameData::
184 get_time_collector(int n) const {
185  nassertr(n >= 0 && n < (int)_time_data.size(), 0);
186  return _time_data[n]._index & 0x7fff;
187 }
188 
189 ////////////////////////////////////////////////////////////////////
190 // Function: PStatFrameData::is_start
191 // Access: Public
192 // Description: Returns true if the nth event represents a start
193 // event, or false if it represents a stop event.
194 ////////////////////////////////////////////////////////////////////
195 INLINE bool PStatFrameData::
196 is_start(int n) const {
197  nassertr(n >= 0 && n < (int)_time_data.size(), 0);
198  return (_time_data[n]._index & 0x8000) == 0;
199 }
200 
201 ////////////////////////////////////////////////////////////////////
202 // Function: PStatFrameData::get_time
203 // Access: Public
204 // Description: Returns the timestamp of the nth event, in seconds
205 // elapsed since some undefined epoch (which is
206 // guaranteed to be shared among all events returned
207 // from a given client).
208 ////////////////////////////////////////////////////////////////////
209 INLINE double PStatFrameData::
210 get_time(int n) const {
211  nassertr(n >= 0 && n < (int)_time_data.size(), 0);
212  return _time_data[n]._value;
213 }
214 
215 ////////////////////////////////////////////////////////////////////
216 // Function: PStatFrameData::get_num_levels
217 // Access: Public
218 // Description: Returns the number of individual level values stored
219 // in the FrameData.
220 ////////////////////////////////////////////////////////////////////
221 INLINE int PStatFrameData::
222 get_num_levels() const {
223  return _level_data.size();
224 }
225 
226 ////////////////////////////////////////////////////////////////////
227 // Function: PStatFrameData::get_level_collector
228 // Access: Public
229 // Description: Returns the index of the collector associated with
230 // the nth level value.
231 ////////////////////////////////////////////////////////////////////
232 INLINE int PStatFrameData::
233 get_level_collector(int n) const {
234  nassertr(n >= 0 && n < (int)_level_data.size(), 0);
235  return _level_data[n]._index;
236 }
237 
238 ////////////////////////////////////////////////////////////////////
239 // Function: PStatFrameData::get_level
240 // Access: Public
241 // Description: Returns the height of the nth level value.
242 ////////////////////////////////////////////////////////////////////
243 INLINE double PStatFrameData::
244 get_level(int n) const {
245  nassertr(n >= 0 && n < (int)_level_data.size(), 0);
246  return _level_data[n]._value;
247 }
248 
249 ////////////////////////////////////////////////////////////////////
250 // Function: PStatFrameData::DataPoint::operator <
251 // Access: Public
252 // Description: Orders the data points by time.
253 ////////////////////////////////////////////////////////////////////
254 INLINE bool PStatFrameData::DataPoint::
255 operator < (const PStatFrameData::DataPoint &other) const {
256  return _value < other._value;
257 }
258 
double get_end() const
Returns the time of the last data point in the frame data.
bool is_empty() const
Returns true if the FrameData has no time or level data.
bool is_time_empty() const
Returns true if there are no time events in the frame data, false otherwise.
int get_time_collector(int n) const
Returns the index of the collector associated with the nth event.
void swap(PStatFrameData &other)
Exchanges the data in this object with the data in the other.
bool is_start(int n) const
Returns true if the nth event represents a start event, or false if it represents a stop event...
void add_start(int index, double time)
Adds a &#39;start collector&#39; data point to the frame data.
double get_level(int n) const
Returns the height of the nth level value.
int get_num_events() const
Returns the number of individual events stored in the FrameData.
double get_start() const
Returns the time of the first data point in the frame data.
Contains the raw timing and level data for a single frame.
double get_net_time() const
Returns the total time elapsed for the frame.
int get_num_levels() const
Returns the number of individual level values stored in the FrameData.
void add_stop(int index, double time)
Adds a &#39;stop collector&#39; data point to the frame data.
void clear()
Removes all the data points from the frame data, in preparation for building up a new frame&#39;s worth...
double get_time(int n) const
Returns the timestamp of the nth event, in seconds elapsed since some undefined epoch (which is guara...
bool is_level_empty() const
Returns true if there are no levels indicated in the frame data, false otherwise. ...
void add_level(int index, double level)
Adds a particular level value associated with a given collector to the frame data.
int get_level_collector(int n) const
Returns the index of the collector associated with the nth level value.