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.

316 lines
8.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: master for refresh, status bar, console, chat, notify, etc
  4. //
  5. //=====================================================================================//
  6. #include "render_pch.h"
  7. #include "client.h"
  8. #include "console.h"
  9. #include "screen.h"
  10. #include "sound.h"
  11. #include "sbar.h"
  12. #include "debugoverlay.h"
  13. #include "ivguicenterprint.h"
  14. #include "cdll_int.h"
  15. #include "gl_matsysiface.h"
  16. #include "cdll_engine_int.h"
  17. #include "demo.h"
  18. #include "cl_main.h"
  19. #include "vgui_baseui_interface.h"
  20. #include "tier0/vcrmode.h"
  21. #include "con_nprint.h"
  22. #include "sys_mainwind.h"
  23. #include "ivideomode.h"
  24. #include "lightcache.h"
  25. #include "toolframework/itoolframework.h"
  26. #include "matchmaking.h"
  27. #include "datacache/idatacache.h"
  28. #include "sys_dll.h"
  29. #if defined( REPLAY_ENABLED )
  30. #include "replay_internal.h"
  31. #endif
  32. #include "tier0/vprof.h"
  33. // memdbgon must be the last include file in a .cpp file!!!
  34. #include "tier0/memdbgon.h"
  35. // In other C files.
  36. extern bool V_CheckGamma( void );
  37. extern void V_RenderView( void );
  38. extern void V_RenderVGuiOnly( void );
  39. bool scr_initialized; // ready to draw
  40. bool scr_disabled_for_loading;
  41. bool scr_drawloading;
  42. int scr_nextdrawtick; // A hack to let things settle on reload/reconnect
  43. //-----------------------------------------------------------------------------
  44. // Purpose:
  45. //-----------------------------------------------------------------------------
  46. void SCR_Init (void)
  47. {
  48. scr_initialized = true;
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Purpose:
  52. //-----------------------------------------------------------------------------
  53. void SCR_Shutdown( void )
  54. {
  55. scr_initialized = false;
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose: starts loading
  59. //-----------------------------------------------------------------------------
  60. void SCR_BeginLoadingPlaque( void )
  61. {
  62. if ( !scr_drawloading )
  63. {
  64. // make sure game UI is allowed to show (gets disabled if chat window is up)
  65. EngineVGui()->SetNotAllowedToShowGameUI( false );
  66. // force QMS to serialize during loading
  67. Host_AllowQueuedMaterialSystem( false );
  68. scr_drawloading = true;
  69. S_StopAllSounds( true );
  70. S_OnLoadScreen( true );
  71. g_pFileSystem->AsyncFinishAll();
  72. g_pMDLCache->FinishPendingLoads();
  73. // redraw with no console and the loading plaque
  74. Con_ClearNotify();
  75. SCR_CenterStringOff();
  76. // NULL HudText clears HudMessage system
  77. if ( g_ClientDLL )
  78. {
  79. g_ClientDLL->HudText( NULL );
  80. }
  81. // let the UI know we're starting loading
  82. EngineVGui()->OnLevelLoadingStarted();
  83. // Don't run any more simulation on the client!!!
  84. g_ClientGlobalVariables.frametime = 0.0f;
  85. host_framecount++;
  86. g_ClientGlobalVariables.framecount = host_framecount;
  87. // Ensure the screen is painted to reflect the loading state
  88. SCR_UpdateScreen();
  89. host_framecount++;
  90. g_ClientGlobalVariables.framecount = host_framecount;
  91. SCR_UpdateScreen();
  92. g_ClientGlobalVariables.frametime = cl.GetFrameTime();
  93. scr_disabled_for_loading = true;
  94. }
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Purpose: finished loading
  98. //-----------------------------------------------------------------------------
  99. void SCR_EndLoadingPlaque( void )
  100. {
  101. if ( scr_drawloading )
  102. {
  103. // let the UI know we're finished
  104. EngineVGui()->OnLevelLoadingFinished();
  105. S_OnLoadScreen( false );
  106. }
  107. else if ( gfExtendedError )
  108. {
  109. if ( IsPC() )
  110. {
  111. EngineVGui()->ShowErrorMessage();
  112. }
  113. }
  114. g_pMatchmaking->OnLevelLoadingFinished();
  115. scr_disabled_for_loading = false;
  116. scr_drawloading = false;
  117. }
  118. //-----------------------------------------------------------------------------
  119. // Places TCR required defective media message and halts
  120. //-----------------------------------------------------------------------------
  121. #ifdef _XBOX
  122. void SCR_FatalDiskError()
  123. {
  124. EngineVGui()->OnDiskError();
  125. while ( 1 )
  126. {
  127. // run the minimal frame to update and paint
  128. EngineVGui()->Simulate();
  129. V_RenderVGuiOnly();
  130. }
  131. }
  132. #endif
  133. //-----------------------------------------------------------------------------
  134. // Purpose:
  135. //-----------------------------------------------------------------------------
  136. void SCR_CenterPrint (char *str)
  137. {
  138. if ( !centerprint )
  139. return;
  140. centerprint->ColorPrint( 255, 255, 255, 0, str );
  141. }
  142. //-----------------------------------------------------------------------------
  143. // Purpose:
  144. //-----------------------------------------------------------------------------
  145. void SCR_CenterStringOff( void )
  146. {
  147. if ( !centerprint )
  148. return;
  149. centerprint->Clear();
  150. }
  151. //-----------------------------------------------------------------------------
  152. // Purpose:
  153. //-----------------------------------------------------------------------------
  154. inline void SCR_ShowVCRPlaybackAmount()
  155. {
  156. if ( VCRGetMode() != VCR_Playback || !g_bShowVCRPlaybackDisplay )
  157. return;
  158. con_nprint_t info;
  159. info.index = 20;
  160. info.time_to_live = 0.01;
  161. info.color[0] = info.color[1] = info.color[2] = 1;
  162. info.fixed_width_font = false;
  163. double flCurPercent = VCRGetPercentCompleted();
  164. Con_NXPrintf( &info, "VCR Playback: %.2f percent, frame %d", flCurPercent * 100.0, host_framecount );
  165. info.index++;
  166. Con_NXPrintf( &info, "'+' to speed up, '-' to slow down [current sleep: %d]", g_iVCRPlaybackSleepInterval );
  167. info.index++;
  168. Con_NXPrintf( &info, "'p' to pause, 's' to single step, 'r' to resume" );
  169. info.index++;
  170. Con_NXPrintf( &info, "'d' to toggle this display" );
  171. info.index++;
  172. Con_NXPrintf( &info, "'q' to quit" );
  173. }
  174. //-----------------------------------------------------------------------------
  175. // Purpose: This is called every frame, and can also be called explicitly to flush
  176. // text to the screen.
  177. //-----------------------------------------------------------------------------
  178. void SCR_UpdateScreen( void )
  179. {
  180. tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ );
  181. R_StudioCheckReinitLightingCache();
  182. // Always force the Gamma Table to be rebuilt. Otherwise,
  183. // we'll load textures with an all white gamma lookup table.
  184. V_CheckGamma();
  185. // This is a HACK to let things settle for a bit on level start
  186. // NOTE: If you remove scr_nextdrawtick, remove it from enginetool.cpp too
  187. if ( scr_nextdrawtick != 0 )
  188. {
  189. if ( host_tickcount < scr_nextdrawtick )
  190. return;
  191. scr_nextdrawtick = 0;
  192. }
  193. if ( scr_disabled_for_loading )
  194. {
  195. if ( !Host_IsSinglePlayerGame() )
  196. {
  197. V_RenderVGuiOnly();
  198. }
  199. return;
  200. }
  201. if ( !scr_initialized || !con_initialized )
  202. {
  203. // not initialized yet
  204. return;
  205. }
  206. SCR_ShowVCRPlaybackAmount();
  207. // Let demo system overwrite view origin/angles during playback
  208. if ( demoplayer->IsPlayingBack() )
  209. {
  210. demoplayer->InterpolateViewpoint();
  211. }
  212. materials->BeginFrame( host_frametime );
  213. {
  214. tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "EngineVGui_Simulate" );
  215. EngineVGui()->Simulate();
  216. }
  217. ClientDLL_FrameStageNotify( FRAME_RENDER_START );
  218. // Simulation meant to occur before any views are rendered
  219. // This needs to happen before the client DLL is called because the client DLL depends on
  220. // some of the setup in FRAME_RENDER_START.
  221. {
  222. tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "FrameBegin" );
  223. g_EngineRenderer->FrameBegin();
  224. toolframework->RenderFrameBegin();
  225. }
  226. cl.UpdateAreaBits_BackwardsCompatible();
  227. Shader_BeginRendering();
  228. // Draw world, etc.
  229. V_RenderView();
  230. CL_TakeSnapshotAndSwap();
  231. #if defined( REPLAY_ENABLED )
  232. if ( g_pReplay )
  233. {
  234. g_pReplay->CL_Render();
  235. }
  236. #endif
  237. ClientDLL_FrameStageNotify( FRAME_RENDER_END );
  238. {
  239. tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "FrameEnd" );
  240. toolframework->RenderFrameEnd();
  241. g_EngineRenderer->FrameEnd();
  242. }
  243. // moved dynamic model update here because this takes the materials lock
  244. // and materials->EndFrame() is where we will synchronize anyway.
  245. // Moved here to leave as much of the frame as possible to overlap threads in the case
  246. // where we actually have models to load here
  247. {
  248. tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "modelloader->UpdateDynamicModels" );
  249. VPROF( "UpdateDynamicModels" );
  250. CMDLCacheCriticalSection critsec( g_pMDLCache );
  251. modelloader->UpdateDynamicModels();
  252. }
  253. {
  254. tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "materials_EndFrame" );
  255. materials->EndFrame();
  256. }
  257. }