Here is C++ interface code with Cyphesis:
In this model Python module observe.py does most work of connecting to Cyphesis, parsing events and interpreting them.
Makefile (probably not hardcoded like here ;-):
CXXFLAGS: -I/usr/include/python1.5 LDFLAGS: -export-dynamic LDLIBS: /usr/lib/python1.5/config/libpython1.5.aInterface source code in C++:
#include <Python.h> //create new object (NPC, house or (axe:ignore it) currently) static PyObject *cmake_event(PyObject *self, PyObject *args) { char *id,*name,*obj_type; double x,y,z; if (!PyArg_ParseTuple(args, "sssddd", &id,&name,&obj_type,&x,&y,&z)) return NULL; //here code to add object to database by id and display it return Py_None; } //destroy object static PyObject *cdestroy_event(PyObject *self, PyObject *args) { char *id; if (!PyArg_ParseTuple(args, "s", &id)) return NULL; //remove it from display at least return Py_None; } //move object static PyObject *cmove_event(PyObject *self, PyObject *args) { char *id; double x,y,z; if (!PyArg_ParseTuple(args, "sddd", &id,&x,&y,&z)) return NULL; //move it: maybe use several iterations to avoid jumping //effect with current timestep (1800s) return Py_None; } //display what certain NPC is thinking now static PyObject *cgoal_event(PyObject *self, PyObject *args) { char *id,*goal; if (!PyArg_ParseTuple(args, "ss", &id,&goal)) return NULL; //display it's though return Py_None; } //fire somewhere static PyObject *cfire_event(PyObject *self, PyObject *args) { char *target_id; double x,y,z; if (!PyArg_ParseTuple(args, "sddd", &target_id,&x,&y,&z)) return NULL; //display fire (x,y,z are optional: they are same as target_id:s xyz) return Py_None; } static PyMethodDef PC_MindMethods[] = { {"cmake_event", cmake_event, METH_VARARGS}, {"cdestroy_event", cdestroy_event, METH_VARARGS}, {"cmove_event", cmove_event, METH_VARARGS}, {"cgoal_event", cgoal_event, METH_VARARGS}, {"cfire_event", cfire_event, METH_VARARGS}, {NULL, NULL} /* Sentinel */ }; void initpc_mind() { (void) Py_InitModule("pc_mind", PC_MindMethods); }Initialization:
/* Initialize the Python interpreter. */ Py_Initialize(); // initialize Cyphesis PyRun_SimpleString("from observe import observe\n"); initIsoObserver(); PyRun_SimpleString("import pc_mind\n"); //Use remote CORBA //PyRun_SimpleString("obs=observe(1,ccode=pc_mind)\n"); //Use local CORBA PyRun_SimpleString("obs=observe(0,ccode=pc_mind)\n");To run one time step:
//Display events as text (runs one time tic) //PyRun_SimpleString("obs.text(1)\n"); //Display text graphics (runs one time tic) PyRun_SimpleString("obs.dsp(1)\n");