summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2011-07-09 17:22:25 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-07-09 17:22:25 (GMT)
commitd42e06f37a93475a09cd2908849b2f33a50513ac (patch)
tree3bb435ec3648d897a821cf99ff2469277da51791 /src
parentd2eb6f1cb31f2d746d5897e775424ed0d1448703 (diff)
downloadpowder-d42e06f37a93475a09cd2908849b2f33a50513ac.zip
powder-d42e06f37a93475a09cd2908849b2f33a50513ac.tar.gz
Merge all GOL types into PT_LIFE, behaviour is determined by ctype
Diffstat (limited to 'src')
-rw-r--r--src/graphics.c114
-rw-r--r--src/interface.c40
-rw-r--r--src/main.c14
-rw-r--r--src/powder.c40
4 files changed, 153 insertions, 55 deletions
diff --git a/src/graphics.c b/src/graphics.c
index 193af98..dc00b17 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -709,7 +709,31 @@ int draw_tool_xy(pixel *vid_buf, int x, int y, int b, unsigned pc)
pixel gc;
if (x > XRES-26 || x < 0)
return 26;
- if (b>=UI_WALLSTART)
+ if ((b&0xFF) == PT_LIFE)
+ {
+#ifdef OpenGL
+ fillrect(vid_buf, x, y, 28, 16, PIXR(pc), PIXG(pc), PIXB(pc), 255);
+#else
+ for (j=1; j<15; j++)
+ {
+ for (i=1; i<27; i++)
+ {
+ vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc;
+ }
+ }
+#endif
+ c = PIXB(pc) + 3*PIXG(pc) + 2*PIXR(pc);
+ if (c<544)
+ {
+ c = 255;
+ }
+ else
+ {
+ c = 0;
+ }
+ drawtext(vid_buf, x+14-textwidth((char *)gmenu[(b>>8)&0xFF].name)/2, y+4, (char *)gmenu[(b>>8)&0xFF].name, c, c, c, 255);
+ }
+ else if (b>=UI_WALLSTART)
{
int ds = 0;
if (b-UI_WALLSTART>=0 && b-UI_WALLSTART<UI_WALLCOUNT)
@@ -2042,48 +2066,52 @@ void draw_parts(pixel *vid)
blendpixel(vid, nx, ny, cr, cg, cb, 255);
}
- else if (t==PT_LOTE)//colors for life states
- {
- if (parts[i].tmp==2)
- blendpixel(vid, nx, ny, 255, 128, 0, 255);
- else if (parts[i].tmp==1)
- blendpixel(vid, nx, ny, 255, 255, 0, 255);
- else
- blendpixel(vid, nx, ny, 255, 0, 0, 255);
- }
- else if (t==PT_FRG2)//colors for life states
- {
- if (parts[i].tmp==2)
- blendpixel(vid, nx, ny, 0, 100, 50, 255);
- else
- blendpixel(vid, nx, ny, 0, 255, 90, 255);
- }
- else if (t==PT_STAR)//colors for life states
- {
- if (parts[i].tmp==4)
- blendpixel(vid, nx, ny, 0, 0, 128, 255);
- else if (parts[i].tmp==3)
- blendpixel(vid, nx, ny, 0, 0, 150, 255);
- else if (parts[i].tmp==2)
- blendpixel(vid, nx, ny, 0, 0, 190, 255);
- else if (parts[i].tmp==1)
- blendpixel(vid, nx, ny, 0, 0, 230, 255);
- else
- blendpixel(vid, nx, ny, 0, 0, 70, 255);
- }
- else if (t==PT_FROG)//colors for life states
- {
- if (parts[i].tmp==2)
- blendpixel(vid, nx, ny, 0, 100, 0, 255);
- else
- blendpixel(vid, nx, ny, 0, 255, 0, 255);
- }
- else if (t==PT_BRAN)//colors for life states
- {
- if (parts[i].tmp==1)
- blendpixel(vid, nx, ny, 150, 150, 0, 255);
- else
- blendpixel(vid, nx, ny, 255, 255, 0, 255);
+ if(t==PT_LIFE && parts[i].ctype < NGOLALT){
+ if (parts[i].ctype==NGT_LOTE)//colors for life states
+ {
+ if (parts[i].tmp==2)
+ blendpixel(vid, nx, ny, 255, 128, 0, 255);
+ else if (parts[i].tmp==1)
+ blendpixel(vid, nx, ny, 255, 255, 0, 255);
+ else
+ blendpixel(vid, nx, ny, 255, 0, 0, 255);
+ }
+ else if (parts[i].ctype==NGT_FRG2)//colors for life states
+ {
+ if (parts[i].tmp==2)
+ blendpixel(vid, nx, ny, 0, 100, 50, 255);
+ else
+ blendpixel(vid, nx, ny, 0, 255, 90, 255);
+ }
+ else if (parts[i].ctype==NGT_STAR)//colors for life states
+ {
+ if (parts[i].tmp==4)
+ blendpixel(vid, nx, ny, 0, 0, 128, 255);
+ else if (parts[i].tmp==3)
+ blendpixel(vid, nx, ny, 0, 0, 150, 255);
+ else if (parts[i].tmp==2)
+ blendpixel(vid, nx, ny, 0, 0, 190, 255);
+ else if (parts[i].tmp==1)
+ blendpixel(vid, nx, ny, 0, 0, 230, 255);
+ else
+ blendpixel(vid, nx, ny, 0, 0, 70, 255);
+ }
+ else if (parts[i].ctype==NGT_FROG)//colors for life states
+ {
+ if (parts[i].tmp==2)
+ blendpixel(vid, nx, ny, 0, 100, 0, 255);
+ else
+ blendpixel(vid, nx, ny, 0, 255, 0, 255);
+ }
+ else if (parts[i].ctype==NGT_BRAN)//colors for life states
+ {
+ if (parts[i].tmp==1)
+ blendpixel(vid, nx, ny, 150, 150, 0, 255);
+ else
+ blendpixel(vid, nx, ny, 255, 255, 0, 255);
+ } else {
+ blendpixel(vid, nx, ny, PIXR(gmenu[parts[i].ctype].colour), PIXG(gmenu[parts[i].ctype].colour), PIXB(gmenu[parts[i].ctype].colour), 255);
+ }
}
else if (t==PT_DEUT)
{
diff --git a/src/interface.c b/src/interface.c
index 002d4c5..923a8d0 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -87,6 +87,7 @@ int drawgrav_enable = 0;
void menu_count(void)//puts the number of elements in each section into .itemcount
{
int i=0;
+ msections[SC_LIFE].itemcount = NGOLALT;
msections[SC_WALL].itemcount = UI_WALLCOUNT-4;
msections[SC_SPECIAL].itemcount = 4;
for (i=0; i<PT_NUM; i++)
@@ -2013,6 +2014,41 @@ void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int *dae, int b, int bq
}
}
}
+ else if(i==SC_LIFE)
+ {
+ int n2;
+ if (fwidth > XRES-BARSIZE) { //fancy scrolling
+ float overflow = fwidth-(XRES-BARSIZE), location = ((float)XRES-BARSIZE)/((float)(mx-(XRES-BARSIZE)));
+ xoff = (int)(overflow / location);
+ }
+ for (n2 = 0; n2<NGOLALT; n2++)
+ {
+ n = PT_LIFE | (n2<<8);
+ x -= draw_tool_xy(vid_buf, x-xoff, y, n, gmenu[n2].colour)+5;
+ if (!bq && mx>=x+32-xoff && mx<x+58-xoff && my>=y && my< y+15)
+ {
+ drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
+ h = n;
+ }
+ if (!bq && mx>=x+32-xoff && mx<x+58-xoff && my>=y && my< y+15&&(sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_SHIFT)))
+ {
+ drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 0, 255, 255, 255);
+ h = n;
+ }
+ else if (n==SLALT)
+ {
+ drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 0, 255, 255, 255);
+ }
+ else if (n==*sl)
+ {
+ drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
+ }
+ else if (n==*sr)
+ {
+ drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 55, 55, 255, 255);
+ }
+ }
+ }
else //all other menus
{
if (fwidth > XRES-BARSIZE) { //fancy scrolling
@@ -2062,6 +2098,10 @@ void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int *dae, int b, int bq
{
drawtext(vid_buf, XRES-textwidth((char *)wtypes[h-UI_WALLSTART].descs)-BARSIZE, sy-10, (char *)wtypes[h-UI_WALLSTART].descs, 255, 255, 255, 255);
}
+ else if (i==SC_LIFE)
+ {
+ drawtext(vid_buf, XRES-textwidth((char *)gmenu[(h>>8)&0xFF].description)-BARSIZE, sy-10, (char *)gmenu[(h>>8)&0xFF].description, 255, 255, 255, 255);
+ }
else
{
drawtext(vid_buf, XRES-textwidth((char *)ptypes[h].descs)-BARSIZE, sy-10, (char *)ptypes[h].descs, 255, 255, 255, 255);
diff --git a/src/main.c b/src/main.c
index 8d84146..633b2fe 100644
--- a/src/main.c
+++ b/src/main.c
@@ -466,7 +466,7 @@ void *build_save(int *size, int x0, int y0, int w, int h, unsigned char bmap[YRE
for (j=0; j<w*h; j++)
{
i = m[j];
- if (i && (parts[i-1].type==PT_CLNE || parts[i-1].type==PT_PCLN || parts[i-1].type==PT_BCLN || parts[i-1].type==PT_SPRK || parts[i-1].type==PT_LAVA || parts[i-1].type==PT_PIPE))
+ if (i && (parts[i-1].type==PT_CLNE || parts[i-1].type==PT_PCLN || parts[i-1].type==PT_BCLN || parts[i-1].type==PT_SPRK || parts[i-1].type==PT_LAVA || parts[i-1].type==PT_PIPE || parts[i-1].type==PT_LIFE))
d[p++] = parts[i-1].ctype;
}
@@ -975,9 +975,10 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char
}
for (j=0; j<w*h; j++)
{
+ int gnum = 0;
i = m[j];
ty = d[pty+j];
- if (i && (ty==PT_CLNE || (ty==PT_PCLN && ver>=43) || (ty==PT_BCLN && ver>=44) || (ty==PT_SPRK && ver>=21) || (ty==PT_LAVA && ver>=34) || (ty==PT_PIPE && ver>=43)))
+ if (i && (ty==PT_CLNE || (ty==PT_PCLN && ver>=43) || (ty==PT_BCLN && ver>=44) || (ty==PT_SPRK && ver>=21) || (ty==PT_LAVA && ver>=34) || (ty==PT_PIPE && ver>=43) || (ty==PT_LIFE && ver>=51)))
{
if (p >= size)
goto corrupt;
@@ -997,6 +998,15 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char
parts[i-1].dcolour = 0xFF000000;
parts[i-1].type = PT_DMND;
}
+ if(ver<51 && ((ty>=78 && ty<=89) || (ty>=134 && ty<=146 && ty!=141))){
+ //Replace old GOL
+ parts[i-1].type = PT_LIFE;
+ for (gnum = 0; gnum<NGOLALT; gnum++){
+ if (ty==goltype[gnum])
+ parts[i-1].ctype = gnum;
+ }
+ ty = PT_LIFE;
+ }
}
}
diff --git a/src/powder.c b/src/powder.c
index 0fa16c9..1db8b3a 100644
--- a/src/powder.c
+++ b/src/powder.c
@@ -636,11 +636,14 @@ inline void part_change_type(int i, int x, int y, int t)//changes the type of pa
#if defined(WIN32) && !defined(__GNUC__)
_inline int create_part(int p, int x, int y, int t)
#else
-inline int create_part(int p, int x, int y, int t)//the function for creating a particle, use p=-1 for creating a new particle, -2 is from a brush, or a particle number to replace a particle.
+inline int create_part(int p, int x, int y, int tv)//the function for creating a particle, use p=-1 for creating a new particle, -2 is from a brush, or a particle number to replace a particle.
#endif
{
int i;
+ int t = tv & 0xFF;
+ int v = (tv >> 8) & 0xFF;
+
if (x<0 || y<0 || x>=XRES || y>=YRES || ((t<0 || t>=PT_NUM)&&t!=SPC_HEAT&&t!=SPC_COOL&&t!=SPC_AIR&&t!=SPC_VACUUM))
return -1;
if (t==OLD_PT_WIND)
@@ -822,12 +825,18 @@ inline int create_part(int p, int x, int y, int t)//the function for creating a
parts[i].life = 50;
parts[i].tmp = 50;
}
- if (ptypes[t].properties&PROP_LIFE) {
+ /*if (ptypes[t].properties&PROP_LIFE) {
int r;
for (r = 0; r<NGOL; r++)
if (t==goltype[r])
parts[i].tmp = grule[r+1][9] - 1;
+ }*/
+ if (t==PT_LIFE)
+ {
+ parts[i].tmp = grule[v+1][9] - 1;
+ parts[i].ctype = v;
}
+
if (t==PT_DEUT)
parts[i].life = 10;
if (t==PT_MERC)
@@ -1458,7 +1467,8 @@ void update_particles_i(pixel *vid, int start, int inc)
int createdsomething = 0;
CGOL=0;
ISGOL=0;
- for (nx=CELL; nx<XRES-CELL; nx++)//go through every particle and set neighbor map
+ for (nx=CELL; nx<XRES-CELL; nx++)
+ {//go through every particle and set neighbor map
for (ny=CELL; ny<YRES-CELL; ny++)
{
r = pmap[ny][nx];
@@ -1468,41 +1478,50 @@ void update_particles_i(pixel *vid, int start, int inc)
continue;
}
else
- for ( golnum=1; golnum<=NGOL; golnum++)
- if (parts[r>>8].type==goltype[golnum-1])
+ {
+ //for ( golnum=1; golnum<=NGOL; golnum++) //This shouldn't be necessary any more.
+ //{
+ if (parts[r>>8].type==PT_LIFE/* && parts[r>>8].ctype==golnum-1*/)
{
+ golnum = parts[r>>8].ctype+1;
if (parts[r>>8].tmp == grule[golnum][9]-1) {
gol[nx][ny] = golnum;
for ( nnx=-1; nnx<2; nnx++)
+ {
for ( nny=-1; nny<2; nny++)//it will count itself as its own neighbor, which is needed, but will have 1 extra for delete check
{
rt = pmap[((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL];
- if (!rt || ptypes[rt&0xFF].properties&PROP_LIFE)
+ if (!rt || (rt&0xFF)==PT_LIFE)
{
gol2[((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][golnum] ++;
gol2[((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][0] ++;
}
}
+ }
} else {
parts[r>>8].tmp --;
if (parts[r>>8].tmp<=0)
parts[r>>8].type = PT_NONE;//using kill_part makes it not work
}
}
+ //}
+ }
}
- for (nx=CELL; nx<XRES-CELL; nx++)//go through every particle again, but check neighbor map, then update particles
+ }
+ for (nx=CELL; nx<XRES-CELL; nx++)
+ { //go through every particle again, but check neighbor map, then update particles
for (ny=CELL; ny<YRES-CELL; ny++)
{
r = pmap[ny][nx];
neighbors = gol2[nx][ny][0];
- if (neighbors==0 || !(ptypes[r&0xFF].properties&PROP_LIFE || !(r&0xFF)) || (r>>8)>=NPART)
+ if (neighbors==0 || !((r&0xFF)==PT_LIFE || !(r&0xFF)) || (r>>8)>=NPART)
continue;
for ( golnum = 1; golnum<=NGOL; golnum++)
{
goldelete = neighbors;
if (gol[nx][ny]==0&&grule[golnum][goldelete]>=2&&gol2[nx][ny][golnum]>=(goldelete%2)+goldelete/2)
{
- if (create_part(-1,nx,ny,goltype[golnum-1]))
+ if (create_part(-1, nx, ny, PT_LIFE|((golnum-1)<<8)))
createdsomething = 1;
}
else if (gol[nx][ny]==golnum&&(grule[golnum][goldelete-1]==0||grule[golnum][goldelete-1]==2))//subtract 1 because it counted itself
@@ -1516,6 +1535,7 @@ void update_particles_i(pixel *vid, int start, int inc)
for ( z = 0; z<=NGOL; z++)
gol2[nx][ny][z] = 0;//this improves performance A LOT compared to the memset, i was getting ~23 more fps with this.
}
+ }
if (createdsomething)
GENERATION ++;
//memset(gol2, 0, sizeof(gol2));
@@ -1839,7 +1859,7 @@ void update_particles_i(pixel *vid, int start, int inc)
}
}
- if (ptypes[t].properties&PROP_LIFE)
+ if (t==PT_LIFE)
{
parts[i].temp = restrict_flt(parts[i].temp-50.0f, MIN_TEMP, MAX_TEMP);
ISGOL=1;//means there is a life particle on screen