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.

180 lines
5.5 KiB

  1. //====== Copyright 1996-2005, 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. static CSimpleLoggingListener s_SimpleLoggingListener;
  25. ILoggingListener *g_pDefaultLoggingListener = &s_SimpleLoggingListener;
  26. //-----------------------------------------------------------------------------
  27. // HACK: Since I don't want to refit vgui yet...
  28. //-----------------------------------------------------------------------------
  29. void *GetAppInstance()
  30. {
  31. return s_HInstance;
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Sets the application instance, should only be used if you're not calling AppMain.
  35. //-----------------------------------------------------------------------------
  36. void SetAppInstance( void* hInstance )
  37. {
  38. s_HInstance = (HINSTANCE)hInstance;
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Version of AppMain used by windows applications
  42. //-----------------------------------------------------------------------------
  43. int AppMain( void* hInstance, void* hPrevInstance, const char* lpCmdLine, int nCmdShow, CAppSystemGroup *pAppSystemGroup )
  44. {
  45. Assert( 0 );
  46. return -1;
  47. }
  48. static CNonFatalLoggingResponsePolicy s_NonFatalLoggingResponsePolicy;
  49. //-----------------------------------------------------------------------------
  50. // Version of AppMain used by console applications
  51. //-----------------------------------------------------------------------------
  52. int AppMain( int argc, char **argv, CAppSystemGroup *pAppSystemGroup )
  53. {
  54. Assert( pAppSystemGroup );
  55. LoggingSystem_SetLoggingResponsePolicy( &s_NonFatalLoggingResponsePolicy );
  56. s_HInstance = NULL;
  57. CommandLine()->CreateCmdLine( argc, argv );
  58. return pAppSystemGroup->Run( );
  59. }
  60. //-----------------------------------------------------------------------------
  61. //
  62. // Default implementation of an application meant to be run using Steam
  63. //
  64. //-----------------------------------------------------------------------------
  65. //-----------------------------------------------------------------------------
  66. // Constructor
  67. //-----------------------------------------------------------------------------
  68. CSteamApplication::CSteamApplication( CSteamAppSystemGroup *pAppSystemGroup )
  69. {
  70. m_pChildAppSystemGroup = pAppSystemGroup;
  71. m_pFileSystem = NULL;
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Create necessary interfaces
  75. //-----------------------------------------------------------------------------
  76. bool CSteamApplication::Create( )
  77. {
  78. FileSystem_SetErrorMode( FS_ERRORMODE_NONE );
  79. char pFileSystemDLL[MAX_PATH];
  80. if ( FileSystem_GetFileSystemDLLName( pFileSystemDLL, MAX_PATH, m_bSteam ) != FS_OK )
  81. return false;
  82. // Add in the cvar factory
  83. AppModule_t cvarModule = LoadModule( VStdLib_GetICVarFactory() );
  84. AddSystem( cvarModule, CVAR_INTERFACE_VERSION );
  85. AppModule_t fileSystemModule = LoadModule( pFileSystemDLL );
  86. m_pFileSystem = (IFileSystem*)AddSystem( fileSystemModule, FILESYSTEM_INTERFACE_VERSION );
  87. if ( !m_pFileSystem )
  88. {
  89. Error( "Unable to load %s", pFileSystemDLL );
  90. return false;
  91. }
  92. return true;
  93. }
  94. bool CSteamApplication::GetFileSystemDLLName( char *pOut, int nMaxBytes, bool &bIsSteam )
  95. {
  96. return FileSystem_GetFileSystemDLLName( pOut, nMaxBytes, bIsSteam ) == FS_OK;
  97. }
  98. //-----------------------------------------------------------------------------
  99. // The file system pointer is invalid at this point
  100. //-----------------------------------------------------------------------------
  101. void CSteamApplication::Destroy()
  102. {
  103. m_pFileSystem = NULL;
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Pre-init, shutdown
  107. //-----------------------------------------------------------------------------
  108. bool CSteamApplication::PreInit( )
  109. {
  110. return true;
  111. }
  112. void CSteamApplication::PostShutdown( )
  113. {
  114. }
  115. //-----------------------------------------------------------------------------
  116. // Run steam main loop
  117. //-----------------------------------------------------------------------------
  118. int CSteamApplication::Main( )
  119. {
  120. // Now that Steam is loaded, we can load up main libraries through steam
  121. m_pChildAppSystemGroup->Setup( m_pFileSystem, this );
  122. return m_pChildAppSystemGroup->Run( );
  123. }
  124. int CSteamApplication::Startup()
  125. {
  126. int nRetVal = BaseClass::Startup();
  127. if ( GetCurrentStage() != NONE )
  128. return nRetVal;
  129. if ( FileSystem_SetBasePaths( m_pFileSystem ) != FS_OK )
  130. return 0;
  131. // Now that Steam is loaded, we can load up main libraries through steam
  132. m_pChildAppSystemGroup->Setup( m_pFileSystem, this );
  133. return m_pChildAppSystemGroup->Startup();
  134. }
  135. void CSteamApplication::Shutdown()
  136. {
  137. m_pChildAppSystemGroup->Shutdown();
  138. BaseClass::Shutdown();
  139. }
  140. // Turn off memdbg macros (turned on up top) since this is included like a header
  141. #include "tier0/memdbgoff.h"