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.

197 lines
5.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef MAPSOLID_H
  8. #define MAPSOLID_H
  9. #pragma once
  10. #include "BlockArray.h"
  11. #include "MapClass.h"
  12. #include "MapFace.h"
  13. enum TextureAlignment_t;
  14. struct ExportDXFInfo_s;
  15. //
  16. // Flags for CreateFromPlanes:
  17. //
  18. #define CREATE_BUILD_PLANE_POINTS 0x0001 // Whether to regenerate the 3 plane points from the generated face points.
  19. #define CREATE_FROM_PLANES_CLIPPING 0x0002
  20. #define MAPSOLID_MAX_FACES 512 // Maximum number of faces a solid can have.
  21. enum HL1_SolidType_t
  22. {
  23. btSolid,
  24. btWater,
  25. btSlime,
  26. btLava
  27. };
  28. typedef BlockArray <CMapFace, 6, (MAPSOLID_MAX_FACES / 6) + 1> CSolidFaces;
  29. class CMapSolid : public CMapClass
  30. {
  31. friend CSSolid;
  32. public:
  33. //
  34. // construction/deconstruction
  35. //
  36. DECLARE_MAPCLASS( CMapSolid, CMapClass );
  37. CMapSolid( CMapClass *Parent0 = NULL );
  38. ~CMapSolid();
  39. //
  40. // Serialization.
  41. //
  42. static void PreloadWorld( void );
  43. static int GetBadSolidCount( void );
  44. static int GetRecordedBadSolidCount( void );
  45. static int GetBadSolidId( int i );
  46. virtual void PostloadWorld(CMapWorld *pWorld);
  47. ChunkFileResult_t LoadVMF( CChunkFile *pFile, bool &bValid );
  48. ChunkFileResult_t SaveVMF( CChunkFile *pFile, CSaveInfo *pSaveInfo );
  49. int SerializeRMF( std::fstream &, BOOL );
  50. int SerializeMAP( std::fstream &, BOOL );
  51. //
  52. // Selection/Hit testing.
  53. //
  54. bool HitTest2D(CMapView2D *pView, const Vector2D &point, HitInfo_t &HitData);
  55. CMapClass *PrepareSelection(SelectMode_t eSelectMode);
  56. bool SaveDXF(ExportDXFInfo_s *pInfo);
  57. //
  58. // creation/copy/editing
  59. //
  60. int CreateFromPlanes(DWORD dwFlags = 0);
  61. void InitializeTextureAxes( TextureAlignment_t eAlignment, DWORD dwFlags );
  62. void CalcBounds( BOOL bFullUpdate = FALSE );
  63. virtual CMapClass *Copy(bool bUpdateDependencies);
  64. virtual CMapClass *CopyFrom(CMapClass *pFrom, bool bUpdateDependencies);
  65. int Split(PLANE *pPlane, CMapSolid **pFront = NULL, CMapSolid **pBack = NULL);
  66. bool Subtract(CMapObjectList *pInside, CMapObjectList *pOutside, CMapClass *pSubtractWith);
  67. virtual bool ShouldAppearInLightingPreview(void);
  68. virtual bool ShouldAppearInRaytracedLightingPreview(void);
  69. virtual bool ShouldAppearOverEngine(void);
  70. //
  71. // rendering
  72. //
  73. bool ShouldRenderLast();
  74. void Render3D(CRender3D *pRender);
  75. void Render2D(CRender2D *pRender);
  76. //
  77. // solid info
  78. //
  79. size_t GetSize();
  80. const char* GetDescription();
  81. inline bool IsValid( void ) { return( m_bValid ); }
  82. inline void SetValid( bool bValid ) { m_bValid = bValid; }
  83. void SetTexture( LPCTSTR pszTex, int iFace = -1 );
  84. LPCTSTR GetTexture( int iFace = -1 );
  85. bool HasDisp( void );
  86. virtual bool IsSolid( ) { return true; }
  87. //
  88. // Half-Life 1 solid types.
  89. //
  90. inline HL1_SolidType_t GetHL1SolidType(void) { return(m_eSolidType); }
  91. inline void SetHL1SolidType(HL1_SolidType_t eSolidType) { m_eSolidType = eSolidType; }
  92. HL1_SolidType_t HL1SolidTypeFromTextureName(const char *pszTexture);
  93. virtual bool IsScaleable(void) const { return(true); }
  94. virtual bool IsVisualElement(void) { return(true); }
  95. // Overridden to set the render color of each of our faces.
  96. virtual void SetRenderColor(unsigned char uchRed, unsigned char uchGreen, unsigned char uchBlue);
  97. virtual void SetRenderColor(color32 rgbColor);
  98. //
  99. // face info
  100. //
  101. inline int GetFaceCount( void ) { return( Faces.GetCount() ); }
  102. inline void SetFaceCount( int nFaceCount ) { Faces.SetCount( nFaceCount ); }
  103. inline CMapFace *GetFace( int nFace ) { return( &Faces[nFace] ); }
  104. int GetFaceIndex( CMapFace *pFace ); // Returns the index (you could use it with GetFace) or -1 if the face doesn't exist in this solid.
  105. void AddFace( CMapFace *pFace );
  106. void DeleteFace( int iIndex );
  107. CMapFace *FindFaceID(int nFaceID);
  108. //
  109. // Notifications.
  110. //
  111. virtual void OnAddToWorld(CMapWorld *pWorld);
  112. virtual void OnPreClone(CMapClass *pClone, CMapWorld *pWorld, const CMapObjectList &OriginalList, CMapObjectList &NewList);
  113. virtual void OnPrePaste(CMapClass *pCopy, CMapWorld *pSourceWorld, CMapWorld *pDestWorld, const CMapObjectList &OriginalList, CMapObjectList &NewList);
  114. virtual void OnRemoveFromWorld(CMapWorld *pWorld, bool bNotifyChildren);
  115. virtual void OnUndoRedo();
  116. inline bool IsCordonBrush() const;
  117. void SetCordonBrush(bool bSet);
  118. virtual void AddShadowingTriangles( CUtlVector<Vector> &tri_list );
  119. #ifdef _DEBUG
  120. void DebugSolid(void);
  121. #endif // _DEBUG
  122. protected:
  123. void GenerateNewFaceIDs(CMapWorld *pWorld);
  124. void PickRandomColor();
  125. color32 GetLineColor( CRender2D *pRender );
  126. //
  127. // Implements CMapAtom transformation functions.
  128. //
  129. void DoTransform(const VMatrix &matrix);
  130. // dvs: brought in from old carve code; should be reconciled with AddFace, Split, Subtract
  131. bool AddPlane(const CMapFace *p);
  132. bool Carve(CMapObjectList *pInside, CMapObjectList *pOutside, CMapSolid *pCarver);
  133. void ClipByFace(const CMapFace *fa, CMapSolid **f, CMapSolid **b);
  134. void RemoveEmptyFaces(void);
  135. //
  136. // Serialization.
  137. //
  138. static ChunkFileResult_t LoadSideCallback(CChunkFile *pFile, CMapSolid *pSolid);
  139. ChunkFileResult_t SaveEditorData(CChunkFile *pFile);
  140. static int g_nBadSolidCount;
  141. static int g_nRecordedBadSolidCount;
  142. static const int MAX_RECORDED_BAD_SOLIDS = 10;
  143. static int g_nRecordedBadSolidIds[MAX_RECORDED_BAD_SOLIDS];
  144. CSolidFaces Faces; // The list of faces on this solid.
  145. bool m_bValid : 1; // Is it a proper convex solid?
  146. bool m_bIsCordonBrush : 1; // Whether this brush was added by the cordon tool.
  147. HL1_SolidType_t m_eSolidType; // Used for HalfLife 1 maps only - solid, water, slime, lava.
  148. };
  149. inline bool CMapSolid::IsCordonBrush() const
  150. {
  151. return m_bIsCordonBrush;
  152. }
  153. #endif // MAPSOLID_H