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.

182 lines
5.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Pieces of the application framework, shared between POSIX systems (Mac OS X, Linux, etc)
  4. //
  5. // $Revision: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "appframework/AppFramework.h"
  9. #include "tier0/dbg.h"
  10. #include "tier0/icommandline.h"
  11. #include "interface.h"
  12. #include "filesystem.h"
  13. #include "appframework/IAppSystemGroup.h"
  14. #include "filesystem_init.h"
  15. #include "tier1/convar.h"
  16. #include "vstdlib/cvar.h"
  17. #include "togl/rendermechanism.h"
  18. // NOTE: This has to be the last file included! (turned off below, since this is included like a header)
  19. #include "tier0/memdbgon.h"
  20. //-----------------------------------------------------------------------------
  21. // Globals...
  22. //-----------------------------------------------------------------------------
  23. HINSTANCE s_HInstance;
  24. //#if !defined(LINUX)
  25. //static CSimpleLoggingListener s_SimpleLoggingListener;
  26. //ILoggingListener *g_pDefaultLoggingListener = &s_SimpleLoggingListener;
  27. //#endif
  28. //-----------------------------------------------------------------------------
  29. // HACK: Since I don't want to refit vgui yet...
  30. //-----------------------------------------------------------------------------
  31. void *GetAppInstance()
  32. {
  33. return s_HInstance;
  34. }
  35. //-----------------------------------------------------------------------------
  36. // Sets the application instance, should only be used if you're not calling AppMain.
  37. //-----------------------------------------------------------------------------
  38. void SetAppInstance( void* hInstance )
  39. {
  40. s_HInstance = (HINSTANCE)hInstance;
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Version of AppMain used by windows applications
  44. //-----------------------------------------------------------------------------
  45. int AppMain( void* hInstance, void* hPrevInstance, const char* lpCmdLine, int nCmdShow, CAppSystemGroup *pAppSystemGroup )
  46. {
  47. Assert( 0 );
  48. return -1;
  49. }
  50. //#if !defined(LINUX)
  51. //static CNonFatalLoggingResponsePolicy s_NonFatalLoggingResponsePolicy;
  52. //#endif
  53. //-----------------------------------------------------------------------------
  54. // Version of AppMain used by console applications
  55. //-----------------------------------------------------------------------------
  56. int AppMain( int argc, char **argv, CAppSystemGroup *pAppSystemGroup )
  57. {
  58. Assert( pAppSystemGroup );
  59. //#if !defined(LINUX)
  60. // LoggingSystem_SetLoggingResponsePolicy( &s_NonFatalLoggingResponsePolicy );
  61. //#endif
  62. s_HInstance = NULL;
  63. CommandLine()->CreateCmdLine( argc, argv );
  64. return pAppSystemGroup->Run( );
  65. }
  66. //-----------------------------------------------------------------------------
  67. //
  68. // Default implementation of an application meant to be run using Steam
  69. //
  70. //-----------------------------------------------------------------------------
  71. //-----------------------------------------------------------------------------
  72. // Constructor
  73. //-----------------------------------------------------------------------------
  74. CSteamApplication::CSteamApplication( CSteamAppSystemGroup *pAppSystemGroup )
  75. {
  76. m_pChildAppSystemGroup = pAppSystemGroup;
  77. m_pFileSystem = NULL;
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Create necessary interfaces
  81. //-----------------------------------------------------------------------------
  82. bool CSteamApplication::Create( )
  83. {
  84. FileSystem_SetErrorMode( FS_ERRORMODE_NONE );
  85. char pFileSystemDLL[MAX_PATH];
  86. if ( FileSystem_GetFileSystemDLLName( pFileSystemDLL, MAX_PATH, m_bSteam ) != FS_OK )
  87. return false;
  88. // Add in the cvar factory
  89. AppModule_t cvarModule = LoadModule( VStdLib_GetICVarFactory() );
  90. AddSystem( cvarModule, CVAR_INTERFACE_VERSION );
  91. AppModule_t fileSystemModule = LoadModule( pFileSystemDLL );
  92. m_pFileSystem = (IFileSystem*)AddSystem( fileSystemModule, FILESYSTEM_INTERFACE_VERSION );
  93. if ( !m_pFileSystem )
  94. {
  95. Error( "Unable to load %s", pFileSystemDLL );
  96. return false;
  97. }
  98. return true;
  99. }
  100. //-----------------------------------------------------------------------------
  101. // The file system pointer is invalid at this point
  102. //-----------------------------------------------------------------------------
  103. void CSteamApplication::Destroy()
  104. {
  105. m_pFileSystem = NULL;
  106. }
  107. //-----------------------------------------------------------------------------
  108. // Pre-init, shutdown
  109. //-----------------------------------------------------------------------------
  110. bool CSteamApplication::PreInit( )
  111. {
  112. return true;
  113. }
  114. void CSteamApplication::PostShutdown( )
  115. {
  116. }
  117. //-----------------------------------------------------------------------------
  118. // Run steam main loop
  119. //-----------------------------------------------------------------------------
  120. int CSteamApplication::Main( )
  121. {
  122. // Now that Steam is loaded, we can load up main libraries through steam
  123. m_pChildAppSystemGroup->Setup( m_pFileSystem, this );
  124. return m_pChildAppSystemGroup->Run( );
  125. }
  126. int CSteamApplication::Startup()
  127. {
  128. int nRetVal = BaseClass::Startup();
  129. if ( GetErrorStage() != NONE )
  130. return nRetVal;
  131. if ( FileSystem_SetBasePaths( m_pFileSystem ) != FS_OK )
  132. return 0;
  133. // Now that Steam is loaded, we can load up main libraries through steam
  134. m_pChildAppSystemGroup->Setup( m_pFileSystem, this );
  135. return m_pChildAppSystemGroup->Startup();
  136. }
  137. void CSteamApplication::Shutdown()
  138. {
  139. m_pChildAppSystemGroup->Shutdown();
  140. BaseClass::Shutdown();
  141. }
  142. // Turn off memdbg macros (turned on up top) since this is included like a header
  143. #include "tier0/memdbgoff.h"