diff --git a/includes/interface.h b/includes/interface.h index d63770afd..f1a93a917 100644 --- a/includes/interface.h +++ b/includes/interface.h @@ -56,7 +56,7 @@ static menu_wall mwalls[] = #define SC_CRACKER2 13 #define SC_TOTAL 10 -static menu_section msections[] = +static menu_section msections[] = //itemcount and doshow do not do anything currently. { {"\xC1", "Walls", 0, 1}, {"\xC2", "Electronics", 0, 1}, diff --git a/src/air.c b/src/air.c index aaf42d265..9fbfc869b 100644 --- a/src/air.c +++ b/src/air.c @@ -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]; -void make_kernel(void) +void make_kernel(void) //used for velocity { int i, j; float s = 0.0f; @@ -34,9 +34,9 @@ void update_air(void) int x, y, i, j; float dp, dx, dy, f, tx, ty; -if (airMode != 4) { +if (airMode != 4) { //airMode 4 is no air/pressure update - for (i=0; i 256.0f) dp = 256.0f; if (dp < -256.0f) dp = -256.0f; if (dx > 256.0f) dx = 256.0f; diff --git a/src/elements/acid.c b/src/elements/acid.c index 3d9f7b065..875f148fa 100644 --- a/src/elements/acid.c +++ b/src/elements/acid.c @@ -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) { - 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--; kill_part(r>>8); diff --git a/src/elements/aray.c b/src/elements/aray.c index f32344489..ac51f660e 100644 --- a/src/elements/aray.c +++ b/src/elements/aray.c @@ -23,27 +23,28 @@ int update_ARAY(UPDATE_FUNC_ARGS) { if (!r) { int nr = create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_BRAY); if (nr!=-1) { - if (destroy) { + if (destroy) {//if it came from PSCN parts[nr].tmp = 2; parts[nr].life = 2; } else parts[nr].ctype = colored; } } 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) { - parts[r>>8].life = 1020; + parts[r>>8].life = 1020;//makes it last a while 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; } - docontinue = 0; - } else if ((r&0xFF)==PT_BRAY&&parts[r>>8].tmp==1) { + docontinue = 0;//then stop it + } 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; //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; + //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)) { if (nyy!=0 || nxx!=0) { 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) { parts[r>>8].life = 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)) { docontinue = 1; } else { diff --git a/src/elements/bomb.c b/src/elements/bomb.c index 59e05f877..8115a88ad 100644 --- a/src/elements/bomb.c +++ b/src/elements/bomb.c @@ -44,7 +44,7 @@ int update_BOMB(UPDATE_FUNC_ARGS) { for (nxi=-rad; nxi<=rad; nxi++) 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) { - 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; nb = create_part(-1, x+nxi, y+nxj, PT_BOMB); if (nb!=-1) { diff --git a/src/elements/ice.c b/src/elements/ice.c index 5b792ce96..96bb22b80 100644 --- a/src/elements/ice.c +++ b/src/elements/ice.c @@ -2,7 +2,7 @@ int update_ICEI(UPDATE_FUNC_ARGS) { //currently used for snow as well 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); } diff --git a/src/elements/pcln.c b/src/elements/pcln.c index 00e5db047..e1c688e1e 100644 --- a/src/elements/pcln.c +++ b/src/elements/pcln.c @@ -40,7 +40,7 @@ int update_PCLN(UPDATE_FUNC_ARGS) { (pmap[y+ry][x+rx]&0xFF)!=0xFF) parts[i].ctype = pmap[y+ry][x+rx]&0xFF; 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 (ry=-1; ry<2; ry++) { 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 (ry=-1; ry<2; ry++) { create_part(-1, x+rx, y+ry, parts[i].ctype); diff --git a/src/elements/pipe.c b/src/elements/pipe.c index 7d709aa58..849d2eaa8 100644 --- a/src/elements/pipe.c +++ b/src/elements/pipe.c @@ -4,7 +4,7 @@ int update_PIPE(UPDATE_FUNC_ARGS) { int r, rx, ry, np, trade, q, ctype; 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) { @@ -32,13 +32,13 @@ int update_PIPE(UPDATE_FUNC_ARGS) { if ((r>>8)>=NPART ) continue; 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) 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 (ry=-1; ry<2; ry++) diff --git a/src/elements/prti.c b/src/elements/prti.c index fa87562fa..2b08aae50 100644 --- a/src/elements/prti.c +++ b/src/elements/prti.c @@ -1,5 +1,14 @@ #include - +/*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 r, nnx, rx, ry, fe = 0; int count =0; diff --git a/src/elements/prto.c b/src/elements/prto.c index 9bec996b1..adf82a75c 100644 --- a/src/elements/prto.c +++ b/src/elements/prto.c @@ -1,5 +1,14 @@ #include - +/*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 r, nnx, rx, ry, np, fe = 0; int count = 0; @@ -20,12 +29,12 @@ int update_PRTO(UPDATE_FUNC_ARGS) { { 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) randomness=1; - if (randomness>9) - randomness=9; - if (portal[parts[i].tmp][randomness-1][nnx]==PT_SPRK)// TODO: make it look better + if (randomness>8) + randomness=8; + 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+1,portal[parts[i].tmp][randomness-1][nnx]); diff --git a/src/elements/qrtz.c b/src/elements/qrtz.c index 431c46ee4..4d3662fad 100644 --- a/src/elements/qrtz.c +++ b/src/elements/qrtz.c @@ -12,6 +12,7 @@ int update_QRTZ(UPDATE_FUNC_ARGS) { part_change_type(i,x,y,PT_PQRT); } } + //new QRTZ growth for (rx=-2; rx<3 && parts[i].ctype!=-1; rx++) for (ry=-2; ry<3; ry++) if (x+rx>=0 && y+ry>0 && x+rx>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; } + //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)))) { parts[i].life = 14; diff --git a/src/graphics.c b/src/graphics.c index d6c1b90d7..05f514375 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -128,6 +128,7 @@ void sdl_blit(int x, int y, int w, int h, pixel *src, int pitch) #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) { 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); } +//old and unused equation to draw walls +/* void draw_tool(pixel *vid_buf, int b, int sl, int sr, unsigned pc, unsigned iswall) { 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 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__) _inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a) #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; } +//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) { #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 } +//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) { #ifdef OpenGL @@ -972,6 +979,7 @@ void clearrect(pixel *vid, int x, int y, int w, int h) for (i=1; i 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 - 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) { - c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f), - clamp_flt(pv[y][x], 0.0f, 8.0f), - clamp_flt(fabsf(vy[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),//pressure adds green + clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue } else if (cmode == CM_CRACK) { int r; int g; 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); 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); 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) r=255; if (g>255) @@ -1190,7 +1200,7 @@ void draw_air(pixel *vid) } 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) r=255; if (g>255) @@ -1200,7 +1210,7 @@ void draw_air(pixel *vid) c = PIXRGB(r, g, b); } } - for (j=0; jabs(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) { 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) { int i, x, y, t, nx, ny, r, s; @@ -1346,7 +1361,7 @@ void draw_parts(pixel *vid) int cr, cg, cb; float fr, fg, fb; float pt = R_TEMP; - if (GRID_MODE) + if (GRID_MODE)//draws the grid { for (ny=0; ny(ptransitions[t].thv-800.0f)) + int z = parts[i].tmp - 5;//speckles! + 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)); 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); } - else if(t==PT_LOTE) + else if(t==PT_LOTE)//colors for life states { if(parts[i].tmp==2) blendpixel(vid, nx, ny, 255, 128, 0, 255); @@ -1763,14 +1778,14 @@ void draw_parts(pixel *vid) else 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) blendpixel(vid, nx, ny, 0, 100, 50, 255); else 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) blendpixel(vid, nx, ny, 0, 0, 128, 255); @@ -1783,14 +1798,14 @@ void draw_parts(pixel *vid) else 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) blendpixel(vid, nx, ny, 0, 100, 0, 255); else 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) 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; y = ny; 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; cb = parts[i].ctype/4; cr = parts[i].flags/4; @@ -1911,7 +1926,7 @@ void draw_parts(pixel *vid) cg = sin(frequency*q + 2) * 127 + 128; cb = sin(frequency*q + 4) * 127 + 128; 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; for (z = 0; z XRES-BARSIZE){ + if (fwidth > XRES-BARSIZE){ //fancy scrolling float overflow = fwidth-(XRES-BARSIZE), location = ((float)XRES-BARSIZE)/((float)(mx-(XRES-BARSIZE))); 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*((i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16)) && my=((XRES+BARSIZE)-16) ) //highlight menu section if (sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_SHIFT)) if (i>=0&&i=0) @@ -1871,7 +1882,7 @@ int sdl_poll(void) return 0; } -void set_cmode(int cm) +void set_cmode(int cm) // sets to given view mode { cmode = cm; itc = 51; @@ -1924,7 +1935,7 @@ void set_cmode(int cm) } 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"); } @@ -1933,7 +1944,7 @@ void set_cmode(int cm) set_cmode(CM_CRACK); } } - else + else //if no special text given, it will display this. { 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); 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; while(cc < 80){ 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; } +//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 i = -1; @@ -4052,6 +4064,7 @@ int console_parse_type(char *txt, int *element, char *err) strcpy(err, "Particle type not recognised"); 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) { // TODO: use regex? @@ -4065,6 +4078,7 @@ int console_parse_coords(char *txt, int *x, int *y, char *err) *y = ny; 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 i = -1, nx, ny; diff --git a/src/main.c b/src/main.c index c36fe0d6e..d6524ca10 100644 --- a/src/main.c +++ b/src/main.c @@ -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) { int index; @@ -310,6 +311,7 @@ void *build_thumb(int *size, int bzip2) 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) { 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) { - ////SDL_EnableKeyRepeat(delay,interval) int keydelay,keyinterval; keydelay=SDL_DEFAULT_REPEAT_DELAY; keyinterval=SDL_DEFAULT_REPEAT_INTERVAL; @@ -1904,7 +1905,6 @@ static PyObject* emb_set_keyrepeat(PyObject *self, PyObject *args) //delete_part static PyObject* emb_delete(PyObject *self, PyObject *args) { - ////SDL_EnableKeyRepeat(delay,interval) int x,y; if(!PyArg_ParseTuple(args, "ii:delete",&x,&y)) return NULL; @@ -1914,7 +1914,6 @@ static PyObject* emb_delete(PyObject *self, PyObject *args) static PyObject* emb_set_pressure(PyObject *self, PyObject *args) { - ////SDL_EnableKeyRepeat(delay,interval) int x,y,press; if(!PyArg_ParseTuple(args, "iii:set_pressure",&x,&y,&press)) return NULL; @@ -1924,7 +1923,6 @@ static PyObject* emb_set_pressure(PyObject *self, PyObject *args) static PyObject* emb_set_velocity(PyObject *self, PyObject *args) { - ////SDL_EnableKeyRepeat(delay,interval) int x,y,xv,yv; if(!PyArg_ParseTuple(args, "iiii:set_velocity",&x,&y,&xv,&yv)) 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); } - 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(); } #ifdef OpenGL ClearScreen(); #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); } - 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); 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); } @@ -2301,12 +2299,12 @@ int main(int argc, char *argv[]) if (bsy<0) bsy = 0; - update_particles(vid_buf); - draw_parts(vid_buf); + update_particles(vid_buf); //update everything + draw_parts(vid_buf); //draw particles 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); } @@ -2321,7 +2319,7 @@ int main(int argc, char *argv[]) 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); draw_svf_ui(vid_buf); @@ -2433,7 +2431,7 @@ int main(int argc, char *argv[]) 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) { @@ -2807,7 +2805,7 @@ int main(int argc, char *argv[]) #endif #ifdef INTERNAL 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 (vs>=1) @@ -2837,7 +2835,7 @@ int main(int argc, char *argv[]) if (sdl_wheel) { - if (sdl_zoom_trig==1) + if (sdl_zoom_trig==1)//zoom window change { ZSIZE += sdl_wheel; if (ZSIZE>60) @@ -2847,7 +2845,7 @@ int main(int argc, char *argv[]) ZFACTOR = 256/ZSIZE; sdl_wheel = 0; } - else + else //change brush size { if (!(sdl_mod & (KMOD_SHIFT|KMOD_CTRL))) { @@ -2880,24 +2878,24 @@ int main(int argc, char *argv[]) } } - bq = b; - b = SDL_GetMouseState(&x, &y); + bq = b; // bq is previous mouse state + b = SDL_GetMouseState(&x, &y); // b is current mouse state - for (i=0; i=sdl_scale*(XRES-2) && x= sdl_scale*((i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16)) && y=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 && x0 && y0 && x=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) { @@ -3088,7 +3086,7 @@ int main(int argc, char *argv[]) else if (da > 0) da --; } - else if (da > 0) + else if (da > 0)//fade away mouseover text da --; if (!sdl_zoom_trig && zoom_en==1) @@ -3119,7 +3117,7 @@ int main(int argc, char *argv[]) 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_y = (my/sdl_scale)/CELL; @@ -3147,14 +3145,14 @@ int main(int argc, char *argv[]) if (save_h<1) save_h = 1; 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_ready = 1; save_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_ready = 1; @@ -3162,7 +3160,7 @@ int main(int argc, char *argv[]) copy_mode = 0; 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); save_mode = 0; @@ -3187,15 +3185,15 @@ int main(int argc, char *argv[]) if (!b && bq) zoom_en = 2; } - else if (b) + else if (b)//there is a click { if (it > 50) it = 50; x /= 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) { @@ -3309,11 +3307,11 @@ int main(int argc, char *argv[]) lb = 0; } } - else if (y=0 && ly>=0 && lx0 && y0 && x=XRES || ly>=YRES || bmap[ly/CELL][lx/CELL]!=WL_FAN) create_line(lx, ly, x, y, bsx, bsy, c); } - else + else//box create_box(lx, ly, x, y, c); lm = 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); 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); - da = 51; - db = 269; + da = 51;//draws mouseover text for the message + 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); mousex = mx/sdl_scale; @@ -3525,7 +3528,7 @@ int main(int argc, char *argv[]) render_zoom(vid_buf); if (da) - switch (db) + switch (db)//various mouseover messages, da is the alpha { case 256: 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: 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--; 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--; drawtext(vid_buf, 16, 20, it_msg, 255, 255, 255, it>51?255:it*5); diff --git a/src/powder.c b/src/powder.c index 1b839e3ab..be647601c 100644 --- a/src/powder.c +++ b/src/powder.c @@ -45,7 +45,7 @@ static int pn_junction_sprk(int x, int y, int pt) 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]; @@ -124,7 +124,7 @@ int eval_move(int pt, int nx, int ny, unsigned *rr) 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; 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)) 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) 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; } - 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 (rand() < RAND_MAX/30) @@ -200,8 +200,9 @@ int try_move(int i, int x, int y, int nx, int ny) } 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) { @@ -216,7 +217,7 @@ int try_move(int i, int x, int y, int nx, int ny) parts[i].type=PT_NONE; return 0; } - if ((r&0xFF)==PT_BHOL) + if ((r&0xFF)==PT_BHOL) //this is where blackhole eats particles { 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; } - if ((pmap[ny][nx]&0xFF)==PT_CNCT) + if ((pmap[ny][nx]&0xFF)==PT_CNCT)//why is this here return 0; - if (parts[i].type==PT_CNCT && y> 8; - if (r && e> 8; //e is now the particle number at r (pmap[ny][nx]) + if (r && e=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__) _inline int create_n_parts(int n, int x, int y, float vx, float vy, int t) #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 { 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__) _inline int create_part(int p, int x, int y, int t) #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 { 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]; } - 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].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].tmp = 0; } + //now set various properties that we want at spawn. if (t==PT_ACID) { 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) parts[i].ctype = 0x47FFFF; + //and finally set the pmap/photon maps to the newly created particle if (t==PT_PHOT||t==PT_NEUT) photons[y][x] = t|(i<<8); - if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT && t!=PT_NEUT) // is this needed? it breaks floodfill, Yes photons should not be placed in the PMAP + if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT && t!=PT_NEUT) pmap[y][x] = t|(i<<8); 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; int i, lr, temp_bin, nx, ny; @@ -894,7 +897,7 @@ static void create_gain_photon(int pp) 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; float r, eff_ior; @@ -941,7 +944,7 @@ static void create_cherenkov_photon(int pp) #if defined(WIN32) && !defined(__GNUC__) _inline void delete_part(int x, int y) #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 { unsigned i; @@ -956,11 +959,11 @@ inline void delete_part(int x, int y) if (!i || (i>>8)>=NPART) return; - if ((parts[i>>8].type==SLALT)||SLALT==0) + if ((parts[i>>8].type==SLALT)||SLALT==0)//specific deletiom { 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); } @@ -1069,7 +1072,7 @@ void set_emap(int x, int y) } #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 inline int parts_avg(int ci, int ni,int t) #endif @@ -1120,6 +1123,7 @@ int nearest_part(int ci, int t) return id; } +//the main function for updating particles 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; @@ -1135,9 +1139,9 @@ void update_particles_i(pixel *vid, int start, int inc) int surround_hconduct[8]; float pGravX, pGravY, pGravD; - if (sys_pause&&!framerender) + if (sys_pause&&!framerender)//do nothing if paused return; - if (ISGRAV==1) + if (ISGRAV==1)//crappy grav color handling, i will change this someday { ISGRAV = 0; GRAV ++; @@ -1183,7 +1187,7 @@ void update_particles_i(pixel *vid, int start, int inc) if (GRAV>180) GRAV = 0; } - if (ISLOVE==1) + if (ISLOVE==1)//LOVE element handling { ISLOVE = 0; for (ny=0; ny=GSPEED)//GSPEED is frames per generation { int createdsomething = 0; CGOL=0; ISGOL=0; - for (nx=CELL; nx=XRES-CELL || y>=YRES-CELL || (bmap[y/CELL][x/CELL] && (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) 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; 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]); } } - else + else//add the hotair variable to the pressure map, like black hole, or white hole. { pv[y/CELL][x/CELL] += ptypes[t].hotair; if (y+CELL= 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]; if (!((r>>8)>=NPART || !r || parts[i].type != (r&0xFF))) { 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; h_count = 0; 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) { 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) { 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) { 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))(i,x,y,surround_space)) continue; } - if (legacy_enable) + if (legacy_enable)//if heat sim is off update_legacy_all(i,x,y,surround_space); killed: - if (parts[i].type == PT_NONE) + if (parts[i].type == PT_NONE)//if its dead, skip to next particle 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; #if defined(WIN32) && !defined(__GNUC__) @@ -2038,7 +2050,7 @@ killed: { if ((pmap[y][x]>>8)==i) pmap[y][x] = 0; else if ((photons[y][x]>>8)==i) photons[y][x] = 0; - if (nx=XRES-CELL || ny=YRES-CELL) + if (nx=XRES-CELL || ny=YRES-CELL)//kill_part if particle is out of bounds { kill_part(i); 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; float lx, ly; @@ -2070,7 +2082,7 @@ void update_particles(pixel *vid) memset(photons, 0, sizeof(photons)); r = rand()%2; NUM_PARTS = 0; - for (j=0; j