mirror of
https://github.com/Blzut3/Wolf3D-Mac.git
synced 2025-02-19 21:31:11 +00:00
1 line
11 KiB
C
1 line
11 KiB
C
|
#include "WolfDef.h"
#include <string.h>
#include <math.h>
#define DOORPIC 59
/* Scale ranges from 0xffff (one tile == 512 pixels high) down to 0x100 (one tile == 2 pixels) */
savenode_t *nodes;
saveseg_t *pwallseg; /* pushwall in motion*/
/*
================================================
MATH ROUTINES
================================================
*/
/* -8.8 * -0.8 = -8.8*/
fixed_t FixedByFrac (fixed_t a, fixed_t b)
{
fixed_t c;
c = ((long)a * (long)b)>>FRACBITS;
return c;
}
/* -8.8 * -0.8 = -8.8*/
fixed_t SUFixedMul (fixed_t a, ufixed_t b)
{
fixed_t c;
c = ((long)a * (long)b)>>FRACBITS;
return c;
}
/* -8.8 / -8.8 = -8.8*/
fixed_t FixedDiv (fixed_t a, fixed_t b)
{
a = (long)(((long)a<<FRACBITS) / (long)b);
return a;
}
/**********************************
Return the x coord for a sprite
**********************************/
fixed_t R_TransformX(fixed_t x,fixed_t y)
{
fixed_t gxt,gyt;
gxt = FixedByFrac(x,viewsin);
gyt = FixedByFrac(y,viewcos);
return gxt-gyt;
}
/**********************************
Return the scale factor for a sprite
**********************************/
fixed_t R_TransformZ(fixed_t x,fixed_t y)
{
fixed_t gxt,gyt;
gxt = FixedByFrac(x,viewcos);
gyt = FixedByFrac(y,viewsin);
return gxt+gyt;
}
/**********************************
Return the scale factor from a 64k range angle
**********************************/
Word ScaleFromGlobalAngle(int visangle,int distance)
{
fixed_t tz;
Word anglea, angleb;
Word sinea, sineb;
visangle >>= ANGLETOFINESHIFT;
anglea = (FINEANGLES/4 + (visangle-centerangle))&(FINEANGLES/2-1);
angleb = (FINEANGLES/4 + (visangle-normalangle))&(FINEANGLES/2-1);
sinea = finesine[anglea]; /* bothe sines are always positive*/
sineb = finesine[angleb];
tz = ((long)distance * sinea) / sineb;
if (tz>=MAXZ) { /* Make sure it's not too big... */
tz = MAXZ-1;
}
return scaleatzptr[tz]; /* Return the size */
}
/**********************************
The automap has to be done in quadrants for various reasons
**********************************/
void DrawAutomap(Word tx,Word ty)
{
Word i, tile;
saveseg_t *seg;
Word x,y,xstep,ystep,count;
Word min,max;
Word maxtx, maxty;
Word NodeCount;
NodeCount = MapPtr->numnodes;
maxtx = tx+(SCREENWIDTH/16);
maxty = ty+(SCREENHEIGHT/16);
seg = (saveseg_t *)nodes;
i = 0;
do {
if ( (seg->dir & (DIR_SEGFLAG|DIR_SEENFLAG)) == (DIR_SEGFLAG|DIR_SEENFLAG) ) {
min = (seg->min-1)>>1;
max = (seg->max+3)>>1;
switch (seg->dir&3) {
case di_north:
x = (seg->plane-1)>>1;
y = min;
xstep = 0;
ystep = 1;
break;
case di_south:
x = seg->plane>>1;
y = min;
xstep = 0;
ystep = 1;
break;
case di_east:
y = (seg->plane-1)>>1;
x = min;
xstep = 1;
ystep = 0;
break;
case di_west:
y = seg->plane>>1;
x = min;
xstep = 1;
ystep = 0;
break;
}
for (count=max-min ; count ; --count,x+=xstep,y+=ystep) {
if (x < tx || x >= maxtx || y < ty || y>=maxty) {
continue;
}
tile = tilemap[y][x];
if (tile & TI_DOOR) {
tile = 59 /*(seg->dir&1) + 30*/;
} else if (tile & TI_PUSHWALL) {
if (ShowPush) {
tile = 64;
} else {
tile = textures[y][x];
}
} else {
tile = MapPtr->tilemap[y][x];
if (! (tile&0x80) ) {
continue; /* not a solid tile*/
}
tile = textures[y][x];
}
DrawSmall(x-tx,y-ty,tile); /* Draw the tile on the screen */
}
}
++seg;
} while (++i<NodeCount);
x = viewx>>8;
y = viewy>>8;
if (x >= tx && x < maxtx && y >= ty && y<maxty) {
DrawSmall(x-tx,y-ty,64); /* Draw BJ's face here */
}
BlastScreen();
}
/**********************************
Init my math tables for the current view
**********************************/
#define PI 3.141592657
Boolean StartupRendering(Word NewSize)
{
#ifdef __MAC__
int i;
Word minz;
int x;
float a, fv;
long t;
LongWord focallength;
Word j;
Word *ScalePtr;
#endif
if (NewSize == MathSize) { /* Already loaded? */
return TRUE;
}
#ifdef __MAC__ /* Only the mac ver
|