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.

220 lines
4.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. // scenemanager.cpp : Defines the entry point for the console application.
  9. //
  10. #include "cbase.h"
  11. #include "appframework/tier3app.h"
  12. #include "workspacemanager.h"
  13. #include "filesystem.h"
  14. #include "FileSystem_Tools.h"
  15. #include "cmdlib.h"
  16. #include "vstdlib/random.h"
  17. #include "SoundEmitterSystem/isoundemittersystembase.h"
  18. #include "iscenemanagersound.h"
  19. #include <vgui/ILocalize.h>
  20. #include <vgui/IVGui.h>
  21. #include "tier0/icommandline.h"
  22. #include "icvar.h"
  23. #include "vstdlib/cvar.h"
  24. #include "mathlib/mathlib.h"
  25. char cmdline[1024] = "";
  26. static CUniformRandomStream g_Random;
  27. IUniformRandomStream *random = &g_Random;
  28. IFileSystem *filesystem = NULL;
  29. SpewRetval_t SceneManagerSpewFunc( SpewType_t spewType, char const *pMsg )
  30. {
  31. switch (spewType)
  32. {
  33. case SPEW_ERROR:
  34. {
  35. MessageBox(NULL, pMsg, "FATAL ERROR", MB_OK);
  36. }
  37. return SPEW_ABORT;
  38. case SPEW_WARNING:
  39. {
  40. Con_ColorPrintf( 255, 0, 0, pMsg );
  41. }
  42. break;
  43. case SPEW_ASSERT:
  44. {
  45. Con_ColorPrintf( 255, 0, 0, pMsg );
  46. }
  47. #ifdef _DEBUG
  48. return SPEW_DEBUGGER;
  49. #else
  50. return SPEW_CONTINUE;
  51. #endif
  52. default:
  53. {
  54. Con_Printf(pMsg);
  55. }
  56. break;
  57. }
  58. return SPEW_CONTINUE;
  59. }
  60. //-----------------------------------------------------------------------------
  61. // The application object
  62. //-----------------------------------------------------------------------------
  63. class CHLSceneManagerApp : public CTier3SteamApp
  64. {
  65. typedef CTier3SteamApp BaseClass;
  66. public:
  67. // Methods of IApplication
  68. virtual bool Create();
  69. virtual bool PreInit();
  70. virtual int Main();
  71. virtual void PostShutdown();
  72. virtual void Destroy();
  73. private:
  74. // Sets up the search paths
  75. bool SetupSearchPaths();
  76. };
  77. bool CHLSceneManagerApp::Create()
  78. {
  79. SpewOutputFunc( SceneManagerSpewFunc );
  80. AppSystemInfo_t appSystems[] =
  81. {
  82. { "vgui2.dll", VGUI_IVGUI_INTERFACE_VERSION },
  83. { "soundemittersystem.dll", SOUNDEMITTERSYSTEM_INTERFACE_VERSION },
  84. { "", "" } // Required to terminate the list
  85. };
  86. return AddSystems( appSystems );
  87. }
  88. void CHLSceneManagerApp::Destroy()
  89. {
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Sets up the game path
  93. //-----------------------------------------------------------------------------
  94. bool CHLSceneManagerApp::SetupSearchPaths()
  95. {
  96. if ( !BaseClass::SetupSearchPaths( NULL, false, true ) )
  97. return false;
  98. // Set gamedir.
  99. Q_MakeAbsolutePath( gamedir, sizeof( gamedir ), GetGameInfoPath() );
  100. Q_AppendSlash( gamedir, sizeof( gamedir ) );
  101. return true;
  102. }
  103. //-----------------------------------------------------------------------------
  104. // Init, shutdown
  105. //-----------------------------------------------------------------------------
  106. bool CHLSceneManagerApp::PreInit( )
  107. {
  108. MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f, false, false, false, false );
  109. if ( !BaseClass::PreInit() )
  110. return false;
  111. g_pFileSystem = filesystem = g_pFullFileSystem;
  112. if ( !g_pSoundEmitterSystem || !g_pVGuiLocalize || !g_pFileSystem )
  113. {
  114. Error("Unable to load required library interface!\n");
  115. return false;
  116. }
  117. filesystem->SetWarningFunc( Warning );
  118. // Add paths...
  119. if ( !SetupSearchPaths() )
  120. return false;
  121. return true;
  122. }
  123. void CHLSceneManagerApp::PostShutdown()
  124. {
  125. g_pFileSystem = filesystem = NULL;
  126. BaseClass::PostShutdown();
  127. }
  128. //-----------------------------------------------------------------------------
  129. // main application
  130. //-----------------------------------------------------------------------------
  131. int CHLSceneManagerApp::Main()
  132. {
  133. g_pSoundEmitterSystem->ModInit();
  134. sound->Init();
  135. CWorkspaceManager *sm = new CWorkspaceManager();
  136. bool workspace_loaded = false;
  137. for ( int i = 1; i < CommandLine()->ParmCount(); i++ )
  138. {
  139. char const *argv = CommandLine()->GetParm( i );
  140. if ( !workspace_loaded && strstr (argv, ".vsw") )
  141. {
  142. workspace_loaded = true;
  143. // Strip game directory and slash
  144. char workspace_name[ 512 ];
  145. filesystem->FullPathToRelativePath( argv, workspace_name, sizeof( workspace_name ) );
  146. sm->AutoLoad( workspace_name );
  147. }
  148. }
  149. if ( !workspace_loaded )
  150. {
  151. sm->AutoLoad( NULL );
  152. }
  153. int retval = mx::run ();
  154. sound->Shutdown();
  155. g_pSoundEmitterSystem->ModShutdown();
  156. return retval;
  157. }
  158. int main (int argc, char *argv[])
  159. {
  160. CommandLine()->CreateCmdLine( argc, argv );
  161. CoInitialize(NULL);
  162. // make sure, we start in the right directory
  163. char szName[256];
  164. strcpy (szName, mx::getApplicationPath() );
  165. mx::init (argc, argv);
  166. char workingdir[ 256 ];
  167. workingdir[0] = 0;
  168. Q_getwd( workingdir, sizeof( workingdir ) );
  169. CHLSceneManagerApp sceneManagerApp;
  170. CSteamApplication steamApplication( &sceneManagerApp );
  171. int nRetVal = steamApplication.Run();
  172. CoUninitialize();
  173. return nRetVal;
  174. }