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:
authorBenoit Bolsee <benoit.bolsee@online.be>2008-06-24 00:26:48 +0400
committerBenoit Bolsee <benoit.bolsee@online.be>2008-06-24 00:26:48 +0400
commit67c0b32375c9c2f9838cf110975d7fce9d783daa (patch)
tree15ab22166395d90765f6f43ce4bfbc7f0c2c472f /source/gameengine/GameLogic/SCA_ISensor.cpp
parent8b9503e0ecb9c1f524278df0fafda409425b21da (diff)
BGE patch: Add level option on sensor and fix sensor reset.
Level option is now available on all sensors but is only implemented on mouse and keyboard sensors. The purpose of that option is to make the sensor react on level rather than edge by default. It's only applicable to state engine system when there is a state transition: the sensor will generate a pulse if the condition is met from the start of the state. Normally, the keyboard sensor generate a pulse only when the key is pressed and not when the key is already pressed. This patch allows to select this behavior. The second part of the patch corrects the reset method for sensors with inverted output.
Diffstat (limited to 'source/gameengine/GameLogic/SCA_ISensor.cpp')
-rw-r--r--source/gameengine/GameLogic/SCA_ISensor.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp
index 1c29eb27be5..6cfae9d8919 100644
--- a/source/gameengine/GameLogic/SCA_ISensor.cpp
+++ b/source/gameengine/GameLogic/SCA_ISensor.cpp
@@ -55,6 +55,7 @@ SCA_ISensor::SCA_ISensor(SCA_IObject* gameobj,
m_links = 0;
m_suspended = false;
m_invert = false;
+ m_level = false;
m_pos_ticks = 0;
m_neg_ticks = 0;
m_pos_pulsemode = false;
@@ -95,6 +96,10 @@ void SCA_ISensor::SetInvert(bool inv) {
m_invert = inv;
}
+void SCA_ISensor::SetLevel(bool lvl) {
+ m_level = lvl;
+}
+
float SCA_ISensor::GetNumber() {
return IsPositiveTrigger();
@@ -177,6 +182,10 @@ PyMethodDef SCA_ISensor::Methods[] = {
METH_VARARGS, GetInvert_doc},
{"setInvert", (PyCFunction) SCA_ISensor::sPySetInvert,
METH_VARARGS, SetInvert_doc},
+ {"getLevel", (PyCFunction) SCA_ISensor::sPyGetLevel,
+ METH_VARARGS, GetLevel_doc},
+ {"setLevel", (PyCFunction) SCA_ISensor::sPySetLevel,
+ METH_VARARGS, SetLevel_doc},
{NULL,NULL} //Sentinel
};
@@ -328,6 +337,31 @@ PyObject* SCA_ISensor::PySetInvert(PyObject* self, PyObject* args, PyObject* kwd
Py_Return;
}
+char SCA_ISensor::GetLevel_doc[] =
+"getLevel()\n"
+"\tReturns whether this sensor is a level detector or a edge detector.\n"
+"\tIt makes a difference only in case of logic state transition (state actuator).\n"
+"\tA level detector will immediately generate a pulse if the condition for the\n"
+"\tdetector is met when entering the state. A edge detector will wait for an off-on\n"
+"\ttransition to occur.\n"
+"\tOnly some sensors implement this feature: keyboard.\n";
+PyObject* SCA_ISensor::PyGetLevel(PyObject* self, PyObject* args, PyObject* kwds)
+{
+ return BoolToPyArg(m_level);
+}
+
+char SCA_ISensor::SetLevel_doc[] =
+"setLevel(level?)\n"
+"\t- level?: Detect level instead of edge? (KX_TRUE, KX_FALSE)\n"
+"\tSet whether to detect level or edge transition when entering a state.\n";
+PyObject* SCA_ISensor::PySetLevel(PyObject* self, PyObject* args, PyObject* kwds)
+{
+ int pyarg = 0;
+ if(!PyArg_ParseTuple(args, "i", &pyarg)) { return NULL; }
+ m_level = PyArgToBool(pyarg);
+ Py_Return;
+}
+
char SCA_ISensor::GetUseNegPulseMode_doc[] =
"getUseNegPulseMode()\n"
"\tReturns whether negative pulse mode is active.\n";