#include "qbsp.h"
#include "l_bsp_sin.h"
#include "aas_map.h"
Include dependency graph for map_sin.c:

Go to the source code of this file.
Functions | |
| int | Sin_BrushContents (mapbrush_t *b) |
| void | Sin_BSPBrushToMapBrush (sin_dbrush_t *bspbrush, entity_t *mapent) |
| void | Sin_CreateMapTexinfo (void) |
| void | Sin_InitNodeStack (void) |
| void | Sin_LoadMapFromBSP (char *filename, int offset, int length) |
| void | Sin_ParseBSPBrushes (entity_t *mapent) |
| qboolean | Sin_ParseBSPEntity (int entnum) |
| int | Sin_PopNodeStack (void) |
| void | Sin_PushNodeStack (int num) |
| void | Sin_ResetMapLoading (void) |
| void | Sin_SetBrushModelNumbers (entity_t *mapent) |
| void | Sin_SetLeafBrushesModelNumbers (int leafnum, int modelnum) |
|
|
Definition at line 40 of file map_sin.c. References b, mapbrush_s::brushnum, side_s::contents, CONTENTS_DETAIL, mapbrush_s::entitynum, texinfo_s::flags, i, mapbrush_t, mapbrush_s::numsides, mapbrush_s::original_sides, printf(), s, side_t, sin_texinfo, SURF_TRANS33, texinfo, side_s::texinfo, and sin_texinfo_s::translucence. Referenced by Sin_BSPBrushToMapBrush(). 00041 {
00042 int contents;
00043 side_t *s;
00044 int i;
00045 #ifdef SIN
00046 float trans = 0;
00047 #else
00048 int trans;
00049 #endif
00050
00051 s = &b->original_sides[0];
00052 contents = s->contents;
00053
00054 #ifdef SIN
00055 trans = sin_texinfo[s->texinfo].translucence;
00056 #else
00057 trans = texinfo[s->texinfo].flags;
00058 #endif
00059 for (i=1 ; i<b->numsides ; i++, s++)
00060 {
00061 s = &b->original_sides[i];
00062 #ifdef SIN
00063 trans += sin_texinfo[s->texinfo].translucence;
00064 #else
00065 trans |= texinfo[s->texinfo].flags;
00066 #endif
00067 if (s->contents != contents)
00068 {
00069 #ifdef SIN
00070 if (
00071 ( s->contents & CONTENTS_DETAIL && !(contents & CONTENTS_DETAIL) ) ||
00072 ( !(s->contents & CONTENTS_DETAIL) && contents & CONTENTS_DETAIL )
00073 )
00074 {
00075 s->contents |= CONTENTS_DETAIL;
00076 contents |= CONTENTS_DETAIL;
00077 continue;
00078 }
00079 #endif
00080 printf ("Entity %i, Brush %i: mixed face contents\n"
00081 , b->entitynum, b->brushnum);
00082 break;
00083 }
00084 }
00085
00086
00087 #ifdef SIN
00088 if (contents & CONTENTS_FENCE)
00089 {
00090 // contents |= CONTENTS_TRANSLUCENT;
00091 contents |= CONTENTS_DETAIL;
00092 contents |= CONTENTS_DUMMYFENCE;
00093 contents &= ~CONTENTS_SOLID;
00094 contents &= ~CONTENTS_FENCE;
00095 contents |= CONTENTS_WINDOW;
00096 }
00097 #endif
00098
00099 // if any side is translucent, mark the contents
00100 // and change solid to window
00101 #ifdef SIN
00102 if ( trans > 0 )
00103 #else
00104 if ( trans & (SURF_TRANS33|SURF_TRANS66) )
00105 #endif
00106 {
00107 contents |= CONTENTS_Q2TRANSLUCENT;
00108 if (contents & CONTENTS_SOLID)
00109 {
00110 contents &= ~CONTENTS_SOLID;
00111 contents |= CONTENTS_WINDOW;
00112 }
00113 }
00114
00115 return contents;
00116 } //*/
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 883 of file map_sin.c. References AAS_CreateMapBrushes(), b, BrushExists(), mapbrush_s::brushnum, brushsides, c_clipbrushes, c_squattbrushes, mapbrush_s::contents, sin_dbrush_t::contents, side_s::contents, CONTENTS_LAVA, CONTENTS_MONSTERCLIP, CONTENTS_PLAYERCLIP, CONTENTS_SLIME, dbrushleafnums, sin_dplane_t::dist, mapbrush_s::entitynum, Error(), FindFloatPlane(), entity_t::firstbrush, sin_dbrush_t::firstside, sin_texinfo_s::flags, side_s::flags, i, k, LAST_VISIBLE_CONTENTS, mapbrush_s::leafnum, Log_Print(), MakeBrushWindings(), mapbrush_t, mapbrushes, mapent, MarkBrushBevels(), n, nodetail, sin_dplane_t::normal, nowater, entity_t::numbrushes, nummapbrushes, nummapbrushsides, mapbrush_s::numsides, sin_dbrush_t::numsides, mapbrush_s::original_sides, side_s::planenum, sin_dbrushside_t::planenum, side_t, Sin_BrushContents(), sin_dbrushsides, sin_dbrushsidetextured, sin_dplanes, sin_texinfo, side_s::surf, SURF_HINT, SURF_TRANS33, side_s::texinfo, and sin_dbrushside_t::texinfo. Referenced by Sin_ParseBSPBrushes(). 00884 {
00885 mapbrush_t *b;
00886 int i, k, n;
00887 side_t *side, *s2;
00888 int planenum;
00889 sin_dbrushside_t *bspbrushside;
00890 sin_dplane_t *bspplane;
00891
00892 if (nummapbrushes >= MAX_MAPFILE_BRUSHES)
00893 Error ("nummapbrushes >= MAX_MAPFILE_BRUSHES");
00894
00895 b = &mapbrushes[nummapbrushes];
00896 b->original_sides = &brushsides[nummapbrushsides];
00897 b->entitynum = mapent-entities;
00898 b->brushnum = nummapbrushes - mapent->firstbrush;
00899 b->leafnum = dbrushleafnums[bspbrush - sin_dbrushes];
00900
00901 for (n = 0; n < bspbrush->numsides; n++)
00902 {
00903 //pointer to the bsp brush side
00904 bspbrushside = &sin_dbrushsides[bspbrush->firstside + n];
00905
00906 if (nummapbrushsides >= MAX_MAPFILE_BRUSHSIDES)
00907 {
00908 Error ("MAX_MAPFILE_BRUSHSIDES");
00909 } //end if
00910 //pointer to the map brush side
00911 side = &brushsides[nummapbrushsides];
00912 //if the BSP brush side is textured
00913 if (sin_dbrushsidetextured[bspbrush->firstside + n]) side->flags |= SFL_TEXTURED;
00914 else side->flags &= ~SFL_TEXTURED;
00915 //ME: can get side contents and surf directly from BSP file
00916 side->contents = bspbrush->contents;
00917 //if the texinfo is TEXINFO_NODE
00918 if (bspbrushside->texinfo < 0) side->surf = 0;
00919 else side->surf = sin_texinfo[bspbrushside->texinfo].flags;
00920
00921 // translucent objects are automatically classified as detail
00922 if (side->surf & (SURF_TRANS33|SURF_TRANS66) )
00923 side->contents |= CONTENTS_DETAIL;
00924 if (side->contents & (CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP) )
00925 side->contents |= CONTENTS_DETAIL;
00926 if (fulldetail)
00927 side->contents &= ~CONTENTS_DETAIL;
00928 if (!(side->contents & ((LAST_VISIBLE_CONTENTS-1)
00929 | CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP|CONTENTS_MIST) ) )
00930 side->contents |= CONTENTS_SOLID;
00931
00932 // hints and skips are never detail, and have no content
00933 if (side->surf & (SURF_HINT|SURF_SKIP) )
00934 {
00935 side->contents = 0;
00936 side->surf &= ~CONTENTS_DETAIL;
00937 }
00938
00939 //ME: get a plane for this side
00940 bspplane = &sin_dplanes[bspbrushside->planenum];
00941 planenum = FindFloatPlane(bspplane->normal, bspplane->dist);
00942 //
00943 // see if the plane has been used already
00944 //
00945 //ME: this really shouldn't happen!!!
00946 //ME: otherwise the bsp file is corrupted??
00947 //ME: still it seems to happen, maybe Johny Boy's
00948 //ME: brush bevel adding is crappy ?
00949 for (k = 0; k < b->numsides; k++)
00950 {
00951 s2 = b->original_sides + k;
00952 if (s2->planenum == planenum)
00953 {
00954 Log_Print("Entity %i, Brush %i: duplicate plane\n"
00955 , b->entitynum, b->brushnum);
00956 break;
00957 }
00958 if ( s2->planenum == (planenum^1) )
00959 {
00960 Log_Print("Entity %i, Brush %i: mirrored plane\n"
00961 , b->entitynum, b->brushnum);
00962 break;
00963 }
00964 }
00965 if (k != b->numsides)
00966 continue; // duplicated
00967
00968 //
00969 // keep this side
00970 //
00971 //ME: reset pointer to side, why? hell I dunno (pointer is set above already)
00972 side = b->original_sides + b->numsides;
00973 //ME: store the plane number
00974 side->planenum = planenum;
00975 //ME: texinfo is already stored when bsp is loaded
00976 //NOTE: check for TEXINFO_NODE, otherwise crash in Sin_BrushContents
00977 if (bspbrushside->texinfo < 0) side->texinfo = 0;
00978 else side->texinfo = bspbrushside->texinfo;
00979
00980 // save the td off in case there is an origin brush and we
00981 // have to recalculate the texinfo
00982 // ME: don't need to recalculate because it's already done
00983 // (for non-world entities) in the BSP file
00984 // side_brushtextures[nummapbrushsides] = td;
00985
00986 nummapbrushsides++;
00987 b->numsides++;
00988 } //end for
00989
00990 // get the content for the entire brush
00991 b->contents = bspbrush->contents;
00992 Sin_BrushContents(b);
00993
00994 if (BrushExists(b))
00995 {
00996 c_squattbrushes++;
00997 b->numsides = 0;
00998 return;
00999 } //end if
01000
01001 //if we're creating AAS
01002 if (create_aas)
01003 {
01004 //create the AAS brushes from this brush, don't add brush bevels
01005 AAS_CreateMapBrushes(b, mapent, false);
01006 return;
01007 } //end if
01008
01009 // allow detail brushes to be removed
01010 if (nodetail && (b->contents & CONTENTS_DETAIL) )
01011 {
01012 b->numsides = 0;
01013 return;
01014 } //end if
01015
01016 // allow water brushes to be removed
01017 if (nowater && (b->contents & (CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER)) )
01018 {
01019 b->numsides = 0;
01020 return;
01021 } //end if
01022
01023 // create windings for sides and bounds for brush
01024 MakeBrushWindings(b);
01025
01026 //mark brushes without winding or with a tiny window as bevels
01027 MarkBrushBevels(b);
01028
01029 // brushes that will not be visible at all will never be
01030 // used as bsp splitters
01031 if (b->contents & (CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP) )
01032 {
01033 c_clipbrushes++;
01034 for (i = 0; i < b->numsides; i++)
01035 b->original_sides[i].texinfo = TEXINFO_NODE;
01036 } //end for
01037
01038 //
01039 // origin brushes are removed, but they set
01040 // the rotation origin for the rest of the brushes
01041 // in the entity. After the entire entity is parsed,
01042 // the planenums and texinfos will be adjusted for
01043 // the origin brush
01044 //
01045 //ME: not needed because the entities in the BSP file already
01046 // have an origin set
01047 // if (b->contents & CONTENTS_ORIGIN)
01048 // {
01049 // char string[32];
01050 // vec3_t origin;
01051 //
01052 // if (num_entities == 1)
01053 // {
01054 // Error ("Entity %i, Brush %i: origin brushes not allowed in world"
01055 // , b->entitynum, b->brushnum);
01056 // return;
01057 // }
01058 //
01059 // VectorAdd (b->mins, b->maxs, origin);
01060 // VectorScale (origin, 0.5, origin);
01061 //
01062 // sprintf (string, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]);
01063 // SetKeyValue (&entities[b->entitynum], "origin", string);
01064 //
01065 // VectorCopy (origin, entities[b->entitynum].origin);
01066 //
01067 // // don't keep this brush
01068 // b->numsides = 0;
01069 //
01070 // return;
01071 // }
01072
01073 //ME: the bsp brushes already have bevels, so we won't try to
01074 // add them again (especially since Johny Boy's bevel adding might
01075 // be crappy)
01076 // AddBrushBevels(b);
01077
01078 nummapbrushes++;
01079 mapent->numbrushes++;
01080 } //end of the function Sin_BSPBrushToMapBrush
|
Here is the call graph for this function:

