Fixed SWCH for real. Fix repeating spark while creating it. Adjustable x and y for brushes.

This commit is contained in:
Philip 2010-11-19 18:01:56 -05:00
parent 435f71c781
commit c1182db42d
5 changed files with 136 additions and 74 deletions

View File

@ -137,7 +137,7 @@ pixel *prerender_save(void *save, int size, int *width, int *height);
int render_thumb(void *thumb, int size, int bzip2, pixel *vid_buf, int px, int py, int scl); int render_thumb(void *thumb, int size, int bzip2, pixel *vid_buf, int px, int py, int scl);
void render_cursor(pixel *vid, int x, int y, int t, int r); void render_cursor(pixel *vid, int x, int y, int t, float rx, float ry);
void sdl_open(void); void sdl_open(void);

View File

@ -540,8 +540,8 @@ 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 flood_parts(int x, int y, int c, int cm, int bm);
int create_parts(int x, int y, int r, int c); int create_parts(int x, int y, float rx, float ry, int c);
void create_line(int x1, int y1, int x2, int y2, int r, int c); void create_line(int x1, int y1, int x2, int y2, float rx, float ry, int c);
#endif #endif

View File

@ -2838,25 +2838,33 @@ corrupt:
return 1; return 1;
} }
void render_cursor(pixel *vid, int x, int y, int t, int r) void render_cursor(pixel *vid, int x, int y, int t, float rx, float ry)
{ {
int i,j,c; int i,j,c;
if(t<PT_NUM||t==SPC_AIR||t==SPC_HEAT||t==SPC_COOL||t==SPC_VACUUM) if(t<PT_NUM||t==SPC_AIR||t==SPC_HEAT||t==SPC_COOL||t==SPC_VACUUM)
{ {
if(r<=0) if(rx<=0)
xor_pixel(x, y, vid);
else if(ry<=0)
xor_pixel(x, y, vid);
if(rx+ry<=0)
xor_pixel(x, y, vid); xor_pixel(x, y, vid);
else if(CURRENT_BRUSH==SQUARE_BRUSH) else if(CURRENT_BRUSH==SQUARE_BRUSH)
for(j=-r; j<=r; j++)
{ {
xor_pixel(x+r, y+j, vid); for(j=0; j<=ry; j++)
xor_pixel(x-r, y+j, vid); for(i=0; i<=rx; i++)
if(abs(j)<r) xor_pixel(x+j, y-r, vid); if(i*j<=ry*rx && ((i+1)>rx || (j+1)>ry))
if(abs(j)<r) xor_pixel(x+j, y+r, vid); {
xor_pixel(x+i, y+j, vid);
xor_pixel(x-i, y-j, vid);
if(i&&j)xor_pixel(x+i, y-j, vid);
if(i&&j)xor_pixel(x-i, y+j, vid);
}
} }
else if(CURRENT_BRUSH==CIRCLE_BRUSH) else if(CURRENT_BRUSH==CIRCLE_BRUSH)
for(j=0; j<=r; j++) for(j=0; j<=ry; j++)
for(i=0; i<=r; i++) for(i=0; i<=rx; i++)
if(i*i+j*j<=r*r && ((i+1)*(i+1)+j*j>r*r || i*i+(j+1)*(j+1)>r*r)) if((i*i)/(rx*rx)+(j*j)/(ry*rx)<=1 && (((i+1)*(i+1))/(rx*rx)+(j*j)/(ry*rx)>1 || ((i*i)/(rx*rx)+((j+1)*(j+1))/(ry*ry)>1)))
{ {
xor_pixel(x+i, y+j, vid); xor_pixel(x+i, y+j, vid);
if(j) xor_pixel(x+i, y-j, vid); if(j) xor_pixel(x+i, y-j, vid);
@ -2867,7 +2875,7 @@ void render_cursor(pixel *vid, int x, int y, int t, int r)
else else
{ {
int tc; int tc;
c = (r/CELL) * CELL; c = (rx/CELL) * CELL;
x = (x/CELL) * CELL; x = (x/CELL) * CELL;
y = (y/CELL) * CELL; y = (y/CELL) * CELL;

View File

@ -993,8 +993,8 @@ int main(int argc, char *argv[])
int vs = 0; int vs = 0;
#endif #endif
int x, y, b = 0, sl=1, sr=0, su=0, c, lb = 0, lx = 0, ly = 0, lm = 0;//, tx, ty; 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;
float nfvx, nfvy; float nfvx, nfvy, bsx = 2, bsy = 2;
int load_mode=0, load_w=0, load_h=0, load_x=0, load_y=0, load_size=0; int load_mode=0, load_w=0, load_h=0, load_x=0, load_y=0, load_size=0;
void *load_data=NULL; void *load_data=NULL;
pixel *load_img=NULL;//, *fbi_img=NULL; pixel *load_img=NULL;//, *fbi_img=NULL;
@ -1292,14 +1292,32 @@ int main(int argc, char *argv[])
} }
else else
{ {
if(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) if(sdl_mod & (KMOD_LALT|KMOD_RALT) && !(sdl_mod & (KMOD_SHIFT|KMOD_CTRL)))
bs -= 1; {
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 else
bs -= ceil((bs/5)+0.5f); {
if(bs>1224) bsx -= ceil((bsx/5)+0.5f);
bs = 1224; bsy -= ceil((bsy/5)+0.5f);
if(bs<0) }
bs = 0; 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_key==SDLK_RIGHTBRACKET) {
@ -1314,14 +1332,32 @@ int main(int argc, char *argv[])
} }
else else
{ {
if(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) if(sdl_mod & (KMOD_LALT|KMOD_RALT) && !(sdl_mod & (KMOD_SHIFT|KMOD_CTRL)))
bs += 1; {
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 else
bs += ceil((bs/5)+0.5f); {
if(bs>1224) bsx += ceil((bsx/5)+0.5f);
bs = 1224; bsy += ceil((bsy/5)+0.5f);
if(bs<0) }
bs = 0; 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) if(sdl_key==SDLK_INSERT)
@ -1407,11 +1443,27 @@ int main(int argc, char *argv[])
} }
else else
{ {
bs += sdl_wheel; if(!(sdl_mod & (KMOD_SHIFT|KMOD_CTRL)))
if(bs>1224) {
bs = 1224; bsx += sdl_wheel;
if(bs<0) bsy += sdl_wheel;
bs = 0; }
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; sdl_wheel = 0;
/*if(su >= PT_NUM) { /*if(su >= PT_NUM) {
if(sl < PT_NUM) if(sl < PT_NUM)
@ -1846,7 +1898,7 @@ int main(int argc, char *argv[])
} }
else else
{ {
create_line(lx, ly, x, y, bs, c); create_line(lx, ly, x, y, bsx, bsy, c);
lx = x; lx = x;
ly = y; ly = y;
} }
@ -1920,7 +1972,7 @@ int main(int argc, char *argv[])
cb_emap[cby][cbx] = emap[cby][cbx]; cb_emap[cby][cbx] = emap[cby][cbx];
} }
create_parts(x, y, bs, c); create_parts(x, y, bsx, bsy, c);
lx = x; lx = x;
ly = y; ly = y;
lb = b; lb = b;
@ -1940,7 +1992,7 @@ int main(int argc, char *argv[])
if(lm == 1) if(lm == 1)
{ {
if(c!=127 || lx<0 || ly<0 || lx>=XRES || ly>=YRES || bmap[ly/CELL][lx/CELL]!=4) 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); create_line(lx, ly, x, y, bsx, bsy, c);
} }
else else
create_box(lx, ly, x, y, c); create_box(lx, ly, x, y, c);
@ -1964,7 +2016,7 @@ int main(int argc, char *argv[])
if(zoom_en!=1 && !load_mode && !save_mode) 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; mousex = mx/sdl_scale;
mousey = my/sdl_scale; mousey = my/sdl_scale;
} }

View File

@ -441,6 +441,8 @@ inline int create_part(int p, int x, int y, int t)
(pmap[y][x]&0xFF)!=PT_IRON && (pmap[y][x]&0xFF)!=PT_IRON &&
(pmap[y][x]&0xFF)!=PT_INWR) (pmap[y][x]&0xFF)!=PT_INWR)
return -1; return -1;
if(parts[pmap[y][x]>>8].life!=0)
return -1;
parts[pmap[y][x]>>8].type = PT_SPRK; parts[pmap[y][x]>>8].type = PT_SPRK;
parts[pmap[y][x]>>8].life = 4; parts[pmap[y][x]>>8].life = 4;
parts[pmap[y][x]>>8].ctype = pmap[y][x]&0xFF; parts[pmap[y][x]>>8].ctype = pmap[y][x]&0xFF;
@ -1226,7 +1228,7 @@ void update_particles_i(pixel *vid, int start, int inc)
nearp = nearest_part(i, PT_ETRD); nearp = nearest_part(i, PT_ETRD);
if(nearp!=-1&&parts_avg(i, nearp)!=PT_INSL) if(nearp!=-1&&parts_avg(i, nearp)!=PT_INSL)
{ {
create_line((int)parts[i].x, (int)parts[i].y, (int)parts[nearp].x, (int)parts[nearp].y, 0, PT_PLSM); create_line((int)parts[i].x, (int)parts[i].y, (int)parts[nearp].x, (int)parts[nearp].y, 0, 0, PT_PLSM);
t = parts[i].type = PT_ETRD; t = parts[i].type = PT_ETRD;
parts[i].ctype = PT_NONE; parts[i].ctype = PT_NONE;
parts[i].life = 20; parts[i].life = 20;
@ -2698,7 +2700,7 @@ void update_particles_i(pixel *vid, int start, int inc)
} }
} }
if(t==PT_SWCH) if(t==PT_SWCH)
if((parts[i].life>0&&parts[i].life<10)|| parts[i].life == 11) if((parts[i].life>0&&parts[i].life<10)|| parts[i].life > 10)
{ {
parts[i].life--; parts[i].life--;
} }
@ -2795,7 +2797,7 @@ void update_particles_i(pixel *vid, int start, int inc)
{ {
parts[r>>8].type = PT_SWCH; parts[r>>8].type = PT_SWCH;
parts[r>>8].ctype = PT_NONE; parts[r>>8].ctype = PT_NONE;
parts[r>>8].life = 0; parts[r>>8].life = 9;
} }
} }
pavg = parts_avg(i, r>>8); pavg = parts_avg(i, r>>8);
@ -2806,7 +2808,7 @@ void update_particles_i(pixel *vid, int start, int inc)
parts[r>>8].life = 10; parts[r>>8].life = 10;
if(parts[i].ctype == PT_NSCN&&pavg != PT_INSL) if(parts[i].ctype == PT_NSCN&&pavg != PT_INSL)
parts[r>>8].life = 9; parts[r>>8].life = 9;
if(!(parts[i].ctype == PT_PSCN||parts[i].ctype == PT_NSCN)&&parts[r>>8].life >= 10&&pavg != PT_INSL) //Life can be 11 too, so don't just check for 10 if(!(parts[i].ctype == PT_PSCN||parts[i].ctype == PT_NSCN)&&parts[r>>8].life == 10&&pavg != PT_INSL)
{ {
parts[r>>8].type = PT_SPRK; parts[r>>8].type = PT_SPRK;
parts[r>>8].ctype = PT_SWCH; parts[r>>8].ctype = PT_SWCH;
@ -2896,7 +2898,7 @@ void update_particles_i(pixel *vid, int start, int inc)
if(t==PT_SPRK&&parts[i].ctype==PT_SWCH&&parts[i].life<=1) if(t==PT_SPRK&&parts[i].ctype==PT_SWCH&&parts[i].life<=1)
{ {
parts[i].type = PT_SWCH; parts[i].type = PT_SWCH;
parts[i].life = 11; parts[i].life = 14;
} }
} }
} }
@ -3112,7 +3114,7 @@ killed:
else else
{ {
if(player[2] == SPC_AIR) if(player[2] == SPC_AIR)
create_parts(nx + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01), ny, 4, SPC_AIR); create_parts(nx + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01), ny, 4, 4, SPC_AIR);
else else
create_part(-1, nx, ny, player[2]); create_part(-1, nx, ny, player[2]);
@ -4212,7 +4214,7 @@ void create_box(int x1, int y1, int x2, int y2, int c)
} }
for(j=y1; j<=y2; j++) for(j=y1; j<=y2; j++)
for(i=x1; i<=x2; i++) for(i=x1; i<=x2; i++)
create_parts(i, j, 1, c); create_parts(i, j, 1, 1, c);
} }
int flood_parts(int x, int y, int c, int cm, int bm) int flood_parts(int x, int y, int c, int cm, int bm)
@ -4268,7 +4270,7 @@ int flood_parts(int x, int y, int c, int cm, int bm)
// fill span // fill span
for(x=x1; x<=x2; x++) for(x=x1; x<=x2; x++)
if(!create_parts(x, y, 0, co)) if(!create_parts(x, y, 0, 0, co))
return 0; return 0;
// fill children // fill children
@ -4285,7 +4287,7 @@ int flood_parts(int x, int y, int c, int cm, int bm)
return 1; return 1;
} }
int create_parts(int x, int y, int r, int c) int create_parts(int x, int y, float rx, float ry, int c)
{ {
int i, j, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0; //n; int i, j, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0; //n;
@ -4374,14 +4376,14 @@ int create_parts(int x, int y, int r, int c)
} }
if(dw==1) if(dw==1)
{ {
r = r/CELL; rx = rx/CELL;
x = x/CELL; x = x/CELL;
y = y/CELL; y = y/CELL;
x -= r/2; x -= rx/2;
y -= r/2; y -= rx/2;
for (ox=x; ox<=x+r; ox++) for (ox=x; ox<=x+rx; ox++)
{ {
for (oy=y; oy<=y+r; oy++) for (oy=y; oy<=y+rx; oy++)
{ {
if(ox>=0&&ox<XRES/CELL&&oy>=0&&oy<YRES/CELL) if(ox>=0&&ox<XRES/CELL&&oy>=0&&oy<YRES/CELL)
{ {
@ -4400,26 +4402,26 @@ int create_parts(int x, int y, int r, int c)
} }
if(((sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_SHIFT))|| sdl_mod & (KMOD_CAPS) )&& !REPLACE_MODE) if(((sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_SHIFT))|| sdl_mod & (KMOD_CAPS) )&& !REPLACE_MODE)
{ {
for(j=-r; j<=r; j++) for(j=-ry; j<=ry; j++)
for(i=-r; i<=r; i++) for(i=-rx; i<=rx; i++)
if((CURRENT_BRUSH==CIRCLE_BRUSH && i*i+j*j<=r*r)||CURRENT_BRUSH==SQUARE_BRUSH) if((CURRENT_BRUSH==CIRCLE_BRUSH && (i*i)/(rx*rx)+(j*j)/(ry*rx)<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx))
delete_part(x+i, y+j); delete_part(x+i, y+j);
return 1; return 1;
} }
if(REPLACE_MODE) if(REPLACE_MODE)
{ {
for(j=-r; j<=r; j++) for(j=-ry; j<=ry; j++)
for(i=-r; i<=r; i++) for(i=-rx; i<=rx; i++)
if((CURRENT_BRUSH==CIRCLE_BRUSH && i*i+j*j<=r*r)||CURRENT_BRUSH==SQUARE_BRUSH) if((CURRENT_BRUSH==CIRCLE_BRUSH && (i*i)/(rx*rx)+(j*j)/(ry*rx)<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx))
delete_part(x+i, y+j); delete_part(x+i, y+j);
if(c==0) if(c==0)
return 1; return 1;
} }
if(c == SPC_AIR || c == SPC_HEAT || c == SPC_COOL || c == SPC_VACUUM) if(c == SPC_AIR || c == SPC_HEAT || c == SPC_COOL || c == SPC_VACUUM)
{ {
for(j=-r; j<=r; j++) for(j=-ry; j<=ry; j++)
for(i=-r; i<=r; i++) for(i=-rx; i<=rx; i++)
if((CURRENT_BRUSH==CIRCLE_BRUSH && i*i+j*j<=r*r)||CURRENT_BRUSH==SQUARE_BRUSH) if((CURRENT_BRUSH==CIRCLE_BRUSH && (i*i)/(rx*rx)+(j*j)/(ry*rx)<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx))
create_part(-1, x+i, y+j, c); create_part(-1, x+i, y+j, c);
return 1; return 1;
} }
@ -4428,23 +4430,23 @@ int create_parts(int x, int y, int r, int c)
{ {
stemp = SLALT; stemp = SLALT;
SLALT = 0; SLALT = 0;
for(j=-r; j<=r; j++) for(j=-ry; j<=ry; j++)
for(i=-r; i<=r; i++) for(i=-rx; i<=rx; i++)
if((CURRENT_BRUSH==CIRCLE_BRUSH && i*i+j*j<=r*r)||CURRENT_BRUSH==SQUARE_BRUSH) if((CURRENT_BRUSH==CIRCLE_BRUSH && (i*i)/(rx*rx)+(j*j)/(ry*rx)<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx))
delete_part(x+i, y+j); delete_part(x+i, y+j);
SLALT = stemp; SLALT = stemp;
return 1; return 1;
} }
for(j=-r; j<=r; j++) for(j=-ry; j<=ry; j++)
for(i=-r; i<=r; i++) for(i=-rx; i<=rx; i++)
if((CURRENT_BRUSH==CIRCLE_BRUSH && i*i+j*j<=r*r)||CURRENT_BRUSH==SQUARE_BRUSH) if((CURRENT_BRUSH==CIRCLE_BRUSH && (i*i)/(rx*rx)+(j*j)/(ry*rx)<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx))
if(create_part(-1, x+i, y+j, c)==-1) if(create_part(-1, x+i, y+j, c)==-1)
f = 1; f = 1;
return !f; return !f;
} }
void create_line(int x1, int y1, int x2, int y2, int r, int c) void create_line(int x1, int y1, int x2, int y2, float rx, float ry, int c)
{ {
int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
float e, de; float e, de;
@ -4478,19 +4480,19 @@ void create_line(int x1, int y1, int x2, int y2, int r, int c)
for(x=x1; x<=x2; x++) for(x=x1; x<=x2; x++)
{ {
if(cp) if(cp)
create_parts(y, x, r, c); create_parts(y, x, rx, ry, c);
else else
create_parts(x, y, r, c); create_parts(x, y, rx, ry, c);
e += de; e += de;
if(e >= 0.5f) if(e >= 0.5f)
{ {
y += sy; y += sy;
if(c==135 || c==140 || c==134 || c==133 || c==132 || c==131 || c==129 || c==128 || c==127 || c==125 || c==124 || c==123 || c==122 || !r) if(c==135 || c==140 || c==134 || c==133 || c==132 || c==131 || c==129 || c==128 || c==127 || c==125 || c==124 || c==123 || c==122 || !(rx+ry))
{ {
if(cp) if(cp)
create_parts(y, x, r, c); create_parts(y, x, rx, ry, c);
else else
create_parts(x, y, r, c); create_parts(x, y, rx, ry, c);
} }
e -= 1.0f; e -= 1.0f;
} }