Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

265 lines
5.2 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef DEMOFORMAT_H
  7. #define DEMOFORMAT_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "mathlib/vector.h"
  12. #include "utlvector.h"
  13. #include "tier0/platform.h"
  14. #define DEMO_HEADER_ID "HL2DEMO"
  15. #define DEMO_PROTOCOL 4
  16. #if !defined( MAX_OSPATH )
  17. #define MAX_OSPATH 260 // max length of a filesystem pathname
  18. #endif
  19. // Demo messages
  20. enum
  21. {
  22. // it's a startup message, process as fast as possible
  23. dem_signon = 1,
  24. // it's a normal network packet that we stored off
  25. dem_packet,
  26. // sync client clock to demo tick
  27. dem_synctick,
  28. // console command
  29. dem_consolecmd,
  30. // user input command
  31. dem_usercmd,
  32. // network data tables
  33. dem_datatables,
  34. // end of time.
  35. dem_stop,
  36. // a blob of binary data understood by a callback function
  37. dem_customdata,
  38. dem_stringtables,
  39. // Last command
  40. dem_lastcmd = dem_stringtables
  41. };
  42. struct demoheader_t
  43. {
  44. char demofilestamp[8]; // Should be HL2DEMO
  45. int demoprotocol; // Should be DEMO_PROTOCOL
  46. int networkprotocol; // Should be PROTOCOL_VERSION
  47. char servername[ MAX_OSPATH ]; // Name of server
  48. char clientname[ MAX_OSPATH ]; // Name of client who recorded the game
  49. char mapname[ MAX_OSPATH ]; // Name of map
  50. char gamedirectory[ MAX_OSPATH ]; // Name of game directory (com_gamedir)
  51. float playback_time; // Time of track
  52. int playback_ticks; // # of ticks in track
  53. int playback_frames; // # of frames in track
  54. int signonlength; // length of sigondata in bytes
  55. };
  56. inline void ByteSwap_demoheader_t( demoheader_t &swap )
  57. {
  58. swap.demoprotocol = LittleDWord( swap.demoprotocol );
  59. swap.networkprotocol = LittleDWord( swap.networkprotocol );
  60. LittleFloat( &swap.playback_time, &swap.playback_time );
  61. swap.playback_ticks = LittleDWord( swap.playback_ticks );
  62. swap.playback_frames = LittleDWord( swap.playback_frames );
  63. swap.signonlength = LittleDWord( swap.signonlength );
  64. }
  65. #define FDEMO_NORMAL 0
  66. #define FDEMO_USE_ORIGIN2 (1<<0)
  67. #define FDEMO_USE_ANGLES2 (1<<1)
  68. #define FDEMO_NOINTERP (1<<2) // don't interpolate between this an last view
  69. struct democmdinfo_t
  70. {
  71. // Default constructor
  72. democmdinfo_t() {}
  73. struct Split_t
  74. {
  75. Split_t()
  76. {
  77. flags = FDEMO_NORMAL;
  78. viewOrigin.Init();
  79. viewAngles.Init();
  80. localViewAngles.Init();
  81. // Resampled origin/angles
  82. viewOrigin2.Init();
  83. viewAngles2.Init();
  84. localViewAngles2.Init();
  85. }
  86. Split_t& operator=(const Split_t& src )
  87. {
  88. if ( this == &src )
  89. return *this;
  90. flags = src.flags;
  91. viewOrigin = src.viewOrigin;
  92. viewAngles = src.viewAngles;
  93. localViewAngles = src.localViewAngles;
  94. viewOrigin2 = src.viewOrigin2;
  95. viewAngles2 = src.viewAngles2;
  96. localViewAngles2 = src.localViewAngles2;
  97. return *this;
  98. }
  99. const Vector& GetViewOrigin()
  100. {
  101. if ( flags & FDEMO_USE_ORIGIN2 )
  102. {
  103. return viewOrigin2;
  104. }
  105. return viewOrigin;
  106. }
  107. const QAngle& GetViewAngles()
  108. {
  109. if ( flags & FDEMO_USE_ANGLES2 )
  110. {
  111. return viewAngles2;
  112. }
  113. return viewAngles;
  114. }
  115. const QAngle& GetLocalViewAngles()
  116. {
  117. if ( flags & FDEMO_USE_ANGLES2 )
  118. {
  119. return localViewAngles2;
  120. }
  121. return localViewAngles;
  122. }
  123. void Reset( void )
  124. {
  125. flags = 0;
  126. viewOrigin2 = viewOrigin;
  127. viewAngles2 = viewAngles;
  128. localViewAngles2 = localViewAngles;
  129. }
  130. int flags;
  131. // original origin/viewangles
  132. Vector viewOrigin;
  133. QAngle viewAngles;
  134. QAngle localViewAngles;
  135. // Resampled origin/viewangles
  136. Vector viewOrigin2;
  137. QAngle viewAngles2;
  138. QAngle localViewAngles2;
  139. };
  140. void Reset( void )
  141. {
  142. for ( int i = 0; i < MAX_SPLITSCREEN_CLIENTS; ++i )
  143. {
  144. u[ i ].Reset();
  145. }
  146. }
  147. Split_t u[ MAX_SPLITSCREEN_CLIENTS ];
  148. };
  149. struct demosmoothing_t
  150. {
  151. demosmoothing_t()
  152. {
  153. file_offset = 0;
  154. frametick = 0;
  155. selected = false;
  156. samplepoint = false;
  157. vecmoved.Init();
  158. angmoved.Init();
  159. targetpoint = false;
  160. vectarget.Init();
  161. }
  162. demosmoothing_t& operator=(const demosmoothing_t& src )
  163. {
  164. if ( this == &src )
  165. return *this;
  166. file_offset = src.file_offset;
  167. frametick = src.frametick;
  168. selected = src.selected;
  169. samplepoint = src.samplepoint;
  170. vecmoved = src.vecmoved;
  171. angmoved = src.angmoved;
  172. targetpoint = src.targetpoint;
  173. vectarget = src.vectarget;
  174. info = src.info;
  175. return *this;
  176. }
  177. int file_offset;
  178. int frametick;
  179. bool selected;
  180. // For moved sample points
  181. bool samplepoint;
  182. Vector vecmoved;
  183. QAngle angmoved;
  184. bool targetpoint;
  185. Vector vectarget;
  186. democmdinfo_t info;
  187. };
  188. struct CSmoothingContext
  189. {
  190. CSmoothingContext()
  191. {
  192. active = false;
  193. filename[ 0 ] = 0;
  194. m_nFirstSelectableSample = 0;
  195. }
  196. CSmoothingContext& operator=(const CSmoothingContext& src )
  197. {
  198. if ( this == &src )
  199. return *this;
  200. active = src.active;
  201. Q_strncpy( filename, src.filename, sizeof( filename ) );
  202. smooth.RemoveAll();
  203. int c = src.smooth.Count();
  204. int i;
  205. for ( i = 0; i < c; i++ )
  206. {
  207. demosmoothing_t newitem;
  208. newitem = src.smooth[ i ];
  209. smooth.AddToTail( newitem );
  210. }
  211. m_nFirstSelectableSample = src.m_nFirstSelectableSample;
  212. return *this;
  213. }
  214. bool active;
  215. char filename[ 512 ];
  216. CUtlVector< demosmoothing_t > smooth;
  217. int m_nFirstSelectableSample;
  218. };
  219. #endif // DEMOFORMAT_H