This commit is contained in:
Simon 2011-04-08 11:09:42 +01:00
parent 1bdf72be1a
commit 767d73c5fc
17 changed files with 1950 additions and 1960 deletions

View File

@ -79,11 +79,15 @@ int cpu_check(void);
// a b // a b
// c d // c d
struct matrix2d {float a,b,c,d;}; struct matrix2d {
float a,b,c,d;
};
typedef struct matrix2d matrix2d; typedef struct matrix2d matrix2d;
// column vector // column vector
struct vector2d {float x,y;}; struct vector2d {
float x,y;
};
typedef struct vector2d vector2d; typedef struct vector2d vector2d;
matrix2d m2d_multiply_m2d(matrix2d m1, matrix2d m2); matrix2d m2d_multiply_m2d(matrix2d m1, matrix2d m2);

348
src/air.c
View File

@ -34,180 +34,180 @@ void update_air(void)
int x, y, i, j; int x, y, i, j;
float dp, dx, dy, f, tx, ty; float dp, dx, dy, f, tx, ty;
if (airMode != 4) { //airMode 4 is no air/pressure update if (airMode != 4) { //airMode 4 is no air/pressure update
for (i=0; i<YRES/CELL; i++) //reduces pressure/velocity on the edges every frame for (i=0; i<YRES/CELL; i++) //reduces pressure/velocity on the edges every frame
{ {
pv[i][0] = pv[i][0]*0.8f; pv[i][0] = pv[i][0]*0.8f;
pv[i][1] = pv[i][1]*0.8f; pv[i][1] = pv[i][1]*0.8f;
pv[i][2] = pv[i][2]*0.8f; pv[i][2] = pv[i][2]*0.8f;
pv[i][XRES/CELL-2] = pv[i][XRES/CELL-2]*0.8f; pv[i][XRES/CELL-2] = pv[i][XRES/CELL-2]*0.8f;
pv[i][XRES/CELL-1] = pv[i][XRES/CELL-1]*0.8f; pv[i][XRES/CELL-1] = pv[i][XRES/CELL-1]*0.8f;
vx[i][0] = vx[i][1]*0.9f; vx[i][0] = vx[i][1]*0.9f;
vx[i][1] = vx[i][2]*0.9f; vx[i][1] = vx[i][2]*0.9f;
vx[i][XRES/CELL-2] = vx[i][XRES/CELL-3]*0.9f; vx[i][XRES/CELL-2] = vx[i][XRES/CELL-3]*0.9f;
vx[i][XRES/CELL-1] = vx[i][XRES/CELL-2]*0.9f; vx[i][XRES/CELL-1] = vx[i][XRES/CELL-2]*0.9f;
vy[i][0] = vy[i][1]*0.9f; vy[i][0] = vy[i][1]*0.9f;
vy[i][1] = vy[i][2]*0.9f; vy[i][1] = vy[i][2]*0.9f;
vy[i][XRES/CELL-2] = vy[i][XRES/CELL-3]*0.9f; vy[i][XRES/CELL-2] = vy[i][XRES/CELL-3]*0.9f;
vy[i][XRES/CELL-1] = vy[i][XRES/CELL-2]*0.9f; vy[i][XRES/CELL-1] = vy[i][XRES/CELL-2]*0.9f;
}
for (i=0; i<XRES/CELL; i++) //reduces pressure/velocity on the edges every frame
{
pv[0][i] = pv[0][i]*0.8f;
pv[1][i] = pv[1][i]*0.8f;
pv[2][i] = pv[2][i]*0.8f;
pv[YRES/CELL-2][i] = pv[YRES/CELL-2][i]*0.8f;
pv[YRES/CELL-1][i] = pv[YRES/CELL-1][i]*0.8f;
vx[0][i] = vx[1][i]*0.9f;
vx[1][i] = vx[2][i]*0.9f;
vx[YRES/CELL-2][i] = vx[YRES/CELL-3][i]*0.9f;
vx[YRES/CELL-1][i] = vx[YRES/CELL-2][i]*0.9f;
vy[0][i] = vy[1][i]*0.9f;
vy[1][i] = vy[2][i]*0.9f;
vy[YRES/CELL-2][i] = vy[YRES/CELL-3][i]*0.9f;
vy[YRES/CELL-1][i] = vy[YRES/CELL-2][i]*0.9f;
}
for (j=1; j<YRES/CELL; j++) //clear some velocities near walls
{
for (i=1; i<XRES/CELL; 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;
vy[j][i] = 0.0f;
vy[j-1][i] = 0.0f;
}
}
}
for (y=1; y<YRES/CELL; y++) //pressure adjustments from velocity
for (x=1; x<XRES/CELL; x++)
{
dp = 0.0f;
dp += vx[y][x-1] - vx[y][x];
dp += vy[y-1][x] - vy[y][x];
pv[y][x] *= AIR_PLOSS;
pv[y][x] += dp*AIR_TSTEPP;
}
for (y=0; y<YRES/CELL-1; y++) //velocity adjustments from pressure
for (x=0; x<XRES/CELL-1; x++)
{
dx = dy = 0.0f;
dx += pv[y][x] - pv[y][x+1];
dy += pv[y][x] - pv[y+1][x];
vx[y][x] *= AIR_VLOSS;
vy[y][x] *= AIR_VLOSS;
vx[y][x] += dx*AIR_TSTEPV;
vy[y][x] += dy*AIR_TSTEPV;
if (bmap[y][x]==WL_WALL || bmap[y][x+1]==WL_WALL ||
bmap[y][x]==WL_WALLELEC || bmap[y][x+1]==WL_WALLELEC ||
(bmap[y][x]==WL_EWALL && !emap[y][x]) ||
(bmap[y][x+1]==WL_EWALL && !emap[y][x+1]))
vx[y][x] = 0;
if (bmap[y][x]==WL_WALL || bmap[y+1][x]==WL_WALL ||
bmap[y][x]==WL_WALLELEC || bmap[y+1][x]==WL_WALLELEC ||
(bmap[y][x]==WL_EWALL && !emap[y][x]) ||
(bmap[y+1][x]==WL_EWALL && !emap[y+1][x]))
vy[y][x] = 0;
}
for (y=0; y<YRES/CELL; y++) //update velocity and pressure
for (x=0; x<XRES/CELL; x++)
{
dx = 0.0f;
dy = 0.0f;
dp = 0.0f;
for (j=-1; j<2; j++)
for (i=-1; i<2; i++)
if (y+j>0 && y+j<YRES/CELL-1 &&
x+i>0 && x+i<XRES/CELL-1 &&
bmap[y+j][x+i]!=WL_WALL &&
bmap[y+j][x+i]!=WL_WALLELEC &&
(bmap[y+j][x+i]!=WL_EWALL || emap[y+j][x+i]))
{
f = kernel[i+1+(j+1)*3];
dx += vx[y+j][x+i]*f;
dy += vy[y+j][x+i]*f;
dp += pv[y+j][x+i]*f;
}
else
{
f = kernel[i+1+(j+1)*3];
dx += vx[y][x]*f;
dy += vy[y][x]*f;
dp += pv[y][x]*f;
}
tx = x - dx*0.7f;
ty = y - dy*0.7f;
i = (int)tx;
j = (int)ty;
tx -= i;
ty -= j;
if (i>=2 && i<XRES/CELL-3 &&
j>=2 && j<YRES/CELL-3)
{
dx *= 1.0f - AIR_VADV;
dy *= 1.0f - AIR_VADV;
dx += AIR_VADV*(1.0f-tx)*(1.0f-ty)*vx[j][i];
dy += AIR_VADV*(1.0f-tx)*(1.0f-ty)*vy[j][i];
dx += AIR_VADV*tx*(1.0f-ty)*vx[j][i+1];
dy += AIR_VADV*tx*(1.0f-ty)*vy[j][i+1];
dx += AIR_VADV*(1.0f-tx)*ty*vx[j+1][i];
dy += AIR_VADV*(1.0f-tx)*ty*vy[j+1][i];
dx += AIR_VADV*tx*ty*vx[j+1][i+1];
dy += AIR_VADV*tx*ty*vy[j+1][i+1];
}
if (bmap[y][x] == WL_FAN)
{
dx += fvx[y][x];
dy += fvy[y][x];
}
// pressure/velocity caps
if (dp > 256.0f) dp = 256.0f;
if (dp < -256.0f) dp = -256.0f;
if (dx > 256.0f) dx = 256.0f;
if (dx < -256.0f) dx = -256.0f;
if (dy > 256.0f) dy = 256.0f;
if (dy < -256.0f) dy = -256.0f;
switch (airMode)
{
default:
case 0: //Default
break;
case 1: //0 Pressure
dp = 0.0f;
break;
case 2: //0 Velocity
dx = 0.0f;
dy = 0.0f;
break;
case 3: //0 Air
dx = 0.0f;
dy = 0.0f;
dp = 0.0f;
break;
case 4: //No Update
break;
}
ovx[y][x] = dx;
ovy[y][x] = dy;
opv[y][x] = dp;
}
memcpy(vx, ovx, sizeof(vx));
memcpy(vy, ovy, sizeof(vy));
memcpy(pv, opv, sizeof(pv));
} }
for (i=0; i<XRES/CELL; i++) //reduces pressure/velocity on the edges every frame
{
pv[0][i] = pv[0][i]*0.8f;
pv[1][i] = pv[1][i]*0.8f;
pv[2][i] = pv[2][i]*0.8f;
pv[YRES/CELL-2][i] = pv[YRES/CELL-2][i]*0.8f;
pv[YRES/CELL-1][i] = pv[YRES/CELL-1][i]*0.8f;
vx[0][i] = vx[1][i]*0.9f;
vx[1][i] = vx[2][i]*0.9f;
vx[YRES/CELL-2][i] = vx[YRES/CELL-3][i]*0.9f;
vx[YRES/CELL-1][i] = vx[YRES/CELL-2][i]*0.9f;
vy[0][i] = vy[1][i]*0.9f;
vy[1][i] = vy[2][i]*0.9f;
vy[YRES/CELL-2][i] = vy[YRES/CELL-3][i]*0.9f;
vy[YRES/CELL-1][i] = vy[YRES/CELL-2][i]*0.9f;
}
for (j=1; j<YRES/CELL; j++) //clear some velocities near walls
{
for (i=1; i<XRES/CELL; 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;
vy[j][i] = 0.0f;
vy[j-1][i] = 0.0f;
}
}
}
for (y=1; y<YRES/CELL; y++) //pressure adjustments from velocity
for (x=1; x<XRES/CELL; x++)
{
dp = 0.0f;
dp += vx[y][x-1] - vx[y][x];
dp += vy[y-1][x] - vy[y][x];
pv[y][x] *= AIR_PLOSS;
pv[y][x] += dp*AIR_TSTEPP;
}
for (y=0; y<YRES/CELL-1; y++) //velocity adjustments from pressure
for (x=0; x<XRES/CELL-1; x++)
{
dx = dy = 0.0f;
dx += pv[y][x] - pv[y][x+1];
dy += pv[y][x] - pv[y+1][x];
vx[y][x] *= AIR_VLOSS;
vy[y][x] *= AIR_VLOSS;
vx[y][x] += dx*AIR_TSTEPV;
vy[y][x] += dy*AIR_TSTEPV;
if (bmap[y][x]==WL_WALL || bmap[y][x+1]==WL_WALL ||
bmap[y][x]==WL_WALLELEC || bmap[y][x+1]==WL_WALLELEC ||
(bmap[y][x]==WL_EWALL && !emap[y][x]) ||
(bmap[y][x+1]==WL_EWALL && !emap[y][x+1]))
vx[y][x] = 0;
if (bmap[y][x]==WL_WALL || bmap[y+1][x]==WL_WALL ||
bmap[y][x]==WL_WALLELEC || bmap[y+1][x]==WL_WALLELEC ||
(bmap[y][x]==WL_EWALL && !emap[y][x]) ||
(bmap[y+1][x]==WL_EWALL && !emap[y+1][x]))
vy[y][x] = 0;
}
for (y=0; y<YRES/CELL; y++) //update velocity and pressure
for (x=0; x<XRES/CELL; x++)
{
dx = 0.0f;
dy = 0.0f;
dp = 0.0f;
for (j=-1; j<2; j++)
for (i=-1; i<2; i++)
if (y+j>0 && y+j<YRES/CELL-1 &&
x+i>0 && x+i<XRES/CELL-1 &&
bmap[y+j][x+i]!=WL_WALL &&
bmap[y+j][x+i]!=WL_WALLELEC &&
(bmap[y+j][x+i]!=WL_EWALL || emap[y+j][x+i]))
{
f = kernel[i+1+(j+1)*3];
dx += vx[y+j][x+i]*f;
dy += vy[y+j][x+i]*f;
dp += pv[y+j][x+i]*f;
}
else
{
f = kernel[i+1+(j+1)*3];
dx += vx[y][x]*f;
dy += vy[y][x]*f;
dp += pv[y][x]*f;
}
tx = x - dx*0.7f;
ty = y - dy*0.7f;
i = (int)tx;
j = (int)ty;
tx -= i;
ty -= j;
if (i>=2 && i<XRES/CELL-3 &&
j>=2 && j<YRES/CELL-3)
{
dx *= 1.0f - AIR_VADV;
dy *= 1.0f - AIR_VADV;
dx += AIR_VADV*(1.0f-tx)*(1.0f-ty)*vx[j][i];
dy += AIR_VADV*(1.0f-tx)*(1.0f-ty)*vy[j][i];
dx += AIR_VADV*tx*(1.0f-ty)*vx[j][i+1];
dy += AIR_VADV*tx*(1.0f-ty)*vy[j][i+1];
dx += AIR_VADV*(1.0f-tx)*ty*vx[j+1][i];
dy += AIR_VADV*(1.0f-tx)*ty*vy[j+1][i];
dx += AIR_VADV*tx*ty*vx[j+1][i+1];
dy += AIR_VADV*tx*ty*vy[j+1][i+1];
}
if (bmap[y][x] == WL_FAN)
{
dx += fvx[y][x];
dy += fvy[y][x];
}
// pressure/velocity caps
if (dp > 256.0f) dp = 256.0f;
if (dp < -256.0f) dp = -256.0f;
if (dx > 256.0f) dx = 256.0f;
if (dx < -256.0f) dx = -256.0f;
if (dy > 256.0f) dy = 256.0f;
if (dy < -256.0f) dy = -256.0f;
switch (airMode)
{
default:
case 0: //Default
break;
case 1: //0 Pressure
dp = 0.0f;
break;
case 2: //0 Velocity
dx = 0.0f;
dy = 0.0f;
break;
case 3: //0 Air
dx = 0.0f;
dy = 0.0f;
dp = 0.0f;
break;
case 4: //No Update
break;
}
ovx[y][x] = dx;
ovy[y][x] = dy;
opv[y][x] = dp;
}
memcpy(vx, ovx, sizeof(vx));
memcpy(vy, ovy, sizeof(vy));
memcpy(pv, opv, sizeof(pv));
}
} }

