qbsp: set up test case for #158

This commit is contained in:
Eric Wasylishen 2017-07-08 16:23:08 -06:00
parent 34a6bf7876
commit 01fa4a9f58
5 changed files with 97 additions and 22 deletions

View File

@ -22,6 +22,8 @@
#ifndef QBSP_MAP_HH
#define QBSP_MAP_HH
#include <qbsp/parser.hh>
typedef struct epair_s {
struct epair_s *next;
char *key;
@ -61,7 +63,8 @@ struct lumpdata {
void *data;
};
typedef struct mapentity_s {
class mapentity_t {
public:
vec3_t origin;
int firstmapbrush;
@ -77,7 +80,25 @@ typedef struct mapentity_s {
struct lumpdata lumps[BSPX_LUMPS];
const mapbrush_t &mapbrush(int i) const;
} mapentity_t;
mapentity_t() :
firstmapbrush(0),
nummapbrushes(0),
solid(nullptr),
sky(nullptr),
detail(nullptr),
detail_illusionary(nullptr),
detail_fence(nullptr),
liquid(nullptr),
epairs(nullptr),
brushes(nullptr),
numbrushes(0) {
VectorSet(origin,0,0,0);
VectorSet(mins,0,0,0);
VectorSet(maxs,0,0,0);
memset(lumps, 0, sizeof(lumps));
}
};
typedef struct mapdata_s {
/* Arrays of actual items */
@ -119,6 +140,8 @@ typedef struct mapdata_s {
extern mapdata_t map;
extern mapentity_t *pWorldEnt();
bool ParseEntity(parser_t *parser, mapentity_t *entity);
void EnsureTexturesLoaded();
void ProcessExternalMapEntity(mapentity_t *entity);
bool IsWorldBrushEntity(const mapentity_t *entity);

View File

@ -313,7 +313,8 @@ enum class conversion_t {
quake, quake2, valve, bp
};
typedef struct options_s {
class options_t {
public:
bool fNofill;
bool fNoclip;
bool fNoskip;
@ -352,7 +353,27 @@ typedef struct options_s {
bool fOmitDetailIllusionary;
bool fOmitDetailFence;
bool fForcePRT1;
} options_t;
options_t() {
memset(this, 0, sizeof(options_t));
// Initial values
this->dxLeakDist = 2;
this->dxSubdivide = 240;
this->fVerbose = true;
this->szMapName[0] = 0;
this->szBSPName[0] = 0;
this->wadPath[0] = 0;
/* Default to the original Quake BSP Version... */
this->BSPVersion = BSPVERSION;
this->fTranswater = true;
this->fixRotateObjTexture = true;
this->fOldaxis = true;
this->maxNodeSize = 1024;
this->on_epsilon = 0.0001;
}
};
extern options_t options;

View File

@ -1515,7 +1515,7 @@ ParseBrush(parser_t *parser, const mapentity_t *entity)
return brush;
}
static bool
bool
ParseEntity(parser_t *parser, mapentity_t *entity)
{
if (!ParseToken(parser, PARSE_NORMAL))

View File

@ -754,14 +754,6 @@ ParseOptions(char *szOptions)
char *szEnd;
int NameCount = 0;
/* Default to the original Quake BSP Version... */
options.BSPVersion = BSPVERSION;
options.fTranswater = true;
options.fixRotateObjTexture = true;
options.fOldaxis = true;
options.maxNodeSize = 1024;
options.on_epsilon = 0.0001;
szEnd = szOptions + strlen(szOptions);
szTok = GetTok(szOptions, szEnd);
while (szTok) {
@ -920,12 +912,6 @@ InitQBSP(int argc, const char **argv)
char *szBuf;
int length;
// Initial values
options.dxLeakDist = 2;
options.dxSubdivide = 240;
options.fVerbose = true;
options.szMapName[0] = options.szBSPName[0] = options.wadPath[0] = 0;
length = LoadFile("qbsp.ini", &szBuf, false);
if (length) {
Message(msgLiteral, "Loading options from qbsp.ini\n");

View File

@ -1,10 +1,55 @@
#include "gtest/gtest.h"
#include <qbsp/qbsp.hh>
#include <qbsp/map.hh>
using namespace std;
// FIXME: Clear global data (planes, etc) between each test
TEST(qbsp, test) {
FAIL();
static face_t *Brush_FirstFaceWithTextureName(brush_t *brush, const char *texname) {
for (face_t *face = brush->faces; face; face = face->next) {
if (map.texinfoTextureName(face->texinfo) == texname)
return face;
}
return nullptr;
}
// https://github.com/ericwa/tyrutils-ericw/issues/158
TEST(qbsp, testTextureIssue) {
const char *buf = R"(
{
"classname" "worldspawn"
"wad" "Q.wad"
{
( -104 -4 23.999998 ) ( -96.000252 -4 39.999489 ) ( -96.000252 4 39.999489 ) skip 0 0 0 1.000000 1.000000 0 0 0
( -135.996902 4 80.001549 ) ( -152 4 72 ) ( -104 4 23.999998 ) skip 0 -11 -45 1.000000 -1.070000 0 0 0
( -152 -4 72 ) ( -135.996902 -4 80.001549 ) ( -95.998451 -4 40.003094 ) skip 0 -11 -45 1.000000 -1.070000 0 0 0
( -96.000633 -4 40.000637 ) ( -136 -4 80.000008 ) ( -136 4 80.000008 ) skip 0 0 0 1.000000 1.000000 0 0 0
( -136 -4 80 ) ( -152 -4 72 ) ( -152 4 72 ) skip 0 0 0 1.000000 1.000000 0 0 0
( -152 -4 72.000008 ) ( -104.000168 -4 24.000172 ) ( -104.000168 4 24.000172 ) tech02_1 0 -8 0 1.000000 0.750000 0 0 0
}
}
)";
parser_t parser;
ParserInit(&parser, buf);
mapentity_t worldspawn;
// FIXME: adds the brush to the global map...
ASSERT_TRUE(ParseEntity(&parser, &worldspawn));
brush_t *brush = LoadBrush(&worldspawn.mapbrush(0), vec3_origin, 0);
ASSERT_NE(nullptr, brush);
face_t *face = Brush_FirstFaceWithTextureName(brush, "tech02_1");
ASSERT_NE(nullptr, face);
const mtexinfo_t &texinfo = map.mtexinfos.at(face->texinfo);
for (int i=0; i<2; i++) {
printf ("%f %f %f %f\n",
texinfo.vecs[i][0],
texinfo.vecs[i][1],
texinfo.vecs[i][2],
texinfo.vecs[i][3]);
}
}