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.
This commit is contained in:
@@ -36,6 +36,8 @@
|
||||
#include "SCA_LogicManager.h"
|
||||
#include "BoolValue.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class SCA_IObject;
|
||||
class SCA_PythonController : public SCA_IController
|
||||
{
|
||||
@@ -47,6 +49,7 @@ class SCA_PythonController : public SCA_IController
|
||||
STR_String m_scriptText;
|
||||
STR_String m_scriptName;
|
||||
PyObject* m_pythondictionary;
|
||||
std::vector<class SCA_ISensor*> m_triggeredSensors;
|
||||
|
||||
public:
|
||||
static SCA_PythonController* m_sCurrentController; // protected !!!
|
||||
@@ -64,6 +67,9 @@ class SCA_PythonController : public SCA_IController
|
||||
void SetScriptText(const STR_String& text);
|
||||
void SetScriptName(const STR_String& name);
|
||||
void SetDictionary(PyObject* pythondictionary);
|
||||
void AddTriggeredSensor(class SCA_ISensor* sensor)
|
||||
{ m_triggeredSensors.push_back(sensor); }
|
||||
int IsTriggered(class SCA_ISensor* sensor);
|
||||
|
||||
static char* sPyGetCurrentController__doc__;
|
||||
static PyObject* sPyGetCurrentController(PyObject* self);
|
||||
|
||||
Reference in New Issue
Block a user