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.

676 lines
20 KiB

  1. //===== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #include "quakedef.h"
  7. #include <assert.h>
  8. #include "engine_launcher_api.h"
  9. #include "iengine.h"
  10. #include "ivideomode.h"
  11. #include "igame.h"
  12. #include "vmodes.h"
  13. #include "modes.h"
  14. #include "sys.h"
  15. #include "host.h"
  16. #include "keys.h"
  17. #include "cdll_int.h"
  18. #include "host_state.h"
  19. #include "cdll_engine_int.h"
  20. #include "sys_dll.h"
  21. #include "tier0/vprof.h"
  22. #include "profile.h"
  23. #include "gl_matsysiface.h"
  24. #include "vprof_engine.h"
  25. #include "server.h"
  26. #include "cl_demo.h"
  27. #include "toolframework/itoolframework.h"
  28. #include "toolframework/itoolsystem.h"
  29. #include "inputsystem/iinputsystem.h"
  30. #include "gl_cvars.h"
  31. #include "filesystem_engine.h"
  32. #include "tier0/cpumonitoring.h"
  33. #ifndef DEDICATED
  34. #include "vgui_baseui_interface.h"
  35. #endif
  36. #ifdef _PS3
  37. #include <sysutil/sysutil_sysparam.h>
  38. #endif
  39. #include "tier0/etwprof.h"
  40. #include "steam/steam_api.h"
  41. #include "appframework/ilaunchermgr.h"
  42. // memdbgon must be the last include file in a .cpp file!!!
  43. #include "tier0/memdbgon.h"
  44. //-----------------------------------------------------------------------------
  45. // Forward declarations
  46. //-----------------------------------------------------------------------------
  47. void Sys_ShutdownGame( void );
  48. int Sys_InitGame( CreateInterfaceFn appSystemFactory,
  49. char const* pBaseDir, void *pwnd, int bIsDedicated );
  50. // sleep time when not focus
  51. ConVar engine_no_focus_sleep( "engine_no_focus_sleep", "50", FCVAR_ARCHIVE );
  52. #define DEFAULT_FPS_MAX 300
  53. static int s_nDesiredFPSMax = DEFAULT_FPS_MAX;
  54. static bool s_bFPSMaxDrivenByPowerSavings = false;
  55. // Dedicated server fps locking to tickrate values
  56. extern float host_nexttick;
  57. //-----------------------------------------------------------------------------
  58. // ConVars and ConCommands
  59. //-----------------------------------------------------------------------------
  60. static void fps_max_callback( IConVar *var, const char *pOldValue, float flOldValue )
  61. {
  62. // Only update s_nDesiredFPSMax when not driven by the mat_powersavingsmode ConVar (see below)
  63. if ( !s_bFPSMaxDrivenByPowerSavings )
  64. {
  65. s_nDesiredFPSMax = ( (ConVar *)var)->GetInt();
  66. }
  67. }
  68. ConVar fps_max( "fps_max", STRINGIFY( DEFAULT_FPS_MAX ), FCVAR_RELEASE, "Frame rate limiter", fps_max_callback );
  69. // When set, this ConVar (typically driven from the advanced video settings) will drive fps_max (see above) to
  70. // half of the refresh rate, if the user hasn't otherwise set fps_max (via console, commandline etc)
  71. static void mat_powersavingsmode_callback( IConVar *var, const char *pOldValue, float flOldValue )
  72. {
  73. s_bFPSMaxDrivenByPowerSavings = true;
  74. int nRefresh = s_nDesiredFPSMax;
  75. if ( ( (ConVar *)var)->GetBool() )
  76. {
  77. MaterialVideoMode_t mode;
  78. materials->GetDisplayMode( mode );
  79. nRefresh = MAX( 30, ( mode.m_RefreshRate + 1 ) >> 1 ); // Half of display refresh rate (min of 30Hz)
  80. }
  81. fps_max.SetValue( nRefresh );
  82. s_bFPSMaxDrivenByPowerSavings = false;
  83. }
  84. static ConVar mat_powersavingsmode( "mat_powersavingsmode", "0", FCVAR_ARCHIVE, "Power Savings Mode", mat_powersavingsmode_callback );
  85. ConVar sleep_when_meeting_framerate( "sleep_when_meeting_framerate", IsGameConsole() ? "0" : "1", FCVAR_NONE, "Sleep instead of spinning if we're meeting the desired framerate." );
  86. static ConVar fps_max_splitscreen( "fps_max_splitscreen", STRINGIFY( DEFAULT_FPS_MAX ), 0, "Frame rate limiter, splitscreen" );
  87. #if !defined( DEDICATED )
  88. static ConVar fps_max_menu( "fps_max_menu", "120", FCVAR_RELEASE, "Frame rate limiter, main menu" );
  89. #endif
  90. static ConVar async_serialize( "async_serialize", "0", 0, "Force async reads to serialize for profiling" );
  91. #define ShouldSerializeAsync() async_serialize.GetBool()
  92. static ConVar vx_do_not_throttle_events( "vx_do_not_throttle_events", "0", 0, "Force VXConsole updates every frame; smoother vprof data on PS3 but at a slight (~0.2ms) perf cost." );
  93. #ifdef WIN32
  94. static void cpu_frequency_monitoring_callback( IConVar *var, const char *pOldValue, float flOldValue )
  95. {
  96. // Set the specified interval for CPU frequency monitoring
  97. SetCPUMonitoringInterval( (unsigned)( ( (ConVar *)var)->GetFloat() * 1000 ) );
  98. }
  99. ConVar cpu_frequency_monitoring( "cpu_frequency_monitoring", "0", FCVAR_RELEASE, "Set CPU frequency monitoring interval in seconds. Zero means disabled.", true, 0.0f, true, 10.0f, cpu_frequency_monitoring_callback );
  100. #endif
  101. float host_filtered_time_history[128] = { 0 };
  102. unsigned int host_filtered_time_history_pos = 0;
  103. CON_COMMAND( host_filtered_time_report, "Dumps time spent idle in previous frames in ms(dedicated only)." )
  104. {
  105. if ( sv.IsDedicated() )
  106. {
  107. for (int i = 1; i <= ARRAYSIZE( host_filtered_time_history ); ++i)
  108. {
  109. unsigned int slot = ( i + host_filtered_time_history_pos) % ARRAYSIZE( host_filtered_time_history );
  110. Msg( "%.4f\n", ( host_filtered_time_history[ slot ] * 1000 ) );
  111. }
  112. }
  113. }
  114. //-----------------------------------------------------------------------------
  115. // Purpose:
  116. //-----------------------------------------------------------------------------
  117. class CEngine : public IEngine
  118. {
  119. public:
  120. CEngine( void );
  121. virtual ~CEngine( void );
  122. bool Load( bool dedicated, const char *basedir );
  123. virtual void Unload( void );
  124. virtual EngineState_t GetState( void );
  125. virtual void SetNextState( EngineState_t iNextState );
  126. void Frame( void );
  127. float GetFrameTime( void );
  128. float GetCurTime( void );
  129. bool TrapKey_Event( ButtonCode_t key, bool down );
  130. void TrapMouse_Event( int buttons, bool down );
  131. void StartTrapMode( void );
  132. bool IsTrapping( void );
  133. bool CheckDoneTrapping( ButtonCode_t& key );
  134. int GetQuitting( void );
  135. void SetQuitting( int quittype );
  136. private:
  137. bool FilterTime( float t );
  138. int m_nQuitting;
  139. EngineState_t m_nDLLState;
  140. EngineState_t m_nNextDLLState;
  141. double m_flCurrentTime;
  142. float m_flFrameTime;
  143. double m_flPreviousTime;
  144. float m_flFilteredTime;
  145. float m_flMinFrameTime; // Expected duration of a frame, or zero if it is unlimited.
  146. #ifdef _GAMECONSOLE
  147. float m_flTimeSinceLastXBXProcessEventsCall;
  148. #endif
  149. #if WITH_OVERLAY_CURSOR_VISIBILITY_WORKAROUND
  150. STEAM_CALLBACK( CEngine, OnGameOverlayActivated, GameOverlayActivated_t, m_CallbackGameOverlayActivated );
  151. #endif
  152. };
  153. static CEngine g_Engine;
  154. IEngine *eng = ( IEngine * )&g_Engine;
  155. //IEngineAPI *engine = NULL;
  156. //-----------------------------------------------------------------------------
  157. // Purpose: Constructor
  158. //-----------------------------------------------------------------------------
  159. CEngine::CEngine( void )
  160. #if WITH_OVERLAY_CURSOR_VISIBILITY_WORKAROUND
  161. : m_CallbackGameOverlayActivated( this, &CEngine::OnGameOverlayActivated )
  162. #endif
  163. {
  164. m_nDLLState = DLL_INACTIVE;
  165. m_nNextDLLState = DLL_INACTIVE;
  166. m_flCurrentTime = 0.0;
  167. m_flFrameTime = 0.0f;
  168. m_flPreviousTime = 0.0;
  169. m_flFilteredTime = 0.0f;
  170. m_flMinFrameTime = 0.0f;
  171. #ifdef _GAMECONSOLE
  172. m_flTimeSinceLastXBXProcessEventsCall = 1.0e19; // make ti call on first frame
  173. #endif
  174. m_nQuitting = QUIT_NOTQUITTING;
  175. }
  176. //-----------------------------------------------------------------------------
  177. // Purpose:
  178. //-----------------------------------------------------------------------------
  179. CEngine::~CEngine( void )
  180. {
  181. }
  182. //-----------------------------------------------------------------------------
  183. // Purpose:
  184. //-----------------------------------------------------------------------------
  185. void CEngine::Unload( void )
  186. {
  187. Sys_ShutdownGame();
  188. m_nDLLState = DLL_INACTIVE;
  189. m_nNextDLLState = DLL_INACTIVE;
  190. }
  191. //-----------------------------------------------------------------------------
  192. // Purpose:
  193. // Output : Returns true on success, false on failure.
  194. //-----------------------------------------------------------------------------
  195. bool CEngine::Load( bool dedicated, const char *rootdir )
  196. {
  197. bool success = false;
  198. // Activate engine
  199. // NOTE: We must bypass the 'next state' block here for initialization to work properly.
  200. m_nDLLState = m_nNextDLLState = DLL_ACTIVE;
  201. if ( Sys_InitGame(
  202. g_AppSystemFactory,
  203. rootdir,
  204. game->GetMainWindowAddress(),
  205. dedicated ) )
  206. {
  207. success = true;
  208. UpdateMaterialSystemConfig();
  209. }
  210. return success;
  211. }
  212. //-----------------------------------------------------------------------------
  213. // Purpose:
  214. // Input : dt -
  215. // Output : Returns true on success, false on failure.
  216. //-----------------------------------------------------------------------------
  217. bool CEngine::FilterTime( float dt )
  218. {
  219. // Dedicated servers will lock fps max to tick rate essentially
  220. if ( sv.IsDedicated() && !g_bDedicatedServerBenchmarkMode )
  221. {
  222. m_flMinFrameTime = host_nexttick;
  223. return ( dt >= host_nexttick );
  224. }
  225. m_flMinFrameTime = 0.0f;
  226. // Dedicated's tic_rate regulates server frame rate. Don't apply fps filter here.
  227. // Only do this restriction on the client. Prevents clients from accomplishing certain
  228. // hacks by pausing their client for a period of time.
  229. if ( IsPC() && !sv.IsDedicated() && !CanCheat() && ( fps_max.GetFloat() < 30 ) && !Host_IsSinglePlayerGame() )
  230. {
  231. // Don't do anything if fps_max=0 (which means it's unlimited).
  232. if ( fps_max.GetFloat() != 0.0f )
  233. {
  234. Warning( "sv_cheats is 0 and fps_max is being limited to a minimum of 30 (or set to 0).\n" );
  235. fps_max.SetValue( 30.0f );
  236. }
  237. }
  238. float fps = fps_max.GetFloat();
  239. #ifdef _GAMECONSOLE
  240. static bool bInitializedFpsMax;
  241. static float flRefreshRate = 0;
  242. if ( !bInitializedFpsMax )
  243. {
  244. bInitializedFpsMax = true;
  245. {
  246. #ifdef _X360
  247. XVIDEO_MODE videoMode;
  248. XGetVideoMode( &videoMode );
  249. flRefreshRate = videoMode.RefreshRate;
  250. #elif defined( _PS3 )
  251. CellVideoOutState videoOutState;
  252. if ( cellVideoOutGetState( CELL_VIDEO_OUT_PRIMARY, 0, &videoOutState) >= CELL_OK )
  253. {
  254. struct { int rrFlag; float flRate; }
  255. arrRefreshRates[] = {
  256. { CELL_VIDEO_OUT_REFRESH_RATE_59_94HZ, 59.94f },
  257. { CELL_VIDEO_OUT_REFRESH_RATE_60HZ, 60.00f },
  258. { CELL_VIDEO_OUT_REFRESH_RATE_50HZ, 50.00f },
  259. { CELL_VIDEO_OUT_REFRESH_RATE_30HZ, 30.00f },
  260. };
  261. for ( int jj = 0; jj < ARRAYSIZE( arrRefreshRates ); ++ jj )
  262. {
  263. if ( arrRefreshRates[jj].rrFlag & videoOutState.displayMode.refreshRates )
  264. {
  265. flRefreshRate = arrRefreshRates[jj].flRate;
  266. break;
  267. }
  268. }
  269. if ( !flRefreshRate )
  270. {
  271. Warning( "Failed to determine PS3 video out refresh rate, assuming 59.94 Hz\n" );
  272. flRefreshRate = 59.94f;
  273. }
  274. }
  275. else
  276. {
  277. bInitializedFpsMax = false;
  278. }
  279. #else
  280. #error
  281. #endif
  282. }
  283. // Taken fps_max out since we'll use the presentation interval to force max 30fps
  284. // This gives us a much smoother frametime and ensure we don't drop a frame
  285. // due to the inaccuracy of fps_max
  286. //
  287. // if ( flRefreshRate > 49 )
  288. // {
  289. // float fpsMax = flRefreshRate / 2.0f, fpsSplitscreenMax = flRefreshRate / 2.0f;
  290. // DevMsg( "Setting fps_max to %f and fps_splitscreen_max to %f (from defaults of %f/%f ) to match refresh rate of %f\n", fpsMax, fpsSplitscreenMax, fps_max.GetFloat(), fps_max_splitscreen.GetFloat(), flRefreshRate );
  291. // fps_max.SetValue( fpsMax );
  292. // fps_max_splitscreen.SetValue( fpsSplitscreenMax );
  293. // }
  294. }
  295. bool bSplitscreen = false;
  296. // Need a smarter way of doing this
  297. for ( int i = 1; i < splitscreen->GetNumSplitScreenPlayers(); i++ )
  298. {
  299. if ( splitscreen->IsValidSplitScreenSlot( i ) )
  300. {
  301. bSplitscreen = true;
  302. break;
  303. }
  304. }
  305. if ( !bSplitscreen )
  306. {
  307. fps = fps_max.GetFloat();
  308. }
  309. else
  310. {
  311. fps = fps_max_splitscreen.GetFloat();
  312. }
  313. #endif
  314. #if !defined( DEDICATED )
  315. extern IVEngineClient *engineClient;
  316. if ( engineClient && !engineClient->IsConnected() && ( fps_max_menu.GetFloat() < fps ) )
  317. {
  318. fps = fps_max_menu.GetFloat();
  319. }
  320. #endif
  321. #ifdef _PS3
  322. {
  323. int nPresentFrequency = 1;
  324. if ( fps > 1.0f )
  325. {
  326. nPresentFrequency = int( (flRefreshRate + 1.0) / fps );
  327. nPresentFrequency = MAX( 1, nPresentFrequency );
  328. }
  329. g_pMaterialSystem->SetFlipPresentFrequency( nPresentFrequency );
  330. }
  331. #endif
  332. if ( fps > 0.0f )
  333. {
  334. // Limit fps to withing tolerable range
  335. // fps = max( MIN_FPS, fps ); // red herring - since we're only checking if dt < 1/fps, clamping against MIN_FPS has no effect
  336. fps = MIN( MAX_FPS, fps );
  337. float minframetime = 1.0 / fps;
  338. m_flMinFrameTime = minframetime;
  339. if (
  340. #if !defined(DEDICATED)
  341. !demoplayer->IsPlayingTimeDemo() &&
  342. #endif
  343. !g_bDedicatedServerBenchmarkMode &&
  344. dt < minframetime )
  345. {
  346. // framerate is too high
  347. return false;
  348. }
  349. }
  350. return true;
  351. }
  352. extern void PS3_PollSaveSystem();
  353. //-----------------------------------------------------------------------------
  354. // Purpose:
  355. // Output : int
  356. //-----------------------------------------------------------------------------
  357. void CEngine::Frame( void )
  358. {
  359. // yield the CPU for a little while when paused, minimized, or not the focus
  360. // FIXME: Move this to main windows message pump?
  361. static ConVarRef cl_embedded_stream_video_playing( "cl_embedded_stream_video_playing" );
  362. if ( IsPC() && !game->IsActiveApp() && !sv.IsDedicated()
  363. && !( cl_embedded_stream_video_playing.IsValid() && cl_embedded_stream_video_playing.GetBool() )
  364. && engine_no_focus_sleep.GetInt() > 0 )
  365. {
  366. g_pInputSystem->SleepUntilInput( engine_no_focus_sleep.GetInt() );
  367. }
  368. // Get current time
  369. m_flCurrentTime = Sys_FloatTime();
  370. // Watch for data from the CPU frequency monitoring system and print it to the console.
  371. const CPUFrequencyResults frequency = GetCPUFrequencyResults();
  372. static double s_lastFrequencyTimestamp;
  373. if ( frequency.m_timeStamp > s_lastFrequencyTimestamp )
  374. {
  375. s_lastFrequencyTimestamp = frequency.m_timeStamp;
  376. Msg( "~CPU Freq: %1.3f GHz Percent of requested: %3.1f%% Minimum percent seen: %3.1f%%\n",
  377. frequency.m_GHz, frequency.m_percentage, frequency.m_lowestPercentage );
  378. }
  379. // Determine dt since we last checked
  380. float dt = m_flCurrentTime - m_flPreviousTime;
  381. if ( sv.IsDedicated() && ( dt < 0 ) )
  382. {
  383. // ... but if the clock ever went backwards due to a bug,
  384. // we'd have no idea how much time has elapsed, so just
  385. // catch up to the next scheduled server tick.
  386. dt = host_nexttick;
  387. }
  388. #ifdef _GAMECONSOLE
  389. #define XBOX_PROCESS_EVENTS_MAXINTERVAL 0.2 // 1/5 sec
  390. // handle Xbox system messages process xbox events occasionally. every frame is too often -
  391. // makes this code add up to something
  392. m_flTimeSinceLastXBXProcessEventsCall += MAX( 0, dt );
  393. if ( m_flTimeSinceLastXBXProcessEventsCall > XBOX_PROCESS_EVENTS_MAXINTERVAL || vx_do_not_throttle_events.GetBool() )
  394. {
  395. XBX_ProcessEvents();
  396. XBX_DispatchEventsQueue();
  397. m_flTimeSinceLastXBXProcessEventsCall = 0.;
  398. }
  399. #endif
  400. // Remember old time
  401. m_flPreviousTime = m_flCurrentTime;
  402. // Accumulate current time delta into the true "frametime"
  403. m_flFrameTime += dt;
  404. // If the time is < 0, that means we've restarted.
  405. // Set the new time high enough so the engine will run a frame
  406. if ( m_flFrameTime < 0.0f )
  407. return;
  408. // If the frametime is still too short, don't pass through
  409. if ( !FilterTime( m_flFrameTime ) )
  410. {
  411. #ifdef POSIX
  412. double fSleepNS = ( m_flMinFrameTime - m_flFrameTime ) * 1000000000.0;
  413. unsigned nSleepNS = (unsigned)floor( fSleepNS );
  414. if ( nSleepNS && sleep_when_meeting_framerate.GetInt() )
  415. {
  416. TM_ZONE( TELEMETRY_LEVEL0, TMZF_NONE, "Engine Nano Sleep" );
  417. ThreadNanoSleep( nSleepNS );
  418. }
  419. #else //POSIX
  420. float fSleepMS = ( m_flMinFrameTime - m_flFrameTime ) * 1000;
  421. unsigned nSleepMS = (unsigned)floor( fSleepMS );
  422. if ( nSleepMS && sleep_when_meeting_framerate.GetInt() )
  423. {
  424. TM_ZONE( TELEMETRY_LEVEL0, TMZF_NONE, "Engine Sleep" );
  425. ThreadSleep( nSleepMS );
  426. }
  427. #endif //POSIX
  428. m_flFilteredTime += dt;
  429. return;
  430. }
  431. TM_ZONE( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __PRETTY_FUNCTION__ );
  432. if ( ShouldSerializeAsync() )
  433. {
  434. static ConVar *pSyncReportConVar = g_pCVar->FindVar( "fs_report_sync_opens" );
  435. bool bReportingSyncOpens = ( pSyncReportConVar && pSyncReportConVar->GetInt() );
  436. int reportLevel = 0;
  437. if ( bReportingSyncOpens )
  438. {
  439. reportLevel = pSyncReportConVar->GetInt();
  440. pSyncReportConVar->SetValue( 0 );
  441. }
  442. g_pFileSystem->AsyncFinishAll();
  443. if ( bReportingSyncOpens )
  444. {
  445. pSyncReportConVar->SetValue( reportLevel );
  446. }
  447. }
  448. #ifdef VPROF_ENABLED
  449. PreUpdateProfile( m_flFilteredTime );
  450. #endif
  451. // Record previous swallowed time counts.
  452. host_filtered_time_history[ host_filtered_time_history_pos ] = m_flFilteredTime;
  453. host_filtered_time_history_pos = ( host_filtered_time_history_pos + 1 ) % ARRAYSIZE(host_filtered_time_history);
  454. // Reset swallowed time...
  455. m_flFilteredTime = 0.0f;
  456. #ifndef DEDICATED
  457. if ( !sv.IsDedicated() )
  458. {
  459. ClientDLL_FrameStageNotify( FRAME_START );
  460. }
  461. #endif
  462. #ifdef VPROF_ENABLED
  463. PostUpdateProfile();
  464. #endif
  465. TelemetryTick();
  466. ETWRenderFrameMark( sv.IsDedicated() );
  467. { // profile scope
  468. VPROF_BUDGET( "CEngine::Frame", VPROF_BUDGETGROUP_OTHER_UNACCOUNTED );
  469. #ifdef RAD_TELEMETRY_ENABLED
  470. TmU64 time0 = tmFastTime();
  471. #endif
  472. switch( m_nDLLState )
  473. {
  474. case DLL_PAUSED: // paused, in hammer
  475. case DLL_INACTIVE: // no dll
  476. break;
  477. case DLL_ACTIVE: // engine is focused
  478. case DLL_CLOSE: // closing down dll
  479. case DLL_RESTART: // engine is shutting down but will restart right away
  480. // Run the engine frame
  481. HostState_Frame( m_flFrameTime );
  482. break;
  483. }
  484. // Has the state changed?
  485. if ( m_nNextDLLState != m_nDLLState )
  486. {
  487. m_nDLLState = m_nNextDLLState;
  488. // Do special things if we change to particular states
  489. switch( m_nDLLState )
  490. {
  491. case DLL_CLOSE:
  492. SetQuitting( QUIT_TODESKTOP );
  493. break;
  494. case DLL_RESTART:
  495. SetQuitting( QUIT_RESTART );
  496. break;
  497. }
  498. }
  499. #ifdef RAD_TELEMETRY_ENABLED
  500. float time = ( tmFastTime() - time0 ) * g_Telemetry.flRDTSCToMilliSeconds;
  501. if( time > 0.5f )
  502. {
  503. tmPlot( TELEMETRY_LEVEL0, TMPT_TIME_MS, 0, time, "CEngine::Frame(ms)" );
  504. }
  505. #endif
  506. } // profile scope
  507. // Reset for next frame
  508. m_flFrameTime = 0.0f;
  509. #if defined( VPROF_ENABLED ) && defined( VPROF_VXCONSOLE_EXISTS )
  510. UpdateVXConsoleProfile();
  511. #endif
  512. // reload dlls that are marked for reload; currently for debug purposes only
  513. #ifdef ENGINE_MANAGES_VJOBS
  514. extern void ReloadDlls();
  515. ReloadDlls();
  516. #endif
  517. }
  518. //-----------------------------------------------------------------------------
  519. // Purpose:
  520. //-----------------------------------------------------------------------------
  521. CEngine::EngineState_t CEngine::GetState( void )
  522. {
  523. return m_nDLLState;
  524. }
  525. //-----------------------------------------------------------------------------
  526. // Purpose:
  527. //-----------------------------------------------------------------------------
  528. void CEngine::SetNextState( EngineState_t iNextState )
  529. {
  530. m_nNextDLLState = iNextState;
  531. }
  532. //-----------------------------------------------------------------------------
  533. // Purpose:
  534. //-----------------------------------------------------------------------------
  535. float CEngine::GetFrameTime( void )
  536. {
  537. return m_flFrameTime;
  538. }
  539. //-----------------------------------------------------------------------------
  540. // Purpose:
  541. //-----------------------------------------------------------------------------
  542. float CEngine::GetCurTime( void )
  543. {
  544. return m_flCurrentTime;
  545. }
  546. //-----------------------------------------------------------------------------
  547. // Purpose: Flag that we are in the process of quiting
  548. //-----------------------------------------------------------------------------
  549. void CEngine::SetQuitting( int quittype )
  550. {
  551. m_nQuitting = quittype;
  552. }
  553. //-----------------------------------------------------------------------------
  554. // Purpose: Check whether we are ready to exit
  555. //-----------------------------------------------------------------------------
  556. int CEngine::GetQuitting( void )
  557. {
  558. return m_nQuitting;
  559. }
  560. #if WITH_OVERLAY_CURSOR_VISIBILITY_WORKAROUND
  561. //-----------------------------------------------------------------------------
  562. // Purpose: The overlay doesn't properly work on OS X 64-bit because a bunch of
  563. // Cocoa functions that we hook were never ported to 64-bit. Until that is fixed,
  564. // we basically have to work around this by making sure the cursor is visible
  565. // and set to something that is reasonable for usage in the overlay.
  566. //-----------------------------------------------------------------------------
  567. void CEngine::OnGameOverlayActivated( GameOverlayActivated_t *pGameOverlayActivated )
  568. {
  569. Assert( pGameOverlayActivated );
  570. if ( pGameOverlayActivated->m_bActive )
  571. g_pLauncherMgr->ForceSystemCursorVisible();
  572. else
  573. g_pLauncherMgr->UnforceSystemCursorVisible();
  574. }
  575. #endif // WITH_OVERLAY_CURSOR_VISIBILITY_WORKAROUND