Team Fortress 2 Source Code as on 22/4/2020
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.

250 lines
5.0 KiB

  1. //========= Copyright 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 3
  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. dem_stringtables,
  37. // Last command
  38. dem_lastcmd = dem_stringtables
  39. };
  40. struct demoheader_t
  41. {
  42. char demofilestamp[8]; // Should be HL2DEMO
  43. int demoprotocol; // Should be DEMO_PROTOCOL
  44. int networkprotocol; // Should be PROTOCOL_VERSION
  45. char servername[ MAX_OSPATH ]; // Name of server
  46. char clientname[ MAX_OSPATH ]; // Name of client who recorded the game
  47. char mapname[ MAX_OSPATH ]; // Name of map
  48. char gamedirectory[ MAX_OSPATH ]; // Name of game directory (com_gamedir)
  49. float playback_time; // Time of track
  50. int playback_ticks; // # of ticks in track
  51. int playback_frames; // # of frames in track
  52. int signonlength; // length of sigondata in bytes
  53. };
  54. inline void ByteSwap_demoheader_t( demoheader_t &swap )
  55. {
  56. swap.demoprotocol = LittleDWord( swap.demoprotocol );
  57. swap.networkprotocol = LittleDWord( swap.networkprotocol );
  58. LittleFloat( &swap.playback_time, &swap.playback_time );
  59. swap.playback_ticks = LittleDWord( swap.playback_ticks );
  60. swap.playback_frames = LittleDWord( swap.playback_frames );
  61. swap.signonlength = LittleDWord( swap.signonlength );
  62. }
  63. #define FDEMO_NORMAL 0
  64. #define FDEMO_USE_ORIGIN2 (1<<0)
  65. #define FDEMO_USE_ANGLES2 (1<<1)
  66. #define FDEMO_NOINTERP (1<<2) // don't interpolate between this an last view
  67. struct democmdinfo_t
  68. {
  69. // Default constructor
  70. democmdinfo_t()
  71. {
  72. flags = FDEMO_NORMAL;
  73. viewOrigin.Init();
  74. viewAngles.Init();
  75. localViewAngles.Init();
  76. // Resampled origin/angles
  77. viewOrigin2.Init();
  78. viewAngles2.Init();
  79. localViewAngles2.Init();
  80. }
  81. // Copy constructor
  82. // Assignment
  83. democmdinfo_t& operator=(const democmdinfo_t& src )
  84. {
  85. if ( this == &src )
  86. return *this;
  87. flags = src.flags;
  88. viewOrigin = src.viewOrigin;
  89. viewAngles = src.viewAngles;
  90. localViewAngles = src.localViewAngles;
  91. viewOrigin2 = src.viewOrigin2;
  92. viewAngles2 = src.viewAngles2;
  93. localViewAngles2 = src.localViewAngles2;
  94. return *this;
  95. }
  96. const Vector& GetViewOrigin()
  97. {
  98. if ( flags & FDEMO_USE_ORIGIN2 )
  99. {
  100. return viewOrigin2;
  101. }
  102. return viewOrigin;
  103. }
  104. const QAngle& GetViewAngles()
  105. {
  106. if ( flags & FDEMO_USE_ANGLES2 )
  107. {
  108. return viewAngles2;
  109. }
  110. return viewAngles;
  111. }
  112. const QAngle& GetLocalViewAngles()
  113. {
  114. if ( flags & FDEMO_USE_ANGLES2 )
  115. {
  116. return localViewAngles2;
  117. }
  118. return localViewAngles;
  119. }
  120. void Reset( void )
  121. {
  122. flags = 0;
  123. viewOrigin2 = viewOrigin;
  124. viewAngles2 = viewAngles;
  125. localViewAngles2 = localViewAngles;
  126. }
  127. int flags;
  128. // original origin/viewangles
  129. Vector viewOrigin;
  130. QAngle viewAngles;
  131. QAngle localViewAngles;
  132. // Resampled origin/viewangles
  133. Vector viewOrigin2;
  134. QAngle viewAngles2;
  135. QAngle localViewAngles2;
  136. };
  137. struct demosmoothing_t
  138. {
  139. demosmoothing_t()
  140. {
  141. file_offset = 0;
  142. frametick = 0;
  143. selected = false;
  144. samplepoint = false;
  145. vecmoved.Init();
  146. angmoved.Init();
  147. targetpoint = false;
  148. vectarget.Init();
  149. }
  150. demosmoothing_t& operator=(const demosmoothing_t& src )
  151. {
  152. if ( this == &src )
  153. return *this;
  154. file_offset = src.file_offset;
  155. frametick = src.frametick;
  156. selected = src.selected;
  157. samplepoint = src.samplepoint;
  158. vecmoved = src.vecmoved;
  159. angmoved = src.angmoved;
  160. targetpoint = src.targetpoint;
  161. vectarget = src.vectarget;
  162. info = src.info;
  163. return *this;
  164. }
  165. int file_offset;
  166. int frametick;
  167. bool selected;
  168. // For moved sample points
  169. bool samplepoint;
  170. Vector vecmoved;
  171. QAngle angmoved;
  172. bool targetpoint;
  173. Vector vectarget;
  174. democmdinfo_t info;
  175. };
  176. struct CSmoothingContext
  177. {
  178. CSmoothingContext()
  179. {
  180. active = false;
  181. filename[ 0 ] = 0;
  182. m_nFirstSelectableSample = 0;
  183. }
  184. CSmoothingContext& operator=(const CSmoothingContext& src )
  185. {
  186. if ( this == &src )
  187. return *this;
  188. active = src.active;
  189. Q_strncpy( filename, src.filename, sizeof( filename ) );
  190. smooth.RemoveAll();
  191. int c = src.smooth.Count();
  192. int i;
  193. for ( i = 0; i < c; i++ )
  194. {
  195. demosmoothing_t newitem;
  196. newitem = src.smooth[ i ];
  197. smooth.AddToTail( newitem );
  198. }
  199. m_nFirstSelectableSample = src.m_nFirstSelectableSample;
  200. return *this;
  201. }
  202. bool active;
  203. char filename[ 512 ];
  204. CUtlVector< demosmoothing_t > smooth;
  205. int m_nFirstSelectableSample;
  206. };
  207. #endif // DEMOFORMAT_H