pStatFrameData.I 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. // Filename: pStatFrameData.I
  2. // Created by: drose (10Jul00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: PStatFrameData::is_time_empty
  20. // Access: Public
  21. // Description: Returns true if there are no time events in the frame
  22. // data, false otherwise.
  23. ////////////////////////////////////////////////////////////////////
  24. INLINE bool PStatFrameData::
  25. is_time_empty() const {
  26. return _time_data.empty();
  27. }
  28. ////////////////////////////////////////////////////////////////////
  29. // Function: PStatFrameData::is_level_empty
  30. // Access: Public
  31. // Description: Returns true if there are no levels indicated in the
  32. // frame data, false otherwise.
  33. ////////////////////////////////////////////////////////////////////
  34. INLINE bool PStatFrameData::
  35. is_level_empty() const {
  36. return _level_data.empty();
  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. // Function: PStatFrameData::clear
  50. // Access: Public
  51. // Description: Removes all the data points from the frame data, in
  52. // preparation for building up a new frame's worth.
  53. ////////////////////////////////////////////////////////////////////
  54. INLINE void PStatFrameData::
  55. clear() {
  56. _time_data.clear();
  57. _level_data.clear();
  58. }
  59. ////////////////////////////////////////////////////////////////////
  60. // Function: PStatFrameData::add_start
  61. // Access: Public
  62. // Description: Adds a 'start collector' data point to the frame
  63. // data.
  64. ////////////////////////////////////////////////////////////////////
  65. INLINE void PStatFrameData::
  66. add_start(int index, float time) {
  67. #ifdef _DEBUG
  68. nassertv((index & 0x7fff) == index);
  69. #endif
  70. DataPoint dp;
  71. dp._index = index;
  72. dp._value = time;
  73. _time_data.push_back(dp);
  74. }
  75. ////////////////////////////////////////////////////////////////////
  76. // Function: PStatFrameData::add_stop
  77. // Access: Public
  78. // Description: Adds a 'stop collector' data point to the frame
  79. // data.
  80. ////////////////////////////////////////////////////////////////////
  81. INLINE void PStatFrameData::
  82. add_stop(int index, float time) {
  83. #ifdef _DEBUG
  84. nassertv((index & 0x7fff) == index);
  85. #endif
  86. DataPoint dp;
  87. dp._index = index | 0x8000;
  88. dp._value = time;
  89. _time_data.push_back(dp);
  90. }
  91. ////////////////////////////////////////////////////////////////////
  92. // Function: PStatFrameData::add_level
  93. // Access: Public
  94. // Description: Adds a particular level value associated with a given
  95. // collector to the frame data.
  96. ////////////////////////////////////////////////////////////////////
  97. INLINE void PStatFrameData::
  98. add_level(int index, float level) {
  99. #ifdef _DEBUG
  100. nassertv((index & 0xffff) == index);
  101. #endif
  102. DataPoint dp;
  103. dp._index = index;
  104. dp._value = level;
  105. _level_data.push_back(dp);
  106. }
  107. ////////////////////////////////////////////////////////////////////
  108. // Function: PStatFrameData::get_start
  109. // Access: Public
  110. // Description: Returns the time of the first data point in the frame
  111. // data. This will generally be the time of the start
  112. // of the frame.
  113. ////////////////////////////////////////////////////////////////////
  114. INLINE float PStatFrameData::
  115. get_start() const {
  116. if (is_empty()) {
  117. return 0.0;
  118. }
  119. return _time_data.front()._value;
  120. }
  121. ////////////////////////////////////////////////////////////////////
  122. // Function: PStatFrameData::get_end
  123. // Access: Public
  124. // Description: Returns the time of the last data point in the frame
  125. // data. This will generally be the time of the end
  126. // of the frame.
  127. ////////////////////////////////////////////////////////////////////
  128. INLINE float PStatFrameData::
  129. get_end() const {
  130. nassertr(!is_empty(), 0.0);
  131. return _time_data.back()._value;
  132. }
  133. ////////////////////////////////////////////////////////////////////
  134. // Function: PStatFrameData::get_net_time
  135. // Access: Public
  136. // Description: Returns the total time elapsed for the frame.
  137. ////////////////////////////////////////////////////////////////////
  138. INLINE float PStatFrameData::
  139. get_net_time() const {
  140. nassertr(!is_empty(), 0.0);
  141. return _time_data.back()._value - _time_data.front()._value;
  142. }
  143. ////////////////////////////////////////////////////////////////////
  144. // Function: PStatFrameData::get_num_events
  145. // Access: Public
  146. // Description: Returns the number of individual events stored in the
  147. // FrameData.
  148. ////////////////////////////////////////////////////////////////////
  149. INLINE int PStatFrameData::
  150. get_num_events() const {
  151. return _time_data.size();
  152. }
  153. ////////////////////////////////////////////////////////////////////
  154. // Function: PStatFrameData::get_time_collector
  155. // Access: Public
  156. // Description: Returns the index of the collector associated with
  157. // the nth event.
  158. ////////////////////////////////////////////////////////////////////
  159. INLINE int PStatFrameData::
  160. get_time_collector(int n) const {
  161. nassertr(n >= 0 && n < (int)_time_data.size(), 0);
  162. return _time_data[n]._index & 0x7fff;
  163. }
  164. ////////////////////////////////////////////////////////////////////
  165. // Function: PStatFrameData::is_start
  166. // Access: Public
  167. // Description: Returns true if the nth event represents a start
  168. // event, or false if it represents a stop event.
  169. ////////////////////////////////////////////////////////////////////
  170. INLINE bool PStatFrameData::
  171. is_start(int n) const {
  172. nassertr(n >= 0 && n < (int)_time_data.size(), 0);
  173. return (_time_data[n]._index & 0x8000) == 0;
  174. }
  175. ////////////////////////////////////////////////////////////////////
  176. // Function: PStatFrameData::get_time
  177. // Access: Public
  178. // Description: Returns the timestamp of the nth event, in seconds
  179. // elapsed since some undefined epoch (which is
  180. // guaranteed to be shared among all events returned
  181. // from a given client).
  182. ////////////////////////////////////////////////////////////////////
  183. INLINE float PStatFrameData::
  184. get_time(int n) const {
  185. nassertr(n >= 0 && n < (int)_time_data.size(), 0);
  186. return _time_data[n]._value;
  187. }
  188. ////////////////////////////////////////////////////////////////////
  189. // Function: PStatFrameData::get_num_levels
  190. // Access: Public
  191. // Description: Returns the number of individual level values stored
  192. // in the FrameData.
  193. ////////////////////////////////////////////////////////////////////
  194. INLINE int PStatFrameData::
  195. get_num_levels() const {
  196. return _level_data.size();
  197. }
  198. ////////////////////////////////////////////////////////////////////
  199. // Function: PStatFrameData::get_level_collector
  200. // Access: Public
  201. // Description: Returns the index of the collector associated with
  202. // the nth level value.
  203. ////////////////////////////////////////////////////////////////////
  204. INLINE int PStatFrameData::
  205. get_level_collector(int n) const {
  206. nassertr(n >= 0 && n < (int)_level_data.size(), 0);
  207. return _level_data[n]._index;
  208. }
  209. ////////////////////////////////////////////////////////////////////
  210. // Function: PStatFrameData::get_level
  211. // Access: Public
  212. // Description: Returns the height of the nth level value.
  213. ////////////////////////////////////////////////////////////////////
  214. INLINE float PStatFrameData::
  215. get_level(int n) const {
  216. nassertr(n >= 0 && n < (int)_level_data.size(), 0);
  217. return _level_data[n]._value;
  218. }
  219. ////////////////////////////////////////////////////////////////////
  220. // Function: PStatFrameData::DataPoint::operator <
  221. // Access: Public
  222. // Description: Orders the data points by time.
  223. ////////////////////////////////////////////////////////////////////
  224. INLINE bool PStatFrameData::DataPoint::
  225. operator < (const PStatFrameData::DataPoint &other) const {
  226. return _value < other._value;
  227. }