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.

233 lines
7.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef MAPWORLD_H
  7. #define MAPWORLD_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "MapEntity.h"
  12. #include "EditGameClass.h"
  13. #include "MapClass.h"
  14. #include "MapPath.h"
  15. // Flags for SaveVMF.
  16. #define SAVEFLAGS_LIGHTSONLY (1<<0)
  17. #define SAVEFLAGS_AUTOSAVE (1<<1)
  18. #define MAX_VISIBLE_OBJECTS 10000
  19. #define NUM_HASHED_ENTITY_BUCKETS 200
  20. class BoundBox;
  21. class CChunkFile;
  22. class CVisGroup;
  23. class CCullTreeNode;
  24. class IEditorTexture;
  25. class CMapGroup;
  26. class CMapDoc;
  27. class CMapInstance;
  28. struct SaveLists_t;
  29. struct UsedTexture_t
  30. {
  31. IEditorTexture *pTex;
  32. int nUsageCount;
  33. };
  34. class CUsedTextureList : public CUtlVector<UsedTexture_t>
  35. {
  36. public:
  37. inline int Find(IEditorTexture *pTex)
  38. {
  39. for (int i = 0; i < Count(); i++)
  40. {
  41. if (Element(i).pTex == pTex)
  42. {
  43. return i;
  44. }
  45. }
  46. return -1;
  47. }
  48. };
  49. class CMapWorld : public CMapClass, public CEditGameClass
  50. {
  51. public:
  52. DECLARE_MAPCLASS(CMapWorld,CMapClass)
  53. CMapWorld( void );
  54. CMapWorld( CMapDoc *pOwningDocument );
  55. ~CMapWorld(void);
  56. CMapDoc *GetOwningDocument( void ) { return m_pOwningDocument; }
  57. //
  58. // Public interface to the culling tree.
  59. //
  60. void CullTree_Build(void);
  61. inline CCullTreeNode *CullTree_GetCullTree(void) { return(m_pCullTree); }
  62. //
  63. // CMapClass virtual overrides.
  64. //
  65. virtual void AddChild(CMapClass *pChild);
  66. virtual CMapClass *Copy(bool bUpdateDependencies);
  67. virtual CMapClass *CopyFrom(CMapClass *pFrom, bool bUpdateDependencies);
  68. virtual void PresaveWorld(void);
  69. virtual void RemoveChild(CMapClass *pChild, bool bUpdateBounds = true);
  70. virtual bool IsWorld() { return true; }
  71. virtual CMapEntity *FindChildByKeyValue( const char* key, const char* value, bool *bIsInInstance = NULL, VMatrix *InstanceMatrix = NULL );
  72. void AddObjectToWorld(CMapClass *pObject, CMapClass *pParent = NULL);
  73. void RemoveObjectFromWorld(CMapClass *pObject, bool bRemoveChildren);
  74. // Groups have to be treated as logical because they potentially have logical children
  75. virtual bool IsLogical(void) { return true; }
  76. virtual bool IsVisibleLogical(void) { return IsVisible(); }
  77. virtual bool IsEditable( void );
  78. //
  79. // Serialization.
  80. //
  81. ChunkFileResult_t LoadVMF(CChunkFile *pFile);
  82. void PostloadWorld(void);
  83. void PostloadVisGroups(void);
  84. // saveFlags is a combination of SAVEFLAGS_ defines.
  85. ChunkFileResult_t SaveSolids(CChunkFile *pFile, CSaveInfo *pSaveInfo, int saveFlags);
  86. ChunkFileResult_t SaveVMF(CChunkFile *pFile, CSaveInfo *pSaveInfo, int saveFlags);
  87. virtual int SerializeRMF(std::fstream &file, BOOL fIsStoring);
  88. virtual int SerializeMAP(std::fstream &file, BOOL fIsStoring, BoundBox *pIntersecting = NULL);
  89. virtual void UpdateChild(CMapClass *pChild);
  90. void UpdateAllDependencies( CMapClass *pObject );
  91. //
  92. // Face ID management.
  93. //
  94. inline int FaceID_GetNext(void);
  95. inline void FaceID_SetNext(int nNextFaceID);
  96. CMapFace *FaceID_FaceForID(int nFaceID);
  97. void FaceID_StringToFaceIDLists(CMapFaceIDList *pFullFaceList, CMapFaceIDList *pPartialFaceList, const char *pszValue);
  98. void FaceID_StringToFaceLists(CMapFaceList *pFullFaceList, CMapFaceList *pPartialFaceList, const char *pszValue);
  99. static bool FaceID_FaceIDListsToString(char *pszList, int nSize, CMapFaceIDList *pFullFaceIDList, CMapFaceIDList *pPartialFaceIDList);
  100. static bool FaceID_FaceListsToString(char *pszValue, int nSize, CMapFaceList *pFullFaceList, CMapFaceList *pPartialFaceList);
  101. void GetUsedTextures(CUsedTextureList &List);
  102. void Subtract(CMapObjectList &Results, CMapClass *pSubtractWith, CMapClass *pSubtractFrom);
  103. CUtlVector<CMapPath*> m_Paths;
  104. // Interface to list of all the entities in the world:
  105. const CMapEntityList *EntityList_GetList(void) { return(&m_EntityList); }
  106. inline int EntityList_GetCount();
  107. inline CMapEntity *EntityList_GetEntity( int nIndex );
  108. CMapEntity *FindEntityByName( const char *pszName, bool bVisiblesOnly = false, bool bSearchInstanceParms = false );
  109. bool FindEntitiesByKeyValue(CMapEntityList &Found, const char *szKey, const char *szValue, bool bVisiblesOnly);
  110. bool FindEntitiesByName(CMapEntityList &Found, const char *szName, bool bVisiblesOnly);
  111. bool FindEntitiesByClassName(CMapEntityList &Found, const char *szClassName, bool bVisiblesOnly);
  112. bool FindEntitiesByNameOrClassName(CMapEntityList &Found, const char *pszName, bool bVisiblesOnly);
  113. bool GenerateNewTargetname( const char *startName, char *newName, int newNameBufferSize, bool bMakeUnique, const char *szPrefix, CMapClass *pRoot = NULL );
  114. // displacement management
  115. inline IWorldEditDispMgr *GetWorldEditDispManager( void ) { return m_pWorldDispMgr; }
  116. int GetGroupList(CUtlVector<CMapGroup *> &GroupList);
  117. protected:
  118. //
  119. // Protected entity list functions.
  120. //
  121. void AddEntity( CMapEntity *pEntity );
  122. void EntityList_Add(CMapClass *pObject);
  123. void EntityList_Remove(CMapClass *pObject, bool bRemoveChildren);
  124. int FindEntityBucket( CMapEntity *pEntity, int *pnIndex );
  125. //
  126. // Serialization.
  127. //
  128. static ChunkFileResult_t LoadKeyCallback(const char *szKey, const char *szValue, CMapWorld *pWorld);
  129. static ChunkFileResult_t LoadGroupCallback(CChunkFile *pFile, CMapWorld *pWorld);
  130. static ChunkFileResult_t LoadHiddenCallback(CChunkFile *pFile, CMapWorld *pWorld);
  131. static ChunkFileResult_t LoadHiddenSolidCallback(CChunkFile *pFile, CMapWorld *pWorld);
  132. static ChunkFileResult_t LoadSolidCallback(CChunkFile *pFile, CMapWorld *pWorld);
  133. ChunkFileResult_t LoadSolid(CChunkFile *pFile, bool bVisible);
  134. static BOOL BuildSaveListsCallback(CMapClass *pObject, SaveLists_t *pSaveLists);
  135. ChunkFileResult_t SaveObjectListVMF(CChunkFile *pFile, CSaveInfo *pSaveInfo, const CMapObjectList *pList, int saveFlags);
  136. //
  137. // Culling tree operations.
  138. //
  139. void CullTree_SplitNode(CCullTreeNode *pNode);
  140. void CullTree_DumpNode(CCullTreeNode *pNode, int nDepth);
  141. void CullTree_FreeNode(CCullTreeNode *pNode);
  142. void CullTree_Free(void);
  143. CCullTreeNode *m_pCullTree; // This world's objects stored in a spatial hierarchy for culling.
  144. CMapEntityList m_EntityList; // A flat list of all the entities in this world.
  145. CMapEntityList m_EntityListByName[NUM_HASHED_ENTITY_BUCKETS]; // A list of all the entities in the world, hashed by name checksum.
  146. int m_nNextFaceID; // Used for assigning unique IDs to every solid face in this world.
  147. IWorldEditDispMgr *m_pWorldDispMgr; // world editable displacement manager
  148. CMapDoc *m_pOwningDocument;
  149. };
  150. //-----------------------------------------------------------------------------
  151. // Purpose: Returns the next unique face ID for this world.
  152. //-----------------------------------------------------------------------------
  153. inline int CMapWorld::FaceID_GetNext(void)
  154. {
  155. return(m_nNextFaceID++);
  156. }
  157. //-----------------------------------------------------------------------------
  158. // Purpose: Sets the unique face ID to assign to the next face that is added
  159. // to this world.
  160. //-----------------------------------------------------------------------------
  161. inline void CMapWorld::FaceID_SetNext(int nNextFaceID)
  162. {
  163. m_nNextFaceID = nNextFaceID;
  164. }
  165. inline int CMapWorld::EntityList_GetCount()
  166. {
  167. return m_EntityList.Count();
  168. }
  169. inline CMapEntity *CMapWorld::EntityList_GetEntity( int nIndex )
  170. {
  171. return m_EntityList.Element( nIndex );
  172. }
  173. #endif // MAPWORLD_H