summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c339
1 files changed, 144 insertions, 195 deletions
diff --git a/src/main.c b/src/main.c
index bb3f5b7..55908f3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -152,7 +152,7 @@ static const char *it_msg =
"'P' will take a screenshot and save it into the current directory.\n"
"\n"
"\bgCopyright (c) 2008-11 Stanislaw K Skowronek (\brhttp://powder.unaligned.org\bg, \bbirc.unaligned.org #wtf\bg)\n"
- "\bgCopyright (c) 2010-11 Simon Robertshaw, Skresanov Savely, cracker64, Bryan Hoyle, Nathan Cousins, jacksonmj\n"
+ "\bgCopyright (c) 2010-11 Simon Robertshaw, Skresanov Savely, cracker64, Bryan Hoyle, Nathan Cousins, jacksonmj, Lieuwe Mosch\n"
"\n"
"\bgTo use online features such as saving, you need to register at: \brhttp://powdertoy.co.uk/Register.html"
;
@@ -224,7 +224,7 @@ void sdl_seticon(void)
//SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(app_icon_w32, 32, 32, 32, 128, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
//SDL_WM_SetIcon(icon, NULL/*app_icon_mask*/);
#else
- SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(app_icon, 16, 16, 32, 128, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
+ SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(app_icon, 16, 16, 32, 64, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
SDL_WM_SetIcon(icon, NULL/*app_icon_mask*/);
#endif
#endif
@@ -310,11 +310,12 @@ void *build_thumb(int *size, int bzip2)
return d;
}
-void *build_save(int *size, int x0, int y0, int w, int h)
+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;
int i,j,x,y,p=0,*m=calloc(XRES*YRES, sizeof(int));
int bx0=x0/CELL, by0=y0/CELL, bw=(w+CELL-1)/CELL, bh=(h+CELL-1)/CELL;
+ particle *parts = partsptr;
// normalize coordinates
x0 = bx0*CELL;
@@ -353,7 +354,8 @@ void *build_save(int *size, int x0, int y0, int w, int h)
y = (int)(parts[i].y+0.5f);
if (x>=x0 && x<x0+w && y>=y0 && y<y0+h) {
if (!m[(x-x0)+(y-y0)*w] ||
- parts[m[(x-x0)+(y-y0)*w]-1].type == PT_PHOT)
+ parts[m[(x-x0)+(y-y0)*w]-1].type == PT_PHOT ||
+ parts[m[(x-x0)+(y-y0)*w]-1].type == PT_NEUT)
m[(x-x0)+(y-y0)*w] = i+1;
}
}
@@ -479,12 +481,13 @@ void *build_save(int *size, int x0, int y0, int w, int h)
return c;
}
-int parse_save(void *save, int size, int replace, int x0, int y0)
+int parse_save(void *save, int size, int replace, int x0, int y0, 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 pmap[YRES][XRES])
{
unsigned char *d,*c=save;
int q,i,j,k,x,y,p=0,*m=calloc(XRES*YRES, sizeof(int)), ver, pty, ty, legacy_beta=0;
int bx0=x0/CELL, by0=y0/CELL, bw, bh, w, h;
int fp[NPART], nf=0, new_format = 0, ttv = 0;
+ particle *parts = partsptr;
//New file header uses PSv, replacing fuC. This is to detect if the client uses a new save format for temperatures
//This creates a problem for old clients, that display and "corrupt" error instead of a "newer version" error
@@ -564,19 +567,7 @@ int parse_save(void *save, int size, int replace, int x0, int y0)
gravityMode = 0;
airMode = 0;
}
- memset(bmap, 0, sizeof(bmap));
- memset(emap, 0, sizeof(emap));
- memset(signs, 0, sizeof(signs));
- memset(parts, 0, sizeof(particle)*NPART);
- memset(pmap, 0, sizeof(pmap));
- memset(vx, 0, sizeof(vx));
- memset(vy, 0, sizeof(vy));
- memset(pv, 0, sizeof(pv));
- memset(photons, 0, sizeof(photons));
- memset(wireless, 0, sizeof(wireless));
- memset(gol2, 0, sizeof(gol2));
- memset(portal, 0, sizeof(portal));
- death = death2 = ISSPAWN1 = ISSPAWN2 = 0;
+ clear_sim();
}
// make a catalog of free parts
@@ -908,13 +899,35 @@ corrupt:
if (replace)
{
legacy_enable = 0;
- memset(signs, 0, sizeof(signs));
- memset(parts, 0, sizeof(particle)*NPART);
- memset(bmap, 0, sizeof(bmap));
+ clear_sim();
}
return 1;
}
+void clear_sim(void)
+{
+ memset(bmap, 0, sizeof(bmap));
+ memset(emap, 0, sizeof(emap));
+ memset(signs, 0, sizeof(signs));
+ memset(parts, 0, sizeof(particle)*NPART);
+ memset(pmap, 0, sizeof(pmap));
+ memset(pv, 0, sizeof(pv));
+ memset(vx, 0, sizeof(vx));
+ memset(vy, 0, sizeof(vy));
+ memset(fvx, 0, sizeof(fvx));
+ memset(fvy, 0, sizeof(fvy));
+ memset(photons, 0, sizeof(photons));
+ memset(wireless, 0, sizeof(wireless));
+ memset(gol2, 0, sizeof(gol2));
+ memset(portal, 0, sizeof(portal));
+ death = death2 = ISSPAWN1 = ISSPAWN2 = 0;
+ memset(pers_bg, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
+ memset(fire_bg, 0, XRES*YRES*PIXELSIZE);
+ memset(fire_r, 0, sizeof(fire_r));
+ memset(fire_g, 0, sizeof(fire_g));
+ memset(fire_b, 0, sizeof(fire_b));
+}
+
// stamps library
stamp stamps[STAMP_MAX];//[STAMP_X*STAMP_Y];
@@ -999,7 +1012,7 @@ void stamp_save(int x, int y, int w, int h)
FILE *f;
int n;
char fn[64], sn[16];
- void *s=build_save(&n, x, y, w, h);
+ void *s=build_save(&n, x, y, w, h, bmap, fvx, fvy, signs, parts);
#ifdef WIN32
_mkdir("stamps");
@@ -1203,8 +1216,7 @@ char console_error[255] = "";
//functions callable from python:
-static PyObject*
-emb_create(PyObject *self, PyObject *args, PyObject *keywds)
+static PyObject* emb_create(PyObject *self, PyObject *args, PyObject *keywds)
{
int x,y,t;
char *name = "";
@@ -1216,9 +1228,8 @@ emb_create(PyObject *self, PyObject *args, PyObject *keywds)
console_parse_type(name, &t, console_error);
return Py_BuildValue("i",create_part(-1,x,y,t));
}
-//sys_pause = !sys_pause
-static PyObject*
-emb_pause(PyObject *self, PyObject *args)
+
+static PyObject* emb_pause(PyObject *self, PyObject *args)
{
int x,y,t;
if(!PyArg_ParseTuple(args, ":unpause"))
@@ -1228,8 +1239,7 @@ emb_pause(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_unpause(PyObject *self, PyObject *args)
+static PyObject* emb_unpause(PyObject *self, PyObject *args)
{
int x,y,t;
if(!PyArg_ParseTuple(args, ":pause"))
@@ -1239,8 +1249,7 @@ emb_unpause(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_toggle_pause(PyObject *self, PyObject *args)
+static PyObject* emb_toggle_pause(PyObject *self, PyObject *args)
{
int x,y,t;
if(!PyArg_ParseTuple(args, ":toggle_pause"))
@@ -1251,9 +1260,7 @@ emb_toggle_pause(PyObject *self, PyObject *args)
}
//console_mode
-
-static PyObject*
-emb_toggle_console(PyObject *self, PyObject *args)
+static PyObject* emb_toggle_console(PyObject *self, PyObject *args)
{
int x,y,t;
if(!PyArg_ParseTuple(args, ":toggle_console"))
@@ -1263,8 +1270,7 @@ emb_toggle_console(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_open_console(PyObject *self, PyObject *args)
+static PyObject* emb_open_console(PyObject *self, PyObject *args)
{
int x,y,t;
if(!PyArg_ParseTuple(args, ":toggle_console"))
@@ -1274,8 +1280,7 @@ emb_open_console(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_close_console(PyObject *self, PyObject *args)
+static PyObject* emb_close_console(PyObject *self, PyObject *args)
{
int x,y,t;
if(!PyArg_ParseTuple(args, ":toggle_console"))
@@ -1285,8 +1290,7 @@ emb_close_console(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_log(PyObject *self, PyObject *args)
+static PyObject* emb_log(PyObject *self, PyObject *args)
{
char *buffer;
if(!PyArg_ParseTuple(args, "s:log",&buffer))
@@ -1299,8 +1303,7 @@ emb_log(PyObject *self, PyObject *args)
char console_more=0;
-static PyObject*
-emb_console_more(PyObject *self, PyObject *args)
+static PyObject* emb_console_more(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":log"))
return NULL;
@@ -1309,8 +1312,7 @@ emb_console_more(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_console_less(PyObject *self, PyObject *args)
+static PyObject* emb_console_less(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":log"))
return NULL;
@@ -1319,10 +1321,7 @@ emb_console_less(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-//drawtext(vid_buf, 15, 175-(cc*12), currentcommand->command, 255, 255, 255, 255);
-
-static PyObject*
-emb_reset_pressure(PyObject *self, PyObject *args)
+static PyObject* emb_reset_pressure(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":reset_pressure"))
return NULL;
@@ -1335,8 +1334,7 @@ emb_reset_pressure(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_reset_velocity(PyObject *self, PyObject *args)
+static PyObject* emb_reset_velocity(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":reset_velocity"))
return NULL;
@@ -1350,8 +1348,7 @@ emb_reset_velocity(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_reset_sparks(PyObject *self, PyObject *args)
+static PyObject* emb_reset_sparks(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":reset_sparks"))
return NULL;
@@ -1367,8 +1364,7 @@ emb_reset_sparks(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_set_life(PyObject *self, PyObject *args, PyObject *keywds)
+static PyObject* emb_set_life(PyObject *self, PyObject *args, PyObject *keywds)
{
int i = -1,life,j,x=-1,y=-1;
char *name = "";
@@ -1408,8 +1404,7 @@ emb_set_life(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_set_type(PyObject *self, PyObject *args, PyObject *keywds)
+static PyObject* emb_set_type(PyObject *self, PyObject *args, PyObject *keywds)
{
int i = -1,life,j=-1,x=-1,y=-1;
char *name = "";
@@ -1451,8 +1446,7 @@ emb_set_type(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_set_temp(PyObject *self, PyObject *args, PyObject *keywds)
+static PyObject* emb_set_temp(PyObject *self, PyObject *args, PyObject *keywds)
{
int i = -1,life,j,x=-1,y=-1;
char *name = "";
@@ -1492,8 +1486,7 @@ emb_set_temp(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_set_tmp(PyObject *self, PyObject *args, PyObject *keywds)
+static PyObject* emb_set_tmp(PyObject *self, PyObject *args, PyObject *keywds)
{
int i = -1,life,j,x=-1,y=-1;
char *name = "";
@@ -1533,8 +1526,7 @@ emb_set_tmp(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_set_x(PyObject *self, PyObject *args, PyObject *keywds)
+static PyObject* emb_set_x(PyObject *self, PyObject *args, PyObject *keywds)
{
int i = -1,life,j,x=-1,y=-1;
char *name = "";
@@ -1575,8 +1567,7 @@ emb_set_x(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_set_y(PyObject *self, PyObject *args, PyObject *keywds)
+static PyObject* emb_set_y(PyObject *self, PyObject *args, PyObject *keywds)
{
int i = -1,life,j,x=-1,y=-1;
char *name = "";
@@ -1616,8 +1607,7 @@ emb_set_y(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_set_ctype(PyObject *self, PyObject *args, PyObject *keywds)
+static PyObject* emb_set_ctype(PyObject *self, PyObject *args, PyObject *keywds)
{
int i = -1,life,j,x=-1,y=-1;
char *name = "";
@@ -1660,8 +1650,7 @@ emb_set_ctype(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_set_vx(PyObject *self, PyObject *args, PyObject *keywds)
+static PyObject* emb_set_vx(PyObject *self, PyObject *args, PyObject *keywds)
{
int i = -1,life,j,x=-1,y=-1;
char *name = "";
@@ -1701,8 +1690,7 @@ emb_set_vx(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_set_vy(PyObject *self, PyObject *args, PyObject *keywds)
+static PyObject* emb_set_vy(PyObject *self, PyObject *args, PyObject *keywds)
{
int i = -1,life,j,x=-1,y=-1;
char *name = "";
@@ -1742,8 +1730,7 @@ emb_set_vy(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_get_pmap(PyObject *self, PyObject *args)
+static PyObject* emb_get_pmap(PyObject *self, PyObject *args)
{
int x,y;
if(!PyArg_ParseTuple(args, "II:get_pmap",&x,&y))
@@ -1755,8 +1742,7 @@ emb_get_pmap(PyObject *self, PyObject *args)
return Py_BuildValue("I",pmap[y][x]);
}
-static PyObject*
-emb_get_prop(PyObject *self, PyObject *args)
+static PyObject* emb_get_prop(PyObject *self, PyObject *args)
{
int i;
char *prop = "";
@@ -1788,8 +1774,7 @@ emb_get_prop(PyObject *self, PyObject *args)
return Py_BuildValue("i",-1);
}
-static PyObject*
-emb_draw_pixel(PyObject *self, PyObject *args)
+static PyObject* emb_draw_pixel(PyObject *self, PyObject *args)
{
int x,y,r,g,b,a;
a=255;
@@ -1805,9 +1790,7 @@ emb_draw_pixel(PyObject *self, PyObject *args)
}
-//drawtext(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a)
-static PyObject*
-emb_draw_text(PyObject *self, PyObject *args)
+static PyObject* emb_draw_text(PyObject *self, PyObject *args)
{
int x,y,r,g,b,a;
char *txt;
@@ -1822,9 +1805,7 @@ emb_draw_text(PyObject *self, PyObject *args)
return Py_BuildValue("i",-1);
}
-//drawrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a)
-static PyObject*
-emb_draw_rect(PyObject *self, PyObject *args)
+static PyObject* emb_draw_rect(PyObject *self, PyObject *args)
{
int x,y,w,h,r,g,b,a;
a=255;
@@ -1839,8 +1820,7 @@ emb_draw_rect(PyObject *self, PyObject *args)
return Py_BuildValue("i",-1);
}
-static PyObject*
-emb_draw_fillrect(PyObject *self, PyObject *args)
+static PyObject* emb_draw_fillrect(PyObject *self, PyObject *args)
{
int x,y,w,h,r,g,b,a;
a=255;
@@ -1855,9 +1835,7 @@ emb_draw_fillrect(PyObject *self, PyObject *args)
return Py_BuildValue("i",-1);
}
-//int textwidth(char *s)
-static PyObject*
-emb_get_width(PyObject *self, PyObject *args)
+static PyObject* emb_get_width(PyObject *self, PyObject *args)
{
char *txt;
if(!PyArg_ParseTuple(args, "s:get_width",&txt))
@@ -1865,9 +1843,7 @@ emb_get_width(PyObject *self, PyObject *args)
return Py_BuildValue("i",textwidth(txt));
}
-//SDL_GetMouseState(&x, &y)
-static PyObject*
-emb_get_mouse(PyObject *self, PyObject *args)
+static PyObject* emb_get_mouse(PyObject *self, PyObject *args)
{
int x,y,mask,b1,b2,b3;
if(!PyArg_ParseTuple(args, ":get_mouse"))
@@ -1879,9 +1855,7 @@ emb_get_mouse(PyObject *self, PyObject *args)
return Py_BuildValue("(ii(iii))",x,y,b1,b2,b3);
}
-//svf_name
-static PyObject*
-emb_get_name(PyObject *self, PyObject *args)
+static PyObject* emb_get_name(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":get_name"))
return NULL;
@@ -1891,8 +1865,7 @@ emb_get_name(PyObject *self, PyObject *args)
return Py_BuildValue("s","");
}
-static PyObject*
-emb_shortcuts_disable(PyObject *self, PyObject *args)
+static PyObject* emb_shortcuts_disable(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":shortcuts_disable"))
return NULL;
@@ -1901,8 +1874,7 @@ emb_shortcuts_disable(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_shortcuts_enable(PyObject *self, PyObject *args)
+static PyObject* emb_shortcuts_enable(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":shortcuts_enable"))
return NULL;
@@ -1911,17 +1883,14 @@ emb_shortcuts_enable(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_get_modifier(PyObject *self, PyObject *args)
+static PyObject* emb_get_modifier(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":get_modifier"))
return NULL;
return Py_BuildValue("(iiiiii)",sdl_mod&KMOD_LCTRL,sdl_mod&KMOD_RCTRL,sdl_mod&KMOD_LALT,sdl_mod&KMOD_RALT,sdl_mod&KMOD_LSHIFT,sdl_mod&KMOD_RSHIFT);
}
-//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
-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;
@@ -1933,8 +1902,7 @@ emb_set_keyrepeat(PyObject *self, PyObject *args)
}
//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;
@@ -1944,8 +1912,7 @@ emb_delete(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-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;
@@ -1955,8 +1922,7 @@ emb_set_pressure(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-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;
@@ -1967,8 +1933,7 @@ emb_set_velocity(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-static PyObject*
-emb_disable_python(PyObject *self, PyObject *args)
+static PyObject* emb_disable_python(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":disable_python"))
return NULL;
@@ -2087,7 +2052,7 @@ int main(int argc, char *argv[])
int is_beta = 0;
#endif
char uitext[512] = "";
- char heattext[128] = "";
+ char heattext[256] = "";
char coordtext[128] = "";
int currentTime = 0;
int FPS = 0;
@@ -2102,8 +2067,9 @@ int main(int argc, char *argv[])
#ifdef INTERNAL
int vs = 0;
#endif
- int x, y, b = 0, su=0, c, lb = 0, lx = 0, ly = 0, lm = 0;//, tx, ty;
- int da = 0, db = 0, it = 2047, mx, my;
+ int wavelength_gfx = 0;
+ int x, y, b = 0, sl=1, sr=0, su=0, c, lb = 0, lx = 0, ly = 0, lm = 0;//, tx, ty;
+ int da = 0, db = 0, it = 2047, mx, my, bsx = 2, bsy = 2;
float nfvx, nfvy;
int load_mode=0, load_w=0, load_h=0, load_x=0, load_y=0, load_size=0;
void *load_data=NULL;
@@ -2111,6 +2077,7 @@ int main(int argc, char *argv[])
int save_mode=0, save_x=0, save_y=0, save_w=0, save_h=0, copy_mode=0;
SDL_AudioSpec fmt;
int username_flash = 0, username_flash_t = 1;
+ pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
GSPEED = 1;
#ifdef PYCONSOLE
PyObject *pname,*pmodule,*pfunc,*pvalue,*pargs,*pstep,*pkey;
@@ -2124,33 +2091,25 @@ int main(int argc, char *argv[])
fmt.callback = mixaudio;
fmt.userdata = NULL;
- #ifdef PYCONSOLE
- //dump tpt_console_stdlib to file here
- /*#include "pystdlib.h"
- FILE* fid;
- fid=fopen("stdlib.zip","w");
- //fputs(tpt_console_stdlib,fid);
- fwrite(&tpt_console_stdlib,1,tpt_console_stdlibsize,fid);
- fclose(fid);*/
- //crashes gcc
-
+#ifdef PYCONSOLE
//initialise python console
Py_Initialize();
PyRun_SimpleString("print 'python present.'");
Py_InitModule("tpt", EmbMethods);
+
//change the path to find all the correct modules
PyRun_SimpleString("import sys\nsys.path.append('./tptPython.zip')\nsys.path.append('.')");
//load the console module and whatnot
- #ifdef PYEXT
+#ifdef PYEXT
PyRun_SimpleString(tpt_console_py);
printf("using external python console file.\n");
pname=PyString_FromString("tpt_console");//create string object
pmodule = PyImport_Import(pname);//import module
Py_DECREF(pname);//throw away string
- #else
+#else
PyObject *tpt_console_obj = PyMarshal_ReadObjectFromString(tpt_console_pyc+8, sizeof(tpt_console_pyc)-8);
pmodule=PyImport_ExecCodeModule("tpt_console", tpt_console_obj);
- #endif
+#endif
if(pmodule!=NULL)
{
pfunc=PyObject_GetAttrString(pmodule,"handle");//get the handler function
@@ -2162,9 +2121,8 @@ int main(int argc, char *argv[])
{
PyErr_Print();
printf("unable to find handle function, mangled console.py?\n");
- //return -1;
- pyready=0;
- pygood=0;
+ pyready = 0;
+ pygood = 0;
}
pstep=PyObject_GetAttrString(pmodule,"step");//get the handler function
@@ -2192,9 +2150,8 @@ int main(int argc, char *argv[])
//sys.stderr
PyErr_Print();
printf("unable to find console module, missing file or mangled console.py?\n");
- //return -1;
- pyready=0;
- pygood=0;
+ pyready = 0;
+ pygood = 0;
}
#else
printf("python console disabled at compile time.");
@@ -2224,8 +2181,7 @@ int main(int argc, char *argv[])
parts[NPART-1].life = -1;
pfree = 0;
fire_bg=calloc(XRES*YRES, PIXELSIZE);
- pers_bg=calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
- memset(signs, 0, sizeof(signs));
+ clear_sim();
//fbi_img = render_packed_rgb(fbi, FBI_W, FBI_H, FBI_CMP);
@@ -2269,6 +2225,19 @@ int main(int argc, char *argv[])
{
file_script = 1;
}
+ else if (!strncmp(argv[i], "open:", 5))
+ {
+ int size;
+ void *file_data;
+ char fn[64];
+ strncpy(fn, argv[i]+5, strlen(argv[i]+5));
+ file_data = file_load(fn, &size);
+ if(file_data)
+ {
+ it=0;
+ parse_save(file_data, size, 0, 0, 0, bmap, fvx, fvy, signs, parts, pmap);
+ }
+ }
}
@@ -2833,8 +2802,6 @@ int main(int argc, char *argv[])
pargs=NULL;
if(pvalue==NULL)
strcpy(console_error,"failed to execute key code.");
- //Py_DECREF(pvalue);
- //puts("a");
pvalue=NULL;
}
#endif
@@ -2950,8 +2917,13 @@ int main(int argc, char *argv[])
if (DEBUG_MODE)
{
int tctype = parts[cr>>8].ctype;
- if (tctype>=PT_NUM)
+ if (tctype>=PT_NUM || tctype<0 || (cr&0xFF)==PT_PHOT)
tctype = 0;
+ if ((cr&0xFF)==PT_PIPE)
+ {
+ if (parts[cr>>8].tmp<PT_NUM) tctype = parts[cr>>8].tmp;
+ else tctype = 0;
+ }
sprintf(heattext, "%s (%s), Pressure: %3.2f, Temp: %4.2f C, Life: %d", ptypes[cr&0xFF].name, ptypes[tctype].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life);
sprintf(coordtext, "#%d, X:%d Y:%d", cr>>8, x/sdl_scale, y/sdl_scale);
} else {
@@ -2961,6 +2933,7 @@ int main(int argc, char *argv[])
sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C", ptypes[cr&0xFF].name, pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL], parts[cr>>8].temp-273.15f);
#endif
}
+ if ((cr&0xFF)==PT_PHOT) wavelength_gfx = parts[cr>>8].ctype;
}
else
{
@@ -3134,7 +3107,7 @@ int main(int argc, char *argv[])
if (load_y<0) load_y=0;
if (bq==1 && !b)
{
- parse_save(load_data, load_size, 0, load_x, load_y);
+ parse_save(load_data, load_size, 0, load_x, load_y, bmap, fvx, fvy, signs, parts, pmap);
free(load_data);
free(load_img);
load_mode = 0;
@@ -3176,35 +3149,19 @@ int main(int argc, char *argv[])
{
if (copy_mode==1)
{
- clipboard_data=build_save(&clipboard_length, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL);
+ 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)
{
- clipboard_data=build_save(&clipboard_length, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL);
+ 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;
clear_area(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL);
}
- else if (copy_mode==3)//rotation
- {
- if (save_h>save_w)
- save_w = save_h;
- rotate_area(save_x*CELL, save_y*CELL, save_w*CELL, save_w*CELL,0);//just do squares for now
- save_mode = 0;
- copy_mode = 0;
- }
- else if (copy_mode==4)//invertion
- {
- if (save_h>save_w)
- save_w = save_h;
- rotate_area(save_x*CELL, save_y*CELL, save_w*CELL, save_w*CELL,1);//just do squares for now
- save_mode = 0;
- copy_mode = 0;
- }
else
{
stamp_save(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL);
@@ -3262,19 +3219,7 @@ int main(int argc, char *argv[])
}
if (x>=(XRES+BARSIZE-(510-367)) && x<=(XRES+BARSIZE-(510-383)) && !bq)
{
- memset(signs, 0, sizeof(signs));
- memset(pv, 0, sizeof(pv));
- memset(vx, 0, sizeof(vx));
- memset(vy, 0, sizeof(vy));
- memset(fvx, 0, sizeof(fvx));
- memset(fvy, 0, sizeof(fvy));
- memset(bmap, 0, sizeof(bmap));
- memset(emap, 0, sizeof(emap));
- memset(parts, 0, sizeof(particle)*NPART);
- memset(photons, 0, sizeof(photons));
- memset(wireless, 0, sizeof(wireless));
- memset(gol2, 0, sizeof(gol2));
- memset(portal, 0, sizeof(portal));
+ clear_sim();
for (i=0; i<NPART-1; i++)
parts[i].life = i+1;
parts[NPART-1].life = -1;
@@ -3291,6 +3236,7 @@ int main(int argc, char *argv[])
svf_description[0] = 0;
gravityMode = 0;
airMode = 0;
+
death = death2 = 0;
isplayer2 = 0;
isplayer = 0;
@@ -3315,8 +3261,14 @@ int main(int argc, char *argv[])
{
if (!svf_open || !svf_own || x>51)
{
- if (save_name_ui(vid_buf))
+ if (save_name_ui(vid_buf)){
execute_save(vid_buf);
+ if(svf_id[0]){
+ char tmpstring[256] = "";
+ sprintf(tmpstring, "Save uploaded with the ID %s", svf_id);
+ info_ui(vid_buf, "Uploaded new save", tmpstring);
+ }
+ }
}
else
execute_save(vid_buf);
@@ -3336,7 +3288,7 @@ int main(int argc, char *argv[])
}
if (x>=19 && x<=35 && svf_last && svf_open && !bq) {
//int tpval = sys_pause;
- parse_save(svf_last, svf_lsize, 1, 0, 0);
+ parse_save(svf_last, svf_lsize, 1, 0, 0, bmap, fvx, fvy, signs, parts, pmap);
//sys_pause = tpval;
}
if (x>=(XRES+BARSIZE-(510-476)) && x<=(XRES+BARSIZE-(510-491)) && !bq)
@@ -3426,14 +3378,16 @@ int main(int argc, char *argv[])
{
for (j=-bsy; j<=bsy; j++)
for (i=-bsx; i<=bsx; i++)
- if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(bsx,2))+(pow(j,2))/(pow(bsy,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=bsy*bsx))
+ if (x+i>0 && y+j>0 && x+i<XRES && y+j<YRES && ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(bsx,2))+(pow(j,2))/(pow(bsy,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=bsy*bsx)))
{
vx[(y+j)/CELL][(x+i)/CELL] += (x-lx)*0.01f;
vy[(y+j)/CELL][(x+i)/CELL] += (y-ly)*0.01f;
}
}
else
+ {
create_line(lx, ly, x, y, bsx, bsy, c);
+ }
lx = x;
ly = y;
}
@@ -3545,14 +3499,7 @@ int main(int argc, char *argv[])
if (save_mode)
{
- if (copy_mode==3||copy_mode==4)//special drawing for rotate, can remove once it can do rectangles
- {
- if (save_h>save_w)
- save_w = save_h;
- xor_rect(vid_buf, save_x*CELL, save_y*CELL, save_w*CELL, save_w*CELL);
- }
- else
- 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;
db = 269;
}
@@ -3707,6 +3654,8 @@ int main(int argc, char *argv[])
fillrect(vid_buf, XRES-20-textwidth(coordtext), 280, textwidth(coordtext)+8, 13, 0, 0, 0, 140);
drawtext(vid_buf, XRES-16-textwidth(coordtext), 282, coordtext, 255, 255, 255, 200);
}
+ if (wavelength_gfx)
+ draw_wavelengths(vid_buf,XRES-20-textwidth(heattext),265,2,wavelength_gfx);
}
else
{
@@ -3717,6 +3666,8 @@ int main(int argc, char *argv[])
fillrect(vid_buf, 12, 280, textwidth(coordtext)+8, 13, 0, 0, 0, 140);
drawtext(vid_buf, 16, 282, coordtext, 255, 255, 255, 200);
}
+ if (wavelength_gfx)
+ draw_wavelengths(vid_buf,12,265,2,wavelength_gfx);
}
}
else
@@ -3728,7 +3679,10 @@ int main(int argc, char *argv[])
fillrect(vid_buf, XRES-20-textwidth(coordtext), 26, textwidth(coordtext)+8, 11, 0, 0, 0, 140);
drawtext(vid_buf, XRES-16-textwidth(coordtext), 27, coordtext, 255, 255, 255, 200);
}
+ if (wavelength_gfx)
+ draw_wavelengths(vid_buf,XRES-20-textwidth(heattext),11,2,wavelength_gfx);
}
+ wavelength_gfx = 0;
fillrect(vid_buf, 12, 12, textwidth(uitext)+8, 15, 0, 0, 0, 140);
drawtext(vid_buf, 16, 16, uitext, 32, 216, 255, 200);
@@ -3823,6 +3777,7 @@ int main(int argc, char *argv[])
}
SDL_CloseAudio();
http_done();
+
PyRun_SimpleString("import os,tempfile,os.path\ntry:\n os.remove(os.path.join(tempfile.gettempdir(),'tpt_console.py'))\nexcept:\n pass");
PyRun_SimpleString("import os,tempfile,os.path\ntry:\n os.remove(os.path.join(tempfile.gettempdir(),'tpt_console.pyo'))\nexcept:\n pass");
PyRun_SimpleString("import os,tempfile,os.path\ntry:\n os.remove(os.path.join(tempfile.gettempdir(),'tpt_console.pyc'))\nexcept:\n pass");
@@ -3848,26 +3803,20 @@ int process_command(pixel *vid_buf,char *console,char *console_error,PyObject *p
if(strcmp(console2, "quit")==0)
{
return -1;
- }
- else
- {
- // sprintf(console_error, "Invalid Command", console2);
- //handle them command
- pargs=Py_BuildValue("(s)",console);
- pvalue = PyObject_CallObject(pfunc, pargs);
- Py_DECREF(pargs);
- pargs=NULL;
- if(pvalue==NULL)
- strcpy(console_error,"failed to execute code.");
- //Py_DECREF(pvalue);
- //puts("a");
- pvalue=NULL;
+ } else {
+ //handle them command
+ pargs=Py_BuildValue("(s)",console);
+ pvalue = PyObject_CallObject(pfunc, pargs);
+ Py_DECREF(pargs);
+ pargs=NULL;
+ if(pvalue==NULL)
+ strcpy(console_error,"failed to execute code.");
+ pvalue=NULL;
}
}
return 1;
}
#endif
-
int process_command_old(pixel *vid_buf,char *console,char *console_error) {
int y,x,nx,ny,i,j,k,m;
int do_next = 1;