void LoadMapFile(void) { char *buf; int i, j, length; void *pTemp; struct lumpdata *texinfo; Message(msgProgress, "LoadMapFile"); length = LoadFile(options.szMapName, (void *)&buf, true); PreParseFile(buf); ParserInit(buf); // Faces are loaded in reverse order, to be compatible with origqbsp. // Brushes too. map.iFaces = map.cFaces - 1; map.iBrushes = map.cBrushes - 1; map.iEntities = 0; pCurEnt = &map.rgEntities[0]; while (ParseEntity(pCurEnt)) { map.iEntities++; pCurEnt++; } FreeMem(buf, OTHER, length + 1); // Print out warnings for entities if (!(rgfStartSpots & info_player_start)) Message(msgWarning, warnNoPlayerStart); if (!(rgfStartSpots & info_player_deathmatch)) Message(msgWarning, warnNoPlayerDeathmatch); // if (!(rgfStartSpots & info_player_coop)) // Message(msgWarning, warnNoPlayerCoop); // Clean up texture memory if (cMiptex > map.cFaces) Message(msgError, errLowMiptexCount); else if (cMiptex < map.cFaces) { // For stuff in AddAnimatingTex, make room available pTemp = (void *)rgszMiptex; rgszMiptex = AllocMem(MIPTEX, cMiptex + cAnimtex * 20, true); memcpy(rgszMiptex, pTemp, cMiptex * rgcMemSize[MIPTEX]); FreeMem(pTemp, MIPTEX, map.cFaces); } texinfo = &pWorldEnt->lumps[BSPTEXINFO]; if (texinfo->index > texinfo->count) Message(msgError, errLowTexinfoCount); else if (texinfo->index < texinfo->count) { pTemp = texinfo->data; texinfo->data = AllocMem(BSPTEXINFO, texinfo->index, true); memcpy(texinfo->data, pTemp, texinfo->index * rgcMemSize[BSPTEXINFO]); FreeMem(pTemp, BSPTEXINFO, texinfo->count); texinfo->count = texinfo->index; } // One plane per face + 6 for portals cPlanes = map.cFaces + 6; // Count # of unique planes for (i = 0; i < map.cFaces; i++) { map.rgFaces[i].fUnique = true; for (j = 0; j < i; j++) if (map.rgFaces[j].fUnique && VectorCompare(map.rgFaces[i].plane.normal, map.rgFaces[j].plane.normal) && fabs(map.rgFaces[i].plane.dist - map.rgFaces[j].plane.dist) < EQUAL_EPSILON) { map.rgFaces[i].fUnique = false; cPlanes--; break; } } // Now iterate through brushes, add one plane for each face below 6 axis aligned faces. // This compensates for planes added in ExpandBrush. int cAxis; for (i = 0; i < map.cBrushes; i++) { cAxis = 0; for (j = map.rgBrushes[i].iFaceStart; j < map.rgBrushes[i].iFaceEnd; j++) { if (fabs(map.rgFaces[j].plane.normal[0]) > 1 - NORMAL_EPSILON || fabs(map.rgFaces[j].plane.normal[1]) > 1 - NORMAL_EPSILON || fabs(map.rgFaces[j].plane.normal[2]) > 1 - NORMAL_EPSILON) cAxis++; } if (6 - cAxis > 0) cPlanes += 6 - cAxis; } // cPlanes*3 because of 3 hulls, then add 20% as a fudge factor for hull edge bevel planes cPlanes = 3 * cPlanes + cPlanes / 5; pPlanes = AllocMem(PLANE, cPlanes, true); Message(msgStat, "%5i faces", map.cFaces); Message(msgStat, "%5i brushes", map.cBrushes); Message(msgStat, "%5i entities", map.cEntities); Message(msgStat, "%5i unique texnames", cMiptex); Message(msgStat, "%5i texinfo", texinfo->count); Message(msgLiteral, "\n"); }
void LoadMapFile(void) { parser_t parser; char *buf; int i, j, length, cAxis; void *pTemp; struct lumpdata *texinfo; mapentity_t *ent; mapbrush_t *brush; mapface_t *face, *face2; Message(msgProgress, "LoadMapFile"); length = LoadFile(options.szMapName, &buf, true); PreParseFile(buf); ParserInit(&parser, buf); map.numfaces = map.numbrushes = map.numentities = 0; ent = map.entities; while (ParseEntity(&parser, ent)) { /* Allocate memory for the bmodel, if needed. */ const char *classname = ValueForKey(ent, "classname"); if (strcmp(classname, "func_detail") && ent->nummapbrushes) { ent->lumps[BSPMODEL].data = AllocMem(BSPMODEL, 1, true); ent->lumps[BSPMODEL].count = 1; } map.numentities++; ent++; } /* Double check the entity count matches our pre-parse count */ if (map.numentities != map.maxentities) Error(errLowEntCount); FreeMem(buf, OTHER, length + 1); // Print out warnings for entities if (!(rgfStartSpots & info_player_start)) Message(msgWarning, warnNoPlayerStart); if (!(rgfStartSpots & info_player_deathmatch)) Message(msgWarning, warnNoPlayerDeathmatch); // if (!(rgfStartSpots & info_player_coop)) // Message(msgWarning, warnNoPlayerCoop); // Clean up texture memory if (map.nummiptex > map.maxfaces) Error(errLowMiptexCount); else if (map.nummiptex < map.maxfaces) { // For stuff in AddAnimatingTex, make room available pTemp = map.miptex; map.maxmiptex = map.nummiptex + cAnimtex * 20; map.miptex = AllocMem(MIPTEX, map.maxmiptex, true); memcpy(map.miptex, pTemp, map.nummiptex * rgcMemSize[MIPTEX]); FreeMem(pTemp, MIPTEX, map.maxfaces); } texinfo = &pWorldEnt->lumps[BSPTEXINFO]; if (texinfo->index > texinfo->count) Error(errLowTexinfoCount); else if (texinfo->index < texinfo->count) { pTemp = texinfo->data; texinfo->data = AllocMem(BSPTEXINFO, texinfo->index, true); memcpy(texinfo->data, pTemp, texinfo->index * rgcMemSize[BSPTEXINFO]); FreeMem(pTemp, BSPTEXINFO, texinfo->count); texinfo->count = texinfo->index; } // One plane per face + 6 for portals map.maxplanes = map.numfaces + 6; // Count # of unique planes in all of the faces for (i = 0, face = map.faces; i < map.numfaces; i++, face++) { face->fUnique = true; for (j = 0, face2 = map.faces; j < i; j++, face2++) { if (face2->fUnique && VectorCompare(face->plane.normal, face2->plane.normal) && fabs(face->plane.dist - face2->plane.dist) < EQUAL_EPSILON) { face->fUnique = false; map.maxplanes--; break; } } } /* * Now iterate through brushes, add one plane for each face below 6 axis * aligned faces. This compensates for planes added in ExpandBrush. */ for (i = 0, brush = map.brushes; i < map.numbrushes; i++, brush++) { cAxis = 0; for (j = 0, face = brush->faces; j < brush->numfaces; j++, face++) { if (fabs(face->plane.normal[0]) > 1 - NORMAL_EPSILON || fabs(face->plane.normal[1]) > 1 - NORMAL_EPSILON || fabs(face->plane.normal[2]) > 1 - NORMAL_EPSILON) cAxis++; } if (6 - cAxis > 0) map.maxplanes += 6 - cAxis; } /* * map.maxplanes*3 because of 3 hulls, then add 20% as a fudge factor for * hull edge bevel planes */ map.maxplanes = 3 * map.maxplanes + map.maxplanes / 5; map.planes = AllocMem(PLANE, map.maxplanes, true); Message(msgStat, "%5i faces", map.numfaces); Message(msgStat, "%5i brushes", map.numbrushes); Message(msgStat, "%5i entities", map.numentities); Message(msgStat, "%5i unique texnames", map.nummiptex); Message(msgStat, "%5i texinfo", texinfo->count); Message(msgLiteral, "\n"); }