Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #ifndef KX_PYTHONCONTROLLER_H 00034 #define KX_PYTHONCONTROLLER_H 00035 00036 #include "SCA_IController.h" 00037 #include "SCA_LogicManager.h" 00038 #include "BoolValue.h" 00039 00040 #include <vector> 00041 00042 class SCA_IObject; 00043 class SCA_PythonController : public SCA_IController 00044 { 00045 Py_Header 00046 #ifdef WITH_PYTHON 00047 struct _object * m_bytecode; /* SCA_PYEXEC_SCRIPT only */ 00048 PyObject* m_function; /* SCA_PYEXEC_MODULE only */ 00049 #endif 00050 int m_function_argc; 00051 bool m_bModified; 00052 bool m_debug; /* use with SCA_PYEXEC_MODULE for reloading every logic run */ 00053 int m_mode; 00054 00055 00056 protected: 00057 STR_String m_scriptText; 00058 STR_String m_scriptName; 00059 #ifdef WITH_PYTHON 00060 PyObject* m_pythondictionary; /* for SCA_PYEXEC_SCRIPT only */ 00061 PyObject* m_pythonfunction; /* for SCA_PYEXEC_MODULE only */ 00062 #endif 00063 std::vector<class SCA_ISensor*> m_triggeredSensors; 00064 00065 public: 00066 enum SCA_PyExecMode 00067 { 00068 SCA_PYEXEC_SCRIPT = 0, 00069 SCA_PYEXEC_MODULE, 00070 SCA_PYEXEC_MAX 00071 }; 00072 00073 static SCA_PythonController* m_sCurrentController; // protected !!! 00074 00075 //for debugging 00076 //virtual CValue* AddRef(); 00077 //virtual int Release(); // Release a reference to this value (when reference count reaches 0, the value is removed from the heap) 00078 00079 SCA_PythonController(SCA_IObject* gameobj, int mode); 00080 virtual ~SCA_PythonController(); 00081 00082 virtual CValue* GetReplica(); 00083 virtual void Trigger(class SCA_LogicManager* logicmgr); 00084 00085 void SetScriptText(const STR_String& text); 00086 void SetScriptName(const STR_String& name); 00087 #ifdef WITH_PYTHON 00088 void SetNamespace(PyObject* pythondictionary); 00089 #endif 00090 void SetDebug(bool debug) { m_debug = debug; } 00091 void AddTriggeredSensor(class SCA_ISensor* sensor) 00092 { m_triggeredSensors.push_back(sensor); } 00093 int IsTriggered(class SCA_ISensor* sensor); 00094 bool Compile(); 00095 bool Import(); 00096 void ErrorPrint(const char *error_msg); 00097 00098 #ifdef WITH_PYTHON 00099 static const char* sPyGetCurrentController__doc__; 00100 static PyObject* sPyGetCurrentController(PyObject* self); 00101 static const char* sPyAddActiveActuator__doc__; 00102 static PyObject* sPyAddActiveActuator(PyObject* self, 00103 PyObject* args); 00104 static SCA_IActuator* LinkedActuatorFromPy(PyObject *value); 00105 00106 00107 KX_PYMETHOD_O(SCA_PythonController,Activate); 00108 KX_PYMETHOD_O(SCA_PythonController,DeActivate); 00109 KX_PYMETHOD_O(SCA_PythonController,SetScript); 00110 KX_PYMETHOD_NOARGS(SCA_PythonController,GetScript); 00111 00112 00113 static PyObject* pyattr_get_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00114 static int pyattr_set_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); 00115 #endif 00116 }; 00117 00118 #endif //KX_PYTHONCONTROLLER_H 00119