merge jacksonmj's and simon's changes, and made mouse coords show up in debug so it is easier to get them.
This commit is contained in:
parent
3babc0586c
commit
c1ca8bae29
@ -227,8 +227,9 @@ void open_link(char *uri);
|
|||||||
int report_ui(pixel *vid_buf, char *save_id);
|
int report_ui(pixel *vid_buf, char *save_id);
|
||||||
|
|
||||||
char *console_ui(pixel *vid_buf, char error[255]);
|
char *console_ui(pixel *vid_buf, char error[255]);
|
||||||
|
int console_parse_coords(char *txt, int *x, int *y, char *err);
|
||||||
int console_get_type(char *element);
|
int console_parse_type(char *txt, int *element, char *err);
|
||||||
|
int console_parse_partref(char *txt, int *which, char *err);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -59,6 +59,8 @@ void load_presets(void);
|
|||||||
|
|
||||||
void save_string(FILE *f, char *str);
|
void save_string(FILE *f, char *str);
|
||||||
|
|
||||||
|
int sregexp(const char *str, char *pattern);
|
||||||
|
|
||||||
int load_string(FILE *f, char *str, int max);
|
int load_string(FILE *f, char *str, int max);
|
||||||
|
|
||||||
void strcaturl(char *dst, char *src);
|
void strcaturl(char *dst, char *src);
|
||||||
|
@ -2885,10 +2885,10 @@ void draw_parts(pixel *vid)
|
|||||||
void render_signs(pixel *vid_buf)
|
void render_signs(pixel *vid_buf)
|
||||||
{
|
{
|
||||||
int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq;
|
int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq;
|
||||||
char buff[30]; //Buffer
|
|
||||||
for (i=0; i<MAXSIGNS; i++)
|
for (i=0; i<MAXSIGNS; i++)
|
||||||
if (signs[i].text[0])
|
if (signs[i].text[0])
|
||||||
{
|
{
|
||||||
|
char buff[256]; //Buffer
|
||||||
get_sign_pos(i, &x, &y, &w, &h);
|
get_sign_pos(i, &x, &y, &w, &h);
|
||||||
clearrect(vid_buf, x, y, w, h);
|
clearrect(vid_buf, x, y, w, h);
|
||||||
drawrect(vid_buf, x, y, w, h, 192, 192, 192, 255);
|
drawrect(vid_buf, x, y, w, h, 192, 192, 192, 255);
|
||||||
@ -2908,8 +2908,23 @@ void render_signs(pixel *vid_buf)
|
|||||||
drawtext(vid_buf, x+3, y+3, buff, 255, 255, 255, 255);
|
drawtext(vid_buf, x+3, y+3, buff, 255, 255, 255, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(sregexp(signs[i].text, "^{c:[0-9]*|.*}$")==0)
|
||||||
|
{
|
||||||
|
int sldr, startm;
|
||||||
|
memset(buff, 0, sizeof(buff));
|
||||||
|
for(sldr=3; signs[i].text[sldr-1] != '|'; sldr++)
|
||||||
|
startm = sldr + 1;
|
||||||
|
sldr = startm;
|
||||||
|
while(signs[i].text[sldr] != '}')
|
||||||
|
{
|
||||||
|
buff[sldr - startm] = signs[i].text[sldr];
|
||||||
|
sldr++;
|
||||||
|
}
|
||||||
|
drawtext(vid_buf, x+3, y+3, buff, 0, 191, 255, 255);
|
||||||
|
}
|
||||||
|
|
||||||
//Usual text
|
//Usual text
|
||||||
if (strcmp(signs[i].text, "{p}") && strcmp(signs[i].text, "{t}"))
|
if(strcmp(signs[i].text, "{p}") && strcmp(signs[i].text, "{t}") && sregexp(signs[i].text, "^{c:[0-9]*|.*}$"))
|
||||||
drawtext(vid_buf, x+3, y+3, signs[i].text, 255, 255, 255, 255);
|
drawtext(vid_buf, x+3, y+3, signs[i].text, 255, 255, 255, 255);
|
||||||
|
|
||||||
x = signs[i].x;
|
x = signs[i].x;
|
||||||
|
137
src/interface.c
137
src/interface.c
@ -89,8 +89,25 @@ void get_sign_pos(int i, int *x0, int *y0, int *w, int *h)
|
|||||||
if (strcmp(signs[i].text, "{t}")==0)
|
if (strcmp(signs[i].text, "{t}")==0)
|
||||||
*w = textwidth("Temp: 0000.00");
|
*w = textwidth("Temp: 0000.00");
|
||||||
|
|
||||||
|
if(sregexp(signs[i].text, "^{c:[0-9]*|.*}$")==0)
|
||||||
|
{
|
||||||
|
int sldr, startm;
|
||||||
|
char buff[256];
|
||||||
|
memset(buff, 0, sizeof(buff));
|
||||||
|
for(sldr=3; signs[i].text[sldr-1] != '|'; sldr++)
|
||||||
|
startm = sldr + 1;
|
||||||
|
|
||||||
|
sldr = startm;
|
||||||
|
while(signs[i].text[sldr] != '}')
|
||||||
|
{
|
||||||
|
buff[sldr - startm] = signs[i].text[sldr];
|
||||||
|
sldr++;
|
||||||
|
}
|
||||||
|
*w = textwidth(buff) + 5;
|
||||||
|
}
|
||||||
|
|
||||||
//Ususal width
|
//Ususal width
|
||||||
if (strcmp(signs[i].text, "{p}") && strcmp(signs[i].text, "{t}"))
|
if (strcmp(signs[i].text, "{p}") && strcmp(signs[i].text, "{t}") && sregexp(signs[i].text, "^{c:[0-9]*|.*}$"))
|
||||||
*w = textwidth(signs[i].text) + 5;
|
*w = textwidth(signs[i].text) + 5;
|
||||||
*h = 14;
|
*h = 14;
|
||||||
*x0 = (signs[i].ju == 2) ? signs[i].x - *w :
|
*x0 = (signs[i].ju == 2) ? signs[i].x - *w :
|
||||||
@ -3841,14 +3858,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?
|
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);
|
draw_line(vid_buf, 1, 219, XRES, 219, 228, 228, 228, XRES+BARSIZE);
|
||||||
drawtext(vid_buf, 100, 15, "Welcome to The Powder Toy console v.2 (by cracker64)\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"
|
"Current commands are quit, set, reset, load, create, file, kill\n"
|
||||||
"You can set type, temp, ctype, life, x, y, vx, vy using this format ('set life particle# 9001')\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"
|
"You can now use particle names (ex. set type all deut)\n"
|
||||||
"Reset works with pressure, velocity, sparks, temp (ex. 'reset pressure')\n"
|
"Reset works with pressure, velocity, sparks, temp (ex. 'reset pressure')\n"
|
||||||
"To load a save use load saveID (ex. load 1337)\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'"
|
"Run scripts from file 'file filename'\n"
|
||||||
|
"You can delete/kill a particle with 'kill x,y'"
|
||||||
,255, 187, 187, 255);
|
,255, 187, 187, 255);
|
||||||
|
|
||||||
cc = 0;
|
cc = 0;
|
||||||
@ -3862,7 +3880,7 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show
|
|||||||
{
|
{
|
||||||
if(cc<9) {
|
if(cc<9) {
|
||||||
currentcommand = currentcommand->prev_command;
|
currentcommand = currentcommand->prev_command;
|
||||||
} else if(currentcommand->prev_command!=NULL){
|
} else if(currentcommand->prev_command!=NULL) {
|
||||||
free(currentcommand->prev_command);
|
free(currentcommand->prev_command);
|
||||||
currentcommand->prev_command = NULL;
|
currentcommand->prev_command = NULL;
|
||||||
}
|
}
|
||||||
@ -3905,7 +3923,7 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(last_command!=NULL){
|
if(last_command!=NULL) {
|
||||||
currentcommand = last_command;
|
currentcommand = last_command;
|
||||||
for (cc = 0; cc<ci; cc++) {
|
for (cc = 0; cc<ci; cc++) {
|
||||||
if(currentcommand->prev_command==NULL)
|
if(currentcommand->prev_command==NULL)
|
||||||
@ -3924,26 +3942,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];
|
char num[4];
|
||||||
i = atoi(element);
|
if (i>=0 && i<PT_NUM)
|
||||||
sprintf(num,"%d",i);
|
{
|
||||||
if (i>=0 && i<PT_NUM && strcmp(element,num)==0)
|
sprintf(num,"%d",i);
|
||||||
return i;
|
if (strcmp(txt,num)==0)
|
||||||
if (strcasecmp(element,"C4")==0) return PT_PLEX;
|
{
|
||||||
if (strcasecmp(element,"C5")==0) return PT_C5;
|
*element = i;
|
||||||
if (strcasecmp(element,"NONE")==0) return PT_NONE;
|
return 1;
|
||||||
for (i=0; i<PT_NUM; i++) {
|
}
|
||||||
if (strcasecmp(element,ptypes[i].name)==0)
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
return -1;
|
i = -1;
|
||||||
|
// alternative names for some elements
|
||||||
|
if (strcasecmp(txt,"C4")==0) i = PT_PLEX;
|
||||||
|
else if (strcasecmp(txt,"C5")==0) i = PT_C5;
|
||||||
|
else if (strcasecmp(txt,"NONE")==0) i = PT_NONE;
|
||||||
|
if (i>=0)
|
||||||
|
{
|
||||||
|
*element = i;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
for (i=1; i<PT_NUM; i++) {
|
||||||
|
if (strcasecmp(txt,ptypes[i].name)==0)
|
||||||
|
{
|
||||||
|
*element = i;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
strcpy(err, "Particle type not recognised");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int console_parse_coords(char *txt, int *x, int *y, char *err)
|
||||||
|
{
|
||||||
|
// TODO: use regex?
|
||||||
|
char *coordtxt;
|
||||||
|
char num[10] = "";
|
||||||
|
int nx = -1, ny = -1;
|
||||||
|
txt = mystrdup(txt);
|
||||||
|
coordtxt = strtok(txt, ",");
|
||||||
|
if (coordtxt) nx = atoi(coordtxt);
|
||||||
|
if (nx>=0 && nx<XRES) sprintf(num,"%d",nx);
|
||||||
|
if (!coordtxt || strcmp(coordtxt, num)!=0)
|
||||||
|
{
|
||||||
|
strcpy(err,"Invalid coordinates");
|
||||||
|
free(txt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
strcpy(num,"");
|
||||||
|
coordtxt = strtok(NULL, ",");
|
||||||
|
if (coordtxt) ny = atoi(coordtxt);
|
||||||
|
if (ny>=0 && ny<YRES) sprintf(num,"%d",ny);
|
||||||
|
if (!coordtxt || strcmp(coordtxt, num)!=0)
|
||||||
|
{
|
||||||
|
strcpy(err,"Invalid coordinates");
|
||||||
|
free(txt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*x = nx;
|
||||||
|
*y = ny;
|
||||||
|
free(txt);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int console_parse_partref(char *txt, int *which, char *err)
|
||||||
|
{
|
||||||
|
// TODO: use regex?
|
||||||
|
int i = -1, nx, ny;
|
||||||
|
if (console_parse_coords(txt, &nx, &ny, err))
|
||||||
|
{
|
||||||
|
i = pmap[ny][nx];
|
||||||
|
if (!i || (i>>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<NPART && parts[i].type)
|
||||||
|
{
|
||||||
|
*which = i;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
strcpy(err,"Particle does not exist");
|
||||||
|
return 0;
|
||||||
}
|
}
|
131
src/main.c
131
src/main.c
@ -718,7 +718,7 @@ int parse_save(void *save, int size, int replace, int x0, int y0)
|
|||||||
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(ptypes[parts[i-1].type].properties&PROP_LIFE && !parts[i-1].tmp)
|
||||||
for(q = 1; q<NGOL ; q++) {
|
for(q = 1; q<=NGOL ; 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;
|
||||||
}
|
}
|
||||||
@ -1113,6 +1113,7 @@ int main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
char uitext[255] = "";
|
char uitext[255] = "";
|
||||||
char heattext[128] = "";
|
char heattext[128] = "";
|
||||||
|
char coordtext[13] = "";
|
||||||
int currentTime = 0;
|
int currentTime = 0;
|
||||||
int FPS = 0;
|
int FPS = 0;
|
||||||
int pastFPS = 0;
|
int pastFPS = 0;
|
||||||
@ -1765,6 +1766,7 @@ int main(int argc, char *argv[])
|
|||||||
if (tctype>=PT_NUM)
|
if (tctype>=PT_NUM)
|
||||||
tctype = 0;
|
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(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);
|
//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 {
|
} 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);
|
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);
|
||||||
@ -1773,6 +1775,8 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
else
|
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]);
|
sprintf(heattext, "Empty, Pressure: %3.2f", pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2159,8 +2163,37 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
else if (y<YRES)
|
else if (y<YRES)
|
||||||
{
|
{
|
||||||
|
int signi;
|
||||||
|
|
||||||
c = (b&1) ? sl : sr;
|
c = (b&1) ? sl : sr;
|
||||||
su = c;
|
su = c;
|
||||||
|
|
||||||
|
if(c!=WL_SIGN+100)
|
||||||
|
{
|
||||||
|
if(!bq)
|
||||||
|
for(signi=0; signi<MAXSIGNS; signi++)
|
||||||
|
if(sregexp(signs[signi].text, "^{c:[0-9]*|.*}$")==0)
|
||||||
|
{
|
||||||
|
int signx, signy, signw, signh;
|
||||||
|
get_sign_pos(signi, &signx, &signy, &signw, &signh);
|
||||||
|
if(x>=signx && x<=signx+signw && y>=signy && y<=signy+signh)
|
||||||
|
{
|
||||||
|
char buff[256];
|
||||||
|
int sldr;
|
||||||
|
|
||||||
|
memset(buff, 0, sizeof(buff));
|
||||||
|
|
||||||
|
for(sldr=3; signs[signi].text[sldr] != '|'; sldr++)
|
||||||
|
buff[sldr-3] = signs[signi].text[sldr];
|
||||||
|
|
||||||
|
char buff2[sldr-2]; //TODO: Fix this for Visual Studio
|
||||||
|
memset(buff2, 0, sizeof(buff2));
|
||||||
|
memcpy(&buff2, &buff, sldr-3);
|
||||||
|
open_ui(vid_buf, buff2, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (c==WL_SIGN+100)
|
if (c==WL_SIGN+100)
|
||||||
{
|
{
|
||||||
if (!bq)
|
if (!bq)
|
||||||
@ -2465,17 +2498,32 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
fillrect(vid_buf, XRES-20-textwidth(heattext), 266, textwidth(heattext)+8, 15, 0, 0, 0, 140);
|
fillrect(vid_buf, XRES-20-textwidth(heattext), 266, textwidth(heattext)+8, 15, 0, 0, 0, 140);
|
||||||
drawtext(vid_buf, XRES-16-textwidth(heattext), 270, heattext, 255, 255, 255, 200);
|
drawtext(vid_buf, XRES-16-textwidth(heattext), 270, heattext, 255, 255, 255, 200);
|
||||||
|
if(DEBUG_MODE)
|
||||||
|
{
|
||||||
|
fillrect(vid_buf, XRES-20-textwidth(coordtext), 280, textwidth(coordtext)+8, 13, 0, 0, 0, 140);
|
||||||
|
drawtext(vid_buf, XRES-16-textwidth(coordtext), 282, coordtext, 255, 255, 255, 200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fillrect(vid_buf, 12, 266, textwidth(heattext)+8, 15, 0, 0, 0, 140);
|
fillrect(vid_buf, 12, 266, textwidth(heattext)+8, 15, 0, 0, 0, 140);
|
||||||
drawtext(vid_buf, 16, 270, heattext, 255, 255, 255, 200);
|
drawtext(vid_buf, 16, 270, heattext, 255, 255, 255, 200);
|
||||||
|
if(DEBUG_MODE)
|
||||||
|
{
|
||||||
|
fillrect(vid_buf, 12, 280, textwidth(coordtext)+8, 13, 0, 0, 0, 140);
|
||||||
|
drawtext(vid_buf, 16, 282, coordtext, 255, 255, 255, 200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fillrect(vid_buf, XRES-20-textwidth(heattext), 12, textwidth(heattext)+8, 15, 0, 0, 0, 140);
|
fillrect(vid_buf, XRES-20-textwidth(heattext), 12, textwidth(heattext)+8, 15, 0, 0, 0, 140);
|
||||||
drawtext(vid_buf, XRES-16-textwidth(heattext), 16, heattext, 255, 255, 255, 200);
|
drawtext(vid_buf, XRES-16-textwidth(heattext), 16, heattext, 255, 255, 255, 200);
|
||||||
|
if(DEBUG_MODE)
|
||||||
|
{
|
||||||
|
fillrect(vid_buf, XRES-20-textwidth(coordtext), 26, textwidth(coordtext)+8, 11, 0, 0, 0, 140);
|
||||||
|
drawtext(vid_buf, XRES-16-textwidth(coordtext), 27, coordtext, 255, 255, 255, 200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fillrect(vid_buf, 12, 12, textwidth(uitext)+8, 15, 0, 0, 0, 140);
|
fillrect(vid_buf, 12, 12, textwidth(uitext)+8, 15, 0, 0, 0, 140);
|
||||||
drawtext(vid_buf, 16, 16, uitext, 32, 216, 255, 200);
|
drawtext(vid_buf, 16, 16, uitext, 32, 216, 255, 200);
|
||||||
@ -2503,7 +2551,7 @@ int main(int argc, char *argv[])
|
|||||||
http_done();
|
http_done();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int process_command(pixel *vid_buf,char *console,char *console_error) { //TODO: delete with coords, have 'set' work with coords as well
|
int process_command(pixel *vid_buf,char *console,char *console_error) {
|
||||||
|
|
||||||
int nx,ny,i,j;
|
int nx,ny,i,j;
|
||||||
char *console2;
|
char *console2;
|
||||||
@ -2556,17 +2604,21 @@ char *console5;
|
|||||||
console_mode = 0;
|
console_mode = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(strcmp(console2, "create")==0 && console3 && console4 && console5)
|
else if (strcmp(console2, "create")==0 && console3 && console4)
|
||||||
{
|
{
|
||||||
j = console_get_type(console3);
|
if (console_parse_type(console3, &j, console_error)
|
||||||
if (j<0)
|
&& console_parse_coords(console4, &nx, &ny, console_error))
|
||||||
sprintf(console_error, "Particle type not recognised", console2);
|
{
|
||||||
nx = atoi(console4);
|
if (!j)
|
||||||
ny = atoi(console5);
|
strcpy(console_error, "Cannot create particle with type NONE");
|
||||||
if(ny < 0 || nx < 0 || ny > YRES || nx > XRES)
|
else if (create_part(-1,nx,ny,j)<0)
|
||||||
sprintf(console_error, "Invalid Coordinates", console2);
|
strcpy(console_error, "Could not create particle");
|
||||||
else
|
}
|
||||||
create_part(-1,nx,ny,j);
|
}
|
||||||
|
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)
|
else if(strcmp(console2, "reset")==0 && console3)
|
||||||
{
|
{
|
||||||
@ -2624,8 +2676,7 @@ char *console5;
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = atoi(console4);
|
if (console_parse_partref(console4, &i, console_error))
|
||||||
if(parts[i].type)
|
|
||||||
{
|
{
|
||||||
j = atoi(console5);
|
j = atoi(console5);
|
||||||
parts[i].life = j;
|
parts[i].life = j;
|
||||||
@ -2636,10 +2687,7 @@ char *console5;
|
|||||||
{
|
{
|
||||||
if(strcmp(console4, "all")==0)
|
if(strcmp(console4, "all")==0)
|
||||||
{
|
{
|
||||||
j = console_get_type(console5);
|
if (console_parse_type(console5, &j, console_error))
|
||||||
if (j<0)
|
|
||||||
sprintf(console_error, "Particle type not recognised", console2);
|
|
||||||
else
|
|
||||||
for(i=0; i<NPART; i++)
|
for(i=0; i<NPART; i++)
|
||||||
{
|
{
|
||||||
if(parts[i].type)
|
if(parts[i].type)
|
||||||
@ -2648,14 +2696,10 @@ char *console5;
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = atoi(console4);
|
if (console_parse_partref(console4, &i, console_error)
|
||||||
if(parts[i].type)
|
&& console_parse_type(console5, &j, console_error))
|
||||||
{
|
{
|
||||||
j = console_get_type(console5);
|
parts[i].type = j;
|
||||||
if (j<0)
|
|
||||||
sprintf(console_error, "Particle type not recognised", console2);
|
|
||||||
else
|
|
||||||
parts[i].type = j;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2672,8 +2716,7 @@ char *console5;
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = atoi(console4);
|
if (console_parse_partref(console4, &i, console_error))
|
||||||
if(parts[i].type)
|
|
||||||
{
|
{
|
||||||
j = atoi(console5);
|
j = atoi(console5);
|
||||||
parts[i].temp = j;
|
parts[i].temp = j;
|
||||||
@ -2693,8 +2736,7 @@ char *console5;
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = atoi(console4);
|
if (console_parse_partref(console4, &i, console_error))
|
||||||
if(parts[i].type)
|
|
||||||
{
|
{
|
||||||
j = atoi(console5);
|
j = atoi(console5);
|
||||||
parts[i].tmp = j;
|
parts[i].tmp = j;
|
||||||
@ -2714,8 +2756,7 @@ char *console5;
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = atoi(console4);
|
if (console_parse_partref(console4, &i, console_error))
|
||||||
if(parts[i].type)
|
|
||||||
{
|
{
|
||||||
j = atoi(console5);
|
j = atoi(console5);
|
||||||
parts[i].x = j;
|
parts[i].x = j;
|
||||||
@ -2735,8 +2776,7 @@ char *console5;
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = atoi(console4);
|
if (console_parse_partref(console4, &i, console_error))
|
||||||
if(parts[i].type)
|
|
||||||
{
|
{
|
||||||
j = atoi(console5);
|
j = atoi(console5);
|
||||||
parts[i].y = j;
|
parts[i].y = j;
|
||||||
@ -2747,19 +2787,18 @@ char *console5;
|
|||||||
{
|
{
|
||||||
if(strcmp(console4, "all")==0)
|
if(strcmp(console4, "all")==0)
|
||||||
{
|
{
|
||||||
j = atoi(console5);
|
if (console_parse_type(console5, &j, console_error))
|
||||||
for(i=0; i<NPART; i++)
|
for(i=0; i<NPART; i++)
|
||||||
{
|
{
|
||||||
if(parts[i].type)
|
if(parts[i].type)
|
||||||
parts[i].ctype = j;
|
parts[i].ctype = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = atoi(console4);
|
if (console_parse_partref(console4, &i, console_error)
|
||||||
if(parts[i].type)
|
&& console_parse_type(console5, &j, console_error))
|
||||||
{
|
{
|
||||||
j = atoi(console5);
|
|
||||||
parts[i].ctype = j;
|
parts[i].ctype = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2777,8 +2816,7 @@ char *console5;
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = atoi(console4);
|
if (console_parse_partref(console4, &i, console_error))
|
||||||
if(parts[i].type)
|
|
||||||
{
|
{
|
||||||
j = atoi(console5);
|
j = atoi(console5);
|
||||||
parts[i].vx = j;
|
parts[i].vx = j;
|
||||||
@ -2798,8 +2836,7 @@ char *console5;
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i = atoi(console4);
|
if (console_parse_partref(console4, &i, console_error))
|
||||||
if(parts[i].type)
|
|
||||||
{
|
{
|
||||||
j = atoi(console5);
|
j = atoi(console5);
|
||||||
parts[i].vy = j;
|
parts[i].vy = j;
|
||||||
@ -2811,5 +2848,5 @@ char *console5;
|
|||||||
sprintf(console_error, "Invalid Command", console2);
|
sprintf(console_error, "Invalid Command", console2);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
src/misc.c
13
src/misc.c
@ -1,6 +1,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <regex.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "interface.h"
|
#include "interface.h"
|
||||||
@ -116,6 +118,17 @@ void save_presets(int do_update)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sregexp(const char *str, char *pattern)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
regex_t patternc;
|
||||||
|
if(regcomp(&patternc, pattern, 0)!=0)
|
||||||
|
return 1;
|
||||||
|
result = regexec(&patternc, str, 0, NULL, 0);
|
||||||
|
regfree(&patternc);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void load_presets(void)
|
void load_presets(void)
|
||||||
{
|
{
|
||||||
FILE *f=fopen("powder.def", "rb");
|
FILE *f=fopen("powder.def", "rb");
|
||||||
|
Reference in New Issue
Block a user