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.

990 lines
34 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef MAPDOC_H
  7. #define MAPDOC_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "MapClass.h"
  12. #include "Selection.h"
  13. #include "MapEntity.h"
  14. #include "GameConfig.h"
  15. #include "filesystem.h"
  16. #include "tier1/utlrbtree.h"
  17. #include "tier1/utlstack.h"
  18. class CToolManager;
  19. class CMapDoc;
  20. class CGameConfig;
  21. class CHistory;
  22. class CMapGroup;
  23. class CMapView;
  24. class CMapView3D;
  25. class CMapView2D;
  26. class IBSPLighting;
  27. class CRender;
  28. class CManifest;
  29. struct FindEntity_t;
  30. struct FindGroup_t;
  31. struct AddNonSelectedInfo_t;
  32. enum SelectionHandleMode_t;
  33. enum MAPFORMAT;
  34. enum ToolID_t;
  35. enum
  36. {
  37. // hints what recently changed
  38. MAPVIEW_UPDATE_OBJECTS = 0x001, // a world object has changed (pos, size etc)
  39. MAPVIEW_UPDATE_ANIMATION = 0x002, // an object animation has been changed
  40. MAPVIEW_UPDATE_COLOR = 0x004, // an object color has been changed
  41. MAPVIEW_UPDATE_SELECTION = 0x008, // the current selection has changed
  42. MAPVIEW_UPDATE_TOOL = 0x010, // the current tool has been changed
  43. // what views should be updated
  44. MAPVIEW_UPDATE_ONLY_2D = 0x020, // update only 2D views for some reason
  45. MAPVIEW_UPDATE_ONLY_3D = 0x040, // update only 3D views for some reason
  46. MAPVIEW_UPDATE_ONLY_LOGICAL = 0x080, // update only Logical views for some reason
  47. MAPVIEW_OPTIONS_CHANGED = 0x100, // view options has been changed
  48. MAPVIEW_UPDATE_VISGROUP_STATE = 0x200, // a visgroup was hidden or shown.
  49. MAPVIEW_UPDATE_VISGROUP_ALL = 0x400, // a visgroup was created or deleted.
  50. MAPVIEW_RENDER_NOW = 0x800, // bypass the main frame loop and render now
  51. };
  52. // Flags for view2dinfo.wflags
  53. enum
  54. {
  55. VI_ZOOM = 0x01,
  56. VI_CENTER = 0x02
  57. };
  58. // Display modes for instances
  59. enum ShowInstance_t
  60. {
  61. INSTANCES_HIDE = 0, // instance contents are not displayed
  62. INSTANCES_SHOW_TINTED, // instance contents are displayed with a yellowish tint
  63. INSTANCES_SHOW_NORMAL // instance contents are displayed normally
  64. };
  65. enum VMFLoadFlags_t
  66. {
  67. VMF_LOAD_ACTIVATE = 0x01, // loading map should be activated
  68. VMF_LOAD_IS_SUBMAP = 0x02, // loading map is part of an instance / manifest
  69. };
  70. typedef struct
  71. {
  72. WORD wFlags;
  73. float fZoom;
  74. Vector ptCenter;
  75. } VIEW2DINFO;
  76. struct ExportDXFInfo_s
  77. {
  78. int nObject;
  79. bool bVisOnly;
  80. CMapWorld *pWorld;
  81. FILE *fp;
  82. };
  83. //
  84. // The doc holds a list of objects with dependents that changed since the last render. The list
  85. // must be processed before rendering so that interobject dependencies are resolved.
  86. //
  87. struct NotifyListEntry_t
  88. {
  89. CSmartPtr< CSafeObject< CMapClass > > pObject;
  90. Notify_Dependent_t eNotifyType;
  91. };
  92. //
  93. // To pass as hint to UpdateAllViews.
  94. //
  95. class UpdateBox : public CObject
  96. {
  97. public:
  98. UpdateBox(void) { Objects = NULL; }
  99. CMapObjectList *Objects;
  100. BoundBox Box;
  101. };
  102. // this holds all of the data needed to visualize the level's portal file
  103. struct portalfile_t
  104. {
  105. CString fileName;
  106. int totalVerts;
  107. CUtlVector<Vector> verts;
  108. CUtlVector<int> vertCount;
  109. };
  110. struct UpdateVisibilityData_t
  111. {
  112. CMapDoc *pDoc;
  113. bool bRadiusCullingEnabled;
  114. Vector vecRadiusCullCenter;
  115. float flRadiusCullDistSq;
  116. };
  117. // this is a structure to manage clipboards
  118. class IHammerClipboard
  119. {
  120. protected:
  121. IHammerClipboard(){}
  122. virtual ~IHammerClipboard() {}
  123. public:
  124. static IHammerClipboard *CreateInstance();
  125. public:
  126. virtual void Destroy() = 0;
  127. };
  128. class CMapDoc : public CDocument
  129. {
  130. friend class CManifest;
  131. protected:
  132. DECLARE_DYNCREATE(CMapDoc)
  133. public:
  134. // attribs:
  135. bool m_bSnapToGrid;
  136. bool m_bShowGrid;
  137. bool m_bShowLogicalGrid;
  138. // pointfile stuff:
  139. enum
  140. {
  141. PFPNext = 1,
  142. PFPPrev = -1
  143. };
  144. int m_iCurPFPoint;
  145. CUtlVector<Vector> m_PFPoints;
  146. CString m_strLastPointFile;
  147. portalfile_t *m_pPortalFile;
  148. static inline CMapDoc *GetActiveMapDoc(void);
  149. static void SetActiveMapDoc(CMapDoc *pDoc);
  150. static void ActivateMapDoc( CMapDoc *pDoc );
  151. static inline CManifest *GetManifest(void);
  152. static inline int GetInLevelLoad( );
  153. private:
  154. static CMapDoc *m_pMapDoc;
  155. static CManifest *m_pManifest;
  156. static int m_nInLevelLoad;
  157. public:
  158. CMapDoc(void);
  159. virtual ~CMapDoc();
  160. virtual void Initialize( void );
  161. virtual bool IsManifest( void ) { return false; }
  162. IBSPLighting *GetBSPLighting() { return m_pBSPLighting; }
  163. CToolManager *GetTools() { return m_pToolManager; } // return tools working on this document
  164. CSelection *GetSelection() { return m_pSelection; } // return current selection
  165. void BeginShellSession(void);
  166. void EndShellSession(void);
  167. bool IsShellSessionActive(void);
  168. inline int GetDocVersion(void);
  169. inline void DecrementDocVersion(void);
  170. //
  171. // Interface to the map document. Functions for object creation, deletion, etc.
  172. //
  173. CMapEntity *CreateEntity(const char *pszClassName, float x, float y, float z);
  174. bool DeleteEntity(const char *pszClassName, float x, float y, float z);
  175. CMapEntity *FindEntity(const char *pszClassName, float x, float y, float z);
  176. CMapEntity *FindEntityByName( const char *pszName, bool bVisiblesOnly );
  177. bool FindEntitiesByKeyValue(CMapEntityList &Found, const char *szKey, const char *szValue, bool bVisiblesOnly);
  178. bool FindEntitiesByName(CMapEntityList &Found, const char *szName, bool bVisiblesOnly);
  179. bool FindEntitiesByClassName(CMapEntityList &Found, const char *szClassName, bool bVisiblesOnly);
  180. bool FindEntitiesByNameOrClassName(CMapEntityList &Found, const char *pszName, bool bVisiblesOnly);
  181. virtual void Update(void);
  182. virtual void SetModifiedFlag(BOOL bModified = TRUE);
  183. void SetAutosaveFlag(BOOL bAutosave = TRUE);
  184. BOOL NeedsAutosave();
  185. BOOL IsAutosave();
  186. CString *AutosavedFrom();
  187. void AddReference( void );
  188. void RemoveReference( void );
  189. int GetReferenceCount( void ) { return m_nExternalReferenceCount; }
  190. // Used to track down a potential crash.
  191. bool AnyNotificationsForObject(CMapClass *pObject);
  192. void SetAnimationTime( float time );
  193. float GetAnimationTime( void ) { return m_flAnimationTime; }
  194. bool IsAnimating( void ) { return m_bIsAnimating; }
  195. // other stuff
  196. float m_flCurrentTime;
  197. void UpdateCurrentTime( void );
  198. float GetTime( void ) { return m_flCurrentTime; }
  199. void GotoPFPoint(int iDirection);
  200. // world cordon
  201. bool IsCordoning(void);
  202. bool SetCordoning( bool bState);
  203. void GetCordon( Vector &mins, Vector &maxs);
  204. void SetCordon( const Vector &mins, const Vector &maxs);
  205. CMapWorld *CordonCreateWorld();
  206. ChunkFileResult_t CordonSaveVMF(CChunkFile *pFile, CSaveInfo *pSaveInfo);
  207. Vector m_vCordonMins;
  208. Vector m_vCordonMaxs;
  209. bool m_bIsCordoning;
  210. CMapView *GetActiveMapView();
  211. CMapView3D *GetFirst3DView();
  212. void Snap(Vector &pt, int nFlags = 0);
  213. inline bool IsSnapEnabled(void);
  214. //
  215. // Face selection for face editing.
  216. //
  217. void SelectFace(CMapSolid *pSolid, int iFace, int cmd);
  218. void UpdateForApplicator(BOOL bApplicator);
  219. void UpdateAnimation( void );
  220. void DeleteObject(CMapClass *pObject);
  221. void DeleteObjectList(CMapObjectList &List);
  222. void InternalEnableLightPreview( bool bCustomFilename );
  223. //
  224. // Object selection:
  225. //
  226. bool SelectObject(CMapClass *pobj, int cmd = scSelect);
  227. void SelectObjectList(const CMapObjectList *pList, int cmd = (scSelect|scClear|scSaveChanges) );
  228. void SelectRegion( BoundBox *pBox, bool bInsideOnly, bool ResetSelection = true );
  229. void SelectLogicalRegion( const Vector2D &vecMins, const Vector2D &vecMaxs, bool bInsideOnly);
  230. // View centering.
  231. void CenterViewsOnSelection();
  232. void CenterViewsOn(const Vector &vec);
  233. void CenterLogicalViewsOnSelection();
  234. void CenterLogicalViewsOn(const Vector2D &vecLogical);
  235. void Center2DViewsOnSelection();
  236. void Center2DViewsOn(const Vector &vec);
  237. void Center3DViewsOnSelection();
  238. void Center3DViewsOn(const Vector &vPos);
  239. void Set3DViewsPosAng( const Vector &vPos, const Vector &vAng );
  240. void GetSelectedCenter(Vector &vCenter);
  241. void GetBestVisiblePoint(Vector &ptOrg);
  242. void Cut( IHammerClipboard *pClipboard );
  243. void Copy( IHammerClipboard *pClipboard = NULL );
  244. void Paste(CMapObjectList &Objects, CMapWorld *pSourceWorld, CMapWorld *pDestWorld, Vector vecOffset, QAngle vecRotate, CMapClass *pParent, bool bMakeEntityNamesUnique, const char *pszEntityNamePrefix);
  245. void PasteInstance(CMapObjectList &Objects, CMapWorld *pSourceWorld, CMapWorld *pDestWorld, Vector vecOffset, QAngle vecRotate, CMapClass *pParent, bool bMakeEntityNamesUnique, const char *pszEntityNamePrefix);
  246. void Paste( IHammerClipboard *pClipboard, CMapWorld *pDestWorld, Vector vecOffset, QAngle vecRotate, CMapClass *pParent, bool bMakeEntityNamesUnique, const char *pszEntityNamePrefix );
  247. void Delete( void );
  248. // FIXME: refactor these!
  249. void CloneObjects(const CMapObjectList &Objects);
  250. void NudgeObjects(const Vector &Delta, bool bClone);
  251. void GetNudgeVector(const Vector& vHorz, const Vector& vVert, int nChar, bool bSnap, Vector &vecNudge);
  252. void GetBestPastePoint(Vector &vecPasteOrigin);
  253. void UpdateStatusbar();
  254. void UpdateStatusBarSnap();
  255. void SetView2dInfo(VIEW2DINFO& vi);
  256. void SetViewLogicalInfo(VIEW2DINFO& vi);
  257. void SetActiveView(CMapView *pViewActivate);
  258. void SetUndoActive(bool bActive);
  259. void UpdateTitle(CView*);
  260. void CountSolids();
  261. void CountSolids2();
  262. void ReplaceTextures(
  263. LPCTSTR pszFind,
  264. LPCTSTR pszReplace,
  265. BOOL bEverything,
  266. int iAction,
  267. BOOL bHidden,
  268. bool bRescaleTextureCoordinates);
  269. void BatchReplaceTextures( FileHandle_t fp );
  270. bool Is3DGridEnabled(void) { return(m_bShow3DGrid); }
  271. ShowInstance_t GetShowInstance( void ) { return m_tShowInstance; }
  272. void ReleaseVideoMemory( );
  273. inline MAPFORMAT GetMapFormat(void);
  274. inline CMapWorld *GetMapWorld(void);
  275. inline CGameConfig *GetGame(void);
  276. inline int GetGridSpacing(void) { return(max(m_nGridSpacing, 1)); }
  277. inline CHistory *GetDocHistory(void);
  278. inline int GetNextMapObjectID(void);
  279. inline int GetNextNodeID(void);
  280. inline void SetNextNodeID(int nID);
  281. static int GetDocumentCount();
  282. static CMapDoc *GetDocument(int index);
  283. void SetMRU(CMapView2D *pView);
  284. void RemoveMRU(CMapView2D *pView);
  285. CUtlVector<CMapView2D*> MRU2DViews;
  286. // if theres anything the document whats to show, do it in RenderDocument()
  287. void RenderDocument(CRender *pRender);
  288. void RenderAllViews(void);
  289. BOOL SelectDocType(void);
  290. BOOL SaveModified(void);
  291. // Set edit prefab mode.
  292. void EditPrefab3D(DWORD dwPrefabID);
  293. //
  294. // Call these when modifying the document contents.
  295. //
  296. virtual void AddObjectToWorld(CMapClass *pObject, CMapClass *pParent = NULL);
  297. BOOL FindObject(CMapClass *pObject);
  298. void RemoveObjectFromWorld(CMapClass *pMapClass, bool bNotifyChildren);
  299. void RenderPreloadObject(CMapClass *pObject);
  300. void UpdateObject(CMapClass *pMapClass);
  301. void UpdateVisibilityAll(void);
  302. void UpdateVisibility(CMapClass *pObject);
  303. void NotifyDependents(CMapClass *pObject, Notify_Dependent_t eNotifyType);
  304. // Radius culling
  305. bool IsCulledBy3DCameraDistance( CMapClass *pObject, UpdateVisibilityData_t *pData );
  306. //
  307. // Morph tool.
  308. //
  309. void Morph_SelectObject(CMapSolid *pSolid, unsigned int uCmd);
  310. void Morph_GetBounds(Vector &mins, Vector &maxs, bool bReset);
  311. int Morph_GetObjectCount(void);
  312. CSSolid *Morph_GetFirstObject(POSITION &pos);
  313. CSSolid *Morph_GetNextObject(POSITION &pos);
  314. //
  315. inline bool IsDispSolidDrawMask( void ) { return m_bDispSolidDrawMask; }
  316. inline void SetDispDrawWalkable( bool bValue ) { m_bDispDrawWalkable = bValue; }
  317. inline bool IsDispDrawWalkable( void ) { return m_bDispDrawWalkable; }
  318. inline bool IsDispDraw3D() { return m_bDispDraw3D; }
  319. inline void SetDispDrawBuildable( bool bValue ) { m_bDispDrawBuildable = bValue; }
  320. inline bool IsDispDrawBuildable( void ) { return m_bDispDrawBuildable; }
  321. inline void SetDispDrawRemove( bool bValue ) { m_bDispDrawRemove = bValue; }
  322. inline bool IsDispDrawRemove( void ) { return m_bDispDrawRemove; }
  323. inline bool IsDispDrawRemovedVerts( void ) { return m_bDispDrawRemovedVerts; }
  324. inline void SetDispDrawRemovedVerts( bool bValue ) { m_bDispDrawRemovedVerts = bValue; }
  325. //
  326. // List of VisGroups.
  327. //
  328. void ShowNewVisGroupsDialog(CMapObjectList &Objects, bool bUnselectObjects);
  329. void VisGroups_CreateNamedVisGroup(CMapObjectList &Objects, const char *szName, bool bHide, bool bRemoveFromOtherVisGroups);
  330. void VisGroups_AddObjectsToVisGroup(CMapObjectList &Objects, CVisGroup *pVisGroup, bool bHide, bool bRemoveFromOtherVisGroups);
  331. CVisGroup *VisGroups_AddGroup(CVisGroup *pGroup);
  332. bool VisGroups_ObjectCanBelongToVisGroup(CMapClass *pObject);
  333. CVisGroup *VisGroups_AddGroup(LPCTSTR pszName, bool bAuto = false);
  334. static BOOL VisGroups_CheckForGroupCallback(CMapClass *pObject, CVisGroup *pGroup);
  335. int VisGroups_GetCount();
  336. CVisGroup *VisGroups_GetVisGroup(int nIndex);
  337. int VisGroups_GetRootCount();
  338. CVisGroup *VisGroups_GetRootVisGroup(int nIndex);
  339. CVisGroup *VisGroups_GroupForID(DWORD id);
  340. CVisGroup *VisGroups_GroupForName( const char *pszName, bool bIsAuto );
  341. void VisGroups_PurgeGroups();
  342. void VisGroups_MoveUp(CVisGroup *pGroup);
  343. void VisGroups_MoveDown(CVisGroup *pGroup);
  344. void VisGroups_ShowVisGroup(CVisGroup *pGroup, bool bShow);
  345. void VisGroups_UpdateAll();
  346. void VisGroups_UpdateForObject(CMapClass *pObject);
  347. void VisGroups_SetParent(CVisGroup *pVisGroup, CVisGroup *pNewParent);
  348. bool VisGroups_CanMoveUp(CVisGroup *pGroup);
  349. bool VisGroups_CanMoveDown(CVisGroup *pGroup);
  350. void VisGroups_RemoveGroup(CVisGroup *pGroup);
  351. void VisGroups_CombineGroups(CVisGroup *pFrom, CVisGroup *pTo);
  352. bool VisGroups_LockUpdates( bool bLock );
  353. void VisGroups_CheckMemberVisibility(CVisGroup *pGroup);
  354. // Quick Hide
  355. void QuickHide_HideObjects( void );
  356. void QuickHide_HideUnselectedObjects( void );
  357. void QuickHide_Unhide( void );
  358. bool QuickHide_IsObjectHidden( CMapClass *pObject );
  359. ChunkFileResult_t QuickHide_SaveVMF( CChunkFile *pFile, CSaveInfo *pSaveInfo );
  360. CUtlVector< CMapClass* > m_QuickHideGroup;
  361. CUtlVector< CMapClass* > m_QuickHideGroupedParents;
  362. // Default logical placement for new entities
  363. void GetDefaultNewLogicalPosition( Vector2D &vecPosition );
  364. private:
  365. void VisGroups_Validate();
  366. void VisGroups_UpdateParents();
  367. void VisGroups_UnlinkGroup(CVisGroup *pGroup);
  368. void VisGroups_DoRemoveOrCombine(CVisGroup *pFrom, CVisGroup *pTo);
  369. bool FindNotification(CMapClass *pObject, Notify_Dependent_t eNotifyType);
  370. protected:
  371. // ClassWizard generated virtual function overrides
  372. //{{AFX_VIRTUAL(CMapDoc)
  373. public:
  374. virtual BOOL OnNewDocument();
  375. virtual void DeleteContents();
  376. virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
  377. virtual void OnCloseDocument(void);
  378. virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
  379. //}}AFX_VIRTUAL
  380. BOOL Serialize(std::fstream &file, BOOL fIsStoring, BOOL bRMF);
  381. // Save a VMF file. saveFlags is a combination of SAVEFLAGS_ defines.
  382. bool SaveVMF(const char *pszFileName, int saveFlags );
  383. bool LoadVMF( const char *pszFileName, int LoadFlags = VMF_LOAD_ACTIVATE );
  384. void Postload(const char *pszFileName);
  385. inline bool IsLoading(void);
  386. inline void SetInitialUpdate( void ) { m_bHasInitialUpdate = true; }
  387. inline bool HasInitialUpdate( void ) { return m_bHasInitialUpdate; }
  388. // manifest routines
  389. void SetManifest( CManifest *pManifest );
  390. void SetEditable( bool IsEditable ) { m_bIsEditable = IsEditable; }
  391. bool IsEditable( void ) { return m_bIsEditable; }
  392. bool IsSelectionEditable( void );
  393. bool CreateNewManifest( void );
  394. CMapWorld *GetCurrentWorld( void );
  395. int GetClipboardCount( void );
  396. void ManifestPaste( CMapWorld *pDestWorld, Vector vecOffset, QAngle vecRotate, CMapClass *pParent, bool bMakeEntityNamesUnique, const char *pszEntityNamePrefix );
  397. virtual void UpdateInstanceMap( CMapDoc *pInstanceMapDoc );
  398. void CollapseInstances( bool bOnlySelected );
  399. void PopulateInstanceParms_r( CMapEntity *pEntity, const CMapObjectList *pChildren, CUtlVector< CString > &ParmList );
  400. void PopulateInstanceParms( CMapEntity *pEntity );
  401. void PopulateInstance( CMapEntity *pEntity );
  402. void InstanceMoved( void );
  403. void ShowWindow( bool bIsVisible );
  404. bool IsVisible( void );
  405. void BuildAllDetailObjects();
  406. void ExpandObjectKeywords(CMapClass *pObject, CMapWorld *pWorld);
  407. #ifdef _DEBUG
  408. virtual void AssertValid() const;
  409. virtual void Dump(CDumpContext& dc) const;
  410. #endif
  411. void UpdateAllCameras(const Vector *vecViewPos, const Vector *vecLookAt, const float *fZoom);
  412. void UpdateAllViews(int nFlags, UpdateBox *ub = NULL );
  413. void SetSmoothingGroupVisual( int iGroup ) { m_SmoothingGroupVisual = iGroup; }
  414. int GetSmoothingGroupVisual( void ) { return m_SmoothingGroupVisual; }
  415. void AddToAutoVisGroup( CMapClass *pObject );
  416. void AddToAutoVisGroup( CMapClass *pObject, const char *pAutoVisGroup );
  417. void AddChildGroupToAutoVisGroup( CMapClass *pObject, const char *pAutoVisGroup, const char *pParentName );
  418. void RemoveFromAutoVisGroups( CMapClass *pObject );
  419. void AddToFGDAutoVisGroups( CMapClass *pObject );
  420. // Builds a list of all objects which are connected to outputs of pObj
  421. void BuildCascadingSelectionList( CMapClass *pObj, CUtlRBTree< CMapClass*, unsigned short > &list, bool bRecursive );
  422. void Public_SaveMap() { OnFileSave(); }
  423. protected:
  424. void AssignAllToAutoVisGroups();
  425. CVisGroup *GetRootAutoVisGroup();
  426. // Tools:
  427. CToolManager *m_pToolManager;
  428. int m_nGridSpacing;
  429. bool m_bDispSolidDrawMask;
  430. bool m_bDispDrawWalkable;
  431. bool m_bDispDraw3D;
  432. bool m_bDispDrawBuildable;
  433. bool m_bDispDrawRemove;
  434. bool m_bDispDrawRemovedVerts;
  435. bool m_bHasInitialUpdate;
  436. bool m_bLoading; // Set to true while we are being loaded from VMF.
  437. static BOOL GetBrushNumberCallback(CMapClass *pObject, void *pFindInfo);
  438. //
  439. // Serialization.
  440. //
  441. ChunkFileResult_t SaveVersionInfoVMF(CChunkFile *pFile, bool bIsAutosave = false);
  442. ChunkFileResult_t VisGroups_SaveVMF(CChunkFile *pFile, CSaveInfo *pSaveInfo);
  443. ChunkFileResult_t SaveViewSettingsVMF(CChunkFile *pFile, CSaveInfo *pSaveInfo);
  444. static bool HandleLoadError(CChunkFile *pFile, const char *szChunkName, ChunkFileResult_t eError, CMapDoc *pDoc);
  445. static ChunkFileResult_t LoadCordonCallback(CChunkFile *pFile, CMapDoc *pDoc);
  446. static ChunkFileResult_t LoadCordonKeyCallback(const char *pszKey, const char *pszValue, CMapDoc *pDoc);
  447. static ChunkFileResult_t LoadEntityCallback(CChunkFile *pFile, CMapDoc *pDoc);
  448. static ChunkFileResult_t LoadHiddenCallback(CChunkFile *pFile, CMapDoc *pDoc);
  449. static ChunkFileResult_t LoadGroupKeyCallback(const char *szKey, const char *szValue, CMapGroup *pGroup);
  450. static ChunkFileResult_t LoadVersionInfoCallback(CChunkFile *pFile, CMapDoc *pDoc);
  451. static ChunkFileResult_t LoadVersionInfoKeyCallback(const char *szKey, const char *szValue, CMapDoc *pDoc);
  452. static ChunkFileResult_t LoadAutosaveCallback(CChunkFile *pFile, CMapDoc *pDoc);
  453. static ChunkFileResult_t LoadAutosaveKeyCallback(const char *szKey, const char *szValue, CMapDoc *pDoc);
  454. static ChunkFileResult_t LoadWorldCallback(CChunkFile *pFile, CMapDoc *pDoc);
  455. static ChunkFileResult_t LoadViewSettingsCallback(CChunkFile *pFile, CMapDoc *pDoc);
  456. static ChunkFileResult_t LoadViewSettingsKeyCallback(const char *szKey, const char *szValue, CMapDoc *pDoc);
  457. //
  458. // Search functions.
  459. //
  460. static BOOL FindEntityCallback(CMapClass *pObject, FindEntity_t *pFindInfo);
  461. static BOOL FindGroupCallback(CMapGroup *pGroup, FindGroup_t *pFindInfo);
  462. void AssignToVisGroups(void);
  463. void AssignToGroups(void);
  464. void RemoveEmptyGroups(void);
  465. void CountGUIDs(void);
  466. void InitUpdateVisibilityData( UpdateVisibilityData_t &data );
  467. bool ShouldObjectBeVisible( CMapClass *pObject, UpdateVisibilityData_t *pData );
  468. static BOOL UpdateVisibilityCallback( CMapClass *pObject, UpdateVisibilityData_t *pData );
  469. bool GetChildrenToHide(CMapClass *pObject, bool bSelected, CMapObjectList &List);
  470. //
  471. // Interobject dependency notification.
  472. //
  473. void ProcessNotifyList();
  474. void DispatchNotifyDependents(CMapClass *pObject, Notify_Dependent_t eNotifyType);
  475. CUtlVector<NotifyListEntry_t > m_NotifyList;
  476. CMapWorld *m_pWorld; // The world that this document represents.
  477. CMapObjectList m_UpdateList; // List of objects that have changed since the last call to Update.
  478. CString m_strLastExportFileName; // The full path that we last exported this document to.
  479. int m_nDocVersion; // A number that increments every time the doc is modified after being saved.
  480. BOOL m_bNeedsAutosave; // True if the document has been changed and needs autosaved.
  481. BOOL m_bIsAutosave;
  482. CString m_strAutosavedFrom;
  483. // Undo/Redo system.
  484. CHistory *m_pUndo;
  485. CHistory *m_pRedo;
  486. CSelection *m_pSelection; // object selection list
  487. int m_nNextMapObjectID; // The ID that will be assigned to the next CMapClass object in this document.
  488. int m_nNextNodeID; // The ID that will be assigned to the next "info_node_xxx" object created in this document.
  489. // Editing prefabs data.
  490. DWORD m_dwPrefabID;
  491. DWORD m_dwPrefabLibraryID;
  492. BOOL m_bEditingPrefab;
  493. bool m_bPrefab; // true if this document IS a prefab, false if not.
  494. // Game configuration.
  495. CGameConfig *m_pGame;
  496. bool m_bShow3DGrid; // Whether to render a grid in the 3D views.
  497. bool m_bHideItems; // Whether to render point entities in all views.
  498. int m_nExternalReferenceCount; // Indicates how many external references ( instances ) are pointing to this map
  499. ShowInstance_t m_tShowInstance; // Indicates how instance contents should be displayed
  500. CManifest *m_pManifestOwner;
  501. bool m_bIsEditable;
  502. bool m_bCollapsingInstances;
  503. //
  504. // Animation.
  505. //
  506. float m_flAnimationTime; // Current time in the animation
  507. bool m_bIsAnimating;
  508. IBSPLighting *m_pBSPLighting;
  509. //
  510. // Visgroups.
  511. //
  512. CUtlVector<CVisGroup *> *m_VisGroups;
  513. CUtlVector<CVisGroup *> *m_RootVisGroups;
  514. bool m_bVisGroupUpdatesLocked;
  515. int m_SmoothingGroupVisual;
  516. int m_nLogicalPositionCount;
  517. //
  518. // Expands %i keyword in prefab targetnames to generate unique targetnames for this map.
  519. //
  520. bool ExpandTargetNameKeywords(char *szNewTargetName, const char *szOldTargetName, CMapWorld *pWorld);
  521. bool DoExpandKeywords(CMapClass *pObject, CMapWorld *pWorld, char *szOldKeyword, char *szNewKeyword);
  522. // Renames all named entities in pRoot
  523. void RenameEntities( CMapClass *pRoot, CMapWorld *pWorld, bool bMakeUnique, const char *pszPrefix );
  524. void CenterOriginsRecursive(CMapClass *pObject);
  525. void SnapObjectsRecursive(CMapClass *pObject);
  526. // Add all entities connected to all entities in the selection list recursively
  527. void AddConnectedNodes( CMapClass *pClass, CUtlRBTree< CMapClass*, unsigned short >& list );
  528. //{{AFX_MSG(CMapDoc)
  529. afx_msg void OnEditDelete();
  530. afx_msg void OnMapSnaptogrid();
  531. afx_msg void OnMapEntityGallery();
  532. afx_msg void OnUpdateMapSnaptogrid(CCmdUI* pCmdUI);
  533. afx_msg void OnEditApplytexture();
  534. afx_msg void OnToolsSubtractselection();
  535. afx_msg void OnToolsCenterOrigins();
  536. afx_msg void OnEnableLightPreview();
  537. afx_msg void OnEnableLightPreviewCustomFilename();
  538. afx_msg void OnDisableLightPreview();
  539. afx_msg void OnToggleLightPreview();
  540. afx_msg void OnUpdateLightPreview();
  541. afx_msg void OnAbortLightCalculation();
  542. afx_msg void OnEditCopy();
  543. afx_msg void OnEditPaste();
  544. afx_msg void OnUpdateEditSelection(CCmdUI *pCmdUI);
  545. afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI);
  546. afx_msg void OnEditCut();
  547. afx_msg void OnEditReplace();
  548. afx_msg void OnToolsGroup();
  549. afx_msg void OnToolsUngroup();
  550. afx_msg void OnUpdateViewGrid(CCmdUI* pCmdUI);
  551. afx_msg void OnUpdateViewLogicalGrid(CCmdUI* pCmdUI);
  552. afx_msg void OnEditSelectall();
  553. afx_msg void OnFileSaveAs();
  554. afx_msg void OnFileSave();
  555. afx_msg void OnMapGridlower();
  556. afx_msg void OnMapGridhigher();
  557. afx_msg void OnEditToworld();
  558. afx_msg void OnEditToWorld();
  559. afx_msg void OnFileExport();
  560. afx_msg void OnFileExportAgain();
  561. afx_msg void OnEditMapproperties();
  562. afx_msg void OnFileConvertWAD();
  563. afx_msg void OnUpdateFileConvertWAD(CCmdUI* pCmdUI);
  564. afx_msg void OnFileRunmap();
  565. afx_msg void OnToolsHideitems();
  566. afx_msg void OnViewHideUnconnectedEntities();
  567. afx_msg void OnUpdateViewHideUnconnectedEntities(CCmdUI* pCmdUI);
  568. afx_msg void OnUpdateToolsSubtractselection(CCmdUI* pCmdUI);
  569. afx_msg void OnUpdateToolsHideitems(CCmdUI* pCmdUI);
  570. afx_msg void OnUpdateEditDelete(CCmdUI* pCmdUI);
  571. afx_msg void OnUpdateEditFunction(CCmdUI* pCmdUI);
  572. afx_msg void OnUpdateEditCut(CCmdUI* pCmdUI);
  573. afx_msg void OnUpdateEditMapproperties(CCmdUI* pCmdUI);
  574. afx_msg void OnMapInformation();
  575. // View menu
  576. afx_msg void OnViewGrid();
  577. afx_msg void OnViewLogicalGrid();
  578. afx_msg void OnViewCenterOnSelection();
  579. afx_msg void OnViewCenter3DViewsOnSelection();
  580. afx_msg BOOL OnViewHideObjects(UINT nID);
  581. afx_msg void OnQuickHide_HideObjects();
  582. afx_msg void OnQuickHide_HideUnselectedObjects();
  583. afx_msg void OnQuickHide_Unhide();
  584. afx_msg void OnQuickHide_UpdateUnHide(CCmdUI *pCmdUI);
  585. afx_msg void OnQuickHide_CreateVisGroupFromHidden();
  586. afx_msg void OnQuickHide_UpdateCreateVisGroupFromHidden(CCmdUI *pCmdUI);
  587. afx_msg void OnViewShowconnections();
  588. afx_msg void OnViewGotoBrush(void);
  589. afx_msg void OnViewGotoCoords(void);
  590. afx_msg void OnViewShowHelpers();
  591. afx_msg void OnViewShowModelsIn2D();
  592. afx_msg void OnViewPreviewModelFade();
  593. afx_msg void OnCollisionWireframe();
  594. afx_msg void OnShowDetailObjects();
  595. afx_msg void OnShowNoDrawBrushes();
  596. afx_msg void OnRadiusCulling();
  597. afx_msg void OnUpdateRadiusCulling(CCmdUI *pCmdUI);
  598. afx_msg void OnToolsHollow();
  599. afx_msg void OnEditPastespecial();
  600. afx_msg void OnUpdateEditPastespecial(CCmdUI* pCmdUI);
  601. afx_msg void OnEditSelnext();
  602. afx_msg void OnEditSelprev();
  603. afx_msg void OnEditSelnextCascading();
  604. afx_msg void OnEditSelprevCascading();
  605. afx_msg void OnLogicalMoveBlock();
  606. afx_msg void OnLogicalSelectAllCascading();
  607. afx_msg void OnLogicalSelectAllConnected();
  608. afx_msg void OnLogicalobjectLayoutgeometric();
  609. afx_msg void OnLogicalobjectLayoutdefault();
  610. afx_msg void OnLogicalobjectLayoutlogical();
  611. afx_msg void OnMapCheck();
  612. afx_msg void OnUpdateViewShowconnections(CCmdUI* pCmdUI);
  613. afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
  614. afx_msg void OnToolsCreateprefab();
  615. afx_msg void OnInsertprefabOriginal();
  616. afx_msg void OnEditReplacetex();
  617. afx_msg void OnToolsSnapselectedtogrid();
  618. afx_msg void OnToolsSnapSelectedToGridIndividually();
  619. afx_msg void OnUpdateToolsSplitface(CCmdUI* pCmdUI);
  620. afx_msg void OnToolsSplitface();
  621. afx_msg void OnToolsTransform();
  622. afx_msg void OnToolsToggletexlock();
  623. afx_msg void OnUpdateToolsToggletexlock(CCmdUI* pCmdUI);
  624. afx_msg void OnToolsToggletexlockScale();
  625. afx_msg void OnUpdateToolsToggletexlockScale(CCmdUI* pCmdUI);
  626. afx_msg void OnToolsTextureAlignment(void);
  627. afx_msg void OnUpdateToolsTextureAlignment(CCmdUI *pCmdUI);
  628. afx_msg void OnToggleCordon();
  629. afx_msg void OnUpdateToggleCordon(CCmdUI* pCmdUI);
  630. afx_msg void OnUpdateShowNoDrawBrushes(CCmdUI* pCmdUI);
  631. afx_msg void OnEditCordon();
  632. afx_msg void OnUpdateEditCordon(CCmdUI* pCmdUI);
  633. afx_msg void OnUpdateViewHideUnselectedObjects(CCmdUI* pCmdUI);
  634. afx_msg void OnToggleGroupignore();
  635. afx_msg void OnUpdateToggleGroupignore(CCmdUI* pCmdUI);
  636. afx_msg void OnVscaleToggle();
  637. afx_msg void OnMapEntityreport();
  638. afx_msg void OnToggleSelectbyhandle();
  639. afx_msg void OnUpdateToggleSelectbyhandle(CCmdUI* pCmdUI);
  640. afx_msg void OnToggleInfiniteselect();
  641. afx_msg void OnUpdateToggleInfiniteselect(CCmdUI* pCmdUI);
  642. afx_msg void OnFileExporttodxf();
  643. afx_msg void OnUpdateEditApplytexture(CCmdUI* pCmdUI);
  644. afx_msg void OnMapLoadpointfile();
  645. afx_msg void OnMapUnloadpointfile();
  646. afx_msg void OnMapLoadportalfile();
  647. afx_msg void OnMapUnloadportalfile();
  648. afx_msg void OnUpdate3dViewUI(CCmdUI* pCmdUI);
  649. afx_msg BOOL OnChange3dViewType(UINT nID);
  650. afx_msg void OnEditToEntity();
  651. afx_msg BOOL OnUndoRedo(UINT nID);
  652. afx_msg void OnUpdateUndoRedo(CCmdUI* pCmdUI);
  653. afx_msg void OnChangeVertexscale();
  654. afx_msg void OnUpdateGroupEditFunction(CCmdUI* pCmdUI);
  655. afx_msg void OnUpdateFileExport(CCmdUI *pCmdUI);
  656. afx_msg void OnEditClearselection();
  657. afx_msg void OnUpdateToggle3DGrid(CCmdUI* pCmdUI);
  658. afx_msg void OnMapShowSelectedBrushNumber();
  659. afx_msg void OnEditFindEntities(void);
  660. afx_msg void OnToolsHideEntityNames(void);
  661. afx_msg void OnUpdateToolsHideEntityNames(CCmdUI *pCmdUI);
  662. afx_msg void OnToggleDispSolidMask( void );
  663. afx_msg void OnUpdateToggleSolidMask(CCmdUI* pCmdUI);
  664. afx_msg void OnToggleDispDrawWalkable( void );
  665. afx_msg void OnUpdateToggleDispDrawWalkable(CCmdUI* pCmdUI);
  666. afx_msg void OnToggleDispDraw3D( void );
  667. afx_msg void OnUpdateToggleDispDraw3D(CCmdUI* pCmdUI);
  668. afx_msg void OnToggleDispDrawBuildable( void );
  669. afx_msg void OnUpdateToggleDispDrawBuildable(CCmdUI* pCmdUI);
  670. afx_msg void OnToggleDispDrawRemovedVerts( void );
  671. afx_msg void OnUpdateToggleDispDrawRemovedVerts(CCmdUI* pCmdUI);
  672. afx_msg void OnUpdateViewShowHelpers(CCmdUI *pCmdUI);
  673. afx_msg void OnUpdateViewShowModelsIn2D(CCmdUI *pCmdUI);
  674. afx_msg void OnUpdateViewPreviewModelFade(CCmdUI *pCmdUI);
  675. afx_msg void OnUpdateCollisionWireframe(CCmdUI *pCmdUI);
  676. afx_msg void OnUpdateShowDetailObjects(CCmdUI *pCmdUI);
  677. afx_msg void OnMapDiff();
  678. afx_msg void OnToolsInstancesHide(void);
  679. afx_msg void OnUpdateToolsInstancesHide(CCmdUI *pCmdUI);
  680. afx_msg void OnToolsInstancesShowTinted(void);
  681. afx_msg void OnUpdateToolsInstancesShowTinted(CCmdUI *pCmdUI);
  682. afx_msg void OnToolsInstancesShowNormal(void);
  683. afx_msg void OnUpdateToolsInstancesShowNormal(CCmdUI *pCmdUI);
  684. afx_msg void OnInstancesHideAll( void );
  685. afx_msg void OnInstancesShowAll( void );
  686. public:
  687. afx_msg void OnToggle3DGrid();
  688. //}}AFX_MSG
  689. DECLARE_MESSAGE_MAP()
  690. afx_msg void OnInstancingCreatemanifest();
  691. afx_msg void OnUpdateInstancingCreatemanifest(CCmdUI *pCmdUI);
  692. afx_msg void OnInstancingCheckinAll();
  693. afx_msg void OnUpdateInstancingCheckinAll( CCmdUI *pCmdUI );
  694. afx_msg void OnInstancingCheckOutManifest();
  695. afx_msg void OnUpdateInstancingCheckOutManifest( CCmdUI *pCmdUI );
  696. afx_msg void OnInstancingAddManifest();
  697. afx_msg void OnUpdateInstancingAddManifest( CCmdUI *pCmdUI );
  698. afx_msg void OnInstancesCollapseAll();
  699. afx_msg void OnInstancesCollapseSelection();
  700. };
  701. //-----------------------------------------------------------------------------
  702. // Purpose:
  703. // Output : inline void
  704. //-----------------------------------------------------------------------------
  705. void CMapDoc::DecrementDocVersion(void)
  706. {
  707. if (m_nDocVersion > 0)
  708. {
  709. m_nDocVersion--;
  710. }
  711. }
  712. //-----------------------------------------------------------------------------
  713. // Purpose: Returns true if we are loading, false if not.
  714. //-----------------------------------------------------------------------------
  715. bool CMapDoc::IsLoading(void)
  716. {
  717. return(m_bLoading);
  718. }
  719. //-----------------------------------------------------------------------------
  720. // Purpose: Returns the document that is currently active.
  721. //-----------------------------------------------------------------------------
  722. CMapDoc *CMapDoc::GetActiveMapDoc(void)
  723. {
  724. return(m_pMapDoc);
  725. }
  726. //-----------------------------------------------------------------------------
  727. // Purpose: Returns the manifest associated with the active document.
  728. //-----------------------------------------------------------------------------
  729. CManifest *CMapDoc::GetManifest(void)
  730. {
  731. return m_pManifest;
  732. }
  733. //-----------------------------------------------------------------------------
  734. // Purpose: Returns the current level loading depth. 0 = not loading level
  735. //-----------------------------------------------------------------------------
  736. int CMapDoc::GetInLevelLoad( )
  737. {
  738. return m_nInLevelLoad;
  739. }
  740. //-----------------------------------------------------------------------------
  741. // Purpose: Returns the current version of the document that is being worked on.
  742. //-----------------------------------------------------------------------------
  743. int CMapDoc::GetDocVersion(void)
  744. {
  745. return(m_nDocVersion);
  746. }
  747. //-----------------------------------------------------------------------------
  748. // Purpose: Returns a pointer to the game configuration for this document.
  749. //-----------------------------------------------------------------------------
  750. CGameConfig *CMapDoc::GetGame(void)
  751. {
  752. return(m_pGame);
  753. }
  754. //-----------------------------------------------------------------------------
  755. // Purpose: Returns a pointer to the Undo system for this document.
  756. //-----------------------------------------------------------------------------
  757. CHistory *CMapDoc::GetDocHistory(void)
  758. {
  759. return(m_pUndo);
  760. }
  761. //-----------------------------------------------------------------------------
  762. // Purpose: Returns the map format of the game configuration for this document.
  763. //-----------------------------------------------------------------------------
  764. MAPFORMAT CMapDoc::GetMapFormat(void)
  765. {
  766. if (m_pGame != NULL)
  767. {
  768. return(m_pGame->mapformat);
  769. }
  770. return(mfHalfLife2);
  771. }
  772. //-----------------------------------------------------------------------------
  773. // Purpose: Returns a pointer to the world that this document edits.
  774. //-----------------------------------------------------------------------------
  775. CMapWorld *CMapDoc::GetMapWorld(void)
  776. {
  777. return(m_pWorld);
  778. }
  779. //-----------------------------------------------------------------------------
  780. // Purpose: All map objects in a given document are assigned a unique ID.
  781. //-----------------------------------------------------------------------------
  782. int CMapDoc::GetNextMapObjectID(void)
  783. {
  784. return(m_nNextMapObjectID++);
  785. }
  786. //-----------------------------------------------------------------------------
  787. // Purpose: Returns the next unique ID for an AI node. Called when an AI node
  788. // is created so that each one can have a unique ID.
  789. //
  790. // We can't use the unique object ID (above) for this because of
  791. // problems with in-engine editing of nodes and node connections.
  792. //-----------------------------------------------------------------------------
  793. int CMapDoc::GetNextNodeID(void)
  794. {
  795. return(m_nNextNodeID++);
  796. }
  797. //-----------------------------------------------------------------------------
  798. // Purpose: Sets the next unique ID for a AI node creation. Called when an AI node
  799. // is created from the shell so that node IDs continue from there.
  800. //-----------------------------------------------------------------------------
  801. void CMapDoc::SetNextNodeID(int nID)
  802. {
  803. m_nNextNodeID = nID;
  804. }
  805. //-----------------------------------------------------------------------------
  806. // Purpose: Returns whether or not grid snap is enabled. Called by the tools and
  807. // views to determine snap behavior.
  808. //-----------------------------------------------------------------------------
  809. bool CMapDoc::IsSnapEnabled(void)
  810. {
  811. return m_bSnapToGrid;
  812. }
  813. #endif // MAPDOC_H