[Gcblue-commits] gcb_wx/src/scriptinterface tcPythonInterface.cpp,1.8,1.9 tcSimPythonInterface.cpp,1
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-06-25 22:10:47
|
Update of /cvsroot/gcblue/gcb_wx/src/scriptinterface In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21991/src/scriptinterface Modified Files: tcPythonInterface.cpp tcSimPythonInterface.cpp Log Message: Fixed bug with crashing when too many range circles were displayed Index: tcSimPythonInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/scriptinterface/tcSimPythonInterface.cpp,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** tcSimPythonInterface.cpp 11 Jun 2005 21:01:45 -0000 1.34 --- tcSimPythonInterface.cpp 25 Jun 2005 22:10:36 -0000 1.35 *************** *** 24,30 **** #ifndef WX_PRECOMP #include "wx/wx.h" - #ifdef WIN32 - #include "wx/msw/private.h" // for MS Windows specific definitions - #endif // WIN32 #endif // WX_PRECOMP --- 24,27 ---- *************** *** 39,46 **** --- 36,47 ---- #include "tcSoundConsole.h" #include "tcDirector.h" + #include "tcMessageInterface.h" + #include "tcTime.h" + #include "ai/ScriptedTask.h" #include "ai/ScriptedTaskInterface.h" #include "common/tcStream.h" #include "common/tcObjStream.h" + #include "common/tcOptions.h" #ifdef _DEBUG *************** *** 953,957 **** } ! void tcSimPythonInterface::Test() { try { --- 954,959 ---- } ! void tcSimPythonInterface::Test() ! { try { *************** *** 968,971 **** --- 970,1042 ---- } + void tcSimPythonInterface::Update() + { + static unsigned int lastUpdate = 0; + + // limit update frequency + unsigned int t = tcTime::Get()->Get30HzCount(); + if (t - lastUpdate < 15) return; + lastUpdate = t; + + UpdateLogs(); + } + + + /** + * Update output and error text logs + * If showPythonErrors is true, then send errors to "Python" message channel in game + */ + void tcSimPythonInterface::UpdateLogs() + { + wxString errorText; + + try + { + handle<>( PyRun_String( + "outfile = file('log\\pyout.txt', 'a')\n" + "errfile = file('log\\pyerr.txt', 'a')\n" + "outfile.write(myout.getvalue())\n" + "ErrorText = myerr.getvalue()\n" + "errfile.write(ErrorText)\n" + "outfile.close()\n" + "errfile.close()\n" + "myout.truncate(0)\n" + "myerr.truncate(0)\n" + , Py_file_input, mpDictionary->ptr(), mpDictionary->ptr()) ); + + if (showPythonErrors) + { + handle<> errorTextHandle(borrowed(PyDict_GetItemString(mpDictionary->ptr(), "ErrorText"))); + str textObject(errorTextHandle); + + errorText = extract<const char*>(textObject); + } + } + catch(error_already_set) + { + fprintf(stderr,"Exception occured during SendTextToConsole\n"); + PyErr_Print(); + } + catch(...) + { + fprintf(stderr,"Unknown exception occured during SendTextToConsole\n"); + PyErr_Print(); + } + + if (errorText.size() > 0) + { + tcMessageInterface::Get()->ChannelMessage("Python", ""); + while (errorText.size() > 0) + { + wxString line = errorText.BeforeFirst('\n'); + errorText = errorText.AfterFirst('\n'); + + tcMessageInterface::Get()->ChannelMessage("Python", line.c_str()); + } + } + + + } + tcSimPythonInterface::tcSimPythonInterface() : *************** *** 974,978 **** mpHookedObj(0), overlay(0), ! isModePushed(false) { mpSimState = tcSimState::Get(); --- 1045,1050 ---- mpHookedObj(0), overlay(0), ! isModePushed(false), ! showPythonErrors(false) { mpSimState = tcSimState::Get(); *************** *** 1076,1079 **** --- 1148,1166 ---- try { + handle<>( PyRun_String("import sys\n" + "import StringIO\n" + "myout = StringIO.StringIO()\n" + "myerr = StringIO.StringIO()\n" + "sys.stdout = myout\n" + "sys.stderr = myerr\n" + "outfile = file('log\\pyout.txt', 'w')\n" + "errfile = file('log\\pyerr.txt', 'w')\n" + //"outfile.write("")\n" + //"errfile.write("")\n" + "outfile.close()\n" + "errfile.close()\n" + , Py_file_input, mpDictionary->ptr(), mpDictionary->ptr()) ); + + handle<>( PyRun_String("import AI\n" , Py_file_input, mpDictionary->ptr(), mpDictionary->ptr()) ); *************** *** 1090,1093 **** --- 1177,1185 ---- } + if (tcOptions::Get()->OptionStringExists("ShowPythonErrors")) + { + showPythonErrors = true; + } + } *************** *** 1096,1099 **** --- 1188,1200 ---- tcSimPythonInterface::~tcSimPythonInterface() { + /*** print standard error to file ***/ + handle<>( PyRun_String( + "outfile = file('log\\pyout.txt', 'a')\n" + "errfile = file('log\\pyerr.txt', 'a')\n" + "outfile.write(myout.getvalue())\n" + "errfile.write(myerr.getvalue())\n" + "outfile.close()\n" + "errfile.close()\n" + , Py_file_input, mpDictionary->ptr(), mpDictionary->ptr()) ); } Index: tcPythonInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/scriptinterface/tcPythonInterface.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** tcPythonInterface.cpp 1 Jun 2005 00:13:32 -0000 1.8 --- tcPythonInterface.cpp 25 Jun 2005 22:10:36 -0000 1.9 *************** *** 174,177 **** --- 174,178 ---- /*** redirect standard error ***/ + /* PyRun_SimpleString( "import StringIO\n" *************** *** 182,185 **** --- 183,187 ---- "sys.stderr = myerr\n" ); + */ /* create fresh dictionary */ *************** *** 189,206 **** } ! tcPythonInterface::~tcPythonInterface(void) { ! ! /*** print standard error to file ***/ ! PyRun_SimpleString( ! "outfile = file('log\\pyout.txt', 'w')\n" ! "errfile = file('log\\pyerr.txt', 'w')\n" ! "outfile.write(myout.getvalue())\n" ! "errfile.write(myerr.getvalue())\n" ! "outfile.close()\n" ! "errfile.close()\n" ! ); ! ! if (mpDictionary != NULL) {delete mpDictionary;} ! Py_Finalize(); } --- 191,208 ---- } ! tcPythonInterface::~tcPythonInterface() { ! /*** print standard error to file ***/ ! /* ! PyRun_SimpleString( ! "outfile = file('log\\pyout.txt', 'w')\n" ! "errfile = file('log\\pyerr.txt', 'w')\n" ! "outfile.write(myout.getvalue())\n" ! "errfile.write(myerr.getvalue())\n" ! "outfile.close()\n" ! "errfile.close()\n" ! ); ! */ ! if (mpDictionary != NULL) {delete mpDictionary;} ! Py_Finalize(); } |