|
|
Definition at line 744 of file map_sin.c. References sin_texinfo_s::flags, map_texinfo_t::flags, i, map_texinfo, memcpy(), map_texinfo_t::nexttexinfo, sin_texinfo, strcpy(), texture, map_texinfo_t::value, vec_t, and vecs. Referenced by Sin_LoadMapFromBSP(). 00745 {
00746 int i;
00747 vec_t defaultvec[4] = {1, 0, 0, 0};
00748
00749 memcpy(map_texinfo[0].vecs[0], defaultvec, sizeof(defaultvec));
00750 memcpy(map_texinfo[0].vecs[1], defaultvec, sizeof(defaultvec));
00751 map_texinfo[0].flags = 0;
00752 map_texinfo[0].value = 0;
00753 strcpy(map_texinfo[0].texture, "generic/misc/red"); //no texture
00754 map_texinfo[0].nexttexinfo = -1;
00755 for (i = 1; i < sin_numtexinfo; i++)
00756 {
00757 memcpy(map_texinfo[i].vecs, sin_texinfo[i].vecs, sizeof(float) * 2 * 4);
00758 map_texinfo[i].flags = sin_texinfo[i].flags;
00759 map_texinfo[i].value = 0;
00760 strcpy(map_texinfo[i].texture, sin_texinfo[i].texture);
00761 map_texinfo[i].nexttexinfo = -1;
00762 } //end for
00763 } //end of the function Sin_CreateMapTexinfo
|
Here is the call graph for this function:

