void OptimizeMap(void) /* optimiza el mapa, eliminando trozos de muros que no se ven */ { int x, z; struct map_block *m; for (z = 1; z < MAP_Z_SIZE - 1; z++) { for (x = 1; x < MAP_X_SIZE - 1; x++) { m = *(m_block + MAP_OFFSET(x, z)); OptimizeFace(m, x + 1, z, 0); OptimizeFace(m, x, z - 1, 1); OptimizeFace(m, x - 1, z, 2); OptimizeFace(m, x, z + 1, 3); } } }
void CEditableMesh::Optimize(BOOL NoOpt) { if (!NoOpt){ #ifdef _EDITOR UnloadRenderBuffers (); UnloadCForm (); #endif UnloadFNormals (true); UnloadVNormals (true); UnloadSVertices (true); UnloadAdjacency (true); // clear static data for (int x=0; x<MX+1; x++) for (int y=0; y<MY+1; y++) for (int z=0; z<MZ+1; z++) VM[x][y][z].clear(); VMscale.set(m_Box.max.x-m_Box.min.x+EPS_S, m_Box.max.y-m_Box.min.y+EPS_S, m_Box.max.z-m_Box.min.z+EPS_S); VMmin.set(m_Box.min.x, m_Box.min.y, m_Box.min.z); VMeps.set(VMscale.x/MX/2,VMscale.y/MY/2,VMscale.z/MZ/2); VMeps.x = (VMeps.x<EPS_L)?VMeps.x:EPS_L; VMeps.y = (VMeps.y<EPS_L)?VMeps.y:EPS_L; VMeps.z = (VMeps.z<EPS_L)?VMeps.z:EPS_L; m_NewPoints.clear(); m_NewPoints.reserve(m_VertCount); boolVec faces_mark; faces_mark.resize(m_FaceCount,false); int i_del_face = 0; for (u32 k=0; k<m_FaceCount; k++){ if (!OptimizeFace(m_Faces[k])){ faces_mark[k] = true; i_del_face ++; } } m_VertCount = m_NewPoints.size(); xr_free (m_Verts); m_Verts = xr_alloc<Fvector>(m_VertCount); Memory.mem_copy (m_Verts,&*m_NewPoints.begin(),m_NewPoints.size()*sizeof(Fvector)); if (i_del_face){ st_Face* old_faces = m_Faces; u32* old_sg = m_SGs; m_Faces = xr_alloc<st_Face> (m_FaceCount-i_del_face); m_SGs = xr_alloc<u32> (m_FaceCount-i_del_face); u32 new_dk = 0; for (u32 dk=0; dk<m_FaceCount; dk++){ if (faces_mark[dk]){ for (SurfFacesPairIt plp_it=m_SurfFaces.begin(); plp_it!=m_SurfFaces.end(); plp_it++){ IntVec& pol_lst = plp_it->second; for (int k=0; k<int(pol_lst.size()); k++){ int& f = pol_lst[k]; if (f>(int)dk){ f--; }else if (f==(int)dk){ pol_lst.erase(pol_lst.begin()+k); k--; } } } continue; } m_Faces[new_dk] = old_faces[dk]; m_SGs[new_dk] = old_sg[dk]; new_dk++; } m_FaceCount = m_FaceCount-i_del_face; xr_free (old_faces); xr_free (old_sg); } } }