From db91bd37f03a1a195a6bfc97235b7d08026d1193 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Tue, 15 Mar 2011 15:28:32 +0000 Subject: [PATCH] Display photon wavelengths in HUD --- includes/graphics.h | 2 +- src/graphics.c | 30 ++++++++++++++++++++++++++++++ src/main.c | 11 ++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/includes/graphics.h b/includes/graphics.h index 4d4d438fb..b7bfdfa66 100644 --- a/includes/graphics.h +++ b/includes/graphics.h @@ -121,7 +121,7 @@ void xor_line(int x1, int y1, int x2, int y2, pixel *vid); void xor_rect(pixel *vid, int x, int y, int w, int h); void draw_parts(pixel *vid); - +void draw_wavelengths(pixel *vid, int x, int y, int h, int wl); void render_signs(pixel *vid_buf); void render_fire(pixel *dst); diff --git a/src/graphics.c b/src/graphics.c index 90e81b0af..ddb836898 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -2925,6 +2925,36 @@ void draw_parts(pixel *vid) } +void draw_wavelengths(pixel *vid, int x, int y, int h, int wl) +{ + fillrect(vid,x-1,y-1,30+1,h+1,64,64,64,255); // coords -1 size +1 to work around bug in fillrect - TODO: fix fillrect + int i,cr,cg,cb,j; + int tmp; + for (i=0;i<30;i++) + { + if ((wl>>i)&1) + { + // Need a spread of wavelengths to get a smooth spectrum, 5 bits seems to work reasonably well + if (i>2) tmp = 0x1F << (i-2); + else tmp = 0x1F >> (2-i); + cg = 0; + cb = 0; + cr = 0; + for (j=0; j<12; j++) { + cr += (tmp >> (j+18)) & 1; + cb += (tmp >> j) & 1; + } + for (j=0; j<14; j++) + cg += (tmp >> (j+9)) & 1; + tmp = 624/(cr+cg+cb+1); + cr *= tmp; + cg *= tmp; + cb *= tmp; + for (j=0;j255?255:cr,cg>255?255:cg,cb>255?255:cb,255); + } + } +} + void render_signs(pixel *vid_buf) { int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq; diff --git a/src/main.c b/src/main.c index 82c942903..845277c75 100644 --- a/src/main.c +++ b/src/main.c @@ -1204,6 +1204,7 @@ int main(int argc, char *argv[]) #ifdef INTERNAL int vs = 0; #endif + int wavelength_gfx = 0; int x, y, b = 0, sl=1, sr=0, su=0, c, lb = 0, lx = 0, ly = 0, lm = 0;//, tx, ty; int da = 0, db = 0, it = 2047, mx, my, bsx = 2, bsy = 2; float nfvx, nfvy; @@ -1954,7 +1955,7 @@ int main(int argc, char *argv[]) if (DEBUG_MODE) { int tctype = parts[cr>>8].ctype; - if (tctype>=PT_NUM) + if (tctype>=PT_NUM || (cr&0xFF)==PT_PHOT) tctype = 0; sprintf(heattext, "%s (%s), Pressure: %3.2f, Temp: %4.2f C, Life: %d", ptypes[cr&0xFF].name, ptypes[tctype].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life); sprintf(coordtext, "#%d, X:%d Y:%d", cr>>8, x/sdl_scale, y/sdl_scale); @@ -1965,6 +1966,7 @@ int main(int argc, char *argv[]) sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C", ptypes[cr&0xFF].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f); #endif } + if ((cr&0xFF)==PT_PHOT) wavelength_gfx = parts[cr>>8].ctype; } else { @@ -2692,6 +2694,8 @@ int main(int argc, char *argv[]) fillrect(vid_buf, XRES-20-textwidth(coordtext), 280, textwidth(coordtext)+8, 13, 0, 0, 0, 140); drawtext(vid_buf, XRES-16-textwidth(coordtext), 282, coordtext, 255, 255, 255, 200); } + if (wavelength_gfx) + draw_wavelengths(vid_buf,XRES-20-textwidth(heattext),265,2,wavelength_gfx); } else { @@ -2702,6 +2706,8 @@ int main(int argc, char *argv[]) fillrect(vid_buf, 12, 280, textwidth(coordtext)+8, 13, 0, 0, 0, 140); drawtext(vid_buf, 16, 282, coordtext, 255, 255, 255, 200); } + if (wavelength_gfx) + draw_wavelengths(vid_buf,12,265,2,wavelength_gfx); } } else @@ -2713,7 +2719,10 @@ int main(int argc, char *argv[]) fillrect(vid_buf, XRES-20-textwidth(coordtext), 26, textwidth(coordtext)+8, 11, 0, 0, 0, 140); drawtext(vid_buf, XRES-16-textwidth(coordtext), 27, coordtext, 255, 255, 255, 200); } + if (wavelength_gfx) + draw_wavelengths(vid_buf,XRES-20-textwidth(heattext),11,2,wavelength_gfx); } + wavelength_gfx = 0; fillrect(vid_buf, 12, 12, textwidth(uitext)+8, 15, 0, 0, 0, 140); drawtext(vid_buf, 16, 16, uitext, 32, 216, 255, 200);