gol2 array is static size, adding new GoL won't increase memory usage.
This commit is contained in:
parent
77102f4bba
commit
2f8574f62b
@ -3560,8 +3560,22 @@ void Simulation::update_particles_i(int start, int inc)
|
|||||||
rt = pmap[ady][adx];
|
rt = pmap[ady][adx];
|
||||||
if (!rt || (rt&0xFF)==PT_LIFE)
|
if (!rt || (rt&0xFF)==PT_LIFE)
|
||||||
{
|
{
|
||||||
gol2[ady][adx][golnum] ++;
|
//the total neighbor count is in 0
|
||||||
gol2[ady][adx][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)
|
if (!r)
|
||||||
{
|
{
|
||||||
//Find which type we can try and create
|
//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));
|
if (golnum<creategol) creategol=golnum;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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
|
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)
|
if (parts[r>>8].tmp==grule[golnum][9]-1)
|
||||||
parts[r>>8].tmp --;
|
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.
|
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)
|
//we still need to kill things with 0 neighbors (higher state life)
|
||||||
|
@ -74,10 +74,9 @@ public:
|
|||||||
int emp_decor;
|
int emp_decor;
|
||||||
//Gol sim
|
//Gol sim
|
||||||
int CGOL;
|
int CGOL;
|
||||||
int ISGOL;
|
|
||||||
int GSPEED;
|
int GSPEED;
|
||||||
unsigned char gol[YRES][XRES];
|
unsigned char gol[YRES][XRES];
|
||||||
unsigned char gol2[YRES][XRES][NGOL+1];
|
unsigned short gol2[YRES][XRES][9];
|
||||||
//Air sim
|
//Air sim
|
||||||
float (*vx)[XRES/CELL];
|
float (*vx)[XRES/CELL];
|
||||||
float (*vy)[XRES/CELL];
|
float (*vy)[XRES/CELL];
|
||||||
|
Reference in New Issue
Block a user