summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLieuwe <lieuwemo@gmail.com>2011-03-05 14:09:15 (GMT)
committer Lieuwe <lieuwemo@gmail.com>2011-03-05 14:09:15 (GMT)
commit85a2ba9a6e64b738337a500c3eb0c69a9ad6ecfe (patch)
treecd7c23fe7b32402842ed3856825b0d6b37ed3153 /src
parent04f4a0d9fe90533d583d118a907122cb2060bf02 (diff)
downloadpowder-85a2ba9a6e64b738337a500c3eb0c69a9ad6ecfe.zip
powder-85a2ba9a6e64b738337a500c3eb0c69a9ad6ecfe.tar.gz
implemented a step hook and modified the makefile to call getheader.py
Diffstat (limited to 'src')
-rw-r--r--src/main.c38
-rw-r--r--src/python/tpt_console.py16
2 files changed, 41 insertions, 13 deletions
diff --git a/src/main.c b/src/main.c
index a793a7b..019befa 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1813,7 +1813,7 @@ int main(int argc, char *argv[])
SDL_AudioSpec fmt;
int username_flash = 0, username_flash_t = 1;
GSPEED = 1;
- PyObject *pname,*pmodule,*pfunc,*pvalue,*pargs;
+ PyObject *pname,*pmodule,*pfunc,*pvalue,*pargs,*pstep;
/* Set 16-bit stereo audio at 22Khz */
fmt.freq = 22050;
@@ -1840,26 +1840,28 @@ int main(int argc, char *argv[])
pfunc=PyObject_GetAttrString(pmodule,"handle");//get the handler function
if(pfunc && PyCallable_Check(pfunc))//check if it's really a function
{
- //it is
printf("python console ready to go.\n");
- /*pargs=Py_BuildValue("(s)","test");
- pvalue = PyObject_CallObject(pfunc, pargs);
- Py_DECREF(pargs);
- pargs=NULL;
- //Py_DECREF(pvalue);
- //puts("a");
- pvalue=NULL;*/
}
else
{
- //oops! mangled console.py?
printf("unable to find handle function, mangled console.py?\n");
return -1;
}
+
+ pstep=PyObject_GetAttrString(pmodule,"step");//get the handler function
+ if(pstep && PyCallable_Check(pfunc))//check if it's really a function
+ {
+ printf("step function found.\n");
+ }
+ else
+ {
+ printf("unable to find step function. ignoring.\n");
+ //return -1;
+ }
}
else
{
- printf("unable to find console module, missing file?\n");
+ printf("unable to find console module, missing file or mangled console.py?\n");
return -1;
}
@@ -3397,6 +3399,19 @@ int main(int argc, char *argv[])
hud_enable = 1;
}
+ //execute python step hook
+ 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;
+ }
sdl_blit(0, 0, XRES+BARSIZE, YRES+MENUSIZE, vid_buf, XRES+BARSIZE);
//Setting an element for the stick man
@@ -3414,7 +3429,6 @@ int main(int argc, char *argv[])
else
player2[2] = PT_DUST;
}
-
}
SDL_CloseAudio();
http_done();
diff --git a/src/python/tpt_console.py b/src/python/tpt_console.py
index 864fed8..a854756 100644
--- a/src/python/tpt_console.py
+++ b/src/python/tpt_console.py
@@ -1,6 +1,5 @@
import tpt
from tpt import *
-from utils import *
import sys
import code
import ctypes
@@ -75,3 +74,18 @@ def _handle(txt):
exec txt in handle.glob
except Exception as ex:
error(ex)
+
+def step():
+ try:
+ a=handle.glob
+ except:
+ clean()
+ try:
+ _step()
+ except Exception as ex:
+ error(ex)
+
+def _step():
+ #print "handling '%s'"%txt
+ #print "step"
+ toggle_pause()