Advertisement
Guest User

Untitled

a guest
May 26th, 2010
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. void LoadADTData(int mapid, int tilex, int tiley, G3D::AABSPTree<TriangleNode*>* bsptree, G3D::Array<TriangleNode*>* nodes)
  2. {
  3. std::map<int, std::string>::iterator itr = g_mapnames.find(mapid);
  4.  
  5. if (itr == g_mapnames.end())
  6. return; //not a valid map
  7.  
  8. EnterCriticalSection(&g_mpqMutex);
  9. char mpqmapfile[1024];
  10. sprintf(mpqmapfile, "World\\Maps\\%s\\%s_%u_%u.adt", itr->second.c_str(), itr->second.c_str(), tilex, tiley);
  11.  
  12. if (!mpq_file_exists(mpqmapfile))
  13. {
  14. LeaveCriticalSection(&g_mpqMutex);
  15. return;
  16. }
  17.  
  18. MPQFile f(mpqmapfile);
  19. if (f.isEof())
  20. {
  21. LeaveCriticalSection(&g_mpqMutex);
  22. return; //wtf
  23. }
  24.  
  25. LeaveCriticalSection(&g_mpqMutex);
  26.  
  27. uint32 chunk;
  28. uint32 chunksize;
  29.  
  30. uint32 mcnkoffsets[256];
  31. uint32 mcnksizes[256];
  32.  
  33. while (!f.isEof())
  34. {
  35. f.read(&chunk, 4);
  36. f.read(&chunksize, 4);
  37.  
  38. size_t nextpos = f.getPos() + chunksize;
  39.  
  40. if (chunk == 'MCIN')
  41. {
  42. for (uint32 i=0; i<256; ++i)
  43. {
  44. f.read(&mcnkoffsets[i],4);
  45. f.read(&mcnksizes[i],4);
  46. f.seekRelative(8);
  47. }
  48. }
  49.  
  50. f.seek(nextpos);
  51. }
  52.  
  53. //now go to each chunk
  54. for (uint32 i=0; i<256; ++i)
  55. {
  56. f.seek(mcnkoffsets[i] + 8);
  57. uint32 indx, indy, holes;
  58. float basez, basex, basey;
  59. f.seekRelative(4); //skip flags
  60. f.read(&indx, 4);
  61. f.read(&indy, 4);
  62. f.seek(mcnkoffsets[i] + 8 + 0x3C);
  63. f.read(&holes, 4);
  64. f.seek(mcnkoffsets[i] + 8 + 0x68);
  65. f.read(&basez, 4);
  66. f.read(&basex, 4);
  67. f.read(&basey, 4);
  68.  
  69. basez = (TILESIZE * 32) - basez;
  70. basex = (TILESIZE * 32) - basex;
  71.  
  72. f.seekRelative(20);
  73.  
  74. float heights[145];
  75. for (uint32 j=0; j<145; ++j)
  76. {
  77. f.read(&heights[j], 4);
  78. heights[j] += basey;
  79. }
  80.  
  81. bool holemap[4][4];
  82. for (int i = 0; i < 16; i++)
  83. {
  84. holemap[i / 4][i % 4] = (((holes >> (i)) & 1) == 1);
  85. }
  86.  
  87. //now this is the complicated part ;)
  88. for (uint32 row=0; row<8; ++row)
  89. {
  90. for (uint32 col=0; col < 8; ++col)
  91. {
  92. //are we a hole? (holes are 4x4 (16bits) and we only use the 9x9 but the 8x8 has to be considered)
  93. //so we can find out if were a hole by using our row and column divided by 2
  94. if (holemap[row / 2][col / 2])
  95. continue;
  96.  
  97. //think of it like this, were making 2 triangles from a rectangle where
  98. //our current position is the top left of the first triangle
  99. #define CREATE_VECTOR(v, r, c) G3D::Vector3 v(basex + ((c) * TILESIZE / 128), heights[((r) * 17) + (c)], basez + ((r) * TILESIZE / 128))
  100.  
  101. //First triangle
  102. CREATE_VECTOR(v1, row + 1, col);
  103. CREATE_VECTOR(v2, row, col);
  104. CREATE_VECTOR(v3, row, col + 1);
  105.  
  106. //Second triangle
  107. CREATE_VECTOR(v4, row + 1, col + 1);
  108. CREATE_VECTOR(v5, row + 1, col);
  109. CREATE_VECTOR(v6, row, col + 1);
  110.  
  111. G3D::Triangle t1(v1, v2, v3);
  112. G3D::Triangle t2(v4, v5, v6);
  113. TriangleNode* node1 = new TriangleNode(t1);
  114. TriangleNode* node2 = new TriangleNode(t2);
  115. node1->m_flags |= FLAG_ADT_TRIANGLE;
  116. node2->m_flags |= FLAG_ADT_TRIANGLE;
  117. //bsptree->insert(node1);
  118. //bsptree->insert(node2);
  119. nodes->push_back(node1);
  120. nodes->push_back(node2);
  121. }
  122. }
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement