diff options
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | build/example.py | 5 | ||||
| -rw-r--r-- | build/tpt_console.py | 106 | ||||
| -rw-r--r-- | console_README | 3 | ||||
| -rw-r--r-- | getheader.py | 1 | ||||
| -rw-r--r-- | src/interface.c | 10 |
6 files changed, 117 insertions, 14 deletions
@@ -2,7 +2,7 @@ SOURCES := src/*.c src/elements/*.c CFLAGS := -w -std=c99 -D_POSIX_C_SOURCE=200112L -Iincludes/ OFLAGS := -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -LFLAGS := -lSDL -lm -lbz2 -lpython2.7 -lm -L/usr/lib/python2.7/config -I/usr/include/python2.7 +LFLAGS := -lSDL -lm -lbz2 -lpython2.7 -lm -L/usr/lib/python2.7/config -I/usr/include/python2.7 LFLAGS_X := -lm -lbz2 -lSDLmain MFLAGS_SSE3 := -march=native -DX86 -DX86_SSE3 -msse3 MFLAGS_SSE2 := -march=native -DX86 -DX86_SSE2 -msse2 @@ -84,11 +84,11 @@ powder-sse.exe: $(SOURCES) powder-res.o mv $@ build powder-x: $(SOURCES) $(PYCOMMAND) - gcc -o $@ $(CFLAGS) $(OFLAGS) $(LFLAGS_X) $(MFLAGS) $(SOURCES) -DMACOSX -DPIX32BGRA -arch x86_64 -framework Cocoa -framework SDL + gcc -o $@ $(CFLAGS) $(OFLAGS) $(LFLAGS_X) $(MFLAGS) $(SOURCES) -DMACOSX -DPIX32BGRA -arch x86_64 -framework Cocoa -framework SDL -framework Python strip $@ mv $@ build powder-x-ogl: $(SOURCES) $(PYCOMMAND) - gcc -o $@ $(CFLAGS) $(OFLAGS) $(LFLAGS_X) $(MFLAGS) $(SOURCES) -DOpenGL -DMACOSX -DPIX32BGRA -arch x86_64 -framework Cocoa -framework SDL -framework OpenGL + gcc -o $@ $(CFLAGS) $(OFLAGS) $(LFLAGS_X) $(MFLAGS) $(SOURCES) -DOpenGL -DMACOSX -DPIX32BGRA -arch x86_64 -framework Cocoa -framework SDL -framework OpenGL -framework Python strip $@ mv $@ build diff --git a/build/example.py b/build/example.py index ade32b7..850d8ae 100644 --- a/build/example.py +++ b/build/example.py @@ -1,6 +1,3 @@ -import tpt -import random -import time import utils # example script @@ -21,4 +18,4 @@ def increment(amount=1): t=129 if t==55: t=56 - tpt.set_type(i=i,settoint=t) + tpt.set_type(i=i,settoint=t)
\ No newline at end of file diff --git a/build/tpt_console.py b/build/tpt_console.py new file mode 100644 index 0000000..e6ecbe4 --- /dev/null +++ b/build/tpt_console.py @@ -0,0 +1,106 @@ +import tpt +import sys +import code +import ctypes +import traceback +from threading import Thread +print "console module loaded." +#redirect stdout like this: +class logger: + def write(self,txt): + txt=txt.split("\n")[-1][:254] + tpt.log(txt) +#sys.stdout=logger() +#sys.stderr=logger() + +element={"none":0,"dust":1,"watr":2,"oil":3,"fire":4,"stne":5,"lava":6,"gunp":7, + "nitr":8,"clne":9,"gas":10,"plex":11,"goo":12,"icei":13,"metl":14,"sprk":15, + "snow":16,"wood":17,"neut":18,"plut":19,"plnt":20,"acid":21,"void":22, + "wtrv":23,"cnct":24,"dstw":25,"salt":26,"sltw":27,"dmnd":28,"bmtl":29, + "brmt":30,"phot":31,"uran":32,"wax":33,"mwax":34,"pscn":35,"nscn":36, + "lntg":37,"insl":38,"bhol":39,"whol":40,"rbdm":41,"lrbd":42,"ntct":43, + "sand":44,"glas":45,"ptct":46,"bgla":47,"thdr":48,"plsm":49,"etrd":50, + "nice":51,"nble":52,"btry":53,"lcry":54,"stkm":55,"swch":56,"smke":57, + "desl":58,"coal":59,"lo2":60,"o2":61,"inwr":62,"yest":63,"dyst":64, + "thrm":65,"glow":66,"brck":67,"hflm":68,"firw":69,"fuse":70,"fsep":71, + "amtr":72,"bcol":73,"pcln":74,"hswc":75,"iron":76,"mort":77,"gol":78, + "hlif":79,"asim":80,"2x2":81,"dani":82,"amoe":83,"move":84,"pgol":85, + "dmoe":86,"34":87,"llif":88,"stan":89,"spng":90,"rime":91,"fog":92, + "bcln":93,"love":94,"deut":95,"warp":96,"pump":97,"fwrk":98,"pipe":99, + "frzz":100,"frzw":101,"grav":102,"bizr":103,"bizrg":104,"bizrs":105, + "inst":106,"isoz":107,"iszs":108,"prti":109,"prto":110,"pste":111, + "psts":112,"anar":113,"vine":114,"invis":115,"equalvel":116,"spawn2":117, + "spawn":118,"shld1":119,"shld2":120,"shld3":121,"shld4":122,"lolz":123, + "wifi":124,"filt":125,"aray":126,"bray":127,"stkm2":128,"bomb":129, + "c5":130,"sing":131,"qrtz":132,"pqrt":133,"seed":134,"maze":135, + "coag":136,"wall":137,"gnar":138,"repl":139,"myst":140,"boyl":141, + "lote":142,"frg2":143,"star":144,"frog":145,"bran":146,"wind":147, + "num":148} + +class _fork(Thread): + def __init__ (self,func): + Thread.__init__(self) + self.func=func + def run(self): + self.func(self) +def fork(func): + try: + a=fork.threads + except: + fork.threads={} + fork.i=0 + tmp=_fork(func) + fork.threads[fork.i]=tmp + fork.i+=1 + tmp.start() + return tmp + tpt.log("Thread #%d started"%(fork.i-1)) +def fork_status(): + count=0 + remove=[] + for key in fork.threads: + if(fork.threads[key].is_alive()): + count+=1 + else: + remove.append[key] + for item in remove: + del fork.threads[item] + tpt.log("%d threads alive. %d threads stopped since last status."%(count,len(remove))) +def fork_unblock(): + pass#i need to implement this some day. +def error(ex): + err=traceback.format_exc() + sys.stdout.write(err) + +def clean(): + #add any functions that must be reachable here. + """copy=["__builtins__","__name__","__doc__","__package__",'tpt','clean', + 'element','fork','_fork','fork_status','fork_unblock','sys'] + handle.glob={} + for item in copy: + handle.glob[item]=globals()[item]""" + handle.glob=globals() + handle.buf="" + +def handle(txt): + try: + a=handle.glob + except: + clean() + try: + _handle(txt) + except Exception as ex: + error(ex) + +def _handle(txt): + #print "handling '%s'"%txt + try: + sys.stdout.write(repr(eval(tmp,handle.glob))) + except: + try: + exec txt in handle.glob + except Exception as ex: + error(ex) + + +
\ No newline at end of file diff --git a/console_README b/console_README index bd85e82..b94053e 100644 --- a/console_README +++ b/console_README @@ -42,5 +42,4 @@ 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 +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 index 43b20ec..536915e 100644 --- a/getheader.py +++ b/getheader.py @@ -35,4 +35,3 @@ out=''.join(["#include <Python.h>\nunsigned char tpt_console_pyc[] = {",tmp,"};" with open("./includes/pyconsole.h","w") as fid: fid.write(out) print "done" -
\ No newline at end of file diff --git a/src/interface.c b/src/interface.c index 6221848..6382ed0 100644 --- a/src/interface.c +++ b/src/interface.c @@ -3867,11 +3867,13 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { //fillrect(vid_buf, -1, -1, XRES, 220, 0, 0, 0, 190); memcpy(old_buf,vid_buf,(XRES+BARSIZE)*YRES*PIXELSIZE); fillrect(old_buf, -1, -1, XRES+1, 220, 0, 0, 0, 190); + currentcommand2 = malloc(sizeof(command_history)); - memset(currentcommand2, 0, sizeof(command_history)); - currentcommand2->prev_command = last_command2; - currentcommand2->command = mystrdup(error); - last_command2 = currentcommand2; + memset(currentcommand2, 0, sizeof(command_history)); + currentcommand2->prev_command = last_command2; + currentcommand2->command = mystrdup(error); + last_command2 = currentcommand2; + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); cc = 0; while(cc < 80){ |
