summaryrefslogtreecommitdiff
path: root/src/simulation/Simulation.cpp
diff options
context:
space:
mode:
authorcracker64 <cracker642@gmail.com>2013-05-06 17:30:03 (GMT)
committer cracker64 <cracker642@gmail.com>2013-05-06 17:30:03 (GMT)
commit2f8574f62bb7731031bf950258a02756d5620bac (patch)
tree2fd9bb1087164f97f12b1c42491d54bd16c3f747 /src/simulation/Simulation.cpp
parent77102f4bbaff9d15617b83e674939b108442ae21 (diff)
downloadpowder-2f8574f62bb7731031bf950258a02756d5620bac.zip
powder-2f8574f62bb7731031bf950258a02756d5620bac.tar.gz
gol2 array is static size, adding new GoL won't increase memory usage.
Diffstat (limited to 'src/simulation/Simulation.cpp')
-rw-r--r--src/simulation/Simulation.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index 577da93..699a611 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -3560,8 +3560,22 @@ void Simulation::update_particles_i(int start, int inc)
rt = pmap[ady][adx];
if (!rt || (rt&0xFF)==PT_LIFE)
{
- gol2[ady][adx][golnum] ++;
+ //the total neighbor count is in 0
gol2[ady][adx][0] ++;
+ //insert golnum into neighbor table
+ for ( i=1; i<9; i++)
+ {
+ if (!gol2[ady][adx][i])
+ {
+ gol2[ady][adx][i] = (golnum<<4)+1;
+ break;
+ }
+ else if((gol2[ady][adx][i]>>4)==golnum)
+ {
+ gol2[ady][adx][i]++;
+ break;
+ }
+ }
}
}
}
@@ -3585,21 +3599,25 @@ void Simulation::update_particles_i(int start, int inc)
if (!r)
{
//Find which type we can try and create
- for (golnum = 1; golnum<=NGOL; golnum++)
+ int creategol = 0xFF;
+ for ( i=1; i<9; i++)
{
- if (grule[golnum][neighbors]>=2 && gol2[ny][nx][golnum]>=(neighbors%2)+neighbors/2)
+ if (!gol2[ny][nx][i]) break;
+ golnum = (gol2[ny][nx][i]>>4);
+ if (grule[golnum][neighbors]>=2 && (gol2[ny][nx][i]&0xF)>=(neighbors%2)+neighbors/2)
{
- create_part(-1, nx, ny, PT_LIFE|((golnum-1)<<8));
- break;
+ if (golnum<creategol) creategol=golnum;
}
}
+ if (creategol<0xFF)
+ create_part(-1, nx, ny, PT_LIFE|((creategol-1)<<8));
}
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 --;
}
- for ( z = 0; z<=NGOL; z++)
+ for ( z = 0; z<9; 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)