qbsp: change mapdata_t to use std::vector

This commit is contained in:
Eric Wasylishen 2016-03-20 14:02:31 -06:00
parent f3639eb1e3
commit 60c0b64906
13 changed files with 233 additions and 319 deletions

View File

@ -204,39 +204,18 @@ PlaneInvEqual(const plane_t *p1, const plane_t *p2)
}
/* Plane Hashing */
#define PLANE_HASHES (1<<10)
static struct plane *plane_hash[PLANE_HASHES];
/*
* Choice of hash function:
* - Begin with abs(dist), very rarely > 4096
* - Many maps probably won't go beyond 2048 units
* - Low 3 bits also very commonly zero (axial planes on multiples of 8 units)
*/
static inline int
plane_hash_fn(const struct plane *p)
plane_hash_fn(const plane_t *p)
{
const int dist = floor(fabs(p->dist) + 0.5);
return (dist ^ (dist >> 3)) & (PLANE_HASHES - 1);
return Q_rint(fabs(p->dist));
}
static void
PlaneHash_Add(struct plane *p)
PlaneHash_Add(const plane_t *p, int index)
{
const int hash = plane_hash_fn(p);
p->hash_chain = plane_hash[hash];
plane_hash[hash] = p;
}
void
PlaneHash_Init(void)
{
int i;
for (i = 0; i < PLANE_HASHES; ++i)
plane_hash[i] = NULL;
map.planehash[hash].push_back(index);
}
/*
@ -246,22 +225,21 @@ PlaneHash_Init(void)
static int
NewPlane(const vec3_t normal, const vec_t dist, int *side)
{
plane_t *plane;
vec_t len;
len = VectorLength(normal);
if (len < 1 - ON_EPSILON || len > 1 + ON_EPSILON)
Error("%s: invalid normal (vector length %.4f)", __func__, len);
if (map.numplanes() == map.maxplanes)
Error("Internal error: didn't allocate enough planes? (%s)", __func__);
plane = &map.planes[map.numplanes()];
VectorCopy(normal, plane->normal);
plane->dist = dist;
*side = NormalizePlane(plane) ? SIDE_BACK : SIDE_FRONT;
PlaneHash_Add(plane);
return map._numplanes++;
plane_t plane;
VectorCopy(normal, plane.normal);
plane.dist = dist;
*side = NormalizePlane(&plane) ? SIDE_BACK : SIDE_FRONT;
int index = map.planes.size();
map.planes.push_back(plane);
PlaneHash_Add(&plane, index);
return index;
}
/*
@ -271,26 +249,16 @@ NewPlane(const vec3_t normal, const vec_t dist, int *side)
int
FindPlane(const plane_t *plane, int *side)
{
const int bins[] = { 0, 1, -1 };
const plane_t *p;
int hash, h;
int i;
/* search the border bins as well */
hash = plane_hash_fn(plane);
for (i = 0; i < 3; ++i) {
h = (hash + bins[i]) & (PLANE_HASHES - 1);
for (p = plane_hash[h]; p; p = p->hash_chain) {
if (PlaneEqual(p, plane)) {
*side = SIDE_FRONT;
return p - map.planes;
} else if (PlaneInvEqual(p, plane)) {
*side = SIDE_BACK;
return p - map.planes;
}
for (int i : map.planehash[plane_hash_fn(plane)]) {
const plane_t &p = map.planes.at(i);
if (PlaneEqual(&p, plane)) {
*side = SIDE_FRONT;
return i;
} else if (PlaneInvEqual(&p, plane)) {
*side = SIDE_BACK;
return i;
}
}
return NewPlane(plane->normal, plane->dist, side);
}
@ -315,7 +283,8 @@ FindTargetEntity(const char *target)
const char *name;
const mapentity_t *entity;
for (i = 0, entity = map.entities; i < map.numentities(); i++, entity++) {
for (i = 0; i < map.numentities(); i++) {
entity = &map.entities.at(i);
name = ValueForKey(entity, "targetname");
if (!Q_strcasecmp(target, name))
return entity;
@ -386,8 +355,8 @@ CreateBrushFaces(hullbrush_t *hullbrush, const vec3_t rotate_offset,
for (i = 0; i < hullbrush->numfaces; i++, mapface++) {
if (!hullnum) {
/* Don't generate hintskip faces */
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const char *texname = map.miptex[texinfo[mapface->texinfo].miptex];
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
const char *texname = map.miptex[texinfo[mapface->texinfo].miptex].c_str();
if (!Q_strcasecmp(texname, "hintskip"))
continue;
}
@ -435,7 +404,7 @@ CreateBrushFaces(hullbrush_t *hullbrush, const vec3_t rotate_offset,
// account for texture offset, from txqbsp-xt
if (options.fixRotateObjTexture) {
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
texinfo_t texInfoNew;
vec3_t vecs[2];
int k, l;
@ -555,7 +524,7 @@ AddBrushPlane(hullbrush_t *hullbrush, plane_t *plane)
}
if (hullbrush->numfaces == MAX_FACES)
Error("brush->faces >= MAX_FACES (%d), source brush on line %d",
MAX_FACES, hullbrush->srcbrush->faces[0].linenum);
MAX_FACES, hullbrush->srcbrush->face(0).linenum);
mapface->plane = *plane;
mapface->texinfo = 0;
@ -641,7 +610,7 @@ AddHullPoint(hullbrush_t *hullbrush, vec3_t p, vec3_t hull_size[2])
if (hullbrush->numpoints == MAX_HULL_POINTS)
Error("hullbrush->numpoints == MAX_HULL_POINTS (%d), "
"source brush on line %d",
MAX_HULL_POINTS, hullbrush->srcbrush->faces[0].linenum);
MAX_HULL_POINTS, hullbrush->srcbrush->face(0).linenum);
VectorCopy(p, hullbrush->points[hullbrush->numpoints]);
@ -690,7 +659,7 @@ AddHullEdge(hullbrush_t *hullbrush, vec3_t p1, vec3_t p2, vec3_t hull_size[2])
if (hullbrush->numedges == MAX_HULL_EDGES)
Error("hullbrush->numedges == MAX_HULL_EDGES (%d), "
"source brush on line %d",
MAX_HULL_EDGES, hullbrush->srcbrush->faces[0].linenum);
MAX_HULL_EDGES, hullbrush->srcbrush->face(0).linenum);
hullbrush->edges[i][0] = pt1;
hullbrush->edges[i][1] = pt2;
@ -790,12 +759,11 @@ ExpandBrush(hullbrush_t *hullbrush, vec3_t hull_size[2], face_t *facelist)
static int
Brush_GetContents(const mapbrush_t *mapbrush)
{
const mapface_t *mapface;
const char *texname;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
mapface = mapbrush->faces;
texname = map.miptex[texinfo[mapface->texinfo].miptex];
const mapface_t &mapface = mapbrush->face(0);
texname = map.miptex[texinfo[mapface.texinfo].miptex].c_str();
if (!Q_strcasecmp(texname, "hint") || !Q_strcasecmp(texname, "hintskip"))
return CONTENTS_HINT;
@ -835,12 +803,12 @@ LoadBrush(const mapbrush_t *mapbrush, const vec3_t rotate_offset,
// create the faces
if (mapbrush->numfaces > MAX_FACES)
Error("brush->faces >= MAX_FACES (%d), source brush on line %d",
MAX_FACES, mapbrush->faces[0].linenum);
MAX_FACES, mapbrush->face(0).linenum);
hullbrush.srcbrush = mapbrush;
hullbrush.numfaces = mapbrush->numfaces;
memcpy(hullbrush.faces, mapbrush->faces,
mapbrush->numfaces * sizeof(mapface_t));
for (int i=0; i<mapbrush->numfaces; i++)
hullbrush.faces[i] = mapbrush->face(i);
facelist = CreateBrushFaces(&hullbrush, rotate_offset, hullnum);
if (!facelist) {
@ -934,7 +902,7 @@ Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int hullnum)
{
const char *classname;
brush_t *brush, *next, *nonsolid, *solid;
mapbrush_t *mapbrush;
const mapbrush_t *mapbrush;
vec3_t rotate_offset;
int i, contents, cflags = 0;
int lmshift;
@ -975,9 +943,9 @@ Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int hullnum)
lmshift++; //only allow power-of-two scales
i /= 2;
}
mapbrush = src->mapbrushes;
for (i = 0; i < src->nummapbrushes; i++, mapbrush++) {
mapbrush = &src->mapbrush(i);
contents = Brush_GetContents(mapbrush);
/*
@ -1007,7 +975,7 @@ Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int hullnum)
}
/* entities never use water merging */
if (dst != pWorldEnt)
if (dst != pWorldEnt())
contents = CONTENTS_SOLID;
/* nonsolid brushes don't show up in clipping hulls */

View File

@ -46,7 +46,6 @@ LoadBSPFile(void)
{
int i;
int cFileSize, cLumpSize, iLumpOff;
mapentity_t *entity;
// Load the file header
StripExtension(options.szBSPName);
@ -70,7 +69,8 @@ LoadBSPFile(void)
options.BSPVersion = header->version;
/* Throw all of the data into the first entity to be written out later */
entity = map.entities;
mapentity_t first;
mapentity_t *entity = &first;
for (i = 0; i < BSP_LUMPS; i++) {
map.cTotal[i] = cLumpSize = header->lumps[i].filelen;
iLumpOff = header->lumps[i].fileofs;
@ -116,6 +116,9 @@ LoadBSPFile(void)
}
}
map.entities.clear();
map.entities.push_back(first);
FreeMem(header, OTHER, cFileSize + 1);
}
@ -135,7 +138,8 @@ AddLump(FILE *f, int Type)
lump = &header->lumps[Type];
lump->fileofs = ftell(f);
for (i = 0, entity = map.entities; i < map.numentities(); i++, entity++) {
for (i = 0; i < map.numentities(); i++) {
entity = &map.entities[i];
entities = &entity->lumps[Type];
if (entities->data) {
if (Type == LUMP_MODELS && !options.hexen2) {
@ -195,7 +199,8 @@ GenLump(const char *bspxlump, int Type, size_t sz)
const mapentity_t *entity;
char *out;
for (i = 0, entity = map.entities; i < map.numentities(); i++, entity++) {
for (i = 0; i < map.numentities(); i++) {
entity = &map.entities[i];
entities = &entity->lumps[Type];
cLen += entities->count*sz;
}
@ -203,7 +208,8 @@ GenLump(const char *bspxlump, int Type, size_t sz)
return;
out = (char *)malloc(cLen);
cLen = 0;
for (i = 0, entity = map.entities; i < map.numentities(); i++, entity++) {
for (i = 0; i < map.numentities(); i++) {
entity = &map.entities[i];
entities = &entity->lumps[Type];
memcpy(out+cLen, entities->data, entities->count*sz);
cLen += entities->count*sz;
@ -363,7 +369,7 @@ PrintBSPFileSizes(void)
Message(msgStat, "%8d edges %10d", map.cTotal[LUMP_EDGES],
map.cTotal[LUMP_EDGES] * MemSize[BSP_EDGE]);
lump = &pWorldEnt->lumps[LUMP_TEXTURES];
lump = &pWorldEnt()->lumps[LUMP_TEXTURES];
if (lump->data)
Message(msgStat, "%8d textures %10d",
((dmiptexlump_t *)lump->data)->nummiptex, lump->count);

View File

@ -21,6 +21,8 @@
#ifndef __BSPFILE_H__
#define __BSPFILE_H__
#include <string>
#include <stdint.h>
#ifdef __cplusplus
@ -34,8 +36,6 @@ typedef uint8_t byte;
#define BSP2RMQVERSION (('B' << 24) | ('S' << 16) | ('P' << 8) | '2')
#define BSP2VERSION ('B' | ('S' << 8) | ('P' << 16) | ('2' << 24))
#define MAX_MAP_PLANES 262144
typedef struct {
int32_t fileofs;
int32_t filelen;
@ -101,7 +101,7 @@ typedef struct {
int32_t dataofs[]; /* [nummiptex] */
} dmiptexlump_t;
typedef char miptex_t[16];
typedef std::string miptex_t;
typedef struct {
float point[3];

View File

@ -45,9 +45,9 @@ GetUV(const texinfo_t *texinfo, const vec_t *pos, const int width, const int hei
static void
ExportObjFace(FILE *f, const face_t *face, int *vertcount)
{
const texinfo_t *texinfos = (const texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const texinfo_t *texinfos = (const texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
const texinfo_t *texinfo = &texinfos[face->texinfo];
const char *texname = map.miptex[texinfo->miptex];
const char *texname = map.miptex[texinfo->miptex].c_str();
const texture_t *texture = WADList_GetTexture(texname);
const int width = texture ? texture->width : 64;

View File

@ -113,7 +113,9 @@ const int MemSize_BSP2rmq[] = {
mapdata_t map;
// Useful shortcuts
mapentity_t *pWorldEnt;
mapentity_t *pWorldEnt() {
return &map.entities.at(0);
}
// Mathlib.c
const vec3_t vec3_origin = { 0, 0, 0 };

View File

@ -19,6 +19,8 @@
See file, 'COPYING', for details.
*/
#include <string>
#include <ctype.h>
#include <string.h>
@ -31,6 +33,14 @@
static int rgfStartSpots;
const mapface_t &mapbrush_t::face(int i) const {
return map.faces.at(this->firstface + i);
}
const mapbrush_t &mapentity_t::mapbrush(int i) const {
return map.brushes.at(this->firstmapbrush + i);
}
static void
AddAnimTex(const char *name)
{
@ -60,16 +70,13 @@ AddAnimTex(const char *name)
for (i = 0; i < frame; i++) {
framename[1] = basechar + i;
for (j = 0; j < map.nummiptex(); j++) {
if (!Q_strcasecmp(framename, map.miptex[j]))
if (!Q_strcasecmp(framename, map.miptex[j].c_str()))
break;
}
if (j < map.nummiptex())
continue;
if (map.nummiptex() == map.maxmiptex)
Error("Internal error: map.nummiptex > map.maxmiptex");
snprintf(map.miptex[j], sizeof(map.miptex[j]), "%s", framename);
map._nummiptex++;
map.miptex.push_back(framename);
}
}
@ -85,11 +92,9 @@ FindMiptex(const char *name)
name = pathsep + 1;
for (i = 0; i < map.nummiptex(); i++) {
if (!Q_strcasecmp(name, map.miptex[i]))
if (!Q_strcasecmp(name, map.miptex[i].c_str()))
return i;
}
if (map.nummiptex() == map.maxmiptex)
Error("Internal error: map.nummiptex > map.maxmiptex");
/* Handle animating textures carefully */
if (name[0] == '+') {
@ -97,9 +102,7 @@ FindMiptex(const char *name)
i = map.nummiptex();
}
snprintf(map.miptex[i], sizeof(map.miptex[i]), "%s", name);
map._nummiptex++;
map.miptex.push_back(name);
return i;
}
@ -151,12 +154,12 @@ FindTexinfo(texinfo_t *texinfo, unsigned int flags)
{
int index, j;
texinfo_t *target;
const int num_texinfo = pWorldEnt->lumps[LUMP_TEXINFO].index;
const int num_texinfo = pWorldEnt()->lumps[LUMP_TEXINFO].index;
/* Set the texture flags */
texinfo->flags = flags;
target = (texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
target = (texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
for (index = 0; index < num_texinfo; index++, target++) {
if (texinfo->miptex != target->miptex)
continue;
@ -179,10 +182,10 @@ FindTexinfo(texinfo_t *texinfo, unsigned int flags)
return index;
}
if (index >= pWorldEnt->lumps[LUMP_TEXINFO].count)
if (index >= pWorldEnt()->lumps[LUMP_TEXINFO].count)
{
/* Enlarge the array */
struct lumpdata *lump = &pWorldEnt->lumps[LUMP_TEXINFO];
struct lumpdata *lump = &pWorldEnt()->lumps[LUMP_TEXINFO];
texinfo_t *olddata = (texinfo_t *)lump->data;
int newcount = lump->count * 2;
texinfo_t *newdata = (texinfo_t *)AllocMem(BSP_TEXINFO, newcount, true);
@ -195,19 +198,19 @@ FindTexinfo(texinfo_t *texinfo, unsigned int flags)
}
/* Allocate a new texinfo at the end of the array */
target = ((texinfo_t *) pWorldEnt->lumps[LUMP_TEXINFO].data) + index;
target = ((texinfo_t *) pWorldEnt()->lumps[LUMP_TEXINFO].data) + index;
*target = *texinfo;
pWorldEnt->lumps[LUMP_TEXINFO].index++;
pWorldEnt()->lumps[LUMP_TEXINFO].index++;
map.cTotal[LUMP_TEXINFO]++;
return index;
}
int
FindTexinfoEnt(texinfo_t *texinfo, mapentity_t *entity)
FindTexinfoEnt(texinfo_t *texinfo, const mapentity_t *entity)
{
unsigned int flags = 0;
const char *texname = map.miptex[texinfo->miptex];
const char *texname = map.miptex[texinfo->miptex].c_str();
if (IsSkipName(texname))
flags |= TEX_SKIP;
if (IsHintName(texname))
@ -569,14 +572,15 @@ ParseTextureDef(parser_t *parser, texinfo_t *tx,
}
}
static bool
ParseBrushFace(parser_t *parser, mapface_t *face, mapentity_t *entity)
static std::unique_ptr<mapface_t>
ParseBrushFace(parser_t *parser, const mapentity_t *entity)
{
vec3_t planepts[3], planevecs[2];
vec_t length;
plane_t *plane;
texinfo_t tx;
int i, j;
std::unique_ptr<mapface_t> face { new mapface_t };
face->linenum = parser->linenum;
ParsePlaneDef(parser, planepts);
@ -593,7 +597,7 @@ ParseBrushFace(parser_t *parser, mapface_t *face, mapentity_t *entity)
if (length < NORMAL_EPSILON) {
Message(msgWarning, warnNoPlaneNormal, parser->linenum);
return false;
return nullptr;
}
// ericw -- round texture vector values that are within ZERO_EPSILON of integers,
@ -610,35 +614,30 @@ ParseBrushFace(parser_t *parser, mapface_t *face, mapentity_t *entity)
face->texinfo = FindTexinfoEnt(&tx, entity);
return true;
return face;
}
static void
ParseBrush(parser_t *parser, mapbrush_t *brush, mapentity_t *entity)
mapbrush_t
ParseBrush(parser_t *parser, const mapentity_t *entity)
{
const mapface_t *check;
mapface_t *face;
bool faceok;
brush->faces = face = map.faces + map.numfaces();
mapbrush_t brush;
while (ParseToken(parser, PARSE_NORMAL)) {
if (!strcmp(parser->token, "}"))
break;
if (map.numfaces() == map.maxfaces)
Error("Internal error: didn't allocate enough faces?");
faceok = ParseBrushFace(parser, face, entity);
if (!faceok)
std::unique_ptr<mapface_t> face = ParseBrushFace(parser, entity);
if (face.get() == nullptr)
continue;
/* Check for duplicate planes */
for (check = brush->faces; check < face; check++) {
if (PlaneEqual(&check->plane, &face->plane)) {
for (int i = 0; i<brush.numfaces; i++) {
const mapface_t &check = brush.face(i);
if (PlaneEqual(&check.plane, &face->plane)) {
Message(msgWarning, warnBrushDuplicatePlane, parser->linenum);
continue;
}
if (PlaneInvEqual(&check->plane, &face->plane)) {
if (PlaneInvEqual(&check.plane, &face->plane)) {
/* FIXME - this is actually an invalid brush */
Message(msgWarning, warnBrushDuplicatePlane, parser->linenum);
continue;
@ -646,113 +645,43 @@ ParseBrush(parser_t *parser, mapbrush_t *brush, mapentity_t *entity)
}
/* Save the face, update progress */
map._numfaces++;
Message(msgPercent, map.numfaces(), map.maxfaces);
face++;
if (0 == brush.numfaces)
brush.firstface = map.faces.size();
brush.numfaces++;
map.faces.push_back(*face);
}
brush->numfaces = face - brush->faces;
if (!brush->numfaces)
brush->faces = NULL;
return brush;
}
static bool
ParseEntity(parser_t *parser, mapentity_t *entity)
{
mapbrush_t *brush;
if (!ParseToken(parser, PARSE_NORMAL))
return false;
return nullptr;
if (strcmp(parser->token, "{"))
Error("line %d: Invalid entity format, { not found", parser->linenum);
if (map.numentities() == map.maxentities)
Error("Internal error: didn't allocate enough entities?");
entity->mapbrushes = brush = map.brushes + map.numbrushes();
entity->nummapbrushes = 0;
do {
if (!ParseToken(parser, PARSE_NORMAL))
Error("Unexpected EOF (no closing brace)");
if (!strcmp(parser->token, "}"))
break;
else if (!strcmp(parser->token, "{")) {
if (map.numbrushes() == map.maxbrushes)
Error("Internal error: didn't allocate enough brushes?");
ParseBrush(parser, brush++, entity);
map._numbrushes++;
mapbrush_t brush = ParseBrush(parser, entity);
if (0 == entity->nummapbrushes)
entity->firstmapbrush = map.brushes.size();
entity->nummapbrushes++;
map.brushes.push_back(brush);
} else
ParseEpair(parser, entity);
} while (1);
entity->nummapbrushes = brush - entity->mapbrushes;
if (!entity->nummapbrushes)
entity->mapbrushes = NULL;
return true;
}
static void
PreParseFile(const char *buf)
{
int braces = 0;
struct lumpdata *texinfo;
map.maxentities = map.maxbrushes = map.maxfaces = 0;
// Very simple... we just want numbers here. Invalid formats are
// detected later. Problems with deviant .MAP formats.
while (*buf != 0) {
if (*buf == '\"') {
buf++;
// Quoted string... skip to end of quote
while (*buf != '\"' && *buf)
buf++;
if (!*buf)
break;
} else if (*buf == '/' && *(buf + 1) == '/') {
// Comment... skip to end of line
while (*buf != '\n' && *buf)
buf++;
if (!*buf)
break;
} else if (*buf == '{' && (isspace(buf[1]) || !buf[1])) {
if (braces == 0)
map.maxentities++;
else if (braces == 1)
map.maxbrushes++;
braces++;
} else if (*buf == '}' && (isspace(buf[1]) || !buf[1])) {
braces--;
} else if (*buf == '(') {
map.maxfaces++;
}
buf++;
}
if (map.maxfaces % 3 != 0)
Message(msgWarning, warnBadMapFaceCount);
map.maxfaces /= 3;
map.faces = (mapface_t *)AllocMem(MAPFACE, map.maxfaces, true);
map.brushes = (mapbrush_t *)AllocMem(MAPBRUSH, map.maxbrushes, true);
map.entities = (mapentity_t *)AllocMem(MAPENTITY, map.maxentities, true);
// While we're here...
pWorldEnt = map.entities;
/*
* Allocate maximum memory here, copy over later
* Maximum possible is one miptex/texinfo per face
* Plus a few extra for animations
*/
map.maxmiptex = map.maxfaces + 100;
map.miptex = (miptex_t *)AllocMem(MIPTEX, map.maxmiptex, true);
texinfo = &pWorldEnt->lumps[LUMP_TEXINFO];
texinfo->data = AllocMem(BSP_TEXINFO, 1024, true);
texinfo->count = 1024;
return entity;
}
/*
@ -780,25 +709,27 @@ LoadMapFile(void)
char *buf;
int length;
struct lumpdata *texinfo;
mapentity_t *entity;
Message(msgProgress, "LoadMapFile");
length = LoadFile(options.szMapName, &buf, true);
PreParseFile(buf);
ParserInit(&parser, buf);
map._numfaces = map._numbrushes = map._numentities = 0;
entity = map.entities;
while (ParseEntity(&parser, entity)) {
map._numentities++;
entity++;
for (int i=0; ; i++) {
map.entities.push_back(mapentity_t {});
mapentity_t *entity = &map.entities.at(i);
if (i == 0) {
texinfo = &entity->lumps[LUMP_TEXINFO];
texinfo->data = AllocMem(BSP_TEXINFO, 1024, true);
texinfo->count = 1024;
}
if (!ParseEntity(&parser, entity)) {
break;
}
}
/* Double check the entity count matches our pre-parse count */
if (map.numentities() != map.maxentities)
Error("Internal error: mismatched entity count?");
FreeMem(buf, OTHER, length + 1);
// Print out warnings for entities
@ -809,10 +740,7 @@ LoadMapFile(void)
// if (!(rgfStartSpots & info_player_coop))
// Message(msgWarning, warnNoPlayerCoop);
texinfo = &pWorldEnt->lumps[LUMP_TEXINFO];
map.maxplanes = MAX_MAP_PLANES;
map.planes = (plane_t *)AllocMem(PLANE, map.maxplanes, true);
texinfo = &pWorldEnt()->lumps[LUMP_TEXINFO];
Message(msgStat, "%8d faces", map.numfaces());
Message(msgStat, "%8d brushes", map.numbrushes());
@ -889,12 +817,13 @@ WriteEntitiesToString(void)
int i;
int cLen;
struct lumpdata *entities;
const mapentity_t *entity;
mapentity_t *entity;
map.cTotal[LUMP_ENTITIES] = 0;
for (i = 0, entity = map.entities; i < map.numentities(); i++, entity++) {
entities = &map.entities[i].lumps[LUMP_ENTITIES];
for (i = 0; i < map.numentities(); i++) {
entity = &map.entities.at(i);
entities = &entity->lumps[LUMP_ENTITIES];
/* Check if entity needs to be removed */
if (!entity->epairs || IsWorldBrushEntity(entity)) {

View File

@ -470,7 +470,8 @@ FillOutside(node_t *node, const int hullnum, const int numportals)
}
inside = false;
for (i = 1, entity = map.entities + 1; i < map.numentities(); i++, entity++) {
for (i = 1; i < map.numentities(); i++) {
entity = &map.entities.at(i);
if (!VectorCompare(entity->origin, vec3_origin)) {
if (PlaceOccupant(i, entity->origin, node))
inside = true;

View File

@ -58,10 +58,10 @@ ProcessEntity(mapentity_t *entity, const int hullnum)
if (!Q_strcasecmp(classname, "func_detail"))
return;
if (entity != pWorldEnt) {
if (entity != pWorldEnt()) {
char mod[20];
if (entity == pWorldEnt + 1)
if (entity == pWorldEnt() + 1)
Message(msgProgress, "Internal Entities");
snprintf(mod, sizeof(mod), "*%d", map.cTotal[LUMP_MODELS]);
if (options.fVerbose)
@ -96,13 +96,13 @@ ProcessEntity(mapentity_t *entity, const int hullnum)
* If this is the world entity, find all func_group and func_detail
* entities and add their brushes with the appropriate contents flag set.
*/
if (entity == pWorldEnt) {
if (entity == pWorldEnt()) {
const mapentity_t *source;
int detailcount;
/* Add func_group brushes first */
source = map.entities + 1;
for (i = 1; i < map.numentities(); i++, source++) {
for (i = 1; i < map.numentities(); i++) {
source = &map.entities.at(i);
classname = ValueForKey(source, "classname");
if (!Q_strcasecmp(classname, "func_group"))
Brush_LoadEntity(entity, source, hullnum);
@ -110,8 +110,8 @@ ProcessEntity(mapentity_t *entity, const int hullnum)
/* Add detail brushes next */
detailcount = 0;
source = map.entities + 1;
for (i = 1; i < map.numentities(); i++, source++) {
source = &map.entities.at(i);
classname = ValueForKey(source, "classname");
if (!Q_strcasecmp(classname, "func_detail")) {
int detailstart = entity->numbrushes;
@ -133,13 +133,13 @@ ProcessEntity(mapentity_t *entity, const int hullnum)
surfs = CSGFaces(entity);
FreeBrushes(entity->brushes);
if (options.fObjExport && entity == pWorldEnt && hullnum == 0) {
if (options.fObjExport && entity == pWorldEnt() && hullnum == 0) {
ExportObj(surfs);
}
if (hullnum != 0) {
nodes = SolidBSP(entity, surfs, true);
if (entity == pWorldEnt && !options.fNofill) {
if (entity == pWorldEnt() && !options.fNofill) {
// assume non-world bmodels are simple
numportals = PortalizeWorld(entity, nodes, hullnum);
if (FillOutside(nodes, hullnum, numportals)) {
@ -167,11 +167,11 @@ ProcessEntity(mapentity_t *entity, const int hullnum)
if (options.forceGoodTree)
nodes = SolidBSP(entity, surfs, false);
else
nodes = SolidBSP(entity, surfs, entity == pWorldEnt);
nodes = SolidBSP(entity, surfs, entity == pWorldEnt());
// build all the portals in the bsp tree
// some portals are solid polygons, and some are paths to other leafs
if (entity == pWorldEnt && !options.fNofill) {
if (entity == pWorldEnt() && !options.fNofill) {
// assume non-world bmodels are simple
numportals = PortalizeWorld(entity, nodes, hullnum);
if (FillOutside(nodes, hullnum, numportals)) {
@ -220,7 +220,8 @@ UpdateEntLump(void)
Message(msgStat, "Updating entities lump...");
modnum = 1;
for (i = 1, entity = map.entities + 1; i < map.numentities(); i++, entity++) {
for (i = 1; i < map.numentities(); i++) {
entity = &map.entities.at(i);
if (!entity->nummapbrushes)
continue;
classname = ValueForKey(entity, "classname");
@ -410,9 +411,10 @@ static void BSPX_CreateBrushList(void)
BSPX_Brushes_Init(&ctx);
for (entnum = 0, ent = map.entities; entnum < map.numentities(); entnum++, ent++)
for (entnum = 0; entnum < map.numentities(); entnum++)
{
if (ent == pWorldEnt)
ent = &map.entities.at(entnum);
if (ent == pWorldEnt())
modelnum = 0;
else
{
@ -432,20 +434,20 @@ static void BSPX_CreateBrushList(void)
* If this is the world entity, find all func_group and func_detail
* entities and add their brushes with the appropriate contents flag set.
*/
if (ent == pWorldEnt) {
if (ent == pWorldEnt()) {
const char *classname;
const mapentity_t *source;
int i;
/* Add func_group brushes first */
source = map.entities + 1;
for (i = 1; i < map.numentities(); i++, source++) {
for (i = 1; i < map.numentities(); i++) {
source = &map.entities.at(i);
classname = ValueForKey(source, "classname");
if (!Q_strcasecmp(classname, "func_group"))
Brush_LoadEntity(ent, source, -1);
}
/* Add detail brushes next */
source = map.entities + 1;
for (i = 1; i < map.numentities(); i++, source++) {
for (i = 1; i < map.numentities(); i++) {
source = &map.entities.at(i);
classname = ValueForKey(source, "classname");
if (!Q_strcasecmp(classname, "func_detail"))
Brush_LoadEntity(ent, source, -1);
@ -475,7 +477,8 @@ CreateSingleHull(const int hullnum)
map.cTotal[LUMP_MODELS] = 0;
// for each entity in the map file that has geometry
for (i = 0, entity = map.entities; i < map.numentities(); i++, entity++) {
for (i = 0; i < map.numentities(); i++) {
entity = &map.entities.at(i);
ProcessEntity(entity, hullnum);
if (!options.fAllverbose)
options.fVerbose = false; // don't print rest of entities
@ -491,8 +494,6 @@ CreateHulls
static void
CreateHulls(void)
{
PlaneHash_Init();
/* create the hulls sequentially */
if (!options.fNoverbose)
options.fVerbose = true;
@ -535,9 +536,9 @@ ProcessFile(void)
}
wadlist = NULL;
wadstring = ValueForKey(pWorldEnt, "_wad");
wadstring = ValueForKey(pWorldEnt(), "_wad");
if (!wadstring[0])
wadstring = ValueForKey(pWorldEnt, "wad");
wadstring = ValueForKey(pWorldEnt(), "wad");
if (!wadstring[0])
Message(msgWarning, warnNoWadKey);
else

View File

@ -25,6 +25,7 @@
#include <vector>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <ctype.h>
@ -360,7 +361,6 @@ typedef struct brush_s {
void FreeBrushes(brush_t *brushlist);
void PlaneHash_Init(void);
int FindPlane(const plane_t *plane, int *side);
int PlaneEqual(const plane_t *p1, const plane_t *p2);
int PlaneInvEqual(const plane_t *p1, const plane_t *p2);
@ -512,10 +512,14 @@ typedef struct mapface_s {
int linenum;
} mapface_t;
typedef struct mapbrush_s {
mapface_t *faces;
class mapbrush_t {
public:
int firstface;
int numfaces;
} mapbrush_t;
mapbrush_t() : firstface(0), numfaces(0) {}
const mapface_t &face(int i) const;
} ;
struct lumpdata {
int count;
@ -525,41 +529,36 @@ struct lumpdata {
typedef struct mapentity_s {
vec3_t origin;
mapbrush_t *mapbrushes; /* Array */
int firstmapbrush;
int nummapbrushes;
epair_t *epairs;
vec3_t mins, maxs;
brush_t *brushes; /* NULL terminated list */
int numbrushes;
struct lumpdata lumps[BSPX_LUMPS];
const mapbrush_t &mapbrush(int i) const;
} mapentity_t;
typedef struct mapdata_s {
/* Maximum space available for items */
int maxfaces;
int maxbrushes;
int maxentities;
int maxplanes;
int maxmiptex;
/* Number of items currently used */
int _numfaces;
int _numbrushes;
int _numentities;
int _numplanes;
int _nummiptex;
int numfaces() const { return _numfaces; };
int numbrushes() const { return _numbrushes; };
int numentities() const { return _numentities; };
int numplanes() const { return _numplanes; };
int nummiptex() const { return _nummiptex; };
/* Arrays of actual items */
mapface_t *faces;
mapbrush_t *brushes;
mapentity_t *entities;
plane_t *planes;
miptex_t *miptex;
std::vector<mapface_t> faces;
std::vector<mapbrush_t> brushes;
std::vector<mapentity_t> entities;
std::vector<plane_t> planes;
std::vector<miptex_t> miptex;
/* map from plane hash code to list of indicies in `planes` vector */
std::unordered_map<int, std::vector<int>> planehash;
/* Number of items currently used */
int numfaces() const { return faces.size(); };
int numbrushes() const { return brushes.size(); };
int numentities() const { return entities.size(); };
int numplanes() const { return planes.size(); };
int nummiptex() const { return miptex.size(); };
/* Totals for BSP data items -> TODO: move to a bspdata struct? */
int cTotal[BSPX_LUMPS];
@ -570,7 +569,7 @@ typedef struct mapdata_s {
} mapdata_t;
extern mapdata_t map;
extern mapentity_t *pWorldEnt;
extern mapentity_t *pWorldEnt();
void LoadMapFile(void);

View File

@ -326,7 +326,7 @@ ChoosePlaneFromList(surface_t *surfaces, vec3_t mins, vec3_t maxs)
vec_t distribution, bestdistribution;
const plane_t *plane, *plane2;
const face_t *face;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
/* pick the plane that splits the least */
minsplits = INT_MAX - 1;

View File

@ -49,7 +49,7 @@ SubdivideFace(face_t *f, face_t **prevptr)
/* special (non-surface cached) faces don't need subdivision */
tex = (texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data + f->texinfo;
tex = (texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data + f->texinfo;
if (tex->flags & (TEX_SPECIAL | TEX_SKIP | TEX_HINT))
return;
@ -426,7 +426,7 @@ MakeFaceEdges_r
static int
MakeFaceEdges_r(mapentity_t *entity, node_t *node, int progress)
{
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
face_t *f;
if (node->planenum == PLANENUM_LEAF)
@ -453,7 +453,7 @@ GrowNodeRegion
static void
GrowNodeRegion_BSP29(mapentity_t *entity, node_t *node)
{
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
struct lumpdata *surfedges = &entity->lumps[LUMP_SURFEDGES];
struct lumpdata *faces = &entity->lumps[LUMP_FACES];
struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT];
@ -505,7 +505,7 @@ GrowNodeRegion_BSP29(mapentity_t *entity, node_t *node)
static void
GrowNodeRegion_BSP2(mapentity_t *entity, node_t *node)
{
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
struct lumpdata *surfedges = &entity->lumps[LUMP_SURFEDGES];
struct lumpdata *faces = &entity->lumps[LUMP_FACES];
struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT];
@ -562,7 +562,7 @@ CountData_r
static void
CountData_r(mapentity_t *entity, node_t *node)
{
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
face_t *f;
if (node->planenum == PLANENUM_LEAF)
@ -602,7 +602,8 @@ MakeFaceEdges(mapentity_t *entity, node_t *headnode)
needlmshifts = false;
cStartEdge = 0;
for (i = 0; i < entity - map.entities; i++)
const int entnum = entity - &map.entities.at(0);
for (i = 0; i < entnum; i++)
cStartEdge += map.entities[i].lumps[LUMP_EDGES].count;
CountData_r(entity, headnode);

View File

@ -20,6 +20,7 @@
*/
#include <string.h>
#include <string>
#include "qbsp.h"
#include "wad.h"
@ -180,7 +181,7 @@ WADList_Process(const wad_t *wadlist)
int i;
lumpinfo_t *texture;
dmiptexlump_t *miptexlump;
struct lumpdata *texdata = &pWorldEnt->lumps[LUMP_TEXTURES];
struct lumpdata *texdata = &pWorldEnt()->lumps[LUMP_TEXTURES];
WADList_AddAnimationFrames(wadlist);
@ -189,7 +190,7 @@ WADList_Process(const wad_t *wadlist)
/* Count texture size. Slower, but saves memory. */
for (i = 0; i < map.nummiptex(); i++) {
texture = WADList_FindTexture(wadlist, map.miptex[i]);
texture = WADList_FindTexture(wadlist, map.miptex[i].c_str());
if (texture) {
if (options.fNoTextures)
texdata->count += sizeof(dmiptex_t);
@ -209,7 +210,7 @@ WADList_Process(const wad_t *wadlist)
for (i = 0; i < map.nummiptex(); i++) {
if (miptexlump->dataofs[i] == 0) {
miptexlump->dataofs[i] = -1;
Message(msgWarning, warnTextureNotFound, map.miptex[i]);
Message(msgWarning, warnTextureNotFound, map.miptex[i].c_str());
}
}
}
@ -220,7 +221,7 @@ WADList_LoadTextures(const wad_t *wadlist, dmiptexlump_t *lump)
int i, size;
byte *data;
const wad_t *wad;
struct lumpdata *texdata = &pWorldEnt->lumps[LUMP_TEXTURES];
struct lumpdata *texdata = &pWorldEnt()->lumps[LUMP_TEXTURES];
data = (byte *)&lump->dataofs[map.nummiptex()];
@ -229,7 +230,7 @@ WADList_LoadTextures(const wad_t *wadlist, dmiptexlump_t *lump)
continue;
size = 0;
for (wad = wadlist; wad; wad = wad->next) {
size = WAD_LoadLump(wad, map.miptex[i], data);
size = WAD_LoadLump(wad, map.miptex[i].c_str(), data);
if (size)
break;
}
@ -282,13 +283,13 @@ WADList_AddAnimationFrames(const wad_t *wadlist)
for (i = 0; i < oldcount; i++) {
if (map.miptex[i][0] != '+')
continue;
snprintf(name, sizeof(name), "%s", map.miptex[i]);
name = map.miptex[i];
/* Search for all animations (0-9) and alt-animations (A-J) */
for (j = 0; j < 20; j++) {
name[1] = (j < 10) ? '0' + j : 'a' + j - 10;
if (WADList_FindTexture(wadlist, name))
FindMiptex(name);
if (WADList_FindTexture(wadlist, name.c_str()))
FindMiptex(name.c_str());
}
}

View File

@ -26,7 +26,7 @@
static void
ExportNodePlanes_r(node_t *node, int *planemap)
{
struct lumpdata *planes = &pWorldEnt->lumps[LUMP_PLANES];
struct lumpdata *planes = &pWorldEnt()->lumps[LUMP_PLANES];
plane_t *plane;
dplane_t *dplane;
int i;
@ -82,14 +82,19 @@ ExportNodePlanes
void
ExportNodePlanes(node_t *nodes)
{
struct lumpdata *planes = &pWorldEnt->lumps[LUMP_PLANES];
struct lumpdata *planes = &pWorldEnt()->lumps[LUMP_PLANES];
int *planemap;
// OK just need one plane array, stick it in worldmodel
if (!planes->data) {
// I'd like to use map.numplanes here but we haven't seen every entity yet...
planes->count = map.maxplanes;
planes->data = AllocMem(BSP_PLANE, planes->count, true);
if (map.numplanes() > planes->count) {
int newcount = map.numplanes();
struct lumpdata *newplanes = (struct lumpdata *)AllocMem(BSP_PLANE, newcount, true);
memcpy(newplanes, planes->data, MemSize[BSP_PLANE] * planes->count);
FreeMem(planes->data, BSP_PLANE, planes->count);
planes->count = newcount;
planes->data = newplanes;
}
// TODO: make one-time allocation?
planemap = (int *)AllocMem(OTHER, sizeof(int) * planes->count, true);
@ -217,7 +222,8 @@ ExportClipNodes(mapentity_t *entity, node_t *nodes, const int hullnum)
oldcount = clipnodes->count;
/* Count nodes before this one */
for (i = 0; i < entity - map.entities; i++)
const int entnum = entity - &map.entities.at(0);
for (i = 0; i < entnum; i++)
clipcount += map.entities[i].lumps[LUMP_CLIPNODES].count;
model->headnode[hullnum] = clipcount + oldcount;
@ -276,7 +282,7 @@ static void
CountLeaves(mapentity_t *entity, node_t *node)
{
face_t **markfaces, *face;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
entity->lumps[LUMP_LEAFS].count++;
for (markfaces = node->markfaces; *markfaces; markfaces++) {
@ -330,7 +336,7 @@ ExportLeaf
static void
ExportLeaf_BSP29(mapentity_t *entity, node_t *node)
{
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
struct lumpdata *leaves = &entity->lumps[LUMP_LEAFS];
struct lumpdata *marksurfs = &entity->lumps[LUMP_MARKSURFACES];
uint16_t *marksurfnums = (uint16_t *)marksurfs->data;
@ -380,7 +386,7 @@ ExportLeaf_BSP29(mapentity_t *entity, node_t *node)
static void
ExportLeaf_BSP2(mapentity_t *entity, node_t *node)
{
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
struct lumpdata *leaves = &entity->lumps[LUMP_LEAFS];
struct lumpdata *marksurfs = &entity->lumps[LUMP_MARKSURFACES];
uint32_t *marksurfnums = (uint32_t *)marksurfs->data;
@ -430,7 +436,7 @@ ExportLeaf_BSP2(mapentity_t *entity, node_t *node)
static void
ExportLeaf_BSP2rmq(mapentity_t *entity, node_t *node)
{
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
struct lumpdata *leaves = &entity->lumps[LUMP_LEAFS];
struct lumpdata *marksurfs = &entity->lumps[LUMP_MARKSURFACES];
uint32_t *marksurfnums = (uint32_t *)marksurfs->data;
@ -630,13 +636,13 @@ ExportDrawNodes(mapentity_t *entity, node_t *headnode, int firstface)
* BeginBSPFile.
*/
if (options.BSPVersion == BSP2VERSION) {
bsp2_dleaf_t *leaf = (bsp2_dleaf_t *)pWorldEnt->lumps[LUMP_LEAFS].data;
bsp2_dleaf_t *leaf = (bsp2_dleaf_t *)pWorldEnt()->lumps[LUMP_LEAFS].data;
leaf->contents = CONTENTS_SOLID;
} else if (options.BSPVersion == BSP2RMQVERSION) {
bsp2rmq_dleaf_t *leaf = (bsp2rmq_dleaf_t *)pWorldEnt->lumps[LUMP_LEAFS].data;
bsp2rmq_dleaf_t *leaf = (bsp2rmq_dleaf_t *)pWorldEnt()->lumps[LUMP_LEAFS].data;
leaf->contents = CONTENTS_SOLID;
} else {
bsp29_dleaf_t *leaf = (bsp29_dleaf_t *)pWorldEnt->lumps[LUMP_LEAFS].data;
bsp29_dleaf_t *leaf = (bsp29_dleaf_t *)pWorldEnt()->lumps[LUMP_LEAFS].data;
leaf->contents = CONTENTS_SOLID;
}
@ -664,7 +670,7 @@ ExportDrawNodes(mapentity_t *entity, node_t *headnode, int firstface)
/* Not counting initial vis leaf */
dmodel->visleafs = leaves->count;
if (entity == pWorldEnt)
if (entity == pWorldEnt())
dmodel->visleafs--;
/* remove the headnode padding */
@ -685,13 +691,13 @@ void
BeginBSPFile(void)
{
// First edge must remain unused because 0 can't be negated
pWorldEnt->lumps[LUMP_EDGES].count++;
pWorldEnt->lumps[LUMP_EDGES].index++;
pWorldEnt()->lumps[LUMP_EDGES].count++;
pWorldEnt()->lumps[LUMP_EDGES].index++;
map.cTotal[LUMP_EDGES]++;
// Leave room for leaf 0 (must be solid)
pWorldEnt->lumps[LUMP_LEAFS].count++;
pWorldEnt->lumps[LUMP_LEAFS].index++;
pWorldEnt()->lumps[LUMP_LEAFS].count++;
pWorldEnt()->lumps[LUMP_LEAFS].index++;
map.cTotal[LUMP_LEAFS]++;
}
@ -703,8 +709,8 @@ static void
WriteExtendedTexinfoFlags(void)
{
bool needwrite = false;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const int num_texinfo = pWorldEnt->lumps[LUMP_TEXINFO].index;
const texinfo_t *texinfo = (const texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
const int num_texinfo = pWorldEnt()->lumps[LUMP_TEXINFO].index;
int i;
for (i = 0; i < num_texinfo; i++) {
@ -738,8 +744,8 @@ WriteExtendedTexinfoFlags(void)
static void
CleanBSPTexinfoFlags(void)
{
texinfo_t *texinfo = (texinfo_t *)pWorldEnt->lumps[LUMP_TEXINFO].data;
const int num_texinfo = pWorldEnt->lumps[LUMP_TEXINFO].index;
texinfo_t *texinfo = (texinfo_t *)pWorldEnt()->lumps[LUMP_TEXINFO].data;
const int num_texinfo = pWorldEnt()->lumps[LUMP_TEXINFO].index;
int i;
for (i = 0; i < num_texinfo; i++, texinfo++)
@ -754,7 +760,7 @@ FinishBSPFile
void
FinishBSPFile(void)
{
struct lumpdata *planes = &pWorldEnt->lumps[LUMP_PLANES];
struct lumpdata *planes = &pWorldEnt()->lumps[LUMP_PLANES];
dplane_t *newdata;
options.fVerbose = true;
@ -772,7 +778,7 @@ FinishBSPFile(void)
struct lumpdata *texinfo;
void *pTemp;
texinfo = &pWorldEnt->lumps[LUMP_TEXINFO];
texinfo = &pWorldEnt()->lumps[LUMP_TEXINFO];
pTemp = texinfo->data;
texinfo->data = AllocMem(BSP_TEXINFO, texinfo->index, true);
memcpy(texinfo->data, pTemp, texinfo->index * MemSize[BSP_TEXINFO]);