diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/elements/fwrk.c | 2 | ||||
| -rw-r--r-- | src/elements/prti.c | 32 | ||||
| -rw-r--r-- | src/elements/prto.c | 37 | ||||
| -rw-r--r-- | src/elements/qrtz.c | 55 | ||||
| -rw-r--r-- | src/elements/sing.c | 38 | ||||
| -rw-r--r-- | src/elements/stkm.c | 25 | ||||
| -rw-r--r-- | src/elements/stkm2.c | 25 | ||||
| -rw-r--r-- | src/graphics.c | 163 | ||||
| -rw-r--r-- | src/interface.c | 72 | ||||
| -rw-r--r-- | src/main.c | 339 | ||||
| -rw-r--r-- | src/misc.c | 149 | ||||
| -rw-r--r-- | src/powder.c | 358 |
12 files changed, 844 insertions, 451 deletions
diff --git a/src/elements/fwrk.c b/src/elements/fwrk.c index 06390c5..5095cde 100644 --- a/src/elements/fwrk.c +++ b/src/elements/fwrk.c @@ -16,7 +16,7 @@ int update_FWRK(UPDATE_FUNC_ARGS) { } if (parts[i].life>=45) parts[i].life=0; - if ((parts[i].life<3&&parts[i].life>0)||parts[i].vy>6&&parts[i].life>0) + if ((parts[i].life<3&&parts[i].life>0)||(parts[i].vy>6&&parts[i].life>0)) { int q = (rand()%255+1); int w = (rand()%255+1); diff --git a/src/elements/prti.c b/src/elements/prti.c index 560ba8c..fa87562 100644 --- a/src/elements/prti.c +++ b/src/elements/prti.c @@ -1,7 +1,7 @@ #include <element.h> int update_PRTI(UPDATE_FUNC_ARGS) { - int r, nnx, rx, ry; + int r, nnx, rx, ry, fe = 0; int count =0; parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1); if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1; @@ -12,6 +12,8 @@ int update_PRTI(UPDATE_FUNC_ARGS) { { r = pmap[y+ry][x+rx]; count ++; + if (!r) + fe = 1; if ((r>>8)>=NPART || !r) continue; if ((r&0xFF)==PT_SPRK || ((r&0xFF)!=PT_PRTI && (r&0xFF)!=PT_PRTO && (ptypes[r&0xFF].falldown!= 0 || ptypes[r&0xFF].state == ST_GAS))) @@ -28,5 +30,33 @@ int update_PRTI(UPDATE_FUNC_ARGS) { break; } } + + + if(fe){ + if(!parts[i].life) parts[i].life = rand(); + if(!parts[i].ctype) parts[i].life = rand(); + int orbd[4] = {0, 0, 0, 0}; //Orbital distances + int orbl[4] = {0, 0, 0, 0}; //Orbital locations + orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); + for(r = 0; r < 4; r++){ + if(orbd[r]>1){ + orbd[r] -= 12; + if(orbd[r]<1){ + orbd[r] = (rand()%128)+128; + orbl[r] = rand()%255; + } else { + orbl[r] += 2; + orbl[r] = orbl[r]%255; + } + } else { + orbd[r] = (rand()%128)+128; + orbl[r] = rand()%255; + } + } + orbitalparts_set(&parts[i].life, &parts[i].ctype, orbd, orbl); + } else { + parts[i].life = 0; + parts[i].ctype = 0; + } return 0; } diff --git a/src/elements/prto.c b/src/elements/prto.c index 8f743e7..9bec996 100644 --- a/src/elements/prto.c +++ b/src/elements/prto.c @@ -1,17 +1,19 @@ #include <element.h> int update_PRTO(UPDATE_FUNC_ARGS) { - int r, nnx, rx, ry, np; + int r, nnx, rx, ry, np, fe = 0; int count = 0; parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1); if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1; else if (parts[i].tmp<0) parts[i].tmp = 0; - for (rx=-1; rx<2; rx++) - for (ry=-1; ry<2; ry++) + for (rx=1; rx>-2; rx--) + for (ry=1; ry>-2; ry--) if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) { r = pmap[y+ry][x+rx]; count ++; + if (!r) + fe = 1; if ((r>>8)>=NPART || r) continue; if (!r) @@ -21,8 +23,8 @@ int update_PRTO(UPDATE_FUNC_ARGS) { int randomness = count + rand()%3-1; if (randomness<1) randomness=1; - if (randomness>8) - randomness=8; + if (randomness>9) + randomness=9; if (portal[parts[i].tmp][randomness-1][nnx]==PT_SPRK)// TODO: make it look better { create_part(-1,x+1,y,portal[parts[i].tmp][randomness-1][nnx]); @@ -51,5 +53,30 @@ int update_PRTO(UPDATE_FUNC_ARGS) { } } } + if(fe){ + if(!parts[i].life) parts[i].life = rand(); + if(!parts[i].ctype) parts[i].life = rand(); + int orbd[4] = {0, 0, 0, 0}; //Orbital distances + int orbl[4] = {0, 0, 0, 0}; //Orbital locations + orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); + for(r = 0; r < 4; r++){ + if(orbd[r]<254){ + orbd[r] += 16; + if(orbd[r]>254){ + orbd[r] = 0; + orbl[r] = rand()%255; + } + //orbl[r] += 1; + //orbl[r] = orbl[r]%255; + } else { + orbd[r] = 0; + orbl[r] = rand()%255; + } + } + orbitalparts_set(&parts[i].life, &parts[i].ctype, orbd, orbl); + } else { + parts[i].life = 0; + parts[i].ctype = 0; + } return 0; } diff --git a/src/elements/qrtz.c b/src/elements/qrtz.c index 74d8c99..e585361 100644 --- a/src/elements/qrtz.c +++ b/src/elements/qrtz.c @@ -1,11 +1,66 @@ #include <element.h> int update_QRTZ(UPDATE_FUNC_ARGS) { + int r, tmp, trade, rx, ry, np; parts[i].pavg[0] = parts[i].pavg[1]; parts[i].pavg[1] = pv[y/CELL][x/CELL]; if (parts[i].pavg[1]-parts[i].pavg[0] > 0.05*(parts[i].temp/3) || parts[i].pavg[1]-parts[i].pavg[0] < -0.05*(parts[i].temp/3)) { part_change_type(i,x,y,PT_PQRT); } + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if ((r>>8)>=NPART || !r) + continue; + else if ((r&0xFF)==PT_SLTW && (1>rand()%2500)) + { + kill_part(r>>8); + parts[i].life ++; + } + } + if (parts[i].life>0) + { + for (rx=-1; rx<2; rx++) + for (ry=-1; ry<2; ry++) + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if ((r>>8)>=NPART || r || parts[i].life==0) continue; + np = create_part(-1,x+rx,y+ry,PT_QRTZ); + if (np<0) continue; + parts[np].tmp = parts[i].tmp; + parts[i].life = 0; + } + } + for ( trade = 0; trade<9; trade ++) + { + rx = rand()%5-2; + ry = rand()%5-2; + if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) + { + r = pmap[y+ry][x+rx]; + if ((r>>8)>=NPART || !r) + continue; + if ((r&0xFF)==PT_QRTZ&&(parts[i].life>parts[r>>8].life)&&parts[i].life>0)//diffusion + { + tmp = parts[i].life - parts[r>>8].life; + if (tmp ==1) + { + parts[r>>8].life ++; + parts[i].life --; + trade = 9; + } + if (tmp>0) + { + parts[r>>8].life += tmp/2; + parts[i].life -= tmp/2; + trade = 9; + } + } + } + } return 0; } diff --git a/src/elements/sing.c b/src/elements/sing.c index 02f5eaf..4514726 100644 --- a/src/elements/sing.c +++ b/src/elements/sing.c @@ -1,7 +1,7 @@ #include <element.h> int update_SING(UPDATE_FUNC_ARGS) { - int r, rx, ry; + int r, rx, ry, cry, crx, rad, nxi, nxj, nb; int singularity = -parts[i].life; if (pv[y/CELL][x/CELL]<singularity) @@ -22,6 +22,41 @@ int update_SING(UPDATE_FUNC_ARGS) { 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++){ + crx = (x/CELL)+rx; + for(ry=-2; ry<3; ry++){ + cry = (y/CELL)+ry; + if(cry > 0 && crx > 0 && crx < (XRES/CELL) && cry < (YRES/CELL)){ + pv[cry][crx] += (float)parts[i].tmp; + } + } + } + rad = (parts[i].tmp>255)?255:parts[i].tmp; + if(rad>=1){ + rad = (int)(((float)rad)/8.0f); + } + if(rad>=1){ + for (nxj=-(rad+1); nxj<=(rad+1); nxj++) + for (nxi=-(rad+1); nxi<=(rad+1); nxi++) + if ((pow(nxi,2))/(pow((rad+1),2))+(pow(nxj,2))/(pow((rad+1),2))<=1) { + if(rand()%2){ + nb = create_part(-1, x+nxi, y+nxj, PT_PHOT); + } else { + nb = create_part(-1, x+nxi, y+nxj, PT_NEUT); + } + if (nb!=-1) { + parts[nb].life = rand()%300; + parts[nb].temp = MAX_TEMP/2; + parts[nb].vx = rand()%10-5; + parts[nb].vy = rand()%10-5; + } + } + } + kill_part(i); + return 1; + } for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) @@ -50,6 +85,7 @@ int update_SING(UPDATE_FUNC_ARGS) { continue; } parts[i].life += 3; + parts[i].tmp++; } parts[i].temp = restrict_flt(parts[r>>8].temp+parts[i].temp, MIN_TEMP, MAX_TEMP); kill_part(r>>8); diff --git a/src/elements/stkm.c b/src/elements/stkm.c index 6d6b4ab..fc6dc55 100644 --- a/src/elements/stkm.c +++ b/src/elements/stkm.c @@ -185,8 +185,10 @@ int update_STKM(UPDATE_FUNC_ARGS) { { r = pmap[y+ry][x+rx]; if (!r || (r>>8)>=NPART) + r = photons[y+ry][x+rx]; + if (!r || (r>>8)>=NPART) continue; - if (ptypes[r&0xFF].falldown!=0 || (r&0xFF) == PT_NEUT || (r&0xFF) == PT_PHOT) // TODO: photons are not in the pmap. This line may not work as intended. + if (ptypes[r&0xFF].falldown!=0 || (r&0xFF) == PT_NEUT || (r&0xFF) == PT_PHOT) { player[2] = r&0xFF; //Current element } @@ -225,26 +227,27 @@ int update_STKM(UPDATE_FUNC_ARGS) { } else { + int np = -1; if (player[2] == SPC_AIR) create_parts(rx + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01), ry, 4, 4, SPC_AIR); else - create_part(-1, rx, ry, player[2]); - - r = pmap[ry][rx]; - if ( ((r>>8) < NPART) && (r>>8)>=0 && player[2] != PT_PHOT && player[2] != SPC_AIR) - parts[r>>8].vx = parts[r>>8].vx + 5*((((int)player[1])&0x02) == 0x02) - 5*(((int)(player[1])&0x01) == 0x01); - if (((r>>8) < NPART) && (r>>8)>=0 && player[2] == PT_PHOT) + np = create_part(-1, rx, ry, player[2]); + if ( (np < NPART) && np>=0 && player[2] != PT_PHOT && player[2] != SPC_AIR) + parts[np].vx = parts[np].vx + 5*((((int)player[1])&0x02) == 0x02) - 5*(((int)(player[1])&0x01) == 0x01); + if ((np < NPART) && np>=0 && player[2] == PT_PHOT) { int random = abs(rand()%3-1)*3; if (random==0) { - parts[r>>8].life = 0; - parts[r>>8].type = PT_NONE; + kill_part(np); } else { - parts[r>>8].vy = 0; - parts[r>>8].vx = (((((int)player[1])&0x02) == 0x02) - (((int)(player[1])&0x01) == 0x01))*random; + parts[np].vy = 0; + if (((int)player[1])&(0x01|0x02)) + parts[np].vx = (((((int)player[1])&0x02) == 0x02) - (((int)(player[1])&0x01) == 0x01))*random; + else + parts[np].vx = random; } } diff --git a/src/elements/stkm2.c b/src/elements/stkm2.c index 319e388..79dbbdf 100644 --- a/src/elements/stkm2.c +++ b/src/elements/stkm2.c @@ -185,8 +185,10 @@ int update_STKM2(UPDATE_FUNC_ARGS) { { r = pmap[y+ry][x+rx]; if (!r || (r>>8)>=NPART) + r = photons[y+ry][x+rx]; + if (!r || (r>>8)>=NPART) continue; - if (ptypes[r&0xFF].falldown!=0 || (r&0xFF) == PT_NEUT || (r&0xFF) == PT_PHOT) // TODO: photons are not in the pmap. This line may not work as intended. + if (ptypes[r&0xFF].falldown!=0 || (r&0xFF) == PT_NEUT || (r&0xFF) == PT_PHOT) { player2[2] = r&0xFF; //Current element } @@ -225,26 +227,27 @@ int update_STKM2(UPDATE_FUNC_ARGS) { } else { + int np = -1; if (player2[2] == SPC_AIR) create_parts(rx + 3*((((int)player2[1])&0x02) == 0x02) - 3*((((int)player2[1])&0x01) == 0x01), ry, 4, 4, SPC_AIR); else - create_part(-1, rx, ry, player2[2]); - - r = pmap[ry][rx]; - if ( ((r>>8) < NPART) && (r>>8)>=0 && player2[2] != PT_PHOT && player2[2] != SPC_AIR) - parts[r>>8].vx = parts[r>>8].vx + 5*((((int)player2[1])&0x02) == 0x02) - 5*(((int)(player2[1])&0x01) == 0x01); - if (((r>>8) < NPART) && (r>>8)>=0 && player2[2] == PT_PHOT) + np = create_part(-1, rx, ry, player2[2]); + if ((np < NPART) && np>=0 && player2[2] != PT_PHOT && player2[2] != SPC_AIR) + parts[np].vx = parts[np].vx + 5*((((int)player2[1])&0x02) == 0x02) - 5*(((int)(player2[1])&0x01) == 0x01); + if ((np < NPART) && np>=0 && player2[2] == PT_PHOT) { int random = abs(rand()%3-1)*3; if (random==0) { - parts[r>>8].life = 0; - parts[r>>8].type = PT_NONE; + kill_part(np); } else { - parts[r>>8].vy = 0; - parts[r>>8].vx = (((((int)player2[1])&0x02) == 0x02) - (((int)(player2[1])&0x01) == 0x01))*random; + parts[np].vy = 0; + if (((int)player2[1])&(0x01|0x02)) + parts[np].vx = (((((int)player2[1])&0x02) == 0x02) - (((int)(player2[1])&0x01) == 0x01))*random; + else + parts[np].vx = random; } } diff --git a/src/graphics.c b/src/graphics.c index cea2ba7..917d267 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1341,6 +1341,8 @@ void xor_rect(pixel *vid, int x, int y, int w, int h) void draw_parts(pixel *vid) { int i, x, y, t, nx, ny, r, s; + int orbd[4] = {0, 0, 0, 0}; + int orbl[4] = {0, 0, 0, 0}; int cr, cg, cb; float fr, fg, fb; float pt = R_TEMP; @@ -1573,31 +1575,27 @@ void draw_parts(pixel *vid) } else if (parts[i].type==PT_GLOW) { - fg = 0; - fb = 0; - fr = 0; - if (pv[ny/CELL][nx/CELL]>0) { - fg = 6 * pv[ny/CELL][nx/CELL]; - fb = 4 * pv[ny/CELL][nx/CELL]; - fr = 2 * pv[ny/CELL][nx/CELL]; - } - vid[ny*(XRES+BARSIZE)+nx] = PIXRGB((int)restrict_flt(0x44 + fr*8, 0, 255), (int)restrict_flt(0x88 + fg*8, 0, 255), (int)restrict_flt(0x44 + fb*8, 0, 255)); + fr = restrict_flt(parts[i].temp-(275.13f+32.0f), 0, 128)/50.0f; + fg = restrict_flt(parts[i].ctype, 0, 128)/50.0f; + fb = restrict_flt(parts[i].tmp, 0, 128)/50.0f; + + cr = restrict_flt(64.0f+parts[i].temp-(275.13f+32.0f), 0, 255); + cg = restrict_flt(64.0f+parts[i].ctype, 0, 255); + cb = restrict_flt(64.0f+parts[i].tmp, 0, 255); - /*x = nx/CELL; + vid[ny*(XRES+BARSIZE)+nx] = PIXRGB(cr, cg, cb); + x = nx/CELL; y = ny/CELL; fg += fire_g[y][x]; - if(fg > 255) fg = 255; - fire_g[y][x] = fg; + if (fg > 255) fg = 255; + fire_g[y][x] = fg; fb += fire_b[y][x]; - if(fb > 255) fb = 255; - fire_b[y][x] = fb; + if (fb > 255) fb = 255; + fire_b[y][x] = fb; fr += fire_r[y][x]; - if(fr > 255) fr = 255; - fire_r[y][x] = fr;*/ + if (fr > 255) fr = 255; + fire_r[y][x] = fr; - cr = (int)restrict_flt(0x44 + fr*8, 0, 255); - cg = (int)restrict_flt(0x88 + fg*8, 0, 255); - cb = (int)restrict_flt(0x44 + fb*8, 0, 255); for (x=-1; x<=1; x++) { for (y=-1; y<=1; y++) @@ -1893,10 +1891,16 @@ void draw_parts(pixel *vid) } if (cr>255) cr=255; + if (cr<0) + cr=0; if (cg>255) cg=255; + if (cg<0) + cg=0; if (cb>255) cb=255; + if (cb<0) + cb=0; blendpixel(vid, nx, ny, cr, cg, cb, 255); } else if (t==PT_WIFI) @@ -1919,32 +1923,76 @@ void draw_parts(pixel *vid) } } } - else if (t==PT_PRTI && DEBUG_MODE) - { - blendpixel(vid,nx,ny, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors),255); - if (mousex==(nx) && mousey==(ny)) - { - int z; - for (z = 0; z<NPART; z++) { - if (parts[z].type) - { - if (parts[z].type==PT_PRTO&&parts[z].tmp==parts[i].tmp) - xor_line(nx,ny,(int)(parts[z].x+0.5f),(int)(parts[z].y+0.5f),vid); + else if (t==PT_PRTI) + { + int nxo = 0; + int nyo = 0; + int fire_rv = 0; + float drad = 0.0f; + float ddist = 0.0f; + orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); + for(r = 0; r < 4; r++){ + ddist = ((float)orbd[r])/16.0f; + drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f; + nxo = ddist*cos(drad); + nyo = ddist*sin(drad); + addpixel(vid, nx+nxo, ny+nyo, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors), 255-orbd[r]); + if(cmode == CM_FIRE){ + fire_rv = fire_r[(ny+nyo)/CELL][(nx+nxo)/CELL]; + fire_rv += (255-orbd[r])/32; + if(fire_rv>255) fire_rv = 255; + fire_r[(ny+nyo)/CELL][(nx+nxo)/CELL] = fire_rv; + } + addpixel(vid, nx, ny, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors), 200); + } + if(DEBUG_MODE){ + blendpixel(vid,nx,ny, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors),255); + if (mousex==(nx) && mousey==(ny)) + { + int z; + for (z = 0; z<NPART; z++) { + if (parts[z].type) + { + if (parts[z].type==PT_PRTO&&parts[z].tmp==parts[i].tmp) + xor_line(nx,ny,(int)(parts[z].x+0.5f),(int)(parts[z].y+0.5f),vid); + } } } } } - else if (t==PT_PRTO && DEBUG_MODE) - { - blendpixel(vid,nx,ny, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors),255); - if (mousex==(nx) && mousey==(ny)) - { - int z; - for (z = 0; z<NPART; z++) { - if (parts[z].type) - { - if (parts[z].type==PT_PRTI&&parts[z].tmp==parts[i].tmp) - xor_line(nx,ny,(int)(parts[z].x+0.5f),(int)(parts[z].y+0.5f),vid); + else if (t==PT_PRTO) + { + int nxo = 0; + int nyo = 0; + int fire_bv = 0; + float drad = 0.0f; + float ddist = 0.0f; + orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); + for(r = 0; r < 4; r++){ + ddist = ((float)orbd[r])/16.0f; + drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f; + nxo = ddist*cos(drad); + nyo = ddist*sin(drad); + addpixel(vid, nx+nxo, ny+nyo, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors), 255-orbd[r]); + if(cmode == CM_FIRE){ + fire_bv = fire_b[(ny+nyo)/CELL][(nx+nxo)/CELL]; + fire_bv += (255-orbd[r])/32; + if(fire_bv>255) fire_bv = 255; + fire_b[(ny+nyo)/CELL][(nx+nxo)/CELL] = fire_bv; + } + addpixel(vid, nx, ny, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors), 200); + } + if(DEBUG_MODE){ + blendpixel(vid,nx,ny, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors),255); + if (mousex==(nx) && mousey==(ny)) + { + int z; + for (z = 0; z<NPART; z++) { + if (parts[z].type) + { + if (parts[z].type==PT_PRTI&&parts[z].tmp==parts[i].tmp) + xor_line(nx,ny,(int)(parts[z].x+0.5f),(int)(parts[z].y+0.5f),vid); + } } } } @@ -2143,6 +2191,7 @@ void draw_parts(pixel *vid) else if (t==PT_BRAY && parts[i].tmp==0) { int trans = parts[i].life * 7; + if (trans>255) trans = 255; if (parts[i].ctype) { cg = 0; cb = 0; @@ -2167,6 +2216,7 @@ void draw_parts(pixel *vid) else if (t==PT_BRAY && parts[i].tmp==1) { int trans = parts[i].life/4; + if (trans>255) trans = 255; if (parts[i].ctype) { cg = 0; cb = 0; @@ -2191,6 +2241,7 @@ void draw_parts(pixel *vid) else if (t==PT_BRAY && parts[i].tmp==2) { int trans = parts[i].life*100; + if (trans>255) trans = 255; blendpixel(vid, nx, ny, 255, 150, 50, trans); } else if (t==PT_PHOT) @@ -2920,6 +2971,36 @@ void draw_parts(pixel *vid) } +void draw_wavelengths(pixel *vid, int x, int y, int h, int wl) +{ + int i,cr,cg,cb,j; + int tmp; + fillrect(vid,x-1,y-1,30+1,h+1,64,64,64,255); // coords -1 size +1 to work around bug in fillrect - TODO: fix fillrect + for (i=0;i<30;i++) + { + if ((wl>>i)&1) + { + // Need a spread of wavelengths to get a smooth spectrum, 5 bits seems to work reasonably well + if (i>2) tmp = 0x1F << (i-2); + else tmp = 0x1F >> (2-i); + cg = 0; + cb = 0; + cr = 0; + for (j=0; j<12; j++) { + cr += (tmp >> (j+18)) & 1; + cb += (tmp >> j) & 1; + } + for (j=0; j<14; j++) + cg += (tmp >> (j+9)) & 1; + tmp = 624/(cr+cg+cb+1); + cr *= tmp; + cg *= tmp; + cb *= tmp; + for (j=0;j<h;j++) blendpixel(vid,x+29-i,y+j,cr>255?255:cr,cg>255?255:cg,cb>255?255:cb,255); + } + } +} + void render_signs(pixel *vid_buf) { int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq; diff --git a/src/interface.c b/src/interface.c index b626138..8220c62 100644 --- a/src/interface.c +++ b/src/interface.c @@ -481,7 +481,7 @@ void draw_svf_ui(pixel *vid_buf) c = svf_login ? 255 : 128; drawtext(vid_buf, 40, YRES+(MENUSIZE-14), "\x82", c, c, c, 255); if (svf_open) - drawtext(vid_buf, 58, YRES+(MENUSIZE-12), svf_name, c, c, c, 255); + drawtextmax(vid_buf, 58, YRES+(MENUSIZE-12), 125, svf_name, c, c, c, 255); else drawtext(vid_buf, 58, YRES+(MENUSIZE-12), "[untitled simulation]", c, c, c, 255); drawrect(vid_buf, 37, YRES+(MENUSIZE-16), 150, 14, c, c, c, 255); @@ -507,7 +507,7 @@ void draw_svf_ui(pixel *vid_buf) drawtext(vid_buf, 222, YRES+(MENUSIZE-15), "\x83", c, c, c, 255); if (svf_tags[0]) - drawtextmax(vid_buf, 240, YRES+(MENUSIZE-12), 154, svf_tags, c, c, c, 255); + drawtextmax(vid_buf, 240, YRES+(MENUSIZE-12), XRES+BARSIZE-405, svf_tags, c, c, c, 255); else drawtext(vid_buf, 240, YRES+(MENUSIZE-12), "[no tags set]", c, c, c, 255); @@ -518,7 +518,7 @@ void draw_svf_ui(pixel *vid_buf) drawtext(vid_buf, XRES-122+BARSIZE/*388*/, YRES+(MENUSIZE-13), "\x84", 255, 255, 255, 255); if (svf_login) - drawtext(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), svf_user, 255, 255, 255, 255); + drawtextmax(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), 66, svf_user, 255, 255, 255, 255); else drawtext(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), "[sign in]", 255, 255, 255, 255); drawrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14, 255, 255, 255, 255); @@ -1205,8 +1205,9 @@ finish: int save_name_ui(pixel *vid_buf) { - int x0=(XRES-420)/2,y0=(YRES-68-YRES/4)/2,b=1,bq,mx,my,ths,nd=0; + int x0=(XRES-420)/2,y0=(YRES-68-YRES/4)/2,b=1,bq,mx,my,ths,idtxtwidth,nd=0; void *th; + char *save_id_text; ui_edit ed; ui_edit ed2; ui_checkbox cb; @@ -1242,6 +1243,10 @@ int save_name_ui(pixel *vid_buf) ed2.cursor = strlen(svf_description); ed2.multiline = 1; strcpy(ed2.str, svf_description); + + save_id_text = malloc(strlen("Current save id: ")+strlen(svf_id)+1); + sprintf(save_id_text,"Current save id: %s",svf_id); + idtxtwidth = textwidth(save_id_text); cb.x = x0+10; cb.y = y0+53+YRES/4; @@ -1277,6 +1282,12 @@ int save_name_ui(pixel *vid_buf) drawrect(vid_buf, x0, y0+74+YRES/4, 192, 16, 192, 192, 192, 255); draw_line(vid_buf, x0+192, y0, x0+192, y0+90+YRES/4, 150, 150, 150, XRES+BARSIZE); + + if (svf_id[0]) + { + fillrect(vid_buf, (XRES+BARSIZE-idtxtwidth)/2-5, YRES+(MENUSIZE-16), idtxtwidth+10, 14, 0, 0, 0, 255); + drawtext(vid_buf, (XRES+BARSIZE-idtxtwidth)/2, YRES+MENUSIZE-12, save_id_text, 255, 255, 255, 255); + } sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE)); @@ -1334,6 +1345,7 @@ int save_name_ui(pixel *vid_buf) } } free(th); + if (save_id_text) free(save_id_text); return 0; } @@ -2734,7 +2746,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) int nyd,nyu,ry,lv; float ryf; - char *uri, *uri_2, *o_uri; + char *uri, *uri_2, *o_uri, *save_id_text; void *data, *info_data; save_info *info = malloc(sizeof(save_info)); void *http = NULL, *http_2 = NULL; @@ -2752,6 +2764,9 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) drawrect(vid_buf, 50, 50, (XRES/2)+1, (YRES/2)+1, 255, 255, 255, 155); drawrect(vid_buf, 50+(XRES/2)+1, 50, XRES+BARSIZE-100-((XRES/2)+1), YRES+MENUSIZE-100, 155, 155, 155, 255); drawtext(vid_buf, 50+(XRES/4)-textwidth("Loading...")/2, 50+(YRES/4), "Loading...", 255, 255, 255, 128); + + save_id_text = malloc(strlen("Save id: ")+strlen(save_id)+1); + sprintf(save_id_text,"Save id: %s",save_id); ed.x = 57+(XRES/2)+1; ed.y = YRES+MENUSIZE-118; @@ -2827,11 +2842,12 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) data = http_async_req_stop(http, &status, &data_size); if (status == 200) { + pixel *full_save; if (!data||!data_size) { error_ui(vid_buf, 0, "Save data is empty (may be corrupt)"); break; } - pixel *full_save = prerender_save(data, data_size, &imgw, &imgh); + full_save = prerender_save(data, data_size, &imgw, &imgh); if (full_save!=NULL) { save_pic = rescale_img(full_save, imgw, imgh, &thumb_w, &thumb_h, 2); data_ready = 1; @@ -2941,6 +2957,10 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) drawrect(vid_buf, XRES+BARSIZE-100, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 255); drawtext(vid_buf, XRES+BARSIZE-90, YRES+MENUSIZE-63, "Submit", 255, 255, 255, 255); } + + cix = textwidth(save_id_text); + fillrect(vid_buf, (XRES+BARSIZE-cix)/2-5, YRES+(MENUSIZE-16), cix+10, 14, 0, 0, 0, 255); + drawtext(vid_buf, (XRES+BARSIZE-cix)/2, YRES+MENUSIZE-12, save_id_text, 255, 255, 255, 255); //Open Button bc = openable?255:150; @@ -3058,7 +3078,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) if (queue_open) { if (info_ready && data_ready) { // Do Open! - status = parse_save(data, data_size, 1, 0, 0); + status = parse_save(data, data_size, 1, 0, 0, bmap, fvx, fvy, signs, parts, pmap); if (!status) { //if(svf_last) //free(svf_last); @@ -3127,6 +3147,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) if (!b) break; } + if (save_id_text) free(save_id_text); //Close open connections if (http) http_async_req_close(http); @@ -3572,21 +3593,21 @@ void execute_save(pixel *vid_buf) char *result; char *names[] = {"Name","Description", "Data:save.bin", "Thumb:thumb.bin", "Publish", "ID", NULL}; - char *parts[6]; + char *uploadparts[6]; int plens[6]; - parts[0] = svf_name; + uploadparts[0] = svf_name; plens[0] = strlen(svf_name); - parts[1] = svf_description; + uploadparts[1] = svf_description; plens[1] = strlen(svf_description); - parts[2] = build_save(plens+2, 0, 0, XRES, YRES); - parts[3] = build_thumb(plens+3, 1); - parts[4] = (svf_publish==1)?"Public":"Private"; + uploadparts[2] = build_save(plens+2, 0, 0, XRES, YRES, bmap, fvx, fvy, signs, parts); + uploadparts[3] = build_thumb(plens+3, 1); + uploadparts[4] = (svf_publish==1)?"Public":"Private"; plens[4] = strlen((svf_publish==1)?"Public":"Private"); if (svf_id[0]) { - parts[5] = svf_id; + uploadparts[5] = svf_id; plens[5] = strlen(svf_id); } else @@ -3594,16 +3615,16 @@ void execute_save(pixel *vid_buf) result = http_multipart_post( "http://" SERVER "/Save.api", - names, parts, plens, + names, uploadparts, plens, svf_user_id, /*svf_pass*/NULL, svf_session_id, &status, NULL); if (svf_last) free(svf_last); - svf_last = parts[2]; + svf_last = uploadparts[2]; svf_lsize = plens[2]; - free(parts[3]); + free(uploadparts[3]); if (status!=200) { @@ -3820,21 +3841,16 @@ void open_link(char *uri) { #ifdef WIN32 ShellExecute(0, "OPEN", uri, NULL, NULL, 0); #elif MACOSX - //char *cmd[] = { "open", uri, (char *)0 }; - //execvp("open", cmd); - //LSOpenCFURLRef(CFURLCreateWithString(NULL, CFStringCreateWithCString(NULL, uri, 0) ,NULL), NULL); //TODO: Get this crap working char *cmd = malloc(7+strlen(uri)); strcpy(cmd, "open "); strappend(cmd, uri); system(cmd); #elif LIN32 - //execlp("xdg-open", "xdg-open", uri, (char *)0); char *cmd = malloc(11+strlen(uri)); strcpy(cmd, "xdg-open "); strappend(cmd, uri); system(cmd); #elif LIN64 - //execlp("xdg-open", "xdg-open", uri, (char *)0); char *cmd = malloc(11+strlen(uri)); strcpy(cmd, "xdg-open "); strappend(cmd, uri); @@ -3868,7 +3884,8 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { ed.cursor = 0; //fillrect(vid_buf, -1, -1, XRES, 220, 0, 0, 0, 190); memcpy(old_buf,vid_buf,(XRES+BARSIZE)*YRES*PIXELSIZE); - fillrect(old_buf, -1, -1, XRES+1, 220, 0, 0, 0, 190); + + fillrect(old_buf, -1, -1, XRES, 220, 0, 0, 0, 190); currentcommand2 = malloc(sizeof(command_history)); memset(currentcommand2, 0, sizeof(command_history)); @@ -3876,7 +3893,7 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { currentcommand2->command = mystrdup(error); last_command2 = currentcommand2; - //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); cc = 0; while(cc < 80){ fillrect(old_buf, -1, -1+cc, XRES+BARSIZE, 2, 0, 0, 0, 160-(cc*2)); @@ -3889,7 +3906,6 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { my /= sdl_scale; ed.focus = 1; - //clearrect(vid_buf, 0, 0, XRES+BARSIZE, 220);//anyway to make it transparent? memcpy(vid_buf,old_buf,(XRES+BARSIZE)*YRES*PIXELSIZE); draw_line(vid_buf, 0, 219, XRES+BARSIZE-1, 219, 228, 228, 228, XRES+BARSIZE); if(pygood) @@ -3964,14 +3980,14 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { currentcommand->command = mystrdup(ed.str); last_command = currentcommand; free(old_buf); - //SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); + SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); return currentcommand->command; } if (sdl_key==SDLK_ESCAPE || sdl_key==SDLK_BACKQUOTE) { console_mode = 0; free(old_buf); - //SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); + SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); return NULL; } if(sdl_key==SDLK_UP || sdl_key==SDLK_DOWN) @@ -4008,7 +4024,7 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { } console_mode = 0; free(old_buf); - //SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); + SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); return NULL; } @@ -152,7 +152,7 @@ static const char *it_msg = "'P' will take a screenshot and save it into the current directory.\n" "\n" "\bgCopyright (c) 2008-11 Stanislaw K Skowronek (\brhttp://powder.unaligned.org\bg, \bbirc.unaligned.org #wtf\bg)\n" - "\bgCopyright (c) 2010-11 Simon Robertshaw, Skresanov Savely, cracker64, Bryan Hoyle, Nathan Cousins, jacksonmj\n" + "\bgCopyright (c) 2010-11 Simon Robertshaw, Skresanov Savely, cracker64, Bryan Hoyle, Nathan Cousins, jacksonmj, Lieuwe Mosch\n" "\n" "\bgTo use online features such as saving, you need to register at: \brhttp://powdertoy.co.uk/Register.html" ; @@ -224,7 +224,7 @@ void sdl_seticon(void) //SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(app_icon_w32, 32, 32, 32, 128, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); //SDL_WM_SetIcon(icon, NULL/*app_icon_mask*/); #else - SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(app_icon, 16, 16, 32, 128, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); + SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(app_icon, 16, 16, 32, 64, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); SDL_WM_SetIcon(icon, NULL/*app_icon_mask*/); #endif #endif @@ -310,11 +310,12 @@ void *build_thumb(int *size, int bzip2) return d; } -void *build_save(int *size, int x0, int y0, int w, int h) +void *build_save(int *size, int x0, int y0, int w, int h, unsigned char bmap[YRES/CELL][XRES/CELL], float fvx[YRES/CELL][XRES/CELL], float fvy[YRES/CELL][XRES/CELL], sign signs[MAXSIGNS], void* partsptr) { unsigned char *d=calloc(1,3*(XRES/CELL)*(YRES/CELL)+(XRES*YRES)*11+MAXSIGNS*262), *c; int i,j,x,y,p=0,*m=calloc(XRES*YRES, sizeof(int)); int bx0=x0/CELL, by0=y0/CELL, bw=(w+CELL-1)/CELL, bh=(h+CELL-1)/CELL; + particle *parts = partsptr; // normalize coordinates x0 = bx0*CELL; @@ -353,7 +354,8 @@ void *build_save(int *size, int x0, int y0, int w, int h) y = (int)(parts[i].y+0.5f); if (x>=x0 && x<x0+w && y>=y0 && y<y0+h) { if (!m[(x-x0)+(y-y0)*w] || - parts[m[(x-x0)+(y-y0)*w]-1].type == PT_PHOT) + parts[m[(x-x0)+(y-y0)*w]-1].type == PT_PHOT || + parts[m[(x-x0)+(y-y0)*w]-1].type == PT_NEUT) m[(x-x0)+(y-y0)*w] = i+1; } } @@ -479,12 +481,13 @@ void *build_save(int *size, int x0, int y0, int w, int h) return c; } -int parse_save(void *save, int size, int replace, int x0, int y0) +int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char bmap[YRES/CELL][XRES/CELL], float fvx[YRES/CELL][XRES/CELL], float fvy[YRES/CELL][XRES/CELL], sign signs[MAXSIGNS], void* partsptr, unsigned pmap[YRES][XRES]) { unsigned char *d,*c=save; int q,i,j,k,x,y,p=0,*m=calloc(XRES*YRES, sizeof(int)), ver, pty, ty, legacy_beta=0; int bx0=x0/CELL, by0=y0/CELL, bw, bh, w, h; int fp[NPART], nf=0, new_format = 0, ttv = 0; + particle *parts = partsptr; //New file header uses PSv, replacing fuC. This is to detect if the client uses a new save format for temperatures //This creates a problem for old clients, that display and "corrupt" error instead of a "newer version" error @@ -564,19 +567,7 @@ int parse_save(void *save, int size, int replace, int x0, int y0) gravityMode = 0; airMode = 0; } - memset(bmap, 0, sizeof(bmap)); - memset(emap, 0, sizeof(emap)); - memset(signs, 0, sizeof(signs)); - memset(parts, 0, sizeof(particle)*NPART); - memset(pmap, 0, sizeof(pmap)); - memset(vx, 0, sizeof(vx)); - memset(vy, 0, sizeof(vy)); - memset(pv, 0, sizeof(pv)); - memset(photons, 0, sizeof(photons)); - memset(wireless, 0, sizeof(wireless)); - memset(gol2, 0, sizeof(gol2)); - memset(portal, 0, sizeof(portal)); - death = death2 = ISSPAWN1 = ISSPAWN2 = 0; + clear_sim(); } // make a catalog of free parts @@ -908,13 +899,35 @@ corrupt: if (replace) { legacy_enable = 0; - memset(signs, 0, sizeof(signs)); - memset(parts, 0, sizeof(particle)*NPART); - memset(bmap, 0, sizeof(bmap)); + clear_sim(); } return 1; } +void clear_sim(void) +{ + memset(bmap, 0, sizeof(bmap)); + memset(emap, 0, sizeof(emap)); + memset(signs, 0, sizeof(signs)); + memset(parts, 0, sizeof(particle)*NPART); + memset(pmap, 0, sizeof(pmap)); + memset(pv, 0, sizeof(pv)); + memset(vx, 0, sizeof(vx)); + memset(vy, 0, sizeof(vy)); + memset(fvx, 0, sizeof(fvx)); + memset(fvy, 0, sizeof(fvy)); + memset(photons, 0, sizeof(photons)); + memset(wireless, 0, sizeof(wireless)); + memset(gol2, 0, sizeof(gol2)); + memset(portal, 0, sizeof(portal)); + death = death2 = ISSPAWN1 = ISSPAWN2 = 0; + memset(pers_bg, 0, (XRES+BARSIZE)*YRES*PIXELSIZE); + memset(fire_bg, 0, XRES*YRES*PIXELSIZE); + memset(fire_r, 0, sizeof(fire_r)); + memset(fire_g, 0, sizeof(fire_g)); + memset(fire_b, 0, sizeof(fire_b)); +} + // stamps library stamp stamps[STAMP_MAX];//[STAMP_X*STAMP_Y]; @@ -999,7 +1012,7 @@ void stamp_save(int x, int y, int w, int h) FILE *f; int n; char fn[64], sn[16]; - void *s=build_save(&n, x, y, w, h); + void *s=build_save(&n, x, y, w, h, bmap, fvx, fvy, signs, parts); #ifdef WIN32 _mkdir("stamps"); @@ -1203,8 +1216,7 @@ char console_error[255] = ""; //functions callable from python: -static PyObject* -emb_create(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_create(PyObject *self, PyObject *args, PyObject *keywds) { int x,y,t; char *name = ""; @@ -1216,9 +1228,8 @@ emb_create(PyObject *self, PyObject *args, PyObject *keywds) console_parse_type(name, &t, console_error); return Py_BuildValue("i",create_part(-1,x,y,t)); } -//sys_pause = !sys_pause -static PyObject* -emb_pause(PyObject *self, PyObject *args) + +static PyObject* emb_pause(PyObject *self, PyObject *args) { int x,y,t; if(!PyArg_ParseTuple(args, ":unpause")) @@ -1228,8 +1239,7 @@ emb_pause(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_unpause(PyObject *self, PyObject *args) +static PyObject* emb_unpause(PyObject *self, PyObject *args) { int x,y,t; if(!PyArg_ParseTuple(args, ":pause")) @@ -1239,8 +1249,7 @@ emb_unpause(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_toggle_pause(PyObject *self, PyObject *args) +static PyObject* emb_toggle_pause(PyObject *self, PyObject *args) { int x,y,t; if(!PyArg_ParseTuple(args, ":toggle_pause")) @@ -1251,9 +1260,7 @@ emb_toggle_pause(PyObject *self, PyObject *args) } //console_mode - -static PyObject* -emb_toggle_console(PyObject *self, PyObject *args) +static PyObject* emb_toggle_console(PyObject *self, PyObject *args) { int x,y,t; if(!PyArg_ParseTuple(args, ":toggle_console")) @@ -1263,8 +1270,7 @@ emb_toggle_console(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_open_console(PyObject *self, PyObject *args) +static PyObject* emb_open_console(PyObject *self, PyObject *args) { int x,y,t; if(!PyArg_ParseTuple(args, ":toggle_console")) @@ -1274,8 +1280,7 @@ emb_open_console(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_close_console(PyObject *self, PyObject *args) +static PyObject* emb_close_console(PyObject *self, PyObject *args) { int x,y,t; if(!PyArg_ParseTuple(args, ":toggle_console")) @@ -1285,8 +1290,7 @@ emb_close_console(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_log(PyObject *self, PyObject *args) +static PyObject* emb_log(PyObject *self, PyObject *args) { char *buffer; if(!PyArg_ParseTuple(args, "s:log",&buffer)) @@ -1299,8 +1303,7 @@ emb_log(PyObject *self, PyObject *args) char console_more=0; -static PyObject* -emb_console_more(PyObject *self, PyObject *args) +static PyObject* emb_console_more(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":log")) return NULL; @@ -1309,8 +1312,7 @@ emb_console_more(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_console_less(PyObject *self, PyObject *args) +static PyObject* emb_console_less(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":log")) return NULL; @@ -1319,10 +1321,7 @@ emb_console_less(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -//drawtext(vid_buf, 15, 175-(cc*12), currentcommand->command, 255, 255, 255, 255); - -static PyObject* -emb_reset_pressure(PyObject *self, PyObject *args) +static PyObject* emb_reset_pressure(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":reset_pressure")) return NULL; @@ -1335,8 +1334,7 @@ emb_reset_pressure(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_reset_velocity(PyObject *self, PyObject *args) +static PyObject* emb_reset_velocity(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":reset_velocity")) return NULL; @@ -1350,8 +1348,7 @@ emb_reset_velocity(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_reset_sparks(PyObject *self, PyObject *args) +static PyObject* emb_reset_sparks(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":reset_sparks")) return NULL; @@ -1367,8 +1364,7 @@ emb_reset_sparks(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_set_life(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_life(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1408,8 +1404,7 @@ emb_set_life(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_type(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_type(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j=-1,x=-1,y=-1; char *name = ""; @@ -1451,8 +1446,7 @@ emb_set_type(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_temp(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_temp(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1492,8 +1486,7 @@ emb_set_temp(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_tmp(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_tmp(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1533,8 +1526,7 @@ emb_set_tmp(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_x(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_x(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1575,8 +1567,7 @@ emb_set_x(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_y(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_y(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1616,8 +1607,7 @@ emb_set_y(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_ctype(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_ctype(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1660,8 +1650,7 @@ emb_set_ctype(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_vx(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_vx(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1701,8 +1690,7 @@ emb_set_vx(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_set_vy(PyObject *self, PyObject *args, PyObject *keywds) +static PyObject* emb_set_vy(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; @@ -1742,8 +1730,7 @@ emb_set_vy(PyObject *self, PyObject *args, PyObject *keywds) return Py_BuildValue("i",1); } -static PyObject* -emb_get_pmap(PyObject *self, PyObject *args) +static PyObject* emb_get_pmap(PyObject *self, PyObject *args) { int x,y; if(!PyArg_ParseTuple(args, "II:get_pmap",&x,&y)) @@ -1755,8 +1742,7 @@ emb_get_pmap(PyObject *self, PyObject *args) return Py_BuildValue("I",pmap[y][x]); } -static PyObject* -emb_get_prop(PyObject *self, PyObject *args) +static PyObject* emb_get_prop(PyObject *self, PyObject *args) { int i; char *prop = ""; @@ -1788,8 +1774,7 @@ emb_get_prop(PyObject *self, PyObject *args) return Py_BuildValue("i",-1); } -static PyObject* -emb_draw_pixel(PyObject *self, PyObject *args) +static PyObject* emb_draw_pixel(PyObject *self, PyObject *args) { int x,y,r,g,b,a; a=255; @@ -1805,9 +1790,7 @@ emb_draw_pixel(PyObject *self, PyObject *args) } -//drawtext(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a) -static PyObject* -emb_draw_text(PyObject *self, PyObject *args) +static PyObject* emb_draw_text(PyObject *self, PyObject *args) { int x,y,r,g,b,a; char *txt; @@ -1822,9 +1805,7 @@ emb_draw_text(PyObject *self, PyObject *args) return Py_BuildValue("i",-1); } -//drawrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a) -static PyObject* -emb_draw_rect(PyObject *self, PyObject *args) +static PyObject* emb_draw_rect(PyObject *self, PyObject *args) { int x,y,w,h,r,g,b,a; a=255; @@ -1839,8 +1820,7 @@ emb_draw_rect(PyObject *self, PyObject *args) return Py_BuildValue("i",-1); } -static PyObject* -emb_draw_fillrect(PyObject *self, PyObject *args) +static PyObject* emb_draw_fillrect(PyObject *self, PyObject *args) { int x,y,w,h,r,g,b,a; a=255; @@ -1855,9 +1835,7 @@ emb_draw_fillrect(PyObject *self, PyObject *args) return Py_BuildValue("i",-1); } -//int textwidth(char *s) -static PyObject* -emb_get_width(PyObject *self, PyObject *args) +static PyObject* emb_get_width(PyObject *self, PyObject *args) { char *txt; if(!PyArg_ParseTuple(args, "s:get_width",&txt)) @@ -1865,9 +1843,7 @@ emb_get_width(PyObject *self, PyObject *args) return Py_BuildValue("i",textwidth(txt)); } -//SDL_GetMouseState(&x, &y) -static PyObject* -emb_get_mouse(PyObject *self, PyObject *args) +static PyObject* emb_get_mouse(PyObject *self, PyObject *args) { int x,y,mask,b1,b2,b3; if(!PyArg_ParseTuple(args, ":get_mouse")) @@ -1879,9 +1855,7 @@ emb_get_mouse(PyObject *self, PyObject *args) return Py_BuildValue("(ii(iii))",x,y,b1,b2,b3); } -//svf_name -static PyObject* -emb_get_name(PyObject *self, PyObject *args) +static PyObject* emb_get_name(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":get_name")) return NULL; @@ -1891,8 +1865,7 @@ emb_get_name(PyObject *self, PyObject *args) return Py_BuildValue("s",""); } -static PyObject* -emb_shortcuts_disable(PyObject *self, PyObject *args) +static PyObject* emb_shortcuts_disable(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":shortcuts_disable")) return NULL; @@ -1901,8 +1874,7 @@ emb_shortcuts_disable(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_shortcuts_enable(PyObject *self, PyObject *args) +static PyObject* emb_shortcuts_enable(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":shortcuts_enable")) return NULL; @@ -1911,17 +1883,14 @@ emb_shortcuts_enable(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_get_modifier(PyObject *self, PyObject *args) +static PyObject* emb_get_modifier(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":get_modifier")) return NULL; return Py_BuildValue("(iiiiii)",sdl_mod&KMOD_LCTRL,sdl_mod&KMOD_RCTRL,sdl_mod&KMOD_LALT,sdl_mod&KMOD_RALT,sdl_mod&KMOD_LSHIFT,sdl_mod&KMOD_RSHIFT); } -//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); -static PyObject* -emb_set_keyrepeat(PyObject *self, PyObject *args) +static PyObject* emb_set_keyrepeat(PyObject *self, PyObject *args) { ////SDL_EnableKeyRepeat(delay,interval) int keydelay,keyinterval; @@ -1933,8 +1902,7 @@ emb_set_keyrepeat(PyObject *self, PyObject *args) } //delete_part -static PyObject* -emb_delete(PyObject *self, PyObject *args) +static PyObject* emb_delete(PyObject *self, PyObject *args) { ////SDL_EnableKeyRepeat(delay,interval) int x,y; @@ -1944,8 +1912,7 @@ emb_delete(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_set_pressure(PyObject *self, PyObject *args) +static PyObject* emb_set_pressure(PyObject *self, PyObject *args) { ////SDL_EnableKeyRepeat(delay,interval) int x,y,press; @@ -1955,8 +1922,7 @@ emb_set_pressure(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_set_velocity(PyObject *self, PyObject *args) +static PyObject* emb_set_velocity(PyObject *self, PyObject *args) { ////SDL_EnableKeyRepeat(delay,interval) int x,y,xv,yv; @@ -1967,8 +1933,7 @@ emb_set_velocity(PyObject *self, PyObject *args) return Py_BuildValue("i",1); } -static PyObject* -emb_disable_python(PyObject *self, PyObject *args) +static PyObject* emb_disable_python(PyObject *self, PyObject *args) { if(!PyArg_ParseTuple(args, ":disable_python")) return NULL; @@ -2087,7 +2052,7 @@ int main(int argc, char *argv[]) int is_beta = 0; #endif char uitext[512] = ""; - char heattext[128] = ""; + char heattext[256] = ""; char coordtext[128] = ""; int currentTime = 0; int FPS = 0; @@ -2102,8 +2067,9 @@ int main(int argc, char *argv[]) #ifdef INTERNAL int vs = 0; #endif - int x, y, b = 0, su=0, c, lb = 0, lx = 0, ly = 0, lm = 0;//, tx, ty; - int da = 0, db = 0, it = 2047, mx, my; + int wavelength_gfx = 0; + int x, y, b = 0, sl=1, sr=0, su=0, c, lb = 0, lx = 0, ly = 0, lm = 0;//, tx, ty; + int da = 0, db = 0, it = 2047, mx, my, bsx = 2, bsy = 2; float nfvx, nfvy; int load_mode=0, load_w=0, load_h=0, load_x=0, load_y=0, load_size=0; void *load_data=NULL; @@ -2111,6 +2077,7 @@ int main(int argc, char *argv[]) int save_mode=0, save_x=0, save_y=0, save_w=0, save_h=0, copy_mode=0; SDL_AudioSpec fmt; int username_flash = 0, username_flash_t = 1; + pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE); GSPEED = 1; #ifdef PYCONSOLE PyObject *pname,*pmodule,*pfunc,*pvalue,*pargs,*pstep,*pkey; @@ -2124,33 +2091,25 @@ int main(int argc, char *argv[]) fmt.callback = mixaudio; fmt.userdata = NULL; - #ifdef PYCONSOLE - //dump tpt_console_stdlib to file here - /*#include "pystdlib.h" - FILE* fid; - fid=fopen("stdlib.zip","w"); - //fputs(tpt_console_stdlib,fid); - fwrite(&tpt_console_stdlib,1,tpt_console_stdlibsize,fid); - fclose(fid);*/ - //crashes gcc - +#ifdef PYCONSOLE //initialise python console Py_Initialize(); PyRun_SimpleString("print 'python present.'"); Py_InitModule("tpt", EmbMethods); + //change the path to find all the correct modules PyRun_SimpleString("import sys\nsys.path.append('./tptPython.zip')\nsys.path.append('.')"); //load the console module and whatnot - #ifdef PYEXT +#ifdef PYEXT PyRun_SimpleString(tpt_console_py); printf("using external python console file.\n"); pname=PyString_FromString("tpt_console");//create string object pmodule = PyImport_Import(pname);//import module Py_DECREF(pname);//throw away string - #else +#else PyObject *tpt_console_obj = PyMarshal_ReadObjectFromString(tpt_console_pyc+8, sizeof(tpt_console_pyc)-8); pmodule=PyImport_ExecCodeModule("tpt_console", tpt_console_obj); - #endif +#endif if(pmodule!=NULL) { pfunc=PyObject_GetAttrString(pmodule,"handle");//get the handler function @@ -2162,9 +2121,8 @@ int main(int argc, char *argv[]) { PyErr_Print(); printf("unable to find handle function, mangled console.py?\n"); - //return -1; - pyready=0; - pygood=0; + pyready = 0; + pygood = 0; } pstep=PyObject_GetAttrString(pmodule,"step");//get the handler function @@ -2192,9 +2150,8 @@ int main(int argc, char *argv[]) //sys.stderr PyErr_Print(); printf("unable to find console module, missing file or mangled console.py?\n"); - //return -1; - pyready=0; - pygood=0; + pyready = 0; + pygood = 0; } #else printf("python console disabled at compile time."); @@ -2224,8 +2181,7 @@ int main(int argc, char *argv[]) parts[NPART-1].life = -1; pfree = 0; fire_bg=calloc(XRES*YRES, PIXELSIZE); - pers_bg=calloc((XRES+BARSIZE)*YRES, PIXELSIZE); - memset(signs, 0, sizeof(signs)); + clear_sim(); //fbi_img = render_packed_rgb(fbi, FBI_W, FBI_H, FBI_CMP); @@ -2269,6 +2225,19 @@ int main(int argc, char *argv[]) { file_script = 1; } + else if (!strncmp(argv[i], "open:", 5)) + { + int size; + void *file_data; + char fn[64]; + strncpy(fn, argv[i]+5, strlen(argv[i]+5)); + file_data = file_load(fn, &size); + if(file_data) + { + it=0; + parse_save(file_data, size, 0, 0, 0, bmap, fvx, fvy, signs, parts, pmap); + } + } } @@ -2833,8 +2802,6 @@ int main(int argc, char *argv[]) pargs=NULL; if(pvalue==NULL) strcpy(console_error,"failed to execute key code."); - //Py_DECREF(pvalue); - //puts("a"); pvalue=NULL; } #endif @@ -2950,8 +2917,13 @@ int main(int argc, char *argv[]) if (DEBUG_MODE) { int tctype = parts[cr>>8].ctype; - if (tctype>=PT_NUM) + if (tctype>=PT_NUM || tctype<0 || (cr&0xFF)==PT_PHOT) tctype = 0; + if ((cr&0xFF)==PT_PIPE) + { + if (parts[cr>>8].tmp<PT_NUM) tctype = parts[cr>>8].tmp; + else tctype = 0; + } sprintf(heattext, "%s (%s), Pressure: %3.2f, Temp: %4.2f C, Life: %d", ptypes[cr&0xFF].name, ptypes[tctype].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life); sprintf(coordtext, "#%d, X:%d Y:%d", cr>>8, x/sdl_scale, y/sdl_scale); } else { @@ -2961,6 +2933,7 @@ int main(int argc, char *argv[]) sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C", ptypes[cr&0xFF].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f); #endif } + if ((cr&0xFF)==PT_PHOT) wavelength_gfx = parts[cr>>8].ctype; } else { @@ -3134,7 +3107,7 @@ int main(int argc, char *argv[]) if (load_y<0) load_y=0; if (bq==1 && !b) { - parse_save(load_data, load_size, 0, load_x, load_y); + parse_save(load_data, load_size, 0, load_x, load_y, bmap, fvx, fvy, signs, parts, pmap); free(load_data); free(load_img); load_mode = 0; @@ -3176,35 +3149,19 @@ int main(int argc, char *argv[]) { if (copy_mode==1) { - clipboard_data=build_save(&clipboard_length, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); + clipboard_data=build_save(&clipboard_length, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL, bmap, fvx, fvy, signs, parts); clipboard_ready = 1; save_mode = 0; copy_mode = 0; } else if (copy_mode==2) { - clipboard_data=build_save(&clipboard_length, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); + clipboard_data=build_save(&clipboard_length, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL, bmap, fvx, fvy, signs, parts); clipboard_ready = 1; save_mode = 0; copy_mode = 0; clear_area(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); } - else if (copy_mode==3)//rotation - { - if (save_h>save_w) - save_w = save_h; - rotate_area(save_x*CELL, save_y*CELL, save_w*CELL, save_w*CELL,0);//just do squares for now - save_mode = 0; - copy_mode = 0; - } - else if (copy_mode==4)//invertion - { - if (save_h>save_w) - save_w = save_h; - rotate_area(save_x*CELL, save_y*CELL, save_w*CELL, save_w*CELL,1);//just do squares for now - save_mode = 0; - copy_mode = 0; - } else { stamp_save(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); @@ -3262,19 +3219,7 @@ int main(int argc, char *argv[]) } if (x>=(XRES+BARSIZE-(510-367)) && x<=(XRES+BARSIZE-(510-383)) && !bq) { - memset(signs, 0, sizeof(signs)); - memset(pv, 0, sizeof(pv)); - memset(vx, 0, sizeof(vx)); - memset(vy, 0, sizeof(vy)); - memset(fvx, 0, sizeof(fvx)); - memset(fvy, 0, sizeof(fvy)); - memset(bmap, 0, sizeof(bmap)); - memset(emap, 0, sizeof(emap)); - memset(parts, 0, sizeof(particle)*NPART); - memset(photons, 0, sizeof(photons)); - memset(wireless, 0, sizeof(wireless)); - memset(gol2, 0, sizeof(gol2)); - memset(portal, 0, sizeof(portal)); + clear_sim(); for (i=0; i<NPART-1; i++) parts[i].life = i+1; parts[NPART-1].life = -1; @@ -3291,6 +3236,7 @@ int main(int argc, char *argv[]) svf_description[0] = 0; gravityMode = 0; airMode = 0; + death = death2 = 0; isplayer2 = 0; isplayer = 0; @@ -3315,8 +3261,14 @@ int main(int argc, char *argv[]) { if (!svf_open || !svf_own || x>51) { - if (save_name_ui(vid_buf)) + if (save_name_ui(vid_buf)){ execute_save(vid_buf); + if(svf_id[0]){ + char tmpstring[256] = ""; + sprintf(tmpstring, "Save uploaded with the ID %s", svf_id); + info_ui(vid_buf, "Uploaded new save", tmpstring); + } + } } else execute_save(vid_buf); @@ -3336,7 +3288,7 @@ int main(int argc, char *argv[]) } if (x>=19 && x<=35 && svf_last && svf_open && !bq) { //int tpval = sys_pause; - parse_save(svf_last, svf_lsize, 1, 0, 0); + parse_save(svf_last, svf_lsize, 1, 0, 0, bmap, fvx, fvy, signs, parts, pmap); //sys_pause = tpval; } if (x>=(XRES+BARSIZE-(510-476)) && x<=(XRES+BARSIZE-(510-491)) && !bq) @@ -3426,14 +3378,16 @@ int main(int argc, char *argv[]) { for (j=-bsy; j<=bsy; j++) for (i=-bsx; i<=bsx; i++) - if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(bsx,2))+(pow(j,2))/(pow(bsy,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=bsy*bsx)) + if (x+i>0 && y+j>0 && x+i<XRES && y+j<YRES && ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(bsx,2))+(pow(j,2))/(pow(bsy,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=bsy*bsx))) { vx[(y+j)/CELL][(x+i)/CELL] += (x-lx)*0.01f; vy[(y+j)/CELL][(x+i)/CELL] += (y-ly)*0.01f; } } else + { create_line(lx, ly, x, y, bsx, bsy, c); + } lx = x; ly = y; } @@ -3545,14 +3499,7 @@ int main(int argc, char *argv[]) if (save_mode) { - if (copy_mode==3||copy_mode==4)//special drawing for rotate, can remove once it can do rectangles - { - if (save_h>save_w) - save_w = save_h; - xor_rect(vid_buf, save_x*CELL, save_y*CELL, save_w*CELL, save_w*CELL); - } - else - xor_rect(vid_buf, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); + xor_rect(vid_buf, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); da = 51; db = 269; } @@ -3707,6 +3654,8 @@ int main(int argc, char *argv[]) fillrect(vid_buf, XRES-20-textwidth(coordtext), 280, textwidth(coordtext)+8, 13, 0, 0, 0, 140); drawtext(vid_buf, XRES-16-textwidth(coordtext), 282, coordtext, 255, 255, 255, 200); } + if (wavelength_gfx) + draw_wavelengths(vid_buf,XRES-20-textwidth(heattext),265,2,wavelength_gfx); } else { @@ -3717,6 +3666,8 @@ int main(int argc, char *argv[]) fillrect(vid_buf, 12, 280, textwidth(coordtext)+8, 13, 0, 0, 0, 140); drawtext(vid_buf, 16, 282, coordtext, 255, 255, 255, 200); } + if (wavelength_gfx) + draw_wavelengths(vid_buf,12,265,2,wavelength_gfx); } } else @@ -3728,7 +3679,10 @@ int main(int argc, char *argv[]) fillrect(vid_buf, XRES-20-textwidth(coordtext), 26, textwidth(coordtext)+8, 11, 0, 0, 0, 140); drawtext(vid_buf, XRES-16-textwidth(coordtext), 27, coordtext, 255, 255, 255, 200); } + if (wavelength_gfx) + draw_wavelengths(vid_buf,XRES-20-textwidth(heattext),11,2,wavelength_gfx); } + wavelength_gfx = 0; fillrect(vid_buf, 12, 12, textwidth(uitext)+8, 15, 0, 0, 0, 140); drawtext(vid_buf, 16, 16, uitext, 32, 216, 255, 200); @@ -3823,6 +3777,7 @@ int main(int argc, char *argv[]) } SDL_CloseAudio(); http_done(); + PyRun_SimpleString("import os,tempfile,os.path\ntry:\n os.remove(os.path.join(tempfile.gettempdir(),'tpt_console.py'))\nexcept:\n pass"); PyRun_SimpleString("import os,tempfile,os.path\ntry:\n os.remove(os.path.join(tempfile.gettempdir(),'tpt_console.pyo'))\nexcept:\n pass"); PyRun_SimpleString("import os,tempfile,os.path\ntry:\n os.remove(os.path.join(tempfile.gettempdir(),'tpt_console.pyc'))\nexcept:\n pass"); @@ -3848,26 +3803,20 @@ int process_command(pixel *vid_buf,char *console,char *console_error,PyObject *p if(strcmp(console2, "quit")==0) { return -1; - } - else - { - // sprintf(console_error, "Invalid Command", console2); - //handle them command - pargs=Py_BuildValue("(s)",console); - pvalue = PyObject_CallObject(pfunc, pargs); - Py_DECREF(pargs); - pargs=NULL; - if(pvalue==NULL) - strcpy(console_error,"failed to execute code."); - //Py_DECREF(pvalue); - //puts("a"); - pvalue=NULL; + } else { + //handle them command + pargs=Py_BuildValue("(s)",console); + pvalue = PyObject_CallObject(pfunc, pargs); + Py_DECREF(pargs); + pargs=NULL; + if(pvalue==NULL) + strcpy(console_error,"failed to execute code."); + pvalue=NULL; } } return 1; } #endif - int process_command_old(pixel *vid_buf,char *console,char *console_error) { int y,x,nx,ny,i,j,k,m; int do_next = 1; @@ -306,3 +306,152 @@ int cpu_check(void) #endif return 0; } + +matrix2d m2d_multiply_m2d(matrix2d m1, matrix2d m2) +{ + matrix2d result = { + m1.a*m2.a+m1.b*m2.c, m1.a*m2.b+m1.b*m2.d, + m1.c*m2.a+m1.d*m2.c, m1.c*m2.b+m1.d*m2.d + }; + return result; +} +vector2d m2d_multiply_v2d(matrix2d m, vector2d v) +{ + vector2d result = { + m.a*v.x+m.b*v.y, + m.c*v.x+m.d*v.y + }; + return result; +} +matrix2d m2d_multiply_float(matrix2d m, float s) +{ + matrix2d result = { + m.a*s, m.b*s, + m.c*s, m.d*s, + }; + return result; +} + +vector2d v2d_multiply_float(vector2d v, float s) +{ + vector2d result = { + v.x*s, + v.y*s + }; + return result; +} + +vector2d v2d_add(vector2d v1, vector2d v2) +{ + vector2d result = { + v1.x+v2.x, + v1.y+v2.y + }; + return result; +} +vector2d v2d_sub(vector2d v1, vector2d v2) +{ + vector2d result = { + v1.x-v2.x, + v1.y-v2.y + }; + return result; +} + +matrix2d m2d_new(float me0, float me1, float me2, float me3) +{ + matrix2d result = {me0,me1,me2,me3}; + return result; +} +vector2d v2d_new(float x, float y) +{ + vector2d result = {x, y}; + return result; +} + +void clipboard_push_text(char * text) +{ + printf("Not implemented: put text on clipboard \"%s\"\n", text); +} + +char * clipboard_pull_text() +{ + printf("Not implemented: get text from clipboard\n"); + return ""; +} + +int register_extension() +{ +#if defined WIN32 + + LONG rresult; + HKEY newkey; + char *currentfilename; + char *iconname; + char *opencommand; + currentfilename = exe_name(); + iconname = malloc(strlen(currentfilename)+3); + opencommand = malloc(strlen(currentfilename)+13); + sprintf(iconname, "%s,1", currentfilename); + sprintf(opencommand, "\"%s\" open:\"%%1\"", currentfilename); + + //Create extension entry + rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\.cps", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL); + if(rresult != ERROR_SUCCESS){ + return 0; + } + rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"PowderToySave", strlen("PowderToySave")+1); + if(rresult != ERROR_SUCCESS){ + RegCloseKey(newkey); + return 0; + } + RegCloseKey(newkey); + + //Create program entry + rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL); + if(rresult != ERROR_SUCCESS){ + return 0; + } + rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"Powder Toy Save", strlen("Powder Toy Save")+1); + if(rresult != ERROR_SUCCESS){ + RegCloseKey(newkey); + return 0; + } + RegCloseKey(newkey); + + //Set DefaultIcon + rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave\\DefaultIcon", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL); + if(rresult != ERROR_SUCCESS){ + return 0; + } + rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)iconname, strlen(iconname)+1); + if(rresult != ERROR_SUCCESS){ + RegCloseKey(newkey); + return 0; + } + RegCloseKey(newkey); + + //Set Launch command + rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave\\shell\\open\\command", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL); + if(rresult != ERROR_SUCCESS){ + return 0; + } + rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)opencommand, strlen(opencommand)+1); + if(rresult != ERROR_SUCCESS){ + RegCloseKey(newkey); + return 0; + } + RegCloseKey(newkey); + + return 1; +#elif defined LIN32 + return 0; +#elif defined LIN64 + return 0; +#elif defined MACOSX + return 0; +#endif +} + +vector2d v2d_zero = {0,0}; +matrix2d m2d_identity = {1,0,0,1}; diff --git a/src/powder.c b/src/powder.c index e15565b..d7f1d8c 100644 --- a/src/powder.c +++ b/src/powder.c @@ -139,6 +139,8 @@ int try_move(int i, int x, int y, int nx, int ny) if (x==nx && y==ny) return 1; + if (nx<0 || ny<0 || nx>=XRES || ny>=YRES) + return 1; e = eval_move(parts[i].type, nx, ny, &r); @@ -253,9 +255,23 @@ int try_move(int i, int x, int y, int nx, int ny) e = r >> 8; if (r && e<NPART) { - if (parts[e].type == PT_PHOT) + if (parts[e].type == PT_PHOT||parts[e].type == PT_NEUT) return 1; + if (parts[i].type==PT_NEUT) { + // target material is NEUTPENETRATE, meaning it gets moved around when neutron passes + unsigned s = pmap[y][x]; + if ((s&0xFF) && (s&0xFF)<PT_NUM && !(ptypes[s&0xFF].properties&PROP_NEUTPENETRATE)) + return 1; // if the element currently underneath neutron isn't NEUTPENETRATE, don't move it around + if ((pmap[ny][nx]>>8)==e) pmap[ny][nx] = (s&~(0xFF))|parts[s>>8].type; + parts[e].x = x; + parts[e].y = y; + pmap[y][x] = (e<<8)|parts[e].type; + parts[s>>8].x = nx; + parts[s>>8].y = ny; + return 1; + } + if ((pmap[ny][nx]>>8)==e) pmap[ny][nx] = 0; parts[e].x += x-nx; parts[e].y += y-ny; @@ -460,7 +476,7 @@ inline void part_change_type(int i, int x, int y, int t) if (x<0 || y<0 || x>=XRES || y>=YRES || i>=NPART || t<0 || t>=PT_NUM) return; parts[i].type = t; - if (t==PT_PHOT)// || t==PT_NEUT) + if (t==PT_PHOT || t==PT_NEUT) { photons[y][x] = t|(i<<8); if ((pmap[y][x]>>8)==i) @@ -491,7 +507,7 @@ inline int create_n_parts(int n, int x, int y, float vx, float vy, int t) if (x<0 || y<0 || x>=XRES || y>=YRES || t<0 || t>=PT_NUM) return -1; - for (c; c<n; c++) { + for (c=0; c<n; c++) { float r = (rand()%128+128)/127.0f; float a = (rand()%360)*3.14159f/180.0f; if (pfree == -1) @@ -508,9 +524,9 @@ inline int create_n_parts(int n, int x, int y, float vx, float vy, int t) parts[i].ctype = 0; parts[i].temp += (n*17); parts[i].tmp = 0; - if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT && !pmap[y][x])// && t!=PT_NEUT) + if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT && t!=PT_NEUT && !pmap[y][x]) pmap[y][x] = t|(i<<8); - else if (t==PT_PHOT && !photons[y][x]) + else if ((t==PT_PHOT||t==PT_NEUT) && !photons[y][x]) photons[y][x] = t|(i<<8); pv[y/CELL][x/CELL] += 6.0f * CFDS; @@ -630,7 +646,7 @@ inline int create_part(int p, int x, int y, int t) } return -1; } - if (photons[y][x] && t==PT_PHOT) + if (photons[y][x] && (t==PT_PHOT||t==PT_NEUT)) return -1; if (pfree == -1) return -1; @@ -738,35 +754,18 @@ inline int create_part(int p, int x, int y, int t) parts[i].vx = 3.0f*cosf(a); parts[i].vy = 3.0f*sinf(a); } - if (t==PT_PHOT) - photons[y][x] = t|(i<<8); if (t==PT_STKM) { if (isplayer==0) { - if (pmap[y][x]&0xFF==PT_SPAWN) - { - parts[pmap[y][x]>>8].type = PT_STKM; - parts[pmap[y][x]>>8].vx = 0; - parts[pmap[y][x]>>8].vy = 0; - parts[pmap[y][x]>>8].life = 100; - parts[pmap[y][x]>>8].ctype = 0; - parts[pmap[y][x]>>8].temp = ptypes[t].heat; - - } - else - { - parts[i].x = (float)x; - parts[i].y = (float)y; - parts[i].type = PT_STKM; - parts[i].vx = 0; - parts[i].vy = 0; - parts[i].life = 100; - parts[i].ctype = 0; - parts[i].temp = ptypes[t].heat; - } - - + parts[i].x = (float)x; + parts[i].y = (float)y; + parts[i].type = PT_STKM; + parts[i].vx = 0; + parts[i].vy = 0; + parts[i].life = 100; + parts[i].ctype = 0; + parts[i].temp = ptypes[t].heat; player[3] = x-1; //Setting legs positions player[4] = y+6; @@ -794,7 +793,6 @@ inline int create_part(int p, int x, int y, int t) { return -1; } - //kill_part(playerspawn); create_part(-1,x,y,PT_SPAWN); ISSPAWN1 = 1; } @@ -802,29 +800,14 @@ inline int create_part(int p, int x, int y, int t) { if (isplayer2==0) { - if (pmap[y][x]&0xFF==PT_SPAWN2) - { - parts[pmap[y][x]>>8].type = PT_STKM2; - parts[pmap[y][x]>>8].vx = 0; - parts[pmap[y][x]>>8].vy = 0; - parts[pmap[y][x]>>8].life = 100; - parts[pmap[y][x]>>8].ctype = 0; - parts[pmap[y][x]>>8].temp = ptypes[t].heat; - - } - else - { - parts[i].x = (float)x; - parts[i].y = (float)y; - parts[i].type = PT_STKM2; - parts[i].vx = 0; - parts[i].vy = 0; - parts[i].life = 100; - parts[i].ctype = 0; - parts[i].temp = ptypes[t].heat; - } - - + parts[i].x = (float)x; + parts[i].y = (float)y; + parts[i].type = PT_STKM2; + parts[i].vx = 0; + parts[i].vy = 0; + parts[i].life = 100; + parts[i].ctype = 0; + parts[i].temp = ptypes[t].heat; player2[3] = x-1; //Setting legs positions player2[4] = y+6; @@ -852,13 +835,14 @@ inline int create_part(int p, int x, int y, int t) { return -1; } - //kill_part(player2spawn); create_part(-1,x,y,PT_SPAWN2); ISSPAWN2 = 1; } if (t==PT_BIZR||t==PT_BIZRG) parts[i].ctype = 0x47FFFF; - if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT)// && t!=PT_NEUT) is this needed? it breaks floodfill, Yes photons should not be placed in the PMAP + if (t==PT_PHOT||t==PT_NEUT) + photons[y][x] = t|(i<<8); + if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT && t!=PT_NEUT) // is this needed? it breaks floodfill, Yes photons should not be placed in the PMAP pmap[y][x] = t|(i<<8); return i; @@ -1342,7 +1326,7 @@ void update_particles_i(pixel *vid, int start, int inc) { r = pmap[ny][nx]; neighbors = gol2[nx][ny][0]; - if(neighbors==0 || !(ptypes[r&0xFF].properties&PROP_LIFE || !r&0xFF) || (r>>8)>=NPART) + if(neighbors==0 || !(ptypes[r&0xFF].properties&PROP_LIFE || !(r&0xFF)) || (r>>8)>=NPART) continue; for ( golnum = 1; golnum<=NGOL; golnum++) { @@ -1385,12 +1369,11 @@ void update_particles_i(pixel *vid, int start, int inc) t = parts[i].type; //printf("parts[%d].type: %d\n", i, parts[i].type); - - if (parts[i].life && t!=PT_ACID && t!=PT_COAL && t!=PT_WOOD && t!=PT_STKM && t!=PT_STKM2 && t!=PT_FUSE && t!=PT_FSEP && t!=PT_BCOL && t!=PT_GOL && t!=PT_SPNG && t!=PT_DEUT) + if (parts[i].life && t!=PT_ACID && t!=PT_COAL && t!=PT_WOOD && t!=PT_STKM && t!=PT_STKM2 && t!=PT_FUSE && t!=PT_FSEP && t!=PT_BCOL && t!=PT_GOL && t!=PT_SPNG && t!=PT_QRTZ && t!=PT_DEUT && t!=PT_PRTO && t!=PT_PRTI) { if (!(parts[i].life==10&&(t==PT_SWCH||t==PT_LCRY||t==PT_PCLN||t==PT_HSWC||t==PT_PUMP))) parts[i].life--; - if (parts[i].life<=0 && !(ptypes[t].properties&PROP_CONDUCTS) && t!=PT_ARAY && t!=PT_FIRW && t!=PT_SWCH && t!=PT_PCLN && t!=PT_HSWC && t!=PT_PUMP && t!=PT_SPRK && t!=PT_LAVA && t!=PT_LCRY && t!=PT_QRTZ && t!=PT_GLOW && t!= PT_FOG && t!=PT_PIPE && t!=PT_FRZW &&(t!=PT_ICEI&&parts[i].ctype!=PT_FRZW)&&t!=PT_INST && t!=PT_SHLD1&& t!=PT_SHLD2&& t!=PT_SHLD3&& t!=PT_SHLD4) + if (parts[i].life<=0 && !(ptypes[t].properties&PROP_CONDUCTS) && t!=PT_ARAY && t!=PT_FIRW && t!=PT_SWCH && t!=PT_PCLN && t!=PT_HSWC && t!=PT_PUMP && t!=PT_SPRK && t!=PT_LAVA && t!=PT_LCRY && t!=PT_QRTZ && t!=PT_GLOW && t!= PT_FOG && t!=PT_PIPE && t!=PT_FRZW &&(t!=PT_ICEI&&parts[i].ctype!=PT_FRZW)&&t!=PT_INST && t!=PT_SHLD1&& t!=PT_SHLD2&& t!=PT_SHLD3&& t!=PT_SHLD4 && t!=PT_SING) { kill_part(i); continue; @@ -2054,13 +2037,13 @@ killed: if (ny!=y || nx!=x) { if ((pmap[y][x]>>8)==i) pmap[y][x] = 0; - else if (t==PT_PHOT&&(photons[y][x]>>8)==i) photons[y][x] = 0; + else if ((photons[y][x]>>8)==i) photons[y][x] = 0; if (nx<CELL || nx>=XRES-CELL || ny<CELL || ny>=YRES-CELL) { kill_part(i); continue; } - if (t==PT_PHOT) + if (t==PT_PHOT||t==PT_NEUT) photons[ny][nx] = t|(i<<8); else pmap[ny][nx] = t|(i<<8); @@ -2095,12 +2078,13 @@ void update_particles(pixel *vid) t = parts[i].type; x = (int)(parts[i].x+0.5f); y = (int)(parts[i].y+0.5f); - if (x>=0 && y>=0 && x<XRES && y<YRES && t!=PT_PHOT) { - if (t!=PT_NEUT || (pmap[y][x]&0xFF)!=PT_GLAS) + if (x>=0 && y>=0 && x<XRES && y<YRES) + { + if (t==PT_PHOT||t==PT_NEUT) + photons[y][x] = t|(i<<8); + else pmap[y][x] = t|(i<<8); } - if (t==PT_PHOT) - photons[y][x] = t|(i<<8); NUM_PARTS ++; } else @@ -2610,90 +2594,6 @@ void update_particles(pixel *vid) } -void rotate_area(int area_x, int area_y, int area_w, int area_h, int invert) -{ - //TODO: MSCC doesn't like arrays who's size is determined at runtime. -#if !(defined(WIN32) && !defined(__GNUC__)) - int cx = 0; - int cy = 0; - unsigned tpmap[area_h][area_w]; - unsigned rtpmap[area_w][area_h]; - unsigned char tbmap[area_h/CELL][area_w/CELL]; - unsigned char rtbmap[area_w/CELL][area_h/CELL]; - float tfvy[area_h/CELL][area_w/CELL]; - float tfvx[area_h/CELL][area_w/CELL]; - for (cy=0; cy<area_h; cy++) - { - for (cx=0; cx<area_w; cx++)//save walls to temp - { - if (area_x + cx<XRES&&area_y + cy<YRES) - { - if (bmap[(cy+area_y)/CELL][(cx+area_x)/CELL]) { - tbmap[cy/CELL][cx/CELL] = bmap[(cy+area_y)/CELL][(cx+area_x)/CELL]; - if (bmap[(cy+area_y)/CELL][(cx+area_x)/CELL]==WL_FAN) { - tfvx[cy/CELL][cx/CELL] = fvx[(cy+area_y)/CELL][(cx+area_x)/CELL]; - tfvy[cy/CELL][cx/CELL] = fvy[(cy+area_y)/CELL][(cx+area_x)/CELL]; - } - } else { - tbmap[cy/CELL][cx/CELL] = 0; - tfvx[cy/CELL][cx/CELL] = 0; - tfvy[cy/CELL][cx/CELL] = 0; - } - } - } - } - for (cy=0; cy<area_h; cy++) - { - for (cx=0; cx<area_w; cx++)//save particles to temp - { - if ((area_x + cx<XRES&&area_y + cy<YRES)) - { - tpmap[cy][cx] = pmap[(int)(cy+area_y+0.5f)][(int)(cx+area_x+0.5f)]; - } - else - tpmap[(int)(cy+0.5f)][(int)(cx+0.5f)] = 0; - } - } - for (cy=0; cy<area_w; cy++) - { - for (cx=0; cx<area_h; cx++)//rotate temp arrays - { - if (invert) - { - rtbmap[cy/CELL][((area_h-1)-cx)/CELL] = tbmap[cy/CELL][cx/CELL]; - rtpmap[cy][(area_h-1)-cx] = tpmap[(int)(cy+0.5f)][(int)(cx+0.5f)]; - tfvx[cy/CELL][((area_h-1)-cx)/CELL] = -tfvx[cy/CELL][cx/CELL]; - tfvy[cy/CELL][((area_h-1)-cx)/CELL] = tfvy[cy/CELL][cx/CELL]; - } - else - { - rtbmap[((area_h-1)-cx)/CELL][cy/CELL] = tbmap[cy/CELL][cx/CELL]; - rtpmap[(area_h-1)-cx][cy] = tpmap[(int)(cy+0.5f)][(int)(cx+0.5f)]; - tfvy[((area_h-1)-cx)/CELL][cy/CELL] = -tfvx[cy/CELL][cx/CELL]; - tfvx[((area_h-1)-cx)/CELL][cy/CELL] = tfvy[cy/CELL][cx/CELL]; - } - } - } - for (cy=0; cy<area_w; cy++) - { - for (cx=0; cx<area_h; cx++)//move particles and walls - { - if (area_x + cx<XRES&&area_y + cy<YRES) - { - if ((rtpmap[cy][cx]>>8)<=NPART&&rtpmap[cy][cx]) - { - parts[rtpmap[(int)(cy+0.5f)][(int)(cx+0.5f)]>>8].x = area_x +cx; - parts[rtpmap[(int)(cy+0.5f)][(int)(cx+0.5f)]>>8].y = area_y +cy; - } - bmap[(area_y+cy)/CELL][(area_x+cx)/CELL] = rtbmap[cy/CELL][cx/CELL]; - fvy[(area_y+cy)/CELL][(area_x+cx)/CELL] = tfvy[cy/CELL][cx/CELL]; - fvx[(area_y+cy)/CELL][(area_x+cx)/CELL] = tfvx[cy/CELL][cx/CELL]; - } - } - } -#endif -} - void clear_area(int area_x, int area_y, int area_w, int area_h) { int cx = 0; @@ -2731,14 +2631,10 @@ void create_box(int x1, int y1, int x2, int y2, int c) int flood_parts(int x, int y, int c, int cm, int bm) { int x1, x2, dy = (c<PT_NUM)?1:CELL; - int co = c, wall; + int co = c; if (cm==PT_INST&&co==PT_SPRK) if ((pmap[y][x]&0xFF)==PT_SPRK) return 0; - if (c>=UI_WALLSTART&&c<=UI_WALLSTART+UI_WALLCOUNT) - { - wall = c-100; - } if (cm==-1) { if (c==0) @@ -2754,7 +2650,7 @@ int flood_parts(int x, int y, int c, int cm, int bm) } if (bm==-1) { - if (wall==WL_ERASE) + if (c-UI_WALLSTART+UI_ACTUALSTART==WL_ERASE) { bm = bmap[y/CELL][x/CELL]; if (!bm) @@ -2873,7 +2769,9 @@ int create_parts(int x, int y, int rx, int ry, int c) dw = 1; } if (c == PT_WIND) + { return 1; + } if (dw==1) { rx = rx/CELL; @@ -3071,3 +2969,149 @@ void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c) } } } + +void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate) +{ + void *ndata; + unsigned char bmapo[YRES/CELL][XRES/CELL], bmapn[YRES/CELL][XRES/CELL]; + particle *partst; + sign signst[MAXSIGNS]; + unsigned pmapt[YRES][XRES]; + float fvxo[YRES/CELL][XRES/CELL], fvyo[YRES/CELL][XRES/CELL]; + float fvxn[YRES/CELL][XRES/CELL], fvyn[YRES/CELL][XRES/CELL]; + int i, x, y, nx, ny, w, h, nw, nh; + vector2d pos, tmp, ctl, cbr; + vector2d cornerso[4]; + unsigned char *odatac = odata; + memset(bmapo, 0, sizeof(bmapo)); + memset(bmapn, 0, sizeof(bmapn)); + memset(signst, 0, sizeof(signst)); + memset(pmapt, 0, sizeof(pmapt)); + memset(fvxo, 0, sizeof(fvxo)); + memset(fvxn, 0, sizeof(fvxn)); + memset(fvyo, 0, sizeof(fvyo)); + memset(fvyn, 0, sizeof(fvyn)); + partst = calloc(sizeof(particle), NPART); + if (parse_save(odata, *size, 0, 0, 0, bmapo, fvxo, fvyo, signst, partst, pmapt)) + { + free(partst); + return odata; + } + w = odatac[6]*CELL; + h = odatac[7]*CELL; + // undo any translation caused by rotation + cornerso[0] = v2d_new(0,0); + cornerso[1] = v2d_new(w-1,0); + cornerso[2] = v2d_new(0,h-1); + cornerso[3] = v2d_new(w-1,h-1); + for (i=0;i<4;i++) + { + tmp = m2d_multiply_v2d(transform,cornerso[i]); + if (i==0) ctl = cbr = tmp; // top left, bottom right corner + if (tmp.x<ctl.x) ctl.x = tmp.x; + if (tmp.y<ctl.y) ctl.y = tmp.y; + if (tmp.x>cbr.x) cbr.x = tmp.x; + if (tmp.y>cbr.y) cbr.y = tmp.y; + } + // casting as int doesn't quite do what we want with negative numbers, so use floor() + tmp = v2d_new(floor(ctl.x+0.5f),floor(ctl.y+0.5f)); + translate = v2d_sub(translate,tmp); + nw = floor(cbr.x+0.5f)-floor(ctl.x+0.5f)+1; + nh = floor(cbr.y+0.5f)-floor(ctl.y+0.5f)+1; + if (nw>XRES) nw = XRES; + if (nh>YRES) nh = YRES; + // rotate and translate signs, parts, walls + for (i=0; i<MAXSIGNS; i++) + { + if (!signst[i].text[0]) continue; + pos = v2d_new(signst[i].x, signst[i].y); + pos = v2d_add(m2d_multiply_v2d(transform,pos),translate); + nx = floor(pos.x+0.5f); + ny = floor(pos.y+0.5f); + if (nx<0 || nx>=nw || ny<0 || ny>=nh) + { + signst[i].text[0] = 0; + continue; + } + signst[i].x = nx; + signst[i].y = ny; + } + for (i=0; i<NPART; i++) + { + if (!partst[i].type) continue; + pos = v2d_new(partst[i].x, partst[i].y); + pos = v2d_add(m2d_multiply_v2d(transform,pos),translate); + nx = floor(pos.x+0.5f); + ny = floor(pos.y+0.5f); + if (nx<0 || nx>=nw || ny<0 || ny>=nh) + { + partst[i].type = PT_NONE; + continue; + } + partst[i].x = nx; + partst[i].y = ny; + } + for (y=0;y<YRES/CELL;y++) + for (x=0;x<XRES/CELL;x++) + { + pos = v2d_new(x*CELL+CELL*0.4f, y*CELL+CELL*0.4f); + pos = v2d_add(m2d_multiply_v2d(transform,pos),translate); + nx = pos.x/CELL; + ny = pos.y/CELL; + if (nx<0 || nx>=nw || ny<0 || ny>=nh) + continue; + if (bmapo[y][x]) + { + bmapn[ny][nx] = bmapo[y][x]; + if (bmapo[y][x]==WL_FAN) + { + fvxn[ny][nx] = fvxo[y][x]; + fvyn[ny][nx] = fvyo[y][x]; + } + } + } + ndata = build_save(size,0,0,nw,nh,bmapn,fvxn,fvyn,signst,partst); + free(partst); + return ndata; +} + +#if defined(WIN32) && !defined(__GNUC__) +_inline void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[]) +#else +inline void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[]) +#endif +{ + resblock1[0] = (block1&0x000000FF); + resblock1[1] = (block1&0x0000FF00)>>8; + resblock1[2] = (block1&0x00FF0000)>>16; + resblock1[3] = (block1&0xFF000000)>>24; + + resblock2[0] = (block2&0x000000FF); + resblock2[1] = (block2&0x0000FF00)>>8; + resblock2[2] = (block2&0x00FF0000)>>16; + resblock2[3] = (block2&0xFF000000)>>24; +} + +#if defined(WIN32) && !defined(__GNUC__) +_inline void orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[]) +#else +inline void orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[]) +#endif +{ + int block1tmp = 0; + int block2tmp = 0; + + block1tmp = (resblock1[0]&0xFF); + block1tmp |= (resblock1[1]&0xFF)<<8; + block1tmp |= (resblock1[2]&0xFF)<<16; + block1tmp |= (resblock1[3]&0xFF)<<24; + + block2tmp = (resblock2[0]&0xFF); + block2tmp |= (resblock2[1]&0xFF)<<8; + block2tmp |= (resblock2[2]&0xFF)<<16; + block2tmp |= (resblock2[3]&0xFF)<<24; + + *block1 = block1tmp; + *block2 = block2tmp; +} + |
