From 01fa4a9f58091ea3dd442b2644286a779810b794 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sat, 8 Jul 2017 16:23:08 -0600 Subject: [PATCH] qbsp: set up test case for #158 --- include/qbsp/map.hh | 27 +++++++++++++++++++++-- include/qbsp/qbsp.hh | 25 ++++++++++++++++++++-- qbsp/map.cc | 2 +- qbsp/qbsp.cc | 14 ------------ qbsp/test_qbsp.cc | 51 +++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 97 insertions(+), 22 deletions(-) diff --git a/include/qbsp/map.hh b/include/qbsp/map.hh index 25119682..90ca0168 100644 --- a/include/qbsp/map.hh +++ b/include/qbsp/map.hh @@ -22,6 +22,8 @@ #ifndef QBSP_MAP_HH #define QBSP_MAP_HH +#include + 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); diff --git a/include/qbsp/qbsp.hh b/include/qbsp/qbsp.hh index 61146fc6..13d6c587 100644 --- a/include/qbsp/qbsp.hh +++ b/include/qbsp/qbsp.hh @@ -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; diff --git a/qbsp/map.cc b/qbsp/map.cc index b575f716..f9109f96 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -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)) diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index 6cb0b002..524d4f68 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -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"); diff --git a/qbsp/test_qbsp.cc b/qbsp/test_qbsp.cc index 0ba6c766..f68b28d1 100644 --- a/qbsp/test_qbsp.cc +++ b/qbsp/test_qbsp.cc @@ -1,10 +1,55 @@ #include "gtest/gtest.h" #include +#include -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]); + } }