Panda3D
pStatFrameData.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 pStatFrameData.I
10  * @author drose
11  * @date 2000-07-10
12  */
13 
14 /**
15  * Returns true if there are no time events in the frame data, false
16  * otherwise.
17  */
18 INLINE bool PStatFrameData::
19 is_time_empty() const {
20  return _time_data.empty();
21 }
22 
23 /**
24  * Returns true if there are no levels indicated in the frame data, false
25  * otherwise.
26  */
27 INLINE bool PStatFrameData::
28 is_level_empty() const {
29  return _level_data.empty();
30 }
31 
32 /**
33  * Returns true if the FrameData has no time or level data.
34  */
35 INLINE bool PStatFrameData::
36 is_empty() const {
37  return is_time_empty() && is_level_empty();
38 }
39 
40 /**
41  * Removes all the data points from the frame data, in preparation for
42  * building up a new frame's worth.
43  */
44 INLINE void PStatFrameData::
45 clear() {
46  _time_data.clear();
47  _level_data.clear();
48 }
49 
50 /**
51  * Exchanges the data in this object with the data in the other.
52  */
53 INLINE void PStatFrameData::
55  _time_data.swap(other._time_data);
56  _level_data.swap(other._level_data);
57 }
58 
59 /**
60  * Adds a 'start collector' data point to the frame data.
61  */
62 INLINE void PStatFrameData::
63 add_start(int index, double time) {
64 #ifdef _DEBUG
65  nassertv((index & 0x7fff) == index);
66 #endif
67  DataPoint dp;
68  dp._index = index;
69  dp._value = time;
70  _time_data.push_back(dp);
71 }
72 
73 /**
74  * Adds a 'stop collector' data point to the frame data.
75  */
76 INLINE void PStatFrameData::
77 add_stop(int index, double time) {
78 #ifdef _DEBUG
79  nassertv((index & 0x7fff) == index);
80 #endif
81  DataPoint dp;
82  dp._index = index | 0x8000;
83  dp._value = time;
84  _time_data.push_back(dp);
85 }
86 
87 /**
88  * Adds a particular level value associated with a given collector to the
89  * frame data.
90  */
91 INLINE void PStatFrameData::
92 add_level(int index, double level) {
93 #ifdef _DEBUG
94  nassertv((index & 0xffff) == index);
95 #endif
96  DataPoint dp;
97  dp._index = index;
98  dp._value = level;
99  _level_data.push_back(dp);
100 }
101 
102 /**
103  * Returns the time of the first data point in the frame data. This will
104  * generally be the time of the start of the frame.
105  */
106 INLINE double PStatFrameData::
107 get_start() const {
108  if (is_empty()) {
109  return 0.0;
110  }
111 
112  return _time_data.front()._value;
113 }
114 
115 /**
116  * Returns the time of the last data point in the frame data. This will
117  * generally be the time of the end of the frame.
118  */
119 INLINE double PStatFrameData::
120 get_end() const {
121  nassertr(!is_empty(), 0.0);
122 
123  return _time_data.back()._value;
124 }
125 
126 /**
127  * Returns the total time elapsed for the frame.
128  */
129 INLINE double PStatFrameData::
130 get_net_time() const {
131  nassertr(!is_empty(), 0.0);
132 
133  return _time_data.back()._value - _time_data.front()._value;
134 }
135 
136 /**
137  * Returns the number of individual events stored in the FrameData.
138  */
139 INLINE size_t PStatFrameData::
140 get_num_events() const {
141  return _time_data.size();
142 }
143 
144 /**
145  * Returns the index of the collector associated with the nth event.
146  */
147 INLINE int PStatFrameData::
148 get_time_collector(size_t n) const {
149  nassertr(n < _time_data.size(), 0);
150  return _time_data[n]._index & 0x7fff;
151 }
152 
153 /**
154  * Returns true if the nth event represents a start event, or false if it
155  * represents a stop event.
156  */
157 INLINE bool PStatFrameData::
158 is_start(size_t n) const {
159  nassertr(n < _time_data.size(), 0);
160  return (_time_data[n]._index & 0x8000) == 0;
161 }
162 
163 /**
164  * Returns the timestamp of the nth event, in seconds elapsed since some
165  * undefined epoch (which is guaranteed to be shared among all events returned
166  * from a given client).
167  */
168 INLINE double PStatFrameData::
169 get_time(size_t n) const {
170  nassertr(n < _time_data.size(), 0);
171  return _time_data[n]._value;
172 }
173 
174 /**
175  * Returns the number of individual level values stored in the FrameData.
176  */
177 INLINE size_t PStatFrameData::
178 get_num_levels() const {
179  return _level_data.size();
180 }
181 
182 /**
183  * Returns the index of the collector associated with the nth level value.
184  */
185 INLINE int PStatFrameData::
186 get_level_collector(size_t n) const {
187  nassertr(n < _level_data.size(), 0);
188  return _level_data[n]._index;
189 }
190 
191 /**
192  * Returns the height of the nth level value.
193  */
194 INLINE double PStatFrameData::
195 get_level(size_t n) const {
196  nassertr(n < _level_data.size(), 0);
197  return _level_data[n]._value;
198 }
199 
200 /**
201  * Orders the data points by time.
202  */
203 INLINE bool PStatFrameData::DataPoint::
204 operator < (const PStatFrameData::DataPoint &other) const {
205  return _value < other._value;
206 }
int get_level_collector(size_t n) const
Returns the index of the collector associated with the nth level value.
bool is_level_empty() const
Returns true if there are no levels indicated in the frame data, false otherwise.
double get_level(size_t n) const
Returns the height of the nth level value.
void swap(PStatFrameData &other)
Exchanges the data in this object with the data in the other.
void add_start(int index, double time)
Adds a 'start collector' data point to the frame data.
Contains the raw timing and level data for a single frame.
double get_time(size_t n) const
Returns the timestamp of the nth event, in seconds elapsed since some undefined epoch (which is guara...
size_t get_num_levels() const
Returns the number of individual level values stored in the FrameData.
int get_time_collector(size_t n) const
Returns the index of the collector associated with the nth event.
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.
bool is_start(size_t n) const
Returns true if the nth event represents a start event, or false if it represents a stop event.
void add_stop(int index, double time)
Adds a 'stop collector' data point to the frame data.
double get_end() const
Returns the time of the last data point in the frame data.
size_t get_num_events() const
Returns the number of individual events stored in the FrameData.
void clear()
Removes all the data points from the frame data, in preparation for building up a new frame's worth.
void add_level(int index, double level)
Adds a particular level value associated with a given collector to the frame data.
double get_start() const
Returns the time of the first data point in the frame data.
double get_net_time() const
Returns the total time elapsed for the frame.