diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2011-06-01 19:18:19 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2011-06-01 19:18:19 (GMT) |
| commit | c003fee63ee63d5bc5194349fe262db101c17e1f (patch) | |
| tree | a5eb45fc8d1c49b0764ae6b9c4e9341162b0c7ef /src | |
| parent | 3d600c69558b4b3e3f05b860531942f1ea2cd1c1 (diff) | |
| download | powder-c003fee63ee63d5bc5194349fe262db101c17e1f.zip powder-c003fee63ee63d5bc5194349fe262db101c17e1f.tar.gz | |
Ambient heat (disabled by default)
Diffstat (limited to 'src')
| -rw-r--r-- | src/air.c | 51 | ||||
| -rw-r--r-- | src/graphics.c | 13 | ||||
| -rw-r--r-- | src/main.c | 9 | ||||
| -rw-r--r-- | src/powder.c | 13 |
4 files changed, 82 insertions, 4 deletions
@@ -23,6 +23,8 @@ float cb_pv[YRES/CELL][XRES/CELL], cb_opv[YRES/CELL][XRES/CELL]; float fvx[YRES/CELL][XRES/CELL], fvy[YRES/CELL][XRES/CELL]; +float hv[YRES/CELL][XRES/CELL], ohv[YRES/CELL][XRES/CELL]; // For Ambient Heat + void make_kernel(void) //used for velocity { int i, j; @@ -38,6 +40,55 @@ void make_kernel(void) //used for velocity for (i=-1; i<2; i++) kernel[(i+1)+3*(j+1)] *= s; } +void update_airh(void) +{ + int x, y, i, j; + float dh, dp, f, tx, ty; + for (i=0; i<YRES/CELL; i++) //reduces pressure/velocity on the edges every frame + { + hv[i][0] = 295.15f; + hv[i][1] = 295.15f; + hv[i][XRES/CELL-3] = 295.15f; + hv[i][XRES/CELL-2] = 295.15f; + hv[i][XRES/CELL-1] = 295.15f; + } + for (i=0; i<XRES/CELL; i++) //reduces pressure/velocity on the edges every frame + { + hv[0][i] = 295.15f; + hv[1][i] = 295.15f; + hv[YRES/CELL-3][i] = 295.15f; + hv[YRES/CELL-2][i] = 295.15f; + hv[YRES/CELL-1][i] = 295.15f; + } + for (y=0; y<YRES/CELL; y++) //update velocity and pressure + for (x=0; x<XRES/CELL; x++) + { + dh = 0.0f; + for (j=-1; j<2; j++) + for (i=-1; i<2; i++) + if (y+j>0 && y+j<YRES/CELL-2 && + x+i>0 && x+i<XRES/CELL-2 && + bmap[y+j][x+i]!=WL_WALL && + bmap[y+j][x+i]!=WL_WALLELEC && + (bmap[y+j][x+i]!=WL_EWALL || emap[y+j][x+i])) + { + f = kernel[i+1+(j+1)*3]; + dh += hv[y+j][x+i]*f; + } + else + { + f = kernel[i+1+(j+1)*3]; + dh += hv[y][x]*f; + } + i = (int)tx; + j = (int)ty; + tx -= i; + ty -= j; + ohv[y][x] = dh; + } + memcpy(hv, ohv, sizeof(hv)); +} + void update_grav(void) { int x, y, i, j, changed = 0; diff --git a/src/graphics.c b/src/graphics.c index 93edd41..9974720 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1234,8 +1234,17 @@ void draw_air(pixel *vid) else if (cmode == CM_VEL) { c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red - clamp_flt(pv[y][x], 0.0f, 8.0f),//pressure adds green - clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue + clamp_flt(pv[y][x], 0.0f, 8.0f),//pressure adds green + clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue + } + else if (cmode == CM_HEAT && aheat_enable) + { + float ttemp = hv[y][x]+(-MIN_TEMP); + int caddress = restrict_flt((int)( restrict_flt(ttemp, 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3); + c = PIXRGB((unsigned char)color_data[caddress], (unsigned char)color_data[caddress+1], (unsigned char)color_data[caddress+2]); + //c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red + // clamp_flt(hv[y][x], 0.0f, 1600.0f),//heat adds green + // clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue } else if (cmode == CM_CRACK) { @@ -176,6 +176,7 @@ int sys_pause = 0; int sys_shortcuts = 1; int legacy_enable = 0; //Used to disable new features such as heat, will be set by save. int ngrav_enable = 0; //Newtonian gravity, will be set by save +int aheat_enable; //Ambient heat int decorations_enable = 1; int death = 0, framerender = 0; int amd = 1; @@ -1747,11 +1748,13 @@ int main(int argc, char *argv[]) if (!sys_pause||framerender) //only update air if not paused { update_air(); + if(aheat_enable) + update_airh(); } #ifdef OpenGL ClearScreen(); #else - if (cmode==CM_VEL || cmode==CM_PRESS || cmode==CM_CRACK)//air only gets drawn in these modes + if (cmode==CM_VEL || cmode==CM_PRESS || cmode==CM_CRACK || (cmode==CM_HEAT && aheat_enable))//air only gets drawn in these modes { draw_air(vid_buf); } @@ -1778,7 +1781,7 @@ int main(int argc, char *argv[]) if(ngrav_enable) draw_grav(vid_buf); - draw_walls(vid_buf); + draw_walls(vid_buf); update_particles(vid_buf); //update everything draw_parts(vid_buf); //draw particles @@ -2277,6 +2280,8 @@ int main(int argc, char *argv[]) VINE_MODE = !VINE_MODE; if (sdl_key==SDLK_SPACE) sys_pause = !sys_pause; + if (sdl_key=='u') + aheat_enable = !aheat_enable; if (sdl_key=='h') hud_enable = !hud_enable; if (sdl_key=='p') diff --git a/src/powder.c b/src/powder.c index cdff223..c7354bc 100644 --- a/src/powder.c +++ b/src/powder.c @@ -1614,6 +1614,19 @@ void update_particles_i(pixel *vid, int start, int inc) h_count = 0; if (t&&(t!=PT_HSWC||parts[i].life==10)&&ptypes[t].hconduct>(rand()%250)) { + if (aheat_enable) + { + if (hv[y/CELL][x/CELL] < parts[i].temp) + { + hv[y/CELL][x/CELL] = hv[y/CELL][x/CELL] + parts[i].temp*0.04; + parts[i].temp = parts[i].temp - hv[y/CELL][x/CELL]*0.04; + } + else + { + hv[y/CELL][x/CELL] = hv[y/CELL][x/CELL] - parts[i].temp*0.04; + parts[i].temp = parts[i].temp + hv[y/CELL][x/CELL]*0.04; + } + } for (j=0; j<8; j++) { surround_hconduct[j] = i; |
