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.

189 lines
5.4 KiB

  1. //========= Copyright 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. virtual void PostloadWorld(CMapWorld *pWorld);
  45. ChunkFileResult_t LoadVMF( CChunkFile *pFile, bool &bValid );
  46. ChunkFileResult_t SaveVMF( CChunkFile *pFile, CSaveInfo *pSaveInfo );
  47. int SerializeRMF( std::fstream &, BOOL );
  48. int SerializeMAP( std::fstream &, BOOL );
  49. //
  50. // Selection/Hit testing.
  51. //
  52. bool HitTest2D(CMapView2D *pView, const Vector2D &point, HitInfo_t &HitData);
  53. CMapClass *PrepareSelection(SelectMode_t eSelectMode);
  54. bool SaveDXF(ExportDXFInfo_s *pInfo);
  55. //
  56. // creation/copy/editing
  57. //
  58. int CreateFromPlanes(DWORD dwFlags = 0);
  59. void InitializeTextureAxes( TextureAlignment_t eAlignment, DWORD dwFlags );
  60. void CalcBounds( BOOL bFullUpdate = FALSE );
  61. virtual CMapClass *Copy(bool bUpdateDependencies);
  62. virtual CMapClass *CopyFrom(CMapClass *pFrom, bool bUpdateDependencies);
  63. int Split(PLANE *pPlane, CMapSolid **pFront = NULL, CMapSolid **pBack = NULL);
  64. bool Subtract(CMapObjectList *pInside, CMapObjectList *pOutside, CMapClass *pSubtractWith);
  65. virtual bool ShouldAppearInLightingPreview(void);
  66. virtual bool ShouldAppearInRaytracedLightingPreview(void);
  67. //
  68. // rendering
  69. //
  70. bool ShouldRenderLast();
  71. void Render3D(CRender3D *pRender);
  72. void Render2D(CRender2D *pRender);
  73. //
  74. // solid info
  75. //
  76. size_t GetSize();
  77. const char* GetDescription();
  78. inline bool IsValid( void ) { return( m_bValid ); }
  79. inline void SetValid( bool bValid ) { m_bValid = bValid; }
  80. void SetTexture( LPCTSTR pszTex, int iFace = -1 );
  81. LPCTSTR GetTexture( int iFace = -1 );
  82. bool HasDisp( void );
  83. virtual bool IsSolid( ) { return true; }
  84. //
  85. // Half-Life 1 solid types.
  86. //
  87. inline HL1_SolidType_t GetHL1SolidType(void) { return(m_eSolidType); }
  88. inline void SetHL1SolidType(HL1_SolidType_t eSolidType) { m_eSolidType = eSolidType; }
  89. HL1_SolidType_t HL1SolidTypeFromTextureName(const char *pszTexture);
  90. virtual bool IsScaleable(void) { return(true); }
  91. virtual bool IsVisualElement(void) { return(true); }
  92. // Overridden to set the render color of each of our faces.
  93. virtual void SetRenderColor(unsigned char uchRed, unsigned char uchGreen, unsigned char uchBlue);
  94. virtual void SetRenderColor(color32 rgbColor);
  95. //
  96. // face info
  97. //
  98. inline int GetFaceCount( void ) { return( Faces.GetCount() ); }
  99. inline void SetFaceCount( int nFaceCount ) { Faces.SetCount( nFaceCount ); }
  100. inline CMapFace *GetFace( int nFace ) { return( &Faces[nFace] ); }
  101. int GetFaceIndex( CMapFace *pFace ); // Returns the index (you could use it with GetFace) or -1 if the face doesn't exist in this solid.
  102. void AddFace( CMapFace *pFace );
  103. void DeleteFace( int iIndex );
  104. CMapFace *FindFaceID(int nFaceID);
  105. //
  106. // Notifications.
  107. //
  108. virtual void OnAddToWorld(CMapWorld *pWorld);
  109. virtual void OnPreClone(CMapClass *pClone, CMapWorld *pWorld, const CMapObjectList &OriginalList, CMapObjectList &NewList);
  110. virtual void OnPrePaste(CMapClass *pCopy, CMapWorld *pSourceWorld, CMapWorld *pDestWorld, const CMapObjectList &OriginalList, CMapObjectList &NewList);
  111. virtual void OnRemoveFromWorld(CMapWorld *pWorld, bool bNotifyChildren);
  112. virtual void OnUndoRedo();
  113. inline bool IsCordonBrush() const;
  114. void SetCordonBrush(bool bSet);
  115. virtual void AddShadowingTriangles( CUtlVector<Vector> &tri_list );
  116. #ifdef _DEBUG
  117. void DebugSolid(void);
  118. #endif // _DEBUG
  119. protected:
  120. void GenerateNewFaceIDs(CMapWorld *pWorld);
  121. void PickRandomColor();
  122. color32 GetLineColor( CRender2D *pRender );
  123. //
  124. // Implements CMapAtom transformation functions.
  125. //
  126. void DoTransform(const VMatrix &matrix);
  127. // dvs: brought in from old carve code; should be reconciled with AddFace, Split, Subtract
  128. bool AddPlane(const CMapFace *p);
  129. bool Carve(CMapObjectList *pInside, CMapObjectList *pOutside, CMapSolid *pCarver);
  130. void ClipByFace(const CMapFace *fa, CMapSolid **f, CMapSolid **b);
  131. void RemoveEmptyFaces(void);
  132. //
  133. // Serialization.
  134. //
  135. static ChunkFileResult_t LoadSideCallback(CChunkFile *pFile, CMapSolid *pSolid);
  136. ChunkFileResult_t SaveEditorData(CChunkFile *pFile);
  137. static int g_nBadSolidCount;
  138. CSolidFaces Faces; // The list of faces on this solid.
  139. bool m_bValid : 1; // Is it a proper convex solid?
  140. bool m_bIsCordonBrush : 1; // Whether this brush was added by the cordon tool.
  141. HL1_SolidType_t m_eSolidType; // Used for HalfLife 1 maps only - solid, water, slime, lava.
  142. };
  143. inline bool CMapSolid::IsCordonBrush() const
  144. {
  145. return m_bIsCordonBrush;
  146. }
  147. #endif // MAPSOLID_H