Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-04-29 16:43:09 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-29 16:43:09 +0400
commitf8656d35101317a2b4a00eaf33f6d91d2d28dd7a (patch)
tree8819e7f5919144b1fb514901c08dfc45e2967079 /source/gameengine/GameLogic/SCA_PythonController.h
parent988fbb88dc621d8f41d1b07a729ae5afc24efdaa (diff)
BGE alternative run mode for python controllers.
Option to run a function in a module rather then a script from a python controller, this has a number of advantages. - No allocating and freeing the namespace dictionary for every time its triggered (hard to measure the overhead here, but in a test with calling 42240 scripts a second each defining 200 vars, using modules was ~25% faster) - Ability to use external python scripts for game logic. - Convenient debug option that lets you edit scripts while the game engine runs.
Diffstat (limited to 'source/gameengine/GameLogic/SCA_PythonController.h')
-rw-r--r--source/gameengine/GameLogic/SCA_PythonController.h26
1 files changed, 21 insertions, 5 deletions
diff --git a/source/gameengine/GameLogic/SCA_PythonController.h b/source/gameengine/GameLogic/SCA_PythonController.h
index f10c4e47ebb..12307632b06 100644
--- a/source/gameengine/GameLogic/SCA_PythonController.h
+++ b/source/gameengine/GameLogic/SCA_PythonController.h
@@ -42,23 +42,35 @@ class SCA_IObject;
class SCA_PythonController : public SCA_IController
{
Py_Header;
- struct _object * m_bytecode;
+ struct _object * m_bytecode; /* SCA_PYEXEC_SCRIPT only */
+ PyObject* m_function; /* SCA_PYEXEC_MODULE only */
bool m_bModified;
-
+ bool m_debug; /* use with SCA_PYEXEC_MODULE for reloading every logic run */
+ int m_mode;
+
protected:
STR_String m_scriptText;
STR_String m_scriptName;
- PyObject* m_pythondictionary;
+ PyObject* m_pythondictionary; /* for SCA_PYEXEC_SCRIPT only */
+ PyObject* m_pythonfunction; /* for SCA_PYEXEC_MODULE only */
+
std::vector<class SCA_ISensor*> m_triggeredSensors;
+
+ public:
+ enum SCA_PyExecMode
+ {
+ SCA_PYEXEC_SCRIPT = 0,
+ SCA_PYEXEC_MODULE,
+ SCA_PYEXEC_MAX
+ };
- public:
static SCA_PythonController* m_sCurrentController; // protected !!!
//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)
- SCA_PythonController(SCA_IObject* gameobj,PyTypeObject* T = &Type);
+ SCA_PythonController(SCA_IObject* gameobj, int mode, PyTypeObject* T = &Type);
virtual ~SCA_PythonController();
virtual CValue* GetReplica();
@@ -67,10 +79,14 @@ class SCA_PythonController : public SCA_IController
void SetScriptText(const STR_String& text);
void SetScriptName(const STR_String& name);
void SetDictionary(PyObject* pythondictionary);
+ void SetDebug(bool debug) { m_debug = debug; }
void AddTriggeredSensor(class SCA_ISensor* sensor)
{ m_triggeredSensors.push_back(sensor); }
int IsTriggered(class SCA_ISensor* sensor);
bool Compile();
+ bool Import();
+ void ErrorPrint(const char *error_msg);
+
static const char* sPyGetCurrentController__doc__;
static PyObject* sPyGetCurrentController(PyObject* self);