From: John Tsiombikas Date: Thu, 13 Aug 2020 00:06:47 +0000 (+0300) Subject: more efficient mountain drawing X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=commitdiff_plain;h=6bb6e7b35b1f10eb26fcd46f2b45af0afa782a1f more efficient mountain drawing --- diff --git a/src/scr/cybersun.c b/src/scr/cybersun.c index e150cab..fde29ab 100644 --- a/src/scr/cybersun.c +++ b/src/scr/cybersun.c @@ -39,7 +39,10 @@ static struct g3d_mesh gmesh; #define GMESH_SIZE 128 static struct image gtex; -static struct image mounttex; +#define MOUNTIMG_WIDTH 512 +#define MOUNTIMG_HEIGHT 64 +static struct image mountimg; +static int mountimg_skip[MOUNTIMG_WIDTH]; static long part_start; @@ -63,11 +66,24 @@ static int init(void) if(load_image(>ex, "data/pgrid.png") == -1) { return -1; } - if(load_image(&mounttex, "data/cybmount.png") == -1) { + if(load_image(&mountimg, "data/cybmount.png") == -1) { return -1; } - assert(mounttex.width == 512); - assert(mounttex.height == 64); + assert(mountimg.width == MOUNTIMG_WIDTH); + assert(mountimg.height == MOUNTIMG_HEIGHT); + + for(i=0; i= FB_HEIGHT) { + /* TODO draw gradient for the sky */ + return; + } + if(horizon_y < 0) { + memset(fb_pixels, 0, FB_WIDTH * FB_HEIGHT * 2); + return; + } for(i=0; i> 8) & 0x1ff); - - for(j=0; j<64; j++) { - if(j + y >= FB_HEIGHT) break; - if(j + y >= 0) { - int32_t col = sptr[j << 9]; - if(col != 0x7e0) { - dptr[j * FB_WIDTH] = col; - } - } + int skip = mountimg_skip[(x >> 8) & 0x1ff]; + int vspan = MOUNTIMG_HEIGHT - skip; + + dptr = fb_pixels + (y + skip) * FB_WIDTH + i; + + for(j=0; j