split up most of bsp5.h and get things compiling again

This commit is contained in:
Bill Currie 2010-08-18 17:52:13 +09:00
parent 4449f10c0a
commit a703956553
34 changed files with 922 additions and 450 deletions

View file

@ -36,7 +36,7 @@
typedef struct
{
vec3_t normal;
float dist;
vec_t dist;
} plane_t;
typedef struct trace_s {

View file

@ -1,3 +1,5 @@
AUTOMAKE_OPTIONS= foreign
EXTRA_DIST= bsp5.h map.h options.h
EXTRA_DIST= brush.h bsp5.h csg4.h draw.h map.h merge.h options.h outside.h \
portals.h readbsp.h region.h solidbsp.h surfaces.h tjunc.h \
winding.h writebsp.h

View file

@ -0,0 +1,54 @@
/*
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.
$Id$
*/
#ifndef qfbsp_brush_h
#define qfbsp_brush_h
#include "QF/mathlib.h"
#include "bsp5.h"
#include "map.h"
#define NUM_HULLS 2 // normal and +16
#define NUM_CONTENTS 2 // solid and water
typedef struct brush_s {
struct brush_s *next;
vec3_t mins, maxs;
struct visfacet_s *faces;
int contents;
} brush_t;
typedef struct brushset_s {
vec3_t mins, maxs;
brush_t *brushes; // NULL terminated list
} brushset_t;
extern int numbrushplanes;
extern plane_t planes[MAX_MAP_PLANES];
brushset_t *Brush_LoadEntity (entity_t *ent, int hullnum);
int PlaneTypeForNormal (vec3_t normal);
int FindPlane (plane_t *dplane, int *side);
#endif//qfbsp_brush_h

View file

@ -20,19 +20,18 @@
$Id$
*/
// bsp5.h
#ifndef qfbsp_bsp5_h
#define qfbsp_bsp5_h
#include "QF/mathlib.h"
#include "QF/bspfile.h"
typedef struct {
typedef struct plane_s {
vec3_t normal;
vec_t dist;
int type;
} plane_t;
#include "map.h"
#define MAX_THREADS 4
#define ON_EPSILON 0.05
@ -45,23 +44,6 @@ typedef struct {
#define TEX_SKIP -1
#define TEX_HINT -2
//============================================================================
typedef struct {
int numpoints;
vec3_t points[8]; // variable sized
} winding_t;
winding_t *BaseWindingForPlane (plane_t *p);
winding_t *NewWinding (int points);
void FreeWinding (winding_t *w);
winding_t *CopyWinding (winding_t *w);
winding_t *CopyWindingReverse (winding_t *w);
winding_t *ClipWinding (winding_t *in, plane_t *split, qboolean keepon);
void DivideWinding (winding_t *in, plane_t *split, winding_t **front, winding_t **back);
//============================================================================
typedef struct visfacet_s {
struct visfacet_s *next;
@ -75,7 +57,7 @@ typedef struct visfacet_s {
// write surfaces
qboolean detail; // is a detail face
winding_t *points;
struct winding_s *points;
int *edges;
} face_t;
@ -117,140 +99,10 @@ typedef struct node_s {
int detail; // 1 if created by detail split
} node_t;
// brush.c ====================================================================
#define NUM_HULLS 2 // normal and +16
#define NUM_CONTENTS 2 // solid and water
typedef struct brush_s {
struct brush_s *next;
vec3_t mins, maxs;
face_t *faces;
int contents;
} brush_t;
typedef struct {
vec3_t mins, maxs;
brush_t *brushes; // NULL terminated list
} brushset_t;
extern int numbrushplanes;
extern plane_t planes[MAX_MAP_PLANES];
brushset_t *Brush_LoadEntity (entity_t *ent, int hullnum);
int PlaneTypeForNormal (vec3_t normal);
int FindPlane (plane_t *dplane, int *side);
// csg4.c =====================================================================
// build surfaces is also used by GatherNodeFaces
extern face_t *validfaces[MAX_MAP_PLANES];
surface_t *BuildSurfaces (void);
face_t *NewFaceFromFace (face_t *in);
surface_t *CSGFaces (brushset_t *bs);
void SplitFace (face_t *in, plane_t *split, face_t **front, face_t **back);
// solidbsp.c =================================================================
void DivideFacet (face_t *in, plane_t *split, face_t **front, face_t **back);
void CalcSurfaceInfo (surface_t *surf);
node_t *SolidBSP (surface_t *surfhead, qboolean midsplit);
// 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 =================================================================
extern int c_cornerverts;
extern int c_tryedges;
extern face_t *edgefaces[MAX_MAP_EDGES][2];
extern int firstmodeledge;
extern int firstmodelface;
void SubdivideFace (face_t *f, face_t **prevptr);
surface_t *GatherNodeFaces (node_t *headnode);
void MakeFaceEdges (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 PortalizeWorld (node_t *headnode);
void PortalizeWorldDetail (node_t *headnode); // stop at detail nodes
void WritePortalfile (node_t *headnode);
void FreeAllPortals (node_t *node);
// region.c ===================================================================
void GrowNodeRegions (node_t *headnode);
// tjunc.c ====================================================================
void tjunc (node_t *headnode);
// writebsp.c =================================================================
void WriteNodePlanes (node_t *headnode);
void WriteClipNodes (node_t *headnode);
void WriteDrawNodes (node_t *headnode);
void BumpModel (int hullnum);
int FindFinalPlane (dplane_t *p);
void BeginBSPFile (void);
void FinishBSPFile (void);
// draw.c =====================================================================
void Draw_ClearBounds (void);
void Draw_AddToBounds (vec3_t v);
void Draw_DrawFace (face_t *f);
void Draw_ClearWindow (void);
void Draw_SetRed (void);
void Draw_SetGrey (void);
void Draw_SetBlack (void);
void DrawPoint (vec3_t v);
void Draw_SetColor (int c);
void SetColor (int c);
void DrawPortal (portal_t *p);
void DrawLeaf (node_t *l, int color);
void DrawBrush (brush_t *b);
void DrawWinding (winding_t *w);
void DrawTri (vec3_t p1, vec3_t p2, vec3_t p3);
// outside.c ==================================================================
qboolean FillOutside (node_t *node);
// readbsp.c ==================================================================
void LoadBSP (void);
void bsp2prt (void);
void extract_textures (void);
void extract_entities (void);
void extract_hull (void);
//=============================================================================
extern brushset_t *brushset;
extern struct brushset_s *brushset;
void qprintf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); // prints only if verbose
@ -275,3 +127,5 @@ struct brush_s *AllocBrush (void);
//=============================================================================
extern bsp_t *bsp;
#endif//qfbsp_bsp5_h

View file

@ -0,0 +1,42 @@
/*
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.
$Id$
*/
#ifndef qfbsp_csg4_h
#define qfbsp_csg4_h
#include "QF/bspfile.h"
struct plane_s;
struct visfacet_s;
struct brushset_s;
struct surface_s;
// build surfaces is also used by GatherNodeFaces
extern struct visfacet_s *validfaces[MAX_MAP_PLANES];
struct surface_s *BuildSurfaces (void);
struct visfacet_s *NewFaceFromFace (struct visfacet_s *in);
struct surface_s *CSGFaces (struct brushset_s *bs);
void SplitFace (struct visfacet_s *in, struct plane_s *split,
struct visfacet_s **front, struct visfacet_s **back);
#endif//qfbsp_csg4_h

View file

@ -0,0 +1,52 @@
/*
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.
$Id$
*/
#ifndef qfbsp_draw_h
#define qfbsp_draw_h
#include "QF/mathlib.h"
struct visfacet_s;
struct portal_s;
struct node_s;
struct brush_s;
struct winding_s;
void Draw_ClearBounds (void);
void Draw_AddToBounds (vec3_t v);
void Draw_DrawFace (struct visfacet_s *f);
void Draw_ClearWindow (void);
void Draw_SetRed (void);
void Draw_SetGrey (void);
void Draw_SetBlack (void);
void DrawPoint (vec3_t v);
void Draw_SetColor (int c);
void SetColor (int c);
void DrawPortal (struct portal_s *p);
void DrawLeaf (struct node_s *l, int color);
void DrawBrush (struct brush_s *b);
void DrawWinding (struct winding_s *w);
void DrawTri (vec3_t p1, vec3_t p2, vec3_t p3);
#endif//qfbsp_draw_h

View file

@ -20,12 +20,17 @@
$Id$
*/
#ifndef qfbsp_map_h
#define qfbsp_map_h
#include "bsp5.h"
#define MAX_FACES 256
typedef struct mface_s
{
struct mface_s *next;
plane_t plane;
int texinfo;
struct mface_s *next;
plane_t plane;
int texinfo;
} mface_t;
typedef struct mbrush_s
@ -68,3 +73,5 @@ void SetKeyValue (entity_t *ent, const char *key, const char *value);
void GetVectorForKey (entity_t *ent, const char *key, vec3_t vec);
void WriteEntitiesToString (void);
#endif//qfbsp_map_h

View file

@ -0,0 +1,31 @@
/*
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.
$Id$
*/
#ifndef qfbsp_merge_h
#define qfbsp_merge_h
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//qfbsp_merge_h

View file

@ -26,8 +26,8 @@
$Id$
*/
#ifndef __options_h
#define __options_h
#ifndef qfbsp_options_h
#define qfbsp_options_h
#include "QF/qtypes.h"
@ -59,4 +59,4 @@ typedef struct {
extern options_t options;
int DecodeArgs (int argc, char **argv);
extern const char *this_program;
#endif//__options_h
#endif//qfbsp_options_h

View file

@ -0,0 +1,29 @@
/*
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.
$Id$
*/
#ifndef qfbsp_outside_h
#define qfbsp_outside_h
struct node_s;
qboolean FillOutside (struct node_s *node);
#endif//qfbsp_outside_h

View file

@ -0,0 +1,42 @@
/*
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.
$Id$
*/
#ifndef qfbsp_portals_h
#define qfbsp_portals_h
struct node_s;
typedef struct portal_s {
int planenum;
struct node_s *nodes[2]; // [0] = front side of planenum
struct portal_s *next[2];
struct winding_s *winding;
} portal_t;
extern struct node_s outside_node; // portals outside the world face this
void PortalizeWorld (struct node_s *headnode);
void PortalizeWorldDetail (struct node_s *headnode); // stop at detail nodes
void WritePortalfile (struct node_s *headnode);
void FreeAllPortals (struct node_s *node);
#endif//qfbsp_portals_h

View file

@ -0,0 +1,32 @@
/*
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.
$Id$
*/
#ifndef qfbsp_readbsp_h
#define qfbsp_readbsp_h
void LoadBSP (void);
void bsp2prt (void);
void extract_textures (void);
void extract_entities (void);
void extract_hull (void);
#endif//qfbsp_readbsp_h

View file

@ -0,0 +1,30 @@
/*
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.
$Id$
*/
#ifndef qfbsp_region_h
#define qfbsp_region_h
struct node_s;
void GrowNodeRegions (struct node_s *headnode);
#endif//qfbsp_region_h

View file

@ -0,0 +1,38 @@
/*
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.
$Id$
*/
#ifndef qfbsp_solidbsp_h
#define qfbsp_solidbsp_h
#include "QF/qtypes.h"
struct visfacet_s;
struct plane_s;
struct surface_s;
struct node_s;
void DivideFacet (struct visfacet_s *in, struct plane_s *split,
struct visfacet_s **front, struct visfacet_s **back);
void CalcSurfaceInfo (struct surface_s *surf);
struct node_s *SolidBSP (struct surface_s *surfhead, qboolean midsplit);
#endif//qfbsp_solidbsp_h

View file

@ -0,0 +1,45 @@
/*
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.
$Id$
*/
#ifndef surfaces_h
#define surfaces_h
#include "QF/bspfile.h"
struct visfacet_s;
struct node_s;
struct surface_s;
extern int c_cornerverts;
extern int c_tryedges;
extern struct visfacet_s *edgefaces[MAX_MAP_EDGES][2];
extern int firstmodeledge;
extern int firstmodelface;
void SubdivideFace (struct visfacet_s *f, struct visfacet_s **prevptr);
struct surface_s *GatherNodeFaces (struct node_s *headnode);
void MakeFaceEdges (struct node_s *headnode);
#endif//surfaces_h

View file

@ -0,0 +1,30 @@
/*
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.
$Id$
*/
#ifndef qfbsp_tjunc_h
#define qfbsp_tjunc_h
struct node_s;
void tjunc (struct node_s *headnode);
#endif//qfbsp_tjunc_h

View file

@ -0,0 +1,44 @@
/*
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.
$Id$
*/
#ifndef qfbsp_winding_h
#define qfbsp_winding_h
#include "QF/mathlib.h"
struct plane_s;
typedef struct winding_s {
int numpoints;
vec3_t points[8]; // variable sized
} winding_t;
winding_t *BaseWindingForPlane (struct plane_s *p);
winding_t *NewWinding (int points);
void FreeWinding (winding_t *w);
winding_t *CopyWinding (winding_t *w);
winding_t *CopyWindingReverse (winding_t *w);
winding_t *ClipWinding (winding_t *in, struct plane_s *split, qboolean keepon);
void DivideWinding (winding_t *in, struct plane_s *split,
winding_t **front, winding_t **back);
#endif//qfbsp_winding_h

View file

@ -0,0 +1,40 @@
/*
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.
$Id$
*/
#ifndef qfbsp_writebsp_h
#define qfbsp_writebsp_h
#include "QF/bspfile.h"
struct node_s;
void WriteNodePlanes (struct node_s *headnode);
void WriteClipNodes (struct node_s *headnode);
void WriteDrawNodes (struct node_s *headnode);
void BumpModel (int hullnum);
int FindFinalPlane (dplane_t *p);
void BeginBSPFile (void);
void FinishBSPFile (void);
#endif//qfbsp_writebsp_h

View file

@ -17,7 +17,8 @@ EXTRA_PROGRAMS= qfbsp
qfbsp_SOURCES= \
brush.c csg4.c map.c merge.c nodraw.c options.c outside.c portals.c \
qfbsp.c readbsp.c region.c solidbsp.c surfaces.c tjunc.c writebsp.c
qfbsp.c readbsp.c region.c solidbsp.c surfaces.c tjunc.c winding.c \
writebsp.c
qfbsp_LDADD= $(QFBSP_LIBS)
qfbsp_DEPENDENCIES= $(QFBSP_DEPS)

View file

@ -30,8 +30,12 @@
#include "QF/sys.h"
#include "compat.h"
#include "brush.h"
#include "bsp5.h"
#include "draw.h"
#include "options.h"
#include "winding.h"
int numbrushplanes;
plane_t planes[MAX_MAP_PLANES];

View file

@ -30,7 +30,13 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/sys.h"
#include "brush.h"
#include "bsp5.h"
#include "csg4.h"
#include "draw.h"
#include "merge.h"
#include "solidbsp.h"
#include "winding.h"
/*
NOTES

View file

@ -40,9 +40,10 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/sys.h"
#include "QF/va.h"
#include "bsp5.h"
#include "compat.h"
#include "map.h"
int nummapbrushfaces;
int nummapbrushes;
mbrush_t mapbrushes[MAX_MAP_BRUSHES];

View file

@ -26,7 +26,12 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/sys.h"
#include "brush.h"
#include "bsp5.h"
#include "csg4.h"
#include "draw.h"
#include "merge.h"
#include "winding.h"
#define CONTINUOUS_EPSILON 0.001

View file

@ -24,7 +24,7 @@
static __attribute__ ((used)) const char rcsid[] =
"$Id$";
#include "bsp5.h"
#include "draw.h"
void
@ -38,7 +38,7 @@ Draw_AddToBounds (vec3_t v)
}
void
Draw_DrawFace (face_t *f)
Draw_DrawFace (struct visfacet_s *f)
{
}
@ -68,17 +68,17 @@ DrawPoint (vec3_t v)
}
void
DrawLeaf (node_t *l, int color)
DrawLeaf (struct node_s *l, int color)
{
}
void
DrawBrush (brush_t *b)
DrawBrush (struct brush_s *b)
{
}
void
DrawWinding (winding_t *w)
DrawWinding (struct winding_s *w)
{
}
@ -88,6 +88,6 @@ DrawTri (vec3_t p1, vec3_t p2, vec3_t p3)
}
void
DrawPortal (portal_t *portal)
DrawPortal (struct portal_s *portal)
{
}

View file

@ -25,8 +25,13 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/sys.h"
#include "brush.h"
#include "bsp5.h"
#include "draw.h"
#include "options.h"
#include "portals.h"
#include "outside.h"
#include "winding.h"
int outleafs;

View file

@ -30,8 +30,12 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/sys.h"
#include "brush.h"
#include "bsp5.h"
#include "draw.h"
#include "options.h"
#include "portals.h"
#include "winding.h"
node_t outside_node; // portals outside the world face this

View file

@ -46,8 +46,18 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/quakefs.h"
#include "QF/sys.h"
#include "csg4.h"
#include "brush.h"
#include "bsp5.h"
#include "merge.h"
#include "options.h"
#include "outside.h"
#include "portals.h"
#include "readbsp.h"
#include "solidbsp.h"
#include "surfaces.h"
#include "writebsp.h"
#include "tjunc.h"
options_t options;
@ -57,7 +67,6 @@ brushset_t *brushset;
int c_activefaces, c_peakfaces;
int c_activesurfaces, c_peaksurfaces;
int c_activewindings, c_peakwindings;
int c_activeportals, c_peakportals;
int valid;
@ -68,285 +77,6 @@ qboolean worldmodel;
int hullnum;
winding_t *
BaseWindingForPlane (plane_t *p)
{
int i, x;
vec_t max, v;
vec3_t org, vright, vup;
winding_t *w;
// find the major axis
max = -BOGUS_RANGE;
x = -1;
for (i = 0; i < 3; i++) {
v = fabs (p->normal[i]);
if (v > max) {
x = i;
max = v;
}
}
if (x == -1)
Sys_Error ("BaseWindingForPlane: no axis found");
VectorZero (vup);
switch (x) {
case 0:
case 1:
vup[2] = 1;
break;
case 2:
vup[0] = 1;
break;
}
v = DotProduct (vup, p->normal);
VectorMultSub (vup, v, p->normal, vup);
_VectorNormalize (vup);
VectorScale (p->normal, p->dist, org);
CrossProduct (vup, p->normal, vright);
VectorScale (vup, BOGUS_RANGE, vup);
VectorScale (vright, BOGUS_RANGE, vright);
// project a really big axis aligned box onto the plane
w = NewWinding (4);
VectorSubtract (org, vright, w->points[0]);
VectorAdd (w->points[0], vup, w->points[0]);
VectorAdd (org, vright, w->points[1]);
VectorAdd (w->points[1], vup, w->points[1]);
VectorAdd (org, vright, w->points[2]);
VectorSubtract (w->points[2], vup, w->points[2]);
VectorSubtract (org, vright, w->points[3]);
VectorSubtract (w->points[3], vup, w->points[3]);
w->numpoints = 4;
return w;
}
winding_t *
CopyWinding (winding_t *w)
{
size_t size;
winding_t *c;
size = (size_t) (uintptr_t) &((winding_t *) 0)->points[w->numpoints];
c = malloc (size);
memcpy (c, w, size);
return c;
}
winding_t *
CopyWindingReverse (winding_t *w)
{
int i;
size_t size;
winding_t *c;
size = (size_t) (uintptr_t) &((winding_t *) 0)->points[w->numpoints];
c = malloc (size);
c->numpoints = w->numpoints;
for (i = 0; i < w->numpoints; i++) {
// add points backwards
VectorCopy (w->points[w->numpoints - 1 - i], c->points[i]);
}
return c;
}
/*
ClipWinding
Clips the winding to the plane, returning the new winding on the positive
side.
Frees the input winding.
If keepon is true, an exactly on-plane winding will be saved, otherwise
it will be clipped away.
*/
winding_t *
ClipWinding (winding_t *in, plane_t *split, qboolean keepon)
{
int maxpts, i, j;
int *sides;
int counts[3];
vec_t dot;
vec_t *dists;
vec_t *p1, *p2;
vec3_t mid;
winding_t *neww;
counts[0] = counts[1] = counts[2] = 0;
sides = alloca ((in->numpoints + 1) * sizeof (int));
dists = alloca ((in->numpoints + 1) * sizeof (vec_t));
// determine sides for each point
for (i = 0; i < in->numpoints; i++) {
dot = DotProduct (in->points[i], split->normal);
dot -= split->dist;
dists[i] = dot;
if (dot > ON_EPSILON)
sides[i] = SIDE_FRONT;
else if (dot < -ON_EPSILON)
sides[i] = SIDE_BACK;
else {
sides[i] = SIDE_ON;
}
counts[sides[i]]++;
}
sides[i] = sides[0];
dists[i] = dists[0];
if (keepon && !counts[SIDE_FRONT] && !counts[SIDE_BACK])
return in;
if (!counts[SIDE_FRONT]) {
FreeWinding (in);
return NULL;
}
if (!counts[SIDE_BACK])
return in;
for (maxpts = 0, i = 0; i < in->numpoints; i++) {
if (!(sides[i] & 1))
maxpts++;
if ((sides[i] ^ 1) == sides[i + 1])
maxpts++;
}
neww = NewWinding (maxpts);
for (i = 0; i < in->numpoints; i++) {
p1 = in->points[i];
if (sides[i] == SIDE_ON) {
if (neww->numpoints == maxpts)
Sys_Error ("ClipWinding: points exceeded estimate");
VectorCopy (p1, neww->points[neww->numpoints]);
neww->numpoints++;
continue;
}
if (sides[i] == SIDE_FRONT) {
if (neww->numpoints == maxpts)
Sys_Error ("ClipWinding: points exceeded estimate");
VectorCopy (p1, neww->points[neww->numpoints]);
neww->numpoints++;
}
if (sides[i + 1] == SIDE_ON || sides[i + 1] == sides[i])
continue;
if (neww->numpoints == maxpts)
Sys_Error ("ClipWinding: points exceeded estimate");
// generate a split point
p2 = in->points[(i + 1) % in->numpoints];
dot = dists[i] / (dists[i] - dists[i + 1]);
for (j = 0; j < 3; j++) { // avoid round off error when possible
if (split->normal[j] == 1)
mid[j] = split->dist;
else if (split->normal[j] == -1)
mid[j] = -split->dist;
else
mid[j] = p1[j] + dot * (p2[j] - p1[j]);
}
VectorCopy (mid, neww->points[neww->numpoints]);
neww->numpoints++;
}
// free the original winding
FreeWinding (in);
return neww;
}
/*
DivideWinding
Divides a winding by a plane, producing one or two windings. The
original winding is not damaged or freed. If on only one side, the
returned winding will be the input winding. If on both sides, two
new windings will be created.
*/
void
DivideWinding (winding_t *in, plane_t *split, winding_t **front,
winding_t **back)
{
int i;
int counts[3];
plane_t plane;
vec_t dot;
winding_t *tmp;
counts[0] = counts[1] = counts[2] = 0;
// determine sides for each point
for (i = 0; i < in->numpoints; i++) {
dot = DotProduct (in->points[i], split->normal) - split->dist;
if (dot > ON_EPSILON)
counts[SIDE_FRONT]++;
else if (dot < -ON_EPSILON)
counts[SIDE_BACK]++;
}
*front = *back = NULL;
if (!counts[SIDE_FRONT]) {
*back = in;
return;
}
if (!counts[SIDE_BACK]) {
*front = in;
return;
}
tmp = CopyWinding (in);
*front = ClipWinding (tmp, split, 0);
plane.dist = -split->dist;
VectorNegate (split->normal, plane.normal);
tmp = CopyWinding (in);
*back = ClipWinding (tmp, &plane, 0);
}
winding_t *
NewWinding (int points)
{
size_t size;
winding_t *w;
if (points < 3)
Sys_Error ("NewWinding: %i points", points);
c_activewindings++;
if (c_activewindings > c_peakwindings)
c_peakwindings = c_activewindings;
size = (size_t) (uintptr_t) &((winding_t *) 0)->points[points];
w = malloc (size);
memset (w, 0, size);
return w;
}
void
FreeWinding (winding_t *w)
{
c_activewindings--;
free (w);
}
face_t *
AllocFace (void)
{

View file

@ -51,8 +51,12 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/va.h"
#include "QF/wad.h"
#include "brush.h"
#include "bsp5.h"
#include "options.h"
#include "portals.h"
#include "readbsp.h"
#include "winding.h"
dmodel_t *models;
face_t *mfaces;

View file

@ -31,8 +31,11 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/sys.h"
#include "compat.h"
#include "bsp5.h"
#include "options.h"
#include "region.h"
#include "surfaces.h"
#include "winding.h"
/*
input

View file

@ -31,7 +31,13 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/sys.h"
#include "brush.h"
#include "csg4.h"
#include "bsp5.h"
#include "draw.h"
#include "solidbsp.h"
#include "surfaces.h"
#include "winding.h"
int leaffaces;
int nodefaces;

View file

@ -32,7 +32,11 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/sys.h"
#include "bsp5.h"
#include "csg4.h"
#include "options.h"
#include "region.h"
#include "surfaces.h"
#include "winding.h"
/*
a surface has all of the faces that could be drawn on a given plane

View file

@ -32,8 +32,11 @@ static __attribute__ ((used)) const char rcsid[] =
#include "compat.h"
#include "brush.h"
#include "bsp5.h"
#include "options.h"
#include "winding.h"
#include "tjunc.h"
typedef struct wvert_s {
vec_t t;

View file

@ -0,0 +1,322 @@
/*
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.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
static __attribute__ ((used)) const char rcsid[] =
"$Id$";
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#include <stdlib.h>
#include "QF/sys.h"
#include "bsp5.h"
#include "winding.h"
int c_activewindings, c_peakwindings;
winding_t *
BaseWindingForPlane (plane_t *p)
{
int i, x;
vec_t max, v;
vec3_t org, vright, vup;
winding_t *w;
// find the major axis
max = -BOGUS_RANGE;
x = -1;
for (i = 0; i < 3; i++) {
v = fabs (p->normal[i]);
if (v > max) {
x = i;
max = v;
}
}
if (x == -1)
Sys_Error ("BaseWindingForPlane: no axis found");
VectorZero (vup);
switch (x) {
case 0:
case 1:
vup[2] = 1;
break;
case 2:
vup[0] = 1;
break;
}
v = DotProduct (vup, p->normal);
VectorMultSub (vup, v, p->normal, vup);
_VectorNormalize (vup);
VectorScale (p->normal, p->dist, org);
CrossProduct (vup, p->normal, vright);
VectorScale (vup, BOGUS_RANGE, vup);
VectorScale (vright, BOGUS_RANGE, vright);
// project a really big axis aligned box onto the plane
w = NewWinding (4);
VectorSubtract (org, vright, w->points[0]);
VectorAdd (w->points[0], vup, w->points[0]);
VectorAdd (org, vright, w->points[1]);
VectorAdd (w->points[1], vup, w->points[1]);
VectorAdd (org, vright, w->points[2]);
VectorSubtract (w->points[2], vup, w->points[2]);
VectorSubtract (org, vright, w->points[3]);
VectorSubtract (w->points[3], vup, w->points[3]);
w->numpoints = 4;
return w;
}
winding_t *
CopyWinding (winding_t *w)
{
size_t size;
winding_t *c;
size = (size_t) (uintptr_t) &((winding_t *) 0)->points[w->numpoints];
c = malloc (size);
memcpy (c, w, size);
return c;
}
winding_t *
CopyWindingReverse (winding_t *w)
{
int i;
size_t size;
winding_t *c;
size = (size_t) (uintptr_t) &((winding_t *) 0)->points[w->numpoints];
c = malloc (size);
c->numpoints = w->numpoints;
for (i = 0; i < w->numpoints; i++) {
// add points backwards
VectorCopy (w->points[w->numpoints - 1 - i], c->points[i]);
}
return c;
}
/*
ClipWinding
Clips the winding to the plane, returning the new winding on the positive
side.
Frees the input winding.
If keepon is true, an exactly on-plane winding will be saved, otherwise
it will be clipped away.
*/
winding_t *
ClipWinding (winding_t *in, plane_t *split, qboolean keepon)
{
int maxpts, i, j;
int *sides;
int counts[3];
vec_t dot;
vec_t *dists;
vec_t *p1, *p2;
vec3_t mid;
winding_t *neww;
counts[0] = counts[1] = counts[2] = 0;
sides = alloca ((in->numpoints + 1) * sizeof (int));
dists = alloca ((in->numpoints + 1) * sizeof (vec_t));
// determine sides for each point
for (i = 0; i < in->numpoints; i++) {
dot = DotProduct (in->points[i], split->normal);
dot -= split->dist;
dists[i] = dot;
if (dot > ON_EPSILON)
sides[i] = SIDE_FRONT;
else if (dot < -ON_EPSILON)
sides[i] = SIDE_BACK;
else {
sides[i] = SIDE_ON;
}
counts[sides[i]]++;
}
sides[i] = sides[0];
dists[i] = dists[0];
if (keepon && !counts[SIDE_FRONT] && !counts[SIDE_BACK])
return in;
if (!counts[SIDE_FRONT]) {
FreeWinding (in);
return NULL;
}
if (!counts[SIDE_BACK])
return in;
for (maxpts = 0, i = 0; i < in->numpoints; i++) {
if (!(sides[i] & 1))
maxpts++;
if ((sides[i] ^ 1) == sides[i + 1])
maxpts++;
}
neww = NewWinding (maxpts);
for (i = 0; i < in->numpoints; i++) {
p1 = in->points[i];
if (sides[i] == SIDE_ON) {
if (neww->numpoints == maxpts)
Sys_Error ("ClipWinding: points exceeded estimate");
VectorCopy (p1, neww->points[neww->numpoints]);
neww->numpoints++;
continue;
}
if (sides[i] == SIDE_FRONT) {
if (neww->numpoints == maxpts)
Sys_Error ("ClipWinding: points exceeded estimate");
VectorCopy (p1, neww->points[neww->numpoints]);
neww->numpoints++;
}
if (sides[i + 1] == SIDE_ON || sides[i + 1] == sides[i])
continue;
if (neww->numpoints == maxpts)
Sys_Error ("ClipWinding: points exceeded estimate");
// generate a split point
p2 = in->points[(i + 1) % in->numpoints];
dot = dists[i] / (dists[i] - dists[i + 1]);
for (j = 0; j < 3; j++) { // avoid round off error when possible
if (split->normal[j] == 1)
mid[j] = split->dist;
else if (split->normal[j] == -1)
mid[j] = -split->dist;
else
mid[j] = p1[j] + dot * (p2[j] - p1[j]);
}
VectorCopy (mid, neww->points[neww->numpoints]);
neww->numpoints++;
}
// free the original winding
FreeWinding (in);
return neww;
}
/*
DivideWinding
Divides a winding by a plane, producing one or two windings. The
original winding is not damaged or freed. If on only one side, the
returned winding will be the input winding. If on both sides, two
new windings will be created.
*/
void
DivideWinding (winding_t *in, plane_t *split, winding_t **front,
winding_t **back)
{
int i;
int counts[3];
plane_t plane;
vec_t dot;
winding_t *tmp;
counts[0] = counts[1] = counts[2] = 0;
// determine sides for each point
for (i = 0; i < in->numpoints; i++) {
dot = DotProduct (in->points[i], split->normal) - split->dist;
if (dot > ON_EPSILON)
counts[SIDE_FRONT]++;
else if (dot < -ON_EPSILON)
counts[SIDE_BACK]++;
}
*front = *back = NULL;
if (!counts[SIDE_FRONT]) {
*back = in;
return;
}
if (!counts[SIDE_BACK]) {
*front = in;
return;
}
tmp = CopyWinding (in);
*front = ClipWinding (tmp, split, 0);
plane.dist = -split->dist;
VectorNegate (split->normal, plane.normal);
tmp = CopyWinding (in);
*back = ClipWinding (tmp, &plane, 0);
}
winding_t *
NewWinding (int points)
{
size_t size;
winding_t *w;
if (points < 3)
Sys_Error ("NewWinding: %i points", points);
c_activewindings++;
if (c_activewindings > c_peakwindings)
c_peakwindings = c_activewindings;
size = (size_t) (uintptr_t) &((winding_t *) 0)->points[points];
w = malloc (size);
memset (w, 0, size);
return w;
}
void
FreeWinding (winding_t *w)
{
c_activewindings--;
free (w);
}

View file

@ -40,8 +40,10 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/va.h"
#include "QF/wad.h"
#include "brush.h"
#include "bsp5.h"
#include "options.h"
#include "writebsp.h"
int headclipnode;
int firstface;