qbsp: split up qbsp.hh

This commit is contained in:
Eric Wasylishen 2017-04-20 19:44:10 -06:00
parent f4c9b6c1a7
commit c34d958d7a
16 changed files with 697 additions and 371 deletions

43
include/qbsp/brush.hh Normal file
View File

@ -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

35
include/qbsp/cmdlib.hh Normal file
View File

@ -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

33
include/qbsp/csg4.hh Normal file
View File

@ -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<int, face_t *> &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

146
include/qbsp/map.hh Normal file
View File

@ -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<mapface_t> faces;
std::vector<mapbrush_t> brushes;
std::vector<mapentity_t> entities;
std::vector<plane_t> planes;
std::vector<miptex_t> miptex;
std::vector<mtexinfo_t> mtexinfos;
/* map from plane hash code to list of indicies in `planes` vector */
std::unordered_map<int, std::vector<int>> 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<int>(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

109
include/qbsp/mathlib.hh Normal file
View File

@ -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

30
include/qbsp/merge.hh Normal file
View File

@ -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

27
include/qbsp/outside.hh Normal file
View File

@ -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

36
include/qbsp/portals.hh Normal file
View File

@ -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

27
include/qbsp/region.hh Normal file
View File

@ -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

31
include/qbsp/solidbsp.hh Normal file
View File

@ -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

34
include/qbsp/surfaces.hh Normal file
View File

@ -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

37
include/qbsp/tjunc.hh Normal file
View File

@ -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

50
include/qbsp/util.hh Normal file
View File

@ -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

30
include/qbsp/writebsp.hh Normal file
View File

@ -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

View File

@ -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

View File

@ -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 <qbsp/cmdlib.hh>
#include <qbsp/mathlib.hh>
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<int, face_t *> &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 <qbsp/brush.hh>
#include <qbsp/csg4.hh>
#include <qbsp/solidbsp.hh>
#include <qbsp/merge.hh>
#include <qbsp/surfaces.hh>
#include <qbsp/portals.hh>
#include <qbsp/region.hh>
#include <qbsp/tjunc.hh>
#include <qbsp/writebsp.hh>
#include <qbsp/outside.hh>
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<mapface_t> faces;
std::vector<mapbrush_t> brushes;
std::vector<mapentity_t> entities;
std::vector<plane_t> planes;
std::vector<miptex_t> miptex;
std::vector<mtexinfo_t> mtexinfos;
/* map from plane hash code to list of indicies in `planes` vector */
std::unordered_map<int, std::vector<int>> 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<int>(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 <qbsp/map.hh>
#include <qbsp/util.hh>
#endif