summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilip <philip@philip-linuxlaptop.(none)>2010-11-07 22:55:25 (GMT)
committer Philip <philip@philip-linuxlaptop.(none)>2010-11-07 22:55:25 (GMT)
commit3de06dea86b09ae382f6eda411c69db5acf2c111 (patch)
tree59576c05ea5964fd2f9fd6e844de46e796f2553c /src
parentcbe3ed49c4604864ef41e6d8e629b25259eb491e (diff)
downloadpowder-3de06dea86b09ae382f6eda411c69db5acf2c111.zip
powder-3de06dea86b09ae382f6eda411c69db5acf2c111.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/main.c2
-rw-r--r--src/powder.c90
2 files changed, 48 insertions, 44 deletions
diff --git a/src/main.c b/src/main.c
index ee20b8d..e7f2cd1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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];
diff --git a/src/powder.c b/src/powder.c
index e3905b6..1daa180 100644
--- a/src/powder.c
+++ b/src/powder.c
@@ -822,13 +822,15 @@ void update_particles_i(pixel *vid, int start, int inc)
float c_heat = 0.0f;
int h_count = 0;
int starti = (start*-1);
- if(sys_pause&&!framerender)
+ if(sys_pause&&!framerender)
return;
- if(CGOL>=GSPEED)
- for(nx=4;nx<XRES-4;nx++)
+ 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,61 +840,62 @@ 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)
- for(int nnx=-1;nnx<2;nnx++)
- for(int nny=-1;nny<2;nny++)
{
- if(ny+nny<4&&nx+nnx<4)
- gol2[XRES-5][YRES-5][golnum] ++;
- else if(ny+nny<4&&nx+nnx>=XRES-4)
- gol2[4][YRES-5][golnum] ++;
- else if(ny+nny>=YRES-4&&nx+nnx<4)
- gol2[XRES-5][4][golnum] ++;
- else if(nx+nnx<4)
- gol2[XRES-5][ny+nny][golnum] ++;
- else if(ny+nny<4)
- gol2[nx+nnx][YRES-5][golnum] ++;
- else if(ny+nny>=YRES-4&&nx+nnx>=XRES-4)
- gol2[4][4][golnum] ++;
- else if(ny+nny>=YRES-4)
- gol2[nx+nnx][4][golnum] ++;
- else if(nx+nnx>=XRES-4)
- gol2[4][ny+nny][golnum] ++;
- else
- gol2[nx+nnx][ny+nny][golnum] ++;
+ 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)//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] ++;
+ else if(ny+nny>=YRES-4&&nx+nnx<4)
+ gol2[XRES-5][4][golnum] ++;
+ else if(nx+nnx<4)
+ gol2[XRES-5][ny+nny][golnum] ++;
+ else if(ny+nny<4)
+ gol2[nx+nnx][YRES-5][golnum] ++;
+ else if(ny+nny>=YRES-4&&nx+nnx>=XRES-4)
+ gol2[4][4][golnum] ++;
+ else if(ny+nny>=YRES-4)
+ gol2[nx+nnx][4][golnum] ++;
+ else if(nx+nnx>=XRES-4)
+ gol2[4][ny+nny][golnum] ++;
+ else
+ gol2[nx+nnx][ny+nny][golnum] ++;
+ }
}
+
}
- for(nx=4;nx<XRES-4;nx++)
- for(ny=4;ny<YRES-4;ny++)
+ 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++)
{
- if(neighbors==goldelete&&gol[nx][ny]==0&&grule[golnum][goldelete]>=2&&gol2[nx][ny][golnum]>=(goldelete%2)+goldelete/2)
+ for(int golnum = 1;golnum<NGOL;golnum++)
+ for(int goldelete = 1;goldelete<10;goldelete++)
{
- create_part(-1,nx,ny,golnum+77);
+ if(neighbors==goldelete&&gol[nx][ny]==0&&grule[golnum][goldelete]>=2&&gol2[nx][ny][golnum]>=(goldelete%2)+goldelete/2)
+ {
+ 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[pmap[ny][nx]>>8].type = PT_NONE;
}
- else if(neighbors==goldelete&&gol[nx][ny]==golnum&&(grule[golnum][goldelete-1]==0||grule[golnum][goldelete-1]==2))
- parts[r>>8].type = PT_NONE;
- }
- for(int z = 1;z<NGOL;z++)
+ for(int z = 1;z<NGOL;z++)
gol2[nx][ny][z] = 0;
+ }
}
- CGOL++;
+ }
+ 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)
{