summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c1638
1 files changed, 715 insertions, 923 deletions
diff --git a/src/main.c b/src/main.c
index fe8496d..8765642 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,6 +29,8 @@
#ifdef PYCONSOLE
#include "Python.h"
#include "pyconsole.h"
+char pyready=1;
+char pygood=1;
#endif
#include <stdio.h>
@@ -1212,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 = "";
@@ -1225,8 +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
-emb_pause(PyObject *self, PyObject *args)
+
+static PyObject* emb_pause(PyObject *self, PyObject *args)
{
int x,y,t;
if(!PyArg_ParseTuple(args, ":unpause"))
@@ -1236,7 +1237,7 @@ emb_pause(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-emb_unpause(PyObject *self, PyObject *args)
+static PyObject* emb_unpause(PyObject *self, PyObject *args)
{
int x,y,t;
if(!PyArg_ParseTuple(args, ":pause"))
@@ -1246,7 +1247,7 @@ emb_unpause(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-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"))
@@ -1257,8 +1258,7 @@ emb_toggle_pause(PyObject *self, PyObject *args)
}
//console_mode
-
-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"))
@@ -1268,7 +1268,7 @@ emb_toggle_console(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-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"))
@@ -1278,7 +1278,7 @@ emb_open_console(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-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"))
@@ -1288,8 +1288,7 @@ emb_close_console(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-
-emb_log(PyObject *self, PyObject *args)
+static PyObject* emb_log(PyObject *self, PyObject *args)
{
char *buffer;
if(!PyArg_ParseTuple(args, "s:log",&buffer))
@@ -1302,7 +1301,7 @@ emb_log(PyObject *self, PyObject *args)
char console_more=0;
-emb_console_more(PyObject *self, PyObject *args)
+static PyObject* emb_console_more(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":log"))
return NULL;
@@ -1311,7 +1310,7 @@ emb_console_more(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-emb_console_less(PyObject *self, PyObject *args)
+static PyObject* emb_console_less(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":log"))
return NULL;
@@ -1320,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);
-
-
-emb_reset_pressure(PyObject *self, PyObject *args)
+static PyObject* emb_reset_pressure(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":reset_pressure"))
return NULL;
@@ -1336,7 +1332,7 @@ emb_reset_pressure(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-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,7 +1346,7 @@ emb_reset_velocity(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-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,11 +1362,11 @@ emb_reset_sparks(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-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 = "";
- char *kwlist[] = {"setto", "setfrom", "i", "x", "y", NULL};
+ char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y))
return NULL;
//
@@ -1406,12 +1402,12 @@ emb_set_life(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-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 = "";
char *type = "";
- char *kwlist[] = {"setto", "settoint", "setfrom", "i", "x", "y", NULL};
+ char *kwlist[] = {"setto", "settoint", "from", "i", "x", "y", NULL};
if(!PyArg_ParseTupleAndKeywords(args, keywds, "|sIsIII:set_type",kwlist ,&type,&life,&name,&i,&x,&y))
return NULL;
//
@@ -1448,11 +1444,11 @@ emb_set_type(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-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 = "";
- char *kwlist[] = {"setto", "setfrom", "i", "x", "y", NULL};
+ char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y))
return NULL;
//
@@ -1488,11 +1484,11 @@ emb_set_temp(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-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 = "";
- char *kwlist[] = {"setto", "setfrom", "i", "x", "y", NULL};
+ char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y))
return NULL;
//
@@ -1528,12 +1524,12 @@ emb_set_tmp(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-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 = "";
char *type = "";
- char *kwlist[] = {"setto", "setfrom", "i", "x", "y", NULL};
+ char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y))
return NULL;
//
@@ -1569,11 +1565,11 @@ emb_set_x(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-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 = "";
- char *kwlist[] = {"setto", "setfrom", "i", "x", "y", NULL};
+ char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y))
return NULL;
//
@@ -1609,12 +1605,12 @@ emb_set_y(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-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 = "";
char *type = "";
- char *kwlist[] = {"setto", "toctypeint", "setfrom", "i", "x", "y", NULL};
+ char *kwlist[] = {"setto", "settoint", "from", "i", "x", "y", NULL};
if(!PyArg_ParseTupleAndKeywords(args, keywds, "s|IsIII:set_type",kwlist ,&type, &life, &name,&i,&x,&y))
return NULL;
//
@@ -1652,11 +1648,11 @@ emb_set_ctype(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-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 = "";
- char *kwlist[] = {"setto", "setfrom", "i", "x", "y", NULL};
+ char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y))
return NULL;
//
@@ -1692,11 +1688,11 @@ emb_set_vx(PyObject *self, PyObject *args, PyObject *keywds)
return Py_BuildValue("i",1);
}
-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 = "";
- char *kwlist[] = {"setto", "setfrom", "i", "x", "y", NULL};
+ char *kwlist[] = {"setto", "from", "i", "x", "y", NULL};
if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y))
return NULL;
//
@@ -1731,7 +1727,8 @@ emb_set_vy(PyObject *self, PyObject *args, PyObject *keywds)
}
return Py_BuildValue("i",1);
}
-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))
@@ -1742,7 +1739,8 @@ emb_get_pmap(PyObject *self, PyObject *args)
return Py_BuildValue("I",pmap[y][x]);
}
-emb_get_prop(PyObject *self, PyObject *args)
+
+static PyObject* emb_get_prop(PyObject *self, PyObject *args)
{
int i;
char *prop = "";
@@ -1774,7 +1772,7 @@ emb_get_prop(PyObject *self, PyObject *args)
return Py_BuildValue("i",-1);
}
-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;
@@ -1790,8 +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)
-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;
@@ -1806,8 +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)
-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;
@@ -1822,7 +1818,7 @@ emb_draw_rect(PyObject *self, PyObject *args)
return Py_BuildValue("i",-1);
}
-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;
@@ -1836,8 +1832,8 @@ emb_draw_fillrect(PyObject *self, PyObject *args)
}
return Py_BuildValue("i",-1);
}
-//int textwidth(char *s)
-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))
@@ -1845,8 +1841,7 @@ emb_get_width(PyObject *self, PyObject *args)
return Py_BuildValue("i",textwidth(txt));
}
-//SDL_GetMouseState(&x, &y)
-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"))
@@ -1858,8 +1853,7 @@ emb_get_mouse(PyObject *self, PyObject *args)
return Py_BuildValue("(ii(iii))",x,y,b1,b2,b3);
}
-//svf_name
-emb_get_name(PyObject *self, PyObject *args)
+static PyObject* emb_get_name(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":get_name"))
return NULL;
@@ -1869,7 +1863,7 @@ emb_get_name(PyObject *self, PyObject *args)
return Py_BuildValue("s","");
}
-emb_shortcuts_disable(PyObject *self, PyObject *args)
+static PyObject* emb_shortcuts_disable(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":shortcuts_disable"))
return NULL;
@@ -1878,7 +1872,7 @@ emb_shortcuts_disable(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-emb_shortcuts_enable(PyObject *self, PyObject *args)
+static PyObject* emb_shortcuts_enable(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":shortcuts_enable"))
return NULL;
@@ -1887,48 +1881,104 @@ emb_shortcuts_enable(PyObject *self, PyObject *args)
return Py_BuildValue("i",1);
}
-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);
}
+static PyObject* emb_set_keyrepeat(PyObject *self, PyObject *args)
+{
+ ////SDL_EnableKeyRepeat(delay,interval)
+ int keydelay,keyinterval;
+ keydelay=SDL_DEFAULT_REPEAT_DELAY;
+ keyinterval=SDL_DEFAULT_REPEAT_INTERVAL;
+ if(!PyArg_ParseTuple(args, "|ii:set_keyrepeat",&keydelay,&keyinterval))
+ return NULL;
+ return Py_BuildValue("i",SDL_EnableKeyRepeat(keydelay,keyinterval));
+}
+
+//delete_part
+static PyObject* emb_delete(PyObject *self, PyObject *args)
+{
+ ////SDL_EnableKeyRepeat(delay,interval)
+ int x,y;
+ if(!PyArg_ParseTuple(args, "ii:delete",&x,&y))
+ return NULL;
+ delete_part(x,y);
+ return Py_BuildValue("i",1);
+}
+
+static PyObject* emb_set_pressure(PyObject *self, PyObject *args)
+{
+ ////SDL_EnableKeyRepeat(delay,interval)
+ int x,y,press;
+ if(!PyArg_ParseTuple(args, "iii:set_pressure",&x,&y,&press))
+ return NULL;
+ pv[y/CELL][x/CELL]=press;
+ return Py_BuildValue("i",1);
+}
+
+static PyObject* emb_set_velocity(PyObject *self, PyObject *args)
+{
+ ////SDL_EnableKeyRepeat(delay,interval)
+ int x,y,xv,yv;
+ if(!PyArg_ParseTuple(args, "iiii:set_velocity",&x,&y,&xv,&yv))
+ return NULL;
+ vx[y/CELL][x/CELL]=xv;
+ vy[y/CELL][x/CELL]=yv;
+ return Py_BuildValue("i",1);
+}
+
+static PyObject* emb_disable_python(PyObject *self, PyObject *args)
+{
+ if(!PyArg_ParseTuple(args, ":disable_python"))
+ return NULL;
+ pyready=0;
+ return Py_BuildValue("i",1);
+}
+
static PyMethodDef EmbMethods[] = { //WARNING! don't forget to register your function here!
- {"create", emb_create, METH_VARARGS|METH_KEYWORDS, "create a particle."},
- {"log", emb_log, METH_VARARGS, "logs an error string to the console."},
- {"reset_pressure", emb_reset_pressure, METH_VARARGS, "resets all the pressure."},
- {"reset_velocity", emb_reset_velocity, METH_VARARGS, "resets all the velocity."},
- {"reset_sparks", emb_reset_sparks, METH_VARARGS, "resets all the sparks."},
- {"set_life", emb_set_life, METH_VARARGS|METH_KEYWORDS, "sets life of a specified particle."},
- {"set_type", emb_set_type, METH_VARARGS|METH_KEYWORDS, "sets type of a specified particle."},
- {"set_temp", emb_set_temp, METH_VARARGS|METH_KEYWORDS, "sets temp of a specified particle."},
- {"set_tmp", emb_set_tmp, METH_VARARGS|METH_KEYWORDS, "sets tmp of a specified particle."},
- {"set_x", emb_set_x, METH_VARARGS|METH_KEYWORDS, "sets x of a specified particle."},
- {"set_y", emb_set_y, METH_VARARGS|METH_KEYWORDS, "sets y of a specified particle."},
- {"set_ctype", emb_set_y, METH_VARARGS|METH_KEYWORDS, "sets ctype of a specified particle."},
- {"set_vx", emb_set_vx, METH_VARARGS|METH_KEYWORDS, "sets vx of a specified particle."},
- {"set_vy", emb_set_vy, METH_VARARGS|METH_KEYWORDS, "sets vy of a specified particle."},
- {"pause", emb_pause, METH_VARARGS, "pause the game."},
- {"unpause", emb_unpause, METH_VARARGS, "unpause the game."},
- {"pause_toggle", emb_toggle_pause, METH_VARARGS, "toggle game pause."},
- {"console_open", emb_open_console, METH_VARARGS, "open the game console."},
- {"console_close", emb_close_console, METH_VARARGS, "close the game console."},
- {"console_toggle", emb_toggle_console, METH_VARARGS, "toggle the game console."},
- {"console_more", emb_console_more, METH_VARARGS, "turns the more indicator on."},
- {"console_less", emb_console_less, METH_VARARGS, "turns the more indicator off."},
- {"get_pmap", emb_get_pmap, METH_VARARGS, "get the pmap value."},
- {"get_prop", emb_get_prop, METH_VARARGS, "get some properties."},
- {"draw_pixel", emb_draw_pixel, METH_VARARGS, "draw a pixel."},
- {"draw_text", emb_draw_text, METH_VARARGS, "draw some text."},
- {"draw_rect", emb_draw_rect, METH_VARARGS, "draw a rect."},
- {"draw_fillrect", emb_draw_fillrect, METH_VARARGS, "draw a rect."},
- {"get_width", emb_get_width, METH_VARARGS, "get string width."},
- {"get_mouse", emb_get_mouse, METH_VARARGS, "get mouse status."},
- {"get_name", emb_get_name, METH_VARARGS, "get name of logged in user"},
- {"shortcuts_disable", emb_shortcuts_disable, METH_VARARGS, "disable keyboard shortcuts"},
- {"shortcuts_enable", emb_shortcuts_enable, METH_VARARGS, "enable keyboard shortcuts"},
- {"get_modifier", emb_get_modifier, METH_VARARGS, "get pressed modifier keys"},
+ {"create", (PyCFunction)emb_create, METH_VARARGS|METH_KEYWORDS, "create a particle."},
+ {"log", (PyCFunction)emb_log, METH_VARARGS, "logs an error string to the console."},
+ {"reset_pressure", (PyCFunction)emb_reset_pressure, METH_VARARGS, "resets all the pressure."},
+ {"reset_velocity", (PyCFunction)emb_reset_velocity, METH_VARARGS, "resets all the velocity."},
+ {"reset_sparks", (PyCFunction)emb_reset_sparks, METH_VARARGS, "resets all the sparks."},
+ {"set_life", (PyCFunction)emb_set_life, METH_VARARGS|METH_KEYWORDS, "sets life of a specified particle."},
+ {"set_type", (PyCFunction)emb_set_type, METH_VARARGS|METH_KEYWORDS, "sets type of a specified particle."},
+ {"set_temp", (PyCFunction)emb_set_temp, METH_VARARGS|METH_KEYWORDS, "sets temp of a specified particle."},
+ {"set_tmp", (PyCFunction)emb_set_tmp, METH_VARARGS|METH_KEYWORDS, "sets tmp of a specified particle."},
+ {"set_x", (PyCFunction)emb_set_x, METH_VARARGS|METH_KEYWORDS, "sets x of a specified particle."},
+ {"set_y", (PyCFunction)emb_set_y, METH_VARARGS|METH_KEYWORDS, "sets y of a specified particle."},
+ {"set_ctype", (PyCFunction)emb_set_ctype, METH_VARARGS|METH_KEYWORDS, "sets ctype of a specified particle."},
+ {"set_vx", (PyCFunction)emb_set_vx, METH_VARARGS|METH_KEYWORDS, "sets vx of a specified particle."},
+ {"set_vy", (PyCFunction)emb_set_vy, METH_VARARGS|METH_KEYWORDS, "sets vy of a specified particle."},
+ {"pause", (PyCFunction)emb_pause, METH_VARARGS, "pause the game."},
+ {"unpause", (PyCFunction)emb_unpause, METH_VARARGS, "unpause the game."},
+ {"pause_toggle", (PyCFunction)emb_toggle_pause, METH_VARARGS, "toggle game pause."},
+ {"console_open", (PyCFunction)emb_open_console, METH_VARARGS, "open the game console."},
+ {"console_close", (PyCFunction)emb_close_console, METH_VARARGS, "close the game console."},
+ {"console_toggle", (PyCFunction)emb_toggle_console, METH_VARARGS, "toggle the game console."},
+ {"console_more", (PyCFunction)emb_console_more, METH_VARARGS, "turns the more indicator on."},
+ {"console_less", (PyCFunction)emb_console_less, METH_VARARGS, "turns the more indicator off."},
+ {"get_pmap", (PyCFunction)emb_get_pmap, METH_VARARGS, "get the pmap value."},
+ {"get_prop", (PyCFunction)emb_get_prop, METH_VARARGS, "get some properties."},
+ {"draw_pixel", (PyCFunction)emb_draw_pixel, METH_VARARGS, "draw a pixel."},
+ {"draw_text", (PyCFunction)emb_draw_text, METH_VARARGS, "draw some text."},
+ {"draw_rect", (PyCFunction)emb_draw_rect, METH_VARARGS, "draw a rect."},
+ {"draw_fillrect", (PyCFunction)emb_draw_fillrect, METH_VARARGS, "draw a rect."},
+ {"get_width", (PyCFunction)emb_get_width, METH_VARARGS, "get string width."},
+ {"get_mouse", (PyCFunction)emb_get_mouse, METH_VARARGS, "get mouse status."},
+ {"get_name", (PyCFunction)emb_get_name, METH_VARARGS, "get name of logged in user"},
+ {"shortcuts_disable", (PyCFunction)emb_shortcuts_disable, METH_VARARGS, "disable keyboard shortcuts"},
+ {"shortcuts_enable", (PyCFunction)emb_shortcuts_enable, METH_VARARGS, "enable keyboard shortcuts"},
+ {"get_modifier", (PyCFunction)emb_get_modifier, METH_VARARGS, "get pressed modifier keys"},
+ {"set_keyrepeat", (PyCFunction)emb_set_keyrepeat, METH_VARARGS, "set key repeat rate."},
+ {"delete", (PyCFunction)emb_delete, METH_VARARGS, "delete a particle"},
+ {"set_pressure", (PyCFunction)emb_set_pressure, METH_VARARGS, "set pressure"},
+ {"set_velocity", (PyCFunction)emb_set_velocity, METH_VARARGS, "set velocity"},
+ {"disable_python", (PyCFunction)emb_disable_python, METH_VARARGS, "switch back to the old console."},
{NULL, NULL, 0, NULL}
};
#endif
@@ -1980,16 +2030,25 @@ int main(int argc, char *argv[])
fmt.callback = mixaudio;
fmt.userdata = NULL;
- #ifdef PYCONSOLE
+#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('.')");
- PyRun_SimpleString("print 'python present.'");
+ PyRun_SimpleString("import sys\nsys.path.append('./tptPython.zip')\nsys.path.append('.')");
//load the console module and whatnot
+#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
PyObject *tpt_console_obj = PyMarshal_ReadObjectFromString(tpt_console_pyc+8, sizeof(tpt_console_pyc)-8);
pmodule=PyImport_ExecCodeModule("tpt_console", tpt_console_obj);
+#endif
if(pmodule!=NULL)
{
pfunc=PyObject_GetAttrString(pmodule,"handle");//get the handler function
@@ -2001,7 +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;
}
pstep=PyObject_GetAttrString(pmodule,"step");//get the handler function
@@ -2029,7 +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;
}
#else
printf("python console disabled at compile time.");
@@ -2658,18 +2719,17 @@ int main(int argc, char *argv[])
}
}
#ifdef PYCONSOLE
- if(pkey!=NULL && sdl_key!=NULL)
- {
- pargs=Py_BuildValue("(c)",sdl_key);
- pvalue = PyObject_CallObject(pkey, pargs);
- Py_DECREF(pargs);
- pargs=NULL;
- if(pvalue==NULL)
- strcpy(console_error,"failed to execute key code.");
- //Py_DECREF(pvalue);
- //puts("a");
- pvalue=NULL;
- }
+ if(pyready==1 && pygood==1)
+ if(pkey!=NULL && sdl_key!=NULL)
+ {
+ pargs=Py_BuildValue("(c)",sdl_key);
+ pvalue = PyObject_CallObject(pkey, pargs);
+ Py_DECREF(pargs);
+ pargs=NULL;
+ if(pvalue==NULL)
+ strcpy(console_error,"failed to execute key code.");
+ pvalue=NULL;
+ }
#endif
#ifdef INTERNAL
int counterthing;
@@ -2690,365 +2750,6 @@ int main(int argc, char *argv[])
}
counterthing = 0;
}
- if ((sdl_key=='s' && (sdl_mod & (KMOD_CTRL))) || (sdl_key=='s' && !isplayer2))
- {
- if (it > 50)
- it = 50;
- save_mode = 1;
- }
- if (sdl_key=='1')
- {
- set_cmode(CM_VEL);
- }
- if (sdl_key=='2')
- {
- set_cmode(CM_PRESS);
- }
- if (sdl_key=='3')
- {
- set_cmode(CM_PERS);
- }
- if (sdl_key=='4')
- {
- set_cmode(CM_FIRE);
- }
- if (sdl_key=='5')
- {
- set_cmode(CM_BLOB);
- }
- if (sdl_key=='6')
- {
- set_cmode(CM_HEAT);
- }
- if (sdl_key=='7')
- {
- set_cmode(CM_FANCY);
- }
- if (sdl_key=='8')
- {
- set_cmode(CM_NOTHING);
- }
- if (sdl_key=='9')
- {
- set_cmode(CM_GRAD);
- }
- if (sdl_key=='0')
- {
- set_cmode(CM_CRACK);
- }
- if (sdl_key=='1'&& (sdl_mod & (KMOD_SHIFT)) && DEBUG_MODE)
- {
- if (counterthing+1>=vs)
- {
- dump_frame(vid_buf, XRES, YRES, XRES+BARSIZE);
- counterthing = 0;
- }
- counterthing = (counterthing+1)%3;
- }
-#endif
-
- if (sdl_wheel)
- {
- if (sdl_zoom_trig==1)
- {
- ZSIZE += sdl_wheel;
- if (ZSIZE>60)
- ZSIZE = 60;
- if (ZSIZE<2)
- ZSIZE = 2;
- ZFACTOR = 256/ZSIZE;
- sdl_wheel = 0;
- }
- else
- {
- if (!(sdl_mod & (KMOD_SHIFT|KMOD_CTRL)))
- {
- bsx += sdl_wheel;
- bsy += sdl_wheel;
- }
- else if (sdl_mod & (KMOD_SHIFT) && !(sdl_mod & (KMOD_CTRL)))
- {
- bsx += sdl_wheel;
- }
- else if (sdl_mod & (KMOD_CTRL) && !(sdl_mod & (KMOD_SHIFT)))
- {
- bsy += sdl_wheel;
- }
- if (bsx>1180)
- bsx = 1180;
- if (bsx<0)
- bsx = 0;
- if (bsy>1180)
- bsy = 1180;
- if (bsy<0)
- bsy = 0;
- sdl_wheel = 0;
- /*if(su >= PT_NUM) {
- if(sl < PT_NUM)
- su = sl;
- if(sr < PT_NUM)
- su = sr;
- }*/
- }
- }
- if (sdl_key==SDLK_RIGHTBRACKET) {
- if (sdl_zoom_trig==1)
- {
- ZSIZE += 1;
- if (ZSIZE>60)
- ZSIZE = 60;
- if (ZSIZE<2)
- ZSIZE = 2;
- ZFACTOR = 256/ZSIZE;
- }
- else
- {
- if (sdl_mod & (KMOD_LALT|KMOD_RALT) && !(sdl_mod & (KMOD_SHIFT|KMOD_CTRL)))
- {
- bsx += 1;
- bsy += 1;
- }
- else if (sdl_mod & (KMOD_SHIFT) && !(sdl_mod & (KMOD_CTRL)))
- {
- bsx += 1;
- }
- else if (sdl_mod & (KMOD_CTRL) && !(sdl_mod & (KMOD_SHIFT)))
- {
- bsy += 1;
- }
- else
- {
- bsx += ceil((bsx/5)+0.5f);
- bsy += ceil((bsy/5)+0.5f);
- }
- if (bsx>1180)
- bsx = 1180;
- if (bsy>1180)
- bsy = 1180;
- if (bsx<0)
- bsx = 0;
- if (bsy<0)
- bsy = 0;
- }
- }
- if ((sdl_key=='d'&&(sdl_mod & (KMOD_CTRL))) || (sdl_key=='d' && !isplayer2))
- DEBUG_MODE = !DEBUG_MODE;
- if (sdl_key=='i')
- {
- int nx, ny;
- for (nx = 0; nx<XRES/CELL; nx++)
- for (ny = 0; ny<YRES/CELL; ny++)
- {
- pv[ny][nx] = -pv[ny][nx];
- vx[ny][nx] = -vx[ny][nx];
- vy[ny][nx] = -vy[ny][nx];
- }
- }
- if ((sdl_mod & (KMOD_RCTRL) )&&( sdl_mod & (KMOD_RALT)))
- active_menu = 11;
- if (sdl_key==SDLK_INSERT)// || sdl_key==SDLK_BACKQUOTE)
- REPLACE_MODE = !REPLACE_MODE;
- if (sdl_key==SDLK_BACKQUOTE)
- {
- console_mode = !console_mode;
- //hud_enable = !console_mode;
- }
- if (sdl_key=='g')
- {
- if (sdl_mod & (KMOD_SHIFT))
- GRID_MODE = (GRID_MODE+9)%10;
- else
- GRID_MODE = (GRID_MODE+1)%10;
- }
- if (sdl_key=='=')
- {
- int nx, ny;
- if(sdl_mod & (KMOD_CTRL))
- {
- for(i=0; i<NPART; i++)
- if(parts[i].type==PT_SPRK)
- {
- parts[i].type = parts[i].ctype;
- parts[i].life = 0;
- }
- }
- else
- {
- for (nx = 0; nx<XRES/CELL; nx++)
- for (ny = 0; ny<YRES/CELL; ny++)
- {
- pv[ny][nx] = 0;
- vx[ny][nx] = 0;
- vy[ny][nx] = 0;
- }
- }
- }
-
- if (sdl_key=='w' && (!isplayer2 || (sdl_mod & (KMOD_SHIFT)))) //Gravity, by Moach
- {
- ++gravityMode; // cycle gravity mode
- itc = 51;
-
- switch (gravityMode)
- {
- default:
- gravityMode = 0;
- case 0:
- strcpy(itc_msg, "Gravity: Vertical");
- break;
- case 1:
- strcpy(itc_msg, "Gravity: Off");
- break;
- case 2:
- strcpy(itc_msg, "Gravity: Radial");
- break;
-
- }
- }
- if (sdl_key=='y')
- {
- ++airMode;
- itc = 52;
-
- switch (airMode)
- {
- default:
- airMode = 0;
- case 0:
- strcpy(itc_msg, "Air: On");
- break;
- case 1:
- strcpy(itc_msg, "Air: Pressure Off");
- break;
- case 2:
- strcpy(itc_msg, "Air: Velocity Off");
- break;
- case 3:
- strcpy(itc_msg, "Air: Off");
- break;
- case 4:
- strcpy(itc_msg, "Air: No Update");
- break;
- }
- }
-
- if (sdl_key=='t')
- VINE_MODE = !VINE_MODE;
- if (sdl_key==SDLK_SPACE)
- sys_pause = !sys_pause;
- if (sdl_key=='h')
- hud_enable = !hud_enable;
- if (sdl_key=='p')
- dump_frame(vid_buf, XRES, YRES, XRES+BARSIZE);
- if (sdl_key=='v'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)))
- {
- if (clipboard_ready==1)
- {
- load_data = malloc(clipboard_length);
- memcpy(load_data, clipboard_data, clipboard_length);
- load_size = clipboard_length;
- if (load_data)
- {
- load_img = prerender_save(load_data, load_size, &load_w, &load_h);
- if (load_img)
- load_mode = 1;
- else
- free(load_data);
- }
- }
- }
- if (load_mode==1)
- {
- matrix2d transform = m2d_identity;
- vector2d translate = v2d_zero;
- void *ndata;
- int doTransform = 0;
- if (sdl_key=='r'&&(sdl_mod & (KMOD_CTRL))&&(sdl_mod & (KMOD_SHIFT)))
- {
- transform = m2d_new(-1,0,0,1); //horizontal invert
- doTransform = 1;
- }
- else if (sdl_key=='r'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)))
- {
- transform = m2d_new(0,1,-1,0); //rotate anticlockwise 90 degrees
- doTransform = 1;
- }
- else if (sdl_mod & (KMOD_CTRL))
- {
- doTransform = 1;
- if (sdl_key==SDLK_LEFT) translate = v2d_new(-1,0);
- else if (sdl_key==SDLK_RIGHT) translate = v2d_new(1,0);
- else if (sdl_key==SDLK_UP) translate = v2d_new(0,-1);
- else if (sdl_key==SDLK_DOWN) translate = v2d_new(0,1);
- else doTransform = 0;
- }
- if (doTransform)
- {
- ndata = transform_save(load_data, &load_size, transform, translate);
- if (ndata!=load_data) free(load_data);
- free(load_img);
- load_data = ndata;
- load_img = prerender_save(load_data, load_size, &load_w, &load_h);
- }
- }
- if (sdl_key=='r'&&!(sdl_mod & (KMOD_CTRL|KMOD_SHIFT)))
- GENERATION = 0;
- if (sdl_key=='x'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)))
- {
- save_mode = 1;
- copy_mode = 2;
- }
- if (sdl_key=='c'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)))
- {
- save_mode = 1;
- copy_mode = 1;
- }
- else if (sdl_key=='c')
- {
- set_cmode((cmode+1) % CM_COUNT);
- if (it > 50)
- it = 50;
- }
- if (sdl_key=='z'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))) // Undo
- {
- int cbx, cby, cbi;
-
- for (cbi=0; cbi<NPART; cbi++)
- parts[cbi] = cb_parts[cbi];
-
- for (cby = 0; cby<YRES; cby++)
- for (cbx = 0; cbx<XRES; cbx++)
- pmap[cby][cbx] = cb_pmap[cby][cbx];
-
- for (cby = 0; cby<(YRES/CELL); cby++)
- for (cbx = 0; cbx<(XRES/CELL); cbx++)
- {
- vx[cby][cbx] = cb_vx[cby][cbx];
- vy[cby][cbx] = cb_vy[cby][cbx];
- pv[cby][cbx] = cb_pv[cby][cbx];
- bmap[cby][cbx] = cb_bmap[cby][cbx];
- emap[cby][cbx] = cb_emap[cby][cbx];
- }
- }
-#ifdef INTERNAL
- int counterthing;
- if (sdl_key=='v'&&!(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)))
- {
- if (sdl_mod & (KMOD_SHIFT)) {
- if (vs>=1)
- vs = 0;
- else
- vs = 3;//every other frame
- }
- else
- {
- if (vs>=1)
- vs = 0;
- else
- vs = 1;
- }
- counterthing = 0;
- }
if (vs)
{
if (counterthing+1>=vs)
@@ -3909,21 +3610,73 @@ int main(int argc, char *argv[])
if(console_mode)
{
- char *console;
- //char error[255] = "error!";
- sys_pause = 1;
- console = console_ui(vid_buf,console_error);
- console = mystrdup(console);
- strcpy(console_error,"");
- if(process_command(vid_buf,console,console_error)==-1)
- {
- free(console);
- break;
- }
- free(console);
- if(!console_mode)
- hud_enable = 1;
+ #ifdef PYCONSOLE
+ if(pyready==1 && pygood==1)
+ {
+ char *console;
+ //char error[255] = "error!";
+ sys_pause = 1;
+ console = console_ui(vid_buf,console_error,console_more);
+ console = mystrdup(console);
+ strcpy(console_error,"");
+ if(process_command(vid_buf,console,&console_error,pfunc)==-1)
+ {
+ free(console);
+ break;
+ }
+ free(console);
+ if(!console_mode)
+ hud_enable = 1;
+ }
+ else
+ {
+ char *console;
+ sys_pause = 1;
+ console = console_ui(vid_buf,console_error,console_more);
+ console = mystrdup(console);
+ strcpy(console_error,"");
+ if(process_command_old(vid_buf,console,&console_error)==-1)
+ {
+ free(console);
+ break;
+ }
+ free(console);
+ if(!console_mode)
+ hud_enable = 1;
+ }
+ #else
+ char *console;
+ sys_pause = 1;
+ console = console_ui(vid_buf,console_error,console_more);
+ console = mystrdup(console);
+ strcpy(console_error,"");
+ if(process_command_old(vid_buf,console,&console_error)==-1)
+ {
+ free(console);
+ break;
+ }
+ free(console);
+ if(!console_mode)
+ hud_enable = 1;
+ #endif
}
+
+ //execute python step hook
+ #ifdef PYCONSOLE
+ if(pyready==1 && pygood==1)
+ if(pstep!=NULL)
+ {
+ pargs=Py_BuildValue("()");
+ pvalue = PyObject_CallObject(pstep, pargs);
+ Py_DECREF(pargs);
+ pargs=NULL;
+ if(pvalue==NULL)
+ strcpy(console_error,"failed to execute step code.");
+ //Py_DECREF(pvalue);
+ //puts("a");
+ pvalue=NULL;
+ }
+ #endif
sdl_blit(0, 0, XRES+BARSIZE, YRES+MENUSIZE, vid_buf, XRES+BARSIZE);
//Setting an element for the stick man
@@ -3944,6 +3697,11 @@ 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");
+
Py_Finalize();//cleanup any python stuff.
return 0;
}
@@ -3965,451 +3723,485 @@ int process_command(pixel *vid_buf,char *console,char *console_error,PyObject *p
if(strcmp(console2, "quit")==0)
{
return -1;
- }
- else if(strcmp(console2, "file")==0)
- {
- if(file_script){
- FILE *f=fopen(console3, "r");
- if(f)
- {
- char fileread[5000];//TODO: make this change with file size
- char pch[5000];
- char tokens[10];
- int tokensize;
- nx = 0;
- ny = 0;
- j = 0;
- m = 0;
- if(console4)
- console_parse_coords(console4, &nx , &ny, console_error);
- memset(pch,0,sizeof(pch));
- memset(fileread,0,sizeof(fileread));
- fread(fileread,1,5000,f);
- for(i=0; i<strlen(fileread); i++)
- {
- if(fileread[i] != '\n')
- {
- pch[i-j] = fileread[i];
- if(fileread[i] != ' ')
- tokens[i-m] = fileread[i];
- }
- if(fileread[i] == ' ' || fileread[i] == '\n')
- {
- if(sregexp(tokens,"^x.[0-9],y.[0-9]")==0)//TODO: fix regex matching to work with x,y ect, right now it has to have a +0 or -0
- {
- char temp[5];
- int starty = 0;
- tokensize = strlen(tokens);
- x = 0;
- y = 0;
- sscanf(tokens,"x%d,y%d",&x,&y);
- sscanf(tokens,"%9s,%9s",xcoord,ycoord);
- x += nx;
- y += ny;
- sprintf(xcoord,"%d",x);
- sprintf(ycoord,"%d",y);
- for(k = 0; k<strlen(xcoord);k++)//rewrite pch with numbers
- {
- pch[i-j-tokensize+k] = xcoord[k];
- starty = k+1;
- }
- pch[i-j-tokensize+starty] = ',';
- starty++;
- for(k=0;k<strlen(ycoord);k++)
- {
- pch[i-j-tokensize+starty+k] = ycoord[k];
-
- }
- pch[i-j-tokensize +strlen(xcoord) +1 +strlen(ycoord)] = ' ';
- j = j -tokensize +strlen(xcoord) +1 +strlen(ycoord);
- }
- memset(tokens,0,sizeof(tokens));
- m = i+1;
- }
- if(fileread[i] == '\n')
- {
-
- if(do_next)
- {
- if(strcmp(pch,"else")==0)
- do_next = 0;
- else
- do_next = process_command(vid_buf, pch, console_error);
- }
- else if(strcmp(pch,"endif")==0 || strcmp(pch,"else")==0)
- do_next = 1;
- memset(pch,0,sizeof(pch));
- j = i+1;
- }
- }
- //sprintf(console_error, "%s exists", console3);
- fclose(f);
- }
- else
- {
- sprintf(console_error, "%s does not exist", console3);
- }
- }
- else
- {
- sprintf(console_error, "Scripts are not enabled");
- }
-
- }
- else if(strcmp(console2, "sound")==0)
- {
- if (sound_enable) play_sound(console3);
- else strcpy(console_error, "Audio device not available - cannot play sounds");
- }
- else if(strcmp(console2, "load")==0)
- {
- j = atoi(console3);
- if(j)
- {
- open_ui(vid_buf, console3, NULL);
- console_mode = 0;
- }
- }
- else if(strcmp(console2, "if")==0)
- {
- if(strcmp(console3, "type")==0)//TODO: add more than just type, and be able to check greater/less than
- {
- if (console_parse_partref(console4, &i, console_error)
- && console_parse_type(console5, &j, console_error))
- {
- if(parts[i].type==j)
- return 1;
- else
- return 0;
- }
- else
- return 0;
- }
- }
- else if (strcmp(console2, "create")==0)
- {
- if (console_parse_type(console3, &j, console_error)
- && console_parse_coords(console4, &nx, &ny, console_error))
- {
- if (!j)
- strcpy(console_error, "Cannot create particle with type NONE");
- else if (create_part(-1,nx,ny,j)<0)
- strcpy(console_error, "Could not create particle");
- }
- }
- else if (strcmp(console2, "delete")==0 || strcmp(console2, "kill")==0)
- {
- if (console_parse_partref(console3, &i, console_error))
- kill_part(i);
- }
- else if(strcmp(console2, "reset")==0)
- {
- if(strcmp(console3, "pressure")==0)
- {
- for (nx = 0; nx<XRES/CELL; nx++)
- for (ny = 0; ny<YRES/CELL; ny++)
- {
- pv[ny][nx] = 0;
- }
- }
- else if(strcmp(console3, "velocity")==0)
- {
- for (nx = 0; nx<XRES/CELL; nx++)
- for (ny = 0; ny<YRES/CELL; ny++)
- {
- vx[ny][nx] = 0;
- vy[ny][nx] = 0;
- }
- }
- else if(strcmp(console3, "sparks")==0)
- {
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type==PT_SPRK)
- {
- parts[i].type = parts[i].ctype;
- parts[i].life = 4;
- }
- }
- }
- else if(strcmp(console3, "temp")==0)
- {
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type)
- {
- parts[i].temp = ptypes[parts[i].type].heat;
- }
- }
- }
- }
- else if(strcmp(console2, "set")==0)
- {
- if(strcmp(console3, "life")==0)
- {
- if(strcmp(console4, "all")==0)
- {
- j = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type)
- parts[i].life = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- k = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type == j)
- parts[i].life = k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- j = atoi(console5);
- parts[i].life = j;
- }
- }
- }
- if(strcmp(console3, "type")==0)
- {
- if(strcmp(console4, "all")==0)
- {
- if (console_parse_type(console5, &j, console_error))
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type)
- parts[i].type = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error)
- && console_parse_type(console5, &k, console_error))
- {
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type == j)
- parts[i].type = k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error)
- && console_parse_type(console5, &j, console_error))
- {
- parts[i].type = j;
- }
- }
- }
- if(strcmp(console3, "temp")==0)
- {
- if(strcmp(console4, "all")==0)
- {
- j = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type)
- parts[i].temp = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- k = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type == j)
- parts[i].temp= k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- j = atoi(console5);
- parts[i].temp = j;
- }
- }
- }
- if(strcmp(console3, "tmp")==0)
- {
- if(strcmp(console4, "all")==0)
- {
- j = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type)
- parts[i].tmp = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- k = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type == j)
- parts[i].tmp = k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- j = atoi(console5);
- parts[i].tmp = j;
- }
- }
- }
- if(strcmp(console3, "x")==0)
- {
- if(strcmp(console4, "all")==0)
- {
- j = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type)
- parts[i].x = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- k = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type == j)
- parts[i].x = k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- j = atoi(console5);
- parts[i].x = j;
- }
- }
- }
- if(strcmp(console3, "y")==0)
- {
- if(strcmp(console4, "all")==0)
- {
- j = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type)
- parts[i].y = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- k = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type == j)
- parts[i].y = k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- j = atoi(console5);
- parts[i].y = j;
- }
- }
- }
- if(strcmp(console3, "ctype")==0)
- {
- if(strcmp(console4, "all")==0)
- {
- if (console_parse_type(console5, &j, console_error))
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type)
- parts[i].ctype = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error)
- && console_parse_type(console5, &k, console_error))
- {
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type == j)
- parts[i].ctype = k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error)
- && console_parse_type(console5, &j, console_error))
- {
- parts[i].ctype = j;
- }
- }
- }
- if(strcmp(console3, "vx")==0)
- {
- if(strcmp(console4, "all")==0)
- {
- j = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type)
- parts[i].vx = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- k = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type == j)
- parts[i].vx = k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- j = atoi(console5);
- parts[i].vx = j;
- }
- }
- }
- if(strcmp(console3, "vy")==0)
- {
- if(strcmp(console4, "all")==0)
- {
- j = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type)
- parts[i].vy = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- k = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type == j)
- parts[i].vy = k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- j = atoi(console5);
- parts[i].vy = j;
- }
- }
- }
- }
- else
- strcpy(console_error, "Invalid Command");
+ } 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;
+ char xcoord[10];
+ char ycoord[10];
+ char console2[15];
+ char console3[15];
+ char console4[15];
+ char console5[15];
+ //sprintf(console_error, "%s", console);
+ if(console && strcmp(console, "")!=0 && strncmp(console, " ", 1)!=0)
+ {
+ sscanf(console,"%14s %14s %14s %14s", console2, console3, console4, console5);//why didn't i know about this function?!
+ if(strcmp(console2, "quit")==0)
+ {
+ return -1;
+ }
+ else if(strcmp(console2, "file")==0 && console3)
+ {
+ if(file_script){
+ FILE *f=fopen(console3, "r");
+ if(f)
+ {
+ char fileread[5000];//TODO: make this change with file size
+ char pch[5000];
+ char tokens[10];
+ int tokensize;
+ nx = 0;
+ ny = 0;
+ j = 0;
+ m = 0;
+ if(console4)
+ console_parse_coords(console4, &nx , &ny, console_error);
+ memset(pch,0,sizeof(pch));
+ memset(fileread,0,sizeof(fileread));
+ fread(fileread,1,5000,f);
+ for(i=0; i<strlen(fileread); i++)
+ {
+ if(fileread[i] != '\n')
+ {
+ pch[i-j] = fileread[i];
+ if(fileread[i] != ' ')
+ tokens[i-m] = fileread[i];
+ }
+ if(fileread[i] == ' ' || fileread[i] == '\n')
+ {
+ if(sregexp(tokens,"^x.[0-9],y.[0-9]")==0)//TODO: fix regex matching to work with x,y ect, right now it has to have a +0 or -0
+ {
+ char temp[5];
+ int starty = 0;
+ tokensize = strlen(tokens);
+ x = 0;
+ y = 0;
+ sscanf(tokens,"x%d,y%d",&x,&y);
+ sscanf(tokens,"%9s,%9s",xcoord,ycoord);
+ x += nx;
+ y += ny;
+ sprintf(xcoord,"%d",x);
+ sprintf(ycoord,"%d",y);
+ for(k = 0; k<strlen(xcoord);k++)//rewrite pch with numbers
+ {
+ pch[i-j-tokensize+k] = xcoord[k];
+ starty = k+1;
+ }
+ pch[i-j-tokensize+starty] = ',';
+ starty++;
+ for(k=0;k<strlen(ycoord);k++)
+ {
+ pch[i-j-tokensize+starty+k] = ycoord[k];
+
+ }
+ pch[i-j-tokensize +strlen(xcoord) +1 +strlen(ycoord)] = ' ';
+ j = j -tokensize +strlen(xcoord) +1 +strlen(ycoord);
+ }
+ memset(tokens,0,sizeof(tokens));
+ m = i+1;
+ }
+ if(fileread[i] == '\n')
+ {
+
+ if(do_next)
+ {
+ if(strcmp(pch,"else")==0)
+ do_next = 0;
+ else
+ do_next = process_command_old(vid_buf, pch, console_error);
+ }
+ else if(strcmp(pch,"endif")==0 || strcmp(pch,"else")==0)
+ do_next = 1;
+ memset(pch,0,sizeof(pch));
+ j = i+1;
+ }
+ }
+ //sprintf(console_error, "%s exists", console3);
+ fclose(f);
+ }
+ else
+ {
+ sprintf(console_error, "%s does not exist", console3);
+ }
+ }
+ else
+ {
+ sprintf(console_error, "Scripts are not enabled");
+ }
+
+ }
+ else if(strcmp(console2, "sound")==0 && console3)
+ {
+ if (sound_enable) play_sound(console3);
+ else strcpy(console_error, "Audio device not available - cannot play sounds");
+ }
+ else if(strcmp(console2, "python")==0)
+ if(pygood==1)
+ pyready=1;
+ else
+ strcpy(console_error, "python not ready. check stdout for more info.");
+ else if(strcmp(console2, "load")==0 && console3)
+ {
+ j = atoi(console3);
+ if(j)
+ {
+ open_ui(vid_buf, console3, NULL);
+ console_mode = 0;
+ }
+ }
+ else if(strcmp(console2, "if")==0 && console3)
+ {
+ if(strcmp(console3, "type")==0)//TODO: add more than just type, and be able to check greater/less than
+ {
+ if (console_parse_partref(console4, &i, console_error)
+ && console_parse_type(console5, &j, console_error))
+ {
+ if(parts[i].type==j)
+ return 1;
+ else
+ return 0;
+ }
+ else
+ return 0;
+ }
+ }
+ else if (strcmp(console2, "create")==0 && console3 && console4)
+ {
+ if (console_parse_type(console3, &j, console_error)
+ && console_parse_coords(console4, &nx, &ny, console_error))
+ {
+ if (!j)
+ strcpy(console_error, "Cannot create particle with type NONE");
+ else if (create_part(-1,nx,ny,j)<0)
+ strcpy(console_error, "Could not create particle");
+ }
+ }
+ else if ((strcmp(console2, "delete")==0 || strcmp(console2, "kill")==0) && console3)
+ {
+ if (console_parse_partref(console3, &i, console_error))
+ kill_part(i);
+ }
+ else if(strcmp(console2, "reset")==0 && console3)
+ {
+ if(strcmp(console3, "pressure")==0)
+ {
+ for (nx = 0; nx<XRES/CELL; nx++)
+ for (ny = 0; ny<YRES/CELL; ny++)
+ {
+ pv[ny][nx] = 0;
+ }
+ }
+ else if(strcmp(console3, "velocity")==0)
+ {
+ for (nx = 0; nx<XRES/CELL; nx++)
+ for (ny = 0; ny<YRES/CELL; ny++)
+ {
+ vx[ny][nx] = 0;
+ vy[ny][nx] = 0;
+ }
+ }
+ else if(strcmp(console3, "sparks")==0)
+ {
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type==PT_SPRK)
+ {
+ parts[i].type = parts[i].ctype;
+ parts[i].life = 4;
+ }
+ }
+ }
+ else if(strcmp(console3, "temp")==0)
+ {
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type)
+ {
+ parts[i].temp = ptypes[parts[i].type].heat;
+ }
+ }
+ }
+ }
+ else if(strcmp(console2, "set")==0 && console3 && console4 && console5)
+ {
+ if(strcmp(console3, "life")==0)
+ {
+ if(strcmp(console4, "all")==0)
+ {
+ j = atoi(console5);
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type)
+ parts[i].life = j;
+ }
+ }
+ else if (console_parse_type(console4, &j, console_error))
+ {
+ k = atoi(console5);
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type == j)
+ parts[i].life = k;
+ }
+ }
+ else
+ {
+ if (console_parse_partref(console4, &i, console_error))
+ {
+ j = atoi(console5);
+ parts[i].life = j;
+ }
+ }
+ }
+ if(strcmp(console3, "type")==0)
+ {
+ if(strcmp(console4, "all")==0)
+ {
+ if (console_parse_type(console5, &j, console_error))
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type)
+ parts[i].type = j;
+ }
+ }
+ else if (console_parse_type(console4, &j, console_error)
+ && console_parse_type(console5, &k, console_error))
+ {
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type == j)
+ parts[i].type = k;
+ }
+ }
+ else
+ {
+ if (console_parse_partref(console4, &i, console_error)
+ && console_parse_type(console5, &j, console_error))
+ {
+ parts[i].type = j;
+ }
+ }
+ }
+ if(strcmp(console3, "temp")==0)
+ {
+ if(strcmp(console4, "all")==0)
+ {
+ j = atoi(console5);
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type)
+ parts[i].temp = j;
+ }
+ }
+ else if (console_parse_type(console4, &j, console_error))
+ {
+ k = atoi(console5);
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type == j)
+ parts[i].temp= k;
+ }
+ }
+ else
+ {
+ if (console_parse_partref(console4, &i, console_error))
+ {
+ j = atoi(console5);
+ parts[i].temp = j;
+ }
+ }
+ }
+ if(strcmp(console3, "tmp")==0)
+ {
+ if(strcmp(console4, "all")==0)
+ {
+ j = atoi(console5);
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type)
+ parts[i].tmp = j;
+ }
+ }
+ else if (console_parse_type(console4, &j, console_error))
+ {
+ k = atoi(console5);
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type == j)
+ parts[i].tmp = k;
+ }
+ }
+ else
+ {
+ if (console_parse_partref(console4, &i, console_error))
+ {
+ j = atoi(console5);
+ parts[i].tmp = j;
+ }
+ }
+ }
+ if(strcmp(console3, "x")==0)
+ {
+ if(strcmp(console4, "all")==0)
+ {
+ j = atoi(console5);
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type)
+ parts[i].x = j;
+ }
+ }
+ else if (console_parse_type(console4, &j, console_error))
+ {
+ k = atoi(console5);
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type == j)
+ parts[i].x = k;
+ }
+ }
+ else
+ {
+ if (console_parse_partref(console4, &i, console_error))
+ {
+ j = atoi(console5);
+ parts[i].x = j;
+ }
+ }
+ }
+ if(strcmp(console3, "y")==0)
+ {
+ if(strcmp(console4, "all")==0)
+ {
+ j = atoi(console5);
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type)
+ parts[i].y = j;
+ }
+ }
+ else if (console_parse_type(console4, &j, console_error))
+ {
+ k = atoi(console5);
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type == j)
+ parts[i].y = k;
+ }
+ }
+ else
+ {
+ if (console_parse_partref(console4, &i, console_error))
+ {
+ j = atoi(console5);
+ parts[i].y = j;
+ }
+ }
+ }
+ if(strcmp(console3, "ctype")==0)
+ {
+ if(strcmp(console4, "all")==0)
+ {
+ if (console_parse_type(console5, &j, console_error))
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type)
+ parts[i].ctype = j;
+ }
+ }
+ else if (console_parse_type(console4, &j, console_error)
+ && console_parse_type(console5, &k, console_error))
+ {
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type == j)
+ parts[i].ctype = k;
+ }
+ }
+ else
+ {
+ if (console_parse_partref(console4, &i, console_error)
+ && console_parse_type(console5, &j, console_error))
+ {
+ parts[i].ctype = j;
+ }
+ }
+ }
+ if(strcmp(console3, "vx")==0)
+ {
+ if(strcmp(console4, "all")==0)
+ {
+ j = atoi(console5);
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type)
+ parts[i].vx = j;
+ }
+ }
+ else if (console_parse_type(console4, &j, console_error))
+ {
+ k = atoi(console5);
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type == j)
+ parts[i].vx = k;
+ }
+ }
+ else
+ {
+ if (console_parse_partref(console4, &i, console_error))
+ {
+ j = atoi(console5);
+ parts[i].vx = j;
+ }
+ }
+ }
+ if(strcmp(console3, "vy")==0)
+ {
+ if(strcmp(console4, "all")==0)
+ {
+ j = atoi(console5);
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type)
+ parts[i].vy = j;
+ }
+ }
+ else if (console_parse_type(console4, &j, console_error))
+ {
+ k = atoi(console5);
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type == j)
+ parts[i].vy = k;
+ }
+ }
+ else
+ {
+ if (console_parse_partref(console4, &i, console_error))
+ {
+ j = atoi(console5);
+ parts[i].vy = j;
+ }
+ }
+ }
+ }
+ else
+ sprintf(console_error, "Invalid Command", console2);
+ }
+ return 1;
+}