From c34d958d7a8bb3d5a20670869cc5c678a50a9ee9 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Thu, 20 Apr 2017 19:44:10 -0600 Subject: [PATCH] qbsp: split up qbsp.hh --- include/qbsp/brush.hh | 43 +++++ include/qbsp/cmdlib.hh | 35 ++++ include/qbsp/csg4.hh | 33 ++++ include/qbsp/map.hh | 146 +++++++++++++++ include/qbsp/mathlib.hh | 109 +++++++++++ include/qbsp/merge.hh | 30 +++ include/qbsp/outside.hh | 27 +++ include/qbsp/portals.hh | 36 ++++ include/qbsp/region.hh | 27 +++ include/qbsp/solidbsp.hh | 31 ++++ include/qbsp/surfaces.hh | 34 ++++ include/qbsp/tjunc.hh | 37 ++++ include/qbsp/util.hh | 50 +++++ include/qbsp/writebsp.hh | 30 +++ qbsp/CMakeLists.txt | 16 +- qbsp/qbsp.hh | 384 ++------------------------------------- 16 files changed, 697 insertions(+), 371 deletions(-) create mode 100644 include/qbsp/brush.hh create mode 100644 include/qbsp/cmdlib.hh create mode 100644 include/qbsp/csg4.hh create mode 100644 include/qbsp/map.hh create mode 100644 include/qbsp/mathlib.hh create mode 100644 include/qbsp/merge.hh create mode 100644 include/qbsp/outside.hh create mode 100644 include/qbsp/portals.hh create mode 100644 include/qbsp/region.hh create mode 100644 include/qbsp/solidbsp.hh create mode 100644 include/qbsp/surfaces.hh create mode 100644 include/qbsp/tjunc.hh create mode 100644 include/qbsp/util.hh create mode 100644 include/qbsp/writebsp.hh diff --git a/include/qbsp/brush.hh b/include/qbsp/brush.hh new file mode 100644 index 00000000..5f90dc72 --- /dev/null +++ b/include/qbsp/brush.hh @@ -0,0 +1,43 @@ +/* + 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. +*/ + +#ifndef QBSP_BRUSH_HH +#define QBSP_BRUSH_HH + +typedef struct brush_s { + struct brush_s *next; + vec3_t mins, maxs; + face_t *faces; + short contents; /* BSP contents */ + short cflags; /* Compiler internal contents flags */ + short lmshift; /* lightmap scaling (qu/lightmap pixel), passed to the light util */ +} brush_t; + +class mapbrush_t; + +brush_t *LoadBrush(const mapbrush_t *mapbrush, const vec3_t rotate_offset, const int hullnum); +void FreeBrushes(brush_t *brushlist); + +int FindPlane(const plane_t *plane, int *side); +int PlaneEqual(const plane_t *p1, const plane_t *p2); +int PlaneInvEqual(const plane_t *p1, const plane_t *p2); + +#endif diff --git a/include/qbsp/cmdlib.hh b/include/qbsp/cmdlib.hh new file mode 100644 index 00000000..f7af899e --- /dev/null +++ b/include/qbsp/cmdlib.hh @@ -0,0 +1,35 @@ +/* + 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. +*/ + +#ifndef QBSP_CMDLIB_HH +#define QBSP_CMDLIB_HH + +double I_FloatTime(void); + +void DefaultExtension(char *path, const char *extension); +void StripExtension(char *path); +void StripFilename(char *path); +int IsAbsolutePath(const char *path); +int Q_strcasecmp(const char *s1, const char *s2); +int Q_strncasecmp(const char *s1, const char *s2, int n); +char *copystring(const char *s); + +#endif diff --git a/include/qbsp/csg4.hh b/include/qbsp/csg4.hh new file mode 100644 index 00000000..36b91b72 --- /dev/null +++ b/include/qbsp/csg4.hh @@ -0,0 +1,33 @@ +/* + 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. +*/ + +#ifndef QBSP_CSG4_HH +#define QBSP_CSG4_HH + +extern int csgmergefaces; + +// build surfaces is also used by GatherNodeFaces +surface_t *BuildSurfaces(const std::map &planefaces); +face_t *NewFaceFromFace(face_t *in); +void SplitFace(face_t *in, const plane_t *split, face_t **front, face_t **back); +void UpdateFaceSphere(face_t *in); + +#endif diff --git a/include/qbsp/map.hh b/include/qbsp/map.hh new file mode 100644 index 00000000..143cf8e4 --- /dev/null +++ b/include/qbsp/map.hh @@ -0,0 +1,146 @@ +/* + 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. +*/ + +#ifndef QBSP_MAP_HH +#define QBSP_MAP_HH + +typedef struct epair_s { + struct epair_s *next; + char *key; + char *value; +} epair_t; + +typedef struct mapface_s { + plane_t plane; + vec3_t planepts[3]; + std::string texname; + int texinfo; + int linenum; +} mapface_t; + +enum class brushformat_t { + NORMAL, BRUSH_PRIMITIVES +}; + +class mapbrush_t { +public: + int firstface; + int numfaces; + brushformat_t format; + + mapbrush_t() : firstface(0), numfaces(0), format(brushformat_t::NORMAL) {} + const mapface_t &face(int i) const; +} ; + +struct lumpdata { + int count; + int index; + void *data; +}; + +typedef struct mapentity_s { + vec3_t origin; + + int firstmapbrush; + int nummapbrushes; + + epair_t *epairs; + vec3_t mins, maxs; + brush_t *brushes; /* NULL terminated list */ + int numbrushes; + struct lumpdata lumps[BSPX_LUMPS]; + + const mapbrush_t &mapbrush(int i) const; +} mapentity_t; + +typedef struct mapdata_s { + /* Arrays of actual items */ + std::vector faces; + std::vector brushes; + std::vector entities; + std::vector planes; + std::vector miptex; + std::vector mtexinfos; + + /* map from plane hash code to list of indicies in `planes` vector */ + std::unordered_map> planehash; + + /* Number of items currently used */ + int numfaces() const { return faces.size(); }; + int numbrushes() const { return brushes.size(); }; + int numentities() const { return entities.size(); }; + int numplanes() const { return planes.size(); }; + int nummiptex() const { return miptex.size(); }; + int numtexinfo() const { return static_cast(mtexinfos.size()); }; + + /* Totals for BSP data items -> TODO: move to a bspdata struct? */ + int cTotal[BSPX_LUMPS]; + + /* Misc other global state for the compile process */ + int fillmark; /* For marking leaves while outside filling */ + bool leakfile; /* Flag once we've written a leak (.por/.pts) file */ +} mapdata_t; + +extern mapdata_t map; +extern mapentity_t *pWorldEnt(); + +void EnsureTexturesLoaded(); +void LoadMapFile(void); +void ConvertMapFile(void); + +int FindMiptex(const char *name); +int FindTexinfo(mtexinfo_t *texinfo, uint64_t flags); //FIXME: Make this take const texinfo +int FindTexinfoEnt(mtexinfo_t *texinfo, mapentity_t *entity); //FIXME: Make this take const texinfo + +void PrintEntity(const mapentity_t *entity); +const char *ValueForKey(const mapentity_t *entity, const char *key); +void SetKeyValue(mapentity_t *entity, const char *key, const char *value); +void GetVectorForKey(const mapentity_t *entity, const char *szKey, vec3_t vec); + +void WriteEntitiesToString(void); + +void FixRotateOrigin(mapentity_t *entity); + +/* Create BSP brushes from map brushes in src and save into dst */ +void Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, + const int hullnum); + +surface_t *CSGFaces(const mapentity_t *entity); +int PortalizeWorld(const mapentity_t *entity, node_t *headnode, const int hullnum); +void TJunc(const mapentity_t *entity, node_t *headnode); +node_t *SolidBSP(const mapentity_t *entity, surface_t *surfhead, bool midsplit); +int MakeFaceEdges(mapentity_t *entity, node_t *headnode); +void ExportClipNodes(mapentity_t *entity, node_t *headnode, const int hullnum); +void ExportDrawNodes(mapentity_t *entity, node_t *headnode, int firstface); + +struct bspxbrushes_s +{ + byte *lumpinfo; + size_t lumpsize; + size_t lumpmaxsize; +}; +void BSPX_Brushes_Finalize(struct bspxbrushes_s *ctx); +void BSPX_Brushes_Init(struct bspxbrushes_s *ctx); +void BSPX_Brushes_AddModel(struct bspxbrushes_s *ctx, int modelnum, brush_t *brushes); + +void ExportObj(const surface_t *surfaces); + +#endif diff --git a/include/qbsp/mathlib.hh b/include/qbsp/mathlib.hh new file mode 100644 index 00000000..2abca6ff --- /dev/null +++ b/include/qbsp/mathlib.hh @@ -0,0 +1,109 @@ +/* + 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. +*/ + +#ifndef QBSP_MATHLIB_HH +#define QBSP_MATHLIB_HH + +#ifdef DOUBLEVEC_T +#define vec_t double +#define VECT_MAX DBL_MAX +#else +#define vec_t float +#define VECT_MAX FLT_MAX +#endif +typedef vec_t vec3_t[3]; + +extern const vec3_t vec3_origin; + +bool VectorCompare(const vec3_t v1, const vec3_t v2); + +vec_t Q_rint(vec_t in); +extern vec_t DotProduct(const vec3_t v1, const vec3_t v2); +extern void VectorSubtract(const vec3_t va, const vec3_t vb, vec3_t out); +extern void VectorAdd(const vec3_t va, const vec3_t vb, vec3_t out); +extern void VectorCopy(const vec3_t in, vec3_t out); + +vec_t VectorLengthSq(const vec3_t v); +vec_t VectorLength(const vec3_t v); + +void VectorMA(const vec3_t va, const double scale, const vec3_t vb, vec3_t vc); + +void CrossProduct(const vec3_t v1, const vec3_t v2, vec3_t cross); +vec_t VectorNormalize(vec3_t v); +void VectorInverse(vec3_t v); +void VectorScale(const vec3_t v, const vec_t scale, vec3_t out); + +float SignedDegreesBetweenUnitVectors(const vec3_t start, const vec3_t end, const vec3_t normal); + +#ifdef __GNUC__ +/* min and max macros with type checking */ +#define qmax(a,b) ({ \ + typeof(a) a_ = (a); \ + typeof(b) b_ = (b); \ + (void)(&a_ == &b_); \ + (a_ > b_) ? a_ : b_; \ +}) +#define qmin(a,b) ({ \ + typeof(a) a_ = (a); \ + typeof(b) b_ = (b); \ + (void)(&a_ == &b_); \ + (a_ < b_) ? a_ : b_; \ +}) +#else +#define qmax(a,b) (((a)>(b)) ? (a) : (b)) +#define qmin(a,b) (((a)>(b)) ? (b) : (a)) +#endif + +#define stringify__(x) #x +#define stringify(x) stringify__(x) + +//====== bsp5.h + +typedef struct plane { + vec3_t normal; + vec_t dist; + int type; + struct plane *hash_chain; +} plane_t; + +//============================================================================ + + +typedef struct { + int numpoints; + vec3_t points[MAXEDGES]; // variable sized +} winding_t; + +winding_t *BaseWindingForPlane(const plane_t *p); +void CheckWinding(const winding_t *w); +winding_t *NewWinding(int points); +void FreeWinding(winding_t *w); +winding_t *CopyWinding(const winding_t *w); +winding_t *ClipWinding(winding_t *in, const plane_t *split, bool keepon); +void DivideWinding(winding_t *in, const plane_t *split, winding_t **front, + winding_t **back); +void MidpointWinding(const winding_t *w, vec3_t v); + +/* Helper function for ClipWinding and it's variants */ +void CalcSides(const winding_t *in, const plane_t *split, int *sides, + vec_t *dists, int counts[3]); + +#endif diff --git a/include/qbsp/merge.hh b/include/qbsp/merge.hh new file mode 100644 index 00000000..3081d8b0 --- /dev/null +++ b/include/qbsp/merge.hh @@ -0,0 +1,30 @@ +/* + 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. +*/ + +#ifndef QBSP_MERGE_HH +#define QBSP_MERGE_HH + +void MergePlaneFaces(surface_t *plane); +face_t *MergeFaceToList(face_t *face, face_t *list); +face_t *FreeMergeListScraps(face_t *merged); +void MergeAll(surface_t *surfhead); + +#endif diff --git a/include/qbsp/outside.hh b/include/qbsp/outside.hh new file mode 100644 index 00000000..046371dc --- /dev/null +++ b/include/qbsp/outside.hh @@ -0,0 +1,27 @@ +/* + 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. +*/ + +#ifndef QBSP_OUTSIDE_HH +#define QBSP_OUTSIDE_HH + +bool FillOutside(node_t *node, const int hullnum, const int numportals); + +#endif diff --git a/include/qbsp/portals.hh b/include/qbsp/portals.hh new file mode 100644 index 00000000..ebb9f7a4 --- /dev/null +++ b/include/qbsp/portals.hh @@ -0,0 +1,36 @@ +/* + 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. +*/ + +#ifndef QBSP_PORTALS_HH +#define QBSP_PORTALS_HH + +typedef struct portal_s { + int planenum; + node_t *nodes[2]; // [0] = front side of planenum + struct portal_s *next[2]; + winding_t *winding; +} portal_t; + +extern node_t outside_node; // portals outside the world face this + +void FreeAllPortals(node_t *node); + +#endif diff --git a/include/qbsp/region.hh b/include/qbsp/region.hh new file mode 100644 index 00000000..62dc5ee3 --- /dev/null +++ b/include/qbsp/region.hh @@ -0,0 +1,27 @@ +/* + 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. +*/ + +#ifndef QBSP_REGION_HH +#define QBSP_REGION_HH + +void GrowNodeRegions(node_t *headnode); + +#endif diff --git a/include/qbsp/solidbsp.hh b/include/qbsp/solidbsp.hh new file mode 100644 index 00000000..bd603592 --- /dev/null +++ b/include/qbsp/solidbsp.hh @@ -0,0 +1,31 @@ +/* + 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. +*/ + +#ifndef QBSP_SOLIDBSP_HH +#define QBSP_SOLIDBSP_HH + +extern int splitnodes; + +void DivideFacet(face_t *in, plane_t *split, face_t **front, face_t **back); +void CalcSurfaceInfo(surface_t *surf); +void SubdivideFace(face_t *f, face_t **prevptr); + +#endif diff --git a/include/qbsp/surfaces.hh b/include/qbsp/surfaces.hh new file mode 100644 index 00000000..46d67508 --- /dev/null +++ b/include/qbsp/surfaces.hh @@ -0,0 +1,34 @@ +/* + 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. +*/ + +#ifndef QBSP_SURFACES_HH +#define QBSP_SURFACES_HH + +typedef struct hashvert_s { + struct hashvert_s *next; + vec3_t point; + int num; + int numedges; +} hashvert_t; + +surface_t *GatherNodeFaces(node_t *headnode); + +#endif diff --git a/include/qbsp/tjunc.hh b/include/qbsp/tjunc.hh new file mode 100644 index 00000000..0df73e82 --- /dev/null +++ b/include/qbsp/tjunc.hh @@ -0,0 +1,37 @@ +/* + 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. +*/ + +#ifndef QBSP_TJUNC_HH +#define QBSP_TJUNC_HH + +typedef struct wvert_s { + vec_t t; /* t-value for parametric equation of edge */ + struct wvert_s *prev, *next; /* t-ordered list of vertices on same edge */ +} wvert_t; + +typedef struct wedge_s { + struct wedge_s *next; /* pointer for hash bucket chain */ + vec3_t dir; /* direction vector for the edge */ + vec3_t origin; /* origin (t = 0) in parametric form */ + wvert_t head; /* linked list of verticies on this edge */ +} wedge_t; + +#endif diff --git a/include/qbsp/util.hh b/include/qbsp/util.hh new file mode 100644 index 00000000..61a96734 --- /dev/null +++ b/include/qbsp/util.hh @@ -0,0 +1,50 @@ +/* + 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. +*/ + +#ifndef QBSP_UTIL_HH +#define QBSP_UTIL_HH + +#define msgWarning 1 +#define msgStat 2 +#define msgProgress 3 +#define msgLiteral 4 +#define msgFile 5 +#define msgScreen 6 +#define msgPercent 7 + +extern const char *rgszWarnings[cWarnings]; +extern const int *MemSize; +extern const int MemSize_BSP29[GLOBAL + 1]; +extern const int MemSize_BSP2rmq[GLOBAL + 1]; +extern const int MemSize_BSP2[GLOBAL + 1]; + +void *AllocMem(int Type, int cSize, bool fZero); +void FreeMem(void *pMem, int Type, int cSize); +void FreeAllMem(void); +void PrintMem(void); + +void Message(int MsgType, ...); +void Error(const char *error, ...) + __attribute__((format(printf,1,2),noreturn)); + +int q_snprintf(char *str, size_t size, const char *format, ...); + +#endif diff --git a/include/qbsp/writebsp.hh b/include/qbsp/writebsp.hh new file mode 100644 index 00000000..f302f978 --- /dev/null +++ b/include/qbsp/writebsp.hh @@ -0,0 +1,30 @@ +/* + 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. +*/ + +#ifndef QBSP_WRITEBSP_HH +#define QBSP_WRITEBSP_HH + +void ExportNodePlanes(node_t *headnode); + +void BeginBSPFile(void); +void FinishBSPFile(void); + +#endif diff --git a/qbsp/CMakeLists.txt b/qbsp/CMakeLists.txt index ed9b4619..137476e6 100644 --- a/qbsp/CMakeLists.txt +++ b/qbsp/CMakeLists.txt @@ -7,7 +7,21 @@ set(QBSP_INCLUDES parser.hh qbsp.hh wad.hh - warnerr.hh) + warnerr.hh + ${CMAKE_SOURCE_DIR}/include/qbsp/brush.hh + ${CMAKE_SOURCE_DIR}/include/qbsp/cmdlib.hh + ${CMAKE_SOURCE_DIR}/include/qbsp/csg4.hh + ${CMAKE_SOURCE_DIR}/include/qbsp/map.hh + ${CMAKE_SOURCE_DIR}/include/qbsp/mathlib.hh + ${CMAKE_SOURCE_DIR}/include/qbsp/merge.hh + ${CMAKE_SOURCE_DIR}/include/qbsp/outside.hh + ${CMAKE_SOURCE_DIR}/include/qbsp/portals.hh + ${CMAKE_SOURCE_DIR}/include/qbsp/region.hh + ${CMAKE_SOURCE_DIR}/include/qbsp/solidbsp.hh + ${CMAKE_SOURCE_DIR}/include/qbsp/surfaces.hh + ${CMAKE_SOURCE_DIR}/include/qbsp/tjunc.hh + ${CMAKE_SOURCE_DIR}/include/qbsp/util.hh + ${CMAKE_SOURCE_DIR}/include/qbsp/writebsp.hh) set(QBSP_SOURCES ${CMAKE_SOURCE_DIR}/common/threads.cc diff --git a/qbsp/qbsp.hh b/qbsp/qbsp.hh index e55a26a8..bb16d061 100644 --- a/qbsp/qbsp.hh +++ b/qbsp/qbsp.hh @@ -54,8 +54,6 @@ #define __attribute__(x) #endif -//===== cmdlib.h - /* * Clipnodes need to be stored as a 16-bit offset. Originally, this was a * signed value and only the positive values up to 32767 were available. Since @@ -194,104 +192,8 @@ enum { GLOBAL }; -double I_FloatTime(void); - -void DefaultExtension(char *path, const char *extension); -void StripExtension(char *path); -void StripFilename(char *path); -int IsAbsolutePath(const char *path); -int Q_strcasecmp(const char *s1, const char *s2); -int Q_strncasecmp(const char *s1, const char *s2, int n); -char *copystring(const char *s); - -//===== mathlib.h - -#ifdef DOUBLEVEC_T -#define vec_t double -#define VECT_MAX DBL_MAX -#else -#define vec_t float -#define VECT_MAX FLT_MAX -#endif -typedef vec_t vec3_t[3]; - -extern const vec3_t vec3_origin; - -bool VectorCompare(const vec3_t v1, const vec3_t v2); - -vec_t Q_rint(vec_t in); -extern vec_t DotProduct(const vec3_t v1, const vec3_t v2); -extern void VectorSubtract(const vec3_t va, const vec3_t vb, vec3_t out); -extern void VectorAdd(const vec3_t va, const vec3_t vb, vec3_t out); -extern void VectorCopy(const vec3_t in, vec3_t out); - -vec_t VectorLengthSq(const vec3_t v); -vec_t VectorLength(const vec3_t v); - -void VectorMA(const vec3_t va, const double scale, const vec3_t vb, vec3_t vc); - -void CrossProduct(const vec3_t v1, const vec3_t v2, vec3_t cross); -vec_t VectorNormalize(vec3_t v); -void VectorInverse(vec3_t v); -void VectorScale(const vec3_t v, const vec_t scale, vec3_t out); - -float SignedDegreesBetweenUnitVectors(const vec3_t start, const vec3_t end, const vec3_t normal); - -#ifdef __GNUC__ -/* min and max macros with type checking */ -#define qmax(a,b) ({ \ - typeof(a) a_ = (a); \ - typeof(b) b_ = (b); \ - (void)(&a_ == &b_); \ - (a_ > b_) ? a_ : b_; \ -}) -#define qmin(a,b) ({ \ - typeof(a) a_ = (a); \ - typeof(b) b_ = (b); \ - (void)(&a_ == &b_); \ - (a_ < b_) ? a_ : b_; \ -}) -#else -#define qmax(a,b) (((a)>(b)) ? (a) : (b)) -#define qmin(a,b) (((a)>(b)) ? (b) : (a)) -#endif - -#define stringify__(x) #x -#define stringify(x) stringify__(x) - -//====== bsp5.h - -typedef struct plane { - vec3_t normal; - vec_t dist; - int type; - struct plane *hash_chain; -} plane_t; - - -//============================================================================ - - -typedef struct { - int numpoints; - vec3_t points[MAXEDGES]; // variable sized -} winding_t; - -winding_t *BaseWindingForPlane(const plane_t *p); -void CheckWinding(const winding_t *w); -winding_t *NewWinding(int points); -void FreeWinding(winding_t *w); -winding_t *CopyWinding(const winding_t *w); -winding_t *ClipWinding(winding_t *in, const plane_t *split, bool keepon); -void DivideWinding(winding_t *in, const plane_t *split, winding_t **front, - winding_t **back); -void MidpointWinding(const winding_t *w, vec3_t v); - -/* Helper function for ClipWinding and it's variants */ -void CalcSides(const winding_t *in, const plane_t *split, int *sides, - vec_t *dists, int counts[3]); - -//============================================================================ +#include +#include typedef struct mtexinfo_s { float vecs[2][4]; /* [s/t][xyz offset] */ @@ -359,125 +261,16 @@ typedef struct node_s { bool detail_separator; // for vis portal generation } node_t; -//============================================================================= - -// brush.c - -typedef struct brush_s { - struct brush_s *next; - vec3_t mins, maxs; - face_t *faces; - short contents; /* BSP contents */ - short cflags; /* Compiler internal contents flags */ - short lmshift; /* lightmap scaling (qu/lightmap pixel), passed to the light util */ -} brush_t; - -class mapbrush_t; - -brush_t *LoadBrush(const mapbrush_t *mapbrush, const vec3_t rotate_offset, const int hullnum); -void FreeBrushes(brush_t *brushlist); - -int FindPlane(const plane_t *plane, int *side); -int PlaneEqual(const plane_t *p1, const plane_t *p2); -int PlaneInvEqual(const plane_t *p1, const plane_t *p2); - -//============================================================================= - -// csg4.c - -extern int csgmergefaces; - -// build surfaces is also used by GatherNodeFaces -surface_t *BuildSurfaces(const std::map &planefaces); -face_t *NewFaceFromFace(face_t *in); -void SplitFace(face_t *in, const plane_t *split, face_t **front, face_t **back); -void UpdateFaceSphere(face_t *in); - -//============================================================================= - -// solidbsp.c - -extern int splitnodes; - -void DivideFacet(face_t *in, plane_t *split, face_t **front, face_t **back); -void CalcSurfaceInfo(surface_t *surf); -void SubdivideFace(face_t *f, face_t **prevptr); - -//============================================================================= - -// merge.c - -void MergePlaneFaces(surface_t *plane); -face_t *MergeFaceToList(face_t *face, face_t *list); -face_t *FreeMergeListScraps(face_t *merged); -void MergeAll(surface_t *surfhead); - -//============================================================================= - -// surfaces.c - -typedef struct hashvert_s { - struct hashvert_s *next; - vec3_t point; - int num; - int numedges; -} hashvert_t; - -surface_t *GatherNodeFaces(node_t *headnode); - -//============================================================================= - -// portals.c - -typedef struct portal_s { - int planenum; - node_t *nodes[2]; // [0] = front side of planenum - struct portal_s *next[2]; - winding_t *winding; -} portal_t; - -extern node_t outside_node; // portals outside the world face this - -void FreeAllPortals(node_t *node); - -//============================================================================= - -// region.c - -void GrowNodeRegions(node_t *headnode); - -//============================================================================= - -// tjunc.c - -typedef struct wvert_s { - vec_t t; /* t-value for parametric equation of edge */ - struct wvert_s *prev, *next; /* t-ordered list of vertices on same edge */ -} wvert_t; - -typedef struct wedge_s { - struct wedge_s *next; /* pointer for hash bucket chain */ - vec3_t dir; /* direction vector for the edge */ - vec3_t origin; /* origin (t = 0) in parametric form */ - wvert_t head; /* linked list of verticies on this edge */ -} wedge_t; - -//============================================================================= - -// writebsp.c - -void ExportNodePlanes(node_t *headnode); - -void BeginBSPFile(void); -void FinishBSPFile(void); - -//============================================================================= - -// outside.c - -bool FillOutside(node_t *node, const int hullnum, const int numportals); - -//============================================================================= +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include typedef enum { TX_QUAKED = 0, @@ -529,156 +322,7 @@ typedef struct options_s { extern options_t options; -//============================================================================= - -// map.c - -typedef struct epair_s { - struct epair_s *next; - char *key; - char *value; -} epair_t; - -typedef struct mapface_s { - plane_t plane; - vec3_t planepts[3]; - std::string texname; - int texinfo; - int linenum; -} mapface_t; - -enum class brushformat_t { - NORMAL, BRUSH_PRIMITIVES -}; - -class mapbrush_t { -public: - int firstface; - int numfaces; - brushformat_t format; - - mapbrush_t() : firstface(0), numfaces(0), format(brushformat_t::NORMAL) {} - const mapface_t &face(int i) const; -} ; - -struct lumpdata { - int count; - int index; - void *data; -}; - -typedef struct mapentity_s { - vec3_t origin; - - int firstmapbrush; - int nummapbrushes; - - epair_t *epairs; - vec3_t mins, maxs; - brush_t *brushes; /* NULL terminated list */ - int numbrushes; - struct lumpdata lumps[BSPX_LUMPS]; - - const mapbrush_t &mapbrush(int i) const; -} mapentity_t; - -typedef struct mapdata_s { - /* Arrays of actual items */ - std::vector faces; - std::vector brushes; - std::vector entities; - std::vector planes; - std::vector miptex; - std::vector mtexinfos; - - /* map from plane hash code to list of indicies in `planes` vector */ - std::unordered_map> planehash; - - /* Number of items currently used */ - int numfaces() const { return faces.size(); }; - int numbrushes() const { return brushes.size(); }; - int numentities() const { return entities.size(); }; - int numplanes() const { return planes.size(); }; - int nummiptex() const { return miptex.size(); }; - int numtexinfo() const { return static_cast(mtexinfos.size()); }; - - /* Totals for BSP data items -> TODO: move to a bspdata struct? */ - int cTotal[BSPX_LUMPS]; - - /* Misc other global state for the compile process */ - int fillmark; /* For marking leaves while outside filling */ - bool leakfile; /* Flag once we've written a leak (.por/.pts) file */ -} mapdata_t; - -extern mapdata_t map; -extern mapentity_t *pWorldEnt(); - -void EnsureTexturesLoaded(); -void LoadMapFile(void); -void ConvertMapFile(void); - -int FindMiptex(const char *name); -int FindTexinfo(mtexinfo_t *texinfo, uint64_t flags); //FIXME: Make this take const texinfo -int FindTexinfoEnt(mtexinfo_t *texinfo, mapentity_t *entity); //FIXME: Make this take const texinfo - -void PrintEntity(const mapentity_t *entity); -const char *ValueForKey(const mapentity_t *entity, const char *key); -void SetKeyValue(mapentity_t *entity, const char *key, const char *value); -void GetVectorForKey(const mapentity_t *entity, const char *szKey, vec3_t vec); - -void WriteEntitiesToString(void); - -void FixRotateOrigin(mapentity_t *entity); - -/* Create BSP brushes from map brushes in src and save into dst */ -void Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, - const int hullnum); - -surface_t *CSGFaces(const mapentity_t *entity); -int PortalizeWorld(const mapentity_t *entity, node_t *headnode, const int hullnum); -void TJunc(const mapentity_t *entity, node_t *headnode); -node_t *SolidBSP(const mapentity_t *entity, surface_t *surfhead, bool midsplit); -int MakeFaceEdges(mapentity_t *entity, node_t *headnode); -void ExportClipNodes(mapentity_t *entity, node_t *headnode, const int hullnum); -void ExportDrawNodes(mapentity_t *entity, node_t *headnode, int firstface); - -struct bspxbrushes_s -{ - byte *lumpinfo; - size_t lumpsize; - size_t lumpmaxsize; -}; -void BSPX_Brushes_Finalize(struct bspxbrushes_s *ctx); -void BSPX_Brushes_Init(struct bspxbrushes_s *ctx); -void BSPX_Brushes_AddModel(struct bspxbrushes_s *ctx, int modelnum, brush_t *brushes); - -void ExportObj(const surface_t *surfaces); - -// util.c - -#define msgWarning 1 -#define msgStat 2 -#define msgProgress 3 -#define msgLiteral 4 -#define msgFile 5 -#define msgScreen 6 -#define msgPercent 7 - -extern const char *rgszWarnings[cWarnings]; -extern const int *MemSize; -extern const int MemSize_BSP29[GLOBAL + 1]; -extern const int MemSize_BSP2rmq[GLOBAL + 1]; -extern const int MemSize_BSP2[GLOBAL + 1]; - -void *AllocMem(int Type, int cSize, bool fZero); -void FreeMem(void *pMem, int Type, int cSize); -void FreeAllMem(void); -void PrintMem(void); - -void Message(int MsgType, ...); -void Error(const char *error, ...) - __attribute__((format(printf,1,2),noreturn)); - -int q_snprintf(char *str, size_t size, const char *format, ...); +#include +#include #endif