Slight speed improvement for liquids and powders

This commit is contained in:
jacksonmj 2011-04-27 19:02:27 +01:00 committed by Simon Robertshaw
parent 7543a3d05e
commit ddaed2ad69

View File

@ -1935,38 +1935,48 @@ killed:
}
else
{
s = 1;
r = (rand()%2)*2-1;
if (fin_y!=clear_y && try_move(i, x, y, clear_x+r, fin_y))
if (clear_x!=x || clear_y!=y || nt || surround_space)
{
parts[i].x = clear_xf+r;
parts[i].y = fin_yf;
parts[i].vx *= ptypes[t].collision;
parts[i].vy *= ptypes[t].collision;
// allow diagonal movement if target position is blocked
// but no point trying this if particle is stuck in a block of identical particles
if (fin_y!=clear_y && try_move(i, x, y, clear_x+r, fin_y))
{
parts[i].x = clear_xf+r;
parts[i].y = fin_yf;
parts[i].vx *= ptypes[t].collision;
parts[i].vy *= ptypes[t].collision;
}
else if (fin_y!=clear_y && try_move(i, x, y, clear_x-r, fin_y))
{
parts[i].x = clear_xf-r;
parts[i].y = fin_yf;
parts[i].vx *= ptypes[t].collision;
parts[i].vy *= ptypes[t].collision;
}
else if (fin_x!=clear_x && try_move(i, x, y, fin_x, clear_y+r))
{
parts[i].x = fin_xf;
parts[i].y = clear_yf+r;
parts[i].vx *= ptypes[t].collision;
parts[i].vy *= ptypes[t].collision;
}
else if (fin_x!=clear_x && try_move(i, x, y, fin_x, clear_y-r))
{
parts[i].x = fin_xf;
parts[i].y = clear_yf-r;
parts[i].vx *= ptypes[t].collision;
parts[i].vy *= ptypes[t].collision;
}
else s = 0;
}
else if (fin_y!=clear_y && try_move(i, x, y, clear_x-r, fin_y))
{
parts[i].x = clear_xf-r;
parts[i].y = fin_yf;
parts[i].vx *= ptypes[t].collision;
parts[i].vy *= ptypes[t].collision;
}
else if (fin_x!=clear_x && try_move(i, x, y, fin_x, clear_y+r))
{
parts[i].x = fin_xf;
parts[i].y = clear_yf+r;
parts[i].vx *= ptypes[t].collision;
parts[i].vy *= ptypes[t].collision;
}
else if (fin_x!=clear_x && try_move(i, x, y, fin_x, clear_y-r))
{
parts[i].x = fin_xf;
parts[i].y = clear_yf-r;
parts[i].vx *= ptypes[t].collision;
parts[i].vy *= ptypes[t].collision;
}
else if (ptypes[t].falldown>1 && (parts[i].vy>fabs(parts[i].vx) || gravityMode==2))
else s = 0;
// s==0 means particle has not yet moved, allow liquids code to run
if (s==0 && ptypes[t].falldown>1 && (parts[i].vy>fabs(parts[i].vx) || gravityMode==2))
{
s = 0;
// rt is true if FLAG_STAGNANT was set for this particle in previous frame
if (!rt || nt) //nt is if there is an something else besides the current particle type, around the particle
rt = 30;//slight less water lag, although it changes how it moves a lot
else