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.

167 lines
4.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // The copyright to the contents herein is the property of Valve, L.L.C.
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. // $Header: $
  9. // $NoKeywords: $
  10. //
  11. // An RTS!
  12. //=============================================================================
  13. #include "legion.h"
  14. #include <windows.h>
  15. #include "inputsystem/iinputsystem.h"
  16. #include "networksystem/inetworksystem.h"
  17. #include "filesystem.h"
  18. #include "materialsystem/imaterialsystem.h"
  19. #include "vgui/IVGui.h"
  20. #include "vgui/ISurface.h"
  21. #include "VGuiMatSurface/IMatSystemSurface.h"
  22. #include "vgui_controls/controls.h"
  23. #include "vgui/ILocalize.h"
  24. #include "vgui_controls/AnimationController.h"
  25. #include "gamemanager.h"
  26. #include "menumanager.h"
  27. #include "physicsmanager.h"
  28. #include "rendermanager.h"
  29. #include "uimanager.h"
  30. #include "inputmanager.h"
  31. #include "networkmanager.h"
  32. #include "worldmanager.h"
  33. #include "tier3/tier3.h"
  34. //-----------------------------------------------------------------------------
  35. // Purpose: Warning/Msg call back through this API
  36. // Input : type -
  37. // *pMsg -
  38. // Output : SpewRetval_t
  39. //-----------------------------------------------------------------------------
  40. SpewRetval_t SpewFunc( SpewType_t type, char const *pMsg )
  41. {
  42. OutputDebugString( pMsg );
  43. if ( type == SPEW_ASSERT )
  44. {
  45. DebuggerBreak();
  46. }
  47. return SPEW_CONTINUE;
  48. }
  49. static CLegionApp s_LegionApp;
  50. extern CLegionApp *g_pApp = &s_LegionApp;
  51. DEFINE_WINDOWED_STEAM_APPLICATION_OBJECT_GLOBALVAR( CLegionApp, s_LegionApp );
  52. //-----------------------------------------------------------------------------
  53. // Create all singleton systems
  54. //-----------------------------------------------------------------------------
  55. bool CLegionApp::Create()
  56. {
  57. SpewOutputFunc( SpewFunc );
  58. // FIXME: Put this into tier1librariesconnect
  59. MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f, false );
  60. if ( !BaseClass::Create() )
  61. return false;
  62. AppSystemInfo_t appSystems[] =
  63. {
  64. { "networksystem.dll", NETWORKSYSTEM_INTERFACE_VERSION },
  65. { "", "" } // Required to terminate the list
  66. };
  67. return AddSystems( appSystems );
  68. }
  69. bool CLegionApp::PreInit( )
  70. {
  71. if ( !BaseClass::PreInit() )
  72. return false;
  73. if ( !g_pInputSystem || !g_pFullFileSystem || !g_pNetworkSystem || !g_pMaterialSystem || !g_pVGui || !g_pVGuiSurface || !g_pMatSystemSurface )
  74. {
  75. Warning( "Legion is missing a required interface!\n" );
  76. return false;
  77. }
  78. return true;
  79. }
  80. void CLegionApp::PostShutdown()
  81. {
  82. BaseClass::PostShutdown();
  83. }
  84. bool CLegionApp::RegisterConCommandBase( ConCommandBase *pCommand )
  85. {
  86. // Mark for easy removal
  87. pCommand->AddFlags( FCVAR_CLIENTDLL );
  88. pCommand->SetNext( 0 );
  89. // Link to variable list
  90. g_pCVar->RegisterConCommandBase( pCommand );
  91. return true;
  92. }
  93. void CLegionApp::UnregisterConCommandBase( ConCommandBase *pCommand )
  94. {
  95. // Unlink from variable list
  96. g_pCVar->UnlinkVariable( pCommand );
  97. }
  98. //-----------------------------------------------------------------------------
  99. // main application
  100. //-----------------------------------------------------------------------------
  101. int CLegionApp::Main()
  102. {
  103. if (!SetVideoMode())
  104. return 0;
  105. ConCommandBaseMgr::OneTimeInit( this );
  106. g_pMaterialSystem->ModInit();
  107. // World database
  108. IGameManager::Add( g_pWorldManager );
  109. // Output
  110. IGameManager::Add( g_pRenderManager );
  111. // Input
  112. IGameManager::Add( g_pNetworkManager );
  113. IGameManager::Add( g_pInputManager );
  114. IGameManager::Add( g_pMenuManager );
  115. IGameManager::Add( g_pUIManager );
  116. // Simulation
  117. IGameManager::Add( g_pPhysicsManager );
  118. // Init the game managers
  119. if ( !IGameManager::InitAllManagers() )
  120. return 0;
  121. // First menu to start on
  122. g_pMenuManager->PushMenu( "MainMenu" );
  123. // This is the main game loop
  124. IGameManager::Start();
  125. // Shut down game systems
  126. IGameManager::ShutdownAllManagers();
  127. g_pMaterialSystem->ModShutdown();
  128. g_pCVar->UnlinkVariables( FCVAR_CLIENTDLL );
  129. return 1;
  130. }