Update of /cvsroot/fftrader/fftrader/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5247/src
Modified Files:
engine.cpp engine.h py_baselib.cpp py_baselib.h
Removed Files:
py_load.cpp py_load.h
Log Message:
Update to Python Engine, still no scripting
Index: engine.cpp
===================================================================
RCS file: /cvsroot/fftrader/fftrader/src/engine.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** engine.cpp 19 Aug 2005 22:39:52 -0000 1.1
--- engine.cpp 21 Aug 2005 11:29:49 -0000 1.2
***************
*** 1,4 ****
--- 1,11 ----
#include "engine.h"
+ extern PyMethodDef fftMethods[];
+ extern PyMethodDef catchMethods[];
+
+ PyObject* module;
+ PyObject* catchmodule;
+ PyObject* objectiveModule;
+
Engine::Engine()
{
***************
*** 14,18 ****
starfields.clear();
Py_Initialize();
! LoadPythonLibraries();
}
Engine::~Engine()
--- 21,50 ----
starfields.clear();
Py_Initialize();
! Log::Write("Loading FFTrader Python Library");
! PyImport_AddModule("fft");
! module = Py_InitModule3("fft", fftMethods, "fft standard module.\n");
!
! PyImport_AddModule("catch");
! catchmodule = Py_InitModule3("catch", catchMethods, "catch sysout and syserr.\n");
!
! PyRun_SimpleString("import sys; sys.path.insert(0, '.')");
!
! PyObject* sysModule = PyImport_ImportModule("sys");
! PyObject_SetAttrString(sysModule, "stdout", catchmodule);
! PyObject_SetAttrString(sysModule, "stderr", catchmodule);
!
! PyRun_SimpleString(
! "import fft\n"
! "def MyFunc():\n"
! "\treturn 1\n"
! "fft.Victory=MyFunc\n"
! );
! PyObject *pDict = PyModule_GetDict(module); //get the dict of the module (listing of all symbols in there),
! PyObject *pFunc = PyDict_GetItemString(pDict, "Victory");
! Log::Write("ok so far");
! PyObject *test=PyObject_CallFunction(pFunc, 0);
! if(PyObject_IsTrue(test)) Log::Write("method is true");
! else Log::Write("method is false");
! Log::Write("got through!");
}
Engine::~Engine()
***************
*** 46,49 ****
--- 78,84 ----
Mix_CloseAudio();
+ Py_XDECREF(module);
+ Py_XDECREF(catchmodule);
+ Py_XDECREF(objectiveModule);
Py_Finalize();
PHYSFS_deinit();
--- py_load.h DELETED ---
Index: py_baselib.h
===================================================================
RCS file: /cvsroot/fftrader/fftrader/src/py_baselib.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** py_baselib.h 19 Aug 2005 22:39:52 -0000 1.1
--- py_baselib.h 21 Aug 2005 11:29:49 -0000 1.2
***************
*** 6,9 ****
--- 6,11 ----
PyObject* fft_log(PyObject* self, PyObject* args);
+ PyObject* fft_victory(PyObject* self);
+ PyObject* fft_loss(PyObject* self);
PyObject* fft_exit(PyObject* self, PyObject* args);
Index: engine.h
===================================================================
RCS file: /cvsroot/fftrader/fftrader/src/engine.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** engine.h 19 Aug 2005 22:39:52 -0000 1.1
--- engine.h 21 Aug 2005 11:29:49 -0000 1.2
***************
*** 4,12 ****
#include <deque>
#include <string>
#include "SDL_mixer.h"
#include "SDL_ttf.h"
#include "gui.h"
#include "log.h"
- #include "py_load.h"
#include "scenario.h"
#include "units.h"
--- 4,12 ----
#include <deque>
#include <string>
+ #include "Python.h"
#include "SDL_mixer.h"
#include "SDL_ttf.h"
#include "gui.h"
#include "log.h"
#include "scenario.h"
#include "units.h"
--- py_load.cpp DELETED ---
Index: py_baselib.cpp
===================================================================
RCS file: /cvsroot/fftrader/fftrader/src/py_baselib.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** py_baselib.cpp 19 Aug 2005 22:39:52 -0000 1.1
--- py_baselib.cpp 21 Aug 2005 11:29:49 -0000 1.2
***************
*** 7,10 ****
--- 7,12 ----
{
{"Exit", fft_exit, METH_VARARGS, "Exit(message)\nExits the current game displaying \"message\", then returns to the main menu\n"},
+ {"Victory", (PyCFunction)fft_victory, METH_NOARGS, "Victory()\nFunction which exists for the sole purpose of determining when victory conditions are met. To make this work, you have to create your own victory function (returning a non zero number on loss, and a 0 otherwise) and set fft.Victory equal to it. The function must have no arguments to work properly. This function will have no effect when called from the script.\n"},
+ {"Loss", (PyCFunction)fft_loss, METH_NOARGS, "Loss()\nFunction which exists for the sole purpose of determining when losing conditions are met. To make this work, you have to create your own loss function (returning a non zero number on loss, and a 0 otherwise) and set fft.Loss equal to it. The function must have no arguments to work properly. This function will have no effect when called from the script.\n"},
{0}
};
***************
*** 26,29 ****
--- 28,39 ----
return Py_None;
}
+ PyObject* fft_victory(PyObject* self)
+ {
+ return Py_BuildValue("i", 0);
+ }
+ PyObject* fft_loss(PyObject* self)
+ {
+ return Py_BuildValue("i", 0);
+ }
PyObject* fft_exit(PyObject* self, PyObject* args)
{
|