diff options
author | Jorge Bernal <jbernalmartinez@gmail.com> | 2014-06-04 00:20:59 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2014-06-17 01:56:36 +0400 |
commit | 8c16f4c7d0b334b70ec3b01ac1d81d280e9759b1 (patch) | |
tree | 018f4298470e095746eb24f9365a98d35c51ce5a /source/gameengine/GameLogic/SCA_PropertySensor.cpp | |
parent | 3144ae2c341e06307e4ecab83e9c7bed7a061d37 (diff) |
BGE: New Property sensor evaluation types
This patch adds "Less Than" and "Greater Than" evaluation types to the property sensor.
The Wiki Docs modifications http://wiki.blender.org/index.php/User:Lordloki/Doc:2.6/Manual/Game_Engine/Logic/Sensors/Property
Also, I have attached a screenshot and a blend to check.
Reviewers: dfelinto, moguri
Reviewed By: moguri
Differential Revision: https://developer.blender.org/D476
Diffstat (limited to 'source/gameengine/GameLogic/SCA_PropertySensor.cpp')
-rw-r--r-- | source/gameengine/GameLogic/SCA_PropertySensor.cpp | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp index ad57e529297..6f34f8710c1 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp +++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp @@ -133,6 +133,7 @@ bool SCA_PropertySensor::CheckPropertyCondition() { case KX_PROPSENSOR_NOTEQUAL: reverse = true; + /* fall-through */ case KX_PROPSENSOR_EQUAL: { CValue* orgprop = GetParent()->FindIdentifier(m_checkpropname); @@ -150,7 +151,7 @@ bool SCA_PropertySensor::CheckPropertyCondition() /* Patch: floating point values cant use strings usefully since you can have "0.0" == "0.0000" * this could be made into a generic Value class function for comparing values with a string. */ - if (result==false && dynamic_cast<CFloatValue *>(orgprop) != NULL) { + if (result==false && (orgprop->GetValueType() == VALUE_FLOAT_TYPE)) { float f; if (sscanf(m_checkpropval.ReadPtr(), "%f", &f) == 1) { result = (f == ((CFloatValue *)orgprop)->GetFloat()); @@ -198,11 +199,11 @@ bool SCA_PropertySensor::CheckPropertyCondition() const float max = m_checkpropmaxval.ToFloat(); float val; - if (dynamic_cast<CStringValue *>(orgprop) == NULL) { - val = orgprop->GetNumber(); + if (orgprop->GetValueType() == VALUE_STRING_TYPE){ + val = orgprop->GetText().ToFloat(); } else { - val = orgprop->GetText().ToFloat(); + val = orgprop->GetNumber(); } result = (min <= val) && (val <= max); @@ -228,6 +229,36 @@ bool SCA_PropertySensor::CheckPropertyCondition() //cout << " \nSens:Prop:changed!"; /* need implementation here!!! */ break; } + case KX_PROPSENSOR_LESSTHAN: + reverse = true; + /* fall-through */ + case KX_PROPSENSOR_GREATERTHAN: + { + CValue* orgprop = GetParent()->FindIdentifier(m_checkpropname); + if (!orgprop->IsError()) + { + const float ref = m_checkpropval.ToFloat(); + float val; + + if (orgprop->GetValueType() == VALUE_STRING_TYPE){ + val = orgprop->GetText().ToFloat(); + } + else { + val = orgprop->GetNumber(); + } + + if (reverse) { + result = val < ref; + } + else { + result = val > ref; + } + + } + orgprop->Release(); + + break; + } default: ; /* error */ } |