/** Makes sure a variable size buffer has enough space for data of a * certain length. * * \param buf The buffer. It is enlarged if necessary. * \param length The length of data we need to add. * \return Pointer to where the new data can go. */ void *VS_GetSpace(vsbuf_t *buf, size_t length) { void *data; if (buf->cursize + length > buf->maxsize) { if (!buf->allowoverflow) I_Error("overflow 111"); if (length > buf->maxsize) I_Error("overflow l%s 112", sizeu1(length)); buf->overflowed = true; CONS_Printf("VS buffer overflow"); VS_Clear(buf); } data = buf->data + buf->cursize; buf->cursize += length; return data; }
// help function for P_LoadSectors, find a flat in the active wad files, // allocate an id for it, and set the levelflat (to speedup search) // static INT32 P_AddLevelFlatRuntime(const char *flatname) { size_t i; levelflat_t *levelflat = levelflats; // // first scan through the already found flats // for (i = 0; i < numlevelflats; i++, levelflat++) if (strnicmp(levelflat->name,flatname,8)==0) break; // that flat was already found in the level, return the id if (i == numlevelflats) { // allocate new flat memory levelflats = Z_Realloc(levelflats, (numlevelflats + 1) * sizeof(*levelflats), PU_LEVEL, NULL); levelflat = levelflats+i; // store the name strlcpy(levelflat->name, flatname, sizeof (levelflat->name)); strupr(levelflat->name); // store the flat lump number levelflat->lumpnum = R_GetFlatNumForName(flatname); #ifndef ZDEBUG CONS_Debug(DBG_SETUP, "flat #%03d: %s\n", atoi(sizeu1(numlevelflats)), levelflat->name); #endif numlevelflats++; } // level flat id return (INT32)i; }
static void DebugPrintpacket(const char *header) { fprintf(debugfile, "%-12s (node %d,ack %d,ackret %d,size %d) type(%d) : %s\n", header, doomcom->remotenode, netbuffer->ack, netbuffer->ackreturn, doomcom->datalength, netbuffer->packettype, packettypename[netbuffer->packettype]); switch (netbuffer->packettype) { case PT_ASKINFO: case PT_ASKINFOVIAMS: fprintf(debugfile, " time %u\n", (tic_t)LONG(netbuffer->u.askinfo.time) ); break; case PT_CLIENTJOIN: fprintf(debugfile, " number %d mode %d\n", netbuffer->u.clientcfg.localplayers, netbuffer->u.clientcfg.mode); break; case PT_SERVERTICS: fprintf(debugfile, " firsttic %u ply %d tics %d ntxtcmd %s\n ", (UINT32)ExpandTics(netbuffer->u.serverpak.starttic), netbuffer->u.serverpak.numslots, netbuffer->u.serverpak.numtics, sizeu1((size_t)(&((UINT8 *)netbuffer)[doomcom->datalength] - (UINT8 *)&netbuffer->u.serverpak.cmds[netbuffer->u.serverpak.numslots*netbuffer->u.serverpak.numtics]))); fprintfstring((char *)&netbuffer->u.serverpak.cmds[netbuffer->u.serverpak.numslots*netbuffer->u.serverpak.numtics],(size_t)( &((UINT8 *)netbuffer)[doomcom->datalength] - (UINT8 *)&netbuffer->u.serverpak.cmds[netbuffer->u.serverpak.numslots*netbuffer->u.serverpak.numtics])); break; case PT_CLIENTCMD: case PT_CLIENT2CMD: case PT_CLIENTMIS: case PT_CLIENT2MIS: case PT_NODEKEEPALIVE: case PT_NODEKEEPALIVEMIS: fprintf(debugfile, " tic %4u resendfrom %u\n", (UINT32)ExpandTics(netbuffer->u.clientpak.client_tic), (UINT32)ExpandTics (netbuffer->u.clientpak.resendfrom)); break; case PT_TEXTCMD: case PT_TEXTCMD2: fprintf(debugfile, " length %d\n ", netbuffer->u.textcmd[0]); fprintfstring((char *)netbuffer->u.textcmd+1, netbuffer->u.textcmd[0]); break; case PT_SERVERCFG: fprintf(debugfile, " playerslots %d clientnode %d serverplayer %d " "gametic %u gamestate %d gametype %d modifiedgame %d\n", netbuffer->u.servercfg.totalslotnum, netbuffer->u.servercfg.clientnode, netbuffer->u.servercfg.serverplayer, (UINT32)LONG(netbuffer->u.servercfg.gametic), netbuffer->u.servercfg.gamestate, netbuffer->u.servercfg.gametype, netbuffer->u.servercfg.modifiedgame); break; case PT_SERVERINFO: fprintf(debugfile, " '%s' player %d/%d, map %s, filenum %d, time %u \n", netbuffer->u.serverinfo.servername, netbuffer->u.serverinfo.numberofplayer, netbuffer->u.serverinfo.maxplayer, netbuffer->u.serverinfo.mapname, netbuffer->u.serverinfo.fileneedednum, (UINT32)LONG(netbuffer->u.serverinfo.time)); fprintfstring((char *)netbuffer->u.serverinfo.fileneeded, (UINT8)((UINT8 *)netbuffer + doomcom->datalength - (UINT8 *)netbuffer->u.serverinfo.fileneeded)); break; case PT_SERVERREFUSE: fprintf(debugfile, " reason %s\n", netbuffer->u.serverrefuse.reason); break; case PT_FILEFRAGMENT: fprintf(debugfile, " fileid %d datasize %d position %u\n", netbuffer->u.filetxpak.fileid, (UINT16)SHORT(netbuffer->u.filetxpak.size), (UINT32)LONG(netbuffer->u.filetxpak.position)); break; case PT_REQUESTFILE: default: // write as a raw packet fprintfstring((char *)netbuffer->u.textcmd, (UINT8)((UINT8 *)netbuffer + doomcom->datalength - (UINT8 *)netbuffer->u.textcmd)); break; } }
static void R_Subsector(size_t num) { INT32 count, floorlightlevel, ceilinglightlevel, light; seg_t *line; subsector_t *sub; static sector_t tempsec; // Deep water hack extracolormap_t *floorcolormap; extracolormap_t *ceilingcolormap; #ifdef RANGECHECK if (num >= numsubsectors) I_Error("R_Subsector: ss %s with numss = %s\n", sizeu1(num), sizeu2(numsubsectors)); #endif // subsectors added at run-time if (num >= numsubsectors) return; sub = &subsectors[num]; frontsector = sub->sector; count = sub->numlines; line = &segs[sub->firstline]; // Deep water/fake ceiling effect. frontsector = R_FakeFlat(frontsector, &tempsec, &floorlightlevel, &ceilinglightlevel, false); floorcolormap = ceilingcolormap = frontsector->extra_colormap; // Check and prep all 3D floors. Set the sector floor/ceiling light levels and colormaps. if (frontsector->ffloors) { if (frontsector->moved) { frontsector->numlights = sub->sector->numlights = 0; R_Prep3DFloors(frontsector); sub->sector->lightlist = frontsector->lightlist; sub->sector->numlights = frontsector->numlights; sub->sector->moved = frontsector->moved = false; } light = R_GetPlaneLight(frontsector, #ifdef ESLOPE frontsector->f_slope ? P_GetZAt(frontsector->f_slope, frontsector->soundorg.x, frontsector->soundorg.y) : #endif frontsector->floorheight, false); if (frontsector->floorlightsec == -1) floorlightlevel = *frontsector->lightlist[light].lightlevel; floorcolormap = frontsector->lightlist[light].extra_colormap; light = R_GetPlaneLight(frontsector, #ifdef ESLOPE frontsector->c_slope ? P_GetZAt(frontsector->c_slope, frontsector->soundorg.x, frontsector->soundorg.y) : #endif frontsector->ceilingheight, false); if (frontsector->ceilinglightsec == -1) ceilinglightlevel = *frontsector->lightlist[light].lightlevel; ceilingcolormap = frontsector->lightlist[light].extra_colormap; } sub->sector->extra_colormap = frontsector->extra_colormap; if ((( #ifdef ESLOPE frontsector->f_slope ? P_GetZAt(frontsector->f_slope, viewx, viewy) : #endif frontsector->floorheight) < viewz || (frontsector->heightsec != -1 && sectors[frontsector->heightsec].ceilingpic == skyflatnum))) { floorplane = R_FindPlane(frontsector->floorheight, frontsector->floorpic, floorlightlevel, frontsector->floor_xoffs, frontsector->floor_yoffs, frontsector->floorpic_angle, floorcolormap, NULL #ifdef ESLOPE , frontsector->f_slope #endif ); } else floorplane = NULL; if ((( #ifdef ESLOPE frontsector->c_slope ? P_GetZAt(frontsector->c_slope, viewx, viewy) : #endif frontsector->ceilingheight) > viewz || frontsector->ceilingpic == skyflatnum || (frontsector->heightsec != -1 && sectors[frontsector->heightsec].floorpic == skyflatnum))) { ceilingplane = R_FindPlane(frontsector->ceilingheight, frontsector->ceilingpic, ceilinglightlevel, frontsector->ceiling_xoffs, frontsector->ceiling_yoffs, frontsector->ceilingpic_angle, ceilingcolormap, NULL #ifdef ESLOPE , frontsector->c_slope #endif ); } else ceilingplane = NULL; numffloors = 0; #ifdef ESLOPE ffloor[numffloors].slope = NULL; #endif ffloor[numffloors].plane = NULL; ffloor[numffloors].polyobj = NULL; if (frontsector->ffloors) { ffloor_t *rover; fixed_t heightcheck; for (rover = frontsector->ffloors; rover && numffloors < MAXFFLOORS; rover = rover->next) { if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERPLANES)) continue; if (frontsector->cullheight) { if (R_DoCulling(frontsector->cullheight, viewsector->cullheight, viewz, *rover->bottomheight, *rover->topheight)) { rover->norender = leveltime; continue; } } ffloor[numffloors].plane = NULL; ffloor[numffloors].polyobj = NULL; heightcheck = #ifdef ESLOPE *rover->b_slope ? P_GetZAt(*rover->b_slope, viewx, viewy) : #endif *rover->bottomheight; if (*rover->bottomheight <= frontsector->ceilingheight && *rover->bottomheight >= frontsector->floorheight && ((viewz < heightcheck && !(rover->flags & FF_INVERTPLANES)) || (viewz > heightcheck && (rover->flags & FF_BOTHPLANES)))) { #ifdef ESLOPE light = R_GetPlaneLight(frontsector, *rover->b_slope ? P_GetZAt(*rover->b_slope, frontsector->soundorg.x, frontsector->soundorg.y) : *rover->bottomheight, viewz < heightcheck); #else light = R_GetPlaneLight(frontsector, *rover->bottomheight, viewz < *rover->bottomheight); #endif ffloor[numffloors].plane = R_FindPlane(*rover->bottomheight, *rover->bottompic, *frontsector->lightlist[light].lightlevel, *rover->bottomxoffs, *rover->bottomyoffs, *rover->bottomangle, frontsector->lightlist[light].extra_colormap, rover #ifdef ESLOPE , *rover->b_slope #endif ); #ifdef ESLOPE ffloor[numffloors].slope = *rover->b_slope; // Tell the renderer this sector has slopes in it. if (ffloor[numffloors].slope) frontsector->hasslope = true; #endif ffloor[numffloors].height = #ifdef ESLOPE *rover->b_slope ? P_GetZAt(*rover->b_slope, viewx, viewy) : #endif *rover->bottomheight; ffloor[numffloors].ffloor = rover; numffloors++; } if (numffloors >= MAXFFLOORS) break; ffloor[numffloors].plane = NULL; ffloor[numffloors].polyobj = NULL; heightcheck = #ifdef ESLOPE *rover->t_slope ? P_GetZAt(*rover->t_slope, viewx, viewy) : #endif *rover->topheight; if (*rover->topheight >= frontsector->floorheight && *rover->topheight <= frontsector->ceilingheight && ((viewz > heightcheck && !(rover->flags & FF_INVERTPLANES)) || (viewz < heightcheck && (rover->flags & FF_BOTHPLANES)))) { #ifdef ESLOPE light = R_GetPlaneLight(frontsector, *rover->t_slope ? P_GetZAt(*rover->t_slope, frontsector->soundorg.x, frontsector->soundorg.y) : *rover->topheight, viewz < heightcheck); #else light = R_GetPlaneLight(frontsector, *rover->topheight, viewz < *rover->topheight); #endif ffloor[numffloors].plane = R_FindPlane(*rover->topheight, *rover->toppic, *frontsector->lightlist[light].lightlevel, *rover->topxoffs, *rover->topyoffs, *rover->topangle, frontsector->lightlist[light].extra_colormap, rover #ifdef ESLOPE , *rover->t_slope #endif ); #ifdef ESLOPE ffloor[numffloors].slope = *rover->t_slope; // Tell the renderer this sector has slopes in it. if (ffloor[numffloors].slope) frontsector->hasslope = true; #endif ffloor[numffloors].height = #ifdef ESLOPE *rover->t_slope ? P_GetZAt(*rover->t_slope, viewx, viewy) : #endif *rover->topheight; ffloor[numffloors].ffloor = rover; numffloors++; } } } #ifdef POLYOBJECTS_PLANES // Polyobjects have planes, too! if (sub->polyList) { polyobj_t *po = sub->polyList; sector_t *polysec; while (po) { if (numffloors >= MAXFFLOORS) break; if (!(po->flags & POF_RENDERPLANES)) // Don't draw planes { po = (polyobj_t *)(po->link.next); continue; } polysec = po->lines[0]->backsector; ffloor[numffloors].plane = NULL; if (polysec->floorheight <= frontsector->ceilingheight && polysec->floorheight >= frontsector->floorheight && (viewz < polysec->floorheight)) { fixed_t xoff, yoff; xoff = polysec->floor_xoffs; yoff = polysec->floor_yoffs; if (po->angle != 0) { angle_t fineshift = po->angle >> ANGLETOFINESHIFT; xoff -= FixedMul(FINECOSINE(fineshift), po->centerPt.x)+FixedMul(FINESINE(fineshift), po->centerPt.y); yoff -= FixedMul(FINESINE(fineshift), po->centerPt.x)-FixedMul(FINECOSINE(fineshift), po->centerPt.y); } else {
/************************************************************************** * * function: Command_Cd_f * * description: * handles all CD commands from the console * **************************************************************************/ static void Command_Cd_f (void) { const char *command; size_t ret, n; if (!cdaudio_started) return; if (COM_Argc() < 2) { CONS_Printf ("%s", M_GetText("cd [on] [off] [remap] [reset] [select]\n" " [open] [info] [play <track>] [resume]\n" " [stop] [pause] [loop <track>]\n")); return; } command = COM_Argv (1); if (!strncmp(command, "on", 2)) { cdEnabled = SDL_TRUE; return; } if (!strncmp(command, "off", 3)) { I_StopCD(); cdEnabled = SDL_FALSE; return; } if (!strncmp(command, "select", 6)) { INT32 newcddrive; newcddrive = atoi(COM_Argv(2)); command = SDL_CDName(newcddrive); I_StopCD(); cdEnabled = SDL_FALSE; SDL_CDClose(cdrom); cdrom = SDL_CDOpen(newcddrive); if (cdrom) { cdEnabled = SDL_TRUE; CONS_Printf(M_GetText("Opened CD-ROM drive %s\n"), command ? command : COM_Argv(2)); } else CONS_Printf(M_GetText("Couldn't open CD-ROM drive %s: %s\n"), command ? command : COM_Argv(2), SDL_GetError()); return; } if (!strncmp(command, "remap", 5)) { ret = COM_Argc() - 2; if (ret <= 0) { for (n = 1; n < MAX_CD_TRACKS; n++) { if (cdRemap[n] != n) CONS_Printf(" %s -> %u\n", sizeu1(n), cdRemap[n]); } return; } for (n = 1; n <= ret; n++) cdRemap[n] = (Uint8)atoi(COM_Argv (n+1)); return; } if (!strncmp(command, "reset", 5)) { if (!cdrom) return; cdEnabled = SDL_TRUE; I_StopCD(); for (n = 0; n < MAX_CD_TRACKS; n++) cdRemap[n] = (Uint8)n; CDAudio_GetAudioDiskInfo(); return; } if (!cdValid) { if (CDAudio_GetAudioDiskInfo()==-1 && !cdValid) { CONS_Printf("%s", M_GetText("No CD in drive\n")); return; } } if (!strncmp(command, "open", 4)) { I_EjectCD(); cdValid = SDL_FALSE; return; } if (!strncmp(command, "info", 4)) { CONS_Printf(M_GetText("%u tracks\n"), maxTrack); if (cdPlaying) CONS_Printf(M_GetText("Currently %s track %u\n"), playLooping ? M_GetText("looping") : M_GetText("playing"), playTrack); else if (wasPlaying) CONS_Printf(M_GetText("Paused %s track %u\n"), playLooping ? M_GetText("looping") : M_GetText("playing"), playTrack); CONS_Printf(M_GetText("Volume is %d\n"), cdvolume); return; } if (!strncmp(command, "play", 4)) { I_PlayCD((UINT8)atoi(COM_Argv (2)), SDL_FALSE); return; } if (!strncmp(command, "loop", 4)) { I_PlayCD((UINT8)atoi(COM_Argv (2)), true); return; } if (!strncmp(command, "stop", 4)) { I_StopCD(); return; } if (!strncmp(command, "pause", 5)) { I_PauseCD(); return; } if (!strncmp(command, "resume", 6)) { I_ResumeCD(); return; } CONS_Printf(M_GetText("Invalid CD command \"CD %s\"\n"), COM_Argv(1)); }
// call this routine after the BSP of a Doom wad file is loaded, // and it will generate all the convex polys for the hardware renderer void HWR_CreatePlanePolygons(INT32 bspnum) { poly_t *rootp; polyvertex_t *rootpv; size_t i; fixed_t rootbbox[4]; DEBPRINT("Creating polygons, please wait...\n"); ls_count = ls_percent = 0; // reset the loading status CON_Drawer(); //let the user know what we are doing I_FinishUpdate(); // page flip or blit buffer HWR_ClearPolys(); // find min/max boundaries of map //DEBPRINT("Looking for boundaries of map...\n"); M_ClearBox(rootbbox); for (i = 0;i < numvertexes; i++) M_AddToBox(rootbbox, vertexes[i].x, vertexes[i].y); //DEBPRINT("Generating subsector polygons... %d subsectors\n", numsubsectors); HWR_FreeExtraSubsectors(); // allocate extra data for each subsector present in map totsubsectors = numsubsectors + NEWSUBSECTORS; extrasubsectors = calloc(totsubsectors, sizeof (*extrasubsectors)); if (extrasubsectors == NULL) I_Error("couldn't malloc extrasubsectors totsubsectors %s\n", sizeu1(totsubsectors)); // allocate table for back to front drawing of subsectors /*gr_drawsubsectors = (INT16 *)malloc(sizeof (*gr_drawsubsectors) * totsubsectors); if (!gr_drawsubsectors) I_Error("couldn't malloc gr_drawsubsectors\n");*/ // number of the first new subsector that might be added addsubsector = numsubsectors; // construct the initial convex poly that encloses the full map rootp = HWR_AllocPoly(4); rootpv = rootp->pts; rootpv->x = FIXED_TO_FLOAT(rootbbox[BOXLEFT ]); rootpv->y = FIXED_TO_FLOAT(rootbbox[BOXBOTTOM]); //lr rootpv++; rootpv->x = FIXED_TO_FLOAT(rootbbox[BOXLEFT ]); rootpv->y = FIXED_TO_FLOAT(rootbbox[BOXTOP ]); //ur rootpv++; rootpv->x = FIXED_TO_FLOAT(rootbbox[BOXRIGHT ]); rootpv->y = FIXED_TO_FLOAT(rootbbox[BOXTOP ]); //ul rootpv++; rootpv->x = FIXED_TO_FLOAT(rootbbox[BOXRIGHT ]); rootpv->y = FIXED_TO_FLOAT(rootbbox[BOXBOTTOM]); //ll rootpv++; WalkBSPNode(bspnum, rootp, NULL,rootbbox); i = SolveTProblem(); //DEBPRINT("%d point divides a polygon line\n",i); AdjustSegs(); //debug debug.. //if (nobackpoly) // DEBPRINT("no back polygon %u times\n",nobackpoly); //"(should happen only with the deep water trick)" //if (skipcut) // DEBPRINT("%u cuts were skipped because of only one point\n",skipcut); //DEBPRINT("done: %u total subsector convex polygons\n", totalsubsecpolys); }