bsp.c

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (C) 1997-2001 Id Software, Inc.
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016 
00017 See the GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00023 */
00024 
00025 #include "map.h"
00026 #include "bsp.h"
00027 
00028 int entity_num;
00029 
00033 dMapTile_t *curTile;
00034 mapTiles_t mapTiles;
00035 
00039 static void ProcessWorldModel (void)
00040 {
00041     entity_t *e = &entities[0];
00042 
00043     brush_start = e->firstbrush;
00044     brush_end = brush_start + e->numbrushes;
00045 
00046     ClearBounds(worldMins, worldMaxs);
00047 
00048     /* This is set so the Emit* functions in writebsp.c work correctly. */
00049     curTile->nummodels = NUM_REGULAR_MODELS;
00050 
00051     /* process levels */
00052     RunSingleThreadOn(ProcessLevel, NUM_REGULAR_MODELS, config.verbosity >= VERB_NORMAL, "LEVEL");
00053 
00054     /* calculate routing */
00055     DoRouting();
00056 }
00057 
00058 
00062 static void ProcessSubModel (int entityNum)
00063 {
00064     const entity_t *e;
00065     int start, end;
00066     tree_t *tree;
00067     bspbrush_t *list;
00068     vec3_t mins, maxs;
00069 
00070     BeginModel(entityNum);
00071 
00072     e = &entities[entityNum];
00073 #if 0
00074     Com_Printf("Processing entity: %i into model %i (%s:%s)\n", entityNum, curTile->nummodels, e->epairs->key, e->epairs->value);
00075 #endif
00076 
00077     start = e->firstbrush;
00078     end = start + e->numbrushes;
00079 
00080     mins[0] = mins[1] = mins[2] = -MAX_WORLD_WIDTH;
00081     maxs[0] = maxs[1] = maxs[2] = MAX_WORLD_WIDTH;
00082 
00083     /* every level (-1) */
00084     list = MakeBspBrushList(start, end, -1, mins, maxs);
00085     if (!config.nocsg)
00086         list = ChopBrushes(list);
00087     tree = BrushBSP(list, mins, maxs);
00088     assert(tree);
00089     assert(tree->headnode);
00090     if (tree->headnode->planenum == PLANENUM_LEAF)
00091         Sys_Error("No head node bmodel of %s (%i)\n", ValueForKey(e, "classname"), entityNum);
00092     MakeTreePortals(tree);
00093     MarkVisibleSides(tree, start, end);
00094     MakeFaces(tree->headnode);
00095     FixTjuncs(tree->headnode);
00096     curTile->models[curTile->nummodels].headnode = WriteBSP(tree->headnode);
00097     FreeTree(tree);
00098 
00099     EndModel();
00100 }
00101 
00102 
00107 void ProcessModels (const char *filename)
00108 {
00109     BeginBSPFile();
00110 
00111     for (entity_num = 0; entity_num < num_entities; entity_num++) {
00112         if (!entities[entity_num].numbrushes)
00113             continue;
00114 
00115         Verb_Printf(VERB_EXTRA, "############### model %i ###############\n", curTile->nummodels);
00116 
00117         if (entity_num == 0)
00118             ProcessWorldModel();
00119         else
00120             ProcessSubModel(entity_num);
00121 
00122         if (!config.verboseentities)
00123             config.verbose = qfalse;    /* don't bother printing submodels */
00124     }
00125 
00126     EndBSPFile(filename);
00127 }

Generated by  doxygen 1.6.2