#include "Air.h" #include #include #include "Simulation.h" #include "ElementClasses.h" #include "common/tpt-rand.h" /*float kernel[9]; float vx[YRES/CELL][XRES/CELL], ovx[YRES/CELL][XRES/CELL]; float vy[YRES/CELL][XRES/CELL], ovy[YRES/CELL][XRES/CELL]; float pv[YRES/CELL][XRES/CELL], opv[YRES/CELL][XRES/CELL]; unsigned char bmap_blockair[YRES/CELL][XRES/CELL]; float cb_vx[YRES/CELL][XRES/CELL]; float cb_vy[YRES/CELL][XRES/CELL]; float cb_pv[YRES/CELL][XRES/CELL]; float cb_hv[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 Air::make_kernel(void) //used for velocity { int i, j; float s = 0.0f; for (j=-1; j<2; j++) for (i=-1; i<2; i++) { kernel[(i+1)+3*(j+1)] = expf(-2.0f*(i*i+j*j)); s += kernel[(i+1)+3*(j+1)]; } s = 1.0f / s; for (j=-1; j<2; j++) for (i=-1; i<2; i++) kernel[(i+1)+3*(j+1)] *= s; } void Air::Clear() { std::fill(&pv[0][0], &pv[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f); std::fill(&vy[0][0], &vy[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f); std::fill(&vx[0][0], &vx[0][0]+((XRES/CELL)*(YRES/CELL)), 0.0f); } void Air::ClearAirH() { std::fill(&hv[0][0], &hv[0][0]+((XRES/CELL)*(YRES/CELL)), ambientAirTemp); } void Air::update_airh(void) { int x, y, i, j; float odh, dh, dx, dy, f, tx, ty; for (i=0; i0 && y+j0 && x+i=2 && i=2 && j0 && !(bmap_blockairh[y-1][x]&0x8)) vy[y][x] -= airdiff/5000.0f; } ohv[y][x] = dh; } } memcpy(hv, ohv, sizeof(hv)); } void Air::update_air(void) { int x = 0, y = 0, i = 0, j = 0; float dp = 0.0f, dx = 0.0f, dy = 0.0f, f = 0.0f, tx = 0.0f, ty = 0.0f; const float advDistanceMult = 0.7f; float stepX, stepY; int stepLimit, step; if (airMode != 4) { //airMode 4 is no air/pressure update for (i=0; i0 && y+j0 && x+i1.0f || dy*advDistanceMult>1.0f) && (tx>=2 && tx=2 && tystd::abs(dy)) { stepX = (dx<0.0f) ? 1 : -1; stepY = -dy/fabsf(dx); stepLimit = (int)(fabsf(dx*advDistanceMult)); } else { stepY = (dy<0.0f) ? 1 : -1; stepX = -dx/fabsf(dy); stepLimit = (int)(fabsf(dy*advDistanceMult)); } tx = x; ty = y; for (step=0; step=2 && i<=XRES/CELL-3 && j>=2 && j<=YRES/CELL-3) { dx *= 1.0f - AIR_VADV; dy *= 1.0f - AIR_VADV; dx += AIR_VADV*(1.0f-tx)*(1.0f-ty)*vx[j][i]; dy += AIR_VADV*(1.0f-tx)*(1.0f-ty)*vy[j][i]; dx += AIR_VADV*tx*(1.0f-ty)*vx[j][i+1]; dy += AIR_VADV*tx*(1.0f-ty)*vy[j][i+1]; dx += AIR_VADV*(1.0f-tx)*ty*vx[j+1][i]; dy += AIR_VADV*(1.0f-tx)*ty*vy[j+1][i]; dx += AIR_VADV*tx*ty*vx[j+1][i+1]; dy += AIR_VADV*tx*ty*vy[j+1][i+1]; } if (bmap[y][x] == WL_FAN) { dx += fvx[y][x]; dy += fvy[y][x]; } // pressure/velocity caps if (dp > 256.0f) dp = 256.0f; if (dp < -256.0f) dp = -256.0f; if (dx > 256.0f) dx = 256.0f; if (dx < -256.0f) dx = -256.0f; if (dy > 256.0f) dy = 256.0f; if (dy < -256.0f) dy = -256.0f; switch (airMode) { default: case 0: //Default break; case 1: //0 Pressure dp = 0.0f; break; case 2: //0 Velocity dx = 0.0f; dy = 0.0f; break; case 3: //0 Air dx = 0.0f; dy = 0.0f; dp = 0.0f; break; case 4: //No Update break; } ovx[y][x] = dx; ovy[y][x] = dy; opv[y][x] = dp; } memcpy(vx, ovx, sizeof(vx)); memcpy(vy, ovy, sizeof(vy)); memcpy(pv, opv, sizeof(pv)); } } void Air::Invert() { int nx, ny; for (nx = 0; nx