📄 r_main.c
字号:
// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------//// $Id: r_main.c,v 1.2 2003/09/08 22:34:31 jasonk Exp $//// Copyright (C) 1993-1996 by id Software, Inc.//// This source is available for distribution and/or modification// only under the terms of the DOOM Source Code License as// published by id Software. All rights reserved.//// The source is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License// for more details.//// $Log: r_main.c,v $// Revision 1.2 2003/09/08 22:34:31 jasonk// Updated files because this fucker won't build for no fucking good reason.//// Revision 1.1.1.1 2003/09/04 21:08:13 jasonk// Initial import//// Revision 1.1 2000/12/08 21:07:54 jeffw// nxdoom initial entry -- No nxdoom/Makefile so it won't build automatically////// DESCRIPTION:// Rendering main loop and setup functions,// utility functions (BSP, geometry, trigonometry).// See tables.c, too.////-----------------------------------------------------------------------------static const char rcsid[] = "$Id: r_main.c,v 1.2 2003/09/08 22:34:31 jasonk Exp $";#include <stdlib.h>#include <math.h>#include "doomdef.h"#include "d_net.h"#include "m_bbox.h"#include "r_local.h"#include "r_sky.h"// Fineangles in the SCREENWIDTH wide window.#define FIELDOFVIEW 2048 int viewangleoffset;// increment every time a check is madeint validcount = 1; lighttable_t* fixedcolormap;extern lighttable_t** walllights;int centerx;int centery;fixed_t centerxfrac;fixed_t centeryfrac;fixed_t projection;// just for profiling purposesint framecount; int sscount;int linecount;int loopcount;fixed_t viewx;fixed_t viewy;fixed_t viewz;angle_t viewangle;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[SCREENWIDTH+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];// bumped light from gun blastsint extralight; void (*colfunc) (void);void (*basecolfunc) (void);void (*fuzzcolfunc) (void);void (*transcolfunc) (void);void (*spanfunc) (void);//// R_AddPointToBox// Expand a given bbox// so that it encloses a given point.//voidR_AddPointToBox( int x, int y, fixed_t* box ){ if (x< box[BOXLEFT]) box[BOXLEFT] = x; if (x> box[BOXRIGHT]) box[BOXRIGHT] = x; if (y< box[BOXBOTTOM]) box[BOXBOTTOM] = y; if (y> box[BOXTOP]) box[BOXTOP] = y;}//// 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_tR_PointToAngle( fixed_t x, fixed_t y ){ x -= viewx; y -= viewy; if ( (!x) && (!y) ) return 0; if (x>= 0) { // x >=0 if (y>= 0) { // y>= 0 if (x>y) { // octant 0 return tantoangle[ SlopeDiv(y,x)]; } else { // octant 1 return ANG90-1-tantoangle[ SlopeDiv(x,y)]; } } else { // y<0 y = -y; if (x>y) { // octant 8 return -tantoangle[SlopeDiv(y,x)]; } else { // octant 7 return ANG270+tantoangle[ SlopeDiv(x,y)]; } } } else { // x<0 x = -x; if (y>= 0) { // y>= 0 if (x>y) { // octant 3 return ANG180-1-tantoangle[ SlopeDiv(y,x)]; } else { // octant 2 return ANG90+ tantoangle[ SlopeDiv(x,y)]; } } else { // y<0 y = -y; if (x>y) { // octant 4 return ANG180+tantoangle[ SlopeDiv(y,x)]; } else { // octant 5 return ANG270-1-tantoangle[ SlopeDiv(x,y)]; } } } return 0;}angle_tR_PointToAngle2( fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2 ){ viewx = x1; viewy = y1; return R_PointToAngle (x2, y2);}fixed_tR_PointToDist( fixed_t x, fixed_t y ){ int angle; fixed_t dx; fixed_t dy; fixed_t temp; fixed_t dist; dx = abs(x - viewx); dy = abs(y - viewy); if (dy>dx) { temp = dx; dx = dy; dy = temp; } angle = (tantoangle[ FixedDiv(dy,dx)>>DBITS ]+ANG90) >> ANGLETOFINESHIFT; // use as cosine dist = FixedDiv (dx, finesine[angle] ); return dist;}//// 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}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -