summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-05-24 18:53:50 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-05-24 18:53:50 (GMT)
commit8196d2a645d386b5c97134c446e959e5e50a345b (patch)
tree33e729715a6122fa5b8dac6f9abf7b784bfbfbc3 /src
parent5a117c2d27f513942d7621980a79d357af122ba4 (diff)
parent1fb778724329782bb5616da032742dce4dbea131 (diff)
downloadpowder-8196d2a645d386b5c97134c446e959e5e50a345b.zip
powder-8196d2a645d386b5c97134c446e959e5e50a345b.tar.gz
Merge pull request #66 from jacob1/Modstuff
Code structure improvements for graphics/drawing, improvements to prevent accidental infinite loops in Lua, Fixes for fusion, improvements for VOID types. And other minor improvements
Diffstat (limited to 'src')
-rw-r--r--src/elementdata.c4
-rw-r--r--src/elements/O2.c59
-rw-r--r--src/elements/co2.c5
-rw-r--r--src/elements/elec.c2
-rw-r--r--src/elements/gel.c5
-rw-r--r--src/elements/h2.c12
-rw-r--r--src/elements/nble.c10
-rw-r--r--src/elements/pyro.c2
-rw-r--r--src/elements/sprk.c4
-rw-r--r--src/graphics.c124
-rw-r--r--src/interface.c74
-rw-r--r--src/luaconsole.c140
-rw-r--r--src/main.c118
-rw-r--r--src/powder.c84
14 files changed, 368 insertions, 275 deletions
diff --git a/src/elementdata.c b/src/elementdata.c
index 2821127..6cf8096 100644
--- a/src/elementdata.c
+++ b/src/elementdata.c
@@ -79,8 +79,8 @@ part_type ptypes[PT_NUM] =
{"GLAS", PIXPACK(0x404040), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 150, "Solid. Meltable. Shatters under pressure", ST_SOLID, TYPE_SOLID | PROP_NEUTPASS | PROP_HOT_GLOW | PROP_SPARKSETTLE, &update_GLAS, NULL},
{"PTCT", PIXPACK(0x405050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Semi-conductor. Only conducts electricity when cold (Less than 100C)", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC, &update_NPTCT, NULL},
{"BGLA", PIXPACK(0x606060), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 5, 2, 1, 1, 90, SC_POWDERS, R_TEMP+0.0f +273.15f, 150, "Broken Glass, Heavy particles. Meltable. Bagels.", ST_SOLID, TYPE_PART | PROP_HOT_GLOW, NULL, NULL},
- {"THDR", PIXPACK(0xFFFFA0), 0.0f, 0.00f * CFDS, 1.0f, 0.30f, -0.99f, 0.6f, 0.62f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 1, SC_EXPLOSIVE, 9000.0f +273.15f, 1, "Lightning! Very hot, inflicts damage upon most materials, transfers current to metals.", ST_NONE, TYPE_ENERGY, &update_THDR, &graphics_THDR},
- {"PLSM", PIXPACK(0xBB99FF), 0.9f, 0.04f * CFDS, 0.97f, 0.20f, 0.0f, -0.1f, 0.30f, 0.001f * CFDS, 0, 0, 0, 0, 0, 1, 1, 1, SC_GAS, 10000.0f +273.15f, 5, "Plasma, extremely hot.", ST_NONE, TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL, &update_PYRO, &graphics_PLSM},
+ {"THDR", PIXPACK(0xFFFFA0), 0.0f, 0.00f * CFDS, 1.0f, 0.30f, -0.99f, 0.6f, 0.62f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 1, SC_EXPLOSIVE, 9000.0f +273.15f, 1, "Lightning! Very hot, inflicts damage upon most materials, transfers current to metals.", ST_NONE, TYPE_PART, &update_THDR, &graphics_THDR},
+ {"PLSM", PIXPACK(0xBB99FF), 0.9f, 0.04f * CFDS, 0.97f, 0.20f, 0.0f, -0.1f, 0.30f, 0.001f * CFDS, 0, 0, 0, 0, 0, 1, 1, 1, SC_GAS, 10000.0f +273.15f, 5, "Plasma, extremely hot.", ST_NONE, TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL, &update_PYRO, &graphics_PLSM},
{"ETRD", PIXPACK(0x404040), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Electrode. Creates a surface that allows Plasma arcs. (Use sparingly)", ST_NONE, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC, NULL, NULL},
{"NICE", PIXPACK(0xC0E0FF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, -0.0005f* CFDS, 0, 0, 0, 0, 20, 1, 1, 100, SC_SOLIDS, 35.0f, 46, "Nitrogen Ice.", ST_SOLID, TYPE_SOLID, NULL, NULL},
{"NBLE", PIXPACK(0xEB4917), 1.0f, 0.01f * CFDS, 0.99f, 0.30f, -0.1f, 0.0f, 0.75f, 0.001f * CFDS, 0, 0, 0, 0, 1, 1, 1, 1, SC_GAS, R_TEMP+2.0f +273.15f, 106, "Noble Gas. Diffuses. Conductive. Ionizes into plasma when introduced to electricity", ST_GAS, TYPE_GAS|PROP_CONDUCTS|PROP_LIFE_DEC, &update_NBLE, NULL},
diff --git a/src/elements/O2.c b/src/elements/O2.c
index 8ca0f46..5152478 100644
--- a/src/elements/O2.c
+++ b/src/elements/O2.c
@@ -18,28 +18,47 @@
int update_O2(UPDATE_FUNC_ARGS)
{
int r,rx,ry;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
-
- if ((r&0xFF)==PT_FIRE)
- {
- parts[r>>8].temp+=(rand()/(RAND_MAX/100));
- if(parts[r>>8].tmp&0x01)
- parts[r>>8].temp=3473;
- parts[r>>8].tmp |= 2;
- }
- if ((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM)
+ if (parts[i].temp < 9273.15)
+ {
+ for (rx=-2; rx<3; rx++)
+ for (ry=-2; ry<3; ry++)
+ if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
{
- create_part(i,x,y,PT_FIRE);
- parts[i].temp+=(rand()/(RAND_MAX/100));
- parts[i].tmp |= 2;
+ r = pmap[y+ry][x+rx];
+ if (!r)
+ continue;
+
+ if ((r&0xFF)==PT_FIRE)
+ {
+ parts[r>>8].temp+=(rand()/(RAND_MAX/100));
+ if(parts[r>>8].tmp&0x01)
+ parts[r>>8].temp=3473;
+ parts[r>>8].tmp |= 2;
+ }
+ if ((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM)
+ {
+ create_part(i,x,y,PT_FIRE);
+ parts[i].temp+=(rand()/(RAND_MAX/100));
+ parts[i].tmp |= 2;
+ }
+
}
+ }
+ else if (parts[i].temp > 9973.15 && pv[y/CELL][x/CELL] > 250.0f && abs(gravx[(((y/sdl_scale)/CELL)*(XRES/CELL))+((x/sdl_scale)/CELL)]) + abs(gravy[(((y/sdl_scale)/CELL)*(XRES/CELL))+((x/sdl_scale)/CELL)]) > 20)
+ {
+ if (rand()%5 < 1)
+ {
+ int j;
+ part_change_type(i,x,y,PT_PLSM);
+ parts[i].life = rand()%150+50;
+ j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); if (j != -1) parts[j].temp = 15000;
+ j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PHOT); if (j != -1) parts[j].temp = 15000;
+ j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_BRMT); if (j != -1) parts[j].temp = 15000;
+ j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_SING); if (j != -1) { parts[j].temp = 15000; parts[i].life = rand()%25+50; }
- }
+ parts[i].temp += 15000;
+ pv[y/CELL][x/CELL] += 300;
+ }
+ }
return 0;
}
diff --git a/src/elements/co2.c b/src/elements/co2.c
index 77a92b0..acdbc99 100644
--- a/src/elements/co2.c
+++ b/src/elements/co2.c
@@ -49,12 +49,13 @@ int update_CO2(UPDATE_FUNC_ARGS) {
int j;
kill_part(i);
j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); if (j != -1) parts[j].temp = 15000;
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); if (j != -1) parts[j].temp = 15000;
+ if (!(rand()%50)) { j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); if (j != -1) parts[j].temp = 15000; }
j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_O2); if (j != -1) parts[j].temp = 15000;
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_SING); if (j != -1) { parts[j].temp = 15000; parts[i].life = rand()%100+450; }
+ if (rand()%1000 < 1) { j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_SING); if (j != -1) { parts[j].temp = 15000; parts[i].life = 3; } }
parts[i].temp += 15000;
pv[y/CELL][x/CELL] += 100;
+ return 1;
}
}
return 0;
diff --git a/src/elements/elec.c b/src/elements/elec.c
index 667499f..919ee87 100644
--- a/src/elements/elec.c
+++ b/src/elements/elec.c
@@ -94,7 +94,7 @@ int update_ELEC(UPDATE_FUNC_ARGS) {
kill_part(i);
return 1;
}
- if (ptypes[r&0xFF].properties & PROP_CONDUCTS && ((r&0xFF)!=PT_H2||parts[i].tmp!=1))
+ if (ptypes[r&0xFF].properties & PROP_CONDUCTS && ((r&0xFF)!=PT_NBLE||parts[i].temp<2273.15))
{
create_part(-1, x+rx, y+ry, PT_SPRK);
kill_part(i);
diff --git a/src/elements/gel.c b/src/elements/gel.c
index e558342..c64591a 100644
--- a/src/elements/gel.c
+++ b/src/elements/gel.c
@@ -17,6 +17,8 @@
int update_GEL(UPDATE_FUNC_ARGS) {
int r, rx, ry;
+ float dx, dy;
+ char gel;
if (parts[i].tmp>100) parts[i].tmp = 100;
if (parts[i].tmp<0) parts[i].tmp = 0;
for (rx=-2; rx<3; rx++)
@@ -41,7 +43,7 @@ int update_GEL(UPDATE_FUNC_ARGS) {
parts[i].tmp++;
}
- char gel = 0;
+ gel = 0;
if ((r&0xFF)==PT_GEL)
gel = 1;
@@ -58,7 +60,6 @@ int update_GEL(UPDATE_FUNC_ARGS) {
parts[i].tmp--;
}
- float dx, dy;
dx = parts[i].x - parts[r>>8].x;
dy = parts[i].y - parts[r>>8].y;
diff --git a/src/elements/h2.c b/src/elements/h2.c
index 212e56e..86c3be3 100644
--- a/src/elements/h2.c
+++ b/src/elements/h2.c
@@ -35,7 +35,7 @@ int update_H2(UPDATE_FUNC_ARGS)
}
if (parts[r>>8].temp > 2273.15)// && pv[y/CELL][x/CELL] > 50.0f)
continue;
- if (parts[i].tmp != 1)
+ if (parts[i].temp < 2273.15)
{
if (rt==PT_FIRE)
{
@@ -54,20 +54,18 @@ int update_H2(UPDATE_FUNC_ARGS)
}
if (parts[i].temp > 2273.15 && pv[y/CELL][x/CELL] > 50.0f)
{
- parts[i].tmp = 1;
if (rand()%5 < 1)
{
int j;
float temp = parts[i].temp;
part_change_type(i,x,y,PT_PLSM);
parts[i].life = rand()%150+50;
- create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT);
- create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC);
+ j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); if (j != -1) parts[j].temp = temp;
+ if (!(rand()%10)) { j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); if (j != -1) parts[j].temp = temp; }
j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PHOT);
if (j != -1) { parts[j].ctype = 0xFFFF00; parts[j].temp = temp; }
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NBLE);
- if (j != -1) { parts[j].tmp = 1; parts[j].temp = temp; }
+ j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NBLE); if (j != -1) parts[j].temp = temp;
if (rand()%2)
{
@@ -75,7 +73,7 @@ int update_H2(UPDATE_FUNC_ARGS)
if (j != -1) { parts[j].tmp = 1; parts[j].temp = temp; }
}
- parts[i].temp += 6000;
+ parts[i].temp += 750+rand()%500;
pv[y/CELL][x/CELL] += 30;
}
}
diff --git a/src/elements/nble.c b/src/elements/nble.c
index bca0291..0c118ed 100644
--- a/src/elements/nble.c
+++ b/src/elements/nble.c
@@ -25,16 +25,16 @@ int update_NBLE(UPDATE_FUNC_ARGS)
float temp = parts[i].temp;
part_change_type(i,x,y,PT_PLSM);
parts[i].life = rand()%150+50;
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); if (j != -1)
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); if (j != -1)
+ j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); if (j != -1) parts[j].temp = temp;
+ if (!(rand()%25)) { j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); if (j != -1) parts[j].temp = temp; }
j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PHOT);
if (j != -1) { parts[j].ctype = 0xFF0000; parts[j].temp = temp; }
j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_CO2);
- if (j != -1) parts[j].temp = temp - 1000;
+ if (j != -1) parts[j].temp = temp;
- parts[i].temp += 10000;
- pv[y/CELL][x/CELL] += 30;
+ parts[i].temp += 1750+rand()%500;
+ pv[y/CELL][x/CELL] += 50;
}
}
return 0;
diff --git a/src/elements/pyro.c b/src/elements/pyro.c
index 854e62d..c09dd63 100644
--- a/src/elements/pyro.c
+++ b/src/elements/pyro.c
@@ -61,7 +61,7 @@ int update_PYRO(UPDATE_FUNC_ARGS) {
(t!=PT_SPRK || (rt!=PT_RBDM && rt!=PT_LRBD && rt!=PT_INSL)) &&
(t!=PT_PHOT || rt!=PT_INSL) &&
(rt!=PT_SPNG || parts[r>>8].life==0) &&
- (rt!=PT_H2 || (parts[r>>8].temp < 2273.15 && pv[y/CELL][x/CELL] < 50.0f)) &&
+ (rt!=PT_H2 || parts[r>>8].temp < 2273.15) &&
ptypes[rt].flammable && (ptypes[rt].flammable + (int)(pv[(y+ry)/CELL][(x+rx)/CELL]*10.0f))>(rand()%1000))
{
part_change_type(r>>8,x+rx,y+ry,PT_FIRE);
diff --git a/src/elements/sprk.c b/src/elements/sprk.c
index d7ee0f0..f1c8c8e 100644
--- a/src/elements/sprk.c
+++ b/src/elements/sprk.c
@@ -59,7 +59,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) {
parts[nearp].ctype = PT_ETRD;
}
}
- else if (ct==PT_NBLE&&parts[i].life<=1&&parts[i].tmp!=1)
+ else if (ct==PT_NBLE&&parts[i].life<=1&&parts[i].temp<5273.15)
{
parts[i].life = rand()%150+50;
part_change_type(i,x,y,PT_PLSM);
@@ -194,7 +194,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) {
conduct_sprk = 0;
if (rt==PT_INST&&ct!=PT_PSCN)
conduct_sprk = 0;
- if (rt == PT_NBLE && parts[r>>8].tmp == 1)
+ if (rt == PT_NBLE && parts[r>>8].temp > 5273.15)
conduct_sprk = 0;
if (conduct_sprk) {
diff --git a/src/graphics.c b/src/graphics.c
index 3916ffd..0c4c965 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -47,6 +47,9 @@
#include <font.h>
#include <misc.h>
#include "hmap.h"
+#ifdef LUACONSOLE
+#include <luaconsole.h>
+#endif
#if defined(LIN32) || defined(LIN64)
#include "icon.h"
@@ -1693,7 +1696,7 @@ void draw_other(pixel *vid) // EMP effect
if (emp_decor>0 && !sys_pause) emp_decor-=emp_decor/25+2;
if (emp_decor>40) emp_decor=40;
if (emp_decor<0) emp_decor = 0;
- if (!(display_mode & DISPLAY_EFFE)) // no in nothing mode
+ if (!(render_mode & EFFECT)) // not in nothing mode
return;
if (emp_decor>0)
{
@@ -1854,8 +1857,29 @@ void render_parts(pixel *vid)
}
else if(!(colour_mode & COLOUR_BASC)) //Don't get special effects for BASIC colour mode
{
+#ifdef LUACONSOLE
+ if (lua_gr_func[t])
+ {
+ if (luacon_graphics_update(t,i, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb))
+ {
+ graphicscache[t].isready = 1;
+ graphicscache[t].pixel_mode = pixel_mode;
+ graphicscache[t].cola = cola;
+ graphicscache[t].colr = colr;
+ graphicscache[t].colg = colg;
+ graphicscache[t].colb = colb;
+ graphicscache[t].firea = firea;
+ graphicscache[t].firer = firer;
+ graphicscache[t].fireg = fireg;
+ graphicscache[t].fireb = fireb;
+ }
+ }
+ else if (ptypes[t].graphics_func)
+ {
+#else
if (ptypes[t].graphics_func)
{
+#endif
if ((*(ptypes[t].graphics_func))(&(parts[i]), nx, ny, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb)) //That's a lot of args, a struct might be better
{
graphicscache[t].isready = 1;
@@ -2869,10 +2893,82 @@ void draw_parts_fbo()
}
#endif
+// draw the graphics that appear before update_particles is called
+void render_before(pixel *part_vbuf)
+{
+#ifdef OGLR
+ if (display_mode & DISPLAY_PERS)//save background for persistent, then clear
+ {
+ clearScreen(0.01f);
+ memset(part_vbuf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
+ }
+ else //clear screen every frame
+ {
+ clearScreen(1.0f);
+ memset(part_vbuf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
+ if (display_mode & DISPLAY_AIR)//air only gets drawn in these modes
+ {
+ draw_air(part_vbuf);
+ }
+ }
+#else
+ if (display_mode & DISPLAY_AIR)//air only gets drawn in these modes
+ {
+ draw_air(part_vbuf);
+ }
+ else if (display_mode & DISPLAY_PERS)//save background for persistent, then clear
+ {
+ memcpy(part_vbuf, pers_bg, (XRES+BARSIZE)*YRES*PIXELSIZE);
+ memset(part_vbuf+((XRES+BARSIZE)*YRES), 0, ((XRES+BARSIZE)*YRES*PIXELSIZE)-((XRES+BARSIZE)*YRES*PIXELSIZE));
+ }
+ else //clear screen every frame
+ {
+ memset(part_vbuf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
+ }
+#endif
+ if(ngrav_enable && drawgrav_enable)
+ draw_grav(part_vbuf);
+ draw_walls(part_vbuf);
+}
+
+int persist_counter = 0;
+// draw the graphics that appear after update_particles is called
+void render_after(pixel *part_vbuf, pixel *vid_buf)
+{
+ render_parts(part_vbuf); //draw particles
+ draw_other(part_vbuf);
+ //if(su == WL_GRAV+100)
+ // draw_grav_zones(part_vbuf);
+ if (vid_buf && (display_mode & DISPLAY_PERS))
+ {
+ if (!persist_counter)
+ {
+ dim_copy_pers(pers_bg, vid_buf);
+ }
+ else
+ {
+ memcpy(pers_bg, vid_buf, (XRES+BARSIZE)*YRES*PIXELSIZE);
+ }
+ persist_counter = (persist_counter+1) % 3;
+ }
+#ifndef OGLR
+ if (render_mode & FIREMODE)
+ render_fire(part_vbuf);
+#endif
+
+ render_signs(part_vbuf);
+
+#ifndef OGLR
+ if(vid_buf && ngrav_enable && (display_mode & DISPLAY_WARP))
+ render_gravlensing(part_vbuf, vid_buf);
+#endif
+}
+
void draw_walls(pixel *vid)
{
- int x, y, i, j, cr, cg, cb;
+ int x, y, i, j, cr, cg, cb, nx, ny, t;
unsigned char wt;
+ float lx, ly;
pixel pc;
pixel gc;
for (y=0; y<YRES/CELL; y++)
@@ -3058,6 +3154,30 @@ void draw_walls(pixel *vid)
}
}
+
+ // draw streamlines
+ for (y=0; y<YRES/CELL; y++)
+ for (x=0; x<XRES/CELL; x++)
+ if (bmap[y][x]==WL_STREAM)
+ {
+ lx = x*CELL + CELL*0.5f;
+ ly = y*CELL + CELL*0.5f;
+ for (t=0; t<1024; t++)
+ {
+ nx = (int)(lx+0.5f);
+ ny = (int)(ly+0.5f);
+ if (nx<0 || nx>=XRES || ny<0 || ny>=YRES)
+ break;
+ addpixel(vid, nx, ny, 255, 255, 255, 64);
+ i = nx/CELL;
+ j = ny/CELL;
+ lx += vx[j][i]*0.125f;
+ ly += vy[j][i]*0.125f;
+ if (bmap[j][i]==WL_STREAM && i!=x && j!=y)
+ break;
+ }
+ drawtext(vid, x*CELL, y*CELL-2, "\x8D", 255, 255, 255, 128);
+ }
}
void create_decorations(int x, int y, int rx, int ry, int r, int g, int b, int click, int tool)
diff --git a/src/interface.c b/src/interface.c
index b7d3d9c..d61dab5 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -2883,6 +2883,7 @@ int sdl_poll(void)
{
SDL_Event event;
sdl_key=sdl_rkey=sdl_wheel=sdl_ascii=0;
+ loop_time = SDL_GetTicks();
while (SDL_PollEvent(&event))
{
switch (event.type)
@@ -5641,7 +5642,8 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved
b = mouse_get_state(&mx, &my);
memcpy(vid_buf,old_buf,(XRES+BARSIZE)*(YRES+MENUSIZE)*PIXELSIZE);
- render_parts(vid_buf);
+ render_before(vid_buf);
+ render_after(vid_buf, NULL);
ui_edit_process(mx, my, b, &box_R);
ui_edit_process(mx, my, b, &box_G);
ui_edit_process(mx, my, b, &box_B);
@@ -5923,6 +5925,9 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved
cb = PIXB(tempcolor);
if (cr || cg || cb)
{
+ if (cr) cr++;
+ if (cg) cg++;
+ if (cb) cb++;
currR = cr;
currG = cg;
currB = cb;
@@ -6666,10 +6671,10 @@ void render_ui(pixel * vid_buf, int xcoord, int ycoord, int orientation)
int render_optionicons[] = {0xE1, 0xDF, 0x9B, 0xC4, 0xBF, 0xDB};
char * render_desc[] = {"Effects", "Glow", "Fire", "Blur", "Blob", "Basic"};
- int display_optioncount = 7;
- int display_options[] = {DISPLAY_AIRC, DISPLAY_AIRP, DISPLAY_AIRV, DISPLAY_AIRH, DISPLAY_WARP, DISPLAY_PERS, DISPLAY_EFFE};
- int display_optionicons[] = {0xD4, 0x99, 0x98, 0xBE, 0xDE, 0x9A, -1};
- char * display_desc[] = {"Air: Cracker", "Air: Pressure", "Air: Velocity", "Air: Heat", "Warp effect", "Persistent", "Effects"};
+ int display_optioncount = 6;
+ int display_options[] = {DISPLAY_AIRC, DISPLAY_AIRP, DISPLAY_AIRV, DISPLAY_AIRH, DISPLAY_WARP, DISPLAY_PERS};
+ int display_optionicons[] = {0xD4, 0x99, 0x98, 0xBE, 0xDE, 0x9A};
+ char * display_desc[] = {"Air: Cracker", "Air: Pressure", "Air: Velocity", "Air: Heat", "Warp effect", "Persistent"};
int colour_optioncount = 4;
int colour_options[] = {COLOUR_BASC, COLOUR_LIFE, COLOUR_HEAT, COLOUR_GRAD};
@@ -6758,63 +6763,24 @@ void render_ui(pixel * vid_buf, int xcoord, int ycoord, int orientation)
b = mouse_get_state(&mx, &my);
memcpy(vid_buf, o_vid_buf, ((YRES+MENUSIZE) * (XRES+BARSIZE)) * PIXELSIZE);
-
- if(ngrav_enable && display_mode & DISPLAY_WARP)
+#ifdef OGLR
+ part_vbuf = vid_buf;
+#else
+ if(ngrav_enable && (display_mode & DISPLAY_WARP))
{
part_vbuf = part_vbuf_store;
memset(vid_buf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
} else {
part_vbuf = vid_buf;
}
-
-#ifdef OGLR
- if (display_mode & DISPLAY_PERS)//save background for persistent, then clear
- {
- clearScreen(0.01f);
- memset(part_vbuf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- }
- else //clear screen every frame
- {
- clearScreen(1.0f);
- memset(part_vbuf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- if (display_mode & DISPLAY_AIR)//air only gets drawn in these modes
- {
- draw_air(part_vbuf);
- }
- }
-#else
- if (display_mode & DISPLAY_AIR)//air only gets drawn in these modes
- {
- draw_air(part_vbuf);
- }
- else if (display_mode & DISPLAY_PERS)//save background for persistent, then clear
- {
- memcpy(part_vbuf, pers_bg, (XRES+BARSIZE)*YRES*PIXELSIZE);
- memset(part_vbuf+((XRES+BARSIZE)*YRES), 0, ((XRES+BARSIZE)*YRES*PIXELSIZE)-((XRES+BARSIZE)*YRES*PIXELSIZE));
- }
- else //clear screen every frame
+#endif
+ render_before(part_vbuf);
+ render_after(part_vbuf, vid_buf);
+ quickoptions_menu(vid_buf, b, bq, mx, my);
+ for (i=0; i<SC_TOTAL; i++)//draw all the menu sections
{
- memset(part_vbuf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
+ draw_menu(vid_buf, i, active_menu);
}
-#endif
-
- if(ngrav_enable && drawgrav_enable)
- draw_grav(vid_buf);
-
- draw_walls(part_vbuf);
-
- render_parts(part_vbuf);
- draw_other(part_vbuf);
-#ifndef OGLR
- if (render_mode & FIREMODE)
- render_fire(part_vbuf);
-#endif
- render_signs(part_vbuf);
-
-#ifndef OGLR
- if(ngrav_enable && display_mode & DISPLAY_WARP)
- render_gravlensing(part_vbuf, vid_buf);
-#endif
draw_svf_ui(vid_buf, sdl_mod & (KMOD_LCTRL|KMOD_RCTRL));
clearrect(vid_buf, xcoord-2, ycoord-2, xsize+4, ysize+4);
diff --git a/src/luaconsole.c b/src/luaconsole.c
index 759dd75..d32147c 100644
--- a/src/luaconsole.c
+++ b/src/luaconsole.c
@@ -96,6 +96,7 @@ void luacon_open(){
{"screenshot",&luatpt_screenshot},
{"element",&luatpt_getelement},
{"element_func",&luatpt_element_func},
+ {"graphics_func",&luatpt_graphics_func},
{NULL,NULL}
};
@@ -213,12 +214,15 @@ tpt.partsdata = nil");
}
lua_setfield(l, tptProperties, "eltransition");
- lua_el_func = calloc(PT_NUM, sizeof(int));
- lua_el_mode = calloc(PT_NUM, sizeof(int));
+ lua_el_func = (int*)calloc(PT_NUM, sizeof(int));
+ lua_el_mode = (int*)calloc(PT_NUM, sizeof(int));
+ lua_gr_func = (int*)calloc(PT_NUM, sizeof(int));
for(i = 0; i < PT_NUM; i++)
{
lua_el_mode[i] = 0;
+ lua_gr_func[i] = 0;
}
+ lua_sethook(l, &lua_hook, LUA_MASKCOUNT, 4000000);
}
#ifndef FFI
int luacon_partread(lua_State* l){
@@ -248,11 +252,11 @@ int luacon_partread(lua_State* l){
switch(format)
{
case 0:
- tempinteger = *((int*)(((void*)&parts[i])+offset));
+ tempinteger = *((int*)(((char*)&parts[i])+offset));
lua_pushnumber(l, tempinteger);
break;
case 1:
- tempfloat = *((float*)(((void*)&parts[i])+offset));
+ tempfloat = *((float*)(((char*)&parts[i])+offset));
lua_pushnumber(l, tempfloat);
break;
}
@@ -280,10 +284,10 @@ int luacon_partwrite(lua_State* l){
switch(format)
{
case 0:
- *((int*)(((void*)&parts[i])+offset)) = luaL_optinteger(l, 3, 0);
+ *((int*)(((char*)&parts[i])+offset)) = luaL_optinteger(l, 3, 0);
break;
case 1:
- *((float*)(((void*)&parts[i])+offset)) = luaL_optnumber(l, 3, 0);
+ *((float*)(((char*)&parts[i])+offset)) = luaL_optnumber(l, 3, 0);
break;
}
return 1;
@@ -410,11 +414,11 @@ int luacon_transitionread(lua_State* l){
switch(format)
{
case 0:
- tempinteger = *((int*)(((void*)&ptransitions[i])+offset));
+ tempinteger = *((int*)(((char*)&ptransitions[i])+offset));
lua_pushnumber(l, tempinteger);
break;
case 1:
- tempfloat = *((float*)(((void*)&ptransitions[i])+offset));
+ tempfloat = *((float*)(((char*)&ptransitions[i])+offset));
lua_pushnumber(l, tempfloat);
break;
}
@@ -444,10 +448,10 @@ int luacon_transitionwrite(lua_State* l){
switch(format)
{
case 0:
- *((int*)(((void*)&ptransitions[i])+offset)) = luaL_optinteger(l, 3, 0);
+ *((int*)(((char*)&ptransitions[i])+offset)) = luaL_optinteger(l, 3, 0);
break;
case 1:
- *((float*)(((void*)&ptransitions[i])+offset)) = luaL_optnumber(l, 3, 0);
+ *((float*)(((char*)&ptransitions[i])+offset)) = luaL_optnumber(l, 3, 0);
break;
}
return 0;
@@ -597,19 +601,19 @@ int luacon_elementread(lua_State* l){
switch(format)
{
case 0:
- tempinteger = *((int*)(((void*)&ptypes[i])+offset));
+ tempinteger = *((int*)(((char*)&ptypes[i])+offset));
lua_pushnumber(l, tempinteger);
break;
case 1:
- tempfloat = *((float*)(((void*)&ptypes[i])+offset));
+ tempfloat = *((float*)(((char*)&ptypes[i])+offset));
lua_pushnumber(l, tempfloat);
break;
case 2:
- tempstring = *((char**)(((void*)&ptypes[i])+offset));
+ tempstring = *((char**)(((char*)&ptypes[i])+offset));
lua_pushstring(l, tempstring);
break;
case 3:
- tempinteger = *((unsigned char*)(((void*)&ptypes[i])+offset));
+ tempinteger = *((unsigned char*)(((char*)&ptypes[i])+offset));
lua_pushnumber(l, tempinteger);
break;
}
@@ -641,10 +645,10 @@ int luacon_elementwrite(lua_State* l){
switch(format)
{
case 0:
- *((int*)(((void*)&ptypes[i])+offset)) = luaL_optinteger(l, 3, 0);
+ *((int*)(((char*)&ptypes[i])+offset)) = luaL_optinteger(l, 3, 0);
break;
case 1:
- *((float*)(((void*)&ptypes[i])+offset)) = luaL_optnumber(l, 3, 0);
+ *((float*)(((char*)&ptypes[i])+offset)) = luaL_optnumber(l, 3, 0);
break;
case 2:
tempstring = mystrdup(luaL_optstring(l, 3, ""));
@@ -667,11 +671,11 @@ int luacon_elementwrite(lua_State* l){
return luaL_error(l, "Name in use");
}
}
- *((char**)(((void*)&ptypes[i])+offset)) = tempstring;
+ *((char**)(((char*)&ptypes[i])+offset)) = tempstring;
//Need some way of cleaning up previous values
break;
case 3:
- *((unsigned char*)(((void*)&ptypes[i])+offset)) = luaL_optinteger(l, 3, 0);
+ *((unsigned char*)(((char*)&ptypes[i])+offset)) = luaL_optinteger(l, 3, 0);
break;
}
if (modified_stuff)
@@ -733,26 +737,39 @@ int luacon_step(int mx, int my, int selectl, int selectr){
lua_setfield(l, tptProperties, "mousey");
lua_setfield(l, tptProperties, "selectedl");
lua_setfield(l, tptProperties, "selectedr");
- if(step_functions[0]){
- //Set mouse globals
- for(i = 0; i<6; i++){
- if(step_functions[i]){
- lua_rawgeti(l, LUA_REGISTRYINDEX, step_functions[i]);
- callret = lua_pcall(l, 0, 0, 0);
- if (callret)
+ for(i = 0; i<6; i++){
+ if(step_functions[i]){
+ loop_time = SDL_GetTicks();
+ lua_rawgeti(l, LUA_REGISTRYINDEX, step_functions[i]);
+ callret = lua_pcall(l, 0, 0, 0);
+ if (callret)
+ {
+ // failed, TODO: better error reporting
+ printf("%s\n",luacon_geterror());
+ if (!strcmp(luacon_geterror(),"Error: Infinite loop"))
{
- // failed, TODO: better error reporting
- printf("%s\n",luacon_geterror());
+ lua_pushcfunction(l,&luatpt_unregister_step);
+ lua_rawgeti(l, LUA_REGISTRYINDEX, step_functions[i]);
+ lua_pcall(l, 1, 0, 0);
}
}
}
- return tempret;
}
return 0;
}
int luacon_eval(char *command){
+ loop_time = SDL_GetTicks();
return luaL_dostring (l, command);
}
+void lua_hook(lua_State *L, lua_Debug *ar)
+{
+ if(ar->event == LUA_HOOKCOUNT && SDL_GetTicks()-loop_time > 3000)
+ {
+ if (confirm_ui(vid_buf,"Infinite Loop","The Lua code might have an infinite loop. Press OK to stop it","OK"))
+ luaL_error(l,"Error: Infinite loop");
+ loop_time = SDL_GetTicks();
+ }
+}
int luacon_part_update(int t, int i, int x, int y, int surround_space, int nt)
{
int retval = 0;
@@ -771,6 +788,29 @@ int luacon_part_update(int t, int i, int x, int y, int surround_space, int nt)
}
return retval;
}
+int luacon_graphics_update(int t, int i, int *pixel_mode, int *cola, int *colr, int *colg, int *colb, int *firea, int *firer, int *fireg, int *fireb)
+{
+ int cache = 0;
+ lua_rawgeti(l, LUA_REGISTRYINDEX, lua_gr_func[t]);
+ lua_pushinteger(l, i);
+ lua_pushinteger(l, *colr);
+ lua_pushinteger(l, *colg);
+ lua_pushinteger(l, *colb);
+ lua_pcall(l, 4, 10, 0);
+
+ cache = luaL_optint(l, 2, 0);
+ *pixel_mode = luaL_optint(l, 3, *pixel_mode);
+ *cola = luaL_optint(l, 4, *cola);
+ *colr = luaL_optint(l, 5, *colr);
+ *colg = luaL_optint(l, 6, *colg);
+ *colb = luaL_optint(l, 7, *colb);
+ *firea = luaL_optint(l, 8, *firea);
+ *firer = luaL_optint(l, 9, *firer);
+ *fireg = luaL_optint(l, 10, *fireg);
+ *fireb = luaL_optint(l, 11, *fireb);
+ lua_pop(l, 10);
+ return cache;
+}
char *luacon_geterror(){
char *error = lua_tostring(l, -1);
if(error==NULL || !error[0]){
@@ -855,6 +895,29 @@ int luatpt_element_func(lua_State *l)
}
return 0;
}
+int luatpt_graphics_func(lua_State *l)
+{
+ if(lua_isfunction(l, 1))
+ {
+ int element = luaL_optint(l, 2, 0);
+ int function;
+ lua_pushvalue(l, 1);
+ function = luaL_ref(l, LUA_REGISTRYINDEX);
+ if(element > 0 && element < PT_NUM)
+ {
+ lua_gr_func[element] = function;
+ graphicscache[element].isready = 0;
+ return 0;
+ }
+ else
+ {
+ return luaL_error(l, "Invalid element");
+ }
+ }
+ else
+ return luaL_error(l, "Not a function");
+ return 0;
+}
int luatpt_error(lua_State* l)
{
char *error = "";
@@ -1075,8 +1138,13 @@ int luatpt_reset_spark(lua_State* l)
{
if (parts[i].type==PT_SPRK)
{
- parts[i].type = parts[i].ctype;
- parts[i].life = 4;
+ if (parts[i].ctype >= 0 && parts[i].ctype < PT_NUM)
+ {
+ parts[i].type = parts[i].ctype;
+ parts[i].life = 0;
+ }
+ else
+ kill_part(i);
}
}
return 0;
@@ -1270,7 +1338,7 @@ int luatpt_set_property(lua_State* l)
} else {
t = luaL_optint(l, 2, 0);
}
- if (format == 3 && (t<0 || t>=PT_NUM))
+ if (format == 3 && (t<0 || t>=PT_NUM || !ptypes[t].enabled))
return luaL_error(l, "Unrecognised element number '%d'", t);
} else {
name = luaL_optstring(l, 2, "dust");
@@ -1462,9 +1530,9 @@ int luatpt_drawrect(lua_State* l)
if (x<0 || y<0 || x>=XRES+BARSIZE || y>=YRES+MENUSIZE)
return luaL_error(l, "Screen coordinates out of range (%d,%d)", x, y);
if(x+w > XRES+BARSIZE)
- w = XRES-x;
+ w = XRES+BARSIZE-x;
if(y+h > YRES+MENUSIZE)
- h = YRES-y;
+ h = YRES+MENUSIZE-y;
if (r<0) r = 0;
if (r>255) r = 255;
if (g<0) g = 0;
@@ -1496,9 +1564,9 @@ int luatpt_fillrect(lua_State* l)
if (x<0 || y<0 || x>=XRES+BARSIZE || y>=YRES+MENUSIZE)
return luaL_error(l, "Screen coordinates out of range (%d,%d)", x, y);
if(x+w > XRES+BARSIZE)
- w = XRES-x;
+ w = XRES+BARSIZE-x;
if(y+h > YRES+MENUSIZE)
- h = YRES-y;
+ h = YRES+MENUSIZE-y;
if (r<0) r = 0;
if (r>255) r = 255;
if (g<0) g = 0;
@@ -1893,6 +1961,8 @@ int luatpt_setdebug(lua_State* l)
int luatpt_setfpscap(lua_State* l)
{
int fpscap = luaL_optint(l, 1, 0);
+ if (fpscap < 2)
+ return luaL_error(l, "fps cap too small");
limitFPS = fpscap;
return 0;
}
diff --git a/src/main.c b/src/main.c
index 4cbef1c..224dfb6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -151,7 +151,7 @@ static const char *it_msg =
"\n"
"Contributors: \bgStanislaw K Skowronek (\brhttp://powder.unaligned.org\bg, \bbirc.unaligned.org #wtf\bg),\n"
"\bgSimon Robertshaw, Skresanov Savely, cracker64, Catelite, Bryan Hoyle, Nathan Cousins, jacksonmj,\n"
- "\bgLieuwe Mosch, Anthony Boot, Matthew \"me4502\", MaksProg\n"
+ "\bgLieuwe Mosch, Anthony Boot, Matthew \"me4502\", MaksProg, jacob1\n"
"\n"
"\bgTo use online features such as saving, you need to register at: \brhttp://powdertoy.co.uk/Register.html\n"
"\n"
@@ -221,6 +221,7 @@ int frameidx = 0;
//int CGOL = 0;
//int GSPEED = 1;//causes my .exe to crash..
int sound_enable = 0;
+int loop_time = 0;
int debug_flags = 0;
int debug_perf_istart = 1;
@@ -755,7 +756,7 @@ int main(int argc, char *argv[])
void *http_ver_check, *http_session_check = NULL;
char *ver_data=NULL, *check_data=NULL, *tmp;
//char console_error[255] = "";
- int result, i, j, bq, bc = 0, fire_fc=0, do_check=0, do_s_check=0, old_version=0, http_ret=0,http_s_ret=0, major, minor, buildnum, is_beta = 0, old_ver_len, new_message_len=0;
+ int result, i, j, bq, bc = 0, do_check=0, do_s_check=0, old_version=0, http_ret=0,http_s_ret=0, major, minor, buildnum, is_beta = 0, old_ver_len, new_message_len=0;
#ifdef INTERNAL
int vs = 0;
#endif
@@ -770,6 +771,7 @@ int main(int argc, char *argv[])
unsigned int rgbSave = PIXRGB(127,0,0);
SDL_AudioSpec fmt;
int username_flash = 0, username_flash_t = 1;
+ int saveOpenError = 0;
#ifdef PTW32_STATIC_LIB
pthread_win32_process_attach_np();
pthread_win32_thread_attach_np();
@@ -779,7 +781,6 @@ int main(int argc, char *argv[])
part_vbuf = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); //Extra video buffer
part_vbuf_store = part_vbuf;
pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
- int saveOpenError = 0;
gravity_init();
GSPEED = 1;
@@ -902,12 +903,12 @@ int main(int argc, char *argv[])
}
else if (!strncmp(argv[i], "ptsave", 7) && i+1<argc)
{
- puts("Got ptsave");
int ci = 0, ns = 0, okay = 0;
char * tempString = argv[i+1];
int tempStringLength = strlen(argv[i+1])-7;
int tempSaveID = 0;
char tempNumberString[32];
+ puts("Got ptsave");
i++;
tempNumberString[31] = 0;
tempNumberString[0] = 0;
@@ -1002,54 +1003,12 @@ int main(int argc, char *argv[])
update_airh();
}
-#ifdef OGLR
- part_vbuf = vid_buf;
-#else
- if(ngrav_enable && display_mode & DISPLAY_WARP)
- {
- part_vbuf = part_vbuf_store;
- memset(vid_buf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- } else {
- part_vbuf = vid_buf;
- }
-#endif
-
if(gravwl_timeout)
{
if(gravwl_timeout==1)
gravity_mask();
gravwl_timeout--;
}
-#ifdef OGLR
- if (display_mode & DISPLAY_PERS)//save background for persistent, then clear
- {
- clearScreen(0.01f);
- memset(part_vbuf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- }
- else //clear screen every frame
- {
- clearScreen(1.0f);
- memset(part_vbuf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- if (display_mode & DISPLAY_AIR)//air only gets drawn in these modes
- {
- draw_air(part_vbuf);
- }
- }
-#else
- if (display_mode & DISPLAY_AIR)//air only gets drawn in these modes
- {
- draw_air(part_vbuf);
- }
- else if (display_mode & DISPLAY_PERS)//save background for persistent, then clear
- {
- memcpy(part_vbuf, pers_bg, (XRES+BARSIZE)*YRES*PIXELSIZE);
- memset(part_vbuf+((XRES+BARSIZE)*YRES), 0, ((XRES+BARSIZE)*YRES*PIXELSIZE)-((XRES+BARSIZE)*YRES*PIXELSIZE));
- }
- else //clear screen every frame
- {
- memset(part_vbuf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- }
-#endif
//Can't be too sure (Limit the cursor size)
if (bsx>1180)
@@ -1067,10 +1026,19 @@ int main(int argc, char *argv[])
sandcolour_b = sandcolour_r = sandcolour_g = (int)(20.0f*sin((float)sandcolour_frame*(M_PI/180.0f)));
sandcolour_frame++;
sandcolour_frame%=360;
-
- if(ngrav_enable && drawgrav_enable)
- draw_grav(vid_buf);
- draw_walls(part_vbuf);
+
+#ifdef OGLR
+ part_vbuf = vid_buf;
+#else
+ if(ngrav_enable && (display_mode & DISPLAY_WARP))
+ {
+ part_vbuf = part_vbuf_store;
+ memset(vid_buf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
+ } else {
+ part_vbuf = vid_buf;
+ }
+#endif
+ render_before(part_vbuf);
if(debug_flags & (DEBUG_PERFORMANCE_CALC|DEBUG_PERFORMANCE_FRAME))
{
@@ -1099,8 +1067,9 @@ int main(int argc, char *argv[])
#endif
}
- render_parts(part_vbuf); //draw particles
- draw_other(part_vbuf);
+ render_after(part_vbuf, vid_buf);
+ if(su == WL_GRAV+100)
+ draw_grav_zones(part_vbuf);
if(debug_flags & (DEBUG_PERFORMANCE_CALC|DEBUG_PERFORMANCE_FRAME))
{
@@ -1118,9 +1087,6 @@ int main(int argc, char *argv[])
debug_perf_istart %= DEBUG_PERF_FRAMECOUNT;
}
- if(sl == WL_GRAV+100 || sr == WL_GRAV+100)
- draw_grav_zones(part_vbuf);
-
gravity_update_async(); //Check for updated velocity maps from gravity thread
if (!sys_pause||framerender) //Only update if not paused
memset(gravmap, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); //Clear the old gravmap
@@ -1130,31 +1096,6 @@ int main(int argc, char *argv[])
sys_pause = 1;
}
- if (display_mode & DISPLAY_PERS)
- {
- 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);
- }
- else
- {
- memcpy(pers_bg, vid_buf, (XRES+BARSIZE)*YRES*PIXELSIZE);
- }
- fire_fc = (fire_fc+1) % 3;
- }
-
-#ifndef OGLR
- if (render_mode & FIREMODE)
- render_fire(part_vbuf);
-#endif
-
- render_signs(part_vbuf);
-
-#ifndef OGLR
- if(ngrav_enable && display_mode & DISPLAY_WARP)
- render_gravlensing(part_vbuf, vid_buf);
-#endif
-
memset(vid_buf+((XRES+BARSIZE)*YRES), 0, (PIXELSIZE*(XRES+BARSIZE))*MENUSIZE);//clear menu areas
clearrect(vid_buf, XRES-1, 0, BARSIZE+1, YRES);
@@ -1553,9 +1494,8 @@ int main(int argc, char *argv[])
}
else
{
- rgbSave = decorations_ui(vid_buf,&bsx,&bsy,rgbSave);//decoration_mode = !decoration_mode;
decorations_enable = 1;
- sys_pause=1;
+ rgbSave = decorations_ui(vid_buf,&bsx,&bsy,rgbSave);//decoration_mode = !decoration_mode;
}
}
if (sdl_key=='g')
@@ -1590,8 +1530,13 @@ int main(int argc, char *argv[])
for (i=0; i<NPART; i++)
if (parts[i].type==PT_SPRK)
{
- parts[i].type = parts[i].ctype;
- parts[i].life = 0;
+ if (parts[i].ctype >= 0 && parts[i].ctype < PT_NUM)
+ {
+ parts[i].type = parts[i].ctype;
+ parts[i].life = 0;
+ }
+ else
+ kill_part(i);
}
}
else
@@ -2807,8 +2752,6 @@ int main(int argc, char *argv[])
break;
}
free(console);
- if (!console_mode)
- hud_enable = 1;
#else
char *console;
sys_pause = 1;
@@ -2821,12 +2764,9 @@ int main(int argc, char *argv[])
break;
}
free(console);
- if (!console_mode)
- hud_enable = 1;
#endif
}
- //execute python step hook
sdl_blit(0, 0, XRES+BARSIZE, YRES+MENUSIZE, vid_buf, XRES+BARSIZE);
//Setting an element for the stick man
diff --git a/src/powder.c b/src/powder.c
index 6d92bc8..700a6d5 100644
--- a/src/powder.c
+++ b/src/powder.c
@@ -176,6 +176,7 @@ void init_can_move()
//whol eats anar
can_move[PT_ANAR][PT_WHOL] = 1;
can_move[PT_ANAR][PT_NWHL] = 1;
+ can_move[PT_THDR][PT_THDR] = 2;
}
/*
@@ -257,7 +258,7 @@ int try_move(int i, int x, int y, int nx, int ny)
if (!e) //if no movement
{
- if (parts[i].type!=PT_NEUT && parts[i].type!=PT_PHOT && parts[i].type!=PT_ELEC)
+ if (!(ptypes[parts[i].type].properties & TYPE_ENERGY))
return 0;
if (!legacy_enable && parts[i].type==PT_PHOT && r)//PHOT heat conduction
{
@@ -271,7 +272,7 @@ int try_move(int i, int x, int y, int nx, int ny)
if (!parts[r>>8].ctype)
parts[r>>8].ctype = parts[i].type;
}
- if ((r&0xFF)==PT_PRTI && (parts[i].type==PT_PHOT || parts[i].type==PT_NEUT || parts[i].type==PT_ELEC))
+ if ((r&0xFF)==PT_PRTI && (ptypes[parts[i].type].properties & TYPE_ENERGY))
{
int nnx, count;
for (count=0; count<8; count++)
@@ -343,7 +344,8 @@ int try_move(int i, int x, int y, int nx, int ny)
}
if ((r&0xFF)==PT_VOID || (r&0xFF)==PT_PVOD) //this is where void eats particles
{
- kill_part(i);
+ if(!parts[r>>8].ctype || (parts[r>>8].ctype==parts[i].type)!=(parts[r>>8].tmp&1))
+ kill_part(i);
return 0;
}
if ((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) //this is where blackhole eats particles
@@ -427,7 +429,7 @@ int do_move(int i, int x, int y, float nxf, float nyf)
kill_part(i);
return -1;
}
- if (t==PT_PHOT||t==PT_NEUT||t==PT_ELEC)
+ if (ptypes[t].properties & TYPE_ENERGY)
photons[ny][nx] = t|(i<<8);
else if (t)
pmap[ny][nx] = t|(i<<8);
@@ -678,7 +680,7 @@ inline void part_change_type(int i, int x, int y, int t)//changes the type of pa
}
parts[i].type = t;
- if (t==PT_PHOT || t==PT_NEUT || t==PT_ELEC)
+ if (ptypes[t].properties & TYPE_ENERGY)
{
photons[y][x] = t|(i<<8);
if ((pmap[y][x]>>8)==i)
@@ -717,23 +719,25 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a
{
if (t==SPC_HEAT&&parts[pmap[y][x]>>8].temp<MAX_TEMP)
{
- if ((pmap[y][x]&0xFF)==PT_PUMP || (pmap[y][x]&0xFF)==PT_GPMP) {
- parts[pmap[y][x]>>8].temp = restrict_flt(parts[pmap[y][x]>>8].temp + 0.1f, MIN_TEMP, MAX_TEMP);
- } else if ((sdl_mod & (KMOD_SHIFT)) && (sdl_mod & (KMOD_CTRL))) {
- parts[pmap[y][x]>>8].temp = restrict_flt(parts[pmap[y][x]>>8].temp + 50.0f, MIN_TEMP, MAX_TEMP);
- } else {
- parts[pmap[y][x]>>8].temp = restrict_flt(parts[pmap[y][x]>>8].temp + 4.0f, MIN_TEMP, MAX_TEMP);
- }
+ float heatchange;
+ int r = pmap[y][x], fast = ((sdl_mod & (KMOD_SHIFT)) && (sdl_mod & (KMOD_CTRL)));
+ if ((r&0xFF)==PT_PUMP || (r&0xFF)==PT_GPMP)
+ heatchange = fast?1.0f:.1f;
+ else
+ heatchange = fast?50.0f:4.0f;
+
+ parts[r>>8].temp = restrict_flt(parts[r>>8].temp + heatchange, MIN_TEMP, MAX_TEMP);
}
if (t==SPC_COOL&&parts[pmap[y][x]>>8].temp>MIN_TEMP)
{
- if ((pmap[y][x]&0xFF)==PT_PUMP || (pmap[y][x]&0xFF)==PT_GPMP) {
- parts[pmap[y][x]>>8].temp = restrict_flt(parts[pmap[y][x]>>8].temp - 0.1f, MIN_TEMP, MAX_TEMP);
- } else if ((sdl_mod & (KMOD_SHIFT)) && (sdl_mod & (KMOD_CTRL))) {
- parts[pmap[y][x]>>8].temp = restrict_flt(parts[pmap[y][x]>>8].temp - 50.0f, MIN_TEMP, MAX_TEMP);
- } else {
- parts[pmap[y][x]>>8].temp = restrict_flt(parts[pmap[y][x]>>8].temp - 4.0f, MIN_TEMP, MAX_TEMP);
- }
+ float heatchange;
+ int r = pmap[y][x], fast = ((sdl_mod & (KMOD_SHIFT)) && (sdl_mod & (KMOD_CTRL)));
+ if ((r&0xFF)==PT_PUMP || (r&0xFF)==PT_GPMP)
+ heatchange = fast?1.0f:.1f;
+ else
+ heatchange = fast?50.0f:4.0f;
+
+ parts[r>>8].temp = restrict_flt(parts[r>>8].temp - heatchange, MIN_TEMP, MAX_TEMP);
}
return pmap[y][x]>>8;
}
@@ -843,7 +847,7 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a
}
return -1;
}
- if (photons[y][x] && (t==PT_PHOT||t==PT_NEUT||t==PT_ELEC))
+ if (photons[y][x] && (ptypes[t].properties & TYPE_ENERGY))
return -1;
if (pfree == -1)
return -1;
@@ -963,7 +967,7 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a
parts[i].tmp = 10;
if (t==PT_BRAY)
parts[i].life = 30;
- if (t==PT_PUMP)
+ if (t==PT_PUMP || t==PT_GPMP)
parts[i].life= 10;
if (t==PT_SING)
parts[i].life = rand()%50+60;
@@ -1104,7 +1108,7 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a
if (t==PT_BIZR||t==PT_BIZRG||t==PT_BIZRS)
parts[i].ctype = 0x47FFFF;
//and finally set the pmap/photon maps to the newly created particle
- if (t==PT_PHOT||t==PT_NEUT||t==PT_ELEC)
+ if (ptypes[t].properties & TYPE_ENERGY)
photons[y][x] = t|(i<<8);
else if (t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH)
pmap[y][x] = t|(i<<8);
@@ -1440,7 +1444,7 @@ void create_arc(int sx, int sy, int dx, int dy, int midpoints, int variance, int
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;
- float mv, dx, dy, ix, iy, lx, ly, nrx, nry, dp, ctemph, ctempl, gravtot;
+ float mv, dx, dy, ix, iy, lx, ly, nrx, nry, dp, ctemph, ctempl, gravtot, gel_scale;
int fin_x, fin_y, clear_x, clear_y, stagnant;
float fin_xf, fin_yf, clear_xf, clear_yf;
float nn, ct1, ct2, swappage;
@@ -1878,7 +1882,7 @@ void update_particles_i(pixel *vid, int start, int inc)
}
}
- float gel_scale = 1.0f;
+ gel_scale = 1.0f;
if (t==PT_GEL)
gel_scale = parts[i].tmp*2.55f;
@@ -2349,7 +2353,7 @@ killed:
stagnant = parts[i].flags & FLAG_STAGNANT;
parts[i].flags &= ~FLAG_STAGNANT;
- if ((t==PT_PHOT||t==PT_NEUT||t==PT_ELEC)) {
+ if (ptypes[t].properties & TYPE_ENERGY) {
if (t == PT_PHOT) {
if (parts[i].flags&FLAG_SKIPMOVE)
{
@@ -2730,8 +2734,7 @@ movedone:
int parts_lastActiveIndex = NPART-1;
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;
+ int i, x, y, t;
int lastPartUsed = 0;
int lastPartUnused = -1;
#ifdef MT
@@ -2751,7 +2754,7 @@ void update_particles(pixel *vid)//doesn't update the particles themselves, but
y = (int)(parts[i].y+0.5f);
if (x>=0 && y>=0 && x<XRES && y<YRES)
{
- if (t==PT_PHOT||t==PT_NEUT||t==PT_ELEC)
+ if (ptypes[t].properties & TYPE_ENERGY)
photons[y][x] = t|(i<<8);
else
pmap[y][x] = t|(i<<8);
@@ -2792,31 +2795,6 @@ void update_particles(pixel *vid)//doesn't update the particles themselves, but
}
update_particles_i(vid, 0, 1);
-
- // this should probably be elsewhere
- for (y=0; y<YRES/CELL; y++)
- for (x=0; x<XRES/CELL; x++)
- if (bmap[y][x]==WL_STREAM)
- {
- lx = x*CELL + CELL*0.5f;
- ly = y*CELL + CELL*0.5f;
- for (t=0; t<1024; t++)
- {
- nx = (int)(lx+0.5f);
- ny = (int)(ly+0.5f);
- if (nx<0 || nx>=XRES || ny<0 || ny>=YRES)
- break;
- addpixel(vid, nx, ny, 255, 255, 255, 64);
- i = nx/CELL;
- j = ny/CELL;
- lx += vx[j][i]*0.125f;
- ly += vy[j][i]*0.125f;
- if (bmap[j][i]==WL_STREAM && i!=x && j!=y)
- break;
- }
- drawtext(vid, x*CELL, y*CELL-2, "\x8D", 255, 255, 255, 128);
- }
-
}
void clear_area(int area_x, int area_y, int area_w, int area_h)