mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-20 23:21:20 +02:00
Fix life cloning
This commit is contained in:
committed by
Simon Robertshaw
parent
7ed0255f04
commit
89cc8d4ded
@@ -7,10 +7,10 @@
|
|||||||
#define PATH_SEP "/"
|
#define PATH_SEP "/"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SAVE_VERSION 52
|
#define SAVE_VERSION 53
|
||||||
#define MINOR_VERSION 0
|
#define MINOR_VERSION 0
|
||||||
#define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter.
|
#define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter.
|
||||||
//#define BETA
|
#define BETA
|
||||||
|
|
||||||
#define SERVER "powdertoy.co.uk"
|
#define SERVER "powdertoy.co.uk"
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@ int update_BCLN(UPDATE_FUNC_ARGS) {
|
|||||||
parts[i].vx += advection*vx[y/CELL][x/CELL];
|
parts[i].vx += advection*vx[y/CELL][x/CELL];
|
||||||
parts[i].vy += advection*vy[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;
|
int r, rx, ry;
|
||||||
for (rx=-1; rx<2; rx++)
|
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_BCLN && (r&0xFF)!=PT_STKM &&
|
||||||
(r&0xFF)!=PT_STKM2 && (r&0xFF)!=PT_PBCN &&
|
(r&0xFF)!=PT_STKM2 && (r&0xFF)!=PT_PBCN &&
|
||||||
(r&0xFF)<PT_NUM)
|
(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 {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
#include <element.h>
|
#include <element.h>
|
||||||
|
|
||||||
int update_CLNE(UPDATE_FUNC_ARGS) {
|
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;
|
int r, rx, ry;
|
||||||
for (rx=-1; rx<2; rx++)
|
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_BCLN && (r&0xFF)!=PT_STKM &&
|
||||||
(r&0xFF)!=PT_PBCN && (r&0xFF)!=PT_STKM2 &&
|
(r&0xFF)!=PT_PBCN && (r&0xFF)!=PT_STKM2 &&
|
||||||
(r&0xFF)<PT_NUM)
|
(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 {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -4,20 +4,20 @@ int update_PBCN(UPDATE_FUNC_ARGS) {
|
|||||||
int r, rx, ry;
|
int r, rx, ry;
|
||||||
if (parts[i].life>0 && parts[i].life!=10)
|
if (parts[i].life>0 && parts[i].life!=10)
|
||||||
parts[i].life--;
|
parts[i].life--;
|
||||||
if (!parts[i].tmp && pv[y/CELL][x/CELL]>4.0f)
|
if (!parts[i].tmp2 && pv[y/CELL][x/CELL]>4.0f)
|
||||||
parts[i].tmp = rand()%40+80;
|
parts[i].tmp2 = rand()%40+80;
|
||||||
if (parts[i].tmp)
|
if (parts[i].tmp2)
|
||||||
{
|
{
|
||||||
float advection = 0.1f;
|
float advection = 0.1f;
|
||||||
parts[i].vx += advection*vx[y/CELL][x/CELL];
|
parts[i].vx += advection*vx[y/CELL][x/CELL];
|
||||||
parts[i].vy += advection*vy[y/CELL][x/CELL];
|
parts[i].vy += advection*vy[y/CELL][x/CELL];
|
||||||
parts[i].tmp--;
|
parts[i].tmp2--;
|
||||||
if(!parts[i].tmp){
|
if(!parts[i].tmp2){
|
||||||
kill_part(i);
|
kill_part(i);
|
||||||
return 1;
|
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 (rx=-1; rx<2; rx++)
|
||||||
for (ry=-1; ry<2; ry++)
|
for (ry=-1; ry<2; ry++)
|
||||||
if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES)
|
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_NSCN && (r&0xFF)!=PT_PSCN &&
|
||||||
(r&0xFF)!=PT_STKM && (r&0xFF)!=PT_STKM2 &&
|
(r&0xFF)!=PT_STKM && (r&0xFF)!=PT_STKM2 &&
|
||||||
(r&0xFF)!=PT_PBCN && (r&0xFF)<PT_NUM)
|
(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)
|
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 (rx=-1; rx<2; rx++) {
|
||||||
for (ry=-1; ry<2; ry++) {
|
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 {
|
} else {
|
||||||
|
@@ -26,7 +26,7 @@ int update_PCLN(UPDATE_FUNC_ARGS) {
|
|||||||
parts[i].life = 10;
|
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 (rx=-1; rx<2; rx++)
|
||||||
for (ry=-1; ry<2; ry++)
|
for (ry=-1; ry<2; ry++)
|
||||||
if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES)
|
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_NSCN && (r&0xFF)!=PT_PSCN &&
|
||||||
(r&0xFF)!=PT_STKM && (r&0xFF)!=PT_STKM2 &&
|
(r&0xFF)!=PT_STKM && (r&0xFF)!=PT_STKM2 &&
|
||||||
(r&0xFF)!=PT_PBCN && (r&0xFF)<PT_NUM)
|
(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>0 && parts[i].ctype<PT_NUM && parts[i].life==10) {
|
||||||
if (parts[i].ctype==PT_PHOT) {//create photons a different way
|
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 (rx=-1; rx<2; rx++) {
|
||||||
for (ry=-1; ry<2; ry++) {
|
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 {
|
} else {
|
||||||
|
43
src/main.c
43
src/main.c
@@ -423,6 +423,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++)
|
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];
|
i = m[j];
|
||||||
if (i) {
|
if (i) {
|
||||||
@@ -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++])<<8;
|
||||||
ttv |= (d[p++]);
|
ttv |= (d[p++]);
|
||||||
parts[i-1].tmp = ttv;
|
parts[i-1].tmp = ttv;
|
||||||
if (ptypes[parts[i-1].type].properties&PROP_LIFE && !parts[i-1].tmp)
|
if (ver<53 && !parts[i-1].tmp)
|
||||||
for (q = 1; q<=NGOL ; q++) {
|
for (q = 1; q<=NGOLALT; q++) {
|
||||||
if (parts[i-1].type==goltype[q-1] && grule[q][9]==2)
|
if (parts[i-1].type==goltype[q-1] && grule[q][9]==2)
|
||||||
parts[i-1].tmp = grule[q][9]-1;
|
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 {
|
} else {
|
||||||
p+=2;
|
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
|
//Read ALPHA component
|
||||||
for (j=0; j<w*h; j++)
|
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;
|
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)
|
if (!ptypes[parts[i-1].type].enabled)
|
||||||
parts[i-1].type = PT_NONE;
|
parts[i-1].type = PT_NONE;
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
parts[pmap[y][x]>>8].ctype = t;
|
||||||
|
if (t==PT_LIFE && v<NGOLALT) parts[pmap[y][x]>>8].tmp = v;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user