doom

a minimalistic implementation of doom
git clone git://ssnf.xyz/doom
Log | Files | Refs

commit 0ff58e8b175a51562047958b47886003a2657f3e
parent a6a242a3ee0286eb47cdbe5bce3d80eaa870c39f
Author: ssnf <ssnf@ssnf.xyz>
Date:   Mon, 21 Jun 2021 01:12:00 +0000

first playable build

Diffstat:
Msrc/p_setup.c | 727+++++++++++++++++++++++++++++++++++++------------------------------------------
1 file changed, 336 insertions(+), 391 deletions(-)

diff --git a/src/p_setup.c b/src/p_setup.c @@ -1,6 +1,7 @@ #include <math.h> -#include "z_zone.h" + #include "m_swap.h" +#include "z_zone.h" #include "m_bbox.h" #include "g_game.h" #include "i_system.h" @@ -9,9 +10,11 @@ #include "p_local.h" #include "s_sound.h" #include "doomstat.h" -void P_SpawnMapThing (mapthing_t* mthing); -int numvertexes; -vertex_t* vertexes; + +#define MAX_DEATHMATCH_STARTS 10 + +vertex_t* vertexes; +int numvertexes; int numsegs; seg_t* segs; int numsectors; @@ -25,431 +28,373 @@ line_t* lines; int numsides; side_t* sides; int bmapwidth; -int bmapheight; -short* blockmap; -short* blockmaplump; +int bmapheight; +short* blockmap; +short* blockmaplump; fixed_t bmaporgx; fixed_t bmaporgy; -mobj_t** blocklinks; +mobj_t** blocklinks; byte* rejectmatrix; -#define MAX_DEATHMATCH_STARTS 10 mapthing_t deathmatchstarts[MAX_DEATHMATCH_STARTS]; mapthing_t* deathmatch_p; mapthing_t playerstarts[MAXPLAYERS]; -void P_LoadVertexes (int lump) + +void P_SpawnMapThing(mapthing_t* mthing); + +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 ; i<numvertexes ; i++, li++, ml++) - { - li->x = SHORT(ml->x)<<FRACBITS; - li->y = SHORT(ml->y)<<FRACBITS; - } - Z_Free (data); + mapvertex_t* ml; + vertex_t* li; + byte* data; + int i; + + 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; i < numvertexes; ++i, ++li, ++ml) { + li->x = SHORT(ml->x)<<FRACBITS; + li->y = SHORT(ml->y)<<FRACBITS; + } + Z_Free(data); } -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; - int 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); + byte* data; + mapseg_t* ml; + seg_t* li; + line_t* ldef; + int i, 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); } -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 ; i<numsubsectors ; i++, ss++, ms++) - { - ss->numlines = SHORT(ms->numsegs); - ss->firstline = SHORT(ms->firstseg); - } - Z_Free (data); + mapsubsector_t* ms; + subsector_t* ss; + byte* data; + int i; + + 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); } -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 ; 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); + mapsector_t* ms; + sector_t* ss; + byte* data; + int i; + + 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); } -void P_LoadNodes (int lump) + +void +P_LoadNodes(int lump) { - byte* data; - int i; - int j; - int 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 ; i<numnodes ; i++, no++, mn++) - { - no->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; + byte* data; + mapnode_t* mn; + node_t* no; + int i, j, k; + + 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; i < numnodes; ++i, ++no, ++mn) { + no->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); + Z_Free(data); } -void P_LoadThings (int lump) + +void +P_LoadThings(int lump) { - byte* data; - int i; - mapthing_t* mt; - int numthings; - boolean spawn; - data = W_CacheLumpNum (lump,PU_STATIC); - numthings = W_LumpLength (lump) / sizeof(mapthing_t); - mt = (mapthing_t *)data; - for (i=0 ; i<numthings ; i++, mt++) - { - spawn = true; - if ( gamemode != commercial) - { - switch(mt->type) - { - case 68: - case 64: - case 88: - case 89: - case 69: - case 67: - case 71: - case 65: - case 66: - case 84: - spawn = false; - break; - } + mapthing_t* mt; + byte* data; + int i, numthings; + boolean spawn; + data = W_CacheLumpNum(lump, PU_STATIC); + + numthings = W_LumpLength(lump) / sizeof(mapthing_t); + mt = (mapthing_t *)data; + for (i = 0; i < numthings; ++i, ++mt) { + spawn = true; + if(spawn == false) break; + 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); } - if (spawn == false) - break; - 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); + Z_Free(data); } -void P_LoadLineDefs (int lump) + +void +P_LoadLineDefs(int lump) { - byte* data; - int i; - maplinedef_t* mld; - line_t* ld; - vertex_t* v1; - vertex_t* 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; + line_t* ld; + vertex_t* v1; + vertex_t* v2; + byte* data; + int i; + maplinedef_t* mld; + + 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; } - 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); + Z_Free(data); } -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 ; 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 = &sectors[SHORT(msd->sector)]; - } - Z_Free (data); + mapsidedef_t* msd; + side_t* sd; + byte* data; + int i; + + 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 = &sectors[SHORT(msd->sector)]; + } + Z_Free(data); } -void P_LoadBlockMap (int lump) + +void +P_LoadBlockMap(int lump) { - int i; - int count; - blockmaplump = W_CacheLumpNum (lump,PU_LEVEL); - blockmap = blockmaplump+4; - count = W_LumpLength (lump)/2; - for (i=0 ; i<count ; i++) - blockmaplump[i] = SHORT(blockmaplump[i]); - bmaporgx = blockmaplump[0]<<FRACBITS; - bmaporgy = blockmaplump[1]<<FRACBITS; - bmapwidth = blockmaplump[2]; - bmapheight = blockmaplump[3]; - count = sizeof(*blocklinks)* bmapwidth*bmapheight; - blocklinks = Z_Malloc (count,PU_LEVEL, 0); - memset (blocklinks, 0, count); + int i, count; + + blockmaplump = W_CacheLumpNum(lump,PU_LEVEL); + blockmap = blockmaplump+4; + count = W_LumpLength(lump)/2; + for (i = 0 ; i < count ; ++i) blockmaplump[i] = SHORT(blockmaplump[i]); + bmaporgx = blockmaplump[0]<<FRACBITS; + bmaporgy = blockmaplump[1]<<FRACBITS; + bmapwidth = blockmaplump[2]; + bmapheight = blockmaplump[3]; + count = sizeof(*blocklinks) * bmapwidth*bmapheight; + blocklinks = Z_Malloc(count,PU_LEVEL, 0); + memset(blocklinks, 0, count); } -void P_GroupLines (void) + +void +P_GroupLines() { - line_t** linebuffer; - int i; - int j; - int total; - line_t* li; - sector_t* sector; - subsector_t* ss; - seg_t* seg; - fixed_t bbox[4]; - int block; - ss = subsectors; - for (i=0 ; i<numsubsectors ; i++, ss++) - { - seg = &segs[ss->firstline]; - ss->sector = seg->sidedef->sector; - } - 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++; + line_t** linebuffer; + line_t* li; + sector_t* sector; + subsector_t* ss; + seg_t* seg; + fixed_t bbox[4]; + int i, j , total, block; + + ss = subsectors; + for (i = 0; i < numsubsectors; ++i, ++ss) { + seg = &segs[ss->firstline]; + ss->sector = seg->sidedef->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); - } + total = 0; + for (i = 0; i < numlines; ++i, ++li) { + ++total; + ++li->frontsector->linecount; + if (li->backsector && li->backsector != li->frontsector) { + ++total; + ++li->backsector->linecount; + } + } + linebuffer = Z_Malloc(total * 4 * 4, PU_LEVEL, 0); /* todo: figure out proper size */ + 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"); + sector->soundorg.x = (bbox[BOXRIGHT]+bbox[BOXLEFT])/2; + sector->soundorg.y = (bbox[BOXTOP]+bbox[BOXBOTTOM])/2; + 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; } - if (linebuffer - sector->lines != sector->linecount) - I_Error ("P_GroupLines: miscounted"); - sector->soundorg.x = (bbox[BOXRIGHT]+bbox[BOXLEFT])/2; - sector->soundorg.y = (bbox[BOXTOP]+bbox[BOXBOTTOM])/2; - 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; - } } + void -P_SetupLevel -( int episode, - int map, - int playermask, - skill_t skill) +P_SetupLevel(int episode, int map, int playermask, skill_t skill) { - int i; - char lumpname[9]; - int lumpnum; - totalkills = totalitems = totalsecret = wminfo.maxfrags = 0; - wminfo.partime = 180; - for (i=0 ; i<MAXPLAYERS ; i++) - { - players[i].killcount = players[i].secretcount - = players[i].itemcount = 0; - } - players[consoleplayer].viewz = 1; - S_Start (); -#if 0 - if (debugfile) - { - Z_FreeTags (PU_LEVEL, MAXINT); - Z_FileDumpHeap (debugfile); - } - else -#endif - Z_FreeTags (PU_LEVEL, PU_PURGELEVEL-1); - P_InitThinkers (); - W_Reload (); - if ( gamemode == commercial) - { - if (map<10) - sprintf (lumpname,"map0%i", map); - else - sprintf (lumpname,"map%i", map); - } - else - { + char lumpname[9]; + int i, lumpnum; + + totalkills = totalitems = totalsecret = wminfo.maxfrags = 0; + wminfo.partime = 180; + for (i = 0 ; i < MAXPLAYERS ; ++i) + players[i].killcount = players[i].secretcount = players[i].itemcount = 0; + players[consoleplayer].viewz = 1; + S_Start(); + Z_FreeTags(PU_LEVEL, PU_PURGELEVEL - 1); + P_InitThinkers(); lumpname[0] = 'E'; lumpname[1] = '0' + episode; lumpname[2] = 'M'; lumpname[3] = '0' + map; - lumpname[4] = 0; - } - lumpnum = W_GetNumForName (lumpname); - leveltime = 0; - P_LoadBlockMap (lumpnum+ML_BLOCKMAP); - P_LoadVertexes (lumpnum+ML_VERTEXES); - P_LoadSectors (lumpnum+ML_SECTORS); - P_LoadSideDefs (lumpnum+ML_SIDEDEFS); - P_LoadLineDefs (lumpnum+ML_LINEDEFS); - P_LoadSubsectors (lumpnum+ML_SSECTORS); - P_LoadNodes (lumpnum+ML_NODES); - P_LoadSegs (lumpnum+ML_SEGS); - rejectmatrix = W_CacheLumpNum (lumpnum+ML_REJECT,PU_LEVEL); - P_GroupLines (); - bodyqueslot = 0; - deathmatch_p = deathmatchstarts; - P_LoadThings (lumpnum+ML_THINGS); - if (deathmatch) - { - for (i=0 ; i<MAXPLAYERS ; i++) - if (playeringame[i]) - { - players[i].mo = NULL; - G_DeathMatchSpawnPlayer (i); - } - } - iquehead = iquetail = 0; - P_SpawnSpecials (); - if (precache) - R_PrecacheLevel (); + lumpname[4] = '\0'; + lumpnum = W_GetNumForName(lumpname); + leveltime = 0; + P_LoadBlockMap(lumpnum+ML_BLOCKMAP); + P_LoadVertexes(lumpnum+ML_VERTEXES); + P_LoadSectors(lumpnum+ML_SECTORS); + P_LoadSideDefs(lumpnum+ML_SIDEDEFS); + P_LoadLineDefs(lumpnum+ML_LINEDEFS); + P_LoadSubsectors(lumpnum+ML_SSECTORS); + P_LoadNodes(lumpnum+ML_NODES); + P_LoadSegs(lumpnum+ML_SEGS); + rejectmatrix = W_CacheLumpNum(lumpnum+ML_REJECT,PU_LEVEL); + P_GroupLines(); + bodyqueslot = 0; + deathmatch_p = deathmatchstarts; + P_LoadThings(lumpnum+ML_THINGS); + if(deathmatch) { + for (i = 0 ; i < MAXPLAYERS; ++i) + if (playeringame[i]) { + players[i].mo = NULL; + G_DeathMatchSpawnPlayer(i); + } + } + iquehead = iquetail = 0; + P_SpawnSpecials(); + if(precache) R_PrecacheLevel(); } -void P_Init (void) + +void +P_Init() { - P_InitSwitchList (); - P_InitPicAnims (); - R_InitSprites (sprnames); + P_InitSwitchList(); + P_InitPicAnims(); + R_InitSprites(sprnames); }