From 208a9610ad15a7b4f0670806ab6ef230d809a6f9 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Tue, 24 Aug 2021 22:21:30 -0600 Subject: [PATCH] qbsp: delete bspfile.cc/hh --- CMakeLists.txt | 2 - include/qbsp/bspfile.hh | 35 ------------ include/qbsp/qbsp.hh | 3 +- qbsp/bspfile.cc | 119 ---------------------------------------- qbsp/qbsp.cc | 8 +-- qbsp/writebsp.cc | 67 +++++++++++++++++++++- 6 files changed, 72 insertions(+), 162 deletions(-) delete mode 100644 include/qbsp/bspfile.hh delete mode 100644 qbsp/bspfile.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index dd0b95f1..71f876af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,6 @@ set(COMMON_INCLUDES ${CMAKE_SOURCE_DIR}/include/common/bsputils.hh) set(QBSP_INCLUDES - ${CMAKE_SOURCE_DIR}/include/qbsp/bspfile.hh ${CMAKE_SOURCE_DIR}/include/qbsp/file.hh ${CMAKE_SOURCE_DIR}/include/qbsp/parser.hh ${CMAKE_SOURCE_DIR}/include/qbsp/qbsp.hh @@ -67,7 +66,6 @@ set(QBSP_SOURCES ${CMAKE_SOURCE_DIR}/common/polylib.cc ${CMAKE_SOURCE_DIR}/common/bsputils.cc ${CMAKE_SOURCE_DIR}/qbsp/brush.cc - ${CMAKE_SOURCE_DIR}/qbsp/bspfile.cc ${CMAKE_SOURCE_DIR}/qbsp/csg4.cc ${CMAKE_SOURCE_DIR}/qbsp/file.cc ${CMAKE_SOURCE_DIR}/qbsp/globals.cc diff --git a/include/qbsp/bspfile.hh b/include/qbsp/bspfile.hh deleted file mode 100644 index 4bc8b779..00000000 --- a/include/qbsp/bspfile.hh +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright (C) 1996-1997 Id Software, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - See file, 'COPYING', for details. -*/ - -#ifndef __BSPFILE_H__ -#define __BSPFILE_H__ - -#include - -#include - -#include - -void LoadBSPFile(void); -void WriteBSPFile(void); -void PrintBSPFileSizes(void); -void BSPX_AddLump(const char *xname, const void *xdata, size_t xsize); - -#endif /* __BSPFILE_H__ */ diff --git a/include/qbsp/qbsp.hh b/include/qbsp/qbsp.hh index f2aa57ec..41e63ca1 100644 --- a/include/qbsp/qbsp.hh +++ b/include/qbsp/qbsp.hh @@ -38,7 +38,8 @@ #include #include -#include "bspfile.hh" +#include + #include "file.hh" #include "warnerr.hh" diff --git a/qbsp/bspfile.cc b/qbsp/bspfile.cc deleted file mode 100644 index 31369ff8..00000000 --- a/qbsp/bspfile.cc +++ /dev/null @@ -1,119 +0,0 @@ -/* - Copyright (C) 1996-1997 Id Software, Inc. - Copyright (C) 1997 Greg Lewis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - See file, 'COPYING', for details. -*/ - -#include - -#include -#include - -static dheader_t *header; - -/* -============= -LoadBSPFile -============= -*/ -void -LoadBSPFile(void) -{ -} - -void BSPX_AddLump(const char *xname, const void *xdata, size_t xsize) -{ -} - -template -static void CopyVector(const std::vector& vec, int* elementCountOut, C** arrayCopyOut) -{ - const size_t numBytes = sizeof(C) * vec.size(); - void* data = (void*)malloc(numBytes); - memcpy(data, vec.data(), numBytes); - - *elementCountOut = vec.size(); - *arrayCopyOut = (C*)data; -} - -static void CopyString(const std::string& string, bool addNullTermination, int* elementCountOut, void** arrayCopyOut) -{ - const size_t numBytes = addNullTermination ? string.size() + 1 : string.size(); - void* data = malloc(numBytes); - memcpy(data, string.data(), numBytes); // std::string::data() has null termination, so it's safe to copy it - - *elementCountOut = numBytes; - *arrayCopyOut = data; -} - -/* -============= -WriteBSPFile -============= -*/ -void -WriteBSPFile(void) -{ - bspdata_t bspdata{}; - - bspdata.version = &bspver_generic; - bspdata.hullcount = MAX_MAP_HULLS_Q1; - - CopyVector(map.exported_planes, &bspdata.data.mbsp.numplanes, &bspdata.data.mbsp.dplanes); - CopyVector(map.exported_leafs_bsp29, &bspdata.data.mbsp.numleafs, &bspdata.data.mbsp.dleafs); - CopyVector(map.exported_vertexes, &bspdata.data.mbsp.numvertexes, &bspdata.data.mbsp.dvertexes); - CopyVector(map.exported_nodes_bsp29, &bspdata.data.mbsp.numnodes, &bspdata.data.mbsp.dnodes); - CopyVector(map.exported_texinfos, &bspdata.data.mbsp.numtexinfo, &bspdata.data.mbsp.texinfo); - CopyVector(map.exported_faces, &bspdata.data.mbsp.numfaces, &bspdata.data.mbsp.dfaces); - CopyVector(map.exported_clipnodes, &bspdata.data.mbsp.numclipnodes, &bspdata.data.mbsp.dclipnodes); - CopyVector(map.exported_marksurfaces, &bspdata.data.mbsp.numleaffaces, &bspdata.data.mbsp.dleaffaces); - CopyVector(map.exported_surfedges, &bspdata.data.mbsp.numsurfedges, &bspdata.data.mbsp.dsurfedges); - CopyVector(map.exported_edges, &bspdata.data.mbsp.numedges, &bspdata.data.mbsp.dedges); - CopyVector(map.exported_models, &bspdata.data.mbsp.nummodels, &bspdata.data.mbsp.dmodels); - - CopyString(map.exported_entities, true, &bspdata.data.mbsp.entdatasize, (void**)&bspdata.data.mbsp.dentdata); - CopyString(map.exported_texdata, false, &bspdata.data.mbsp.texdatasize, (void**)&bspdata.data.mbsp.dtexdata); - - // TODO: pass bspx lumps to generic bsp code so they are written - - //GenLump("LMSHIFT", BSPX_LMSHIFT, 1); - - ConvertBSPFormat(&bspdata, &bspver_q1); // assume q1 for now - - StripExtension(options.szBSPName); - strcat(options.szBSPName, ".bsp"); - - WriteBSPFile(options.szBSPName, &bspdata); - logprint("Wrote %s\n", options.szBSPName); - - PrintBSPFileSizes(&bspdata); -} - -//============================================================================ - -/* -============= -PrintBSPFileSizes - -Dumps info about current file -============= -*/ -void -PrintBSPFileSizes(void) -{ -} diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index 5dfae11b..a335182e 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -302,9 +302,9 @@ UpdateEntLump(void) FixRotateOrigin(entity); } - LoadBSPFile(); - WriteEntitiesToString(); - WriteBSPFile(); + //LoadBSPFile(); // FIXME: fix -onlyents + WriteEntitiesToString(); + //WriteBSPFile(); // FIXME: fix -onlyents if (!options.fAllverbose) options.fVerbose = false; @@ -317,7 +317,7 @@ This lump replaces the clipnodes stuff for custom collision sizes. */ void BSPX_Brushes_Finalize(struct bspxbrushes_s *ctx) { - BSPX_AddLump("BRUSHLIST", ctx->lumpinfo, ctx->lumpsize); + //BSPX_AddLump("BRUSHLIST", ctx->lumpinfo, ctx->lumpsize); // FIXME: fix bspx // free(ctx->lumpinfo); } diff --git a/qbsp/writebsp.cc b/qbsp/writebsp.cc index 4651da66..27533663 100644 --- a/qbsp/writebsp.cc +++ b/qbsp/writebsp.cc @@ -394,6 +394,72 @@ WriteExtendedTexinfoFlags(void) fclose(texinfofile); } +template +static void +CopyVector(const std::vector& vec, int* elementCountOut, C** arrayCopyOut) +{ + const size_t numBytes = sizeof(C) * vec.size(); + void* data = (void*)malloc(numBytes); + memcpy(data, vec.data(), numBytes); + + *elementCountOut = vec.size(); + *arrayCopyOut = (C*)data; +} + +static void +CopyString(const std::string& string, bool addNullTermination, int* elementCountOut, void** arrayCopyOut) +{ + const size_t numBytes = addNullTermination ? string.size() + 1 : string.size(); + void* data = malloc(numBytes); + memcpy(data, string.data(), numBytes); // std::string::data() has null termination, so it's safe to copy it + + *elementCountOut = numBytes; + *arrayCopyOut = data; +} + +/* +============= +WriteBSPFile +============= +*/ +static void +WriteBSPFile() +{ + bspdata_t bspdata{}; + + bspdata.version = &bspver_generic; + bspdata.hullcount = MAX_MAP_HULLS_Q1; + + CopyVector(map.exported_planes, &bspdata.data.mbsp.numplanes, &bspdata.data.mbsp.dplanes); + CopyVector(map.exported_leafs_bsp29, &bspdata.data.mbsp.numleafs, &bspdata.data.mbsp.dleafs); + CopyVector(map.exported_vertexes, &bspdata.data.mbsp.numvertexes, &bspdata.data.mbsp.dvertexes); + CopyVector(map.exported_nodes_bsp29, &bspdata.data.mbsp.numnodes, &bspdata.data.mbsp.dnodes); + CopyVector(map.exported_texinfos, &bspdata.data.mbsp.numtexinfo, &bspdata.data.mbsp.texinfo); + CopyVector(map.exported_faces, &bspdata.data.mbsp.numfaces, &bspdata.data.mbsp.dfaces); + CopyVector(map.exported_clipnodes, &bspdata.data.mbsp.numclipnodes, &bspdata.data.mbsp.dclipnodes); + CopyVector(map.exported_marksurfaces, &bspdata.data.mbsp.numleaffaces, &bspdata.data.mbsp.dleaffaces); + CopyVector(map.exported_surfedges, &bspdata.data.mbsp.numsurfedges, &bspdata.data.mbsp.dsurfedges); + CopyVector(map.exported_edges, &bspdata.data.mbsp.numedges, &bspdata.data.mbsp.dedges); + CopyVector(map.exported_models, &bspdata.data.mbsp.nummodels, &bspdata.data.mbsp.dmodels); + + CopyString(map.exported_entities, true, &bspdata.data.mbsp.entdatasize, (void**)&bspdata.data.mbsp.dentdata); + CopyString(map.exported_texdata, false, &bspdata.data.mbsp.texdatasize, (void**)&bspdata.data.mbsp.dtexdata); + + // TODO: pass bspx lumps to generic bsp code so they are written + + //GenLump("LMSHIFT", BSPX_LMSHIFT, 1); + + ConvertBSPFormat(&bspdata, &bspver_q1); // assume q1 for now + + StripExtension(options.szBSPName); + strcat(options.szBSPName, ".bsp"); + + WriteBSPFile(options.szBSPName, &bspdata); + logprint("Wrote %s\n", options.szBSPName); + + PrintBSPFileSizes(&bspdata); +} + /* ================== FinishBSPFile @@ -407,7 +473,6 @@ FinishBSPFile(void) WriteExtendedTexinfoFlags(); WriteBSPFile(); - PrintBSPFileSizes(); options.fVerbose = options.fAllverbose; }