diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/elements/fwrk.c | 2 | ||||
| -rw-r--r-- | src/main.c | 100 | ||||
| -rw-r--r-- | src/powder.c | 10 |
3 files changed, 51 insertions, 61 deletions
diff --git a/src/elements/fwrk.c b/src/elements/fwrk.c index 06390c5..5095cde 100644 --- a/src/elements/fwrk.c +++ b/src/elements/fwrk.c @@ -16,7 +16,7 @@ int update_FWRK(UPDATE_FUNC_ARGS) { } if (parts[i].life>=45) parts[i].life=0; - if ((parts[i].life<3&&parts[i].life>0)||parts[i].vy>6&&parts[i].life>0) + if ((parts[i].life<3&&parts[i].life>0)||(parts[i].vy>6&&parts[i].life>0)) { int q = (rand()%255+1); int w = (rand()%255+1); @@ -554,19 +554,7 @@ int parse_save(void *save, int size, int replace, int x0, int y0) gravityMode = 0; airMode = 0; } - memset(bmap, 0, sizeof(bmap)); - memset(emap, 0, sizeof(emap)); - memset(signs, 0, sizeof(signs)); - memset(parts, 0, sizeof(particle)*NPART); - memset(pmap, 0, sizeof(pmap)); - memset(vx, 0, sizeof(vx)); - memset(vy, 0, sizeof(vy)); - memset(pv, 0, sizeof(pv)); - memset(photons, 0, sizeof(photons)); - memset(wireless, 0, sizeof(wireless)); - memset(gol2, 0, sizeof(gol2)); - memset(portal, 0, sizeof(portal)); - death = death2 = ISSPAWN1 = ISSPAWN2 = 0; + clear_sim(); } // make a catalog of free parts @@ -898,13 +886,35 @@ corrupt: if (replace) { legacy_enable = 0; - memset(signs, 0, sizeof(signs)); - memset(parts, 0, sizeof(particle)*NPART); - memset(bmap, 0, sizeof(bmap)); + clear_sim(); } return 1; } +void clear_sim(void) +{ + memset(bmap, 0, sizeof(bmap)); + memset(emap, 0, sizeof(emap)); + memset(signs, 0, sizeof(signs)); + memset(parts, 0, sizeof(particle)*NPART); + memset(pmap, 0, sizeof(pmap)); + memset(pv, 0, sizeof(pv)); + memset(vx, 0, sizeof(vx)); + memset(vy, 0, sizeof(vy)); + memset(fvx, 0, sizeof(fvx)); + memset(fvy, 0, sizeof(fvy)); + memset(photons, 0, sizeof(photons)); + memset(wireless, 0, sizeof(wireless)); + memset(gol2, 0, sizeof(gol2)); + memset(portal, 0, sizeof(portal)); + death = death2 = ISSPAWN1 = ISSPAWN2 = 0; + memset(pers_bg, 0, (XRES+BARSIZE)*YRES*PIXELSIZE); + memset(fire_bg, 0, XRES*YRES*PIXELSIZE); + memset(fire_r, 0, sizeof(fire_r)); + memset(fire_g, 0, sizeof(fire_g)); + memset(fire_b, 0, sizeof(fire_b)); +} + // stamps library stamp stamps[STAMP_MAX];//[STAMP_X*STAMP_Y]; @@ -1189,6 +1199,7 @@ int main(int argc, char *argv[]) int pastFPS = 0; int past = 0; pixel *vid_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); + pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE); void *http_ver_check; void *http_session_check = NULL; char *ver_data=NULL, *check_data=NULL, *tmp; @@ -1240,8 +1251,7 @@ int main(int argc, char *argv[]) parts[NPART-1].life = -1; pfree = 0; fire_bg=calloc(XRES*YRES, PIXELSIZE); - pers_bg=calloc((XRES+BARSIZE)*YRES, PIXELSIZE); - memset(signs, 0, sizeof(signs)); + clear_sim(); //fbi_img = render_packed_rgb(fbi, FBI_W, FBI_H, FBI_CMP); @@ -1441,8 +1451,8 @@ int main(int argc, char *argv[]) { svf_admin = 0; svf_mod = 1; - } - } + } + } } else { @@ -1527,7 +1537,7 @@ int main(int argc, char *argv[]) free(load_data); } } - if (sdl_key=='s' && (sdl_mod & (KMOD_CTRL)) || (sdl_key=='s' && !isplayer2)) + if ((sdl_key=='s' && (sdl_mod & (KMOD_CTRL))) || (sdl_key=='s' && !isplayer2)) { if (it > 50) it = 50; @@ -1661,7 +1671,7 @@ int main(int argc, char *argv[]) bsy = 0; } } - if (sdl_key=='d'&&(sdl_mod & (KMOD_CTRL)) || (sdl_key=='d' && !isplayer2)) + if ((sdl_key=='d'&&(sdl_mod & (KMOD_CTRL))) || (sdl_key=='d' && !isplayer2)) DEBUG_MODE = !DEBUG_MODE; if (sdl_key=='i') { @@ -1918,7 +1928,7 @@ int main(int argc, char *argv[]) console = console_ui(vid_buf,console_error); console = mystrdup(console); strcpy(console_error,""); - if(process_command(vid_buf,console,&console_error)==-1) + if(process_command(vid_buf,console,console_error)==-1) { free(console); break; @@ -2276,19 +2286,7 @@ int main(int argc, char *argv[]) } if (x>=(XRES+BARSIZE-(510-367)) && x<=(XRES+BARSIZE-(510-383)) && !bq) { - memset(signs, 0, sizeof(signs)); - memset(pv, 0, sizeof(pv)); - memset(vx, 0, sizeof(vx)); - memset(vy, 0, sizeof(vy)); - memset(fvx, 0, sizeof(fvx)); - memset(fvy, 0, sizeof(fvy)); - memset(bmap, 0, sizeof(bmap)); - memset(emap, 0, sizeof(emap)); - memset(parts, 0, sizeof(particle)*NPART); - memset(photons, 0, sizeof(photons)); - memset(wireless, 0, sizeof(wireless)); - memset(gol2, 0, sizeof(gol2)); - memset(portal, 0, sizeof(portal)); + clear_sim(); for (i=0; i<NPART-1; i++) parts[i].life = i+1; parts[NPART-1].life = -1; @@ -2305,17 +2303,8 @@ int main(int argc, char *argv[]) svf_description[0] = 0; gravityMode = 0; airMode = 0; - death = death2 = 0; isplayer2 = 0; isplayer = 0; - ISSPAWN1 = 0; - ISSPAWN2 = 0; - - memset(fire_bg, 0, XRES*YRES*PIXELSIZE); - memset(pers_bg, 0, (XRES+BARSIZE)*YRES*PIXELSIZE); - memset(fire_r, 0, sizeof(fire_r)); - memset(fire_g, 0, sizeof(fire_g)); - memset(fire_b, 0, sizeof(fire_b)); } if (x>=(XRES+BARSIZE-(510-385)) && x<=(XRES+BARSIZE-(510-476))) { @@ -2775,7 +2764,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { { return -1; } - else if(strcmp(console2, "file")==0 && console3) + else if(strcmp(console2, "file")==0) { if(file_script){ FILE *f=fopen(console3, "r"); @@ -2789,8 +2778,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { ny = 0; j = 0; m = 0; - if(console4) - console_parse_coords(console4, &nx , &ny, console_error); + console_parse_coords(console4, &nx , &ny, console_error); memset(pch,0,sizeof(pch)); memset(fileread,0,sizeof(fileread)); fread(fileread,1,5000,f); @@ -2865,12 +2853,12 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { } } - else if(strcmp(console2, "sound")==0 && console3) + else if(strcmp(console2, "sound")==0) { if (sound_enable) play_sound(console3); else strcpy(console_error, "Audio device not available - cannot play sounds"); } - else if(strcmp(console2, "load")==0 && console3) + else if(strcmp(console2, "load")==0) { j = atoi(console3); if(j) @@ -2879,7 +2867,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { console_mode = 0; } } - else if(strcmp(console2, "if")==0 && console3) + else if(strcmp(console2, "if")==0) { if(strcmp(console3, "type")==0)//TODO: add more than just type, and be able to check greater/less than { @@ -2895,7 +2883,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { return 0; } } - else if (strcmp(console2, "create")==0 && console3 && console4) + else if (strcmp(console2, "create")==0) { if (console_parse_type(console3, &j, console_error) && console_parse_coords(console4, &nx, &ny, console_error)) @@ -2906,12 +2894,12 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { strcpy(console_error, "Could not create particle"); } } - else if ((strcmp(console2, "delete")==0 || strcmp(console2, "kill")==0) && console3) + else if (strcmp(console2, "delete")==0 || strcmp(console2, "kill")==0) { if (console_parse_partref(console3, &i, console_error)) kill_part(i); } - else if(strcmp(console2, "reset")==0 && console3) + else if(strcmp(console2, "reset")==0) { if(strcmp(console3, "pressure")==0) { @@ -2952,7 +2940,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { } } } - else if(strcmp(console2, "set")==0 && console3 && console4 && console5) + else if(strcmp(console2, "set")==0) { if(strcmp(console3, "life")==0) { @@ -3217,7 +3205,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { } } else - sprintf(console_error, "Invalid Command", console2); + strcpy(console_error, "Invalid Command"); } return 1; } diff --git a/src/powder.c b/src/powder.c index 78562b8..914bb4e 100644 --- a/src/powder.c +++ b/src/powder.c @@ -488,7 +488,7 @@ inline int create_n_parts(int n, int x, int y, float vx, float vy, int t) if (x<0 || y<0 || x>=XRES || y>=YRES || t<0 || t>=PT_NUM) return -1; - for (c; c<n; c++) { + for (c=0; c<n; c++) { float r = (rand()%128+128)/127.0f; float a = (rand()%360)*3.14159f/180.0f; if (pfree == -1) @@ -741,7 +741,7 @@ inline int create_part(int p, int x, int y, int t) { if (isplayer==0) { - if (pmap[y][x]&0xFF==PT_SPAWN) + if ((pmap[y][x]&0xFF)==PT_SPAWN) { parts[pmap[y][x]>>8].type = PT_STKM; parts[pmap[y][x]>>8].vx = 0; @@ -799,7 +799,7 @@ inline int create_part(int p, int x, int y, int t) { if (isplayer2==0) { - if (pmap[y][x]&0xFF==PT_SPAWN2) + if ((pmap[y][x]&0xFF)==PT_SPAWN2) { parts[pmap[y][x]>>8].type = PT_STKM2; parts[pmap[y][x]>>8].vx = 0; @@ -1335,7 +1335,7 @@ void update_particles_i(pixel *vid, int start, int inc) { r = pmap[ny][nx]; neighbors = gol2[nx][ny][0]; - if(neighbors==0 || !(ptypes[r&0xFF].properties&PROP_LIFE || !r&0xFF) || (r>>8)>=NPART) + if(neighbors==0 || !(ptypes[r&0xFF].properties&PROP_LIFE || !(r&0xFF)) || (r>>8)>=NPART) continue; for ( golnum = 1; golnum<=NGOL; golnum++) for ( goldelete = 0; goldelete<9; goldelete++) @@ -2925,10 +2925,12 @@ int create_parts(int x, int y, int rx, int ry, int c) for (j=-ry; j<=ry; j++) for (i=-rx; i<=rx; i++) if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx)) + { if (!REPLACE_MODE) create_part(-2, x+i, y+j, c); else if ((pmap[y+j][x+i]&0xFF)==SLALT&&SLALT!=0) create_part(-2, x+i, y+j, c); + } return 1; } |
