diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/elements/fwrk.c | 2 | ||||
| -rw-r--r-- | src/elements/prto.c | 8 | ||||
| -rw-r--r-- | src/elements/stkm.c | 25 | ||||
| -rw-r--r-- | src/elements/stkm2.c | 25 | ||||
| -rw-r--r-- | src/graphics.c | 73 | ||||
| -rw-r--r-- | src/interface.c | 54 | ||||
| -rw-r--r-- | src/main.c | 311 | ||||
| -rw-r--r-- | src/misc.c | 65 | ||||
| -rw-r--r-- | src/powder.c | 313 |
9 files changed, 466 insertions, 410 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); diff --git a/src/elements/prto.c b/src/elements/prto.c index 8f743e7..fbbd5a1 100644 --- a/src/elements/prto.c +++ b/src/elements/prto.c @@ -6,8 +6,8 @@ int update_PRTO(UPDATE_FUNC_ARGS) { 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++) + for (rx=1; rx>-2; rx--) + for (ry=1; ry>-2; ry--) if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) { r = pmap[y+ry][x+rx]; @@ -21,8 +21,8 @@ int update_PRTO(UPDATE_FUNC_ARGS) { int randomness = count + rand()%3-1; if (randomness<1) randomness=1; - if (randomness>8) - randomness=8; + if (randomness>9) + randomness=9; if (portal[parts[i].tmp][randomness-1][nnx]==PT_SPRK)// TODO: make it look better { create_part(-1,x+1,y,portal[parts[i].tmp][randomness-1][nnx]); diff --git a/src/elements/stkm.c b/src/elements/stkm.c index 6d6b4ab..fc6dc55 100644 --- a/src/elements/stkm.c +++ b/src/elements/stkm.c @@ -185,8 +185,10 @@ int update_STKM(UPDATE_FUNC_ARGS) { { r = pmap[y+ry][x+rx]; if (!r || (r>>8)>=NPART) + r = photons[y+ry][x+rx]; + if (!r || (r>>8)>=NPART) continue; - if (ptypes[r&0xFF].falldown!=0 || (r&0xFF) == PT_NEUT || (r&0xFF) == PT_PHOT) // TODO: photons are not in the pmap. This line may not work as intended. + if (ptypes[r&0xFF].falldown!=0 || (r&0xFF) == PT_NEUT || (r&0xFF) == PT_PHOT) { player[2] = r&0xFF; //Current element } @@ -225,26 +227,27 @@ int update_STKM(UPDATE_FUNC_ARGS) { } else { + int np = -1; if (player[2] == SPC_AIR) create_parts(rx + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01), ry, 4, 4, SPC_AIR); else - create_part(-1, rx, ry, player[2]); - - r = pmap[ry][rx]; - if ( ((r>>8) < NPART) && (r>>8)>=0 && player[2] != PT_PHOT && player[2] != SPC_AIR) - parts[r>>8].vx = parts[r>>8].vx + 5*((((int)player[1])&0x02) == 0x02) - 5*(((int)(player[1])&0x01) == 0x01); - if (((r>>8) < NPART) && (r>>8)>=0 && player[2] == PT_PHOT) + np = create_part(-1, rx, ry, player[2]); + if ( (np < NPART) && np>=0 && player[2] != PT_PHOT && player[2] != SPC_AIR) + parts[np].vx = parts[np].vx + 5*((((int)player[1])&0x02) == 0x02) - 5*(((int)(player[1])&0x01) == 0x01); + if ((np < NPART) && np>=0 && player[2] == PT_PHOT) { int random = abs(rand()%3-1)*3; if (random==0) { - parts[r>>8].life = 0; - parts[r>>8].type = PT_NONE; + kill_part(np); } else { - parts[r>>8].vy = 0; - parts[r>>8].vx = (((((int)player[1])&0x02) == 0x02) - (((int)(player[1])&0x01) == 0x01))*random; + parts[np].vy = 0; + if (((int)player[1])&(0x01|0x02)) + parts[np].vx = (((((int)player[1])&0x02) == 0x02) - (((int)(player[1])&0x01) == 0x01))*random; + else + parts[np].vx = random; } } diff --git a/src/elements/stkm2.c b/src/elements/stkm2.c index 319e388..79dbbdf 100644 --- a/src/elements/stkm2.c +++ b/src/elements/stkm2.c @@ -185,8 +185,10 @@ int update_STKM2(UPDATE_FUNC_ARGS) { { r = pmap[y+ry][x+rx]; if (!r || (r>>8)>=NPART) + r = photons[y+ry][x+rx]; + if (!r || (r>>8)>=NPART) continue; - if (ptypes[r&0xFF].falldown!=0 || (r&0xFF) == PT_NEUT || (r&0xFF) == PT_PHOT) // TODO: photons are not in the pmap. This line may not work as intended. + if (ptypes[r&0xFF].falldown!=0 || (r&0xFF) == PT_NEUT || (r&0xFF) == PT_PHOT) { player2[2] = r&0xFF; //Current element } @@ -225,26 +227,27 @@ int update_STKM2(UPDATE_FUNC_ARGS) { } else { + int np = -1; if (player2[2] == SPC_AIR) create_parts(rx + 3*((((int)player2[1])&0x02) == 0x02) - 3*((((int)player2[1])&0x01) == 0x01), ry, 4, 4, SPC_AIR); else - create_part(-1, rx, ry, player2[2]); - - r = pmap[ry][rx]; - if ( ((r>>8) < NPART) && (r>>8)>=0 && player2[2] != PT_PHOT && player2[2] != SPC_AIR) - parts[r>>8].vx = parts[r>>8].vx + 5*((((int)player2[1])&0x02) == 0x02) - 5*(((int)(player2[1])&0x01) == 0x01); - if (((r>>8) < NPART) && (r>>8)>=0 && player2[2] == PT_PHOT) + np = create_part(-1, rx, ry, player2[2]); + if ((np < NPART) && np>=0 && player2[2] != PT_PHOT && player2[2] != SPC_AIR) + parts[np].vx = parts[np].vx + 5*((((int)player2[1])&0x02) == 0x02) - 5*(((int)(player2[1])&0x01) == 0x01); + if ((np < NPART) && np>=0 && player2[2] == PT_PHOT) { int random = abs(rand()%3-1)*3; if (random==0) { - parts[r>>8].life = 0; - parts[r>>8].type = PT_NONE; + kill_part(np); } else { - parts[r>>8].vy = 0; - parts[r>>8].vx = (((((int)player2[1])&0x02) == 0x02) - (((int)(player2[1])&0x01) == 0x01))*random; + parts[np].vy = 0; + if (((int)player2[1])&(0x01|0x02)) + parts[np].vx = (((((int)player2[1])&0x02) == 0x02) - (((int)(player2[1])&0x01) == 0x01))*random; + else + parts[np].vx = random; } } diff --git a/src/graphics.c b/src/graphics.c index cea2ba7..fb3d384 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1573,31 +1573,27 @@ void draw_parts(pixel *vid) } else if (parts[i].type==PT_GLOW) { - fg = 0; - fb = 0; - fr = 0; - if (pv[ny/CELL][nx/CELL]>0) { - fg = 6 * pv[ny/CELL][nx/CELL]; - fb = 4 * pv[ny/CELL][nx/CELL]; - fr = 2 * pv[ny/CELL][nx/CELL]; - } - vid[ny*(XRES+BARSIZE)+nx] = PIXRGB((int)restrict_flt(0x44 + fr*8, 0, 255), (int)restrict_flt(0x88 + fg*8, 0, 255), (int)restrict_flt(0x44 + fb*8, 0, 255)); + fr = restrict_flt(parts[i].temp-(275.13f+32.0f), 0, 128)/50.0f; + fg = restrict_flt(parts[i].ctype, 0, 128)/50.0f; + fb = restrict_flt(parts[i].tmp, 0, 128)/50.0f; + + cr = restrict_flt(64.0f+parts[i].temp-(275.13f+32.0f), 0, 255); + cg = restrict_flt(64.0f+parts[i].ctype, 0, 255); + cb = restrict_flt(64.0f+parts[i].tmp, 0, 255); - /*x = nx/CELL; + vid[ny*(XRES+BARSIZE)+nx] = PIXRGB(cr, cg, cb); + x = nx/CELL; y = ny/CELL; fg += fire_g[y][x]; - if(fg > 255) fg = 255; - fire_g[y][x] = fg; + if (fg > 255) fg = 255; + fire_g[y][x] = fg; fb += fire_b[y][x]; - if(fb > 255) fb = 255; - fire_b[y][x] = fb; + if (fb > 255) fb = 255; + fire_b[y][x] = fb; fr += fire_r[y][x]; - if(fr > 255) fr = 255; - fire_r[y][x] = fr;*/ + if (fr > 255) fr = 255; + fire_r[y][x] = fr; - cr = (int)restrict_flt(0x44 + fr*8, 0, 255); - cg = (int)restrict_flt(0x88 + fg*8, 0, 255); - cb = (int)restrict_flt(0x44 + fb*8, 0, 255); for (x=-1; x<=1; x++) { for (y=-1; y<=1; y++) @@ -1893,10 +1889,16 @@ void draw_parts(pixel *vid) } if (cr>255) cr=255; + if (cr<0) + cr=0; if (cg>255) cg=255; + if (cg<0) + cg=0; if (cb>255) cb=255; + if (cb<0) + cb=0; blendpixel(vid, nx, ny, cr, cg, cb, 255); } else if (t==PT_WIFI) @@ -2143,6 +2145,7 @@ void draw_parts(pixel *vid) else if (t==PT_BRAY && parts[i].tmp==0) { int trans = parts[i].life * 7; + if (trans>255) trans = 255; if (parts[i].ctype) { cg = 0; cb = 0; @@ -2167,6 +2170,7 @@ void draw_parts(pixel *vid) else if (t==PT_BRAY && parts[i].tmp==1) { int trans = parts[i].life/4; + if (trans>255) trans = 255; if (parts[i].ctype) { cg = 0; cb = 0; @@ -2191,6 +2195,7 @@ void draw_parts(pixel *vid) else if (t==PT_BRAY && parts[i].tmp==2) { int trans = parts[i].life*100; + if (trans>255) trans = 255; blendpixel(vid, nx, ny, 255, 150, 50, trans); } else if (t==PT_PHOT) @@ -2920,6 +2925,36 @@ void draw_parts(pixel *vid) } +void draw_wavelengths(pixel *vid, int x, int y, int h, int wl) +{ + int i,cr,cg,cb,j; + int tmp; + fillrect(vid,x-1,y-1,30+1,h+1,64,64,64,255); // coords -1 size +1 to work around bug in fillrect - TODO: fix fillrect + for (i=0;i<30;i++) + { + if ((wl>>i)&1) + { + // Need a spread of wavelengths to get a smooth spectrum, 5 bits seems to work reasonably well + if (i>2) tmp = 0x1F << (i-2); + else tmp = 0x1F >> (2-i); + cg = 0; + cb = 0; + cr = 0; + for (j=0; j<12; j++) { + cr += (tmp >> (j+18)) & 1; + cb += (tmp >> j) & 1; + } + for (j=0; j<14; j++) + cg += (tmp >> (j+9)) & 1; + tmp = 624/(cr+cg+cb+1); + cr *= tmp; + cg *= tmp; + cb *= tmp; + for (j=0;j<h;j++) blendpixel(vid,x+29-i,y+j,cr>255?255:cr,cg>255?255:cg,cb>255?255:cb,255); + } + } +} + void render_signs(pixel *vid_buf) { int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq; diff --git a/src/interface.c b/src/interface.c index b626138..680b6a9 100644 --- a/src/interface.c +++ b/src/interface.c @@ -481,7 +481,7 @@ void draw_svf_ui(pixel *vid_buf) c = svf_login ? 255 : 128; drawtext(vid_buf, 40, YRES+(MENUSIZE-14), "\x82", c, c, c, 255); if (svf_open) - drawtext(vid_buf, 58, YRES+(MENUSIZE-12), svf_name, c, c, c, 255); + drawtextmax(vid_buf, 58, YRES+(MENUSIZE-12), 125, svf_name, c, c, c, 255); else drawtext(vid_buf, 58, YRES+(MENUSIZE-12), "[untitled simulation]", c, c, c, 255); drawrect(vid_buf, 37, YRES+(MENUSIZE-16), 150, 14, c, c, c, 255); @@ -507,7 +507,7 @@ void draw_svf_ui(pixel *vid_buf) drawtext(vid_buf, 222, YRES+(MENUSIZE-15), "\x83", c, c, c, 255); if (svf_tags[0]) - drawtextmax(vid_buf, 240, YRES+(MENUSIZE-12), 154, svf_tags, c, c, c, 255); + drawtextmax(vid_buf, 240, YRES+(MENUSIZE-12), XRES+BARSIZE-405, svf_tags, c, c, c, 255); else drawtext(vid_buf, 240, YRES+(MENUSIZE-12), "[no tags set]", c, c, c, 255); @@ -518,7 +518,7 @@ void draw_svf_ui(pixel *vid_buf) drawtext(vid_buf, XRES-122+BARSIZE/*388*/, YRES+(MENUSIZE-13), "\x84", 255, 255, 255, 255); if (svf_login) - drawtext(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), svf_user, 255, 255, 255, 255); + drawtextmax(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), 66, svf_user, 255, 255, 255, 255); else drawtext(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), "[sign in]", 255, 255, 255, 255); drawrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14, 255, 255, 255, 255); @@ -1205,8 +1205,9 @@ finish: int save_name_ui(pixel *vid_buf) { - int x0=(XRES-420)/2,y0=(YRES-68-YRES/4)/2,b=1,bq,mx,my,ths,nd=0; + int x0=(XRES-420)/2,y0=(YRES-68-YRES/4)/2,b=1,bq,mx,my,ths,idtxtwidth,nd=0; void *th; + char *save_id_text; ui_edit ed; ui_edit ed2; ui_checkbox cb; @@ -1242,6 +1243,10 @@ int save_name_ui(pixel *vid_buf) ed2.cursor = strlen(svf_description); ed2.multiline = 1; strcpy(ed2.str, svf_description); + + save_id_text = malloc(strlen("Current save id: ")+strlen(svf_id)+1); + sprintf(save_id_text,"Current save id: %s",svf_id); + idtxtwidth = textwidth(save_id_text); cb.x = x0+10; cb.y = y0+53+YRES/4; @@ -1277,6 +1282,12 @@ int save_name_ui(pixel *vid_buf) drawrect(vid_buf, x0, y0+74+YRES/4, 192, 16, 192, 192, 192, 255); draw_line(vid_buf, x0+192, y0, x0+192, y0+90+YRES/4, 150, 150, 150, XRES+BARSIZE); + + if (svf_id[0]) + { + fillrect(vid_buf, (XRES+BARSIZE-idtxtwidth)/2-5, YRES+(MENUSIZE-16), idtxtwidth+10, 14, 0, 0, 0, 255); + drawtext(vid_buf, (XRES+BARSIZE-idtxtwidth)/2, YRES+MENUSIZE-12, save_id_text, 255, 255, 255, 255); + } sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE)); @@ -1334,6 +1345,7 @@ int save_name_ui(pixel *vid_buf) } } free(th); + if (save_id_text) free(save_id_text); return 0; } @@ -2734,7 +2746,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) int nyd,nyu,ry,lv; float ryf; - char *uri, *uri_2, *o_uri; + char *uri, *uri_2, *o_uri, *save_id_text; void *data, *info_data; save_info *info = malloc(sizeof(save_info)); void *http = NULL, *http_2 = NULL; @@ -2752,6 +2764,9 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) drawrect(vid_buf, 50, 50, (XRES/2)+1, (YRES/2)+1, 255, 255, 255, 155); drawrect(vid_buf, 50+(XRES/2)+1, 50, XRES+BARSIZE-100-((XRES/2)+1), YRES+MENUSIZE-100, 155, 155, 155, 255); drawtext(vid_buf, 50+(XRES/4)-textwidth("Loading...")/2, 50+(YRES/4), "Loading...", 255, 255, 255, 128); + + save_id_text = malloc(strlen("Save id: ")+strlen(save_id)+1); + sprintf(save_id_text,"Save id: %s",save_id); ed.x = 57+(XRES/2)+1; ed.y = YRES+MENUSIZE-118; @@ -2827,11 +2842,12 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) data = http_async_req_stop(http, &status, &data_size); if (status == 200) { + pixel *full_save; if (!data||!data_size) { error_ui(vid_buf, 0, "Save data is empty (may be corrupt)"); break; } - pixel *full_save = prerender_save(data, data_size, &imgw, &imgh); + full_save = prerender_save(data, data_size, &imgw, &imgh); if (full_save!=NULL) { save_pic = rescale_img(full_save, imgw, imgh, &thumb_w, &thumb_h, 2); data_ready = 1; @@ -2941,6 +2957,10 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) drawrect(vid_buf, XRES+BARSIZE-100, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 255); drawtext(vid_buf, XRES+BARSIZE-90, YRES+MENUSIZE-63, "Submit", 255, 255, 255, 255); } + + cix = textwidth(save_id_text); + fillrect(vid_buf, (XRES+BARSIZE-cix)/2-5, YRES+(MENUSIZE-16), cix+10, 14, 0, 0, 0, 255); + drawtext(vid_buf, (XRES+BARSIZE-cix)/2, YRES+MENUSIZE-12, save_id_text, 255, 255, 255, 255); //Open Button bc = openable?255:150; @@ -3058,7 +3078,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) if (queue_open) { if (info_ready && data_ready) { // Do Open! - status = parse_save(data, data_size, 1, 0, 0); + status = parse_save(data, data_size, 1, 0, 0, bmap, fvx, fvy, signs, parts, pmap); if (!status) { //if(svf_last) //free(svf_last); @@ -3127,6 +3147,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) if (!b) break; } + if (save_id_text) free(save_id_text); //Close open connections if (http) http_async_req_close(http); @@ -3579,7 +3600,7 @@ void execute_save(pixel *vid_buf) plens[0] = strlen(svf_name); parts[1] = svf_description; plens[1] = strlen(svf_description); - parts[2] = build_save(plens+2, 0, 0, XRES, YRES); + parts[2] = build_save(plens+2, 0, 0, XRES, YRES, bmap, fvx, fvy, signs, parts); parts[3] = build_thumb(plens+3, 1); parts[4] = (svf_publish==1)?"Public":"Private"; plens[4] = strlen((svf_publish==1)?"Public":"Private"); @@ -3820,21 +3841,16 @@ void open_link(char *uri) { #ifdef WIN32 ShellExecute(0, "OPEN", uri, NULL, NULL, 0); #elif MACOSX - //char *cmd[] = { "open", uri, (char *)0 }; - //execvp("open", cmd); - //LSOpenCFURLRef(CFURLCreateWithString(NULL, CFStringCreateWithCString(NULL, uri, 0) ,NULL), NULL); //TODO: Get this crap working char *cmd = malloc(7+strlen(uri)); strcpy(cmd, "open "); strappend(cmd, uri); system(cmd); #elif LIN32 - //execlp("xdg-open", "xdg-open", uri, (char *)0); char *cmd = malloc(11+strlen(uri)); strcpy(cmd, "xdg-open "); strappend(cmd, uri); system(cmd); #elif LIN64 - //execlp("xdg-open", "xdg-open", uri, (char *)0); char *cmd = malloc(11+strlen(uri)); strcpy(cmd, "xdg-open "); strappend(cmd, uri); @@ -3868,7 +3884,8 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { ed.cursor = 0; //fillrect(vid_buf, -1, -1, XRES, 220, 0, 0, 0, 190); memcpy(old_buf,vid_buf,(XRES+BARSIZE)*YRES*PIXELSIZE); - fillrect(old_buf, -1, -1, XRES+1, 220, 0, 0, 0, 190); + + fillrect(old_buf, -1, -1, XRES, 220, 0, 0, 0, 190); currentcommand2 = malloc(sizeof(command_history)); memset(currentcommand2, 0, sizeof(command_history)); @@ -3876,7 +3893,7 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { currentcommand2->command = mystrdup(error); last_command2 = currentcommand2; - //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); cc = 0; while(cc < 80){ fillrect(old_buf, -1, -1+cc, XRES+BARSIZE, 2, 0, 0, 0, 160-(cc*2)); @@ -3889,7 +3906,6 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { my /= sdl_scale; ed.focus = 1; - //clearrect(vid_buf, 0, 0, XRES+BARSIZE, 220);//anyway to make it transparent? memcpy(vid_buf,old_buf,(XRES+BARSIZE)*YRES*PIXELSIZE); draw_line(vid_buf, 0, 219, XRES+BARSIZE-1, 219, 228, 228, 228, XRES+BARSIZE); if(pygood) @@ -3964,14 +3980,14 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { currentcommand->command = mystrdup(ed.str); last_command = currentcommand; free(old_buf); - //SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); + SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); return currentcommand->command; } if (sdl_key==SDLK_ESCAPE || sdl_key==SDLK_BACKQUOTE) { console_mode = 0; free(old_buf); - //SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); + SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); return NULL; } if(sdl_key==SDLK_UP || sdl_key==SDLK_DOWN) @@ -4008,7 +4024,7 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { } console_mode = 0; free(old_buf); - //SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); + SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); return NULL; } @@ -29,7 +29,6 @@ #ifdef PYCONSOLE #include "Python.h" #include "pyconsole.h" -//#include "pystdlib.h" char pyready=1; char pygood=1; #endif @@ -223,7 +222,7 @@ void sdl_seticon(void) //SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(app_icon_w32, 32, 32, 32, 128, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); //SDL_WM_SetIcon(icon, NULL/*app_icon_mask*/); #else - SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(app_icon, 16, 16, 32, 128, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); + SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(app_icon, 16, 16, 32, 64, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); SDL_WM_SetIcon(icon, NULL/*app_icon_mask*/); #endif #endif @@ -309,11 +308,12 @@ void *build_thumb(int *size, int bzip2) return d; } -void *build_save(int *size, int x0, int y0, int w, int h) +void *build_save(int *size, int x0, int y0, int w, int h, unsigned char bmap[YRES/CELL][XRES/CELL], float fvx[YRES/CELL][XRES/CELL], float fvy[YRES/CELL][XRES/CELL], sign signs[MAXSIGNS], void* partsptr) { unsigned char *d=calloc(1,3*(XRES/CELL)*(YRES/CELL)+(XRES*YRES)*11+MAXSIGNS*262), *c; int i,j,x,y,p=0,*m=calloc(XRES*YRES, sizeof(int)); int bx0=x0/CELL, by0=y0/CELL, bw=(w+CELL-1)/CELL, bh=(h+CELL-1)/CELL; + particle *parts = partsptr; // normalize coordinates x0 = bx0*CELL; @@ -352,7 +352,8 @@ void *build_save(int *size, int x0, int y0, int w, int h) y = (int)(parts[i].y+0.5f); if (x>=x0 && x<x0+w && y>=y0 && y<y0+h) { if (!m[(x-x0)+(y-y0)*w] || - parts[m[(x-x0)+(y-y0)*w]-1].type == PT_PHOT) + parts[m[(x-x0)+(y-y0)*w]-1].type == PT_PHOT || + parts[m[(x-x0)+(y-y0)*w]-1].type == PT_NEUT) m[(x-x0)+(y-y0)*w] = i+1; } } @@ -478,12 +479,13 @@ void *build_save(int *size, int x0, int y0, int w, int h) return c; } -int parse_save(void *save, int size, int replace, int x0, int y0) +int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char bmap[YRES/CELL][XRES/CELL], float fvx[YRES/CELL][XRES/CELL], float fvy[YRES/CELL][XRES/CELL], sign signs[MAXSIGNS], void* partsptr, unsigned pmap[YRES][XRES]) { unsigned char *d,*c=save; int q,i,j,k,x,y,p=0,*m=calloc(XRES*YRES, sizeof(int)), ver, pty, ty, legacy_beta=0; int bx0=x0/CELL, by0=y0/CELL, bw, bh, w, h; int fp[NPART], nf=0, new_format = 0, ttv = 0; + particle *parts = partsptr; //New file header uses PSv, replacing fuC. This is to detect if the client uses a new save format for temperatures //This creates a problem for old clients, that display and "corrupt" error instead of a "newer version" error @@ -563,19 +565,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 @@ -907,13 +897,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]; @@ -998,7 +1010,7 @@ void stamp_save(int x, int y, int w, int h) FILE *f; int n; char fn[64], sn[16]; - void *s=build_save(&n, x, y, w, h); + void *s=build_save(&n, x, y, w, h, bmap, fvx, fvy, signs, parts); #ifdef WIN32 _mkdir("stamps"); @@ -1202,8 +1214,7 @@ char console_error[255] = ""; //functions callable from python: -static PyObject* -emb_create(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_create(PyObject *self, PyObject *args, PyObject *keywds) { int x,y,t; char *name = ""; @@ -1215,9 +1226,8 @@ emb_create(PyObject *self, PyObject *args, PyObject *keywds) console_parse_type(name, &t, console_error); return Py_BuildValue("i",create_part(-1,x,y,t)); } -//sys_pause = !sys_pause -static PyObject* -emb_pause(PyObject *self, PyObject *args) + +static PyObject* emb_pause(PyObject *self, PyObject *args) { int x,y,t; if(!PyArg_ParseTuple(args, ":unpause")) @@ -1227,8 +1237,7 @@ emb_pause(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_unpause(PyObject *self, PyObject *args) +static PyObject* emb_unpause(PyObject *self, PyObject *args) { int x,y,t; if(!PyArg_ParseTuple(args, ":pause")) @@ -1238,8 +1247,7 @@ emb_unpause(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_toggle_pause(PyObject *self, PyObject *args) +static PyObject* emb_toggle_pause(PyObject *self, PyObject *args) { int x,y,t; if(!PyArg_ParseTuple(args, ":toggle_pause")) @@ -1250,9 +1258,7 @@ emb_toggle_pause(PyObject *self, PyObject *args) } //console_mode - -static PyObject* -emb_toggle_console(PyObject *self, PyObject *args) +static PyObject* emb_toggle_console(PyObject *self, PyObject *args) { int x,y,t; if(!PyArg_ParseTuple(args, ":toggle_console")) @@ -1262,8 +1268,7 @@ emb_toggle_console(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_open_console(PyObject *self, PyObject *args) +static PyObject* emb_open_console(PyObject *self, PyObject *args) { int x,y,t; if(!PyArg_ParseTuple(args, ":toggle_console")) @@ -1273,8 +1278,7 @@ emb_open_console(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_close_console(PyObject *self, PyObject *args) +static PyObject* emb_close_console(PyObject *self, PyObject *args) { int x,y,t; if(!PyArg_ParseTuple(args, ":toggle_console")) @@ -1284,8 +1288,7 @@ emb_close_console(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_log(PyObject *self, PyObject *args) +static PyObject* emb_log(PyObject *self, PyObject *args) { char *buffer; if(!PyArg_ParseTuple(args, "s:log",&buffer)) @@ -1298,8 +1301,7 @@ emb_log(PyObject *self, PyObject *args) char console_more=0; -static PyObject* -emb_console_more(PyObject *self, PyObject *args) +static PyObject* emb_console_more(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":log")) return NULL; @@ -1308,8 +1310,7 @@ emb_console_more(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_console_less(PyObject *self, PyObject *args) +static PyObject* emb_console_less(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":log")) return NULL; @@ -1318,10 +1319,7 @@ emb_console_less(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -//drawtext(vid_buf, 15, 175-(cc*12), currentcommand->command, 255, 255, 255, 255); - -static PyObject* -emb_reset_pressure(PyObject *self, PyObject *args) +static PyObject* emb_reset_pressure(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":reset_pressure")) return NULL; @@ -1334,8 +1332,7 @@ emb_reset_pressure(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_reset_velocity(PyObject *self, PyObject *args) +static PyObject* emb_reset_velocity(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":reset_velocity")) return NULL; @@ -1349,8 +1346,7 @@ emb_reset_velocity(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_reset_sparks(PyObject *self, PyObject *args) +static PyObject* emb_reset_sparks(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":reset_sparks")) return NULL; @@ -1366,8 +1362,7 @@ emb_reset_sparks(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_set_life(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_life(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1407,8 +1402,7 @@ emb_set_life(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_type(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_type(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j=-1,x=-1,y=-1; char *name = ""; @@ -1450,8 +1444,7 @@ emb_set_type(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_temp(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_temp(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1491,8 +1484,7 @@ emb_set_temp(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_tmp(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_tmp(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1532,8 +1524,7 @@ emb_set_tmp(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_x(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_x(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1574,8 +1565,7 @@ emb_set_x(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_y(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_y(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1615,8 +1605,7 @@ emb_set_y(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_ctype(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_ctype(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1659,8 +1648,7 @@ emb_set_ctype(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_vx(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_vx(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1700,8 +1688,7 @@ emb_set_vx(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_vy(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_vy(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1741,8 +1728,7 @@ emb_set_vy(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_get_pmap(PyObject *self, PyObject *args) +static PyObject* emb_get_pmap(PyObject *self, PyObject *args) { int x,y; if(!PyArg_ParseTuple(args, "II:get_pmap",&x,&y)) @@ -1754,8 +1740,7 @@ emb_get_pmap(PyObject *self, PyObject *args) return Py_BuildValue("I",pmap[y][x]); } -static PyObject* -emb_get_prop(PyObject *self, PyObject *args) +static PyObject* emb_get_prop(PyObject *self, PyObject *args) { int i; char *prop = ""; @@ -1787,8 +1772,7 @@ emb_get_prop(PyObject *self, PyObject *args) return Py_BuildValue("i",-1); } -static PyObject* -emb_draw_pixel(PyObject *self, PyObject *args) +static PyObject* emb_draw_pixel(PyObject *self, PyObject *args) { int x,y,r,g,b,a; a=255; @@ -1804,9 +1788,7 @@ emb_draw_pixel(PyObject *self, PyObject *args) } -//drawtext(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a) -static PyObject* -emb_draw_text(PyObject *self, PyObject *args) +static PyObject* emb_draw_text(PyObject *self, PyObject *args) { int x,y,r,g,b,a; char *txt; @@ -1821,9 +1803,7 @@ emb_draw_text(PyObject *self, PyObject *args) return Py_BuildValue("i",-1); } -//drawrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a) -static PyObject* -emb_draw_rect(PyObject *self, PyObject *args) +static PyObject* emb_draw_rect(PyObject *self, PyObject *args) { int x,y,w,h,r,g,b,a; a=255; @@ -1838,8 +1818,7 @@ emb_draw_rect(PyObject *self, PyObject *args) return Py_BuildValue("i",-1); } -static PyObject* -emb_draw_fillrect(PyObject *self, PyObject *args) +static PyObject* emb_draw_fillrect(PyObject *self, PyObject *args) { int x,y,w,h,r,g,b,a; a=255; @@ -1854,9 +1833,7 @@ emb_draw_fillrect(PyObject *self, PyObject *args) return Py_BuildValue("i",-1); } -//int textwidth(char *s) -static PyObject* -emb_get_width(PyObject *self, PyObject *args) +static PyObject* emb_get_width(PyObject *self, PyObject *args) { char *txt; if(!PyArg_ParseTuple(args, "s:get_width",&txt)) @@ -1864,9 +1841,7 @@ emb_get_width(PyObject *self, PyObject *args) return Py_BuildValue("i",textwidth(txt)); } -//SDL_GetMouseState(&x, &y) -static PyObject* -emb_get_mouse(PyObject *self, PyObject *args) +static PyObject* emb_get_mouse(PyObject *self, PyObject *args) { int x,y,mask,b1,b2,b3; if(!PyArg_ParseTuple(args, ":get_mouse")) @@ -1878,9 +1853,7 @@ emb_get_mouse(PyObject *self, PyObject *args) return Py_BuildValue("(ii(iii))",x,y,b1,b2,b3); } -//svf_name -static PyObject* -emb_get_name(PyObject *self, PyObject *args) +static PyObject* emb_get_name(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":get_name")) return NULL; @@ -1890,8 +1863,7 @@ emb_get_name(PyObject *self, PyObject *args) return Py_BuildValue("s",""); } -static PyObject* -emb_shortcuts_disable(PyObject *self, PyObject *args) +static PyObject* emb_shortcuts_disable(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":shortcuts_disable")) return NULL; @@ -1900,8 +1872,7 @@ emb_shortcuts_disable(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_shortcuts_enable(PyObject *self, PyObject *args) +static PyObject* emb_shortcuts_enable(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":shortcuts_enable")) return NULL; @@ -1910,17 +1881,14 @@ emb_shortcuts_enable(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_get_modifier(PyObject *self, PyObject *args) +static PyObject* emb_get_modifier(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":get_modifier")) return NULL; return Py_BuildValue("(iiiiii)",sdl_mod&KMOD_LCTRL,sdl_mod&KMOD_RCTRL,sdl_mod&KMOD_LALT,sdl_mod&KMOD_RALT,sdl_mod&KMOD_LSHIFT,sdl_mod&KMOD_RSHIFT); } -//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); -static PyObject* -emb_set_keyrepeat(PyObject *self, PyObject *args) +static PyObject* emb_set_keyrepeat(PyObject *self, PyObject *args) { ////SDL_EnableKeyRepeat(delay,interval) int keydelay,keyinterval; @@ -1932,8 +1900,7 @@ emb_set_keyrepeat(PyObject *self, PyObject *args) } //delete_part -static PyObject* -emb_delete(PyObject *self, PyObject *args) +static PyObject* emb_delete(PyObject *self, PyObject *args) { ////SDL_EnableKeyRepeat(delay,interval) int x,y; @@ -1943,8 +1910,7 @@ emb_delete(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_set_pressure(PyObject *self, PyObject *args) +static PyObject* emb_set_pressure(PyObject *self, PyObject *args) { ////SDL_EnableKeyRepeat(delay,interval) int x,y,press; @@ -1954,8 +1920,7 @@ emb_set_pressure(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_set_velocity(PyObject *self, PyObject *args) +static PyObject* emb_set_velocity(PyObject *self, PyObject *args) { ////SDL_EnableKeyRepeat(delay,interval) int x,y,xv,yv; @@ -1966,8 +1931,7 @@ emb_set_velocity(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_disable_python(PyObject *self, PyObject *args) +static PyObject* emb_disable_python(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":disable_python")) return NULL; @@ -2042,6 +2006,7 @@ int main(int argc, char *argv[]) #ifdef INTERNAL int vs = 0; #endif + int wavelength_gfx = 0; int x, y, b = 0, sl=1, sr=0, su=0, c, lb = 0, lx = 0, ly = 0, lm = 0;//, tx, ty; int da = 0, db = 0, it = 2047, mx, my, bsx = 2, bsy = 2; float nfvx, nfvy; @@ -2051,6 +2016,7 @@ int main(int argc, char *argv[]) int save_mode=0, save_x=0, save_y=0, save_w=0, save_h=0, copy_mode=0; SDL_AudioSpec fmt; int username_flash = 0, username_flash_t = 1; + pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE); GSPEED = 1; #ifdef PYCONSOLE PyObject *pname,*pmodule,*pfunc,*pvalue,*pargs,*pstep,*pkey; @@ -2064,33 +2030,25 @@ int main(int argc, char *argv[]) fmt.callback = mixaudio; fmt.userdata = NULL; - #ifdef PYCONSOLE - //dump tpt_console_stdlib to file here - /*#include "pystdlib.h" - FILE* fid; - fid=fopen("stdlib.zip","w"); - //fputs(tpt_console_stdlib,fid); - fwrite(&tpt_console_stdlib,1,tpt_console_stdlibsize,fid); - fclose(fid);*/ - //crashes gcc - +#ifdef PYCONSOLE //initialise python console Py_Initialize(); PyRun_SimpleString("print 'python present.'"); Py_InitModule("tpt", EmbMethods); + //change the path to find all the correct modules PyRun_SimpleString("import sys\nsys.path.append('./tptPython.zip')\nsys.path.append('.')"); //load the console module and whatnot - #ifdef PYEXT +#ifdef PYEXT PyRun_SimpleString(tpt_console_py); printf("using external python console file.\n"); pname=PyString_FromString("tpt_console");//create string object pmodule = PyImport_Import(pname);//import module Py_DECREF(pname);//throw away string - #else +#else PyObject *tpt_console_obj = PyMarshal_ReadObjectFromString(tpt_console_pyc+8, sizeof(tpt_console_pyc)-8); pmodule=PyImport_ExecCodeModule("tpt_console", tpt_console_obj); - #endif +#endif if(pmodule!=NULL) { pfunc=PyObject_GetAttrString(pmodule,"handle");//get the handler function @@ -2102,9 +2060,8 @@ int main(int argc, char *argv[]) { PyErr_Print(); printf("unable to find handle function, mangled console.py?\n"); - //return -1; - pyready=0; - pygood=0; + pyready = 0; + pygood = 0; } pstep=PyObject_GetAttrString(pmodule,"step");//get the handler function @@ -2132,9 +2089,8 @@ int main(int argc, char *argv[]) //sys.stderr PyErr_Print(); printf("unable to find console module, missing file or mangled console.py?\n"); - //return -1; - pyready=0; - pygood=0; + pyready = 0; + pygood = 0; } #else printf("python console disabled at compile time."); @@ -2164,8 +2120,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); @@ -2773,8 +2728,6 @@ int main(int argc, char *argv[]) pargs=NULL; if(pvalue==NULL) strcpy(console_error,"failed to execute key code."); - //Py_DECREF(pvalue); - //puts("a"); pvalue=NULL; } #endif @@ -2890,8 +2843,13 @@ int main(int argc, char *argv[]) if (DEBUG_MODE) { int tctype = parts[cr>>8].ctype; - if (tctype>=PT_NUM) + if (tctype>=PT_NUM || (cr&0xFF)==PT_PHOT) tctype = 0; + if ((cr&0xFF)==PT_PIPE) + { + if (parts[cr>>8].tmp<PT_NUM) tctype = parts[cr>>8].tmp; + else 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(coordtext, "#%d, X:%d Y:%d", cr>>8, x/sdl_scale, y/sdl_scale); } else { @@ -2901,6 +2859,7 @@ int main(int argc, char *argv[]) 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); #endif } + if ((cr&0xFF)==PT_PHOT) wavelength_gfx = parts[cr>>8].ctype; } else { @@ -3074,7 +3033,7 @@ int main(int argc, char *argv[]) if (load_y<0) load_y=0; if (bq==1 && !b) { - parse_save(load_data, load_size, 0, load_x, load_y); + parse_save(load_data, load_size, 0, load_x, load_y, bmap, fvx, fvy, signs, parts, pmap); free(load_data); free(load_img); load_mode = 0; @@ -3116,35 +3075,19 @@ int main(int argc, char *argv[]) { if (copy_mode==1) { - clipboard_data=build_save(&clipboard_length, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); + clipboard_data=build_save(&clipboard_length, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL, bmap, fvx, fvy, signs, parts); clipboard_ready = 1; save_mode = 0; copy_mode = 0; } else if (copy_mode==2) { - clipboard_data=build_save(&clipboard_length, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); + clipboard_data=build_save(&clipboard_length, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL, bmap, fvx, fvy, signs, parts); clipboard_ready = 1; save_mode = 0; copy_mode = 0; clear_area(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); } - else if (copy_mode==3)//rotation - { - if (save_h>save_w) - save_w = save_h; - rotate_area(save_x*CELL, save_y*CELL, save_w*CELL, save_w*CELL,0);//just do squares for now - save_mode = 0; - copy_mode = 0; - } - else if (copy_mode==4)//invertion - { - if (save_h>save_w) - save_w = save_h; - rotate_area(save_x*CELL, save_y*CELL, save_w*CELL, save_w*CELL,1);//just do squares for now - save_mode = 0; - copy_mode = 0; - } else { stamp_save(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); @@ -3202,19 +3145,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; @@ -3231,6 +3162,7 @@ int main(int argc, char *argv[]) svf_description[0] = 0; gravityMode = 0; airMode = 0; + death = death2 = 0; isplayer2 = 0; isplayer = 0; @@ -3276,7 +3208,7 @@ int main(int argc, char *argv[]) } if (x>=19 && x<=35 && svf_last && svf_open && !bq) { //int tpval = sys_pause; - parse_save(svf_last, svf_lsize, 1, 0, 0); + parse_save(svf_last, svf_lsize, 1, 0, 0, bmap, fvx, fvy, signs, parts, pmap); //sys_pause = tpval; } if (x>=(XRES+BARSIZE-(510-476)) && x<=(XRES+BARSIZE-(510-491)) && !bq) @@ -3366,14 +3298,16 @@ int main(int argc, char *argv[]) { for (j=-bsy; j<=bsy; j++) for (i=-bsx; i<=bsx; i++) - if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(bsx,2))+(pow(j,2))/(pow(bsy,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=bsy*bsx)) + if (x+i>0 && y+j>0 && x+i<XRES && y+j<YRES && ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(bsx,2))+(pow(j,2))/(pow(bsy,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=bsy*bsx))) { vx[(y+j)/CELL][(x+i)/CELL] += (x-lx)*0.01f; vy[(y+j)/CELL][(x+i)/CELL] += (y-ly)*0.01f; } } else + { create_line(lx, ly, x, y, bsx, bsy, c); + } lx = x; ly = y; } @@ -3485,14 +3419,7 @@ int main(int argc, char *argv[]) if (save_mode) { - if (copy_mode==3||copy_mode==4)//special drawing for rotate, can remove once it can do rectangles - { - if (save_h>save_w) - save_w = save_h; - xor_rect(vid_buf, save_x*CELL, save_y*CELL, save_w*CELL, save_w*CELL); - } - else - xor_rect(vid_buf, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); + xor_rect(vid_buf, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); da = 51; db = 269; } @@ -3647,6 +3574,8 @@ int main(int argc, char *argv[]) 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); } + if (wavelength_gfx) + draw_wavelengths(vid_buf,XRES-20-textwidth(heattext),265,2,wavelength_gfx); } else { @@ -3657,6 +3586,8 @@ int main(int argc, char *argv[]) fillrect(vid_buf, 12, 280, textwidth(coordtext)+8, 13, 0, 0, 0, 140); drawtext(vid_buf, 16, 282, coordtext, 255, 255, 255, 200); } + if (wavelength_gfx) + draw_wavelengths(vid_buf,12,265,2,wavelength_gfx); } } else @@ -3668,7 +3599,10 @@ int main(int argc, char *argv[]) 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); } + if (wavelength_gfx) + draw_wavelengths(vid_buf,XRES-20-textwidth(heattext),11,2,wavelength_gfx); } + wavelength_gfx = 0; fillrect(vid_buf, 12, 12, textwidth(uitext)+8, 15, 0, 0, 0, 140); drawtext(vid_buf, 16, 16, uitext, 32, 216, 255, 200); @@ -3763,6 +3697,7 @@ int main(int argc, char *argv[]) } SDL_CloseAudio(); http_done(); + PyRun_SimpleString("import os,tempfile,os.path\ntry:\n os.remove(os.path.join(tempfile.gettempdir(),'tpt_console.py'))\nexcept:\n pass"); PyRun_SimpleString("import os,tempfile,os.path\ntry:\n os.remove(os.path.join(tempfile.gettempdir(),'tpt_console.pyo'))\nexcept:\n pass"); PyRun_SimpleString("import os,tempfile,os.path\ntry:\n os.remove(os.path.join(tempfile.gettempdir(),'tpt_console.pyc'))\nexcept:\n pass"); @@ -3788,26 +3723,20 @@ int process_command(pixel *vid_buf,char *console,char *console_error,PyObject *p if(strcmp(console2, "quit")==0) { return -1; - } - else - { - // sprintf(console_error, "Invalid Command", console2); - //handle them command - pargs=Py_BuildValue("(s)",console); - pvalue = PyObject_CallObject(pfunc, pargs); - Py_DECREF(pargs); - pargs=NULL; - if(pvalue==NULL) - strcpy(console_error,"failed to execute code."); - //Py_DECREF(pvalue); - //puts("a"); - pvalue=NULL; + } else { + //handle them command + pargs=Py_BuildValue("(s)",console); + pvalue = PyObject_CallObject(pfunc, pargs); + Py_DECREF(pargs); + pargs=NULL; + if(pvalue==NULL) + strcpy(console_error,"failed to execute code."); + pvalue=NULL; } } return 1; } #endif - int process_command_old(pixel *vid_buf,char *console,char *console_error) { int y,x,nx,ny,i,j,k,m; int do_next = 1; @@ -306,3 +306,68 @@ int cpu_check(void) #endif return 0; } + +matrix2d m2d_multiply_m2d(matrix2d m1, matrix2d m2) +{ + matrix2d result = { + m1.a*m2.a+m1.b*m2.c, m1.a*m2.b+m1.b*m2.d, + m1.c*m2.a+m1.d*m2.c, m1.c*m2.b+m1.d*m2.d + }; + return result; +} +vector2d m2d_multiply_v2d(matrix2d m, vector2d v) +{ + vector2d result = { + m.a*v.x+m.b*v.y, + m.c*v.x+m.d*v.y + }; + return result; +} +matrix2d m2d_multiply_float(matrix2d m, float s) +{ + matrix2d result = { + m.a*s, m.b*s, + m.c*s, m.d*s, + }; + return result; +} + +vector2d v2d_multiply_float(vector2d v, float s) +{ + vector2d result = { + v.x*s, + v.y*s + }; + return result; +} + +vector2d v2d_add(vector2d v1, vector2d v2) +{ + vector2d result = { + v1.x+v2.x, + v1.y+v2.y + }; + return result; +} +vector2d v2d_sub(vector2d v1, vector2d v2) +{ + vector2d result = { + v1.x-v2.x, + v1.y-v2.y + }; + return result; +} + +matrix2d m2d_new(float me0, float me1, float me2, float me3) +{ + matrix2d result = {me0,me1,me2,me3}; + return result; +} +vector2d v2d_new(float x, float y) +{ + vector2d result = {x, y}; + return result; +} + +vector2d v2d_zero = {0,0}; +matrix2d m2d_identity = {1,0,0,1}; diff --git a/src/powder.c b/src/powder.c index e15565b..af59585 100644 --- a/src/powder.c +++ b/src/powder.c @@ -139,6 +139,8 @@ int try_move(int i, int x, int y, int nx, int ny) if (x==nx && y==ny) return 1; + if (nx<0 || ny<0 || nx>=XRES || ny>=YRES) + return 1; e = eval_move(parts[i].type, nx, ny, &r); @@ -253,8 +255,22 @@ int try_move(int i, int x, int y, int nx, int ny) e = r >> 8; if (r && e<NPART) { - if (parts[e].type == PT_PHOT) + if (parts[e].type == PT_PHOT||parts[e].type == PT_NEUT) + return 1; + + if (parts[i].type==PT_NEUT) { + // target material is NEUTPENETRATE, meaning it gets moved around when neutron passes + unsigned s = pmap[y][x]; + if ((s&0xFF) && (s&0xFF)<PT_NUM && !(ptypes[s&0xFF].properties&PROP_NEUTPENETRATE)) + return 1; // if the element currently underneath neutron isn't NEUTPENETRATE, don't move it around + if ((pmap[ny][nx]>>8)==e) pmap[ny][nx] = (s&~(0xFF))|parts[s>>8].type; + parts[e].x = x; + parts[e].y = y; + pmap[y][x] = (e<<8)|parts[e].type; + parts[s>>8].x = nx; + parts[s>>8].y = ny; return 1; + } if ((pmap[ny][nx]>>8)==e) pmap[ny][nx] = 0; parts[e].x += x-nx; @@ -460,7 +476,7 @@ inline void part_change_type(int i, int x, int y, int t) if (x<0 || y<0 || x>=XRES || y>=YRES || i>=NPART || t<0 || t>=PT_NUM) return; parts[i].type = t; - if (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) @@ -491,7 +507,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) @@ -508,9 +524,9 @@ inline int create_n_parts(int n, int x, int y, float vx, float vy, int t) parts[i].ctype = 0; parts[i].temp += (n*17); parts[i].tmp = 0; - if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT && !pmap[y][x])// && t!=PT_NEUT) + if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT && t!=PT_NEUT && !pmap[y][x]) pmap[y][x] = t|(i<<8); - else if (t==PT_PHOT && !photons[y][x]) + else if ((t==PT_PHOT||t==PT_NEUT) && !photons[y][x]) photons[y][x] = t|(i<<8); pv[y/CELL][x/CELL] += 6.0f * CFDS; @@ -630,7 +646,7 @@ inline int create_part(int p, int x, int y, int t) } return -1; } - if (photons[y][x] && t==PT_PHOT) + if (photons[y][x] && (t==PT_PHOT||t==PT_NEUT)) return -1; if (pfree == -1) return -1; @@ -738,35 +754,18 @@ inline int create_part(int p, int x, int y, int t) parts[i].vx = 3.0f*cosf(a); parts[i].vy = 3.0f*sinf(a); } - if (t==PT_PHOT) - photons[y][x] = t|(i<<8); if (t==PT_STKM) { if (isplayer==0) { - if (pmap[y][x]&0xFF==PT_SPAWN) - { - parts[pmap[y][x]>>8].type = PT_STKM; - parts[pmap[y][x]>>8].vx = 0; - parts[pmap[y][x]>>8].vy = 0; - parts[pmap[y][x]>>8].life = 100; - parts[pmap[y][x]>>8].ctype = 0; - parts[pmap[y][x]>>8].temp = ptypes[t].heat; - - } - else - { - parts[i].x = (float)x; - parts[i].y = (float)y; - parts[i].type = PT_STKM; - parts[i].vx = 0; - parts[i].vy = 0; - parts[i].life = 100; - parts[i].ctype = 0; - parts[i].temp = ptypes[t].heat; - } - - + parts[i].x = (float)x; + parts[i].y = (float)y; + parts[i].type = PT_STKM; + parts[i].vx = 0; + parts[i].vy = 0; + parts[i].life = 100; + parts[i].ctype = 0; + parts[i].temp = ptypes[t].heat; player[3] = x-1; //Setting legs positions player[4] = y+6; @@ -794,7 +793,6 @@ inline int create_part(int p, int x, int y, int t) { return -1; } - //kill_part(playerspawn); create_part(-1,x,y,PT_SPAWN); ISSPAWN1 = 1; } @@ -802,29 +800,14 @@ inline int create_part(int p, int x, int y, int t) { if (isplayer2==0) { - if (pmap[y][x]&0xFF==PT_SPAWN2) - { - parts[pmap[y][x]>>8].type = PT_STKM2; - parts[pmap[y][x]>>8].vx = 0; - parts[pmap[y][x]>>8].vy = 0; - parts[pmap[y][x]>>8].life = 100; - parts[pmap[y][x]>>8].ctype = 0; - parts[pmap[y][x]>>8].temp = ptypes[t].heat; - - } - else - { - parts[i].x = (float)x; - parts[i].y = (float)y; - parts[i].type = PT_STKM2; - parts[i].vx = 0; - parts[i].vy = 0; - parts[i].life = 100; - parts[i].ctype = 0; - parts[i].temp = ptypes[t].heat; - } - - + parts[i].x = (float)x; + parts[i].y = (float)y; + parts[i].type = PT_STKM2; + parts[i].vx = 0; + parts[i].vy = 0; + parts[i].life = 100; + parts[i].ctype = 0; + parts[i].temp = ptypes[t].heat; player2[3] = x-1; //Setting legs positions player2[4] = y+6; @@ -852,13 +835,14 @@ inline int create_part(int p, int x, int y, int t) { return -1; } - //kill_part(player2spawn); create_part(-1,x,y,PT_SPAWN2); ISSPAWN2 = 1; } if (t==PT_BIZR||t==PT_BIZRG) parts[i].ctype = 0x47FFFF; - if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT)// && t!=PT_NEUT) is this needed? it breaks floodfill, Yes photons should not be placed in the PMAP + if (t==PT_PHOT||t==PT_NEUT) + photons[y][x] = t|(i<<8); + if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT && t!=PT_NEUT) // is this needed? it breaks floodfill, Yes photons should not be placed in the PMAP pmap[y][x] = t|(i<<8); return i; @@ -1342,7 +1326,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++) { @@ -2054,13 +2038,13 @@ 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; + else if ((photons[y][x]>>8)==i) photons[y][x] = 0; if (nx<CELL || nx>=XRES-CELL || ny<CELL || ny>=YRES-CELL) { kill_part(i); continue; } - if (t==PT_PHOT) + if (t==PT_PHOT||t==PT_NEUT) photons[ny][nx] = t|(i<<8); else pmap[ny][nx] = t|(i<<8); @@ -2095,12 +2079,13 @@ void update_particles(pixel *vid) t = parts[i].type; x = (int)(parts[i].x+0.5f); y = (int)(parts[i].y+0.5f); - if (x>=0 && y>=0 && x<XRES && y<YRES && t!=PT_PHOT) { - if (t!=PT_NEUT || (pmap[y][x]&0xFF)!=PT_GLAS) + if (x>=0 && y>=0 && x<XRES && y<YRES) + { + if (t==PT_PHOT||t==PT_NEUT) + photons[y][x] = t|(i<<8); + else pmap[y][x] = t|(i<<8); } - if (t==PT_PHOT) - photons[y][x] = t|(i<<8); NUM_PARTS ++; } else @@ -2610,90 +2595,6 @@ void update_particles(pixel *vid) } -void rotate_area(int area_x, int area_y, int area_w, int area_h, int invert) -{ - //TODO: MSCC doesn't like arrays who's size is determined at runtime. -#if !(defined(WIN32) && !defined(__GNUC__)) - int cx = 0; - int cy = 0; - unsigned tpmap[area_h][area_w]; - unsigned rtpmap[area_w][area_h]; - unsigned char tbmap[area_h/CELL][area_w/CELL]; - unsigned char rtbmap[area_w/CELL][area_h/CELL]; - float tfvy[area_h/CELL][area_w/CELL]; - float tfvx[area_h/CELL][area_w/CELL]; - for (cy=0; cy<area_h; cy++) - { - for (cx=0; cx<area_w; cx++)//save walls to temp - { - if (area_x + cx<XRES&&area_y + cy<YRES) - { - if (bmap[(cy+area_y)/CELL][(cx+area_x)/CELL]) { - tbmap[cy/CELL][cx/CELL] = bmap[(cy+area_y)/CELL][(cx+area_x)/CELL]; - if (bmap[(cy+area_y)/CELL][(cx+area_x)/CELL]==WL_FAN) { - tfvx[cy/CELL][cx/CELL] = fvx[(cy+area_y)/CELL][(cx+area_x)/CELL]; - tfvy[cy/CELL][cx/CELL] = fvy[(cy+area_y)/CELL][(cx+area_x)/CELL]; - } - } else { - tbmap[cy/CELL][cx/CELL] = 0; - tfvx[cy/CELL][cx/CELL] = 0; - tfvy[cy/CELL][cx/CELL] = 0; - } - } - } - } - for (cy=0; cy<area_h; cy++) - { - for (cx=0; cx<area_w; cx++)//save particles to temp - { - if ((area_x + cx<XRES&&area_y + cy<YRES)) - { - tpmap[cy][cx] = pmap[(int)(cy+area_y+0.5f)][(int)(cx+area_x+0.5f)]; - } - else - tpmap[(int)(cy+0.5f)][(int)(cx+0.5f)] = 0; - } - } - for (cy=0; cy<area_w; cy++) - { - for (cx=0; cx<area_h; cx++)//rotate temp arrays - { - if (invert) - { - rtbmap[cy/CELL][((area_h-1)-cx)/CELL] = tbmap[cy/CELL][cx/CELL]; - rtpmap[cy][(area_h-1)-cx] = tpmap[(int)(cy+0.5f)][(int)(cx+0.5f)]; - tfvx[cy/CELL][((area_h-1)-cx)/CELL] = -tfvx[cy/CELL][cx/CELL]; - tfvy[cy/CELL][((area_h-1)-cx)/CELL] = tfvy[cy/CELL][cx/CELL]; - } - else - { - rtbmap[((area_h-1)-cx)/CELL][cy/CELL] = tbmap[cy/CELL][cx/CELL]; - rtpmap[(area_h-1)-cx][cy] = tpmap[(int)(cy+0.5f)][(int)(cx+0.5f)]; - tfvy[((area_h-1)-cx)/CELL][cy/CELL] = -tfvx[cy/CELL][cx/CELL]; - tfvx[((area_h-1)-cx)/CELL][cy/CELL] = tfvy[cy/CELL][cx/CELL]; - } - } - } - for (cy=0; cy<area_w; cy++) - { - for (cx=0; cx<area_h; cx++)//move particles and walls - { - if (area_x + cx<XRES&&area_y + cy<YRES) - { - if ((rtpmap[cy][cx]>>8)<=NPART&&rtpmap[cy][cx]) - { - parts[rtpmap[(int)(cy+0.5f)][(int)(cx+0.5f)]>>8].x = area_x +cx; - parts[rtpmap[(int)(cy+0.5f)][(int)(cx+0.5f)]>>8].y = area_y +cy; - } - bmap[(area_y+cy)/CELL][(area_x+cx)/CELL] = rtbmap[cy/CELL][cx/CELL]; - fvy[(area_y+cy)/CELL][(area_x+cx)/CELL] = tfvy[cy/CELL][cx/CELL]; - fvx[(area_y+cy)/CELL][(area_x+cx)/CELL] = tfvx[cy/CELL][cx/CELL]; - } - } - } -#endif -} - void clear_area(int area_x, int area_y, int area_w, int area_h) { int cx = 0; @@ -2731,14 +2632,10 @@ void create_box(int x1, int y1, int x2, int y2, int c) int flood_parts(int x, int y, int c, int cm, int bm) { int x1, x2, dy = (c<PT_NUM)?1:CELL; - int co = c, wall; + int co = c; if (cm==PT_INST&&co==PT_SPRK) if ((pmap[y][x]&0xFF)==PT_SPRK) return 0; - if (c>=UI_WALLSTART&&c<=UI_WALLSTART+UI_WALLCOUNT) - { - wall = c-100; - } if (cm==-1) { if (c==0) @@ -2754,7 +2651,7 @@ int flood_parts(int x, int y, int c, int cm, int bm) } if (bm==-1) { - if (wall==WL_ERASE) + if (c-UI_WALLSTART+UI_ACTUALSTART==WL_ERASE) { bm = bmap[y/CELL][x/CELL]; if (!bm) @@ -2873,7 +2770,9 @@ int create_parts(int x, int y, int rx, int ry, int c) dw = 1; } if (c == PT_WIND) + { return 1; + } if (dw==1) { rx = rx/CELL; @@ -3071,3 +2970,109 @@ void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c) } } } + +void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate) +{ + void *ndata; + unsigned char bmapo[YRES/CELL][XRES/CELL], bmapn[YRES/CELL][XRES/CELL]; + particle *partst; + sign signst[MAXSIGNS]; + unsigned pmapt[YRES][XRES]; + float fvxo[YRES/CELL][XRES/CELL], fvyo[YRES/CELL][XRES/CELL]; + float fvxn[YRES/CELL][XRES/CELL], fvyn[YRES/CELL][XRES/CELL]; + int i, x, y, nx, ny, w, h, nw, nh; + vector2d pos, tmp, ctl, cbr; + vector2d cornerso[4]; + unsigned char *odatac = odata; + memset(bmapo, 0, sizeof(bmapo)); + memset(bmapn, 0, sizeof(bmapn)); + memset(signst, 0, sizeof(signst)); + memset(pmapt, 0, sizeof(pmapt)); + memset(fvxo, 0, sizeof(fvxo)); + memset(fvxn, 0, sizeof(fvxn)); + memset(fvyo, 0, sizeof(fvyo)); + memset(fvyn, 0, sizeof(fvyn)); + partst = calloc(sizeof(particle), NPART); + if (parse_save(odata, *size, 0, 0, 0, bmapo, fvxo, fvyo, signst, partst, pmapt)) + { + free(partst); + return odata; + } + w = odatac[6]*CELL; + h = odatac[7]*CELL; + // undo any translation caused by rotation + cornerso[0] = v2d_new(0,0); + cornerso[1] = v2d_new(w-1,0); + cornerso[2] = v2d_new(0,h-1); + cornerso[3] = v2d_new(w-1,h-1); + for (i=0;i<4;i++) + { + tmp = m2d_multiply_v2d(transform,cornerso[i]); + if (i==0) ctl = cbr = tmp; // top left, bottom right corner + if (tmp.x<ctl.x) ctl.x = tmp.x; + if (tmp.y<ctl.y) ctl.y = tmp.y; + if (tmp.x>cbr.x) cbr.x = tmp.x; + if (tmp.y>cbr.y) cbr.y = tmp.y; + } + // casting as int doesn't quite do what we want with negative numbers, so use floor() + tmp = v2d_new(floor(ctl.x+0.5f),floor(ctl.y+0.5f)); + translate = v2d_sub(translate,tmp); + nw = floor(cbr.x+0.5f)-floor(ctl.x+0.5f)+1; + nh = floor(cbr.y+0.5f)-floor(ctl.y+0.5f)+1; + if (nw>XRES) nw = XRES; + if (nh>YRES) nh = YRES; + // rotate and translate signs, parts, walls + for (i=0; i<MAXSIGNS; i++) + { + if (!signst[i].text[0]) continue; + pos = v2d_new(signst[i].x, signst[i].y); + pos = v2d_add(m2d_multiply_v2d(transform,pos),translate); + nx = floor(pos.x+0.5f); + ny = floor(pos.y+0.5f); + if (nx<0 || nx>=nw || ny<0 || ny>=nh) + { + signst[i].text[0] = 0; + continue; + } + signst[i].x = nx; + signst[i].y = ny; + } + for (i=0; i<NPART; i++) + { + if (!partst[i].type) continue; + pos = v2d_new(partst[i].x, partst[i].y); + pos = v2d_add(m2d_multiply_v2d(transform,pos),translate); + nx = floor(pos.x+0.5f); + ny = floor(pos.y+0.5f); + if (nx<0 || nx>=nw || ny<0 || ny>=nh) + { + partst[i].type = PT_NONE; + continue; + } + partst[i].x = nx; + partst[i].y = ny; + } + for (y=0;y<YRES/CELL;y++) + for (x=0;x<XRES/CELL;x++) + { + pos = v2d_new(x*CELL+CELL*0.4f, y*CELL+CELL*0.4f); + pos = v2d_add(m2d_multiply_v2d(transform,pos),translate); + nx = pos.x/CELL; + ny = pos.y/CELL; + if (nx<0 || nx>=nw || ny<0 || ny>=nh) + continue; + if (bmapo[y][x]) + { + bmapn[ny][nx] = bmapo[y][x]; + if (bmapo[y][x]==WL_FAN) + { + fvxn[ny][nx] = fvxo[y][x]; + fvyn[ny][nx] = fvyo[y][x]; + } + } + } + ndata = build_save(size,0,0,nw,nh,bmapn,fvxn,fvyn,signst,partst); + free(partst); + return ndata; +} + |
