Fix makefile for OS X

This commit is contained in:
Simon 2011-03-09 18:01:53 +00:00
commit 0ded22493e
8 changed files with 849 additions and 382 deletions

View File

@ -11,67 +11,84 @@ FLAGS_DBUG := -Wall -std=c99 -D_POSIX_C_SOURCE=200112L -pg -DX86 -DX86_SSE3 -mss
COMPILER := gcc
LINUX_TARG := powder-64-sse2 powder-sse powder-sse2
WIN32_TARG := powder-sse.exe powder-sse2.exe
PYCOMMAND := python2 getheader.py
powder: $(SOURCES)
$(PYCOMMAND)
$(COMPILER) -DINTERNAL -o$@ $(CFLAGS) $(OFLAGS) $(LFLAGS) $(MFLAGS_SSE3) $(SOURCES) -DLIN64
mv $@ build
powder-debug-64: $(SOURCES)
$(PYCOMMAND)
$(COMPILER) -m64 -o$@ $(FLAGS_DBUG) -DLIN64 $(SOURCES) -Iincludes/
mv $@ build
powder-debug: $(SOURCES)
$(PYCOMMAND)
$(COMPILER) -m32 -o$@ $(FLAGS_DBUG) -DLIN32 $(SOURCES) -Iincludes/
mv $@ build
powder-sse3: $(SOURCES)
$(PYCOMMAND)
$(COMPILER) -m32 -o$@ $(CFLAGS) $(OFLAGS) $(LFLAGS) $(MFLAGS_SSE3) $(SOURCES) -DLIN32
strip $@
mv $@ build
powder-sse2: $(SOURCES)
$(PYCOMMAND)
$(COMPILER) -m32 -o$@ $(CFLAGS) $(OFLAGS) $(LFLAGS) $(MFLAGS_SSE2) $(SOURCES) -DLIN32
strip $@
mv $@ build
powder-sse: $(SOURCES)
$(PYCOMMAND)
$(COMPILER) -m32 -o$@ $(CFLAGS) $(OFLAGS) $(LFLAGS) $(MFLAGS_SSE) $(SOURCES) -DLIN32
strip $@
mv $@ build
powder-64-sse3-opengl: $(SOURCES)
$(PYCOMMAND)
$(COMPILER) -m64 -o$@ $(CFLAGS) $(OFLAGS) $(LFLAGS) $(MFLAGS_SSE3) $(SOURCES) -DLIN64 -lGL -lGLU -DOpenGL
strip $@
mv $@ build
powder-64-sse3: $(SOURCES)
$(PYCOMMAND)
$(COMPILER) -m64 -o$@ $(CFLAGS) $(OFLAGS) $(LFLAGS) $(MFLAGS_SSE3) $(SOURCES) -DLIN64
strip $@
mv $@ build
powder-64-sse2: $(SOURCES)
$(PYCOMMAND)
$(COMPILER) -m64 -o$@ $(CFLAGS) $(OFLAGS) $(LFLAGS) $(MFLAGS_SSE2) $(SOURCES) -DLIN64
strip $@
mv $@ build
powder-icc: $(SOURCES)
$(PYCOMMAND)
/opt/intel/Compiler/11.1/073/bin/intel64/icc -m64 -o$@ -Iincludes/ -O2 -march=core2 -msse3 -mfpmath=sse -lSDL -lbz2 -lm -xW $(SOURCES) -std=c99 -D_POSIX_C_SOURCE=200112L
powder-res.o: powder-res.rc powder.ico
$(PYCOMMAND)
i586-mingw32msvc-windres powder-res.rc powder-res.o
powder-sse3.exe: $(SOURCES) powder-res.o
$(PYCOMMAND)
i586-mingw32msvc-gcc -o$@ $(CFLAGS) $(OFLAGS) $(MFLAGS_SSE3) $(SOURCES) powder-res.o -lmingw32 -llibregex -lws2_32 -lSDLmain $(LFLAGS) -mwindows -DWIN32
strip $@
chmod 0644 $@
mv $@ build
powder-sse2.exe: $(SOURCES) powder-res.o
$(PYCOMMAND)
i586-mingw32msvc-gcc -o$@ $(CFLAGS) $(OFLAGS) $(MFLAGS_SSE2) $(SOURCES) powder-res.o -lmingw32 -llibregex -lws2_32 -lSDLmain $(LFLAGS) -mwindows -DWIN32
strip $@
chmod 0644 $@
mv $@ build
powder-sse.exe: $(SOURCES) powder-res.o
$(PYCOMMAND)
i586-mingw32msvc-gcc -o$@ $(CFLAGS) $(OFLAGS) $(MFLAGS_SSE) $(SOURCES) powder-res.o -lmingw32 -llibregex -lws2_32 -lSDLmain $(LFLAGS) -mwindows -DWIN32
strip $@
chmod 0644 $@
mv $@ build
powder-x: $(SOURCES)
$(PYCOMMAND)
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 -framework Python
strip $@
mv $@ build

211
build/ext_chat.py Normal file
View File

@ -0,0 +1,211 @@
import tpt
import sys
import time
import socket
import tpt_console
HOST="irc.freenode.net"
PORT=6667
name=tpt.get_name()
print "name is %s"%repr(name)
if(name==""):
#fuck. abort?
raise SystemExit("please log in!")
def raw(s,st):
s.send("%s\n\r"%st)
def init():
global frame,s,rec,readbuffer,namelist,typing,typed,IDENT,NICK
global REALNAME,CHANNEL
frame=0
s=None
rec=([("",0,0,0,255)]*20)+[("connected.",255,0,0,128)]
readbuffer=""
namelist=[]
typing=False
typed=""
NICK=name+"[tpt]"
IDENT=name+"[tpt]"
REALNAME=name
CHANNEL="#foobar7"
readbuffer=""
def exit():
raw(s,"QUIT")
s.close()
def console_handle(txt):
"""
:doxin!~lieuwe@unaffiliated/lieuwe JOIN :#foobar7
:doxin!~lieuwe@unaffiliated/lieuwe PRIVMSG #foobar7 :there
:doxin!~lieuwe@unaffiliated/lieuwe PRIVMSG #foobar7 :ACTION is fat
"""
lst=txt.split(" ")
if(lst[0]=="/me"):
rec.append(("%s %s"%(NICK,txt[4:]),255,0,255,128))
raw(s,"PRIVMSG %s :\x01ACTION %s\x01"%(CHANNEL,txt[4:]))
tpt.console_close()
else:
rec.append(("<%s>: %s"%(NICK,txt),255,255,0,128))
raw(s,"PRIVMSG %s :%s"%(CHANNEL,txt))
tpt.console_close()
def key(keyy) :
try:
a=key.pmod
except:
key.pmod=(False,False,False)
global typing,typed
print "got %s"%repr(keyy)
ctrl1,ctrl2,alt1,alt2,shift1,shift2=tpt.get_modifier()
mod=(ctrl1 or ctrl2,alt1 or alt2,shift1 or shift2)
skip=False
if(not key.pmod[0] and mod[0]):
skip=True
if(not key.pmod[1] and mod[1]):
skip=True
if(not key.pmod[2] and mod[2]):
skip=True
key.pmod=mod
if(skip):
return
if(typing and ord(keyy)>=32 and ord(keyy)<=126):
if(mod[2]):
typed+=keyy.upper()#needs to be fixed for special chars
else:
typed+=keyy
if(keyy=="\x1b" and typing):
typing=False
typed=""
tpt.shortcuts_enable()
if(keyy=="t" and typing==False):
typing=True
tpt.shortcuts_disable()
if(keyy=="\r" and typing==True):
console_handle(typed)
typed=""
typing=False
tpt.shortcuts_enable()
#got '\t'
#got '\x08'
if(keyy=="\x08"):
typed=typed[:-1]
#if(keyy=="\t"):
# startswith=
def step():
global frame,s,rec,readbuffer,namelist
frame+=1
if(frame==1):
tpt.console_close()
#lets see if we can seize the console:
tpt_console._handle=console_handle
if(frame==2):
tpt.draw_fillrect(0,0,612,384,0,0,0,128)
tpt.draw_text(32,32,"opening connection\nhold on to your pants.",255,255,255)
if(frame==3):
s=socket.socket()
s.settimeout(5)
s.connect((HOST, PORT))
raw(s,"NICK %s" % NICK)
raw(s,"USER %s %s bla :%s" % (IDENT, HOST, REALNAME))
s.settimeout(0)
if(frame==120):
raw(s,"JOIN %s"%CHANNEL)
rec.append(("joined",255,0,0,255))
if(frame>=3):
try:
readbuffer=readbuffer+s.recv(1024)
except IOError:
pass
else:
temp=readbuffer.split("\n")
readbuffer=temp.pop()
for line in temp:
line=line.strip()
#print repr(line)
line=line.split()
if(line[1]=="PRIVMSG"):
#:doxin!~lieuwe@unaffiliated/lieuwe PRIVMSG doxin[tpt] :some shit
frm=line[0][1:].partition("!")[0]
msg=' '.join(line[3:])[1:]
tmp=["<",frm,"> ",msg]
if(msg[0]=="\x01" and msg[-1]=="\x01"):
msg=msg[8:-1]#ACTION
tmp=[frm," ",msg]
if(line[2]==NICK):
rec.append((''.join(tmp),255,255,255,255))
else:
rec.append((''.join(tmp),255,255,255,128))
elif(line[0]=="PING"):
raw(s,"PONG %s"%line[1])
elif(line[1]=="353"):
#:leguin.freenode.net 353 doxin[tpt] = #powder :doxin[tpt] ZebraineZ _-_Rafael_-_ doxin bildramer BlueMaxima TheRazorsEDGE raj-k webb|AP where @devast8a Merbo FrozenKnight EppyMoon EvilJStoker Mortvert SpitfireWP @frankbro Ares
names=line[4:]
namelist=[]
for item in names:
item=item.strip()
r=255
g=255
b=255
if(item[0]==":"):
item=item[1:]
elif(item[0]=="@"):
g=0
b=0
namelist.append((item,r,g,b,128))
elif(line[1]=="JOIN"):
#':savask!~savask@95-190-25-195-xdsl-dynamic.kuzbass.net JOIN :#powder'
tmp=line[0][1:].partition("!")[0]
namelist.append((tmp,255,255,255,128))
rec.append(("%s joined"%name,0,255,0,128))
elif(line[1]=="PART"):
#':savask!~savask@95-190-25-195-xdsl-dynamic.kuzbass.net PART #powder :"Leaving."'
tmp=line[0][1:].partition("!")[0]
msg=' '.join(line[2:])[1:]
rem=None
for item in namelist:
if(item[0]==tmp or item[0]=="@"+tmp):
rem=item
rec.append(("%s parted: %s"%(name,msg),0,255,0,128))
if(rem!=None):
namelist.remove(rem)
elif(line[1]=="NICK"):
#:doxin!~lieuwe@unaffiliated/lieuwe NICK :d0x1n
tmp=line[0][1:].partition("!")[0]
rem=None
for item in namelist:
if(item[0]==tmp or item[0]=="@"+tmp):
rem=item
rec.append(("%s is now known as %s"%(name,line[2]),0,255,0,128))
if(rem!=None):
if(rem[0][0]=="@"):
namelist.append(("@"+line[2][1:],rem[1],rem[2],rem[3],rem[4]))
else:
namelist.append((line[2][1:],rem[1],rem[2],rem[3],rem[4]))
namelist.remove(rem)
yy=32
if(len(rec)>20):
rec=rec[-20:]
for item in rec:
tpt.draw_text(8,yy,item[0],item[1],item[2],item[3],item[4])
yy+=8
if(typing):
if(frame%30<15):
tpt.draw_text(8,yy,typed+"|",255,255,255,255)
else:
tpt.draw_text(8,yy,typed,255,255,255,255)
#print namelist
yy=32
for item in namelist:
tpt.draw_text(604-tpt.get_width(item[0]),yy,item[0],item[1],item[2],item[3],item[4])
yy+=8

