diff --git a/qbsp/test_qbsp.cc b/qbsp/test_qbsp.cc index f68b28d1..36a84de7 100644 --- a/qbsp/test_qbsp.cc +++ b/qbsp/test_qbsp.cc @@ -13,43 +13,74 @@ static face_t *Brush_FirstFaceWithTextureName(brush_t *brush, const char *texnam 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 +static const mapface_t *Mapbrush_FirstFaceWithTextureName(const mapbrush_t *brush, const std::string &texname) { + for (int i=0; inumfaces; i++) { + const mapface_t *face = &brush->face(i); + if (face->texname == texname) { + return face; + } } + return nullptr; } -)"; - + +static std::array +GetTexvecs(const char *map, const char *texname) +{ parser_t parser; - ParserInit(&parser, buf); + ParserInit(&parser, map); mapentity_t worldspawn; // FIXME: adds the brush to the global map... - ASSERT_TRUE(ParseEntity(&parser, &worldspawn)); + Q_assert(ParseEntity(&parser, &worldspawn)); - brush_t *brush = LoadBrush(&worldspawn.mapbrush(0), vec3_origin, 0); - ASSERT_NE(nullptr, brush); + const mapbrush_t *mapbrush = &worldspawn.mapbrush(0); + const mapface_t *mapface = Mapbrush_FirstFaceWithTextureName(mapbrush, "tech02_1"); + Q_assert(nullptr != mapface); - 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]); - } + return mapface->get_texvecs(); } +// https://github.com/ericwa/tyrutils-ericw/issues/158 +TEST(qbsp, testTextureIssue) { + const char *bufActual = 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 + } + } + )"; + + const char *bufExpected = 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 ) ( -104 -4 24 ) ( -104 4 24 ) tech02_1 0 -8 0 1 0.75 0 0 0 + } + } + )"; + + const auto texvecsExpected = GetTexvecs(bufExpected, "tech02_1"); + const auto texvecsActual = GetTexvecs(bufActual, "tech02_1"); + + // not going to fix #158 for now +#if 0 + for (int i=0; i<2; i++) { + for (int j=0; j<4; j++) { + EXPECT_FLOAT_EQ(texvecsExpected[i][j], texvecsActual[i][j]); + } + } +#endif +}