2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
* Execute Python scripts
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KX_PYTHONCONTROLLER_H
|
|
|
|
#define KX_PYTHONCONTROLLER_H
|
|
|
|
|
|
|
|
#include "SCA_IController.h"
|
|
|
|
#include "SCA_LogicManager.h"
|
|
|
|
#include "BoolValue.h"
|
|
|
|
|
2008-08-23 11:54:27 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
class SCA_IObject;
|
|
|
|
class SCA_PythonController : public SCA_IController
|
|
|
|
{
|
|
|
|
Py_Header;
|
2009-09-29 21:42:40 +00:00
|
|
|
#ifndef DISABLE_PYTHON
|
2009-06-08 20:08:19 +00:00
|
|
|
struct _object * m_bytecode; /* SCA_PYEXEC_SCRIPT only */
|
|
|
|
PyObject* m_function; /* SCA_PYEXEC_MODULE only */
|
2009-09-29 21:42:40 +00:00
|
|
|
#endif
|
2009-06-08 20:08:19 +00:00
|
|
|
int m_function_argc;
|
2002-10-12 11:37:38 +00:00
|
|
|
bool m_bModified;
|
2009-06-08 20:08:19 +00:00
|
|
|
bool m_debug; /* use with SCA_PYEXEC_MODULE for reloading every logic run */
|
|
|
|
int m_mode;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-06-08 20:08:19 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
protected:
|
|
|
|
STR_String m_scriptText;
|
|
|
|
STR_String m_scriptName;
|
2009-09-29 21:42:40 +00:00
|
|
|
#ifndef DISABLE_PYTHON
|
2009-06-08 20:08:19 +00:00
|
|
|
PyObject* m_pythondictionary; /* for SCA_PYEXEC_SCRIPT only */
|
|
|
|
PyObject* m_pythonfunction; /* for SCA_PYEXEC_MODULE only */
|
2009-09-29 21:42:40 +00:00
|
|
|
#endif
|
2008-08-23 11:54:27 +00:00
|
|
|
std::vector<class SCA_ISensor*> m_triggeredSensors;
|
2009-06-08 20:08:19 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum SCA_PyExecMode
|
|
|
|
{
|
|
|
|
SCA_PYEXEC_SCRIPT = 0,
|
|
|
|
SCA_PYEXEC_MODULE,
|
|
|
|
SCA_PYEXEC_MAX
|
|
|
|
};
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
static SCA_PythonController* m_sCurrentController; // protected !!!
|
|
|
|
|
2006-05-14 03:39:07 +00:00
|
|
|
//for debugging
|
|
|
|
//virtual CValue* AddRef();
|
|
|
|
//virtual int Release(); // Release a reference to this value (when reference count reaches 0, the value is removed from the heap)
|
|
|
|
|
2009-06-28 11:22:26 +00:00
|
|
|
SCA_PythonController(SCA_IObject* gameobj, int mode);
|
2002-10-12 11:37:38 +00:00
|
|
|
virtual ~SCA_PythonController();
|
|
|
|
|
|
|
|
virtual CValue* GetReplica();
|
|
|
|
virtual void Trigger(class SCA_LogicManager* logicmgr);
|
|
|
|
|
|
|
|
void SetScriptText(const STR_String& text);
|
|
|
|
void SetScriptName(const STR_String& name);
|
2009-09-29 21:42:40 +00:00
|
|
|
#ifndef DISABLE_PYTHON
|
2009-09-29 22:49:33 +00:00
|
|
|
void SetNamespace(PyObject* pythondictionary);
|
2009-09-29 21:42:40 +00:00
|
|
|
#endif
|
2009-06-08 20:08:19 +00:00
|
|
|
void SetDebug(bool debug) { m_debug = debug; }
|
2008-08-23 11:54:27 +00:00
|
|
|
void AddTriggeredSensor(class SCA_ISensor* sensor)
|
|
|
|
{ m_triggeredSensors.push_back(sensor); }
|
|
|
|
int IsTriggered(class SCA_ISensor* sensor);
|
2009-02-24 03:29:31 +00:00
|
|
|
bool Compile();
|
2009-06-08 20:08:19 +00:00
|
|
|
bool Import();
|
|
|
|
void ErrorPrint(const char *error_msg);
|
|
|
|
|
2009-09-29 21:42:40 +00:00
|
|
|
#ifndef DISABLE_PYTHON
|
2008-09-20 11:08:35 +00:00
|
|
|
static const char* sPyGetCurrentController__doc__;
|
2008-07-04 00:05:50 +00:00
|
|
|
static PyObject* sPyGetCurrentController(PyObject* self);
|
2008-09-20 11:08:35 +00:00
|
|
|
static const char* sPyAddActiveActuator__doc__;
|
2002-10-12 11:37:38 +00:00
|
|
|
static PyObject* sPyAddActiveActuator(PyObject* self,
|
2008-07-04 00:05:50 +00:00
|
|
|
PyObject* args);
|
2009-02-24 05:50:45 +00:00
|
|
|
static SCA_IActuator* LinkedActuatorFromPy(PyObject *value);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-02-24 05:50:45 +00:00
|
|
|
|
|
|
|
KX_PYMETHOD_O(SCA_PythonController,Activate);
|
|
|
|
KX_PYMETHOD_O(SCA_PythonController,DeActivate);
|
2008-07-04 00:05:50 +00:00
|
|
|
KX_PYMETHOD_O(SCA_PythonController,SetScript);
|
|
|
|
KX_PYMETHOD_NOARGS(SCA_PythonController,GetScript);
|
2009-06-08 20:08:19 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
static PyObject* pyattr_get_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
|
|
|
|
static int pyattr_set_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
|
2009-09-29 21:42:40 +00:00
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //KX_PYTHONCONTROLLER_H
|
|
|
|
|