summaryrefslogtreecommitdiff
path: root/src/simulation
diff options
context:
space:
mode:
authorSimon 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)
commitf8766201a688598633e41166225d5e77275a2d5a (patch)
treee90eaf8bf33373596fc39d1eee08fe8ee708be5e /src/simulation
parent76070f99e0e9e4817f17dc55489756276b7b58c3 (diff)
downloadpowder-f8766201a688598633e41166225d5e77275a2d5a.zip
powder-f8766201a688598633e41166225d5e77275a2d5a.tar.gz
TPT: Optimization for GoL, Added brush size and mouse wheel to lua! e7035233fd
Diffstat (limited to 'src/simulation')
-rw-r--r--src/simulation/Simulation.cpp24
-rw-r--r--src/simulation/Simulation.h4
-rw-r--r--src/simulation/elements/PLNT.cpp2
-rw-r--r--src/simulation/elements/STKM.cpp6
4 files changed, 18 insertions, 18 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));
diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h
index 60a010c..7095c66 100644
--- a/src/simulation/Simulation.h
+++ b/src/simulation/Simulation.h
@@ -77,8 +77,8 @@ public:
int CGOL;
int ISGOL;
int GSPEED;
- unsigned char gol[XRES][YRES];
- unsigned char gol2[XRES][YRES][NGOL+1];
+ unsigned char gol[YRES][XRES];
+ unsigned char gol2[YRES][XRES][NGOL+1];
//Air sim
float (*vx)[XRES/CELL];
float (*vy)[XRES/CELL];
diff --git a/src/simulation/elements/PLNT.cpp b/src/simulation/elements/PLNT.cpp
index 92a4fdf..9c87e22 100644
--- a/src/simulation/elements/PLNT.cpp
+++ b/src/simulation/elements/PLNT.cpp
@@ -73,7 +73,7 @@ int Element_PLNT::update(UPDATE_FUNC_ARGS)
sim->kill_part(r>>8);
parts[i].life = rand()%60 + 60;
}
- else if (surround_space && ((r&0xFF)==PT_WOOD) && (1>rand()%20) && (abs(rx+ry)<=2) && (VINE_MODE || parts[i].tmp==1) )
+ else if (surround_space && ((r&0xFF)==PT_WOOD) && (1>rand()%20) && (abs(rx+ry)<=2) && (sim->VINE_MODE || parts[i].tmp==1) )
{
int nnx = rand()%3 -1;
int nny = rand()%3 -1;
diff --git a/src/simulation/elements/STKM.cpp b/src/simulation/elements/STKM.cpp
index fb0ade0..ee35105 100644
--- a/src/simulation/elements/STKM.cpp
+++ b/src/simulation/elements/STKM.cpp
@@ -510,15 +510,15 @@ void Element_STKM::STKM_interact(Simulation * sim, playerst* playerp, int i, int
break;
}
}
- if (((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) && parts[i].type)
+ if (((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) && sim->parts[i].type)
{
if (!sim->legacy_enable)
{
- parts[r>>8].temp = restrict_flt(parts[r>>8].temp+parts[i].temp/2, MIN_TEMP, MAX_TEMP);
+ sim->parts[r>>8].temp = restrict_flt(sim->parts[r>>8].temp+sim->parts[i].temp/2, MIN_TEMP, MAX_TEMP);
}
sim->kill_part(i);
}
- if (((r&0xFF)==PT_VOID || ((r&0xFF)==PT_PVOD && parts[r>>8].life==10)) && (!parts[r>>8].ctype || (parts[r>>8].ctype==parts[i].type)!=(parts[r>>8].tmp&1)) && parts[i].type)
+ if (((r&0xFF)==PT_VOID || ((r&0xFF)==PT_PVOD && sim->parts[r>>8].life==10)) && (!sim->parts[r>>8].ctype || (sim->parts[r>>8].ctype==sim->parts[i].type)!=(sim->parts[r>>8].tmp&1)) && sim->parts[i].type)
{
sim->kill_part(i);
}