Clone of Akilla's ac2d @ https://github.com/deregtd/AC2D

BSPTypes.cpp 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "stdafx.h"
  2. #include "BSPTypes.h"
  3. cBSPNode * cBSPNode::ParseNode(cByteStream *pData, DWORD dwTreeType)
  4. {
  5. //figure out what type it is;
  6. DWORD bspType = pData->ReadDWORD();
  7. switch (bspType)
  8. {
  9. case 'PORT':
  10. {
  11. cBSPPortal * Prt = new cBSPPortal();
  12. Prt->Parse(pData, dwTreeType);
  13. return Prt;
  14. }
  15. case 'LEAF':
  16. {
  17. cBSPLeaf * Leaf = new cBSPLeaf();
  18. Leaf->Parse(pData, dwTreeType);
  19. return Leaf;
  20. }
  21. default:
  22. {
  23. cBSPNode * Node = new cBSPNode();
  24. Node->Parse(pData, dwTreeType, bspType);
  25. return Node;
  26. }
  27. }
  28. }
  29. void cBSPNode::Parse(cByteStream *pData, DWORD dwTreeType, DWORD dwNodeType)
  30. {
  31. //plane - Plane
  32. float fX = pData->ReadFloat(); //Normal to Plane
  33. float fY = pData->ReadFloat();
  34. float fZ = pData->ReadFloat();
  35. float fDist = pData->ReadFloat(); //Distance
  36. switch ( dwNodeType )
  37. {
  38. case 'BPnn':
  39. case 'BPIn':
  40. m_pChild30 = cBSPNode::ParseNode(pData, dwTreeType);
  41. break;
  42. case 'BpIN':
  43. case 'BpnN':
  44. m_pChild34 = cBSPNode::ParseNode(pData, dwTreeType);
  45. break;
  46. case 'BPIN':
  47. case 'BPnN':
  48. m_pChild30 = cBSPNode::ParseNode(pData, dwTreeType);
  49. m_pChild34 = cBSPNode::ParseNode(pData, dwTreeType);
  50. break;
  51. }
  52. if ((dwTreeType == 0) || (dwTreeType == 1))
  53. {
  54. //bounds - Sphere
  55. pData->ReadGroup(3*sizeof(float)); //Origin
  56. float fRadius = pData->ReadFloat(); //Radius
  57. }
  58. if (dwTreeType)
  59. return;
  60. //Triangle index list...
  61. DWORD dwTriCount = pData->ReadDWORD();
  62. for (DWORD i = 0; i < dwTriCount; i++)
  63. {
  64. WORD wTriIndex = pData->ReadWORD();
  65. }
  66. }
  67. void cBSPPortal::Parse(cByteStream *pData, DWORD dwTreeType)
  68. {
  69. //plane - Plane
  70. pData->ReadGroup(3*sizeof(float)); //Normal
  71. float fDist = pData->ReadFloat(); //Distance
  72. m_pChild30 = cBSPNode::ParseNode(pData, dwTreeType);
  73. m_pChild34 = cBSPNode::ParseNode(pData, dwTreeType);
  74. if (dwTreeType)
  75. return;
  76. //bounds - Sphere
  77. pData->ReadGroup(3*sizeof(float)); //Origin
  78. pData->ReadFloat(); //Radius
  79. //Triangle index list...
  80. DWORD dwTriCount = pData->ReadDWORD();
  81. DWORD dwPolyCount = pData->ReadDWORD();
  82. for (DWORD i = 0; i < dwTriCount; i++)
  83. {
  84. WORD wTriIndex = pData->ReadWORD();
  85. }
  86. for (DWORD i = 0; i < dwPolyCount; i++)
  87. {
  88. //unpack a CPortalPoly here
  89. WORD wIndex = pData->ReadWORD();
  90. WORD wWhat = pData->ReadWORD();
  91. }
  92. }
  93. void cBSPLeaf::Parse(cByteStream *pData, DWORD dwTreeType)
  94. {
  95. m_dwLeaf38 = pData->ReadDWORD();
  96. if (dwTreeType != 1)
  97. return;
  98. m_dwLeaf3C = pData->ReadDWORD();
  99. //bounds - Sphere
  100. pData->ReadGroup(3*sizeof(float)); //Origin
  101. pData->ReadFloat(); //Radius
  102. //Triangle index list...
  103. DWORD dwTriCount = pData->ReadDWORD();
  104. for (DWORD i = 0; i < dwTriCount; i++)
  105. {
  106. WORD wTriIndex = pData->ReadWORD();
  107. }
  108. }