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.

249 lines
7.1 KiB

  1. //===== Copyright � 1996-2005, 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 void InitFoundryMode( CreateInterfaceFn factory, void *hGameWnd, const char *szGameDir );
  78. virtual void NoteEngineGotFocus();
  79. virtual bool IsHammerVisible();
  80. virtual void ToggleHammerVisible();
  81. virtual bool HammerPreTranslateMessage( MSG * pMsg );
  82. virtual bool HammerIsIdleMessage( MSG * pMsg );
  83. virtual bool HammerOnIdle( long count );
  84. virtual void RunFrame();
  85. virtual int MainLoop();
  86. virtual const char *GetDefaultMod();
  87. virtual const char *GetDefaultGame();
  88. virtual RequestRetval_t RequestNewConfig();
  89. virtual const char *GetDefaultModFullPath();
  90. virtual bool InitSessionGameConfig(const char *szGame);
  91. virtual BOOL PreTranslateMessage(MSG *pMsg);
  92. // Are we running in Foundry mode?
  93. bool IsFoundryMode() const { return m_bFoundryMode; }
  94. // Overrides
  95. // ClassWizard generated virtual function overrides
  96. //{{AFX_VIRTUAL(CHammer)
  97. public:
  98. virtual BOOL InitInstance();
  99. virtual int ExitInstance();
  100. virtual CDocument *OpenDocumentFile(LPCTSTR lpszFileName); // Called by the framework
  101. virtual CDocument *OpenDocumentOrInstanceFile(LPCTSTR lpszFileName); // Called by instances or other Hammer code
  102. virtual BOOL OnIdle(LONG lCount);
  103. virtual int Run(void);
  104. //}}AFX_VIRTUAL
  105. void GetDirectory(DirIndex_t dir, char *p);
  106. void SetDirectory(DirIndex_t dir, const char *p);
  107. COLORREF GetProfileColor(const char *pszSection, const char *pszKey, int r, int g, int b);
  108. void OnActivateApp(bool bActive);
  109. bool IsActiveApp();
  110. void BeginImportWCSettings();
  111. void BeginImportVHESettings();
  112. void EndImportSettings();
  113. void BeginClosing();
  114. bool IsClosing();
  115. void Enable3DRender(bool bEnable);
  116. void ReleaseVideoMemory();
  117. void SuppressVideoAllocation( bool bSuppress );
  118. bool CanAllocateVideo() const;
  119. void Help(const char *pszTopic);
  120. CGameConfig *PromptForGameConfig();
  121. void OpenURL(const char *pszURL, HWND hwnd);
  122. void OpenURL(UINT nID, HWND hwnd);
  123. // list of "command arrays" for compiling files:
  124. CTypedPtrArray<CPtrArray,CCommandSequence*> m_CmdSequences;
  125. void SaveSequences();
  126. bool LoadSequences( const char *szSeqFileName );
  127. void Autosave();
  128. void LoadLastGoodSave();
  129. void ResetAutosaveTimer();
  130. bool VerifyAutosaveDirectory( char *szAutosaveDir = 0 ) const;
  131. int GetNextAutosaveNumber( CUtlMap<FILETIME, WIN32_FIND_DATA, int> *pFileMap, DWORD *pdwTotalDirSize, const CString * ) const;
  132. // When in lighting preview, it will avoid rendering frames.
  133. // This forces it to render the next frame.
  134. void SetForceRenderNextFrame();
  135. bool GetForceRenderNextFrame();
  136. static void SetIsNewDocumentVisible( bool bIsVisible );
  137. static bool IsNewDocumentVisible( void );
  138. void SetCustomAccelerator( HWND hWnd, WORD nID );
  139. void ClearCustomAccelerator( );
  140. CHammerDocTemplate *pMapDocTemplate;
  141. CHammerDocTemplate *pManifestDocTemplate;
  142. //{{AFX_MSG(CHammer)
  143. afx_msg void OnAppAbout();
  144. afx_msg void OnFileOpen();
  145. afx_msg void OnFileNew();
  146. //}}AFX_MSG
  147. DECLARE_MESSAGE_MAP()
  148. protected:
  149. // These execute inside a minidump handler.
  150. static int StaticHammerInternalInit( void *pParam );
  151. InitReturnVal_t HammerInternalInit();
  152. static int StaticInternalMainLoop( void *pParam );
  153. int InternalMainLoop();
  154. static bool m_bIsNewDocumentVisible;
  155. // Check for 16-bit color or higher.
  156. bool Check16BitColor();
  157. void UpdateLighting(CMapDoc *pDoc);
  158. bool m_bClosing; // The user has initiated app shutdown.
  159. bool m_bActiveApp;
  160. bool m_SuppressVideoAllocation;
  161. bool m_bForceRenderNextFrame;
  162. char m_szAppDir[MAX_PATH];
  163. char m_szAutosaveDir[MAX_PATH];
  164. bool m_bFoundryMode;
  165. HWND m_CustomAcceleratorWindow;
  166. HACCEL m_CustomAccelerator;
  167. };
  168. #define APP() ((CHammer *)AfxGetApp())
  169. //-----------------------------------------------------------------------------
  170. // Global interfaces...
  171. //-----------------------------------------------------------------------------
  172. #define HAMMER_FILESYSTEM_DEFINED
  173. extern IBaseFileSystem *g_pFileSystem;
  174. extern IEngineAPI *g_pEngineAPI;
  175. extern CreateInterfaceFn g_Factory;
  176. bool IsRunningInEngine();
  177. // event update system - lets you check for events such as gemoetry modification for updating stuff.
  178. void SignalUpdate(int ev); // EVTYPE_xx
  179. int GetUpdateCounter(int ev); // return timestamp
  180. float GetUpdateTime(int ev); // return floating point time event was signalled
  181. void SignalGlobalUpdate(void); // flag ALL events, such as on map load
  182. #define EVTYPE_FACE_CHANGED 0
  183. #define EVTYPE_LIGHTING_CHANGED 1
  184. #define EVTYPE_BITMAP_RECEIVED_FROM_LPREVIEW 2
  185. extern bool g_bHDR; // should we act like we're in hdr mode?
  186. extern int g_nBitmapGenerationCounter;
  187. #endif // HAMMER_H