From ddaed2ad6951b212d44e5752b11c08dcf80c76c0 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Wed, 27 Apr 2011 19:02:27 +0100 Subject: [PATCH] Slight speed improvement for liquids and powders --- src/powder.c | 64 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/src/powder.c b/src/powder.c index 54d9e3dd2..533fc4962 100644 --- a/src/powder.c +++ b/src/powder.c @@ -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