diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index b110b723f..577da9343 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -3326,7 +3326,7 @@ void Simulation::delete_part(int x, int y, int flags)//calls kill_part with the void Simulation::update_particles_i(int start, int inc) { - int i, j, x, y, t, nx, ny, r, surround_space, s, lt, rt, nt, nnx, nny, q, golnum, goldelete, z, neighbors, createdsomething; + int i, j, x, y, t, nx, ny, r, surround_space, s, lt, rt, nt, nnx, nny, q, golnum, z, neighbors; float mv, dx, dy, ix, iy, lx, ly, nrx, nry, dp, ctemph, ctempl, gravtot; int fin_x, fin_y, clear_x, clear_y, stagnant; float fin_xf, fin_yf, clear_xf, clear_yf; @@ -3530,9 +3530,7 @@ void Simulation::update_particles_i(int start, int inc) //game of life! if (elementCount[PT_LIFE]>0&&++CGOL>=GSPEED)//GSPEED is frames per generation { - int createdsomething = 0; CGOL=0; - ISGOL=0; //TODO: maybe this should only loop through active particles for (ny=CELL; ny>8].type==PT_LIFE) - { - golnum = parts[r>>8].ctype+1; - if (golnum<=0 || golnum>NGOL) { - kill_part(r>>8); - continue; - } - if (parts[r>>8].tmp == grule[golnum][9]-1) { - gol[ny][nx] = golnum; - for ( nnx=-1; nnx<2; nnx++) + golnum = parts[r>>8].ctype+1; + if (golnum<=0 || golnum>NGOL) { + kill_part(r>>8); + continue; + } + gol[ny][nx] = golnum; + if (parts[r>>8].tmp == grule[golnum][9]-1) { + for ( nnx=-1; nnx<2; nnx++) + { + for ( nny=-1; nny<2; nny++)//it will count itself as its own neighbor, which is needed, but will have 1 extra for delete check { - for ( nny=-1; nny<2; nny++)//it will count itself as its own neighbor, which is needed, but will have 1 extra for delete check + int adx = ((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL; + int ady = ((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL; + rt = pmap[ady][adx]; + if (!rt || (rt&0xFF)==PT_LIFE) { - rt = pmap[((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL]; - if (!rt || (rt&0xFF)==PT_LIFE) - { - gol2[((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][golnum] ++; - gol2[((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][0] ++; - } + gol2[ady][adx][golnum] ++; + gol2[ady][adx][0] ++; } } - } else { - parts[r>>8].tmp --; - if (parts[r>>8].tmp<=0) - parts[r>>8].type = PT_NONE;//TODO: move delete into an update function, change to kill_part } + } else { + parts[r>>8].tmp --; } } } @@ -3581,27 +3576,35 @@ void Simulation::update_particles_i(int start, int inc) for (nx=CELL; nx=2&&gol2[ny][nx][golnum]>=(goldelete%2)+goldelete/2) + golnum = gol[ny][nx]; + if (!r) { - if (create_part(-1, nx, ny, PT_LIFE|((golnum-1)<<8))) - createdsomething = 1; + //Find which type we can try and create + for (golnum = 1; golnum<=NGOL; golnum++) + { + if (grule[golnum][neighbors]>=2 && gol2[ny][nx][golnum]>=(neighbors%2)+neighbors/2) + { + create_part(-1, nx, ny, PT_LIFE|((golnum-1)<<8)); + break; + } + } } - else if (gol[ny][nx]==golnum&&(grule[golnum][goldelete-1]==0||grule[golnum][goldelete-1]==2))//subtract 1 because it counted itself + else if (grule[golnum][neighbors-1]==0 || grule[golnum][neighbors-1]==2)//subtract 1 because it counted itself { if (parts[r>>8].tmp==grule[golnum][9]-1) parts[r>>8].tmp --; } - if (r && parts[r>>8].tmp<=0) - parts[r>>8].type = PT_NONE;//TODO: move delete into an update function, change to kill_part + for ( z = 0; z<=NGOL; z++) + gol2[ny][nx][z] = 0;//this improves performance A LOT compared to the memset, i was getting ~23 more fps with this. } - for ( z = 0; z<=NGOL; z++) - gol2[ny][nx][z] = 0;//this improves performance A LOT compared to the memset, i was getting ~23 more fps with this. + //we still need to kill things with 0 neighbors (higher state life) + if (r && parts[r>>8].tmp<=0) + kill_part(r>>8); } } //memset(gol2, 0, sizeof(gol2)); @@ -4076,7 +4079,6 @@ void Simulation::update_particles_i(int start, int inc) if (t==PT_LIFE) { parts[i].temp = restrict_flt(parts[i].temp-50.0f, MIN_TEMP, MAX_TEMP); - //ISGOL=1;//means there is a life particle on screen } if (t==PT_WIRE) {