pStatFrameData.I 8.5 KB

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