From 77bcac1a5628aecdf8e4c1968106e3bed86890ab Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Tue, 1 Feb 2011 16:03:09 +0000 Subject: [PATCH 01/17] Small fixes Fix nearest_part distance calculation Rename air constants to avoid PLOSS clash with math.h Prevent crashes due to bad lava ctype. --- includes/defines.h | 12 +++++------- src/air.c | 32 ++++++++++++++++---------------- src/powder.c | 6 +++--- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/includes/defines.h b/includes/defines.h index b3b604ff9..9fba0fb2e 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -14,8 +14,6 @@ #define SERVER "powdertoy.co.uk" -#undef PLOSS - #define THUMB_CACHE_SIZE 256 #define IMGCONNS 3 @@ -45,11 +43,11 @@ extern unsigned char ZSIZE; #define ISTP (CELL/2) #define CFDS (4.0f/CELL) -#define TSTEPP 0.3f -#define TSTEPV 0.4f -#define VADV 0.3f -#define VLOSS 0.999f -#define PLOSS 0.9999f +#define AIR_TSTEPP 0.3f +#define AIR_TSTEPV 0.4f +#define AIR_VADV 0.3f +#define AIR_VLOSS 0.999f +#define AIR_PLOSS 0.9999f #define GRID_X 5 #define GRID_Y 4 diff --git a/src/air.c b/src/air.c index 33a491376..e9a8b9e93 100644 --- a/src/air.c +++ b/src/air.c @@ -86,8 +86,8 @@ void update_air(void) dp = 0.0f; dp += vx[y][x-1] - vx[y][x]; dp += vy[y-1][x] - vy[y][x]; - pv[y][x] *= PLOSS; - pv[y][x] += dp*TSTEPP; + pv[y][x] *= AIR_PLOSS; + pv[y][x] += dp*AIR_TSTEPP; } for (y=0; y=2 && i=2 && j=GSPEED)//GSPEED is frames per generation { + int createdsomething = 0; CGOL=0; ISGOL=0; - int createdsomething = 0; for (nx=CELL; nx=ptransitions[parts[i].ctype].thv) s = 0; else if (parts[i].ctype==PT_THRM&&pt>=ptransitions[PT_BMTL].thv) s = 0; else if (pt>=973.0f) s = 0; // freezing point for lava with any other (not listed in ptransitions as turning into lava) ctype From 5b1210714d3909139886cc7f8a72291580fc0eeb Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Wed, 2 Feb 2011 17:37:59 +0000 Subject: [PATCH 02/17] More fixes Fix PHOT and FWRK. Fix QRTZ conductivity (broken by removing PROP_CONDUCTS) Add some things lost during rewrite: NTCT/PTCT not heated if INSL in the way; boiling point varies with pressure. --- src/elements/fwrk.c | 20 ++++++++++---------- src/elements/phot.c | 1 + src/elements/sprk.c | 4 ++-- src/powder.c | 14 +++++++++++--- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/elements/fwrk.c b/src/elements/fwrk.c index def28e401..06390c59d 100644 --- a/src/elements/fwrk.c +++ b/src/elements/fwrk.c @@ -7,9 +7,9 @@ int update_FWRK(UPDATE_FUNC_ARGS) { np = create_part(-1, x , y-1 , PT_FWRK); if (np!=-1) { - parts[r>>8].vy = rand()%8-22; - parts[r>>8].vx = rand()%20-rand()%20; - parts[r>>8].life=rand()%15+25; + parts[np].vy = rand()%8-22; + parts[np].vx = rand()%20-rand()%20; + parts[np].life=rand()%15+25; kill_part(i); return 1; } @@ -33,13 +33,13 @@ int update_FWRK(UPDATE_FUNC_ARGS) { pv[y/CELL][x/CELL] += 2.00f*CFDS; if (np!=-1) { - parts[r>>8].vy = -(rand()%10-1); - parts[r>>8].vx = ((rand()%2)*2-1)*rand()%(5+5)+(parts[i].vx)*2 ; - parts[r>>8].life= rand()%37+18; - parts[r>>8].tmp=q; - parts[r>>8].flags=w; - parts[r>>8].ctype=e; - parts[r>>8].temp= rand()%20+6000; + parts[np].vy = -(rand()%10-1); + parts[np].vx = ((rand()%2)*2-1)*rand()%(5+5)+(parts[i].vx)*2 ; + parts[np].life= rand()%37+18; + parts[np].tmp=q; + parts[np].flags=w; + parts[np].ctype=e; + parts[np].temp= rand()%20+6000; } } } diff --git a/src/elements/phot.c b/src/elements/phot.c index 11585f9fb..59e9cd8b9 100644 --- a/src/elements/phot.c +++ b/src/elements/phot.c @@ -7,6 +7,7 @@ int update_PHOT(UPDATE_FUNC_ARGS) { for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (x+rx>=0 && y+ry>0 && x+rx>8)>=NPART || !r) continue; if ((r&0xFF)==PT_ISOZ && 5>(rand()%2000)) diff --git a/src/elements/sprk.c b/src/elements/sprk.c index ddac968c5..39f74975b 100644 --- a/src/elements/sprk.c +++ b/src/elements/sprk.c @@ -97,12 +97,12 @@ int update_SPRK(UPDATE_FUNC_ARGS) { // ct = spark from material, rt = spark to material. Make conduct_sprk = 0 if conduction not allowed if (pavg == PT_INSL) conduct_sprk = 0; - if (!(ptypes[rt].properties&PROP_CONDUCTS||rt==PT_INST)) conduct_sprk = 0; + if (!(ptypes[rt].properties&PROP_CONDUCTS||rt==PT_INST||rt==PT_QRTZ)) conduct_sprk = 0; if (abs(rx)+abs(ry)>=4 &&ct!=PT_SWCH&&rt!=PT_SWCH) conduct_sprk = 0; - if (ct==PT_METL && (rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR||(rt==PT_SPRK&&(parts[r>>8].ctype==PT_NTCT||parts[r>>8].ctype==PT_PTCT)))) + if (ct==PT_METL && (rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR||(rt==PT_SPRK&&(parts[r>>8].ctype==PT_NTCT||parts[r>>8].ctype==PT_PTCT))) && pavg!=PT_INSL) { parts[r>>8].temp = 473.0f; if (rt==PT_NTCT||rt==PT_PTCT) diff --git a/src/powder.c b/src/powder.c index f8a5d3d78..b9495a723 100644 --- a/src/powder.c +++ b/src/powder.c @@ -1127,7 +1127,7 @@ int nearest_part(int ci, int t) void update_particles_i(pixel *vid, int start, int inc) { int i, j, x, y, t, nx, ny, r, surround_space, s, lt, rt, nt, nnx, nny, q, golnum, goldelete, z, neighbors; - float mv, dx, dy, ix, iy, lx, ly, nrx, nry, dp; + float mv, dx, dy, ix, iy, lx, ly, nrx, nry, dp, ctemph, ctempl; int fin_x, fin_y, clear_x, clear_y; float fin_xf, fin_yf, clear_xf, clear_yf; float nn, ct1, ct2, swappage; @@ -1522,8 +1522,16 @@ void update_particles_i(pixel *vid, int start, int inc) parts[surround_hconduct[j]].temp = pt; } + ctemph = ctempl = pt; + // change boiling point with pressure + if ((ptypes[t].state==ST_LIQUID && ptransitions[t].tht>-1 && ptransitions[t].tht-1 && ptransitions[t].tltptransitions[t].thv&&ptransitions[t].tht>-1) { + if (ctemph>ptransitions[t].thv&&ptransitions[t].tht>-1) { // particle type change due to high temperature if (ptransitions[t].tht!=PT_NUM) t = ptransitions[t].tht; @@ -1544,7 +1552,7 @@ void update_particles_i(pixel *vid, int start, int inc) else t = PT_WTRV; } else s = 0; - } else if (pt-1) { + } else if (ctempl-1) { // particle type change due to low temperature if (ptransitions[t].tlt!=PT_NUM) t = ptransitions[t].tlt; From 9d716cba4719721e852028cf714ebb5143b9abb0 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Wed, 2 Feb 2011 21:11:19 +0000 Subject: [PATCH 03/17] Add menu sections (prevents menu_count exceeding msections size) --- includes/interface.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/interface.h b/includes/interface.h index 2cb64dd2d..e1d7e6f22 100644 --- a/includes/interface.h +++ b/includes/interface.h @@ -69,6 +69,8 @@ static menu_section msections[] = {"\xC6", "Radioactive", 0, 1}, {"\xCC", "Special", 0, 1}, {"\xD2", "Life", 0, 1}, + {"\xD2", "More Life", 0, 1}, + {"\xC8", "", 0, 0}, {"\xC8", "Cracker", 0, 0}, {"\xC8", "Cracker!", 0, 0}, }; From 8aaaae1daf36d52cfd924fc9afec89e14519bacb Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Thu, 3 Feb 2011 00:08:56 +0000 Subject: [PATCH 04/17] Make PTCT/NTCT cool down even when covered with spark Also fix typo in update_PHOT --- src/elements/phot.c | 4 ++-- src/elements/sprk.c | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/elements/phot.c b/src/elements/phot.c index 59e9cd8b9..a6a5d0714 100644 --- a/src/elements/phot.c +++ b/src/elements/phot.c @@ -6,8 +6,8 @@ int update_PHOT(UPDATE_FUNC_ARGS) { if (1>rand()%10) update_PYRO(UPDATE_FUNC_SUBCALL_ARGS); for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) - if (x+rx>=0 && y+ry>0 && x+rx=0 && y+ry>=0 && x+rx>8)>=NPART || !r) continue; if ((r&0xFF)==PT_ISOZ && 5>(rand()%2000)) diff --git a/src/elements/sprk.c b/src/elements/sprk.c index 39f74975b..f107b9af6 100644 --- a/src/elements/sprk.c +++ b/src/elements/sprk.c @@ -25,6 +25,10 @@ int update_SPRK(UPDATE_FUNC_ARGS) { kill_part(i); return 1; } + else if (ct==PT_NTCT || ct==PT_PTCT) + { + update_NPTCT(UPDATE_FUNC_SUBCALL_ARGS); + } else if (ct==PT_ETRD&&parts[i].life==1) { nearp = nearest_part(i, PT_ETRD); From 54caad7a69c424b6bcb78374aa0d0785a8a5ac93 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Thu, 3 Feb 2011 12:04:11 +0000 Subject: [PATCH 05/17] Possible fix for liquids transferring spark through INSL --- src/powder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/powder.c b/src/powder.c index b9495a723..3c85167a7 100644 --- a/src/powder.c +++ b/src/powder.c @@ -1080,7 +1080,7 @@ inline int parts_avg(int ci, int ni,int t) { if (t==PT_INSL)//to keep electronics working { - int pmr = pmap[(int)((parts[ci].y + parts[ni].y)/2)][(int)((parts[ci].x + parts[ni].x)/2)]; + int pmr = pmap[((int)(parts[ci].y+0.5f) + (int)(parts[ni].y+0.5f))/2][((int)(parts[ci].x+0.5f) + (int)(parts[ni].x+0.5f))/2]; if ((pmr>>8) < NPART && pmr) return parts[pmr>>8].type; else From 196ccd1e36270d54c534ea68c5d5b74b5cead236 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Fri, 4 Feb 2011 20:53:15 +0000 Subject: [PATCH 06/17] Uninitialised pointer segfault if not previously logged in --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 49d496e00..114d75250 100644 --- a/src/main.c +++ b/src/main.c @@ -1181,7 +1181,7 @@ int main(int argc, char *argv[]) pixel *vid_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); pixel *pers_bg=calloc((XRES+BARSIZE)*YRES, PIXELSIZE); void *http_ver_check; - void *http_session_check; + void *http_session_check = NULL; char *ver_data=NULL, *check_data=NULL, *tmp; char console_error[255] = ""; int i, j, bq, fire_fc=0, do_check=0, do_s_check=0, old_version=0, http_ret=0,http_s_ret=0, major, minor, old_ver_len; From 21d0dd0ca2191df7f1ae46f3cd8c4d081e18e603 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sat, 5 Feb 2011 15:44:29 +0000 Subject: [PATCH 07/17] Better text wrapping --- src/graphics.c | 135 +++++++++++++++++++++++++++++++------------------ 1 file changed, 86 insertions(+), 49 deletions(-) diff --git a/src/graphics.c b/src/graphics.c index 2d9989f24..1549f374f 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -855,49 +855,65 @@ int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, i int rh = 12; int rw = 0; int cw = x; - for (; *s; s++) + int wordlen; + int charspace; + while (*s) { - if (*s == '\n') + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, w-(x-cw)); + if (charspace=-1; s++) { - switch (s[1]) + if (*s == '\n') { - case 'w': - r = g = b = 255; - break; - case 'g': - r = g = b = 192; - break; - case 'o': - r = 255; - g = 216; - b = 32; - break; - case 'r': - r = 255; - g = b = 0; - break; - case 'b': - r = g = 0; - b = 255; - break; - } - s++; - } - else - { - if (x-cw>=w) { x = sx; rw = 0; - y+=FONT_H+2; - rh+=FONT_H+2; + y += FONT_H+2; + } + else if (*s == '\b') + { + switch (s[1]) + { + case 'w': + r = g = b = 255; + break; + case 'g': + r = g = b = 192; + break; + case 'o': + r = 255; + g = 216; + b = 32; + break; + case 'r': + r = 255; + g = b = 0; + break; + case 'b': + r = g = 0; + b = 255; + break; + } + s++; + } + else + { + + if (x-cw>=w) + { + x = sx; + rw = 0; + y+=FONT_H+2; + rh+=FONT_H+2; + } + x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); } - x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a); } } #endif @@ -1009,18 +1025,29 @@ void textnpos(char *s, int n, int w, int *cx, int *cy) { int x = 0; int y = 0; - //TODO: Implement Textnheight for wrapped text - for (; *s; s++) + int wordlen, charspace; + while (*s&&n) { - if (!n) { - break; - } - x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if (x>=w) { + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, w-x); + if (charspace=-1; s++) + { + if (!n) { + break; + } + x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if (x>=w) + { + x = 0; + y += FONT_H+2; + } + n--; + } } *cx = x-1; *cy = y; @@ -1041,18 +1068,28 @@ int textwidthx(char *s, int w) } int textposxy(char *s, int width, int w, int h) { - int x=0,y=0,n=0,cw; - for (; *s; s++) + int x=0,y=0,n=0,cw, wordlen, charspace; + while (*s) { - cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; - if (x+(cw/2) >= w && y+6 >= h) - break; - x += cw; - if (x>=width) { + wordlen = strcspn(s," .,!?\n"); + charspace = textwidthx(s, width-x); + if (charspace=-1; s++) + { + cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + if ((x+(cw/2) >= w && y+6 >= h)||(y+6 >= h+FONT_H+2)) + return n++; + x += cw; + if (x>=width) { + x = 0; + y += FONT_H+2; + } + n++; + } } return n; } From b7e50f521c7163b21488c030be3d7bed4cba5807 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sun, 6 Feb 2011 17:16:49 +0000 Subject: [PATCH 08/17] Fix flood_parts crashes Crashes due to infinite recursion in flood_parts, which seemed to be caused by the pmap being incorrect. --- src/powder.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/powder.c b/src/powder.c index 4d8ba4598..8348fb04b 100644 --- a/src/powder.c +++ b/src/powder.c @@ -253,11 +253,9 @@ int try_move(int i, int x, int y, int nx, int ny) parts[e].x += x-nx; parts[e].y += y-ny; + pmap[(int)(parts[e].y+0.5f)][(int)(parts[e].x+0.5f)] = (e<<8)|parts[e].type; } - pmap[ny][nx] = (i<<8)|parts[i].type; - pmap[y][x] = r; - return 1; } @@ -2030,10 +2028,18 @@ killed: } nx = (int)(parts[i].x+0.5f); ny = (int)(parts[i].y+0.5f); - if (nx=XRES-CELL || ny=YRES-CELL) + if (ny!=y || nx!=x) { - kill_part(i); - continue; + if ((pmap[y][x]>>8)==i) pmap[y][x] = 0; + if (nx=XRES-CELL || ny=YRES-CELL) + { + kill_part(i); + continue; + } + if (t==PT_PHOT) + photons[ny][nx] = t|(i<<8); + else + pmap[ny][nx] = t|(i<<8); } } if (framerender) { From e791e21c3e3681c0716562477ebbe3eec88a7df1 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sun, 6 Feb 2011 17:50:40 +0000 Subject: [PATCH 09/17] Fix x,y not always updating and particle # not showing when BETA defined --- src/main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index 114d75250..0c4aa5f09 100644 --- a/src/main.c +++ b/src/main.c @@ -1903,7 +1903,7 @@ int main(int argc, char *argv[]) int tctype = parts[cr>>8].ctype; if (tctype>=PT_NUM) tctype = 0; - sprintf(heattext, "%s (%s), Pressure: %3.2f, Temp: %4.2f C, Life: %d", ptypes[cr&0xFF].name, ptypes[tctype].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life); + sprintf(heattext, "%s (%s), Pressure: %3.2f, Temp: %4.2f C, Life: %d, #%d", ptypes[cr&0xFF].name, ptypes[tctype].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life, cr>>8); //sprintf(heattext, "%s (%s), Pressure: %3.2f, Temp: %4.2f C, Life: %d", ptypes[cr&0xFF].name, ptypes[parts[cr>>8].ctype].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life); } else sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C, Life: %d", ptypes[cr&0xFF].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life); @@ -1914,7 +1914,6 @@ int main(int argc, char *argv[]) if (tctype>=PT_NUM) tctype = 0; sprintf(heattext, "%s (%s), Pressure: %3.2f, Temp: %4.2f C, Life: %d, #%d", ptypes[cr&0xFF].name, ptypes[tctype].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life ,cr>>8); - sprintf(coordtext, "X:%d Y:%d", x/sdl_scale, y/sdl_scale); //sprintf(heattext, "%s (%s), Pressure: %3.2f, Temp: %4.2f C, Life: %d", ptypes[cr&0xFF].name, ptypes[parts[cr>>8].ctype].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life); } else { sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C", ptypes[cr&0xFF].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f); @@ -1923,10 +1922,10 @@ int main(int argc, char *argv[]) } else { - if (DEBUG_MODE) - sprintf(coordtext, "X:%d Y:%d", x/sdl_scale, y/sdl_scale); sprintf(heattext, "Empty, Pressure: %3.2f", pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL]); } + if (DEBUG_MODE) + sprintf(coordtext, "X:%d Y:%d", x/sdl_scale, y/sdl_scale); } mx = x; my = y; From 6749eb19600882e8ffe57595d538a8a2eba1f9c0 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sun, 6 Feb 2011 20:13:47 +0000 Subject: [PATCH 10/17] More flood_parts fixes kill_part needs to update photon map, otherwise delete_part keeps deleting the same photon, leading to infinite flood_parts recursion. --- src/powder.c | 69 +++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/src/powder.c b/src/powder.c index 8348fb04b..20dc94c1b 100644 --- a/src/powder.c +++ b/src/powder.c @@ -413,33 +413,31 @@ void kill_part(int i) { int x, y; - if (parts[i].type != PT_PHOT) { - x = (int)(parts[i].x+0.5f); - y = (int)(parts[i].y+0.5f); - if (parts[i].type == PT_STKM) - { - death = 1; - isplayer = 0; - } - if (parts[i].type == PT_STKM2) - { - death2 = 1; - isplayer2 = 0; - } - if (parts[i].type == PT_SPAWN) - { - ISSPAWN1 = 0; - } - if (parts[i].type == PT_SPAWN2) - { - ISSPAWN2 = 0; - } - if (x>=0 && y>=0 && x>8)==i) - pmap[y][x] = 0; - else if ((photons[y][x]>>8)==i) - photons[y][x] = 0; - } + x = (int)(parts[i].x+0.5f); + y = (int)(parts[i].y+0.5f); + if (parts[i].type == PT_STKM) + { + death = 1; + isplayer = 0; + } + if (parts[i].type == PT_STKM2) + { + death2 = 1; + isplayer2 = 0; + } + if (parts[i].type == PT_SPAWN) + { + ISSPAWN1 = 0; + } + if (parts[i].type == PT_SPAWN2) + { + ISSPAWN2 = 0; + } + if (x>=0 && y>=0 && x>8)==i) + pmap[y][x] = 0; + else if ((photons[y][x]>>8)==i) + photons[y][x] = 0; } parts[i].type = PT_NONE; @@ -456,10 +454,18 @@ inline void part_change_type(int i, int x, int y, int t) if (x<0 || y<0 || x>=XRES || y>=YRES || i>=NPART) return -1; parts[i].type = t; - if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT)// && t!=PT_NEUT) + if (t==PT_PHOT)// || t==PT_NEUT) + { + photons[y][x] = t|(i<<8); + if ((pmap[y][x]>>8)==i) + pmap[y][x] = 0; + } + else + { pmap[y][x] = t|(i<<8); - else if ((pmap[y][x]>>8)==i) - pmap[y][x] = 0; + if ((photons[y][x]>>8)==i) + photons[y][x] = 0; + } } #if defined(WIN32) && !defined(__GNUC__) @@ -498,6 +504,8 @@ inline int create_n_parts(int n, int x, int y, float vx, float vy, int t) parts[i].tmp = 0; if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT && !pmap[y][x])// && t!=PT_NEUT) pmap[y][x] = t|(i<<8); + else if (t==PT_PHOT && !photons[y][x]) + photons[y][x] = t|(i<<8); pv[y/CELL][x/CELL] += 6.0f * CFDS; } @@ -2031,6 +2039,7 @@ killed: if (ny!=y || nx!=x) { if ((pmap[y][x]>>8)==i) pmap[y][x] = 0; + else if (t==PT_PHOT&&(photons[y][x]>>8)==i) photons[y][x] = 0; if (nx=XRES-CELL || ny=YRES-CELL) { kill_part(i); From ee100cb4f0dee7f59b975a07de4f59db2addbf02 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Mon, 7 Feb 2011 15:24:08 +0000 Subject: [PATCH 11/17] Fix GoL deleting particle 0 --- src/powder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/powder.c b/src/powder.c index 20dc94c1b..f7106ed19 100644 --- a/src/powder.c +++ b/src/powder.c @@ -1347,7 +1347,7 @@ void update_particles_i(pixel *vid, int start, int inc) if(parts[r>>8].tmp==grule[golnum][9]-1) parts[r>>8].tmp --; } - if(parts[r>>8].tmp<=0) + if (r && parts[r>>8].tmp<=0) parts[r>>8].type = PT_NONE;//using kill_part makes it not work } gol2[nx][ny][0] = 0; From 5fbb37ba60d4d262f4c2d4fedb0b7b07cd0c0d0f Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Mon, 7 Feb 2011 15:54:57 +0000 Subject: [PATCH 12/17] Fix console particle number, coordinate parsing --- src/interface.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/interface.c b/src/interface.c index 96b2dbc56..ea63733ba 100644 --- a/src/interface.c +++ b/src/interface.c @@ -3995,13 +3995,7 @@ int console_parse_coords(char *txt, int *x, int *y, char *err) { // TODO: use regex? int nx = -1, ny = -1; - sscanf(txt,"%d,%d",&nx,&ny); - if (nx<0 && nx>=XRES) - { - strcpy(err,"Invalid coordinates"); - return 0; - } - if (ny<0 && ny>=YRES) + if (sscanf(txt,"%d,%d",&nx,&ny)!=2 || nx<0 || nx>=XRES || ny<0 || ny>=YRES) { strcpy(err,"Invalid coordinates"); return 0; @@ -4012,9 +4006,10 @@ int console_parse_coords(char *txt, int *x, int *y, char *err) } int console_parse_partref(char *txt, int *which, char *err) { + strcpy(err,""); // TODO: use regex? int i = -1, nx, ny; - if (console_parse_coords(txt, &nx, &ny, err)) + if (strchr(txt,',') && console_parse_coords(txt, &nx, &ny, err)) { i = pmap[ny][nx]; if (!i || (i>>8)>=NPART) @@ -4025,7 +4020,6 @@ int console_parse_partref(char *txt, int *which, char *err) else if (txt) { char *num = (char*)malloc(strlen(txt)+3); - strcpy(err,""); // suppress error message from failed coordinate parsing i = atoi(txt); sprintf(num,"%d",i); if (!txt || strcmp(txt,num)!=0) @@ -4038,6 +4032,6 @@ int console_parse_partref(char *txt, int *which, char *err) strcpy(err,""); return 1; } - strcpy(err,"Particle does not exist"); + if (strcmp(err,"")==0) strcpy(err,"Particle does not exist"); return 0; } From 29bd6e42f578aaee5aa82156d6150966059a200d Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Mon, 7 Feb 2011 16:08:40 +0000 Subject: [PATCH 13/17] Correct some fancy mode graphics --- src/graphics.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/graphics.c b/src/graphics.c index 1549f374f..78f1867fb 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1520,7 +1520,9 @@ void draw_parts(pixel *vid) t!=PT_HFLM && t!=PT_SPRK && t!=PT_FIRW && t!=PT_DUST && t!=PT_FIRW && t!=PT_FWRK && t!=PT_NEUT && t!=PT_LAVA && t!=PT_BOMB && - t!=PT_PHOT && t!=PT_THDR && t!=PT_SMKE) + t!=PT_PHOT && t!=PT_THDR && t!=PT_SMKE && + t!=PT_LCRY && t!=PT_SWCH && t!=PT_PCLN && + t!=PT_PUMP && t!=PT_HSWC && t!=PT_FILT) { if (ptypes[parts[i].type].properties&TYPE_LIQUID) { From cb74b0bacfd4d726d2713f5e3e26f4f8548cb90f Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Mon, 7 Feb 2011 17:11:18 +0000 Subject: [PATCH 14/17] Improve console element parsing GOL, 34, 2x2 now work. Element types can no longer be referred to by number, to remove ambiguity between type and particle number. --- includes/powder.h | 6 +++--- src/interface.c | 14 +------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/includes/powder.h b/includes/powder.h index 1b2824ecc..77e7ca185 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -447,16 +447,16 @@ static const part_type ptypes[PT_NUM] = {"HSWC", PIXPACK(0x3B1010), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Heat switch. Conducts Heat only when activated", ST_NONE, TYPE_SOLID, &update_HSWC}, {"IRON", PIXPACK(0x707070), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 50, 1, 100, SC_CRACKER2, R_TEMP+0.0f +273.15f, 251, "Rusts with salt, can be used for electrolysis of WATR", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS, &update_IRON}, {"MORT", PIXPACK(0xE0E0E0), 0.0f, 0.00f * CFDS, 1.00f, 1.00f, -0.99f, 0.0f, 0.01f, 0.002f * CFDS, 0, 0, 0, 0, 0, 1, -1, SC_CRACKER2, R_TEMP+4.0f +273.15f, 60, "Steam Train.", ST_NONE, TYPE_PART, &update_MORT}, - {"GOL ", PIXPACK(0x0CAC00), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Game Of Life! B3/S23", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, + {"GOL", PIXPACK(0x0CAC00), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Game Of Life! B3/S23", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, {"HLIF", PIXPACK(0xFF0000), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "High Life! B36/S23", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, {"ASIM", PIXPACK(0x0000FF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Assimilation! B345/S4567", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, - {"2x2 ", PIXPACK(0xFFFF00), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "2x2! B36/S125", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, + {"2x2", PIXPACK(0xFFFF00), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "2x2! B36/S125", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, {"DANI", PIXPACK(0x00FFFF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Day and Night! B3678/S34678", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, {"AMOE", PIXPACK(0xFF00FF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Amoeba! B357/S1358", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, {"MOVE", PIXPACK(0xFFFFFF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "'Move' particles! Does not move things.. it is a life type B368/S245", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, {"PGOL", PIXPACK(0xE05010), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Pseudo Life! B357/S238", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, {"DMOE", PIXPACK(0x500000), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Diamoeba! B35678/S5678", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, - {"34 ", PIXPACK(0x500050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "34! B34/S34)", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, + {"34", PIXPACK(0x500050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "34! B34/S34)", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, {"LLIF", PIXPACK(0x505050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Long Life! B345/S5", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, {"STAN", PIXPACK(0x5000FF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Stains! B3678/S235678", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL}, {"SPNG", PIXPACK(0xFFBE30), 0.00f, 0.00f * CFDS, 0.00f, 1.00f, 0.00f, 0.0f, 0.00f, 0.000f * CFDS, 0, 20, 0, 1, 30, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 251, "A sponge, absorbs water.", ST_SOLID, TYPE_SOLID, &update_SPNG}, diff --git a/src/interface.c b/src/interface.c index ea63733ba..32c83a18b 100644 --- a/src/interface.c +++ b/src/interface.c @@ -3957,19 +3957,7 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show int console_parse_type(char *txt, int *element, char *err) { - int i = atoi(txt); - char num[4]; - if (i>=0 && i Date: Mon, 7 Feb 2011 20:29:11 +0000 Subject: [PATCH 15/17] Prevent crashes in the event of ridiculous temperatures --- includes/powder.h | 9 +++++---- src/elements/prti.c | 2 ++ src/elements/prto.c | 2 ++ src/elements/wifi.c | 2 ++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/includes/powder.h b/includes/powder.h index 77e7ca185..6eb2a7426 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -767,10 +767,11 @@ static int lolzrule[9][9] = {0,1,0,0,0,0,0,1,0}, {0,1,0,0,0,0,0,1,0}, }; -int portal[(int)(MAX_TEMP-73.15f)/100+2][8][80]; -float portaltemp[(int)(MAX_TEMP-73.15f)/100+2][8][80]; -int portalctype[(int)(MAX_TEMP-73.15f)/100+2][8][80]; -int wireless[(int)(MAX_TEMP-73.15f)/100+2][2]; +#define CHANNELS ((int)(MAX_TEMP-73.15f)/100+2) +int portal[CHANNELS][8][80]; +float portaltemp[CHANNELS][8][80]; +int portalctype[CHANNELS][8][80]; +int wireless[CHANNELS][2]; extern int isplayer; extern float player[27]; diff --git a/src/elements/prti.c b/src/elements/prti.c index b25f7a3db..560ba8ca7 100644 --- a/src/elements/prti.c +++ b/src/elements/prti.c @@ -4,6 +4,8 @@ int update_PRTI(UPDATE_FUNC_ARGS) { int r, nnx, rx, ry; int count =0; parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1); + if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1; + else if (parts[i].tmp<0) parts[i].tmp = 0; for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (x+rx>=0 && y+ry>0 && x+rx=CHANNELS) parts[i].tmp = CHANNELS-1; + else if (parts[i].tmp<0) parts[i].tmp = 0; for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (x+rx>=0 && y+ry>0 && x+rx=CHANNELS) parts[i].tmp = CHANNELS-1; + else if (parts[i].tmp<0) parts[i].tmp = 0; for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (x+rx>=0 && y+ry>0 && x+rx Date: Tue, 8 Feb 2011 14:30:02 +0000 Subject: [PATCH 16/17] Sound device not compulsory --- includes/defines.h | 2 +- src/main.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/includes/defines.h b/includes/defines.h index 967e3f133..f4a2a4dfa 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -99,7 +99,7 @@ int GRAV_G2; int GRAV_B2; extern int legacy_enable; - +extern int sound_enable; extern int kiosk_enable; extern int sys_pause; diff --git a/src/main.c b/src/main.c index 0c4aa5f09..938a949dc 100644 --- a/src/main.c +++ b/src/main.c @@ -82,6 +82,8 @@ void play_sound(char *file) Uint32 dlen; SDL_AudioCVT cvt; + if (!sound_enable) return; + /* Look for an empty (or finished) sound slot */ for ( index=0; index Date: Tue, 8 Feb 2011 22:24:45 +0000 Subject: [PATCH 17/17] gol2 not resetting properly Causes life to malfunction severely in some cases --- src/powder.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/powder.c b/src/powder.c index f7106ed19..b3ab91b41 100644 --- a/src/powder.c +++ b/src/powder.c @@ -1350,12 +1350,10 @@ void update_particles_i(pixel *vid, int start, int inc) if (r && parts[r>>8].tmp<=0) parts[r>>8].type = PT_NONE;//using kill_part makes it not work } - gol2[nx][ny][0] = 0; - for ( z = 1; z<=NGOL; z++) - gol2[nx][ny][z] = 0; } if (createdsomething) GENERATION ++; + memset(gol2, 0, sizeof(gol2)); } if (ISWIRE==1) {