Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

SCA_PythonController.h

Go to the documentation of this file.
00001 
00006 
00007 #ifndef KX_PYTHONCONTROLLER_H
00008 #define KX_PYTHONCONTROLLER_H
00009               
00010 #include "SCA_IController.h"
00011 #include "SCA_LogicManager.h"
00012 #include "BoolValue.h"
00013 
00014 class SCA_IObject;
00015 class SCA_PythonController : public SCA_IController
00016 {
00017         Py_Header;
00018         struct _object *                m_bytecode;
00019         bool                                    m_bModified;
00020 
00021  protected:
00022         CCString                                m_scriptText;
00023         CCString                                m_scriptName;
00024         PyObject*                               m_pythondictionary;
00025 
00026  public: 
00027         static SCA_PythonController* m_sCurrentController; // protected !!!
00028 
00029         SCA_PythonController(SCA_IObject* gameobj,PyTypeObject* T = &Type);
00030         virtual ~SCA_PythonController();
00031 
00032         virtual CValue* GetReplica() {
00033                 CValue* replica = new SCA_PythonController(*this);
00034                 // this will copy properties and so on...
00035                 CValue::AddDataToReplica(replica);
00036                 return replica;
00037         };
00038         virtual void  Trigger(class SCA_LogicManager* logicmgr);
00039   
00040         void                    SetScriptText(const CCString& text) { 
00041                 m_scriptText = text;
00042                 m_bModified = true;
00043         };
00044         void                    SetScriptName(const CCString& name) {
00045                 m_scriptName = name;
00046         }
00047         void                    SetDictionary(PyObject* pythondictionary)

00048                 {
00049                         m_pythondictionary = pythondictionary;
00050                 }
00051 
00052         // actuator
00053         PyObject* PyGetActuators(PyObject* self, PyObject* args, PyObject* kwds);
00054         static char* sPyGetActuators__doc__;
00055         static PyObject* sPyGetActuators(PyObject* self, 
00056                                                                          PyObject* args, 
00057                                                                          PyObject* kwds)

00058                 {
00059                         return ((SCA_PythonController*) self)->PyGetActuators(self, args, kwds);
00060                 }
00061         // sensor
00062         PyObject* PyGetSensors(PyObject* self, PyObject* args, PyObject* kwds);
00063         static char* sPyGetSensors__doc__;
00064         static PyObject* sPyGetSensors(PyObject* self, 
00065                                                                    PyObject* args, 
00066                                                                    PyObject* kwds)

00067                 {
00068                         return ((SCA_PythonController*) self)->PyGetSensors(self, args, kwds);
00069                 }
00070         static char* sPyGetCurrentController__doc__;
00071         static PyObject* sPyGetCurrentController(PyObject* self, 
00072                                                                                          PyObject* args, 
00073                                                                                          PyObject* kwds)

00074                 {
00075                         m_sCurrentController->AddRef();
00076                         return m_sCurrentController;
00077                 }
00078 
00079         static char* sPyAddActiveActuator__doc__;
00080         
00081   
00082         static PyObject* sPyAddActiveActuator(
00083           
00084                 PyObject* self, 
00085                 PyObject* args, 
00086                 PyObject* kwds)

00087                 {
00088 
00089                         PyObject* ob1;
00090                         int boolval;
00091                         if (!PyArg_ParseTuple(args, "Oi", &ob1,&boolval))
00092                         {
00093                                 return NULL;
00094 
00095                         }
00096                         // for safety, todo: only allow for registered actuators (pointertable)
00097                         // we don't want to crash gameengine/blender by python scripts
00098 
00099                         CValue* ac = (CValue*)ob1;
00100           
00101                         m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)ac,new CBoolValue(boolval!=0));
00102                         Py_INCREF(Py_None);
00103                         return Py_None;
00104                 }
00105 
00106         virtual PyObject*  _getattr(char *attr);
00107 
00108         KX_PYMETHOD_DOC(SCA_PythonController,GetSensor);
00109         KX_PYMETHOD(SCA_PythonController,SetScript);
00110         KX_PYMETHOD(SCA_PythonController,GetScript);
00111         
00112 
00113 };
00114 
00115 #endif //KX_PYTHONCONTROLLER_H

Generated at Thu Feb 1 13:03:11 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000