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.

110 lines
3.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef LEDGEWRITER_H
  7. #define LEDGEWRITER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "vphysics/virtualmesh.h"
  12. // 2-sided triangle ledge rep
  13. struct triangleledge_t
  14. {
  15. IVP_Compact_Ledge ledge;
  16. IVP_Compact_Triangle faces[2];
  17. };
  18. // minimum footprint convex hull rep. Assume 8-bits of index space per edge/triangle/vert
  19. // NOTE: EACH ELEMENT OF THESE STRUCTS MUST BE 8-bits OR YOU HAVE TO WRITE SWAPPING CODE FOR
  20. // THE X360 IMPLEMENTATION. THERE IS NO SUCH CODE AS OF NOW.
  21. #pragma pack(1)
  22. struct packedtriangle_t
  23. {
  24. byte e0; // only bytes allowed see above
  25. byte e1;
  26. byte e2;
  27. byte opposite;
  28. };
  29. struct packededge_t
  30. {
  31. byte v0; // only bytes allowed see above
  32. byte v1;
  33. };
  34. struct packedhull_t
  35. {
  36. byte triangleCount; // only bytes allowed see above
  37. byte vtriCount;
  38. byte edgeCount;
  39. byte vedgeCount;
  40. byte baseVert;
  41. inline size_t DataSize() const
  42. {
  43. return (sizeof(packedtriangle_t) * triangleCount) + (sizeof(packededge_t)*edgeCount);
  44. }
  45. };
  46. struct virtualmeshhull_t
  47. {
  48. byte hullCount; // only bytes allowed see above
  49. byte pad[3];
  50. inline const packedhull_t *GetPackedHull( int hullIndex ) const
  51. {
  52. Assert(hullIndex<hullCount);
  53. return ((const packedhull_t *)(this+1)) + hullIndex;
  54. }
  55. inline const packedtriangle_t *GetPackedTriangles( int hullIndex ) const
  56. {
  57. const packedhull_t *pHull = GetPackedHull(0);
  58. // the first triangle is immediately following the memory for the packed hulls
  59. const byte *pStart = reinterpret_cast<const byte *>(GetPackedHull(0) + hullCount);
  60. for ( int i = 0; i < hullIndex; i++ )
  61. {
  62. pStart += pHull[i].DataSize();
  63. }
  64. return reinterpret_cast<const packedtriangle_t *>(pStart);
  65. }
  66. inline const packededge_t *GetPackedEdges( int hullIndex ) const
  67. {
  68. return reinterpret_cast<const packededge_t *>(GetPackedTriangles(hullIndex) + GetPackedHull(hullIndex)->triangleCount);
  69. }
  70. inline size_t TotalSize() const
  71. {
  72. size_t size = sizeof(*this) + sizeof(packedhull_t) * hullCount;
  73. for ( int i = 0; i < hullCount; i++ )
  74. {
  75. size += GetPackedHull(i)->DataSize();
  76. }
  77. return size;
  78. }
  79. };
  80. #pragma pack()
  81. // end
  82. // NOTE: EACH ELEMENT OF THE ABOVE STRUCTS MUST BE 8-bits OR YOU HAVE TO WRITE SWAPPING CODE FOR
  83. // THE X360 IMPLEMENTATION. THERE IS NO SUCH CODE AS OF NOW.
  84. // These statics are grouped in a class so they can be friends of IVP_Compact_Ledge and access its private data
  85. class CVPhysicsVirtualMeshWriter
  86. {
  87. public:
  88. // init a 2-sided triangle ledge
  89. static void InitTwoSidedTriangleLege( triangleledge_t *pOut, const IVP_Compact_Poly_Point *pPoints, int v0, int v1, int v2, int materialIndex );
  90. static virtualmeshhull_t *CreatePackedHullFromLedges( const virtualmeshlist_t &list, const IVP_Compact_Ledge **pLedges, int ledgeCount );
  91. static void UnpackCompactLedgeFromHull( IVP_Compact_Ledge *pLedge, int materialIndex, const IVP_Compact_Poly_Point *pPointList, const virtualmeshhull_t *pHullHeader, int hullIndex, bool isVirtualLedge );
  92. static void DestroyPackedHull( virtualmeshhull_t *pHull );
  93. static bool LedgeCanBePacked(const IVP_Compact_Ledge *pLedge, const virtualmeshlist_t &list);
  94. static unsigned int UnpackLedgeListFromHull( byte *pOut, virtualmeshhull_t *pHull, IVP_Compact_Poly_Point *pPoints );
  95. };
  96. #endif // LEDGEWRITER_H