📄 p_setup.c
字号:
// Emacs style mode select -*- C++ -*-//-----------------------------------------------------------------------------//// $Id: p_setup.c,v 1.28 2001/04/30 17:19:24 stroggonmeth Exp $//// Copyright (C) 1993-1996 by id Software, Inc.// Portions Copyright (C) 1998-2000 by DooM Legacy Team.//// 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.////// $Log: p_setup.c,v $// Revision 1.28 2001/04/30 17:19:24 stroggonmeth// HW fix and misc. changes//// Revision 1.27 2001/03/30 17:12:51 bpereira// no message//// Revision 1.26 2001/03/19 21:18:48 metzgermeister// * missing textures in HW mode are replaced by default texture// * fixed crash bug with P_SpawnMissile(.) returning NULL// * deep water trick and other nasty thing work now in HW mode (tested with tnt/map02 eternal/map02)// * added cvar gr_correcttricks//// Revision 1.25 2001/03/13 22:14:19 stroggonmeth// Long time no commit. 3D floors, FraggleScript, portals, ect.//// Revision 1.24 2001/01/25 22:15:43 bpereira// added heretic support//// Revision 1.23 2000/11/04 16:23:43 bpereira// no message//// Revision 1.22 2000/11/03 03:27:17 stroggonmeth// Again with the bug fixing...//// Revision 1.21 2000/11/02 19:49:36 bpereira// no message//// Revision 1.20 2000/11/02 17:50:08 stroggonmeth// Big 3Dfloors & FraggleScript commit!!//// Revision 1.19 2000/10/02 18:25:45 bpereira// no message//// Revision 1.18 2000/08/31 14:30:56 bpereira// no message//// Revision 1.17 2000/08/11 21:37:17 hurdler// fix win32 compilation problem//// Revision 1.16 2000/08/11 19:10:13 metzgermeister// *** empty log message ***//// Revision 1.15 2000/05/23 15:22:34 stroggonmeth// Not much. A graphic bug fixed.//// Revision 1.14 2000/05/03 23:51:00 stroggonmeth// A few, quick, changes.//// Revision 1.13 2000/04/19 15:21:02 hurdler// add SDL midi support//// Revision 1.12 2000/04/18 12:55:39 hurdler// join with Boris' code//// Revision 1.11 2000/04/16 18:38:07 bpereira// no message//// Revision 1.10 2000/04/15 22:12:57 stroggonmeth// Minor bug fixes//// Revision 1.9 2000/04/13 23:47:47 stroggonmeth// See logs//// Revision 1.8 2000/04/12 16:01:59 hurdler// ready for T&L code and true static lighting//// Revision 1.7 2000/04/11 19:07:24 stroggonmeth// Finished my logs, fixed a crashing bug.//// Revision 1.6 2000/04/08 11:27:29 hurdler// fix some boom stuffs//// Revision 1.5 2000/04/06 20:40:22 hurdler// Mostly remove warnings under windows//// Revision 1.4 2000/04/04 19:28:43 stroggonmeth// Global colormaps working. Added a new linedef type 272.//// Revision 1.3 2000/04/04 00:32:47 stroggonmeth// Initial Boom compatability plus few misc changes all around.//// Revision 1.2 2000/02/27 00:42:10 hurdler// fix CR+LF problem//// Revision 1.1.1.1 2000/02/22 20:32:33 hurdler// Initial import into CVS (v1.29 pr3)////// DESCRIPTION:// Do all the WAD I/O, get map description,// set up initial state and misc. LUTs.////-----------------------------------------------------------------------------#include "doomdef.h"#include "d_main.h"#include "byteptr.h"#include "g_game.h"#include "p_local.h"#include "p_setup.h"#include "p_spec.h"#include "i_sound.h" //for I_PlayCD()..#include "r_sky.h"#include "r_data.h"#include "r_things.h"#include "r_sky.h"#include "s_sound.h"#include "st_stuff.h"#include "w_wad.h"#include "z_zone.h"#include "r_splats.h"#include "p_info.h"#include "t_func.h"#include "t_script.h"#include "hu_stuff.h"#ifdef __WIN32__#include "malloc.h"#include "math.h"#endif#ifdef HWRENDER#include "i_video.h" //rendermode#include "hardware/hw_main.h"#include "hardware/hw_light.h"#endif#ifdef LINUXint strupr(char *n);#endif//// MAP related Lookup tables.// Store VERTEXES, LINEDEFS, SIDEDEFS, etc.//boolean newlevel = false;boolean doom1level = false; // doom 1 level running under doom 2char *levelmapname = NULL;int numvertexes;vertex_t* vertexes;int numsegs;seg_t* segs;int numsectors;sector_t* sectors;int numsubsectors;subsector_t* subsectors;int numnodes;node_t* nodes;int numlines;line_t* lines;int numsides;side_t* sides;int nummapthings;mapthing_t* mapthings;/*typedef struct mapdata_s { int numvertexes; vertex_t* vertexes; int numsegs; seg_t* segs; int numsectors; sector_t* sectors; int numsubsectors; subsector_t* subsectors; int numnodes; node_t* nodes; int numlines; line_t* lines; int numsides; side_t* sides;} mapdata_t;*/// BLOCKMAP// Created from axis aligned bounding box// of the map, a rectangular array of// blocks of size ...// Used to speed up collision detection// by spatial subdivision in 2D.//// Blockmap size.int bmapwidth;int bmapheight; // size in mapblocksshort* blockmap; // int for large maps// offsets in blockmap are from hereshort* blockmaplump;// origin of block mapfixed_t bmaporgx;fixed_t bmaporgy;// for thing chainsmobj_t** blocklinks;// REJECT// For fast sight rejection.// Speeds up enemy AI by skipping detailed// LineOf Sight calculation.// Without special effect, this could be// used as a PVS lookup as well.//byte* rejectmatrix;// Maintain single and multi player starting spots.mapthing_t *deathmatchstarts[MAX_DM_STARTS];int numdmstarts;//mapthing_t** deathmatch_p;mapthing_t *playerstarts[MAXPLAYERS];//// P_LoadVertexes//void P_LoadVertexes (int lump){ byte* data; int i; mapvertex_t* ml; vertex_t* li; // Determine number of lumps: // total lump length / vertex record length. numvertexes = W_LumpLength (lump) / sizeof(mapvertex_t); // Allocate zone memory for buffer. vertexes = Z_Malloc (numvertexes*sizeof(vertex_t),PU_LEVEL,0); // Load data into cache. data = W_CacheLumpNum (lump,PU_STATIC); ml = (mapvertex_t *)data; li = vertexes; // Copy and convert vertex coordinates, // internal representation as fixed. for (i=0 ; i<numvertexes ; i++, li++, ml++) { li->x = SHORT(ml->x)<<FRACBITS; li->y = SHORT(ml->y)<<FRACBITS; } // Free buffer memory. Z_Free (data);}//// Computes the line length in frac units, the glide render needs this//#define crapmul (1.0f / 65536.0f)float P_SegLength (seg_t* seg){ double dx,dy; // make a vector (start at origin) dx = (seg->v2->x - seg->v1->x)*crapmul; dy = (seg->v2->y - seg->v1->y)*crapmul; return sqrt(dx*dx+dy*dy)*FRACUNIT;}//// P_LoadSegs//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)];#ifdef HWRENDER // not win32 only 19990829 by Kin // used for the hardware render if (rendermode != render_soft) { li->length = P_SegLength (li);#ifdef TANDL //Hurdler: 04/12/2000: for now, only used in hardware mode li->lightmaps = NULL; // list of static lightmap for this seg#endif }#endif 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; li->numlights = 0; li->rlights = NULL; } Z_Free (data);}//// P_LoadSubsectors//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);}//// P_LoadSectors////// levelflats//#define MAXLEVELFLATS 256int numlevelflats;levelflat_t* levelflats;//SoM: Other files want this info.int P_PrecacheLevelFlats(){ int flatmemory = 0; int i; int lump; //SoM: 4/18/2000: New flat code to make use of levelflats. for(i = 0; i < numlevelflats; i++) { lump = levelflats[i].lumpnum; if(devparm) flatmemory += W_LumpLength(lump); R_GetFlat (lump); } return flatmemory;}int P_FlatNumForName(char *flatname){ return P_AddLevelFlat(flatname, levelflats);}// 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)//int P_AddLevelFlat (char* flatname, levelflat_t* levelflat){ union { char s[9]; int x[2]; } name8; int i; int v1,v2; int lump; strncpy (name8.s,flatname,8); // make it two ints for fast compares name8.s[8] = 0; // in case the name was a fill 8 chars strupr (name8.s); // case insensitive v1 = name8.x[0]; v2 = name8.x[1]; // // first scan through the already found flats // for (i=0; i<numlevelflats; i++,levelflat++) { if ( *(int *)levelflat->name == v1 && *(int *)&levelflat->name[4] == v2) { break; } } // that flat was already found in the level, return the id if (i==numlevelflats) { // store the name *((int*)levelflat->name) = v1; *((int*)&levelflat->name[4]) = v2; // store the flat lump number lump = R_GetFlatNumForName (flatname); levelflat->lumpnum = lump; if (devparm) CONS_Printf ("flat %#03d: %s\n", numlevelflats, name8.s); numlevelflats++; if (numlevelflats>=MAXLEVELFLATS) I_Error("P_LoadSectors: too many flats in level\n"); } // level flat id return i;}// SoM: Do I really need to comment this?char *P_FlatNameForNum(int num){ if(num < 0 || num > numlevelflats) I_Error("P_FlatNameForNum: Invalid flatnum\n"); return Z_Strdup(va("%.8s", levelflats[num].name), PU_STATIC, 0);}void P_LoadSectors (int lump){ byte* data; int i; mapsector_t* ms; sector_t* ss; levelflat_t* foundflats; 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); //Fab:FIXME: allocate for whatever number of flats // 512 different flats per level should be plenty foundflats = alloca(sizeof(levelflat_t) * MAXLEVELFLATS); if (!foundflats) I_Error ("P_LoadSectors: no mem\n"); memset (foundflats, 0, sizeof(levelflat_t) * MAXLEVELFLATS); numlevelflats = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -