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.

190 lines
4.9 KiB

  1. //========= Copyright © 1996-2005, 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 "decals.h"
  11. #include "engine/ivmodelinfo.h"
  12. #include "ivieweffects.h"
  13. #include "shake.h"
  14. #include "precache_register.h"
  15. #ifdef PORTAL2
  16. #include "paint_stream_manager.h"
  17. #endif
  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. RecvPropInt(RECVINFO(m_iTimeOfDay)),
  53. #ifdef PORTAL2
  54. RecvPropInt(RECVINFO(m_nMaxBlobCount)),
  55. #endif
  56. END_RECV_TABLE()
  57. C_World::C_World( void )
  58. {
  59. }
  60. C_World::~C_World( void )
  61. {
  62. }
  63. bool C_World::Init( int entnum, int iSerialNum )
  64. {
  65. m_flWaveHeight = 0.0f;
  66. return BaseClass::Init( entnum, iSerialNum );
  67. }
  68. void C_World::Release()
  69. {
  70. Term();
  71. }
  72. void C_World::PreDataUpdate( DataUpdateType_t updateType )
  73. {
  74. BaseClass::PreDataUpdate( updateType );
  75. }
  76. void C_World::OnDataChanged( DataUpdateType_t updateType )
  77. {
  78. BaseClass::OnDataChanged( updateType );
  79. // Always force reset to normal mode upon receipt of world in new map
  80. if ( updateType == DATA_UPDATE_CREATED )
  81. {
  82. modemanager->SwitchMode( false, true );
  83. if ( m_bStartDark )
  84. {
  85. ScreenFade_t sf;
  86. memset( &sf, 0, sizeof( sf ) );
  87. sf.a = 255;
  88. sf.r = 0;
  89. sf.g = 0;
  90. sf.b = 0;
  91. sf.duration = (float)(1<<SCREENFADE_FRACBITS) * 5.0f;
  92. sf.holdTime = (float)(1<<SCREENFADE_FRACBITS) * 1.0f;
  93. sf.fadeFlags = FFADE_IN | FFADE_PURGE;
  94. FOR_EACH_VALID_SPLITSCREEN_PLAYER( hh )
  95. {
  96. ACTIVE_SPLITSCREEN_PLAYER_GUARD( hh );
  97. GetViewEffects()->Fade( sf );
  98. }
  99. }
  100. OcclusionParams_t params;
  101. params.m_flMaxOccludeeArea = m_flMaxOccludeeArea;
  102. params.m_flMinOccluderArea = m_flMinOccluderArea;
  103. engine->SetOcclusionParameters( params );
  104. modelinfo->SetLevelScreenFadeRange( m_flMinPropScreenSpaceWidth, m_flMaxPropScreenSpaceWidth );
  105. #ifdef PORTAL2
  106. PaintStreamManager.AllocatePaintBlobPool( m_nMaxBlobCount );
  107. #endif
  108. }
  109. }
  110. // -----------------------------------------
  111. // Sprite Index info
  112. // -----------------------------------------
  113. #if !defined( TF_DLL ) && !defined ( DOTA_DLL ) && !defined ( PORTAL2 )
  114. int g_sModelIndexLaser; // holds the index for the laser beam
  115. int g_sModelIndexLaserDot; // holds the index for the laser beam dot
  116. int g_sModelIndexFireball; // holds the index for the fireball
  117. int g_sModelIndexWExplosion; // holds the index for the underwater explosion
  118. int g_sModelIndexBubbles; // holds the index for the bubbles model
  119. #endif
  120. int g_sModelIndexSmoke; // holds the index for the smoke cloud
  121. int g_sModelIndexBloodSpray; // holds the sprite index for splattered blood
  122. int g_sModelIndexBloodDrop; // holds the sprite index for the initial blood
  123. //-----------------------------------------------------------------------------
  124. // Purpose: Precache global weapon resources
  125. //-----------------------------------------------------------------------------
  126. PRECACHE_REGISTER_BEGIN( GLOBAL, WeaponSprites )
  127. #if !defined( TF_DLL ) && !defined ( DOTA_DLL ) && !defined ( PORTAL2 )
  128. PRECACHE_INDEX( MODEL, "sprites/zerogxplode.vmt", g_sModelIndexFireball )
  129. PRECACHE_INDEX( MODEL, "sprites/WXplo1.vmt", g_sModelIndexWExplosion )
  130. PRECACHE_INDEX( MODEL, "sprites/steam1.vmt", g_sModelIndexSmoke )
  131. PRECACHE_INDEX( MODEL, "sprites/bubble.vmt", g_sModelIndexBubbles )
  132. PRECACHE_INDEX( MODEL, "sprites/bloodspray.vmt", g_sModelIndexBloodSpray )
  133. PRECACHE_INDEX( MODEL, "sprites/blood.vmt", g_sModelIndexBloodDrop )
  134. PRECACHE_INDEX( MODEL, "sprites/laserbeam.vmt", g_sModelIndexLaser )
  135. PRECACHE_INDEX( MODEL, "sprites/laserdot.vmt", g_sModelIndexLaserDot )
  136. #endif
  137. PRECACHE_REGISTER_END()
  138. void W_Precache(void)
  139. {
  140. PrecacheFileWeaponInfoDatabase();
  141. }
  142. void C_World::Precache( void )
  143. {
  144. // Get weapon precaches
  145. W_Precache();
  146. }
  147. void C_World::Spawn( void )
  148. {
  149. Precache();
  150. }
  151. C_World *GetClientWorldEntity()
  152. {
  153. Assert( g_pClientWorld != NULL );
  154. return g_pClientWorld;
  155. }