UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
bsp.cpp
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 #include "bsp.h"
26 #include "levels.h"
27 #include "map.h"
28 
34 
38 static void ProcessWorldModel (int entityNumber)
39 {
40  entity_t* e = &entities[0];
41 
44 
45  /* This is set so the Emit* functions in writebsp.c work correctly. */
46  curTile->nummodels = NUM_REGULAR_MODELS;
47 
48  ProcessLevelEntityNumber(entityNumber);
49 
50  /* process levels */
52 
53  /* calculate routing */
54  DoRouting();
55 }
56 
57 
61 static void ProcessSubModel (int entityNum)
62 {
63  const entity_t* e;
64  int start, end;
65  tree_t* tree;
66  bspbrush_t* list;
67  AABB aabb;
68 
69  BeginModel(entityNum);
70 
71  e = &entities[entityNum];
72 #if 0
73  Com_Printf("Processing entity: %i into model %i (%s:%s)\n", entityNum, curTile->nummodels, e->epairs->key, e->epairs->value);
74 #endif
75 
76  start = e->firstbrush;
77  end = start + e->numbrushes;
78 
79  aabb.reset();
80  aabb.expand(MAX_WORLD_WIDTH);
81 
82  /* every level (-1) */
83  list = MakeBspBrushList(start, end, -1, aabb);
84  if (!config.nocsg)
85  list = ChopBrushes(list);
86  tree = BuildTree(list, aabb.mins, aabb.maxs);
87  assert(tree);
88  assert(tree->headnode);
89  if (tree->headnode->planenum == PLANENUM_LEAF)
90  Sys_Error("No head node bmodel of %s (%i)\n", ValueForKey(e, "classname"), entityNum);
91  MakeTreePortals(tree);
92  MarkVisibleSides(tree, start, end);
93  MakeFaces(tree->headnode);
94  FixTjuncs(tree->headnode);
95  curTile->models[curTile->nummodels].headnode = WriteBSP(tree->headnode);
96  FreeTree(tree);
97 
98  EndModel();
99 }
100 
101 
106 void ProcessModels (const char* filename)
107 {
108  int entity_num;
109 
110  BeginBSPFile();
111 
112  for (entity_num = 0; entity_num < num_entities; entity_num++) {
113  if (!entities[entity_num].numbrushes)
114  continue;
115 
116  Verb_Printf(VERB_EXTRA, "############### model %i ###############\n", curTile->nummodels);
117 
118  if (entity_num == 0)
119  ProcessWorldModel(entity_num);
120  else
121  ProcessSubModel(entity_num);
122 
123  if (!config.verboseentities)
124  config.verbose = false; /* don't bother printing submodels */
125  }
126 
127  EndBSPFile(filename);
128 }
static int entityNum
Definition: levels.cpp:220
void Sys_Error(const char *error,...)
Definition: g_main.cpp:421
static void ProcessWorldModel(int entityNumber)
Definition: bsp.cpp:38
void ProcessModels(const char *filename)
Definition: bsp.cpp:106
mapTiles_t mapTiles
Definition: bsp.cpp:33
int firstbrush
Definition: bspfile.h:48
dBspModel_t models[MAX_MAP_MODELS]
Definition: typedefs.h:468
void RunSingleThreadOn(void(*func)(unsigned int), unsigned int workcount, bool progress, const char *id)
Definition: aabb.h:42
Definition: bsp.h:61
const char * filename
Definition: ioapi.h:41
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
void Com_Printf(const char *const fmt,...)
Definition: common.cpp:386
const char * value
Definition: bspfile.h:39
vec3_t maxs
Definition: aabb.h:258
entity_t entities[MAX_MAP_ENTITIES]
Definition: bspfile.cpp:395
int nummodels
Definition: typedefs.h:467
void MarkVisibleSides(tree_t *tree, int start, int end)
Definition: portals.cpp:482
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
void expand(const float byVal)
expand the box in all directions, but clip them to the maximum boundaries
Definition: aabb.h:240
bool verbose
Definition: test_all.cpp:39
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 BeginModel(int entityNum)
Sets up a new brush model.
Definition: writebsp.cpp:353
#define NUM_REGULAR_MODELS
Definition: defines.h:354
void ProcessLevelEntityNumber(int entityNumber)
Definition: levels.cpp:222
void ProcessLevel(unsigned int levelnum)
process brushes with that level mask
Definition: levels.cpp:238
int32_t headnode
Definition: typedefs.h:357
int brush_start
Definition: levels.cpp:29
void Verb_Printf(const verbosityLevel_t importance, const char *format,...) __attribute__((format(__printf__
static config_t config
Definition: test_all.cpp:43
dMapTile_t * curTile
Definition: bsp.cpp:32
int numbrushes
Definition: bspfile.h:49
#define PLANENUM_LEAF
Definition: defines.h:45
struct node_s * headnode
Definition: bsp.h:62
void EndBSPFile(const char *filename)
Finishes a new bsp and writes to disk.
Definition: writebsp.cpp:336
const char * key
Definition: bspfile.h:38
void FixTjuncs(node_t *headnode)
Definition: faces.cpp:370
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
void MakeFaces(node_t *headnode)
Definition: faces.cpp:764
void EndModel(void)
Finish a model's processing.
Definition: writebsp.cpp:387
#define MAX_WORLD_WIDTH
-MAX_WORLD_WIDTH up tp +MAX_WORLD_WIDTH
Definition: defines.h:288
int brush_end
Definition: levels.cpp:29
void MakeTreePortals(tree_t *tree)
Definition: portals.cpp:391
vec3_t mins
Definition: aabb.h:257
const char * ValueForKey(const entity_t *ent, const char *key)
Definition: bspfile.cpp:558
static void ProcessSubModel(int entityNum)
Definition: bsp.cpp:61
bspbrush_t * MakeBspBrushList(int startbrush, int endbrush, int level, const AABB &clip)
Definition: csg.cpp:292
void reset()
Definition: aabb.h:83
int num_entities
Definition: bspfile.cpp:394
epair_t * epairs
Definition: bspfile.h:50