From 2f8574f62bb7731031bf950258a02756d5620bac Mon Sep 17 00:00:00 2001 From: cracker64 Date: Mon, 6 May 2013 13:30:03 -0400 Subject: gol2 array is static size, adding new GoL won't increase memory usage. 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>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) diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 9e9424f..5ce0d1e 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -74,10 +74,9 @@ public: int emp_decor; //Gol sim int CGOL; - int ISGOL; int GSPEED; unsigned char gol[YRES][XRES]; - unsigned char gol2[YRES][XRES][NGOL+1]; + unsigned short gol2[YRES][XRES][9]; //Air sim float (*vx)[XRES/CELL]; float (*vy)[XRES/CELL]; -- cgit v0.9.2-21-gd62e