UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
bsp.h
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 1997-2001 Id Software, Inc.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23 */
24 
25 #pragma once
26 
27 #include <assert.h>
28 
29 #include "map.h"
30 #include "bspbrush.h"
31 
32 #include "common/shared.h"
33 #include "common/scriplib.h"
34 #include "common/polylib.h"
35 #include "common/bspfile.h"
36 
37 #include "../../common/tracing.h"
38 
39 extern dMapTile_t* curTile;
40 extern mapTiles_t mapTiles;
41 
42 typedef struct node_s {
44  int32_t planenum;
45  struct node_s* parent;
51  struct node_s* children[2];
53 
56  int32_t contentFlags;
57  int area;
58  struct portal_s* portals;
59 } node_t;
60 
61 typedef struct tree_s {
62  struct node_s* headnode;
65 } tree_t;
66 
68 extern int nummapplanes;
69 
70 extern int nummapbrushes;
72 
73 extern int nummapbrushsides;
76 
77 extern int brush_start, brush_end;
78 
80 void LoadMapFile(const char* filename);
81 void WriteMapFile(const char* filename);
82 uint16_t FindOrCreateFloatPlane(vec3_t normal, vec_t dist);
83 
84 /*============================================================================= */
85 
86 /* csg.c */
87 int MapBrushesBounds(const int startbrush, const int endbrush, const int level, const AABB& clipBox, AABB& bBox);
88 bspbrush_t* MakeBspBrushList(int startbrush, int endbrush, int level, const AABB& clip);
90 
91 /* portals.c */
92 uint32_t VisibleContents(uint32_t contents);
93 void MarkVisibleSides(tree_t* tree, int start, int end);
94 void FreePortal(portal_t* p);
95 void MakeTreePortals(tree_t* tree);
96 void RemovePortalFromNode(portal_t* portal, node_t* l);
97 
98 /*============================================================================= */
99 
100 /* writebsp.c */
101 void SetModelNumbers(void);
102 
103 void BeginBSPFile(void);
104 int WriteBSP(node_t* headnode);
105 void EndBSPFile(const char* filename);
106 void BeginModel(int entityNum);
107 void EndModel(void);
108 void EmitBrushes(void);
109 void EmitPlanes(void);
110 
111 /* faces.c */
112 void MakeFaces(node_t* headnode);
113 void FixTjuncs(node_t* headnode);
114 int GetEdge(int v1, int v2, const face_t* f);
115 void FreeFace(face_t* f);
116 
117 /* tree.c */
118 node_t* AllocNode(void);
119 tree_t* AllocTree(void);
120 tree_t* BuildTree(bspbrush_t* brushlist, const vec3_t mins, const vec3_t maxs);
121 void FreeTree(tree_t* tree);
122 void PruneNodes(node_t* node);
123 
124 /* trace.c */
125 void MakeTracingNodes(int levels);
126 void CloseTracingNodes(void);
127 
128 /* routing.c */
129 void DoRouting(void);
130 
131 /* bsp.c */
132 void ProcessModels(const char* filename);
static int entityNum
Definition: levels.cpp:220
int32_t contentFlags
Definition: bsp.h:56
byte GetLevelFlagsFromBrush(const mapbrush_t *brush)
Extract the level flags (1-8) from the content flags of the given brush.
Definition: map.cpp:277
void LoadMapFile(const char *filename)
Definition: map.cpp:1197
Definition: map.h:42
uint16_t FindOrCreateFloatPlane(vec3_t normal, vec_t dist)
Definition: map.cpp:194
#define MAX_MAP_PLANES
Definition: defines.h:139
void CloseTracingNodes(void)
Definition: trace.cpp:65
Definition: aabb.h:42
Definition: bsp.h:61
const char * filename
Definition: ioapi.h:41
side_t brushsides[MAX_MAP_SIDES]
Definition: map.cpp:37
float vec_t
Definition: ufotypes.h:37
void FreePortal(portal_t *p)
Definition: portals.cpp:52
void ProcessModels(const char *filename)
Definition: bsp.cpp:106
void BeginBSPFile(void)
Starts a new bsp file.
Definition: writebsp.cpp:303
void DoRouting(void)
Calculates the routing of a map.
Definition: routing.cpp:115
brush_texture_t side_brushtextures[MAX_MAP_SIDES]
Definition: map.cpp:40
int nummapbrushes
Definition: map.cpp:35
void MarkVisibleSides(tree_t *tree, int start, int end)
Definition: portals.cpp:482
void MakeTracingNodes(int levels)
Use the bsp node structure to reconstruct efficient tracing structures that are used for fast visibil...
Definition: trace.cpp:38
bspbrush_t * ChopBrushes(bspbrush_t *head)
Carves any intersecting solid brushes into the minimum number of non-intersecting brushes...
Definition: csg.cpp:376
int32_t planenum
Definition: bsp.h:44
void FreeTree(tree_t *tree)
Definition: tree.cpp:102
mapbrush_t mapbrushes[MAX_MAP_BRUSHES]
Definition: map.cpp:34
side_t * side
Definition: bsp.h:50
int nummapplanes
Definition: map.cpp:44
mapTiles_t mapTiles
Definition: bsp.cpp:33
tree_t * BuildTree(bspbrush_t *brushlist, const vec3_t mins, const vec3_t maxs)
The incoming list will be freed before exiting.
Definition: tree.cpp:182
void SetModelNumbers(void)
Set the model numbers for SOLID_BSP or SOLID_TRIGGER entities like func_door or func_breakable.
Definition: writebsp.cpp:217
void BeginModel(int entityNum)
Sets up a new brush model.
Definition: writebsp.cpp:353
void FreeFace(face_t *f)
Definition: faces.cpp:133
Definition: map.h:98
struct node_s * children[2]
Definition: bsp.h:51
bspbrush_t * volume
Definition: bsp.h:47
tree_t * AllocTree(void)
Allocates a tree and initializes it.
Definition: tree.cpp:92
node_t * AllocNode(void)
Definition: tree.cpp:34
void WriteMapFile(const char *filename)
Definition: map.cpp:1055
int brush_start
Definition: levels.cpp:29
#define MAX_MAP_SIDES
Definition: defines.h:383
plane_t mapplanes[MAX_MAP_PLANES]
Definition: map.cpp:43
Definition: map.h:60
struct portal_s * portals
Definition: bsp.h:58
QGL_EXTERN GLfloat f
Definition: r_gl.h:114
struct node_s * headnode
Definition: bsp.h:62
AABB nBox
Definition: bsp.h:46
struct node_s * parent
Definition: bsp.h:45
void EmitBrushes(void)
Writes the brush list to the bsp.
Definition: writebsp.cpp:236
void EndBSPFile(const char *filename)
Finishes a new bsp and writes to disk.
Definition: writebsp.cpp:336
bspbrush_t * brushlist
Definition: bsp.h:55
void RemovePortalFromNode(portal_t *portal, node_t *l)
Removes references to the given portal from the given node.
Definition: portals.cpp:102
void FixTjuncs(node_t *headnode)
Definition: faces.cpp:370
AABB aabb
Definition: bsp.h:64
Definition: map.h:75
int WriteBSP(node_t *headnode)
copies working data for a bsp tree into the structures used to create the bsp file.
Definition: writebsp.cpp:195
struct node_s node_t
void MakeFaces(node_t *headnode)
Definition: faces.cpp:764
void EndModel(void)
Finish a model's processing.
Definition: writebsp.cpp:387
vec_t vec3_t[3]
Definition: ufotypes.h:39
int GetEdge(int v1, int v2, const face_t *f)
Definition: faces.cpp:399
void EmitPlanes(void)
Emits planes to the bsp file.
Definition: writebsp.cpp:41
uint32_t VisibleContents(uint32_t contents)
Returns the single content bit of the strongest visible content present.
Definition: portals.cpp:64
int brush_end
Definition: levels.cpp:29
void MakeTreePortals(tree_t *tree)
Definition: portals.cpp:391
Definition: map.h:110
face_t * faces
Definition: bsp.h:52
struct node_s outside_node
Definition: bsp.h:63
Definition: bsp.h:42
int area
Definition: bsp.h:57
uint8_t byte
Definition: ufotypes.h:34
bspbrush_t * MakeBspBrushList(int startbrush, int endbrush, int level, const AABB &clip)
Definition: csg.cpp:292
int MapBrushesBounds(const int startbrush, const int endbrush, const int level, const AABB &clipBox, AABB &bBox)
sets mins and maxs to the smallest sizes that can contain all brushes from startbrush to endbrush tha...
Definition: csg.cpp:264
void PruneNodes(node_t *node)
Definition: tree.cpp:261
#define MAX_MAP_BRUSHES
Definition: defines.h:135
struct tree_s tree_t
dMapTile_t * curTile
Definition: bsp.cpp:32
int nummapbrushsides
Definition: map.cpp:38
level_locals_t level
Definition: g_main.cpp:38