diff --git a/includes/defines.h b/includes/defines.h index 74ac0625d..f5e5c8d48 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -8,9 +8,9 @@ #endif //VersionInfoStart -#define SAVE_VERSION 76 +#define SAVE_VERSION 77 #define MINOR_VERSION 0 -#define BUILD_NUM 157 +#define BUILD_NUM 159 //VersionInfoEnd #define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter diff --git a/includes/interface.h b/includes/interface.h index 57f75b694..858e289f2 100644 --- a/includes/interface.h +++ b/includes/interface.h @@ -340,5 +340,10 @@ void render_ui(pixel *vid_buf, int xcoord, int ycoord, int orientation); void simulation_ui(pixel *vid_buf); unsigned int decorations_ui(pixel *vid_buf, int *bsx, int *bsy, unsigned int savedColor); + +Uint8 mouse_get_state(int *x, int *y); + +void mouse_coords_window_to_sim(int *sim_x, int *sim_y, int window_x, int window_y); + #endif diff --git a/includes/powder.h b/includes/powder.h index ea6eb41bb..72d42eb89 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -330,6 +330,8 @@ int graphics_DCEL(GRAPHICS_FUNC_ARGS); int graphics_GEL(GRAPHICS_FUNC_ARGS); int graphics_TRON(GRAPHICS_FUNC_ARGS); +void TRON_init_graphics(); + #define UPDATE_FUNC_ARGS int i, int x, int y, int surround_space, int nt // to call another update function with same arguments: #define UPDATE_FUNC_SUBCALL_ARGS i, x, y, surround_space, nt diff --git a/src/console.c b/src/console.c index 6d8ffe2f9..40807c92f 100644 --- a/src/console.c +++ b/src/console.c @@ -340,7 +340,7 @@ int process_command_old(pixel *vid_buf, char *console, char *console_error) } } } - if (strcmp(console3, "type")==0) + else if (strcmp(console3, "type")==0) { if (strcmp(console4, "all")==0) { @@ -369,7 +369,7 @@ int process_command_old(pixel *vid_buf, char *console, char *console_error) } } } - if (strcmp(console3, "temp")==0) + else if (strcmp(console3, "temp")==0) { if (strcmp(console4, "all")==0) { @@ -398,7 +398,7 @@ int process_command_old(pixel *vid_buf, char *console, char *console_error) } } } - if (strcmp(console3, "tmp")==0) + else if (strcmp(console3, "tmp")==0) { if (strcmp(console4, "all")==0) { @@ -427,7 +427,36 @@ int process_command_old(pixel *vid_buf, char *console, char *console_error) } } } - if (strcmp(console3, "x")==0) + else if (strcmp(console3, "tmp2")==0) + { + if (strcmp(console4, "all")==0) + { + j = atoi(console5); + for (i=0; i>8); } diff --git a/src/elements/sing.c b/src/elements/sing.c index d6fc273fb..3e17fe01b 100644 --- a/src/elements/sing.c +++ b/src/elements/sing.c @@ -15,21 +15,21 @@ int update_SING(UPDATE_FUNC_ARGS) { if (y+CELL0 && pv[y/CELL-1][x/CELL]=0 && pv[y/CELL-1][x/CELL]0) + if (x-CELL>=0) { pv[y/CELL][x/CELL-1] += 0.1f*(singularity-pv[y/CELL][x/CELL-1]); - if (y+CELL>0) + if (y-CELL>=0) pv[y/CELL-1][x/CELL-1] += 0.1f*(singularity-pv[y/CELL-1][x/CELL-1]); } if (parts[i].life<1) { //Pop! - for (rx=-2; rx<3; rx++) { + for (rx=-1; rx<2; rx++) { crx = (x/CELL)+rx; - for (ry=-2; ry<3; ry++) { + for (ry=-1; ry<2; ry++) { cry = (y/CELL)+ry; - if (cry > 0 && crx > 0 && crx < (XRES/CELL) && cry < (YRES/CELL)) { + if (cry >= 0 && crx >= 0 && crx < (XRES/CELL) && cry < (YRES/CELL)) { pv[cry][crx] += (float)parts[i].tmp; } } diff --git a/src/elements/tron.c b/src/elements/tron.c index df8fbe370..00d2e9e91 100644 --- a/src/elements/tron.c +++ b/src/elements/tron.c @@ -24,6 +24,7 @@ #define TRON_DEATH 16 //Crashed, now dying int tron_rx[4] = {-1, 0, 1, 0}; int tron_ry[4] = { 0,-1, 0, 1}; +unsigned int tron_colours[32]; int new_tronhead(int x, int y, int i, int direction) { int np = create_part(-1, x , y ,PT_TRON); @@ -90,14 +91,6 @@ int trymovetron(int x, int y, int dir, int i, int len) } int update_TRON(UPDATE_FUNC_ARGS) { int r, rx, ry, np; - if(!parts[i].ctype) - { - int r, g, b; - int hue = (parts[i].tmp&0xF800)>>7; - HSV_to_RGB(hue,255,255,&r,&g,&b); - parts[i].ctype = r<<16 | g<<8 | b; - //Use photon-like wavelength? - } if (parts[i].tmp&TRON_WAIT) { parts[i].tmp &= ~TRON_WAIT; @@ -162,20 +155,12 @@ int update_TRON(UPDATE_FUNC_ARGS) { } int graphics_TRON(GRAPHICS_FUNC_ARGS) { + unsigned int col = tron_colours[(cpart->tmp&0xF800)>>11]; if(cpart->tmp & TRON_HEAD) *pixel_mode |= PMODE_GLOW; - if(cpart->ctype) - { - *colr = (cpart->ctype & 0xFF0000)>>16; - *colg = (cpart->ctype & 0x00FF00)>>8; - *colb = (cpart->ctype & 0x0000FF); - } - else - { - *colr = 255; - *colg = 255; - *colb = 255; - } + *colr = (col & 0xFF0000)>>16; + *colg = (col & 0x00FF00)>>8; + *colb = (col & 0x0000FF); if(cpart->tmp & TRON_DEATH) { *pixel_mode |= FIRE_ADD | PMODE_FLARE; @@ -191,4 +176,15 @@ int graphics_TRON(GRAPHICS_FUNC_ARGS) { *cola = (int)((((float)cpart->life)/((float)cpart->tmp2))*255.0f); } return 0; -} \ No newline at end of file +} + +void TRON_init_graphics() +{ + int i; + int r, g, b; + for (i=0; i<32; i++) + { + HSV_to_RGB(i<<4,255,255,&r,&g,&b); + tron_colours[i] = r<<16 | g<<8 | b; + } +} diff --git a/src/graphics.c b/src/graphics.c index 93bea8199..3a8971e55 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -3181,9 +3181,8 @@ void render_signs(pixel *vid_buf) if (MSIGN==i) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + mouse_get_state(&mx, &my); + mouse_coords_window_to_sim(&mx, &my, mx, my); signs[i].x = mx; signs[i].y = my; } diff --git a/src/interface.c b/src/interface.c index 3729cfc67..4824cb977 100644 --- a/src/interface.c +++ b/src/interface.c @@ -150,15 +150,17 @@ void add_sign_ui(pixel *vid_buf, int mx, int my) int x0=(XRES-192)/2,y0=(YRES-80)/2,b=1,bq; ui_edit ed; + // if currently moving a sign, stop doing so + if (MSIGN!=-1) + { + MSIGN = -1; + return; + } + // check if it is an existing sign for (i=0; i=x && mx<=x+w && my>=y && my<=y+h) break; @@ -182,7 +184,7 @@ void add_sign_ui(pixel *vid_buf, int mx, int my) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -203,9 +205,7 @@ void add_sign_ui(pixel *vid_buf, int mx, int my) while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); drawrect(vid_buf, x0, y0, 192, 80, 192, 192, 192, 255); clearrect(vid_buf, x0, y0, 192, 80); @@ -488,16 +488,14 @@ void ui_list_process(pixel * vid_buf, int mx, int my, int mb, ui_list *ed) ystart = 5; while (!sdl_poll()) { - mb = SDL_GetMouseState(&mx, &my); + mb = mouse_get_state(&mx, &my); if (!mb) break; } while (!sdl_poll() && !selected) { - mb = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + mb = mouse_get_state(&mx, &my); for(i = 0; i < ed->count; i++) { if(mx > ed->x && mx < ed->x+ed->w && my > (ystart + i*16) && my < (ystart + i * 16) + 16) @@ -523,7 +521,7 @@ void ui_list_process(pixel * vid_buf, int mx, int my, int mb, ui_list *ed) } while (!sdl_poll()) { - mb = SDL_GetMouseState(&mx, &my); + mb = mouse_get_state(&mx, &my); if (!mb) break; } @@ -921,7 +919,7 @@ void error_ui(pixel *vid_buf, int err, char *txt) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -929,9 +927,7 @@ void error_ui(pixel *vid_buf, int err, char *txt) while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); clearrect(vid_buf, x0-2, y0-2, 244, 52+textheight); drawrect(vid_buf, x0, y0, 240, 48+textheight, 192, 192, 192, 255); @@ -957,7 +953,7 @@ void error_ui(pixel *vid_buf, int err, char *txt) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -988,7 +984,7 @@ char *input_ui(pixel *vid_buf, char *title, char *prompt, char *text, char *shad while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -996,9 +992,7 @@ char *input_ui(pixel *vid_buf, char *title, char *prompt, char *text, char *shad while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4); drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255); @@ -1026,7 +1020,7 @@ char *input_ui(pixel *vid_buf, char *title, char *prompt, char *text, char *shad while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -1079,7 +1073,7 @@ void prop_edit_ui(pixel *vid_buf, int x, int y) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -1087,9 +1081,7 @@ void prop_edit_ui(pixel *vid_buf, int x, int y) while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4); drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255); @@ -1221,7 +1213,7 @@ void prop_edit_ui(pixel *vid_buf, int x, int y) exit: while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -1233,7 +1225,7 @@ void info_ui(pixel *vid_buf, char *top, char *txt) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -1241,9 +1233,7 @@ void info_ui(pixel *vid_buf, char *top, char *txt) while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); clearrect(vid_buf, x0-2, y0-2, 244, 64); drawrect(vid_buf, x0, y0, 240, 60, 192, 192, 192, 255); @@ -1264,7 +1254,7 @@ void info_ui(pixel *vid_buf, char *top, char *txt) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -1312,7 +1302,7 @@ void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -1320,9 +1310,7 @@ void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt) while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4); drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255); @@ -1348,7 +1336,7 @@ void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -1367,7 +1355,7 @@ int confirm_ui(pixel *vid_buf, char *top, char *msg, char *btn) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -1375,9 +1363,7 @@ int confirm_ui(pixel *vid_buf, char *top, char *msg, char *btn) while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); clearrect(vid_buf, x0-2, y0-2, 244, 52+textheight); drawrect(vid_buf, x0, y0, 240, 48+textheight, 192, 192, 192, 255); @@ -1410,7 +1396,7 @@ int confirm_ui(pixel *vid_buf, char *top, char *msg, char *btn) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -1426,7 +1412,7 @@ void login_ui(pixel *vid_buf) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -1456,9 +1442,7 @@ void login_ui(pixel *vid_buf) while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); drawrect(vid_buf, x0, y0, 192, 80, 192, 192, 192, 255); clearrect(vid_buf, x0, y0, 192, 80); @@ -1596,7 +1580,7 @@ int stamp_ui(pixel *vid_buf) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -1604,9 +1588,7 @@ int stamp_ui(pixel *vid_buf) while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); clearrect(vid_buf, -1, -1, XRES+BARSIZE+1, YRES+MENUSIZE+1); k = stamp_page*per_page;//0; @@ -1721,7 +1703,7 @@ int stamp_ui(pixel *vid_buf) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -1752,9 +1734,7 @@ void tag_list_ui(pixel *vid_buf) while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); op = tag = NULL; @@ -1866,7 +1846,7 @@ void tag_list_ui(pixel *vid_buf) } while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -1890,7 +1870,7 @@ int save_name_ui(pixel *vid_buf) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -1940,9 +1920,7 @@ int save_name_ui(pixel *vid_buf) while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); drawrect(vid_buf, x0, y0, 420, 90+YRES/4, 192, 192, 192, 255); clearrect(vid_buf, x0, y0, 420, 90+YRES/4); @@ -2033,16 +2011,14 @@ void menu_ui(pixel *vid_buf, int i, int *sl, int *sr) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); rows = ceil((float)msections[i].itemcount/16.0f); height = (ceil((float)msections[i].itemcount/16.0f)*18); width = restrict_flt(msections[i].itemcount*31, 0, 16*31); @@ -2211,7 +2187,7 @@ void menu_ui(pixel *vid_buf, int i, int *sl, int *sr) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -2223,8 +2199,6 @@ void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int *su, int *dae, int { int h,x,y,n=0,height,width,sy,rows=0,xoff=0,fwidth; SEC = SEC2; - mx /= sdl_scale; - my /= sdl_scale; rows = ceil((float)msections[i].itemcount/16.0f); height = (ceil((float)msections[i].itemcount/16.0f)*18); width = restrict_flt(msections[i].itemcount*31, 0, 16*31); @@ -2592,8 +2566,6 @@ int quickoptions_tooltip_y = 0; void quickoptions_menu(pixel *vid_buf, int b, int bq, int x, int y) { int i = 0; - x /= sdl_scale; - y /= sdl_scale; if(quickoptions_tooltip_fade && quickoptions_tooltip) { drawtext_outline(vid_buf, (XRES - 5) - textwidth(quickoptions_tooltip), quickoptions_tooltip_y, quickoptions_tooltip, 255, 255, 255, quickoptions_tooltip_fade*20, 0, 0, 0, quickoptions_tooltip_fade*15); @@ -3086,7 +3058,7 @@ int search_ui(pixel *vid_buf) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -3114,9 +3086,7 @@ int search_ui(pixel *vid_buf) bq = b; mxq = mx; myq = my; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); if (mx!=mxq || my!=myq || sdl_wheel || b) mmt = 0; @@ -3798,7 +3768,7 @@ int report_ui(pixel* vid_buf, char *save_id) fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192); while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -3809,9 +3779,7 @@ int report_ui(pixel* vid_buf, char *save_id) drawrect(vid_buf, 205, 155, (XRES+BARSIZE-400)-10, (YRES+MENUSIZE-300)-28, 255, 255, 255, 170); bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); drawrect(vid_buf, 200, (YRES+MENUSIZE-150)-18, 50, 18, 255, 255, 255, 255); @@ -3897,7 +3865,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -3991,9 +3959,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); if (active && http_async_req_status(http)) { @@ -4365,7 +4331,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) //Prevent those mouse clicks being passed down. while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -5198,9 +5164,7 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { } while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); ed.focus = 1; memcpy(vid_buf,old_buf,(XRES+BARSIZE)*YRES*PIXELSIZE); @@ -5338,6 +5302,7 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int savedColor) {//TODO: have the text boxes be editable and update the color. int i,ss,hh,vv,cr=127,cg=0,cb=0,b = 0,mx,my,bq = 0,j, lb=0,lx=0,ly=0,lm=0,hidden=0; + int line_x=0, line_y=0; int window_offset_x_left = 2; int window_offset_x_right = XRES - 279; int window_offset_y = 2; @@ -5400,9 +5365,7 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); memcpy(vid_buf,old_buf,(XRES+BARSIZE)*(YRES+MENUSIZE)*PIXELSIZE); render_parts(vid_buf); @@ -5428,14 +5391,8 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved box_G.x = XRES - 254 + 40; box_B.x = XRES - 254 + 75; } - if (zoom_en && mx>=zoom_wx && my>=zoom_wy //change mouse position while it is in a zoom window - && mx<(zoom_wx+ZFACTOR*ZSIZE) - && my<(zoom_wy+ZFACTOR*ZSIZE)) - { - mx = (((mx-zoom_wx)/ZFACTOR)+zoom_x); - my = (((my-zoom_wy)/ZFACTOR)+zoom_y); - } - + mouse_coords_window_to_sim(&mx, &my, mx, my);//change mouse position while it is in a zoom window + drawrect(vid_buf, -1, -1, XRES+1, YRES+1, 220, 220, 220, 255); drawrect(vid_buf, -1, -1, XRES+2, YRES+2, 70, 70, 70, 255); drawtext(vid_buf, 2, 388, "Welcome to the decoration editor v.3 (by cracker64) \n\nClicking the current color on the window will move it to the other side. Right click is eraser. ", 255, 255, 255, 255); @@ -5637,7 +5594,19 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved { if (lm == 1)//line tool preview { - xor_line(lx, ly, mx, my, vid_buf); + if (sdl_mod & KMOD_ALT) + { + float snap_angle = floor(atan2(my-ly, mx-lx)/(M_PI*0.25)+0.5)*M_PI*0.25; + float line_mag = sqrtf(pow(mx-lx,2)+pow(my-ly,2)); + line_x = (int)(line_mag*cos(snap_angle)+lx+0.5f); + line_y = (int)(line_mag*sin(snap_angle)+ly+0.5f); + } + else + { + line_x = mx; + line_y = my; + } + xor_line(lx, ly, line_x, line_y, vid_buf); } else if (lm == 2)//box tool preview { @@ -5706,7 +5675,7 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved if (lb && lm) //lm is box/line tool { if (lm == 1)//line - line_decorations(lx, ly, mx, my, *bsx, *bsy, currR, currG, currB, lb, tool); + line_decorations(lx, ly, line_x, line_y, *bsx, *bsy, currR, currG, currB, lb, tool); else//box box_decorations(lx, ly, mx, my, currR, currG, currB, lb, tool); lm = 0; @@ -6005,7 +5974,7 @@ int save_filename_ui(pixel *vid_buf) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -6018,9 +5987,7 @@ int save_filename_ui(pixel *vid_buf) while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4); drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255); @@ -6105,7 +6072,7 @@ int save_filename_ui(pixel *vid_buf) savefin: while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -6150,7 +6117,7 @@ void catalogue_ui(pixel * vid_buf) cssave = csave = saves; while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -6158,9 +6125,7 @@ void catalogue_ui(pixel * vid_buf) fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192); while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); sprintf(savetext, "Found %d save%s", rescount, rescount==1?"":"s"); clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4); clearrect(vid_buf2, x0-2, y0-2, xsize+4, ysize+4); @@ -6337,7 +6302,7 @@ void catalogue_ui(pixel * vid_buf) openfin: while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -6496,7 +6461,7 @@ void render_ui(pixel * vid_buf, int xcoord, int ycoord, int orientation) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -6504,9 +6469,7 @@ void render_ui(pixel * vid_buf, int xcoord, int ycoord, int orientation) while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); memcpy(vid_buf, o_vid_buf, ((YRES+MENUSIZE) * (XRES+BARSIZE)) * PIXELSIZE); render_parts(vid_buf); @@ -6661,7 +6624,7 @@ void render_ui(pixel * vid_buf, int xcoord, int ycoord, int orientation) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -6738,7 +6701,7 @@ void simulation_ui(pixel * vid_buf) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } @@ -6746,9 +6709,7 @@ void simulation_ui(pixel * vid_buf) while (!sdl_poll()) { bq = b; - b = SDL_GetMouseState(&mx, &my); - mx /= sdl_scale; - my /= sdl_scale; + b = mouse_get_state(&mx, &my); clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4); drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255); @@ -6841,8 +6802,36 @@ void simulation_ui(pixel * vid_buf) while (!sdl_poll()) { - b = SDL_GetMouseState(&mx, &my); + b = mouse_get_state(&mx, &my); if (!b) break; } } + +Uint8 mouse_get_state(int *x, int *y) +{ + //Wrapper around SDL_GetMouseState to divide by sdl_scale + Uint8 sdl_b; + int sdl_x, sdl_y; + sdl_b = SDL_GetMouseState(&sdl_x, &sdl_y); + *x = sdl_x/sdl_scale; + *y = sdl_y/sdl_scale; + return sdl_b; +} + +void mouse_coords_window_to_sim(int *sim_x, int *sim_y, int window_x, int window_y) +{ + //Change mouse coords to take zoom window into account + if (zoom_en && window_x>=zoom_wx && window_y>=zoom_wy + && window_x<(zoom_wx+ZFACTOR*ZSIZE) + && window_y<(zoom_wy+ZFACTOR*ZSIZE)) + { + *sim_x = (((window_x-zoom_wx)/ZFACTOR)+zoom_x); + *sim_y = (((window_y-zoom_wy)/ZFACTOR)+zoom_y); + } + else + { + *sim_x = window_x; + *sim_y = window_y; + } +} diff --git a/src/main.c b/src/main.c index f6e741c5a..ebda63fe2 100644 --- a/src/main.c +++ b/src/main.c @@ -657,6 +657,7 @@ int main(int argc, char *argv[]) colour_mode = COLOUR_DEFAULT; init_display_modes(); + TRON_init_graphics(); sys_pause = 1; parts = calloc(sizeof(particle), NPART); @@ -806,6 +807,7 @@ int main(int argc, char *argv[]) colour_mode = COLOUR_DEFAULT; init_display_modes(); + TRON_init_graphics(); //fbi_img = render_packed_rgb(fbi, FBI_W, FBI_H, FBI_CMP); @@ -1761,25 +1763,25 @@ int main(int argc, char *argv[]) } bq = bc; // bq is previous mouse state - bc = b = SDL_GetMouseState(&x, &y); // b is current mouse state + bc = b = mouse_get_state(&x, &y); // b is current mouse state #ifdef LUACONSOLE if(bc && bq){ - if(!luacon_mouseevent(x/sdl_scale, y/sdl_scale, bc, LUACON_MPRESS)){ + if(!luacon_mouseevent(x, y, bc, LUACON_MPRESS)){ b = 0; } } else if(bc && !bq){ - if(!luacon_mouseevent(x/sdl_scale, y/sdl_scale, bc, LUACON_MDOWN)){ + if(!luacon_mouseevent(x, y, bc, LUACON_MDOWN)){ b = 0; } } else if(!bc && bq){ - if(!luacon_mouseevent(x/sdl_scale, y/sdl_scale, bq, LUACON_MUP)){ + if(!luacon_mouseevent(x, y, bq, LUACON_MUP)){ b = 0; } } - luacon_step(x/sdl_scale, y/sdl_scale,sl,sr); + luacon_step(x, y,sl,sr); #endif quickoptions_menu(vid_buf, b, bq, x, y); @@ -1791,27 +1793,21 @@ int main(int argc, char *argv[]) for (i=0; i=sdl_scale*(XRES-2) && x= sdl_scale*((i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16)) && y=(XRES-2) && x<(XRES+BARSIZE-1) &&y>= ((i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16)) && y<((i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16)+15)) { active_menu = i; } } menu_ui_v3(vid_buf, active_menu, &sl, &sr, &su, &dae, b, bq, x, y); //draw the elements in the current menu - if (zoom_en && x>=sdl_scale*zoom_wx && y>=sdl_scale*zoom_wy //change mouse position while it is in a zoom window - && x0 && y0 && x=0 && y=0 && x>8].temp-273.15f, parts[cr>>8].life, parts[cr>>8].tmp); - sprintf(coordtext, "#%d, X:%d Y:%d", cr>>8, x/sdl_scale, y/sdl_scale); + sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C, Life: %d, Tmp:%d", nametext, pv[y/CELL][x/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life, parts[cr>>8].tmp); + sprintf(coordtext, "#%d, X:%d Y:%d", cr>>8, x, y); } else { #ifdef BETA - sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C, Life: %d, Tmp:%d", nametext, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life, parts[cr>>8].tmp); + sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C, Life: %d, Tmp:%d", nametext, pv[y/CELL][x/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life, parts[cr>>8].tmp); #else - sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C", nametext, 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", nametext, pv[y/CELL][x/CELL], parts[cr>>8].temp-273.15f); #endif } if ((cr&0xFF)==PT_PHOT) wavelength_gfx = parts[cr>>8].ctype; } else { - sprintf(heattext, "Empty, Pressure: %3.2f", pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL]); + sprintf(heattext, "Empty, Pressure: %3.2f", pv[y/CELL][x/CELL]); if (DEBUG_MODE) { if (ngrav_enable) - sprintf(coordtext, "X:%d Y:%d. GX: %.2f GY: %.2f", x/sdl_scale, y/sdl_scale, gravx[(((y/sdl_scale)/CELL)*(XRES/CELL))+((x/sdl_scale)/CELL)], gravy[(((y/sdl_scale)/CELL)*(XRES/CELL))+((x/sdl_scale)/CELL)]); + sprintf(coordtext, "X:%d Y:%d. GX: %.2f GY: %.2f", x, y, gravx[((y/CELL)*(XRES/CELL))+(x/CELL)], gravy[((y/CELL)*(XRES/CELL))+(x/CELL)]); else - sprintf(coordtext, "X:%d Y:%d", x/sdl_scale, y/sdl_scale); + sprintf(coordtext, "X:%d Y:%d", x, y); } } } @@ -1885,8 +1881,8 @@ int main(int argc, char *argv[]) mx = x; my = y; - if (b && !bq && x>=(XRES-19-new_message_len)*sdl_scale && - x<=(XRES-14)*sdl_scale && y>=(YRES-37)*sdl_scale && y<=(YRES-24)*sdl_scale && svf_messages) + if (b && !bq && x>=(XRES-19-new_message_len) && + x<=(XRES-14) && y>=(YRES-37) && y<=(YRES-24) && svf_messages) { open_link("http://" SERVER "/Conversations.html"); } @@ -1908,8 +1904,8 @@ int main(int argc, char *argv[]) update_flag = 0; } - if (b && !bq && x>=(XRES-19-old_ver_len)*sdl_scale && - x<=(XRES-14)*sdl_scale && y>=(YRES-22)*sdl_scale && y<=(YRES-9)*sdl_scale && old_version) + if (b && !bq && x>=(XRES-19-old_ver_len) && + x<=(XRES-14) && y>=(YRES-22) && y<=(YRES-9) && old_version) { tmp = malloc(128); #ifdef BETA @@ -1954,9 +1950,9 @@ int main(int argc, char *argv[]) old_version = 0; } } - if (y>=sdl_scale*(YRES+(MENUSIZE-20))) //mouse checks for buttons at the bottom, to draw mouseover texts + if (y>=(YRES+(MENUSIZE-20))) //mouse checks for buttons at the bottom, to draw mouseover texts { - if (x>=189*sdl_scale && x<=202*sdl_scale && svf_login && svf_open && svf_myvote==0) + if (x>=189 && x<=202 && svf_login && svf_open && svf_myvote==0) { db = svf_own ? 275 : 272; if (da < 51) @@ -1974,25 +1970,25 @@ int main(int argc, char *argv[]) if (da < 51) da ++; } - else if (x>=219*sdl_scale && x<=((XRES+BARSIZE-(510-349))*sdl_scale) && svf_login && svf_open) + else if (x>=219 && x<=((XRES+BARSIZE-(510-349))) && svf_login && svf_open) { db = svf_own ? 257 : 256; if (da < 51) da ++; } - else if (x>=((XRES+BARSIZE-(510-351))*sdl_scale) && x<((XRES+BARSIZE-(510-366))*sdl_scale)) + else if (x>=((XRES+BARSIZE-(510-351))) && x<((XRES+BARSIZE-(510-366)))) { db = 270; if (da < 51) da ++; } - else if (x>=((XRES+BARSIZE-(510-367))*sdl_scale) && x<((XRES+BARSIZE-(510-383))*sdl_scale)) + else if (x>=((XRES+BARSIZE-(510-367))) && x<((XRES+BARSIZE-(510-383)))) { db = 266; if (da < 51) da ++; } - else if (x>=37*sdl_scale && x<=187*sdl_scale) + else if (x>=37 && x<=187) { if(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) { @@ -2003,13 +1999,13 @@ int main(int argc, char *argv[]) else if(svf_login) { db = 259; - if (svf_open && svf_own && x<=55*sdl_scale) + if (svf_open && svf_own && x<=55) db = 258; if (da < 51) da ++; } } - else if (x>=((XRES+BARSIZE-(510-385))*sdl_scale) && x<=((XRES+BARSIZE-(510-476))*sdl_scale)) + else if (x>=((XRES+BARSIZE-(510-385))) && x<=((XRES+BARSIZE-(510-476)))) { db = svf_login ? 261 : 260; if (svf_admin) @@ -2023,7 +2019,7 @@ int main(int argc, char *argv[]) if (da < 51) da ++; } - else if (x>=sdl_scale && x<=17*sdl_scale) + else if (x>=1 && x<=17) { if(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) db = 276; @@ -2032,19 +2028,19 @@ int main(int argc, char *argv[]) if (da < 51) da ++; } - else if (x>=((XRES+BARSIZE-(510-494))*sdl_scale) && x<=((XRES+BARSIZE-(510-509))*sdl_scale)) + else if (x>=((XRES+BARSIZE-(510-494))) && x<=((XRES+BARSIZE-(510-509)))) { db = sys_pause ? 264 : 263; if (da < 51) da ++; } - else if (x>=((XRES+BARSIZE-(510-476))*sdl_scale) && x<=((XRES+BARSIZE-(510-491))*sdl_scale)) + else if (x>=((XRES+BARSIZE-(510-476))) && x<=((XRES+BARSIZE-(510-491)))) { db = 267; if (da < 51) da ++; } - else if (x>=19*sdl_scale && x<=35*sdl_scale && svf_open) + else if (x>=19 && x<=35 && svf_open) { db = 265; if (da < 51) @@ -2067,8 +2063,8 @@ int main(int argc, char *argv[]) if (load_mode) { - load_x = CELL*((mx/sdl_scale-load_w/2+CELL/2)/CELL); - load_y = CELL*((my/sdl_scale-load_h/2+CELL/2)/CELL); + load_x = CELL*((mx-load_w/2+CELL/2)/CELL); + load_y = CELL*((my-load_h/2+CELL/2)/CELL); if (load_x+load_w>XRES) load_x=XRES-load_w; if (load_y+load_h>YRES) load_y=YRES-load_h; if (load_x<0) load_x=0; @@ -2089,8 +2085,8 @@ int main(int argc, char *argv[]) } else if (save_mode==1)//getting the area you are selecting { - save_x = mx/sdl_scale; - save_y = my/sdl_scale; + save_x = mx; + save_y = my; if (save_x >= XRES) save_x = XRES-1; if (save_y >= YRES) save_y = YRES-1; save_w = 1; @@ -2107,8 +2103,8 @@ int main(int argc, char *argv[]) } else if (save_mode==2) { - save_w = mx/sdl_scale + 1 - save_x; - save_h = my/sdl_scale + 1 - save_y; + save_w = mx + 1 - save_x; + save_h = my + 1 - save_y; if (save_w+save_x>XRES) save_w = XRES-save_x; if (save_h+save_y>YRES) save_h = YRES-save_y; if (save_w<1) save_w = 1; @@ -2139,8 +2135,6 @@ int main(int argc, char *argv[]) } else if (sdl_zoom_trig && zoom_en<2) { - x /= sdl_scale; - y /= sdl_scale; x -= ZSIZE/2; y -= ZSIZE/2; if (x<0) x=0; @@ -2162,8 +2156,6 @@ int main(int argc, char *argv[]) { if (it > 50) it = 50; - x /= sdl_scale; - y /= sdl_scale; if (y>=YRES+(MENUSIZE-20))//check if mouse is on menu buttons { if (!lb)//mouse is NOT held down, so it is a first click @@ -2245,7 +2237,7 @@ int main(int argc, char *argv[]) else execute_save(vid_buf); while (!sdl_poll()) - if (!SDL_GetMouseState(&x, &y)) + if (!mouse_get_state(&x, &y)) break; b = bq = 0; } @@ -2303,7 +2295,7 @@ int main(int argc, char *argv[]) } } - if (c==WL_SIGN+100) + if (c==WL_SIGN+100 || MSIGN!=-1) // if sign tool is selected or a sign is being moved { if (!bq) add_sign_ui(vid_buf, x, y); @@ -2475,8 +2467,6 @@ int main(int argc, char *argv[]) { if (lb && lm) //lm is box/line tool { - x /= sdl_scale; - y /= sdl_scale; c = (lb&1) ? sl : sr; su = c; if (lm == 1)//line @@ -2506,9 +2496,9 @@ int main(int argc, char *argv[]) if (zoom_en!=1 && !load_mode && !save_mode)//draw normal cursor { - render_cursor(vid_buf, mx/sdl_scale, my/sdl_scale, su, bsx, bsy); - mousex = mx/sdl_scale; - mousey = my/sdl_scale; + render_cursor(vid_buf, mx, my, su, bsx, bsy); + mousex = mx; + mousey = my; } #ifdef OGLR draw_parts_fbo(); diff --git a/src/powder.c b/src/powder.c index f5b1f2273..b96a3ae36 100644 --- a/src/powder.c +++ b/src/powder.c @@ -2794,6 +2794,7 @@ void clear_area(int area_x, int area_y, int area_w, int area_h) { int cx = 0; int cy = 0; + int i; for (cy=0; cy=area_x && signs[i].x=area_y && signs[i].y>8; + //Store saved particle index+1 for this partsptr index (0 means not saved) + partsSaveIndex[i] = (partsCount++) + 1; + //Type (required) partsData[partsDataLen++] = partsptr[i].type; + elementCount[partsptr[i].type]++; //Location of the field descriptor fieldDescLoc = partsDataLen++; @@ -679,6 +687,47 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h } } } + + soapLinkData = malloc(3*elementCount[PT_SOAP]); + soapLinkDataLen = 0; + //Iterate through particles in the same order that they were saved + for (y=0;y>8; + + if (partsptr[i].type==PT_SOAP) + { + //Only save forward link for each particle, back links can be deduced from other forward links + //linkedIndex is index within saved particles + 1, 0 means not saved or no link + unsigned linkedIndex = 0; + if ((partsptr[i].ctype&2) && partsptr[i].tmp>=0 && partsptr[i].tmp>16; + soapLinkData[soapLinkDataLen++] = (linkedIndex&0x00FF00)>>8; + soapLinkData[soapLinkDataLen++] = (linkedIndex&0x0000FF); + } + + //Get the pmap entry for the next particle in the same position + i = partsPosLink[i]; + } + } + } + if(!soapLinkDataLen) + { + free(soapLinkData); + soapLinkData = NULL; + } if(!partsDataLen) { free(partsData); @@ -704,10 +753,12 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h bson_append_binary(&b, "wallMap", BSON_BIN_USER, wallData, wallDataLen); if(fanData) bson_append_binary(&b, "fanMap", BSON_BIN_USER, fanData, fanDataLen); + if(soapLinkData) + bson_append_binary(&b, "soapLinks", BSON_BIN_USER, soapLinkData, soapLinkDataLen); signsCount = 0; for(i = 0; i < MAXSIGNS; i++) { - if(signs[i].text[0] && signs[i].x>=fullX && signs[i].x<=fullX+fullW && signs[i].y>=fullY && signs[i].y<=fullY+fullH) + if(signs[i].text[0] && signs[i].x>=orig_x0 && signs[i].x<=orig_x0+orig_w && signs[i].y>=orig_y0 && signs[i].y<=orig_y0+orig_h) { signsCount++; } @@ -717,7 +768,7 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h bson_append_start_array(&b, "signs"); for(i = 0; i < MAXSIGNS; i++) { - if(signs[i].text[0] && signs[i].x>=fullX && signs[i].x<=fullX+fullW && signs[i].y>=fullY && signs[i].y<=fullY+fullH) + if(signs[i].text[0] && signs[i].x>=orig_x0 && signs[i].x<=orig_x0+orig_w && signs[i].y>=orig_y0 && signs[i].y<=orig_y0+orig_h) { bson_append_start_object(&b, "sign"); bson_append_string(&b, "text", signs[i].text); @@ -770,6 +821,12 @@ fin: free(wallData); if(fanData) free(fanData); + if (elementCount) + free(elementCount); + if (partsSaveIndex) + free(partsSaveIndex); + if (soapLinkData) + free(soapLinkData); return outputData; } @@ -777,8 +834,9 @@ fin: int parse_save_OPS(void *save, int size, int replace, int x0, int y0, unsigned char bmap[YRES/CELL][XRES/CELL], float vx[YRES/CELL][XRES/CELL], float vy[YRES/CELL][XRES/CELL], float pv[YRES/CELL][XRES/CELL], float fvx[YRES/CELL][XRES/CELL], float fvy[YRES/CELL][XRES/CELL], sign signs[MAXSIGNS], void* o_partsptr, unsigned pmap[YRES][XRES]) { particle *partsptr = o_partsptr; - unsigned char * inputData = save, *bsonData = NULL, *partsData = NULL, *partsPosData = NULL, *fanData = NULL, *wallData = NULL; - int inputDataLen = size, bsonDataLen = 0, partsDataLen, partsPosDataLen, fanDataLen, wallDataLen; + unsigned char * inputData = save, *bsonData = NULL, *partsData = NULL, *partsPosData = NULL, *fanData = NULL, *wallData = NULL, *soapLinkData = NULL; + int inputDataLen = size, bsonDataLen = 0, partsDataLen, partsPosDataLen, fanDataLen, wallDataLen, soapLinkDataLen; + unsigned partsCount = 0, *partsSimIndex = NULL; int i, freeIndicesCount, x, y, returnCode = 0, j; int *freeIndices = NULL; int blockX, blockY, blockW, blockH, fullX, fullY, fullW, fullH; @@ -874,7 +932,7 @@ int parse_save_OPS(void *save, int size, int replace, int x0, int y0, unsigned c { if(strcmp(bson_iterator_key(&signiter), "text")==0 && bson_iterator_type(&signiter)==BSON_STRING) { - strcpy(signs[i].text, bson_iterator_string(&signiter)); + strncpy(signs[i].text, bson_iterator_string(&signiter), 255); clean_text(signs[i].text, 158-14); } else if(strcmp(bson_iterator_key(&signiter), "justification")==0 && bson_iterator_type(&signiter)==BSON_INT) @@ -951,6 +1009,17 @@ int parse_save_OPS(void *save, int size, int replace, int x0, int y0, unsigned c fprintf(stderr, "Invalid datatype of fan data: %d[%d] %d[%d] %d[%d]\n", bson_iterator_type(&iter), bson_iterator_type(&iter)==BSON_BINDATA, (unsigned char)bson_iterator_bin_type(&iter), ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER, bson_iterator_bin_len(&iter), bson_iterator_bin_len(&iter)>0); } } + else if(strcmp(bson_iterator_key(&iter), "soapLinks")==0) + { + if(bson_iterator_type(&iter)==BSON_BINDATA && ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER && (soapLinkDataLen = bson_iterator_bin_len(&iter)) > 0) + { + soapLinkData = bson_iterator_bin_data(&iter); + } + else + { + fprintf(stderr, "Invalid datatype of soap data: %d[%d] %d[%d] %d[%d]\n", bson_iterator_type(&iter), bson_iterator_type(&iter)==BSON_BINDATA, (unsigned char)bson_iterator_bin_type(&iter), ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER, bson_iterator_bin_len(&iter), bson_iterator_bin_len(&iter)>0); + } + } else if(strcmp(bson_iterator_key(&iter), "legacyEnable")==0 && replace) { if(bson_iterator_type(&iter)==BSON_BOOL) @@ -1102,6 +1171,8 @@ int parse_save_OPS(void *save, int size, int replace, int x0, int y0, unsigned c parts_lastActiveIndex = NPART-1; freeIndicesCount = 0; freeIndices = calloc(sizeof(int), NPART); + partsSimIndex = calloc(NPART, sizeof(unsigned)); + partsCount = 0; for (i = 0; i= PT_NUM) partsData[i] = PT_DMND; //Replace all invalid elements with diamond - if(pmap[y][x]) + if(pmap[y][x] && posCount==0) // Check posCount to make sure an existing particle is not replaced twice if two particles are saved in that position { //Replace existing particle or allocated block newIndex = pmap[y][x]>>8; @@ -1158,7 +1229,10 @@ int parse_save_OPS(void *save, int size, int replace, int x0, int y0, unsigned c } if(newIndex < 0 || newIndex >= NPART) goto fail; - + + //Store partsptr index+1 for this saved particle index (0 means not loaded) + partsSimIndex[partsCount++] = newIndex+1; + //Clear the particle, ready for our new properties memset(&(partsptr[newIndex]), 0, sizeof(particle)); @@ -1284,11 +1358,43 @@ int parse_save_OPS(void *save, int size, int replace, int x0, int y0, unsigned c STKM_init_legs(&(fighters[fcount]), newIndex); } } + else if (partsptr[newIndex].type == PT_SOAP) + { + //Clear soap links, links will be added back in if soapLinkData is present + partsptr[newIndex].ctype &= ~6; + } if (!ptypes[partsptr[newIndex].type].enabled) partsptr[newIndex].type = PT_NONE; } } } + if (soapLinkData) + { + int soapLinkDataPos = 0; + for (i=0; i soapLinkDataLen) break; + linkedIndex |= soapLinkData[soapLinkDataPos++]<<16; + linkedIndex |= soapLinkData[soapLinkDataPos++]<<8; + linkedIndex |= soapLinkData[soapLinkDataPos++]; + // All indexes in soapLinkData and partsSimIndex have 1 added to them (0 means not saved/loaded) + if (!linkedIndex || linkedIndex-1>=partsCount || !partsSimIndex[linkedIndex-1]) + continue; + linkedIndex = partsSimIndex[linkedIndex-1]-1; + newIndex = partsSimIndex[i]-1; + + //Attach the two particles + partsptr[newIndex].ctype |= 2; + partsptr[newIndex].tmp = linkedIndex; + partsptr[linkedIndex].ctype |= 4; + partsptr[linkedIndex].tmp2 = newIndex; + } + } + } } goto fin; fail: @@ -1298,6 +1404,8 @@ fin: bson_destroy(&b); if(freeIndices) free(freeIndices); + if(partsSimIndex) + free(partsSimIndex); return returnCode; } @@ -1580,7 +1688,7 @@ void *build_save_PSv(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h for (j=0; j=x0 && signs[i].x=y0 && signs[i].y=orig_x0 && signs[i].x=orig_y0 && signs[i].y=x0 && signs[i].x=y0 && signs[i].y=orig_x0 && signs[i].x=orig_y0 && signs[i].y>8; @@ -1963,7 +2071,7 @@ int parse_save_PSv(void *save, int size, int replace, int x0, int y0, unsigned c { i = m[j]; ty = d[pty+j]; - if (i && ty==PT_PBCN) + if (i && (ty==PT_PBCN || (ty==PT_TRON && ver>=77))) { if (p >= size) goto corrupt;