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.

287 lines
7.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "igamesystem.h"
  9. #include "point_camera.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. #define CAM_THINK_INTERVAL 0.05
  13. // Spawnflags
  14. #define SF_CAMERA_START_OFF 0x01
  15. // UNDONE: Share properly with the client code!!!
  16. #define POINT_CAMERA_MSG_SETACTIVE 1
  17. CEntityClassList<CPointCamera> g_PointCameraList;
  18. template <> CPointCamera *CEntityClassList<CPointCamera>::m_pClassList = NULL;
  19. CPointCamera* GetPointCameraList()
  20. {
  21. return g_PointCameraList.m_pClassList;
  22. }
  23. // These are already built into CBaseEntity
  24. // DEFINE_KEYFIELD( m_iName, FIELD_STRING, "targetname" ),
  25. // DEFINE_KEYFIELD( m_iParent, FIELD_STRING, "parentname" ),
  26. // DEFINE_KEYFIELD( m_target, FIELD_STRING, "target" ),
  27. #ifndef INFESTED_DLL
  28. LINK_ENTITY_TO_CLASS( point_camera, CPointCamera );
  29. #endif
  30. //-----------------------------------------------------------------------------
  31. // Purpose:
  32. //-----------------------------------------------------------------------------
  33. CPointCamera::~CPointCamera()
  34. {
  35. g_PointCameraList.Remove( this );
  36. }
  37. CPointCamera::CPointCamera()
  38. {
  39. // Set these to opposites so that it'll be sent the first time around.
  40. m_bActive = false;
  41. m_bIsOn = false;
  42. m_bFogEnable = false;
  43. g_PointCameraList.Insert( this );
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Purpose:
  47. //-----------------------------------------------------------------------------
  48. void CPointCamera::Spawn( void )
  49. {
  50. BaseClass::Spawn();
  51. if ( m_spawnflags & SF_CAMERA_START_OFF )
  52. {
  53. m_bIsOn = false;
  54. }
  55. else
  56. {
  57. m_bIsOn = true;
  58. }
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose: Override ShouldTransmit since we want to be sent even though we don't have a model, etc.
  62. // All that matters is if we are in the pvs.
  63. //-----------------------------------------------------------------------------
  64. int CPointCamera::UpdateTransmitState()
  65. {
  66. if ( m_bActive )
  67. {
  68. return SetTransmitState( FL_EDICT_ALWAYS );
  69. }
  70. else
  71. {
  72. return SetTransmitState( FL_EDICT_DONTSEND );
  73. }
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Purpose:
  77. //-----------------------------------------------------------------------------
  78. void CPointCamera::SetActive( bool bActive )
  79. {
  80. // If the mapmaker's told the camera it's off, it enforces inactive state
  81. if ( !m_bIsOn )
  82. {
  83. bActive = false;
  84. }
  85. if ( m_bActive != bActive )
  86. {
  87. m_bActive = bActive;
  88. DispatchUpdateTransmitState();
  89. }
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Purpose:
  93. //-----------------------------------------------------------------------------
  94. void CPointCamera::InputChangeFOV( inputdata_t &inputdata )
  95. {
  96. // Parse the keyvalue data
  97. char parseString[255];
  98. Q_strncpy(parseString, inputdata.value.String(), sizeof(parseString));
  99. // Get FOV
  100. char *pszParam = strtok(parseString," ");
  101. if(pszParam)
  102. {
  103. m_TargetFOV = atof( pszParam );
  104. }
  105. else
  106. {
  107. // Assume no change
  108. m_TargetFOV = m_FOV;
  109. }
  110. // Get Time
  111. float flChangeTime;
  112. pszParam = strtok(NULL," ");
  113. if(pszParam)
  114. {
  115. flChangeTime = atof( pszParam );
  116. }
  117. else
  118. {
  119. // Assume 1 second.
  120. flChangeTime = 1.0;
  121. }
  122. m_DegreesPerSecond = ( m_TargetFOV - m_FOV ) / flChangeTime;
  123. SetThink( &CPointCamera::ChangeFOVThink );
  124. SetNextThink( gpGlobals->curtime );
  125. }
  126. //-----------------------------------------------------------------------------
  127. // Purpose:
  128. //-----------------------------------------------------------------------------
  129. void CPointCamera::ChangeFOVThink( void )
  130. {
  131. SetNextThink( gpGlobals->curtime + CAM_THINK_INTERVAL );
  132. float newFOV = m_FOV;
  133. newFOV += m_DegreesPerSecond * CAM_THINK_INTERVAL;
  134. if( m_DegreesPerSecond < 0 )
  135. {
  136. if( newFOV <= m_TargetFOV )
  137. {
  138. newFOV = m_TargetFOV;
  139. SetThink( NULL );
  140. }
  141. }
  142. else
  143. {
  144. if( newFOV >= m_TargetFOV )
  145. {
  146. newFOV = m_TargetFOV;
  147. SetThink( NULL );
  148. }
  149. }
  150. m_FOV = newFOV;
  151. }
  152. //-----------------------------------------------------------------------------
  153. // Purpose: Turn this camera on, and turn all other cameras off
  154. //-----------------------------------------------------------------------------
  155. void CPointCamera::InputSetOnAndTurnOthersOff( inputdata_t &inputdata )
  156. {
  157. CBaseEntity *pEntity = NULL;
  158. while ((pEntity = gEntList.FindEntityByClassname( pEntity, "point_camera" )) != NULL)
  159. {
  160. CPointCamera *pCamera = (CPointCamera*)pEntity;
  161. pCamera->InputSetOff( inputdata );
  162. }
  163. // Now turn myself on
  164. InputSetOn( inputdata );
  165. }
  166. //-----------------------------------------------------------------------------
  167. // Purpose:
  168. //-----------------------------------------------------------------------------
  169. void CPointCamera::InputSetOn( inputdata_t &inputdata )
  170. {
  171. m_bIsOn = true;
  172. }
  173. //-----------------------------------------------------------------------------
  174. // Purpose:
  175. //-----------------------------------------------------------------------------
  176. void CPointCamera::InputSetOff( inputdata_t &inputdata )
  177. {
  178. m_bIsOn = false;
  179. SetActive( false );
  180. }
  181. //-----------------------------------------------------------------------------
  182. // Purpose:
  183. //-----------------------------------------------------------------------------
  184. void CPointCamera::InputForceActive( inputdata_t &inputdata )
  185. {
  186. CBaseEntity *pEntity = NULL;
  187. while ((pEntity = gEntList.FindEntityByClassname( pEntity, "point_camera" )) != NULL)
  188. {
  189. CPointCamera *pCamera = (CPointCamera*)pEntity;
  190. pCamera->m_bActive = false;
  191. }
  192. // Now turn myself on
  193. InputSetOn( inputdata );
  194. m_bActive = true;
  195. UpdateTransmitState();
  196. }
  197. //-----------------------------------------------------------------------------
  198. // Purpose:
  199. //-----------------------------------------------------------------------------
  200. void CPointCamera::InputForceInactive( inputdata_t &inputdata )
  201. {
  202. m_bIsOn = false;
  203. SetActive( false );
  204. UpdateTransmitState();
  205. }
  206. BEGIN_DATADESC( CPointCamera )
  207. // Save/restore Keyvalue fields
  208. DEFINE_KEYFIELD( m_FOV, FIELD_FLOAT, "FOV" ),
  209. DEFINE_KEYFIELD( m_Resolution, FIELD_FLOAT, "resolution" ),
  210. DEFINE_KEYFIELD( m_bFogEnable, FIELD_BOOLEAN, "fogEnable" ),
  211. DEFINE_KEYFIELD( m_FogColor, FIELD_COLOR32, "fogColor" ),
  212. DEFINE_KEYFIELD( m_flFogStart, FIELD_FLOAT, "fogStart" ),
  213. DEFINE_KEYFIELD( m_flFogEnd, FIELD_FLOAT, "fogEnd" ),
  214. DEFINE_KEYFIELD( m_flFogMaxDensity, FIELD_FLOAT, "fogMaxDensity" ),
  215. DEFINE_KEYFIELD( m_bUseScreenAspectRatio, FIELD_BOOLEAN, "UseScreenAspectRatio" ),
  216. DEFINE_FIELD( m_bActive, FIELD_BOOLEAN ),
  217. DEFINE_FIELD( m_bIsOn, FIELD_BOOLEAN ),
  218. DEFINE_FIELD( m_TargetFOV, FIELD_FLOAT ),
  219. DEFINE_FIELD( m_DegreesPerSecond, FIELD_FLOAT ),
  220. // This is re-set up in the constructor
  221. //DEFINE_FIELD( m_pNext, FIELD_CLASSPTR ),
  222. DEFINE_FUNCTION( ChangeFOVThink ),
  223. // Input
  224. DEFINE_INPUTFUNC( FIELD_STRING, "ChangeFOV", InputChangeFOV ),
  225. DEFINE_INPUTFUNC( FIELD_VOID, "SetOnAndTurnOthersOff", InputSetOnAndTurnOthersOff ),
  226. DEFINE_INPUTFUNC( FIELD_VOID, "SetOn", InputSetOn ),
  227. DEFINE_INPUTFUNC( FIELD_VOID, "SetOff", InputSetOff ),
  228. DEFINE_INPUTFUNC( FIELD_VOID, "Activate", InputForceActive ),
  229. DEFINE_INPUTFUNC( FIELD_VOID, "Deactivate", InputForceInactive ),
  230. END_DATADESC()
  231. IMPLEMENT_SERVERCLASS_ST( CPointCamera, DT_PointCamera )
  232. SendPropFloat( SENDINFO( m_FOV ), 0, SPROP_NOSCALE ),
  233. SendPropFloat( SENDINFO( m_Resolution ), 0, SPROP_NOSCALE ),
  234. SendPropInt( SENDINFO( m_bFogEnable ), 1, SPROP_UNSIGNED ),
  235. SendPropInt( SENDINFO( m_FogColor ), 32, SPROP_UNSIGNED, SendProxy_Color32ToInt32 ),
  236. SendPropFloat( SENDINFO( m_flFogStart ), 0, SPROP_NOSCALE ),
  237. SendPropFloat( SENDINFO( m_flFogEnd ), 0, SPROP_NOSCALE ),
  238. SendPropFloat( SENDINFO( m_flFogMaxDensity ), 0, SPROP_NOSCALE ),
  239. SendPropInt( SENDINFO( m_bActive ), 1, SPROP_UNSIGNED ),
  240. SendPropInt( SENDINFO( m_bUseScreenAspectRatio ), 1, SPROP_UNSIGNED ),
  241. END_SEND_TABLE()