- /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *
- // In this function we read from a bunch of new lumps. These include
- // the BSP nodes, the leafs, the leaf faces, BSP splitter planes and
- // visibility data (clusters).
- // Store the number of nodes and allocate the memory to hold them
- m_numOfNodes = lumps[kNodes].length / sizeof(tBSPNode);
- m_pNodes = new tBSPNode [m_numOfNodes];
- // Seek to the position in the file that hold the nodes and store them in m_pNodes
- fseek(fp, lumps[kNodes].offset, SEEK_SET);
- fread(m_pNodes, m_numOfNodes, sizeof(tBSPNode), fp);
- // Store the number of leafs and allocate the memory to hold them
- m_numOfLeafs = lumps[kLeafs].length / sizeof(tBSPLeaf);
- m_pLeafs = new tBSPLeaf [m_numOfLeafs];
- // Seek to the position in the file that holds the leafs and store them in m_pLeafs
- fseek(fp, lumps[kLeafs].offset, SEEK_SET);
- fread(m_pLeafs, m_numOfLeafs, sizeof(tBSPLeaf), fp);
- // Now we need to go through and convert all the leaf bounding boxes
- // to the normal OpenGL Y up axis.
- for(i = 0; i < m_numOfLeafs; i++)
- {
- // Swap the min y and z values, then negate the new Z
- int temp = m_pLeafs[i].min.y;
- m_pLeafs[i].min.y = m_pLeafs[i].min.z;
- m_pLeafs[i].min.z = -temp;
- // Swap the max y and z values, then negate the new Z
- temp = m_pLeafs[i].max.y;
- m_pLeafs[i].max.y = m_pLeafs[i].max.z;
- m_pLeafs[i].max.z = -temp;
- }
- // Store the number of leaf faces and allocate the memory for them
- m_numOfLeafFaces = lumps[kLeafFaces].length / sizeof(int);
- m_pLeafFaces = new int [m_numOfLeafFaces];
- // Seek to the leaf faces lump, then read it's data
- fseek(fp, lumps[kLeafFaces].offset, SEEK_SET);
- fread(m_pLeafFaces, m_numOfLeafFaces, sizeof(int), fp);
- // Store the number of planes, then allocate memory to hold them
- m_numOfPlanes = lumps[kPlanes].length / sizeof(tBSPPlane);
- m_pPlanes = new tBSPPlane [m_numOfPlanes];
- // Seek to the planes lump in the file, then read them into m_pPlanes
- fseek(fp, lumps[kPlanes].offset, SEEK_SET);
- fread(m_pPlanes, m_numOfPlanes, sizeof(tBSPPlane), fp);
- // Go through every plane and convert it's normal to the Y-axis being up
- for(i = 0; i < m_numOfPlanes; i++)
- {
- float temp = m_pPlanes[i].vNormal.y;
- m_pPlanes[i].vNormal.y = m_pPlanes[i].vNormal.z;
- m_pPlanes[i].vNormal.z = -temp;
- }
- // Seek to the position in the file that holds the visibility lump
- fseek(fp, lumps[kVisData].offset, SEEK_SET);
- // Check if there is any visibility information first
- if(lumps[kVisData].length)
- {
- // Read in the number of vectors and each vector's size
- fread(&(m_clusters.numOfClusters), 1, sizeof(int), fp);
- fread(&(m_clusters.bytesPerCluster), 1, sizeof(int), fp);
- // Allocate the memory for the cluster bitsets
- int size = m_clusters.numOfClusters * m_clusters.bytesPerCluster;
- m_clusters.pBitsets = new byte [size];
- // Read in the all the visibility bitsets for each cluster
- fread(m_clusters.pBitsets, 1, sizeof(byte) * size, fp);
- }
- // Otherwise, we don't have any visibility data (prevents a crash)
- else
- m_clusters.pBitsets = NULL;
- /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *