bsp.c
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00049 curTile->nummodels = NUM_REGULAR_MODELS;
00050
00051
00052 RunSingleThreadOn(ProcessLevel, NUM_REGULAR_MODELS, config.verbosity >= VERB_NORMAL, "LEVEL");
00053
00054
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
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;
00124 }
00125
00126 EndBSPFile(filename);
00127 }