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.

95 lines
2.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "model_types.h"
  8. #include "vcollide.h"
  9. #include "vcollide_parse.h"
  10. #include "solidsetdefaults.h"
  11. #include "bone_setup.h"
  12. #include "engine/ivmodelinfo.h"
  13. #include "physics.h"
  14. #include "view.h"
  15. #include "clienteffectprecachesystem.h"
  16. #include "c_physicsprop.h"
  17. #include "tier0/vprof.h"
  18. #include "ivrenderview.h"
  19. // memdbgon must be the last include file in a .cpp file!!!
  20. #include "tier0/memdbgon.h"
  21. IMPLEMENT_CLIENTCLASS_DT(C_PhysicsProp, DT_PhysicsProp, CPhysicsProp)
  22. RecvPropBool( RECVINFO( m_bAwake ) ),
  23. END_RECV_TABLE()
  24. ConVar r_PhysPropStaticLighting( "r_PhysPropStaticLighting", "1" );
  25. //-----------------------------------------------------------------------------
  26. // Purpose:
  27. //-----------------------------------------------------------------------------
  28. C_PhysicsProp::C_PhysicsProp( void )
  29. {
  30. m_pPhysicsObject = NULL;
  31. m_takedamage = DAMAGE_YES;
  32. // default true so static lighting will get recomputed when we go to sleep
  33. m_bAwakeLastTime = true;
  34. }
  35. //-----------------------------------------------------------------------------
  36. // Purpose:
  37. //-----------------------------------------------------------------------------
  38. C_PhysicsProp::~C_PhysicsProp( void )
  39. {
  40. }
  41. // @MULTICORE (toml 9/18/2006): this visualization will need to be implemented elsewhere
  42. ConVar r_visualizeproplightcaching( "r_visualizeproplightcaching", "0" );
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Draws the object
  45. // Input : flags -
  46. //-----------------------------------------------------------------------------
  47. bool C_PhysicsProp::OnInternalDrawModel( ClientModelRenderInfo_t *pInfo )
  48. {
  49. CreateModelInstance();
  50. if ( r_PhysPropStaticLighting.GetBool() && m_bAwakeLastTime != m_bAwake )
  51. {
  52. if ( m_bAwakeLastTime && !m_bAwake )
  53. {
  54. // transition to sleep, bake lighting now, once
  55. if ( !modelrender->RecomputeStaticLighting( GetModelInstance() ) )
  56. {
  57. // not valid for drawing
  58. return false;
  59. }
  60. if ( r_visualizeproplightcaching.GetBool() )
  61. {
  62. float color[] = { 0.0f, 1.0f, 0.0f, 1.0f };
  63. render->SetColorModulation( color );
  64. }
  65. }
  66. else if ( r_visualizeproplightcaching.GetBool() )
  67. {
  68. float color[] = { 1.0f, 0.0f, 0.0f, 1.0f };
  69. render->SetColorModulation( color );
  70. }
  71. }
  72. if ( !m_bAwake && r_PhysPropStaticLighting.GetBool() )
  73. {
  74. // going to sleep, have static lighting
  75. pInfo->flags |= STUDIO_STATIC_LIGHTING;
  76. }
  77. // track state
  78. m_bAwakeLastTime = m_bAwake;
  79. return true;
  80. }