View File

@ -2,47 +2,47 @@
int update_O2(UPDATE_FUNC_ARGS) int update_O2(UPDATE_FUNC_ARGS)
{ {
int r,rx,ry; int r,rx,ry;
for(rx=-2; rx<3; rx++) for (rx=-2; rx<3; rx++)
for(ry=-2; ry<3; ry++) for (ry=-2; ry<3; ry++)
if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
{ {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if ((r>>8)>=NPART || !r) if ((r>>8)>=NPART || !r)
continue; continue;
if((r&0xFF)==PT_FIRE) if ((r&0xFF)==PT_FIRE)
{ {
parts[r>>8].life+=(rand()/(RAND_MAX/100))*2; parts[r>>8].life+=(rand()/(RAND_MAX/100))*2;
parts[r>>8].temp+=(rand()/(RAND_MAX/100)); parts[r>>8].temp+=(rand()/(RAND_MAX/100));
parts[i].tmp++; parts[i].tmp++;
} }
} }
if(pv[y/CELL][x/CELL] > 8.0f) if (pv[y/CELL][x/CELL] > 8.0f)
{ {
for(rx=-2; rx<3; rx++) for (rx=-2; rx<3; rx++)
for(ry=-2; ry<3; ry++) for (ry=-2; ry<3; ry++)
if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
{ {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if ((r>>8)>=NPART || !r) if ((r>>8)>=NPART || !r)
continue; continue;
if((r&0xFF)==PT_H2) if ((r&0xFF)==PT_H2)
if(50<(rand()/(RAND_MAX/100))){ if (50<(rand()/(RAND_MAX/100))) {
part_change_type(i,x,y,PT_WATR); part_change_type(i,x,y,PT_WATR);
part_change_type(r>>8,x+rx,y+ry,PT_WATR); part_change_type(r>>8,x+rx,y+ry,PT_WATR);
} }
} }
} }
if(parts[i].tmp>=50) if (parts[i].tmp>=50)
{ {
create_part(i,x,y,PT_FIRE); create_part(i,x,y,PT_FIRE);
parts[i].life+=(rand()/(RAND_MAX/100))+50; parts[i].life+=(rand()/(RAND_MAX/100))+50;
parts[i].temp+=(rand()/(RAND_MAX/100)); parts[i].temp+=(rand()/(RAND_MAX/100));
} }
return 0; return 0;
} }

