diff --git a/common/bspfile.cc b/common/bspfile.cc index 272438a9..3b5efa8f 100644 --- a/common/bspfile.cc +++ b/common/bspfile.cc @@ -21,17 +21,18 @@ #include #include -const bspversion_t bspver_generic { NO_VERSION, NO_VERSION, "mbsp", "generic BSP" }; -const bspversion_t bspver_q1 { BSPVERSION, NO_VERSION, "bsp29", "Quake BSP" }; -const bspversion_t bspver_bsp2 { BSP2VERSION, NO_VERSION, "bsp2", "Quake BSP2" }; -const bspversion_t bspver_bsp2rmq { BSP2RMQVERSION, NO_VERSION, "bsp2rmq", "Quake BSP2-RMQ" }; -/* Hexen II doesn't use a separate version, but we can still use a separate tag/name for it */ -const bspversion_t bspver_h2 { BSPVERSION, NO_VERSION, "hexen2", "Hexen II BSP" }; -const bspversion_t bspver_h2bsp2 { BSP2VERSION, NO_VERSION, "hexen2bsp2", "Hexen II BSP2" }; -const bspversion_t bspver_h2bsp2rmq { BSP2RMQVERSION, NO_VERSION, "hexen2bsp2rmq", "Hexen II BSP2-RMQ" }; -const bspversion_t bspver_hl { BSPHLVERSION, NO_VERSION, "hl", "Half-Life BSP" }; -const bspversion_t bspver_q2 { Q2_BSPIDENT, Q2_BSPVERSION, "q2bsp", "Quake II BSP" }; -const bspversion_t bspver_qbism { Q2_QBISMIDENT, Q2_BSPVERSION, "qbism", "Quake II Qbism BSP" }; +/* hexen2, quake2 */ +const bspversion_t bspver_generic { NO_VERSION, NO_VERSION, "mbsp", "generic BSP", false, false }; +const bspversion_t bspver_q1 { BSPVERSION, NO_VERSION, "bsp29", "Quake BSP", false, false }; +const bspversion_t bspver_bsp2 { BSP2VERSION, NO_VERSION, "bsp2", "Quake BSP2", false, false }; +const bspversion_t bspver_bsp2rmq { BSP2RMQVERSION, NO_VERSION, "bsp2rmq", "Quake BSP2-RMQ", false, false }; +/* Hexen II doesn't use a separate version, but we can still use a separate tag/name for it */ +const bspversion_t bspver_h2 { BSPVERSION, NO_VERSION, "hexen2", "Hexen II BSP", true, false }; +const bspversion_t bspver_h2bsp2 { BSP2VERSION, NO_VERSION, "hexen2bsp2", "Hexen II BSP2", true, false }; +const bspversion_t bspver_h2bsp2rmq { BSP2RMQVERSION, NO_VERSION, "hexen2bsp2rmq", "Hexen II BSP2-RMQ", true, false }; +const bspversion_t bspver_hl { BSPHLVERSION, NO_VERSION, "hl", "Half-Life BSP", false, false }; +const bspversion_t bspver_q2 { Q2_BSPIDENT, Q2_BSPVERSION, "q2bsp", "Quake II BSP", false, true }; +const bspversion_t bspver_qbism { Q2_QBISMIDENT, Q2_BSPVERSION, "qbism", "Quake II Qbism BSP", false, true }; static const char * BSPVersionString(const bspversion_t *version) diff --git a/include/common/bspfile.hh b/include/common/bspfile.hh index a7dddd26..3fd3fed5 100644 --- a/include/common/bspfile.hh +++ b/include/common/bspfile.hh @@ -61,6 +61,8 @@ struct bspversion_t const char *short_name; /* full display name for printing */ const char *name; + bool hexen2; + bool quake2; }; #define NO_VERSION -1 diff --git a/include/qbsp/qbsp.hh b/include/qbsp/qbsp.hh index cab5d557..b15b433c 100644 --- a/include/qbsp/qbsp.hh +++ b/include/qbsp/qbsp.hh @@ -286,8 +286,7 @@ public: bool fixRotateObjTexture; bool fbspx_brushes; bool fNoTextures; - int hexen2;/*2 if the worldspawn mission pack flag was set*/ - int BSPVersion; + const bspversion_t *target_version = nullptr; int dxSubdivide; int dxLeakDist; int maxNodeSize; @@ -342,8 +341,6 @@ public: fixRotateObjTexture(true), fbspx_brushes(false), fNoTextures(false), - hexen2(0), - BSPVersion(BSPVERSION), // Default to the original Quake BSP Version... dxSubdivide(240), dxLeakDist(2), maxNodeSize(1024), diff --git a/qbsp/brush.cc b/qbsp/brush.cc index 8ad30083..a951f3fe 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -487,7 +487,7 @@ CreateBrushFaces(const mapentity_t *src, hullbrush_t *hullbrush, (rotate_offset[0] != 0.0 || rotate_offset[1] != 0.0 || rotate_offset[2] != 0.0) && rottype == rotation_t::hipnotic && (hullnum >= 0) // hullnum < 0 corresponds to -wrbrushes clipping hulls - && !options.hexen2; // never do this in Hexen 2 + && !options.target_version->hexen2; // never do this in Hexen 2 if (shouldExpand) { vec_t delta; @@ -909,7 +909,7 @@ brush_t *LoadBrush(const mapentity_t *src, const mapbrush_t *mapbrush, int conte return NULL; } - if (options.BSPVersion == BSPHLVERSION) + if (options.target_version == &bspver_hl) { if (hullnum == 1) { vec3_t size[2] = { {-16, -16, -36}, {16, 16, 36} }; @@ -930,7 +930,7 @@ brush_t *LoadBrush(const mapentity_t *src, const mapbrush_t *mapbrush, int conte facelist = CreateBrushFaces(src, &hullbrush, rotate_offset, rottype, hullnum); } } - else if (options.hexen2) + else if (options.target_version->hexen2) { if (hullnum == 1) { vec3_t size[2] = { {-16, -16, -32}, {16, 16, 24} }; diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index 54969893..efe4bbe6 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -576,9 +576,9 @@ CreateHulls(void) CreateSingleHull(1); CreateSingleHull(2); - if (options.BSPVersion == BSPHLVERSION) + if (options.target_version == &bspver_hl) CreateSingleHull(3); - else if (options.hexen2) + else if (options.target_version->hexen2) { /*note: h2mp doesn't use hull 2 automatically, however gamecode can explicitly set ent.hull=3 to access it*/ CreateSingleHull(3); CreateSingleHull(4); @@ -781,6 +781,9 @@ ParseOptions(char *szOptions) char *szEnd; int NameCount = 0; + // temporary flags + bool hexen2 = false; + szEnd = szOptions + strlen(szOptions); szTok = GetTok(szOptions, szEnd); while (szTok) { @@ -832,7 +835,11 @@ ParseOptions(char *szOptions) else if (!Q_strcasecmp(szTok, "nopercent")) options.fNopercent = true; else if (!Q_strcasecmp(szTok, "hexen2")) - options.hexen2 = true; + hexen2 = true; // can be combined with -bsp2 or -2psb + else if (!Q_strcasecmp(szTok, "q2bsp")) + options.target_version = &bspver_q2; + else if (!Q_strcasecmp(szTok, "qbism")) + options.target_version = &bspver_qbism; else if (!Q_strcasecmp(szTok, "wrbrushes") || !Q_strcasecmp(szTok, "bspx")) options.fbspx_brushes = true; else if (!Q_strcasecmp(szTok, "wrbrushesonly") || !Q_strcasecmp(szTok, "bspxonly")) { @@ -840,11 +847,11 @@ ParseOptions(char *szOptions) options.fNoclip = true; } else if (!Q_strcasecmp(szTok, "hlbsp")) { - options.BSPVersion = BSPHLVERSION; + options.target_version = &bspver_hl; } else if (!Q_strcasecmp(szTok, "bsp2")) { - options.BSPVersion = BSP2VERSION; + options.target_version = &bspver_bsp2; } else if (!Q_strcasecmp(szTok, "2psb")) { - options.BSPVersion = BSP2RMQVERSION; + options.target_version = &bspver_bsp2rmq; } else if (!Q_strcasecmp(szTok, "leakdist")) { szTok2 = GetTok(szTok + strlen(szTok) + 1, szEnd); if (!szTok2) @@ -951,6 +958,22 @@ ParseOptions(char *szOptions) } szTok = GetTok(szTok + strlen(szTok) + 1, szEnd); } + + // combine format flags + if (hexen2) { + if (options.target_version == &bspver_bsp2) { + options.target_version = &bspver_h2bsp2; + } else if (options.target_version == &bspver_bsp2rmq) { + options.target_version = &bspver_h2bsp2rmq; + } else { + options.target_version = &bspver_h2; + } + } + + // default to bspver_q1 + if (options.target_version == nullptr) { + options.target_version = &bspver_q1; + } } diff --git a/qbsp/wad.cc b/qbsp/wad.cc index 1e310a32..21fdeae8 100644 --- a/qbsp/wad.cc +++ b/qbsp/wad.cc @@ -80,7 +80,7 @@ WAD_LoadInfo(wad_t *wad, bool external) int w = LittleLong(miptex.width); int h = LittleLong(miptex.height); wad->lumps[i].size = sizeof(miptex) + (w>>0)*(h>>0) + (w>>1)*(h>>1) + (w>>2)*(h>>2) + (w>>3)*(h>>3); - if (options.BSPVersion == BSPHLVERSION) + if (options.target_version == &bspver_hl) wad->lumps[i].size += 2+3*256; //palette size+palette data wad->lumps[i].size = (wad->lumps[i].size+3) & ~3; //keep things aligned if we can. @@ -296,7 +296,7 @@ WAD_LoadLump(const wad_t *wad, const char *name, uint8_t *dest) memcpy(dest+out->offsets[2], data.data()+(in->offsets[2]), (in->width>>2)*(in->height>>2)); memcpy(dest+out->offsets[3], data.data()+(in->offsets[3]), (in->width>>3)*(in->height>>3)); - if (options.BSPVersion == BSPHLVERSION) + if (options.target_version == &bspver_hl) { //palette size. 256 in little endian. dest[palofs+0] = ((256>>0)&0xff); dest[palofs+1] = ((256>>8)&0xff); @@ -329,7 +329,7 @@ WADList_AddAnimationFrames(const wad_t *wadlist) oldcount = map.nummiptex(); for (i = 0; i < oldcount; i++) { - if (map.miptex.at(i)[0] != '+' && (options.BSPVersion!=BSPHLVERSION||map.miptex.at(i)[0] != '-')) + if (map.miptex.at(i)[0] != '+' && (options.target_version != &bspver_hl || map.miptex.at(i)[0] != '-')) continue; std::string name = map.miptex.at(i); diff --git a/qbsp/writebsp.cc b/qbsp/writebsp.cc index c0d87341..2eff1a6f 100644 --- a/qbsp/writebsp.cc +++ b/qbsp/writebsp.cc @@ -442,7 +442,7 @@ WriteBSPFile() //GenLump("LMSHIFT", BSPX_LMSHIFT, 1); - ConvertBSPFormat(&bspdata, &bspver_q1); // assume q1 for now + ConvertBSPFormat(&bspdata, options.target_version); StripExtension(options.szBSPName); strcat(options.szBSPName, ".bsp");