BGE Py API
[blender.git] / source / gameengine / GameLogic / SCA_PythonController.h
1 /**
2  * Execute Python scripts
3  *
4  * $Id$
5  *
6  * ***** BEGIN GPL LICENSE BLOCK *****
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL LICENSE BLOCK *****
30  */
31
32 #ifndef KX_PYTHONCONTROLLER_H
33 #define KX_PYTHONCONTROLLER_H
34               
35 #include "SCA_IController.h"
36 #include "SCA_LogicManager.h"
37 #include "BoolValue.h"
38
39 #include <vector>
40
41 class SCA_IObject;
42 class SCA_PythonController : public SCA_IController
43 {
44         Py_Header;
45         struct _object *                m_bytecode;
46         bool                                    m_bModified;
47
48  protected:
49         STR_String                              m_scriptText;
50         STR_String                              m_scriptName;
51         PyObject*                               m_pythondictionary;
52         std::vector<class SCA_ISensor*>         m_triggeredSensors;
53
54  public: 
55         static SCA_PythonController* m_sCurrentController; // protected !!!
56
57         //for debugging
58         //virtual       CValue*         AddRef();
59         //virtual int                   Release();                                                                                              // Release a reference to this value (when reference count reaches 0, the value is removed from the heap)
60
61         SCA_PythonController(SCA_IObject* gameobj,PyTypeObject* T = &Type);
62         virtual ~SCA_PythonController();
63
64         virtual CValue* GetReplica();
65         virtual void  Trigger(class SCA_LogicManager* logicmgr);
66   
67         void    SetScriptText(const STR_String& text);
68         void    SetScriptName(const STR_String& name);
69         void    SetDictionary(PyObject* pythondictionary);
70         void    AddTriggeredSensor(class SCA_ISensor* sensor)
71                 { m_triggeredSensors.push_back(sensor); }
72         int             IsTriggered(class SCA_ISensor* sensor);
73         bool    Compile();
74
75         static const char* sPyGetCurrentController__doc__;
76         static PyObject* sPyGetCurrentController(PyObject* self);
77         static const char* sPyAddActiveActuator__doc__;
78         static PyObject* sPyAddActiveActuator(PyObject* self, 
79                                                                                   PyObject* args);
80         static SCA_IActuator* LinkedActuatorFromPy(PyObject *value);
81         virtual PyObject* _getattr(const char *attr);
82         virtual int _setattr(const char *attr, PyObject *value);
83
84                 
85         KX_PYMETHOD_O(SCA_PythonController,Activate);
86         KX_PYMETHOD_O(SCA_PythonController,DeActivate);
87         KX_PYMETHOD_DOC_NOARGS(SCA_PythonController,GetSensors);
88         KX_PYMETHOD_DOC_NOARGS(SCA_PythonController,GetActuators);
89         KX_PYMETHOD_DOC_O(SCA_PythonController,GetSensor);
90         KX_PYMETHOD_DOC_O(SCA_PythonController,GetActuator);
91         KX_PYMETHOD_O(SCA_PythonController,SetScript);
92         KX_PYMETHOD_NOARGS(SCA_PythonController,GetScript);
93         KX_PYMETHOD_NOARGS(SCA_PythonController,GetState);
94         
95
96 };
97
98 #endif //KX_PYTHONCONTROLLER_H
99