diff options
| author | Simon <simon@hardwired.org.uk> | 2010-12-05 15:49:48 (GMT) |
|---|---|---|
| committer | Simon <simon@hardwired.org.uk> | 2010-12-05 15:49:48 (GMT) |
| commit | 40ab51d79f68eaef88defee0e3cf1de5cfb0b0b0 (patch) | |
| tree | fffbf3f7b503d36829dd91cde10cb39abb7ca5e8 /src/main.c | |
| parent | 6ecc177c8ff8a90b5c4fc996090bd1de915237ab (diff) | |
| download | powder-40ab51d79f68eaef88defee0e3cf1de5cfb0b0b0.zip powder-40ab51d79f68eaef88defee0e3cf1de5cfb0b0b0.tar.gz | |
Cracker64 merge
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 259 |
1 files changed, 190 insertions, 69 deletions
@@ -6,6 +6,7 @@ * Copyright (c) 2010 Skresanov Savely * Copyright (c) 2010 Bryan Hoyle * Copyright (c) 2010 Nathan Cousins + * Copyright (c) 2010 cracker64 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,6 +22,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -28,6 +30,7 @@ #include <SDL/SDL.h> #include <bzlib.h> #include <time.h> + #ifdef WIN32 #include <direct.h> #else @@ -49,7 +52,7 @@ #include <icon.h> static const char *it_msg = - "\brThe Powder Toy\n" + "\brThe Powder Toy - http://powdertoy.co.uk/\n" "\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\n" "\n" "\bgControl+C/V/X are Copy, Paste and cut respectively.\n" @@ -66,18 +69,16 @@ static const char *it_msg = "'L' will load the most recent stamp, 'K' shows a library of stamps you saved.\n" "'C' will cycle the display mode (Fire, Blob, Velocity and Pressure). The numbers 1 to 7 will do the same\n" "Use the mouse scroll wheel to change the tool size for particles.\n" - "'Q' will quit the application.\n" "The spacebar can be used to pause physics.\n" "'P' will take a screenshot and save it into the current directory.\n" "\n" - "\brhttp://powdertoy.co.uk/\n" "\bgCopyright (c) 2008-10 Stanislaw K Skowronek (\brhttp://powder.unaligned.org\bg, \bbirc.unaligned.org #wtf\bg)\n" "\bgCopyright (c) 2010 Simon Robertshaw (\brhttp://powdertoy.co.uk\bg, \bbirc.freenode.net #powder\bg)\n" "\bgCopyright (c) 2010 Skresanov Savely (Stickman)\n" + "\bgCopyright (c) 2010 cracker64\n" "\bgCopyright (c) 2010 Bryan Hoyle (New elements)\n" "\bgCopyright (c) 2010 Nathan Cousins (New elements, small engine mods.)\n" "\n" - "\bgSpecial thanks to Brian Ledbetter for maintaining ports.\n" "\bgTo use online features such as saving, you need to register at: \brhttp://powdertoy.co.uk/Register.html" ; @@ -99,6 +100,9 @@ int legacy_enable = 0; //Used to disable new features such as heat, will be set int death = 0, framerender = 0; int amd = 1; int FPSB = 0; +int MSIGN =-1; +//int CGOL = 0; +//int GSPEED = 1;//causes my .exe to crash.. sign signs[MAXSIGNS]; @@ -245,7 +249,7 @@ void *build_save(int *size, int x0, int y0, int w, int h) d[p++] = bmap[y][x]; for(y=by0; y<by0+bh; y++) for(x=bx0; x<bx0+bw; x++) - if(bmap[y][x]==4) + if(bmap[y][x]==WL_FAN) { i = (int)(fvx[y][x]*64.0f+127.5f); if(i<0) i=0; @@ -254,7 +258,7 @@ void *build_save(int *size, int x0, int y0, int w, int h) } for(y=by0; y<by0+bh; y++) for(x=bx0; x<bx0+bw; x++) - if(bmap[y][x]==4) + if(bmap[y][x]==WL_FAN) { i = (int)(fvy[y][x]*64.0f+127.5f); if(i<0) i=0; @@ -325,7 +329,7 @@ void *build_save(int *size, int x0, int y0, int w, int h) for(j=0; j<w*h; j++) { i = m[j]; - if(i && (parts[i-1].type==PT_CLNE || parts[i-1].type==PT_PCLN || parts[i-1].type==PT_SPRK || parts[i-1].type==PT_LAVA)) + if(i && (parts[i-1].type==PT_CLNE || parts[i-1].type==PT_PCLN || parts[i-1].type==PT_SPRK || parts[i-1].type==PT_LAVA || parts[i-1].type==PT_PIPE)) d[p++] = parts[i-1].ctype; } @@ -481,7 +485,36 @@ int parse_save(void *save, int size, int replace, int x0, int y0) for(x=bx0; x<bx0+bw; x++) { if(d[p]) + { bmap[y][x] = d[p]; + if(bmap[y][x]==1) + bmap[y][x]=WL_WALL; + if(bmap[y][x]==2) + bmap[y][x]=WL_DESTROYALL; + if(bmap[y][x]==3) + bmap[y][x]=WL_ALLOWLIQUID; + if(bmap[y][x]==4) + bmap[y][x]=WL_FAN; + if(bmap[y][x]==5) + bmap[y][x]=WL_STREAM; + if(bmap[y][x]==6) + bmap[y][x]=WL_DETECT; + if(bmap[y][x]==7) + bmap[y][x]=WL_EWALL; + if(bmap[y][x]==8) + bmap[y][x]=WL_WALLELEC; + if(bmap[y][x]==9) + bmap[y][x]=WL_ALLOWAIR; + if(bmap[y][x]==10) + bmap[y][x]=WL_ALLOWSOLID; + if(bmap[y][x]==11) + bmap[y][x]=WL_ALLOWALLELEC; + if(bmap[y][x]==12) + bmap[y][x]=WL_EHOLE; + if(bmap[y][x]==13) + bmap[y][x]=WL_ALLOWGAS; + } + p++; } for(y=by0; y<by0+bh; y++) @@ -514,6 +547,7 @@ int parse_save(void *save, int size, int replace, int x0, int y0) //TODO: Possibly some server side translation j = PT_DUST;//goto corrupt; } + gol[x][y]=0; if(j)// && !(isplayer == 1 && j==PT_STKM)) { if(pmap[y][x]) @@ -529,6 +563,10 @@ int parse_save(void *save, int size, int replace, int x0, int y0) else if(i < nf) { parts[fp[i]].type = j; + if(j == PT_COAL) + parts[fp[i]].tmp = 50; + if(j == PT_FUSE) + parts[fp[i]].tmp = 50; if(j == PT_PHOT) parts[fp[i]].ctype = 0x3fffffff; parts[fp[i]].x = (float)x; @@ -654,7 +692,7 @@ int parse_save(void *save, int size, int replace, int x0, int y0) { i = m[j]; ty = d[pty+j]; - if(i && (ty==PT_CLNE || (ty==PT_PCLN && ver>=43) || (ty==PT_SPRK && ver>=21) || (ty==PT_LAVA && ver>=34))) + if(i && (ty==PT_CLNE || (ty==PT_PCLN && ver>=43) || (ty==PT_SPRK && ver>=21) || (ty==PT_LAVA && ver>=34) || (ty==PT_PIPE && ver>=43))) { if(p >= size) goto corrupt; @@ -1003,7 +1041,7 @@ int main(int argc, char *argv[]) int vs = 0; #endif 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, bs = 2; + int da = 0, db = 0, it = 2047, mx, my, bsx = 2, bsy = 2; float nfvx, nfvy; int load_mode=0, load_w=0, load_h=0, load_x=0, load_y=0, load_size=0; void *load_data=NULL; @@ -1118,7 +1156,7 @@ int main(int argc, char *argv[]) { for(i=1; i<XRES/CELL; i++) { - if(bmap[j][i]==1 || bmap[j][i]==8 || (bmap[j][i]==7 && !emap[j][i])) + if(bmap[j][i]==WL_WALL || bmap[j][i]==WL_WALLELEC || (bmap[j][i]==WL_EWALL && !emap[j][i])) { vx[j][i] = 0.0f; vx[j][i-1] = 0.0f; @@ -1135,11 +1173,11 @@ int main(int argc, char *argv[]) #ifdef OpenGL ClearScreen(); #else - if(cmode==0 || cmode==1) + if(cmode==CM_VEL || cmode==CM_PRESS || cmode==CM_CRACK) { draw_air(vid_buf); } - else if(cmode==2) + else if(cmode==CM_PERS) { memcpy(vid_buf, fire_bg, XRES*YRES*PIXELSIZE); memset(vid_buf+(XRES*YRES), 0, ((XRES+BARSIZE)*YRES*PIXELSIZE)-(XRES*YRES*PIXELSIZE)); @@ -1152,7 +1190,7 @@ int main(int argc, char *argv[]) update_particles(vid_buf); draw_parts(vid_buf); - if(cmode==2) + if(cmode==CM_PERS) { if(!fire_fc) { @@ -1164,7 +1202,7 @@ int main(int argc, char *argv[]) } fire_fc = (fire_fc+1) % 3; } - if(cmode==3||cmode==4||cmode==6) + if(cmode==CM_FIRE||cmode==CM_BLOB||cmode==CM_FANCY) render_fire(vid_buf); render_signs(vid_buf); @@ -1252,76 +1290,134 @@ int main(int argc, char *argv[]) } if(sdl_key=='1') { - set_cmode(0); + set_cmode(CM_VEL); } if(sdl_key=='2') { - set_cmode(1); + set_cmode(CM_PRESS); } if(sdl_key=='3') { - set_cmode(2); + set_cmode(CM_PERS); } if(sdl_key=='4') { - set_cmode(3); + set_cmode(CM_FIRE); } if(sdl_key=='5') { - set_cmode(4); + set_cmode(CM_BLOB); } if(sdl_key=='6') { - set_cmode(5); + set_cmode(CM_HEAT); } if(sdl_key=='7') { - set_cmode(6); + set_cmode(CM_FANCY); + } + if(sdl_key=='8') + { + set_cmode(CM_NOTHING); + } + if(sdl_key=='9') + { + set_cmode(CM_CRACK); + } + if(sdl_key=='0') + { + set_cmode(CM_GRAD); } + if(sdl_key==SDLK_TAB) + { + CURRENT_BRUSH =(CURRENT_BRUSH + 1)%BRUSH_NUM ; + } if(sdl_key==SDLK_LEFTBRACKET) { if(sdl_zoom_trig==1) { ZSIZE -= 1; - if(ZSIZE>32) - ZSIZE = 32; + if(ZSIZE>60) + ZSIZE = 60; if(ZSIZE<2) ZSIZE = 2; ZFACTOR = 256/ZSIZE; } else { - if(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) - bs -= 1; + if(sdl_mod & (KMOD_LALT|KMOD_RALT) && !(sdl_mod & (KMOD_SHIFT|KMOD_CTRL))) + { + bsx -= 1; + bsy -= 1; + } + else if(sdl_mod & (KMOD_SHIFT) && !(sdl_mod & (KMOD_CTRL))) + { + bsx -= 1; + } + else if(sdl_mod & (KMOD_CTRL) && !(sdl_mod & (KMOD_SHIFT))) + { + bsy -= 1; + } else - bs -= ceil((bs/5)+0.5f); - if(bs>1224) - bs = 1224; - if(bs<0) - bs = 0; + { + bsx -= ceil((bsx/5)+0.5f); + bsy -= ceil((bsy/5)+0.5f); + } + if(bsx>1180) + bsx = 1180; + if(bsy>1180) + bsy = 1180; + if(bsx<0) + bsx = 0; + if(bsy<0) + bsy = 0; } } if(sdl_key==SDLK_RIGHTBRACKET) { if(sdl_zoom_trig==1) { ZSIZE += 1; - if(ZSIZE>32) - ZSIZE = 32; + if(ZSIZE>60) + ZSIZE = 60; if(ZSIZE<2) ZSIZE = 2; ZFACTOR = 256/ZSIZE; } else { - if(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) - bs += 1; + if(sdl_mod & (KMOD_LALT|KMOD_RALT) && !(sdl_mod & (KMOD_SHIFT|KMOD_CTRL))) + { + bsx += 1; + bsy += 1; + } + else if(sdl_mod & (KMOD_SHIFT) && !(sdl_mod & (KMOD_CTRL))) + { + bsx += 1; + } + else if(sdl_mod & (KMOD_CTRL) && !(sdl_mod & (KMOD_SHIFT))) + { + bsy += 1; + } else - bs += ceil((bs/5)+0.5f); - if(bs>1224) - bs = 1224; - if(bs<0) - bs = 0; + { + bsx += ceil((bsx/5)+0.5f); + bsy += ceil((bsy/5)+0.5f); + } + if(bsx>1180) + bsx = 1180; + if(bsy>1180) + bsy = 1180; + if(bsx<0) + bsx = 0; + if(bsy<0) + bsy = 0; } } + if(sdl_key==SDLK_INSERT) + REPLACE_MODE = !REPLACE_MODE; + if(sdl_key=='g') + GRID_MODE = (GRID_MODE+1)%10; + if(sdl_key=='t') + VINE_MODE = !VINE_MODE; if(sdl_key==SDLK_SPACE) sys_pause = !sys_pause; if(sdl_key=='h') @@ -1357,7 +1453,7 @@ int main(int argc, char *argv[]) } else if(sdl_key=='c') { - set_cmode((cmode+1) % 7); + set_cmode((cmode+1) % CM_COUNT); if(it > 50) it = 50; } @@ -1394,8 +1490,8 @@ int main(int argc, char *argv[]) if(sdl_zoom_trig==1) { ZSIZE += sdl_wheel; - if(ZSIZE>32) - ZSIZE = 32; + if(ZSIZE>60) + ZSIZE = 60; if(ZSIZE<2) ZSIZE = 2; ZFACTOR = 256/ZSIZE; @@ -1403,11 +1499,27 @@ int main(int argc, char *argv[]) } else { - bs += sdl_wheel; - if(bs>1224) - bs = 1224; - if(bs<0) - bs = 0; + if(!(sdl_mod & (KMOD_SHIFT|KMOD_CTRL))) + { + bsx += sdl_wheel; + bsy += sdl_wheel; + } + else if(sdl_mod & (KMOD_SHIFT) && !(sdl_mod & (KMOD_CTRL))) + { + bsx += sdl_wheel; + } + else if(sdl_mod & (KMOD_CTRL) && !(sdl_mod & (KMOD_SHIFT))) + { + bsy += sdl_wheel; + } + if(bsx>1180) + bsx = 1180; + if(bsx<0) + bsx = 0; + if(bsy>1180) + bsy = 1180; + if(bsy<0) + bsy = 0; sdl_wheel = 0; /*if(su >= PT_NUM) { if(sl < PT_NUM) @@ -1794,9 +1906,9 @@ int main(int argc, char *argv[]) if(x>=(XRES+BARSIZE-(510-476)) && x<=(XRES+BARSIZE-(510-491)) && !bq) { if(b & SDL_BUTTON_LMASK) - set_cmode((cmode+1) % 7); + set_cmode((cmode+1) % CM_COUNT); if(b & SDL_BUTTON_RMASK) - set_cmode((cmode+6) % 7); + set_cmode((cmode+(CM_COUNT-1)) % CM_COUNT); save_presets(0); } if(x>=(XRES+BARSIZE-(510-494)) && x<=(XRES+BARSIZE-(510-509)) && !bq) @@ -1808,7 +1920,7 @@ int main(int argc, char *argv[]) { c = (b&1) ? sl : sr; su = c; - if(c==126) + if(c==WL_SIGN+100) { if(!bq) add_sign_ui(vid_buf, x, y); @@ -1818,18 +1930,18 @@ int main(int argc, char *argv[]) if(lm == 1) { xor_line(lx, ly, x, y, vid_buf); - if(c==127 && lx>=0 && ly>=0 && lx<XRES && ly<YRES && bmap[ly/CELL][lx/CELL]==4) + if(c==WL_FAN+100 && lx>=0 && ly>=0 && lx<XRES && ly<YRES && bmap[ly/CELL][lx/CELL]==WL_FAN) { nfvx = (x-lx)*0.005f; nfvy = (y-ly)*0.005f; - flood_parts(lx, ly, 255, -1, 4); + flood_parts(lx, ly, WL_FANHELPER, -1, WL_FAN); for(j=0; j<YRES/CELL; j++) for(i=0; i<XRES/CELL; i++) - if(bmap[j][i] == 255) + if(bmap[j][i] == WL_FANHELPER) { fvx[j][i] = nfvx; fvy[j][i] = nfvy; - bmap[j][i] = 4; + bmap[j][i] = WL_FAN; } } } @@ -1842,14 +1954,14 @@ int main(int argc, char *argv[]) } else { - create_line(lx, ly, x, y, bs, c); + create_line(lx, ly, x, y, bsx, bsy, c); lx = x; ly = y; } } else { - if((sdl_mod & (KMOD_LSHIFT|KMOD_RSHIFT)) && !(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))) + if((sdl_mod & (KMOD_LSHIFT|KMOD_RSHIFT)) && !(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL|KMOD_LALT))) { lx = x; ly = y; @@ -1863,16 +1975,18 @@ int main(int argc, char *argv[]) lb = b; lm = 2; } - else if((sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) && (sdl_mod & (KMOD_LSHIFT|KMOD_RSHIFT))) + else if((sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) && (sdl_mod & (KMOD_LSHIFT|KMOD_RSHIFT)) && !(sdl_mod & (KMOD_LALT))) { - if(c!=125&&c!=SPC_AIR&&c!=SPC_HEAT&&c!=SPC_COOL&&c!=SPC_VACUUM) + if(sdl_mod & (KMOD_CAPS)) + c = 0; + if(c!=WL_STREAM&&c!=SPC_AIR&&c!=SPC_HEAT&&c!=SPC_COOL&&c!=SPC_VACUUM&&!REPLACE_MODE) flood_parts(x, y, c, -1, -1); lx = x; ly = y; lb = 0; lm = 0; } - else if((sdl_mod & (KMOD_LALT||KMOD_RALT)) || b==SDL_BUTTON_MIDDLE) + else if(((sdl_mod & (KMOD_LALT|KMOD_RALT)) && !(sdl_mod & (KMOD_SHIFT))) || b==SDL_BUTTON_MIDDLE) { if(y>0 && y<sdl_scale*YRES && x>0 && x<sdl_scale*XRES) { @@ -1914,7 +2028,7 @@ int main(int argc, char *argv[]) cb_emap[cby][cbx] = emap[cby][cbx]; } - create_parts(x, y, bs, c); + create_parts(x, y, bsx, bsy, c); lx = x; ly = y; lb = b; @@ -1933,8 +2047,8 @@ int main(int argc, char *argv[]) su = c; if(lm == 1) { - if(c!=127 || lx<0 || ly<0 || lx>=XRES || ly>=YRES || bmap[ly/CELL][lx/CELL]!=4) - create_line(lx, ly, x, y, bs, c); + if(c!=WL_FAN+100 || lx<0 || ly<0 || lx>=XRES || ly>=YRES || bmap[ly/CELL][lx/CELL]!=WL_FAN) + create_line(lx, ly, x, y, bsx, bsy, c); } else create_box(lx, ly, x, y, c); @@ -1958,7 +2072,7 @@ int main(int argc, char *argv[]) if(zoom_en!=1 && !load_mode && !save_mode) { - render_cursor(vid_buf, mx/sdl_scale, my/sdl_scale, su, bs); + render_cursor(vid_buf, mx/sdl_scale, my/sdl_scale, su, bsx, bsy); mousex = mx/sdl_scale; mousey = my/sdl_scale; } @@ -2071,16 +2185,23 @@ int main(int argc, char *argv[]) } if(currentTime-pastFPS>=1000) { -#ifdef BETA - sprintf(uitext, "Version %d (Beta %d) FPS:%d", SAVE_VERSION, MINOR_VERSION, FPS); - //printf("%s\n", uitext); -#else - sprintf(uitext, "Version %d.%d FPS:%d", SAVE_VERSION, MINOR_VERSION, FPS); -#endif FPSB = FPS; FPS = 0; pastFPS = currentTime; } + +#ifdef BETA + sprintf(uitext, "Version %d Beta %d FPS:%d Parts:%d", SAVE_VERSION, MINOR_VERSION, FPSB, NUM_PARTS); +#else + sprintf(uitext, "Version %d.%d FPS:%d", SAVE_VERSION, MINOR_VERSION, FPSB); +#endif + if(REPLACE_MODE) + strappend(uitext, " [REPLACE MODE]"); + if(sdl_mod&(KMOD_CAPS)) + strappend(uitext, " [CAP LOCKS]"); + if(GRID_MODE) + sprintf(uitext, "%s [GRID: %d]", uitext, GRID_MODE); + if(sdl_zoom_trig||zoom_en) { if(zoom_x<XRES/2) |
