Increased efficiency a lot, GoL only runs when there is a GoL particle, and other small checks to make it faster. Blank screen fps went from 44 to 60, with a few particles, 44 to 55.

This commit is contained in:
Philip 2010-11-07 17:55:25 -05:00
parent cbe3ed49c4
commit 3de06dea86
3 changed files with 53 additions and 48 deletions

View File

@ -18,7 +18,7 @@
#define THUMB_CACHE_SIZE 256
#define NGOL 11
#define NGOL 10
#define IMGCONNS 3
#define TIMEOUT 100
@ -107,6 +107,7 @@ typedef struct stamp stamp;
int MSIGN;
int CGOL;
int ISGOL;
int GSPEED;
int gol[XRES][YRES];
int gol2[XRES][YRES][NGOL];

View File

@ -103,7 +103,7 @@ int amd = 1;
int FPSB = 0;
int MSIGN =-1;
int CGOL = 0;
int GSPEED = 0;
int GSPEED = 1;
sign signs[MAXSIGNS];

View File

@ -824,11 +824,13 @@ void update_particles_i(pixel *vid, int start, int inc)
int starti = (start*-1);
if(sys_pause&&!framerender)
return;
if(CGOL>=GSPEED)
if(ISGOL==1&&CGOL>=GSPEED)//GSPEED is frames per generation
{
for(nx=4;nx<XRES-4;nx++)
for(ny=4;ny<YRES-4;ny++)
{
CGOL=0;
ISGOL=0;
r = pmap[ny][nx];
if((r>>8)>=NPART || !r)
{
@ -838,18 +840,12 @@ void update_particles_i(pixel *vid, int start, int inc)
else
for(int golnum=1;golnum<NGOL;golnum++)
if(parts[r>>8].type==golnum+77)
gol[nx][ny] = golnum;
}
for(nx=4;nx<XRES-4;nx++)
for(ny=4;ny<YRES-4;ny++)
{
int golnum = gol[nx][ny];
if(golnum>=1)
gol[nx][ny] = golnum;
for(int nnx=-1;nnx<2;nnx++)
for(int nny=-1;nny<2;nny++)
{
if(ny+nny<4&&nx+nnx<4)
if(ny+nny<4&&nx+nnx<4)//any way to make wrapping code smaller?
gol2[XRES-5][YRES-5][golnum] ++;
else if(ny+nny<4&&nx+nnx>=XRES-4)
gol2[4][YRES-5][golnum] ++;
@ -871,14 +867,18 @@ void update_particles_i(pixel *vid, int start, int inc)
}
}
}
for(nx=4;nx<XRES-4;nx++)
for(ny=4;ny<YRES-4;ny++)
{
r = pmap[ny][nx];
int neighbors = 0;
for(int golnum = 1;golnum<NGOL;golnum++)
{
neighbors += gol2[nx][ny][golnum];
}
if(neighbors!=0)
{
for(int golnum = 1;golnum<NGOL;golnum++)
for(int goldelete = 1;goldelete<10;goldelete++)
{
@ -887,11 +887,14 @@ void update_particles_i(pixel *vid, int start, int inc)
create_part(-1,nx,ny,golnum+77);
}
else if(neighbors==goldelete&&gol[nx][ny]==golnum&&(grule[golnum][goldelete-1]==0||grule[golnum][goldelete-1]==2))
parts[r>>8].type = PT_NONE;
parts[pmap[ny][nx]>>8].type = PT_NONE;
}
for(int z = 1;z<NGOL;z++)
gol2[nx][ny][z] = 0;
}
}
}
if(ISGOL)
CGOL++;
for(i=start; i<(NPART-starti); i+=inc)
if(parts[i].type)
@ -1861,6 +1864,7 @@ void update_particles_i(pixel *vid, int start, int inc)
{
if(parts[i].temp>0)
parts[i].temp -= 50.0f;
ISGOL=1;
}
else if(t==PT_LCRY)
{