Skip to content

Commit

Permalink
Prevent air going through walls in cases of extreme velocity
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonmj committed Jan 26, 2014
1 parent 216b336 commit 09e7418
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions src/simulation/Air.cpp
Expand Up @@ -131,6 +131,9 @@ 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

Expand Down Expand Up @@ -232,8 +235,51 @@ void Air::update_air(void)
dp += pv[y][x]*f;
}

tx = x - dx*0.7f;
ty = y - dy*0.7f;
if (dx*advDistanceMult<=1.0f && dy*advDistanceMult<=1.0f)
{
tx = x - dx*advDistanceMult;
ty = y - dy*advDistanceMult;
}
else if (bmap_blockair[y][x])
{
tx = x;
ty = y;
}
else
{
// Trying to take velocity from far away, check whether there is an intervening wall. Step from current position to desired source location, looking for walls, with either the x or y step size being 1 cell
if (abs(dx)>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<stepLimit; ++step)
{
tx += stepX;
ty += stepY;
if (bmap_blockair[(int)(ty+0.5f)][(int)(tx+0.5f)])
{
tx -= stepX;
ty -= stepY;
break;
}
}
if (step==stepLimit)
{
// No wall found
tx = x - dx*advDistanceMult;
ty = y - dy*advDistanceMult;
}
}
i = (int)tx;
j = (int)ty;
tx -= i;
Expand Down

0 comments on commit 09e7418

Please sign in to comment.