eobish

diff src/rend.c @ 5:0baf4e98315e

depth cueing
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 19 Jan 2015 02:32:01 +0200
parents ce0548d24918
children
line diff
     1.1 --- a/src/rend.c	Sun Jan 18 13:30:30 2015 +0200
     1.2 +++ b/src/rend.c	Mon Jan 19 02:32:01 2015 +0200
     1.3 @@ -1,5 +1,6 @@
     1.4  #include <stdlib.h>
     1.5  #include <string.h>
     1.6 +#include <assert.h>
     1.7  #include "rend.h"
     1.8  #include "player.h"
     1.9  
    1.10 @@ -39,7 +40,7 @@
    1.11  	int i, j, dx, dy, backz, clear_start, clear_end;
    1.12  	char cells[3][MAX_Z + 1];
    1.13  	struct tileset *ts = &lvl->tileset;
    1.14 -	struct tile *tile_ceil, *tile_floor;
    1.15 +	struct tile *tile;
    1.16  
    1.17  	dx = pdir == DIR_EAST ? 1 : (pdir == DIR_WEST ? -1 : 0);
    1.18  	dy = pdir == DIR_NORTH ? -1 : (pdir == DIR_SOUTH ? 1 : 0);
    1.19 @@ -57,14 +58,28 @@
    1.20  	}
    1.21  
    1.22  	/* draw floor and ceiling */
    1.23 -	tile_ceil = get_tile(ts, "ceil");
    1.24 -	tile_floor = get_tile(ts, "floor");
    1.25 +	clear_start = 0;
    1.26 +	clear_end = fb.ysz;
    1.27  
    1.28 -	clear_start = tile_ceil ? tile_ceil->orig_y + tile_ceil->img.ysz : 0;
    1.29 -	clear_end = tile_floor ? tile_floor->orig_y : fb.ysz;
    1.30 +	for(i=0; i<MAX_Z; i++) {
    1.31 +		if((tile = get_tilef(ts, "ccs%d", i))) { /* ceil-center-solid-<z> */
    1.32 +			draw_tile(tile);
    1.33  
    1.34 -	draw_tile(tile_ceil);
    1.35 -	draw_tile(tile_floor);
    1.36 +			if(i == MAX_Z - 1) {
    1.37 +				clear_start = tile->orig_y + tile->img.ysz;
    1.38 +			}
    1.39 +		}
    1.40 +
    1.41 +		if((tile = get_tilef(ts, "fcs%d", i))) { /* floor-center-solid-<z> */
    1.42 +			draw_tile(tile);
    1.43 +			if(i == MAX_Z - 1) {
    1.44 +				clear_end = tile->orig_y;
    1.45 +			}
    1.46 +		}
    1.47 +	}
    1.48 +	assert(clear_end >= clear_start);
    1.49 +
    1.50 +	/* fill the area between floor an ceiling with black */
    1.51  	memset(fb.pixels + clear_start * fb.xsz, 0, (clear_end - clear_start) * fb.xsz);
    1.52  
    1.53  	/* find where the back wall should go if it is within visual range
    1.54 @@ -73,21 +88,17 @@
    1.55  	backz = -1;
    1.56  	for(i=1; i<MAX_Z + 1; i++) {
    1.57  		if(cells[CENTER][i] == '#') {
    1.58 -			char name[] = "wcs ";	/* wall-center-solid */
    1.59  			backz = i;
    1.60 -			name[CHR_Z] = backz + '0' - 1;
    1.61 -			draw_tile(get_tile(ts, name));
    1.62 +			draw_tile(get_tilef(ts, "wcs%d", backz - 1)); /* wall-center-solid */
    1.63  			break;
    1.64  		}
    1.65  	}
    1.66  	if(backz == -1) {
    1.67 -		char name[] = "wco ";	/* wall-center-open */
    1.68  		backz = MAX_Z;
    1.69 -		name[CHR_Z] = backz + '0' - 1;
    1.70 -		draw_tile(get_tile(ts, name));
    1.71 +		draw_tile(get_tilef(ts, "wco%d", backz - 1));	/* wall-center-open */
    1.72  	}
    1.73  
    1.74 -	/* now render back to front */
    1.75 +	/* now render the walls back to front */
    1.76  	for(i=0; i<backz; i++) {
    1.77  		int z = backz - i - 1;
    1.78  		char name[] = "w---";	/* wall-<side>-<state>-<z> */