Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Iskhodnyy_kod_Doom

.pdf
Скачиваний:
7
Добавлен:
13.02.2015
Размер:
1.01 Mб
Скачать
width, height )
i;

} while (count--);

}

//

//R_InitBuffer

//Creats lookup tables that avoid

//multiplies and other hazzles

//for getting the framebuffer address

//of a pixel to draw.

//

void R_InitBuffer ( int

int

{

int

//Handle resize,

//e.g. smaller view windows

//with border and/or status bar. viewwindowx = (SCREENWIDTH-width) >> 1;

//Column offset. For windows.

for (i=0 ; i<width ; i++) columnofs[i] = viewwindowx + i;

//Samw with base row offset. if (width == SCREENWIDTH)

viewwindowy = 0;

else

viewwindowy = (SCREENHEIGHT-SBARHEIGHT-height) >> 1;

//Preclaculate all row offsets.

for (i=0 ; i<height ; i++)

ylookup[i] = screens[0] + (i+viewwindowy)*SCREENWIDTH;

}

//

//R_FillBackScreen

//Fills the back screen with a pattern

//for variable screen sizes

//Also draws a beveled edge.

//

void R_FillBackScreen (void)

{

byte*

src;

 

byte*

dest;

 

int

x;

 

int

y;

 

patch_t*

patch;

 

// DOOM border patch.

 

char

name1[] =

"FLOOR7_2";

// DOOM II border patch.

char

name2[] =

"GRNROCK";

char*

name;

 

if (scaledviewwidth == 320) return;

641

if ( gamemode == commercial) name = name2;

else

name = name1;

src = W_CacheLumpName (name, PU_CACHE); dest = screens[1];

for (y=0 ; y<SCREENHEIGHT-SBARHEIGHT ; y++)

{

for (x=0 ; x<SCREENWIDTH/64 ; x++)

{

memcpy (dest, src+((y&63)<<6), 64); dest += 64;

}

if (SCREENWIDTH&63)

{

memcpy (dest, src+((y&63)<<6), SCREENWIDTH&63); dest += (SCREENWIDTH&63);

}

}

patch = W_CacheLumpName ("brdr_t",PU_CACHE);

for (x=0 ; x<scaledviewwidth ; x+=8)

V_DrawPatch (viewwindowx+x,viewwindowy-8,1,patch); patch = W_CacheLumpName ("brdr_b",PU_CACHE);

for (x=0 ; x<scaledviewwidth ; x+=8)

V_DrawPatch (viewwindowx+x,viewwindowy+viewheight,1,patch); patch = W_CacheLumpName ("brdr_l",PU_CACHE);

for (y=0 ; y<viewheight ; y+=8)

V_DrawPatch (viewwindowx-8,viewwindowy+y,1,patch); patch = W_CacheLumpName ("brdr_r",PU_CACHE);

for (y=0 ; y<viewheight ; y+=8)

V_DrawPatch (viewwindowx+scaledviewwidth,viewwindowy+y,1,patch);

// Draw beveled edge. V_DrawPatch (viewwindowx-8,

viewwindowy-8, 1,

W_CacheLumpName ("brdr_tl",PU_CACHE));

V_DrawPatch (viewwindowx+scaledviewwidth,

viewwindowy-8,

1,

W_CacheLumpName ("brdr_tr",PU_CACHE));

V_DrawPatch (viewwindowx-8, viewwindowy+viewheight, 1,

W_CacheLumpName ("brdr_bl",PU_CACHE));

V_DrawPatch (viewwindowx+scaledviewwidth,

viewwindowy+viewheight,

1,

W_CacheLumpName ("brdr_br",PU_CACHE));

}

//

642

x,
y,
width, height );

// Copy a screen buffer.

//

 

void

 

R_VideoErase

 

( unsigned

ofs,

int

count )

{

 

//LFB copy.

//This might not be a good idea if memcpy

//is not optiomal, e.g. byte by byte on

//a 32bit CPU, as GNU GCC/Linux libc did

//at one point.

memcpy (screens[0]+ofs, screens[1]+ofs, count);

}

//

//R_DrawViewBorder

//Draws the border around the view

//for different size windows?

//

void V_MarkRect ( int

int int int

void R_DrawViewBorder (void)

{

int

top;

int

side;

int

ofs;

int

i;

if (scaledviewwidth == SCREENWIDTH) return;

top = ((SCREENHEIGHT-SBARHEIGHT)-viewheight)/2; side = (SCREENWIDTH-scaledviewwidth)/2;

//copy top and one line of left side R_VideoErase (0, top*SCREENWIDTH+side);

//copy one line of right side and bottom ofs = (viewheight+top)*SCREENWIDTH-side; R_VideoErase (ofs, top*SCREENWIDTH+side);

//copy sides using wraparound

ofs = top*SCREENWIDTH + SCREENWIDTH-side; side <<= 1;

for (i=1 ; i<viewheight ; i++)

{

R_VideoErase (ofs, side); ofs += SCREENWIDTH;

}

// ?

V_MarkRect (0,0,SCREENWIDTH, SCREENHEIGHT-SBARHEIGHT);

}

643

10.7 r draw.h

// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------

//

//$Id:$

//Copyright (C) 1993-1996 by id Software, Inc.

//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.

//

//DESCRIPTION:

//System specific interface stuff.

//-----------------------------------------------------------------------------

#ifndef __R_DRAW__ #define __R_DRAW__

#ifdef __GNUG__

 

#pragma interface

 

#endif

 

extern lighttable_t*

dc_colormap;

extern int

dc_x;

extern int

dc_yl;

extern int

dc_yh;

extern fixed_t

dc_iscale;

extern fixed_t

dc_texturemid;

// first pixel in a column

 

extern byte*

dc_source;

// The span blitting interface.

// Hook in assembler or system specific BLT

//

here.

void

R_DrawColumn (void);

void

R_DrawColumnLow (void);

// The Spectre/Invisibility effect.

void

R_DrawFuzzColumn (void);

void

R_DrawFuzzColumnLow (void);

//Draw with color translation tables,

//for player sprite rendering,

//Green/Red/Blue/Indigo shirts.

void

R_DrawTranslatedColumn (void);

void

R_DrawTranslatedColumnLow (void);

void

 

R_VideoErase

 

( unsigned

ofs,

int

count );

644

extern int

ds_y;

extern int

ds_x1;

extern int

ds_x2;

extern lighttable_t*

ds_colormap;

extern fixed_t

ds_xfrac;

extern fixed_t

ds_yfrac;

extern fixed_t

ds_xstep;

extern fixed_t

ds_ystep;

// start of a 64*64 tile image

extern byte*

ds_source;

extern byte*

translationtables;

extern byte*

dc_translation;

//Span blitting for rows, floor/ceiling.

//No Sepctre effect needed.

void

R_DrawSpan (void);

// Low resolution mode, 160x200?

void

R_DrawSpanLow (void);

void

 

R_InitBuffer

 

( int

width,

int

height );

//Initialize color translation tables,

//for player rendering etc.

void

R_InitTranslationTables (void);

// Rendering function.

void

R_FillBackScreen (void);

// If the view size is not full screen, draws a border around it. void R_DrawViewBorder (void);

#endif //-----------------------------------------------------------------------------

//

// $Log:$

//

//-----------------------------------------------------------------------------

10.8 r local.h

// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------

//

//$Id:$

//Copyright (C) 1993-1996 by id Software, Inc.

//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

645

//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.

//

//DESCRIPTION:

//Refresh (R_*) module, global header.

//All the rendering/drawing stuff is here.

//-----------------------------------------------------------------------------

#ifndef __R_LOCAL__ #define __R_LOCAL__

//Binary Angles, sine/cosine/atan lookups. #include "tables.h"

//Screen size related parameters.

#include "doomdef.h"

// Include the refresh/render data structs. #include "r_data.h"

//

// Separate header file for each module.

//

#include "r_main.h" #include "r_bsp.h" #include "r_segs.h" #include "r_plane.h" #include "r_data.h" #include "r_things.h" #include "r_draw.h"

#endif

// __R_LOCAL__

//-----------------------------------------------------------------------------

 

//

 

// $Log:$

 

//

 

//-----------------------------------------------------------------------------

 

10.9 r main.c

// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------

//

//$Id:$

//Copyright (C) 1993-1996 by id Software, Inc.

//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:$

646

//

//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.5 1997/02/03 22:45:12 b1 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 made

int

 

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 purposes

int

 

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;

647

player_t*

viewplayer;

// 0 = high, 1 = low

 

int

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 blasts

int

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.

void R_AddPointToBox

( int

x,

int

y,

fixed_t*

box )

{

 

if (x< box[BOXLEFT]) box[BOXLEFT] = x; if (x> box[BOXRIGHT])

box[BOXRIGHT] = x;

648

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).

int R_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;

}

649

int R_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;

}

//

650

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]