|
|
Definition at line 789 of file map_sin.c. References nodestackptr, and nodestacksize. Referenced by Sin_SetBrushModelNumbers(). 00790 {
00791 nodestackptr = nodestack;
00792 nodestacksize = 0;
00793 } //end of the function Sin_InitNodeStack
|
|
||||||||||||||||
|
Definition at line 1159 of file map_sin.c. References AddPointToBounds(), brushmodelnumbers, ClearBounds(), entities, i, length(), loadedmaptype, Log_Print(), map_maxs, map_mins, mapbrushes, mapbrush_s::mins, num_entities, entity_t::numbrushes, nummapbrushsides, offset, Sin_CreateMapTexinfo(), Sin_LoadBSPFile(), Sin_ParseBSPEntity(), and Sin_ParseEntities(). Referenced by LoadMapFromBSP(). 01160 {
01161 int i;
01162
01163 Log_Print("-- Sin_LoadMapFromBSP --\n");
01164 //loaded map type
01165 loadedmaptype = MAPTYPE_SIN;
01166
01167 Log_Print("Loading map from %s...\n", filename);
01168 //load the bsp file
01169 Sin_LoadBSPFile(filename, offset, length);
01170
01171 //create an index from bsp planes to map planes
01172 //DPlanes2MapPlanes();
01173 //clear brush model numbers
01174 for (i = 0; i < MAX_MAPFILE_BRUSHES; i++)
01175 brushmodelnumbers[i] = -1;
01176
01177 nummapbrushsides = 0;
01178 num_entities = 0;
01179
01180 Sin_ParseEntities();
01181 //
01182 for (i = 0; i < num_entities; i++)
01183 {
01184 Sin_ParseBSPEntity(i);
01185 } //end for
01186
01187 //get the map mins and maxs from the world model
01188 ClearBounds(map_mins, map_maxs);
01189 for (i = 0; i < entities[0].numbrushes; i++)
01190 {
01191 if (mapbrushes[i].mins[0] > 4096)
01192 continue; //no valid points
01193 AddPointToBounds (mapbrushes[i].mins, map_mins, map_maxs);
01194 AddPointToBounds (mapbrushes[i].maxs, map_mins, map_maxs);
01195 } //end for
01196 //
01197 Sin_CreateMapTexinfo();
01198 } //end of the function Sin_LoadMapFromBSP
|
Here is the call graph for this function:

|
|
Definition at line 1083 of file map_sin.c. References brushmodelnumbers, i, mapent, entity_t::modelnum, Sin_BSPBrushToMapBrush(), sin_dbrushes, and Sin_SetBrushModelNumbers(). Referenced by Sin_ParseBSPEntity(). 01084 {
01085 int i, testnum = 0;
01086
01087 //give all the brushes that belong to this entity the number of the
01088 //BSP model used by this entity
01089 Sin_SetBrushModelNumbers(mapent);
01090 //now parse all the brushes with the correct mapent->modelnum
01091 for (i = 0; i < sin_numbrushes; i++)
01092 {
01093 if (brushmodelnumbers[i] == mapent->modelnum)
01094 {
01095 testnum++;
01096 Sin_BSPBrushToMapBrush(&sin_dbrushes[i], mapent);
01097 } //end if
01098 } //end for
01099 } //end of the function Sin_ParseBSPBrushes
|
Here is the call graph for this function:

|
|
Definition at line 1102 of file map_sin.c. References entity_t::areaportalnum, atoi, c_areaportals, entities, entity_t::firstbrush, GetVectorForKey(), mapent, entity_t::modelnum, entity_t::numbrushes, entity_t::origin, qboolean, Sin_ParseBSPBrushes(), strcmp(), and ValueForKey(). Referenced by Sin_LoadMapFromBSP(). 01103 {
01104 entity_t *mapent;
01105 char *model;
01106 int startbrush, startsides;
01107
01108 startbrush = nummapbrushes;
01109 startsides = nummapbrushsides;
01110
01111 mapent = &entities[entnum];//num_entities];
01112 mapent->firstbrush = nummapbrushes;
01113 mapent->numbrushes = 0;
01114 mapent->modelnum = -1; //-1 = no model
01115
01116 model = ValueForKey(mapent, "model");
01117 if (model && *model == '*')
01118 {
01119 mapent->modelnum = atoi(&model[1]);
01120 //Log_Print("model = %s\n", model);
01121 //Log_Print("mapent->modelnum = %d\n", mapent->modelnum);
01122 } //end if
01123
01124 GetVectorForKey(mapent, "origin", mapent->origin);
01125
01126 //if this is the world entity it has model number zero
01127 //the world entity has no model key
01128 if (!strcmp("worldspawn", ValueForKey(mapent, "classname")))
01129 {
01130 mapent->modelnum = 0;
01131 } //end if
01132 //if the map entity has a BSP model (a modelnum of -1 is used for
01133 //entities that aren't using a BSP model)
01134 if (mapent->modelnum >= 0)
01135 {
01136 //parse the bsp brushes
01137 Sin_ParseBSPBrushes(mapent);
01138 } //end if
01139 //
01140 //the origin of the entity is already taken into account
01141 //
01142 //func_group entities can't be in the bsp file
01143 //
01144 //check out the func_areaportal entities
01145 if (!strcmp ("func_areaportal", ValueForKey (mapent, "classname")))
01146 {
01147 c_areaportals++;
01148 mapent->areaportalnum = c_areaportals;
01149 return true;
01150 } //end if
01151 return true;
01152 } //end of the function Sin_ParseBSPEntity
|
Here is the call graph for this function:

|
|
Definition at line 817 of file map_sin.c. References nodestackptr, and nodestacksize. Referenced by Sin_SetBrushModelNumbers(). 00818 {
00819 //if the stack is empty
00820 if (nodestackptr <= nodestack) return -1;
00821 //decrease stack pointer
00822 nodestackptr--;
00823 nodestacksize--;
00824 //return the top value from the stack
00825 return *nodestackptr;
00826 } //end of the function Sin_PopNodeStack
|
|
|
Definition at line 800 of file map_sin.c. References Error(), nodestack, nodestackptr, and nodestacksize. Referenced by Sin_SetBrushModelNumbers(). 00801 {
00802 *nodestackptr = num;
00803 nodestackptr++;
00804 nodestacksize++;
00805 //
00806 if (nodestackptr >= &nodestack[NODESTACKSIZE])
00807 {
00808 Error("Sin_PushNodeStack: stack overflow\n");
00809 } //end if
00810 } //end of the function Sin_PushNodeStack
|
Here is the call graph for this function:

|
|
Definition at line 1200 of file map_sin.c. References brushmodelnumbers, MAX_MAPFILE_BRUSHES, memset(), nodestack, nodestackptr, NODESTACKSIZE, and nodestacksize. Referenced by ResetMapLoading(). 01201 {
01202 //reset for map loading from bsp
01203 memset(nodestack, 0, NODESTACKSIZE * sizeof(int));
01204 nodestackptr = NULL;
01205 nodestacksize = 0;
01206 memset(brushmodelnumbers, 0, MAX_MAPFILE_BRUSHES * sizeof(int));
01207 } //end of the function Sin_ResetMapLoading
|
Here is the call graph for this function:

|
|
Definition at line 833 of file map_sin.c. References sin_dnode_t::children, sin_dmodel_t::headnode, mapent, entity_t::modelnum, n, sin_dmodels, sin_dnodes, Sin_InitNodeStack(), Sin_PopNodeStack(), Sin_PushNodeStack(), and Sin_SetLeafBrushesModelNumbers(). Referenced by Sin_ParseBSPBrushes(). 00834 {
00835 int n, pn;
00836 int leafnum;
00837
00838 //
00839 Sin_InitNodeStack();
00840 //head node (root) of the bsp tree
00841 n = sin_dmodels[mapent->modelnum].headnode;
00842 pn = 0;
00843
00844 do
00845 {
00846 //if we are in a leaf (negative node number)
00847 if (n < 0)
00848 {
00849 //number of the leaf
00850 leafnum = (-n) - 1;
00851 //set the brush numbers
00852 Sin_SetLeafBrushesModelNumbers(leafnum, mapent->modelnum);
00853 //walk back into the tree to find a second child to continue with
00854 for (pn = Sin_PopNodeStack(); pn >= 0; n = pn, pn = Sin_PopNodeStack())
00855 {
00856 //if we took the first child at the parent node
00857 if (sin_dnodes[pn].children[0] == n) break;
00858 } //end for
00859 //if the stack wasn't empty (if not processed whole tree)
00860 if (pn >= 0)
00861 {
00862 //push the parent node again
00863 Sin_PushNodeStack(pn);
00864 //we proceed with the second child of the parent node
00865 n = sin_dnodes[pn].children[1];
00866 } //end if
00867 } //end if
00868 else
00869 {
00870 //push the current node onto the stack
00871 Sin_PushNodeStack(n);
00872 //walk forward into the tree to the first child
00873 n = sin_dnodes[n].children[0];
00874 } //end else
00875 } while(pn >= 0);
00876 } //end of the function Sin_SetBrushModelNumbers
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 770 of file map_sin.c. References brushmodelnumbers, dbrushleafnums, sin_dleaf_t::firstleafbrush, i, sin_dleaf_t::numleafbrushes, sin_dleafbrushes, and sin_dleafs. Referenced by Sin_SetBrushModelNumbers(). 00771 {
00772 int i, brushnum;
00773 sin_dleaf_t *leaf;
00774
00775 leaf = &sin_dleafs[leafnum];
00776 for (i = 0; i < leaf->numleafbrushes; i++)
00777 {
00778 brushnum = sin_dleafbrushes[leaf->firstleafbrush + i];
00779 brushmodelnumbers[brushnum] = modelnum;
00780 dbrushleafnums[brushnum] = leafnum;
00781 } //end for
00782 } //end of the function Sin_SetLeafBrushesModelNumbers
|
1.3.9.1