9
build/ext_fun.py Normal file
View File

@ -0,0 +1,9 @@
import tpt
def init():
pass
def key(keyy):
pass
def step():
tpt.draw_text(100,100,"FUCK YEAH!",255,255,255,255)
def exit():
pass

View File

@ -17,7 +17,7 @@ print args,"-I%s"%path
lst=[]
compileall.compile_dir("./src/python", force=1)
print "\n\n\ngenerating pyconsole.h"
print "generating pyconsole.h"
fname="./src/python/tpt_console.pyc"
try:

View File

@ -67,6 +67,8 @@ extern unsigned char ZSIZE;
#define SQUARE_BRUSH 1
#define BRUSH_NUM 2
#define PYCONSOLE
#ifdef PIX16
typedef unsigned short pixel;
#else

File diff suppressed because one or more lines are too long

View File

@ -23,8 +23,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#include <defines.h>
#ifdef PYCONSOLE
#include "Python.h"
#include "pyconsole.h"
#endif
#include <stdio.h>
#include <stdlib.h>
@ -44,7 +48,6 @@
#include <misc.h>
#include <font.h>
#include <defines.h>
#include <powder.h>
#include <graphics.h>
#include <version.h>
@ -55,6 +58,8 @@
#include <air.h>
#include <icon.h>
pixel *vid_buf;
#define NUM_SOUNDS 2
struct sample {
Uint8 *data;
@ -161,6 +166,7 @@ float mheat = 0.0f;
int do_open = 0;
int sys_pause = 0;
int sys_shortcuts = 1;
int legacy_enable = 0; //Used to disable new features such as heat, will be set by commandline or save.
int death = 0, framerender = 0;
int amd = 1;
@ -1177,6 +1183,7 @@ char my_uri[] = "http://" SERVER "/Update.api?Action=Download&Architecture="
char console_error[255] = "";
#ifdef PYCONSOLE
/*
* PYTHON FUNCTIONS
* instructions on making a function callable from python:
@ -1190,6 +1197,7 @@ char console_error[255] = "";
*/
//functions callable from python:
static PyObject*
emb_create(PyObject *self, PyObject *args, PyObject *keywds)
{
@ -1752,6 +1760,126 @@ emb_get_prop(PyObject *self, PyObject *args)
return Py_BuildValue("i",-1);
}
emb_draw_pixel(PyObject *self, PyObject *args)
{
int x,y,r,g,b,a;
a=255;
if(!PyArg_ParseTuple(args, "IIIII|I:draw_pixel",&x,&y,&r,&g,&b,&a))
return NULL;
if(vid_buf!=NULL)
{
drawpixel(vid_buf,x,y,r,g,b,a);
return Py_BuildValue("i",1);
}
return Py_BuildValue("i",-1);
}
//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)
{
int x,y,r,g,b,a;
char *txt;
a=255;
if(!PyArg_ParseTuple(args, "IIsIII|I:draw_text",&x,&y,&txt,&r,&g,&b,&a))
return NULL;
if(vid_buf!=NULL)
{
drawtext(vid_buf,x,y,txt,r,g,b,a);
return Py_BuildValue("i",1);
}
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)
{
int x,y,w,h,r,g,b,a;
a=255;
if(!PyArg_ParseTuple(args, "IIIIIII|I:draw_rect",&x,&y,&w,&h,&r,&g,&b,&a))
return NULL;
if(vid_buf!=NULL)
{
drawrect(vid_buf,x,y,w,h,r,g,b,a);
//fillrect
return Py_BuildValue("i",1);
}
return Py_BuildValue("i",-1);
}
emb_draw_fillrect(PyObject *self, PyObject *args)
{
int x,y,w,h,r,g,b,a;
a=255;
if(!PyArg_ParseTuple(args, "IIIIIII|I:draw_fillrect",&x,&y,&w,&h,&r,&g,&b,&a))
return NULL;
if(vid_buf!=NULL)
{
fillrect(vid_buf,x,y,w,h,r,g,b,a);
//fillrect
return Py_BuildValue("i",1);
}
return Py_BuildValue("i",-1);
}
//int textwidth(char *s)
emb_get_width(PyObject *self, PyObject *args)
{
char *txt;
if(!PyArg_ParseTuple(args, "s:get_width",&txt))
return NULL;
return Py_BuildValue("i",textwidth(txt));
}
//SDL_GetMouseState(&x, &y)
emb_get_mouse(PyObject *self, PyObject *args)
{
int x,y,mask,b1,b2,b3;
if(!PyArg_ParseTuple(args, ":get_mouse"))
return NULL;
mask=SDL_GetMouseState(&x, &y);
b1=mask&SDL_BUTTON(1);
b2=mask&SDL_BUTTON(2);
b3=mask&SDL_BUTTON(3);
return Py_BuildValue("(ii(iii))",x,y,b1,b2,b3);
}
//svf_name
emb_get_name(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":get_name"))
return NULL;
if(svf_login)
return Py_BuildValue("s",svf_user);
else
return Py_BuildValue("s","");
}
emb_shortcuts_disable(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":shortcuts_disable"))
return NULL;
//
sys_shortcuts=0;
return Py_BuildValue("i",1);
}
emb_shortcuts_enable(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":shortcuts_enable"))
return NULL;
//
sys_shortcuts=1;
return Py_BuildValue("i",1);
}
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 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."},
@ -1769,16 +1897,27 @@ static PyMethodDef EmbMethods[] = { //WARNING! don't forget to register your fun
{"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."},
{"toggle_pause", emb_toggle_pause, METH_VARARGS, "toggle game pause."},
{"open_console", emb_open_console, METH_VARARGS, "open the game console."},
{"close_console", emb_close_console, METH_VARARGS, "close the game console."},
{"toggle_console", emb_toggle_console, METH_VARARGS, "toggle the game console."},
{"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"},
{NULL, NULL, 0, NULL}
};
#endif
int main(int argc, char *argv[])
{
@ -1794,9 +1933,9 @@ int main(int argc, char *argv[])
int FPS = 0;
int pastFPS = 0;
int past = 0;
pixel *vid_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
void *http_ver_check;
void *http_session_check = NULL;
vid_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
char *ver_data=NULL, *check_data=NULL, *tmp;
//char console_error[255] = "";
int i, j, bq, fire_fc=0, do_check=0, do_s_check=0, old_version=0, http_ret=0,http_s_ret=0, major, minor, old_ver_len;
@ -1813,7 +1952,9 @@ 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;
#ifdef PYCONSOLE
PyObject *pname,*pmodule,*pfunc,*pvalue,*pargs,*pstep,*pkey;
#endif
/* Set 16-bit stereo audio at 22Khz */
fmt.freq = 22050;
@ -1823,6 +1964,7 @@ int main(int argc, char *argv[])
fmt.callback = mixaudio;
fmt.userdata = NULL;
#ifdef PYCONSOLE
//initialise python console
Py_Initialize();
Py_InitModule("tpt", EmbMethods);
@ -1840,28 +1982,45 @@ 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?
PyErr_Print();
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(pstep))//check if it's really a function
{
printf("step function found.\n");
}
else
{
printf("unable to find console module, missing file?\n");
printf("unable to find step function. ignoring.\n");
}
pkey=PyObject_GetAttrString(pmodule,"keypress");//get the handler function
if(pstep && PyCallable_Check(pkey))//check if it's really a function
{
printf("key function found.\n");
}
else
{
printf("unable to find key function. ignoring.\n");
}
}
else
{
//sys.stderr
PyErr_Print();
printf("unable to find console module, missing file or mangled console.py?\n");
return -1;
}
#else
printf("python console disabled at compile time.");
#endif
#ifdef MT
numCores = core_count();
@ -2127,6 +2286,8 @@ int main(int argc, char *argv[])
do_s_check = (do_s_check+1) & 15;
}
if(sys_shortcuts==1)
{
if (sdl_key=='q' || sdl_key==SDLK_ESCAPE)
{
if (confirm_ui(vid_buf, "You are about to quit", "Are you sure you want to quit?", "Quit"))
@ -2483,6 +2644,21 @@ int main(int argc, char *argv[])
emap[cby][cbx] = cb_emap[cby][cbx];
}
}
}
#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;
}
#endif
#ifdef INTERNAL
int counterthing;
if (sdl_key=='v'&&!(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)))
@ -2766,7 +2942,7 @@ int main(int argc, char *argv[])
if (!sdl_zoom_trig && zoom_en==1)
zoom_en = 0;
if (sdl_key=='z' && zoom_en==2)
if (sdl_key=='z' && zoom_en==2 && sys_shortcuts==1)
zoom_en = 1;
if (load_mode)
@ -3381,6 +3557,7 @@ int main(int argc, char *argv[])
if(console_mode)
{
#ifdef PYCONSOLE
char *console;
//char error[255] = "error!";
sys_pause = 1;
@ -3395,8 +3572,26 @@ int main(int argc, char *argv[])
free(console);
if(!console_mode)
hud_enable = 1;
#else
console_mode=0;
#endif
}
//execute python step hook
#ifdef PYCONSOLE
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
@ -3414,19 +3609,13 @@ int main(int argc, char *argv[])
else
player2[2] = PT_DUST;
}
}
SDL_CloseAudio();
http_done();
//make sure no threads are blocking us
//fork_unblock
pargs=Py_BuildValue("(s)","fork_unblock()");//this deamonises all threads.
pvalue = PyObject_CallObject(pfunc, pargs);
Py_DECREF(pargs);
pargs=NULL;
Py_Finalize();//cleanup any python stuff.
return 0;
}
#ifdef PYCONSOLE
int process_command(pixel *vid_buf,char *console,char *console_error,PyObject *pfunc) {
int y,x,nx,ny,i,j,k,m;
int do_next = 1;
@ -3462,4 +3651,4 @@ int process_command(pixel *vid_buf,char *console,char *console_error,PyObject *p
}
return 1;
}
#endif