View File

@ -44,7 +44,7 @@ int update_ARAY(UPDATE_FUNC_ARGS) {
} }
else if ((r&0xFF)==PT_FILT) {//get color if passed through FILT else if ((r&0xFF)==PT_FILT) {//get color if passed through FILT
colored = parts[r>>8].ctype; colored = parts[r>>8].ctype;
//this if prevents BRAY from stopping on certain materials //this if prevents BRAY from stopping on certain materials
} else if ((r&0xFF)!=PT_INWR && (r&0xFF)!=PT_ARAY && (r&0xFF)!=PT_WIFI && !((r&0xFF)==PT_SWCH && parts[r>>8].life>=10)) { } else if ((r&0xFF)!=PT_INWR && (r&0xFF)!=PT_ARAY && (r&0xFF)!=PT_WIFI && !((r&0xFF)==PT_SWCH && parts[r>>8].life>=10)) {
if (nyy!=0 || nxx!=0) { if (nyy!=0 || nxx!=0) {
create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_SPRK); create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_SPRK);
@ -59,7 +59,7 @@ int update_ARAY(UPDATE_FUNC_ARGS) {
if ((r&0xFF)==PT_BRAY) { if ((r&0xFF)==PT_BRAY) {
parts[r>>8].life = 1; parts[r>>8].life = 1;
docontinue = 1; docontinue = 1;
//this if prevents red BRAY from stopping on certain materials //this if prevents red BRAY from stopping on certain materials
} else if ((r&0xFF)==PT_INWR || (r&0xFF)==PT_ARAY || (r&0xFF)==PT_WIFI || (r&0xFF)==PT_FILT || ((r&0xFF)==PT_SWCH && parts[r>>8].life>=10)) { } else if ((r&0xFF)==PT_INWR || (r&0xFF)==PT_ARAY || (r&0xFF)==PT_WIFI || (r&0xFF)==PT_FILT || ((r&0xFF)==PT_SWCH && parts[r>>8].life>=10)) {
docontinue = 1; docontinue = 1;
} else { } else {

View File

@ -2,20 +2,20 @@
int update_H2(UPDATE_FUNC_ARGS) int update_H2(UPDATE_FUNC_ARGS)
{ {
int r,rx,ry,rt; int r,rx,ry,rt;
for(rx=-2; rx<3; rx++) for (rx=-2; rx<3; rx++)
for(ry=-2; ry<3; ry++) for (ry=-2; ry<3; ry++)
if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
{ {
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
rt = (r&0xFF); rt = (r&0xFF);
if ((r>>8)>=NPART || !r) if ((r>>8)>=NPART || !r)
continue; continue;
if(pv[y/CELL][x/CELL] > 8.0f && rt == PT_DESL) // This will not work. DESL turns to fire above 5.0 pressure if (pv[y/CELL][x/CELL] > 8.0f && rt == PT_DESL) // This will not work. DESL turns to fire above 5.0 pressure
{ {
part_change_type(r>>8,x+rx,y+ry,PT_WATR); part_change_type(r>>8,x+rx,y+ry,PT_WATR);
part_change_type(i,x,y,PT_OIL); part_change_type(i,x,y,PT_OIL);
} }
} }
return 0; return 0;
} }

View File

@ -41,16 +41,16 @@ int update_PRTI(UPDATE_FUNC_ARGS) {
} }
if(fe){ if (fe) {
int orbd[4] = {0, 0, 0, 0}; //Orbital distances int orbd[4] = {0, 0, 0, 0}; //Orbital distances
int orbl[4] = {0, 0, 0, 0}; //Orbital locations int orbl[4] = {0, 0, 0, 0}; //Orbital locations
if(!parts[i].life) parts[i].life = rand(); if (!parts[i].life) parts[i].life = rand();
if(!parts[i].ctype) parts[i].life = rand(); if (!parts[i].ctype) parts[i].life = rand();
orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl);
for(r = 0; r < 4; r++){ for (r = 0; r < 4; r++) {
if(orbd[r]>1){ if (orbd[r]>1) {
orbd[r] -= 12; orbd[r] -= 12;
if(orbd[r]<1){ if (orbd[r]<1) {
orbd[r] = (rand()%128)+128; orbd[r] = (rand()%128)+128;
orbl[r] = rand()%255; orbl[r] = rand()%255;
} else { } else {

View File

@ -62,16 +62,16 @@ int update_PRTO(UPDATE_FUNC_ARGS) {
} }
} }
} }
if(fe){ if (fe) {
int orbd[4] = {0, 0, 0, 0}; //Orbital distances int orbd[4] = {0, 0, 0, 0}; //Orbital distances
int orbl[4] = {0, 0, 0, 0}; //Orbital locations int orbl[4] = {0, 0, 0, 0}; //Orbital locations
if(!parts[i].life) parts[i].life = rand(); if (!parts[i].life) parts[i].life = rand();
if(!parts[i].ctype) parts[i].life = rand(); if (!parts[i].ctype) parts[i].life = rand();
orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl);
for(r = 0; r < 4; r++){ for (r = 0; r < 4; r++) {
if(orbd[r]<254){ if (orbd[r]<254) {
orbd[r] += 16; orbd[r] += 16;
if(orbd[r]>254){ if (orbd[r]>254) {
orbd[r] = 0; orbd[r] = 0;
orbl[r] = rand()%255; orbl[r] = rand()%255;
} }

View File

@ -3,7 +3,7 @@
int update_QRTZ(UPDATE_FUNC_ARGS) { int update_QRTZ(UPDATE_FUNC_ARGS) {
int r, tmp, trade, rx, ry, np, t; int r, tmp, trade, rx, ry, np, t;
t = parts[i].type; t = parts[i].type;
if(t == PT_QRTZ) if (t == PT_QRTZ)
{ {
parts[i].pavg[0] = parts[i].pavg[1]; parts[i].pavg[0] = parts[i].pavg[1];
parts[i].pavg[1] = pv[y/CELL][x/CELL]; parts[i].pavg[1] = pv[y/CELL][x/CELL];
@ -32,29 +32,29 @@ int update_QRTZ(UPDATE_FUNC_ARGS) {
{ {
rx = rand()%3-1; rx = rand()%3-1;
ry = rand()%3-1; ry = rand()%3-1;
if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || 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].ctype!=0)
{ {
r = pmap[y+ry][x+rx]; np = create_part(-1,x+rx,y+ry,PT_QRTZ);
if ((r>>8)<NPART && !r && parts[i].ctype!=0) if (np>0)
{ {
np = create_part(-1,x+rx,y+ry,PT_QRTZ); parts[np].tmp = parts[i].tmp;
if (np>0) parts[i].ctype = 0;
if (5>rand()%10)
{ {
parts[np].tmp = parts[i].tmp; parts[np].ctype=-1;//dead qrtz
parts[i].ctype = 0;
if(5>rand()%10)
{
parts[np].ctype=-1;//dead qrtz
}
else if(1>rand()%15)
{
parts[i].ctype=-1;
}
break;
} }
else if (1>rand()%15)
{
parts[i].ctype=-1;
}
break;
} }
} }
}
} }
} }
for ( trade = 0; trade<9; trade ++) for ( trade = 0; trade<9; trade ++)

View File

@ -22,26 +22,26 @@ int update_SING(UPDATE_FUNC_ARGS) {
if (y+CELL>0) if (y+CELL>0)
pv[y/CELL-1][x/CELL-1] += 0.1f*(singularity-pv[y/CELL-1][x/CELL-1]); pv[y/CELL-1][x/CELL-1] += 0.1f*(singularity-pv[y/CELL-1][x/CELL-1]);
} }
if(parts[i].life<1){ if (parts[i].life<1) {
//Pop! //Pop!
for(rx=-2; rx<3; rx++){ for (rx=-2; rx<3; rx++) {
crx = (x/CELL)+rx; crx = (x/CELL)+rx;
for(ry=-2; ry<3; ry++){ for (ry=-2; ry<3; ry++) {
cry = (y/CELL)+ry; cry = (y/CELL)+ry;
if(cry > 0 && crx > 0 && crx < (XRES/CELL) && cry < (YRES/CELL)){ if (cry > 0 && crx > 0 && crx < (XRES/CELL) && cry < (YRES/CELL)) {
pv[cry][crx] += (float)parts[i].tmp; pv[cry][crx] += (float)parts[i].tmp;
} }
} }
} }
rad = (parts[i].tmp>255)?255:parts[i].tmp; rad = (parts[i].tmp>255)?255:parts[i].tmp;
if(rad>=1){ if (rad>=1) {
rad = (int)(((float)rad)/8.0f); rad = (int)(((float)rad)/8.0f);
} }
if(rad>=1){ if (rad>=1) {
for (nxj=-(rad+1); nxj<=(rad+1); nxj++) for (nxj=-(rad+1); nxj<=(rad+1); nxj++)
for (nxi=-(rad+1); nxi<=(rad+1); nxi++) 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 ((pow(nxi,2))/(pow((rad+1),2))+(pow(nxj,2))/(pow((rad+1),2))<=1) {
if(rand()%2){ if (rand()%2) {
nb = create_part(-1, x+nxi, y+nxj, PT_PHOT); nb = create_part(-1, x+nxi, y+nxj, PT_PHOT);
} else { } else {
nb = create_part(-1, x+nxi, y+nxj, PT_NEUT); nb = create_part(-1, x+nxi, y+nxj, PT_NEUT);

View File

@ -1808,45 +1808,45 @@ void draw_parts(pixel *vid)
blendpixel(vid, nx, ny, cr, cg, cb, 255); blendpixel(vid, nx, ny, cr, cg, cb, 255);
} }
else if(t==PT_LOTE)//colors for life states else if (t==PT_LOTE)//colors for life states
{ {
if(parts[i].tmp==2) if (parts[i].tmp==2)
blendpixel(vid, nx, ny, 255, 128, 0, 255); blendpixel(vid, nx, ny, 255, 128, 0, 255);
else if(parts[i].tmp==1) else if (parts[i].tmp==1)
blendpixel(vid, nx, ny, 255, 255, 0, 255); blendpixel(vid, nx, ny, 255, 255, 0, 255);
else else
blendpixel(vid, nx, ny, 255, 0, 0, 255); blendpixel(vid, nx, ny, 255, 0, 0, 255);
} }
else if(t==PT_FRG2)//colors for life states else if (t==PT_FRG2)//colors for life states
{ {
if(parts[i].tmp==2) if (parts[i].tmp==2)
blendpixel(vid, nx, ny, 0, 100, 50, 255); blendpixel(vid, nx, ny, 0, 100, 50, 255);
else else
blendpixel(vid, nx, ny, 0, 255, 90, 255); blendpixel(vid, nx, ny, 0, 255, 90, 255);
} }
else if(t==PT_STAR)//colors for life states else if (t==PT_STAR)//colors for life states
{ {
if(parts[i].tmp==4) if (parts[i].tmp==4)
blendpixel(vid, nx, ny, 0, 0, 128, 255); blendpixel(vid, nx, ny, 0, 0, 128, 255);
else if(parts[i].tmp==3) else if (parts[i].tmp==3)
blendpixel(vid, nx, ny, 0, 0, 150, 255); blendpixel(vid, nx, ny, 0, 0, 150, 255);
else if(parts[i].tmp==2) else if (parts[i].tmp==2)
blendpixel(vid, nx, ny, 0, 0, 190, 255); blendpixel(vid, nx, ny, 0, 0, 190, 255);
else if(parts[i].tmp==1) else if (parts[i].tmp==1)
blendpixel(vid, nx, ny, 0, 0, 230, 255); blendpixel(vid, nx, ny, 0, 0, 230, 255);
else else
blendpixel(vid, nx, ny, 0, 0, 70, 255); blendpixel(vid, nx, ny, 0, 0, 70, 255);
} }
else if(t==PT_FROG)//colors for life states else if (t==PT_FROG)//colors for life states
{ {
if(parts[i].tmp==2) if (parts[i].tmp==2)
blendpixel(vid, nx, ny, 0, 100, 0, 255); blendpixel(vid, nx, ny, 0, 100, 0, 255);
else else
blendpixel(vid, nx, ny, 0, 255, 0, 255); blendpixel(vid, nx, ny, 0, 255, 0, 255);
} }
else if(t==PT_BRAN)//colors for life states else if (t==PT_BRAN)//colors for life states
{ {
if(parts[i].tmp==1) if (parts[i].tmp==1)
blendpixel(vid, nx, ny, 150, 150, 0, 255); blendpixel(vid, nx, ny, 150, 150, 0, 255);
else else
blendpixel(vid, nx, ny, 255, 255, 0, 255); blendpixel(vid, nx, ny, 255, 255, 0, 255);
@ -1985,23 +1985,23 @@ void draw_parts(pixel *vid)
float drad = 0.0f; float drad = 0.0f;
float ddist = 0.0f; float ddist = 0.0f;
orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl);
for(r = 0; r < 4; r++){ for (r = 0; r < 4; r++) {
ddist = ((float)orbd[r])/16.0f; ddist = ((float)orbd[r])/16.0f;
drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f; drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f;
nxo = ddist*cos(drad); nxo = ddist*cos(drad);
nyo = ddist*sin(drad); nyo = ddist*sin(drad);
if(ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES){ if (ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES) {
addpixel(vid, nx+nxo, ny+nyo, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors), 255-orbd[r]); 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 && r == 1){ if (cmode == CM_FIRE && r == 1) {
fire_rv = fire_r[(ny+nyo)/CELL][(nx+nxo)/CELL]; fire_rv = fire_r[(ny+nyo)/CELL][(nx+nxo)/CELL];
fire_rv += 1; fire_rv += 1;
if(fire_rv>255) fire_rv = 255; if (fire_rv>255) fire_rv = 255;
fire_r[(ny+nyo)/CELL][(nx+nxo)/CELL] = fire_rv; 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); addpixel(vid, nx, ny, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors), 200);
} }
if(DEBUG_MODE){//draw lines connecting portals if (DEBUG_MODE) {//draw lines connecting portals
blendpixel(vid,nx,ny, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors),255); blendpixel(vid,nx,ny, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors),255);
if (mousex==(nx) && mousey==(ny)) if (mousex==(nx) && mousey==(ny))
{ {
@ -2024,23 +2024,23 @@ void draw_parts(pixel *vid)
float drad = 0.0f; float drad = 0.0f;
float ddist = 0.0f; float ddist = 0.0f;
orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl);
for(r = 0; r < 4; r++){ for (r = 0; r < 4; r++) {
ddist = ((float)orbd[r])/16.0f; ddist = ((float)orbd[r])/16.0f;
drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f; drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f;
nxo = ddist*cos(drad); nxo = ddist*cos(drad);
nyo = ddist*sin(drad); nyo = ddist*sin(drad);
if(ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES){ if (ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES) {
addpixel(vid, nx+nxo, ny+nyo, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors), 255-orbd[r]); 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 && r == 1){ if (cmode == CM_FIRE && r == 1) {
fire_bv = fire_b[(ny+nyo)/CELL][(nx+nxo)/CELL]; fire_bv = fire_b[(ny+nyo)/CELL][(nx+nxo)/CELL];
fire_bv += 1; fire_bv += 1;
if(fire_bv>255) fire_bv = 255; if (fire_bv>255) fire_bv = 255;
fire_b[(ny+nyo)/CELL][(nx+nxo)/CELL] = fire_bv; 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); addpixel(vid, nx, ny, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors), 200);
} }
if(DEBUG_MODE){//draw lines connecting portals if (DEBUG_MODE) {//draw lines connecting portals
blendpixel(vid,nx,ny, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors),255); blendpixel(vid,nx,ny, PIXR(ptypes[t].pcolors), PIXG(ptypes[t].pcolors), PIXB(ptypes[t].pcolors),255);
if (mousex==(nx) && mousey==(ny)) if (mousex==(nx) && mousey==(ny))
{ {
@ -2711,7 +2711,7 @@ void draw_parts(pixel *vid)
blendpixel(vid, nx-1, ny, cr, cg, cb, (gradv*2)>255?255:(gradv*2) ); blendpixel(vid, nx-1, ny, cr, cg, cb, (gradv*2)>255?255:(gradv*2) );
blendpixel(vid, nx, ny+1, cr, cg, cb, (gradv*2)>255?255:(gradv*2) ); blendpixel(vid, nx, ny+1, cr, cg, cb, (gradv*2)>255?255:(gradv*2) );
blendpixel(vid, nx, ny-1, cr, cg, cb, (gradv*2)>255?255:(gradv*2) ); blendpixel(vid, nx, ny-1, cr, cg, cb, (gradv*2)>255?255:(gradv*2) );
if(gradv>255) gradv=255; if (gradv>255) gradv=255;
blendpixel(vid, nx+1, ny-1, cr, cg, cb, gradv); blendpixel(vid, nx+1, ny-1, cr, cg, cb, gradv);
blendpixel(vid, nx-1, ny-1, cr, cg, cb, gradv); blendpixel(vid, nx-1, ny-1, cr, cg, cb, gradv);
blendpixel(vid, nx+1, ny+1, cr, cg, cb, gradv); blendpixel(vid, nx+1, ny+1, cr, cg, cb, gradv);
@ -3039,7 +3039,7 @@ void draw_wavelengths(pixel *vid, int x, int y, int h, int wl)
int i,cr,cg,cb,j; int i,cr,cg,cb,j;
int tmp; 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 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++) for (i=0; i<30; i++)
{ {
if ((wl>>i)&1) if ((wl>>i)&1)
{ {
@ -3059,7 +3059,7 @@ void draw_wavelengths(pixel *vid, int x, int y, int h, int wl)
cr *= tmp; cr *= tmp;
cg *= tmp; cg *= tmp;
cb *= 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); 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);
} }
} }
} }
@ -3090,14 +3090,14 @@ void render_signs(pixel *vid_buf)
drawtext(vid_buf, x+3, y+3, buff, 255, 255, 255, 255); drawtext(vid_buf, x+3, y+3, buff, 255, 255, 255, 255);
} }
if(sregexp(signs[i].text, "^{c:[0-9]*|.*}$")==0) if (sregexp(signs[i].text, "^{c:[0-9]*|.*}$")==0)
{ {
int sldr, startm; int sldr, startm;
memset(buff, 0, sizeof(buff)); memset(buff, 0, sizeof(buff));
for(sldr=3; signs[i].text[sldr-1] != '|'; sldr++) for (sldr=3; signs[i].text[sldr-1] != '|'; sldr++)
startm = sldr + 1; startm = sldr + 1;
sldr = startm; sldr = startm;
while(signs[i].text[sldr] != '}') while (signs[i].text[sldr] != '}')
{ {
buff[sldr - startm] = signs[i].text[sldr]; buff[sldr - startm] = signs[i].text[sldr];
sldr++; sldr++;
@ -3106,7 +3106,7 @@ void render_signs(pixel *vid_buf)
} }
//Usual text //Usual text
if(strcmp(signs[i].text, "{p}") && strcmp(signs[i].text, "{t}") && sregexp(signs[i].text, "^{c:[0-9]*|.*}$")) if (strcmp(signs[i].text, "{p}") && strcmp(signs[i].text, "{t}") && sregexp(signs[i].text, "^{c:[0-9]*|.*}$"))
drawtext(vid_buf, x+3, y+3, signs[i].text, 255, 255, 255, 255); drawtext(vid_buf, x+3, y+3, signs[i].text, 255, 255, 255, 255);
x = signs[i].x; x = signs[i].x;

View File

@ -709,7 +709,7 @@ void http_auth_headers(void *ctx, char *user, char *pass, char *session_id)
http_async_add_header(ctx, "X-Auth-Hash", tmp); http_async_add_header(ctx, "X-Auth-Hash", tmp);
free(tmp); free(tmp);
} }
if(session_id) if (session_id)
{ {
http_async_add_header(ctx, "X-Auth-User-Id", user); http_async_add_header(ctx, "X-Auth-User-Id", user);
http_async_add_header(ctx, "X-Auth-Session-Key", session_id); http_async_add_header(ctx, "X-Auth-Session-Key", session_id);
@ -1031,7 +1031,7 @@ retry:
http_async_add_header(ctx, "X-Auth-Hash", tmp); http_async_add_header(ctx, "X-Auth-Hash", tmp);
free(tmp); free(tmp);
} }
if(session_id) if (session_id)
{ {
http_async_add_header(ctx, "X-Auth-User-Id", user); http_async_add_header(ctx, "X-Auth-User-Id", user);
http_async_add_header(ctx, "X-Auth-Session-Key", session_id); http_async_add_header(ctx, "X-Auth-Session-Key", session_id);

View File

@ -89,16 +89,16 @@ void get_sign_pos(int i, int *x0, int *y0, int *w, int *h)
if (strcmp(signs[i].text, "{t}")==0) if (strcmp(signs[i].text, "{t}")==0)
*w = textwidth("Temp: 0000.00"); *w = textwidth("Temp: 0000.00");
if(sregexp(signs[i].text, "^{c:[0-9]*|.*}$")==0) if (sregexp(signs[i].text, "^{c:[0-9]*|.*}$")==0)
{ {
int sldr, startm; int sldr, startm;
char buff[256]; char buff[256];
memset(buff, 0, sizeof(buff)); memset(buff, 0, sizeof(buff));
for(sldr=3; signs[i].text[sldr-1] != '|'; sldr++) for (sldr=3; signs[i].text[sldr-1] != '|'; sldr++)
startm = sldr + 1; startm = sldr + 1;
sldr = startm; sldr = startm;
while(signs[i].text[sldr] != '}') while (signs[i].text[sldr] != '}')
{ {
buff[sldr - startm] = signs[i].text[sldr]; buff[sldr - startm] = signs[i].text[sldr];
sldr++; sldr++;
@ -486,8 +486,8 @@ void ui_checkbox_process(int mx, int my, int mb, int mbq, ui_checkbox *ed)
void ui_copytext_draw(pixel *vid_buf, ui_copytext *ed) void ui_copytext_draw(pixel *vid_buf, ui_copytext *ed)
{ {
int g = 180, i = 0; int g = 180, i = 0;
if(!ed->state){ if (!ed->state) {
if(ed->hover){ if (ed->hover) {
i = 0; i = 0;
} else { } else {
i = 100; i = 100;
@ -507,8 +507,8 @@ void ui_copytext_draw(pixel *vid_buf, ui_copytext *ed)
void ui_copytext_process(int mx, int my, int mb, int mbq, ui_copytext *ed) void ui_copytext_process(int mx, int my, int mb, int mbq, ui_copytext *ed)
{ {
if(my>=ed->y && my<=ed->y+ed->height && mx>=ed->x && mx<=ed->x+ed->width && !ed->state){ if (my>=ed->y && my<=ed->y+ed->height && mx>=ed->x && mx<=ed->x+ed->width && !ed->state) {
if(mb && !mbq){ if (mb && !mbq) {
clipboard_push_text(ed->text); clipboard_push_text(ed->text);
ed->state = 1; ed->state = 1;
} }
@ -1823,7 +1823,7 @@ void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int b, int bq, int mx,
} }
else //all other menus else //all other menus
{ {
if (fwidth > XRES-BARSIZE){ //fancy scrolling if (fwidth > XRES-BARSIZE) { //fancy scrolling
float overflow = fwidth-(XRES-BARSIZE), location = ((float)XRES-BARSIZE)/((float)(mx-(XRES-BARSIZE))); float overflow = fwidth-(XRES-BARSIZE), location = ((float)XRES-BARSIZE)/((float)(mx-(XRES-BARSIZE)));
xoff = (int)(overflow / location); xoff = (int)(overflow / location);
} }
@ -4063,7 +4063,7 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);//enable keyrepeat for console (is disabled on console close later) SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);//enable keyrepeat for console (is disabled on console close later)
cc = 0; cc = 0;
while(cc < 80){ while (cc < 80) {
fillrect(old_buf, -1, -1+cc, XRES+BARSIZE, 2, 0, 0, 0, 160-(cc*2)); fillrect(old_buf, -1, -1+cc, XRES+BARSIZE, 2, 0, 0, 0, 160-(cc*2));
cc++; cc++;
} }
@ -4077,30 +4077,30 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
memcpy(vid_buf,old_buf,(XRES+BARSIZE)*YRES*PIXELSIZE); memcpy(vid_buf,old_buf,(XRES+BARSIZE)*YRES*PIXELSIZE);
draw_line(vid_buf, 0, 219, XRES+BARSIZE-1, 219, 228, 228, 228, XRES+BARSIZE); draw_line(vid_buf, 0, 219, XRES+BARSIZE-1, 219, 228, 228, 228, XRES+BARSIZE);
#ifdef PYCONSOLE #ifdef PYCONSOLE
if(pygood) if (pygood)
i=255; i=255;
else else
i=0; i=0;
if(pyready) if (pyready)
drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.3 (by cracker64, python by Doxin)", 255, i, i, 255); drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.3 (by cracker64, python by Doxin)", 255, i, i, 255);
else else
drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.3 (by cracker64, python disabled)", 255, i, i, 255); drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.3 (by cracker64, python disabled)", 255, i, i, 255);
#else #else
drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.3 (by cracker64, python disabled)", 255, 255, 255, 255); drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.3 (by cracker64, python disabled)", 255, 255, 255, 255);
#endif #endif
cc = 0; cc = 0;
currentcommand = last_command; currentcommand = last_command;
while(cc < 10) while (cc < 10)
{ {
if(currentcommand==NULL) if (currentcommand==NULL)
break; break;
drawtext(vid_buf, 15, 175-(cc*12), currentcommand->command, 255, 255, 255, 255); drawtext(vid_buf, 15, 175-(cc*12), currentcommand->command, 255, 255, 255, 255);
if(currentcommand->prev_command!=NULL) if (currentcommand->prev_command!=NULL)
{ {
if(cc<9) { if (cc<9) {
currentcommand = currentcommand->prev_command; currentcommand = currentcommand->prev_command;
} else if(currentcommand->prev_command!=NULL) { } else if (currentcommand->prev_command!=NULL) {
free(currentcommand->prev_command); free(currentcommand->prev_command);
currentcommand->prev_command = NULL; currentcommand->prev_command = NULL;
} }
@ -4113,16 +4113,16 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
} }
cc = 0; cc = 0;
currentcommand2 = last_command2; currentcommand2 = last_command2;
while(cc < 10) while (cc < 10)
{ {
if(currentcommand2==NULL) if (currentcommand2==NULL)
break; break;
drawtext(vid_buf, 215, 175-(cc*12), currentcommand2->command, 255, 225, 225, 255); drawtext(vid_buf, 215, 175-(cc*12), currentcommand2->command, 255, 225, 225, 255);
if(currentcommand2->prev_command!=NULL) if (currentcommand2->prev_command!=NULL)
{ {
if(cc<9) { if (cc<9) {
currentcommand2 = currentcommand2->prev_command; currentcommand2 = currentcommand2->prev_command;
} else if(currentcommand2->prev_command!=NULL) { } else if (currentcommand2->prev_command!=NULL) {
free(currentcommand2->prev_command); free(currentcommand2->prev_command);
currentcommand2->prev_command = NULL; currentcommand2->prev_command = NULL;
} }
@ -4135,11 +4135,11 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
} }
//if(error && ed.str[0]=='\0') //if(error && ed.str[0]=='\0')
//drawtext(vid_buf, 20, 207, error, 255, 127, 127, 200); //drawtext(vid_buf, 20, 207, error, 255, 127, 127, 200);
if(console_more==0) if (console_more==0)
drawtext(vid_buf, 5, 207, ">", 255, 255, 255, 240); drawtext(vid_buf, 5, 207, ">", 255, 255, 255, 240);
else else
drawtext(vid_buf, 5, 207, "...", 255, 255, 255, 240); drawtext(vid_buf, 5, 207, "...", 255, 255, 255, 240);
ui_edit_draw(vid_buf, &ed); ui_edit_draw(vid_buf, &ed);
ui_edit_process(mx, my, b, &ed); ui_edit_process(mx, my, b, &ed);
@ -4162,22 +4162,22 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
return NULL; return NULL;
} }
if(sdl_key==SDLK_UP || sdl_key==SDLK_DOWN) if (sdl_key==SDLK_UP || sdl_key==SDLK_DOWN)
{ {
ci += sdl_key==SDLK_UP?1:-1; ci += sdl_key==SDLK_UP?1:-1;
if(ci<-1) if (ci<-1)
ci = -1; ci = -1;
if(ci==-1) if (ci==-1)
{ {
strcpy(ed.str, ""); strcpy(ed.str, "");
ed.cursor = strlen(ed.str); ed.cursor = strlen(ed.str);
} }
else else
{ {
if(last_command!=NULL) { if (last_command!=NULL) {
currentcommand = last_command; currentcommand = last_command;
for (cc = 0; cc<ci; cc++) { for (cc = 0; cc<ci; cc++) {
if(currentcommand->prev_command==NULL) if (currentcommand->prev_command==NULL)
ci = cc; ci = cc;
else else
currentcommand = currentcommand->prev_command; currentcommand = currentcommand->prev_command;

2990
src/main.c

File diff suppressed because it is too large Load Diff

View File

@ -128,7 +128,7 @@ int sregexp(const char *str, char *pattern)
{ {
int result; int result;
regex_t patternc; regex_t patternc;
if(regcomp(&patternc, pattern, 0)!=0) if (regcomp(&patternc, pattern, 0)!=0)
return 1; return 1;
result = regexec(&patternc, str, 0, NULL, 0); result = regexec(&patternc, str, 0, NULL, 0);
regfree(&patternc); regfree(&patternc);
@ -164,7 +164,7 @@ void load_presets(void)
remove("powder.def"); remove("powder.def");
return; return;
} }
if(sig[3]==0x66){ if (sig[3]==0x66) {
if (load_string(f, svf_user, 63)) if (load_string(f, svf_user, 63))
goto fail; goto fail;
if (load_string(f, svf_pass, 63)) if (load_string(f, svf_pass, 63))
@ -380,14 +380,14 @@ void clipboard_push_text(char * text)
#ifdef MACOSX #ifdef MACOSX
PasteboardRef newclipboard; PasteboardRef newclipboard;
if(PasteboardCreate(kPasteboardClipboard, &newclipboard)!=noErr) return; if (PasteboardCreate(kPasteboardClipboard, &newclipboard)!=noErr) return;
if(PasteboardClear(newclipboard)!=noErr) return; if (PasteboardClear(newclipboard)!=noErr) return;
PasteboardSynchronize(newclipboard); PasteboardSynchronize(newclipboard);
CFDataRef data = CFDataCreate(kCFAllocatorDefault, text, strlen(text)); CFDataRef data = CFDataCreate(kCFAllocatorDefault, text, strlen(text));
PasteboardPutItemFlavor(newclipboard, (PasteboardItemID)1, CFSTR("com.apple.traditional-mac-plain-text"), data, 0); PasteboardPutItemFlavor(newclipboard, (PasteboardItemID)1, CFSTR("com.apple.traditional-mac-plain-text"), data, 0);
#elif defined WIN32 #elif defined WIN32
if(OpenClipboard(NULL)) if (OpenClipboard(NULL))
{ {
HGLOBAL cbuffer; HGLOBAL cbuffer;
char * glbuffer; char * glbuffer;
@ -432,11 +432,11 @@ int register_extension()
//Create extension entry //Create extension entry
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\.cps", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL); rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\.cps", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
if(rresult != ERROR_SUCCESS){ if (rresult != ERROR_SUCCESS) {
return 0; return 0;
} }
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"PowderToySave", strlen("PowderToySave")+1); rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"PowderToySave", strlen("PowderToySave")+1);
if(rresult != ERROR_SUCCESS){ if (rresult != ERROR_SUCCESS) {
RegCloseKey(newkey); RegCloseKey(newkey);
return 0; return 0;
} }
@ -444,11 +444,11 @@ int register_extension()
//Create program entry //Create program entry
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL); rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
if(rresult != ERROR_SUCCESS){ if (rresult != ERROR_SUCCESS) {
return 0; return 0;
} }
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"Powder Toy Save", strlen("Powder Toy Save")+1); rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"Powder Toy Save", strlen("Powder Toy Save")+1);
if(rresult != ERROR_SUCCESS){ if (rresult != ERROR_SUCCESS) {
RegCloseKey(newkey); RegCloseKey(newkey);
return 0; return 0;
} }
@ -456,11 +456,11 @@ int register_extension()
//Set DefaultIcon //Set DefaultIcon
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave\\DefaultIcon", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL); 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){ if (rresult != ERROR_SUCCESS) {
return 0; return 0;
} }
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)iconname, strlen(iconname)+1); rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)iconname, strlen(iconname)+1);
if(rresult != ERROR_SUCCESS){ if (rresult != ERROR_SUCCESS) {
RegCloseKey(newkey); RegCloseKey(newkey);
return 0; return 0;
} }
@ -468,11 +468,11 @@ int register_extension()
//Set Launch command //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); 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){ if (rresult != ERROR_SUCCESS) {
return 0; return 0;
} }
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)opencommand, strlen(opencommand)+1); rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)opencommand, strlen(opencommand)+1);
if(rresult != ERROR_SUCCESS){ if (rresult != ERROR_SUCCESS) {
RegCloseKey(newkey); RegCloseKey(newkey);
return 0; return 0;
} }

View File

@ -79,7 +79,7 @@ int eval_move(int pt, int nx, int ny, unsigned *rr)
if ((r&0xFF)==PT_VOID || (r&0xFF)==PT_BHOL) if ((r&0xFF)==PT_VOID || (r&0xFF)==PT_BHOL)
return 1; return 1;
if(pt==PT_SPRK)//spark shouldn't move if (pt==PT_SPRK)//spark shouldn't move
return 0; return 0;
if (pt==PT_PHOT&&( if (pt==PT_PHOT&&(
@ -702,8 +702,8 @@ inline int create_part(int p, int x, int y, int t)//the function for creating a
} }
if (ptypes[t].properties&PROP_LIFE) { if (ptypes[t].properties&PROP_LIFE) {
int r; int r;
for(r = 0; r<NGOL; r++) for (r = 0; r<NGOL; r++)
if(t==goltype[r]) if (t==goltype[r])
parts[i].tmp = grule[r+1][9] - 1; parts[i].tmp = grule[r+1][9] - 1;
} }
if (t==PT_DEUT) if (t==PT_DEUT)
@ -1313,7 +1313,7 @@ void update_particles_i(pixel *vid, int start, int inc)
for ( golnum=1; golnum<=NGOL; golnum++) for ( golnum=1; golnum<=NGOL; golnum++)
if (parts[r>>8].type==goltype[golnum-1]) if (parts[r>>8].type==goltype[golnum-1])
{ {
if(parts[r>>8].tmp == grule[golnum][9]-1) { if (parts[r>>8].tmp == grule[golnum][9]-1) {
gol[nx][ny] = golnum; gol[nx][ny] = golnum;
for ( nnx=-1; nnx<2; nnx++) for ( nnx=-1; nnx<2; nnx++)
for ( nny=-1; nny<2; nny++)//it will count itself as its own neighbor, which is needed, but will have 1 extra for delete check for ( nny=-1; nny<2; nny++)//it will count itself as its own neighbor, which is needed, but will have 1 extra for delete check
@ -1327,7 +1327,7 @@ void update_particles_i(pixel *vid, int start, int inc)
} }
} else { } else {
parts[r>>8].tmp --; parts[r>>8].tmp --;
if(parts[r>>8].tmp<=0) if (parts[r>>8].tmp<=0)
parts[r>>8].type = PT_NONE;//using kill_part makes it not work parts[r>>8].type = PT_NONE;//using kill_part makes it not work
} }
} }
@ -1337,25 +1337,25 @@ void update_particles_i(pixel *vid, int start, int inc)
{ {
r = pmap[ny][nx]; r = pmap[ny][nx];
neighbors = gol2[nx][ny][0]; 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; continue;
for ( golnum = 1; golnum<=NGOL; golnum++) for ( golnum = 1; golnum<=NGOL; golnum++)
{
goldelete = neighbors;
if (gol[nx][ny]==0&&grule[golnum][goldelete]>=2&&gol2[nx][ny][golnum]>=(goldelete%2)+goldelete/2)
{ {
goldelete = neighbors; if (create_part(-1,nx,ny,goltype[golnum-1]))
if (gol[nx][ny]==0&&grule[golnum][goldelete]>=2&&gol2[nx][ny][golnum]>=(goldelete%2)+goldelete/2) createdsomething = 1;
{
if (create_part(-1,nx,ny,goltype[golnum-1]))
createdsomething = 1;
}
else if (gol[nx][ny]==golnum&&(grule[golnum][goldelete-1]==0||grule[golnum][goldelete-1]==2))//subtract 1 because it counted itself
{
if(parts[r>>8].tmp==grule[golnum][9]-1)
parts[r>>8].tmp --;
}
if (r && parts[r>>8].tmp<=0)
parts[r>>8].type = PT_NONE;//using kill_part makes it not work
} }
for( z = 0;z<=NGOL;z++) else if (gol[nx][ny]==golnum&&(grule[golnum][goldelete-1]==0||grule[golnum][goldelete-1]==2))//subtract 1 because it counted itself
{
if (parts[r>>8].tmp==grule[golnum][9]-1)
parts[r>>8].tmp --;
}
if (r && parts[r>>8].tmp<=0)
parts[r>>8].type = PT_NONE;//using kill_part makes it not work
}
for ( z = 0; z<=NGOL; z++)
gol2[nx][ny][z] = 0;//this improves performance A LOT compared to the memset, i was getting ~23 more fps with this. gol2[nx][ny][z] = 0;//this improves performance A LOT compared to the memset, i was getting ~23 more fps with this.
} }
if (createdsomething) if (createdsomething)
@ -1450,18 +1450,18 @@ void update_particles_i(pixel *vid, int start, int inc)
//Gravity mode by Moach //Gravity mode by Moach
switch (gravityMode) switch (gravityMode)
{ {
default: default:
case 0: case 0:
pGravX = 0.0f; pGravX = 0.0f;
pGravY = ptypes[t].gravity; pGravY = ptypes[t].gravity;
break; break;
case 1: case 1:
pGravX = pGravY = 0.0f; pGravX = pGravY = 0.0f;
break; break;
case 2: case 2:
pGravD = 0.01f - hypotf((x - XCNTR), (y - YCNTR)); pGravD = 0.01f - hypotf((x - XCNTR), (y - YCNTR));
pGravX = ptypes[t].gravity * ((float)(x - XCNTR) / pGravD); pGravX = ptypes[t].gravity * ((float)(x - XCNTR) / pGravD);
pGravY = ptypes[t].gravity * ((float)(y - YCNTR) / pGravD); pGravY = ptypes[t].gravity * ((float)(y - YCNTR) / pGravD);
} }
//velocity updates for the particle //velocity updates for the particle
parts[i].vx *= ptypes[t].loss; parts[i].vx *= ptypes[t].loss;
@ -2704,9 +2704,9 @@ 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(cm==PT_INST&&co==PT_SPRK) if (cm==PT_INST&&co==PT_SPRK)
{ {
if(create_part(-1,x, y, co)==-1) if (create_part(-1,x, y, co)==-1)
return 0; return 0;
} }
else if (!create_parts(x, y, 0, 0, co)) else if (!create_parts(x, y, 0, 0, co))
@ -2864,7 +2864,7 @@ int create_parts(int x, int y, int rx, int ry, int c)
for (i=-rx; i<=rx; i++) for (i=-rx; i<=rx; i++)
if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx)) if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx))
{ {
if( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES) if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES)
continue; continue;
if (!REPLACE_MODE) if (!REPLACE_MODE)
create_part(-2, x+i, y+j, c); create_part(-2, x+i, y+j, c);
@ -2910,7 +2910,7 @@ int create_parts(int x, int y, int rx, int ry, int c)
for (i=-rx; i<=rx; i++) for (i=-rx; i<=rx; i++)
if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx)) if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx))
{ {
if( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES) if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES)
continue; continue;
if ((pmap[y+j][x+i]&0xFF)!=SLALT&&SLALT!=0) if ((pmap[y+j][x+i]&0xFF)!=SLALT&&SLALT!=0)
continue; continue;
@ -3026,7 +3026,7 @@ void *transform_save(void *odata, int *size, matrix2d transform, vector2d transl
cornerso[1] = v2d_new(w-1,0); cornerso[1] = v2d_new(w-1,0);
cornerso[2] = v2d_new(0,h-1); cornerso[2] = v2d_new(0,h-1);
cornerso[3] = v2d_new(w-1,h-1); cornerso[3] = v2d_new(w-1,h-1);
for (i=0;i<4;i++) for (i=0; i<4; i++)
{ {
tmp = m2d_multiply_v2d(transform,cornerso[i]); tmp = m2d_multiply_v2d(transform,cornerso[i]);
if (i==0) ctl = cbr = tmp; // top left, bottom right corner if (i==0) ctl = cbr = tmp; // top left, bottom right corner
@ -3073,8 +3073,8 @@ void *transform_save(void *odata, int *size, matrix2d transform, vector2d transl
partst[i].x = nx; partst[i].x = nx;
partst[i].y = ny; partst[i].y = ny;
} }
for (y=0;y<YRES/CELL;y++) for (y=0; y<YRES/CELL; y++)
for (x=0;x<XRES/CELL;x++) for (x=0; x<XRES/CELL; x++)
{ {
pos = v2d_new(x*CELL+CELL*0.4f, y*CELL+CELL*0.4f); pos = v2d_new(x*CELL+CELL*0.4f, y*CELL+CELL*0.4f);
pos = v2d_add(m2d_multiply_v2d(transform,pos),translate); pos = v2d_add(m2d_multiply_v2d(transform,pos),translate);