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.

164 lines
4.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef DETAILOBJECTS_H
  7. #define DETAILOBJECTS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "mathlib/mathlib.h"
  12. #include "datamap.h"
  13. #include "bspfile.h"
  14. #include "builddisp.h"
  15. #include "mapface.h"
  16. #include "mapdisp.h"
  17. #include "utlsymbol.h"
  18. #include "sprite.h"
  19. #include "studiomodel.h"
  20. //=============================================================================
  21. // DetailObjects:: class
  22. //=============================================================================
  23. class DetailObjects : public CMapPoint
  24. {
  25. // Comparators Functions for initialized member lists
  26. // Error checking.. make sure the model is valid + is a static prop
  27. struct StaticPropLookup_t
  28. {
  29. CUtlSymbol m_ModelName;
  30. bool m_IsValid;
  31. };
  32. // Comparator for static property sorting
  33. static bool StaticLess( StaticPropLookup_t const& src1, StaticPropLookup_t const& src2 )
  34. {
  35. return src1.m_ModelName < src2.m_ModelName;
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Contructors / Destructors
  39. //-----------------------------------------------------------------------------
  40. public:
  41. DetailObjects() {}
  42. ~DetailObjects();
  43. //-----------------------------------------------------------------------------
  44. // Internal Constants & Data Structures
  45. //-----------------------------------------------------------------------------
  46. protected:
  47. enum { DETAIL_NAME_LENGTH = 128 };
  48. enum DetailPropOrientation_t
  49. {
  50. DETAIL_PROP_ORIENT_NORMAL = 0,
  51. DETAIL_PROP_ORIENT_SCREEN_ALIGNED,
  52. DETAIL_PROP_ORIENT_SCREEN_ALIGNED_VERTICAL,
  53. };
  54. // NOTE: If DetailPropType_t enum changes, change CDetailModel::QuadsToDraw
  55. // in detailobjectsystem.cpp
  56. enum DetailPropType_t
  57. {
  58. DETAIL_PROP_TYPE_MODEL = 0,
  59. DETAIL_PROP_TYPE_SPRITE,
  60. DETAIL_PROP_TYPE_SHAPE_CROSS,
  61. DETAIL_PROP_TYPE_SHAPE_TRI,
  62. };
  63. // Information about particular detail object types
  64. enum
  65. {
  66. MODELFLAG_UPRIGHT = 0x1,
  67. };
  68. class DetailModel_t
  69. {
  70. public:
  71. DetailModel_t();
  72. CUtlSymbol m_ModelName;
  73. float m_Amount;
  74. float m_MinCosAngle;
  75. float m_MaxCosAngle;
  76. int m_Flags;
  77. int m_Orientation;
  78. int m_Type;
  79. Vector2D m_Pos[2];
  80. Vector2D m_Tex[2];
  81. float m_flRandomScaleStdDev;
  82. unsigned char m_ShapeSize;
  83. unsigned char m_ShapeAngle;
  84. unsigned char m_SwayAmount;
  85. };
  86. struct DetailObjectGroup_t
  87. {
  88. float m_Alpha;
  89. CUtlVector< DetailModel_t > m_Models;
  90. };
  91. struct DetailObject_t
  92. {
  93. CUtlSymbol m_Name;
  94. float m_Density;
  95. CUtlVector< DetailObjectGroup_t > m_Groups;
  96. bool operator==(const DetailObject_t& src ) const
  97. {
  98. return src.m_Name == m_Name;
  99. }
  100. };
  101. //-----------------------------------------------------------------------------
  102. // Publically callable interfaces
  103. //-----------------------------------------------------------------------------
  104. public:
  105. static void LoadEmitDetailObjectDictionary( char const* pGameDir );
  106. static void BuildAnyDetailObjects(CMapFace *);
  107. static void EnableBuildDetailObjects( bool bBuild ); // This is used to delay building detail objects until the
  108. // end of the map load. Prevents it from generating the
  109. // detail objects 3x more often than necessary.
  110. void Render3D( CRender3D* pRender );
  111. bool ShouldRenderLast(void);
  112. //-----------------------------------------------------------------------------
  113. // Internal Helper Functions
  114. //-----------------------------------------------------------------------------
  115. protected:
  116. static const char *FindDetailVBSPName( void );
  117. static void ParseDetailObjectFile( KeyValues& keyValues );
  118. static void ParseDetailGroup( int detailId, KeyValues* pGroupKeyValues );
  119. bool LoadStudioModel( char const* pFileName, char const* pEntityType, CUtlBuffer& buf );
  120. float ComputeDisplacementFaceArea( CMapFace *pMapFace );
  121. int SelectGroup( const DetailObject_t& detail, float alpha );
  122. int SelectDetail( DetailObjectGroup_t const& group );
  123. void PlaceDetail( DetailModel_t const& model, const Vector& pt, const Vector& normal );
  124. void EmitDetailObjectsOnFace( CMapFace *pMapFace, DetailObject_t& detail );
  125. void EmitDetailObjectsOnDisplacementFace( CMapFace *pMapFace, DetailObject_t& detail );
  126. void AddDetailSpriteToFace( const Vector &vecOrigin, const QAngle &vecAngles, DetailModel_t const& model, float flScale );
  127. void AddDetailModelToFace( const char* pModelName, const Vector& pt, const QAngle& angles, int nOrientation );
  128. //-----------------------------------------------------------------------------
  129. // Protected Data Members
  130. //-----------------------------------------------------------------------------
  131. static CUtlVector<DetailObject_t> s_DetailObjectDict; // static members?
  132. static bool s_bBuildDetailObjects;
  133. CUtlVector<CSpriteModel *> m_DetailSprites;
  134. CUtlVector<StudioModel *> m_DetailModels;
  135. };
  136. #endif // DETAILOBJECTS_H