From 5d34cae2e48938aaeebb44786e164bc3c7d94a43 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sat, 29 Jan 2011 11:18:10 +0000 Subject: [PATCH 1/7] Consistent use of NGOL, better NSCN description --- includes/defines.h | 4 ++-- includes/powder.h | 4 ++-- src/main.c | 2 +- src/powder.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/includes/defines.h b/includes/defines.h index 43b259846..b6df68921 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -61,7 +61,7 @@ extern unsigned char ZSIZE; #define STAMP_Y 4 #define STAMP_MAX 120 -#define NGOL 26 +#define NGOL 25 #define CIRCLE_BRUSH 0 #define SQUARE_BRUSH 1 @@ -136,7 +136,7 @@ int GSPEED; int love[XRES/9][YRES/9]; int lolz[XRES/9][YRES/9]; int gol[XRES][YRES]; -int gol2[XRES][YRES][NGOL]; +int gol2[XRES][YRES][NGOL+1]; int SEC; int SEC2; int REPLACE_MODE; diff --git a/includes/powder.h b/includes/powder.h index 91d8f1fa2..b09ad5ead 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -405,7 +405,7 @@ static const part_type ptypes[PT_NUM] = {"WAX", PIXPACK(0xF0F0BB), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 10, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 44, "Wax. Melts at moderately high temperatures.", ST_SOLID, TYPE_SOLID, NULL}, {"MWAX", PIXPACK(0xE0E0AA), 0.3f, 0.02f * CFDS, 0.95f, 0.80f, 0.0f, 0.15f, 0.00f, 0.000001f* CFDS,2, 5, 0, 0, 2, 1, 25, SC_LIQUID, R_TEMP+28.0f+273.15f, 44, "Liquid Wax.", ST_LIQUID, TYPE_LIQUID, NULL}, {"PSCN", PIXPACK(0x805050), 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, "P-Type Silicon, Will transfer current to any conductor.", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS, NULL}, - {"NSCN", PIXPACK(0x505080), 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, "N-Type Silicon, Will only transfer current to P-Type Silicon.", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS, NULL}, + {"NSCN", PIXPACK(0x505080), 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, "N-Type Silicon, Will not transfer current to P-Type Silicon.", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS, NULL}, {"LN2", PIXPACK(0x80A0DF), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 0, 1, 30, SC_LIQUID, 70.15f, 70, "Liquid Nitrogen. Very cold.", ST_SOLID, TYPE_LIQUID, NULL}, {"INSL", PIXPACK(0x9EA3B6), 0.0f, 0.00f * CFDS, 0.95f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 7, 0, 0, 10, 1, 100, SC_SPECIAL, R_TEMP+0.0f +273.15f, 0, "Insulator, does not conduct heat or electricity.", ST_SOLID, TYPE_SOLID, NULL}, {"BHOL", PIXPACK(0x202020), 0.0f, 0.00f * CFDS, 0.95f, 0.00f, 0.0f, 0.0f, 0.00f, -0.01f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_SPECIAL, R_TEMP+70.0f+273.15f, 255, "Black hole, sucks in other particles and heats up.", ST_NONE, TYPE_SOLID, NULL}, @@ -687,7 +687,7 @@ static part_transition ptransitions[PT_NUM] = #undef ST -static int grule[NGOL][10] = +static int grule[NGOL+1][10] = { // 0,1,2,3,4,5,6,7,8,STATES live=1 spawn=2 spawn&live=3 States are kind of how long until it dies, normal ones use two states(living,dead) for others the intermediate states live but do nothing {0,0,0,0,0,0,0,0,0,2},//blank diff --git a/src/main.c b/src/main.c index 46267c22c..aa2e19066 100644 --- a/src/main.c +++ b/src/main.c @@ -718,7 +718,7 @@ int parse_save(void *save, int size, int replace, int x0, int y0) 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>8)>=NPART) continue; - for ( golnum = 1; golnum=2&&gol2[nx][ny][golnum]>=(goldelete%2)+goldelete/2) @@ -1345,7 +1345,7 @@ void update_particles_i(pixel *vid, int start, int inc) parts[r>>8].type = PT_NONE;//using kill_part makes it not work } gol2[nx][ny][0] = 0; - for ( z = 1; z Date: Sun, 30 Jan 2011 22:37:59 +0000 Subject: [PATCH 2/7] Console segfault fix ed.str is deallocated when console_ui returns. Dereferencing the returned pointer to ed.str therefore results in bad things. --- src/interface.c | 2 +- src/main.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/interface.c b/src/interface.c index e3450074a..d020bf6fb 100644 --- a/src/interface.c +++ b/src/interface.c @@ -3883,7 +3883,7 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show currentcommand->prev_command = last_command; currentcommand->command = mystrdup(ed.str); last_command = currentcommand; - return ed.str; + return currentcommand->command; } if (sdl_key==SDLK_ESCAPE || sdl_key==SDLK_BACKQUOTE) { diff --git a/src/main.c b/src/main.c index d20fb35e0..a3891d097 100644 --- a/src/main.c +++ b/src/main.c @@ -1707,6 +1707,7 @@ int main(int argc, char *argv[]) //char error[255] = "error!"; sys_pause = 1; console = console_ui(vid_buf,error); + console = mystrdup(console); strcpy(error,""); if(console && strcmp(console, "")!=0 && strncmp(console, " ", 1)!=0) { @@ -1716,6 +1717,7 @@ int main(int argc, char *argv[]) console5 = strtok(NULL, " "); if(strcmp(console2, "quit")==0) { + free(console); break; } else if(strcmp(console2, "load")==0 && console3) @@ -1955,6 +1957,7 @@ int main(int argc, char *argv[]) else sprintf(error, "Invalid Command", console2); } + free(console); if(!console_mode) hud_enable = 1; } From cdd7399cc1c009838970ab5dce60c5ad4c332d46 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Mon, 31 Jan 2011 02:42:34 +0000 Subject: [PATCH 3/7] Make console recognise element names --- includes/interface.h | 2 ++ src/interface.c | 16 +++++++++++++++ src/main.c | 49 +++++++++++++++++++++++++++++--------------- 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/includes/interface.h b/includes/interface.h index de1c95509..870e917e1 100644 --- a/includes/interface.h +++ b/includes/interface.h @@ -228,5 +228,7 @@ int report_ui(pixel *vid_buf, char *save_id); char *console_ui(pixel *vid_buf, char error[255]); +int console_get_type(char *element); + #endif diff --git a/src/interface.c b/src/interface.c index 7975278c6..221f2d5a0 100644 --- a/src/interface.c +++ b/src/interface.c @@ -3927,3 +3927,19 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show } +int console_get_type(char *element) +{ + int i; + char num[4]; + i = atoi(element); + sprintf(num,"%d",i); + if (i>=0 && i Date: Mon, 31 Jan 2011 00:12:47 -0500 Subject: [PATCH 4/7] Moved console commands into own function. Added running script files so console commands can be run instantly. Added create command. element names work, from jacksonmj. --- includes/interface.h | 2 + src/interface.c | 19 ++ src/main.c | 569 ++++++++++++++++++++++++------------------- 3 files changed, 336 insertions(+), 254 deletions(-) diff --git a/includes/interface.h b/includes/interface.h index de1c95509..870e917e1 100644 --- a/includes/interface.h +++ b/includes/interface.h @@ -228,5 +228,7 @@ int report_ui(pixel *vid_buf, char *save_id); char *console_ui(pixel *vid_buf, char error[255]); +int console_get_type(char *element); + #endif diff --git a/src/interface.c b/src/interface.c index 8ec97fb46..65f340c1f 100644 --- a/src/interface.c +++ b/src/interface.c @@ -3898,6 +3898,7 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show if(ci==-1) { strcpy(ed.str, ""); + ed.cursor = strlen(ed.str); } else { @@ -3916,6 +3917,7 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show { ci = -1; strcpy(ed.str, ""); + ed.cursor = strlen(ed.str); } } } @@ -3925,3 +3927,20 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show } +int console_get_type(char *element) +{ + int i; + char num[4]; + i = atoi(element); + sprintf(num,"%d",i); + if (i>=0 && i YRES || nx > XRES) + sprintf(console_error, "Invalid Coordinates", console2); + else + create_part(-1,nx,ny,j); + } + else if(strcmp(console2, "reset")==0 && console3) + { + if(strcmp(console3, "pressure")==0) + { + for (nx = 0; nx Date: Mon, 31 Jan 2011 00:49:50 -0500 Subject: [PATCH 5/7] stupid git, didn't take description change --- src/interface.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/interface.c b/src/interface.c index 65f340c1f..1d1c258b0 100644 --- a/src/interface.c +++ b/src/interface.c @@ -3840,12 +3840,15 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show clearrect(vid_buf, 0, 0, XRES+BARSIZE, 220);//anyway to make it transparent? draw_line(vid_buf, 1, 219, XRES, 219, 228, 228, 228, XRES+BARSIZE); - drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.1 (by cracker64)\n" - "Current commands are quit, set, reset, load\n" + drawtext(vid_buf, 100, 15, "Welcome to The Powder Toy console v.2 (by cracker64)\n" + "Current commands are quit, set, reset, load, create, file\n" "You can set type, temp, ctype, life, x, y, vx, vy using this format ('set life particle# 9001')\n" - "You can also use 'all' instead of a particle number to do it to everything\n" + "You can also use 'all' instead of a particle number to do it to everything.\n" + "You can now use particle names (ex. set type all deut)\n" "Reset works with pressure, velocity, sparks, temp (ex. 'reset pressure')\n" - "To load a save use load saveID (ex. load 1337)" + "To load a save use load saveID (ex. load 1337)\n" + "Create particles with 'create deut x y' where x and y are the coords\n" + "Run scripts from file 'file filename'" ,255, 187, 187, 255); cc = 0; From 5bf8755655c081610db47288c15e65f8e7b748ba Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Mon, 31 Jan 2011 16:36:40 +0000 Subject: [PATCH 6/7] Console improvements Can use x,y coordinates to specify which particle. ctype now also accepts element names. More sanity checking of input. delete command added. --- includes/interface.h | 5 +- src/interface.c | 111 ++++++++++++++++++++++++++++++++++++------- src/main.c | 79 +++++++++++++----------------- 3 files changed, 130 insertions(+), 65 deletions(-) diff --git a/includes/interface.h b/includes/interface.h index 870e917e1..2cb64dd2d 100644 --- a/includes/interface.h +++ b/includes/interface.h @@ -227,8 +227,9 @@ void open_link(char *uri); int report_ui(pixel *vid_buf, char *save_id); char *console_ui(pixel *vid_buf, char error[255]); - -int console_get_type(char *element); +int console_parse_coords(char *txt, int *x, int *y, char *err); +int console_parse_type(char *txt, int *element, char *err); +int console_parse_partref(char *txt, int *which, char *err); #endif diff --git a/src/interface.c b/src/interface.c index af607c118..709a3fa4e 100644 --- a/src/interface.c +++ b/src/interface.c @@ -3847,7 +3847,7 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show "You can now use particle names (ex. set type all deut)\n" "Reset works with pressure, velocity, sparks, temp (ex. 'reset pressure')\n" "To load a save use load saveID (ex. load 1337)\n" - "Create particles with 'create deut x y' where x and y are the coords\n" + "Create particles with 'create deut x,y' where x and y are the coords\n" "Run scripts from file 'file filename'" ,255, 187, 187, 255); @@ -3924,26 +3924,101 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show } } } - } - - + return NULL; } -int console_get_type(char *element) +int console_parse_type(char *txt, int *element, char *err) { - int i; + int i = atoi(txt); char num[4]; - i = atoi(element); - sprintf(num,"%d",i); - if (i>=0 && i=0 && i=0) + { + *element = i; + return 1; + } + for (i=1; i=0 && nx=0 && ny>8)>=NPART) + i = -1; + else + i = i>>8; + } + 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) + i = -1; + free(num); + } + if (i>=0 && i YRES || nx > XRES) - sprintf(console_error, "Invalid Coordinates", console2); - else - create_part(-1,nx,ny,j); + if (console_parse_type(console3, &j, console_error) + && console_parse_coords(console4, &nx, &ny, console_error)) + { + if (!j) + strcpy(console_error, "Cannot create particle with type NONE"); + else if (create_part(-1,nx,ny,j)<0) + strcpy(console_error, "Could not create particle"); + } + } + else if ((strcmp(console2, "delete")==0 || strcmp(console2, "kill")==0) && console3) + { + if (console_parse_partref(console3, &i, console_error)) + kill_part(i); } else if(strcmp(console2, "reset")==0 && console3) { @@ -2624,8 +2628,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { //TODO: } else { - i = atoi(console4); - if(parts[i].type) + if (console_parse_partref(console4, &i, console_error)) { j = atoi(console5); parts[i].life = j; @@ -2636,10 +2639,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { //TODO: { if(strcmp(console4, "all")==0) { - j = console_get_type(console5); - if (j<0) - sprintf(console_error, "Particle type not recognised", console2); - else + if (console_parse_type(console5, &j, console_error)) for(i=0; i Date: Mon, 31 Jan 2011 22:00:12 +0000 Subject: [PATCH 7/7] Attempt fix for liquids --- src/powder.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/powder.c b/src/powder.c index a378da46d..493dec71f 100644 --- a/src/powder.c +++ b/src/powder.c @@ -1963,15 +1963,15 @@ killed: { parts[i].x = clear_xf+(j-clear_x); parts[i].y = fin_yf; - x = j; - y = fin_y; + nx = j; + ny = fin_y; s = 1; break; } if (try_move(i, x, y, j, clear_y)) { parts[i].x = clear_xf+(j-clear_x); - x = j; + nx = j; s = 1; break; } @@ -1985,12 +1985,12 @@ killed: if (s) for (j=clear_y+r; j>=0 && j=clear_y-rt && j