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.

231 lines
6.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Defines the application object.
  4. //
  5. //===========================================================================//
  6. #ifndef HAMMER_H
  7. #define HAMMER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #ifndef __AFXWIN_H__
  12. #error include 'stdafx.h' before including this file for PCH
  13. #endif
  14. #include "resource.h" // main symbols
  15. #include "RunCommands.h"
  16. #include "IHammer.h"
  17. #include "tier1/utlmap.h"
  18. #include "tier3/tier3dm.h"
  19. //-----------------------------------------------------------------------------
  20. // Forward declarations...
  21. //-----------------------------------------------------------------------------
  22. class CMapDoc;
  23. class IStudioRender;
  24. class IBaseFileSystem;
  25. class IEngineAPI;
  26. class IMDLCache;
  27. class CGameConfig;
  28. //
  29. // Values for retrieving specific directories using GetDirectory.
  30. //
  31. enum DirIndex_t
  32. {
  33. DIR_PROGRAM, // The editor install directory.
  34. DIR_PREFABS, // The directory for prefabs.
  35. DIR_GAME_EXE, // The location of the game executable.
  36. DIR_MOD, // The location of the mod currently being worked on.
  37. DIR_GAME, // The location of the base game currently being worked on.
  38. DIR_MATERIALS, // The location of the mod's materials.
  39. DIR_AUTOSAVE // The location of autosave files.
  40. };
  41. // combines a list of commands & a name:
  42. class CCommandSequence
  43. {
  44. public:
  45. CCommandArray m_Commands;
  46. char m_szName[128];
  47. };
  48. class CHammerDocTemplate : public CMultiDocTemplate
  49. {
  50. public:
  51. CHammerDocTemplate( UINT nIDResource, CRuntimeClass* pDocClass, CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass ) :
  52. CMultiDocTemplate( nIDResource, pDocClass, pFrameClass, pViewClass )
  53. {
  54. }
  55. virtual CDocument *OpenDocumentFile( LPCTSTR lpszPathName, BOOL bMakeVisible = TRUE );
  56. virtual void CloseAllDocuments( BOOL bEndSession );
  57. virtual void InitialUpdateFrame( CFrameWnd* pFrame, CDocument* pDoc, BOOL bMakeVisible = TRUE );
  58. void UpdateInstanceMap( CMapDoc *pInstanceMapDoc );
  59. };
  60. void AppRegisterPostInitFn( void (*)() );
  61. void AppRegisterMessageLoopFn( void (*)() );
  62. void AppRegisterMessagePretranslateFn( void (*)( MSG * ) );
  63. void AppRegisterPreShutdownFn( void (*)() );
  64. class CHammer : public CWinApp, public CTier3AppSystem< IHammer >
  65. {
  66. typedef CTier3AppSystem< IHammer > BaseClass;
  67. public:
  68. CHammer(void);
  69. virtual ~CHammer(void);
  70. // Methods of IAppSystem
  71. virtual bool Connect( CreateInterfaceFn factory );
  72. virtual void Disconnect();
  73. virtual void *QueryInterface( const char *pInterfaceName );
  74. virtual InitReturnVal_t Init();
  75. virtual void Shutdown();
  76. // Methods of IHammer
  77. virtual bool HammerPreTranslateMessage( MSG * pMsg );
  78. virtual bool HammerIsIdleMessage( MSG * pMsg );
  79. virtual bool HammerOnIdle( long count );
  80. virtual void RunFrame();
  81. virtual int MainLoop();
  82. virtual const char *GetDefaultMod();
  83. virtual const char *GetDefaultGame();
  84. virtual RequestRetval_t RequestNewConfig();
  85. virtual const char *GetDefaultModFullPath();
  86. virtual bool InitSessionGameConfig(const char *szGame);
  87. virtual BOOL PreTranslateMessage(MSG *pMsg);
  88. // Overrides
  89. // ClassWizard generated virtual function overrides
  90. //{{AFX_VIRTUAL(CHammer)
  91. public:
  92. virtual BOOL InitInstance();
  93. virtual int ExitInstance();
  94. virtual CDocument* OpenDocumentFile(LPCTSTR lpszFileName);
  95. virtual BOOL OnIdle(LONG lCount);
  96. virtual int Run(void);
  97. //}}AFX_VIRTUAL
  98. void GetDirectory(DirIndex_t dir, char *p);
  99. void SetDirectory(DirIndex_t dir, const char *p);
  100. COLORREF GetProfileColor(const char *pszSection, const char *pszKey, int r, int g, int b);
  101. void OnActivateApp(bool bActive);
  102. bool IsActiveApp();
  103. void BeginImportWCSettings();
  104. void BeginImportVHESettings();
  105. void EndImportSettings();
  106. void BeginClosing();
  107. bool IsClosing();
  108. void Enable3DRender(bool bEnable);
  109. void ReleaseVideoMemory();
  110. void SuppressVideoAllocation( bool bSuppress );
  111. bool CanAllocateVideo() const;
  112. void Help(const char *pszTopic);
  113. CGameConfig *PromptForGameConfig();
  114. void OpenURL(const char *pszURL, HWND hwnd);
  115. void OpenURL(UINT nID, HWND hwnd);
  116. // list of "command arrays" for compiling files:
  117. CTypedPtrArray<CPtrArray,CCommandSequence*> m_CmdSequences;
  118. void SaveSequences();
  119. void LoadSequences();
  120. void Autosave();
  121. void LoadLastGoodSave();
  122. void ResetAutosaveTimer();
  123. bool VerifyAutosaveDirectory( char *szAutosaveDir = 0 ) const;
  124. int GetNextAutosaveNumber( CUtlMap<FILETIME, WIN32_FIND_DATA, int> *pFileMap, DWORD *pdwTotalDirSize, const CString * ) const;
  125. // When in lighting preview, it will avoid rendering frames.
  126. // This forces it to render the next frame.
  127. void SetForceRenderNextFrame();
  128. bool GetForceRenderNextFrame();
  129. static void SetIsNewDocumentVisible( bool bIsVisible );
  130. static bool IsNewDocumentVisible( void );
  131. CHammerDocTemplate *pMapDocTemplate;
  132. CHammerDocTemplate *pManifestDocTemplate;
  133. //{{AFX_MSG(CHammer)
  134. afx_msg void OnAppAbout();
  135. afx_msg void OnFileOpen();
  136. afx_msg void OnFileNew();
  137. //}}AFX_MSG
  138. DECLARE_MESSAGE_MAP()
  139. protected:
  140. // These execute inside a minidump handler.
  141. static int StaticHammerInternalInit( void *pParam );
  142. InitReturnVal_t HammerInternalInit();
  143. static int StaticInternalMainLoop( void *pParam );
  144. int InternalMainLoop();
  145. static bool m_bIsNewDocumentVisible;
  146. // Check for 16-bit color or higher.
  147. bool Check16BitColor();
  148. void UpdateLighting(CMapDoc *pDoc);
  149. bool m_bClosing; // The user has initiated app shutdown.
  150. bool m_bActiveApp;
  151. bool m_SuppressVideoAllocation;
  152. bool m_bForceRenderNextFrame;
  153. char m_szAppDir[MAX_PATH];
  154. char m_szAutosaveDir[MAX_PATH];
  155. };
  156. #define APP() ((CHammer *)AfxGetApp())
  157. //-----------------------------------------------------------------------------
  158. // Global interfaces...
  159. //-----------------------------------------------------------------------------
  160. extern IBaseFileSystem *g_pFileSystem;
  161. extern IEngineAPI *g_pEngineAPI;
  162. extern CreateInterfaceFn g_Factory;
  163. bool IsRunningInEngine();
  164. // event update system - lets you check for events such as gemoetry modification for updating stuff.
  165. void SignalUpdate(int ev); // EVTYPE_xx
  166. int GetUpdateCounter(int ev); // return timestamp
  167. float GetUpdateTime(int ev); // return floating point time event was signalled
  168. void SignalGlobalUpdate(void); // flag ALL events, such as on map load
  169. #define EVTYPE_FACE_CHANGED 0
  170. #define EVTYPE_LIGHTING_CHANGED 1
  171. #define EVTYPE_BITMAP_RECEIVED_FROM_LPREVIEW 2
  172. extern bool g_bHDR; // should we act like we're in hdr mode?
  173. extern int g_nBitmapGenerationCounter;
  174. #endif // HAMMER_H