From bc8f002a4c68235db766fbd72bc383feb7836341 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sat, 23 Aug 2008 11:54:27 +0000 Subject: BGE state system improvement: the sensor with Level option enabled will trigger the controller of a newly activated state, even if the sensor is already connected to an active state; new isTriggered() python function to determine which sensor triggered the current controller. Previously, this behaviour was available only for sensors that were not connected to any active state, which was forcing the game designer to duplicate sensors in some cases. For example the Always sensors used to initialize the states needed to be duplicated for each state. With this patch, a single Always sensor with Level option enabled will suffice to initialize all the states. A Python controller can determine which sensor did trigger with the new SCA_ISensor::isTriggered() function. Notes: - When a sensor with level option enabled is connected to multiple controllers, only those of newly activated states will be triggered. The controllers of already activated states will receive no trigger, unless the sensor internal state toggled, in which case all the controllers are triggered as always. - The old isPositive() function returns the internal state of the sensor, positive or negative; the new isTriggered() function returns 1 only for sensors that generated an event in the current frame. --- source/gameengine/GameLogic/SCA_PythonController.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source/gameengine/GameLogic/SCA_PythonController.cpp') diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index f9081c90288..e6f7b1dd143 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -35,6 +35,7 @@ #include "SCA_IActuator.h" #include "compile.h" #include "eval.h" +#include #ifdef HAVE_CONFIG_H #include @@ -139,6 +140,14 @@ void SCA_PythonController::SetDictionary(PyObject* pythondictionary) m_pythondictionary = PyDict_Copy(pythondictionary); /* new reference */ } +int SCA_PythonController::IsTriggered(class SCA_ISensor* sensor) +{ + if (std::find(m_triggeredSensors.begin(), m_triggeredSensors.end(), sensor) != + m_triggeredSensors.end()) + return 1; + return 0; +} + #if 0 static char* sPyGetCurrentController__doc__; #endif @@ -294,7 +303,7 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) // something in this dictionary and crash? PyDict_Clear(excdict); Py_DECREF(excdict); - + m_triggeredSensors.erase(m_triggeredSensors.begin(), m_triggeredSensors.end()); m_sCurrentController = NULL; } -- cgit v1.2.3