From 2dbb14b8b45c36f12837503413932aa9502422ff Mon Sep 17 00:00:00 2001 From: "chaos.powdertoy.co.uk" Date: Fri, 27 Apr 2012 13:53:56 +0100 Subject: Version Increment diff --git a/includes/defines.h b/includes/defines.h index 74ac062..701d515 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -10,7 +10,7 @@ //VersionInfoStart #define SAVE_VERSION 76 #define MINOR_VERSION 0 -#define BUILD_NUM 157 +#define BUILD_NUM 158 //VersionInfoEnd #define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter -- cgit v0.9.2-21-gd62e From 418bdf0892b53103faa2976a1621bf83de92c59c Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Fri, 27 Apr 2012 17:41:45 +0100 Subject: Add tmp2 support to old console diff --git a/src/console.c b/src/console.c index 6d8ffe2..40807c9 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 Date: Fri, 27 Apr 2012 17:46:40 +0100 Subject: Save tmp2 for tron diff --git a/src/save.c b/src/save.c index a96cb05..df98635 100644 --- a/src/save.c +++ b/src/save.c @@ -1580,7 +1580,7 @@ void *build_save_PSv(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h for (j=0; j=77))) { if (p >= size) goto corrupt; -- cgit v0.9.2-21-gd62e From 6101c04ff9ee55e2be9a100a76a65ed1559ca24a Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Fri, 27 Apr 2012 17:59:24 +0100 Subject: Use an array instead of ctype to cache tron colour diff --git a/includes/powder.h b/includes/powder.h index c471aa7..48a0664 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -329,6 +329,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/elements/tron.c b/src/elements/tron.c index df8fbe3..00d2e9e 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/main.c b/src/main.c index f6e741c..4e60674 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); -- cgit v0.9.2-21-gd62e From 257c069da19bb4d9365177ad852bc6a154197ce5 Mon Sep 17 00:00:00 2001 From: "chaos.powdertoy.co.uk" Date: Fri, 27 Apr 2012 18:18:14 +0100 Subject: Version Increment diff --git a/includes/defines.h b/includes/defines.h index 701d515..f5e5c8d 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 158 +#define BUILD_NUM 159 //VersionInfoEnd #define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter -- cgit v0.9.2-21-gd62e From 5d5b8143a41cdd2bc1fe7a136e2370bfc9f61b0a Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Fri, 27 Apr 2012 18:26:37 +0100 Subject: OPS loading: don't replace existing particles twice, and clear soap ctype diff --git a/src/save.c b/src/save.c index df98635..0e8c086 100644 --- a/src/save.c +++ b/src/save.c @@ -1141,7 +1141,7 @@ int parse_save_OPS(void *save, int size, int replace, int x0, int y0, unsigned c } if(partsData[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; @@ -1284,6 +1284,10 @@ 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) + { + partsptr[newIndex].ctype = 0; + } if (!ptypes[partsptr[newIndex].type].enabled) partsptr[newIndex].type = PT_NONE; } -- cgit v0.9.2-21-gd62e From ade3fd9568e029b43bf8337a42034e3a5cd867fa Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sun, 29 Apr 2012 00:11:54 +0100 Subject: Delete signs when cutting; change sign location check when saving Save signs within the original box that was drawn by the user, not within the box that has been expanded to match the wall grid diff --git a/src/powder.c b/src/powder.c index 354c788..e0ddd5c 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=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 +717,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); @@ -1642,14 +1642,14 @@ void *build_save_PSv(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h j = 0; for (i=0; i=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; -- cgit v0.9.2-21-gd62e From 34bfd77aa5210cc66df9902e1bfebba0b5889706 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sun, 29 Apr 2012 00:22:02 +0100 Subject: Line snapping for deco editor diff --git a/src/interface.c b/src/interface.c index 3729cfc..3ef7ed2 100644 --- a/src/interface.c +++ b/src/interface.c @@ -5338,6 +5338,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; @@ -5637,7 +5638,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 +5719,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; -- cgit v0.9.2-21-gd62e From 38057065c2b18bd455f150e32348a266ecfc1355 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sun, 29 Apr 2012 00:34:56 +0100 Subject: Fix bugs when moving signs Signs could not be repositioned on top of another sign (dependent on the indices of the two signs), and could not be placed after selecting an element from the menu. diff --git a/src/interface.c b/src/interface.c index 3ef7ed2..7f7ec65 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; diff --git a/src/main.c b/src/main.c index 4e60674..683cd96 100644 --- a/src/main.c +++ b/src/main.c @@ -2305,7 +2305,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); -- cgit v0.9.2-21-gd62e From d7f798da60ac6844dd386ee1f4a0145c4d18a8ec Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sun, 29 Apr 2012 01:37:52 +0100 Subject: Fix bounds checking for SING and make explosion pressure area smaller Making the area smaller means a bit less pressure is generated, but it does stop the pressure going through walls diff --git a/src/elements/sing.c b/src/elements/sing.c index d6fc273..3e17fe0 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; } } -- cgit v0.9.2-21-gd62e From 6717f4ff32aa7a341a73735061dfbc72eed8ea2a Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sun, 29 Apr 2012 15:31:18 +0100 Subject: Save soap bubbles diff --git a/src/save.c b/src/save.c index f6ad26f..90e2252 100644 --- a/src/save.c +++ b/src/save.c @@ -440,9 +440,11 @@ fin: void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h, 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) { particle *partsptr = o_partsptr; - unsigned char *partsData = NULL, *partsPosData = NULL, *fanData = NULL, *wallData = NULL, *finalData = NULL, *outputData = NULL; + unsigned char *partsData = NULL, *partsPosData = NULL, *fanData = NULL, *wallData = NULL, *finalData = NULL, *outputData = NULL, *soapLinkData = NULL; unsigned *partsPosLink = NULL, *partsPosFirstMap = NULL, *partsPosCount = NULL, *partsPosLastMap = NULL; - int partsDataLen, partsPosDataLen, fanDataLen, wallDataLen, finalDataLen, outputDataLen; + unsigned partsCount = 0, *partsSaveIndex = NULL; + unsigned *elementCount = calloc(PT_NUM, sizeof(unsigned)); + int partsDataLen, partsPosDataLen, fanDataLen, wallDataLen, finalDataLen, outputDataLen, soapLinkDataLen; int blockX, blockY, blockW, blockH, fullX, fullY, fullW, fullH; int x, y, i, wallDataFound = 0; int posCount, signsCount; @@ -557,6 +559,8 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h */ partsData = malloc(NPART * (sizeof(particle)+1)); partsDataLen = 0; + partsSaveIndex = calloc(NPART, sizeof(unsigned)); + partsCount = 0; for (y=0;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,6 +753,8 @@ 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++) { @@ -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; @@ -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= 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)); @@ -1286,13 +1360,41 @@ int parse_save_OPS(void *save, int size, int replace, int x0, int y0, unsigned c } else if (partsptr[newIndex].type == PT_SOAP) { - partsptr[newIndex].ctype = 0; + //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: @@ -1302,6 +1404,8 @@ fin: bson_destroy(&b); if(freeIndices) free(freeIndices); + if(partsSimIndex) + free(partsSimIndex); return returnCode; } -- cgit v0.9.2-21-gd62e From 74979102b34980ce2a815ebf15985d356a73de3c Mon Sep 17 00:00:00 2001 From: savask Date: Mon, 30 Apr 2012 00:37:51 +0700 Subject: One gel particle can't absorb more than 100 water particles now. diff --git a/src/elements/gel.c b/src/elements/gel.c index efd9d78..5c1b1f5 100644 --- a/src/elements/gel.c +++ b/src/elements/gel.c @@ -14,7 +14,7 @@ int update_GEL(UPDATE_FUNC_ARGS) { if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW || (r&0xFF)==PT_SLTW || (r&0xFF)==PT_CBNW) && parts[i].tmp<100) { - parts[i].tmp = (100+parts[i].tmp)/2; + parts[i].tmp++; kill_part(r>>8); } -- cgit v0.9.2-21-gd62e From 8872e33b44ddc766e2c92fc843e2ee883247f473 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Mon, 30 Apr 2012 00:34:07 +0100 Subject: Massive cleanup of sdl_scale, and fix moving a sign in the zoom window diff --git a/includes/interface.h b/includes/interface.h index 57f75b6..858e289 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/src/graphics.c b/src/graphics.c index 93bea81..3a8971e 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 7f7ec65..4824cb9 100644 --- a/src/interface.c +++ b/src/interface.c @@ -184,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; } @@ -205,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); @@ -490,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) @@ -525,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; } @@ -923,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; } @@ -931,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); @@ -959,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; } @@ -990,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; } @@ -998,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); @@ -1028,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; } @@ -1081,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; } @@ -1089,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); @@ -1223,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; } @@ -1235,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; } @@ -1243,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); @@ -1266,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; } @@ -1314,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; } @@ -1322,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); @@ -1350,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; } @@ -1369,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; } @@ -1377,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); @@ -1412,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; } @@ -1428,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; } @@ -1458,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); @@ -1598,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; } @@ -1606,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; @@ -1723,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; } @@ -1754,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; @@ -1868,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; } @@ -1892,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; } @@ -1942,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); @@ -2035,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); @@ -2213,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; } @@ -2225,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); @@ -2594,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); @@ -3088,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; } @@ -3116,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; @@ -3800,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; } @@ -3811,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); @@ -3899,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; } @@ -3993,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)) { @@ -4367,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; } @@ -5200,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); @@ -5403,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); @@ -5431,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); @@ -6020,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; } @@ -6033,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); @@ -6120,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; } @@ -6165,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; } @@ -6173,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); @@ -6352,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; } @@ -6511,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; } @@ -6519,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); @@ -6676,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; } @@ -6753,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; } @@ -6761,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); @@ -6856,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 683cd96..ebda63f 100644 --- a/src/main.c +++ b/src/main.c @@ -1763,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); @@ -1793,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); } } } @@ -1887,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"); } @@ -1910,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 @@ -1956,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) @@ -1976,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)) { @@ -2005,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) @@ -2025,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; @@ -2034,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) @@ -2069,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; @@ -2091,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; @@ -2109,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; @@ -2141,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; @@ -2164,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 @@ -2247,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; } @@ -2477,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 @@ -2508,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(); -- cgit v0.9.2-21-gd62e From 433c1881bc37ea257999b88eee920c19a92798c5 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Mon, 30 Apr 2012 14:36:45 +0100 Subject: strncpy for loading sign text in OPS diff --git a/src/save.c b/src/save.c index 90e2252..56b7424 100644 --- a/src/save.c +++ b/src/save.c @@ -932,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) -- cgit v0.9.2-21-gd62e