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.

237 lines
7.4 KiB

  1. //========= Copyright � 1996-2005, 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. void Init();
  57. CMapDoc *GetOwningDocument( void ) { return m_pOwningDocument; }
  58. //
  59. // Public interface to the culling tree.
  60. //
  61. void CullTree_Build(void);
  62. inline CCullTreeNode *CullTree_GetCullTree(void) { return(m_pCullTree); }
  63. //
  64. // CMapClass virtual overrides.
  65. //
  66. virtual void AddChild(CMapClass *pChild);
  67. virtual CMapClass *Copy(bool bUpdateDependencies);
  68. virtual CMapClass *CopyFrom(CMapClass *pFrom, bool bUpdateDependencies);
  69. virtual void PresaveWorld(void);
  70. virtual void RemoveChild(CMapClass *pChild, bool bUpdateBounds = true);
  71. virtual bool IsWorld() { return true; }
  72. virtual CMapEntity *FindChildByKeyValue( const char* key, const char* value, bool *bIsInInstance = NULL, VMatrix *InstanceMatrix = NULL );
  73. void AddObjectToWorld(CMapClass *pObject, CMapClass *pParent = NULL);
  74. void RemoveObjectFromWorld(CMapClass *pObject, bool bRemoveChildren);
  75. // Groups have to be treated as logical because they potentially have logical children
  76. virtual bool IsLogical(void) { return true; }
  77. virtual bool IsVisibleLogical(void) { return IsVisible(); }
  78. virtual bool IsEditable( void );
  79. //
  80. // Serialization.
  81. //
  82. ChunkFileResult_t LoadVMF(CChunkFile *pFile);
  83. void PostloadWorld(void);
  84. void PostloadVisGroups(void);
  85. // saveFlags is a combination of SAVEFLAGS_ defines.
  86. ChunkFileResult_t SaveSolids(CChunkFile *pFile, CSaveInfo *pSaveInfo, int saveFlags);
  87. ChunkFileResult_t SaveVMF(CChunkFile *pFile, CSaveInfo *pSaveInfo, int saveFlags);
  88. virtual int SerializeRMF(std::fstream &file, BOOL fIsStoring);
  89. virtual int SerializeMAP(std::fstream &file, BOOL fIsStoring, BoundBox *pIntersecting = NULL);
  90. virtual void UpdateChild(CMapClass *pChild);
  91. virtual void OnUndoRedo();
  92. void UpdateAllDependencies( CMapClass *pObject );
  93. //
  94. // Face ID management.
  95. //
  96. inline int FaceID_GetNext(void);
  97. inline void FaceID_SetNext(int nNextFaceID);
  98. CMapFace *FaceID_FaceForID(int nFaceID);
  99. void FaceID_StringToFaceIDLists(CMapFaceIDList *pFullFaceList, CMapFaceIDList *pPartialFaceList, const char *pszValue);
  100. void FaceID_StringToFaceLists(CMapFaceList *pFullFaceList, CMapFaceList *pPartialFaceList, const char *pszValue);
  101. static bool FaceID_FaceIDListsToString(char *pszList, int nSize, CMapFaceIDList *pFullFaceIDList, CMapFaceIDList *pPartialFaceIDList);
  102. static bool FaceID_FaceListsToString(char *pszValue, int nSize, CMapFaceList *pFullFaceList, CMapFaceList *pPartialFaceList);
  103. void GetUsedTextures(CUsedTextureList &List);
  104. void Subtract(CMapObjectList &Results, CMapClass *pSubtractWith, CMapClass *pSubtractFrom);
  105. CUtlVector<CMapPath*> m_Paths;
  106. // Interface to list of all the entities in the world:
  107. const CMapEntityList *EntityList_GetList(void) { return(&m_EntityList); }
  108. inline int EntityList_GetCount();
  109. inline CMapEntity *EntityList_GetEntity( int nIndex );
  110. CMapEntity *FindEntityByName( const char *pszName, bool bVisiblesOnly = false, bool bSearchInstanceParms = false );
  111. bool FindEntitiesByKeyValue(CMapEntityList &Found, const char *szKey, const char *szValue, bool bVisiblesOnly);
  112. bool FindEntitiesByName(CMapEntityList &Found, const char *szName, bool bVisiblesOnly);
  113. bool FindEntitiesByClassName(CMapEntityList &Found, const char *szClassName, bool bVisiblesOnly);
  114. bool FindEntitiesByNameOrClassName(CMapEntityList &Found, const char *pszName, bool bVisiblesOnly);
  115. bool GenerateNewTargetname( const char *startName, char *newName, int newNameBufferSize, bool bMakeUnique, const char *szPrefix, CMapClass *pRoot = NULL );
  116. // displacement management
  117. inline IWorldEditDispMgr *GetWorldEditDispManager( void ) { return m_pWorldDispMgr; }
  118. int GetGroupList(CUtlVector<CMapGroup *> &GroupList);
  119. protected:
  120. //
  121. // Protected entity list functions.
  122. //
  123. void AddEntity( CMapEntity *pEntity );
  124. void EntityList_Add(CMapClass *pObject);
  125. void EntityList_Remove(CMapClass *pObject, bool bRemoveChildren);
  126. int FindEntityBucket( CMapEntity *pEntity, int *pnIndex );
  127. //
  128. // Serialization.
  129. //
  130. static ChunkFileResult_t LoadKeyCallback(const char *szKey, const char *szValue, CMapWorld *pWorld);
  131. static ChunkFileResult_t LoadGroupCallback(CChunkFile *pFile, CMapWorld *pWorld);
  132. static ChunkFileResult_t LoadHiddenCallback(CChunkFile *pFile, CMapWorld *pWorld);
  133. static ChunkFileResult_t LoadHiddenSolidCallback(CChunkFile *pFile, CMapWorld *pWorld);
  134. static ChunkFileResult_t LoadSolidCallback(CChunkFile *pFile, CMapWorld *pWorld);
  135. ChunkFileResult_t LoadSolid(CChunkFile *pFile, bool bVisible);
  136. static BOOL BuildSaveListsCallback(CMapClass *pObject, SaveLists_t *pSaveLists);
  137. ChunkFileResult_t SaveObjectListVMF(CChunkFile *pFile, CSaveInfo *pSaveInfo, const CMapObjectList *pList, int saveFlags);
  138. //
  139. // Culling tree operations.
  140. //
  141. void CullTree_SplitNode(CCullTreeNode *pNode);
  142. void CullTree_DumpNode(CCullTreeNode *pNode, int nDepth);
  143. void CullTree_FreeNode(CCullTreeNode *pNode);
  144. void CullTree_Free(void);
  145. CCullTreeNode *m_pCullTree; // This world's objects stored in a spatial hierarchy for culling.
  146. CMapEntityList m_EntityList; // A flat list of all the entities in this world.
  147. CMapEntityList m_EntityListByName[NUM_HASHED_ENTITY_BUCKETS]; // A list of all the entities in the world, hashed by name checksum.
  148. int m_nNextFaceID; // Used for assigning unique IDs to every solid face in this world.
  149. IWorldEditDispMgr *m_pWorldDispMgr; // world editable displacement manager
  150. CMapDoc *m_pOwningDocument;
  151. };
  152. //-----------------------------------------------------------------------------
  153. // Purpose: Returns the next unique face ID for this world.
  154. //-----------------------------------------------------------------------------
  155. inline int CMapWorld::FaceID_GetNext(void)
  156. {
  157. return(m_nNextFaceID++);
  158. }
  159. //-----------------------------------------------------------------------------
  160. // Purpose: Sets the unique face ID to assign to the next face that is added
  161. // to this world.
  162. //-----------------------------------------------------------------------------
  163. inline void CMapWorld::FaceID_SetNext(int nNextFaceID)
  164. {
  165. m_nNextFaceID = nNextFaceID;
  166. }
  167. inline int CMapWorld::EntityList_GetCount()
  168. {
  169. return m_EntityList.Count();
  170. }
  171. inline CMapEntity *CMapWorld::EntityList_GetEntity( int nIndex )
  172. {
  173. return m_EntityList.Element( nIndex );
  174. }
  175. #endif // MAPWORLD_H