View File

@ -1,10 +1,11 @@
import tpt
from tpt import *
from utils import *
import sys
import code
import ctypes
import traceback
DEBUG=False
#print "console module loaded."
#redirect stdout like this:
class logger:
@ -12,8 +13,10 @@ class logger:
txt=txt.strip().split("\n")[-1]
repr(txt)
tpt.log(txt)
sys.stdout=logger()
sys.stderr=logger()
if(DEBUG==False):
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,
@ -43,6 +46,7 @@ element={"none":0,"dust":1,"watr":2,"oil":3,"fire":4,"stne":5,"lava":6,"gunp":7,
def fork_unblock():
pass#i need to implement this some day.
def error(ex):
traceback.print_exc()
err=traceback.format_exc()
sys.stdout.write(err)
@ -75,3 +79,38 @@ def _handle(txt):
exec txt in handle.glob
except Exception as ex:
error(ex)
_extensions=[]
def loadext(fname):
ext=__import__(fname)
ext.init()
_extensions.append(ext)
def keypress(key):
unload=[]
for item in _extensions:
try:
item.key(key)
except Exception as ex:
error(ex)
unload.append(item)
for item in unload:
item.exit()
_extensions.remove(item)
def step():
unload=[]
for item in _extensions:
try:
item.step()
except Exception as ex:
error(ex)
unload.append(item)
for item in unload:
try:
item.exit()
except Exception as ex:
error(ex)
_extensions.remove(item)