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.

166 lines
4.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implements the Effects API
  4. // Created: YWB 9/5/2000
  5. //
  6. //===========================================================================//
  7. #include "quakedef.h"
  8. #include "r_efx.h"
  9. #include "r_efxextern.h"
  10. #include "r_local.h"
  11. #include "cl_main.h"
  12. #include "decal.h"
  13. #include "client.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. // Effects API object.
  17. static CVEfx efx;
  18. // Engine internal accessor to effects api ( see cl_parsetent.cpp, etc. )
  19. CVEfx *g_pEfx = &efx;
  20. extern CClientState cl;
  21. //-----------------------------------------------------------------------------
  22. // Purpose:
  23. //-----------------------------------------------------------------------------
  24. int CVEfx::Draw_DecalIndexFromName( char *name )
  25. {
  26. bool found = false;
  27. return ::Draw_DecalIndexFromName( name, &found );
  28. }
  29. //-----------------------------------------------------------------------------
  30. // Retrieve decal texture name from decal by index
  31. //-----------------------------------------------------------------------------
  32. const char *CVEfx::Draw_DecalNameFromIndex( int nIndex )
  33. {
  34. return ::Draw_DecalNameFromIndex( nIndex );
  35. }
  36. //-----------------------------------------------------------------------------
  37. // Purpose:
  38. // Input : textureIndex -
  39. // entity -
  40. // modelIndex -
  41. // position -
  42. // flags -
  43. //-----------------------------------------------------------------------------
  44. void CVEfx::DecalShoot( int textureIndex, int entity, const model_t *model, const Vector& model_origin, const QAngle& model_angles, const Vector& position, const Vector *saxis, int flags)
  45. {
  46. color32 white = {255,255,255,255};
  47. DecalColorShoot( textureIndex, entity, model, model_origin, model_angles, position, saxis, flags, white );
  48. }
  49. void CVEfx::DecalColorShoot( int textureIndex, int entity, const model_t *model, const Vector& model_origin, const QAngle& model_angles,
  50. const Vector& position, const Vector *saxis, int flags, const color32 &rgbaColor)
  51. {
  52. Vector localPosition = position;
  53. if ( entity ) // Not world?
  54. {
  55. matrix3x4_t matrix;
  56. AngleMatrix( model_angles, model_origin, matrix );
  57. VectorITransform( position, matrix, localPosition );
  58. }
  59. ::R_DecalShoot( textureIndex, entity, model, localPosition, saxis, flags, rgbaColor, NULL );
  60. }
  61. //-----------------------------------------------------------------------------
  62. // Purpose:
  63. // Input : *material -
  64. // userdata -
  65. // entity -
  66. // *model -
  67. // position -
  68. // *saxis -
  69. // flags -
  70. // &rgbaColor -
  71. //-----------------------------------------------------------------------------
  72. void CVEfx::PlayerDecalShoot( IMaterial *material, void *userdata, int entity, const model_t *model, const Vector& model_origin, const QAngle& model_angles,
  73. const Vector& position, const Vector *saxis, int flags, const color32 &rgbaColor )
  74. {
  75. Vector localPosition = position;
  76. if ( entity ) // Not world?
  77. {
  78. matrix3x4_t matrix;
  79. AngleMatrix( model_angles, model_origin, matrix );
  80. VectorITransform( position, matrix, localPosition );
  81. }
  82. R_PlayerDecalShoot( material, userdata, entity, model, position, saxis, flags, rgbaColor );
  83. }
  84. //-----------------------------------------------------------------------------
  85. // Purpose:
  86. // Input : key -
  87. // Output : dlight_t
  88. //-----------------------------------------------------------------------------
  89. dlight_t *CVEfx::CL_AllocDlight( int key )
  90. {
  91. return ::CL_AllocDlight( key );
  92. }
  93. int CVEfx::CL_GetActiveDLights( dlight_t *pList[MAX_DLIGHTS] )
  94. {
  95. int nOut = 0;
  96. if ( g_bActiveDlights )
  97. {
  98. for ( int i=0; i < MAX_DLIGHTS; i++ )
  99. {
  100. if ( r_dlightactive & (1 << i) )
  101. {
  102. pList[nOut++] = &cl_dlights[i];
  103. }
  104. }
  105. }
  106. return nOut;
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Purpose:
  110. // Input : key -
  111. // Output : dlight_t
  112. //-----------------------------------------------------------------------------
  113. dlight_t *CVEfx::CL_AllocElight( int key )
  114. {
  115. return ::CL_AllocElight( key );
  116. }
  117. // Given an elight key, find it. Does not search ordinary dlights. May return NULL.
  118. dlight_t *CVEfx::GetElightByKey( int key )
  119. {
  120. if ( g_bActiveElights )
  121. {
  122. for ( unsigned int i = 0 ; i < MAX_ELIGHTS ; ++i )
  123. {
  124. // if the keys match...
  125. if (cl_elights[i].key == key)
  126. {
  127. // then if the light is active, return it. If it's died,
  128. // return NULL.
  129. if ( cl_elights[i].die > cl.GetTime() )
  130. {
  131. return cl_elights + i;
  132. }
  133. else
  134. {
  135. return NULL;
  136. }
  137. }
  138. }
  139. }
  140. // if we are down here, we found nothing, or no lights were active
  141. return NULL;
  142. }
  143. // Expose it to the client .dll
  144. EXPOSE_SINGLE_INTERFACE( CVEfx, IVEfx, VENGINE_EFFECTS_INTERFACE_VERSION );