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