diff options
| author | jacksonmj <mj-pt@jacksonmj.co.uk> | 2011-07-22 21:06:07 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2011-07-24 12:10:43 (GMT) |
| commit | 89cc8d4ded6cf96941520e5d0097224f60b79929 (patch) | |
| tree | 31adc041d90200bdc0e0a93e3a39aa882142026e /src | |
| parent | 7ed0255f04f494e914b724cf5614f4f1d343069a (diff) | |
| download | powder-89cc8d4ded6cf96941520e5d0097224f60b79929.zip powder-89cc8d4ded6cf96941520e5d0097224f60b79929.tar.gz | |
Fix life cloning
Diffstat (limited to 'src')
| -rw-r--r-- | src/elements/bcln.c | 11 | ||||
| -rw-r--r-- | src/elements/clne.c | 11 | ||||
| -rw-r--r-- | src/elements/pbcn.c | 22 | ||||
| -rw-r--r-- | src/elements/pcln.c | 12 | ||||
| -rw-r--r-- | src/main.c | 43 | ||||
| -rw-r--r-- | src/powder.c | 1 |
6 files changed, 79 insertions, 21 deletions
diff --git a/src/elements/bcln.c b/src/elements/bcln.c index 6ecacac..062c85f 100644 --- a/src/elements/bcln.c +++ b/src/elements/bcln.c @@ -9,7 +9,7 @@ int update_BCLN(UPDATE_FUNC_ARGS) { parts[i].vx += advection*vx[y/CELL][x/CELL]; parts[i].vy += advection*vy[y/CELL][x/CELL]; } - if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM) + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) { int r, rx, ry; for (rx=-1; rx<2; rx++) @@ -25,11 +25,16 @@ int update_BCLN(UPDATE_FUNC_ARGS) { (r&0xFF)!=PT_BCLN && (r&0xFF)!=PT_STKM && (r&0xFF)!=PT_STKM2 && (r&0xFF)!=PT_PBCN && (r&0xFF)<PT_NUM) - parts[i].ctype = r&0xFF; + { + parts[i].ctype = r&0xFF; + if ((r&0xFF)==PT_LIFE) + parts[i].tmp = parts[r>>8].ctype; + } } } else { - create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype); + if (parts[i].ctype==PT_LIFE) create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype|(parts[i].tmp<<8)); + else create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype); } return 0; } diff --git a/src/elements/clne.c b/src/elements/clne.c index 850a3ae..41f27e3 100644 --- a/src/elements/clne.c +++ b/src/elements/clne.c @@ -1,7 +1,7 @@ #include <element.h> int update_CLNE(UPDATE_FUNC_ARGS) { - if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM) + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) { int r, rx, ry; for (rx=-1; rx<2; rx++) @@ -17,11 +17,16 @@ int update_CLNE(UPDATE_FUNC_ARGS) { (r&0xFF)!=PT_BCLN && (r&0xFF)!=PT_STKM && (r&0xFF)!=PT_PBCN && (r&0xFF)!=PT_STKM2 && (r&0xFF)<PT_NUM) - parts[i].ctype = r&0xFF; + { + parts[i].ctype = r&0xFF; + if ((r&0xFF)==PT_LIFE) + parts[i].tmp = parts[r>>8].ctype; + } } } else { - create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype); + if (parts[i].ctype==PT_LIFE) create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype|(parts[i].tmp<<8)); + else create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype); } return 0; } diff --git a/src/elements/pbcn.c b/src/elements/pbcn.c index 3c41820..3f40628 100644 --- a/src/elements/pbcn.c +++ b/src/elements/pbcn.c @@ -4,20 +4,20 @@ int update_PBCN(UPDATE_FUNC_ARGS) { int r, rx, ry; if (parts[i].life>0 && parts[i].life!=10) parts[i].life--; - if (!parts[i].tmp && pv[y/CELL][x/CELL]>4.0f) - parts[i].tmp = rand()%40+80; - if (parts[i].tmp) + if (!parts[i].tmp2 && pv[y/CELL][x/CELL]>4.0f) + parts[i].tmp2 = rand()%40+80; + if (parts[i].tmp2) { float advection = 0.1f; parts[i].vx += advection*vx[y/CELL][x/CELL]; parts[i].vy += advection*vy[y/CELL][x/CELL]; - parts[i].tmp--; - if(!parts[i].tmp){ + parts[i].tmp2--; + if(!parts[i].tmp2){ kill_part(i); return 1; } } - if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM) + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) @@ -32,7 +32,11 @@ int update_PBCN(UPDATE_FUNC_ARGS) { (r&0xFF)!=PT_NSCN && (r&0xFF)!=PT_PSCN && (r&0xFF)!=PT_STKM && (r&0xFF)!=PT_STKM2 && (r&0xFF)!=PT_PBCN && (r&0xFF)<PT_NUM) - parts[i].ctype = r&0xFF; + { + parts[i].ctype = r&0xFF; + if ((r&0xFF)==PT_LIFE) + parts[i].tmp = parts[r>>8].ctype; + } } if (parts[i].life==10) { @@ -65,10 +69,10 @@ int update_PBCN(UPDATE_FUNC_ARGS) { } } } - else if (ptypes[parts[i].ctype].properties&PROP_LIFE) {//create life a different way + else if (parts[i].ctype==PT_LIFE) {//create life a different way for (rx=-1; rx<2; rx++) { for (ry=-1; ry<2; ry++) { - create_part(-1, x+rx, y+ry, parts[i].ctype); + create_part(-1, x+rx, y+ry, parts[i].ctype|(parts[i].tmp<<8)); } } } else { diff --git a/src/elements/pcln.c b/src/elements/pcln.c index 3f785bb..45cfc79 100644 --- a/src/elements/pcln.c +++ b/src/elements/pcln.c @@ -26,7 +26,7 @@ int update_PCLN(UPDATE_FUNC_ARGS) { parts[i].life = 10; } } - if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM) + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) @@ -41,7 +41,11 @@ int update_PCLN(UPDATE_FUNC_ARGS) { (r&0xFF)!=PT_NSCN && (r&0xFF)!=PT_PSCN && (r&0xFF)!=PT_STKM && (r&0xFF)!=PT_STKM2 && (r&0xFF)!=PT_PBCN && (r&0xFF)<PT_NUM) - parts[i].ctype = r&0xFF; + { + parts[i].ctype = r&0xFF; + if ((r&0xFF)==PT_LIFE) + parts[i].tmp = parts[r>>8].ctype; + } } if (parts[i].ctype>0 && parts[i].ctype<PT_NUM && parts[i].life==10) { if (parts[i].ctype==PT_PHOT) {//create photons a different way @@ -55,10 +59,10 @@ int update_PCLN(UPDATE_FUNC_ARGS) { } } } - else if (ptypes[parts[i].ctype].properties&PROP_LIFE) {//create life a different way + else if (parts[i].ctype==PT_LIFE) {//create life a different way for (rx=-1; rx<2; rx++) { for (ry=-1; ry<2; ry++) { - create_part(-1, x+rx, y+ry, parts[i].ctype); + create_part(-1, x+rx, y+ry, parts[i].ctype|(parts[i].tmp<<8)); } } } else { @@ -425,6 +425,14 @@ 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_PBCN)) { + //Save tmp2 + d[p++] = parts[i-1].tmp2; + } + } + for (j=0; j<w*h; j++) + { + i = m[j]; if (i) { //Save colour (ALPHA) d[p++] = (parts[i-1].dcolour&0xFF000000)>>24; @@ -848,17 +856,38 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char ttv = (d[p++])<<8; ttv |= (d[p++]); parts[i-1].tmp = ttv; - if (ptypes[parts[i-1].type].properties&PROP_LIFE && !parts[i-1].tmp) - for (q = 1; q<=NGOL ; q++) { + if (ver<53 && !parts[i-1].tmp) + for (q = 1; q<=NGOLALT; q++) { if (parts[i-1].type==goltype[q-1] && grule[q][9]==2) parts[i-1].tmp = grule[q][9]-1; } + if (ver>=51 && ver<53 && parts[i-1].type==PT_PBCN) + { + parts[i-1].tmp2 = parts[i-1].tmp; + parts[i-1].tmp = 0; + } } else { p+=2; } } } } + if (ver>=53) { + for (j=0; j<w*h; j++) + { + i = m[j]; + ty = d[pty+j]; + if (i && ty==PT_PBCN) + { + if (p >= size) + goto corrupt; + if (i <= NPART) + parts[i-1].tmp2 = d[p++]; + else + p++; + } + } + } //Read ALPHA component for (j=0; j<w*h; j++) { @@ -1009,6 +1038,16 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char } ty = PT_LIFE; } + if(ver<52 && (ty==PT_CLNE || ty==PT_PCLN || ty==PT_BCLN)){ + //Replace old GOL ctypes in clone + for (gnum = 0; gnum<NGOLALT; gnum++){ + if (parts[i-1].ctype==goltype[gnum]) + { + parts[i-1].ctype = PT_LIFE; + parts[i-1].tmp = gnum; + } + } + } if (!ptypes[parts[i-1].type].enabled) parts[i-1].type = PT_NONE; } diff --git a/src/powder.c b/src/powder.c index 6167abf..201ec97 100644 --- a/src/powder.c +++ b/src/powder.c @@ -756,6 +756,7 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a ) { parts[pmap[y][x]>>8].ctype = t; + if (t==PT_LIFE && v<NGOLALT) parts[pmap[y][x]>>8].tmp = v; } return -1; } |
