summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c311
1 files changed, 120 insertions, 191 deletions
diff --git a/src/main.c b/src/main.c
index 2b41426..8765642 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,7 +29,6 @@
#ifdef PYCONSOLE
#include "Python.h"
#include "pyconsole.h"
-//#include "pystdlib.h"
char pyready=1;
char pygood=1;
#endif
@@ -223,7 +222,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
@@ -309,11 +308,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;
@@ -352,7 +352,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;
}
}
@@ -478,12 +479,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
@@ -563,19 +565,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
@@ -907,13 +897,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];
@@ -998,7 +1010,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");
@@ -1202,8 +1214,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 = "";
@@ -1215,9 +1226,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"))
@@ -1227,8 +1237,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"))
@@ -1238,8 +1247,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"))
@@ -1250,9 +1258,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"))
@@ -1262,8 +1268,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"))
@@ -1273,8 +1278,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"))
@@ -1284,8 +1288,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))
@@ -1298,8 +1301,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;
@@ -1308,8 +1310,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;
@@ -1318,10 +1319,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;
@@ -1334,8 +1332,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;
@@ -1349,8 +1346,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;
@@ -1366,8 +1362,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 = "";
@@ -1407,8 +1402,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 = "";
@@ -1450,8 +1444,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 = "";
@@ -1491,8 +1484,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 = "";
@@ -1532,8 +1524,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 = "";
@@ -1574,8 +1565,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 = "";
@@ -1615,8 +1605,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 = "";
@@ -1659,8 +1648,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 = "";
@@ -1700,8 +1688,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 = "";
@@ -1741,8 +1728,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))
@@ -1754,8 +1740,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 = "";
@@ -1787,8 +1772,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;
@@ -1804,9 +1788,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;
@@ -1821,9 +1803,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;
@@ -1838,8 +1818,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;
@@ -1854,9 +1833,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))
@@ -1864,9 +1841,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"))
@@ -1878,9 +1853,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;
@@ -1890,8 +1863,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;
@@ -1900,8 +1872,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;
@@ -1910,17 +1881,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;
@@ -1932,8 +1900,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;
@@ -1943,8 +1910,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;
@@ -1954,8 +1920,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;
@@ -1966,8 +1931,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;
@@ -2042,6 +2006,7 @@ int main(int argc, char *argv[])
#ifdef INTERNAL
int vs = 0;
#endif
+ 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;
@@ -2051,6 +2016,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;
@@ -2064,33 +2030,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
@@ -2102,9 +2060,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
@@ -2132,9 +2089,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.");
@@ -2164,8 +2120,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);
@@ -2773,8 +2728,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
@@ -2890,8 +2843,13 @@ int main(int argc, char *argv[])
if (DEBUG_MODE)
{
int tctype = parts[cr>>8].ctype;
- if (tctype>=PT_NUM)
+ if (tctype>=PT_NUM || (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 {
@@ -2901,6 +2859,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
{
@@ -3074,7 +3033,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;
@@ -3116,35 +3075,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);
@@ -3202,19 +3145,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;
@@ -3231,6 +3162,7 @@ int main(int argc, char *argv[])
svf_description[0] = 0;
gravityMode = 0;
airMode = 0;
+
death = death2 = 0;
isplayer2 = 0;
isplayer = 0;
@@ -3276,7 +3208,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)
@@ -3366,14 +3298,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;
}
@@ -3485,14 +3419,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;
}
@@ -3647,6 +3574,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
{
@@ -3657,6 +3586,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
@@ -3668,7 +3599,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);
@@ -3763,6 +3697,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");
@@ -3788,26 +3723,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;