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.

158 lines
6.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: An application framework
  4. //
  5. // $Revision: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #ifndef APPFRAMEWORK_H
  9. #define APPFRAMEWORK_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "appframework/IAppSystemGroup.h"
  14. //-----------------------------------------------------------------------------
  15. // Gets the application instance..
  16. //-----------------------------------------------------------------------------
  17. void *GetAppInstance();
  18. //-----------------------------------------------------------------------------
  19. // Sets the application instance, should only be used if you're not calling AppMain.
  20. //-----------------------------------------------------------------------------
  21. void SetAppInstance( void* hInstance );
  22. //-----------------------------------------------------------------------------
  23. // Main entry point for the application
  24. //-----------------------------------------------------------------------------
  25. int AppMain( void* hInstance, void* hPrevInstance, const char* lpCmdLine, int nCmdShow, CAppSystemGroup *pAppSystemGroup );
  26. int AppMain( int argc, char **argv, CAppSystemGroup *pAppSystemGroup );
  27. //-----------------------------------------------------------------------------
  28. // Used to startup/shutdown the application
  29. //-----------------------------------------------------------------------------
  30. int AppStartup( void* hInstance, void* hPrevInstance, const char* lpCmdLine, int nCmdShow, CAppSystemGroup *pAppSystemGroup );
  31. int AppStartup( int argc, char **argv, CAppSystemGroup *pAppSystemGroup );
  32. void AppShutdown( CAppSystemGroup *pAppSystemGroup );
  33. //-----------------------------------------------------------------------------
  34. // Macros to create singleton application objects for windowed + console apps
  35. //-----------------------------------------------------------------------------
  36. #if !defined( _X360 )
  37. #ifdef WIN32
  38. #define DEFINE_WINDOWED_APPLICATION_OBJECT_GLOBALVAR( _globalVarName ) \
  39. int __stdcall WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) \
  40. { \
  41. return AppMain( hInstance, hPrevInstance, lpCmdLine, nCmdShow, &_globalVarName ); \
  42. }
  43. #elif defined( OSX )
  44. #define DEFINE_WINDOWED_APPLICATION_OBJECT_GLOBALVAR( _globalVarName ) \
  45. int main( int argc, char **argv ) \
  46. { \
  47. extern int ValveCocoaMain( int argc, char **argv, CAppSystemGroup *pAppSystemGroup ); \
  48. return ValveCocoaMain( argc, argv, &_globalVarName ); \
  49. }
  50. #elif defined( LINUX )
  51. #define DEFINE_WINDOWED_APPLICATION_OBJECT_GLOBALVAR( _globalVarName ) \
  52. int main( int argc, char **argv ) \
  53. { \
  54. extern int ValveLinuxWindowedMain( int argc, char **argv, CAppSystemGroup *pAppSystemGroup ); \
  55. return ValveLinuxWindowedMain( argc, argv, &_globalVarName ); \
  56. }
  57. #else
  58. #error
  59. #endif
  60. #else
  61. #define DEFINE_WINDOWED_APPLICATION_OBJECT_GLOBALVAR( _globalVarName ) \
  62. void __cdecl main() \
  63. { \
  64. AppMain( (HINSTANCE)1, (HINSTANCE)0, NULL, 0, &_globalVarName ); \
  65. }
  66. #endif
  67. #if !defined( _X360 )
  68. #define DEFINE_CONSOLE_APPLICATION_OBJECT_GLOBALVAR( _globalVarName ) \
  69. int main( int argc, char **argv ) \
  70. { \
  71. return AppMain( argc, argv, &_globalVarName ); \
  72. }
  73. #else
  74. #define DEFINE_CONSOLE_APPLICATION_OBJECT_GLOBALVAR( _globalVarName ) \
  75. void __cdecl main() \
  76. { \
  77. AppMain( 0, (char**)NULL, &_globalVarName ); \
  78. }
  79. #endif
  80. #define DEFINE_WINDOWED_APPLICATION_OBJECT( _className ) \
  81. static _className __s_ApplicationObject; \
  82. DEFINE_WINDOWED_APPLICATION_OBJECT_GLOBALVAR( __s_ApplicationObject )
  83. #define DEFINE_CONSOLE_APPLICATION_OBJECT( _className ) \
  84. static _className __s_ApplicationObject; \
  85. DEFINE_CONSOLE_APPLICATION_OBJECT_GLOBALVAR( __s_ApplicationObject )
  86. //-----------------------------------------------------------------------------
  87. // This class is a helper class used for steam-based applications.
  88. // It loads up the file system in preparation for using it to load other
  89. // required modules from steam.
  90. //-----------------------------------------------------------------------------
  91. class CSteamApplication : public CAppSystemGroup
  92. {
  93. typedef CAppSystemGroup BaseClass;
  94. public:
  95. CSteamApplication( CSteamAppSystemGroup *pAppSystemGroup );
  96. // Implementation of IAppSystemGroup
  97. virtual bool Create( );
  98. virtual bool PreInit( );
  99. virtual int Main( );
  100. virtual void PostShutdown();
  101. virtual void Destroy();
  102. // Use this version in cases where you can't control the main loop and
  103. // expect to be ticked
  104. virtual int Startup();
  105. virtual void Shutdown();
  106. protected:
  107. IFileSystem *m_pFileSystem;
  108. CSteamAppSystemGroup *m_pChildAppSystemGroup;
  109. bool m_bSteam;
  110. };
  111. //-----------------------------------------------------------------------------
  112. // Macros to help create singleton application objects for windowed + console steam apps
  113. //-----------------------------------------------------------------------------
  114. #define DEFINE_WINDOWED_STEAM_APPLICATION_OBJECT_GLOBALVAR( _className, _varName ) \
  115. static CSteamApplication __s_SteamApplicationObject( &_varName ); \
  116. DEFINE_WINDOWED_APPLICATION_OBJECT_GLOBALVAR( __s_SteamApplicationObject )
  117. #define DEFINE_WINDOWED_STEAM_APPLICATION_OBJECT( _className ) \
  118. static _className __s_ApplicationObject; \
  119. static CSteamApplication __s_SteamApplicationObject( &__s_ApplicationObject ); \
  120. DEFINE_WINDOWED_APPLICATION_OBJECT_GLOBALVAR( __s_SteamApplicationObject )
  121. #define DEFINE_CONSOLE_STEAM_APPLICATION_OBJECT_GLOBALVAR( _className, _varName ) \
  122. static CSteamApplication __s_SteamApplicationObject( &_varName ); \
  123. DEFINE_CONSOLE_APPLICATION_OBJECT_GLOBALVAR( __s_SteamApplicationObject )
  124. #define DEFINE_CONSOLE_STEAM_APPLICATION_OBJECT( _className ) \
  125. static _className __s_ApplicationObject; \
  126. static CSteamApplication __s_SteamApplicationObject( &__s_ApplicationObject ); \
  127. DEFINE_CONSOLE_APPLICATION_OBJECT_GLOBALVAR( __s_SteamApplicationObject )
  128. #endif // APPFRAMEWORK_H