Skip to content

Commit

Permalink
Precalculate pixelangle.
Browse files Browse the repository at this point in the history
Clean ewolf3d.



git-svn-id: svn+ssh://jay/var/svn/wolf/trunk@112 32837ae5-38f0-4cfd-8401-3ff76d8497c4
  • Loading branch information
paul committed Aug 12, 2007
1 parent 72ef27a commit d2034e9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -111,7 +111,8 @@ sprites.c: build_sprites.c pagemap.c pal4bit.c
./build_sprites > sprites.c ./build_sprites > sprites.c


clean: clean:
rm -rf swolf3d xwolf3d sdlwolf3d *.o *.il build_tables tables.c \ rm -rf swolf3d xwolf3d sdlwolf3d ewolf3d *.o *.il \
build_tables tables.c \
build_huffman huffman.h build_mapheaders mapheaders.c \ build_huffman huffman.h build_mapheaders mapheaders.c \
build_pagemap pagemap.c build_grstarts grstarts.c \ build_pagemap pagemap.c build_grstarts grstarts.c \
build_pictable pictable.c build_pal4bit pal4bit.c \ build_pictable pictable.c build_pal4bit pal4bit.c \
Expand Down
35 changes: 34 additions & 1 deletion build_tables.c
Expand Up @@ -8,12 +8,18 @@ fixed finetangent[FINEANGLES/4];
fixed sintable[ANGLES+ANGLES/4+1]; fixed sintable[ANGLES+ANGLES/4+1];


static const double radtoint = (double)FINEANGLES/2.0/PI; static const double radtoint = (double)FINEANGLES/2.0/PI;
#ifdef EMBEDDED
static myshort pa[128];
#endif


int main() int main()
{ {
myint i; myint i;
double tang, angle, anglestep; long intang;
myint halfview;
double tang, angle, anglestep, facedist;
fixed value; fixed value;
fixed scale;


/* FIXME: Use linear interpolation to reduce size of trig tables. */ /* FIXME: Use linear interpolation to reduce size of trig tables. */
/* calculate fine tangents */ /* calculate fine tangents */
Expand Down Expand Up @@ -50,6 +56,33 @@ int main()
angle += anglestep; angle += anglestep;
} }
printf ("\n};\n"); printf ("\n};\n");

#ifdef EMBEDDED
facedist = 0x5800+MINDIST;
halfview = 64; /* half view in pixels */

if (MAXVIEWWIDTH != 128)
printf("#error MAXVIEWWIDTH %d, expected 128\n", MAXVIEWWIDTH);
/*
calculate scale value for vertical height calculations
and sprite x calculations
*/
scale = halfview*facedist/(VIEWGLOBAL/2);

/* calculate the angle offset from view angle of each pixel's ray */
for (i = 0; i < halfview; i++) {
tang = ((double)i)*VIEWGLOBAL/128/facedist;
angle = atan(tang);
intang = angle*radtoint;
pa[halfview-1-i] = intang;
pa[halfview+i] = -intang;
}
printf ("const myshort pixelangle[128] = {\n");
for (i = 0; i < 128; i++) {
printf (" %d,\n", pa[i]);
}
printf ("};\n");
#endif
return 0; return 0;
} }


5 changes: 5 additions & 0 deletions wl_def.h
Expand Up @@ -709,7 +709,12 @@ extern boolean startgame,loadedgame;
extern myint mouseadjustment; extern myint mouseadjustment;


/* math tables */ /* math tables */
#ifdef EMBEDDED
// FIXME: This only needs to be half size.
extern const myshort pixelangle[MAXVIEWWIDTH];
#else
extern myshort pixelangle[MAXVIEWWIDTH]; extern myshort pixelangle[MAXVIEWWIDTH];
#endif
extern const fixed finetangent[FINEANGLES/4]; extern const fixed finetangent[FINEANGLES/4];
extern const uint16_t sintable[]; extern const uint16_t sintable[];


Expand Down
6 changes: 6 additions & 0 deletions wl_draw.c
Expand Up @@ -51,9 +51,13 @@ static const double radtoint = (double)FINEANGLES/2.0/PI;
// FIXME: Use fixed display size and precalculate angles. // FIXME: Use fixed display size and precalculate angles.
void CalcProjection(long focal) void CalcProjection(long focal)
{ {
#ifdef EMBEDDED
long facedist;
#else
myint i; myint i;
long intang; long intang;
double angle, tang, facedist; double angle, tang, facedist;
#endif
myint halfview; myint halfview;


focallength = focal; focallength = focal;
Expand All @@ -72,6 +76,7 @@ void CalcProjection(long focal)
*/ */
heightnumerator = (TILEGLOBAL*scale)>>6; heightnumerator = (TILEGLOBAL*scale)>>6;


#ifndef EMBEDDED
/* calculate the angle offset from view angle of each pixel's ray */ /* calculate the angle offset from view angle of each pixel's ray */
for (i = 0; i < halfview; i++) { for (i = 0; i < halfview; i++) {
tang = ((double)i)*VIEWGLOBAL/viewwidth/facedist; tang = ((double)i)*VIEWGLOBAL/viewwidth/facedist;
Expand All @@ -80,6 +85,7 @@ void CalcProjection(long focal)
pixelangle[halfview-1-i] = intang; pixelangle[halfview-1-i] = intang;
pixelangle[halfview+i] = -intang; pixelangle[halfview+i] = -intang;
} }
#endif
} }


/* /*
Expand Down
2 changes: 2 additions & 0 deletions wl_main.c
Expand Up @@ -34,7 +34,9 @@ long frameon;
long lasttimecount; long lasttimecount;
fixed viewsin, viewcos; fixed viewsin, viewcos;
fixed viewx, viewy; /* the focal point */ fixed viewx, viewy; /* the focal point */
#ifndef EMBEDDED
myshort pixelangle[MAXVIEWWIDTH]; myshort pixelangle[MAXVIEWWIDTH];
#endif
//int32_t finetangent[FINEANGLES/4]; //int32_t finetangent[FINEANGLES/4];
myshort horizwall[MAXWALLTILES], vertwall[MAXWALLTILES]; myshort horizwall[MAXWALLTILES], vertwall[MAXWALLTILES];


Expand Down

0 comments on commit d2034e9

Please sign in to comment.