From 636b1db4d231e0d9f1815ddb74abd97b64b1d3ba Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sat, 18 Jun 2011 14:48:00 +0100 Subject: [PATCH] Better liquids movement in radial/Newtonian gravity --- src/powder.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 2 deletions(-) diff --git a/src/powder.c b/src/powder.c index afb1591aa..917f9bf17 100644 --- a/src/powder.c +++ b/src/powder.c @@ -2109,9 +2109,8 @@ killed: goto movedone; } } - if (ptypes[t].falldown>1 && (parts[i].vy>fabsf(parts[i].vx) || gravityMode==2)) + if (ptypes[t].falldown>1 && !ngrav_enable && gravityMode==0 && parts[i].vy>fabsf(parts[i].vx)) { - // TODO: rewrite to operate better with radial gravity s = 0; // stagnant is true if FLAG_STAGNANT was set for this particle in previous frame if (!stagnant || nt) //nt is if there is an something else besides the current particle type, around the particle @@ -2155,6 +2154,106 @@ killed: parts[i].vx *= ptypes[t].collision; parts[i].vy *= ptypes[t].collision; } + else if (ptypes[t].falldown>1 && fabsf(pGravX*parts[i].vx+pGravY*parts[i].vy)>fabsf(pGravY*parts[i].vx+pGravX*parts[i].vy)) + { + float nxf, nyf, ptGrav = ptypes[t].gravity; + s = 0; + // stagnant is true if FLAG_STAGNANT was set for this particle in previous frame + if (!stagnant || 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 + rt = 10; + nxf = clear_xf; + nyf = clear_yf; + for (j=0;jfabsf(pGravX)) + mv = fabsf(pGravY); + else + mv = fabsf(pGravX); + if (mv<0.0001f) break; + pGravX /= mv; + pGravY /= mv; + nxf += r*pGravY; + nyf -= r*pGravX; + nx = (int)(nxf+0.5f); + ny = (int)(nyf+0.5f); + if (nx<0 || ny<0 || nx>=XRES || ny >=YRES) + break; + if ((pmap[ny][nx]&0xFF)!=t || bmap[ny/CELL][nx/CELL]) + { + s = do_move(i, x, y, nxf, nyf); + if (s || bmap[ny/CELL][nx/CELL]!=WL_STREAM) + break; + } + } + if (s==1) + { + clear_x = nx; + clear_y = ny; + for (j=0;jfabsf(pGravX)) + mv = fabsf(pGravY); + else + mv = fabsf(pGravX); + if (mv<0.0001f) break; + pGravX /= mv; + pGravY /= mv; + nxf += pGravX; + nyf += pGravY; + nx = (int)(nxf+0.5f); + ny = (int)(nyf+0.5f); + if (nx<0 || ny<0 || nx>=XRES || ny>=YRES) + break; + if ((pmap[ny][nx]&0xFF)!=t || bmap[ny/CELL][nx/CELL]) + { + s = do_move(i, clear_x, clear_y, nxf, nyf); + if (s || bmap[ny/CELL][nx/CELL]!=WL_STREAM) + break; + } + } + } + else if (s==-1) {} // particle is out of bounds + else if ((clear_x!=x||clear_y!=y) && do_move(i, x, y, clear_xf, clear_yf)) {} + else parts[i].flags |= FLAG_STAGNANT; + parts[i].vx *= ptypes[t].collision; + parts[i].vy *= ptypes[t].collision; + } else { // if interpolation was done, try moving to last clear position