📄 r_main.c
字号:
// Emacs style mode select -*- C++ -*-//-----------------------------------------------------------------------------//// $Id: r_main.c,v 1.22 2001/03/30 17:12:51 bpereira 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: r_main.c,v $// Revision 1.22 2001/03/30 17:12:51 bpereira// no message//// Revision 1.21 2001/03/21 18:24:39 stroggonmeth// Misc changes and fixes. Code cleanup//// Revision 1.20 2001/03/13 22:14:20 stroggonmeth// Long time no commit. 3D floors, FraggleScript, portals, ect.//// Revision 1.19 2001/02/10 12:27:14 bpereira// no message//// Revision 1.18 2001/01/25 22:15:44 bpereira// added heretic support//// Revision 1.17 2000/11/02 17:50:09 stroggonmeth// Big 3Dfloors & FraggleScript commit!!//// Revision 1.16 2000/10/04 16:19:24 hurdler// Change all those "3dfx names" to more appropriate names//// Revision 1.15 2000/09/28 20:57:17 bpereira// no message//// Revision 1.14 2000/09/21 16:45:06 bpereira// no message//// Revision 1.13 2000/08/31 14:30:56 bpereira// no message//// Revision 1.12 2000/07/01 09:23:49 bpereira// no message//// Revision 1.11 2000/04/30 10:30:10 bpereira// no message//// Revision 1.10 2000/04/24 20:24:38 bpereira// no message//// Revision 1.9 2000/04/18 17:39:39 stroggonmeth// Bug fixes and performance tuning.//// Revision 1.8 2000/04/08 17:29:25 stroggonmeth// no message//// Revision 1.7 2000/04/06 21:06:19 stroggonmeth// Optimized extra_colormap code...// Added #ifdefs for older water code.//// Revision 1.6 2000/04/04 19:28:43 stroggonmeth// Global colormaps working. Added a new linedef type 272.//// Revision 1.5 2000/04/04 00:32:47 stroggonmeth// Initial Boom compatability plus few misc changes all around.//// Revision 1.4 2000/03/06 15:15:54 hurdler// compiler warning removed//// Revision 1.3 2000/02/27 16:30:28 hurdler// dead player bug fix + add allowmlook <yes|no>//// 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:// Rendering main loop and setup functions,// utility functions (BSP, geometry, trigonometry).// See tables.c, too.////-----------------------------------------------------------------------------#include "doomdef.h"#include "g_game.h"#include "g_input.h"#include "r_local.h"#include "r_splats.h" //faB(21jan):testing#include "r_sky.h"#include "st_stuff.h"#include "p_local.h"#include "keys.h"#include "i_video.h"#include "m_menu.h"#include "p_local.h"#include "t_func.h"#include "am_map.h"#ifdef HWRENDER#include "hardware/hw_main.h"#endif//profile stuff ---------------------------------------------------------//#define TIMING#ifdef TIMING#include "p5prof.h"long long mycount;long long mytotal = 0;//unsigned long nombre = 100000;#endif//profile stuff ---------------------------------------------------------// Fineangles in the SCREENWIDTH wide window.#define FIELDOFVIEW 2048int viewangleoffset;// increment every time a check is madeint validcount = 1;lighttable_t* fixedcolormap;int centerx;int centery;int centerypsp; //added:06-02-98:cf R_DrawPSpritefixed_t centerxfrac;fixed_t centeryfrac;fixed_t projection;//added:02-02-98:fixing the aspect ration stuff...fixed_t projectiony;// just for profiling purposesint framecount;int sscount;int linecount;int loopcount;fixed_t viewx;fixed_t viewy;fixed_t viewz;fixed_t bspx;fixed_t bspy;angle_t viewangle;angle_t aimingangle;// SoM: Used for detecting surfaces out of view range of portals.angle_t bspangle;fixed_t viewcos;fixed_t viewsin;player_t* viewplayer;// 0 = high, 1 = lowint detailshift;//// precalculated math tables//angle_t clipangle;// The viewangletox[viewangle + FINEANGLES/4] lookup// maps the visible view angles to screen X coordinates,// flattening the arc to a flat projection plane.// There will be many angles mapped to the same X.int viewangletox[FINEANGLES/2];// The xtoviewangleangle[] table maps a screen pixel// to the lowest viewangle that maps back to x ranges// from clipangle to -clipangle.angle_t xtoviewangle[MAXVIDWIDTH+1];// UNUSED.// The finetangentgent[angle+FINEANGLES/4] table// holds the fixed_t tangent values for view angles,// ranging from MININT to 0 to MAXINT.// fixed_t finetangent[FINEANGLES/2];// fixed_t finesine[5*FINEANGLES/4];fixed_t* finecosine = &finesine[FINEANGLES/4];lighttable_t* scalelight[LIGHTLEVELS][MAXLIGHTSCALE];lighttable_t* scalelightfixed[MAXLIGHTSCALE];lighttable_t* zlight[LIGHTLEVELS][MAXLIGHTZ];//SoM: 3/30/2000: Hack to support extra boom colormaps.int num_extra_colormaps;extracolormap_t extra_colormaps[MAXCOLORMAPS];// bumped light from gun blastsint extralight;consvar_t cv_chasecam = {"chasecam","0",0,CV_OnOff};consvar_t cv_allowmlook = {"allowmlook","1",CV_NETVAR,CV_YesNo};consvar_t cv_psprites = {"playersprites","1",0,CV_OnOff};consvar_t cv_perspcorr = {"perspectivecrunch","0",0,CV_OnOff};consvar_t cv_tiltview = {"tiltview","0",0,CV_OnOff};CV_PossibleValue_t viewsize_cons_t[]={{3,"MIN"},{12,"MAX"},{0,NULL}};CV_PossibleValue_t detaillevel_cons_t[]={{0,"High"},{1,"Low"},{0,NULL}};consvar_t cv_viewsize = {"viewsize","10",CV_SAVE|CV_CALL,viewsize_cons_t,R_SetViewSize}; //3-12consvar_t cv_detaillevel = {"detaillevel","0",CV_SAVE|CV_CALL,detaillevel_cons_t,R_SetViewSize}; // UNUSEDconsvar_t cv_scalestatusbar = {"scalestatusbar","0",CV_SAVE|CV_CALL,CV_YesNo,R_SetViewSize};// added 16-6-98:splitscreenvoid SplitScreen_OnChange(void);consvar_t cv_splitscreen = {"splitscreen","0",CV_CALL ,CV_OnOff,SplitScreen_OnChange};void SplitScreen_OnChange(void){ // recompute screen size R_ExecuteSetViewSize(); // change the menu M_SwitchSplitscreen(); if( !demoplayback) { if(cv_splitscreen.value) CL_AddSplitscreenPlayer(); else CL_RemoveSplitscreenPlayer(); if(server && !netgame) multiplayer=cv_splitscreen.value; } else { int i; secondarydisplayplayer = consoleplayer; for( i=0; i<MAXPLAYERS;i++) if( playeringame[i] && i!=consoleplayer ) { secondarydisplayplayer = i; break; } }}//// R_PointOnSide// Traverse BSP (sub) tree,// check point against partition plane.// Returns side 0 (front) or 1 (back).//intR_PointOnSide( fixed_t x, fixed_t y, node_t* node ){ fixed_t dx; fixed_t dy; fixed_t left; fixed_t right; if (!node->dx) { if (x <= node->x) return node->dy > 0; return node->dy < 0; } if (!node->dy) { if (y <= node->y) return node->dx < 0; return node->dx > 0; } dx = (x - node->x); dy = (y - node->y); // Try to quickly decide by looking at sign bits. if ( (node->dy ^ node->dx ^ dx ^ dy)&0x80000000 ) { if ( (node->dy ^ dx) & 0x80000000 ) { // (left is negative) return 1; } return 0; } left = FixedMul ( node->dy>>FRACBITS , dx ); right = FixedMul ( dy , node->dx>>FRACBITS ); if (right < left) { // front side return 0; } // back side return 1;}intR_PointOnSegSide( fixed_t x, fixed_t y, seg_t* line ){ fixed_t lx; fixed_t ly; fixed_t ldx; fixed_t ldy; fixed_t dx; fixed_t dy; fixed_t left; fixed_t right; lx = line->v1->x; ly = line->v1->y; ldx = line->v2->x - lx; ldy = line->v2->y - ly; if (!ldx) { if (x <= lx) return ldy > 0; return ldy < 0; } if (!ldy) { if (y <= ly) return ldx < 0; return ldx > 0; } dx = (x - lx); dy = (y - ly); // Try to quickly decide by looking at sign bits. if ( (ldy ^ ldx ^ dx ^ dy)&0x80000000 ) { if ( (ldy ^ dx) & 0x80000000 ) { // (left is negative) return 1; } return 0; } left = FixedMul ( ldy>>FRACBITS , dx ); right = FixedMul ( dy , ldx>>FRACBITS ); if (right < left) { // front side return 0; } // back side return 1;}//// R_PointToAngle// To get a global angle from cartesian coordinates,// the coordinates are flipped until they are in// the first octant of the coordinate system, then// the y (<=x) is scaled and divided by x to get a// tangent (slope) value which is looked up in the// tantoangle[] table.//angle_t R_PointToAngle2 ( fixed_t x2, fixed_t y2, fixed_t x1, fixed_t y1){ x1 -= x2; y1 -= y2; if ( (!x1) && (!y1) ) return 0; if (x1>= 0) { // x >=0 if (y1>= 0) { // y>= 0 if (x1>y1) { // octant 0 return tantoangle[ SlopeDiv(y1,x1)]; } else { // octant 1 return ANG90-1-tantoangle[ SlopeDiv(x1,y1)]; } } else { // y<0 y1 = -y1; if (x1>y1) { // octant 8 return -tantoangle[SlopeDiv(y1,x1)]; } else { // octant 7 return ANG270+tantoangle[ SlopeDiv(x1,y1)]; } } } else { // x<0 x1 = -x1; if (y1>= 0) { // y>= 0 if (x1>y1) { // octant 3 return ANG180-1-tantoangle[ SlopeDiv(y1,x1)]; } else { // octant 2 return ANG90+ tantoangle[ SlopeDiv(x1,y1)]; } } else { // y<0 y1 = -y1; if (x1>y1) { // octant 4 return ANG180+tantoangle[ SlopeDiv(y1,x1)]; } else { // octant 5 return ANG270-1-tantoangle[ SlopeDiv(x1,y1)]; } } } return 0;}angle_tR_PointToAngle( fixed_t x, fixed_t y){ return R_PointToAngle2 (viewx, viewy, x, y);}fixed_tR_PointToDist2( fixed_t x2, fixed_t y2, fixed_t x1, fixed_t y1){ int angle; fixed_t dx; fixed_t dy; fixed_t dist; dx = abs(x1 - x2); dy = abs(y1 - y2); if (dy>dx) { fixed_t temp; temp = dx; dx = dy; dy = temp; } if(dy==0) return dx; angle = (tantoangle[ FixedDiv(dy,dx)>>DBITS ]+ANG90) >> ANGLETOFINESHIFT; // use as cosine dist = FixedDiv (dx, finesine[angle] ); return dist;}//SoM: 3/27/2000: Little extra utility. Works in the same way as//R_PointToAngle2fixed_tR_PointToDist( fixed_t x, fixed_t y){ return R_PointToDist2(viewx, viewy, x, y);}//// R_InitPointToAngle//void R_InitPointToAngle (void){ // UNUSED - now getting from tables.c#if 0 int i; long t; float f;//// slope (tangent) to angle lookup// for (i=0 ; i<=SLOPERANGE ; i++) { f = atan( (float)i/SLOPERANGE )/(3.141592657*2); t = 0xffffffff*f; tantoangle[i] = t; }#endif}//// R_ScaleFromGlobalAngle// Returns the texture mapping scale// for the current line (horizontal span)// at the given angle.// rw_distance must be calculated first.////added:02-02-98:note: THIS IS USED ONLY FOR WALLS!fixed_t R_ScaleFromGlobalAngle (angle_t visangle){ // UNUSED#if 0 //added:02-02-98:note: I've tried this and it displays weird... fixed_t scale; fixed_t dist; fixed_t z; fixed_t sinv; fixed_t cosv; sinv = finesine[(visangle-rw_normalangle)>>ANGLETOFINESHIFT]; dist = FixedDiv (rw_distance, sinv); cosv = finecosine[(viewangle-visangle)>>ANGLETOFINESHIFT]; z = abs(FixedMul (dist, cosv)); scale = FixedDiv(projection, z); return scale;#else fixed_t scale; int anglea;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -