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.

194 lines
5.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "c_world.h"
  9. #include "ivmodemanager.h"
  10. #include "activitylist.h"
  11. #include "decals.h"
  12. #include "engine/ivmodelinfo.h"
  13. #include "ivieweffects.h"
  14. #include "shake.h"
  15. #include "eventlist.h"
  16. // NVNT haptic include for notification of world precache
  17. #include "haptics/haptic_utils.h"
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include "tier0/memdbgon.h"
  20. #ifdef CWorld
  21. #undef CWorld
  22. #endif
  23. C_GameRules *g_pGameRules = NULL;
  24. static C_World *g_pClientWorld;
  25. void ClientWorldFactoryInit()
  26. {
  27. g_pClientWorld = new C_World;
  28. }
  29. void ClientWorldFactoryShutdown()
  30. {
  31. delete g_pClientWorld;
  32. g_pClientWorld = NULL;
  33. }
  34. static IClientNetworkable* ClientWorldFactory( int entnum, int serialNum )
  35. {
  36. Assert( g_pClientWorld != NULL );
  37. g_pClientWorld->Init( entnum, serialNum );
  38. return g_pClientWorld;
  39. }
  40. IMPLEMENT_CLIENTCLASS_FACTORY( C_World, DT_World, CWorld, ClientWorldFactory );
  41. BEGIN_RECV_TABLE( C_World, DT_World )
  42. RecvPropFloat(RECVINFO(m_flWaveHeight)),
  43. RecvPropVector(RECVINFO(m_WorldMins)),
  44. RecvPropVector(RECVINFO(m_WorldMaxs)),
  45. RecvPropInt(RECVINFO(m_bStartDark)),
  46. RecvPropFloat(RECVINFO(m_flMaxOccludeeArea)),
  47. RecvPropFloat(RECVINFO(m_flMinOccluderArea)),
  48. RecvPropFloat(RECVINFO(m_flMaxPropScreenSpaceWidth)),
  49. RecvPropFloat(RECVINFO(m_flMinPropScreenSpaceWidth)),
  50. RecvPropString(RECVINFO(m_iszDetailSpriteMaterial)),
  51. RecvPropInt(RECVINFO(m_bColdWorld)),
  52. END_RECV_TABLE()
  53. C_World::C_World( void )
  54. {
  55. }
  56. C_World::~C_World( void )
  57. {
  58. }
  59. bool C_World::Init( int entnum, int iSerialNum )
  60. {
  61. m_flWaveHeight = 0.0f;
  62. ActivityList_Init();
  63. EventList_Init();
  64. return BaseClass::Init( entnum, iSerialNum );
  65. }
  66. void C_World::Release()
  67. {
  68. ActivityList_Free();
  69. Term();
  70. }
  71. void C_World::PreDataUpdate( DataUpdateType_t updateType )
  72. {
  73. BaseClass::PreDataUpdate( updateType );
  74. }
  75. void C_World::OnDataChanged( DataUpdateType_t updateType )
  76. {
  77. BaseClass::OnDataChanged( updateType );
  78. // Always force reset to normal mode upon receipt of world in new map
  79. if ( updateType == DATA_UPDATE_CREATED )
  80. {
  81. modemanager->SwitchMode( false, true );
  82. if ( m_bStartDark )
  83. {
  84. ScreenFade_t sf;
  85. memset( &sf, 0, sizeof( sf ) );
  86. sf.a = 255;
  87. sf.r = 0;
  88. sf.g = 0;
  89. sf.b = 0;
  90. sf.duration = (float)(1<<SCREENFADE_FRACBITS) * 5.0f;
  91. sf.holdTime = (float)(1<<SCREENFADE_FRACBITS) * 1.0f;
  92. sf.fadeFlags = FFADE_IN | FFADE_PURGE;
  93. vieweffects->Fade( sf );
  94. }
  95. OcclusionParams_t params;
  96. params.m_flMaxOccludeeArea = m_flMaxOccludeeArea;
  97. params.m_flMinOccluderArea = m_flMinOccluderArea;
  98. engine->SetOcclusionParameters( params );
  99. modelinfo->SetLevelScreenFadeRange( m_flMinPropScreenSpaceWidth, m_flMaxPropScreenSpaceWidth );
  100. }
  101. }
  102. void C_World::RegisterSharedActivities( void )
  103. {
  104. ActivityList_RegisterSharedActivities();
  105. EventList_RegisterSharedEvents();
  106. }
  107. // -----------------------------------------
  108. // Sprite Index info
  109. // -----------------------------------------
  110. short g_sModelIndexLaser; // holds the index for the laser beam
  111. const char *g_pModelNameLaser = "sprites/laserbeam.vmt";
  112. short g_sModelIndexLaserDot; // holds the index for the laser beam dot
  113. short g_sModelIndexFireball; // holds the index for the fireball
  114. short g_sModelIndexSmoke; // holds the index for the smoke cloud
  115. short g_sModelIndexWExplosion; // holds the index for the underwater explosion
  116. short g_sModelIndexBubbles; // holds the index for the bubbles model
  117. short g_sModelIndexBloodDrop; // holds the sprite index for the initial blood
  118. short g_sModelIndexBloodSpray; // holds the sprite index for splattered blood
  119. //-----------------------------------------------------------------------------
  120. // Purpose: Precache global weapon sounds
  121. //-----------------------------------------------------------------------------
  122. void W_Precache(void)
  123. {
  124. PrecacheFileWeaponInfoDatabase( filesystem, g_pGameRules->GetEncryptionKey() );
  125. g_sModelIndexFireball = modelinfo->GetModelIndex ("sprites/zerogxplode.vmt");// fireball
  126. g_sModelIndexWExplosion = modelinfo->GetModelIndex ("sprites/WXplo1.vmt");// underwater fireball
  127. g_sModelIndexSmoke = modelinfo->GetModelIndex ("sprites/steam1.vmt");// smoke
  128. g_sModelIndexBubbles = modelinfo->GetModelIndex ("sprites/bubble.vmt");//bubbles
  129. g_sModelIndexBloodSpray = modelinfo->GetModelIndex ("sprites/bloodspray.vmt"); // initial blood
  130. g_sModelIndexBloodDrop = modelinfo->GetModelIndex ("sprites/blood.vmt"); // splattered blood
  131. g_sModelIndexLaser = modelinfo->GetModelIndex( (char *)g_pModelNameLaser );
  132. g_sModelIndexLaserDot = modelinfo->GetModelIndex("sprites/laserdot.vmt");
  133. }
  134. void C_World::Precache( void )
  135. {
  136. // UNDONE: Make most of these things server systems or precache_registers
  137. // =================================================
  138. // Activities
  139. // =================================================
  140. ActivityList_Free();
  141. EventList_Free();
  142. RegisterSharedActivities();
  143. // Get weapon precaches
  144. W_Precache();
  145. // Call all registered precachers.
  146. CPrecacheRegister::Precache();
  147. // NVNT notify system of precache
  148. if (haptics)
  149. haptics->WorldPrecache();
  150. }
  151. void C_World::Spawn( void )
  152. {
  153. Precache();
  154. }
  155. C_World *GetClientWorldEntity()
  156. {
  157. Assert( g_pClientWorld != NULL );
  158. return g_pClientWorld;
  159. }