A cracker commit with some nice comments

This commit is contained in:
Simon 2011-03-30 18:57:49 +01:00
parent 3863a75877
commit b7a004986f
16 changed files with 265 additions and 189 deletions

View File

@ -56,7 +56,7 @@ static menu_wall mwalls[] =
#define SC_CRACKER2 13 #define SC_CRACKER2 13
#define SC_TOTAL 10 #define SC_TOTAL 10
static menu_section msections[] = static menu_section msections[] = //itemcount and doshow do not do anything currently.
{ {
{"\xC1", "Walls", 0, 1}, {"\xC1", "Walls", 0, 1},
{"\xC2", "Electronics", 0, 1}, {"\xC2", "Electronics", 0, 1},

View File

@ -14,7 +14,7 @@ float cb_pv[YRES/CELL][XRES/CELL], cb_opv[YRES/CELL][XRES/CELL];
float fvx[YRES/CELL][XRES/CELL], fvy[YRES/CELL][XRES/CELL]; float fvx[YRES/CELL][XRES/CELL], fvy[YRES/CELL][XRES/CELL];
void make_kernel(void) void make_kernel(void) //used for velocity
{ {
int i, j; int i, j;
float s = 0.0f; float s = 0.0f;
@ -34,9 +34,9 @@ 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) { if (airMode != 4) { //airMode 4 is no air/pressure update
for (i=0; i<YRES/CELL; i++) 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;
@ -52,7 +52,7 @@ if (airMode != 4) {
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++) for (i=0; i<XRES/CELL; i++) //reduces pressure/velocity on the edges every frame
{ {
pv[0][i] = pv[0][i]*0.8f; pv[0][i] = pv[0][i]*0.8f;
pv[1][i] = pv[1][i]*0.8f; pv[1][i] = pv[1][i]*0.8f;
@ -69,7 +69,7 @@ if (airMode != 4) {
vy[YRES/CELL-1][i] = vy[YRES/CELL-2][i]*0.9f; vy[YRES/CELL-1][i] = vy[YRES/CELL-2][i]*0.9f;
} }
for (j=1; j<YRES/CELL; j++) for (j=1; j<YRES/CELL; j++) //clear some velocities near walls
{ {
for (i=1; i<XRES/CELL; i++) for (i=1; i<XRES/CELL; i++)
{ {
@ -83,7 +83,7 @@ if (airMode != 4) {
} }
} }
for (y=1; y<YRES/CELL; y++) for (y=1; y<YRES/CELL; y++) //pressure adjustments from velocity
for (x=1; x<XRES/CELL; x++) for (x=1; x<XRES/CELL; x++)
{ {
dp = 0.0f; dp = 0.0f;
@ -93,7 +93,7 @@ if (airMode != 4) {
pv[y][x] += dp*AIR_TSTEPP; pv[y][x] += dp*AIR_TSTEPP;
} }
for (y=0; y<YRES/CELL-1; y++) for (y=0; y<YRES/CELL-1; y++) //velocity adjustments from pressure
for (x=0; x<XRES/CELL-1; x++) for (x=0; x<XRES/CELL-1; x++)
{ {
dx = dy = 0.0f; dx = dy = 0.0f;
@ -115,7 +115,7 @@ if (airMode != 4) {
vy[y][x] = 0; vy[y][x] = 0;
} }
for (y=0; y<YRES/CELL; y++) for (y=0; y<YRES/CELL; y++) //update velocity and pressure
for (x=0; x<XRES/CELL; x++) for (x=0; x<XRES/CELL; x++)
{ {
dx = 0.0f; dx = 0.0f;
@ -172,7 +172,7 @@ if (airMode != 4) {
dx += fvx[y][x]; dx += fvx[y][x];
dy += fvy[y][x]; dy += fvy[y][x];
} }
// pressure/velocity caps
if (dp > 256.0f) dp = 256.0f; if (dp > 256.0f) dp = 256.0f;
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;

View File

@ -20,7 +20,7 @@ int update_ACID(UPDATE_FUNC_ARGS) {
} }
else if (((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && ptypes[r&0xFF].hardness>(rand()%1000))&&parts[i].life>=50) else if (((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && ptypes[r&0xFF].hardness>(rand()%1000))&&parts[i].life>=50)
{ {
if (parts_avg(i, r>>8,PT_GLAS)!= PT_GLAS) if (parts_avg(i, r>>8,PT_GLAS)!= PT_GLAS)//GLAS protects stuff from acid
{ {
parts[i].life--; parts[i].life--;
kill_part(r>>8); kill_part(r>>8);

View File

@ -23,27 +23,28 @@ int update_ARAY(UPDATE_FUNC_ARGS) {
if (!r) { if (!r) {
int nr = create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_BRAY); int nr = create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_BRAY);
if (nr!=-1) { if (nr!=-1) {
if (destroy) { if (destroy) {//if it came from PSCN
parts[nr].tmp = 2; parts[nr].tmp = 2;
parts[nr].life = 2; parts[nr].life = 2;
} else } else
parts[nr].ctype = colored; parts[nr].ctype = colored;
} }
} else if (!destroy) { } else if (!destroy) {
if ((r&0xFF)==PT_BRAY&&parts[r>>8].tmp==0) { if ((r&0xFF)==PT_BRAY&&parts[r>>8].tmp==0) {//if it hits another BRAY that isn't red
if (nyy!=0 || nxx!=0) { if (nyy!=0 || nxx!=0) {
parts[r>>8].life = 1020; parts[r>>8].life = 1020;//makes it last a while
parts[r>>8].tmp = 1; parts[r>>8].tmp = 1;
if (!parts[r>>8].ctype) if (!parts[r>>8].ctype)//and colors it if it isn't already
parts[r>>8].ctype = colored; parts[r>>8].ctype = colored;
} }
docontinue = 0; docontinue = 0;//then stop it
} else if ((r&0xFF)==PT_BRAY&&parts[r>>8].tmp==1) { } else if ((r&0xFF)==PT_BRAY&&parts[r>>8].tmp==1) {//if it hits one that already was a long life, reset it
parts[r>>8].life = 1020; parts[r>>8].life = 1020;
//docontinue = 1; //docontinue = 1;
} }
else if ((r&0xFF)==PT_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
} 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);
@ -58,6 +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
} 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

@ -44,7 +44,7 @@ int update_BOMB(UPDATE_FUNC_ARGS) {
for (nxi=-rad; nxi<=rad; nxi++) for (nxi=-rad; nxi<=rad; nxi++)
if ((pow(nxi,2))/(pow(rad,2))+(pow(nxj,2))/(pow(rad,2))<=1) if ((pow(nxi,2))/(pow(rad,2))+(pow(nxj,2))/(pow(rad,2))<=1)
if ((pmap[y+nxj][x+nxi]&0xFF)!=PT_DMND && (pmap[y+nxj][x+nxi]&0xFF)!=PT_CLNE && (pmap[y+nxj][x+nxi]&0xFF)!=PT_PCLN && (pmap[y+nxj][x+nxi]&0xFF)!=PT_BCLN) { if ((pmap[y+nxj][x+nxi]&0xFF)!=PT_DMND && (pmap[y+nxj][x+nxi]&0xFF)!=PT_CLNE && (pmap[y+nxj][x+nxi]&0xFF)!=PT_PCLN && (pmap[y+nxj][x+nxi]&0xFF)!=PT_BCLN) {
delete_part(x+nxi, y+nxj); delete_part(x+nxi, y+nxj);//it SHOULD kill anything but the exceptions above, doesn't seem to always work
pv[(y+nxj)/CELL][(x+nxi)/CELL] += 0.1f; pv[(y+nxj)/CELL][(x+nxi)/CELL] += 0.1f;
nb = create_part(-1, x+nxi, y+nxj, PT_BOMB); nb = create_part(-1, x+nxi, y+nxj, PT_BOMB);
if (nb!=-1) { if (nb!=-1) {

View File

@ -2,7 +2,7 @@
int update_ICEI(UPDATE_FUNC_ARGS) { //currently used for snow as well int update_ICEI(UPDATE_FUNC_ARGS) { //currently used for snow as well
int r, rx, ry; int r, rx, ry;
if (parts[i].ctype==PT_FRZW) if (parts[i].ctype==PT_FRZW)//get colder if it is from FRZW
{ {
parts[i].temp = restrict_flt(parts[i].temp-1.0f, MIN_TEMP, MAX_TEMP); parts[i].temp = restrict_flt(parts[i].temp-1.0f, MIN_TEMP, MAX_TEMP);
} }

View File

@ -40,7 +40,7 @@ int update_PCLN(UPDATE_FUNC_ARGS) {
(pmap[y+ry][x+rx]&0xFF)!=0xFF) (pmap[y+ry][x+rx]&0xFF)!=0xFF)
parts[i].ctype = pmap[y+ry][x+rx]&0xFF; parts[i].ctype = pmap[y+ry][x+rx]&0xFF;
if (parts[i].ctype && parts[i].life==10) { if (parts[i].ctype && parts[i].life==10) {
if (parts[i].ctype==PT_PHOT) { if (parts[i].ctype==PT_PHOT) {//create photons a different way
for (rx=-1; rx<2; rx++) { for (rx=-1; rx<2; rx++) {
for (ry=-1; ry<2; ry++) { for (ry=-1; ry<2; ry++) {
int r = create_part(-1, x+rx, y+ry, parts[i].ctype); int r = create_part(-1, x+rx, y+ry, parts[i].ctype);
@ -51,7 +51,7 @@ int update_PCLN(UPDATE_FUNC_ARGS) {
} }
} }
} }
else if (ptypes[parts[i].ctype].properties&PROP_LIFE) { else if (ptypes[parts[i].ctype].properties&PROP_LIFE) {//create life a different way
for (rx=-1; rx<2; rx++) { for (rx=-1; rx<2; rx++) {
for (ry=-1; ry<2; ry++) { for (ry=-1; ry<2; ry++) {
create_part(-1, x+rx, y+ry, parts[i].ctype); create_part(-1, x+rx, y+ry, parts[i].ctype);

View File

@ -4,7 +4,7 @@ int update_PIPE(UPDATE_FUNC_ARGS) {
int r, rx, ry, np, trade, q, ctype; int r, rx, ry, np, trade, q, ctype;
if (!parts[i].ctype && parts[i].life<=10) if (!parts[i].ctype && parts[i].life<=10)
{ {
if (parts[i].temp<272.15) if (parts[i].temp<272.15)//manual pipe colors
{ {
if (parts[i].temp>173.25&&parts[i].temp<273.15) if (parts[i].temp>173.25&&parts[i].temp<273.15)
{ {
@ -32,13 +32,13 @@ int update_PIPE(UPDATE_FUNC_ARGS) {
if ((r>>8)>=NPART ) if ((r>>8)>=NPART )
continue; continue;
if (!r) if (!r)
create_part(-1,x+rx,y+ry,PT_BRCK); create_part(-1,x+rx,y+ry,PT_BRCK);//BRCK border, people didn't like DMND
} }
if (parts[i].life==1) if (parts[i].life==1)
parts[i].ctype = 1; parts[i].ctype = 1;
} }
} }
if (parts[i].ctype==1) if (parts[i].ctype==1)//waiting for empty space
{ {
for (rx=-1; rx<2; rx++) for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++) for (ry=-1; ry<2; ry++)

View File

@ -1,5 +1,14 @@
#include <element.h> #include <element.h>
/*these are the count vaules of where the particle gets stored, depending on where it came from
1 4 6
2 . 7
3 5 8
PRTO counts backwards, so that it will come out at the opposite place of where it came in
8 5 3
7 . 2
6 4 1
PRTO does +/-1 to the count, so it doesn't jam as easily
*/
int update_PRTI(UPDATE_FUNC_ARGS) { int update_PRTI(UPDATE_FUNC_ARGS) {
int r, nnx, rx, ry, fe = 0; int r, nnx, rx, ry, fe = 0;
int count =0; int count =0;

View File

@ -1,5 +1,14 @@
#include <element.h> #include <element.h>
/*these are the count vaules of where the particle gets stored, depending on where it came from
1 4 6
2 . 7
3 5 8
PRTO counts backwards, so that it will come out at the opposite place of where it came in
8 5 3
7 . 2
6 4 1
PRTO does +/-1 to the count, so it doesn't jam as easily
*/
int update_PRTO(UPDATE_FUNC_ARGS) { int update_PRTO(UPDATE_FUNC_ARGS) {
int r, nnx, rx, ry, np, fe = 0; int r, nnx, rx, ry, np, fe = 0;
int count = 0; int count = 0;
@ -20,12 +29,12 @@ int update_PRTO(UPDATE_FUNC_ARGS) {
{ {
for ( nnx =0 ; nnx<80; nnx++) for ( nnx =0 ; nnx<80; nnx++)
{ {
int randomness = count + rand()%3-1; int randomness = count + rand()%3-1;//add -1,0,or 1 to count
if (randomness<1) if (randomness<1)
randomness=1; randomness=1;
if (randomness>9) if (randomness>8)
randomness=9; randomness=8;
if (portal[parts[i].tmp][randomness-1][nnx]==PT_SPRK)// TODO: make it look better if (portal[parts[i].tmp][randomness-1][nnx]==PT_SPRK)// TODO: make it look better, spark creation
{ {
create_part(-1,x+1,y,portal[parts[i].tmp][randomness-1][nnx]); create_part(-1,x+1,y,portal[parts[i].tmp][randomness-1][nnx]);
create_part(-1,x+1,y+1,portal[parts[i].tmp][randomness-1][nnx]); create_part(-1,x+1,y+1,portal[parts[i].tmp][randomness-1][nnx]);

View File

@ -12,6 +12,7 @@ int update_QRTZ(UPDATE_FUNC_ARGS) {
part_change_type(i,x,y,PT_PQRT); part_change_type(i,x,y,PT_PQRT);
} }
} }
//new QRTZ growth
for (rx=-2; rx<3 && parts[i].ctype!=-1; rx++) for (rx=-2; rx<3 && parts[i].ctype!=-1; 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))

View File

@ -25,10 +25,12 @@ int update_SWCH(UPDATE_FUNC_ARGS) {
} }
} }
} }
//turn off SWCH from two red BRAYS
if (parts[i].life==10 && (!(pmap[y-1][x-1]&0xFF) && ((pmap[y-1][x]&0xFF)==PT_BRAY&&parts[pmap[y-1][x]>>8].tmp==2) && !(pmap[y-1][x+1]&0xFF) && ((pmap[y][x+1]&0xFF)==PT_BRAY&&parts[pmap[y][x+1]>>8].tmp==2))) if (parts[i].life==10 && (!(pmap[y-1][x-1]&0xFF) && ((pmap[y-1][x]&0xFF)==PT_BRAY&&parts[pmap[y-1][x]>>8].tmp==2) && !(pmap[y-1][x+1]&0xFF) && ((pmap[y][x+1]&0xFF)==PT_BRAY&&parts[pmap[y][x+1]>>8].tmp==2)))
{ {
parts[i].life = 9; parts[i].life = 9;
} }
//turn on SWCH from two red BRAYS
else if (parts[i].life<=5 && (!(pmap[y-1][x-1]&0xFF) && (((pmap[y-1][x]&0xFF)==PT_BRAY&&parts[pmap[y-1][x]>>8].tmp==2) || ((pmap[y+1][x]&0xFF)==PT_BRAY&&parts[pmap[y+1][x]>>8].tmp==2)) && !(pmap[y-1][x+1]&0xFF) && (((pmap[y][x+1]&0xFF)==PT_BRAY&&parts[pmap[y][x+1]>>8].tmp==2) || ((pmap[y][x-1]&0xFF)==PT_BRAY&&parts[pmap[y][x-1]>>8].tmp==2)))) else if (parts[i].life<=5 && (!(pmap[y-1][x-1]&0xFF) && (((pmap[y-1][x]&0xFF)==PT_BRAY&&parts[pmap[y-1][x]>>8].tmp==2) || ((pmap[y+1][x]&0xFF)==PT_BRAY&&parts[pmap[y+1][x]>>8].tmp==2)) && !(pmap[y-1][x+1]&0xFF) && (((pmap[y][x+1]&0xFF)==PT_BRAY&&parts[pmap[y][x+1]>>8].tmp==2) || ((pmap[y][x-1]&0xFF)==PT_BRAY&&parts[pmap[y][x-1]>>8].tmp==2))))
{ {
parts[i].life = 14; parts[i].life = 14;

View File

@ -128,6 +128,7 @@ void sdl_blit(int x, int y, int w, int h, pixel *src, int pitch)
#endif #endif
} }
//an easy way to draw a blob
void drawblob(pixel *vid, int x, int y, unsigned char cr, unsigned char cg, unsigned char cb) void drawblob(pixel *vid, int x, int y, unsigned char cr, unsigned char cg, unsigned char cb)
{ {
blendpixel(vid, x+1, y, cr, cg, cb, 112); blendpixel(vid, x+1, y, cr, cg, cb, 112);
@ -141,6 +142,8 @@ void drawblob(pixel *vid, int x, int y, unsigned char cr, unsigned char cg, unsi
blendpixel(vid, x-1, y+1, cr, cg, cb, 64); blendpixel(vid, x-1, y+1, cr, cg, cb, 64);
} }
//old and unused equation to draw walls
/*
void draw_tool(pixel *vid_buf, int b, int sl, int sr, unsigned pc, unsigned iswall) void draw_tool(pixel *vid_buf, int b, int sl, int sr, unsigned pc, unsigned iswall)
{ {
int x, y, i, j, c; int x, y, i, j, c;
@ -444,7 +447,8 @@ void draw_tool(pixel *vid_buf, int b, int sl, int sr, unsigned pc, unsigned iswa
} }
} }
} }
*/
//draw walls
int draw_tool_xy(pixel *vid_buf, int x, int y, int b, unsigned pc) int draw_tool_xy(pixel *vid_buf, int x, int y, int b, unsigned pc)
{ {
int i, j, c; int i, j, c;
@ -763,6 +767,7 @@ void draw_menu(pixel *vid_buf, int i, int hover)
} }
} }
//draws a pixel, identical to blendpixel(), except blendpixel has OpenGL support
#if defined(WIN32) && !defined(__GNUC__) #if defined(WIN32) && !defined(__GNUC__)
_inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a) _inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
#else #else
@ -923,6 +928,7 @@ int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, i
return rh; return rh;
} }
//draws a rectange, (x,y) are the top left coords.
void drawrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a) void drawrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a)
{ {
#ifdef OpenGL #ifdef OpenGL
@ -948,6 +954,7 @@ void drawrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a
#endif #endif
} }
//draws a rectangle and fills it in as well.
void fillrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a) void fillrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a)
{ {
#ifdef OpenGL #ifdef OpenGL
@ -972,6 +979,7 @@ void clearrect(pixel *vid, int x, int y, int w, int h)
for (i=1; i<h; i++) for (i=1; i<h; i++)
memset(vid+(x+1+(XRES+BARSIZE)*(y+i)), 0, PIXELSIZE*(w-1)); memset(vid+(x+1+(XRES+BARSIZE)*(y+i)), 0, PIXELSIZE*(w-1));
} }
//draws a line of dots, where h is the height. (why is this even here)
void drawdots(pixel *vid, int x, int y, int h, int r, int g, int b, int a) void drawdots(pixel *vid, int x, int y, int h, int r, int g, int b, int a)
{ {
#ifdef OpenGL #ifdef OpenGL
@ -1097,6 +1105,7 @@ int textposxy(char *s, int width, int w, int h)
return n; return n;
} }
//the most used function for drawing a pixel, because it has OpenGL support, which is not fully implemented.
#if defined(WIN32) && !defined(__GNUC__) #if defined(WIN32) && !defined(__GNUC__)
_inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a) _inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
#else #else
@ -1150,7 +1159,7 @@ void draw_air(pixel *vid)
int x, y, i, j; int x, y, i, j;
pixel c; pixel c;
if (cmode == CM_PERS) if (cmode == CM_PERS)//this should never happen anyway
return; return;
for (y=0; y<YRES/CELL; y++) for (y=0; y<YRES/CELL; y++)
@ -1159,27 +1168,28 @@ void draw_air(pixel *vid)
if (cmode == CM_PRESS) if (cmode == CM_PRESS)
{ {
if (pv[y][x] > 0.0f) if (pv[y][x] > 0.0f)
c = PIXRGB(clamp_flt(pv[y][x], 0.0f, 8.0f), 0, 0); c = PIXRGB(clamp_flt(pv[y][x], 0.0f, 8.0f), 0, 0);//positive pressure is red!
else else
c = PIXRGB(0, 0, clamp_flt(-pv[y][x], 0.0f, 8.0f)); c = PIXRGB(0, 0, clamp_flt(-pv[y][x], 0.0f, 8.0f));//negative pressure is blue!
} }
else if (cmode == CM_VEL) else if (cmode == CM_VEL)
{ {
c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f), c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red
clamp_flt(pv[y][x], 0.0f, 8.0f), clamp_flt(pv[y][x], 0.0f, 8.0f),//pressure adds green
clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f)); clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue
} }
else if (cmode == CM_CRACK) else if (cmode == CM_CRACK)
{ {
int r; int r;
int g; int g;
int b; int b;
// velocity adds grey
r = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f); r = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f);
g = clamp_flt(fabsf(vx[y][x]), 0.0f, 20.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 24.0f); g = clamp_flt(fabsf(vx[y][x]), 0.0f, 20.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 24.0f);
b = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f); b = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f);
if (pv[y][x] > 0.0f) if (pv[y][x] > 0.0f)
{ {
r += clamp_flt(pv[y][x], 0.0f, 16.0f); r += clamp_flt(pv[y][x], 0.0f, 16.0f);//pressure adds red!
if (r>255) if (r>255)
r=255; r=255;
if (g>255) if (g>255)
@ -1190,7 +1200,7 @@ void draw_air(pixel *vid)
} }
else else
{ {
b += clamp_flt(-pv[y][x], 0.0f, 16.0f); b += clamp_flt(-pv[y][x], 0.0f, 16.0f);//pressure adds blue!
if (r>255) if (r>255)
r=255; r=255;
if (g>255) if (g>255)
@ -1200,7 +1210,7 @@ void draw_air(pixel *vid)
c = PIXRGB(r, g, b); c = PIXRGB(r, g, b);
} }
} }
for (j=0; j<CELL; j++) for (j=0; j<CELL; j++)//draws the colors
for (i=0; i<CELL; i++) for (i=0; i<CELL; i++)
vid[(x*CELL+i) + (y*CELL+j)*(XRES+BARSIZE)] = c; vid[(x*CELL+i) + (y*CELL+j)*(XRES+BARSIZE)] = c;
} }
@ -1246,6 +1256,7 @@ void draw_line(pixel *vid, int x1, int y1, int x2, int y2, int r, int g, int b,
} }
} }
//adds color to a pixel, does not overwrite.
void addpixel(pixel *vid, int x, int y, int r, int g, int b, int a) void addpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
{ {
pixel t; pixel t;
@ -1264,6 +1275,7 @@ void addpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b); vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b);
} }
//draws one of two colors, so that it is always clearly visible
void xor_pixel(int x, int y, pixel *vid) void xor_pixel(int x, int y, pixel *vid)
{ {
int c; int c;
@ -1277,6 +1289,7 @@ void xor_pixel(int x, int y, pixel *vid)
vid[y*(XRES+BARSIZE)+x] = PIXPACK(0x404040); vid[y*(XRES+BARSIZE)+x] = PIXPACK(0x404040);
} }
//same as xor_pixel, but draws a line of it
void xor_line(int x1, int y1, int x2, int y2, pixel *vid) void xor_line(int x1, int y1, int x2, int y2, pixel *vid)
{ {
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;
@ -1323,6 +1336,7 @@ void xor_line(int x1, int y1, int x2, int y2, pixel *vid)
} }
} }
//same as xor_pixel, but draws a rectangle
void xor_rect(pixel *vid, int x, int y, int w, int h) void xor_rect(pixel *vid, int x, int y, int w, int h)
{ {
int i; int i;
@ -1338,6 +1352,7 @@ void xor_rect(pixel *vid, int x, int y, int w, int h)
} }
} }
//the main function for drawing the particles
void draw_parts(pixel *vid) void draw_parts(pixel *vid)
{ {
int i, x, y, t, nx, ny, r, s; int i, x, y, t, nx, ny, r, s;
@ -1346,7 +1361,7 @@ void draw_parts(pixel *vid)
int cr, cg, cb; int cr, cg, cb;
float fr, fg, fb; float fr, fg, fb;
float pt = R_TEMP; float pt = R_TEMP;
if (GRID_MODE) if (GRID_MODE)//draws the grid
{ {
for (ny=0; ny<YRES; ny++) for (ny=0; ny<YRES; ny++)
for (nx=0; nx<XRES; nx++) for (nx=0; nx<XRES; nx++)
@ -1499,7 +1514,7 @@ void draw_parts(pixel *vid)
blendpixel(vid, nx, ny, cr, cg, cb, 255); blendpixel(vid, nx, ny, cr, cg, cb, 255);
} }
} }
else if (cmode==CM_GRAD)//forgot to put else, broke nothing view else if (cmode==CM_GRAD)
{ {
float frequency = 0.05; float frequency = 0.05;
int q = parts[i].temp-40; int q = parts[i].temp-40;
@ -1520,7 +1535,7 @@ void draw_parts(pixel *vid)
cb = 0; cb = 0;
blendpixel(vid, nx, ny, cr, cg, cb, 255); blendpixel(vid, nx, ny, cr, cg, cb, 255);
} }
else if (cmode==CM_FANCY && else if (cmode==CM_FANCY && //all fancy mode effects go here, this is a list of exceptions to skip
t!=PT_FIRE && t!=PT_PLSM && t!=PT_WTRV && t!=PT_FIRE && t!=PT_PLSM && t!=PT_WTRV &&
t!=PT_HFLM && t!=PT_SPRK && t!=PT_FIRW && t!=PT_HFLM && t!=PT_SPRK && t!=PT_FIRW &&
t!=PT_DUST && t!=PT_FIRW && t!=PT_FWRK && t!=PT_DUST && t!=PT_FIRW && t!=PT_FWRK &&
@ -1529,7 +1544,7 @@ void draw_parts(pixel *vid)
t!=PT_LCRY && t!=PT_SWCH && t!=PT_PCLN && t!=PT_LCRY && t!=PT_SWCH && t!=PT_PCLN &&
t!=PT_PUMP && t!=PT_HSWC && t!=PT_FILT) t!=PT_PUMP && t!=PT_HSWC && t!=PT_FILT)
{ {
if (ptypes[parts[i].type].properties&TYPE_LIQUID) if (ptypes[parts[i].type].properties&TYPE_LIQUID) //special effects for liquids in fancy mode
{ {
if (parts[i].type==PT_DEUT) if (parts[i].type==PT_DEUT)
{ {
@ -1675,7 +1690,7 @@ void draw_parts(pixel *vid)
} }
} }
} }
else else //if no fancy effects, draw a simple pixel
{ {
vid[ny*(XRES+BARSIZE)+nx] = ptypes[t].pcolors; vid[ny*(XRES+BARSIZE)+nx] = ptypes[t].pcolors;
} }
@ -1707,8 +1722,8 @@ void draw_parts(pixel *vid)
} }
else if (t==PT_QRTZ || t==PT_PQRT) else if (t==PT_QRTZ || t==PT_PQRT)
{ {
int z = parts[i].tmp - 5; int z = parts[i].tmp - 5;//speckles!
if (parts[i].temp>(ptransitions[t].thv-800.0f)) if (parts[i].temp>(ptransitions[t].thv-800.0f))//hotglow for quartz
{ {
float frequency = 3.1415/(2*ptransitions[t].thv-(ptransitions[t].thv-800.0f)); float frequency = 3.1415/(2*ptransitions[t].thv-(ptransitions[t].thv-800.0f));
int q = (parts[i].temp>ptransitions[t].thv)?ptransitions[t].thv-(ptransitions[t].thv-800.0f):parts[i].temp-(ptransitions[t].thv-800.0f); int q = (parts[i].temp>ptransitions[t].thv)?ptransitions[t].thv-(ptransitions[t].thv-800.0f):parts[i].temp-(ptransitions[t].thv-800.0f);
@ -1754,7 +1769,7 @@ 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) 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);
@ -1763,14 +1778,14 @@ void draw_parts(pixel *vid)
else else
blendpixel(vid, nx, ny, 255, 0, 0, 255); blendpixel(vid, nx, ny, 255, 0, 0, 255);
} }
else if(t==PT_FRG2) 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) 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);
@ -1783,14 +1798,14 @@ void draw_parts(pixel *vid)
else else
blendpixel(vid, nx, ny, 0, 0, 70, 255); blendpixel(vid, nx, ny, 0, 0, 70, 255);
} }
else if(t==PT_FROG) 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) 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);
@ -1833,13 +1848,13 @@ void draw_parts(pixel *vid)
} }
} }
else if (t==PT_DUST && parts[i].life >= 1) else if (t==PT_DUST && parts[i].life >= 1)//dust colors!
{ {
x = nx; x = nx;
y = ny; y = ny;
if (cmode == CM_FIRE||cmode==CM_BLOB || cmode==CM_FANCY) if (cmode == CM_FIRE||cmode==CM_BLOB || cmode==CM_FANCY)
{ {
vid[ny*(XRES+BARSIZE)+nx] = PIXRGB(parts[i].tmp,parts[i].ctype,parts[i].flags); vid[ny*(XRES+BARSIZE)+nx] = PIXRGB(parts[i].tmp,parts[i].ctype,parts[i].flags);//yes i know this pixel is different color than the glow... i don't know why
cg = parts[i].tmp/4; cg = parts[i].tmp/4;
cb = parts[i].ctype/4; cb = parts[i].ctype/4;
cr = parts[i].flags/4; cr = parts[i].flags/4;
@ -1911,7 +1926,7 @@ void draw_parts(pixel *vid)
cg = sin(frequency*q + 2) * 127 + 128; cg = sin(frequency*q + 2) * 127 + 128;
cb = sin(frequency*q + 4) * 127 + 128; cb = sin(frequency*q + 4) * 127 + 128;
blendpixel(vid, nx, ny, cr, cg, cb, 255); blendpixel(vid, nx, ny, cr, cg, cb, 255);
if (mousex==(nx) && mousey==(ny) && DEBUG_MODE) if (mousex==(nx) && mousey==(ny) && DEBUG_MODE)//draw lines connecting wifi channels
{ {
int z; int z;
for (z = 0; z<NPART; z++) { for (z = 0; z<NPART; z++) {
@ -1945,7 +1960,7 @@ void draw_parts(pixel *vid)
} }
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){ 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))
{ {
@ -1982,7 +1997,7 @@ void draw_parts(pixel *vid)
} }
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){ 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))
{ {
@ -2859,10 +2874,10 @@ void draw_parts(pixel *vid)
fire_b[y][x] = cb; fire_b[y][x] = cb;
} }
} }
else else //if no special effect, draw a simple pixel
vid[ny*(XRES+BARSIZE)+nx] = ptypes[t].pcolors; vid[ny*(XRES+BARSIZE)+nx] = ptypes[t].pcolors;
} }
else else //heat view
{ {
float ttemp = parts[i].temp+(-MIN_TEMP); float ttemp = parts[i].temp+(-MIN_TEMP);
int caddress = restrict_flt((int)( restrict_flt(ttemp, 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3); int caddress = restrict_flt((int)( restrict_flt(ttemp, 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3);
@ -2926,6 +2941,7 @@ void draw_parts(pixel *vid)
//blendpixel(vid, nx+1, ny, R, G, B, 255); //blendpixel(vid, nx+1, ny, R, G, B, 255);
} }
} }
//blob view!
if (cmode == CM_BLOB&&t!=PT_FIRE&&t!=PT_PLSM&&t!=PT_HFLM&&t!=PT_NONE&&t!=PT_ACID&&t!=PT_LCRY&&t!=PT_GLOW&&t!=PT_SWCH&&t!=PT_SMKE&&t!=PT_WTRV&&!(t==PT_FIRW&&parts[i].tmp==3)) if (cmode == CM_BLOB&&t!=PT_FIRE&&t!=PT_PLSM&&t!=PT_HFLM&&t!=PT_NONE&&t!=PT_ACID&&t!=PT_LCRY&&t!=PT_GLOW&&t!=PT_SWCH&&t!=PT_SMKE&&t!=PT_WTRV&&!(t==PT_FIRW&&parts[i].tmp==3))
{ {
if (t==PT_PHOT) { if (t==PT_PHOT) {
@ -2974,6 +2990,7 @@ void draw_parts(pixel *vid)
} }
//draws the photon colors in the HUD
void draw_wavelengths(pixel *vid, int x, int y, int h, int wl) 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;
@ -3161,7 +3178,7 @@ void draw_image(pixel *vid, pixel *img, int x, int y, int w, int h, int a)
} }
} }
void dim_copy(pixel *dst, pixel *src) void dim_copy(pixel *dst, pixel *src) //old persistent, unused
{ {
int i,r,g,b; int i,r,g,b;
for (i=0; i<XRES*YRES; i++) for (i=0; i<XRES*YRES; i++)
@ -3179,7 +3196,7 @@ void dim_copy(pixel *dst, pixel *src)
} }
} }
void dim_copy_pers(pixel *dst, pixel *src) void dim_copy_pers(pixel *dst, pixel *src) //for persistent view, reduces rgb slowly
{ {
int i,r,g,b; int i,r,g,b;
for (i=0; i<(XRES+BARSIZE)*YRES; i++) for (i=0; i<(XRES+BARSIZE)*YRES; i++)
@ -3197,7 +3214,7 @@ void dim_copy_pers(pixel *dst, pixel *src)
} }
} }
void render_zoom(pixel *img) void render_zoom(pixel *img) //draws the zoom box
{ {
int x, y, i, j; int x, y, i, j;
pixel pix; pixel pix;
@ -3227,6 +3244,7 @@ void render_zoom(pixel *img)
} }
} }
//gets the thumbnail preview for stamps
pixel *prerender_save(void *save, int size, int *width, int *height) pixel *prerender_save(void *save, int size, int *width, int *height)
{ {
unsigned char *d,*c=save; unsigned char *d,*c=save;
@ -3511,6 +3529,7 @@ corrupt:
return 1; return 1;
} }
//draws the cursor
void render_cursor(pixel *vid, int x, int y, int t, int rx, int ry) void render_cursor(pixel *vid, int x, int y, int t, int rx, int ry)
{ {
int i,j,c; int i,j,c;
@ -3545,7 +3564,7 @@ void render_cursor(pixel *vid, int x, int y, int t, int rx, int ry)
if (i&&j) xor_pixel(x-i, y-j, vid); if (i&&j) xor_pixel(x-i, y-j, vid);
} }
} }
else else //wall cursor
{ {
int tc; int tc;
c = (rx/CELL) * CELL; c = (rx/CELL) * CELL;

View File

@ -68,7 +68,7 @@ int zoom_wx=0, zoom_wy=0;
unsigned char ZFACTOR = 256/ZSIZE_D; unsigned char ZFACTOR = 256/ZSIZE_D;
unsigned char ZSIZE = ZSIZE_D; unsigned char ZSIZE = ZSIZE_D;
void menu_count(void) void menu_count(void)// never used
{ {
int i=0; int i=0;
msections[SC_WALL].itemcount = UI_WALLCOUNT-4; msections[SC_WALL].itemcount = UI_WALLCOUNT-4;
@ -467,17 +467,20 @@ void ui_checkbox_process(int mx, int my, int mb, int mbq, ui_checkbox *ed)
} }
} }
void draw_svf_ui(pixel *vid_buf) void draw_svf_ui(pixel *vid_buf)// all the buttons at the bottom
{ {
int c; int c;
drawtext(vid_buf, 4, YRES+(MENUSIZE-14), "\x81", 255, 255, 255, 255); //the open browser button
drawtext(vid_buf, 4, YRES+(MENUSIZE-14), "\x81", 255, 255, 255, 255);
drawrect(vid_buf, 1, YRES+(MENUSIZE-16), 16, 14, 255, 255, 255, 255); drawrect(vid_buf, 1, YRES+(MENUSIZE-16), 16, 14, 255, 255, 255, 255);
// the reload button
c = svf_open ? 255 : 128; c = svf_open ? 255 : 128;
drawtext(vid_buf, 23, YRES+(MENUSIZE-14), "\x91", c, c, c, 255); drawtext(vid_buf, 23, YRES+(MENUSIZE-14), "\x91", c, c, c, 255);
drawrect(vid_buf, 19, YRES+(MENUSIZE-16), 16, 14, c, c, c, 255); drawrect(vid_buf, 19, YRES+(MENUSIZE-16), 16, 14, c, c, c, 255);
// the save sim button
c = svf_login ? 255 : 128; c = svf_login ? 255 : 128;
drawtext(vid_buf, 40, YRES+(MENUSIZE-14), "\x82", c, c, c, 255); drawtext(vid_buf, 40, YRES+(MENUSIZE-14), "\x82", c, c, c, 255);
if (svf_open) if (svf_open)
@ -490,6 +493,7 @@ void draw_svf_ui(pixel *vid_buf)
c = (svf_login && svf_open) ? 255 : 128; c = (svf_login && svf_open) ? 255 : 128;
//the vote buttons
drawrect(vid_buf, 189, YRES+(MENUSIZE-16), 14, 14, c, c, c, 255); drawrect(vid_buf, 189, YRES+(MENUSIZE-16), 14, 14, c, c, c, 255);
drawrect(vid_buf, 203, YRES+(MENUSIZE-16), 14, 14, c, c, c, 255); drawrect(vid_buf, 203, YRES+(MENUSIZE-16), 14, 14, c, c, c, 255);
@ -501,10 +505,10 @@ void draw_svf_ui(pixel *vid_buf)
{ {
fillrect(vid_buf, 203, YRES+(MENUSIZE-16), 14, 14, 108, 10, 0, 255); fillrect(vid_buf, 203, YRES+(MENUSIZE-16), 14, 14, 108, 10, 0, 255);
} }
drawtext(vid_buf, 192, YRES+(MENUSIZE-12), "\xCB", 0, 187, 18, c); drawtext(vid_buf, 192, YRES+(MENUSIZE-12), "\xCB", 0, 187, 18, c);
drawtext(vid_buf, 205, YRES+(MENUSIZE-14), "\xCA", 187, 40, 0, c); drawtext(vid_buf, 205, YRES+(MENUSIZE-14), "\xCA", 187, 40, 0, c);
//the tags button
drawtext(vid_buf, 222, YRES+(MENUSIZE-15), "\x83", c, c, c, 255); drawtext(vid_buf, 222, YRES+(MENUSIZE-15), "\x83", c, c, c, 255);
if (svf_tags[0]) if (svf_tags[0])
drawtextmax(vid_buf, 240, YRES+(MENUSIZE-12), XRES+BARSIZE-405, svf_tags, c, c, c, 255); drawtextmax(vid_buf, 240, YRES+(MENUSIZE-12), XRES+BARSIZE-405, svf_tags, c, c, c, 255);
@ -513,9 +517,11 @@ void draw_svf_ui(pixel *vid_buf)
drawrect(vid_buf, 219, YRES+(MENUSIZE-16), XRES+BARSIZE-380, 14, c, c, c, 255); drawrect(vid_buf, 219, YRES+(MENUSIZE-16), XRES+BARSIZE-380, 14, c, c, c, 255);
//the clear sim button------------some of the commented values are wrong
drawtext(vid_buf, XRES-139+BARSIZE/*371*/, YRES+(MENUSIZE-14), "\x92", 255, 255, 255, 255); drawtext(vid_buf, XRES-139+BARSIZE/*371*/, YRES+(MENUSIZE-14), "\x92", 255, 255, 255, 255);
drawrect(vid_buf, XRES-143+BARSIZE/*367*/, YRES+(MENUSIZE-16), 16, 14, 255, 255, 255, 255); drawrect(vid_buf, XRES-143+BARSIZE/*367*/, YRES+(MENUSIZE-16), 16, 14, 255, 255, 255, 255);
//the login button
drawtext(vid_buf, XRES-122+BARSIZE/*388*/, YRES+(MENUSIZE-13), "\x84", 255, 255, 255, 255); drawtext(vid_buf, XRES-122+BARSIZE/*388*/, YRES+(MENUSIZE-13), "\x84", 255, 255, 255, 255);
if (svf_login) if (svf_login)
drawtextmax(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), 66, svf_user, 255, 255, 255, 255); drawtextmax(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), 66, svf_user, 255, 255, 255, 255);
@ -523,6 +529,7 @@ void draw_svf_ui(pixel *vid_buf)
drawtext(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), "[sign in]", 255, 255, 255, 255); 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); drawrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14, 255, 255, 255, 255);
//te pause button
if (sys_pause) if (sys_pause)
{ {
fillrect(vid_buf, XRES-17+BARSIZE/*493*/, YRES+(MENUSIZE-17), 16, 16, 255, 255, 255, 255); fillrect(vid_buf, XRES-17+BARSIZE/*493*/, YRES+(MENUSIZE-17), 16, 16, 255, 255, 255, 255);
@ -534,6 +541,7 @@ void draw_svf_ui(pixel *vid_buf)
drawrect(vid_buf, XRES-16+BARSIZE/*494*/, YRES+(MENUSIZE-16), 14, 14, 255, 255, 255, 255); drawrect(vid_buf, XRES-16+BARSIZE/*494*/, YRES+(MENUSIZE-16), 14, 14, 255, 255, 255, 255);
} }
//the heat sim button
if (!legacy_enable) if (!legacy_enable)
{ {
fillrect(vid_buf, XRES-160+BARSIZE/*493*/, YRES+(MENUSIZE-17), 16, 16, 255, 255, 255, 255); fillrect(vid_buf, XRES-160+BARSIZE/*493*/, YRES+(MENUSIZE-17), 16, 16, 255, 255, 255, 255);
@ -546,6 +554,7 @@ void draw_svf_ui(pixel *vid_buf)
drawrect(vid_buf, XRES-159+BARSIZE/*494*/, YRES+(MENUSIZE-16), 14, 14, 255, 255, 255, 255); drawrect(vid_buf, XRES-159+BARSIZE/*494*/, YRES+(MENUSIZE-16), 14, 14, 255, 255, 255, 255);
} }
//the view mode button
switch (cmode) switch (cmode)
{ {
case CM_VEL: case CM_VEL:
@ -587,6 +596,7 @@ void draw_svf_ui(pixel *vid_buf)
} }
drawrect(vid_buf, XRES-32+BARSIZE/*478*/, YRES+(MENUSIZE-16), 14, 14, 255, 255, 255, 255); drawrect(vid_buf, XRES-32+BARSIZE/*478*/, YRES+(MENUSIZE-16), 14, 14, 255, 255, 255, 255);
// special icons for admin/mods
if (svf_admin) if (svf_admin)
{ {
drawtext(vid_buf, XRES-45+BARSIZE/*463*/, YRES+(MENUSIZE-14), "\xC9", 232, 127, 35, 255); drawtext(vid_buf, XRES-45+BARSIZE/*463*/, YRES+(MENUSIZE-14), "\xC9", 232, 127, 35, 255);
@ -1349,6 +1359,8 @@ int save_name_ui(pixel *vid_buf)
return 0; return 0;
} }
//unused old function, with all the elements drawn at the bottom
/*
void menu_ui(pixel *vid_buf, int i, int *sl, int *sr) void menu_ui(pixel *vid_buf, int i, int *sl, int *sr)
{ {
int b=1,bq,mx,my,h,x,y,n=0,height,width,sy,rows=0; int b=1,bq,mx,my,h,x,y,n=0,height,width,sy,rows=0;
@ -1542,7 +1554,8 @@ void menu_ui(pixel *vid_buf, int i, int *sl, int *sr)
} }
//drawtext(vid_buf, XRES+2, (12*i)+2, msections[i].icon, 255, 255, 255, 255); //drawtext(vid_buf, XRES+2, (12*i)+2, msections[i].icon, 255, 255, 255, 255);
} }
*/
//current menu function
void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int b, int bq, int mx, int my) void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int b, int bq, int mx, int my)
{ {
int h,x,y,n=0,height,width,sy,rows=0,xoff=0,fwidth; int h,x,y,n=0,height,width,sy,rows=0,xoff=0,fwidth;
@ -1557,7 +1570,7 @@ void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int b, int bq, int mx,
x = XRES-BARSIZE-18; x = XRES-BARSIZE-18;
y = YRES+1; y = YRES+1;
sy = y; sy = y;
if (i==SC_WALL) if (i==SC_WALL)//wall menu
{ {
for (n = UI_WALLSTART; n<UI_WALLSTART+UI_WALLCOUNT; n++) for (n = UI_WALLSTART; n<UI_WALLSTART+UI_WALLCOUNT; n++)
{ {
@ -1594,7 +1607,7 @@ void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int b, int bq, int mx,
} }
} }
} }
else if (i==SC_SPECIAL) else if (i==SC_SPECIAL)//special menu
{ {
for (n = UI_WALLSTART; n<UI_WALLSTART+UI_WALLCOUNT; n++) for (n = UI_WALLSTART; n<UI_WALLSTART+UI_WALLCOUNT; n++)
{ {
@ -1665,9 +1678,9 @@ void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int b, int bq, int mx,
} }
} }
} }
else else //all other menus
{ {
if (fwidth > XRES-BARSIZE){ 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);
} }
@ -1701,13 +1714,10 @@ void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int b, int bq, int mx,
} }
} }
} }
if (!bq&&mx>=sdl_scale*((XRES+BARSIZE)-16) && mx<sdl_scale*(XRES+BARSIZE-1) &&my>= sdl_scale*((i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16)) && my<sdl_scale*((i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16)+15)) if (!bq && mx>=((XRES+BARSIZE)-16) ) //highlight menu section
{
if (sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_SHIFT)) if (sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_SHIFT))
if (i>=0&&i<SC_TOTAL) if (i>=0&&i<SC_TOTAL)
SEC = i; SEC = i;
}
if (h==-1) if (h==-1)
{ {
@ -1721,7 +1731,8 @@ void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int b, int bq, int mx,
{ {
drawtext(vid_buf, XRES-textwidth((char *)ptypes[h].descs)-BARSIZE, sy-10, (char *)ptypes[h].descs, 255, 255, 255, 255); drawtext(vid_buf, XRES-textwidth((char *)ptypes[h].descs)-BARSIZE, sy-10, (char *)ptypes[h].descs, 255, 255, 255, 255);
} }
//these are click events, b=1 is left click, b=4 is right
//h has the value of the element it is over, and -1 if not over an element
if (b==1&&h==-1) if (b==1&&h==-1)
{ {
if (sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_SHIFT) && SEC>=0) if (sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_SHIFT) && SEC>=0)
@ -1871,7 +1882,7 @@ int sdl_poll(void)
return 0; return 0;
} }
void set_cmode(int cm) void set_cmode(int cm) // sets to given view mode
{ {
cmode = cm; cmode = cm;
itc = 51; itc = 51;
@ -1924,7 +1935,7 @@ void set_cmode(int cm)
} }
else if (cmode==CM_LIFE) else if (cmode==CM_LIFE)
{ {
if (DEBUG_MODE) if (DEBUG_MODE) //can only get to Life view in debug mode
{ {
strcpy(itc_msg, "Life Display"); strcpy(itc_msg, "Life Display");
} }
@ -1933,7 +1944,7 @@ void set_cmode(int cm)
set_cmode(CM_CRACK); set_cmode(CM_CRACK);
} }
} }
else else //if no special text given, it will display this.
{ {
strcpy(itc_msg, "Velocity Display"); strcpy(itc_msg, "Velocity Display");
} }
@ -3893,7 +3904,7 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
currentcommand2->command = mystrdup(error); currentcommand2->command = mystrdup(error);
last_command2 = currentcommand2; last_command2 = currentcommand2;
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); 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));
@ -4028,6 +4039,7 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) {
return NULL; return NULL;
} }
//takes a a string and compares it to element names, and puts it value into element.
int console_parse_type(char *txt, int *element, char *err) int console_parse_type(char *txt, int *element, char *err)
{ {
int i = -1; int i = -1;
@ -4052,6 +4064,7 @@ int console_parse_type(char *txt, int *element, char *err)
strcpy(err, "Particle type not recognised"); strcpy(err, "Particle type not recognised");
return 0; return 0;
} }
//takes a string of coords "x,y" and puts the values into x and y.
int console_parse_coords(char *txt, int *x, int *y, char *err) int console_parse_coords(char *txt, int *x, int *y, char *err)
{ {
// TODO: use regex? // TODO: use regex?
@ -4065,6 +4078,7 @@ int console_parse_coords(char *txt, int *x, int *y, char *err)
*y = ny; *y = ny;
return 1; return 1;
} }
//takes a string of either coords or a particle number, and puts the particle number into *which
int console_parse_partref(char *txt, int *which, char *err) int console_parse_partref(char *txt, int *which, char *err)
{ {
int i = -1, nx, ny; int i = -1, nx, ny;

View File

@ -87,6 +87,7 @@ void mixaudio(void *unused, Uint8 *stream, int len)
} }
} }
//plays a .wav file (sounds must be enabled)
void play_sound(char *file) void play_sound(char *file)
{ {
int index; int index;
@ -310,6 +311,7 @@ void *build_thumb(int *size, int bzip2)
return d; return d;
} }
//the saving function
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) 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; unsigned char *d=calloc(1,3*(XRES/CELL)*(YRES/CELL)+(XRES*YRES)*11+MAXSIGNS*262), *c;
@ -1892,7 +1894,6 @@ static PyObject* emb_get_modifier(PyObject *self, PyObject *args)
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; int keydelay,keyinterval;
keydelay=SDL_DEFAULT_REPEAT_DELAY; keydelay=SDL_DEFAULT_REPEAT_DELAY;
keyinterval=SDL_DEFAULT_REPEAT_INTERVAL; keyinterval=SDL_DEFAULT_REPEAT_INTERVAL;
@ -1904,7 +1905,6 @@ static PyObject* emb_set_keyrepeat(PyObject *self, PyObject *args)
//delete_part //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; int x,y;
if(!PyArg_ParseTuple(args, "ii:delete",&x,&y)) if(!PyArg_ParseTuple(args, "ii:delete",&x,&y))
return NULL; return NULL;
@ -1914,7 +1914,6 @@ static PyObject* emb_delete(PyObject *self, PyObject *args)
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; int x,y,press;
if(!PyArg_ParseTuple(args, "iii:set_pressure",&x,&y,&press)) if(!PyArg_ParseTuple(args, "iii:set_pressure",&x,&y,&press))
return NULL; return NULL;
@ -1924,7 +1923,6 @@ static PyObject* emb_set_pressure(PyObject *self, PyObject *args)
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; int x,y,xv,yv;
if(!PyArg_ParseTuple(args, "iiii:set_velocity",&x,&y,&xv,&yv)) if(!PyArg_ParseTuple(args, "iiii:set_velocity",&x,&y,&xv,&yv))
return NULL; return NULL;
@ -2267,25 +2265,25 @@ int main(int argc, char *argv[])
http_auth_headers(http_session_check, svf_user_id, NULL, svf_session_id); http_auth_headers(http_session_check, svf_user_id, NULL, svf_session_id);
} }
while (!sdl_poll()) while (!sdl_poll()) //the main loop
{ {
if (!sys_pause||framerender) if (!sys_pause||framerender) //only update air if not paused
{ {
update_air(); update_air();
} }
#ifdef OpenGL #ifdef OpenGL
ClearScreen(); ClearScreen();
#else #else
if (cmode==CM_VEL || cmode==CM_PRESS || cmode==CM_CRACK) if (cmode==CM_VEL || cmode==CM_PRESS || cmode==CM_CRACK)//air only gets drawn in these modes
{ {
draw_air(vid_buf); draw_air(vid_buf);
} }
else if (cmode==CM_PERS) else if (cmode==CM_PERS)//save background for persistent, then clear
{ {
memcpy(vid_buf, pers_bg, (XRES+BARSIZE)*YRES*PIXELSIZE); memcpy(vid_buf, pers_bg, (XRES+BARSIZE)*YRES*PIXELSIZE);
memset(vid_buf+((XRES+BARSIZE)*YRES), 0, ((XRES+BARSIZE)*YRES*PIXELSIZE)-((XRES+BARSIZE)*YRES*PIXELSIZE)); memset(vid_buf+((XRES+BARSIZE)*YRES), 0, ((XRES+BARSIZE)*YRES*PIXELSIZE)-((XRES+BARSIZE)*YRES*PIXELSIZE));
} }
else else //clear screen every frame
{ {
memset(vid_buf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE); memset(vid_buf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
} }
@ -2301,12 +2299,12 @@ int main(int argc, char *argv[])
if (bsy<0) if (bsy<0)
bsy = 0; bsy = 0;
update_particles(vid_buf); update_particles(vid_buf); //update everything
draw_parts(vid_buf); draw_parts(vid_buf); //draw particles
if (cmode==CM_PERS) if (cmode==CM_PERS)
{ {
if (!fire_fc) if (!fire_fc)//fire_fc has nothing to do with fire... it is a counter for diminishing persistent view every 3 frames
{ {
dim_copy_pers(pers_bg, vid_buf); dim_copy_pers(pers_bg, vid_buf);
} }
@ -2321,7 +2319,7 @@ int main(int argc, char *argv[])
render_signs(vid_buf); render_signs(vid_buf);
memset(vid_buf+((XRES+BARSIZE)*YRES), 0, (PIXELSIZE*(XRES+BARSIZE))*MENUSIZE); memset(vid_buf+((XRES+BARSIZE)*YRES), 0, (PIXELSIZE*(XRES+BARSIZE))*MENUSIZE);//clear menu areas
clearrect(vid_buf, XRES-1, 0, BARSIZE+1, YRES); clearrect(vid_buf, XRES-1, 0, BARSIZE+1, YRES);
draw_svf_ui(vid_buf); draw_svf_ui(vid_buf);
@ -2433,7 +2431,7 @@ int main(int argc, char *argv[])
do_s_check = (do_s_check+1) & 15; do_s_check = (do_s_check+1) & 15;
} }
if(sys_shortcuts==1) if(sys_shortcuts==1)//all shortcuts can be disabled by python scripts
{ {
if (sdl_key=='q' || sdl_key==SDLK_ESCAPE) if (sdl_key=='q' || sdl_key==SDLK_ESCAPE)
{ {
@ -2807,7 +2805,7 @@ int main(int argc, char *argv[])
#endif #endif
#ifdef INTERNAL #ifdef INTERNAL
int counterthing; int counterthing;
if (sdl_key=='v'&&!(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))) if (sdl_key=='v'&&!(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)))//frame capture
{ {
if (sdl_mod & (KMOD_SHIFT)) { if (sdl_mod & (KMOD_SHIFT)) {
if (vs>=1) if (vs>=1)
@ -2837,7 +2835,7 @@ int main(int argc, char *argv[])
if (sdl_wheel) if (sdl_wheel)
{ {
if (sdl_zoom_trig==1) if (sdl_zoom_trig==1)//zoom window change
{ {
ZSIZE += sdl_wheel; ZSIZE += sdl_wheel;
if (ZSIZE>60) if (ZSIZE>60)
@ -2847,7 +2845,7 @@ int main(int argc, char *argv[])
ZFACTOR = 256/ZSIZE; ZFACTOR = 256/ZSIZE;
sdl_wheel = 0; sdl_wheel = 0;
} }
else else //change brush size
{ {
if (!(sdl_mod & (KMOD_SHIFT|KMOD_CTRL))) if (!(sdl_mod & (KMOD_SHIFT|KMOD_CTRL)))
{ {
@ -2880,24 +2878,24 @@ int main(int argc, char *argv[])
} }
} }
bq = b; bq = b; // bq is previous mouse state
b = SDL_GetMouseState(&x, &y); b = SDL_GetMouseState(&x, &y); // b is current mouse state
for (i=0; i<SC_TOTAL; i++) for (i=0; i<SC_TOTAL; i++)//draw all the menu sections
{ {
draw_menu(vid_buf, i, active_menu); draw_menu(vid_buf, i, active_menu);
} }
for (i=0; i<SC_TOTAL; i++) for (i=0; i<SC_TOTAL; i++)//check mouse position to see if it is on a menu section
{ {
if (!b&&x>=sdl_scale*(XRES-2) && x<sdl_scale*(XRES+BARSIZE-1) &&y>= sdl_scale*((i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16)) && y<sdl_scale*((i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16)+15)) if (!b&&x>=sdl_scale*(XRES-2) && x<sdl_scale*(XRES+BARSIZE-1) &&y>= sdl_scale*((i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16)) && y<sdl_scale*((i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16)+15))
{ {
active_menu = i; active_menu = i;
} }
} }
menu_ui_v3(vid_buf, active_menu, &sl, &sr, b, bq, x, y); menu_ui_v3(vid_buf, active_menu, &sl, &sr, b, bq, x, y); //draw the elements in the current menu
if (zoom_en && x>=sdl_scale*zoom_wx && y>=sdl_scale*zoom_wy if (zoom_en && x>=sdl_scale*zoom_wx && y>=sdl_scale*zoom_wy //change mouse position while it is in a zoom window
&& x<sdl_scale*(zoom_wx+ZFACTOR*ZSIZE) && x<sdl_scale*(zoom_wx+ZFACTOR*ZSIZE)
&& y<sdl_scale*(zoom_wy+ZFACTOR*ZSIZE)) && y<sdl_scale*(zoom_wy+ZFACTOR*ZSIZE))
{ {
@ -2906,7 +2904,7 @@ int main(int argc, char *argv[])
} }
if (y>0 && y<sdl_scale*YRES && x>0 && x<sdl_scale*XRES) if (y>0 && y<sdl_scale*YRES && x>0 && x<sdl_scale*XRES)
{ {
int cr; int cr; //cr is particle under mouse, for drawing HUD information
if (photons[y/sdl_scale][x/sdl_scale]) { if (photons[y/sdl_scale][x/sdl_scale]) {
cr = photons[y/sdl_scale][x/sdl_scale]; cr = photons[y/sdl_scale][x/sdl_scale];
} else { } else {
@ -3001,7 +2999,7 @@ int main(int argc, char *argv[])
else else
free(tmp); free(tmp);
} }
if (y>=sdl_scale*(YRES+(MENUSIZE-20))) if (y>=sdl_scale*(YRES+(MENUSIZE-20))) //mouse checks for buttons at the bottom, to draw mouseover texts
{ {
if (x>=189*sdl_scale && x<=202*sdl_scale && svf_login && svf_open && svf_myvote==0) if (x>=189*sdl_scale && x<=202*sdl_scale && svf_login && svf_open && svf_myvote==0)
{ {
@ -3088,7 +3086,7 @@ int main(int argc, char *argv[])
else if (da > 0) else if (da > 0)
da --; da --;
} }
else if (da > 0) else if (da > 0)//fade away mouseover text
da --; da --;
if (!sdl_zoom_trig && zoom_en==1) if (!sdl_zoom_trig && zoom_en==1)
@ -3119,7 +3117,7 @@ int main(int argc, char *argv[])
load_mode = 0; load_mode = 0;
} }
} }
else if (save_mode==1) else if (save_mode==1)//getting the area you are selecting
{ {
save_x = (mx/sdl_scale)/CELL; save_x = (mx/sdl_scale)/CELL;
save_y = (my/sdl_scale)/CELL; save_y = (my/sdl_scale)/CELL;
@ -3147,14 +3145,14 @@ int main(int argc, char *argv[])
if (save_h<1) save_h = 1; if (save_h<1) save_h = 1;
if (!b) if (!b)
{ {
if (copy_mode==1) if (copy_mode==1)//CTRL-C, copy
{ {
clipboard_data=build_save(&clipboard_length, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL, bmap, fvx, fvy, signs, parts); 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; clipboard_ready = 1;
save_mode = 0; save_mode = 0;
copy_mode = 0; copy_mode = 0;
} }
else if (copy_mode==2) else if (copy_mode==2)//CTRL-X, cut
{ {
clipboard_data=build_save(&clipboard_length, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL, bmap, fvx, fvy, signs, parts); 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; clipboard_ready = 1;
@ -3162,7 +3160,7 @@ int main(int argc, char *argv[])
copy_mode = 0; copy_mode = 0;
clear_area(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); clear_area(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL);
} }
else else//normal save
{ {
stamp_save(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL); stamp_save(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL);
save_mode = 0; save_mode = 0;
@ -3187,15 +3185,15 @@ int main(int argc, char *argv[])
if (!b && bq) if (!b && bq)
zoom_en = 2; zoom_en = 2;
} }
else if (b) else if (b)//there is a click
{ {
if (it > 50) if (it > 50)
it = 50; it = 50;
x /= sdl_scale; x /= sdl_scale;
y /= sdl_scale; y /= sdl_scale;
if (y>=YRES+(MENUSIZE-20)) if (y>=YRES+(MENUSIZE-20))//check if mouse is on menu buttons
{ {
if (!lb) if (!lb)//mouse is NOT held down, so it is a first click
{ {
if (x>=189 && x<=202 && svf_login && svf_open && svf_myvote==0 && svf_own==0) if (x>=189 && x<=202 && svf_login && svf_open && svf_myvote==0 && svf_own==0)
{ {
@ -3309,11 +3307,11 @@ int main(int argc, char *argv[])
lb = 0; lb = 0;
} }
} }
else if (y<YRES)//mouse handling else if (y<YRES)// mouse is in playing field
{ {
int signi; int signi;
c = (b&1) ? sl : sr; c = (b&1) ? sl : sr; //c is element to be spawned
su = c; su = c;
if(c!=WL_SIGN+100) if(c!=WL_SIGN+100)
@ -3345,9 +3343,10 @@ int main(int argc, char *argv[])
if (!bq) if (!bq)
add_sign_ui(vid_buf, x, y); add_sign_ui(vid_buf, x, y);
} }
else if (lb) //for the click functions, lx and ly, are the positions of where the FIRST click happened. x,y are current mouse position.
else if (lb)//lb means you are holding mouse down
{ {
if (lm == 1) if (lm == 1)//line tool
{ {
xor_line(lx, ly, x, y, vid_buf); xor_line(lx, ly, x, y, vid_buf);
if (c==WL_FAN+100 && lx>=0 && ly>=0 && lx<XRES && ly<YRES && bmap[ly/CELL][lx/CELL]==WL_FAN) if (c==WL_FAN+100 && lx>=0 && ly>=0 && lx<XRES && ly<YRES && bmap[ly/CELL][lx/CELL]==WL_FAN)
@ -3375,14 +3374,14 @@ int main(int argc, char *argv[])
} }
} }
} }
else if (lm == 2) else if (lm == 2)//box tool
{ {
xor_line(lx, ly, lx, y, vid_buf); xor_line(lx, ly, lx, y, vid_buf);
xor_line(lx, y, x, y, vid_buf); xor_line(lx, y, x, y, vid_buf);
xor_line(x, y, x, ly, vid_buf); xor_line(x, y, x, ly, vid_buf);
xor_line(x, ly, lx, ly, vid_buf); xor_line(x, ly, lx, ly, vid_buf);
} }
else else//while mouse is held down, it draws lines between previous and current positions
{ {
if (c == PT_WIND) if (c == PT_WIND)
{ {
@ -3402,22 +3401,25 @@ int main(int argc, char *argv[])
ly = y; ly = y;
} }
} }
else else //it is the first click
{ {
//start line tool
if ((sdl_mod & (KMOD_LSHIFT|KMOD_RSHIFT)) && !(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL|KMOD_LALT))) if ((sdl_mod & (KMOD_LSHIFT|KMOD_RSHIFT)) && !(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL|KMOD_LALT)))
{ {
lx = x; lx = x;
ly = y; ly = y;
lb = b; lb = b;
lm = 1; lm = 1;//line
} }
//start box tool
else if ((sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) && !(sdl_mod & (KMOD_LSHIFT|KMOD_RSHIFT))) else if ((sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) && !(sdl_mod & (KMOD_LSHIFT|KMOD_RSHIFT)))
{ {
lx = x; lx = x;
ly = y; ly = y;
lb = b; lb = b;
lm = 2; lm = 2;//box
} }
//flood fill
else if ((sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) && (sdl_mod & (KMOD_LSHIFT|KMOD_RSHIFT)) && !(sdl_mod & (KMOD_LALT))) else if ((sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) && (sdl_mod & (KMOD_LSHIFT|KMOD_RSHIFT)) && !(sdl_mod & (KMOD_LALT)))
{ {
if (sdl_mod & (KMOD_CAPS)) if (sdl_mod & (KMOD_CAPS))
@ -3431,6 +3433,7 @@ int main(int argc, char *argv[])
lb = 0; lb = 0;
lm = 0; lm = 0;
} }
//sample
else if (((sdl_mod & (KMOD_LALT|KMOD_RALT)) && !(sdl_mod & (KMOD_SHIFT))) || b==SDL_BUTTON_MIDDLE) else if (((sdl_mod & (KMOD_LALT|KMOD_RALT)) && !(sdl_mod & (KMOD_SHIFT))) || b==SDL_BUTTON_MIDDLE)
{ {
if (y>0 && y<sdl_scale*YRES && x>0 && x<sdl_scale*XRES) if (y>0 && y<sdl_scale*YRES && x>0 && x<sdl_scale*XRES)
@ -3451,7 +3454,7 @@ int main(int argc, char *argv[])
lb = 0; lb = 0;
lm = 0; lm = 0;
} }
else else //normal click, spawn element
{ {
//Copy state before drawing any particles (for undo)7 //Copy state before drawing any particles (for undo)7
int cbx, cby, cbi; int cbx, cby, cbi;
@ -3483,38 +3486,38 @@ int main(int argc, char *argv[])
} }
else else
{ {
if (lb && lm) if (lb && lm) //lm is box/line tool
{ {
x /= sdl_scale; x /= sdl_scale;
y /= sdl_scale; y /= sdl_scale;
c = (lb&1) ? sl : sr; c = (lb&1) ? sl : sr;
su = c; su = c;
if (lm == 1) if (lm == 1)//line
{ {
if (c!=WL_FAN+100 || lx<0 || ly<0 || lx>=XRES || ly>=YRES || bmap[ly/CELL][lx/CELL]!=WL_FAN) if (c!=WL_FAN+100 || lx<0 || ly<0 || lx>=XRES || ly>=YRES || bmap[ly/CELL][lx/CELL]!=WL_FAN)
create_line(lx, ly, x, y, bsx, bsy, c); create_line(lx, ly, x, y, bsx, bsy, c);
} }
else else//box
create_box(lx, ly, x, y, c); create_box(lx, ly, x, y, c);
lm = 0; lm = 0;
} }
lb = 0; lb = 0;
} }
if (load_mode) if (load_mode)//draw preview of stamp
{ {
draw_image(vid_buf, load_img, load_x, load_y, load_w, load_h, 128); draw_image(vid_buf, load_img, load_x, load_y, load_w, load_h, 128);
xor_rect(vid_buf, load_x, load_y, load_w, load_h); xor_rect(vid_buf, load_x, load_y, load_w, load_h);
} }
if (save_mode) if (save_mode)//draw dotted lines for selection
{ {
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; da = 51;//draws mouseover text for the message
db = 269; db = 269;//the save message
} }
if (zoom_en!=1 && !load_mode && !save_mode) if (zoom_en!=1 && !load_mode && !save_mode)//draw normal cursor
{ {
render_cursor(vid_buf, mx/sdl_scale, my/sdl_scale, su, bsx, bsy); render_cursor(vid_buf, mx/sdl_scale, my/sdl_scale, su, bsx, bsy);
mousex = mx/sdl_scale; mousex = mx/sdl_scale;
@ -3525,7 +3528,7 @@ int main(int argc, char *argv[])
render_zoom(vid_buf); render_zoom(vid_buf);
if (da) if (da)
switch (db) switch (db)//various mouseover messages, da is the alpha
{ {
case 256: case 256:
drawtext(vid_buf, 16, YRES-24, "Add simulation tags.", 255, 255, 255, da*5); drawtext(vid_buf, 16, YRES-24, "Add simulation tags.", 255, 255, 255, da*5);
@ -3590,12 +3593,12 @@ int main(int argc, char *argv[])
default: default:
drawtext(vid_buf, 16, YRES-24, (char *)ptypes[db].descs, 255, 255, 255, da*5); drawtext(vid_buf, 16, YRES-24, (char *)ptypes[db].descs, 255, 255, 255, da*5);
} }
if (itc) if (itc)//message in the middle of the screen, such as view mode changes
{ {
itc--; itc--;
drawtext(vid_buf, (XRES-textwidth(itc_msg))/2, ((YRES/2)-10), itc_msg, 255, 255, 255, itc>51?255:itc*5); drawtext(vid_buf, (XRES-textwidth(itc_msg))/2, ((YRES/2)-10), itc_msg, 255, 255, 255, itc>51?255:itc*5);
} }
if (it) if (it)//intro message
{ {
it--; it--;
drawtext(vid_buf, 16, 20, it_msg, 255, 255, 255, it>51?255:it*5); drawtext(vid_buf, 16, 20, it_msg, 255, 255, 255, it>51?255:it*5);

View File

@ -45,7 +45,7 @@ static int pn_junction_sprk(int x, int y, int pt)
return 1; return 1;
} }
static void photoelectric_effect(int nx, int ny) static void photoelectric_effect(int nx, int ny)//create sparks from PHOT when hitting PSCN and NSCN
{ {
unsigned r = pmap[ny][nx]; unsigned r = pmap[ny][nx];
@ -124,7 +124,7 @@ int eval_move(int pt, int nx, int ny, unsigned *rr)
return 0; return 0;
} }
if (r && ((r&0xFF) >= PT_NUM || (ptypes[pt].weight <= ptypes[(r&0xFF)].weight))) if (r && ((r&0xFF) >= PT_NUM || (ptypes[pt].weight <= ptypes[(r&0xFF)].weight))) //the particle weight check
return 0; return 0;
if (pt == PT_PHOT) if (pt == PT_PHOT)
@ -155,9 +155,9 @@ int try_move(int i, int x, int y, int nx, int ny)
(pmap[y][x]&0xFF)==PT_BMTL)) (pmap[y][x]&0xFF)==PT_BMTL))
e = 2; e = 2;
if (!e) if (!e) //if no movement
{ {
if (!legacy_enable && parts[i].type==PT_PHOT && r) if (!legacy_enable && parts[i].type==PT_PHOT && r)//PHOT heat conduction
{ {
if ((r & 0xFF) == PT_COAL || (r & 0xFF) == PT_BCOL) if ((r & 0xFF) == PT_COAL || (r & 0xFF) == PT_BCOL)
parts[r>>8].temp = parts[i].temp; parts[r>>8].temp = parts[i].temp;
@ -168,7 +168,7 @@ int try_move(int i, int x, int y, int nx, int ny)
return 0; return 0;
} }
if (e == 2) if (e == 2) //if occupy same space
{ {
if (parts[i].type == PT_PHOT && (r&0xFF)==PT_GLOW && !parts[r>>8].life) if (parts[i].type == PT_PHOT && (r&0xFF)==PT_GLOW && !parts[r>>8].life)
if (rand() < RAND_MAX/30) if (rand() < RAND_MAX/30)
@ -200,8 +200,9 @@ int try_move(int i, int x, int y, int nx, int ny)
} }
return 1; return 1;
} }
//else e=1 , we are trying to swap the particles, return 0 no swap/move, 1 is still overlap/move, because the swap takes place later
if ((r&0xFF)==PT_VOID) if ((r&0xFF)==PT_VOID) //this is where void eats particles
{ {
if (parts[i].type == PT_STKM) if (parts[i].type == PT_STKM)
{ {
@ -216,7 +217,7 @@ int try_move(int i, int x, int y, int nx, int ny)
parts[i].type=PT_NONE; parts[i].type=PT_NONE;
return 0; return 0;
} }
if ((r&0xFF)==PT_BHOL) if ((r&0xFF)==PT_BHOL) //this is where blackhole eats particles
{ {
if (parts[i].type == PT_STKM) if (parts[i].type == PT_STKM)
{ {
@ -236,9 +237,9 @@ int try_move(int i, int x, int y, int nx, int ny)
return 0; return 0;
} }
if ((pmap[ny][nx]&0xFF)==PT_CNCT) if ((pmap[ny][nx]&0xFF)==PT_CNCT)//why is this here
return 0; return 0;
if (parts[i].type==PT_CNCT && y<ny && (pmap[y+1][x]&0xFF)==PT_CNCT) if (parts[i].type==PT_CNCT && y<ny && (pmap[y+1][x]&0xFF)==PT_CNCT)//check below CNCT for another CNCT
return 0; return 0;
if (bmap[ny/CELL][nx/CELL]==WL_EHOLE && !emap[y/CELL][x/CELL]) if (bmap[ny/CELL][nx/CELL]==WL_EHOLE && !emap[y/CELL][x/CELL])
@ -252,8 +253,8 @@ int try_move(int i, int x, int y, int nx, int ny)
if (parts[i].type == PT_PHOT) if (parts[i].type == PT_PHOT)
return 1; return 1;
e = r >> 8; e = r >> 8; //e is now the particle number at r (pmap[ny][nx])
if (r && e<NPART) if (r && e<NPART)//the swap part, if we make it this far, swap
{ {
if (parts[e].type == PT_PHOT||parts[e].type == PT_NEUT) if (parts[e].type == PT_PHOT||parts[e].type == PT_NEUT)
return 1; return 1;
@ -431,7 +432,7 @@ int get_normal_interp(int pt, float x0, float y0, float dx, float dy, float *nx,
return get_normal(pt, x, y, dx, dy, nx, ny); return get_normal(pt, x, y, dx, dy, nx, ny);
} }
void kill_part(int i) void kill_part(int i)//kills particle number i
{ {
int x, y; int x, y;
@ -470,7 +471,7 @@ void kill_part(int i)
#if defined(WIN32) && !defined(__GNUC__) #if defined(WIN32) && !defined(__GNUC__)
_inline void part_change_type(int i, int x, int y, int t) _inline void part_change_type(int i, int x, int y, int t)
#else #else
inline void part_change_type(int i, int x, int y, int t) inline void part_change_type(int i, int x, int y, int t)//changes the type of particle number i, to t. This also changes pmap at the same time.
#endif #endif
{ {
if (x<0 || y<0 || x>=XRES || y>=YRES || i>=NPART || t<0 || t>=PT_NUM) if (x<0 || y<0 || x>=XRES || y>=YRES || i>=NPART || t<0 || t>=PT_NUM)
@ -493,7 +494,7 @@ inline void part_change_type(int i, int x, int y, int t)
#if defined(WIN32) && !defined(__GNUC__) #if defined(WIN32) && !defined(__GNUC__)
_inline int create_n_parts(int n, int x, int y, float vx, float vy, int t) _inline int create_n_parts(int n, int x, int y, float vx, float vy, int t)
#else #else
inline int create_n_parts(int n, int x, int y, float vx, float vy, int t) inline int create_n_parts(int n, int x, int y, float vx, float vy, int t)//testing a new deut create part
#endif #endif
{ {
int i, c; int i, c;
@ -537,7 +538,7 @@ inline int create_n_parts(int n, int x, int y, float vx, float vy, int t)
#if defined(WIN32) && !defined(__GNUC__) #if defined(WIN32) && !defined(__GNUC__)
_inline int create_part(int p, int x, int y, int t) _inline int create_part(int p, int x, int y, int t)
#else #else
inline int create_part(int p, int x, int y, int t) inline int create_part(int p, int x, int y, int t)//the function for creating a particle, use p=-1 for creating a new particle, -2 is from a brush, or a particle number to replace a particle.
#endif #endif
{ {
int i; int i;
@ -664,7 +665,7 @@ inline int create_part(int p, int x, int y, int t)
{ {
parts[i].pavg[1] = pv[y/CELL][x/CELL]; parts[i].pavg[1] = pv[y/CELL][x/CELL];
} }
if (t!=PT_STKM&&t!=PT_STKM2) if (t!=PT_STKM&&t!=PT_STKM2)//set everything to default values first, except for stickman.
{ {
parts[i].x = (float)x; parts[i].x = (float)x;
parts[i].y = (float)y; parts[i].y = (float)y;
@ -676,6 +677,7 @@ inline int create_part(int p, int x, int y, int t)
parts[i].temp = ptypes[t].heat; parts[i].temp = ptypes[t].heat;
parts[i].tmp = 0; parts[i].tmp = 0;
} }
//now set various properties that we want at spawn.
if (t==PT_ACID) if (t==PT_ACID)
{ {
parts[i].life = 75; parts[i].life = 75;
@ -840,15 +842,16 @@ inline int create_part(int p, int x, int y, int t)
} }
if (t==PT_BIZR||t==PT_BIZRG) if (t==PT_BIZR||t==PT_BIZRG)
parts[i].ctype = 0x47FFFF; parts[i].ctype = 0x47FFFF;
//and finally set the pmap/photon maps to the newly created particle
if (t==PT_PHOT||t==PT_NEUT) if (t==PT_PHOT||t==PT_NEUT)
photons[y][x] = t|(i<<8); 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 if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT && t!=PT_NEUT)
pmap[y][x] = t|(i<<8); pmap[y][x] = t|(i<<8);
return i; return i;
} }
static void create_gain_photon(int pp) static void create_gain_photon(int pp)//photons from PHOT going through GLOW
{ {
float xx, yy; float xx, yy;
int i, lr, temp_bin, nx, ny; int i, lr, temp_bin, nx, ny;
@ -894,7 +897,7 @@ static void create_gain_photon(int pp)
parts[i].ctype = 0x1F << temp_bin; parts[i].ctype = 0x1F << temp_bin;
} }
static void create_cherenkov_photon(int pp) static void create_cherenkov_photon(int pp)//photons from NEUT going through GLAS
{ {
int i, lr, nx, ny; int i, lr, nx, ny;
float r, eff_ior; float r, eff_ior;
@ -941,7 +944,7 @@ static void create_cherenkov_photon(int pp)
#if defined(WIN32) && !defined(__GNUC__) #if defined(WIN32) && !defined(__GNUC__)
_inline void delete_part(int x, int y) _inline void delete_part(int x, int y)
#else #else
inline void delete_part(int x, int y) inline void delete_part(int x, int y)//calls kill_part with the particle located at x,y
#endif #endif
{ {
unsigned i; unsigned i;
@ -956,11 +959,11 @@ inline void delete_part(int x, int y)
if (!i || (i>>8)>=NPART) if (!i || (i>>8)>=NPART)
return; return;
if ((parts[i>>8].type==SLALT)||SLALT==0) if ((parts[i>>8].type==SLALT)||SLALT==0)//specific deletiom
{ {
kill_part(i>>8); kill_part(i>>8);
} }
else if (ptypes[parts[i>>8].type].menusection==SEC) else if (ptypes[parts[i>>8].type].menusection==SEC)//specific menu deletion
{ {
kill_part(i>>8); kill_part(i>>8);
} }
@ -1069,7 +1072,7 @@ void set_emap(int x, int y)
} }
#if defined(WIN32) && !defined(__GNUC__) #if defined(WIN32) && !defined(__GNUC__)
_inline int parts_avg(int ci, int ni,int t)//t is the particle you are looking for _inline int parts_avg(int ci, int ni,int t)//t is the particle you are looking for, returns the particle between two particles
#else #else
inline int parts_avg(int ci, int ni,int t) inline int parts_avg(int ci, int ni,int t)
#endif #endif
@ -1120,6 +1123,7 @@ int nearest_part(int ci, int t)
return id; return id;
} }
//the main function for updating particles
void update_particles_i(pixel *vid, int start, int inc) void update_particles_i(pixel *vid, int start, int inc)
{ {
int i, j, x, y, t, nx, ny, r, surround_space, s, lt, rt, nt, nnx, nny, q, golnum, goldelete, z, neighbors, createdsomething; int i, j, x, y, t, nx, ny, r, surround_space, s, lt, rt, nt, nnx, nny, q, golnum, goldelete, z, neighbors, createdsomething;
@ -1135,9 +1139,9 @@ void update_particles_i(pixel *vid, int start, int inc)
int surround_hconduct[8]; int surround_hconduct[8];
float pGravX, pGravY, pGravD; float pGravX, pGravY, pGravD;
if (sys_pause&&!framerender) if (sys_pause&&!framerender)//do nothing if paused
return; return;
if (ISGRAV==1) if (ISGRAV==1)//crappy grav color handling, i will change this someday
{ {
ISGRAV = 0; ISGRAV = 0;
GRAV ++; GRAV ++;
@ -1183,7 +1187,7 @@ void update_particles_i(pixel *vid, int start, int inc)
if (GRAV>180) GRAV = 0; if (GRAV>180) GRAV = 0;
} }
if (ISLOVE==1) if (ISLOVE==1)//LOVE element handling
{ {
ISLOVE = 0; ISLOVE = 0;
for (ny=0; ny<YRES-4; ny++) for (ny=0; ny<YRES-4; ny++)
@ -1233,7 +1237,7 @@ void update_particles_i(pixel *vid, int start, int inc)
} }
} }
} }
if (ISLOLZ==1) if (ISLOLZ==1)//LOLZ element handling
{ {
ISLOLZ = 0; ISLOLZ = 0;
for (ny=0; ny<YRES-4; ny++) for (ny=0; ny<YRES-4; ny++)
@ -1284,12 +1288,13 @@ void update_particles_i(pixel *vid, int start, int inc)
} }
} }
} }
//game of life!
if (ISGOL==1&&++CGOL>=GSPEED)//GSPEED is frames per generation if (ISGOL==1&&++CGOL>=GSPEED)//GSPEED is frames per generation
{ {
int createdsomething = 0; int createdsomething = 0;
CGOL=0; CGOL=0;
ISGOL=0; ISGOL=0;
for (nx=CELL; nx<XRES-CELL; nx++) for (nx=CELL; nx<XRES-CELL; nx++)//go through every particle and set neighbor map
for (ny=CELL; ny<YRES-CELL; ny++) for (ny=CELL; ny<YRES-CELL; ny++)
{ {
r = pmap[ny][nx]; r = pmap[ny][nx];
@ -1321,7 +1326,7 @@ void update_particles_i(pixel *vid, int start, int inc)
} }
} }
} }
for (nx=CELL; nx<XRES-CELL; nx++) for (nx=CELL; nx<XRES-CELL; nx++)//go through every particle again, but check neighbor map, then update particles
for (ny=CELL; ny<YRES-CELL; ny++) for (ny=CELL; ny<YRES-CELL; ny++)
{ {
r = pmap[ny][nx]; r = pmap[ny][nx];
@ -1351,7 +1356,7 @@ void update_particles_i(pixel *vid, int start, int inc)
GENERATION ++; GENERATION ++;
//memset(gol2, 0, sizeof(gol2)); //memset(gol2, 0, sizeof(gol2));
} }
if (ISWIRE==1) if (ISWIRE==1)//wifi channel reseting
{ {
for ( q = 0; q<(int)(MAX_TEMP-73.15f)/100+2; q++) for ( q = 0; q<(int)(MAX_TEMP-73.15f)/100+2; q++)
if (!wireless[q][1]) if (!wireless[q][1])
@ -1361,6 +1366,7 @@ void update_particles_i(pixel *vid, int start, int inc)
else else
wireless[q][1] = 0; wireless[q][1] = 0;
} }
//the main particle loop function, goes over all particles.
for (i=start; i<(NPART-starti); i+=inc) for (i=start; i<(NPART-starti); i+=inc)
if (parts[i].type) if (parts[i].type)
{ {
@ -1369,10 +1375,13 @@ void update_particles_i(pixel *vid, int start, int inc)
t = parts[i].type; t = parts[i].type;
//printf("parts[%d].type: %d\n", i, parts[i].type); //printf("parts[%d].type: %d\n", i, parts[i].type);
//this if is whether or not life goes down automatically.
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 && t!=PT_PRTO && t!=PT_PRTI) 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 && t!=PT_PRTO && t!=PT_PRTI)
{ {
//this if is for stopping life loss when at a certain life value
if (!(parts[i].life==10&&(t==PT_SWCH||t==PT_LCRY||t==PT_PCLN||t==PT_HSWC||t==PT_PUMP))) if (!(parts[i].life==10&&(t==PT_SWCH||t==PT_LCRY||t==PT_PCLN||t==PT_HSWC||t==PT_PUMP)))
parts[i].life--; parts[i].life--;
//this if is for stopping death when life hits 0
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) 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); kill_part(i);
@ -1383,7 +1392,7 @@ void update_particles_i(pixel *vid, int start, int inc)
x = (int)(parts[i].x+0.5f); x = (int)(parts[i].x+0.5f);
y = (int)(parts[i].y+0.5f); y = (int)(parts[i].y+0.5f);
//this kills any particle out of the screen, or in a wall where it isn't supposed to go
if (x<CELL || y<CELL || x>=XRES-CELL || y>=YRES-CELL || if (x<CELL || y<CELL || x>=XRES-CELL || y>=YRES-CELL ||
(bmap[y/CELL][x/CELL] && (bmap[y/CELL][x/CELL] &&
(bmap[y/CELL][x/CELL]==WL_WALL || (bmap[y/CELL][x/CELL]==WL_WALL ||
@ -1402,7 +1411,7 @@ void update_particles_i(pixel *vid, int start, int inc)
if (bmap[y/CELL][x/CELL]==WL_DETECT && emap[y/CELL][x/CELL]<8) if (bmap[y/CELL][x/CELL]==WL_DETECT && emap[y/CELL][x/CELL]<8)
set_emap(x/CELL, y/CELL); set_emap(x/CELL, y/CELL);
//adding to velocity from the particle's velocity
vx[y/CELL][x/CELL] = vx[y/CELL][x/CELL]*ptypes[t].airloss + ptypes[t].airdrag*parts[i].vx; vx[y/CELL][x/CELL] = vx[y/CELL][x/CELL]*ptypes[t].airloss + ptypes[t].airdrag*parts[i].vx;
vy[y/CELL][x/CELL] = vy[y/CELL][x/CELL]*ptypes[t].airloss + ptypes[t].airdrag*parts[i].vy; vy[y/CELL][x/CELL] = vy[y/CELL][x/CELL]*ptypes[t].airloss + ptypes[t].airdrag*parts[i].vy;
@ -1419,7 +1428,7 @@ void update_particles_i(pixel *vid, int start, int inc)
pv[y/CELL+1][x/CELL+1] += ptypes[t].hotair*(3.5f-pv[y/CELL+1][x/CELL+1]); pv[y/CELL+1][x/CELL+1] += ptypes[t].hotair*(3.5f-pv[y/CELL+1][x/CELL+1]);
} }
} }
else else//add the hotair variable to the pressure map, like black hole, or white hole.
{ {
pv[y/CELL][x/CELL] += ptypes[t].hotair; pv[y/CELL][x/CELL] += ptypes[t].hotair;
if (y+CELL<YRES) if (y+CELL<YRES)
@ -1448,21 +1457,21 @@ void update_particles_i(pixel *vid, int start, int inc)
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
parts[i].vx *= ptypes[t].loss; parts[i].vx *= ptypes[t].loss;
parts[i].vy *= ptypes[t].loss; parts[i].vy *= ptypes[t].loss;
//particle gets velocity from the vx and vy maps
parts[i].vx += ptypes[t].advection*vx[y/CELL][x/CELL] + pGravX; parts[i].vx += ptypes[t].advection*vx[y/CELL][x/CELL] + pGravX;
parts[i].vy += ptypes[t].advection*vy[y/CELL][x/CELL] + pGravY; parts[i].vy += ptypes[t].advection*vy[y/CELL][x/CELL] + pGravY;
if (ptypes[t].diffusion) if (ptypes[t].diffusion)//the random diffusion that gasses have
{ {
parts[i].vx += ptypes[t].diffusion*(rand()/(0.5f*RAND_MAX)-1.0f); parts[i].vx += ptypes[t].diffusion*(rand()/(0.5f*RAND_MAX)-1.0f);
parts[i].vy += ptypes[t].diffusion*(rand()/(0.5f*RAND_MAX)-1.0f); parts[i].vy += ptypes[t].diffusion*(rand()/(0.5f*RAND_MAX)-1.0f);
} }
j = surround_space = nt = 0; j = surround_space = nt = 0;//if nt is 1 after this, then there is a particle around the current particle, that is NOT the current particle's type, for water movement.
for (nx=-1; nx<2; nx++) for (nx=-1; nx<2; nx++)
for (ny=-1; ny<2; ny++) { for (ny=-1; ny<2; ny++) {
if (nx||ny) { if (nx||ny) {
@ -1471,16 +1480,16 @@ void update_particles_i(pixel *vid, int start, int inc)
if (!bmap[(y+ny)/CELL][(x+nx)/CELL] || bmap[(y+ny)/CELL][(x+nx)/CELL]==WL_STREAM) if (!bmap[(y+ny)/CELL][(x+nx)/CELL] || bmap[(y+ny)/CELL][(x+nx)/CELL]==WL_STREAM)
{ {
if (!(r&0xFF)) if (!(r&0xFF))
surround_space = 1; surround_space = 1;//there is empty space
if ((r&0xFF)!=t) if ((r&0xFF)!=t)
nt = 1; nt = 1;//there is nothing or a different particle
} }
} }
} }
if (!legacy_enable) if (!legacy_enable)
{ {
if (y-2 >= 0 && y-2 < YRES && (ptypes[t].properties&TYPE_LIQUID)) { if (y-2 >= 0 && y-2 < YRES && (ptypes[t].properties&TYPE_LIQUID)) {//some heat convection for liquids
r = pmap[y-2][x]; r = pmap[y-2][x];
if (!((r>>8)>=NPART || !r || parts[i].type != (r&0xFF))) { if (!((r>>8)>=NPART || !r || parts[i].type != (r&0xFF))) {
if (parts[i].temp>parts[r>>8].temp) { if (parts[i].temp>parts[r>>8].temp) {
@ -1491,6 +1500,7 @@ void update_particles_i(pixel *vid, int start, int inc)
} }
} }
//heat transfer code
c_heat = 0.0f; c_heat = 0.0f;
h_count = 0; h_count = 0;
if (t&&(t!=PT_HSWC||parts[i].life==10)&&ptypes[t].hconduct>(rand()%250)) if (t&&(t!=PT_HSWC||parts[i].life==10)&&ptypes[t].hconduct>(rand()%250))
@ -1626,8 +1636,9 @@ void update_particles_i(pixel *vid, int start, int inc)
if (ptypes[t].properties&PROP_LIFE) if (ptypes[t].properties&PROP_LIFE)
{ {
parts[i].temp = restrict_flt(parts[i].temp-50.0f, MIN_TEMP, MAX_TEMP); parts[i].temp = restrict_flt(parts[i].temp-50.0f, MIN_TEMP, MAX_TEMP);
ISGOL=1; ISGOL=1;//means there is a life particle on screen
} }
//spark updates from walls
if ((ptypes[t].properties&PROP_CONDUCTS) || t==PT_SPRK) if ((ptypes[t].properties&PROP_CONDUCTS) || t==PT_SPRK)
{ {
nx = x % CELL; nx = x % CELL;
@ -1661,7 +1672,7 @@ void update_particles_i(pixel *vid, int start, int inc)
} }
} }
//the basic explosion, from the .explosive variable
if ((ptypes[t].explosive&2) && pv[y/CELL][x/CELL]>2.5f) if ((ptypes[t].explosive&2) && pv[y/CELL][x/CELL]>2.5f)
{ {
parts[i].life = rand()%80+180; parts[i].life = rand()%80+180;
@ -1703,19 +1714,20 @@ void update_particles_i(pixel *vid, int start, int inc)
} }
} }
//call the particle update function, if there is one
if (ptypes[t].update_func) if (ptypes[t].update_func)
{ {
if ((*(ptypes[t].update_func))(i,x,y,surround_space)) if ((*(ptypes[t].update_func))(i,x,y,surround_space))
continue; continue;
} }
if (legacy_enable) if (legacy_enable)//if heat sim is off
update_legacy_all(i,x,y,surround_space); update_legacy_all(i,x,y,surround_space);
killed: killed:
if (parts[i].type == PT_NONE) if (parts[i].type == PT_NONE)//if its dead, skip to next particle
continue; continue;
if (!parts[i].vx&&!parts[i].vy) if (!parts[i].vx&&!parts[i].vy)//if its not moving, skip to next particle, movement code it next
continue; continue;
#if defined(WIN32) && !defined(__GNUC__) #if defined(WIN32) && !defined(__GNUC__)
@ -2038,7 +2050,7 @@ killed:
{ {
if ((pmap[y][x]>>8)==i) pmap[y][x] = 0; if ((pmap[y][x]>>8)==i) pmap[y][x] = 0;
else if ((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) if (nx<CELL || nx>=XRES-CELL || ny<CELL || ny>=YRES-CELL)//kill_part if particle is out of bounds
{ {
kill_part(i); kill_part(i);
continue; continue;
@ -2055,7 +2067,7 @@ killed:
} }
} }
void update_particles(pixel *vid) void update_particles(pixel *vid)//doesn't update the particles themselves, but some other things
{ {
int i, j, x, y, t, nx, ny, r, cr,cg,cb, l = -1; int i, j, x, y, t, nx, ny, r, cr,cg,cb, l = -1;
float lx, ly; float lx, ly;
@ -2070,7 +2082,7 @@ void update_particles(pixel *vid)
memset(photons, 0, sizeof(photons)); memset(photons, 0, sizeof(photons));
r = rand()%2; r = rand()%2;
NUM_PARTS = 0; NUM_PARTS = 0;
for (j=0; j<NPART; j++) for (j=0; j<NPART; j++)//the particle loop that resets the pmap/photon maps every frame, to update them.
{ {
i = r ? (NPART-1-j) : j; i = r ? (NPART-1-j) : j;
if (parts[i].type) if (parts[i].type)
@ -2094,7 +2106,7 @@ void update_particles(pixel *vid)
} }
} }
pfree=l; pfree=l;
if (cmode==CM_BLOB) if (cmode==CM_BLOB)//draw walls in BLOB mode differently, this should be moved elsewhere
{ {
for (y=0; y<YRES/CELL; y++) for (y=0; y<YRES/CELL; y++)
{ {
@ -2347,7 +2359,7 @@ void update_particles(pixel *vid)
} }
} }
} }
else else //draw walls in other modes, this should be elsewhere
{ {
for (y=0; y<YRES/CELL; y++) for (y=0; y<YRES/CELL; y++)
{ {
@ -2745,6 +2757,7 @@ int flood_parts(int x, int y, int c, int cm, int bm)
return 1; return 1;
} }
//this creates particles from a brush, don't use if you want to create one particle
int create_parts(int x, int y, int rx, int ry, int c) int create_parts(int x, int y, int rx, int ry, int c)
{ {
int i, j, r, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0;//n; int i, j, r, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0;//n;
@ -2819,6 +2832,7 @@ int create_parts(int x, int y, int rx, int ry, int c)
return 1; return 1;
} }
//if SHIFT+ALT or CAPSLOCK is on, specific delete
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)
{ {
if (rx==0&&ry==0) if (rx==0&&ry==0)
@ -2833,6 +2847,7 @@ int create_parts(int x, int y, int rx, int ry, int c)
return 1; return 1;
} }
//why do these need a special if
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)
{ {
if (rx==0&&ry==0) if (rx==0&&ry==0)
@ -2854,10 +2869,11 @@ int create_parts(int x, int y, int rx, int ry, int c)
return 1; return 1;
} }
//eraser
if (c == 0 && !REPLACE_MODE) if (c == 0 && !REPLACE_MODE)
{ {
stemp = SLALT; stemp = SLALT;
SLALT = 0; SLALT = 0;//temporarily clear specific deletion element
if (rx==0&&ry==0) if (rx==0&&ry==0)
{ {
delete_part(x, y); delete_part(x, y);
@ -2903,6 +2919,7 @@ int create_parts(int x, int y, int rx, int ry, int c)
return 1; return 1;
} }
//else, no special modes, draw element like normal.
if (rx==0&&ry==0)//workaround for 1pixel brush/floodfill crashing. todo: find a better fix later. if (rx==0&&ry==0)//workaround for 1pixel brush/floodfill crashing. todo: find a better fix later.
{ {
if (create_part(-2, x, y, c)==-1) if (create_part(-2, x, y, c)==-1)