diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-07-25 18:32:36 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-07-25 18:32:36 (GMT) |
| commit | f8766201a688598633e41166225d5e77275a2d5a (patch) | |
| tree | e90eaf8bf33373596fc39d1eee08fe8ee708be5e /src/simulation/Simulation.cpp | |
| parent | 76070f99e0e9e4817f17dc55489756276b7b58c3 (diff) | |
| download | powder-f8766201a688598633e41166225d5e77275a2d5a.zip powder-f8766201a688598633e41166225d5e77275a2d5a.tar.gz | |
TPT: Optimization for GoL, Added brush size and mouse wheel to lua! e7035233fd
Diffstat (limited to 'src/simulation/Simulation.cpp')
| -rw-r--r-- | src/simulation/Simulation.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 9cac3cf..b5d07bc 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -3174,14 +3174,14 @@ void Simulation::update_particles_i(int start, int inc) int createdsomething = 0; CGOL=0; ISGOL=0; - for (nx=CELL; nx<XRES-CELL; nx++) + for (ny=CELL; ny<YRES-CELL; ny++) {//go through every particle and set neighbor map - for (ny=CELL; ny<YRES-CELL; ny++) + for (nx=CELL; nx<XRES-CELL; nx++) { r = pmap[ny][nx]; if (!r) { - gol[nx][ny] = 0; + gol[ny][nx] = 0; continue; } else @@ -3196,7 +3196,7 @@ void Simulation::update_particles_i(int start, int inc) continue; } if (parts[r>>8].tmp == grule[golnum][9]-1) { - gol[nx][ny] = golnum; + gol[ny][nx] = golnum; 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 @@ -3204,8 +3204,8 @@ void Simulation::update_particles_i(int start, int inc) 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[((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][golnum] ++; - gol2[((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][0] ++; + 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] ++; } } } @@ -3219,23 +3219,23 @@ void Simulation::update_particles_i(int start, int inc) } } } - for (nx=CELL; nx<XRES-CELL; nx++) + for (ny=CELL; ny<YRES-CELL; ny++) { //go through every particle again, but check neighbor map, then update particles - for (ny=CELL; ny<YRES-CELL; ny++) + for (nx=CELL; nx<XRES-CELL; nx++) { r = pmap[ny][nx]; - neighbors = gol2[nx][ny][0]; + neighbors = gol2[ny][nx][0]; if (neighbors==0 || !((r&0xFF)==PT_LIFE || !(r&0xFF))) continue; for ( golnum = 1; golnum<=NGOL; golnum++) { goldelete = neighbors; - if (gol[nx][ny]==0&&grule[golnum][goldelete]>=2&&gol2[nx][ny][golnum]>=(goldelete%2)+goldelete/2) + if (gol[ny][nx]==0&&grule[golnum][goldelete]>=2&&gol2[ny][nx][golnum]>=(goldelete%2)+goldelete/2) { if (create_part(-1, nx, ny, PT_LIFE|((golnum-1)<<8))) createdsomething = 1; } - else if (gol[nx][ny]==golnum&&(grule[golnum][goldelete-1]==0||grule[golnum][goldelete-1]==2))//subtract 1 because it counted itself + else if (gol[ny][nx]==golnum&&(grule[golnum][goldelete-1]==0||grule[golnum][goldelete-1]==2))//subtract 1 because it counted itself { if (parts[r>>8].tmp==grule[golnum][9]-1) parts[r>>8].tmp --; @@ -3244,7 +3244,7 @@ void Simulation::update_particles_i(int start, int inc) parts[r>>8].type = PT_NONE;//using kill_part makes it not work } for ( z = 0; z<=NGOL; z++) - gol2[nx][ny][z] = 0;//this improves performance A LOT compared to the memset, i was getting ~23 more fps with this. + gol2[ny][nx][z] = 0;//this improves performance A LOT compared to the memset, i was getting ~23 more fps with this. } } //memset(gol2, 0, sizeof(gol2)); |
