Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void LoadADTData(int mapid, int tilex, int tiley, G3D::AABSPTree<TriangleNode*>* bsptree, G3D::Array<TriangleNode*>* nodes)
- {
- std::map<int, std::string>::iterator itr = g_mapnames.find(mapid);
- if (itr == g_mapnames.end())
- return; //not a valid map
- EnterCriticalSection(&g_mpqMutex);
- char mpqmapfile[1024];
- sprintf(mpqmapfile, "World\\Maps\\%s\\%s_%u_%u.adt", itr->second.c_str(), itr->second.c_str(), tilex, tiley);
- if (!mpq_file_exists(mpqmapfile))
- {
- LeaveCriticalSection(&g_mpqMutex);
- return;
- }
- MPQFile f(mpqmapfile);
- if (f.isEof())
- {
- LeaveCriticalSection(&g_mpqMutex);
- return; //wtf
- }
- LeaveCriticalSection(&g_mpqMutex);
- uint32 chunk;
- uint32 chunksize;
- uint32 mcnkoffsets[256];
- uint32 mcnksizes[256];
- while (!f.isEof())
- {
- f.read(&chunk, 4);
- f.read(&chunksize, 4);
- size_t nextpos = f.getPos() + chunksize;
- if (chunk == 'MCIN')
- {
- for (uint32 i=0; i<256; ++i)
- {
- f.read(&mcnkoffsets[i],4);
- f.read(&mcnksizes[i],4);
- f.seekRelative(8);
- }
- }
- f.seek(nextpos);
- }
- //now go to each chunk
- for (uint32 i=0; i<256; ++i)
- {
- f.seek(mcnkoffsets[i] + 8);
- uint32 indx, indy, holes;
- float basez, basex, basey;
- f.seekRelative(4); //skip flags
- f.read(&indx, 4);
- f.read(&indy, 4);
- f.seek(mcnkoffsets[i] + 8 + 0x3C);
- f.read(&holes, 4);
- f.seek(mcnkoffsets[i] + 8 + 0x68);
- f.read(&basez, 4);
- f.read(&basex, 4);
- f.read(&basey, 4);
- basez = (TILESIZE * 32) - basez;
- basex = (TILESIZE * 32) - basex;
- f.seekRelative(20);
- float heights[145];
- for (uint32 j=0; j<145; ++j)
- {
- f.read(&heights[j], 4);
- heights[j] += basey;
- }
- bool holemap[4][4];
- for (int i = 0; i < 16; i++)
- {
- holemap[i / 4][i % 4] = (((holes >> (i)) & 1) == 1);
- }
- //now this is the complicated part ;)
- for (uint32 row=0; row<8; ++row)
- {
- for (uint32 col=0; col < 8; ++col)
- {
- //are we a hole? (holes are 4x4 (16bits) and we only use the 9x9 but the 8x8 has to be considered)
- //so we can find out if were a hole by using our row and column divided by 2
- if (holemap[row / 2][col / 2])
- continue;
- //think of it like this, were making 2 triangles from a rectangle where
- //our current position is the top left of the first triangle
- #define CREATE_VECTOR(v, r, c) G3D::Vector3 v(basex + ((c) * TILESIZE / 128), heights[((r) * 17) + (c)], basez + ((r) * TILESIZE / 128))
- //First triangle
- CREATE_VECTOR(v1, row + 1, col);
- CREATE_VECTOR(v2, row, col);
- CREATE_VECTOR(v3, row, col + 1);
- //Second triangle
- CREATE_VECTOR(v4, row + 1, col + 1);
- CREATE_VECTOR(v5, row + 1, col);
- CREATE_VECTOR(v6, row, col + 1);
- G3D::Triangle t1(v1, v2, v3);
- G3D::Triangle t2(v4, v5, v6);
- TriangleNode* node1 = new TriangleNode(t1);
- TriangleNode* node2 = new TriangleNode(t2);
- node1->m_flags |= FLAG_ADT_TRIANGLE;
- node2->m_flags |= FLAG_ADT_TRIANGLE;
- //bsptree->insert(node1);
- //bsptree->insert(node2);
- nodes->push_back(node1);
- nodes->push_back(node2);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement