Home » Archimedes archive » Acorn User » AU 1997-08 B.adf » Features » 3D/!AU_Attack/source/c/engine
3D/!AU_Attack/source/c/engine
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Acorn User » AU 1997-08 B.adf » Features |
Filename: | 3D/!AU_Attack/source/c/engine |
Read OK: | ✔ |
File size: | AF27 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
/* engine.c : Written by Greg Scott 1997 for Acorn User, as part of the "Virtual Worlds" series. Usage of the source code is done at the owners risk, and Acorn User or the author hold no responsibility for damages. */ /* AUTHORS NOTE: A lot of the code in here is very complex, and can never be adequately explained. PLEASE PLEASE contact me for more assistance, it is much easier to address personal problems with the ideas than in general. AUThreeD@aol.com or contact the Acorn User offices and they will pass it on. Thank you. */ /* ANSI C includes */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> /* OTHER includes */ #include "our_lib.h" /* DEFINES */ #define WORLD_WIDTH 64 /* This is the number of walls across in our world */ #define WORLD_HEIGHT 64 /* This is the number of walls down in our world */ #define WALL_WIDTH 64 /* This is the width of each wall in pixels */ #define WALL_HEIGHT 64 /* This is the height of each wall in pixels */ #define WALL_NUMBER 20 /* This defines the number of walls allowed */ #define CELL_X_SIZE 64 /* this is the size in units of each cell */ #define CELL_Y_SIZE 64 /* this is the size in units of each cell */ #define CELL_X_SIZE_FP 6 /* this is used in binary shifting */ #define CELL_Y_SIZE_FP 6 /* this is used in binary shifting */ #define FOUND_WALL 1 /* this flag is used to indicate when an intersection has be found */ #define MAX_DISTANCE 4000 /* this defines the largest distance a ray could travel in the world, used for look up tables */ #define MAX_SCALE 300 /* used for clipping */ #define CLOSEST 50 /* this stores the closest a player can walk into a wall */ /* NEW use of ANGLES variables, they are now not defines but are inputted by the command line at the beginning of main()*/ /* OLD defines have been converted to integers because we now load them in from the command line */ int ANGLE_0,ANGLE_6,ANGLE_30,ANGLE_90,ANGLE_180,ANGLE_270,ANGLE_360,STEP_LENGTH,VERTICAL_SCALE,VIEWVAR,VIEWVART,SCREEN_HEIGHT,SCREEN_WIDTH,DEMO_READ,DEMO_WRITE; /* GLOBAL variables */ char world[WORLD_HEIGHT+1][WORLD_WIDTH+1];/* This holds our text data file */ char objects[WORLD_HEIGHT+1][WORLD_WIDTH+1]; /* NEW object array (as world)*/ char walls[WALL_NUMBER+1][(WALL_WIDTH*WALL_HEIGHT)+1]; char objgraphics[WALL_NUMBER+1][(WALL_WIDTH*WALL_HEIGHT)+1]; /* This holds the wall graphics in a two dimensional array */ /* Note the usage of char and not "int" in both cases. This is because a char is 8 bytes, which gives 256 colours (used in our Mode 13 screen) and also an integer up to 256, when our text file doesn't go over 20 in number! Hence there is no need for an int array in either case. */ char *screen_address; /* this will hold the base of the screen memory which we will manipulate. By altering values in the screen memory, we alter what appears on the screen. Note that this is of type "char *" because it holds the memory address of a byte array - the 256 colour mode 13 screen (well it will do!) */ char *screen_address_bank; /* this is another pointer to the other area of screen memory which we will be using for SCREEN BANKING - avoiding flickering of the screen during animating graphics */ char *screen_address_temp; /* this is a spare pointer for use during the switching of the two above values */ /* these new FIXED POINT INTEGER pointers point to look-up tables used in the ray casting engine. These are explained of in the engine, but the look-ups are generated in aua_tables() */ int *tan_table,*inv_tan_table; /* pointers to tangent look_ups */ int *y_step,*x_step; /* pointers to more complex look_ups */ int *inv_cos_table, /* sin/cos tables (look_ups) */ *inv_sin_table; int *cos_table; /* cosinal look_up table */ int *recip_table; /* reciprocal table used instead of a */ /* division. See later */ int *coso_table,*sino_table; /* these two tables are for objects */ int *dx_table, /* FIXED POINT tables for moving the */ *dy_table; /* view point very quickly */ int scale_array[320]; /* NEW used to store scale values of each */ /* sliver,for objects later on */ /* FUNCTION definitions */ /* this function generates LOOK UP tables - arrays holding pre-calculated trigonometric variables used in the ray casting process */ void aua_tables(void) { int ang, /* this is used to hold values while making look-ups */ angt; /* same */ float rad_angle; /* this holds the radians equivalent of the fixed point angle system (0-1920 = 0-360 degrees = 0-6.whatever radians. Next month I'll be changing the system so it becomes 0-1800 instead of 1920, this will allow a slightly smaller screen width, more like Wolfenstein, this will lead to an increase in frame rate. Yes! */ /* dynamically allocated adequate memory for the look-ups */ tan_table = (int *)malloc(sizeof(int) * (ANGLE_360+1)); inv_tan_table = (int *)malloc(sizeof(int) * (ANGLE_360+1)); y_step = (int *)malloc(sizeof(int) * (ANGLE_360+1)); x_step = (int *)malloc(sizeof(int) * (ANGLE_360+1)); cos_table = (int *)malloc(sizeof(int) * (ANGLE_360+1)); inv_cos_table = (int *)malloc(sizeof(int) * (ANGLE_360+1)); inv_sin_table = (int *)malloc(sizeof(int) * (ANGLE_360+1)); /* new table, for the engine, to avoid using a divide */ recip_table = (int *)malloc(sizeof(int) * (MAX_DISTANCE+1)); /* new tables for moving the view point */ dx_table = (int *)malloc(sizeof(int) * (ANGLE_360+1)); dy_table = (int *)malloc(sizeof(int) * (ANGLE_360+1)); /* generate them, their use is explained in the ray casting engine */ /* two new tables to use for object plotting */ coso_table = (int *)malloc(sizeof(int) * (ANGLE_360+1)); sino_table = (int *)malloc(sizeof(int) * (ANGLE_360+1)); for(angt=ANGLE_0;angt<=ANGLE_360;angt++) { ang=angt; /* this next line calculates the radian angle to pass to the trig. functions */ rad_angle=(float)((3.272e-4) + ang * 2*3.141592654/ANGLE_360); tan_table[ang]=(int)(tan(rad_angle)*65536); inv_tan_table[ang]=(int)((1/tan(rad_angle))*65536); /* note tha above conversions to fixed point integers */ /* we do the same for these tables, but unfortunately at the asymptotes the numbers become awkwardly large to store in our fixed point representation. Instead of multiplying by 64 we do 8, to make sure that no overflow can occur at this stage. We only need to multiply by another 8 later in the engine, its okay */ if(ang>=ANGLE_0 && ang<ANGLE_180) { y_step[ang]=fabs( (8) * (tan_table[ang]) ); } else y_step[ang]=-fabs( (8) * (tan_table[ang]) ); if(ang>=ANGLE_90 && ang<ANGLE_270) { x_step[ang]=-fabs( (8) * (inv_tan_table[ang]) ); } else { x_step[ang]=fabs( (8) * (inv_tan_table[ang]) ); } /* conversion to fixed point */ inv_cos_table[ang]=(int)((1/cos(rad_angle))*65536); inv_sin_table[ang]=(int)((1/sin(rad_angle))*65536); /* conversion to fixed point of object plotting sine and cosines */ sino_table[ang]=(int)(sin(rad_angle-1.570796327)*65536); coso_table[ang]=(int)(cos(rad_angle-1.570796327)*65536); /* work out tables for moving the viewpoint */ dx_table[ang]=(int)(cos(6.28*ang/ANGLE_360)*STEP_LENGTH)*65536; dy_table[ang]=(int)(sin(6.28*ang/ANGLE_360)*STEP_LENGTH)*65536; } /* the cosine table is used to get rid of the "fish bowl effect", explained in the ray caster. Basically we work out cosines for our own span of vision, from -30 degrees to +30 degrees. This means that as we scan from left to right, or vice versa, our rays of light are actually cast out in a cartesian, circular way. Our world is however square, polar, so we have to acknowledge the distortion caused by mixing cartesian and polar coordinates. In this look up we also have a bit of scaling in it, yet more time saving !!! */ for(ang=-ANGLE_30;ang<=ANGLE_30;ang++) { /* work out radians to pass to cosine function */ rad_angle=(float)((3.272e-4)+ ang * 2*3.141592654/ANGLE_360); /*fixed point conversion */ cos_table[ang+ANGLE_30]=(int)(VERTICAL_SCALE/(cos(rad_angle))*65536); } /* this creates a reciprocal table, so we don't have to use divides. Multiplying by the reciprocal of a number is the same as dividing by it: After all, 8 / 4 = 2 and 8 * 0.25 (1 over 4) = 2 - they produce the same result */ for(ang=1;ang<MAX_DISTANCE;ang++) { /* it is still fixed point though */ recip_table[ang]=(int)(1.0/(float)ang*65536); } } /* this function is the heart of the program, the engine, to generate the first person view */ void aua_raycaster(int view_x,int view_y,int view_angle) { /* remember that we are thinking in 2-D, not in 3D when we discuss ideas. Below does not mean "a floor below", it really means "behind", but we say below because we are imagining looking down on the view point to form a 2-D plan */ /* this function, for each column of the 320 pixel width Mode 13 screen, casts out two rays. One ray looks for X, horizontal intersections with walls, and the other tracks intersections with Y, vertical wall boundaries. After all, the only time a collision could occur is on a boundary of a cell, as the wall fills up the entire cell. Expect to see lots of 64's, though remember that this ray caster is very routine, and has not at all been put through my "box of magic". The engine will become much more personalised very soon! */ int cell_x, /* used to store which cell of the walls data the ray is in */ cell_y, /* " */ casting=2, /* used to store if ray casting has finished */ x_hit_type, /* this stores the wall type hit by the x casting ray */ y_hit_type, /* this sotres the wall type (number) hit by the y ray */ x_bound, /* this holds the next x boundary for a possible intersection */ y_bound, /* this holds the next y boundary for a possible intersection */ next_y_cell, /* this is used to figure out the quadrant of the ray (+/-)*/ next_x_cell, /* " */ x_delta, /* this is +'d to the x_bound var. to move to the next boundary */ y_delta, /* this is +'d to the y_bound var. to move to the next boundary */ xi_save, /* this stores where the x casting ray made its intersection */ yi_save, /* this stores where the y casting ray made its intersection */ scale, /* this stores the scale of the sliver to be drawn in each column */ ray, /* this stores the ray number being cast out (0-320)*/ xray, /* this flag is used to show if casting is over */ yray, /* " */ dist_x, /* this holds the distance to the x intersection */ dist_y; /* this holds the distance to the y intersection */ int xi, yi, xadd, yadd; /* these are used to accurately trace and move each ray */ int variables[6], /* this is used to pass variables to a sliver renderer */ clip; /* this could be used later for clipping */ int xtrans_dist, /* these NEW TRANSPARENT variables are used for windows */ ytrans_dist, /* each one will be used later to draw transparent walls */ xtrans_col, ytrans_col, xtrans_type, ytrans_type, xtrans_done,/* these last two are used as flags to mark if a transpar-*/ ytrans_done;/*ency has been found or not */ int counter=0; /* firstly, we set up the variables[] we already know, such as screen_address, walls and the screen height we are using. These are all things which our sliver renderer needs to know to plot its column */ variables[0]=(int)screen_address; /* now we get down to the nitty gritty. Here we subtract 30 degrees from the viewing angle remember that our FOV is 60 degrees which means that we cast from -30 to +30 */ if ( (view_angle-=ANGLE_30) < 0) { /* this ensures that we don't go over or under 0/360 degrees! */ view_angle=ANGLE_360 + view_angle; } /* now we start the main loop, start at the right of the screen (319), and cast each column one by one to the left */ for (ray=SCREEN_WIDTH-1; ray>=0; ray--) { /* for each ray to be cast we actually cast out two rays : one to check for vertical boundary collisions and the other to check for horizontal boundary collisions. Considering that walls fill up each cell, we need only look for intersections on the boundaries. We have to perform seperate cast because just casting one ray complicates the matter and it doesn't give much speed increase, if any. */ /* NEW LINE : We have to check to see if the viewing angle is at the asymptotes, unfortunately the fixed point system cannot store the values held at these angles, so we have to avoid their use. This is not very elegant I know, but it saves a lot of head aches and no one can tell we've done it! */ if(view_angle==ANGLE_0 || view_angle==ANGLE_90 || view_angle ==ANGLE_180 || view_angle==ANGLE_270)view_angle++; /* SECTION 1 : CALCULATING THE FIRST X and Y INTERSECTIONS*/ /* Once we have done this the following intersections are easy*/ /* The X CASTING RAY : here we test to see if the angle of the ray is facing upwards. We need to know which halfplane we're casting from relative to the y-axis. */ if (view_angle >= ANGLE_0 && view_angle < ANGLE_180) { /* if so then we assign variables to that effect. We must compute the first horizontal line that could be intersected with the ray. Note : it will be above the viewer.*/ y_bound = (CELL_Y_SIZE + (view_y & 0xffc0)); /* this line is merely an optimized version of CELL_Y_SIZE + (view_y % 64). I use it many times in this engine. */ y_delta = CELL_Y_SIZE; /* this means that for every movement of the ray, the y boundary moves up one cell, which it would. It is the delta to get to the next horizontal line */ /* next we use the inverse tan function to calculate the initial position of the x boundary searching ray on its first intersection. We have to use tan because it is related to slopes */ /* NEW FIXED POINT CALCULATION of xi = (float)(inv_tan_table[view_angle] * (y_bound - view_y)) +view_x; */ xi=((y_bound-view_y))*(inv_tan_table[view_angle]); xi+=(view_x<<16); /* this means that the quadrant of the ray is not negative, that is the next y boundary will appear above the view point and not below (in terms of looking down on the viewer). This is the cell delta */ next_y_cell = 0; } /* if the viewing angle is greater than 180 degrees and less than 270 degrees then we have to do other calculations (lower half plane) */ else { /* we know that because the viewing angle is downwards, so then the horizontal intersection has to be BELOW the viewer */ y_bound = (int)(view_y & 0xffc0); /* because of this we also know that the next Y intersections will be a cell below each other. So the delta for each horizontal intersection will be a cell below the last */ y_delta = -CELL_Y_SIZE; /* we again use the tangent function, just as before, to calculate the first x intersection with a boundary. */ /* NEW FIXED POINT, I won't show the old lines any more */ xi=((y_bound-view_y))*(inv_tan_table[view_angle]); xi+=(view_x<<16); /* and we know also that the quadrant is below the player, so the cell y delta will be negative */ next_y_cell = -1; } /* Y RAY : we do similar calculations but this time to calculate the first y intersections */ /* we test to see if the view angle is within the vertical asymptotes of 360 degrees. We need to know which halfplane we're casting from relative to the x-axis. */ if (view_angle < ANGLE_90 || view_angle >= ANGLE_270) { /* we can deduce certain things, just as with the x ray. We know that because the view angle is to the right, the next X boundary (which is constant) will be to the RIGHT of the viewer. */ x_bound = (int)(CELL_X_SIZE + (view_x & 0xffc0)); /* notice this recurring optimization of view_x % 64 */ /* and we also know that each vertical cell boundary after the first will be a cell's width away */ x_delta = CELL_X_SIZE; /* this time we use the tangent function (not the inverse tan) to calculate where the first y boundary intersection will occur). */ /* NEW FIXED POINT */ yi=((x_bound - view_x))*(tan_table[view_angle]); yi+=(view_y<<16); /* and we know also that because the view is positive, the next_x_cell delta does not need to be negative */ next_x_cell = 0; } /* otherwise, if the viewing angle is towards the other direction...*/ else { /* we know that the first x boundary can occur only to the left of the viewer because the ray angle is facing left. So we can do view_x % 64 to calculate the first vertical boundary, this should be becoming obvious */ x_bound = (int)(view_x & 0xffc0); /* we also know that the delta for the cell will be to the left, each time the ray moves to the next boundary the next vertical intersection will be a cell to the left than the last. */ x_delta = -CELL_X_SIZE; /* we use the tangental function again to calculate the position on the horizontal intersections */ /* NEW FIXED POINT */ yi=((x_bound - view_x))*(tan_table[view_angle]); yi+=(view_y<<16); /* and we also know that the x cell value will be minus, because as the ray moves to another cell, because the ray is going left, the value must be minus. */ next_x_cell = -1; } /* Now we have performed the slightly tricky task of the first intersections, we can move on to calculating the next ones. This is more simple, as we know that the intersections can only occur at cell boundaries.*/ /* SECTION 2 : Testing for further intersections */ /* these flags store if casting of both rays is complete */ xray=yray=xtrans_done=ytrans_done=0; /* X Ray is first */ /* because we are testing for each next intersection, we can figure out more easily the following intersections. */ /* this is a look up table holding the next y intercepts, based on the tangental function and the size of cells. Basically we add this to the ray each time we move it a bit more, searching for a wall at a cell boundary */ /* NEW FIXED POINT, note the shift 3 times to the left, the equivalent of a multiply by 8, this takes no time, and really I don't know why I've done it like this! It works. */ xadd=y_step[view_angle]<<3; /* start casting the x ray */ while(!xray) { /* compute current cell position of the ray to inspect*/ cell_x = ( (x_bound+next_x_cell) >> CELL_X_SIZE_FP); /* Note we have to shift not only by 6, but also by 16 to convert BACK to normal maths */ cell_y = (int)yi>>22; /* both of the above examples use binary shifting to achieve a divide by 64. Cell_y computation uses identical techniques to those covered in the magazine. Cell_x is calculated by using the x_bound and next_x_cell values calculated beforehand. */ if(cell_x<0)cell_x=0;if(cell_x>63)cell_x=63; if(cell_y<0)cell_y=0;if(cell_y>63)cell_y=63; /* these simple lines ensure that the ray doesn't go out of the world, though they aren't really needed. */ /* we look up in the world file to see if there is a wall at the intersection of our ray */ if ((x_hit_type =world[cell_y][cell_x])!=0) { /* or any (extra or different) tile value you wish */ if(x_hit_type==9 || x_hit_type==7){ /*THEN THE WALL IS TRANSPARENT!!!*/ xtrans_dist=((yi-(view_y<<16))>>8)*(inv_sin_table[view_angle]>>8); xtrans_type=x_hit_type; xtrans_col=((int)(yi>>16) & 0x003f); xtrans_done=FOUND_WALL; /* we record all required details then continue */ } else { /* if so we calculate the distance to it using the old O-Level technique of using sine and cosine instead of doing the standard PYTHAGORAS technique.*/ /* NEW FIXED POINT calculation, notice that in this next line we have both a conversion TO fixed point (view_y) and also the check against over flow is very apparent, we share the accuracy. See the article for more details */ dist_x = ( (yi - (view_y<<16))>>8) * (inv_sin_table[view_angle]>>8); /* we also save the exact position of the intersection because we will need it later to add texture mapping. */ /* We save yi after converting it back to normal maths */ yi_save = (int)yi>>16; /* because the x ray has found a wall, we can stop casting */ xray=FOUND_WALL; } } /* if not, we compute the next possible intersection */ yi +=xadd; /* FIXED POINT ADDITION requires no extra work */ x_bound += x_delta; /* and we also calculate the next horizontal boundary, which we know will be x_delta away, no need for complex workings. */ } /* SECTION 3 */ /* WE NOW do exactly the same but for the yray, we cast it out, check for a wall, if there is one we take the distance to it etc, if not, we move the ray until a wall it found. */ /* look up the value to add to the ray each time we move it */ /* See above for more information, this is FIXED POINT remember */ yadd=x_step[view_angle]<<3; /* start casting the ray */ while(!yray) { /* compute current cell to inspect */ /* Because XI IS IN FIXED POINT we have to not only divide by 64 but also we have to convert BACK to normal maths */ cell_x = (int)xi>>22; cell_y = ( (y_bound + next_y_cell) >> CELL_Y_SIZE_FP); /* these calculations work out which cells the ray is in, ready to check for walls in the world[][] array. They both use binary shifting to perform divide by 64's. */ /* check that the ray has not gone out of the world, though this isn't really necessary */ if(cell_x<0)cell_x=0;if(cell_x>63)cell_x=63; if(cell_y<0)cell_y=0;if(cell_y>63)cell_y=63; /* look and see if there is a wall at the current point of intersection */ if ((y_hit_type = world[cell_y][cell_x])!=0) { if(y_hit_type==9 || y_hit_type==7){ /*THEN THE WALL IS TRANSPARENT!!!*/ ytrans_dist=((xi-(view_x<<16))>>8)*(inv_cos_table[view_angle]>>8); ytrans_type=y_hit_type; ytrans_col=((int)(xi>>16) & 0x003f); ytrans_done=FOUND_WALL; } /* we record all required details then continue */ else { /* Use the old O-Level triangle method of calulating distance using cos, rather than using PYTHAGORAS, which is slower because it uses a square root! */ /* FIXED POINT calculation, just the same as the inv_sin calculation see above. */ dist_y = ( (xi - (view_x<<16))>>8) * (inv_cos_table[view_angle]>>8); /* save the exact intersection point, we will need it later */ /* Same as aobve, very simple conversion back from FIXED POINT to normal maths */ xi_save = (int)xi>>16; /* STOP y casting in that case, a wall has been found. */ yray=FOUND_WALL; } } /* if not, move the ray on */ xi+=yadd; /* AGAIN, no extra work is required for FIXED POINT ADDITION */ y_bound += y_delta; /* and move to the next vertical boundary position */ } /* SECTION 4*/ /* Both rays have been cast, both rays have met a wall, we now need to see which is closer, and then plot it correctly. */ /* find out which wall (x or y) is nearer the viewer. */ /* we have altered this distance checking line to avoid minus distances being selected to draw, which produces large spikes on the screen! Again this is because of fixed point */ if (dist_x < dist_y && dist_x>0 || dist_y<0) { /* we need to take into account here, when computing the scale of the vertical strip (sliver) to be drawn, a phenemenon (of sorts) known as the "fish bowl effect". This is caused by mizing of cartesian and polar coordinates. To get rid of it we use the cosine function. I have combined other multiplies of a vertical scaling factor with the cosine transformation to save time. All we eventually be explained. You could replace the line with scale=13312/dist_x++ and see what weird results you get! */ /* NEW NEW NEW : We have fixed point here, and using the reciprocal table (see around) we don't have to do a lengthy divide! Notice how we convert dist_x back to normal to index the recip_table array, and that all accuracy is lost with the cos_table, because all its figures are above zero (see aua_tables) and also that we actually convert the whole answer back to normal maths for scale */ scale = (int)( (cos_table[ray]>>16) * (recip_table[dist_x>>16]) >>16); /* assign the variables we need to the variables to be passed to the ASM sliver renderer (super fast!) */ if(scale>SCREEN_HEIGHT) { scale=SCREEN_HEIGHT-1; } variables[2]=scale; /*stores the scale of the strip (height of it)*/ variables[3]=ray; /* we use ray as the x position to plot to (0-319)*/ variables[1]=(int)&walls[x_hit_type][(yi_save & 0x003f)]; variables[4]=(recip_table[scale]<<6); /* and we call the assembler function (explained at a later date)*/ ourlib_new(&variables[0]); scale_array[ray]=scale; } /* else the dist_y was nearer, everything from above applies */ else { /* avoid fish bowl effect and scale properly with FIXED POINT clever bits!, see above */ scale = (int)( (cos_table[ray]>>16) * (recip_table[dist_y>>16]) >> 16); /* set up variables for our sliver engine, see above */ if(scale>SCREEN_HEIGHT) { scale=SCREEN_HEIGHT-1; } variables[2]=scale; /*stores the scale of the strip (height of it)*/ variables[3]=ray; /* we use ray as the x position to plot to (0-319)*/ variables[1]=(int)&walls[y_hit_type+1][(xi_save & 0x003f)]; variables[4]=(recip_table[scale]<<6); /* notice we add one to the wall graphic selection, so the darker tile is used for added variation. See the article for more details of this sort of shading, if you want to call it that! */ /* call our sliver engine */ ourlib_new(&variables[0]); scale_array[ray]=scale; } /* it is here that we draw the overlaying transparent wall */ if(xtrans_done && xtrans_dist<dist_y) { scale=(int)((cos_table[ray]>>16) * (recip_table[xtrans_dist>>16])>>16); if(scale>SCREEN_HEIGHT)scale=SCREEN_HEIGHT-1; variables[2]=scale; variables[3]=ray; variables[4]=(recip_table[scale]<<6); variables[1]=(int)&walls[xtrans_type][xtrans_col]; /* now call our special function which treats color 0 as a mask */ ourlib_new_mask(variables); scale_array[ray]=scale; } else if(ytrans_done && ytrans_dist<dist_x) { scale=(int)((cos_table[ray]>>16) * (recip_table[ytrans_dist>>16])>>16); if(scale>SCREEN_HEIGHT)scale=SCREEN_HEIGHT-1; variables[2]=scale; variables[3]=ray; variables[4]=(recip_table[scale]<<6); variables[1]=(int)&walls[ytrans_type+1][ytrans_col]; /* now call our special function which treats color 0 as a mask */ ourlib_new_mask(variables); scale_array[ray]=scale; } /* this ray has been finished. Increase the angle of the next ray and start again! */ if (++view_angle>=ANGLE_360) { /* this ensures that the ray angle doesn't go over 360 degrees! */ view_angle=0; } /* ray loop */ } /* end ray caster engine */ /* objects*/ } /* this function grabs all the different walls from a single file */ void aua_graphics(void) { int x, /* this is used to store the x coordinate of a point on the screen */ y, /* this is used to store the y coordinate of a point on the screen */ wall_number; /* this will be used to index the walls[x][] char array */ /* first of all we get the graphics file <AUARay$Dir>.graphics onto the screen */ system("*ScreenLoad <AUARay$Dir>.graphics"); /* next we start grabbing each tile, 64 x 64 pixels, into the walls[][] array */ /* we use this large for loop at the ourlib_bitmap_grab function to invidually grab each tile into its own walls[x][] array slot, note that we CAN'T HAVE WALL 0 as this represents a gap in the world! */ ourlib_killcursor(); /* get rid of cursor first */ for(wall_number=1,y=0;y<256;y+=WALL_HEIGHT)for(x=0;x<320;x+=WALL_WIDTH,wall_number++) { /* this calls the function ourlib_bitmap_grab (I said it would be handy!) which grabs the area of screen memory marked by the first four parameters, stores it in the byte array pointer in parameter five, reading it all from the screen pointed to by screen_address */ ourlib_bitmap_grab(x,y,x+WALL_WIDTH-1,y+WALL_HEIGHT-1,&walls[wall_number][0],screen_address); /* this makes sure we don't go over our number of walls limit */ if(wall_number>=WALL_NUMBER)break; } /* new stuff load in objects separately */ /* see above for comments (its identical) */ system("*ScreenLoad <AUARay$Dir>.Objgraphic"); ourlib_killcursor(); for(wall_number=1,y=0;y<256;y+=WALL_HEIGHT)for(x=0;x<320;x+=WALL_WIDTH,wall_number++) { ourlib_bitmap_grab(x,y,x+63,y+63,&objgraphics[wall_number][0],screen_address); if(wall_number>WALL_NUMBER)break; } } /* this function loads in the data from our world text file and stores it in the world[][] array */ void aua_world(void) { FILE *world_file; /* we need a file pointer as we will be loading in text */ int row, /* this will be used to index the world[][] array */ column,counter=0; /* this will be used to index the world[][] array */ char ch; /* this is used to store each number as it is loaded in */ /* open the world file, if it is not there then exit the program */ if(!(world_file=fopen("<AUARay$Dir>.world","r")))exit(1); /* this program loads in the data from the world file, row by row, column by column using the getc() ANSI function */ for(row=0;row<WORLD_HEIGHT;row++) { for(column=0;column<WORLD_WIDTH;column++) { while((ch=getc(world_file))==10){} /* this filters out any mess, though not often used! */ if(ch==' ')ch=0; /*this ensures the correct value is stored, if there is a gap in the file, this means a space in the world, a zero */ else ch=ch-'0'; /* this new line will (should!) convert letters into their appropriate number */ if(ch>16)ch-=6; world[(WORLD_HEIGHT-1)-row][column]=ch; /* this finally stores the value in the correct position */ /*printf("%d",ch); uncomment this line to see the world data loaded in */ } /*printf("\n"); uncomment this line to see the world data loaded in */ } /* when all is done, close the file */ fclose(world_file); /* new part to load in object data, see above for comments */ if(!(world_file=fopen("<AUARay$Dir>.objworld","r"))) exit(1); for(row=0;row<WORLD_HEIGHT;row++) { for(column=0;column<WORLD_WIDTH;column++) { while((ch=getc(world_file))==10){} if(ch==' ')ch=0; else ch=ch-'0'; if(ch>16)ch-=7; objects[(WORLD_HEIGHT-1)-row][column]=ch; } } fclose(world_file); } /* NEWER MAIN function . All changes are commented */ void main(int argc,char *argv[]) { int view_x, /* this holds the viewing x coordinate */ view_y, /* this holds the viewing y coordinate */ view_angle; /* this holds the viewing angle in fixed units 0-1920 */ int done=0, /* flag to indicate if the user wants to quit */ dx, /* movement variables for the viewer */ dy, y_cell, /* these NEW variables are used to store the player/viewer*/ x_cell, /* world positions, for calculating viewer hitting walls */ y_sub_cell, x_sub_cell, time_start, time_finish, /* These last few variables are used to work out */ frames=0, /* the frames per sec. of the system, slow for now! */ door_x, door_y; /* These new variables will be used for door things */ /* New Object Code ***************** Added Article 5 - good stuff ! */ int object_x,object_y,trans_x,trans_z,screen_x,screen_y1,screen_y2,temp_1,counter,scale,variables[7],index,increment,grid_x,grid_y,object_type,start_x,start_y,stop_x,stop_y,move_x,move_y,tview_x,tview_y,tview_angle; /* New Object Code Variables Over *************** See Later in Main() */ /* NEW demo file which can load/store demo information for a walkthrough*/ FILE *demo_file; /* NEW system of passing, we use the standard argc and argv to supply parameters to the engine. FIRST we must extract them:*/ /* check that correct number of parameters have been passed */ if(argc!=14) { /* quit if not */ printf("Error: Incorrect number of parameters passed. _Exiting\n"); exit(1); /* "beep" (on most machines)*/ putchar('\a'); } /* use atoi to get it right */ /* INPUT ALL VALUES FROM COMMAND LINE using ATOI and then work out needed*/ /* angle values for the ray casting engine. */ view_x=atoi(argv[1]); view_y=atoi(argv[2]); view_angle=atoi(argv[3]); SCREEN_WIDTH=atoi(argv[4]); SCREEN_HEIGHT=atoi(argv[5]); ANGLE_360=atoi(argv[6]); ANGLE_180=ANGLE_360/2;ANGLE_90=ANGLE_180/2; ANGLE_6=atoi(argv[9]); ANGLE_30=(int)ANGLE_90/3; ANGLE_0=0; ANGLE_270=ANGLE_90*3; VERTICAL_SCALE=atoi(argv[7]); STEP_LENGTH=atoi(argv[8]); VIEWVAR=atoi(argv[10]); VIEWVART=atoi(argv[11]); DEMO_READ=atoi(argv[12]); DEMO_WRITE=atoi(argv[13]); /* Now we print the information just for the information of the user */ printf("_system variables:\nview_x: %d view_y: %d view_angle: %d\nscreen_width: %d screen_height: %d angle_360: %d\nvertical_scale: %d step_length: %d viewvars: %d %d\ndemo_read: %d demo_write: %d\n\n",view_x,view_y,view_angle,SCREEN_WIDTH,SCREEN_HEIGHT,ANGLE_360,VERTICAL_SCALE,STEP_LENGTH,VIEWVAR,VIEWVART,DEMO_READ,DEMO_WRITE); if(DEMO_WRITE==1){ if(!(demo_file=fopen("<AUARay$Dir>.demo","w")))exit(1); printf("writing to file\n"); } else if(DEMO_READ==1) { if(!(demo_file=fopen("<AUARay$Dir>.demo","r")))exit(1); printf("reading demo file\n"); } /* DONE. Now continue as normal with the program */ /* It is here that we see if the DEMOFLAG is set to read/write demos */ /* now we call aua_world to load in the text world file which defines our walls type and layout */ printf("\nloading in text file <AUARay$Dir>.world\n"); aua_world(); /* check to see if the viewer is inside a game cell WALL, which would be bad news! */ if(world[view_y>>6][view_x>>6]) { printf("\nBad coordinates given, viewer is IN a WALL!, exiting\n"); exit(1); } /* now we call aua_tables to generate some look-up tables for the engine to use, look-ups are explained up at the top of the file next to the global variables */ printf("calling aua_tables(), could take a long time on slower machines\n"); /* newer fixed point version */ aua_tables(); /* all is done in terms of input for now. We need to switch to Mode 13 */ printf("switching to mode thirteen\n"); /* call ourlib_changemode to switch to mode 13 */ ourlib_changemode(13); /* call ourlib_findscreen to get the screen base address of mode 13, without the correct address we can't draw anything and the computer could crash */ screen_address=(char *)ourlib_findscreen(); /* NEW LOAD TITLE SCREEN */ system("*ScreenLoad <AUARay$Dir>.title");ourlib_killcursor(); ourlib_wait(200); /*ourlib_screen_dissolve(screen_address,81920); USE IF WANTED */ /* THEN WAIT THEN SCREENDISSOLVE OUT, see above */ /* now we need to *screenload our graphics file, and grab each individual wall graphic one by one, the function aua_graphics does this */ aua_graphics(); /* NOW we call setup_screens, a small function which helps with banking */ /* With all the data loaded in we shall try and initiate SCREEN BANKS. First we change to MODE 15, so that screen memory becomes available for two times MODE 13 */ ourlib_setup_screens(); ourlib_changemode(15); /* Now we switch to MODE 13, and get the first screen address */ ourlib_changemode(13); ourlib_killcursor(); /*os_clg();*/ screen_address=(char *)ourlib_findscreen(); /* Now we switch to the other screen bank and get the other screen address */ ourlib_simpleswitch(); screen_address_bank=(char *)ourlib_findscreen(); ourlib_slowclear(screen_address_bank,81920,0); ourlib_killcursor(); /* Switch back to the other screen */ ourlib_simpleswitch(); /* NOW we can call setup background, to tell the screen clearer the colour of the floor and ceilings we want.*/ ourlib_setup_background(208,45); /* NOW we can start the main loop, exitable only by pressing the Q key. Use the Cursors to move the viewpoint around */ /* We shall also take a reading to work out the frame rate of the system, slow for now */ /* NEW ADJUSTING LINES : we add an offset to both screen memory areas in order to centre the image in the middle of the screen no matter what size */ screen_address+=(320-SCREEN_WIDTH)>>1; screen_address_bank+=(320-SCREEN_WIDTH)>>1; ourlib_killcursor(); /* get rid of the cursor flashing away */ time_start=ourlib_gettime(); while(!done) /* the loop will continue until done */ { ourlib_fastclg_two(screen_address,SCREEN_WIDTH,SCREEN_HEIGHT); /* we call the floor/ceiling function to colour the whole screen */ /* then we call the ray caster to draw over it */ aua_raycaster(view_x,view_y,view_angle); dx=dy=0; /* now we test for different key presses and take action accordingly */ if(ourlib_keydown(16)==255)done=1; /* if Q is pressed then quit */ /* LEFT */ if(ourlib_keydown(121)==255) { if((view_angle-=ANGLE_6)<ANGLE_0) view_angle=ANGLE_360; } /*RIGHT */ if(ourlib_keydown(25)==255) { if((view_angle+=ANGLE_6)>ANGLE_360) view_angle=ANGLE_0; } /* UP and DOWN */ if(ourlib_keydown(57)==255) { dx=dx_table[view_angle]; dy=dy_table[view_angle]; } if(ourlib_keydown(41)==255) { dx=-dx_table[view_angle]; dy=-dy_table[view_angle]; } /* NOW we need to move the player and recalculate the cell the viewer is in, and ALSO check to see if the player has hit a wall */ /* Watch for the conversions of fixed point and things */ /* Player X actually is in normal maths */ view_x= (int)((view_x<<16)+dx)>>16; view_y= (int)((view_y<<16)+dy)>>16; /* DEMO HANDLING CODE COMES HERE */ /* Note that this is described briefly in article 5 */ if(DEMO_WRITE || DEMO_READ) { tview_x=view_x; tview_y=view_y; tview_angle=view_angle; if(DEMO_WRITE)fprintf(demo_file,"%d %d %d ",tview_x,tview_y,tview_angle); if(DEMO_READ)if((fscanf(demo_file,"%d %d %d ",&tview_x,&tview_y,&tview_angle))==EOF)rewind(demo_file); view_x=tview_x; view_y=tview_y; view_angle=tview_angle; } /* NEW OPTIMIZED VERSIONS OF MOVING THE PLAYER */ x_cell = view_x>>6; y_cell = view_y>>6; x_sub_cell = view_x & 0x003f; y_sub_cell = view_y & 0x003f; /* CHECK to see if player has walked into walls */ if ((dx>>8)>0 ){ if ((world[y_cell][x_cell+1] != 0) && (x_sub_cell>(CELL_X_SIZE-CLOSEST))) { view_x-= (x_sub_cell-(CELL_X_SIZE-CLOSEST )); } } else { if ( (world[y_cell][x_cell-1] != 0) && (x_sub_cell < (CLOSEST) ) ) { view_x+= (CLOSEST-x_sub_cell) ; } } if ((dy>>8)>0 ){ if ( (world[(y_cell+1)][x_cell] != 0) && (y_sub_cell > (CELL_Y_SIZE-CLOSEST ) ) ) { view_y-= (y_sub_cell-(CELL_Y_SIZE-CLOSEST )); } } else { if ( (world[(y_cell-1)][x_cell] != 0) && (y_sub_cell < (CLOSEST) ) ) { view_y+= (CLOSEST-y_sub_cell); } } /* NEW DOOR code. A "probe" is sent out in front of the player, if a door tile is found near it then the block is destroyed. */ if(ourlib_keydown(98)==255) { /* Use similar techniques to above to find door */ dx=dx_table[view_angle]; dy=dy_table[view_angle]; /* Calculate door x and y, it is in normal maths */ door_x= (int)((view_x<<16)+(dx<<3))>>16; door_y= (int)((view_y<<16)+(dy<<3))>>16; /* NEW OPTIMIZED VERSIONS OF FINDIN DOORS */ /* now find the cell we are looking in with the standard equation */ x_cell = (int)door_x>>6; y_cell = (int)door_y>>6; /* Check if a doors is present */ if(world[y_cell][x_cell]==7 /* OR WHATEVER YOU LIKE */) { world[y_cell][x_cell]=0; /* or alternatively do what you like */ } } /* New Object Code ****************** Added Article 5, good stuff! */ /* This code cycles through the objects and plots them appropriately if they are visible by the viewer. See ARTICLE 5 for more details.*/ /* Firstly, set up variables we know are going to be used */ variables[0]=(int)screen_address; variables[2]=SCREEN_HEIGHT; /* Next we loop through all the visible squares to see if an object has been found */ if(view_angle>ANGLE_0 && view_angle<ANGLE_90) { start_x=(view_x>>6)+15; start_y=(view_y>>6)+15; stop_x=(view_x>>6)-5; stop_y=(view_y>>6)-5; move_x=-1; move_y=-1; if(stop_x<0)stop_x=0;if(stop_x>63)stop_x=63; if(start_x<0)start_x=0;if(start_x>63)start_x=63; if(stop_y<0)stop_y=0;if(stop_y>63)stop_y=63; if(start_y<0)start_y=0;if(start_y>63)start_y=63; } else if(view_angle>=ANGLE_90 && view_angle<ANGLE_180) { start_x=(view_x>>6)-15; start_y=(view_y>>6)+15; stop_x=(view_x>>6)+5; stop_y=(view_y>>6)-5; move_x=1; move_y=-1; if(stop_x<0)stop_x=0;if(stop_x>63)stop_x=63; if(start_x<0)start_x=0;if(start_x>63)start_x=63; if(stop_y<0)stop_y=0;if(stop_y>63)stop_y=63; if(start_y<0)start_y=0;if(start_y>63)start_y=63; } else if(view_angle>=ANGLE_180 && view_angle<ANGLE_270) { start_x=(view_x>>6)-15; start_y=(view_y>>6)-15; stop_x=(view_x>>6)+5; stop_y=(view_y>>6)+5; move_x=1; move_y=1; if(stop_x<0)stop_x=0;if(stop_x>63)stop_x=63; if(start_x<0)start_x=0;if(start_x>63)start_x=63; if(stop_y<0)stop_y=0;if(stop_y>63)stop_y=63; if(start_y<0)start_y=0;if(start_y>63)start_y=63; } else { start_x=(view_x>>6)+15; start_y=(view_y>>6)-15; stop_x=(view_x>>6)-5; stop_y=(view_y>>6)+5; move_x=-1; move_y=1; if(stop_x<0)stop_x=0;if(stop_x>63)stop_x=63; if(start_x<0)start_x=0;if(start_x>63)start_x=63; if(stop_y<0)stop_y=0;if(stop_y>63)stop_y=63; if(start_y<0)start_y=0;if(start_y>63)start_y=63; } for(grid_x=start_x;grid_x!=stop_x;grid_x+=move_x)for(grid_y=start_y;grid_y!=stop_y;grid_y+=move_y) { if(!objects[grid_y][grid_x])continue; /* An object has been found in this grid square yippee!*/ /* in that case we process and plot the object */ object_x=(grid_x<<6)+32; object_y=(grid_y<<6)+32; /* now we have to rotate the objects coordinates around the viewer */ /* to establish where it is on the view plane ,using standard rots.*/ trans_x=( (object_x-view_x)*coso_table[view_angle]+(object_y-view_y)* sino_table[view_angle])>>16; trans_z=(-(object_x-view_x)*sino_table[view_angle]+(object_y-view_y)* coso_table[view_angle])>>16; /* now if the object is infront of the viewer we go further */ if(trans_z<0)continue; /* else we move to next object */ /* we have to work out screen positions now (above and below!) */ temp_1=(((VIEWVART<<5) * recip_table[trans_z]))>>16; screen_y1=128-temp_1; /* 128 and 160 here indicate origins at the*/ screen_y2=128+temp_1; /* center of the screen ofcourse */ /* the above lines works out the top and bottom of the object */ if((scale=(screen_y2-screen_y1))>MAX_SCALE)continue; screen_x=160 + ( ( VIEWVAR*trans_x * recip_table[trans_z])>>16); if(scale>(SCREEN_HEIGHT)) { scale=SCREEN_HEIGHT; } variables[5]=screen_y1; /* above line works out scale from y1 and y2 ready for drawing */ screen_x-=scale>>1; /* we offset screen_x so then we are at the left of the object */ increment=(int)(recip_table[scale]<<6); variables[3]=scale; object_type=objects[grid_y][grid_x]; /* above line prepares more variables for the ourlib function */ /* next we set up fixed point systems to index the object graphic */ /* while we draw it. Instead of floating point this is of course */ index=0; /* next we use a counter to count if we have finished drawing it. */ counter=scale; /* initialise a loop to render each sliver one by one */ /* keep going until off the screen or just finished! */ while(screen_x>-64 && screen_x<320 && counter>0) { /* check to see if object is infront of wall, important! */ if(scale>scale_array[screen_x] && screen_x>0) { /* if so draw this sliver! */ variables[1]=(int)&objgraphics[object_type][(int)index>>16]; variables[4]=screen_x; ourlib_sliver_mask(variables); } /* add on graphic increment, decrease counter and move to next column */ index+=increment; counter--; screen_x++; } } /* Object Code OVER ************* Continue as normal */ /* *************** See Article 5 for more details */ /* PHEW! Now we can wait for a vysnc and then switch the views/banks over ot produce flicker-free animation */ ourlib_waitvsync(); ourlib_simpleswitch(); /* We also have to switch the memory addresses around so our functions draw to the correct memory */ screen_address_temp=screen_address_bank; screen_address_bank=screen_address; screen_address=screen_address_temp; /* add one to the frames count, we are counting the number of frames generated */ frames++; } /* record the time stopped */ time_finish=ourlib_gettime(); /* take a screenshot, using *screen save, and save it inside the directory */ system("*ScreenSave <AUARay$Dir>.scrshot"); if(DEMO_READ || DEMO_WRITE)fclose(demo_file); /* close down the screens using an ourlib function */ ourlib_closedown_screens(); /* change to mode 15 and bring back the cursor just in case */ ourlib_changemode(15); ourlib_revivecursor(); /* print the calculation and other info. */ printf("******* FRAMES PER SECOND ********\n%f",(float)frames/(float)((time_finish-time_start)/100)); }
00000000 2f 2a 0a 20 20 20 65 6e 67 69 6e 65 2e 63 20 3a |/*. engine.c :| 00000010 20 57 72 69 74 74 65 6e 20 62 79 20 47 72 65 67 | Written by Greg| 00000020 20 53 63 6f 74 74 20 20 20 31 39 39 37 0a 20 20 | Scott 1997. | 00000030 20 66 6f 72 20 41 63 6f 72 6e 20 55 73 65 72 2c | for Acorn User,| 00000040 20 61 73 20 70 61 72 74 20 6f 66 20 74 68 65 20 | as part of the | 00000050 22 56 69 72 74 75 61 6c 0a 20 20 20 57 6f 72 6c |"Virtual. Worl| 00000060 64 73 22 20 73 65 72 69 65 73 2e 0a 0a 20 20 20 |ds" series... | 00000070 55 73 61 67 65 20 6f 66 20 74 68 65 20 73 6f 75 |Usage of the sou| 00000080 72 63 65 20 63 6f 64 65 20 69 73 20 64 6f 6e 65 |rce code is done| 00000090 20 61 74 20 74 68 65 20 6f 77 6e 65 72 73 20 72 | at the owners r| 000000a0 69 73 6b 2c 20 61 6e 64 20 41 63 6f 72 6e 20 55 |isk, and Acorn U| 000000b0 73 65 72 20 6f 72 20 74 68 65 20 20 20 61 75 74 |ser or the aut| 000000c0 68 6f 72 20 68 6f 6c 64 20 6e 6f 20 72 65 73 70 |hor hold no resp| 000000d0 6f 6e 73 69 62 69 6c 69 74 79 20 66 6f 72 20 64 |onsibility for d| 000000e0 61 6d 61 67 65 73 2e 0a 2a 2f 0a 0a 2f 2a 20 41 |amages..*/../* A| 000000f0 55 54 48 4f 52 53 20 4e 4f 54 45 3a 20 41 20 6c |UTHORS NOTE: A l| 00000100 6f 74 20 6f 66 20 74 68 65 20 63 6f 64 65 20 69 |ot of the code i| 00000110 6e 20 68 65 72 65 20 69 73 20 76 65 72 79 20 63 |n here is very c| 00000120 6f 6d 70 6c 65 78 2c 20 61 6e 64 20 63 61 6e 20 |omplex, and can | 00000130 6e 65 76 65 72 20 62 65 20 61 64 65 71 75 61 74 |never be adequat| 00000140 65 6c 79 20 65 78 70 6c 61 69 6e 65 64 2e 20 50 |ely explained. P| 00000150 4c 45 41 53 45 20 50 4c 45 41 53 45 20 63 6f 6e |LEASE PLEASE con| 00000160 74 61 63 74 20 6d 65 20 66 6f 72 20 6d 6f 72 65 |tact me for more| 00000170 20 61 73 73 69 73 74 61 6e 63 65 2c 20 69 74 20 | assistance, it | 00000180 69 73 20 6d 75 63 68 20 65 61 73 69 65 72 20 74 |is much easier t| 00000190 6f 20 61 64 64 72 65 73 73 20 70 65 72 73 6f 6e |o address person| 000001a0 61 6c 20 70 72 6f 62 6c 65 6d 73 20 77 69 74 68 |al problems with| 000001b0 20 74 68 65 20 69 64 65 61 73 20 74 68 61 6e 20 | the ideas than | 000001c0 69 6e 20 67 65 6e 65 72 61 6c 2e 0a 0a 41 55 54 |in general...AUT| 000001d0 68 72 65 65 44 40 61 6f 6c 2e 63 6f 6d 0a 0a 6f |hreeD@aol.com..o| 000001e0 72 20 63 6f 6e 74 61 63 74 20 74 68 65 20 41 63 |r contact the Ac| 000001f0 6f 72 6e 20 55 73 65 72 20 6f 66 66 69 63 65 73 |orn User offices| 00000200 20 61 6e 64 20 74 68 65 79 20 77 69 6c 6c 20 70 | and they will p| 00000210 61 73 73 20 69 74 20 6f 6e 2e 20 54 68 61 6e 6b |ass it on. Thank| 00000220 20 79 6f 75 2e 20 2a 2f 0a 0a 2f 2a 20 41 4e 53 | you. */../* ANS| 00000230 49 20 43 20 69 6e 63 6c 75 64 65 73 20 2a 2f 0a |I C includes */.| 00000240 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f |.#include <stdio| 00000250 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 |.h>.#include <st| 00000260 64 6c 69 62 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 |dlib.h>.#include| 00000270 20 3c 6d 61 74 68 2e 68 3e 0a 23 69 6e 63 6c 75 | <math.h>.#inclu| 00000280 64 65 20 3c 73 74 72 69 6e 67 2e 68 3e 0a 2f 2a |de <string.h>./*| 00000290 20 4f 54 48 45 52 20 69 6e 63 6c 75 64 65 73 20 | OTHER includes | 000002a0 2a 2f 0a 0a 23 69 6e 63 6c 75 64 65 20 22 6f 75 |*/..#include "ou| 000002b0 72 5f 6c 69 62 2e 68 22 0a 0a 2f 2a 20 44 45 46 |r_lib.h"../* DEF| 000002c0 49 4e 45 53 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 |INES */..#define| 000002d0 20 57 4f 52 4c 44 5f 57 49 44 54 48 20 36 34 20 | WORLD_WIDTH 64 | 000002e0 2f 2a 20 54 68 69 73 20 69 73 20 74 68 65 20 6e |/* This is the n| 000002f0 75 6d 62 65 72 20 6f 66 20 77 61 6c 6c 73 20 61 |umber of walls a| 00000300 63 72 6f 73 73 20 69 6e 20 6f 75 72 20 77 6f 72 |cross in our wor| 00000310 6c 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 4f |ld */.#define WO| 00000320 52 4c 44 5f 48 45 49 47 48 54 20 36 34 20 2f 2a |RLD_HEIGHT 64 /*| 00000330 20 54 68 69 73 20 69 73 20 74 68 65 20 6e 75 6d | This is the num| 00000340 62 65 72 20 6f 66 20 77 61 6c 6c 73 20 64 6f 77 |ber of walls dow| 00000350 6e 20 69 6e 20 6f 75 72 20 77 6f 72 6c 64 20 2a |n in our world *| 00000360 2f 0a 23 64 65 66 69 6e 65 20 57 41 4c 4c 5f 57 |/.#define WALL_W| 00000370 49 44 54 48 20 36 34 20 2f 2a 20 54 68 69 73 20 |IDTH 64 /* This | 00000380 69 73 20 74 68 65 20 77 69 64 74 68 20 6f 66 20 |is the width of | 00000390 65 61 63 68 20 77 61 6c 6c 20 69 6e 20 70 69 78 |each wall in pix| 000003a0 65 6c 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 |els */.#define W| 000003b0 41 4c 4c 5f 48 45 49 47 48 54 20 36 34 20 2f 2a |ALL_HEIGHT 64 /*| 000003c0 20 54 68 69 73 20 69 73 20 74 68 65 20 68 65 69 | This is the hei| 000003d0 67 68 74 20 6f 66 20 65 61 63 68 20 77 61 6c 6c |ght of each wall| 000003e0 20 69 6e 20 70 69 78 65 6c 73 20 2a 2f 0a 23 64 | in pixels */.#d| 000003f0 65 66 69 6e 65 20 57 41 4c 4c 5f 4e 55 4d 42 45 |efine WALL_NUMBE| 00000400 52 20 32 30 20 2f 2a 20 54 68 69 73 20 64 65 66 |R 20 /* This def| 00000410 69 6e 65 73 20 74 68 65 20 6e 75 6d 62 65 72 20 |ines the number | 00000420 6f 66 20 77 61 6c 6c 73 20 61 6c 6c 6f 77 65 64 |of walls allowed| 00000430 20 2a 2f 0a 23 64 65 66 69 6e 65 20 43 45 4c 4c | */.#define CELL| 00000440 5f 58 5f 53 49 5a 45 20 36 34 20 2f 2a 20 74 68 |_X_SIZE 64 /* th| 00000450 69 73 20 69 73 20 74 68 65 20 73 69 7a 65 20 69 |is is the size i| 00000460 6e 20 75 6e 69 74 73 20 6f 66 20 65 61 63 68 20 |n units of each | 00000470 63 65 6c 6c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 |cell */.#define | 00000480 43 45 4c 4c 5f 59 5f 53 49 5a 45 20 36 34 20 2f |CELL_Y_SIZE 64 /| 00000490 2a 20 74 68 69 73 20 69 73 20 74 68 65 20 73 69 |* this is the si| 000004a0 7a 65 20 69 6e 20 75 6e 69 74 73 20 6f 66 20 65 |ze in units of e| 000004b0 61 63 68 20 63 65 6c 6c 20 2a 2f 0a 23 64 65 66 |ach cell */.#def| 000004c0 69 6e 65 20 43 45 4c 4c 5f 58 5f 53 49 5a 45 5f |ine CELL_X_SIZE_| 000004d0 46 50 20 36 20 2f 2a 20 74 68 69 73 20 69 73 20 |FP 6 /* this is | 000004e0 75 73 65 64 20 69 6e 20 62 69 6e 61 72 79 20 73 |used in binary s| 000004f0 68 69 66 74 69 6e 67 20 2a 2f 0a 23 64 65 66 69 |hifting */.#defi| 00000500 6e 65 20 43 45 4c 4c 5f 59 5f 53 49 5a 45 5f 46 |ne CELL_Y_SIZE_F| 00000510 50 20 36 20 2f 2a 20 74 68 69 73 20 69 73 20 75 |P 6 /* this is u| 00000520 73 65 64 20 69 6e 20 62 69 6e 61 72 79 20 73 68 |sed in binary sh| 00000530 69 66 74 69 6e 67 20 2a 2f 0a 23 64 65 66 69 6e |ifting */.#defin| 00000540 65 20 46 4f 55 4e 44 5f 57 41 4c 4c 20 31 20 2f |e FOUND_WALL 1 /| 00000550 2a 20 74 68 69 73 20 66 6c 61 67 20 69 73 20 75 |* this flag is u| 00000560 73 65 64 20 74 6f 20 69 6e 64 69 63 61 74 65 20 |sed to indicate | 00000570 77 68 65 6e 20 61 6e 20 69 6e 74 65 72 73 65 63 |when an intersec| 00000580 74 69 6f 6e 20 68 61 73 20 62 65 20 66 6f 75 6e |tion has be foun| 00000590 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 41 58 |d */.#define MAX| 000005a0 5f 44 49 53 54 41 4e 43 45 20 34 30 30 30 20 2f |_DISTANCE 4000 /| 000005b0 2a 20 74 68 69 73 20 64 65 66 69 6e 65 73 20 74 |* this defines t| 000005c0 68 65 20 6c 61 72 67 65 73 74 20 64 69 73 74 61 |he largest dista| 000005d0 6e 63 65 20 61 20 72 61 79 20 63 6f 75 6c 64 20 |nce a ray could | 000005e0 74 72 61 76 65 6c 20 69 6e 20 74 68 65 20 77 6f |travel in the wo| 000005f0 72 6c 64 2c 20 75 73 65 64 20 66 6f 72 20 6c 6f |rld, used for lo| 00000600 6f 6b 20 75 70 20 74 61 62 6c 65 73 20 2a 2f 0a |ok up tables */.| 00000610 23 64 65 66 69 6e 65 20 4d 41 58 5f 53 43 41 4c |#define MAX_SCAL| 00000620 45 20 33 30 30 20 2f 2a 20 75 73 65 64 20 66 6f |E 300 /* used fo| 00000630 72 20 63 6c 69 70 70 69 6e 67 20 2a 2f 0a 23 64 |r clipping */.#d| 00000640 65 66 69 6e 65 20 43 4c 4f 53 45 53 54 20 35 30 |efine CLOSEST 50| 00000650 20 2f 2a 20 74 68 69 73 20 73 74 6f 72 65 73 20 | /* this stores | 00000660 74 68 65 20 63 6c 6f 73 65 73 74 20 61 20 70 6c |the closest a pl| 00000670 61 79 65 72 20 63 61 6e 20 77 61 6c 6b 20 69 6e |ayer can walk in| 00000680 74 6f 20 61 20 77 61 6c 6c 20 2a 2f 0a 2f 2a 20 |to a wall */./* | 00000690 4e 45 57 20 75 73 65 20 6f 66 20 41 4e 47 4c 45 |NEW use of ANGLE| 000006a0 53 20 76 61 72 69 61 62 6c 65 73 2c 20 74 68 65 |S variables, the| 000006b0 79 20 61 72 65 20 6e 6f 77 20 6e 6f 74 20 64 65 |y are now not de| 000006c0 66 69 6e 65 73 20 62 75 74 20 61 72 65 20 69 6e |fines but are in| 000006d0 70 75 74 74 65 64 20 62 79 20 74 68 65 20 63 6f |putted by the co| 000006e0 6d 6d 61 6e 64 20 6c 69 6e 65 20 61 74 20 74 68 |mmand line at th| 000006f0 65 20 62 65 67 69 6e 6e 69 6e 67 20 6f 66 20 6d |e beginning of m| 00000700 61 69 6e 28 29 2a 2f 0a 0a 2f 2a 20 4f 4c 44 20 |ain()*/../* OLD | 00000710 64 65 66 69 6e 65 73 20 68 61 76 65 20 62 65 65 |defines have bee| 00000720 6e 20 63 6f 6e 76 65 72 74 65 64 20 74 6f 20 69 |n converted to i| 00000730 6e 74 65 67 65 72 73 20 62 65 63 61 75 73 65 20 |ntegers because | 00000740 77 65 20 6e 6f 77 20 6c 6f 61 64 20 74 68 65 6d |we now load them| 00000750 20 69 6e 20 66 72 6f 6d 20 74 68 65 20 63 6f 6d | in from the com| 00000760 6d 61 6e 64 20 6c 69 6e 65 20 2a 2f 0a 69 6e 74 |mand line */.int| 00000770 20 41 4e 47 4c 45 5f 30 2c 41 4e 47 4c 45 5f 36 | ANGLE_0,ANGLE_6| 00000780 2c 41 4e 47 4c 45 5f 33 30 2c 41 4e 47 4c 45 5f |,ANGLE_30,ANGLE_| 00000790 39 30 2c 41 4e 47 4c 45 5f 31 38 30 2c 41 4e 47 |90,ANGLE_180,ANG| 000007a0 4c 45 5f 32 37 30 2c 41 4e 47 4c 45 5f 33 36 30 |LE_270,ANGLE_360| 000007b0 2c 53 54 45 50 5f 4c 45 4e 47 54 48 2c 56 45 52 |,STEP_LENGTH,VER| 000007c0 54 49 43 41 4c 5f 53 43 41 4c 45 2c 56 49 45 57 |TICAL_SCALE,VIEW| 000007d0 56 41 52 2c 56 49 45 57 56 41 52 54 2c 53 43 52 |VAR,VIEWVART,SCR| 000007e0 45 45 4e 5f 48 45 49 47 48 54 2c 53 43 52 45 45 |EEN_HEIGHT,SCREE| 000007f0 4e 5f 57 49 44 54 48 2c 44 45 4d 4f 5f 52 45 41 |N_WIDTH,DEMO_REA| 00000800 44 2c 44 45 4d 4f 5f 57 52 49 54 45 3b 0a 0a 2f |D,DEMO_WRITE;../| 00000810 2a 20 47 4c 4f 42 41 4c 20 76 61 72 69 61 62 6c |* GLOBAL variabl| 00000820 65 73 20 2a 2f 0a 0a 63 68 61 72 20 77 6f 72 6c |es */..char worl| 00000830 64 5b 57 4f 52 4c 44 5f 48 45 49 47 48 54 2b 31 |d[WORLD_HEIGHT+1| 00000840 5d 5b 57 4f 52 4c 44 5f 57 49 44 54 48 2b 31 5d |][WORLD_WIDTH+1]| 00000850 3b 2f 2a 20 54 68 69 73 20 68 6f 6c 64 73 20 6f |;/* This holds o| 00000860 75 72 20 74 65 78 74 20 64 61 74 61 20 66 69 6c |ur text data fil| 00000870 65 20 2a 2f 0a 63 68 61 72 20 6f 62 6a 65 63 74 |e */.char object| 00000880 73 5b 57 4f 52 4c 44 5f 48 45 49 47 48 54 2b 31 |s[WORLD_HEIGHT+1| 00000890 5d 5b 57 4f 52 4c 44 5f 57 49 44 54 48 2b 31 5d |][WORLD_WIDTH+1]| 000008a0 3b 20 2f 2a 20 4e 45 57 20 6f 62 6a 65 63 74 20 |; /* NEW object | 000008b0 61 72 72 61 79 20 28 61 73 20 77 6f 72 6c 64 29 |array (as world)| 000008c0 2a 2f 0a 63 68 61 72 20 77 61 6c 6c 73 5b 57 41 |*/.char walls[WA| 000008d0 4c 4c 5f 4e 55 4d 42 45 52 2b 31 5d 5b 28 57 41 |LL_NUMBER+1][(WA| 000008e0 4c 4c 5f 57 49 44 54 48 2a 57 41 4c 4c 5f 48 45 |LL_WIDTH*WALL_HE| 000008f0 49 47 48 54 29 2b 31 5d 3b 0a 63 68 61 72 20 6f |IGHT)+1];.char o| 00000900 62 6a 67 72 61 70 68 69 63 73 5b 57 41 4c 4c 5f |bjgraphics[WALL_| 00000910 4e 55 4d 42 45 52 2b 31 5d 5b 28 57 41 4c 4c 5f |NUMBER+1][(WALL_| 00000920 57 49 44 54 48 2a 57 41 4c 4c 5f 48 45 49 47 48 |WIDTH*WALL_HEIGH| 00000930 54 29 2b 31 5d 3b 0a 0a 2f 2a 20 54 68 69 73 20 |T)+1];../* This | 00000940 68 6f 6c 64 73 20 74 68 65 20 77 61 6c 6c 20 67 |holds the wall g| 00000950 72 61 70 68 69 63 73 20 69 6e 20 61 20 74 77 6f |raphics in a two| 00000960 20 64 69 6d 65 6e 73 69 6f 6e 61 6c 20 61 72 72 | dimensional arr| 00000970 61 79 20 2a 2f 0a 2f 2a 20 4e 6f 74 65 20 74 68 |ay */./* Note th| 00000980 65 20 75 73 61 67 65 20 6f 66 20 63 68 61 72 20 |e usage of char | 00000990 61 6e 64 20 6e 6f 74 20 22 69 6e 74 22 20 69 6e |and not "int" in| 000009a0 20 62 6f 74 68 20 63 61 73 65 73 2e 20 54 68 69 | both cases. Thi| 000009b0 73 20 69 73 20 62 65 63 61 75 73 65 20 61 20 63 |s is because a c| 000009c0 68 61 72 20 69 73 20 38 20 62 79 74 65 73 2c 20 |har is 8 bytes, | 000009d0 77 68 69 63 68 20 67 69 76 65 73 20 32 35 36 20 |which gives 256 | 000009e0 63 6f 6c 6f 75 72 73 20 28 75 73 65 64 20 69 6e |colours (used in| 000009f0 20 6f 75 72 20 4d 6f 64 65 20 31 33 20 73 63 72 | our Mode 13 scr| 00000a00 65 65 6e 29 20 61 6e 64 20 61 6c 73 6f 20 61 6e |een) and also an| 00000a10 20 69 6e 74 65 67 65 72 20 75 70 20 74 6f 20 32 | integer up to 2| 00000a20 35 36 2c 20 77 68 65 6e 20 6f 75 72 20 74 65 78 |56, when our tex| 00000a30 74 20 66 69 6c 65 20 64 6f 65 73 6e 27 74 20 67 |t file doesn't g| 00000a40 6f 20 6f 76 65 72 20 32 30 20 69 6e 20 6e 75 6d |o over 20 in num| 00000a50 62 65 72 21 20 48 65 6e 63 65 20 74 68 65 72 65 |ber! Hence there| 00000a60 20 69 73 20 6e 6f 20 6e 65 65 64 20 66 6f 72 20 | is no need for | 00000a70 61 6e 20 69 6e 74 20 61 72 72 61 79 20 69 6e 20 |an int array in | 00000a80 65 69 74 68 65 72 20 63 61 73 65 2e 20 2a 2f 0a |either case. */.| 00000a90 0a 63 68 61 72 20 2a 73 63 72 65 65 6e 5f 61 64 |.char *screen_ad| 00000aa0 64 72 65 73 73 3b 20 2f 2a 20 74 68 69 73 20 77 |dress; /* this w| 00000ab0 69 6c 6c 20 68 6f 6c 64 20 74 68 65 20 62 61 73 |ill hold the bas| 00000ac0 65 20 6f 66 20 74 68 65 20 73 63 72 65 65 6e 20 |e of the screen | 00000ad0 6d 65 6d 6f 72 79 20 77 68 69 63 68 20 77 65 20 |memory which we | 00000ae0 77 69 6c 6c 20 6d 61 6e 69 70 75 6c 61 74 65 2e |will manipulate.| 00000af0 20 42 79 20 61 6c 74 65 72 69 6e 67 20 76 61 6c | By altering val| 00000b00 75 65 73 20 69 6e 20 74 68 65 20 73 63 72 65 65 |ues in the scree| 00000b10 6e 20 6d 65 6d 6f 72 79 2c 20 77 65 20 61 6c 74 |n memory, we alt| 00000b20 65 72 20 77 68 61 74 20 61 70 70 65 61 72 73 20 |er what appears | 00000b30 6f 6e 20 74 68 65 20 73 63 72 65 65 6e 2e 20 4e |on the screen. N| 00000b40 6f 74 65 20 74 68 61 74 20 74 68 69 73 20 69 73 |ote that this is| 00000b50 20 6f 66 20 74 79 70 65 20 22 63 68 61 72 20 2a | of type "char *| 00000b60 22 20 62 65 63 61 75 73 65 20 69 74 20 68 6f 6c |" because it hol| 00000b70 64 73 20 74 68 65 20 6d 65 6d 6f 72 79 20 61 64 |ds the memory ad| 00000b80 64 72 65 73 73 20 6f 66 20 61 20 62 79 74 65 20 |dress of a byte | 00000b90 61 72 72 61 79 20 2d 20 74 68 65 20 32 35 36 20 |array - the 256 | 00000ba0 63 6f 6c 6f 75 72 20 6d 6f 64 65 20 31 33 20 73 |colour mode 13 s| 00000bb0 63 72 65 65 6e 20 28 77 65 6c 6c 20 69 74 20 77 |creen (well it w| 00000bc0 69 6c 6c 20 64 6f 21 29 20 2a 2f 0a 63 68 61 72 |ill do!) */.char| 00000bd0 20 2a 73 63 72 65 65 6e 5f 61 64 64 72 65 73 73 | *screen_address| 00000be0 5f 62 61 6e 6b 3b 20 2f 2a 20 74 68 69 73 20 69 |_bank; /* this i| 00000bf0 73 20 61 6e 6f 74 68 65 72 20 70 6f 69 6e 74 65 |s another pointe| 00000c00 72 20 74 6f 20 74 68 65 20 6f 74 68 65 72 20 61 |r to the other a| 00000c10 72 65 61 20 6f 66 20 73 63 72 65 65 6e 20 6d 65 |rea of screen me| 00000c20 6d 6f 72 79 20 77 68 69 63 68 20 77 65 20 77 69 |mory which we wi| 00000c30 6c 6c 20 62 65 20 75 73 69 6e 67 20 66 6f 72 20 |ll be using for | 00000c40 53 43 52 45 45 4e 20 42 41 4e 4b 49 4e 47 20 2d |SCREEN BANKING -| 00000c50 20 61 76 6f 69 64 69 6e 67 20 66 6c 69 63 6b 65 | avoiding flicke| 00000c60 72 69 6e 67 20 6f 66 20 74 68 65 20 73 63 72 65 |ring of the scre| 00000c70 65 6e 20 64 75 72 69 6e 67 20 61 6e 69 6d 61 74 |en during animat| 00000c80 69 6e 67 20 67 72 61 70 68 69 63 73 20 2a 2f 0a |ing graphics */.| 00000c90 63 68 61 72 20 2a 73 63 72 65 65 6e 5f 61 64 64 |char *screen_add| 00000ca0 72 65 73 73 5f 74 65 6d 70 3b 20 2f 2a 20 74 68 |ress_temp; /* th| 00000cb0 69 73 20 69 73 20 61 20 73 70 61 72 65 20 70 6f |is is a spare po| 00000cc0 69 6e 74 65 72 20 66 6f 72 20 75 73 65 20 64 75 |inter for use du| 00000cd0 72 69 6e 67 20 74 68 65 20 73 77 69 74 63 68 69 |ring the switchi| 00000ce0 6e 67 20 6f 66 20 74 68 65 20 74 77 6f 20 61 62 |ng of the two ab| 00000cf0 6f 76 65 20 76 61 6c 75 65 73 20 2a 2f 0a 0a 2f |ove values */../| 00000d00 2a 20 74 68 65 73 65 20 6e 65 77 20 46 49 58 45 |* these new FIXE| 00000d10 44 20 50 4f 49 4e 54 20 49 4e 54 45 47 45 52 20 |D POINT INTEGER | 00000d20 70 6f 69 6e 74 65 72 73 20 70 6f 69 6e 74 20 74 |pointers point t| 00000d30 6f 20 6c 6f 6f 6b 2d 75 70 20 74 61 62 6c 65 73 |o look-up tables| 00000d40 20 75 73 65 64 20 69 6e 20 74 68 65 20 72 61 79 | used in the ray| 00000d50 20 63 61 73 74 69 6e 67 20 65 6e 67 69 6e 65 2e | casting engine.| 00000d60 20 54 68 65 73 65 20 61 72 65 20 65 78 70 6c 61 | These are expla| 00000d70 69 6e 65 64 20 6f 66 20 69 6e 20 74 68 65 20 65 |ined of in the e| 00000d80 6e 67 69 6e 65 2c 20 62 75 74 20 74 68 65 20 6c |ngine, but the l| 00000d90 6f 6f 6b 2d 75 70 73 20 61 72 65 20 67 65 6e 65 |ook-ups are gene| 00000da0 72 61 74 65 64 20 69 6e 20 61 75 61 5f 74 61 62 |rated in aua_tab| 00000db0 6c 65 73 28 29 20 2a 2f 0a 0a 69 6e 74 20 2a 74 |les() */..int *t| 00000dc0 61 6e 5f 74 61 62 6c 65 2c 2a 69 6e 76 5f 74 61 |an_table,*inv_ta| 00000dd0 6e 5f 74 61 62 6c 65 3b 20 2f 2a 20 70 6f 69 6e |n_table; /* poin| 00000de0 74 65 72 73 20 74 6f 20 74 61 6e 67 65 6e 74 20 |ters to tangent | 00000df0 6c 6f 6f 6b 5f 75 70 73 20 2a 2f 0a 69 6e 74 20 |look_ups */.int | 00000e00 2a 79 5f 73 74 65 70 2c 2a 78 5f 73 74 65 70 3b |*y_step,*x_step;| 00000e10 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 70 6f | /* po| 00000e20 69 6e 74 65 72 73 20 74 6f 20 6d 6f 72 65 20 63 |inters to more c| 00000e30 6f 6d 70 6c 65 78 20 6c 6f 6f 6b 5f 75 70 73 20 |omplex look_ups | 00000e40 2a 2f 0a 69 6e 74 20 2a 69 6e 76 5f 63 6f 73 5f |*/.int *inv_cos_| 00000e50 74 61 62 6c 65 2c 20 20 20 20 20 20 20 20 20 20 |table, | 00000e60 20 20 2f 2a 20 73 69 6e 2f 63 6f 73 20 74 61 62 | /* sin/cos tab| 00000e70 6c 65 73 20 28 6c 6f 6f 6b 5f 75 70 73 29 20 20 |les (look_ups) | 00000e80 20 20 2a 2f 0a 20 20 20 20 2a 69 6e 76 5f 73 69 | */. *inv_si| 00000e90 6e 5f 74 61 62 6c 65 3b 0a 69 6e 74 20 2a 63 6f |n_table;.int *co| 00000ea0 73 5f 74 61 62 6c 65 3b 20 20 20 20 20 20 20 20 |s_table; | 00000eb0 20 20 20 20 20 20 20 20 2f 2a 20 63 6f 73 69 6e | /* cosin| 00000ec0 61 6c 20 6c 6f 6f 6b 5f 75 70 20 74 61 62 6c 65 |al look_up table| 00000ed0 20 20 20 20 2a 2f 0a 69 6e 74 20 2a 72 65 63 69 | */.int *reci| 00000ee0 70 5f 74 61 62 6c 65 3b 20 20 20 20 20 20 20 20 |p_table; | 00000ef0 20 20 20 20 20 20 2f 2a 20 72 65 63 69 70 72 6f | /* recipro| 00000f00 63 61 6c 20 74 61 62 6c 65 20 75 73 65 64 20 69 |cal table used i| 00000f10 6e 73 74 65 61 64 20 6f 66 20 61 20 2a 2f 0a 20 |nstead of a */. | 00000f20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000f30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a | /*| 00000f40 20 64 69 76 69 73 69 6f 6e 2e 20 53 65 65 20 6c | division. See l| 00000f50 61 74 65 72 20 2a 2f 0a 69 6e 74 20 2a 63 6f 73 |ater */.int *cos| 00000f60 6f 5f 74 61 62 6c 65 2c 2a 73 69 6e 6f 5f 74 61 |o_table,*sino_ta| 00000f70 62 6c 65 3b 20 20 20 2f 2a 20 74 68 65 73 65 20 |ble; /* these | 00000f80 74 77 6f 20 74 61 62 6c 65 73 20 61 72 65 20 66 |two tables are f| 00000f90 6f 72 20 6f 62 6a 65 63 74 73 20 2a 2f 0a 69 6e |or objects */.in| 00000fa0 74 20 2a 64 78 5f 74 61 62 6c 65 2c 20 20 20 20 |t *dx_table, | 00000fb0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 | /* | 00000fc0 46 49 58 45 44 20 50 4f 49 4e 54 20 74 61 62 6c |FIXED POINT tabl| 00000fd0 65 73 20 66 6f 72 20 6d 6f 76 69 6e 67 20 74 68 |es for moving th| 00000fe0 65 20 2a 2f 0a 20 20 20 20 2a 64 79 5f 74 61 62 |e */. *dy_tab| 00000ff0 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 |le; | 00001000 20 20 20 20 2f 2a 20 76 69 65 77 20 70 6f 69 6e | /* view poin| 00001010 74 20 76 65 72 79 20 71 75 69 63 6b 6c 79 20 2a |t very quickly *| 00001020 2f 0a 69 6e 74 20 73 63 61 6c 65 5f 61 72 72 61 |/.int scale_arra| 00001030 79 5b 33 32 30 5d 3b 20 20 20 20 20 20 20 20 20 |y[320]; | 00001040 20 2f 2a 20 4e 45 57 20 75 73 65 64 20 74 6f 20 | /* NEW used to | 00001050 73 74 6f 72 65 20 73 63 61 6c 65 20 76 61 6c 75 |store scale valu| 00001060 65 73 20 6f 66 20 65 61 63 68 20 2a 2f 0a 20 20 |es of each */. | 00001070 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00001080 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 | /* | 00001090 73 6c 69 76 65 72 2c 66 6f 72 20 6f 62 6a 65 63 |sliver,for objec| 000010a0 74 73 20 6c 61 74 65 72 20 6f 6e 20 2a 2f 0a 0a |ts later on */..| 000010b0 2f 2a 20 46 55 4e 43 54 49 4f 4e 20 64 65 66 69 |/* FUNCTION defi| 000010c0 6e 69 74 69 6f 6e 73 20 2a 2f 0a 0a 2f 2a 20 74 |nitions */../* t| 000010d0 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 67 65 6e |his function gen| 000010e0 65 72 61 74 65 73 20 4c 4f 4f 4b 20 55 50 20 74 |erates LOOK UP t| 000010f0 61 62 6c 65 73 20 2d 20 61 72 72 61 79 73 20 68 |ables - arrays h| 00001100 6f 6c 64 69 6e 67 20 70 72 65 2d 63 61 6c 63 75 |olding pre-calcu| 00001110 6c 61 74 65 64 20 74 72 69 67 6f 6e 6f 6d 65 74 |lated trigonomet| 00001120 72 69 63 20 76 61 72 69 61 62 6c 65 73 20 75 73 |ric variables us| 00001130 65 64 20 69 6e 20 74 68 65 20 72 61 79 20 63 61 |ed in the ray ca| 00001140 73 74 69 6e 67 20 70 72 6f 63 65 73 73 20 2a 2f |sting process */| 00001150 0a 0a 76 6f 69 64 20 61 75 61 5f 74 61 62 6c 65 |..void aua_table| 00001160 73 28 76 6f 69 64 29 0a 7b 0a 0a 69 6e 74 20 61 |s(void).{..int a| 00001170 6e 67 2c 20 2f 2a 20 74 68 69 73 20 69 73 20 75 |ng, /* this is u| 00001180 73 65 64 20 74 6f 20 68 6f 6c 64 20 76 61 6c 75 |sed to hold valu| 00001190 65 73 20 77 68 69 6c 65 20 6d 61 6b 69 6e 67 20 |es while making | 000011a0 6c 6f 6f 6b 2d 75 70 73 20 2a 2f 0a 20 20 20 20 |look-ups */. | 000011b0 61 6e 67 74 3b 20 2f 2a 20 73 61 6d 65 20 2a 2f |angt; /* same */| 000011c0 0a 0a 66 6c 6f 61 74 20 72 61 64 5f 61 6e 67 6c |..float rad_angl| 000011d0 65 3b 20 2f 2a 20 74 68 69 73 20 68 6f 6c 64 73 |e; /* this holds| 000011e0 20 74 68 65 20 72 61 64 69 61 6e 73 20 65 71 75 | the radians equ| 000011f0 69 76 61 6c 65 6e 74 20 6f 66 20 74 68 65 20 66 |ivalent of the f| 00001200 69 78 65 64 20 70 6f 69 6e 74 20 61 6e 67 6c 65 |ixed point angle| 00001210 20 73 79 73 74 65 6d 20 28 30 2d 31 39 32 30 20 | system (0-1920 | 00001220 3d 20 30 2d 33 36 30 20 64 65 67 72 65 65 73 20 |= 0-360 degrees | 00001230 3d 20 30 2d 36 2e 77 68 61 74 65 76 65 72 20 72 |= 0-6.whatever r| 00001240 61 64 69 61 6e 73 2e 20 4e 65 78 74 20 6d 6f 6e |adians. Next mon| 00001250 74 68 20 49 27 6c 6c 20 62 65 20 63 68 61 6e 67 |th I'll be chang| 00001260 69 6e 67 20 74 68 65 20 73 79 73 74 65 6d 20 73 |ing the system s| 00001270 6f 20 69 74 20 62 65 63 6f 6d 65 73 20 30 2d 31 |o it becomes 0-1| 00001280 38 30 30 20 69 6e 73 74 65 61 64 20 6f 66 20 31 |800 instead of 1| 00001290 39 32 30 2c 20 74 68 69 73 20 77 69 6c 6c 20 61 |920, this will a| 000012a0 6c 6c 6f 77 20 61 20 73 6c 69 67 68 74 6c 79 20 |llow a slightly | 000012b0 73 6d 61 6c 6c 65 72 20 73 63 72 65 65 6e 20 77 |smaller screen w| 000012c0 69 64 74 68 2c 20 6d 6f 72 65 20 6c 69 6b 65 20 |idth, more like | 000012d0 57 6f 6c 66 65 6e 73 74 65 69 6e 2c 20 74 68 69 |Wolfenstein, thi| 000012e0 73 20 77 69 6c 6c 20 6c 65 61 64 20 74 6f 20 61 |s will lead to a| 000012f0 6e 20 69 6e 63 72 65 61 73 65 20 69 6e 20 66 72 |n increase in fr| 00001300 61 6d 65 20 72 61 74 65 2e 20 59 65 73 21 20 2a |ame rate. Yes! *| 00001310 2f 0a 0a 2f 2a 20 64 79 6e 61 6d 69 63 61 6c 6c |/../* dynamicall| 00001320 79 20 61 6c 6c 6f 63 61 74 65 64 20 61 64 65 71 |y allocated adeq| 00001330 75 61 74 65 20 6d 65 6d 6f 72 79 20 66 6f 72 20 |uate memory for | 00001340 74 68 65 20 6c 6f 6f 6b 2d 75 70 73 20 2a 2f 0a |the look-ups */.| 00001350 74 61 6e 5f 74 61 62 6c 65 20 20 20 20 20 3d 20 |tan_table = | 00001360 28 69 6e 74 20 2a 29 6d 61 6c 6c 6f 63 28 73 69 |(int *)malloc(si| 00001370 7a 65 6f 66 28 69 6e 74 29 20 2a 20 28 41 4e 47 |zeof(int) * (ANG| 00001380 4c 45 5f 33 36 30 2b 31 29 29 3b 0a 69 6e 76 5f |LE_360+1));.inv_| 00001390 74 61 6e 5f 74 61 62 6c 65 20 3d 20 28 69 6e 74 |tan_table = (int| 000013a0 20 2a 29 6d 61 6c 6c 6f 63 28 73 69 7a 65 6f 66 | *)malloc(sizeof| 000013b0 28 69 6e 74 29 20 2a 20 28 41 4e 47 4c 45 5f 33 |(int) * (ANGLE_3| 000013c0 36 30 2b 31 29 29 3b 0a 0a 79 5f 73 74 65 70 20 |60+1));..y_step | 000013d0 20 20 20 20 20 20 20 3d 20 28 69 6e 74 20 2a 29 | = (int *)| 000013e0 6d 61 6c 6c 6f 63 28 73 69 7a 65 6f 66 28 69 6e |malloc(sizeof(in| 000013f0 74 29 20 2a 20 28 41 4e 47 4c 45 5f 33 36 30 2b |t) * (ANGLE_360+| 00001400 31 29 29 3b 0a 78 5f 73 74 65 70 20 20 20 20 20 |1));.x_step | 00001410 20 20 20 3d 20 28 69 6e 74 20 20 2a 29 6d 61 6c | = (int *)mal| 00001420 6c 6f 63 28 73 69 7a 65 6f 66 28 69 6e 74 29 20 |loc(sizeof(int) | 00001430 2a 20 28 41 4e 47 4c 45 5f 33 36 30 2b 31 29 29 |* (ANGLE_360+1))| 00001440 3b 0a 0a 63 6f 73 5f 74 61 62 6c 65 20 20 20 20 |;..cos_table | 00001450 20 3d 20 28 69 6e 74 20 20 2a 29 6d 61 6c 6c 6f | = (int *)mallo| 00001460 63 28 73 69 7a 65 6f 66 28 69 6e 74 29 20 2a 20 |c(sizeof(int) * | 00001470 28 41 4e 47 4c 45 5f 33 36 30 2b 31 29 29 3b 0a |(ANGLE_360+1));.| 00001480 69 6e 76 5f 63 6f 73 5f 74 61 62 6c 65 20 3d 20 |inv_cos_table = | 00001490 28 69 6e 74 20 20 2a 29 6d 61 6c 6c 6f 63 28 73 |(int *)malloc(s| 000014a0 69 7a 65 6f 66 28 69 6e 74 29 20 2a 20 28 41 4e |izeof(int) * (AN| 000014b0 47 4c 45 5f 33 36 30 2b 31 29 29 3b 0a 69 6e 76 |GLE_360+1));.inv| 000014c0 5f 73 69 6e 5f 74 61 62 6c 65 20 3d 20 28 69 6e |_sin_table = (in| 000014d0 74 20 20 2a 29 6d 61 6c 6c 6f 63 28 73 69 7a 65 |t *)malloc(size| 000014e0 6f 66 28 69 6e 74 29 20 2a 20 28 41 4e 47 4c 45 |of(int) * (ANGLE| 000014f0 5f 33 36 30 2b 31 29 29 3b 0a 2f 2a 20 6e 65 77 |_360+1));./* new| 00001500 20 74 61 62 6c 65 2c 20 66 6f 72 20 74 68 65 20 | table, for the | 00001510 65 6e 67 69 6e 65 2c 20 74 6f 20 61 76 6f 69 64 |engine, to avoid| 00001520 20 75 73 69 6e 67 20 61 20 64 69 76 69 64 65 20 | using a divide | 00001530 2a 2f 0a 72 65 63 69 70 5f 74 61 62 6c 65 20 20 |*/.recip_table | 00001540 20 3d 20 28 69 6e 74 20 20 2a 29 6d 61 6c 6c 6f | = (int *)mallo| 00001550 63 28 73 69 7a 65 6f 66 28 69 6e 74 29 20 2a 20 |c(sizeof(int) * | 00001560 28 4d 41 58 5f 44 49 53 54 41 4e 43 45 2b 31 29 |(MAX_DISTANCE+1)| 00001570 29 3b 0a 2f 2a 20 6e 65 77 20 74 61 62 6c 65 73 |);./* new tables| 00001580 20 66 6f 72 20 6d 6f 76 69 6e 67 20 74 68 65 20 | for moving the | 00001590 76 69 65 77 20 70 6f 69 6e 74 20 2a 2f 0a 64 78 |view point */.dx| 000015a0 5f 74 61 62 6c 65 20 20 20 20 20 20 3d 20 28 69 |_table = (i| 000015b0 6e 74 20 20 2a 29 6d 61 6c 6c 6f 63 28 73 69 7a |nt *)malloc(siz| 000015c0 65 6f 66 28 69 6e 74 29 20 2a 20 28 41 4e 47 4c |eof(int) * (ANGL| 000015d0 45 5f 33 36 30 2b 31 29 29 3b 0a 64 79 5f 74 61 |E_360+1));.dy_ta| 000015e0 62 6c 65 20 20 20 20 20 20 3d 20 28 69 6e 74 20 |ble = (int | 000015f0 20 2a 29 6d 61 6c 6c 6f 63 28 73 69 7a 65 6f 66 | *)malloc(sizeof| 00001600 28 69 6e 74 29 20 2a 20 28 41 4e 47 4c 45 5f 33 |(int) * (ANGLE_3| 00001610 36 30 2b 31 29 29 3b 0a 2f 2a 20 67 65 6e 65 72 |60+1));./* gener| 00001620 61 74 65 20 74 68 65 6d 2c 20 74 68 65 69 72 20 |ate them, their | 00001630 75 73 65 20 69 73 20 65 78 70 6c 61 69 6e 65 64 |use is explained| 00001640 20 69 6e 20 74 68 65 20 72 61 79 20 63 61 73 74 | in the ray cast| 00001650 69 6e 67 20 65 6e 67 69 6e 65 20 2a 2f 0a 2f 2a |ing engine */./*| 00001660 20 74 77 6f 20 6e 65 77 20 74 61 62 6c 65 73 20 | two new tables | 00001670 74 6f 20 75 73 65 20 66 6f 72 20 6f 62 6a 65 63 |to use for objec| 00001680 74 20 70 6c 6f 74 74 69 6e 67 20 2a 2f 0a 63 6f |t plotting */.co| 00001690 73 6f 5f 74 61 62 6c 65 20 20 20 20 20 3d 20 28 |so_table = (| 000016a0 69 6e 74 20 20 2a 29 6d 61 6c 6c 6f 63 28 73 69 |int *)malloc(si| 000016b0 7a 65 6f 66 28 69 6e 74 29 20 2a 20 28 41 4e 47 |zeof(int) * (ANG| 000016c0 4c 45 5f 33 36 30 2b 31 29 29 3b 0a 73 69 6e 6f |LE_360+1));.sino| 000016d0 5f 74 61 62 6c 65 20 3d 20 20 20 20 20 28 69 6e |_table = (in| 000016e0 74 20 20 2a 29 6d 61 6c 6c 6f 63 28 73 69 7a 65 |t *)malloc(size| 000016f0 6f 66 28 69 6e 74 29 20 2a 20 28 41 4e 47 4c 45 |of(int) * (ANGLE| 00001700 5f 33 36 30 2b 31 29 29 3b 0a 0a 66 6f 72 28 61 |_360+1));..for(a| 00001710 6e 67 74 3d 41 4e 47 4c 45 5f 30 3b 61 6e 67 74 |ngt=ANGLE_0;angt| 00001720 3c 3d 41 4e 47 4c 45 5f 33 36 30 3b 61 6e 67 74 |<=ANGLE_360;angt| 00001730 2b 2b 29 0a 7b 0a 61 6e 67 3d 61 6e 67 74 3b 0a |++).{.ang=angt;.| 00001740 2f 2a 20 74 68 69 73 20 6e 65 78 74 20 6c 69 6e |/* this next lin| 00001750 65 20 63 61 6c 63 75 6c 61 74 65 73 20 74 68 65 |e calculates the| 00001760 20 72 61 64 69 61 6e 20 61 6e 67 6c 65 20 74 6f | radian angle to| 00001770 20 70 61 73 73 20 74 6f 20 74 68 65 20 74 72 69 | pass to the tri| 00001780 67 2e 20 66 75 6e 63 74 69 6f 6e 73 20 2a 2f 0a |g. functions */.| 00001790 72 61 64 5f 61 6e 67 6c 65 3d 28 66 6c 6f 61 74 |rad_angle=(float| 000017a0 29 28 28 33 2e 32 37 32 65 2d 34 29 20 2b 20 61 |)((3.272e-4) + a| 000017b0 6e 67 20 2a 20 32 2a 33 2e 31 34 31 35 39 32 36 |ng * 2*3.1415926| 000017c0 35 34 2f 41 4e 47 4c 45 5f 33 36 30 29 3b 0a 0a |54/ANGLE_360);..| 000017d0 74 61 6e 5f 74 61 62 6c 65 5b 61 6e 67 5d 3d 28 |tan_table[ang]=(| 000017e0 69 6e 74 29 28 74 61 6e 28 72 61 64 5f 61 6e 67 |int)(tan(rad_ang| 000017f0 6c 65 29 2a 36 35 35 33 36 29 3b 0a 69 6e 76 5f |le)*65536);.inv_| 00001800 74 61 6e 5f 74 61 62 6c 65 5b 61 6e 67 5d 3d 28 |tan_table[ang]=(| 00001810 69 6e 74 29 28 28 31 2f 74 61 6e 28 72 61 64 5f |int)((1/tan(rad_| 00001820 61 6e 67 6c 65 29 29 2a 36 35 35 33 36 29 3b 0a |angle))*65536);.| 00001830 2f 2a 20 6e 6f 74 65 20 74 68 61 20 61 62 6f 76 |/* note tha abov| 00001840 65 20 63 6f 6e 76 65 72 73 69 6f 6e 73 20 74 6f |e conversions to| 00001850 20 66 69 78 65 64 20 70 6f 69 6e 74 20 69 6e 74 | fixed point int| 00001860 65 67 65 72 73 20 2a 2f 0a 0a 2f 2a 20 77 65 20 |egers */../* we | 00001870 64 6f 20 74 68 65 20 73 61 6d 65 20 66 6f 72 20 |do the same for | 00001880 74 68 65 73 65 20 74 61 62 6c 65 73 2c 20 62 75 |these tables, bu| 00001890 74 20 75 6e 66 6f 72 74 75 6e 61 74 65 6c 79 20 |t unfortunately | 000018a0 61 74 20 74 68 65 20 61 73 79 6d 70 74 6f 74 65 |at the asymptote| 000018b0 73 20 74 68 65 20 6e 75 6d 62 65 72 73 20 62 65 |s the numbers be| 000018c0 63 6f 6d 65 20 61 77 6b 77 61 72 64 6c 79 20 6c |come awkwardly l| 000018d0 61 72 67 65 20 74 6f 20 73 74 6f 72 65 20 69 6e |arge to store in| 000018e0 20 6f 75 72 20 66 69 78 65 64 20 70 6f 69 6e 74 | our fixed point| 000018f0 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 2e | representation.| 00001900 20 49 6e 73 74 65 61 64 20 6f 66 20 6d 75 6c 74 | Instead of mult| 00001910 69 70 6c 79 69 6e 67 20 62 79 20 36 34 20 77 65 |iplying by 64 we| 00001920 20 64 6f 20 38 2c 20 74 6f 20 6d 61 6b 65 20 73 | do 8, to make s| 00001930 75 72 65 20 74 68 61 74 20 6e 6f 20 6f 76 65 72 |ure that no over| 00001940 66 6c 6f 77 20 63 61 6e 20 6f 63 63 75 72 20 61 |flow can occur a| 00001950 74 20 74 68 69 73 20 73 74 61 67 65 2e 20 57 65 |t this stage. We| 00001960 20 6f 6e 6c 79 20 6e 65 65 64 20 74 6f 20 6d 75 | only need to mu| 00001970 6c 74 69 70 6c 79 20 62 79 20 61 6e 6f 74 68 65 |ltiply by anothe| 00001980 72 20 38 20 6c 61 74 65 72 20 69 6e 20 74 68 65 |r 8 later in the| 00001990 20 65 6e 67 69 6e 65 2c 20 69 74 73 20 6f 6b 61 | engine, its oka| 000019a0 79 20 2a 2f 0a 0a 69 66 28 61 6e 67 3e 3d 41 4e |y */..if(ang>=AN| 000019b0 47 4c 45 5f 30 20 26 26 20 61 6e 67 3c 41 4e 47 |GLE_0 && ang<ANG| 000019c0 4c 45 5f 31 38 30 29 0a 7b 0a 79 5f 73 74 65 70 |LE_180).{.y_step| 000019d0 5b 61 6e 67 5d 3d 66 61 62 73 28 20 28 38 29 20 |[ang]=fabs( (8) | 000019e0 2a 20 28 74 61 6e 5f 74 61 62 6c 65 5b 61 6e 67 |* (tan_table[ang| 000019f0 5d 29 20 29 3b 0a 7d 0a 65 6c 73 65 0a 20 20 79 |]) );.}.else. y| 00001a00 5f 73 74 65 70 5b 61 6e 67 5d 3d 2d 66 61 62 73 |_step[ang]=-fabs| 00001a10 28 20 28 38 29 20 2a 20 28 74 61 6e 5f 74 61 62 |( (8) * (tan_tab| 00001a20 6c 65 5b 61 6e 67 5d 29 20 29 3b 0a 0a 69 66 28 |le[ang]) );..if(| 00001a30 61 6e 67 3e 3d 41 4e 47 4c 45 5f 39 30 20 26 26 |ang>=ANGLE_90 &&| 00001a40 20 61 6e 67 3c 41 4e 47 4c 45 5f 32 37 30 29 0a | ang<ANGLE_270).| 00001a50 7b 0a 78 5f 73 74 65 70 5b 61 6e 67 5d 3d 2d 66 |{.x_step[ang]=-f| 00001a60 61 62 73 28 20 28 38 29 20 2a 20 28 69 6e 76 5f |abs( (8) * (inv_| 00001a70 74 61 6e 5f 74 61 62 6c 65 5b 61 6e 67 5d 29 20 |tan_table[ang]) | 00001a80 29 3b 0a 7d 0a 65 6c 73 65 0a 7b 0a 78 5f 73 74 |);.}.else.{.x_st| 00001a90 65 70 5b 61 6e 67 5d 3d 66 61 62 73 28 20 28 38 |ep[ang]=fabs( (8| 00001aa0 29 20 2a 20 28 69 6e 76 5f 74 61 6e 5f 74 61 62 |) * (inv_tan_tab| 00001ab0 6c 65 5b 61 6e 67 5d 29 20 29 3b 0a 7d 0a 0a 2f |le[ang]) );.}../| 00001ac0 2a 20 63 6f 6e 76 65 72 73 69 6f 6e 20 74 6f 20 |* conversion to | 00001ad0 66 69 78 65 64 20 70 6f 69 6e 74 20 2a 2f 0a 69 |fixed point */.i| 00001ae0 6e 76 5f 63 6f 73 5f 74 61 62 6c 65 5b 61 6e 67 |nv_cos_table[ang| 00001af0 5d 3d 28 69 6e 74 29 28 28 31 2f 63 6f 73 28 72 |]=(int)((1/cos(r| 00001b00 61 64 5f 61 6e 67 6c 65 29 29 2a 36 35 35 33 36 |ad_angle))*65536| 00001b10 29 3b 0a 69 6e 76 5f 73 69 6e 5f 74 61 62 6c 65 |);.inv_sin_table| 00001b20 5b 61 6e 67 5d 3d 28 69 6e 74 29 28 28 31 2f 73 |[ang]=(int)((1/s| 00001b30 69 6e 28 72 61 64 5f 61 6e 67 6c 65 29 29 2a 36 |in(rad_angle))*6| 00001b40 35 35 33 36 29 3b 0a 2f 2a 20 63 6f 6e 76 65 72 |5536);./* conver| 00001b50 73 69 6f 6e 20 74 6f 20 66 69 78 65 64 20 70 6f |sion to fixed po| 00001b60 69 6e 74 20 6f 66 20 6f 62 6a 65 63 74 20 70 6c |int of object pl| 00001b70 6f 74 74 69 6e 67 20 73 69 6e 65 20 61 6e 64 20 |otting sine and | 00001b80 63 6f 73 69 6e 65 73 20 2a 2f 0a 73 69 6e 6f 5f |cosines */.sino_| 00001b90 74 61 62 6c 65 5b 61 6e 67 5d 3d 28 69 6e 74 29 |table[ang]=(int)| 00001ba0 28 73 69 6e 28 72 61 64 5f 61 6e 67 6c 65 2d 31 |(sin(rad_angle-1| 00001bb0 2e 35 37 30 37 39 36 33 32 37 29 2a 36 35 35 33 |.570796327)*6553| 00001bc0 36 29 3b 0a 63 6f 73 6f 5f 74 61 62 6c 65 5b 61 |6);.coso_table[a| 00001bd0 6e 67 5d 3d 28 69 6e 74 29 28 63 6f 73 28 72 61 |ng]=(int)(cos(ra| 00001be0 64 5f 61 6e 67 6c 65 2d 31 2e 35 37 30 37 39 36 |d_angle-1.570796| 00001bf0 33 32 37 29 2a 36 35 35 33 36 29 3b 0a 2f 2a 20 |327)*65536);./* | 00001c00 77 6f 72 6b 20 6f 75 74 20 74 61 62 6c 65 73 20 |work out tables | 00001c10 66 6f 72 20 6d 6f 76 69 6e 67 20 74 68 65 20 76 |for moving the v| 00001c20 69 65 77 70 6f 69 6e 74 20 2a 2f 0a 64 78 5f 74 |iewpoint */.dx_t| 00001c30 61 62 6c 65 5b 61 6e 67 5d 3d 28 69 6e 74 29 28 |able[ang]=(int)(| 00001c40 63 6f 73 28 36 2e 32 38 2a 61 6e 67 2f 41 4e 47 |cos(6.28*ang/ANG| 00001c50 4c 45 5f 33 36 30 29 2a 53 54 45 50 5f 4c 45 4e |LE_360)*STEP_LEN| 00001c60 47 54 48 29 2a 36 35 35 33 36 3b 0a 64 79 5f 74 |GTH)*65536;.dy_t| 00001c70 61 62 6c 65 5b 61 6e 67 5d 3d 28 69 6e 74 29 28 |able[ang]=(int)(| 00001c80 73 69 6e 28 36 2e 32 38 2a 61 6e 67 2f 41 4e 47 |sin(6.28*ang/ANG| 00001c90 4c 45 5f 33 36 30 29 2a 53 54 45 50 5f 4c 45 4e |LE_360)*STEP_LEN| 00001ca0 47 54 48 29 2a 36 35 35 33 36 3b 0a 7d 0a 0a 2f |GTH)*65536;.}../| 00001cb0 2a 20 74 68 65 20 63 6f 73 69 6e 65 20 74 61 62 |* the cosine tab| 00001cc0 6c 65 20 69 73 20 75 73 65 64 20 74 6f 20 67 65 |le is used to ge| 00001cd0 74 20 72 69 64 20 6f 66 20 74 68 65 20 22 66 69 |t rid of the "fi| 00001ce0 73 68 20 62 6f 77 6c 20 65 66 66 65 63 74 22 2c |sh bowl effect",| 00001cf0 20 65 78 70 6c 61 69 6e 65 64 20 69 6e 20 74 68 | explained in th| 00001d00 65 20 72 61 79 20 63 61 73 74 65 72 2e 20 42 61 |e ray caster. Ba| 00001d10 73 69 63 61 6c 6c 79 20 77 65 20 77 6f 72 6b 20 |sically we work | 00001d20 6f 75 74 20 63 6f 73 69 6e 65 73 20 66 6f 72 20 |out cosines for | 00001d30 6f 75 72 20 6f 77 6e 20 73 70 61 6e 20 6f 66 20 |our own span of | 00001d40 76 69 73 69 6f 6e 2c 20 66 72 6f 6d 20 2d 33 30 |vision, from -30| 00001d50 20 64 65 67 72 65 65 73 20 74 6f 20 2b 33 30 20 | degrees to +30 | 00001d60 64 65 67 72 65 65 73 2e 20 54 68 69 73 20 6d 65 |degrees. This me| 00001d70 61 6e 73 20 74 68 61 74 20 61 73 20 77 65 20 73 |ans that as we s| 00001d80 63 61 6e 20 66 72 6f 6d 20 6c 65 66 74 20 74 6f |can from left to| 00001d90 20 72 69 67 68 74 2c 20 6f 72 20 76 69 63 65 20 | right, or vice | 00001da0 76 65 72 73 61 2c 20 6f 75 72 20 72 61 79 73 20 |versa, our rays | 00001db0 6f 66 20 6c 69 67 68 74 20 61 72 65 20 61 63 74 |of light are act| 00001dc0 75 61 6c 6c 79 20 63 61 73 74 20 6f 75 74 20 69 |ually cast out i| 00001dd0 6e 20 61 20 63 61 72 74 65 73 69 61 6e 2c 20 63 |n a cartesian, c| 00001de0 69 72 63 75 6c 61 72 20 77 61 79 2e 20 4f 75 72 |ircular way. Our| 00001df0 20 77 6f 72 6c 64 20 69 73 20 68 6f 77 65 76 65 | world is howeve| 00001e00 72 20 73 71 75 61 72 65 2c 20 70 6f 6c 61 72 2c |r square, polar,| 00001e10 20 73 6f 20 77 65 20 68 61 76 65 20 74 6f 20 61 | so we have to a| 00001e20 63 6b 6e 6f 77 6c 65 64 67 65 20 74 68 65 20 64 |cknowledge the d| 00001e30 69 73 74 6f 72 74 69 6f 6e 20 63 61 75 73 65 64 |istortion caused| 00001e40 20 62 79 20 6d 69 78 69 6e 67 20 63 61 72 74 65 | by mixing carte| 00001e50 73 69 61 6e 20 61 6e 64 20 70 6f 6c 61 72 20 63 |sian and polar c| 00001e60 6f 6f 72 64 69 6e 61 74 65 73 2e 20 49 6e 20 74 |oordinates. In t| 00001e70 68 69 73 20 6c 6f 6f 6b 20 75 70 20 77 65 20 61 |his look up we a| 00001e80 6c 73 6f 20 68 61 76 65 20 61 20 62 69 74 20 6f |lso have a bit o| 00001e90 66 20 73 63 61 6c 69 6e 67 20 69 6e 20 69 74 2c |f scaling in it,| 00001ea0 20 79 65 74 20 6d 6f 72 65 20 74 69 6d 65 20 73 | yet more time s| 00001eb0 61 76 69 6e 67 20 21 21 21 20 2a 2f 0a 0a 66 6f |aving !!! */..fo| 00001ec0 72 28 61 6e 67 3d 2d 41 4e 47 4c 45 5f 33 30 3b |r(ang=-ANGLE_30;| 00001ed0 61 6e 67 3c 3d 41 4e 47 4c 45 5f 33 30 3b 61 6e |ang<=ANGLE_30;an| 00001ee0 67 2b 2b 29 0a 7b 0a 2f 2a 20 77 6f 72 6b 20 6f |g++).{./* work o| 00001ef0 75 74 20 72 61 64 69 61 6e 73 20 74 6f 20 70 61 |ut radians to pa| 00001f00 73 73 20 74 6f 20 63 6f 73 69 6e 65 20 66 75 6e |ss to cosine fun| 00001f10 63 74 69 6f 6e 20 2a 2f 0a 72 61 64 5f 61 6e 67 |ction */.rad_ang| 00001f20 6c 65 3d 28 66 6c 6f 61 74 29 28 28 33 2e 32 37 |le=(float)((3.27| 00001f30 32 65 2d 34 29 2b 20 61 6e 67 20 2a 20 32 2a 33 |2e-4)+ ang * 2*3| 00001f40 2e 31 34 31 35 39 32 36 35 34 2f 41 4e 47 4c 45 |.141592654/ANGLE| 00001f50 5f 33 36 30 29 3b 0a 0a 2f 2a 66 69 78 65 64 20 |_360);../*fixed | 00001f60 70 6f 69 6e 74 20 63 6f 6e 76 65 72 73 69 6f 6e |point conversion| 00001f70 20 2a 2f 0a 63 6f 73 5f 74 61 62 6c 65 5b 61 6e | */.cos_table[an| 00001f80 67 2b 41 4e 47 4c 45 5f 33 30 5d 3d 28 69 6e 74 |g+ANGLE_30]=(int| 00001f90 29 28 56 45 52 54 49 43 41 4c 5f 53 43 41 4c 45 |)(VERTICAL_SCALE| 00001fa0 2f 28 63 6f 73 28 72 61 64 5f 61 6e 67 6c 65 29 |/(cos(rad_angle)| 00001fb0 29 2a 36 35 35 33 36 29 3b 0a 7d 0a 0a 2f 2a 20 |)*65536);.}../* | 00001fc0 74 68 69 73 20 63 72 65 61 74 65 73 20 61 20 72 |this creates a r| 00001fd0 65 63 69 70 72 6f 63 61 6c 20 74 61 62 6c 65 2c |eciprocal table,| 00001fe0 20 73 6f 20 77 65 20 64 6f 6e 27 74 20 68 61 76 | so we don't hav| 00001ff0 65 20 74 6f 20 75 73 65 20 64 69 76 69 64 65 73 |e to use divides| 00002000 2e 20 4d 75 6c 74 69 70 6c 79 69 6e 67 20 62 79 |. Multiplying by| 00002010 20 74 68 65 20 72 65 63 69 70 72 6f 63 61 6c 20 | the reciprocal | 00002020 6f 66 20 61 20 6e 75 6d 62 65 72 20 69 73 20 74 |of a number is t| 00002030 68 65 20 73 61 6d 65 20 61 73 20 64 69 76 69 64 |he same as divid| 00002040 69 6e 67 20 62 79 20 69 74 3a 20 41 66 74 65 72 |ing by it: After| 00002050 20 61 6c 6c 2c 0a 0a 38 20 2f 20 34 20 3d 20 32 | all,..8 / 4 = 2| 00002060 20 61 6e 64 20 38 20 2a 20 30 2e 32 35 20 28 31 | and 8 * 0.25 (1| 00002070 20 6f 76 65 72 20 34 29 20 3d 20 32 20 2d 20 74 | over 4) = 2 - t| 00002080 68 65 79 20 70 72 6f 64 75 63 65 20 74 68 65 20 |hey produce the | 00002090 73 61 6d 65 20 72 65 73 75 6c 74 20 2a 2f 0a 0a |same result */..| 000020a0 66 6f 72 28 61 6e 67 3d 31 3b 61 6e 67 3c 4d 41 |for(ang=1;ang<MA| 000020b0 58 5f 44 49 53 54 41 4e 43 45 3b 61 6e 67 2b 2b |X_DISTANCE;ang++| 000020c0 29 0a 7b 0a 20 20 2f 2a 20 69 74 20 69 73 20 73 |).{. /* it is s| 000020d0 74 69 6c 6c 20 66 69 78 65 64 20 70 6f 69 6e 74 |till fixed point| 000020e0 20 74 68 6f 75 67 68 20 2a 2f 0a 20 20 72 65 63 | though */. rec| 000020f0 69 70 5f 74 61 62 6c 65 5b 61 6e 67 5d 3d 28 69 |ip_table[ang]=(i| 00002100 6e 74 29 28 31 2e 30 2f 28 66 6c 6f 61 74 29 61 |nt)(1.0/(float)a| 00002110 6e 67 2a 36 35 35 33 36 29 3b 0a 7d 0a 0a 7d 0a |ng*65536);.}..}.| 00002120 0a 2f 2a 20 74 68 69 73 20 66 75 6e 63 74 69 6f |./* this functio| 00002130 6e 20 69 73 20 74 68 65 20 68 65 61 72 74 20 6f |n is the heart o| 00002140 66 20 74 68 65 20 70 72 6f 67 72 61 6d 2c 20 74 |f the program, t| 00002150 68 65 20 65 6e 67 69 6e 65 2c 20 74 6f 20 67 65 |he engine, to ge| 00002160 6e 65 72 61 74 65 20 74 68 65 20 66 69 72 73 74 |nerate the first| 00002170 20 70 65 72 73 6f 6e 20 76 69 65 77 20 2a 2f 0a | person view */.| 00002180 76 6f 69 64 20 61 75 61 5f 72 61 79 63 61 73 74 |void aua_raycast| 00002190 65 72 28 69 6e 74 20 76 69 65 77 5f 78 2c 69 6e |er(int view_x,in| 000021a0 74 20 76 69 65 77 5f 79 2c 69 6e 74 20 76 69 65 |t view_y,int vie| 000021b0 77 5f 61 6e 67 6c 65 29 0a 7b 0a 2f 2a 20 72 65 |w_angle).{./* re| 000021c0 6d 65 6d 62 65 72 20 74 68 61 74 20 77 65 20 61 |member that we a| 000021d0 72 65 20 74 68 69 6e 6b 69 6e 67 20 69 6e 20 32 |re thinking in 2| 000021e0 2d 44 2c 20 6e 6f 74 20 69 6e 20 33 44 20 77 68 |-D, not in 3D wh| 000021f0 65 6e 20 77 65 20 64 69 73 63 75 73 73 20 69 64 |en we discuss id| 00002200 65 61 73 2e 20 42 65 6c 6f 77 20 64 6f 65 73 20 |eas. Below does | 00002210 6e 6f 74 20 6d 65 61 6e 20 22 61 20 66 6c 6f 6f |not mean "a floo| 00002220 72 20 62 65 6c 6f 77 22 2c 20 69 74 20 72 65 61 |r below", it rea| 00002230 6c 6c 79 20 6d 65 61 6e 73 20 22 62 65 68 69 6e |lly means "behin| 00002240 64 22 2c 20 62 75 74 20 77 65 20 73 61 79 20 62 |d", but we say b| 00002250 65 6c 6f 77 20 62 65 63 61 75 73 65 20 77 65 20 |elow because we | 00002260 61 72 65 20 69 6d 61 67 69 6e 69 6e 67 20 6c 6f |are imagining lo| 00002270 6f 6b 69 6e 67 20 64 6f 77 6e 20 6f 6e 20 74 68 |oking down on th| 00002280 65 20 76 69 65 77 20 70 6f 69 6e 74 20 74 6f 20 |e view point to | 00002290 66 6f 72 6d 20 61 20 32 2d 44 20 70 6c 61 6e 20 |form a 2-D plan | 000022a0 2a 2f 0a 0a 2f 2a 20 74 68 69 73 20 66 75 6e 63 |*/../* this func| 000022b0 74 69 6f 6e 2c 20 66 6f 72 20 65 61 63 68 20 63 |tion, for each c| 000022c0 6f 6c 75 6d 6e 20 6f 66 20 74 68 65 20 33 32 30 |olumn of the 320| 000022d0 20 70 69 78 65 6c 20 77 69 64 74 68 20 4d 6f 64 | pixel width Mod| 000022e0 65 20 31 33 20 73 63 72 65 65 6e 2c 20 63 61 73 |e 13 screen, cas| 000022f0 74 73 20 6f 75 74 20 74 77 6f 20 72 61 79 73 2e |ts out two rays.| 00002300 20 4f 6e 65 20 72 61 79 20 6c 6f 6f 6b 73 20 66 | One ray looks f| 00002310 6f 72 20 58 2c 20 68 6f 72 69 7a 6f 6e 74 61 6c |or X, horizontal| 00002320 20 69 6e 74 65 72 73 65 63 74 69 6f 6e 73 20 77 | intersections w| 00002330 69 74 68 20 77 61 6c 6c 73 2c 20 61 6e 64 20 74 |ith walls, and t| 00002340 68 65 20 6f 74 68 65 72 20 74 72 61 63 6b 73 20 |he other tracks | 00002350 69 6e 74 65 72 73 65 63 74 69 6f 6e 73 20 77 69 |intersections wi| 00002360 74 68 20 59 2c 20 76 65 72 74 69 63 61 6c 20 77 |th Y, vertical w| 00002370 61 6c 6c 20 62 6f 75 6e 64 61 72 69 65 73 2e 20 |all boundaries. | 00002380 41 66 74 65 72 20 61 6c 6c 2c 20 74 68 65 20 6f |After all, the o| 00002390 6e 6c 79 20 74 69 6d 65 20 61 20 63 6f 6c 6c 69 |nly time a colli| 000023a0 73 69 6f 6e 20 63 6f 75 6c 64 20 6f 63 63 75 72 |sion could occur| 000023b0 20 69 73 20 6f 6e 20 61 20 62 6f 75 6e 64 61 72 | is on a boundar| 000023c0 79 20 6f 66 20 61 20 63 65 6c 6c 2c 20 61 73 20 |y of a cell, as | 000023d0 74 68 65 20 77 61 6c 6c 20 66 69 6c 6c 73 20 75 |the wall fills u| 000023e0 70 20 74 68 65 20 65 6e 74 69 72 65 20 63 65 6c |p the entire cel| 000023f0 6c 2e 20 45 78 70 65 63 74 20 74 6f 20 73 65 65 |l. Expect to see| 00002400 20 6c 6f 74 73 20 6f 66 20 36 34 27 73 2c 20 74 | lots of 64's, t| 00002410 68 6f 75 67 68 20 72 65 6d 65 6d 62 65 72 20 74 |hough remember t| 00002420 68 61 74 20 74 68 69 73 20 72 61 79 20 63 61 73 |hat this ray cas| 00002430 74 65 72 20 69 73 20 76 65 72 79 20 72 6f 75 74 |ter is very rout| 00002440 69 6e 65 2c 20 61 6e 64 20 68 61 73 20 6e 6f 74 |ine, and has not| 00002450 20 61 74 20 61 6c 6c 20 62 65 65 6e 20 70 75 74 | at all been put| 00002460 20 74 68 72 6f 75 67 68 20 6d 79 20 22 62 6f 78 | through my "box| 00002470 20 6f 66 20 6d 61 67 69 63 22 2e 20 54 68 65 20 | of magic". The | 00002480 65 6e 67 69 6e 65 20 77 69 6c 6c 20 62 65 63 6f |engine will beco| 00002490 6d 65 20 6d 75 63 68 20 6d 6f 72 65 20 70 65 72 |me much more per| 000024a0 73 6f 6e 61 6c 69 73 65 64 20 76 65 72 79 20 73 |sonalised very s| 000024b0 6f 6f 6e 21 20 2a 2f 0a 0a 0a 0a 69 6e 74 20 63 |oon! */....int c| 000024c0 65 6c 6c 5f 78 2c 20 2f 2a 20 75 73 65 64 20 74 |ell_x, /* used t| 000024d0 6f 20 73 74 6f 72 65 20 77 68 69 63 68 20 63 65 |o store which ce| 000024e0 6c 6c 20 6f 66 20 74 68 65 20 77 61 6c 6c 73 20 |ll of the walls | 000024f0 64 61 74 61 20 74 68 65 20 72 61 79 20 69 73 20 |data the ray is | 00002500 69 6e 20 2a 2f 0a 63 65 6c 6c 5f 79 2c 20 2f 2a |in */.cell_y, /*| 00002510 20 22 20 2a 2f 0a 63 61 73 74 69 6e 67 3d 32 2c | " */.casting=2,| 00002520 20 2f 2a 20 75 73 65 64 20 74 6f 20 73 74 6f 72 | /* used to stor| 00002530 65 20 69 66 20 72 61 79 20 63 61 73 74 69 6e 67 |e if ray casting| 00002540 20 68 61 73 20 66 69 6e 69 73 68 65 64 20 2a 2f | has finished */| 00002550 0a 78 5f 68 69 74 5f 74 79 70 65 2c 20 2f 2a 20 |.x_hit_type, /* | 00002560 74 68 69 73 20 73 74 6f 72 65 73 20 74 68 65 20 |this stores the | 00002570 77 61 6c 6c 20 74 79 70 65 20 68 69 74 20 62 79 |wall type hit by| 00002580 20 74 68 65 20 78 20 63 61 73 74 69 6e 67 20 72 | the x casting r| 00002590 61 79 20 2a 2f 0a 79 5f 68 69 74 5f 74 79 70 65 |ay */.y_hit_type| 000025a0 2c 20 2f 2a 20 74 68 69 73 20 73 6f 74 72 65 73 |, /* this sotres| 000025b0 20 74 68 65 20 77 61 6c 6c 20 74 79 70 65 20 28 | the wall type (| 000025c0 6e 75 6d 62 65 72 29 20 68 69 74 20 62 79 20 74 |number) hit by t| 000025d0 68 65 20 79 20 72 61 79 20 2a 2f 0a 78 5f 62 6f |he y ray */.x_bo| 000025e0 75 6e 64 2c 20 2f 2a 20 74 68 69 73 20 68 6f 6c |und, /* this hol| 000025f0 64 73 20 74 68 65 20 6e 65 78 74 20 78 20 62 6f |ds the next x bo| 00002600 75 6e 64 61 72 79 20 66 6f 72 20 61 20 70 6f 73 |undary for a pos| 00002610 73 69 62 6c 65 20 69 6e 74 65 72 73 65 63 74 69 |sible intersecti| 00002620 6f 6e 20 2a 2f 0a 79 5f 62 6f 75 6e 64 2c 20 2f |on */.y_bound, /| 00002630 2a 20 74 68 69 73 20 68 6f 6c 64 73 20 74 68 65 |* this holds the| 00002640 20 6e 65 78 74 20 79 20 62 6f 75 6e 64 61 72 79 | next y boundary| 00002650 20 66 6f 72 20 61 20 70 6f 73 73 69 62 6c 65 20 | for a possible | 00002660 69 6e 74 65 72 73 65 63 74 69 6f 6e 20 2a 2f 0a |intersection */.| 00002670 6e 65 78 74 5f 79 5f 63 65 6c 6c 2c 20 2f 2a 20 |next_y_cell, /* | 00002680 74 68 69 73 20 69 73 20 75 73 65 64 20 74 6f 20 |this is used to | 00002690 66 69 67 75 72 65 20 6f 75 74 20 74 68 65 20 71 |figure out the q| 000026a0 75 61 64 72 61 6e 74 20 6f 66 20 74 68 65 20 72 |uadrant of the r| 000026b0 61 79 20 28 2b 2f 2d 29 2a 2f 0a 6e 65 78 74 5f |ay (+/-)*/.next_| 000026c0 78 5f 63 65 6c 6c 2c 20 2f 2a 20 22 20 2a 2f 0a |x_cell, /* " */.| 000026d0 78 5f 64 65 6c 74 61 2c 20 2f 2a 20 74 68 69 73 |x_delta, /* this| 000026e0 20 69 73 20 2b 27 64 20 74 6f 20 74 68 65 20 78 | is +'d to the x| 000026f0 5f 62 6f 75 6e 64 20 76 61 72 2e 20 74 6f 20 6d |_bound var. to m| 00002700 6f 76 65 20 74 6f 20 74 68 65 20 6e 65 78 74 20 |ove to the next | 00002710 62 6f 75 6e 64 61 72 79 20 2a 2f 0a 79 5f 64 65 |boundary */.y_de| 00002720 6c 74 61 2c 20 2f 2a 20 74 68 69 73 20 69 73 20 |lta, /* this is | 00002730 2b 27 64 20 74 6f 20 74 68 65 20 79 5f 62 6f 75 |+'d to the y_bou| 00002740 6e 64 20 76 61 72 2e 20 74 6f 20 6d 6f 76 65 20 |nd var. to move | 00002750 74 6f 20 74 68 65 20 6e 65 78 74 20 62 6f 75 6e |to the next boun| 00002760 64 61 72 79 20 2a 2f 0a 78 69 5f 73 61 76 65 2c |dary */.xi_save,| 00002770 20 2f 2a 20 74 68 69 73 20 73 74 6f 72 65 73 20 | /* this stores | 00002780 77 68 65 72 65 20 74 68 65 20 78 20 63 61 73 74 |where the x cast| 00002790 69 6e 67 20 72 61 79 20 6d 61 64 65 20 69 74 73 |ing ray made its| 000027a0 20 69 6e 74 65 72 73 65 63 74 69 6f 6e 20 2a 2f | intersection */| 000027b0 0a 79 69 5f 73 61 76 65 2c 20 2f 2a 20 74 68 69 |.yi_save, /* thi| 000027c0 73 20 73 74 6f 72 65 73 20 77 68 65 72 65 20 74 |s stores where t| 000027d0 68 65 20 79 20 63 61 73 74 69 6e 67 20 72 61 79 |he y casting ray| 000027e0 20 6d 61 64 65 20 69 74 73 20 69 6e 74 65 72 73 | made its inters| 000027f0 65 63 74 69 6f 6e 20 2a 2f 0a 73 63 61 6c 65 2c |ection */.scale,| 00002800 20 20 20 2f 2a 20 74 68 69 73 20 73 74 6f 72 65 | /* this store| 00002810 73 20 74 68 65 20 73 63 61 6c 65 20 6f 66 20 74 |s the scale of t| 00002820 68 65 20 73 6c 69 76 65 72 20 74 6f 20 62 65 20 |he sliver to be | 00002830 64 72 61 77 6e 20 69 6e 20 65 61 63 68 20 63 6f |drawn in each co| 00002840 6c 75 6d 6e 20 2a 2f 0a 72 61 79 2c 20 2f 2a 20 |lumn */.ray, /* | 00002850 74 68 69 73 20 73 74 6f 72 65 73 20 74 68 65 20 |this stores the | 00002860 72 61 79 20 6e 75 6d 62 65 72 20 62 65 69 6e 67 |ray number being| 00002870 20 63 61 73 74 20 6f 75 74 20 28 30 2d 33 32 30 | cast out (0-320| 00002880 29 2a 2f 0a 78 72 61 79 2c 20 2f 2a 20 74 68 69 |)*/.xray, /* thi| 00002890 73 20 66 6c 61 67 20 69 73 20 75 73 65 64 20 74 |s flag is used t| 000028a0 6f 20 73 68 6f 77 20 69 66 20 63 61 73 74 69 6e |o show if castin| 000028b0 67 20 69 73 20 6f 76 65 72 20 2a 2f 0a 79 72 61 |g is over */.yra| 000028c0 79 2c 20 2f 2a 20 22 20 2a 2f 0a 64 69 73 74 5f |y, /* " */.dist_| 000028d0 78 2c 20 2f 2a 20 74 68 69 73 20 68 6f 6c 64 73 |x, /* this holds| 000028e0 20 74 68 65 20 64 69 73 74 61 6e 63 65 20 74 6f | the distance to| 000028f0 20 74 68 65 20 78 20 69 6e 74 65 72 73 65 63 74 | the x intersect| 00002900 69 6f 6e 20 2a 2f 0a 64 69 73 74 5f 79 3b 20 2f |ion */.dist_y; /| 00002910 2a 20 74 68 69 73 20 68 6f 6c 64 73 20 74 68 65 |* this holds the| 00002920 20 64 69 73 74 61 6e 63 65 20 74 6f 20 74 68 65 | distance to the| 00002930 20 79 20 69 6e 74 65 72 73 65 63 74 69 6f 6e 20 | y intersection | 00002940 2a 2f 0a 0a 69 6e 74 20 20 20 78 69 2c 0a 20 20 |*/..int xi,. | 00002950 20 20 20 20 79 69 2c 0a 20 20 20 20 20 20 78 61 | yi,. xa| 00002960 64 64 2c 0a 20 20 20 20 20 20 79 61 64 64 3b 20 |dd,. yadd; | 00002970 2f 2a 20 74 68 65 73 65 20 61 72 65 20 75 73 65 |/* these are use| 00002980 64 20 74 6f 20 61 63 63 75 72 61 74 65 6c 79 20 |d to accurately | 00002990 74 72 61 63 65 20 61 6e 64 20 6d 6f 76 65 20 65 |trace and move e| 000029a0 61 63 68 20 72 61 79 20 20 20 20 20 20 2a 2f 0a |ach ray */.| 000029b0 0a 69 6e 74 20 76 61 72 69 61 62 6c 65 73 5b 36 |.int variables[6| 000029c0 5d 2c 20 2f 2a 20 74 68 69 73 20 69 73 20 75 73 |], /* this is us| 000029d0 65 64 20 74 6f 20 70 61 73 73 20 76 61 72 69 61 |ed to pass varia| 000029e0 62 6c 65 73 20 74 6f 20 61 20 73 6c 69 76 65 72 |bles to a sliver| 000029f0 20 72 65 6e 64 65 72 65 72 20 20 2a 2f 0a 20 20 | renderer */. | 00002a00 20 20 63 6c 69 70 3b 20 20 20 20 20 20 2f 2a 20 | clip; /* | 00002a10 74 68 69 73 20 63 6f 75 6c 64 20 62 65 20 75 73 |this could be us| 00002a20 65 64 20 6c 61 74 65 72 20 66 6f 72 20 63 6c 69 |ed later for cli| 00002a30 70 70 69 6e 67 20 2a 2f 0a 69 6e 74 20 78 74 72 |pping */.int xtr| 00002a40 61 6e 73 5f 64 69 73 74 2c 20 2f 2a 20 74 68 65 |ans_dist, /* the| 00002a50 73 65 20 4e 45 57 20 54 52 41 4e 53 50 41 52 45 |se NEW TRANSPARE| 00002a60 4e 54 20 76 61 72 69 61 62 6c 65 73 20 61 72 65 |NT variables are| 00002a70 20 75 73 65 64 20 66 6f 72 20 77 69 6e 64 6f 77 | used for window| 00002a80 73 20 20 2a 2f 0a 20 20 20 20 79 74 72 61 6e 73 |s */. ytrans| 00002a90 5f 64 69 73 74 2c 20 2f 2a 20 65 61 63 68 20 6f |_dist, /* each o| 00002aa0 6e 65 20 77 69 6c 6c 20 62 65 20 75 73 65 64 20 |ne will be used | 00002ab0 6c 61 74 65 72 20 74 6f 20 64 72 61 77 20 74 72 |later to draw tr| 00002ac0 61 6e 73 70 61 72 65 6e 74 20 77 61 6c 6c 73 20 |ansparent walls | 00002ad0 2a 2f 0a 20 20 20 20 78 74 72 61 6e 73 5f 63 6f |*/. xtrans_co| 00002ae0 6c 2c 0a 20 20 20 20 79 74 72 61 6e 73 5f 63 6f |l,. ytrans_co| 00002af0 6c 2c 0a 20 20 20 20 78 74 72 61 6e 73 5f 74 79 |l,. xtrans_ty| 00002b00 70 65 2c 0a 20 20 20 20 79 74 72 61 6e 73 5f 74 |pe,. ytrans_t| 00002b10 79 70 65 2c 0a 20 20 20 20 78 74 72 61 6e 73 5f |ype,. xtrans_| 00002b20 64 6f 6e 65 2c 2f 2a 20 74 68 65 73 65 20 6c 61 |done,/* these la| 00002b30 73 74 20 74 77 6f 20 61 72 65 20 75 73 65 64 20 |st two are used | 00002b40 61 73 20 66 6c 61 67 73 20 74 6f 20 6d 61 72 6b |as flags to mark| 00002b50 20 69 66 20 61 20 74 72 61 6e 73 70 61 72 2d 2a | if a transpar-*| 00002b60 2f 0a 20 20 20 20 79 74 72 61 6e 73 5f 64 6f 6e |/. ytrans_don| 00002b70 65 3b 2f 2a 65 6e 63 79 20 68 61 73 20 62 65 65 |e;/*ency has bee| 00002b80 6e 20 66 6f 75 6e 64 20 6f 72 20 6e 6f 74 20 2a |n found or not *| 00002b90 2f 0a 0a 69 6e 74 20 63 6f 75 6e 74 65 72 3d 30 |/..int counter=0| 00002ba0 3b 0a 2f 2a 20 66 69 72 73 74 6c 79 2c 20 77 65 |;./* firstly, we| 00002bb0 20 73 65 74 20 75 70 20 74 68 65 20 76 61 72 69 | set up the vari| 00002bc0 61 62 6c 65 73 5b 5d 20 77 65 20 61 6c 72 65 61 |ables[] we alrea| 00002bd0 64 79 20 6b 6e 6f 77 2c 20 73 75 63 68 20 61 73 |dy know, such as| 00002be0 20 73 63 72 65 65 6e 5f 61 64 64 72 65 73 73 2c | screen_address,| 00002bf0 20 77 61 6c 6c 73 20 61 6e 64 20 74 68 65 20 73 | walls and the s| 00002c00 63 72 65 65 6e 20 68 65 69 67 68 74 20 77 65 20 |creen height we | 00002c10 61 72 65 20 75 73 69 6e 67 2e 20 54 68 65 73 65 |are using. These| 00002c20 20 61 72 65 20 61 6c 6c 20 74 68 69 6e 67 73 20 | are all things | 00002c30 77 68 69 63 68 20 6f 75 72 20 73 6c 69 76 65 72 |which our sliver| 00002c40 20 72 65 6e 64 65 72 65 72 20 6e 65 65 64 73 20 | renderer needs | 00002c50 74 6f 20 6b 6e 6f 77 20 74 6f 20 70 6c 6f 74 20 |to know to plot | 00002c60 69 74 73 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 0a 76 |its column */..v| 00002c70 61 72 69 61 62 6c 65 73 5b 30 5d 3d 28 69 6e 74 |ariables[0]=(int| 00002c80 29 73 63 72 65 65 6e 5f 61 64 64 72 65 73 73 3b |)screen_address;| 00002c90 0a 0a 0a 2f 2a 20 6e 6f 77 20 77 65 20 67 65 74 |.../* now we get| 00002ca0 20 64 6f 77 6e 20 74 6f 20 74 68 65 20 6e 69 74 | down to the nit| 00002cb0 74 79 20 67 72 69 74 74 79 2e 20 48 65 72 65 20 |ty gritty. Here | 00002cc0 77 65 20 73 75 62 74 72 61 63 74 20 33 30 20 64 |we subtract 30 d| 00002cd0 65 67 72 65 65 73 20 66 72 6f 6d 20 74 68 65 20 |egrees from the | 00002ce0 76 69 65 77 69 6e 67 20 61 6e 67 6c 65 20 72 65 |viewing angle re| 00002cf0 6d 65 6d 62 65 72 20 74 68 61 74 20 6f 75 72 20 |member that our | 00002d00 46 4f 56 20 69 73 20 36 30 20 64 65 67 72 65 65 |FOV is 60 degree| 00002d10 73 20 77 68 69 63 68 20 6d 65 61 6e 73 20 74 68 |s which means th| 00002d20 61 74 20 77 65 20 63 61 73 74 20 66 72 6f 6d 20 |at we cast from | 00002d30 2d 33 30 20 74 6f 20 2b 33 30 20 2a 2f 0a 0a 69 |-30 to +30 */..i| 00002d40 66 20 28 20 28 76 69 65 77 5f 61 6e 67 6c 65 2d |f ( (view_angle-| 00002d50 3d 41 4e 47 4c 45 5f 33 30 29 20 3c 20 30 29 0a |=ANGLE_30) < 0).| 00002d60 20 20 20 7b 0a 20 20 20 2f 2a 20 74 68 69 73 20 | {. /* this | 00002d70 65 6e 73 75 72 65 73 20 74 68 61 74 20 77 65 20 |ensures that we | 00002d80 64 6f 6e 27 74 20 67 6f 20 6f 76 65 72 20 6f 72 |don't go over or| 00002d90 20 75 6e 64 65 72 20 30 2f 33 36 30 20 64 65 67 | under 0/360 deg| 00002da0 72 65 65 73 21 20 2a 2f 0a 20 20 20 76 69 65 77 |rees! */. view| 00002db0 5f 61 6e 67 6c 65 3d 41 4e 47 4c 45 5f 33 36 30 |_angle=ANGLE_360| 00002dc0 20 2b 20 76 69 65 77 5f 61 6e 67 6c 65 3b 0a 20 | + view_angle;. | 00002dd0 20 20 7d 0a 2f 2a 20 6e 6f 77 20 77 65 20 73 74 | }./* now we st| 00002de0 61 72 74 20 74 68 65 20 6d 61 69 6e 20 6c 6f 6f |art the main loo| 00002df0 70 2c 20 73 74 61 72 74 20 61 74 20 74 68 65 20 |p, start at the | 00002e00 72 69 67 68 74 20 6f 66 20 74 68 65 20 73 63 72 |right of the scr| 00002e10 65 65 6e 20 28 33 31 39 29 2c 20 61 6e 64 20 63 |een (319), and c| 00002e20 61 73 74 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 |ast each column | 00002e30 6f 6e 65 20 62 79 20 6f 6e 65 20 74 6f 20 74 68 |one by one to th| 00002e40 65 20 6c 65 66 74 20 2a 2f 0a 0a 66 6f 72 20 28 |e left */..for (| 00002e50 72 61 79 3d 53 43 52 45 45 4e 5f 57 49 44 54 48 |ray=SCREEN_WIDTH| 00002e60 2d 31 3b 20 72 61 79 3e 3d 30 3b 20 72 61 79 2d |-1; ray>=0; ray-| 00002e70 2d 29 0a 20 20 20 20 7b 0a 2f 2a 20 66 6f 72 20 |-). {./* for | 00002e80 65 61 63 68 20 72 61 79 20 74 6f 20 62 65 20 63 |each ray to be c| 00002e90 61 73 74 20 77 65 20 61 63 74 75 61 6c 6c 79 20 |ast we actually | 00002ea0 63 61 73 74 20 6f 75 74 20 74 77 6f 20 72 61 79 |cast out two ray| 00002eb0 73 20 3a 20 6f 6e 65 20 74 6f 20 63 68 65 63 6b |s : one to check| 00002ec0 20 66 6f 72 20 76 65 72 74 69 63 61 6c 20 62 6f | for vertical bo| 00002ed0 75 6e 64 61 72 79 20 63 6f 6c 6c 69 73 69 6f 6e |undary collision| 00002ee0 73 20 61 6e 64 20 74 68 65 20 6f 74 68 65 72 20 |s and the other | 00002ef0 74 6f 20 63 68 65 63 6b 20 66 6f 72 20 68 6f 72 |to check for hor| 00002f00 69 7a 6f 6e 74 61 6c 20 62 6f 75 6e 64 61 72 79 |izontal boundary| 00002f10 20 63 6f 6c 6c 69 73 69 6f 6e 73 2e 20 43 6f 6e | collisions. Con| 00002f20 73 69 64 65 72 69 6e 67 20 74 68 61 74 20 77 61 |sidering that wa| 00002f30 6c 6c 73 20 66 69 6c 6c 20 75 70 20 65 61 63 68 |lls fill up each| 00002f40 20 63 65 6c 6c 2c 20 77 65 20 6e 65 65 64 20 6f | cell, we need o| 00002f50 6e 6c 79 20 6c 6f 6f 6b 20 66 6f 72 20 69 6e 74 |nly look for int| 00002f60 65 72 73 65 63 74 69 6f 6e 73 20 6f 6e 20 74 68 |ersections on th| 00002f70 65 20 62 6f 75 6e 64 61 72 69 65 73 2e 20 57 65 |e boundaries. We| 00002f80 20 68 61 76 65 20 74 6f 20 70 65 72 66 6f 72 6d | have to perform| 00002f90 20 73 65 70 65 72 61 74 65 20 63 61 73 74 20 62 | seperate cast b| 00002fa0 65 63 61 75 73 65 20 6a 75 73 74 20 63 61 73 74 |ecause just cast| 00002fb0 69 6e 67 20 6f 6e 65 20 72 61 79 20 63 6f 6d 70 |ing one ray comp| 00002fc0 6c 69 63 61 74 65 73 20 74 68 65 20 6d 61 74 74 |licates the matt| 00002fd0 65 72 20 61 6e 64 20 69 74 20 64 6f 65 73 6e 27 |er and it doesn'| 00002fe0 74 20 67 69 76 65 20 6d 75 63 68 20 73 70 65 65 |t give much spee| 00002ff0 64 20 69 6e 63 72 65 61 73 65 2c 20 69 66 20 61 |d increase, if a| 00003000 6e 79 2e 20 2a 2f 0a 0a 2f 2a 20 4e 45 57 20 4c |ny. */../* NEW L| 00003010 49 4e 45 20 3a 20 57 65 20 68 61 76 65 20 74 6f |INE : We have to| 00003020 20 63 68 65 63 6b 20 74 6f 20 73 65 65 20 69 66 | check to see if| 00003030 20 74 68 65 20 76 69 65 77 69 6e 67 20 61 6e 67 | the viewing ang| 00003040 6c 65 20 69 73 20 61 74 20 74 68 65 20 61 73 79 |le is at the asy| 00003050 6d 70 74 6f 74 65 73 2c 20 75 6e 66 6f 72 74 75 |mptotes, unfortu| 00003060 6e 61 74 65 6c 79 20 74 68 65 20 66 69 78 65 64 |nately the fixed| 00003070 20 70 6f 69 6e 74 20 73 79 73 74 65 6d 20 63 61 | point system ca| 00003080 6e 6e 6f 74 20 73 74 6f 72 65 20 74 68 65 20 76 |nnot store the v| 00003090 61 6c 75 65 73 20 68 65 6c 64 20 61 74 20 74 68 |alues held at th| 000030a0 65 73 65 20 61 6e 67 6c 65 73 2c 20 73 6f 20 77 |ese angles, so w| 000030b0 65 20 68 61 76 65 20 74 6f 20 61 76 6f 69 64 20 |e have to avoid | 000030c0 74 68 65 69 72 20 75 73 65 2e 20 54 68 69 73 20 |their use. This | 000030d0 69 73 20 6e 6f 74 20 76 65 72 79 20 65 6c 65 67 |is not very eleg| 000030e0 61 6e 74 20 49 20 6b 6e 6f 77 2c 20 62 75 74 20 |ant I know, but | 000030f0 69 74 20 73 61 76 65 73 20 61 20 6c 6f 74 20 6f |it saves a lot o| 00003100 66 20 68 65 61 64 20 61 63 68 65 73 20 61 6e 64 |f head aches and| 00003110 20 6e 6f 20 6f 6e 65 20 63 61 6e 20 74 65 6c 6c | no one can tell| 00003120 20 77 65 27 76 65 20 64 6f 6e 65 20 69 74 21 20 | we've done it! | 00003130 2a 2f 0a 0a 69 66 28 76 69 65 77 5f 61 6e 67 6c |*/..if(view_angl| 00003140 65 3d 3d 41 4e 47 4c 45 5f 30 20 7c 7c 20 76 69 |e==ANGLE_0 || vi| 00003150 65 77 5f 61 6e 67 6c 65 3d 3d 41 4e 47 4c 45 5f |ew_angle==ANGLE_| 00003160 39 30 20 7c 7c 20 76 69 65 77 5f 61 6e 67 6c 65 |90 || view_angle| 00003170 20 3d 3d 41 4e 47 4c 45 5f 31 38 30 20 7c 7c 20 | ==ANGLE_180 || | 00003180 76 69 65 77 5f 61 6e 67 6c 65 3d 3d 41 4e 47 4c |view_angle==ANGL| 00003190 45 5f 32 37 30 29 76 69 65 77 5f 61 6e 67 6c 65 |E_270)view_angle| 000031a0 2b 2b 3b 0a 2f 2a 20 53 45 43 54 49 4f 4e 20 31 |++;./* SECTION 1| 000031b0 20 3a 20 43 41 4c 43 55 4c 41 54 49 4e 47 20 54 | : CALCULATING T| 000031c0 48 45 20 46 49 52 53 54 20 58 20 61 6e 64 20 59 |HE FIRST X and Y| 000031d0 20 49 4e 54 45 52 53 45 43 54 49 4f 4e 53 2a 2f | INTERSECTIONS*/| 000031e0 0a 2f 2a 20 4f 6e 63 65 20 77 65 20 68 61 76 65 |./* Once we have| 000031f0 20 64 6f 6e 65 20 74 68 69 73 20 74 68 65 20 66 | done this the f| 00003200 6f 6c 6c 6f 77 69 6e 67 20 69 6e 74 65 72 73 65 |ollowing interse| 00003210 63 74 69 6f 6e 73 20 61 72 65 20 65 61 73 79 2a |ctions are easy*| 00003220 2f 0a 0a 0a 2f 2a 20 54 68 65 20 58 20 43 41 53 |/.../* The X CAS| 00003230 54 49 4e 47 20 52 41 59 20 3a 20 68 65 72 65 20 |TING RAY : here | 00003240 77 65 20 74 65 73 74 20 74 6f 20 73 65 65 20 69 |we test to see i| 00003250 66 20 74 68 65 20 61 6e 67 6c 65 20 6f 66 20 74 |f the angle of t| 00003260 68 65 20 72 61 79 20 69 73 20 66 61 63 69 6e 67 |he ray is facing| 00003270 20 75 70 77 61 72 64 73 2e 20 57 65 20 6e 65 65 | upwards. We nee| 00003280 64 20 74 6f 20 6b 6e 6f 77 20 77 68 69 63 68 20 |d to know which | 00003290 68 61 6c 66 70 6c 61 6e 65 20 77 65 27 72 65 20 |halfplane we're | 000032a0 63 61 73 74 69 6e 67 20 66 72 6f 6d 20 72 65 6c |casting from rel| 000032b0 61 74 69 76 65 20 74 6f 20 74 68 65 20 79 2d 61 |ative to the y-a| 000032c0 78 69 73 2e 20 2a 2f 0a 0a 0a 20 69 66 20 28 76 |xis. */... if (v| 000032d0 69 65 77 5f 61 6e 67 6c 65 20 3e 3d 20 41 4e 47 |iew_angle >= ANG| 000032e0 4c 45 5f 30 20 26 26 20 76 69 65 77 5f 61 6e 67 |LE_0 && view_ang| 000032f0 6c 65 20 3c 20 41 4e 47 4c 45 5f 31 38 30 29 0a |le < ANGLE_180).| 00003300 20 20 20 20 20 20 20 7b 0a 2f 2a 20 69 66 20 73 | {./* if s| 00003310 6f 20 74 68 65 6e 20 77 65 20 61 73 73 69 67 6e |o then we assign| 00003320 20 76 61 72 69 61 62 6c 65 73 20 74 6f 20 74 68 | variables to th| 00003330 61 74 20 65 66 66 65 63 74 2e 20 57 65 20 6d 75 |at effect. We mu| 00003340 73 74 20 63 6f 6d 70 75 74 65 20 74 68 65 20 66 |st compute the f| 00003350 69 72 73 74 20 68 6f 72 69 7a 6f 6e 74 61 6c 20 |irst horizontal | 00003360 6c 69 6e 65 20 74 68 61 74 20 63 6f 75 6c 64 20 |line that could | 00003370 62 65 20 69 6e 74 65 72 73 65 63 74 65 64 20 77 |be intersected w| 00003380 69 74 68 20 74 68 65 20 72 61 79 2e 20 4e 6f 74 |ith the ray. Not| 00003390 65 20 3a 20 69 74 20 77 69 6c 6c 20 62 65 20 61 |e : it will be a| 000033a0 62 6f 76 65 20 74 68 65 20 76 69 65 77 65 72 2e |bove the viewer.| 000033b0 2a 2f 0a 0a 79 5f 62 6f 75 6e 64 20 3d 20 28 43 |*/..y_bound = (C| 000033c0 45 4c 4c 5f 59 5f 53 49 5a 45 20 2b 20 28 76 69 |ELL_Y_SIZE + (vi| 000033d0 65 77 5f 79 20 26 20 30 78 66 66 63 30 29 29 3b |ew_y & 0xffc0));| 000033e0 20 2f 2a 20 74 68 69 73 20 6c 69 6e 65 20 69 73 | /* this line is| 000033f0 20 6d 65 72 65 6c 79 20 61 6e 20 6f 70 74 69 6d | merely an optim| 00003400 69 7a 65 64 20 76 65 72 73 69 6f 6e 20 6f 66 20 |ized version of | 00003410 43 45 4c 4c 5f 59 5f 53 49 5a 45 20 2b 20 28 76 |CELL_Y_SIZE + (v| 00003420 69 65 77 5f 79 20 25 20 36 34 29 2e 20 49 20 75 |iew_y % 64). I u| 00003430 73 65 20 69 74 20 6d 61 6e 79 20 74 69 6d 65 73 |se it many times| 00003440 20 69 6e 20 74 68 69 73 20 65 6e 67 69 6e 65 2e | in this engine.| 00003450 20 2a 2f 0a 0a 79 5f 64 65 6c 74 61 20 3d 20 43 | */..y_delta = C| 00003460 45 4c 4c 5f 59 5f 53 49 5a 45 3b 20 2f 2a 20 74 |ELL_Y_SIZE; /* t| 00003470 68 69 73 20 6d 65 61 6e 73 20 74 68 61 74 20 66 |his means that f| 00003480 6f 72 20 65 76 65 72 79 20 6d 6f 76 65 6d 65 6e |or every movemen| 00003490 74 20 6f 66 20 74 68 65 20 72 61 79 2c 20 74 68 |t of the ray, th| 000034a0 65 20 79 20 62 6f 75 6e 64 61 72 79 20 6d 6f 76 |e y boundary mov| 000034b0 65 73 20 75 70 20 6f 6e 65 20 63 65 6c 6c 2c 20 |es up one cell, | 000034c0 77 68 69 63 68 20 69 74 20 77 6f 75 6c 64 2e 20 |which it would. | 000034d0 49 74 20 69 73 20 74 68 65 20 64 65 6c 74 61 20 |It is the delta | 000034e0 74 6f 20 67 65 74 20 74 6f 20 74 68 65 20 6e 65 |to get to the ne| 000034f0 78 74 20 68 6f 72 69 7a 6f 6e 74 61 6c 20 6c 69 |xt horizontal li| 00003500 6e 65 20 2a 2f 0a 0a 2f 2a 20 6e 65 78 74 20 77 |ne */../* next w| 00003510 65 20 75 73 65 20 74 68 65 20 69 6e 76 65 72 73 |e use the invers| 00003520 65 20 74 61 6e 20 66 75 6e 63 74 69 6f 6e 20 74 |e tan function t| 00003530 6f 20 63 61 6c 63 75 6c 61 74 65 20 74 68 65 20 |o calculate the | 00003540 69 6e 69 74 69 61 6c 20 70 6f 73 69 74 69 6f 6e |initial position| 00003550 20 6f 66 20 74 68 65 20 78 20 62 6f 75 6e 64 61 | of the x bounda| 00003560 72 79 20 73 65 61 72 63 68 69 6e 67 20 72 61 79 |ry searching ray| 00003570 20 6f 6e 20 69 74 73 20 66 69 72 73 74 20 69 6e | on its first in| 00003580 74 65 72 73 65 63 74 69 6f 6e 2e 20 57 65 20 68 |tersection. We h| 00003590 61 76 65 20 74 6f 20 75 73 65 20 74 61 6e 20 62 |ave to use tan b| 000035a0 65 63 61 75 73 65 20 69 74 20 69 73 20 72 65 6c |ecause it is rel| 000035b0 61 74 65 64 20 74 6f 20 73 6c 6f 70 65 73 20 2a |ated to slopes *| 000035c0 2f 0a 0a 2f 2a 20 4e 45 57 20 46 49 58 45 44 20 |/../* NEW FIXED | 000035d0 50 4f 49 4e 54 20 43 41 4c 43 55 4c 41 54 49 4f |POINT CALCULATIO| 000035e0 4e 20 6f 66 0a 78 69 20 3d 20 28 66 6c 6f 61 74 |N of.xi = (float| 000035f0 29 28 69 6e 76 5f 74 61 6e 5f 74 61 62 6c 65 5b |)(inv_tan_table[| 00003600 76 69 65 77 5f 61 6e 67 6c 65 5d 20 2a 20 28 79 |view_angle] * (y| 00003610 5f 62 6f 75 6e 64 20 2d 20 76 69 65 77 5f 79 29 |_bound - view_y)| 00003620 29 20 2b 76 69 65 77 5f 78 3b 20 2a 2f 0a 0a 78 |) +view_x; */..x| 00003630 69 3d 28 28 79 5f 62 6f 75 6e 64 2d 76 69 65 77 |i=((y_bound-view| 00003640 5f 79 29 29 2a 28 69 6e 76 5f 74 61 6e 5f 74 61 |_y))*(inv_tan_ta| 00003650 62 6c 65 5b 76 69 65 77 5f 61 6e 67 6c 65 5d 29 |ble[view_angle])| 00003660 3b 0a 78 69 2b 3d 28 76 69 65 77 5f 78 3c 3c 31 |;.xi+=(view_x<<1| 00003670 36 29 3b 0a 0a 2f 2a 20 74 68 69 73 20 6d 65 61 |6);../* this mea| 00003680 6e 73 20 74 68 61 74 20 74 68 65 20 71 75 61 64 |ns that the quad| 00003690 72 61 6e 74 20 6f 66 20 74 68 65 20 72 61 79 20 |rant of the ray | 000036a0 69 73 20 6e 6f 74 20 6e 65 67 61 74 69 76 65 2c |is not negative,| 000036b0 20 74 68 61 74 20 69 73 20 74 68 65 20 6e 65 78 | that is the nex| 000036c0 74 20 79 20 62 6f 75 6e 64 61 72 79 20 77 69 6c |t y boundary wil| 000036d0 6c 20 61 70 70 65 61 72 20 61 62 6f 76 65 20 74 |l appear above t| 000036e0 68 65 20 76 69 65 77 20 70 6f 69 6e 74 20 61 6e |he view point an| 000036f0 64 20 6e 6f 74 20 62 65 6c 6f 77 20 28 69 6e 20 |d not below (in | 00003700 74 65 72 6d 73 20 6f 66 20 6c 6f 6f 6b 69 6e 67 |terms of looking| 00003710 20 64 6f 77 6e 20 6f 6e 20 74 68 65 20 76 69 65 | down on the vie| 00003720 77 65 72 29 2e 20 54 68 69 73 20 69 73 20 74 68 |wer). This is th| 00003730 65 20 63 65 6c 6c 20 64 65 6c 74 61 20 2a 2f 0a |e cell delta */.| 00003740 6e 65 78 74 5f 79 5f 63 65 6c 6c 20 3d 20 30 3b |next_y_cell = 0;| 00003750 0a 0a 20 20 20 20 20 20 20 7d 0a 2f 2a 20 69 66 |.. }./* if| 00003760 20 74 68 65 20 76 69 65 77 69 6e 67 20 61 6e 67 | the viewing ang| 00003770 6c 65 20 69 73 20 67 72 65 61 74 65 72 20 74 68 |le is greater th| 00003780 61 6e 20 31 38 30 20 64 65 67 72 65 65 73 20 61 |an 180 degrees a| 00003790 6e 64 20 6c 65 73 73 20 74 68 61 6e 20 32 37 30 |nd less than 270| 000037a0 20 64 65 67 72 65 65 73 20 74 68 65 6e 20 77 65 | degrees then we| 000037b0 20 68 61 76 65 20 74 6f 20 64 6f 20 6f 74 68 65 | have to do othe| 000037c0 72 20 63 61 6c 63 75 6c 61 74 69 6f 6e 73 20 28 |r calculations (| 000037d0 6c 6f 77 65 72 20 68 61 6c 66 20 70 6c 61 6e 65 |lower half plane| 000037e0 29 20 2a 2f 0a 20 20 20 20 65 6c 73 65 0a 20 20 |) */. else. | 000037f0 20 20 20 20 20 7b 0a 2f 2a 20 77 65 20 6b 6e 6f | {./* we kno| 00003800 77 20 74 68 61 74 20 62 65 63 61 75 73 65 20 74 |w that because t| 00003810 68 65 20 76 69 65 77 69 6e 67 20 61 6e 67 6c 65 |he viewing angle| 00003820 20 69 73 20 64 6f 77 6e 77 61 72 64 73 2c 20 73 | is downwards, s| 00003830 6f 20 74 68 65 6e 20 74 68 65 20 68 6f 72 69 7a |o then the horiz| 00003840 6f 6e 74 61 6c 20 69 6e 74 65 72 73 65 63 74 69 |ontal intersecti| 00003850 6f 6e 20 68 61 73 20 74 6f 20 62 65 20 42 45 4c |on has to be BEL| 00003860 4f 57 20 74 68 65 20 76 69 65 77 65 72 20 2a 2f |OW the viewer */| 00003870 0a 79 5f 62 6f 75 6e 64 20 3d 20 28 69 6e 74 29 |.y_bound = (int)| 00003880 28 76 69 65 77 5f 79 20 26 20 30 78 66 66 63 30 |(view_y & 0xffc0| 00003890 29 3b 0a 0a 2f 2a 20 62 65 63 61 75 73 65 20 6f |);../* because o| 000038a0 66 20 74 68 69 73 20 77 65 20 61 6c 73 6f 20 6b |f this we also k| 000038b0 6e 6f 77 20 74 68 61 74 20 74 68 65 20 6e 65 78 |now that the nex| 000038c0 74 20 59 20 69 6e 74 65 72 73 65 63 74 69 6f 6e |t Y intersection| 000038d0 73 20 77 69 6c 6c 20 62 65 20 61 20 63 65 6c 6c |s will be a cell| 000038e0 20 62 65 6c 6f 77 20 65 61 63 68 20 6f 74 68 65 | below each othe| 000038f0 72 2e 20 53 6f 20 74 68 65 20 64 65 6c 74 61 20 |r. So the delta | 00003900 66 6f 72 20 65 61 63 68 20 68 6f 72 69 7a 6f 6e |for each horizon| 00003910 74 61 6c 20 69 6e 74 65 72 73 65 63 74 69 6f 6e |tal intersection| 00003920 20 77 69 6c 6c 20 62 65 20 61 20 63 65 6c 6c 20 | will be a cell | 00003930 62 65 6c 6f 77 20 20 74 68 65 20 6c 61 73 74 20 |below the last | 00003940 2a 2f 0a 79 5f 64 65 6c 74 61 20 3d 20 2d 43 45 |*/.y_delta = -CE| 00003950 4c 4c 5f 59 5f 53 49 5a 45 3b 0a 0a 2f 2a 20 77 |LL_Y_SIZE;../* w| 00003960 65 20 61 67 61 69 6e 20 75 73 65 20 74 68 65 20 |e again use the | 00003970 74 61 6e 67 65 6e 74 20 66 75 6e 63 74 69 6f 6e |tangent function| 00003980 2c 20 6a 75 73 74 20 61 73 20 62 65 66 6f 72 65 |, just as before| 00003990 2c 20 74 6f 20 63 61 6c 63 75 6c 61 74 65 20 74 |, to calculate t| 000039a0 68 65 20 66 69 72 73 74 20 78 20 69 6e 74 65 72 |he first x inter| 000039b0 73 65 63 74 69 6f 6e 20 77 69 74 68 20 61 20 62 |section with a b| 000039c0 6f 75 6e 64 61 72 79 2e 20 2a 2f 0a 0a 2f 2a 20 |oundary. */../* | 000039d0 4e 45 57 20 46 49 58 45 44 20 50 4f 49 4e 54 2c |NEW FIXED POINT,| 000039e0 20 49 20 77 6f 6e 27 74 20 73 68 6f 77 20 74 68 | I won't show th| 000039f0 65 20 6f 6c 64 20 6c 69 6e 65 73 20 61 6e 79 20 |e old lines any | 00003a00 6d 6f 72 65 20 2a 2f 0a 0a 78 69 3d 28 28 79 5f |more */..xi=((y_| 00003a10 62 6f 75 6e 64 2d 76 69 65 77 5f 79 29 29 2a 28 |bound-view_y))*(| 00003a20 69 6e 76 5f 74 61 6e 5f 74 61 62 6c 65 5b 76 69 |inv_tan_table[vi| 00003a30 65 77 5f 61 6e 67 6c 65 5d 29 3b 0a 78 69 2b 3d |ew_angle]);.xi+=| 00003a40 28 76 69 65 77 5f 78 3c 3c 31 36 29 3b 0a 0a 2f |(view_x<<16);../| 00003a50 2a 20 61 6e 64 20 77 65 20 6b 6e 6f 77 20 61 6c |* and we know al| 00003a60 73 6f 20 74 68 61 74 20 74 68 65 20 71 75 61 64 |so that the quad| 00003a70 72 61 6e 74 20 69 73 20 62 65 6c 6f 77 20 74 68 |rant is below th| 00003a80 65 20 70 6c 61 79 65 72 2c 20 73 6f 20 74 68 65 |e player, so the| 00003a90 20 63 65 6c 6c 20 79 20 64 65 6c 74 61 20 77 69 | cell y delta wi| 00003aa0 6c 6c 20 62 65 20 6e 65 67 61 74 69 76 65 20 2a |ll be negative *| 00003ab0 2f 0a 0a 6e 65 78 74 5f 79 5f 63 65 6c 6c 20 3d |/..next_y_cell =| 00003ac0 20 2d 31 3b 0a 0a 20 20 20 20 20 20 20 7d 0a 2f | -1;.. }./| 00003ad0 2a 20 59 20 52 41 59 20 3a 20 77 65 20 64 6f 20 |* Y RAY : we do | 00003ae0 73 69 6d 69 6c 61 72 20 63 61 6c 63 75 6c 61 74 |similar calculat| 00003af0 69 6f 6e 73 20 62 75 74 20 74 68 69 73 20 74 69 |ions but this ti| 00003b00 6d 65 20 74 6f 20 63 61 6c 63 75 6c 61 74 65 20 |me to calculate | 00003b10 74 68 65 20 66 69 72 73 74 20 79 20 69 6e 74 65 |the first y inte| 00003b20 72 73 65 63 74 69 6f 6e 73 20 2a 2f 0a 0a 2f 2a |rsections */../*| 00003b30 20 77 65 20 74 65 73 74 20 74 6f 20 73 65 65 20 | we test to see | 00003b40 69 66 20 74 68 65 20 76 69 65 77 20 61 6e 67 6c |if the view angl| 00003b50 65 20 69 73 20 77 69 74 68 69 6e 20 74 68 65 20 |e is within the | 00003b60 76 65 72 74 69 63 61 6c 20 61 73 79 6d 70 74 6f |vertical asympto| 00003b70 74 65 73 20 6f 66 20 33 36 30 20 64 65 67 72 65 |tes of 360 degre| 00003b80 65 73 2e 20 57 65 20 6e 65 65 64 20 74 6f 20 6b |es. We need to k| 00003b90 6e 6f 77 20 77 68 69 63 68 20 68 61 6c 66 70 6c |now which halfpl| 00003ba0 61 6e 65 20 77 65 27 72 65 20 63 61 73 74 69 6e |ane we're castin| 00003bb0 67 20 66 72 6f 6d 20 72 65 6c 61 74 69 76 65 20 |g from relative | 00003bc0 74 6f 20 74 68 65 20 78 2d 61 78 69 73 2e 20 2a |to the x-axis. *| 00003bd0 2f 0a 0a 69 66 20 28 76 69 65 77 5f 61 6e 67 6c |/..if (view_angl| 00003be0 65 20 3c 20 41 4e 47 4c 45 5f 39 30 20 7c 7c 20 |e < ANGLE_90 || | 00003bf0 76 69 65 77 5f 61 6e 67 6c 65 20 3e 3d 20 41 4e |view_angle >= AN| 00003c00 47 4c 45 5f 32 37 30 29 0a 20 20 20 20 20 20 20 |GLE_270). | 00003c10 7b 0a 2f 2a 20 77 65 20 63 61 6e 20 64 65 64 75 |{./* we can dedu| 00003c20 63 65 20 63 65 72 74 61 69 6e 20 74 68 69 6e 67 |ce certain thing| 00003c30 73 2c 20 6a 75 73 74 20 61 73 20 77 69 74 68 20 |s, just as with | 00003c40 74 68 65 20 78 20 72 61 79 2e 20 57 65 20 6b 6e |the x ray. We kn| 00003c50 6f 77 20 74 68 61 74 20 62 65 63 61 75 73 65 20 |ow that because | 00003c60 74 68 65 20 76 69 65 77 20 61 6e 67 6c 65 20 69 |the view angle i| 00003c70 73 20 74 6f 20 74 68 65 20 72 69 67 68 74 2c 20 |s to the right, | 00003c80 74 68 65 20 6e 65 78 74 20 58 20 62 6f 75 6e 64 |the next X bound| 00003c90 61 72 79 20 28 77 68 69 63 68 20 69 73 20 63 6f |ary (which is co| 00003ca0 6e 73 74 61 6e 74 29 20 77 69 6c 6c 20 62 65 20 |nstant) will be | 00003cb0 74 6f 20 74 68 65 20 52 49 47 48 54 20 6f 66 20 |to the RIGHT of | 00003cc0 74 68 65 20 76 69 65 77 65 72 2e 20 2a 2f 0a 78 |the viewer. */.x| 00003cd0 5f 62 6f 75 6e 64 20 3d 20 28 69 6e 74 29 28 43 |_bound = (int)(C| 00003ce0 45 4c 4c 5f 58 5f 53 49 5a 45 20 2b 20 28 76 69 |ELL_X_SIZE + (vi| 00003cf0 65 77 5f 78 20 26 20 30 78 66 66 63 30 29 29 3b |ew_x & 0xffc0));| 00003d00 0a 0a 2f 2a 20 6e 6f 74 69 63 65 20 74 68 69 73 |../* notice this| 00003d10 20 72 65 63 75 72 72 69 6e 67 20 6f 70 74 69 6d | recurring optim| 00003d20 69 7a 61 74 69 6f 6e 20 6f 66 20 76 69 65 77 5f |ization of view_| 00003d30 78 20 25 20 36 34 20 2a 2f 0a 0a 2f 2a 20 61 6e |x % 64 */../* an| 00003d40 64 20 77 65 20 61 6c 73 6f 20 6b 6e 6f 77 20 74 |d we also know t| 00003d50 68 61 74 20 65 61 63 68 20 76 65 72 74 69 63 61 |hat each vertica| 00003d60 6c 20 63 65 6c 6c 20 62 6f 75 6e 64 61 72 79 20 |l cell boundary | 00003d70 61 66 74 65 72 20 74 68 65 20 66 69 72 73 74 20 |after the first | 00003d80 77 69 6c 6c 20 62 65 20 61 20 63 65 6c 6c 27 73 |will be a cell's| 00003d90 20 77 69 64 74 68 20 61 77 61 79 20 2a 2f 0a 0a | width away */..| 00003da0 78 5f 64 65 6c 74 61 20 3d 20 43 45 4c 4c 5f 58 |x_delta = CELL_X| 00003db0 5f 53 49 5a 45 3b 0a 2f 2a 20 74 68 69 73 20 74 |_SIZE;./* this t| 00003dc0 69 6d 65 20 77 65 20 75 73 65 20 74 68 65 20 74 |ime we use the t| 00003dd0 61 6e 67 65 6e 74 20 66 75 6e 63 74 69 6f 6e 20 |angent function | 00003de0 28 6e 6f 74 20 74 68 65 20 69 6e 76 65 72 73 65 |(not the inverse| 00003df0 20 74 61 6e 29 20 74 6f 20 63 61 6c 63 75 6c 61 | tan) to calcula| 00003e00 74 65 20 77 68 65 72 65 20 74 68 65 20 66 69 72 |te where the fir| 00003e10 73 74 20 79 20 62 6f 75 6e 64 61 72 79 20 69 6e |st y boundary in| 00003e20 74 65 72 73 65 63 74 69 6f 6e 20 77 69 6c 6c 20 |tersection will | 00003e30 6f 63 63 75 72 29 2e 20 2a 2f 0a 0a 2f 2a 20 4e |occur). */../* N| 00003e40 45 57 20 46 49 58 45 44 20 50 4f 49 4e 54 20 2a |EW FIXED POINT *| 00003e50 2f 0a 0a 79 69 3d 28 28 78 5f 62 6f 75 6e 64 20 |/..yi=((x_bound | 00003e60 2d 20 76 69 65 77 5f 78 29 29 2a 28 74 61 6e 5f |- view_x))*(tan_| 00003e70 74 61 62 6c 65 5b 76 69 65 77 5f 61 6e 67 6c 65 |table[view_angle| 00003e80 5d 29 3b 0a 79 69 2b 3d 28 76 69 65 77 5f 79 3c |]);.yi+=(view_y<| 00003e90 3c 31 36 29 3b 0a 2f 2a 20 61 6e 64 20 77 65 20 |<16);./* and we | 00003ea0 6b 6e 6f 77 20 61 6c 73 6f 20 74 68 61 74 20 62 |know also that b| 00003eb0 65 63 61 75 73 65 20 74 68 65 20 76 69 65 77 20 |ecause the view | 00003ec0 69 73 20 70 6f 73 69 74 69 76 65 2c 20 74 68 65 |is positive, the| 00003ed0 20 6e 65 78 74 5f 78 5f 63 65 6c 6c 20 64 65 6c | next_x_cell del| 00003ee0 74 61 20 64 6f 65 73 20 6e 6f 74 20 6e 65 65 64 |ta does not need| 00003ef0 20 74 6f 20 62 65 20 6e 65 67 61 74 69 76 65 20 | to be negative | 00003f00 2a 2f 0a 0a 6e 65 78 74 5f 78 5f 63 65 6c 6c 20 |*/..next_x_cell | 00003f10 3d 20 30 3b 0a 0a 20 20 20 20 20 20 20 7d 0a 2f |= 0;.. }./| 00003f20 2a 20 6f 74 68 65 72 77 69 73 65 2c 20 69 66 20 |* otherwise, if | 00003f30 74 68 65 20 76 69 65 77 69 6e 67 20 61 6e 67 6c |the viewing angl| 00003f40 65 20 69 73 20 74 6f 77 61 72 64 73 20 74 68 65 |e is towards the| 00003f50 20 6f 74 68 65 72 20 64 69 72 65 63 74 69 6f 6e | other direction| 00003f60 2e 2e 2e 2a 2f 0a 20 20 20 20 65 6c 73 65 0a 20 |...*/. else. | 00003f70 20 20 20 20 20 20 7b 0a 2f 2a 20 77 65 20 6b 6e | {./* we kn| 00003f80 6f 77 20 74 68 61 74 20 74 68 65 20 66 69 72 73 |ow that the firs| 00003f90 74 20 78 20 62 6f 75 6e 64 61 72 79 20 63 61 6e |t x boundary can| 00003fa0 20 6f 63 63 75 72 20 6f 6e 6c 79 20 74 6f 20 74 | occur only to t| 00003fb0 68 65 20 6c 65 66 74 20 6f 66 20 74 68 65 20 76 |he left of the v| 00003fc0 69 65 77 65 72 20 62 65 63 61 75 73 65 20 74 68 |iewer because th| 00003fd0 65 20 72 61 79 20 61 6e 67 6c 65 20 69 73 20 66 |e ray angle is f| 00003fe0 61 63 69 6e 67 20 6c 65 66 74 2e 20 53 6f 20 77 |acing left. So w| 00003ff0 65 20 63 61 6e 20 64 6f 20 76 69 65 77 5f 78 20 |e can do view_x | 00004000 25 20 36 34 20 74 6f 20 63 61 6c 63 75 6c 61 74 |% 64 to calculat| 00004010 65 20 74 68 65 20 66 69 72 73 74 20 76 65 72 74 |e the first vert| 00004020 69 63 61 6c 20 62 6f 75 6e 64 61 72 79 2c 20 74 |ical boundary, t| 00004030 68 69 73 20 73 68 6f 75 6c 64 20 62 65 20 62 65 |his should be be| 00004040 63 6f 6d 69 6e 67 20 6f 62 76 69 6f 75 73 20 2a |coming obvious *| 00004050 2f 0a 78 5f 62 6f 75 6e 64 20 3d 20 28 69 6e 74 |/.x_bound = (int| 00004060 29 28 76 69 65 77 5f 78 20 26 20 30 78 66 66 63 |)(view_x & 0xffc| 00004070 30 29 3b 0a 0a 2f 2a 20 77 65 20 61 6c 73 6f 20 |0);../* we also | 00004080 6b 6e 6f 77 20 74 68 61 74 20 74 68 65 20 64 65 |know that the de| 00004090 6c 74 61 20 66 6f 72 20 74 68 65 20 63 65 6c 6c |lta for the cell| 000040a0 20 77 69 6c 6c 20 62 65 20 74 6f 20 74 68 65 20 | will be to the | 000040b0 6c 65 66 74 2c 20 65 61 63 68 20 74 69 6d 65 20 |left, each time | 000040c0 74 68 65 20 72 61 79 20 6d 6f 76 65 73 20 74 6f |the ray moves to| 000040d0 20 74 68 65 20 6e 65 78 74 20 62 6f 75 6e 64 61 | the next bounda| 000040e0 72 79 20 74 68 65 20 6e 65 78 74 20 76 65 72 74 |ry the next vert| 000040f0 69 63 61 6c 20 69 6e 74 65 72 73 65 63 74 69 6f |ical intersectio| 00004100 6e 20 77 69 6c 6c 20 62 65 20 61 20 63 65 6c 6c |n will be a cell| 00004110 20 74 6f 20 74 68 65 20 6c 65 66 74 20 74 68 61 | to the left tha| 00004120 6e 20 74 68 65 20 6c 61 73 74 2e 20 2a 2f 0a 78 |n the last. */.x| 00004130 5f 64 65 6c 74 61 20 3d 20 2d 43 45 4c 4c 5f 58 |_delta = -CELL_X| 00004140 5f 53 49 5a 45 3b 0a 0a 2f 2a 20 77 65 20 75 73 |_SIZE;../* we us| 00004150 65 20 74 68 65 20 74 61 6e 67 65 6e 74 61 6c 20 |e the tangental | 00004160 66 75 6e 63 74 69 6f 6e 20 61 67 61 69 6e 20 74 |function again t| 00004170 6f 20 63 61 6c 63 75 6c 61 74 65 20 74 68 65 20 |o calculate the | 00004180 70 6f 73 69 74 69 6f 6e 20 6f 6e 20 74 68 65 20 |position on the | 00004190 68 6f 72 69 7a 6f 6e 74 61 6c 20 69 6e 74 65 72 |horizontal inter| 000041a0 73 65 63 74 69 6f 6e 73 20 2a 2f 0a 0a 2f 2a 20 |sections */../* | 000041b0 4e 45 57 20 46 49 58 45 44 20 50 4f 49 4e 54 20 |NEW FIXED POINT | 000041c0 2a 2f 0a 0a 79 69 3d 28 28 78 5f 62 6f 75 6e 64 |*/..yi=((x_bound| 000041d0 20 2d 20 76 69 65 77 5f 78 29 29 2a 28 74 61 6e | - view_x))*(tan| 000041e0 5f 74 61 62 6c 65 5b 76 69 65 77 5f 61 6e 67 6c |_table[view_angl| 000041f0 65 5d 29 3b 0a 79 69 2b 3d 28 76 69 65 77 5f 79 |e]);.yi+=(view_y| 00004200 3c 3c 31 36 29 3b 0a 2f 2a 20 61 6e 64 20 77 65 |<<16);./* and we| 00004210 20 61 6c 73 6f 20 6b 6e 6f 77 20 74 68 61 74 20 | also know that | 00004220 74 68 65 20 78 20 63 65 6c 6c 20 76 61 6c 75 65 |the x cell value| 00004230 20 77 69 6c 6c 20 62 65 20 6d 69 6e 75 73 2c 20 | will be minus, | 00004240 62 65 63 61 75 73 65 20 61 73 20 74 68 65 20 72 |because as the r| 00004250 61 79 20 6d 6f 76 65 73 20 74 6f 20 61 6e 6f 74 |ay moves to anot| 00004260 68 65 72 20 63 65 6c 6c 2c 20 62 65 63 61 75 73 |her cell, becaus| 00004270 65 20 74 68 65 20 72 61 79 20 69 73 20 67 6f 69 |e the ray is goi| 00004280 6e 67 20 6c 65 66 74 2c 20 74 68 65 20 76 61 6c |ng left, the val| 00004290 75 65 20 6d 75 73 74 20 62 65 20 6d 69 6e 75 73 |ue must be minus| 000042a0 2e 20 2a 2f 0a 6e 65 78 74 5f 78 5f 63 65 6c 6c |. */.next_x_cell| 000042b0 20 3d 20 2d 31 3b 0a 0a 20 20 20 20 20 20 20 7d | = -1;.. }| 000042c0 0a 0a 2f 2a 20 4e 6f 77 20 77 65 20 68 61 76 65 |../* Now we have| 000042d0 20 70 65 72 66 6f 72 6d 65 64 20 74 68 65 20 73 | performed the s| 000042e0 6c 69 67 68 74 6c 79 20 74 72 69 63 6b 79 20 74 |lightly tricky t| 000042f0 61 73 6b 20 6f 66 20 74 68 65 20 66 69 72 73 74 |ask of the first| 00004300 20 69 6e 74 65 72 73 65 63 74 69 6f 6e 73 2c 20 | intersections, | 00004310 77 65 20 63 61 6e 20 6d 6f 76 65 20 6f 6e 20 74 |we can move on t| 00004320 6f 20 63 61 6c 63 75 6c 61 74 69 6e 67 20 74 68 |o calculating th| 00004330 65 20 6e 65 78 74 20 6f 6e 65 73 2e 20 54 68 69 |e next ones. Thi| 00004340 73 20 69 73 20 6d 6f 72 65 20 73 69 6d 70 6c 65 |s is more simple| 00004350 2c 20 61 73 20 77 65 20 6b 6e 6f 77 20 74 68 61 |, as we know tha| 00004360 74 20 74 68 65 20 69 6e 74 65 72 73 65 63 74 69 |t the intersecti| 00004370 6f 6e 73 20 63 61 6e 20 6f 6e 6c 79 20 6f 63 63 |ons can only occ| 00004380 75 72 20 61 74 20 63 65 6c 6c 20 62 6f 75 6e 64 |ur at cell bound| 00004390 61 72 69 65 73 2e 2a 2f 0a 0a 2f 2a 20 53 45 43 |aries.*/../* SEC| 000043a0 54 49 4f 4e 20 32 20 3a 20 54 65 73 74 69 6e 67 |TION 2 : Testing| 000043b0 20 66 6f 72 20 66 75 72 74 68 65 72 20 69 6e 74 | for further int| 000043c0 65 72 73 65 63 74 69 6f 6e 73 20 2a 2f 0a 0a 2f |ersections */../| 000043d0 2a 20 74 68 65 73 65 20 66 6c 61 67 73 20 73 74 |* these flags st| 000043e0 6f 72 65 20 69 66 20 63 61 73 74 69 6e 67 20 6f |ore if casting o| 000043f0 66 20 62 6f 74 68 20 72 61 79 73 20 69 73 20 63 |f both rays is c| 00004400 6f 6d 70 6c 65 74 65 20 2a 2f 0a 78 72 61 79 3d |omplete */.xray=| 00004410 79 72 61 79 3d 78 74 72 61 6e 73 5f 64 6f 6e 65 |yray=xtrans_done| 00004420 3d 79 74 72 61 6e 73 5f 64 6f 6e 65 3d 30 3b 0a |=ytrans_done=0;.| 00004430 0a 2f 2a 20 58 20 52 61 79 20 69 73 20 66 69 72 |./* X Ray is fir| 00004440 73 74 20 2a 2f 0a 2f 2a 20 62 65 63 61 75 73 65 |st */./* because| 00004450 20 77 65 20 61 72 65 20 74 65 73 74 69 6e 67 20 | we are testing | 00004460 66 6f 72 20 65 61 63 68 20 6e 65 78 74 20 69 6e |for each next in| 00004470 74 65 72 73 65 63 74 69 6f 6e 2c 20 77 65 20 63 |tersection, we c| 00004480 61 6e 20 66 69 67 75 72 65 20 6f 75 74 20 6d 6f |an figure out mo| 00004490 72 65 20 65 61 73 69 6c 79 20 74 68 65 20 66 6f |re easily the fo| 000044a0 6c 6c 6f 77 69 6e 67 20 69 6e 74 65 72 73 65 63 |llowing intersec| 000044b0 74 69 6f 6e 73 2e 20 2a 2f 0a 2f 2a 20 74 68 69 |tions. */./* thi| 000044c0 73 20 69 73 20 61 20 6c 6f 6f 6b 20 75 70 20 74 |s is a look up t| 000044d0 61 62 6c 65 20 68 6f 6c 64 69 6e 67 20 74 68 65 |able holding the| 000044e0 20 6e 65 78 74 20 79 20 69 6e 74 65 72 63 65 70 | next y intercep| 000044f0 74 73 2c 20 62 61 73 65 64 20 6f 6e 20 74 68 65 |ts, based on the| 00004500 20 74 61 6e 67 65 6e 74 61 6c 20 66 75 6e 63 74 | tangental funct| 00004510 69 6f 6e 20 61 6e 64 20 74 68 65 20 73 69 7a 65 |ion and the size| 00004520 20 6f 66 20 63 65 6c 6c 73 2e 20 42 61 73 69 63 | of cells. Basic| 00004530 61 6c 6c 79 20 77 65 20 61 64 64 20 74 68 69 73 |ally we add this| 00004540 20 74 6f 20 74 68 65 20 72 61 79 20 65 61 63 68 | to the ray each| 00004550 20 74 69 6d 65 20 77 65 20 6d 6f 76 65 20 69 74 | time we move it| 00004560 20 61 20 62 69 74 20 6d 6f 72 65 2c 20 73 65 61 | a bit more, sea| 00004570 72 63 68 69 6e 67 20 66 6f 72 20 61 20 77 61 6c |rching for a wal| 00004580 6c 20 61 74 20 61 20 63 65 6c 6c 20 62 6f 75 6e |l at a cell boun| 00004590 64 61 72 79 20 2a 2f 0a 0a 2f 2a 20 4e 45 57 20 |dary */../* NEW | 000045a0 46 49 58 45 44 20 50 4f 49 4e 54 2c 20 6e 6f 74 |FIXED POINT, not| 000045b0 65 20 74 68 65 20 73 68 69 66 74 20 33 20 74 69 |e the shift 3 ti| 000045c0 6d 65 73 20 74 6f 20 74 68 65 20 6c 65 66 74 2c |mes to the left,| 000045d0 20 74 68 65 20 65 71 75 69 76 61 6c 65 6e 74 20 | the equivalent | 000045e0 6f 66 20 61 20 6d 75 6c 74 69 70 6c 79 20 62 79 |of a multiply by| 000045f0 20 38 2c 20 74 68 69 73 20 74 61 6b 65 73 20 6e | 8, this takes n| 00004600 6f 20 74 69 6d 65 2c 20 61 6e 64 20 72 65 61 6c |o time, and real| 00004610 6c 79 20 49 20 64 6f 6e 27 74 20 6b 6e 6f 77 20 |ly I don't know | 00004620 77 68 79 20 49 27 76 65 20 64 6f 6e 65 20 69 74 |why I've done it| 00004630 20 6c 69 6b 65 20 74 68 69 73 21 20 49 74 20 77 | like this! It w| 00004640 6f 72 6b 73 2e 20 2a 2f 0a 0a 78 61 64 64 3d 79 |orks. */..xadd=y| 00004650 5f 73 74 65 70 5b 76 69 65 77 5f 61 6e 67 6c 65 |_step[view_angle| 00004660 5d 3c 3c 33 3b 0a 0a 2f 2a 20 73 74 61 72 74 20 |]<<3;../* start | 00004670 63 61 73 74 69 6e 67 20 74 68 65 20 78 20 72 61 |casting the x ra| 00004680 79 20 2a 2f 0a 77 68 69 6c 65 28 21 78 72 61 79 |y */.while(!xray| 00004690 29 0a 7b 0a 2f 2a 20 63 6f 6d 70 75 74 65 20 63 |).{./* compute c| 000046a0 75 72 72 65 6e 74 20 63 65 6c 6c 20 70 6f 73 69 |urrent cell posi| 000046b0 74 69 6f 6e 20 6f 66 20 74 68 65 20 72 61 79 20 |tion of the ray | 000046c0 74 6f 20 69 6e 73 70 65 63 74 2a 2f 0a 0a 63 65 |to inspect*/..ce| 000046d0 6c 6c 5f 78 20 3d 20 28 20 28 78 5f 62 6f 75 6e |ll_x = ( (x_boun| 000046e0 64 2b 6e 65 78 74 5f 78 5f 63 65 6c 6c 29 20 3e |d+next_x_cell) >| 000046f0 3e 20 43 45 4c 4c 5f 58 5f 53 49 5a 45 5f 46 50 |> CELL_X_SIZE_FP| 00004700 29 3b 0a 2f 2a 20 4e 6f 74 65 20 77 65 20 68 61 |);./* Note we ha| 00004710 76 65 20 74 6f 20 73 68 69 66 74 20 6e 6f 74 20 |ve to shift not | 00004720 6f 6e 6c 79 20 62 79 20 36 2c 20 62 75 74 20 61 |only by 6, but a| 00004730 6c 73 6f 20 62 79 20 31 36 20 74 6f 20 63 6f 6e |lso by 16 to con| 00004740 76 65 72 74 20 42 41 43 4b 20 74 6f 20 6e 6f 72 |vert BACK to nor| 00004750 6d 61 6c 20 6d 61 74 68 73 20 2a 2f 0a 63 65 6c |mal maths */.cel| 00004760 6c 5f 79 20 3d 20 28 69 6e 74 29 79 69 3e 3e 32 |l_y = (int)yi>>2| 00004770 32 3b 0a 0a 2f 2a 20 62 6f 74 68 20 6f 66 20 74 |2;../* both of t| 00004780 68 65 20 61 62 6f 76 65 20 65 78 61 6d 70 6c 65 |he above example| 00004790 73 20 75 73 65 20 62 69 6e 61 72 79 20 73 68 69 |s use binary shi| 000047a0 66 74 69 6e 67 20 74 6f 20 61 63 68 69 65 76 65 |fting to achieve| 000047b0 20 61 20 64 69 76 69 64 65 20 62 79 20 36 34 2e | a divide by 64.| 000047c0 20 43 65 6c 6c 5f 79 20 63 6f 6d 70 75 74 61 74 | Cell_y computat| 000047d0 69 6f 6e 20 75 73 65 73 20 69 64 65 6e 74 69 63 |ion uses identic| 000047e0 61 6c 20 74 65 63 68 6e 69 71 75 65 73 20 74 6f |al techniques to| 000047f0 20 74 68 6f 73 65 20 63 6f 76 65 72 65 64 20 69 | those covered i| 00004800 6e 20 74 68 65 20 6d 61 67 61 7a 69 6e 65 2e 20 |n the magazine. | 00004810 43 65 6c 6c 5f 78 20 69 73 20 63 61 6c 63 75 6c |Cell_x is calcul| 00004820 61 74 65 64 20 62 79 20 75 73 69 6e 67 20 74 68 |ated by using th| 00004830 65 20 78 5f 62 6f 75 6e 64 20 61 6e 64 20 6e 65 |e x_bound and ne| 00004840 78 74 5f 78 5f 63 65 6c 6c 20 76 61 6c 75 65 73 |xt_x_cell values| 00004850 20 63 61 6c 63 75 6c 61 74 65 64 20 62 65 66 6f | calculated befo| 00004860 72 65 68 61 6e 64 2e 20 2a 2f 0a 0a 69 66 28 63 |rehand. */..if(c| 00004870 65 6c 6c 5f 78 3c 30 29 63 65 6c 6c 5f 78 3d 30 |ell_x<0)cell_x=0| 00004880 3b 69 66 28 63 65 6c 6c 5f 78 3e 36 33 29 63 65 |;if(cell_x>63)ce| 00004890 6c 6c 5f 78 3d 36 33 3b 0a 69 66 28 63 65 6c 6c |ll_x=63;.if(cell| 000048a0 5f 79 3c 30 29 63 65 6c 6c 5f 79 3d 30 3b 69 66 |_y<0)cell_y=0;if| 000048b0 28 63 65 6c 6c 5f 79 3e 36 33 29 63 65 6c 6c 5f |(cell_y>63)cell_| 000048c0 79 3d 36 33 3b 0a 2f 2a 20 74 68 65 73 65 20 73 |y=63;./* these s| 000048d0 69 6d 70 6c 65 20 6c 69 6e 65 73 20 65 6e 73 75 |imple lines ensu| 000048e0 72 65 20 74 68 61 74 20 74 68 65 20 72 61 79 20 |re that the ray | 000048f0 64 6f 65 73 6e 27 74 20 67 6f 20 6f 75 74 20 6f |doesn't go out o| 00004900 66 20 74 68 65 20 77 6f 72 6c 64 2c 20 74 68 6f |f the world, tho| 00004910 75 67 68 20 74 68 65 79 20 61 72 65 6e 27 74 20 |ugh they aren't | 00004920 72 65 61 6c 6c 79 20 6e 65 65 64 65 64 2e 20 2a |really needed. *| 00004930 2f 0a 0a 2f 2a 20 77 65 20 6c 6f 6f 6b 20 75 70 |/../* we look up| 00004940 20 69 6e 20 74 68 65 20 77 6f 72 6c 64 20 66 69 | in the world fi| 00004950 6c 65 20 74 6f 20 73 65 65 20 69 66 20 74 68 65 |le to see if the| 00004960 72 65 20 69 73 20 61 20 77 61 6c 6c 20 61 74 20 |re is a wall at | 00004970 74 68 65 20 69 6e 74 65 72 73 65 63 74 69 6f 6e |the intersection| 00004980 20 6f 66 20 6f 75 72 20 72 61 79 20 2a 2f 0a 0a | of our ray */..| 00004990 69 66 20 28 28 78 5f 68 69 74 5f 74 79 70 65 20 |if ((x_hit_type | 000049a0 3d 77 6f 72 6c 64 5b 63 65 6c 6c 5f 79 5d 5b 63 |=world[cell_y][c| 000049b0 65 6c 6c 5f 78 5d 29 21 3d 30 29 0a 7b 0a 20 2f |ell_x])!=0).{. /| 000049c0 2a 20 6f 72 20 61 6e 79 20 28 65 78 74 72 61 20 |* or any (extra | 000049d0 6f 72 20 64 69 66 66 65 72 65 6e 74 29 20 74 69 |or different) ti| 000049e0 6c 65 20 76 61 6c 75 65 20 79 6f 75 20 77 69 73 |le value you wis| 000049f0 68 20 2a 2f 0a 69 66 28 78 5f 68 69 74 5f 74 79 |h */.if(x_hit_ty| 00004a00 70 65 3d 3d 39 20 7c 7c 20 78 5f 68 69 74 5f 74 |pe==9 || x_hit_t| 00004a10 79 70 65 3d 3d 37 29 7b 0a 20 20 2f 2a 54 48 45 |ype==7){. /*THE| 00004a20 4e 20 54 48 45 20 57 41 4c 4c 20 49 53 20 54 52 |N THE WALL IS TR| 00004a30 41 4e 53 50 41 52 45 4e 54 21 21 21 2a 2f 0a 20 |ANSPARENT!!!*/. | 00004a40 78 74 72 61 6e 73 5f 64 69 73 74 3d 28 28 79 69 |xtrans_dist=((yi| 00004a50 2d 28 76 69 65 77 5f 79 3c 3c 31 36 29 29 3e 3e |-(view_y<<16))>>| 00004a60 38 29 2a 28 69 6e 76 5f 73 69 6e 5f 74 61 62 6c |8)*(inv_sin_tabl| 00004a70 65 5b 76 69 65 77 5f 61 6e 67 6c 65 5d 3e 3e 38 |e[view_angle]>>8| 00004a80 29 3b 0a 20 78 74 72 61 6e 73 5f 74 79 70 65 3d |);. xtrans_type=| 00004a90 78 5f 68 69 74 5f 74 79 70 65 3b 0a 20 78 74 72 |x_hit_type;. xtr| 00004aa0 61 6e 73 5f 63 6f 6c 3d 28 28 69 6e 74 29 28 79 |ans_col=((int)(y| 00004ab0 69 3e 3e 31 36 29 20 26 20 30 78 30 30 33 66 29 |i>>16) & 0x003f)| 00004ac0 3b 0a 20 78 74 72 61 6e 73 5f 64 6f 6e 65 3d 46 |;. xtrans_done=F| 00004ad0 4f 55 4e 44 5f 57 41 4c 4c 3b 0a 2f 2a 20 77 65 |OUND_WALL;./* we| 00004ae0 20 72 65 63 6f 72 64 20 61 6c 6c 20 72 65 71 75 | record all requ| 00004af0 69 72 65 64 20 64 65 74 61 69 6c 73 20 74 68 65 |ired details the| 00004b00 6e 20 63 6f 6e 74 69 6e 75 65 20 2a 2f 0a 20 20 |n continue */. | 00004b10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d | }| 00004b20 0a 0a 65 6c 73 65 0a 7b 0a 2f 2a 20 69 66 20 73 |..else.{./* if s| 00004b30 6f 20 77 65 20 63 61 6c 63 75 6c 61 74 65 20 74 |o we calculate t| 00004b40 68 65 20 64 69 73 74 61 6e 63 65 20 74 6f 20 69 |he distance to i| 00004b50 74 20 75 73 69 6e 67 20 74 68 65 20 6f 6c 64 20 |t using the old | 00004b60 4f 2d 4c 65 76 65 6c 20 74 65 63 68 6e 69 71 75 |O-Level techniqu| 00004b70 65 20 6f 66 20 75 73 69 6e 67 20 73 69 6e 65 20 |e of using sine | 00004b80 61 6e 64 20 63 6f 73 69 6e 65 20 69 6e 73 74 65 |and cosine inste| 00004b90 61 64 20 6f 66 20 64 6f 69 6e 67 20 74 68 65 20 |ad of doing the | 00004ba0 73 74 61 6e 64 61 72 64 20 50 59 54 48 41 47 4f |standard PYTHAGO| 00004bb0 52 41 53 20 74 65 63 68 6e 69 71 75 65 2e 2a 2f |RAS technique.*/| 00004bc0 0a 0a 2f 2a 20 4e 45 57 20 46 49 58 45 44 20 50 |../* NEW FIXED P| 00004bd0 4f 49 4e 54 20 63 61 6c 63 75 6c 61 74 69 6f 6e |OINT calculation| 00004be0 2c 20 6e 6f 74 69 63 65 20 74 68 61 74 20 69 6e |, notice that in| 00004bf0 20 74 68 69 73 20 6e 65 78 74 20 6c 69 6e 65 20 | this next line | 00004c00 77 65 20 68 61 76 65 20 62 6f 74 68 20 61 20 63 |we have both a c| 00004c10 6f 6e 76 65 72 73 69 6f 6e 20 54 4f 20 66 69 78 |onversion TO fix| 00004c20 65 64 20 70 6f 69 6e 74 20 28 76 69 65 77 5f 79 |ed point (view_y| 00004c30 29 20 61 6e 64 20 61 6c 73 6f 20 74 68 65 20 63 |) and also the c| 00004c40 68 65 63 6b 20 61 67 61 69 6e 73 74 20 6f 76 65 |heck against ove| 00004c50 72 20 66 6c 6f 77 20 69 73 20 76 65 72 79 20 61 |r flow is very a| 00004c60 70 70 61 72 65 6e 74 2c 20 77 65 20 73 68 61 72 |pparent, we shar| 00004c70 65 20 74 68 65 20 61 63 63 75 72 61 63 79 2e 20 |e the accuracy. | 00004c80 53 65 65 20 74 68 65 20 61 72 74 69 63 6c 65 20 |See the article | 00004c90 66 6f 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 |for more details| 00004ca0 20 2a 2f 0a 0a 64 69 73 74 5f 78 20 20 3d 20 28 | */..dist_x = (| 00004cb0 20 28 79 69 20 2d 20 28 76 69 65 77 5f 79 3c 3c | (yi - (view_y<<| 00004cc0 31 36 29 29 3e 3e 38 29 20 2a 20 28 69 6e 76 5f |16))>>8) * (inv_| 00004cd0 73 69 6e 5f 74 61 62 6c 65 5b 76 69 65 77 5f 61 |sin_table[view_a| 00004ce0 6e 67 6c 65 5d 3e 3e 38 29 3b 0a 2f 2a 20 77 65 |ngle]>>8);./* we| 00004cf0 20 61 6c 73 6f 20 73 61 76 65 20 74 68 65 20 65 | also save the e| 00004d00 78 61 63 74 20 70 6f 73 69 74 69 6f 6e 20 6f 66 |xact position of| 00004d10 20 74 68 65 20 69 6e 74 65 72 73 65 63 74 69 6f | the intersectio| 00004d20 6e 20 62 65 63 61 75 73 65 20 77 65 20 77 69 6c |n because we wil| 00004d30 6c 20 6e 65 65 64 20 69 74 20 6c 61 74 65 72 20 |l need it later | 00004d40 74 6f 20 61 64 64 20 74 65 78 74 75 72 65 20 6d |to add texture m| 00004d50 61 70 70 69 6e 67 2e 20 2a 2f 0a 0a 2f 2a 20 57 |apping. */../* W| 00004d60 65 20 73 61 76 65 20 79 69 20 61 66 74 65 72 20 |e save yi after | 00004d70 63 6f 6e 76 65 72 74 69 6e 67 20 69 74 20 62 61 |converting it ba| 00004d80 63 6b 20 74 6f 20 6e 6f 72 6d 61 6c 20 6d 61 74 |ck to normal mat| 00004d90 68 73 20 2a 2f 0a 0a 79 69 5f 73 61 76 65 20 3d |hs */..yi_save =| 00004da0 20 28 69 6e 74 29 79 69 3e 3e 31 36 3b 0a 0a 2f | (int)yi>>16;../| 00004db0 2a 20 62 65 63 61 75 73 65 20 74 68 65 20 78 20 |* because the x | 00004dc0 72 61 79 20 68 61 73 20 66 6f 75 6e 64 20 61 20 |ray has found a | 00004dd0 77 61 6c 6c 2c 20 77 65 20 63 61 6e 20 73 74 6f |wall, we can sto| 00004de0 70 20 63 61 73 74 69 6e 67 20 2a 2f 0a 78 72 61 |p casting */.xra| 00004df0 79 3d 46 4f 55 4e 44 5f 57 41 4c 4c 3b 0a 0a 7d |y=FOUND_WALL;..}| 00004e00 0a 7d 0a 0a 0a 2f 2a 20 69 66 20 6e 6f 74 2c 20 |.}.../* if not, | 00004e10 77 65 20 63 6f 6d 70 75 74 65 20 74 68 65 20 6e |we compute the n| 00004e20 65 78 74 20 70 6f 73 73 69 62 6c 65 20 69 6e 74 |ext possible int| 00004e30 65 72 73 65 63 74 69 6f 6e 20 2a 2f 0a 79 69 20 |ersection */.yi | 00004e40 2b 3d 78 61 64 64 3b 20 2f 2a 20 46 49 58 45 44 |+=xadd; /* FIXED| 00004e50 20 50 4f 49 4e 54 20 41 44 44 49 54 49 4f 4e 20 | POINT ADDITION | 00004e60 72 65 71 75 69 72 65 73 20 6e 6f 20 65 78 74 72 |requires no extr| 00004e70 61 20 77 6f 72 6b 20 2a 2f 0a 78 5f 62 6f 75 6e |a work */.x_boun| 00004e80 64 20 2b 3d 20 78 5f 64 65 6c 74 61 3b 20 2f 2a |d += x_delta; /*| 00004e90 20 61 6e 64 20 77 65 20 61 6c 73 6f 20 63 61 6c | and we also cal| 00004ea0 63 75 6c 61 74 65 20 74 68 65 20 6e 65 78 74 20 |culate the next | 00004eb0 68 6f 72 69 7a 6f 6e 74 61 6c 20 62 6f 75 6e 64 |horizontal bound| 00004ec0 61 72 79 2c 20 77 68 69 63 68 20 77 65 20 6b 6e |ary, which we kn| 00004ed0 6f 77 20 77 69 6c 6c 20 62 65 20 78 5f 64 65 6c |ow will be x_del| 00004ee0 74 61 20 61 77 61 79 2c 20 6e 6f 20 6e 65 65 64 |ta away, no need| 00004ef0 20 66 6f 72 20 63 6f 6d 70 6c 65 78 20 77 6f 72 | for complex wor| 00004f00 6b 69 6e 67 73 2e 20 2a 2f 0a 0a 7d 0a 2f 2a 20 |kings. */..}./* | 00004f10 53 45 43 54 49 4f 4e 20 33 20 2a 2f 0a 2f 2a 20 |SECTION 3 */./* | 00004f20 57 45 20 4e 4f 57 20 64 6f 20 65 78 61 63 74 6c |WE NOW do exactl| 00004f30 79 20 74 68 65 20 73 61 6d 65 20 62 75 74 20 66 |y the same but f| 00004f40 6f 72 20 74 68 65 20 79 72 61 79 2c 20 77 65 20 |or the yray, we | 00004f50 63 61 73 74 20 69 74 20 6f 75 74 2c 20 63 68 65 |cast it out, che| 00004f60 63 6b 20 66 6f 72 20 61 20 77 61 6c 6c 2c 20 69 |ck for a wall, i| 00004f70 66 20 74 68 65 72 65 20 69 73 20 6f 6e 65 20 77 |f there is one w| 00004f80 65 20 74 61 6b 65 20 74 68 65 20 64 69 73 74 61 |e take the dista| 00004f90 6e 63 65 20 74 6f 20 69 74 20 65 74 63 2c 20 69 |nce to it etc, i| 00004fa0 66 20 6e 6f 74 2c 20 77 65 20 6d 6f 76 65 20 20 |f not, we move | 00004fb0 74 68 65 20 72 61 79 20 75 6e 74 69 6c 20 61 20 |the ray until a | 00004fc0 77 61 6c 6c 20 69 74 20 66 6f 75 6e 64 2e 20 2a |wall it found. *| 00004fd0 2f 0a 0a 2f 2a 20 6c 6f 6f 6b 20 75 70 20 74 68 |/../* look up th| 00004fe0 65 20 76 61 6c 75 65 20 74 6f 20 61 64 64 20 74 |e value to add t| 00004ff0 6f 20 74 68 65 20 72 61 79 20 65 61 63 68 20 74 |o the ray each t| 00005000 69 6d 65 20 77 65 20 6d 6f 76 65 20 69 74 20 2a |ime we move it *| 00005010 2f 0a 0a 2f 2a 20 53 65 65 20 61 62 6f 76 65 20 |/../* See above | 00005020 66 6f 72 20 6d 6f 72 65 20 69 6e 66 6f 72 6d 61 |for more informa| 00005030 74 69 6f 6e 2c 20 74 68 69 73 20 69 73 20 46 49 |tion, this is FI| 00005040 58 45 44 20 50 4f 49 4e 54 20 72 65 6d 65 6d 62 |XED POINT rememb| 00005050 65 72 20 2a 2f 0a 79 61 64 64 3d 78 5f 73 74 65 |er */.yadd=x_ste| 00005060 70 5b 76 69 65 77 5f 61 6e 67 6c 65 5d 3c 3c 33 |p[view_angle]<<3| 00005070 3b 0a 0a 2f 2a 20 73 74 61 72 74 20 63 61 73 74 |;../* start cast| 00005080 69 6e 67 20 74 68 65 20 72 61 79 20 2a 2f 0a 77 |ing the ray */.w| 00005090 68 69 6c 65 28 21 79 72 61 79 29 0a 7b 0a 0a 2f |hile(!yray).{../| 000050a0 2a 20 63 6f 6d 70 75 74 65 20 63 75 72 72 65 6e |* compute curren| 000050b0 74 20 63 65 6c 6c 20 74 6f 20 69 6e 73 70 65 63 |t cell to inspec| 000050c0 74 20 2a 2f 0a 0a 2f 2a 20 42 65 63 61 75 73 65 |t */../* Because| 000050d0 20 58 49 20 49 53 20 49 4e 20 46 49 58 45 44 20 | XI IS IN FIXED | 000050e0 50 4f 49 4e 54 20 77 65 20 68 61 76 65 20 74 6f |POINT we have to| 000050f0 20 6e 6f 74 20 6f 6e 6c 79 20 64 69 76 69 64 65 | not only divide| 00005100 20 62 79 20 36 34 20 62 75 74 20 61 6c 73 6f 20 | by 64 but also | 00005110 77 65 20 68 61 76 65 20 74 6f 20 63 6f 6e 76 65 |we have to conve| 00005120 72 74 20 42 41 43 4b 20 74 6f 20 6e 6f 72 6d 61 |rt BACK to norma| 00005130 6c 20 6d 61 74 68 73 20 2a 2f 0a 0a 63 65 6c 6c |l maths */..cell| 00005140 5f 78 20 3d 20 28 69 6e 74 29 78 69 3e 3e 32 32 |_x = (int)xi>>22| 00005150 3b 0a 63 65 6c 6c 5f 79 20 3d 20 28 20 28 79 5f |;.cell_y = ( (y_| 00005160 62 6f 75 6e 64 20 2b 20 6e 65 78 74 5f 79 5f 63 |bound + next_y_c| 00005170 65 6c 6c 29 20 3e 3e 20 43 45 4c 4c 5f 59 5f 53 |ell) >> CELL_Y_S| 00005180 49 5a 45 5f 46 50 29 3b 0a 2f 2a 20 74 68 65 73 |IZE_FP);./* thes| 00005190 65 20 63 61 6c 63 75 6c 61 74 69 6f 6e 73 20 77 |e calculations w| 000051a0 6f 72 6b 20 6f 75 74 20 77 68 69 63 68 20 63 65 |ork out which ce| 000051b0 6c 6c 73 20 74 68 65 20 72 61 79 20 69 73 20 69 |lls the ray is i| 000051c0 6e 2c 20 72 65 61 64 79 20 74 6f 20 63 68 65 63 |n, ready to chec| 000051d0 6b 20 66 6f 72 20 77 61 6c 6c 73 20 69 6e 20 74 |k for walls in t| 000051e0 68 65 20 77 6f 72 6c 64 5b 5d 5b 5d 20 61 72 72 |he world[][] arr| 000051f0 61 79 2e 20 54 68 65 79 20 62 6f 74 68 20 75 73 |ay. They both us| 00005200 65 20 62 69 6e 61 72 79 20 73 68 69 66 74 69 6e |e binary shiftin| 00005210 67 20 74 6f 20 70 65 72 66 6f 72 6d 20 64 69 76 |g to perform div| 00005220 69 64 65 20 62 79 20 36 34 27 73 2e 20 2a 2f 0a |ide by 64's. */.| 00005230 0a 2f 2a 20 63 68 65 63 6b 20 74 68 61 74 20 74 |./* check that t| 00005240 68 65 20 72 61 79 20 68 61 73 20 6e 6f 74 20 67 |he ray has not g| 00005250 6f 6e 65 20 6f 75 74 20 6f 66 20 74 68 65 20 77 |one out of the w| 00005260 6f 72 6c 64 2c 20 74 68 6f 75 67 68 20 74 68 69 |orld, though thi| 00005270 73 20 69 73 6e 27 74 20 72 65 61 6c 6c 79 20 6e |s isn't really n| 00005280 65 63 65 73 73 61 72 79 20 2a 2f 0a 69 66 28 63 |ecessary */.if(c| 00005290 65 6c 6c 5f 78 3c 30 29 63 65 6c 6c 5f 78 3d 30 |ell_x<0)cell_x=0| 000052a0 3b 69 66 28 63 65 6c 6c 5f 78 3e 36 33 29 63 65 |;if(cell_x>63)ce| 000052b0 6c 6c 5f 78 3d 36 33 3b 0a 69 66 28 63 65 6c 6c |ll_x=63;.if(cell| 000052c0 5f 79 3c 30 29 63 65 6c 6c 5f 79 3d 30 3b 69 66 |_y<0)cell_y=0;if| 000052d0 28 63 65 6c 6c 5f 79 3e 36 33 29 63 65 6c 6c 5f |(cell_y>63)cell_| 000052e0 79 3d 36 33 3b 0a 0a 2f 2a 20 6c 6f 6f 6b 20 61 |y=63;../* look a| 000052f0 6e 64 20 73 65 65 20 69 66 20 74 68 65 72 65 20 |nd see if there | 00005300 69 73 20 61 20 77 61 6c 6c 20 61 74 20 74 68 65 |is a wall at the| 00005310 20 63 75 72 72 65 6e 74 20 70 6f 69 6e 74 20 6f | current point o| 00005320 66 20 69 6e 74 65 72 73 65 63 74 69 6f 6e 20 2a |f intersection *| 00005330 2f 0a 0a 69 66 20 28 28 79 5f 68 69 74 5f 74 79 |/..if ((y_hit_ty| 00005340 70 65 20 3d 20 77 6f 72 6c 64 5b 63 65 6c 6c 5f |pe = world[cell_| 00005350 79 5d 5b 63 65 6c 6c 5f 78 5d 29 21 3d 30 29 0a |y][cell_x])!=0).| 00005360 7b 0a 69 66 28 79 5f 68 69 74 5f 74 79 70 65 3d |{.if(y_hit_type=| 00005370 3d 39 20 7c 7c 20 79 5f 68 69 74 5f 74 79 70 65 |=9 || y_hit_type| 00005380 3d 3d 37 29 7b 0a 20 20 2f 2a 54 48 45 4e 20 54 |==7){. /*THEN T| 00005390 48 45 20 57 41 4c 4c 20 49 53 20 54 52 41 4e 53 |HE WALL IS TRANS| 000053a0 50 41 52 45 4e 54 21 21 21 2a 2f 0a 79 74 72 61 |PARENT!!!*/.ytra| 000053b0 6e 73 5f 64 69 73 74 3d 28 28 78 69 2d 28 76 69 |ns_dist=((xi-(vi| 000053c0 65 77 5f 78 3c 3c 31 36 29 29 3e 3e 38 29 2a 28 |ew_x<<16))>>8)*(| 000053d0 69 6e 76 5f 63 6f 73 5f 74 61 62 6c 65 5b 76 69 |inv_cos_table[vi| 000053e0 65 77 5f 61 6e 67 6c 65 5d 3e 3e 38 29 3b 0a 79 |ew_angle]>>8);.y| 000053f0 74 72 61 6e 73 5f 74 79 70 65 3d 79 5f 68 69 74 |trans_type=y_hit| 00005400 5f 74 79 70 65 3b 0a 79 74 72 61 6e 73 5f 63 6f |_type;.ytrans_co| 00005410 6c 3d 28 28 69 6e 74 29 28 78 69 3e 3e 31 36 29 |l=((int)(xi>>16)| 00005420 20 26 20 30 78 30 30 33 66 29 3b 0a 79 74 72 61 | & 0x003f);.ytra| 00005430 6e 73 5f 64 6f 6e 65 3d 46 4f 55 4e 44 5f 57 41 |ns_done=FOUND_WA| 00005440 4c 4c 3b 0a 7d 0a 2f 2a 20 77 65 20 72 65 63 6f |LL;.}./* we reco| 00005450 72 64 20 61 6c 6c 20 72 65 71 75 69 72 65 64 20 |rd all required | 00005460 64 65 74 61 69 6c 73 20 74 68 65 6e 20 63 6f 6e |details then con| 00005470 74 69 6e 75 65 20 2a 2f 0a 0a 65 6c 73 65 0a 7b |tinue */..else.{| 00005480 0a 0a 0a 0a 2f 2a 20 55 73 65 20 74 68 65 20 6f |..../* Use the o| 00005490 6c 64 20 4f 2d 4c 65 76 65 6c 20 74 72 69 61 6e |ld O-Level trian| 000054a0 67 6c 65 20 6d 65 74 68 6f 64 20 6f 66 20 63 61 |gle method of ca| 000054b0 6c 75 6c 61 74 69 6e 67 20 64 69 73 74 61 6e 63 |lulating distanc| 000054c0 65 20 75 73 69 6e 67 20 63 6f 73 2c 20 72 61 74 |e using cos, rat| 000054d0 68 65 72 20 74 68 61 6e 20 75 73 69 6e 67 20 50 |her than using P| 000054e0 59 54 48 41 47 4f 52 41 53 2c 20 77 68 69 63 68 |YTHAGORAS, which| 000054f0 20 69 73 20 73 6c 6f 77 65 72 20 62 65 63 61 75 | is slower becau| 00005500 73 65 20 69 74 20 75 73 65 73 20 61 20 73 71 75 |se it uses a squ| 00005510 61 72 65 20 72 6f 6f 74 21 20 2a 2f 0a 2f 2a 20 |are root! */./* | 00005520 46 49 58 45 44 20 50 4f 49 4e 54 20 63 61 6c 63 |FIXED POINT calc| 00005530 75 6c 61 74 69 6f 6e 2c 20 6a 75 73 74 20 74 68 |ulation, just th| 00005540 65 20 73 61 6d 65 20 61 73 20 74 68 65 20 69 6e |e same as the in| 00005550 76 5f 73 69 6e 20 63 61 6c 63 75 6c 61 74 69 6f |v_sin calculatio| 00005560 6e 20 73 65 65 20 61 62 6f 76 65 2e 20 2a 2f 0a |n see above. */.| 00005570 64 69 73 74 5f 79 20 20 3d 20 28 20 28 78 69 20 |dist_y = ( (xi | 00005580 2d 20 28 76 69 65 77 5f 78 3c 3c 31 36 29 29 3e |- (view_x<<16))>| 00005590 3e 38 29 20 2a 20 28 69 6e 76 5f 63 6f 73 5f 74 |>8) * (inv_cos_t| 000055a0 61 62 6c 65 5b 76 69 65 77 5f 61 6e 67 6c 65 5d |able[view_angle]| 000055b0 3e 3e 38 29 3b 0a 0a 2f 2a 20 73 61 76 65 20 74 |>>8);../* save t| 000055c0 68 65 20 65 78 61 63 74 20 69 6e 74 65 72 73 65 |he exact interse| 000055d0 63 74 69 6f 6e 20 70 6f 69 6e 74 2c 20 77 65 20 |ction point, we | 000055e0 77 69 6c 6c 20 6e 65 65 64 20 69 74 20 6c 61 74 |will need it lat| 000055f0 65 72 20 2a 2f 0a 2f 2a 20 53 61 6d 65 20 61 73 |er */./* Same as| 00005600 20 61 6f 62 76 65 2c 20 76 65 72 79 20 73 69 6d | aobve, very sim| 00005610 70 6c 65 20 63 6f 6e 76 65 72 73 69 6f 6e 20 62 |ple conversion b| 00005620 61 63 6b 20 66 72 6f 6d 20 46 49 58 45 44 20 50 |ack from FIXED P| 00005630 4f 49 4e 54 20 74 6f 20 6e 6f 72 6d 61 6c 20 6d |OINT to normal m| 00005640 61 74 68 73 20 2a 2f 0a 78 69 5f 73 61 76 65 20 |aths */.xi_save | 00005650 3d 20 28 69 6e 74 29 78 69 3e 3e 31 36 3b 0a 2f |= (int)xi>>16;./| 00005660 2a 20 53 54 4f 50 20 79 20 63 61 73 74 69 6e 67 |* STOP y casting| 00005670 20 69 6e 20 74 68 61 74 20 63 61 73 65 2c 20 61 | in that case, a| 00005680 20 77 61 6c 6c 20 68 61 73 20 62 65 65 6e 20 66 | wall has been f| 00005690 6f 75 6e 64 2e 20 2a 2f 0a 79 72 61 79 3d 46 4f |ound. */.yray=FO| 000056a0 55 4e 44 5f 57 41 4c 4c 3b 0a 7d 0a 7d 0a 0a 0a |UND_WALL;.}.}...| 000056b0 2f 2a 20 69 66 20 6e 6f 74 2c 20 6d 6f 76 65 20 |/* if not, move | 000056c0 74 68 65 20 72 61 79 20 6f 6e 20 2a 2f 0a 78 69 |the ray on */.xi| 000056d0 2b 3d 79 61 64 64 3b 20 2f 2a 20 41 47 41 49 4e |+=yadd; /* AGAIN| 000056e0 2c 20 6e 6f 20 65 78 74 72 61 20 77 6f 72 6b 20 |, no extra work | 000056f0 69 73 20 72 65 71 75 69 72 65 64 20 66 6f 72 20 |is required for | 00005700 46 49 58 45 44 20 50 4f 49 4e 54 20 41 44 44 49 |FIXED POINT ADDI| 00005710 54 49 4f 4e 20 2a 2f 0a 79 5f 62 6f 75 6e 64 20 |TION */.y_bound | 00005720 2b 3d 20 79 5f 64 65 6c 74 61 3b 20 2f 2a 20 61 |+= y_delta; /* a| 00005730 6e 64 20 6d 6f 76 65 20 74 6f 20 74 68 65 20 6e |nd move to the n| 00005740 65 78 74 20 76 65 72 74 69 63 61 6c 20 62 6f 75 |ext vertical bou| 00005750 6e 64 61 72 79 20 70 6f 73 69 74 69 6f 6e 20 2a |ndary position *| 00005760 2f 0a 0a 0a 0a 7d 0a 0a 2f 2a 20 53 45 43 54 49 |/....}../* SECTI| 00005770 4f 4e 20 34 2a 2f 0a 2f 2a 20 42 6f 74 68 20 72 |ON 4*/./* Both r| 00005780 61 79 73 20 68 61 76 65 20 62 65 65 6e 20 63 61 |ays have been ca| 00005790 73 74 2c 20 62 6f 74 68 20 72 61 79 73 20 68 61 |st, both rays ha| 000057a0 76 65 20 6d 65 74 20 61 20 77 61 6c 6c 2c 20 77 |ve met a wall, w| 000057b0 65 20 6e 6f 77 20 6e 65 65 64 20 74 6f 20 73 65 |e now need to se| 000057c0 65 20 77 68 69 63 68 20 69 73 20 63 6c 6f 73 65 |e which is close| 000057d0 72 2c 20 61 6e 64 20 74 68 65 6e 20 70 6c 6f 74 |r, and then plot| 000057e0 20 69 74 20 63 6f 72 72 65 63 74 6c 79 2e 20 2a | it correctly. *| 000057f0 2f 0a 0a 2f 2a 20 66 69 6e 64 20 6f 75 74 20 77 |/../* find out w| 00005800 68 69 63 68 20 77 61 6c 6c 20 28 78 20 6f 72 20 |hich wall (x or | 00005810 79 29 20 69 73 20 6e 65 61 72 65 72 20 74 68 65 |y) is nearer the| 00005820 20 76 69 65 77 65 72 2e 20 2a 2f 0a 0a 2f 2a 20 | viewer. */../* | 00005830 77 65 20 68 61 76 65 20 61 6c 74 65 72 65 64 20 |we have altered | 00005840 74 68 69 73 20 64 69 73 74 61 6e 63 65 20 63 68 |this distance ch| 00005850 65 63 6b 69 6e 67 20 6c 69 6e 65 20 74 6f 20 61 |ecking line to a| 00005860 76 6f 69 64 20 6d 69 6e 75 73 20 64 69 73 74 61 |void minus dista| 00005870 6e 63 65 73 20 62 65 69 6e 67 20 73 65 6c 65 63 |nces being selec| 00005880 74 65 64 20 74 6f 20 64 72 61 77 2c 20 77 68 69 |ted to draw, whi| 00005890 63 68 20 70 72 6f 64 75 63 65 73 20 6c 61 72 67 |ch produces larg| 000058a0 65 20 73 70 69 6b 65 73 20 6f 6e 20 74 68 65 20 |e spikes on the | 000058b0 73 63 72 65 65 6e 21 20 41 67 61 69 6e 20 74 68 |screen! Again th| 000058c0 69 73 20 69 73 20 62 65 63 61 75 73 65 20 6f 66 |is is because of| 000058d0 20 66 69 78 65 64 20 70 6f 69 6e 74 20 2a 2f 0a | fixed point */.| 000058e0 0a 20 20 20 20 69 66 20 28 64 69 73 74 5f 78 20 |. if (dist_x | 000058f0 3c 20 64 69 73 74 5f 79 20 26 26 20 64 69 73 74 |< dist_y && dist| 00005900 5f 78 3e 30 20 7c 7c 20 64 69 73 74 5f 79 3c 30 |_x>0 || dist_y<0| 00005910 29 0a 0a 20 20 20 20 20 20 20 7b 0a 0a 0a 2f 2a |).. {.../*| 00005920 20 77 65 20 6e 65 65 64 20 74 6f 20 74 61 6b 65 | we need to take| 00005930 20 69 6e 74 6f 20 61 63 63 6f 75 6e 74 20 68 65 | into account he| 00005940 72 65 2c 20 77 68 65 6e 20 63 6f 6d 70 75 74 69 |re, when computi| 00005950 6e 67 20 74 68 65 20 73 63 61 6c 65 20 6f 66 20 |ng the scale of | 00005960 74 68 65 20 76 65 72 74 69 63 61 6c 20 73 74 72 |the vertical str| 00005970 69 70 20 28 73 6c 69 76 65 72 29 20 74 6f 20 62 |ip (sliver) to b| 00005980 65 20 64 72 61 77 6e 2c 20 61 20 70 68 65 6e 65 |e drawn, a phene| 00005990 6d 65 6e 6f 6e 20 28 6f 66 20 73 6f 72 74 73 29 |menon (of sorts)| 000059a0 20 6b 6e 6f 77 6e 20 61 73 20 74 68 65 20 22 66 | known as the "f| 000059b0 69 73 68 20 62 6f 77 6c 20 65 66 66 65 63 74 22 |ish bowl effect"| 000059c0 2e 20 54 68 69 73 20 69 73 20 63 61 75 73 65 64 |. This is caused| 000059d0 20 62 79 20 6d 69 7a 69 6e 67 20 6f 66 20 63 61 | by mizing of ca| 000059e0 72 74 65 73 69 61 6e 20 61 6e 64 20 70 6f 6c 61 |rtesian and pola| 000059f0 72 20 63 6f 6f 72 64 69 6e 61 74 65 73 2e 20 54 |r coordinates. T| 00005a00 6f 20 67 65 74 20 72 69 64 20 6f 66 20 69 74 20 |o get rid of it | 00005a10 77 65 20 75 73 65 20 74 68 65 20 63 6f 73 69 6e |we use the cosin| 00005a20 65 20 66 75 6e 63 74 69 6f 6e 2e 20 49 20 68 61 |e function. I ha| 00005a30 76 65 20 63 6f 6d 62 69 6e 65 64 20 6f 74 68 65 |ve combined othe| 00005a40 72 20 6d 75 6c 74 69 70 6c 69 65 73 20 6f 66 20 |r multiplies of | 00005a50 61 20 76 65 72 74 69 63 61 6c 20 73 63 61 6c 69 |a vertical scali| 00005a60 6e 67 20 66 61 63 74 6f 72 20 77 69 74 68 20 74 |ng factor with t| 00005a70 68 65 20 63 6f 73 69 6e 65 20 74 72 61 6e 73 66 |he cosine transf| 00005a80 6f 72 6d 61 74 69 6f 6e 20 74 6f 20 73 61 76 65 |ormation to save| 00005a90 20 74 69 6d 65 2e 20 41 6c 6c 20 77 65 20 65 76 | time. All we ev| 00005aa0 65 6e 74 75 61 6c 6c 79 20 62 65 20 65 78 70 6c |entually be expl| 00005ab0 61 69 6e 65 64 2e 20 59 6f 75 20 63 6f 75 6c 64 |ained. You could| 00005ac0 20 72 65 70 6c 61 63 65 20 74 68 65 20 6c 69 6e | replace the lin| 00005ad0 65 20 77 69 74 68 20 73 63 61 6c 65 3d 31 33 33 |e with scale=133| 00005ae0 31 32 2f 64 69 73 74 5f 78 2b 2b 20 61 6e 64 20 |12/dist_x++ and | 00005af0 73 65 65 20 77 68 61 74 20 77 65 69 72 64 20 72 |see what weird r| 00005b00 65 73 75 6c 74 73 20 79 6f 75 20 67 65 74 21 20 |esults you get! | 00005b10 2a 2f 0a 0a 2f 2a 20 4e 45 57 20 4e 45 57 20 4e |*/../* NEW NEW N| 00005b20 45 57 20 3a 20 57 65 20 68 61 76 65 20 66 69 78 |EW : We have fix| 00005b30 65 64 20 70 6f 69 6e 74 20 68 65 72 65 2c 20 61 |ed point here, a| 00005b40 6e 64 20 75 73 69 6e 67 20 74 68 65 20 72 65 63 |nd using the rec| 00005b50 69 70 72 6f 63 61 6c 20 74 61 62 6c 65 20 28 73 |iprocal table (s| 00005b60 65 65 20 61 72 6f 75 6e 64 29 20 77 65 20 64 6f |ee around) we do| 00005b70 6e 27 74 20 68 61 76 65 20 74 6f 20 64 6f 20 61 |n't have to do a| 00005b80 20 6c 65 6e 67 74 68 79 20 64 69 76 69 64 65 21 | lengthy divide!| 00005b90 20 4e 6f 74 69 63 65 20 68 6f 77 20 77 65 20 63 | Notice how we c| 00005ba0 6f 6e 76 65 72 74 20 64 69 73 74 5f 78 20 62 61 |onvert dist_x ba| 00005bb0 63 6b 20 74 6f 20 6e 6f 72 6d 61 6c 20 74 6f 20 |ck to normal to | 00005bc0 69 6e 64 65 78 20 74 68 65 20 72 65 63 69 70 5f |index the recip_| 00005bd0 74 61 62 6c 65 20 61 72 72 61 79 2c 20 61 6e 64 |table array, and| 00005be0 20 74 68 61 74 20 61 6c 6c 20 61 63 63 75 72 61 | that all accura| 00005bf0 63 79 20 69 73 20 6c 6f 73 74 20 77 69 74 68 20 |cy is lost with | 00005c00 74 68 65 20 63 6f 73 5f 74 61 62 6c 65 2c 20 62 |the cos_table, b| 00005c10 65 63 61 75 73 65 20 61 6c 6c 20 69 74 73 20 66 |ecause all its f| 00005c20 69 67 75 72 65 73 20 61 72 65 20 61 62 6f 76 65 |igures are above| 00005c30 20 7a 65 72 6f 20 28 73 65 65 20 61 75 61 5f 74 | zero (see aua_t| 00005c40 61 62 6c 65 73 29 20 61 6e 64 20 61 6c 73 6f 20 |ables) and also | 00005c50 74 68 61 74 20 77 65 20 61 63 74 75 61 6c 6c 79 |that we actually| 00005c60 20 63 6f 6e 76 65 72 74 20 74 68 65 20 77 68 6f | convert the who| 00005c70 6c 65 20 61 6e 73 77 65 72 20 62 61 63 6b 20 74 |le answer back t| 00005c80 6f 20 6e 6f 72 6d 61 6c 20 6d 61 74 68 73 20 66 |o normal maths f| 00005c90 6f 72 20 73 63 61 6c 65 20 2a 2f 0a 0a 73 63 61 |or scale */..sca| 00005ca0 6c 65 20 3d 20 28 69 6e 74 29 28 20 28 63 6f 73 |le = (int)( (cos| 00005cb0 5f 74 61 62 6c 65 5b 72 61 79 5d 3e 3e 31 36 29 |_table[ray]>>16)| 00005cc0 20 2a 20 28 72 65 63 69 70 5f 74 61 62 6c 65 5b | * (recip_table[| 00005cd0 64 69 73 74 5f 78 3e 3e 31 36 5d 29 20 3e 3e 31 |dist_x>>16]) >>1| 00005ce0 36 29 3b 0a 0a 2f 2a 20 61 73 73 69 67 6e 20 74 |6);../* assign t| 00005cf0 68 65 20 76 61 72 69 61 62 6c 65 73 20 77 65 20 |he variables we | 00005d00 6e 65 65 64 20 74 6f 20 74 68 65 20 76 61 72 69 |need to the vari| 00005d10 61 62 6c 65 73 20 74 6f 20 62 65 20 70 61 73 73 |ables to be pass| 00005d20 65 64 20 74 6f 20 74 68 65 20 41 53 4d 20 73 6c |ed to the ASM sl| 00005d30 69 76 65 72 20 72 65 6e 64 65 72 65 72 20 28 73 |iver renderer (s| 00005d40 75 70 65 72 20 66 61 73 74 21 29 20 2a 2f 0a 69 |uper fast!) */.i| 00005d50 66 28 73 63 61 6c 65 3e 53 43 52 45 45 4e 5f 48 |f(scale>SCREEN_H| 00005d60 45 49 47 48 54 29 0a 7b 0a 0a 20 20 73 63 61 6c |EIGHT).{.. scal| 00005d70 65 3d 53 43 52 45 45 4e 5f 48 45 49 47 48 54 2d |e=SCREEN_HEIGHT-| 00005d80 31 3b 0a 7d 0a 0a 76 61 72 69 61 62 6c 65 73 5b |1;.}..variables[| 00005d90 32 5d 3d 73 63 61 6c 65 3b 20 2f 2a 73 74 6f 72 |2]=scale; /*stor| 00005da0 65 73 20 74 68 65 20 73 63 61 6c 65 20 6f 66 20 |es the scale of | 00005db0 74 68 65 20 73 74 72 69 70 20 28 68 65 69 67 68 |the strip (heigh| 00005dc0 74 20 6f 66 20 69 74 29 2a 2f 0a 76 61 72 69 61 |t of it)*/.varia| 00005dd0 62 6c 65 73 5b 33 5d 3d 72 61 79 3b 20 2f 2a 20 |bles[3]=ray; /* | 00005de0 77 65 20 75 73 65 20 72 61 79 20 61 73 20 74 68 |we use ray as th| 00005df0 65 20 78 20 70 6f 73 69 74 69 6f 6e 20 74 6f 20 |e x position to | 00005e00 70 6c 6f 74 20 74 6f 20 28 30 2d 33 31 39 29 2a |plot to (0-319)*| 00005e10 2f 0a 76 61 72 69 61 62 6c 65 73 5b 31 5d 3d 28 |/.variables[1]=(| 00005e20 69 6e 74 29 26 77 61 6c 6c 73 5b 78 5f 68 69 74 |int)&walls[x_hit| 00005e30 5f 74 79 70 65 5d 5b 28 79 69 5f 73 61 76 65 20 |_type][(yi_save | 00005e40 26 20 30 78 30 30 33 66 29 5d 3b 0a 76 61 72 69 |& 0x003f)];.vari| 00005e50 61 62 6c 65 73 5b 34 5d 3d 28 72 65 63 69 70 5f |ables[4]=(recip_| 00005e60 74 61 62 6c 65 5b 73 63 61 6c 65 5d 3c 3c 36 29 |table[scale]<<6)| 00005e70 3b 0a 2f 2a 20 61 6e 64 20 77 65 20 63 61 6c 6c |;./* and we call| 00005e80 20 74 68 65 20 61 73 73 65 6d 62 6c 65 72 20 66 | the assembler f| 00005e90 75 6e 63 74 69 6f 6e 20 28 65 78 70 6c 61 69 6e |unction (explain| 00005ea0 65 64 20 61 74 20 61 20 6c 61 74 65 72 20 64 61 |ed at a later da| 00005eb0 74 65 29 2a 2f 0a 6f 75 72 6c 69 62 5f 6e 65 77 |te)*/.ourlib_new| 00005ec0 28 26 76 61 72 69 61 62 6c 65 73 5b 30 5d 29 3b |(&variables[0]);| 00005ed0 0a 73 63 61 6c 65 5f 61 72 72 61 79 5b 72 61 79 |.scale_array[ray| 00005ee0 5d 3d 73 63 61 6c 65 3b 0a 20 20 20 20 20 20 20 |]=scale;. | 00005ef0 7d 0a 2f 2a 20 65 6c 73 65 20 74 68 65 20 64 69 |}./* else the di| 00005f00 73 74 5f 79 20 77 61 73 20 6e 65 61 72 65 72 2c |st_y was nearer,| 00005f10 20 65 76 65 72 79 74 68 69 6e 67 20 66 72 6f 6d | everything from| 00005f20 20 61 62 6f 76 65 20 61 70 70 6c 69 65 73 20 2a | above applies *| 00005f30 2f 0a 20 20 20 20 65 6c 73 65 0a 20 20 20 20 20 |/. else. | 00005f40 20 20 7b 0a 0a 2f 2a 20 61 76 6f 69 64 20 66 69 | {../* avoid fi| 00005f50 73 68 20 62 6f 77 6c 20 65 66 66 65 63 74 20 61 |sh bowl effect a| 00005f60 6e 64 20 73 63 61 6c 65 20 70 72 6f 70 65 72 6c |nd scale properl| 00005f70 79 20 77 69 74 68 20 46 49 58 45 44 20 50 4f 49 |y with FIXED POI| 00005f80 4e 54 20 63 6c 65 76 65 72 20 62 69 74 73 21 2c |NT clever bits!,| 00005f90 20 73 65 65 20 61 62 6f 76 65 20 2a 2f 0a 73 63 | see above */.sc| 00005fa0 61 6c 65 20 3d 20 28 69 6e 74 29 28 20 28 63 6f |ale = (int)( (co| 00005fb0 73 5f 74 61 62 6c 65 5b 72 61 79 5d 3e 3e 31 36 |s_table[ray]>>16| 00005fc0 29 20 2a 20 28 72 65 63 69 70 5f 74 61 62 6c 65 |) * (recip_table| 00005fd0 5b 64 69 73 74 5f 79 3e 3e 31 36 5d 29 20 3e 3e |[dist_y>>16]) >>| 00005fe0 20 31 36 29 3b 0a 0a 0a 2f 2a 20 73 65 74 20 75 | 16);.../* set u| 00005ff0 70 20 76 61 72 69 61 62 6c 65 73 20 66 6f 72 20 |p variables for | 00006000 6f 75 72 20 73 6c 69 76 65 72 20 65 6e 67 69 6e |our sliver engin| 00006010 65 2c 20 73 65 65 20 61 62 6f 76 65 20 2a 2f 0a |e, see above */.| 00006020 69 66 28 73 63 61 6c 65 3e 53 43 52 45 45 4e 5f |if(scale>SCREEN_| 00006030 48 45 49 47 48 54 29 0a 7b 0a 0a 20 20 73 63 61 |HEIGHT).{.. sca| 00006040 6c 65 3d 53 43 52 45 45 4e 5f 48 45 49 47 48 54 |le=SCREEN_HEIGHT| 00006050 2d 31 3b 0a 7d 0a 0a 76 61 72 69 61 62 6c 65 73 |-1;.}..variables| 00006060 5b 32 5d 3d 73 63 61 6c 65 3b 20 2f 2a 73 74 6f |[2]=scale; /*sto| 00006070 72 65 73 20 74 68 65 20 73 63 61 6c 65 20 6f 66 |res the scale of| 00006080 20 74 68 65 20 73 74 72 69 70 20 28 68 65 69 67 | the strip (heig| 00006090 68 74 20 6f 66 20 69 74 29 2a 2f 0a 76 61 72 69 |ht of it)*/.vari| 000060a0 61 62 6c 65 73 5b 33 5d 3d 72 61 79 3b 20 2f 2a |ables[3]=ray; /*| 000060b0 20 77 65 20 75 73 65 20 72 61 79 20 61 73 20 74 | we use ray as t| 000060c0 68 65 20 78 20 70 6f 73 69 74 69 6f 6e 20 74 6f |he x position to| 000060d0 20 70 6c 6f 74 20 74 6f 20 28 30 2d 33 31 39 29 | plot to (0-319)| 000060e0 2a 2f 0a 76 61 72 69 61 62 6c 65 73 5b 31 5d 3d |*/.variables[1]=| 000060f0 28 69 6e 74 29 26 77 61 6c 6c 73 5b 79 5f 68 69 |(int)&walls[y_hi| 00006100 74 5f 74 79 70 65 2b 31 5d 5b 28 78 69 5f 73 61 |t_type+1][(xi_sa| 00006110 76 65 20 26 20 30 78 30 30 33 66 29 5d 3b 0a 76 |ve & 0x003f)];.v| 00006120 61 72 69 61 62 6c 65 73 5b 34 5d 3d 28 72 65 63 |ariables[4]=(rec| 00006130 69 70 5f 74 61 62 6c 65 5b 73 63 61 6c 65 5d 3c |ip_table[scale]<| 00006140 3c 36 29 3b 0a 2f 2a 20 6e 6f 74 69 63 65 20 77 |<6);./* notice w| 00006150 65 20 61 64 64 20 6f 6e 65 20 74 6f 20 74 68 65 |e add one to the| 00006160 20 77 61 6c 6c 20 67 72 61 70 68 69 63 20 73 65 | wall graphic se| 00006170 6c 65 63 74 69 6f 6e 2c 20 73 6f 20 74 68 65 20 |lection, so the | 00006180 64 61 72 6b 65 72 20 74 69 6c 65 20 69 73 20 75 |darker tile is u| 00006190 73 65 64 20 66 6f 72 20 61 64 64 65 64 20 76 61 |sed for added va| 000061a0 72 69 61 74 69 6f 6e 2e 20 53 65 65 20 74 68 65 |riation. See the| 000061b0 20 61 72 74 69 63 6c 65 20 66 6f 72 20 6d 6f 72 | article for mor| 000061c0 65 20 64 65 74 61 69 6c 73 20 6f 66 20 74 68 69 |e details of thi| 000061d0 73 20 73 6f 72 74 20 6f 66 20 73 68 61 64 69 6e |s sort of shadin| 000061e0 67 2c 20 69 66 20 79 6f 75 20 77 61 6e 74 20 74 |g, if you want t| 000061f0 6f 20 63 61 6c 6c 20 69 74 20 74 68 61 74 21 20 |o call it that! | 00006200 2a 2f 0a 0a 2f 2a 20 63 61 6c 6c 20 6f 75 72 20 |*/../* call our | 00006210 73 6c 69 76 65 72 20 65 6e 67 69 6e 65 20 2a 2f |sliver engine */| 00006220 0a 6f 75 72 6c 69 62 5f 6e 65 77 28 26 76 61 72 |.ourlib_new(&var| 00006230 69 61 62 6c 65 73 5b 30 5d 29 3b 0a 73 63 61 6c |iables[0]);.scal| 00006240 65 5f 61 72 72 61 79 5b 72 61 79 5d 3d 73 63 61 |e_array[ray]=sca| 00006250 6c 65 3b 0a 20 20 20 20 20 20 20 7d 0a 2f 2a 20 |le;. }./* | 00006260 69 74 20 69 73 20 68 65 72 65 20 74 68 61 74 20 |it is here that | 00006270 77 65 20 64 72 61 77 20 74 68 65 20 6f 76 65 72 |we draw the over| 00006280 6c 61 79 69 6e 67 20 74 72 61 6e 73 70 61 72 65 |laying transpare| 00006290 6e 74 20 77 61 6c 6c 20 2a 2f 0a 69 66 28 78 74 |nt wall */.if(xt| 000062a0 72 61 6e 73 5f 64 6f 6e 65 20 26 26 20 78 74 72 |rans_done && xtr| 000062b0 61 6e 73 5f 64 69 73 74 3c 64 69 73 74 5f 79 29 |ans_dist<dist_y)| 000062c0 0a 7b 0a 20 20 73 63 61 6c 65 3d 28 69 6e 74 29 |.{. scale=(int)| 000062d0 28 28 63 6f 73 5f 74 61 62 6c 65 5b 72 61 79 5d |((cos_table[ray]| 000062e0 3e 3e 31 36 29 20 2a 20 28 72 65 63 69 70 5f 74 |>>16) * (recip_t| 000062f0 61 62 6c 65 5b 78 74 72 61 6e 73 5f 64 69 73 74 |able[xtrans_dist| 00006300 3e 3e 31 36 5d 29 3e 3e 31 36 29 3b 0a 20 20 69 |>>16])>>16);. i| 00006310 66 28 73 63 61 6c 65 3e 53 43 52 45 45 4e 5f 48 |f(scale>SCREEN_H| 00006320 45 49 47 48 54 29 73 63 61 6c 65 3d 53 43 52 45 |EIGHT)scale=SCRE| 00006330 45 4e 5f 48 45 49 47 48 54 2d 31 3b 0a 20 20 76 |EN_HEIGHT-1;. v| 00006340 61 72 69 61 62 6c 65 73 5b 32 5d 3d 73 63 61 6c |ariables[2]=scal| 00006350 65 3b 0a 20 20 76 61 72 69 61 62 6c 65 73 5b 33 |e;. variables[3| 00006360 5d 3d 72 61 79 3b 0a 20 20 76 61 72 69 61 62 6c |]=ray;. variabl| 00006370 65 73 5b 34 5d 3d 28 72 65 63 69 70 5f 74 61 62 |es[4]=(recip_tab| 00006380 6c 65 5b 73 63 61 6c 65 5d 3c 3c 36 29 3b 0a 20 |le[scale]<<6);. | 00006390 20 76 61 72 69 61 62 6c 65 73 5b 31 5d 3d 28 69 | variables[1]=(i| 000063a0 6e 74 29 26 77 61 6c 6c 73 5b 78 74 72 61 6e 73 |nt)&walls[xtrans| 000063b0 5f 74 79 70 65 5d 5b 78 74 72 61 6e 73 5f 63 6f |_type][xtrans_co| 000063c0 6c 5d 3b 0a 0a 2f 2a 20 6e 6f 77 20 63 61 6c 6c |l];../* now call| 000063d0 20 6f 75 72 20 73 70 65 63 69 61 6c 20 66 75 6e | our special fun| 000063e0 63 74 69 6f 6e 20 77 68 69 63 68 20 74 72 65 61 |ction which trea| 000063f0 74 73 20 63 6f 6c 6f 72 20 30 20 61 73 20 61 20 |ts color 0 as a | 00006400 6d 61 73 6b 20 2a 2f 0a 0a 6f 75 72 6c 69 62 5f |mask */..ourlib_| 00006410 6e 65 77 5f 6d 61 73 6b 28 76 61 72 69 61 62 6c |new_mask(variabl| 00006420 65 73 29 3b 0a 73 63 61 6c 65 5f 61 72 72 61 79 |es);.scale_array| 00006430 5b 72 61 79 5d 3d 73 63 61 6c 65 3b 0a 7d 0a 65 |[ray]=scale;.}.e| 00006440 6c 73 65 20 69 66 28 79 74 72 61 6e 73 5f 64 6f |lse if(ytrans_do| 00006450 6e 65 20 26 26 20 79 74 72 61 6e 73 5f 64 69 73 |ne && ytrans_dis| 00006460 74 3c 64 69 73 74 5f 78 29 0a 7b 0a 20 20 73 63 |t<dist_x).{. sc| 00006470 61 6c 65 3d 28 69 6e 74 29 28 28 63 6f 73 5f 74 |ale=(int)((cos_t| 00006480 61 62 6c 65 5b 72 61 79 5d 3e 3e 31 36 29 20 2a |able[ray]>>16) *| 00006490 20 28 72 65 63 69 70 5f 74 61 62 6c 65 5b 79 74 | (recip_table[yt| 000064a0 72 61 6e 73 5f 64 69 73 74 3e 3e 31 36 5d 29 3e |rans_dist>>16])>| 000064b0 3e 31 36 29 3b 0a 20 20 69 66 28 73 63 61 6c 65 |>16);. if(scale| 000064c0 3e 53 43 52 45 45 4e 5f 48 45 49 47 48 54 29 73 |>SCREEN_HEIGHT)s| 000064d0 63 61 6c 65 3d 53 43 52 45 45 4e 5f 48 45 49 47 |cale=SCREEN_HEIG| 000064e0 48 54 2d 31 3b 0a 20 20 76 61 72 69 61 62 6c 65 |HT-1;. variable| 000064f0 73 5b 32 5d 3d 73 63 61 6c 65 3b 0a 20 20 76 61 |s[2]=scale;. va| 00006500 72 69 61 62 6c 65 73 5b 33 5d 3d 72 61 79 3b 0a |riables[3]=ray;.| 00006510 20 20 76 61 72 69 61 62 6c 65 73 5b 34 5d 3d 28 | variables[4]=(| 00006520 72 65 63 69 70 5f 74 61 62 6c 65 5b 73 63 61 6c |recip_table[scal| 00006530 65 5d 3c 3c 36 29 3b 0a 20 20 76 61 72 69 61 62 |e]<<6);. variab| 00006540 6c 65 73 5b 31 5d 3d 28 69 6e 74 29 26 77 61 6c |les[1]=(int)&wal| 00006550 6c 73 5b 79 74 72 61 6e 73 5f 74 79 70 65 2b 31 |ls[ytrans_type+1| 00006560 5d 5b 79 74 72 61 6e 73 5f 63 6f 6c 5d 3b 0a 0a |][ytrans_col];..| 00006570 2f 2a 20 6e 6f 77 20 63 61 6c 6c 20 6f 75 72 20 |/* now call our | 00006580 73 70 65 63 69 61 6c 20 66 75 6e 63 74 69 6f 6e |special function| 00006590 20 77 68 69 63 68 20 74 72 65 61 74 73 20 63 6f | which treats co| 000065a0 6c 6f 72 20 30 20 61 73 20 61 20 6d 61 73 6b 20 |lor 0 as a mask | 000065b0 2a 2f 0a 0a 6f 75 72 6c 69 62 5f 6e 65 77 5f 6d |*/..ourlib_new_m| 000065c0 61 73 6b 28 76 61 72 69 61 62 6c 65 73 29 3b 0a |ask(variables);.| 000065d0 73 63 61 6c 65 5f 61 72 72 61 79 5b 72 61 79 5d |scale_array[ray]| 000065e0 3d 73 63 61 6c 65 3b 0a 7d 0a 0a 0a 0a 0a 2f 2a |=scale;.}...../*| 000065f0 20 74 68 69 73 20 72 61 79 20 68 61 73 20 62 65 | this ray has be| 00006600 65 6e 20 66 69 6e 69 73 68 65 64 2e 20 49 6e 63 |en finished. Inc| 00006610 72 65 61 73 65 20 74 68 65 20 61 6e 67 6c 65 20 |rease the angle | 00006620 6f 66 20 74 68 65 20 6e 65 78 74 20 72 61 79 20 |of the next ray | 00006630 61 6e 64 20 73 74 61 72 74 20 61 67 61 69 6e 21 |and start again!| 00006640 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28 2b 2b 76 | */.. if (++v| 00006650 69 65 77 5f 61 6e 67 6c 65 3e 3d 41 4e 47 4c 45 |iew_angle>=ANGLE| 00006660 5f 33 36 30 29 0a 20 20 20 20 20 20 20 7b 0a 20 |_360). {. | 00006670 20 20 20 20 20 20 2f 2a 20 74 68 69 73 20 65 6e | /* this en| 00006680 73 75 72 65 73 20 74 68 61 74 20 74 68 65 20 72 |sures that the r| 00006690 61 79 20 61 6e 67 6c 65 20 64 6f 65 73 6e 27 74 |ay angle doesn't| 000066a0 20 67 6f 20 6f 76 65 72 20 33 36 30 20 64 65 67 | go over 360 deg| 000066b0 72 65 65 73 21 20 2a 2f 0a 20 20 20 20 20 20 20 |rees! */. | 000066c0 76 69 65 77 5f 61 6e 67 6c 65 3d 30 3b 0a 0a 20 |view_angle=0;.. | 000066d0 20 20 20 20 20 20 7d 0a 2f 2a 20 72 61 79 20 6c | }./* ray l| 000066e0 6f 6f 70 20 2a 2f 0a 20 20 20 20 7d 0a 2f 2a 20 |oop */. }./* | 000066f0 65 6e 64 20 72 61 79 20 63 61 73 74 65 72 20 65 |end ray caster e| 00006700 6e 67 69 6e 65 20 2a 2f 0a 2f 2a 20 6f 62 6a 65 |ngine */./* obje| 00006710 63 74 73 2a 2f 0a 0a 0a 7d 0a 0a 0a 0a 2f 2a 20 |cts*/...}..../* | 00006720 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 67 72 |this function gr| 00006730 61 62 73 20 61 6c 6c 20 74 68 65 20 64 69 66 66 |abs all the diff| 00006740 65 72 65 6e 74 20 77 61 6c 6c 73 20 66 72 6f 6d |erent walls from| 00006750 20 61 20 73 69 6e 67 6c 65 20 66 69 6c 65 20 2a | a single file *| 00006760 2f 0a 0a 76 6f 69 64 20 61 75 61 5f 67 72 61 70 |/..void aua_grap| 00006770 68 69 63 73 28 76 6f 69 64 29 0a 7b 0a 69 6e 74 |hics(void).{.int| 00006780 20 78 2c 20 2f 2a 20 74 68 69 73 20 69 73 20 75 | x, /* this is u| 00006790 73 65 64 20 74 6f 20 73 74 6f 72 65 20 74 68 65 |sed to store the| 000067a0 20 78 20 63 6f 6f 72 64 69 6e 61 74 65 20 6f 66 | x coordinate of| 000067b0 20 61 20 70 6f 69 6e 74 20 6f 6e 20 74 68 65 20 | a point on the | 000067c0 73 63 72 65 65 6e 20 2a 2f 0a 20 20 20 20 79 2c |screen */. y,| 000067d0 20 2f 2a 20 74 68 69 73 20 69 73 20 75 73 65 64 | /* this is used| 000067e0 20 74 6f 20 73 74 6f 72 65 20 74 68 65 20 79 20 | to store the y | 000067f0 63 6f 6f 72 64 69 6e 61 74 65 20 6f 66 20 61 20 |coordinate of a | 00006800 70 6f 69 6e 74 20 6f 6e 20 74 68 65 20 73 63 72 |point on the scr| 00006810 65 65 6e 20 2a 2f 0a 20 20 20 20 77 61 6c 6c 5f |een */. wall_| 00006820 6e 75 6d 62 65 72 3b 20 2f 2a 20 74 68 69 73 20 |number; /* this | 00006830 77 69 6c 6c 20 62 65 20 75 73 65 64 20 74 6f 20 |will be used to | 00006840 69 6e 64 65 78 20 74 68 65 20 77 61 6c 6c 73 5b |index the walls[| 00006850 78 5d 5b 5d 20 63 68 61 72 20 61 72 72 61 79 20 |x][] char array | 00006860 2a 2f 0a 0a 2f 2a 20 66 69 72 73 74 20 6f 66 20 |*/../* first of | 00006870 61 6c 6c 20 77 65 20 67 65 74 20 74 68 65 20 67 |all we get the g| 00006880 72 61 70 68 69 63 73 20 66 69 6c 65 20 3c 41 55 |raphics file <AU| 00006890 41 52 61 79 24 44 69 72 3e 2e 67 72 61 70 68 69 |ARay$Dir>.graphi| 000068a0 63 73 20 6f 6e 74 6f 20 74 68 65 20 73 63 72 65 |cs onto the scre| 000068b0 65 6e 20 2a 2f 0a 0a 73 79 73 74 65 6d 28 22 2a |en */..system("*| 000068c0 53 63 72 65 65 6e 4c 6f 61 64 20 3c 41 55 41 52 |ScreenLoad <AUAR| 000068d0 61 79 24 44 69 72 3e 2e 67 72 61 70 68 69 63 73 |ay$Dir>.graphics| 000068e0 22 29 3b 0a 0a 2f 2a 20 6e 65 78 74 20 77 65 20 |");../* next we | 000068f0 73 74 61 72 74 20 67 72 61 62 62 69 6e 67 20 65 |start grabbing e| 00006900 61 63 68 20 74 69 6c 65 2c 20 36 34 20 78 20 36 |ach tile, 64 x 6| 00006910 34 20 70 69 78 65 6c 73 2c 20 69 6e 74 6f 20 74 |4 pixels, into t| 00006920 68 65 20 77 61 6c 6c 73 5b 5d 5b 5d 20 61 72 72 |he walls[][] arr| 00006930 61 79 20 2a 2f 0a 0a 2f 2a 20 77 65 20 75 73 65 |ay */../* we use| 00006940 20 74 68 69 73 20 6c 61 72 67 65 20 66 6f 72 20 | this large for | 00006950 6c 6f 6f 70 20 61 74 20 74 68 65 20 6f 75 72 6c |loop at the ourl| 00006960 69 62 5f 62 69 74 6d 61 70 5f 67 72 61 62 20 66 |ib_bitmap_grab f| 00006970 75 6e 63 74 69 6f 6e 20 74 6f 20 69 6e 76 69 64 |unction to invid| 00006980 75 61 6c 6c 79 20 67 72 61 62 20 65 61 63 68 20 |ually grab each | 00006990 74 69 6c 65 20 69 6e 74 6f 20 69 74 73 20 6f 77 |tile into its ow| 000069a0 6e 20 77 61 6c 6c 73 5b 78 5d 5b 5d 20 61 72 72 |n walls[x][] arr| 000069b0 61 79 20 73 6c 6f 74 2c 20 6e 6f 74 65 20 74 68 |ay slot, note th| 000069c0 61 74 20 77 65 20 43 41 4e 27 54 20 48 41 56 45 |at we CAN'T HAVE| 000069d0 20 57 41 4c 4c 20 30 20 61 73 20 74 68 69 73 20 | WALL 0 as this | 000069e0 72 65 70 72 65 73 65 6e 74 73 20 61 20 67 61 70 |represents a gap| 000069f0 20 69 6e 20 74 68 65 20 77 6f 72 6c 64 21 20 2a | in the world! *| 00006a00 2f 0a 0a 6f 75 72 6c 69 62 5f 6b 69 6c 6c 63 75 |/..ourlib_killcu| 00006a10 72 73 6f 72 28 29 3b 20 2f 2a 20 67 65 74 20 72 |rsor(); /* get r| 00006a20 69 64 20 6f 66 20 63 75 72 73 6f 72 20 66 69 72 |id of cursor fir| 00006a30 73 74 20 2a 2f 0a 0a 66 6f 72 28 77 61 6c 6c 5f |st */..for(wall_| 00006a40 6e 75 6d 62 65 72 3d 31 2c 79 3d 30 3b 79 3c 32 |number=1,y=0;y<2| 00006a50 35 36 3b 79 2b 3d 57 41 4c 4c 5f 48 45 49 47 48 |56;y+=WALL_HEIGH| 00006a60 54 29 66 6f 72 28 78 3d 30 3b 78 3c 33 32 30 3b |T)for(x=0;x<320;| 00006a70 78 2b 3d 57 41 4c 4c 5f 57 49 44 54 48 2c 77 61 |x+=WALL_WIDTH,wa| 00006a80 6c 6c 5f 6e 75 6d 62 65 72 2b 2b 29 0a 7b 0a 2f |ll_number++).{./| 00006a90 2a 20 74 68 69 73 20 63 61 6c 6c 73 20 74 68 65 |* this calls the| 00006aa0 20 66 75 6e 63 74 69 6f 6e 20 6f 75 72 6c 69 62 | function ourlib| 00006ab0 5f 62 69 74 6d 61 70 5f 67 72 61 62 20 28 49 20 |_bitmap_grab (I | 00006ac0 73 61 69 64 20 69 74 20 77 6f 75 6c 64 20 62 65 |said it would be| 00006ad0 20 68 61 6e 64 79 21 29 20 77 68 69 63 68 20 67 | handy!) which g| 00006ae0 72 61 62 73 20 74 68 65 20 61 72 65 61 20 6f 66 |rabs the area of| 00006af0 20 73 63 72 65 65 6e 20 6d 65 6d 6f 72 79 20 6d | screen memory m| 00006b00 61 72 6b 65 64 20 62 79 20 74 68 65 20 66 69 72 |arked by the fir| 00006b10 73 74 20 66 6f 75 72 20 70 61 72 61 6d 65 74 65 |st four paramete| 00006b20 72 73 2c 20 73 74 6f 72 65 73 20 69 74 20 69 6e |rs, stores it in| 00006b30 20 74 68 65 20 62 79 74 65 20 61 72 72 61 79 20 | the byte array | 00006b40 70 6f 69 6e 74 65 72 20 69 6e 20 70 61 72 61 6d |pointer in param| 00006b50 65 74 65 72 20 66 69 76 65 2c 20 72 65 61 64 69 |eter five, readi| 00006b60 6e 67 20 69 74 20 61 6c 6c 20 66 72 6f 6d 20 74 |ng it all from t| 00006b70 68 65 20 73 63 72 65 65 6e 20 70 6f 69 6e 74 65 |he screen pointe| 00006b80 64 20 74 6f 20 62 79 20 73 63 72 65 65 6e 5f 61 |d to by screen_a| 00006b90 64 64 72 65 73 73 20 2a 2f 0a 0a 6f 75 72 6c 69 |ddress */..ourli| 00006ba0 62 5f 62 69 74 6d 61 70 5f 67 72 61 62 28 78 2c |b_bitmap_grab(x,| 00006bb0 79 2c 78 2b 57 41 4c 4c 5f 57 49 44 54 48 2d 31 |y,x+WALL_WIDTH-1| 00006bc0 2c 79 2b 57 41 4c 4c 5f 48 45 49 47 48 54 2d 31 |,y+WALL_HEIGHT-1| 00006bd0 2c 26 77 61 6c 6c 73 5b 77 61 6c 6c 5f 6e 75 6d |,&walls[wall_num| 00006be0 62 65 72 5d 5b 30 5d 2c 73 63 72 65 65 6e 5f 61 |ber][0],screen_a| 00006bf0 64 64 72 65 73 73 29 3b 0a 0a 2f 2a 20 74 68 69 |ddress);../* thi| 00006c00 73 20 6d 61 6b 65 73 20 73 75 72 65 20 77 65 20 |s makes sure we | 00006c10 64 6f 6e 27 74 20 67 6f 20 6f 76 65 72 20 6f 75 |don't go over ou| 00006c20 72 20 6e 75 6d 62 65 72 20 6f 66 20 77 61 6c 6c |r number of wall| 00006c30 73 20 6c 69 6d 69 74 20 2a 2f 0a 0a 69 66 28 77 |s limit */..if(w| 00006c40 61 6c 6c 5f 6e 75 6d 62 65 72 3e 3d 57 41 4c 4c |all_number>=WALL| 00006c50 5f 4e 55 4d 42 45 52 29 62 72 65 61 6b 3b 0a 7d |_NUMBER)break;.}| 00006c60 0a 0a 2f 2a 20 6e 65 77 20 73 74 75 66 66 20 6c |../* new stuff l| 00006c70 6f 61 64 20 69 6e 20 6f 62 6a 65 63 74 73 20 73 |oad in objects s| 00006c80 65 70 61 72 61 74 65 6c 79 20 2a 2f 0a 2f 2a 20 |eparately */./* | 00006c90 73 65 65 20 61 62 6f 76 65 20 66 6f 72 20 63 6f |see above for co| 00006ca0 6d 6d 65 6e 74 73 20 28 69 74 73 20 69 64 65 6e |mments (its iden| 00006cb0 74 69 63 61 6c 29 20 2a 2f 0a 73 79 73 74 65 6d |tical) */.system| 00006cc0 28 22 2a 53 63 72 65 65 6e 4c 6f 61 64 20 3c 41 |("*ScreenLoad <A| 00006cd0 55 41 52 61 79 24 44 69 72 3e 2e 4f 62 6a 67 72 |UARay$Dir>.Objgr| 00006ce0 61 70 68 69 63 22 29 3b 0a 6f 75 72 6c 69 62 5f |aphic");.ourlib_| 00006cf0 6b 69 6c 6c 63 75 72 73 6f 72 28 29 3b 0a 0a 66 |killcursor();..f| 00006d00 6f 72 28 77 61 6c 6c 5f 6e 75 6d 62 65 72 3d 31 |or(wall_number=1| 00006d10 2c 79 3d 30 3b 79 3c 32 35 36 3b 79 2b 3d 57 41 |,y=0;y<256;y+=WA| 00006d20 4c 4c 5f 48 45 49 47 48 54 29 66 6f 72 28 78 3d |LL_HEIGHT)for(x=| 00006d30 30 3b 78 3c 33 32 30 3b 78 2b 3d 57 41 4c 4c 5f |0;x<320;x+=WALL_| 00006d40 57 49 44 54 48 2c 77 61 6c 6c 5f 6e 75 6d 62 65 |WIDTH,wall_numbe| 00006d50 72 2b 2b 29 0a 7b 0a 6f 75 72 6c 69 62 5f 62 69 |r++).{.ourlib_bi| 00006d60 74 6d 61 70 5f 67 72 61 62 28 78 2c 79 2c 78 2b |tmap_grab(x,y,x+| 00006d70 36 33 2c 79 2b 36 33 2c 26 6f 62 6a 67 72 61 70 |63,y+63,&objgrap| 00006d80 68 69 63 73 5b 77 61 6c 6c 5f 6e 75 6d 62 65 72 |hics[wall_number| 00006d90 5d 5b 30 5d 2c 73 63 72 65 65 6e 5f 61 64 64 72 |][0],screen_addr| 00006da0 65 73 73 29 3b 0a 69 66 28 77 61 6c 6c 5f 6e 75 |ess);.if(wall_nu| 00006db0 6d 62 65 72 3e 57 41 4c 4c 5f 4e 55 4d 42 45 52 |mber>WALL_NUMBER| 00006dc0 29 62 72 65 61 6b 3b 0a 7d 0a 0a 0a 7d 0a 0a 2f |)break;.}...}../| 00006dd0 2a 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 |* this function | 00006de0 6c 6f 61 64 73 20 69 6e 20 74 68 65 20 64 61 74 |loads in the dat| 00006df0 61 20 66 72 6f 6d 20 6f 75 72 20 77 6f 72 6c 64 |a from our world| 00006e00 20 74 65 78 74 20 66 69 6c 65 20 61 6e 64 20 73 | text file and s| 00006e10 74 6f 72 65 73 20 69 74 20 69 6e 20 74 68 65 20 |tores it in the | 00006e20 77 6f 72 6c 64 5b 5d 5b 5d 20 61 72 72 61 79 20 |world[][] array | 00006e30 2a 2f 0a 0a 76 6f 69 64 20 61 75 61 5f 77 6f 72 |*/..void aua_wor| 00006e40 6c 64 28 76 6f 69 64 29 0a 7b 0a 0a 46 49 4c 45 |ld(void).{..FILE| 00006e50 20 2a 77 6f 72 6c 64 5f 66 69 6c 65 3b 20 2f 2a | *world_file; /*| 00006e60 20 77 65 20 6e 65 65 64 20 61 20 66 69 6c 65 20 | we need a file | 00006e70 70 6f 69 6e 74 65 72 20 61 73 20 77 65 20 77 69 |pointer as we wi| 00006e80 6c 6c 20 62 65 20 6c 6f 61 64 69 6e 67 20 69 6e |ll be loading in| 00006e90 20 74 65 78 74 20 2a 2f 0a 0a 69 6e 74 20 72 6f | text */..int ro| 00006ea0 77 2c 20 2f 2a 20 74 68 69 73 20 77 69 6c 6c 20 |w, /* this will | 00006eb0 62 65 20 75 73 65 64 20 74 6f 20 69 6e 64 65 78 |be used to index| 00006ec0 20 74 68 65 20 77 6f 72 6c 64 5b 5d 5b 5d 20 61 | the world[][] a| 00006ed0 72 72 61 79 20 2a 2f 0a 20 20 20 20 63 6f 6c 75 |rray */. colu| 00006ee0 6d 6e 2c 63 6f 75 6e 74 65 72 3d 30 3b 20 2f 2a |mn,counter=0; /*| 00006ef0 20 74 68 69 73 20 77 69 6c 6c 20 62 65 20 75 73 | this will be us| 00006f00 65 64 20 74 6f 20 69 6e 64 65 78 20 74 68 65 20 |ed to index the | 00006f10 77 6f 72 6c 64 5b 5d 5b 5d 20 61 72 72 61 79 20 |world[][] array | 00006f20 2a 2f 0a 0a 63 68 61 72 20 63 68 3b 20 2f 2a 20 |*/..char ch; /* | 00006f30 74 68 69 73 20 69 73 20 75 73 65 64 20 74 6f 20 |this is used to | 00006f40 73 74 6f 72 65 20 65 61 63 68 20 6e 75 6d 62 65 |store each numbe| 00006f50 72 20 61 73 20 69 74 20 69 73 20 6c 6f 61 64 65 |r as it is loade| 00006f60 64 20 69 6e 20 2a 2f 0a 0a 2f 2a 20 6f 70 65 6e |d in */../* open| 00006f70 20 74 68 65 20 77 6f 72 6c 64 20 66 69 6c 65 2c | the world file,| 00006f80 20 69 66 20 69 74 20 69 73 20 6e 6f 74 20 74 68 | if it is not th| 00006f90 65 72 65 20 74 68 65 6e 20 65 78 69 74 20 74 68 |ere then exit th| 00006fa0 65 20 70 72 6f 67 72 61 6d 20 2a 2f 0a 0a 69 66 |e program */..if| 00006fb0 28 21 28 77 6f 72 6c 64 5f 66 69 6c 65 3d 66 6f |(!(world_file=fo| 00006fc0 70 65 6e 28 22 3c 41 55 41 52 61 79 24 44 69 72 |pen("<AUARay$Dir| 00006fd0 3e 2e 77 6f 72 6c 64 22 2c 22 72 22 29 29 29 65 |>.world","r")))e| 00006fe0 78 69 74 28 31 29 3b 0a 0a 2f 2a 20 74 68 69 73 |xit(1);../* this| 00006ff0 20 70 72 6f 67 72 61 6d 20 6c 6f 61 64 73 20 69 | program loads i| 00007000 6e 20 74 68 65 20 64 61 74 61 20 66 72 6f 6d 20 |n the data from | 00007010 74 68 65 20 77 6f 72 6c 64 20 66 69 6c 65 2c 20 |the world file, | 00007020 72 6f 77 20 62 79 20 72 6f 77 2c 20 63 6f 6c 75 |row by row, colu| 00007030 6d 6e 20 62 79 20 63 6f 6c 75 6d 6e 20 75 73 69 |mn by column usi| 00007040 6e 67 20 74 68 65 20 67 65 74 63 28 29 20 41 4e |ng the getc() AN| 00007050 53 49 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 0a |SI function */..| 00007060 66 6f 72 28 72 6f 77 3d 30 3b 72 6f 77 3c 57 4f |for(row=0;row<WO| 00007070 52 4c 44 5f 48 45 49 47 48 54 3b 72 6f 77 2b 2b |RLD_HEIGHT;row++| 00007080 29 0a 7b 0a 66 6f 72 28 63 6f 6c 75 6d 6e 3d 30 |).{.for(column=0| 00007090 3b 63 6f 6c 75 6d 6e 3c 57 4f 52 4c 44 5f 57 49 |;column<WORLD_WI| 000070a0 44 54 48 3b 63 6f 6c 75 6d 6e 2b 2b 29 0a 7b 0a |DTH;column++).{.| 000070b0 77 68 69 6c 65 28 28 63 68 3d 67 65 74 63 28 77 |while((ch=getc(w| 000070c0 6f 72 6c 64 5f 66 69 6c 65 29 29 3d 3d 31 30 29 |orld_file))==10)| 000070d0 7b 7d 20 2f 2a 20 74 68 69 73 20 66 69 6c 74 65 |{} /* this filte| 000070e0 72 73 20 6f 75 74 20 61 6e 79 20 6d 65 73 73 2c |rs out any mess,| 000070f0 20 74 68 6f 75 67 68 20 6e 6f 74 20 6f 66 74 65 | though not ofte| 00007100 6e 20 75 73 65 64 21 20 2a 2f 0a 0a 69 66 28 63 |n used! */..if(c| 00007110 68 3d 3d 27 20 27 29 63 68 3d 30 3b 20 2f 2a 74 |h==' ')ch=0; /*t| 00007120 68 69 73 20 65 6e 73 75 72 65 73 20 74 68 65 20 |his ensures the | 00007130 63 6f 72 72 65 63 74 20 76 61 6c 75 65 20 69 73 |correct value is| 00007140 20 73 74 6f 72 65 64 2c 20 69 66 20 74 68 65 72 | stored, if ther| 00007150 65 20 69 73 20 61 20 67 61 70 20 69 6e 20 74 68 |e is a gap in th| 00007160 65 20 66 69 6c 65 2c 20 74 68 69 73 20 6d 65 61 |e file, this mea| 00007170 6e 73 20 61 20 73 70 61 63 65 20 69 6e 20 74 68 |ns a space in th| 00007180 65 20 77 6f 72 6c 64 2c 20 61 20 7a 65 72 6f 20 |e world, a zero | 00007190 2a 2f 0a 65 6c 73 65 20 63 68 3d 63 68 2d 27 30 |*/.else ch=ch-'0| 000071a0 27 3b 0a 0a 2f 2a 20 74 68 69 73 20 6e 65 77 20 |';../* this new | 000071b0 6c 69 6e 65 20 77 69 6c 6c 20 28 73 68 6f 75 6c |line will (shoul| 000071c0 64 21 29 20 63 6f 6e 76 65 72 74 20 6c 65 74 74 |d!) convert lett| 000071d0 65 72 73 20 69 6e 74 6f 20 74 68 65 69 72 20 61 |ers into their a| 000071e0 70 70 72 6f 70 72 69 61 74 65 20 6e 75 6d 62 65 |ppropriate numbe| 000071f0 72 20 2a 2f 0a 0a 69 66 28 63 68 3e 31 36 29 63 |r */..if(ch>16)c| 00007200 68 2d 3d 36 3b 0a 0a 77 6f 72 6c 64 5b 28 57 4f |h-=6;..world[(WO| 00007210 52 4c 44 5f 48 45 49 47 48 54 2d 31 29 2d 72 6f |RLD_HEIGHT-1)-ro| 00007220 77 5d 5b 63 6f 6c 75 6d 6e 5d 3d 63 68 3b 20 2f |w][column]=ch; /| 00007230 2a 20 74 68 69 73 20 66 69 6e 61 6c 6c 79 20 73 |* this finally s| 00007240 74 6f 72 65 73 20 74 68 65 20 76 61 6c 75 65 20 |tores the value | 00007250 69 6e 20 74 68 65 20 63 6f 72 72 65 63 74 20 70 |in the correct p| 00007260 6f 73 69 74 69 6f 6e 20 2a 2f 0a 0a 2f 2a 70 72 |osition */../*pr| 00007270 69 6e 74 66 28 22 25 64 22 2c 63 68 29 3b 20 75 |intf("%d",ch); u| 00007280 6e 63 6f 6d 6d 65 6e 74 20 74 68 69 73 20 6c 69 |ncomment this li| 00007290 6e 65 20 74 6f 20 73 65 65 20 74 68 65 20 77 6f |ne to see the wo| 000072a0 72 6c 64 20 64 61 74 61 20 6c 6f 61 64 65 64 20 |rld data loaded | 000072b0 69 6e 20 2a 2f 0a 7d 0a 2f 2a 70 72 69 6e 74 66 |in */.}./*printf| 000072c0 28 22 5c 6e 22 29 3b 20 75 6e 63 6f 6d 6d 65 6e |("\n"); uncommen| 000072d0 74 20 74 68 69 73 20 6c 69 6e 65 20 74 6f 20 73 |t this line to s| 000072e0 65 65 20 74 68 65 20 77 6f 72 6c 64 20 64 61 74 |ee the world dat| 000072f0 61 20 6c 6f 61 64 65 64 20 69 6e 20 2a 2f 0a 7d |a loaded in */.}| 00007300 0a 0a 2f 2a 20 77 68 65 6e 20 61 6c 6c 20 69 73 |../* when all is| 00007310 20 64 6f 6e 65 2c 20 63 6c 6f 73 65 20 74 68 65 | done, close the| 00007320 20 66 69 6c 65 20 2a 2f 0a 66 63 6c 6f 73 65 28 | file */.fclose(| 00007330 77 6f 72 6c 64 5f 66 69 6c 65 29 3b 0a 0a 2f 2a |world_file);../*| 00007340 20 6e 65 77 20 70 61 72 74 20 74 6f 20 6c 6f 61 | new part to loa| 00007350 64 20 69 6e 20 6f 62 6a 65 63 74 20 64 61 74 61 |d in object data| 00007360 2c 20 73 65 65 20 61 62 6f 76 65 20 66 6f 72 20 |, see above for | 00007370 63 6f 6d 6d 65 6e 74 73 20 2a 2f 0a 0a 69 66 28 |comments */..if(| 00007380 21 28 77 6f 72 6c 64 5f 66 69 6c 65 3d 66 6f 70 |!(world_file=fop| 00007390 65 6e 28 22 3c 41 55 41 52 61 79 24 44 69 72 3e |en("<AUARay$Dir>| 000073a0 2e 6f 62 6a 77 6f 72 6c 64 22 2c 22 72 22 29 29 |.objworld","r"))| 000073b0 29 20 65 78 69 74 28 31 29 3b 0a 66 6f 72 28 72 |) exit(1);.for(r| 000073c0 6f 77 3d 30 3b 72 6f 77 3c 57 4f 52 4c 44 5f 48 |ow=0;row<WORLD_H| 000073d0 45 49 47 48 54 3b 72 6f 77 2b 2b 29 0a 7b 0a 20 |EIGHT;row++).{. | 000073e0 20 66 6f 72 28 63 6f 6c 75 6d 6e 3d 30 3b 63 6f | for(column=0;co| 000073f0 6c 75 6d 6e 3c 57 4f 52 4c 44 5f 57 49 44 54 48 |lumn<WORLD_WIDTH| 00007400 3b 63 6f 6c 75 6d 6e 2b 2b 29 0a 20 20 7b 0a 20 |;column++). {. | 00007410 20 77 68 69 6c 65 28 28 63 68 3d 67 65 74 63 28 | while((ch=getc(| 00007420 77 6f 72 6c 64 5f 66 69 6c 65 29 29 3d 3d 31 30 |world_file))==10| 00007430 29 7b 7d 0a 20 20 69 66 28 63 68 3d 3d 27 20 27 |){}. if(ch==' '| 00007440 29 63 68 3d 30 3b 0a 20 20 65 6c 73 65 20 63 68 |)ch=0;. else ch| 00007450 3d 63 68 2d 27 30 27 3b 0a 20 20 69 66 28 63 68 |=ch-'0';. if(ch| 00007460 3e 31 36 29 63 68 2d 3d 37 3b 0a 0a 6f 62 6a 65 |>16)ch-=7;..obje| 00007470 63 74 73 5b 28 57 4f 52 4c 44 5f 48 45 49 47 48 |cts[(WORLD_HEIGH| 00007480 54 2d 31 29 2d 72 6f 77 5d 5b 63 6f 6c 75 6d 6e |T-1)-row][column| 00007490 5d 3d 63 68 3b 0a 0a 20 20 7d 0a 7d 0a 0a 66 63 |]=ch;.. }.}..fc| 000074a0 6c 6f 73 65 28 77 6f 72 6c 64 5f 66 69 6c 65 29 |lose(world_file)| 000074b0 3b 0a 0a 7d 0a 0a 0a 2f 2a 20 4e 45 57 45 52 20 |;..}.../* NEWER | 000074c0 4d 41 49 4e 20 66 75 6e 63 74 69 6f 6e 20 2e 0a |MAIN function ..| 000074d0 0a 41 6c 6c 20 63 68 61 6e 67 65 73 20 61 72 65 |.All changes are| 000074e0 20 63 6f 6d 6d 65 6e 74 65 64 20 2a 2f 0a 0a 76 | commented */..v| 000074f0 6f 69 64 20 6d 61 69 6e 28 69 6e 74 20 61 72 67 |oid main(int arg| 00007500 63 2c 63 68 61 72 20 2a 61 72 67 76 5b 5d 29 0a |c,char *argv[]).| 00007510 7b 0a 20 20 69 6e 74 20 76 69 65 77 5f 78 2c 20 |{. int view_x, | 00007520 2f 2a 20 74 68 69 73 20 68 6f 6c 64 73 20 74 68 |/* this holds th| 00007530 65 20 76 69 65 77 69 6e 67 20 78 20 63 6f 6f 72 |e viewing x coor| 00007540 64 69 6e 61 74 65 20 2a 2f 0a 20 20 20 20 20 20 |dinate */. | 00007550 76 69 65 77 5f 79 2c 20 2f 2a 20 74 68 69 73 20 |view_y, /* this | 00007560 68 6f 6c 64 73 20 74 68 65 20 76 69 65 77 69 6e |holds the viewin| 00007570 67 20 79 20 63 6f 6f 72 64 69 6e 61 74 65 20 2a |g y coordinate *| 00007580 2f 0a 20 20 20 20 20 20 76 69 65 77 5f 61 6e 67 |/. view_ang| 00007590 6c 65 3b 20 2f 2a 20 74 68 69 73 20 68 6f 6c 64 |le; /* this hold| 000075a0 73 20 74 68 65 20 76 69 65 77 69 6e 67 20 61 6e |s the viewing an| 000075b0 67 6c 65 20 69 6e 20 66 69 78 65 64 20 75 6e 69 |gle in fixed uni| 000075c0 74 73 20 30 2d 31 39 32 30 20 2a 2f 0a 0a 20 20 |ts 0-1920 */.. | 000075d0 69 6e 74 0a 20 20 20 20 20 20 64 6f 6e 65 3d 30 |int. done=0| 000075e0 2c 20 20 20 20 2f 2a 20 66 6c 61 67 20 74 6f 20 |, /* flag to | 000075f0 69 6e 64 69 63 61 74 65 20 69 66 20 74 68 65 20 |indicate if the | 00007600 75 73 65 72 20 77 61 6e 74 73 20 74 6f 20 71 75 |user wants to qu| 00007610 69 74 20 2a 2f 0a 20 20 20 20 20 20 64 78 2c 20 |it */. dx, | 00007620 20 20 20 20 20 20 20 2f 2a 20 6d 6f 76 65 6d 65 | /* moveme| 00007630 6e 74 20 76 61 72 69 61 62 6c 65 73 20 66 6f 72 |nt variables for| 00007640 20 74 68 65 20 76 69 65 77 65 72 20 2a 2f 0a 20 | the viewer */. | 00007650 20 20 20 20 20 64 79 2c 0a 20 20 20 20 20 20 79 | dy,. y| 00007660 5f 63 65 6c 6c 2c 20 20 20 20 2f 2a 20 74 68 65 |_cell, /* the| 00007670 73 65 20 4e 45 57 20 76 61 72 69 61 62 6c 65 73 |se NEW variables| 00007680 20 61 72 65 20 75 73 65 64 20 74 6f 20 73 74 6f | are used to sto| 00007690 72 65 20 74 68 65 20 70 6c 61 79 65 72 2f 76 69 |re the player/vi| 000076a0 65 77 65 72 2a 2f 0a 20 20 20 20 20 20 78 5f 63 |ewer*/. x_c| 000076b0 65 6c 6c 2c 20 20 20 20 2f 2a 20 77 6f 72 6c 64 |ell, /* world| 000076c0 20 70 6f 73 69 74 69 6f 6e 73 2c 20 66 6f 72 20 | positions, for | 000076d0 63 61 6c 63 75 6c 61 74 69 6e 67 20 76 69 65 77 |calculating view| 000076e0 65 72 20 68 69 74 74 69 6e 67 20 77 61 6c 6c 73 |er hitting walls| 000076f0 20 2a 2f 0a 20 20 20 20 20 20 79 5f 73 75 62 5f | */. y_sub_| 00007700 63 65 6c 6c 2c 0a 20 20 20 20 20 20 78 5f 73 75 |cell,. x_su| 00007710 62 5f 63 65 6c 6c 2c 0a 20 20 20 20 20 20 74 69 |b_cell,. ti| 00007720 6d 65 5f 73 74 61 72 74 2c 0a 20 20 20 20 20 20 |me_start,. | 00007730 74 69 6d 65 5f 66 69 6e 69 73 68 2c 20 2f 2a 20 |time_finish, /* | 00007740 54 68 65 73 65 20 6c 61 73 74 20 66 65 77 20 76 |These last few v| 00007750 61 72 69 61 62 6c 65 73 20 61 72 65 20 75 73 65 |ariables are use| 00007760 64 20 74 6f 20 77 6f 72 6b 20 6f 75 74 20 2a 2f |d to work out */| 00007770 0a 20 20 20 20 20 20 66 72 61 6d 65 73 3d 30 2c |. frames=0,| 00007780 20 20 20 20 2f 2a 20 74 68 65 20 66 72 61 6d 65 | /* the frame| 00007790 73 20 70 65 72 20 73 65 63 2e 20 6f 66 20 74 68 |s per sec. of th| 000077a0 65 20 73 79 73 74 65 6d 2c 20 73 6c 6f 77 20 66 |e system, slow f| 000077b0 6f 72 20 6e 6f 77 21 20 2a 2f 0a 20 20 20 20 20 |or now! */. | 000077c0 20 64 6f 6f 72 5f 78 2c 0a 20 20 20 20 20 20 64 | door_x,. d| 000077d0 6f 6f 72 5f 79 3b 20 20 20 20 20 20 2f 2a 20 54 |oor_y; /* T| 000077e0 68 65 73 65 20 6e 65 77 20 76 61 72 69 61 62 6c |hese new variabl| 000077f0 65 73 20 77 69 6c 6c 20 62 65 20 75 73 65 64 20 |es will be used | 00007800 66 6f 72 20 64 6f 6f 72 20 74 68 69 6e 67 73 20 |for door things | 00007810 2a 2f 0a 0a 2f 2a 20 4e 65 77 20 4f 62 6a 65 63 |*/../* New Objec| 00007820 74 20 43 6f 64 65 20 2a 2a 2a 2a 2a 2a 2a 2a 2a |t Code *********| 00007830 2a 2a 2a 2a 2a 2a 2a 2a 20 41 64 64 65 64 20 41 |******** Added A| 00007840 72 74 69 63 6c 65 20 35 20 2d 20 67 6f 6f 64 20 |rticle 5 - good | 00007850 73 74 75 66 66 20 21 20 2a 2f 0a 69 6e 74 20 6f |stuff ! */.int o| 00007860 62 6a 65 63 74 5f 78 2c 6f 62 6a 65 63 74 5f 79 |bject_x,object_y| 00007870 2c 74 72 61 6e 73 5f 78 2c 74 72 61 6e 73 5f 7a |,trans_x,trans_z| 00007880 2c 73 63 72 65 65 6e 5f 78 2c 73 63 72 65 65 6e |,screen_x,screen| 00007890 5f 79 31 2c 73 63 72 65 65 6e 5f 79 32 2c 74 65 |_y1,screen_y2,te| 000078a0 6d 70 5f 31 2c 63 6f 75 6e 74 65 72 2c 73 63 61 |mp_1,counter,sca| 000078b0 6c 65 2c 76 61 72 69 61 62 6c 65 73 5b 37 5d 2c |le,variables[7],| 000078c0 69 6e 64 65 78 2c 69 6e 63 72 65 6d 65 6e 74 2c |index,increment,| 000078d0 67 72 69 64 5f 78 2c 67 72 69 64 5f 79 2c 6f 62 |grid_x,grid_y,ob| 000078e0 6a 65 63 74 5f 74 79 70 65 2c 73 74 61 72 74 5f |ject_type,start_| 000078f0 78 2c 73 74 61 72 74 5f 79 2c 73 74 6f 70 5f 78 |x,start_y,stop_x| 00007900 2c 73 74 6f 70 5f 79 2c 6d 6f 76 65 5f 78 2c 6d |,stop_y,move_x,m| 00007910 6f 76 65 5f 79 2c 74 76 69 65 77 5f 78 2c 74 76 |ove_y,tview_x,tv| 00007920 69 65 77 5f 79 2c 74 76 69 65 77 5f 61 6e 67 6c |iew_y,tview_angl| 00007930 65 3b 0a 2f 2a 20 4e 65 77 20 4f 62 6a 65 63 74 |e;./* New Object| 00007940 20 43 6f 64 65 20 56 61 72 69 61 62 6c 65 73 20 | Code Variables | 00007950 4f 76 65 72 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a |Over ***********| 00007960 2a 2a 2a 2a 20 53 65 65 20 4c 61 74 65 72 20 69 |**** See Later i| 00007970 6e 20 4d 61 69 6e 28 29 20 2a 2f 0a 2f 2a 20 4e |n Main() */./* N| 00007980 45 57 20 64 65 6d 6f 20 66 69 6c 65 20 77 68 69 |EW demo file whi| 00007990 63 68 20 63 61 6e 20 6c 6f 61 64 2f 73 74 6f 72 |ch can load/stor| 000079a0 65 20 64 65 6d 6f 20 69 6e 66 6f 72 6d 61 74 69 |e demo informati| 000079b0 6f 6e 20 66 6f 72 20 61 20 77 61 6c 6b 74 68 72 |on for a walkthr| 000079c0 6f 75 67 68 2a 2f 0a 0a 46 49 4c 45 20 2a 64 65 |ough*/..FILE *de| 000079d0 6d 6f 5f 66 69 6c 65 3b 0a 0a 2f 2a 20 4e 45 57 |mo_file;../* NEW| 000079e0 20 73 79 73 74 65 6d 20 6f 66 20 70 61 73 73 69 | system of passi| 000079f0 6e 67 2c 20 77 65 20 75 73 65 20 74 68 65 20 73 |ng, we use the s| 00007a00 74 61 6e 64 61 72 64 20 61 72 67 63 20 61 6e 64 |tandard argc and| 00007a10 20 61 72 67 76 20 74 6f 20 73 75 70 70 6c 79 20 | argv to supply | 00007a20 70 61 72 61 6d 65 74 65 72 73 20 74 6f 20 74 68 |parameters to th| 00007a30 65 20 65 6e 67 69 6e 65 2e 20 46 49 52 53 54 20 |e engine. FIRST | 00007a40 77 65 20 6d 75 73 74 20 65 78 74 72 61 63 74 20 |we must extract | 00007a50 74 68 65 6d 3a 2a 2f 0a 0a 2f 2a 20 63 68 65 63 |them:*/../* chec| 00007a60 6b 20 74 68 61 74 20 63 6f 72 72 65 63 74 20 6e |k that correct n| 00007a70 75 6d 62 65 72 20 6f 66 20 70 61 72 61 6d 65 74 |umber of paramet| 00007a80 65 72 73 20 68 61 76 65 20 62 65 65 6e 20 70 61 |ers have been pa| 00007a90 73 73 65 64 20 2a 2f 0a 0a 69 66 28 61 72 67 63 |ssed */..if(argc| 00007aa0 21 3d 31 34 29 0a 7b 0a 2f 2a 20 71 75 69 74 20 |!=14).{./* quit | 00007ab0 69 66 20 6e 6f 74 20 2a 2f 0a 70 72 69 6e 74 66 |if not */.printf| 00007ac0 28 22 45 72 72 6f 72 3a 20 49 6e 63 6f 72 72 65 |("Error: Incorre| 00007ad0 63 74 20 6e 75 6d 62 65 72 20 6f 66 20 70 61 72 |ct number of par| 00007ae0 61 6d 65 74 65 72 73 20 70 61 73 73 65 64 2e 20 |ameters passed. | 00007af0 5f 45 78 69 74 69 6e 67 5c 6e 22 29 3b 20 65 78 |_Exiting\n"); ex| 00007b00 69 74 28 31 29 3b 0a 2f 2a 20 22 62 65 65 70 22 |it(1);./* "beep"| 00007b10 20 28 6f 6e 20 6d 6f 73 74 20 6d 61 63 68 69 6e | (on most machin| 00007b20 65 73 29 2a 2f 20 70 75 74 63 68 61 72 28 27 5c |es)*/ putchar('\| 00007b30 61 27 29 3b 0a 7d 0a 2f 2a 20 75 73 65 20 61 74 |a');.}./* use at| 00007b40 6f 69 20 74 6f 20 67 65 74 20 69 74 20 72 69 67 |oi to get it rig| 00007b50 68 74 20 2a 2f 0a 2f 2a 20 49 4e 50 55 54 20 41 |ht */./* INPUT A| 00007b60 4c 4c 20 56 41 4c 55 45 53 20 46 52 4f 4d 20 43 |LL VALUES FROM C| 00007b70 4f 4d 4d 41 4e 44 20 4c 49 4e 45 20 75 73 69 6e |OMMAND LINE usin| 00007b80 67 20 41 54 4f 49 20 61 6e 64 20 74 68 65 6e 20 |g ATOI and then | 00007b90 77 6f 72 6b 20 6f 75 74 20 6e 65 65 64 65 64 2a |work out needed*| 00007ba0 2f 0a 2f 2a 20 61 6e 67 6c 65 20 76 61 6c 75 65 |/./* angle value| 00007bb0 73 20 66 6f 72 20 74 68 65 20 72 61 79 20 63 61 |s for the ray ca| 00007bc0 73 74 69 6e 67 20 65 6e 67 69 6e 65 2e 20 2a 2f |sting engine. */| 00007bd0 0a 76 69 65 77 5f 78 3d 61 74 6f 69 28 61 72 67 |.view_x=atoi(arg| 00007be0 76 5b 31 5d 29 3b 0a 76 69 65 77 5f 79 3d 61 74 |v[1]);.view_y=at| 00007bf0 6f 69 28 61 72 67 76 5b 32 5d 29 3b 0a 76 69 65 |oi(argv[2]);.vie| 00007c00 77 5f 61 6e 67 6c 65 3d 61 74 6f 69 28 61 72 67 |w_angle=atoi(arg| 00007c10 76 5b 33 5d 29 3b 0a 53 43 52 45 45 4e 5f 57 49 |v[3]);.SCREEN_WI| 00007c20 44 54 48 3d 61 74 6f 69 28 61 72 67 76 5b 34 5d |DTH=atoi(argv[4]| 00007c30 29 3b 0a 53 43 52 45 45 4e 5f 48 45 49 47 48 54 |);.SCREEN_HEIGHT| 00007c40 3d 61 74 6f 69 28 61 72 67 76 5b 35 5d 29 3b 0a |=atoi(argv[5]);.| 00007c50 41 4e 47 4c 45 5f 33 36 30 3d 61 74 6f 69 28 61 |ANGLE_360=atoi(a| 00007c60 72 67 76 5b 36 5d 29 3b 0a 41 4e 47 4c 45 5f 31 |rgv[6]);.ANGLE_1| 00007c70 38 30 3d 41 4e 47 4c 45 5f 33 36 30 2f 32 3b 41 |80=ANGLE_360/2;A| 00007c80 4e 47 4c 45 5f 39 30 3d 41 4e 47 4c 45 5f 31 38 |NGLE_90=ANGLE_18| 00007c90 30 2f 32 3b 0a 41 4e 47 4c 45 5f 36 3d 61 74 6f |0/2;.ANGLE_6=ato| 00007ca0 69 28 61 72 67 76 5b 39 5d 29 3b 0a 41 4e 47 4c |i(argv[9]);.ANGL| 00007cb0 45 5f 33 30 3d 28 69 6e 74 29 41 4e 47 4c 45 5f |E_30=(int)ANGLE_| 00007cc0 39 30 2f 33 3b 0a 41 4e 47 4c 45 5f 30 3d 30 3b |90/3;.ANGLE_0=0;| 00007cd0 0a 41 4e 47 4c 45 5f 32 37 30 3d 41 4e 47 4c 45 |.ANGLE_270=ANGLE| 00007ce0 5f 39 30 2a 33 3b 0a 56 45 52 54 49 43 41 4c 5f |_90*3;.VERTICAL_| 00007cf0 53 43 41 4c 45 3d 61 74 6f 69 28 61 72 67 76 5b |SCALE=atoi(argv[| 00007d00 37 5d 29 3b 0a 53 54 45 50 5f 4c 45 4e 47 54 48 |7]);.STEP_LENGTH| 00007d10 3d 61 74 6f 69 28 61 72 67 76 5b 38 5d 29 3b 0a |=atoi(argv[8]);.| 00007d20 56 49 45 57 56 41 52 3d 61 74 6f 69 28 61 72 67 |VIEWVAR=atoi(arg| 00007d30 76 5b 31 30 5d 29 3b 0a 56 49 45 57 56 41 52 54 |v[10]);.VIEWVART| 00007d40 3d 61 74 6f 69 28 61 72 67 76 5b 31 31 5d 29 3b |=atoi(argv[11]);| 00007d50 0a 44 45 4d 4f 5f 52 45 41 44 3d 61 74 6f 69 28 |.DEMO_READ=atoi(| 00007d60 61 72 67 76 5b 31 32 5d 29 3b 0a 44 45 4d 4f 5f |argv[12]);.DEMO_| 00007d70 57 52 49 54 45 3d 61 74 6f 69 28 61 72 67 76 5b |WRITE=atoi(argv[| 00007d80 31 33 5d 29 3b 0a 0a 2f 2a 20 4e 6f 77 20 77 65 |13]);../* Now we| 00007d90 20 70 72 69 6e 74 20 74 68 65 20 69 6e 66 6f 72 | print the infor| 00007da0 6d 61 74 69 6f 6e 20 6a 75 73 74 20 66 6f 72 20 |mation just for | 00007db0 74 68 65 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 |the information | 00007dc0 6f 66 20 74 68 65 20 75 73 65 72 20 2a 2f 0a 70 |of the user */.p| 00007dd0 72 69 6e 74 66 28 22 5f 73 79 73 74 65 6d 20 76 |rintf("_system v| 00007de0 61 72 69 61 62 6c 65 73 3a 5c 6e 76 69 65 77 5f |ariables:\nview_| 00007df0 78 3a 20 25 64 20 76 69 65 77 5f 79 3a 20 25 64 |x: %d view_y: %d| 00007e00 20 76 69 65 77 5f 61 6e 67 6c 65 3a 20 25 64 5c | view_angle: %d\| 00007e10 6e 73 63 72 65 65 6e 5f 77 69 64 74 68 3a 20 25 |nscreen_width: %| 00007e20 64 20 73 63 72 65 65 6e 5f 68 65 69 67 68 74 3a |d screen_height:| 00007e30 20 25 64 20 61 6e 67 6c 65 5f 33 36 30 3a 20 25 | %d angle_360: %| 00007e40 64 5c 6e 76 65 72 74 69 63 61 6c 5f 73 63 61 6c |d\nvertical_scal| 00007e50 65 3a 20 25 64 20 73 74 65 70 5f 6c 65 6e 67 74 |e: %d step_lengt| 00007e60 68 3a 20 25 64 20 76 69 65 77 76 61 72 73 3a 20 |h: %d viewvars: | 00007e70 25 64 20 25 64 5c 6e 64 65 6d 6f 5f 72 65 61 64 |%d %d\ndemo_read| 00007e80 3a 20 25 64 20 64 65 6d 6f 5f 77 72 69 74 65 3a |: %d demo_write:| 00007e90 20 25 64 5c 6e 5c 6e 22 2c 76 69 65 77 5f 78 2c | %d\n\n",view_x,| 00007ea0 76 69 65 77 5f 79 2c 76 69 65 77 5f 61 6e 67 6c |view_y,view_angl| 00007eb0 65 2c 53 43 52 45 45 4e 5f 57 49 44 54 48 2c 53 |e,SCREEN_WIDTH,S| 00007ec0 43 52 45 45 4e 5f 48 45 49 47 48 54 2c 41 4e 47 |CREEN_HEIGHT,ANG| 00007ed0 4c 45 5f 33 36 30 2c 56 45 52 54 49 43 41 4c 5f |LE_360,VERTICAL_| 00007ee0 53 43 41 4c 45 2c 53 54 45 50 5f 4c 45 4e 47 54 |SCALE,STEP_LENGT| 00007ef0 48 2c 56 49 45 57 56 41 52 2c 56 49 45 57 56 41 |H,VIEWVAR,VIEWVA| 00007f00 52 54 2c 44 45 4d 4f 5f 52 45 41 44 2c 44 45 4d |RT,DEMO_READ,DEM| 00007f10 4f 5f 57 52 49 54 45 29 3b 0a 0a 0a 69 66 28 44 |O_WRITE);...if(D| 00007f20 45 4d 4f 5f 57 52 49 54 45 3d 3d 31 29 7b 0a 69 |EMO_WRITE==1){.i| 00007f30 66 28 21 28 64 65 6d 6f 5f 66 69 6c 65 3d 66 6f |f(!(demo_file=fo| 00007f40 70 65 6e 28 22 3c 41 55 41 52 61 79 24 44 69 72 |pen("<AUARay$Dir| 00007f50 3e 2e 64 65 6d 6f 22 2c 22 77 22 29 29 29 65 78 |>.demo","w")))ex| 00007f60 69 74 28 31 29 3b 0a 70 72 69 6e 74 66 28 22 77 |it(1);.printf("w| 00007f70 72 69 74 69 6e 67 20 74 6f 20 66 69 6c 65 5c 6e |riting to file\n| 00007f80 22 29 3b 0a 7d 0a 65 6c 73 65 20 69 66 28 44 45 |");.}.else if(DE| 00007f90 4d 4f 5f 52 45 41 44 3d 3d 31 29 0a 7b 0a 20 20 |MO_READ==1).{. | 00007fa0 69 66 28 21 28 64 65 6d 6f 5f 66 69 6c 65 3d 66 |if(!(demo_file=f| 00007fb0 6f 70 65 6e 28 22 3c 41 55 41 52 61 79 24 44 69 |open("<AUARay$Di| 00007fc0 72 3e 2e 64 65 6d 6f 22 2c 22 72 22 29 29 29 65 |r>.demo","r")))e| 00007fd0 78 69 74 28 31 29 3b 0a 20 20 70 72 69 6e 74 66 |xit(1);. printf| 00007fe0 28 22 72 65 61 64 69 6e 67 20 64 65 6d 6f 20 66 |("reading demo f| 00007ff0 69 6c 65 5c 6e 22 29 3b 0a 7d 0a 0a 2f 2a 20 44 |ile\n");.}../* D| 00008000 4f 4e 45 2e 20 4e 6f 77 20 63 6f 6e 74 69 6e 75 |ONE. Now continu| 00008010 65 20 61 73 20 6e 6f 72 6d 61 6c 20 77 69 74 68 |e as normal with| 00008020 20 74 68 65 20 70 72 6f 67 72 61 6d 20 2a 2f 0a | the program */.| 00008030 2f 2a 20 49 74 20 69 73 20 68 65 72 65 20 74 68 |/* It is here th| 00008040 61 74 20 77 65 20 73 65 65 20 69 66 20 74 68 65 |at we see if the| 00008050 20 44 45 4d 4f 46 4c 41 47 20 69 73 20 73 65 74 | DEMOFLAG is set| 00008060 20 74 6f 20 72 65 61 64 2f 77 72 69 74 65 20 64 | to read/write d| 00008070 65 6d 6f 73 20 2a 2f 0a 0a 0a 0a 2f 2a 20 6e 6f |emos */..../* no| 00008080 77 20 77 65 20 63 61 6c 6c 20 61 75 61 5f 77 6f |w we call aua_wo| 00008090 72 6c 64 20 74 6f 20 6c 6f 61 64 20 69 6e 20 74 |rld to load in t| 000080a0 68 65 20 74 65 78 74 20 77 6f 72 6c 64 20 66 69 |he text world fi| 000080b0 6c 65 20 77 68 69 63 68 20 64 65 66 69 6e 65 73 |le which defines| 000080c0 20 6f 75 72 20 77 61 6c 6c 73 20 74 79 70 65 20 | our walls type | 000080d0 61 6e 64 20 6c 61 79 6f 75 74 20 2a 2f 0a 0a 70 |and layout */..p| 000080e0 72 69 6e 74 66 28 22 5c 6e 6c 6f 61 64 69 6e 67 |rintf("\nloading| 000080f0 20 69 6e 20 74 65 78 74 20 66 69 6c 65 20 3c 41 | in text file <A| 00008100 55 41 52 61 79 24 44 69 72 3e 2e 77 6f 72 6c 64 |UARay$Dir>.world| 00008110 5c 6e 22 29 3b 0a 61 75 61 5f 77 6f 72 6c 64 28 |\n");.aua_world(| 00008120 29 3b 0a 0a 2f 2a 20 63 68 65 63 6b 20 74 6f 20 |);../* check to | 00008130 73 65 65 20 69 66 20 74 68 65 20 76 69 65 77 65 |see if the viewe| 00008140 72 20 69 73 20 69 6e 73 69 64 65 20 61 20 67 61 |r is inside a ga| 00008150 6d 65 20 63 65 6c 6c 20 57 41 4c 4c 2c 20 77 68 |me cell WALL, wh| 00008160 69 63 68 20 77 6f 75 6c 64 20 62 65 20 62 61 64 |ich would be bad| 00008170 20 6e 65 77 73 21 20 2a 2f 0a 0a 69 66 28 77 6f | news! */..if(wo| 00008180 72 6c 64 5b 76 69 65 77 5f 79 3e 3e 36 5d 5b 76 |rld[view_y>>6][v| 00008190 69 65 77 5f 78 3e 3e 36 5d 29 0a 7b 0a 20 20 70 |iew_x>>6]).{. p| 000081a0 72 69 6e 74 66 28 22 5c 6e 42 61 64 20 63 6f 6f |rintf("\nBad coo| 000081b0 72 64 69 6e 61 74 65 73 20 67 69 76 65 6e 2c 20 |rdinates given, | 000081c0 76 69 65 77 65 72 20 69 73 20 49 4e 20 61 20 57 |viewer is IN a W| 000081d0 41 4c 4c 21 2c 20 65 78 69 74 69 6e 67 5c 6e 22 |ALL!, exiting\n"| 000081e0 29 3b 0a 20 20 65 78 69 74 28 31 29 3b 0a 7d 0a |);. exit(1);.}.| 000081f0 0a 2f 2a 20 6e 6f 77 20 77 65 20 63 61 6c 6c 20 |./* now we call | 00008200 61 75 61 5f 74 61 62 6c 65 73 20 74 6f 20 67 65 |aua_tables to ge| 00008210 6e 65 72 61 74 65 20 73 6f 6d 65 20 6c 6f 6f 6b |nerate some look| 00008220 2d 75 70 20 74 61 62 6c 65 73 20 66 6f 72 20 74 |-up tables for t| 00008230 68 65 20 65 6e 67 69 6e 65 20 74 6f 20 75 73 65 |he engine to use| 00008240 2c 20 6c 6f 6f 6b 2d 75 70 73 20 61 72 65 20 65 |, look-ups are e| 00008250 78 70 6c 61 69 6e 65 64 20 75 70 20 61 74 20 74 |xplained up at t| 00008260 68 65 20 74 6f 70 20 6f 66 20 74 68 65 20 66 69 |he top of the fi| 00008270 6c 65 20 6e 65 78 74 20 74 6f 20 74 68 65 20 67 |le next to the g| 00008280 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c 65 73 20 |lobal variables | 00008290 2a 2f 0a 0a 70 72 69 6e 74 66 28 22 63 61 6c 6c |*/..printf("call| 000082a0 69 6e 67 20 61 75 61 5f 74 61 62 6c 65 73 28 29 |ing aua_tables()| 000082b0 2c 20 63 6f 75 6c 64 20 74 61 6b 65 20 61 20 6c |, could take a l| 000082c0 6f 6e 67 20 74 69 6d 65 20 6f 6e 20 73 6c 6f 77 |ong time on slow| 000082d0 65 72 20 6d 61 63 68 69 6e 65 73 5c 6e 22 29 3b |er machines\n");| 000082e0 0a 2f 2a 20 6e 65 77 65 72 20 66 69 78 65 64 20 |./* newer fixed | 000082f0 70 6f 69 6e 74 20 76 65 72 73 69 6f 6e 20 2a 2f |point version */| 00008300 0a 61 75 61 5f 74 61 62 6c 65 73 28 29 3b 0a 0a |.aua_tables();..| 00008310 2f 2a 20 61 6c 6c 20 69 73 20 64 6f 6e 65 20 69 |/* all is done i| 00008320 6e 20 74 65 72 6d 73 20 6f 66 20 69 6e 70 75 74 |n terms of input| 00008330 20 66 6f 72 20 6e 6f 77 2e 20 57 65 20 6e 65 65 | for now. We nee| 00008340 64 20 74 6f 20 73 77 69 74 63 68 20 74 6f 20 4d |d to switch to M| 00008350 6f 64 65 20 31 33 20 2a 2f 0a 0a 70 72 69 6e 74 |ode 13 */..print| 00008360 66 28 22 73 77 69 74 63 68 69 6e 67 20 74 6f 20 |f("switching to | 00008370 6d 6f 64 65 20 74 68 69 72 74 65 65 6e 5c 6e 22 |mode thirteen\n"| 00008380 29 3b 0a 0a 2f 2a 20 63 61 6c 6c 20 6f 75 72 6c |);../* call ourl| 00008390 69 62 5f 63 68 61 6e 67 65 6d 6f 64 65 20 74 6f |ib_changemode to| 000083a0 20 73 77 69 74 63 68 20 74 6f 20 6d 6f 64 65 20 | switch to mode | 000083b0 31 33 20 2a 2f 0a 0a 6f 75 72 6c 69 62 5f 63 68 |13 */..ourlib_ch| 000083c0 61 6e 67 65 6d 6f 64 65 28 31 33 29 3b 0a 0a 2f |angemode(13);../| 000083d0 2a 20 63 61 6c 6c 20 6f 75 72 6c 69 62 5f 66 69 |* call ourlib_fi| 000083e0 6e 64 73 63 72 65 65 6e 20 74 6f 20 67 65 74 20 |ndscreen to get | 000083f0 74 68 65 20 73 63 72 65 65 6e 20 62 61 73 65 20 |the screen base | 00008400 61 64 64 72 65 73 73 20 6f 66 20 6d 6f 64 65 20 |address of mode | 00008410 31 33 2c 20 20 77 69 74 68 6f 75 74 20 74 68 65 |13, without the| 00008420 20 63 6f 72 72 65 63 74 20 61 64 64 72 65 73 73 | correct address| 00008430 20 77 65 20 63 61 6e 27 74 20 64 72 61 77 20 61 | we can't draw a| 00008440 6e 79 74 68 69 6e 67 20 61 6e 64 20 74 68 65 20 |nything and the | 00008450 63 6f 6d 70 75 74 65 72 20 63 6f 75 6c 64 20 63 |computer could c| 00008460 72 61 73 68 20 2a 2f 0a 0a 73 63 72 65 65 6e 5f |rash */..screen_| 00008470 61 64 64 72 65 73 73 3d 28 63 68 61 72 20 2a 29 |address=(char *)| 00008480 6f 75 72 6c 69 62 5f 66 69 6e 64 73 63 72 65 65 |ourlib_findscree| 00008490 6e 28 29 3b 0a 2f 2a 20 4e 45 57 20 4c 4f 41 44 |n();./* NEW LOAD| 000084a0 20 54 49 54 4c 45 20 53 43 52 45 45 4e 20 2a 2f | TITLE SCREEN */| 000084b0 0a 73 79 73 74 65 6d 28 22 2a 53 63 72 65 65 6e |.system("*Screen| 000084c0 4c 6f 61 64 20 3c 41 55 41 52 61 79 24 44 69 72 |Load <AUARay$Dir| 000084d0 3e 2e 74 69 74 6c 65 22 29 3b 6f 75 72 6c 69 62 |>.title");ourlib| 000084e0 5f 6b 69 6c 6c 63 75 72 73 6f 72 28 29 3b 0a 6f |_killcursor();.o| 000084f0 75 72 6c 69 62 5f 77 61 69 74 28 32 30 30 29 3b |urlib_wait(200);| 00008500 0a 2f 2a 6f 75 72 6c 69 62 5f 73 63 72 65 65 6e |./*ourlib_screen| 00008510 5f 64 69 73 73 6f 6c 76 65 28 73 63 72 65 65 6e |_dissolve(screen| 00008520 5f 61 64 64 72 65 73 73 2c 38 31 39 32 30 29 3b |_address,81920);| 00008530 20 55 53 45 20 49 46 20 57 41 4e 54 45 44 20 2a | USE IF WANTED *| 00008540 2f 0a 0a 2f 2a 20 54 48 45 4e 20 57 41 49 54 20 |/../* THEN WAIT | 00008550 54 48 45 4e 20 53 43 52 45 45 4e 44 49 53 53 4f |THEN SCREENDISSO| 00008560 4c 56 45 20 4f 55 54 2c 20 73 65 65 20 61 62 6f |LVE OUT, see abo| 00008570 76 65 20 2a 2f 0a 0a 2f 2a 20 6e 6f 77 20 77 65 |ve */../* now we| 00008580 20 6e 65 65 64 20 74 6f 20 2a 73 63 72 65 65 6e | need to *screen| 00008590 6c 6f 61 64 20 6f 75 72 20 67 72 61 70 68 69 63 |load our graphic| 000085a0 73 20 66 69 6c 65 2c 20 61 6e 64 20 67 72 61 62 |s file, and grab| 000085b0 20 65 61 63 68 20 69 6e 64 69 76 69 64 75 61 6c | each individual| 000085c0 20 77 61 6c 6c 20 67 72 61 70 68 69 63 20 6f 6e | wall graphic on| 000085d0 65 20 62 79 20 6f 6e 65 2c 20 74 68 65 20 66 75 |e by one, the fu| 000085e0 6e 63 74 69 6f 6e 20 61 75 61 5f 67 72 61 70 68 |nction aua_graph| 000085f0 69 63 73 20 64 6f 65 73 20 74 68 69 73 20 2a 2f |ics does this */| 00008600 0a 0a 61 75 61 5f 67 72 61 70 68 69 63 73 28 29 |..aua_graphics()| 00008610 3b 0a 0a 0a 2f 2a 20 4e 4f 57 20 77 65 20 63 61 |;.../* NOW we ca| 00008620 6c 6c 20 73 65 74 75 70 5f 73 63 72 65 65 6e 73 |ll setup_screens| 00008630 2c 20 61 20 73 6d 61 6c 6c 20 66 75 6e 63 74 69 |, a small functi| 00008640 6f 6e 20 77 68 69 63 68 20 68 65 6c 70 73 20 77 |on which helps w| 00008650 69 74 68 20 62 61 6e 6b 69 6e 67 20 2a 2f 0a 2f |ith banking */./| 00008660 2a 20 57 69 74 68 20 61 6c 6c 20 74 68 65 20 64 |* With all the d| 00008670 61 74 61 20 6c 6f 61 64 65 64 20 69 6e 20 77 65 |ata loaded in we| 00008680 20 73 68 61 6c 6c 20 74 72 79 20 61 6e 64 20 69 | shall try and i| 00008690 6e 69 74 69 61 74 65 20 53 43 52 45 45 4e 20 42 |nitiate SCREEN B| 000086a0 41 4e 4b 53 2e 20 46 69 72 73 74 20 77 65 20 63 |ANKS. First we c| 000086b0 68 61 6e 67 65 20 74 6f 20 4d 4f 44 45 20 31 35 |hange to MODE 15| 000086c0 2c 20 73 6f 20 74 68 61 74 20 73 63 72 65 65 6e |, so that screen| 000086d0 20 6d 65 6d 6f 72 79 20 62 65 63 6f 6d 65 73 20 | memory becomes | 000086e0 61 76 61 69 6c 61 62 6c 65 20 66 6f 72 20 74 77 |available for tw| 000086f0 6f 20 74 69 6d 65 73 20 4d 4f 44 45 20 31 33 20 |o times MODE 13 | 00008700 2a 2f 0a 0a 6f 75 72 6c 69 62 5f 73 65 74 75 70 |*/..ourlib_setup| 00008710 5f 73 63 72 65 65 6e 73 28 29 3b 0a 6f 75 72 6c |_screens();.ourl| 00008720 69 62 5f 63 68 61 6e 67 65 6d 6f 64 65 28 31 35 |ib_changemode(15| 00008730 29 3b 0a 0a 2f 2a 20 4e 6f 77 20 77 65 20 73 77 |);../* Now we sw| 00008740 69 74 63 68 20 74 6f 20 4d 4f 44 45 20 31 33 2c |itch to MODE 13,| 00008750 20 61 6e 64 20 67 65 74 20 74 68 65 20 66 69 72 | and get the fir| 00008760 73 74 20 73 63 72 65 65 6e 20 61 64 64 72 65 73 |st screen addres| 00008770 73 20 2a 2f 0a 0a 6f 75 72 6c 69 62 5f 63 68 61 |s */..ourlib_cha| 00008780 6e 67 65 6d 6f 64 65 28 31 33 29 3b 0a 6f 75 72 |ngemode(13);.our| 00008790 6c 69 62 5f 6b 69 6c 6c 63 75 72 73 6f 72 28 29 |lib_killcursor()| 000087a0 3b 0a 2f 2a 6f 73 5f 63 6c 67 28 29 3b 2a 2f 0a |;./*os_clg();*/.| 000087b0 73 63 72 65 65 6e 5f 61 64 64 72 65 73 73 3d 28 |screen_address=(| 000087c0 63 68 61 72 20 2a 29 6f 75 72 6c 69 62 5f 66 69 |char *)ourlib_fi| 000087d0 6e 64 73 63 72 65 65 6e 28 29 3b 0a 0a 2f 2a 20 |ndscreen();../* | 000087e0 4e 6f 77 20 77 65 20 73 77 69 74 63 68 20 74 6f |Now we switch to| 000087f0 20 74 68 65 20 6f 74 68 65 72 20 73 63 72 65 65 | the other scree| 00008800 6e 20 62 61 6e 6b 20 61 6e 64 20 67 65 74 20 74 |n bank and get t| 00008810 68 65 20 6f 74 68 65 72 20 73 63 72 65 65 6e 20 |he other screen | 00008820 61 64 64 72 65 73 73 20 2a 2f 0a 0a 6f 75 72 6c |address */..ourl| 00008830 69 62 5f 73 69 6d 70 6c 65 73 77 69 74 63 68 28 |ib_simpleswitch(| 00008840 29 3b 0a 0a 73 63 72 65 65 6e 5f 61 64 64 72 65 |);..screen_addre| 00008850 73 73 5f 62 61 6e 6b 3d 28 63 68 61 72 20 2a 29 |ss_bank=(char *)| 00008860 6f 75 72 6c 69 62 5f 66 69 6e 64 73 63 72 65 65 |ourlib_findscree| 00008870 6e 28 29 3b 0a 6f 75 72 6c 69 62 5f 73 6c 6f 77 |n();.ourlib_slow| 00008880 63 6c 65 61 72 28 73 63 72 65 65 6e 5f 61 64 64 |clear(screen_add| 00008890 72 65 73 73 5f 62 61 6e 6b 2c 38 31 39 32 30 2c |ress_bank,81920,| 000088a0 30 29 3b 0a 6f 75 72 6c 69 62 5f 6b 69 6c 6c 63 |0);.ourlib_killc| 000088b0 75 72 73 6f 72 28 29 3b 0a 2f 2a 20 53 77 69 74 |ursor();./* Swit| 000088c0 63 68 20 62 61 63 6b 20 74 6f 20 74 68 65 20 6f |ch back to the o| 000088d0 74 68 65 72 20 73 63 72 65 65 6e 20 2a 2f 0a 0a |ther screen */..| 000088e0 6f 75 72 6c 69 62 5f 73 69 6d 70 6c 65 73 77 69 |ourlib_simpleswi| 000088f0 74 63 68 28 29 3b 0a 0a 2f 2a 20 4e 4f 57 20 77 |tch();../* NOW w| 00008900 65 20 63 61 6e 20 63 61 6c 6c 20 73 65 74 75 70 |e can call setup| 00008910 20 62 61 63 6b 67 72 6f 75 6e 64 2c 20 74 6f 20 | background, to | 00008920 74 65 6c 6c 20 74 68 65 20 73 63 72 65 65 6e 20 |tell the screen | 00008930 63 6c 65 61 72 65 72 20 74 68 65 20 63 6f 6c 6f |clearer the colo| 00008940 75 72 20 6f 66 20 74 68 65 20 66 6c 6f 6f 72 20 |ur of the floor | 00008950 61 6e 64 20 63 65 69 6c 69 6e 67 73 20 77 65 20 |and ceilings we | 00008960 77 61 6e 74 2e 2a 2f 0a 0a 6f 75 72 6c 69 62 5f |want.*/..ourlib_| 00008970 73 65 74 75 70 5f 62 61 63 6b 67 72 6f 75 6e 64 |setup_background| 00008980 28 32 30 38 2c 34 35 29 3b 0a 0a 2f 2a 20 4e 4f |(208,45);../* NO| 00008990 57 20 77 65 20 63 61 6e 20 73 74 61 72 74 20 74 |W we can start t| 000089a0 68 65 20 6d 61 69 6e 20 6c 6f 6f 70 2c 20 65 78 |he main loop, ex| 000089b0 69 74 61 62 6c 65 20 6f 6e 6c 79 20 62 79 20 70 |itable only by p| 000089c0 72 65 73 73 69 6e 67 20 74 68 65 20 51 20 6b 65 |ressing the Q ke| 000089d0 79 2e 20 55 73 65 20 74 68 65 20 43 75 72 73 6f |y. Use the Curso| 000089e0 72 73 20 74 6f 20 6d 6f 76 65 20 74 68 65 20 76 |rs to move the v| 000089f0 69 65 77 70 6f 69 6e 74 20 61 72 6f 75 6e 64 20 |iewpoint around | 00008a00 2a 2f 0a 2f 2a 20 57 65 20 73 68 61 6c 6c 20 61 |*/./* We shall a| 00008a10 6c 73 6f 20 74 61 6b 65 20 61 20 72 65 61 64 69 |lso take a readi| 00008a20 6e 67 20 74 6f 20 77 6f 72 6b 20 6f 75 74 20 74 |ng to work out t| 00008a30 68 65 20 66 72 61 6d 65 20 72 61 74 65 20 6f 66 |he frame rate of| 00008a40 20 74 68 65 20 73 79 73 74 65 6d 2c 20 73 6c 6f | the system, slo| 00008a50 77 20 66 6f 72 20 6e 6f 77 20 2a 2f 0a 0a 2f 2a |w for now */../*| 00008a60 20 4e 45 57 20 41 44 4a 55 53 54 49 4e 47 20 4c | NEW ADJUSTING L| 00008a70 49 4e 45 53 20 3a 20 77 65 20 61 64 64 20 61 6e |INES : we add an| 00008a80 20 6f 66 66 73 65 74 20 74 6f 20 62 6f 74 68 20 | offset to both | 00008a90 73 63 72 65 65 6e 20 6d 65 6d 6f 72 79 20 61 72 |screen memory ar| 00008aa0 65 61 73 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 |eas in order to | 00008ab0 63 65 6e 74 72 65 20 74 68 65 20 69 6d 61 67 65 |centre the image| 00008ac0 20 69 6e 20 74 68 65 20 6d 69 64 64 6c 65 20 6f | in the middle o| 00008ad0 66 20 74 68 65 20 73 63 72 65 65 6e 20 6e 6f 20 |f the screen no | 00008ae0 6d 61 74 74 65 72 20 77 68 61 74 20 73 69 7a 65 |matter what size| 00008af0 20 2a 2f 0a 0a 73 63 72 65 65 6e 5f 61 64 64 72 | */..screen_addr| 00008b00 65 73 73 2b 3d 28 33 32 30 2d 53 43 52 45 45 4e |ess+=(320-SCREEN| 00008b10 5f 57 49 44 54 48 29 3e 3e 31 3b 0a 73 63 72 65 |_WIDTH)>>1;.scre| 00008b20 65 6e 5f 61 64 64 72 65 73 73 5f 62 61 6e 6b 2b |en_address_bank+| 00008b30 3d 28 33 32 30 2d 53 43 52 45 45 4e 5f 57 49 44 |=(320-SCREEN_WID| 00008b40 54 48 29 3e 3e 31 3b 0a 0a 6f 75 72 6c 69 62 5f |TH)>>1;..ourlib_| 00008b50 6b 69 6c 6c 63 75 72 73 6f 72 28 29 3b 20 2f 2a |killcursor(); /*| 00008b60 20 67 65 74 20 72 69 64 20 6f 66 20 74 68 65 20 | get rid of the | 00008b70 63 75 72 73 6f 72 20 66 6c 61 73 68 69 6e 67 20 |cursor flashing | 00008b80 61 77 61 79 20 2a 2f 0a 74 69 6d 65 5f 73 74 61 |away */.time_sta| 00008b90 72 74 3d 6f 75 72 6c 69 62 5f 67 65 74 74 69 6d |rt=ourlib_gettim| 00008ba0 65 28 29 3b 0a 0a 77 68 69 6c 65 28 21 64 6f 6e |e();..while(!don| 00008bb0 65 29 20 2f 2a 20 74 68 65 20 6c 6f 6f 70 20 77 |e) /* the loop w| 00008bc0 69 6c 6c 20 63 6f 6e 74 69 6e 75 65 20 75 6e 74 |ill continue unt| 00008bd0 69 6c 20 64 6f 6e 65 20 2a 2f 0a 7b 0a 0a 20 6f |il done */.{.. o| 00008be0 75 72 6c 69 62 5f 66 61 73 74 63 6c 67 5f 74 77 |urlib_fastclg_tw| 00008bf0 6f 28 73 63 72 65 65 6e 5f 61 64 64 72 65 73 73 |o(screen_address| 00008c00 2c 53 43 52 45 45 4e 5f 57 49 44 54 48 2c 53 43 |,SCREEN_WIDTH,SC| 00008c10 52 45 45 4e 5f 48 45 49 47 48 54 29 3b 20 2f 2a |REEN_HEIGHT); /*| 00008c20 20 77 65 20 63 61 6c 6c 20 74 68 65 20 66 6c 6f | we call the flo| 00008c30 6f 72 2f 63 65 69 6c 69 6e 67 20 66 75 6e 63 74 |or/ceiling funct| 00008c40 69 6f 6e 20 74 6f 20 63 6f 6c 6f 75 72 20 74 68 |ion to colour th| 00008c50 65 20 77 68 6f 6c 65 20 73 63 72 65 65 6e 20 2a |e whole screen *| 00008c60 2f 0a 2f 2a 20 74 68 65 6e 20 77 65 20 63 61 6c |/./* then we cal| 00008c70 6c 20 74 68 65 20 72 61 79 20 63 61 73 74 65 72 |l the ray caster| 00008c80 20 74 6f 20 64 72 61 77 20 6f 76 65 72 20 69 74 | to draw over it| 00008c90 20 2a 2f 0a 20 61 75 61 5f 72 61 79 63 61 73 74 | */. aua_raycast| 00008ca0 65 72 28 76 69 65 77 5f 78 2c 76 69 65 77 5f 79 |er(view_x,view_y| 00008cb0 2c 76 69 65 77 5f 61 6e 67 6c 65 29 3b 0a 0a 64 |,view_angle);..d| 00008cc0 78 3d 64 79 3d 30 3b 0a 0a 2f 2a 20 6e 6f 77 20 |x=dy=0;../* now | 00008cd0 77 65 20 74 65 73 74 20 66 6f 72 20 64 69 66 66 |we test for diff| 00008ce0 65 72 65 6e 74 20 6b 65 79 20 70 72 65 73 73 65 |erent key presse| 00008cf0 73 20 61 6e 64 20 74 61 6b 65 20 61 63 74 69 6f |s and take actio| 00008d00 6e 20 61 63 63 6f 72 64 69 6e 67 6c 79 20 2a 2f |n accordingly */| 00008d10 0a 0a 69 66 28 6f 75 72 6c 69 62 5f 6b 65 79 64 |..if(ourlib_keyd| 00008d20 6f 77 6e 28 31 36 29 3d 3d 32 35 35 29 64 6f 6e |own(16)==255)don| 00008d30 65 3d 31 3b 20 2f 2a 20 69 66 20 51 20 69 73 20 |e=1; /* if Q is | 00008d40 70 72 65 73 73 65 64 20 74 68 65 6e 20 71 75 69 |pressed then qui| 00008d50 74 20 2a 2f 0a 0a 2f 2a 20 4c 45 46 54 20 2a 2f |t */../* LEFT */| 00008d60 0a 69 66 28 6f 75 72 6c 69 62 5f 6b 65 79 64 6f |.if(ourlib_keydo| 00008d70 77 6e 28 31 32 31 29 3d 3d 32 35 35 29 0a 7b 0a |wn(121)==255).{.| 00008d80 20 20 69 66 28 28 76 69 65 77 5f 61 6e 67 6c 65 | if((view_angle| 00008d90 2d 3d 41 4e 47 4c 45 5f 36 29 3c 41 4e 47 4c 45 |-=ANGLE_6)<ANGLE| 00008da0 5f 30 29 0a 20 20 76 69 65 77 5f 61 6e 67 6c 65 |_0). view_angle| 00008db0 3d 41 4e 47 4c 45 5f 33 36 30 3b 0a 7d 0a 0a 2f |=ANGLE_360;.}../| 00008dc0 2a 52 49 47 48 54 20 2a 2f 0a 69 66 28 6f 75 72 |*RIGHT */.if(our| 00008dd0 6c 69 62 5f 6b 65 79 64 6f 77 6e 28 32 35 29 3d |lib_keydown(25)=| 00008de0 3d 32 35 35 29 0a 7b 0a 20 20 69 66 28 28 76 69 |=255).{. if((vi| 00008df0 65 77 5f 61 6e 67 6c 65 2b 3d 41 4e 47 4c 45 5f |ew_angle+=ANGLE_| 00008e00 36 29 3e 41 4e 47 4c 45 5f 33 36 30 29 0a 20 20 |6)>ANGLE_360). | 00008e10 76 69 65 77 5f 61 6e 67 6c 65 3d 41 4e 47 4c 45 |view_angle=ANGLE| 00008e20 5f 30 3b 0a 7d 0a 2f 2a 20 55 50 20 61 6e 64 20 |_0;.}./* UP and | 00008e30 44 4f 57 4e 20 2a 2f 0a 69 66 28 6f 75 72 6c 69 |DOWN */.if(ourli| 00008e40 62 5f 6b 65 79 64 6f 77 6e 28 35 37 29 3d 3d 32 |b_keydown(57)==2| 00008e50 35 35 29 0a 7b 0a 20 20 64 78 3d 64 78 5f 74 61 |55).{. dx=dx_ta| 00008e60 62 6c 65 5b 76 69 65 77 5f 61 6e 67 6c 65 5d 3b |ble[view_angle];| 00008e70 0a 20 20 64 79 3d 64 79 5f 74 61 62 6c 65 5b 76 |. dy=dy_table[v| 00008e80 69 65 77 5f 61 6e 67 6c 65 5d 3b 0a 7d 0a 0a 69 |iew_angle];.}..i| 00008e90 66 28 6f 75 72 6c 69 62 5f 6b 65 79 64 6f 77 6e |f(ourlib_keydown| 00008ea0 28 34 31 29 3d 3d 32 35 35 29 0a 7b 0a 0a 20 20 |(41)==255).{.. | 00008eb0 64 78 3d 2d 64 78 5f 74 61 62 6c 65 5b 76 69 65 |dx=-dx_table[vie| 00008ec0 77 5f 61 6e 67 6c 65 5d 3b 0a 20 20 64 79 3d 2d |w_angle];. dy=-| 00008ed0 64 79 5f 74 61 62 6c 65 5b 76 69 65 77 5f 61 6e |dy_table[view_an| 00008ee0 67 6c 65 5d 3b 0a 7d 0a 0a 2f 2a 20 4e 4f 57 20 |gle];.}../* NOW | 00008ef0 77 65 20 6e 65 65 64 20 74 6f 20 6d 6f 76 65 20 |we need to move | 00008f00 74 68 65 20 70 6c 61 79 65 72 20 61 6e 64 20 72 |the player and r| 00008f10 65 63 61 6c 63 75 6c 61 74 65 20 74 68 65 20 63 |ecalculate the c| 00008f20 65 6c 6c 20 74 68 65 20 76 69 65 77 65 72 20 69 |ell the viewer i| 00008f30 73 20 69 6e 2c 20 61 6e 64 20 41 4c 53 4f 20 63 |s in, and ALSO c| 00008f40 68 65 63 6b 20 74 6f 20 73 65 65 20 69 66 20 74 |heck to see if t| 00008f50 68 65 20 70 6c 61 79 65 72 20 68 61 73 20 68 69 |he player has hi| 00008f60 74 20 61 20 77 61 6c 6c 20 2a 2f 0a 0a 2f 2a 20 |t a wall */../* | 00008f70 57 61 74 63 68 20 66 6f 72 20 74 68 65 20 63 6f |Watch for the co| 00008f80 6e 76 65 72 73 69 6f 6e 73 20 6f 66 20 66 69 78 |nversions of fix| 00008f90 65 64 20 70 6f 69 6e 74 20 61 6e 64 20 74 68 69 |ed point and thi| 00008fa0 6e 67 73 20 2a 2f 0a 0a 2f 2a 20 50 6c 61 79 65 |ngs */../* Playe| 00008fb0 72 20 58 20 61 63 74 75 61 6c 6c 79 20 69 73 20 |r X actually is | 00008fc0 69 6e 20 6e 6f 72 6d 61 6c 20 6d 61 74 68 73 20 |in normal maths | 00008fd0 2a 2f 0a 20 76 69 65 77 5f 78 3d 20 28 69 6e 74 |*/. view_x= (int| 00008fe0 29 28 28 76 69 65 77 5f 78 3c 3c 31 36 29 2b 64 |)((view_x<<16)+d| 00008ff0 78 29 3e 3e 31 36 3b 0a 20 76 69 65 77 5f 79 3d |x)>>16;. view_y=| 00009000 20 28 69 6e 74 29 28 28 76 69 65 77 5f 79 3c 3c | (int)((view_y<<| 00009010 31 36 29 2b 64 79 29 3e 3e 31 36 3b 0a 0a 2f 2a |16)+dy)>>16;../*| 00009020 20 44 45 4d 4f 20 48 41 4e 44 4c 49 4e 47 20 43 | DEMO HANDLING C| 00009030 4f 44 45 20 43 4f 4d 45 53 20 48 45 52 45 20 2a |ODE COMES HERE *| 00009040 2f 0a 2f 2a 20 4e 6f 74 65 20 74 68 61 74 20 74 |/./* Note that t| 00009050 68 69 73 20 69 73 20 64 65 73 63 72 69 62 65 64 |his is described| 00009060 20 62 72 69 65 66 6c 79 20 69 6e 20 61 72 74 69 | briefly in arti| 00009070 63 6c 65 20 35 20 2a 2f 0a 0a 69 66 28 44 45 4d |cle 5 */..if(DEM| 00009080 4f 5f 57 52 49 54 45 20 7c 7c 20 44 45 4d 4f 5f |O_WRITE || DEMO_| 00009090 52 45 41 44 29 0a 7b 0a 74 76 69 65 77 5f 78 3d |READ).{.tview_x=| 000090a0 76 69 65 77 5f 78 3b 0a 74 76 69 65 77 5f 79 3d |view_x;.tview_y=| 000090b0 76 69 65 77 5f 79 3b 0a 74 76 69 65 77 5f 61 6e |view_y;.tview_an| 000090c0 67 6c 65 3d 76 69 65 77 5f 61 6e 67 6c 65 3b 0a |gle=view_angle;.| 000090d0 69 66 28 44 45 4d 4f 5f 57 52 49 54 45 29 66 70 |if(DEMO_WRITE)fp| 000090e0 72 69 6e 74 66 28 64 65 6d 6f 5f 66 69 6c 65 2c |rintf(demo_file,| 000090f0 22 25 64 20 25 64 20 25 64 20 22 2c 74 76 69 65 |"%d %d %d ",tvie| 00009100 77 5f 78 2c 74 76 69 65 77 5f 79 2c 74 76 69 65 |w_x,tview_y,tvie| 00009110 77 5f 61 6e 67 6c 65 29 3b 0a 69 66 28 44 45 4d |w_angle);.if(DEM| 00009120 4f 5f 52 45 41 44 29 69 66 28 28 66 73 63 61 6e |O_READ)if((fscan| 00009130 66 28 64 65 6d 6f 5f 66 69 6c 65 2c 22 25 64 20 |f(demo_file,"%d | 00009140 25 64 20 25 64 20 22 2c 26 74 76 69 65 77 5f 78 |%d %d ",&tview_x| 00009150 2c 26 74 76 69 65 77 5f 79 2c 26 74 76 69 65 77 |,&tview_y,&tview| 00009160 5f 61 6e 67 6c 65 29 29 3d 3d 45 4f 46 29 72 65 |_angle))==EOF)re| 00009170 77 69 6e 64 28 64 65 6d 6f 5f 66 69 6c 65 29 3b |wind(demo_file);| 00009180 0a 76 69 65 77 5f 78 3d 74 76 69 65 77 5f 78 3b |.view_x=tview_x;| 00009190 0a 76 69 65 77 5f 79 3d 74 76 69 65 77 5f 79 3b |.view_y=tview_y;| 000091a0 0a 76 69 65 77 5f 61 6e 67 6c 65 3d 74 76 69 65 |.view_angle=tvie| 000091b0 77 5f 61 6e 67 6c 65 3b 0a 7d 0a 2f 2a 20 4e 45 |w_angle;.}./* NE| 000091c0 57 20 4f 50 54 49 4d 49 5a 45 44 20 56 45 52 53 |W OPTIMIZED VERS| 000091d0 49 4f 4e 53 20 4f 46 20 4d 4f 56 49 4e 47 20 54 |IONS OF MOVING T| 000091e0 48 45 20 50 4c 41 59 45 52 20 2a 2f 0a 0a 20 78 |HE PLAYER */.. x| 000091f0 5f 63 65 6c 6c 20 3d 20 76 69 65 77 5f 78 3e 3e |_cell = view_x>>| 00009200 36 3b 0a 20 79 5f 63 65 6c 6c 20 3d 20 76 69 65 |6;. y_cell = vie| 00009210 77 5f 79 3e 3e 36 3b 0a 0a 20 78 5f 73 75 62 5f |w_y>>6;.. x_sub_| 00009220 63 65 6c 6c 20 3d 20 76 69 65 77 5f 78 20 26 20 |cell = view_x & | 00009230 30 78 30 30 33 66 3b 0a 20 79 5f 73 75 62 5f 63 |0x003f;. y_sub_c| 00009240 65 6c 6c 20 3d 20 76 69 65 77 5f 79 20 26 20 30 |ell = view_y & 0| 00009250 78 30 30 33 66 3b 0a 0a 2f 2a 20 43 48 45 43 4b |x003f;../* CHECK| 00009260 20 74 6f 20 73 65 65 20 69 66 20 70 6c 61 79 65 | to see if playe| 00009270 72 20 68 61 73 20 77 61 6c 6b 65 64 20 69 6e 74 |r has walked int| 00009280 6f 20 77 61 6c 6c 73 20 2a 2f 0a 20 69 66 20 28 |o walls */. if (| 00009290 28 64 78 3e 3e 38 29 3e 30 20 29 7b 0a 20 69 66 |(dx>>8)>0 ){. if| 000092a0 20 28 28 77 6f 72 6c 64 5b 79 5f 63 65 6c 6c 5d | ((world[y_cell]| 000092b0 5b 78 5f 63 65 6c 6c 2b 31 5d 20 21 3d 20 30 29 |[x_cell+1] != 0)| 000092c0 20 20 26 26 20 28 78 5f 73 75 62 5f 63 65 6c 6c | && (x_sub_cell| 000092d0 3e 28 43 45 4c 4c 5f 58 5f 53 49 5a 45 2d 43 4c |>(CELL_X_SIZE-CL| 000092e0 4f 53 45 53 54 29 29 29 0a 20 20 20 20 20 20 20 |OSEST))). | 000092f0 20 20 20 20 20 20 20 20 20 7b 0a 20 20 20 20 20 | {. | 00009300 20 20 20 20 20 20 20 20 20 20 20 76 69 65 77 5f | view_| 00009310 78 2d 3d 20 28 78 5f 73 75 62 5f 63 65 6c 6c 2d |x-= (x_sub_cell-| 00009320 28 43 45 4c 4c 5f 58 5f 53 49 5a 45 2d 43 4c 4f |(CELL_X_SIZE-CLO| 00009330 53 45 53 54 20 29 29 3b 0a 20 20 20 20 20 20 20 |SEST ));. | 00009340 20 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 | }. | 00009350 20 20 20 20 20 20 20 20 20 20 20 7d 0a 20 65 6c | }. el| 00009360 73 65 0a 20 7b 0a 20 69 66 20 28 20 28 77 6f 72 |se. {. if ( (wor| 00009370 6c 64 5b 79 5f 63 65 6c 6c 5d 5b 78 5f 63 65 6c |ld[y_cell][x_cel| 00009380 6c 2d 31 5d 20 21 3d 20 30 29 20 20 26 26 20 28 |l-1] != 0) && (| 00009390 78 5f 73 75 62 5f 63 65 6c 6c 20 3c 20 28 43 4c |x_sub_cell < (CL| 000093a0 4f 53 45 53 54 29 20 29 20 29 0a 20 20 20 20 20 |OSEST) ) ). | 000093b0 20 20 20 20 20 20 20 20 20 20 20 7b 0a 20 20 20 | {. | 000093c0 20 20 20 20 20 20 20 20 20 20 20 20 20 76 69 65 | vie| 000093d0 77 5f 78 2b 3d 20 28 43 4c 4f 53 45 53 54 2d 78 |w_x+= (CLOSEST-x| 000093e0 5f 73 75 62 5f 63 65 6c 6c 29 20 3b 0a 20 20 20 |_sub_cell) ;. | 000093f0 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 20 | }. | 00009400 7d 0a 0a 20 69 66 20 28 28 64 79 3e 3e 38 29 3e |}.. if ((dy>>8)>| 00009410 30 20 29 7b 0a 20 69 66 20 28 20 28 77 6f 72 6c |0 ){. if ( (worl| 00009420 64 5b 28 79 5f 63 65 6c 6c 2b 31 29 5d 5b 78 5f |d[(y_cell+1)][x_| 00009430 63 65 6c 6c 5d 20 21 3d 20 30 29 20 20 26 26 0a |cell] != 0) &&.| 00009440 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00009450 28 79 5f 73 75 62 5f 63 65 6c 6c 20 3e 20 28 43 |(y_sub_cell > (C| 00009460 45 4c 4c 5f 59 5f 53 49 5a 45 2d 43 4c 4f 53 45 |ELL_Y_SIZE-CLOSE| 00009470 53 54 20 29 20 29 20 29 0a 20 20 20 20 20 20 20 |ST ) ) ). | 00009480 20 20 20 20 20 20 20 20 20 7b 0a 20 20 20 20 20 | {. | 00009490 20 20 20 20 20 20 20 20 20 20 20 76 69 65 77 5f | view_| 000094a0 79 2d 3d 20 28 79 5f 73 75 62 5f 63 65 6c 6c 2d |y-= (y_sub_cell-| 000094b0 28 43 45 4c 4c 5f 59 5f 53 49 5a 45 2d 43 4c 4f |(CELL_Y_SIZE-CLO| 000094c0 53 45 53 54 20 29 29 3b 0a 20 20 20 20 20 20 20 |SEST ));. | 000094d0 20 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 | }. | 000094e0 20 20 20 20 20 20 20 20 20 20 20 7d 0a 20 65 6c | }. el| 000094f0 73 65 0a 20 7b 0a 20 69 66 20 28 20 28 77 6f 72 |se. {. if ( (wor| 00009500 6c 64 5b 28 79 5f 63 65 6c 6c 2d 31 29 5d 5b 78 |ld[(y_cell-1)][x| 00009510 5f 63 65 6c 6c 5d 20 21 3d 20 30 29 20 20 26 26 |_cell] != 0) &&| 00009520 20 28 79 5f 73 75 62 5f 63 65 6c 6c 20 3c 20 28 | (y_sub_cell < (| 00009530 43 4c 4f 53 45 53 54 29 20 29 20 29 0a 20 20 20 |CLOSEST) ) ). | 00009540 20 20 20 20 20 20 20 20 20 20 20 20 20 7b 0a 20 | {. | 00009550 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 76 | v| 00009560 69 65 77 5f 79 2b 3d 20 28 43 4c 4f 53 45 53 54 |iew_y+= (CLOSEST| 00009570 2d 79 5f 73 75 62 5f 63 65 6c 6c 29 3b 0a 20 20 |-y_sub_cell);. | 00009580 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a | }.| 00009590 20 7d 0a 0a 0a 0a 2f 2a 20 4e 45 57 20 44 4f 4f | }..../* NEW DOO| 000095a0 52 20 63 6f 64 65 2e 20 41 20 22 70 72 6f 62 65 |R code. A "probe| 000095b0 22 20 69 73 20 73 65 6e 74 20 6f 75 74 20 69 6e |" is sent out in| 000095c0 20 66 72 6f 6e 74 20 6f 66 20 74 68 65 20 70 6c | front of the pl| 000095d0 61 79 65 72 2c 20 69 66 20 61 20 64 6f 6f 72 20 |ayer, if a door | 000095e0 74 69 6c 65 20 69 73 20 66 6f 75 6e 64 20 6e 65 |tile is found ne| 000095f0 61 72 20 69 74 20 74 68 65 6e 20 74 68 65 20 62 |ar it then the b| 00009600 6c 6f 63 6b 20 69 73 20 64 65 73 74 72 6f 79 65 |lock is destroye| 00009610 64 2e 20 2a 2f 0a 0a 69 66 28 6f 75 72 6c 69 62 |d. */..if(ourlib| 00009620 5f 6b 65 79 64 6f 77 6e 28 39 38 29 3d 3d 32 35 |_keydown(98)==25| 00009630 35 29 0a 7b 0a 2f 2a 20 55 73 65 20 73 69 6d 69 |5).{./* Use simi| 00009640 6c 61 72 20 74 65 63 68 6e 69 71 75 65 73 20 74 |lar techniques t| 00009650 6f 20 61 62 6f 76 65 20 74 6f 20 66 69 6e 64 20 |o above to find | 00009660 64 6f 6f 72 20 2a 2f 0a 0a 64 78 3d 64 78 5f 74 |door */..dx=dx_t| 00009670 61 62 6c 65 5b 76 69 65 77 5f 61 6e 67 6c 65 5d |able[view_angle]| 00009680 3b 0a 64 79 3d 64 79 5f 74 61 62 6c 65 5b 76 69 |;.dy=dy_table[vi| 00009690 65 77 5f 61 6e 67 6c 65 5d 3b 0a 0a 2f 2a 20 43 |ew_angle];../* C| 000096a0 61 6c 63 75 6c 61 74 65 20 64 6f 6f 72 20 78 20 |alculate door x | 000096b0 61 6e 64 20 79 2c 20 69 74 20 69 73 20 69 6e 20 |and y, it is in | 000096c0 6e 6f 72 6d 61 6c 20 6d 61 74 68 73 20 2a 2f 0a |normal maths */.| 000096d0 20 64 6f 6f 72 5f 78 3d 20 28 69 6e 74 29 28 28 | door_x= (int)((| 000096e0 76 69 65 77 5f 78 3c 3c 31 36 29 2b 28 64 78 3c |view_x<<16)+(dx<| 000096f0 3c 33 29 29 3e 3e 31 36 3b 0a 20 64 6f 6f 72 5f |<3))>>16;. door_| 00009700 79 3d 20 28 69 6e 74 29 28 28 76 69 65 77 5f 79 |y= (int)((view_y| 00009710 3c 3c 31 36 29 2b 28 64 79 3c 3c 33 29 29 3e 3e |<<16)+(dy<<3))>>| 00009720 31 36 3b 0a 0a 2f 2a 20 4e 45 57 20 4f 50 54 49 |16;../* NEW OPTI| 00009730 4d 49 5a 45 44 20 56 45 52 53 49 4f 4e 53 20 4f |MIZED VERSIONS O| 00009740 46 20 46 49 4e 44 49 4e 20 44 4f 4f 52 53 20 2a |F FINDIN DOORS *| 00009750 2f 0a 2f 2a 20 6e 6f 77 20 66 69 6e 64 20 74 68 |/./* now find th| 00009760 65 20 63 65 6c 6c 20 77 65 20 61 72 65 20 6c 6f |e cell we are lo| 00009770 6f 6b 69 6e 67 20 69 6e 20 77 69 74 68 20 74 68 |oking in with th| 00009780 65 20 73 74 61 6e 64 61 72 64 20 65 71 75 61 74 |e standard equat| 00009790 69 6f 6e 20 2a 2f 0a 0a 20 78 5f 63 65 6c 6c 20 |ion */.. x_cell | 000097a0 3d 20 28 69 6e 74 29 64 6f 6f 72 5f 78 3e 3e 36 |= (int)door_x>>6| 000097b0 3b 0a 20 79 5f 63 65 6c 6c 20 3d 20 28 69 6e 74 |;. y_cell = (int| 000097c0 29 64 6f 6f 72 5f 79 3e 3e 36 3b 0a 0a 2f 2a 20 |)door_y>>6;../* | 000097d0 43 68 65 63 6b 20 69 66 20 61 20 64 6f 6f 72 73 |Check if a doors| 000097e0 20 69 73 20 70 72 65 73 65 6e 74 20 2a 2f 0a 0a | is present */..| 000097f0 69 66 28 77 6f 72 6c 64 5b 79 5f 63 65 6c 6c 5d |if(world[y_cell]| 00009800 5b 78 5f 63 65 6c 6c 5d 3d 3d 37 20 2f 2a 20 4f |[x_cell]==7 /* O| 00009810 52 20 57 48 41 54 45 56 45 52 20 59 4f 55 20 4c |R WHATEVER YOU L| 00009820 49 4b 45 20 2a 2f 29 0a 7b 0a 77 6f 72 6c 64 5b |IKE */).{.world[| 00009830 79 5f 63 65 6c 6c 5d 5b 78 5f 63 65 6c 6c 5d 3d |y_cell][x_cell]=| 00009840 30 3b 20 2f 2a 20 6f 72 20 61 6c 74 65 72 6e 61 |0; /* or alterna| 00009850 74 69 76 65 6c 79 20 64 6f 20 77 68 61 74 20 79 |tively do what y| 00009860 6f 75 20 6c 69 6b 65 20 2a 2f 0a 7d 0a 7d 0a 0a |ou like */.}.}..| 00009870 0a 0a 0a 0a 2f 2a 20 4e 65 77 20 4f 62 6a 65 63 |..../* New Objec| 00009880 74 20 43 6f 64 65 20 2a 2a 2a 2a 2a 2a 2a 2a 2a |t Code *********| 00009890 2a 2a 2a 2a 2a 2a 2a 2a 2a 20 41 64 64 65 64 20 |********* Added | 000098a0 41 72 74 69 63 6c 65 20 35 2c 20 67 6f 6f 64 20 |Article 5, good | 000098b0 73 74 75 66 66 21 20 20 20 2a 2f 0a 2f 2a 20 54 |stuff! */./* T| 000098c0 68 69 73 20 63 6f 64 65 20 63 79 63 6c 65 73 20 |his code cycles | 000098d0 74 68 72 6f 75 67 68 20 74 68 65 20 6f 62 6a 65 |through the obje| 000098e0 63 74 73 20 61 6e 64 20 70 6c 6f 74 73 20 74 68 |cts and plots th| 000098f0 65 6d 20 61 70 70 72 6f 70 72 69 61 74 65 6c 79 |em appropriately| 00009900 0a 20 20 20 69 66 20 74 68 65 79 20 61 72 65 20 |. if they are | 00009910 76 69 73 69 62 6c 65 20 62 79 20 74 68 65 20 76 |visible by the v| 00009920 69 65 77 65 72 2e 20 53 65 65 20 41 52 54 49 43 |iewer. See ARTIC| 00009930 4c 45 20 35 20 66 6f 72 20 6d 6f 72 65 20 64 65 |LE 5 for more de| 00009940 74 61 69 6c 73 2e 2a 2f 0a 0a 2f 2a 20 46 69 72 |tails.*/../* Fir| 00009950 73 74 6c 79 2c 20 73 65 74 20 75 70 20 76 61 72 |stly, set up var| 00009960 69 61 62 6c 65 73 20 77 65 20 6b 6e 6f 77 20 61 |iables we know a| 00009970 72 65 20 67 6f 69 6e 67 20 74 6f 20 62 65 20 75 |re going to be u| 00009980 73 65 64 20 2a 2f 0a 76 61 72 69 61 62 6c 65 73 |sed */.variables| 00009990 5b 30 5d 3d 28 69 6e 74 29 73 63 72 65 65 6e 5f |[0]=(int)screen_| 000099a0 61 64 64 72 65 73 73 3b 0a 76 61 72 69 61 62 6c |address;.variabl| 000099b0 65 73 5b 32 5d 3d 53 43 52 45 45 4e 5f 48 45 49 |es[2]=SCREEN_HEI| 000099c0 47 48 54 3b 0a 2f 2a 20 4e 65 78 74 20 77 65 20 |GHT;./* Next we | 000099d0 6c 6f 6f 70 20 74 68 72 6f 75 67 68 20 61 6c 6c |loop through all| 000099e0 20 74 68 65 20 76 69 73 69 62 6c 65 20 73 71 75 | the visible squ| 000099f0 61 72 65 73 20 74 6f 20 73 65 65 20 69 66 20 61 |ares to see if a| 00009a00 6e 20 6f 62 6a 65 63 74 20 68 61 73 20 62 65 65 |n object has bee| 00009a10 6e 20 66 6f 75 6e 64 20 2a 2f 0a 0a 69 66 28 76 |n found */..if(v| 00009a20 69 65 77 5f 61 6e 67 6c 65 3e 41 4e 47 4c 45 5f |iew_angle>ANGLE_| 00009a30 30 20 26 26 20 76 69 65 77 5f 61 6e 67 6c 65 3c |0 && view_angle<| 00009a40 41 4e 47 4c 45 5f 39 30 29 0a 7b 0a 73 74 61 72 |ANGLE_90).{.star| 00009a50 74 5f 78 3d 28 76 69 65 77 5f 78 3e 3e 36 29 2b |t_x=(view_x>>6)+| 00009a60 31 35 3b 0a 73 74 61 72 74 5f 79 3d 28 76 69 65 |15;.start_y=(vie| 00009a70 77 5f 79 3e 3e 36 29 2b 31 35 3b 0a 73 74 6f 70 |w_y>>6)+15;.stop| 00009a80 5f 78 3d 28 76 69 65 77 5f 78 3e 3e 36 29 2d 35 |_x=(view_x>>6)-5| 00009a90 3b 0a 73 74 6f 70 5f 79 3d 28 76 69 65 77 5f 79 |;.stop_y=(view_y| 00009aa0 3e 3e 36 29 2d 35 3b 0a 6d 6f 76 65 5f 78 3d 2d |>>6)-5;.move_x=-| 00009ab0 31 3b 0a 6d 6f 76 65 5f 79 3d 2d 31 3b 0a 69 66 |1;.move_y=-1;.if| 00009ac0 28 73 74 6f 70 5f 78 3c 30 29 73 74 6f 70 5f 78 |(stop_x<0)stop_x| 00009ad0 3d 30 3b 69 66 28 73 74 6f 70 5f 78 3e 36 33 29 |=0;if(stop_x>63)| 00009ae0 73 74 6f 70 5f 78 3d 36 33 3b 0a 69 66 28 73 74 |stop_x=63;.if(st| 00009af0 61 72 74 5f 78 3c 30 29 73 74 61 72 74 5f 78 3d |art_x<0)start_x=| 00009b00 30 3b 69 66 28 73 74 61 72 74 5f 78 3e 36 33 29 |0;if(start_x>63)| 00009b10 73 74 61 72 74 5f 78 3d 36 33 3b 0a 69 66 28 73 |start_x=63;.if(s| 00009b20 74 6f 70 5f 79 3c 30 29 73 74 6f 70 5f 79 3d 30 |top_y<0)stop_y=0| 00009b30 3b 69 66 28 73 74 6f 70 5f 79 3e 36 33 29 73 74 |;if(stop_y>63)st| 00009b40 6f 70 5f 79 3d 36 33 3b 0a 69 66 28 73 74 61 72 |op_y=63;.if(star| 00009b50 74 5f 79 3c 30 29 73 74 61 72 74 5f 79 3d 30 3b |t_y<0)start_y=0;| 00009b60 69 66 28 73 74 61 72 74 5f 79 3e 36 33 29 73 74 |if(start_y>63)st| 00009b70 61 72 74 5f 79 3d 36 33 3b 0a 0a 0a 7d 0a 65 6c |art_y=63;...}.el| 00009b80 73 65 20 69 66 28 76 69 65 77 5f 61 6e 67 6c 65 |se if(view_angle| 00009b90 3e 3d 41 4e 47 4c 45 5f 39 30 20 26 26 20 76 69 |>=ANGLE_90 && vi| 00009ba0 65 77 5f 61 6e 67 6c 65 3c 41 4e 47 4c 45 5f 31 |ew_angle<ANGLE_1| 00009bb0 38 30 29 0a 7b 0a 20 20 73 74 61 72 74 5f 78 3d |80).{. start_x=| 00009bc0 28 76 69 65 77 5f 78 3e 3e 36 29 2d 31 35 3b 0a |(view_x>>6)-15;.| 00009bd0 20 20 73 74 61 72 74 5f 79 3d 28 76 69 65 77 5f | start_y=(view_| 00009be0 79 3e 3e 36 29 2b 31 35 3b 0a 20 20 73 74 6f 70 |y>>6)+15;. stop| 00009bf0 5f 78 3d 28 76 69 65 77 5f 78 3e 3e 36 29 2b 35 |_x=(view_x>>6)+5| 00009c00 3b 0a 20 20 73 74 6f 70 5f 79 3d 28 76 69 65 77 |;. stop_y=(view| 00009c10 5f 79 3e 3e 36 29 2d 35 3b 0a 6d 6f 76 65 5f 78 |_y>>6)-5;.move_x| 00009c20 3d 31 3b 0a 6d 6f 76 65 5f 79 3d 2d 31 3b 0a 69 |=1;.move_y=-1;.i| 00009c30 66 28 73 74 6f 70 5f 78 3c 30 29 73 74 6f 70 5f |f(stop_x<0)stop_| 00009c40 78 3d 30 3b 69 66 28 73 74 6f 70 5f 78 3e 36 33 |x=0;if(stop_x>63| 00009c50 29 73 74 6f 70 5f 78 3d 36 33 3b 0a 69 66 28 73 |)stop_x=63;.if(s| 00009c60 74 61 72 74 5f 78 3c 30 29 73 74 61 72 74 5f 78 |tart_x<0)start_x| 00009c70 3d 30 3b 69 66 28 73 74 61 72 74 5f 78 3e 36 33 |=0;if(start_x>63| 00009c80 29 73 74 61 72 74 5f 78 3d 36 33 3b 0a 69 66 28 |)start_x=63;.if(| 00009c90 73 74 6f 70 5f 79 3c 30 29 73 74 6f 70 5f 79 3d |stop_y<0)stop_y=| 00009ca0 30 3b 69 66 28 73 74 6f 70 5f 79 3e 36 33 29 73 |0;if(stop_y>63)s| 00009cb0 74 6f 70 5f 79 3d 36 33 3b 0a 69 66 28 73 74 61 |top_y=63;.if(sta| 00009cc0 72 74 5f 79 3c 30 29 73 74 61 72 74 5f 79 3d 30 |rt_y<0)start_y=0| 00009cd0 3b 69 66 28 73 74 61 72 74 5f 79 3e 36 33 29 73 |;if(start_y>63)s| 00009ce0 74 61 72 74 5f 79 3d 36 33 3b 0a 7d 0a 65 6c 73 |tart_y=63;.}.els| 00009cf0 65 20 69 66 28 76 69 65 77 5f 61 6e 67 6c 65 3e |e if(view_angle>| 00009d00 3d 41 4e 47 4c 45 5f 31 38 30 20 26 26 20 76 69 |=ANGLE_180 && vi| 00009d10 65 77 5f 61 6e 67 6c 65 3c 41 4e 47 4c 45 5f 32 |ew_angle<ANGLE_2| 00009d20 37 30 29 0a 7b 0a 20 20 73 74 61 72 74 5f 78 3d |70).{. start_x=| 00009d30 28 76 69 65 77 5f 78 3e 3e 36 29 2d 31 35 3b 0a |(view_x>>6)-15;.| 00009d40 20 20 73 74 61 72 74 5f 79 3d 28 76 69 65 77 5f | start_y=(view_| 00009d50 79 3e 3e 36 29 2d 31 35 3b 0a 20 20 73 74 6f 70 |y>>6)-15;. stop| 00009d60 5f 78 3d 28 76 69 65 77 5f 78 3e 3e 36 29 2b 35 |_x=(view_x>>6)+5| 00009d70 3b 0a 20 20 73 74 6f 70 5f 79 3d 28 76 69 65 77 |;. stop_y=(view| 00009d80 5f 79 3e 3e 36 29 2b 35 3b 0a 6d 6f 76 65 5f 78 |_y>>6)+5;.move_x| 00009d90 3d 31 3b 0a 6d 6f 76 65 5f 79 3d 31 3b 0a 69 66 |=1;.move_y=1;.if| 00009da0 28 73 74 6f 70 5f 78 3c 30 29 73 74 6f 70 5f 78 |(stop_x<0)stop_x| 00009db0 3d 30 3b 69 66 28 73 74 6f 70 5f 78 3e 36 33 29 |=0;if(stop_x>63)| 00009dc0 73 74 6f 70 5f 78 3d 36 33 3b 0a 69 66 28 73 74 |stop_x=63;.if(st| 00009dd0 61 72 74 5f 78 3c 30 29 73 74 61 72 74 5f 78 3d |art_x<0)start_x=| 00009de0 30 3b 69 66 28 73 74 61 72 74 5f 78 3e 36 33 29 |0;if(start_x>63)| 00009df0 73 74 61 72 74 5f 78 3d 36 33 3b 0a 69 66 28 73 |start_x=63;.if(s| 00009e00 74 6f 70 5f 79 3c 30 29 73 74 6f 70 5f 79 3d 30 |top_y<0)stop_y=0| 00009e10 3b 69 66 28 73 74 6f 70 5f 79 3e 36 33 29 73 74 |;if(stop_y>63)st| 00009e20 6f 70 5f 79 3d 36 33 3b 0a 69 66 28 73 74 61 72 |op_y=63;.if(star| 00009e30 74 5f 79 3c 30 29 73 74 61 72 74 5f 79 3d 30 3b |t_y<0)start_y=0;| 00009e40 69 66 28 73 74 61 72 74 5f 79 3e 36 33 29 73 74 |if(start_y>63)st| 00009e50 61 72 74 5f 79 3d 36 33 3b 0a 7d 0a 65 6c 73 65 |art_y=63;.}.else| 00009e60 0a 7b 0a 0a 20 20 73 74 61 72 74 5f 78 3d 28 76 |.{.. start_x=(v| 00009e70 69 65 77 5f 78 3e 3e 36 29 2b 31 35 3b 0a 20 20 |iew_x>>6)+15;. | 00009e80 73 74 61 72 74 5f 79 3d 28 76 69 65 77 5f 79 3e |start_y=(view_y>| 00009e90 3e 36 29 2d 31 35 3b 0a 20 20 73 74 6f 70 5f 78 |>6)-15;. stop_x| 00009ea0 3d 28 76 69 65 77 5f 78 3e 3e 36 29 2d 35 3b 0a |=(view_x>>6)-5;.| 00009eb0 20 20 73 74 6f 70 5f 79 3d 28 76 69 65 77 5f 79 | stop_y=(view_y| 00009ec0 3e 3e 36 29 2b 35 3b 0a 20 20 6d 6f 76 65 5f 78 |>>6)+5;. move_x| 00009ed0 3d 2d 31 3b 0a 20 20 6d 6f 76 65 5f 79 3d 31 3b |=-1;. move_y=1;| 00009ee0 0a 69 66 28 73 74 6f 70 5f 78 3c 30 29 73 74 6f |.if(stop_x<0)sto| 00009ef0 70 5f 78 3d 30 3b 69 66 28 73 74 6f 70 5f 78 3e |p_x=0;if(stop_x>| 00009f00 36 33 29 73 74 6f 70 5f 78 3d 36 33 3b 0a 69 66 |63)stop_x=63;.if| 00009f10 28 73 74 61 72 74 5f 78 3c 30 29 73 74 61 72 74 |(start_x<0)start| 00009f20 5f 78 3d 30 3b 69 66 28 73 74 61 72 74 5f 78 3e |_x=0;if(start_x>| 00009f30 36 33 29 73 74 61 72 74 5f 78 3d 36 33 3b 0a 69 |63)start_x=63;.i| 00009f40 66 28 73 74 6f 70 5f 79 3c 30 29 73 74 6f 70 5f |f(stop_y<0)stop_| 00009f50 79 3d 30 3b 69 66 28 73 74 6f 70 5f 79 3e 36 33 |y=0;if(stop_y>63| 00009f60 29 73 74 6f 70 5f 79 3d 36 33 3b 0a 69 66 28 73 |)stop_y=63;.if(s| 00009f70 74 61 72 74 5f 79 3c 30 29 73 74 61 72 74 5f 79 |tart_y<0)start_y| 00009f80 3d 30 3b 69 66 28 73 74 61 72 74 5f 79 3e 36 33 |=0;if(start_y>63| 00009f90 29 73 74 61 72 74 5f 79 3d 36 33 3b 0a 7d 0a 0a |)start_y=63;.}..| 00009fa0 0a 0a 66 6f 72 28 67 72 69 64 5f 78 3d 73 74 61 |..for(grid_x=sta| 00009fb0 72 74 5f 78 3b 67 72 69 64 5f 78 21 3d 73 74 6f |rt_x;grid_x!=sto| 00009fc0 70 5f 78 3b 67 72 69 64 5f 78 2b 3d 6d 6f 76 65 |p_x;grid_x+=move| 00009fd0 5f 78 29 66 6f 72 28 67 72 69 64 5f 79 3d 73 74 |_x)for(grid_y=st| 00009fe0 61 72 74 5f 79 3b 67 72 69 64 5f 79 21 3d 73 74 |art_y;grid_y!=st| 00009ff0 6f 70 5f 79 3b 67 72 69 64 5f 79 2b 3d 6d 6f 76 |op_y;grid_y+=mov| 0000a000 65 5f 79 29 0a 7b 0a 0a 0a 20 20 69 66 28 21 6f |e_y).{... if(!o| 0000a010 62 6a 65 63 74 73 5b 67 72 69 64 5f 79 5d 5b 67 |bjects[grid_y][g| 0000a020 72 69 64 5f 78 5d 29 63 6f 6e 74 69 6e 75 65 3b |rid_x])continue;| 0000a030 0a 20 20 20 20 20 20 2f 2a 20 41 6e 20 6f 62 6a |. /* An obj| 0000a040 65 63 74 20 68 61 73 20 62 65 65 6e 20 66 6f 75 |ect has been fou| 0000a050 6e 64 20 69 6e 20 74 68 69 73 20 67 72 69 64 20 |nd in this grid | 0000a060 73 71 75 61 72 65 20 79 69 70 70 65 65 21 2a 2f |square yippee!*/| 0000a070 0a 20 20 20 20 20 20 2f 2a 20 69 6e 20 74 68 61 |. /* in tha| 0000a080 74 20 63 61 73 65 20 77 65 20 70 72 6f 63 65 73 |t case we proces| 0000a090 73 20 61 6e 64 20 70 6c 6f 74 20 74 68 65 20 6f |s and plot the o| 0000a0a0 62 6a 65 63 74 20 2a 2f 0a 0a 20 20 20 20 20 20 |bject */.. | 0000a0b0 6f 62 6a 65 63 74 5f 78 3d 28 67 72 69 64 5f 78 |object_x=(grid_x| 0000a0c0 3c 3c 36 29 2b 33 32 3b 0a 20 20 20 20 20 20 6f |<<6)+32;. o| 0000a0d0 62 6a 65 63 74 5f 79 3d 28 67 72 69 64 5f 79 3c |bject_y=(grid_y<| 0000a0e0 3c 36 29 2b 33 32 3b 0a 20 20 20 20 20 20 2f 2a |<6)+32;. /*| 0000a0f0 20 6e 6f 77 20 77 65 20 68 61 76 65 20 74 6f 20 | now we have to | 0000a100 72 6f 74 61 74 65 20 74 68 65 20 6f 62 6a 65 63 |rotate the objec| 0000a110 74 73 20 63 6f 6f 72 64 69 6e 61 74 65 73 20 61 |ts coordinates a| 0000a120 72 6f 75 6e 64 20 74 68 65 20 76 69 65 77 65 72 |round the viewer| 0000a130 20 2a 2f 0a 20 20 20 20 20 20 2f 2a 20 74 6f 20 | */. /* to | 0000a140 65 73 74 61 62 6c 69 73 68 20 77 68 65 72 65 20 |establish where | 0000a150 69 74 20 69 73 20 6f 6e 20 74 68 65 20 76 69 65 |it is on the vie| 0000a160 77 20 70 6c 61 6e 65 20 2c 75 73 69 6e 67 20 73 |w plane ,using s| 0000a170 74 61 6e 64 61 72 64 20 72 6f 74 73 2e 2a 2f 0a |tandard rots.*/.| 0000a180 20 20 20 20 20 20 74 72 61 6e 73 5f 78 3d 28 20 | trans_x=( | 0000a190 28 6f 62 6a 65 63 74 5f 78 2d 76 69 65 77 5f 78 |(object_x-view_x| 0000a1a0 29 2a 63 6f 73 6f 5f 74 61 62 6c 65 5b 76 69 65 |)*coso_table[vie| 0000a1b0 77 5f 61 6e 67 6c 65 5d 2b 28 6f 62 6a 65 63 74 |w_angle]+(object| 0000a1c0 5f 79 2d 76 69 65 77 5f 79 29 2a 0a 20 20 20 20 |_y-view_y)*. | 0000a1d0 20 20 73 69 6e 6f 5f 74 61 62 6c 65 5b 76 69 65 | sino_table[vie| 0000a1e0 77 5f 61 6e 67 6c 65 5d 29 3e 3e 31 36 3b 0a 20 |w_angle])>>16;. | 0000a1f0 20 20 20 20 20 74 72 61 6e 73 5f 7a 3d 28 2d 28 | trans_z=(-(| 0000a200 6f 62 6a 65 63 74 5f 78 2d 76 69 65 77 5f 78 29 |object_x-view_x)| 0000a210 2a 73 69 6e 6f 5f 74 61 62 6c 65 5b 76 69 65 77 |*sino_table[view| 0000a220 5f 61 6e 67 6c 65 5d 2b 28 6f 62 6a 65 63 74 5f |_angle]+(object_| 0000a230 79 2d 76 69 65 77 5f 79 29 2a 0a 20 20 20 20 20 |y-view_y)*. | 0000a240 20 63 6f 73 6f 5f 74 61 62 6c 65 5b 76 69 65 77 | coso_table[view| 0000a250 5f 61 6e 67 6c 65 5d 29 3e 3e 31 36 3b 0a 20 20 |_angle])>>16;. | 0000a260 20 20 20 20 2f 2a 20 6e 6f 77 20 69 66 20 74 68 | /* now if th| 0000a270 65 20 6f 62 6a 65 63 74 20 69 73 20 69 6e 66 72 |e object is infr| 0000a280 6f 6e 74 20 6f 66 20 74 68 65 20 76 69 65 77 65 |ont of the viewe| 0000a290 72 20 77 65 20 67 6f 20 66 75 72 74 68 65 72 20 |r we go further | 0000a2a0 2a 2f 0a 20 20 20 20 20 20 69 66 28 74 72 61 6e |*/. if(tran| 0000a2b0 73 5f 7a 3c 30 29 63 6f 6e 74 69 6e 75 65 3b 20 |s_z<0)continue; | 0000a2c0 2f 2a 20 65 6c 73 65 20 77 65 20 6d 6f 76 65 20 |/* else we move | 0000a2d0 74 6f 20 6e 65 78 74 20 6f 62 6a 65 63 74 20 2a |to next object *| 0000a2e0 2f 0a 0a 20 20 20 20 20 20 20 20 2f 2a 20 77 65 |/.. /* we| 0000a2f0 20 68 61 76 65 20 74 6f 20 77 6f 72 6b 20 6f 75 | have to work ou| 0000a300 74 20 73 63 72 65 65 6e 20 70 6f 73 69 74 69 6f |t screen positio| 0000a310 6e 73 20 6e 6f 77 20 28 61 62 6f 76 65 20 61 6e |ns now (above an| 0000a320 64 20 62 65 6c 6f 77 21 29 20 2a 2f 0a 20 20 20 |d below!) */. | 0000a330 20 20 20 20 20 20 74 65 6d 70 5f 31 3d 28 28 28 | temp_1=(((| 0000a340 56 49 45 57 56 41 52 54 3c 3c 35 29 20 2a 20 72 |VIEWVART<<5) * r| 0000a350 65 63 69 70 5f 74 61 62 6c 65 5b 74 72 61 6e 73 |ecip_table[trans| 0000a360 5f 7a 5d 29 29 3e 3e 31 36 3b 0a 20 20 20 20 20 |_z]))>>16;. | 0000a370 20 20 20 73 63 72 65 65 6e 5f 79 31 3d 31 32 38 | screen_y1=128| 0000a380 2d 74 65 6d 70 5f 31 3b 20 2f 2a 20 31 32 38 20 |-temp_1; /* 128 | 0000a390 61 6e 64 20 31 36 30 20 68 65 72 65 20 69 6e 64 |and 160 here ind| 0000a3a0 69 63 61 74 65 20 6f 72 69 67 69 6e 73 20 61 74 |icate origins at| 0000a3b0 20 74 68 65 2a 2f 0a 20 20 20 20 20 20 20 20 73 | the*/. s| 0000a3c0 63 72 65 65 6e 5f 79 32 3d 31 32 38 2b 74 65 6d |creen_y2=128+tem| 0000a3d0 70 5f 31 3b 20 2f 2a 20 63 65 6e 74 65 72 20 6f |p_1; /* center o| 0000a3e0 66 20 74 68 65 20 73 63 72 65 65 6e 20 6f 66 63 |f the screen ofc| 0000a3f0 6f 75 72 73 65 20 2a 2f 0a 20 20 20 20 20 20 20 |ourse */. | 0000a400 20 2f 2a 20 74 68 65 20 61 62 6f 76 65 20 6c 69 | /* the above li| 0000a410 6e 65 73 20 77 6f 72 6b 73 20 6f 75 74 20 74 68 |nes works out th| 0000a420 65 20 74 6f 70 20 61 6e 64 20 62 6f 74 74 6f 6d |e top and bottom| 0000a430 20 6f 66 20 74 68 65 20 6f 62 6a 65 63 74 20 2a | of the object *| 0000a440 2f 0a 0a 20 20 20 20 20 20 20 20 69 66 28 28 73 |/.. if((s| 0000a450 63 61 6c 65 3d 28 73 63 72 65 65 6e 5f 79 32 2d |cale=(screen_y2-| 0000a460 73 63 72 65 65 6e 5f 79 31 29 29 3e 4d 41 58 5f |screen_y1))>MAX_| 0000a470 53 43 41 4c 45 29 63 6f 6e 74 69 6e 75 65 3b 0a |SCALE)continue;.| 0000a480 0a 20 20 20 20 20 20 20 20 73 63 72 65 65 6e 5f |. screen_| 0000a490 78 3d 31 36 30 20 2b 20 28 20 28 20 56 49 45 57 |x=160 + ( ( VIEW| 0000a4a0 56 41 52 2a 74 72 61 6e 73 5f 78 20 2a 20 72 65 |VAR*trans_x * re| 0000a4b0 63 69 70 5f 74 61 62 6c 65 5b 74 72 61 6e 73 5f |cip_table[trans_| 0000a4c0 7a 5d 29 3e 3e 31 36 29 3b 0a 0a 20 20 20 20 20 |z])>>16);.. | 0000a4d0 20 20 20 69 66 28 73 63 61 6c 65 3e 28 53 43 52 | if(scale>(SCR| 0000a4e0 45 45 4e 5f 48 45 49 47 48 54 29 29 0a 20 20 20 |EEN_HEIGHT)). | 0000a4f0 20 20 20 20 20 7b 0a 0a 20 20 20 20 20 20 20 20 | {.. | 0000a500 20 20 73 63 61 6c 65 3d 53 43 52 45 45 4e 5f 48 | scale=SCREEN_H| 0000a510 45 49 47 48 54 3b 0a 0a 20 20 20 20 20 20 20 20 |EIGHT;.. | 0000a520 7d 0a 20 20 20 20 20 20 20 20 76 61 72 69 61 62 |}. variab| 0000a530 6c 65 73 5b 35 5d 3d 73 63 72 65 65 6e 5f 79 31 |les[5]=screen_y1| 0000a540 3b 0a 20 20 20 20 20 20 20 20 2f 2a 20 61 62 6f |;. /* abo| 0000a550 76 65 20 6c 69 6e 65 20 77 6f 72 6b 73 20 6f 75 |ve line works ou| 0000a560 74 20 73 63 61 6c 65 20 66 72 6f 6d 20 79 31 20 |t scale from y1 | 0000a570 61 6e 64 20 79 32 20 72 65 61 64 79 20 66 6f 72 |and y2 ready for| 0000a580 20 64 72 61 77 69 6e 67 20 2a 2f 0a 20 20 20 20 | drawing */. | 0000a590 20 20 20 20 73 63 72 65 65 6e 5f 78 2d 3d 73 63 | screen_x-=sc| 0000a5a0 61 6c 65 3e 3e 31 3b 0a 20 20 20 20 20 20 20 20 |ale>>1;. | 0000a5b0 2f 2a 20 77 65 20 6f 66 66 73 65 74 20 73 63 72 |/* we offset scr| 0000a5c0 65 65 6e 5f 78 20 73 6f 20 74 68 65 6e 20 77 65 |een_x so then we| 0000a5d0 20 61 72 65 20 61 74 20 74 68 65 20 6c 65 66 74 | are at the left| 0000a5e0 20 6f 66 20 74 68 65 20 6f 62 6a 65 63 74 20 2a | of the object *| 0000a5f0 2f 20 20 20 20 20 20 20 20 20 20 20 20 69 6e 63 |/ inc| 0000a600 72 65 6d 65 6e 74 3d 28 69 6e 74 29 28 72 65 63 |rement=(int)(rec| 0000a610 69 70 5f 74 61 62 6c 65 5b 73 63 61 6c 65 5d 3c |ip_table[scale]<| 0000a620 3c 36 29 3b 0a 20 20 20 20 20 20 20 20 76 61 72 |<6);. var| 0000a630 69 61 62 6c 65 73 5b 33 5d 3d 73 63 61 6c 65 3b |iables[3]=scale;| 0000a640 0a 0a 0a 20 20 20 20 20 20 20 20 20 6f 62 6a 65 |... obje| 0000a650 63 74 5f 74 79 70 65 3d 6f 62 6a 65 63 74 73 5b |ct_type=objects[| 0000a660 67 72 69 64 5f 79 5d 5b 67 72 69 64 5f 78 5d 3b |grid_y][grid_x];| 0000a670 0a 20 20 20 20 20 20 20 20 2f 2a 20 61 62 6f 76 |. /* abov| 0000a680 65 20 6c 69 6e 65 20 70 72 65 70 61 72 65 73 20 |e line prepares | 0000a690 6d 6f 72 65 20 76 61 72 69 61 62 6c 65 73 20 66 |more variables f| 0000a6a0 6f 72 20 74 68 65 20 6f 75 72 6c 69 62 20 66 75 |or the ourlib fu| 0000a6b0 6e 63 74 69 6f 6e 20 20 20 20 2a 2f 0a 20 20 20 |nction */. | 0000a6c0 20 20 20 20 20 2f 2a 20 6e 65 78 74 20 77 65 20 | /* next we | 0000a6d0 73 65 74 20 75 70 20 66 69 78 65 64 20 70 6f 69 |set up fixed poi| 0000a6e0 6e 74 20 73 79 73 74 65 6d 73 20 74 6f 20 69 6e |nt systems to in| 0000a6f0 64 65 78 20 74 68 65 20 6f 62 6a 65 63 74 20 67 |dex the object g| 0000a700 72 61 70 68 69 63 20 2a 2f 0a 20 20 20 20 20 20 |raphic */. | 0000a710 20 20 2f 2a 20 77 68 69 6c 65 20 77 65 20 64 72 | /* while we dr| 0000a720 61 77 20 69 74 2e 20 49 6e 73 74 65 61 64 20 6f |aw it. Instead o| 0000a730 66 20 66 6c 6f 61 74 69 6e 67 20 70 6f 69 6e 74 |f floating point| 0000a740 20 74 68 69 73 20 69 73 20 6f 66 20 63 6f 75 72 | this is of cour| 0000a750 73 65 20 20 2a 2f 0a 20 20 20 20 20 20 20 20 69 |se */. i| 0000a760 6e 64 65 78 3d 30 3b 0a 20 20 20 20 20 20 20 20 |ndex=0;. | 0000a770 2f 2a 20 6e 65 78 74 20 77 65 20 75 73 65 20 61 |/* next we use a| 0000a780 20 63 6f 75 6e 74 65 72 20 74 6f 20 63 6f 75 6e | counter to coun| 0000a790 74 20 69 66 20 77 65 20 68 61 76 65 20 66 69 6e |t if we have fin| 0000a7a0 69 73 68 65 64 20 64 72 61 77 69 6e 67 20 69 74 |ished drawing it| 0000a7b0 2e 20 2a 2f 0a 20 20 20 20 20 20 20 20 63 6f 75 |. */. cou| 0000a7c0 6e 74 65 72 3d 73 63 61 6c 65 3b 0a 20 20 20 20 |nter=scale;. | 0000a7d0 20 20 20 20 2f 2a 20 69 6e 69 74 69 61 6c 69 73 | /* initialis| 0000a7e0 65 20 61 20 6c 6f 6f 70 20 74 6f 20 72 65 6e 64 |e a loop to rend| 0000a7f0 65 72 20 65 61 63 68 20 73 6c 69 76 65 72 20 6f |er each sliver o| 0000a800 6e 65 20 62 79 20 6f 6e 65 20 2a 2f 0a 20 20 20 |ne by one */. | 0000a810 20 20 20 20 20 2f 2a 20 6b 65 65 70 20 67 6f 69 | /* keep goi| 0000a820 6e 67 20 75 6e 74 69 6c 20 6f 66 66 20 74 68 65 |ng until off the| 0000a830 20 73 63 72 65 65 6e 20 6f 72 20 6a 75 73 74 20 | screen or just | 0000a840 66 69 6e 69 73 68 65 64 21 20 2a 2f 0a 0a 20 77 |finished! */.. w| 0000a850 68 69 6c 65 28 73 63 72 65 65 6e 5f 78 3e 2d 36 |hile(screen_x>-6| 0000a860 34 20 26 26 20 73 63 72 65 65 6e 5f 78 3c 33 32 |4 && screen_x<32| 0000a870 30 20 26 26 20 63 6f 75 6e 74 65 72 3e 30 29 0a |0 && counter>0).| 0000a880 20 20 20 20 20 20 20 20 20 20 20 7b 0a 0a 20 20 | {.. | 0000a890 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 63 | /* c| 0000a8a0 68 65 63 6b 20 74 6f 20 73 65 65 20 69 66 20 6f |heck to see if o| 0000a8b0 62 6a 65 63 74 20 69 73 20 69 6e 66 72 6f 6e 74 |bject is infront| 0000a8c0 20 6f 66 20 77 61 6c 6c 2c 20 69 6d 70 6f 72 74 | of wall, import| 0000a8d0 61 6e 74 21 20 2a 2f 0a 20 20 20 20 20 20 20 20 |ant! */. | 0000a8e0 20 20 20 20 20 20 69 66 28 73 63 61 6c 65 3e 73 | if(scale>s| 0000a8f0 63 61 6c 65 5f 61 72 72 61 79 5b 73 63 72 65 65 |cale_array[scree| 0000a900 6e 5f 78 5d 20 26 26 20 73 63 72 65 65 6e 5f 78 |n_x] && screen_x| 0000a910 3e 30 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 |>0). | 0000a920 20 20 20 20 20 20 7b 0a 20 20 20 20 20 20 20 20 | {. | 0000a930 20 20 20 20 20 20 20 20 20 20 2f 2a 20 69 66 20 | /* if | 0000a940 73 6f 20 64 72 61 77 20 74 68 69 73 20 73 6c 69 |so draw this sli| 0000a950 76 65 72 21 20 2a 2f 0a 20 20 20 20 20 20 20 20 |ver! */. | 0000a960 20 20 20 20 20 20 20 20 20 76 61 72 69 61 62 6c | variabl| 0000a970 65 73 5b 31 5d 3d 28 69 6e 74 29 26 6f 62 6a 67 |es[1]=(int)&objg| 0000a980 72 61 70 68 69 63 73 5b 6f 62 6a 65 63 74 5f 74 |raphics[object_t| 0000a990 79 70 65 5d 5b 28 69 6e 74 29 69 6e 64 65 78 3e |ype][(int)index>| 0000a9a0 3e 31 36 5d 3b 0a 0a 20 20 20 20 20 20 20 20 20 |>16];.. | 0000a9b0 20 20 20 20 20 20 20 20 20 76 61 72 69 61 62 6c | variabl| 0000a9c0 65 73 5b 34 5d 3d 73 63 72 65 65 6e 5f 78 3b 0a |es[4]=screen_x;.| 0000a9d0 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |. | 0000a9e0 20 20 6f 75 72 6c 69 62 5f 73 6c 69 76 65 72 5f | ourlib_sliver_| 0000a9f0 6d 61 73 6b 28 76 61 72 69 61 62 6c 65 73 29 3b |mask(variables);| 0000aa00 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |. | 0000aa10 20 20 20 7d 0a 20 20 2f 2a 20 61 64 64 20 6f 6e | }. /* add on| 0000aa20 20 67 72 61 70 68 69 63 20 69 6e 63 72 65 6d 65 | graphic increme| 0000aa30 6e 74 2c 20 64 65 63 72 65 61 73 65 20 63 6f 75 |nt, decrease cou| 0000aa40 6e 74 65 72 20 61 6e 64 20 6d 6f 76 65 20 74 6f |nter and move to| 0000aa50 20 6e 65 78 74 20 63 6f 6c 75 6d 6e 20 2a 2f 20 | next column */ | 0000aa60 20 20 20 20 69 6e 64 65 78 2b 3d 69 6e 63 72 65 | index+=incre| 0000aa70 6d 65 6e 74 3b 0a 20 20 63 6f 75 6e 74 65 72 2d |ment;. counter-| 0000aa80 2d 3b 0a 20 20 73 63 72 65 65 6e 5f 78 2b 2b 3b |-;. screen_x++;| 0000aa90 0a 20 20 20 20 20 20 20 20 20 20 20 7d 0a 0a 0a |. }...| 0000aaa0 7d 0a 2f 2a 20 4f 62 6a 65 63 74 20 43 6f 64 65 |}./* Object Code| 0000aab0 20 4f 56 45 52 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a | OVER **********| 0000aac0 2a 2a 2a 20 43 6f 6e 74 69 6e 75 65 20 61 73 20 |*** Continue as | 0000aad0 6e 6f 72 6d 61 6c 20 2a 2f 0a 2f 2a 20 2a 2a 2a |normal */./* ***| 0000aae0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 20 53 65 65 |************ See| 0000aaf0 20 41 72 74 69 63 6c 65 20 35 20 66 6f 72 20 6d | Article 5 for m| 0000ab00 6f 72 65 20 64 65 74 61 69 6c 73 20 2a 2f 0a 0a |ore details */..| 0000ab10 0a 0a 2f 2a 20 50 48 45 57 21 20 4e 6f 77 20 77 |../* PHEW! Now w| 0000ab20 65 20 63 61 6e 20 77 61 69 74 20 66 6f 72 20 61 |e can wait for a| 0000ab30 20 76 79 73 6e 63 20 61 6e 64 20 74 68 65 6e 20 | vysnc and then | 0000ab40 73 77 69 74 63 68 20 74 68 65 20 76 69 65 77 73 |switch the views| 0000ab50 2f 62 61 6e 6b 73 20 6f 76 65 72 20 6f 74 20 20 |/banks over ot | 0000ab60 70 72 6f 64 75 63 65 20 66 6c 69 63 6b 65 72 2d |produce flicker-| 0000ab70 66 72 65 65 20 61 6e 69 6d 61 74 69 6f 6e 20 2a |free animation *| 0000ab80 2f 0a 0a 6f 75 72 6c 69 62 5f 77 61 69 74 76 73 |/..ourlib_waitvs| 0000ab90 79 6e 63 28 29 3b 0a 6f 75 72 6c 69 62 5f 73 69 |ync();.ourlib_si| 0000aba0 6d 70 6c 65 73 77 69 74 63 68 28 29 3b 0a 0a 2f |mpleswitch();../| 0000abb0 2a 20 57 65 20 61 6c 73 6f 20 68 61 76 65 20 74 |* We also have t| 0000abc0 6f 20 73 77 69 74 63 68 20 74 68 65 20 6d 65 6d |o switch the mem| 0000abd0 6f 72 79 20 61 64 64 72 65 73 73 65 73 20 61 72 |ory addresses ar| 0000abe0 6f 75 6e 64 20 73 6f 20 6f 75 72 20 66 75 6e 63 |ound so our func| 0000abf0 74 69 6f 6e 73 20 64 72 61 77 20 74 6f 20 74 68 |tions draw to th| 0000ac00 65 20 63 6f 72 72 65 63 74 20 6d 65 6d 6f 72 79 |e correct memory| 0000ac10 20 2a 2f 0a 0a 73 63 72 65 65 6e 5f 61 64 64 72 | */..screen_addr| 0000ac20 65 73 73 5f 74 65 6d 70 3d 73 63 72 65 65 6e 5f |ess_temp=screen_| 0000ac30 61 64 64 72 65 73 73 5f 62 61 6e 6b 3b 0a 73 63 |address_bank;.sc| 0000ac40 72 65 65 6e 5f 61 64 64 72 65 73 73 5f 62 61 6e |reen_address_ban| 0000ac50 6b 3d 73 63 72 65 65 6e 5f 61 64 64 72 65 73 73 |k=screen_address| 0000ac60 3b 0a 73 63 72 65 65 6e 5f 61 64 64 72 65 73 73 |;.screen_address| 0000ac70 3d 73 63 72 65 65 6e 5f 61 64 64 72 65 73 73 5f |=screen_address_| 0000ac80 74 65 6d 70 3b 0a 0a 2f 2a 20 61 64 64 20 6f 6e |temp;../* add on| 0000ac90 65 20 74 6f 20 74 68 65 20 66 72 61 6d 65 73 20 |e to the frames | 0000aca0 63 6f 75 6e 74 2c 20 77 65 20 61 72 65 20 63 6f |count, we are co| 0000acb0 75 6e 74 69 6e 67 20 74 68 65 20 6e 75 6d 62 65 |unting the numbe| 0000acc0 72 20 6f 66 20 66 72 61 6d 65 73 20 67 65 6e 65 |r of frames gene| 0000acd0 72 61 74 65 64 20 20 2a 2f 0a 66 72 61 6d 65 73 |rated */.frames| 0000ace0 2b 2b 3b 0a 0a 7d 0a 2f 2a 20 72 65 63 6f 72 64 |++;..}./* record| 0000acf0 20 74 68 65 20 74 69 6d 65 20 73 74 6f 70 70 65 | the time stoppe| 0000ad00 64 20 2a 2f 0a 0a 74 69 6d 65 5f 66 69 6e 69 73 |d */..time_finis| 0000ad10 68 3d 6f 75 72 6c 69 62 5f 67 65 74 74 69 6d 65 |h=ourlib_gettime| 0000ad20 28 29 3b 0a 0a 2f 2a 20 74 61 6b 65 20 61 20 73 |();../* take a s| 0000ad30 63 72 65 65 6e 73 68 6f 74 2c 20 75 73 69 6e 67 |creenshot, using| 0000ad40 20 2a 73 63 72 65 65 6e 20 73 61 76 65 2c 20 61 | *screen save, a| 0000ad50 6e 64 20 73 61 76 65 20 69 74 20 69 6e 73 69 64 |nd save it insid| 0000ad60 65 20 74 68 65 20 64 69 72 65 63 74 6f 72 79 20 |e the directory | 0000ad70 2a 2f 0a 0a 73 79 73 74 65 6d 28 22 2a 53 63 72 |*/..system("*Scr| 0000ad80 65 65 6e 53 61 76 65 20 3c 41 55 41 52 61 79 24 |eenSave <AUARay$| 0000ad90 44 69 72 3e 2e 73 63 72 73 68 6f 74 22 29 3b 0a |Dir>.scrshot");.| 0000ada0 69 66 28 44 45 4d 4f 5f 52 45 41 44 20 7c 7c 20 |if(DEMO_READ || | 0000adb0 44 45 4d 4f 5f 57 52 49 54 45 29 66 63 6c 6f 73 |DEMO_WRITE)fclos| 0000adc0 65 28 64 65 6d 6f 5f 66 69 6c 65 29 3b 0a 2f 2a |e(demo_file);./*| 0000add0 20 63 6c 6f 73 65 20 64 6f 77 6e 20 74 68 65 20 | close down the | 0000ade0 73 63 72 65 65 6e 73 20 75 73 69 6e 67 20 61 6e |screens using an| 0000adf0 20 6f 75 72 6c 69 62 20 66 75 6e 63 74 69 6f 6e | ourlib function| 0000ae00 20 2a 2f 0a 0a 6f 75 72 6c 69 62 5f 63 6c 6f 73 | */..ourlib_clos| 0000ae10 65 64 6f 77 6e 5f 73 63 72 65 65 6e 73 28 29 3b |edown_screens();| 0000ae20 0a 0a 2f 2a 20 63 68 61 6e 67 65 20 74 6f 20 6d |../* change to m| 0000ae30 6f 64 65 20 31 35 20 61 6e 64 20 62 72 69 6e 67 |ode 15 and bring| 0000ae40 20 62 61 63 6b 20 74 68 65 20 63 75 72 73 6f 72 | back the cursor| 0000ae50 20 6a 75 73 74 20 69 6e 20 63 61 73 65 20 2a 2f | just in case */| 0000ae60 0a 0a 6f 75 72 6c 69 62 5f 63 68 61 6e 67 65 6d |..ourlib_changem| 0000ae70 6f 64 65 28 31 35 29 3b 0a 6f 75 72 6c 69 62 5f |ode(15);.ourlib_| 0000ae80 72 65 76 69 76 65 63 75 72 73 6f 72 28 29 3b 0a |revivecursor();.| 0000ae90 0a 2f 2a 20 70 72 69 6e 74 20 74 68 65 20 63 61 |./* print the ca| 0000aea0 6c 63 75 6c 61 74 69 6f 6e 20 61 6e 64 20 6f 74 |lculation and ot| 0000aeb0 68 65 72 20 69 6e 66 6f 2e 20 2a 2f 0a 70 72 69 |her info. */.pri| 0000aec0 6e 74 66 28 22 2a 2a 2a 2a 2a 2a 2a 20 46 52 41 |ntf("******* FRA| 0000aed0 4d 45 53 20 50 45 52 20 53 45 43 4f 4e 44 20 2a |MES PER SECOND *| 0000aee0 2a 2a 2a 2a 2a 2a 2a 5c 6e 25 66 22 2c 28 66 6c |*******\n%f",(fl| 0000aef0 6f 61 74 29 66 72 61 6d 65 73 2f 28 66 6c 6f 61 |oat)frames/(floa| 0000af00 74 29 28 28 74 69 6d 65 5f 66 69 6e 69 73 68 2d |t)((time_finish-| 0000af10 74 69 6d 65 5f 73 74 61 72 74 29 2f 31 30 30 29 |time_start)/100)| 0000af20 29 3b 0a 0a 7d 0a 0a |);..}..| 0000af27