From a3cc010aae7407c6e4600de691da876dc5c7b8fd Mon Sep 17 00:00:00 2001 From: Cracker64 Date: Fri, 11 Mar 2011 20:58:43 -0500 Subject: [PATCH] forgot some files, and a few fixes, set commands use 'setfrom' instead of 'from' as a keyword, wind brush fixes. --- console_README | 45 +++++++++++++++++++++++++++++++++++++++++++++ getheader.py | 37 +++++++++++++++++++++++++++++++++++++ src/main.c | 20 ++++++++++---------- 3 files changed, 92 insertions(+), 10 deletions(-) create mode 100644 console_README create mode 100644 getheader.py diff --git a/console_README b/console_README new file mode 100644 index 000000000..0171b2a11 --- /dev/null +++ b/console_README @@ -0,0 +1,45 @@ +### CONSOLE ### +the console in this version is a python console and will execute any command you enter. +the api for interacting with the powder toy is contained in the tpt module and is already imported at startup. +currently implemented api functions: + create(x,y,type) create a particle of type at , + reset_velocity() resets all velocity + reset_pressure() resets all pressure + reset_sparks() resets all sparks + +### USING SET COMMANDS ### +the console uses keywords to identify variables of what to set, you can specify x and y coords with x=100 y=100, ect. +i is the particle number +setfrom will change all of setfrom's type to the setto variable. It needs to be a string "dust" ect, "all" for all. +the setto is what the particle(s) will be set to, it is a string for the type/ctype commands, and an int for the rest, there is a settoint for type and ctype command. +you need to set the to* variable and one location/name/coords for it to work. + set_type(x=,y=,i=,setfrom="",setto="") + set_life() + set_temp() + set_tmp() + set_x() + set_y() + set_vx() + set_vy() + set_ctype() + + pause() pause the game(note that closing the console + pauses the game) + unpause() unpause the game(note that closing the console + pauses the game) + toggle_pause() toggle pause(note that closing the console + pauses the game) + close_console() closes the console and pauses the game + open_console() opens the console + toggle_console() toggles the console + +NOTE: these functions don't do bounds checking, which means that they CAN AND + WILL CRASH the powder toy. be carefull. + +### TIPS&TRICKS ### +all functions that need a particle type expect a number. but instead of doing +tpt.set_life(32,life) you can do tpt.set_life(element['uran'],life) + +### COMPILING ### +before you compile you should have python 2.x installed. +you must run the "getheader.py" script to get the correct linking options, add these options to the makefile diff --git a/getheader.py b/getheader.py new file mode 100644 index 000000000..536915e27 --- /dev/null +++ b/getheader.py @@ -0,0 +1,37 @@ +import sys +import os.path +import compileall +path=os.path.join(sys.exec_prefix,"include","python%s"%sys.version[:3]) +#print "headers at ",repr(path) +#-lpython2.3 -lm -L/usr/lib/python2.3/config +args="-lpython%s -lm -L%s"%(sys.version[:3],os.path.join(sys.exec_prefix,"lib","python%s"%sys.version[:3],"config")) +print " linux args are" +print args,"-I%s"%path + +path=os.path.join(sys.exec_prefix,"include") +args="-lpython%s -lm -L%s"%(sys.version[:3],os.path.join(sys.exec_prefix,"lib","config"))#,"python%s"%sys.version[:3] +print "\n windows args are" +print args,"-I%s"%path + +#unsigned char tpt_console_pyc[] = { 0x1B, 0x57}; +lst=[] +compileall.compile_dir("./src/python", force=1) + +print "generating pyconsole.h" + +fname="./src/python/tpt_console.pyc" +try: + fid=open(fname,"r") +except IOError: + fname="./src/python/tpt_console.pyo" +finally: + fid.close() + +with open(fname,"r") as fid: + for char in fid.read(): + lst.append(hex(ord(char))) +tmp=",".join(lst) +out=''.join(["#include \nunsigned char tpt_console_pyc[] = {",tmp,"};"]) +with open("./includes/pyconsole.h","w") as fid: + fid.write(out) +print "done" diff --git a/src/main.c b/src/main.c index 2323b9794..c94bd18df 100644 --- a/src/main.c +++ b/src/main.c @@ -1357,7 +1357,7 @@ emb_set_life(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; - char *kwlist[] = {"setto", "from", "i", "x", "y", NULL}; + char *kwlist[] = {"setto", "setfrom", "i", "x", "y", NULL}; if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y)) return NULL; // @@ -1398,7 +1398,7 @@ 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", "from", "i", "x", "y", NULL}; + char *kwlist[] = {"setto", "settoint", "setfrom", "i", "x", "y", NULL}; if(!PyArg_ParseTupleAndKeywords(args, keywds, "|sIsIII:set_type",kwlist ,&type,&life,&name,&i,&x,&y)) return NULL; // @@ -1439,7 +1439,7 @@ emb_set_temp(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; - char *kwlist[] = {"setto", "from", "i", "x", "y", NULL}; + char *kwlist[] = {"setto", "setfrom", "i", "x", "y", NULL}; if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y)) return NULL; // @@ -1479,7 +1479,7 @@ emb_set_tmp(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; - char *kwlist[] = {"setto", "from", "i", "x", "y", NULL}; + char *kwlist[] = {"setto", "setfrom", "i", "x", "y", NULL}; if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y)) return NULL; // @@ -1520,7 +1520,7 @@ 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", "from", "i", "x", "y", NULL}; + char *kwlist[] = {"setto", "setfrom", "i", "x", "y", NULL}; if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y)) return NULL; // @@ -1560,7 +1560,7 @@ emb_set_y(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; - char *kwlist[] = {"setto", "from", "i", "x", "y", NULL}; + char *kwlist[] = {"setto", "setfrom", "i", "x", "y", NULL}; if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y)) return NULL; // @@ -1601,7 +1601,7 @@ 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", "from", "i", "x", "y", NULL}; + char *kwlist[] = {"setto", "toctypeint", "setfrom", "i", "x", "y", NULL}; if(!PyArg_ParseTupleAndKeywords(args, keywds, "s|IsIII:set_type",kwlist ,&type, &life, &name,&i,&x,&y)) return NULL; // @@ -1643,7 +1643,7 @@ emb_set_vx(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; - char *kwlist[] = {"setto", "from", "i", "x", "y", NULL}; + char *kwlist[] = {"setto", "setfrom", "i", "x", "y", NULL}; if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y)) return NULL; // @@ -1683,7 +1683,7 @@ emb_set_vy(PyObject *self, PyObject *args, PyObject *keywds) { int i = -1,life,j,x=-1,y=-1; char *name = ""; - char *kwlist[] = {"setto", "from", "i", "x", "y", NULL}; + char *kwlist[] = {"setto", "setfrom", "i", "x", "y", NULL}; if(!PyArg_ParseTupleAndKeywords(args, keywds, "I|sIII:set_type",kwlist ,&life,&name,&i,&x,&y)) return NULL; // @@ -3245,7 +3245,7 @@ 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