From c7ddc423f67236a99956960cf9fe89abf077839b Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 5 Sep 2008 00:02:14 +0000 Subject: Reformat (beautify) Raven sources and add GPL headers. Subversion-branch: /branches/raven-branch Subversion-revision: 1197 --- src/heretic/p_setup.c | 890 ++++++++++++++++++++++++++------------------------ 1 file changed, 456 insertions(+), 434 deletions(-) (limited to 'src/heretic/p_setup.c') diff --git a/src/heretic/p_setup.c b/src/heretic/p_setup.c index a704e7b0..35797fbe 100644 --- a/src/heretic/p_setup.c +++ b/src/heretic/p_setup.c @@ -1,3 +1,25 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright(C) 1993-1996 Id Software, Inc. +// Copyright(C) 1993-2008 Raven Software +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +//----------------------------------------------------------------------------- // P_main.c @@ -7,39 +29,39 @@ #include "P_local.h" #include "soundst.h" -void P_SpawnMapThing (mapthing_t *mthing); +void P_SpawnMapThing(mapthing_t * mthing); -int numvertexes; -vertex_t *vertexes; +int numvertexes; +vertex_t *vertexes; -int numsegs; -seg_t *segs; +int numsegs; +seg_t *segs; -int numsectors; -sector_t *sectors; +int numsectors; +sector_t *sectors; -int numsubsectors; -subsector_t *subsectors; +int numsubsectors; +subsector_t *subsectors; -int numnodes; -node_t *nodes; +int numnodes; +node_t *nodes; -int numlines; -line_t *lines; +int numlines; +line_t *lines; -int numsides; -side_t *sides; +int numsides; +side_t *sides; -short *blockmaplump; // offsets in blockmap are from here -short *blockmap; -int bmapwidth, bmapheight; // in mapblocks -fixed_t bmaporgx, bmaporgy; // origin of block map -mobj_t **blocklinks; // for thing chains +short *blockmaplump; // offsets in blockmap are from here +short *blockmap; +int bmapwidth, bmapheight; // in mapblocks +fixed_t bmaporgx, bmaporgy; // origin of block map +mobj_t **blocklinks; // for thing chains -byte *rejectmatrix; // for fast sight rejection +byte *rejectmatrix; // for fast sight rejection -mapthing_t deathmatchstarts[10], *deathmatch_p; -mapthing_t playerstarts[MAXPLAYERS]; +mapthing_t deathmatchstarts[10], *deathmatch_p; +mapthing_t playerstarts[MAXPLAYERS]; /* ================= @@ -49,26 +71,26 @@ mapthing_t playerstarts[MAXPLAYERS]; ================= */ -void P_LoadVertexes (int lump) +void P_LoadVertexes(int lump) { - byte *data; - int i; - mapvertex_t *ml; - vertex_t *li; - - numvertexes = W_LumpLength (lump) / sizeof(mapvertex_t); - vertexes = Z_Malloc (numvertexes*sizeof(vertex_t),PU_LEVEL,0); - data = W_CacheLumpNum (lump,PU_STATIC); - - ml = (mapvertex_t *)data; - li = vertexes; - for (i=0 ; ix = SHORT(ml->x)<y = SHORT(ml->y)<x = SHORT(ml->x) << FRACBITS; + li->y = SHORT(ml->y) << FRACBITS; + } + + Z_Free(data); } @@ -80,42 +102,42 @@ void P_LoadVertexes (int lump) ================= */ -void P_LoadSegs (int lump) +void P_LoadSegs(int lump) { - byte *data; - int i; - mapseg_t *ml; - seg_t *li; - line_t *ldef; - int linedef, side; - - numsegs = W_LumpLength (lump) / sizeof(mapseg_t); - segs = Z_Malloc (numsegs*sizeof(seg_t),PU_LEVEL,0); - memset (segs, 0, numsegs*sizeof(seg_t)); - data = W_CacheLumpNum (lump,PU_STATIC); - - ml = (mapseg_t *)data; - li = segs; - for (i=0 ; iv1 = &vertexes[SHORT(ml->v1)]; - li->v2 = &vertexes[SHORT(ml->v2)]; - - li->angle = (SHORT(ml->angle))<<16; - li->offset = (SHORT(ml->offset))<<16; - linedef = SHORT(ml->linedef); - ldef = &lines[linedef]; - li->linedef = ldef; - side = SHORT(ml->side); - li->sidedef = &sides[ldef->sidenum[side]]; - li->frontsector = sides[ldef->sidenum[side]].sector; - if (ldef-> flags & ML_TWOSIDED) - li->backsector = sides[ldef->sidenum[side^1]].sector; - else - li->backsector = 0; - } - - Z_Free (data); + byte *data; + int i; + mapseg_t *ml; + seg_t *li; + line_t *ldef; + int linedef, side; + + numsegs = W_LumpLength(lump) / sizeof(mapseg_t); + segs = Z_Malloc(numsegs * sizeof(seg_t), PU_LEVEL, 0); + memset(segs, 0, numsegs * sizeof(seg_t)); + data = W_CacheLumpNum(lump, PU_STATIC); + + ml = (mapseg_t *) data; + li = segs; + for (i = 0; i < numsegs; i++, li++, ml++) + { + li->v1 = &vertexes[SHORT(ml->v1)]; + li->v2 = &vertexes[SHORT(ml->v2)]; + + li->angle = (SHORT(ml->angle)) << 16; + li->offset = (SHORT(ml->offset)) << 16; + linedef = SHORT(ml->linedef); + ldef = &lines[linedef]; + li->linedef = ldef; + side = SHORT(ml->side); + li->sidedef = &sides[ldef->sidenum[side]]; + li->frontsector = sides[ldef->sidenum[side]].sector; + if (ldef->flags & ML_TWOSIDED) + li->backsector = sides[ldef->sidenum[side ^ 1]].sector; + else + li->backsector = 0; + } + + Z_Free(data); } @@ -127,27 +149,27 @@ void P_LoadSegs (int lump) ================= */ -void P_LoadSubsectors (int lump) +void P_LoadSubsectors(int lump) { - byte *data; - int i; - mapsubsector_t *ms; - subsector_t *ss; - - numsubsectors = W_LumpLength (lump) / sizeof(mapsubsector_t); - subsectors = Z_Malloc (numsubsectors*sizeof(subsector_t),PU_LEVEL,0); - data = W_CacheLumpNum (lump,PU_STATIC); - - ms = (mapsubsector_t *)data; - memset (subsectors,0, numsubsectors*sizeof(subsector_t)); - ss = subsectors; - for (i=0 ; inumlines = SHORT(ms->numsegs); - ss->firstline = SHORT(ms->firstseg); - } - - Z_Free (data); + byte *data; + int i; + mapsubsector_t *ms; + subsector_t *ss; + + numsubsectors = W_LumpLength(lump) / sizeof(mapsubsector_t); + subsectors = Z_Malloc(numsubsectors * sizeof(subsector_t), PU_LEVEL, 0); + data = W_CacheLumpNum(lump, PU_STATIC); + + ms = (mapsubsector_t *) data; + memset(subsectors, 0, numsubsectors * sizeof(subsector_t)); + ss = subsectors; + for (i = 0; i < numsubsectors; i++, ss++, ms++) + { + ss->numlines = SHORT(ms->numsegs); + ss->firstline = SHORT(ms->firstseg); + } + + Z_Free(data); } @@ -159,33 +181,33 @@ void P_LoadSubsectors (int lump) ================= */ -void P_LoadSectors (int lump) +void P_LoadSectors(int lump) { - byte *data; - int i; - mapsector_t *ms; - sector_t *ss; - - numsectors = W_LumpLength (lump) / sizeof(mapsector_t); - sectors = Z_Malloc (numsectors*sizeof(sector_t),PU_LEVEL,0); - memset (sectors, 0, numsectors*sizeof(sector_t)); - data = W_CacheLumpNum (lump,PU_STATIC); - - ms = (mapsector_t *)data; - ss = sectors; - for (i=0 ; ifloorheight = SHORT(ms->floorheight)<ceilingheight = SHORT(ms->ceilingheight)<floorpic = R_FlatNumForName(ms->floorpic); - ss->ceilingpic = R_FlatNumForName(ms->ceilingpic); - ss->lightlevel = SHORT(ms->lightlevel); - ss->special = SHORT(ms->special); - ss->tag = SHORT(ms->tag); - ss->thinglist = NULL; - } - - Z_Free (data); + byte *data; + int i; + mapsector_t *ms; + sector_t *ss; + + numsectors = W_LumpLength(lump) / sizeof(mapsector_t); + sectors = Z_Malloc(numsectors * sizeof(sector_t), PU_LEVEL, 0); + memset(sectors, 0, numsectors * sizeof(sector_t)); + data = W_CacheLumpNum(lump, PU_STATIC); + + ms = (mapsector_t *) data; + ss = sectors; + for (i = 0; i < numsectors; i++, ss++, ms++) + { + ss->floorheight = SHORT(ms->floorheight) << FRACBITS; + ss->ceilingheight = SHORT(ms->ceilingheight) << FRACBITS; + ss->floorpic = R_FlatNumForName(ms->floorpic); + ss->ceilingpic = R_FlatNumForName(ms->ceilingpic); + ss->lightlevel = SHORT(ms->lightlevel); + ss->special = SHORT(ms->special); + ss->tag = SHORT(ms->tag); + ss->thinglist = NULL; + } + + Z_Free(data); } @@ -197,34 +219,34 @@ void P_LoadSectors (int lump) ================= */ -void P_LoadNodes (int lump) +void P_LoadNodes(int lump) { - byte *data; - int i,j,k; - mapnode_t *mn; - node_t *no; - - numnodes = W_LumpLength (lump) / sizeof(mapnode_t); - nodes = Z_Malloc (numnodes*sizeof(node_t),PU_LEVEL,0); - data = W_CacheLumpNum (lump,PU_STATIC); - - mn = (mapnode_t *)data; - no = nodes; - for (i=0 ; ix = SHORT(mn->x)<y = SHORT(mn->y)<dx = SHORT(mn->dx)<dy = SHORT(mn->dy)<children[j] = SHORT(mn->children[j]); - for (k=0 ; k<4 ; k++) - no->bbox[j][k] = SHORT(mn->bbox[j][k])<x = SHORT(mn->x) << FRACBITS; + no->y = SHORT(mn->y) << FRACBITS; + no->dx = SHORT(mn->dx) << FRACBITS; + no->dy = SHORT(mn->dy) << FRACBITS; + for (j = 0; j < 2; j++) + { + no->children[j] = SHORT(mn->children[j]); + for (k = 0; k < 4; k++) + no->bbox[j][k] = SHORT(mn->bbox[j][k]) << FRACBITS; + } + } + + Z_Free(data); } @@ -237,28 +259,28 @@ void P_LoadNodes (int lump) ================= */ -void P_LoadThings (int lump) +void P_LoadThings(int lump) { - byte *data; - int i; - mapthing_t *mt; - int numthings; - - data = W_CacheLumpNum (lump,PU_STATIC); - numthings = W_LumpLength (lump) / sizeof(mapthing_t); - - mt = (mapthing_t *)data; - for (i=0 ; ix = SHORT(mt->x); - mt->y = SHORT(mt->y); - mt->angle = SHORT(mt->angle); - mt->type = SHORT(mt->type); - mt->options = SHORT(mt->options); - P_SpawnMapThing (mt); - } - - Z_Free (data); + byte *data; + int i; + mapthing_t *mt; + int numthings; + + data = W_CacheLumpNum(lump, PU_STATIC); + numthings = W_LumpLength(lump) / sizeof(mapthing_t); + + mt = (mapthing_t *) data; + for (i = 0; i < numthings; i++, mt++) + { + mt->x = SHORT(mt->x); + mt->y = SHORT(mt->y); + mt->angle = SHORT(mt->angle); + mt->type = SHORT(mt->type); + mt->options = SHORT(mt->options); + P_SpawnMapThing(mt); + } + + Z_Free(data); } @@ -272,75 +294,75 @@ void P_LoadThings (int lump) ================= */ -void P_LoadLineDefs (int lump) +void P_LoadLineDefs(int lump) { - byte *data; - int i; - maplinedef_t *mld; - line_t *ld; - vertex_t *v1, *v2; - - numlines = W_LumpLength (lump) / sizeof(maplinedef_t); - lines = Z_Malloc (numlines*sizeof(line_t),PU_LEVEL,0); - memset (lines, 0, numlines*sizeof(line_t)); - data = W_CacheLumpNum (lump,PU_STATIC); - - mld = (maplinedef_t *)data; - ld = lines; - for (i=0 ; iflags = SHORT(mld->flags); - ld->special = SHORT(mld->special); - ld->tag = SHORT(mld->tag); - v1 = ld->v1 = &vertexes[SHORT(mld->v1)]; - v2 = ld->v2 = &vertexes[SHORT(mld->v2)]; - ld->dx = v2->x - v1->x; - ld->dy = v2->y - v1->y; - if (!ld->dx) - ld->slopetype = ST_VERTICAL; - else if (!ld->dy) - ld->slopetype = ST_HORIZONTAL; - else - { - if (FixedDiv (ld->dy , ld->dx) > 0) - ld->slopetype = ST_POSITIVE; - else - ld->slopetype = ST_NEGATIVE; - } - - if (v1->x < v2->x) - { - ld->bbox[BOXLEFT] = v1->x; - ld->bbox[BOXRIGHT] = v2->x; - } - else - { - ld->bbox[BOXLEFT] = v2->x; - ld->bbox[BOXRIGHT] = v1->x; - } - if (v1->y < v2->y) - { - ld->bbox[BOXBOTTOM] = v1->y; - ld->bbox[BOXTOP] = v2->y; - } - else - { - ld->bbox[BOXBOTTOM] = v2->y; - ld->bbox[BOXTOP] = v1->y; - } - ld->sidenum[0] = SHORT(mld->sidenum[0]); - ld->sidenum[1] = SHORT(mld->sidenum[1]); - if (ld->sidenum[0] != -1) - ld->frontsector = sides[ld->sidenum[0]].sector; - else - ld->frontsector = 0; - if (ld->sidenum[1] != -1) - ld->backsector = sides[ld->sidenum[1]].sector; - else - ld->backsector = 0; - } - - Z_Free (data); + byte *data; + int i; + maplinedef_t *mld; + line_t *ld; + vertex_t *v1, *v2; + + numlines = W_LumpLength(lump) / sizeof(maplinedef_t); + lines = Z_Malloc(numlines * sizeof(line_t), PU_LEVEL, 0); + memset(lines, 0, numlines * sizeof(line_t)); + data = W_CacheLumpNum(lump, PU_STATIC); + + mld = (maplinedef_t *) data; + ld = lines; + for (i = 0; i < numlines; i++, mld++, ld++) + { + ld->flags = SHORT(mld->flags); + ld->special = SHORT(mld->special); + ld->tag = SHORT(mld->tag); + v1 = ld->v1 = &vertexes[SHORT(mld->v1)]; + v2 = ld->v2 = &vertexes[SHORT(mld->v2)]; + ld->dx = v2->x - v1->x; + ld->dy = v2->y - v1->y; + if (!ld->dx) + ld->slopetype = ST_VERTICAL; + else if (!ld->dy) + ld->slopetype = ST_HORIZONTAL; + else + { + if (FixedDiv(ld->dy, ld->dx) > 0) + ld->slopetype = ST_POSITIVE; + else + ld->slopetype = ST_NEGATIVE; + } + + if (v1->x < v2->x) + { + ld->bbox[BOXLEFT] = v1->x; + ld->bbox[BOXRIGHT] = v2->x; + } + else + { + ld->bbox[BOXLEFT] = v2->x; + ld->bbox[BOXRIGHT] = v1->x; + } + if (v1->y < v2->y) + { + ld->bbox[BOXBOTTOM] = v1->y; + ld->bbox[BOXTOP] = v2->y; + } + else + { + ld->bbox[BOXBOTTOM] = v2->y; + ld->bbox[BOXTOP] = v1->y; + } + ld->sidenum[0] = SHORT(mld->sidenum[0]); + ld->sidenum[1] = SHORT(mld->sidenum[1]); + if (ld->sidenum[0] != -1) + ld->frontsector = sides[ld->sidenum[0]].sector; + else + ld->frontsector = 0; + if (ld->sidenum[1] != -1) + ld->backsector = sides[ld->sidenum[1]].sector; + else + ld->backsector = 0; + } + + Z_Free(data); } @@ -352,31 +374,31 @@ void P_LoadLineDefs (int lump) ================= */ -void P_LoadSideDefs (int lump) +void P_LoadSideDefs(int lump) { - byte *data; - int i; - mapsidedef_t *msd; - side_t *sd; - - numsides = W_LumpLength (lump) / sizeof(mapsidedef_t); - sides = Z_Malloc (numsides*sizeof(side_t),PU_LEVEL,0); - memset (sides, 0, numsides*sizeof(side_t)); - data = W_CacheLumpNum (lump,PU_STATIC); - - msd = (mapsidedef_t *)data; - sd = sides; - for (i=0 ; itextureoffset = SHORT(msd->textureoffset)<rowoffset = SHORT(msd->rowoffset)<toptexture = R_TextureNumForName(msd->toptexture); - sd->bottomtexture = R_TextureNumForName(msd->bottomtexture); - sd->midtexture = R_TextureNumForName(msd->midtexture); - sd->sector = §ors[SHORT(msd->sector)]; - } - - Z_Free (data); + byte *data; + int i; + mapsidedef_t *msd; + side_t *sd; + + numsides = W_LumpLength(lump) / sizeof(mapsidedef_t); + sides = Z_Malloc(numsides * sizeof(side_t), PU_LEVEL, 0); + memset(sides, 0, numsides * sizeof(side_t)); + data = W_CacheLumpNum(lump, PU_STATIC); + + msd = (mapsidedef_t *) data; + sd = sides; + for (i = 0; i < numsides; i++, msd++, sd++) + { + sd->textureoffset = SHORT(msd->textureoffset) << FRACBITS; + sd->rowoffset = SHORT(msd->rowoffset) << FRACBITS; + sd->toptexture = R_TextureNumForName(msd->toptexture); + sd->bottomtexture = R_TextureNumForName(msd->bottomtexture); + sd->midtexture = R_TextureNumForName(msd->midtexture); + sd->sector = §ors[SHORT(msd->sector)]; + } + + Z_Free(data); } @@ -389,25 +411,25 @@ void P_LoadSideDefs (int lump) ================= */ -void P_LoadBlockMap (int lump) +void P_LoadBlockMap(int lump) { - int i, count; - - blockmaplump = W_CacheLumpNum (lump,PU_LEVEL); - blockmap = blockmaplump+4; - count = W_LumpLength (lump)/2; - for (i=0 ; ifirstline]; - ss->sector = seg->sidedef->sector; - } + ss = subsectors; + for (i = 0; i < numsubsectors; i++, ss++) + { + seg = &segs[ss->firstline]; + ss->sector = seg->sidedef->sector; + } // count number of lines in each sector - li = lines; - total = 0; - for (i=0 ; ifrontsector->linecount++; - if (li->backsector && li->backsector != li->frontsector) - { - li->backsector->linecount++; - total++; - } - } - -// build line tables for each sector - linebuffer = Z_Malloc (total*4, PU_LEVEL, 0); - sector = sectors; - for (i=0 ; ilines = linebuffer; - li = lines; - for (j=0 ; jfrontsector == sector || li->backsector == sector) - { - *linebuffer++ = li; - M_AddToBox (bbox, li->v1->x, li->v1->y); - M_AddToBox (bbox, li->v2->x, li->v2->y); - } - } - if (linebuffer - sector->lines != sector->linecount) - I_Error ("P_GroupLines: miscounted"); - - // set the degenmobj_t to the middle of the bounding box - sector->soundorg.x = (bbox[BOXRIGHT]+bbox[BOXLEFT])/2; - sector->soundorg.y = (bbox[BOXTOP]+bbox[BOXBOTTOM])/2; - - // adjust bounding box to map blocks - block = (bbox[BOXTOP]-bmaporgy+MAXRADIUS)>>MAPBLOCKSHIFT; - block = block >= bmapheight ? bmapheight-1 : block; - sector->blockbox[BOXTOP]=block; - - block = (bbox[BOXBOTTOM]-bmaporgy-MAXRADIUS)>>MAPBLOCKSHIFT; - block = block < 0 ? 0 : block; - sector->blockbox[BOXBOTTOM]=block; - - block = (bbox[BOXRIGHT]-bmaporgx+MAXRADIUS)>>MAPBLOCKSHIFT; - block = block >= bmapwidth ? bmapwidth-1 : block; - sector->blockbox[BOXRIGHT]=block; - - block = (bbox[BOXLEFT]-bmaporgx-MAXRADIUS)>>MAPBLOCKSHIFT; - block = block < 0 ? 0 : block; - sector->blockbox[BOXLEFT]=block; - } - + li = lines; + total = 0; + for (i = 0; i < numlines; i++, li++) + { + total++; + li->frontsector->linecount++; + if (li->backsector && li->backsector != li->frontsector) + { + li->backsector->linecount++; + total++; + } + } + +// build line tables for each sector + linebuffer = Z_Malloc(total * 4, PU_LEVEL, 0); + sector = sectors; + for (i = 0; i < numsectors; i++, sector++) + { + M_ClearBox(bbox); + sector->lines = linebuffer; + li = lines; + for (j = 0; j < numlines; j++, li++) + { + if (li->frontsector == sector || li->backsector == sector) + { + *linebuffer++ = li; + M_AddToBox(bbox, li->v1->x, li->v1->y); + M_AddToBox(bbox, li->v2->x, li->v2->y); + } + } + if (linebuffer - sector->lines != sector->linecount) + I_Error("P_GroupLines: miscounted"); + + // set the degenmobj_t to the middle of the bounding box + sector->soundorg.x = (bbox[BOXRIGHT] + bbox[BOXLEFT]) / 2; + sector->soundorg.y = (bbox[BOXTOP] + bbox[BOXBOTTOM]) / 2; + + // adjust bounding box to map blocks + block = (bbox[BOXTOP] - bmaporgy + MAXRADIUS) >> MAPBLOCKSHIFT; + block = block >= bmapheight ? bmapheight - 1 : block; + sector->blockbox[BOXTOP] = block; + + block = (bbox[BOXBOTTOM] - bmaporgy - MAXRADIUS) >> MAPBLOCKSHIFT; + block = block < 0 ? 0 : block; + sector->blockbox[BOXBOTTOM] = block; + + block = (bbox[BOXRIGHT] - bmaporgx + MAXRADIUS) >> MAPBLOCKSHIFT; + block = block >= bmapwidth ? bmapwidth - 1 : block; + sector->blockbox[BOXRIGHT] = block; + + block = (bbox[BOXLEFT] - bmaporgx - MAXRADIUS) >> MAPBLOCKSHIFT; + block = block < 0 ? 0 : block; + sector->blockbox[BOXLEFT] = block; + } + } //============================================================================= @@ -511,95 +533,95 @@ void P_GroupLines (void) ================= */ -void P_SetupLevel (int episode, int map, int playermask, skill_t skill) +void P_SetupLevel(int episode, int map, int playermask, skill_t skill) { - int i; - int parm; - char lumpname[9]; - int lumpnum; - mobj_t *mobj; - - totalkills = totalitems = totalsecret = 0; - for (i=0 ; i