internal_highlevel.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /////////////////////////////////////////////////////////////////////////EA-V1
  19. // $File: //depot/GeneralsMD/Staging/code/Libraries/Source/profile/internal_highlevel.h $
  20. // $Author: mhoffe $
  21. // $Revision: #2 $
  22. // $DateTime: 2003/08/14 13:43:29 $
  23. //
  24. // ©2003 Electronic Arts
  25. //
  26. // High level profiling (internal header)
  27. //////////////////////////////////////////////////////////////////////////////
  28. #ifdef _MSC_VER
  29. # pragma once
  30. #endif
  31. #ifndef INTERNAL_HIGHLEVEL_H // Include guard
  32. #define INTERNAL_HIGHLEVEL_H
  33. /// an internal high level profile ID
  34. class ProfileId
  35. {
  36. ProfileId(const ProfileId&);
  37. ProfileId& operator=(const ProfileId&);
  38. public:
  39. /**
  40. Creates a new high level profile ID.
  41. \param name profile name
  42. \param descr descriptive name
  43. \param unit unit name
  44. \param precision number of decimal places to show
  45. \param exp10 10 base exponent (used for scaleing)
  46. */
  47. ProfileId(const char *name, const char *descr, const char *unit, int precision, int exp10);
  48. /**
  49. Retrieves the first profile ID.
  50. \return first profile ID
  51. */
  52. static ProfileId *GetFirst(void) { return first; }
  53. /**
  54. Retrieves next profile ID.
  55. \return next profile ID, NULL if none
  56. */
  57. ProfileId *GetNext(void) const { return m_next; }
  58. /**
  59. Retrieves name of the profile ID.
  60. \return profile ID name
  61. */
  62. const char *GetName(void) const { return m_name; }
  63. /**
  64. Retrieves unit name of the profile ID.
  65. \return profile ID unit name
  66. */
  67. const char *GetUnit(void) const { return m_unit?m_unit:""; }
  68. /**
  69. Retrieves description of the profile ID.
  70. \return profile description
  71. */
  72. const char *GetDescr(void) const { return m_descr?m_descr:""; }
  73. /**
  74. Increments the profile value.
  75. \param add add value
  76. */
  77. void Increment(double add);
  78. /**
  79. Sets a new maximum value.
  80. \param max new maximum value
  81. */
  82. void Maximum(double max);
  83. /**
  84. Returns current value, internally resetting it.
  85. \return current value
  86. */
  87. double GetCurrentValue(void)
  88. {
  89. double help=m_curVal;
  90. m_curVal=0.;
  91. return help;
  92. }
  93. /**
  94. Returns total value
  95. \return total value
  96. */
  97. double GetTotalValue(void) const
  98. {
  99. return m_totalVal;
  100. }
  101. /**
  102. Returns value at the given frame.
  103. \param frame frame number
  104. \param value value at frame
  105. \return true if frame found, false if not
  106. */
  107. bool GetFrameValue(unsigned frame, double &value) const
  108. {
  109. if (frame<(unsigned)m_firstFrame||
  110. frame>=(unsigned)curFrame)
  111. return false;
  112. value=m_recFrameVal[frame-m_firstFrame];
  113. return true;
  114. }
  115. /**
  116. Translate given numeric value into a string, using an internal temp buffer.
  117. \param v value
  118. \return given numeric value as string
  119. */
  120. const char *AsString(double v) const;
  121. /**
  122. Shutdown function.
  123. */
  124. static void Shutdown(void);
  125. /**
  126. Starts frame based profiling, starts a new frame.
  127. */
  128. static int FrameStart(void);
  129. /**
  130. Ends frame based profiling.
  131. */
  132. static void FrameEnd(int which, int mixIndex);
  133. /**
  134. Clears all total values.
  135. */
  136. static void ClearTotals(void)
  137. {
  138. for (ProfileId *cur=first;cur;cur=cur->m_next)
  139. cur->m_totalVal=0.;
  140. }
  141. private:
  142. /**
  143. ProfileId's can't be destructed.
  144. */
  145. ~ProfileId() {}
  146. enum
  147. {
  148. /// # of simultaneous frame recordings
  149. MAX_FRAME_RECORDS = 4,
  150. /// size of internal string buffer
  151. STRING_BUFFER_SIZE = 1024
  152. };
  153. /// possible value modes
  154. enum ValueMode
  155. {
  156. Unknown,
  157. ModeIncrement,
  158. ModeMaximum
  159. };
  160. /// first profile ID
  161. static ProfileId *first;
  162. /// next profile ID
  163. ProfileId *m_next;
  164. /// profile name
  165. char *m_name;
  166. /// profile description
  167. char *m_descr;
  168. /// profile unit
  169. char *m_unit;
  170. /// number of decimal places to show
  171. int m_precision;
  172. /// 10 base exponent (used for scaleing)
  173. int m_exp10;
  174. /// current value
  175. double m_curVal;
  176. /// total value
  177. double m_totalVal;
  178. /// frame values
  179. double m_frameVal[MAX_FRAME_RECORDS];
  180. /// list of recorded frame values
  181. double *m_recFrameVal;
  182. /// index of first recorded frame
  183. int m_firstFrame;
  184. /// value mode
  185. ValueMode m_valueMode;
  186. /// current frame
  187. static int curFrame;
  188. /// bit mask, currently recording which cur[] entries?
  189. static unsigned frameRecordMask;
  190. /// internal string buffer
  191. static char stringBuf[STRING_BUFFER_SIZE];
  192. /// next unused char in string buffer
  193. static unsigned stringBufUnused;
  194. };
  195. #endif // INTERNAL_HIGHLEVEL_H