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 | |
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
27 files changed, 142 insertions, 12 deletions
diff --git a/doc/python_api/rst/bge.logic.rst b/doc/python_api/rst/bge.logic.rst index 0ddae476e08..b37806437a9 100644 --- a/doc/python_api/rst/bge.logic.rst +++ b/doc/python_api/rst/bge.logic.rst @@ -507,6 +507,18 @@ Property Sensor :value: 5 +.. data:: KX_PROPSENSOR_LESSTHAN + + Activate when the property is less than the sensor value + + :value: 6 + +.. data:: KX_PROPSENSOR_GREATERTHAN + + Activate when the property is greater than the sensor value + + :value: 7 + ------------ Radar Sensor ------------ diff --git a/source/blender/editors/space_logic/logic_window.c b/source/blender/editors/space_logic/logic_window.c index 4b533292a95..7f0fadc07ef 100644 --- a/source/blender/editors/space_logic/logic_window.c +++ b/source/blender/editors/space_logic/logic_window.c @@ -1182,9 +1182,9 @@ static void draw_sensor_property(uiLayout *layout, PointerRNA *ptr) uiItemR(row, ptr, "value_max", 0, NULL, ICON_NONE); break; case SENS_PROP_EQUAL: - uiItemR(layout, ptr, "value", 0, NULL, ICON_NONE); - break; case SENS_PROP_NEQUAL: + case SENS_PROP_LESSTHAN: + case SENS_PROP_GREATERTHAN: uiItemR(layout, ptr, "value", 0, NULL, ICON_NONE); break; case SENS_PROP_CHANGED: diff --git a/source/blender/makesdna/DNA_sensor_types.h b/source/blender/makesdna/DNA_sensor_types.h index fcdbbe31541..cd1977c0ce3 100644 --- a/source/blender/makesdna/DNA_sensor_types.h +++ b/source/blender/makesdna/DNA_sensor_types.h @@ -202,6 +202,8 @@ typedef struct bJoystickSensor { #define SENS_PROP_INTERVAL 2 #define SENS_PROP_CHANGED 3 #define SENS_PROP_EXPRESSION 4 +#define SENS_PROP_LESSTHAN 5 +#define SENS_PROP_GREATERTHAN 6 /* raysensor->axisflag */ /* flip x and y to make y default!!! */ diff --git a/source/blender/makesrna/intern/rna_sensor.c b/source/blender/makesrna/intern/rna_sensor.c index f5e59119baa..aeef04f4ac7 100644 --- a/source/blender/makesrna/intern/rna_sensor.c +++ b/source/blender/makesrna/intern/rna_sensor.c @@ -478,6 +478,8 @@ static void rna_def_property_sensor(BlenderRNA *brna) {SENS_PROP_INTERVAL, "PROPINTERVAL", 0, "Interval", ""}, {SENS_PROP_CHANGED, "PROPCHANGED", 0, "Changed", ""}, /* {SENS_PROP_EXPRESSION, "PROPEXPRESSION", 0, "Expression", ""}, NOT_USED_IN_UI */ + {SENS_PROP_LESSTHAN, "PROPLESSTHAN", 0, "Less Than", ""}, + {SENS_PROP_GREATERTHAN, "PROPGREATERTHAN", 0, "Greater Than", ""}, {0, NULL, 0, NULL, NULL} }; @@ -498,7 +500,7 @@ static void rna_def_property_sensor(BlenderRNA *brna) prop = RNA_def_property(srna, "value", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "value"); - RNA_def_property_ui_text(prop, "Value", "Check for this value in types in Equal or Not Equal types"); + RNA_def_property_ui_text(prop, "Value", "Check for this value in types in Equal, Not Equal, Less Than and Greater Than types"); RNA_def_property_update(prop, NC_LOGIC, NULL); prop = RNA_def_property(srna, "value_min", PROP_STRING, PROP_NONE); diff --git a/source/gameengine/Converter/KX_ConvertSensors.cpp b/source/gameengine/Converter/KX_ConvertSensors.cpp index b3c6f6ddd24..93a5ee11366 100644 --- a/source/gameengine/Converter/KX_ConvertSensors.cpp +++ b/source/gameengine/Converter/KX_ConvertSensors.cpp @@ -377,6 +377,12 @@ void BL_ConvertSensors(struct Object* blenderobject, propchecktype = SCA_PropertySensor::KX_PROPSENSOR_EXPRESSION; /* error */ break; + case SENS_PROP_LESSTHAN: + propchecktype = SCA_PropertySensor::KX_PROPSENSOR_LESSTHAN; + break; + case SENS_PROP_GREATERTHAN: + propchecktype = SCA_PropertySensor::KX_PROPSENSOR_GREATERTHAN; + break; default: ; /* error */ } diff --git a/source/gameengine/Expressions/BoolValue.cpp b/source/gameengine/Expressions/BoolValue.cpp index ee913877c96..9ff53395056 100644 --- a/source/gameengine/Expressions/BoolValue.cpp +++ b/source/gameengine/Expressions/BoolValue.cpp @@ -186,6 +186,13 @@ double CBoolValue::GetNumber() +int CBoolValue::GetValueType() +{ + return VALUE_BOOL_TYPE; +} + + + const STR_String& CBoolValue::GetText() { return m_bool ? sTrueString : sFalseString; diff --git a/source/gameengine/Expressions/BoolValue.h b/source/gameengine/Expressions/BoolValue.h index b88c839a58e..161d6112f68 100644 --- a/source/gameengine/Expressions/BoolValue.h +++ b/source/gameengine/Expressions/BoolValue.h @@ -41,6 +41,7 @@ public: virtual const STR_String& GetText(); virtual double GetNumber(); + virtual int GetValueType(); bool GetBool(); virtual void SetValue(CValue* newval); diff --git a/source/gameengine/Expressions/EmptyValue.cpp b/source/gameengine/Expressions/EmptyValue.cpp index 7f3af9f649d..f8e72181ed7 100644 --- a/source/gameengine/Expressions/EmptyValue.cpp +++ b/source/gameengine/Expressions/EmptyValue.cpp @@ -82,6 +82,13 @@ double CEmptyValue::GetNumber() +int CEmptyValue::GetValueType() +{ + return VALUE_EMPTY_TYPE; +} + + + CListValue* CEmptyValue::GetPolySoup() { CListValue* soup = new CListValue(); diff --git a/source/gameengine/Expressions/EmptyValue.h b/source/gameengine/Expressions/EmptyValue.h index 8eccb97e0f5..88ef206f0f0 100644 --- a/source/gameengine/Expressions/EmptyValue.h +++ b/source/gameengine/Expressions/EmptyValue.h @@ -32,6 +32,7 @@ public: virtual const STR_String & GetText(); virtual double GetNumber(); + virtual int GetValueType(); CListValue* GetPolySoup(); virtual double* GetVector3(bool bGetTransformedVec=false); bool IsInside(CValue* testpoint,bool bBorderInclude=true); diff --git a/source/gameengine/Expressions/ErrorValue.cpp b/source/gameengine/Expressions/ErrorValue.cpp index ba9c52be6c7..46e09b9073f 100644 --- a/source/gameengine/Expressions/ErrorValue.cpp +++ b/source/gameengine/Expressions/ErrorValue.cpp @@ -107,6 +107,13 @@ double CErrorValue::GetNumber() +int CErrorValue::GetValueType() +{ + return VALUE_ERROR_TYPE; +} + + + const STR_String & CErrorValue::GetText() { return m_strErrorText; diff --git a/source/gameengine/Expressions/ErrorValue.h b/source/gameengine/Expressions/ErrorValue.h index 0095528254e..61c72151f40 100644 --- a/source/gameengine/Expressions/ErrorValue.h +++ b/source/gameengine/Expressions/ErrorValue.h @@ -27,6 +27,7 @@ class CErrorValue : public CPropValue public: virtual const STR_String & GetText(); virtual double GetNumber(); + virtual int GetValueType(); CErrorValue(); CErrorValue(const char *errmsg); virtual ~CErrorValue(); diff --git a/source/gameengine/Expressions/FloatValue.cpp b/source/gameengine/Expressions/FloatValue.cpp index 0f468e328ed..4d6f3f467eb 100644 --- a/source/gameengine/Expressions/FloatValue.cpp +++ b/source/gameengine/Expressions/FloatValue.cpp @@ -285,6 +285,13 @@ double CFloatValue::GetNumber() +int CFloatValue::GetValueType() +{ + return VALUE_FLOAT_TYPE; +} + + + void CFloatValue::SetValue(CValue* newval) { m_float = (float)newval->GetNumber(); diff --git a/source/gameengine/Expressions/FloatValue.h b/source/gameengine/Expressions/FloatValue.h index bc6a2d052d4..379c3e951bc 100644 --- a/source/gameengine/Expressions/FloatValue.h +++ b/source/gameengine/Expressions/FloatValue.h @@ -33,6 +33,7 @@ public: void Configure(CValue* menuvalue); virtual double GetNumber(); + virtual int GetValueType(); virtual void SetValue(CValue* newval); float GetFloat(); void SetFloat(float fl); diff --git a/source/gameengine/Expressions/IntValue.cpp b/source/gameengine/Expressions/IntValue.cpp index fa4c9ad8ac9..5cb8a1ca296 100644 --- a/source/gameengine/Expressions/IntValue.cpp +++ b/source/gameengine/Expressions/IntValue.cpp @@ -298,6 +298,13 @@ double CIntValue::GetNumber() +int CIntValue::GetValueType() +{ + return VALUE_INT_TYPE; +} + + + const STR_String & CIntValue::GetText() { if (!m_pstrRep) diff --git a/source/gameengine/Expressions/IntValue.h b/source/gameengine/Expressions/IntValue.h index 8411b09693c..6da975f4f7f 100644 --- a/source/gameengine/Expressions/IntValue.h +++ b/source/gameengine/Expressions/IntValue.h @@ -31,6 +31,7 @@ class CIntValue : public CPropValue public: virtual const STR_String& GetText(); virtual double GetNumber(); + virtual int GetValueType(); cInt GetInt(); CIntValue(); diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 1f12a9b78e1..75e3b490505 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -250,6 +250,13 @@ double CListValue::GetNumber() +int CListValue::GetValueType() +{ + return VALUE_LIST_TYPE; +} + + + void CListValue::SetModified(bool bModified) { CValue::SetModified(bModified); diff --git a/source/gameengine/Expressions/ListValue.h b/source/gameengine/Expressions/ListValue.h index 5240c54ae4e..bb188179836 100644 --- a/source/gameengine/Expressions/ListValue.h +++ b/source/gameengine/Expressions/ListValue.h @@ -40,6 +40,7 @@ public: VALUE_OPERATOR op, CValue* val); virtual double GetNumber(); + virtual int GetValueType(); virtual CValue* GetReplica(); public: diff --git a/source/gameengine/Expressions/StringValue.cpp b/source/gameengine/Expressions/StringValue.cpp index 166125bc906..098949c9d7b 100644 --- a/source/gameengine/Expressions/StringValue.cpp +++ b/source/gameengine/Expressions/StringValue.cpp @@ -120,6 +120,13 @@ double CStringValue::GetNumber() +int CStringValue::GetValueType() +{ + return VALUE_STRING_TYPE; +} + + + const STR_String & CStringValue::GetText() { return m_strString; diff --git a/source/gameengine/Expressions/StringValue.h b/source/gameengine/Expressions/StringValue.h index 22d433455ec..cb60600ad88 100644 --- a/source/gameengine/Expressions/StringValue.h +++ b/source/gameengine/Expressions/StringValue.h @@ -36,6 +36,7 @@ public: virtual bool IsEqual(const STR_String & other); virtual const STR_String & GetText(); virtual double GetNumber(); + virtual int GetValueType(); virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index e5c4001de4c..1ced71e66a4 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -494,6 +494,15 @@ void CValue::ProcessReplica() /* was AddDataToReplica in 2.48 */ } } + + +int CValue::GetValueType() +{ + return VALUE_NO_TYPE; +} + + + CValue* CValue::FindIdentifier(const STR_String& identifiername) { diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h index db7d69a638f..7f6ce9aa703 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/Value.h @@ -82,11 +82,9 @@ enum VALUE_DATA_TYPE { VALUE_BOOL_TYPE, VALUE_ERROR_TYPE, VALUE_EMPTY_TYPE, - VALUE_SOLID_TYPE, - VALUE_COMBISOLID_TYPE, + VALUE_LIST_TYPE, + VALUE_VOID_TYPE, VALUE_VECTOR_TYPE, - VALUE_MENU_TYPE, - VALUE_ACTOR_TYPE, VALUE_MAX_TYPE //only here to provide number of types }; @@ -311,6 +309,7 @@ public: virtual const STR_String & GetText() = 0; virtual double GetNumber() = 0; + virtual int GetValueType(); // Get Prop value type double* ZeroVector() { return m_sZeroVec; } virtual double* GetVector3(bool bGetTransformedVec = false); @@ -323,7 +322,6 @@ public: virtual void ProcessReplica(); //virtual CValue* Copy() = 0; - STR_String op2str(VALUE_OPERATOR op); // setting / getting flags diff --git a/source/gameengine/Expressions/VectorValue.cpp b/source/gameengine/Expressions/VectorValue.cpp index a0e1b616d5e..6931ba2aa76 100644 --- a/source/gameengine/Expressions/VectorValue.cpp +++ b/source/gameengine/Expressions/VectorValue.cpp @@ -162,6 +162,14 @@ double CVectorValue::GetNumber() } + +int CVectorValue::GetValueType() +{ + return VALUE_VECTOR_TYPE; +} + + + double* CVectorValue::GetVector3(bool bGetTransformedVec) { if (bGetTransformedVec) diff --git a/source/gameengine/Expressions/VectorValue.h b/source/gameengine/Expressions/VectorValue.h index 69f2d4b54ae..717fa68f6dc 100644 --- a/source/gameengine/Expressions/VectorValue.h +++ b/source/gameengine/Expressions/VectorValue.h @@ -37,6 +37,7 @@ public: void Configure(CValue* menuvalue); virtual double* GetVector3(bool bGetTransformedVec=false); virtual double GetNumber(); + virtual int GetValueType(); CValue* Calc(VALUE_OPERATOR op, CValue *val) { return val->CalcFinal(VALUE_VECTOR_TYPE, op, this); diff --git a/source/gameengine/Expressions/VoidValue.h b/source/gameengine/Expressions/VoidValue.h index 832f75c9c9f..4f74910dd8a 100644 --- a/source/gameengine/Expressions/VoidValue.h +++ b/source/gameengine/Expressions/VoidValue.h @@ -59,6 +59,7 @@ public: /// Value -> String or number virtual const STR_String & GetText(); /* Get string description of void value (unimplemented) */ virtual double GetNumber() { return -1; } + virtual int GetValueType() { return VALUE_VOID_TYPE; } /// Value calculation virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); 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 */ } diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.h b/source/gameengine/GameLogic/SCA_PropertySensor.h index fee03dcf4c0..f9cfb5fb1d2 100644 --- a/source/gameengine/GameLogic/SCA_PropertySensor.h +++ b/source/gameengine/GameLogic/SCA_PropertySensor.h @@ -57,6 +57,8 @@ public: KX_PROPSENSOR_INTERVAL, KX_PROPSENSOR_CHANGED, KX_PROPSENSOR_EXPRESSION, + KX_PROPSENSOR_LESSTHAN, + KX_PROPSENSOR_GREATERTHAN, KX_PROPSENSOR_MAX }; diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 234d03ab618..913851bcc3f 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1538,6 +1538,8 @@ PyObject *initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_INTERVAL, SCA_PropertySensor::KX_PROPSENSOR_INTERVAL); KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_CHANGED, SCA_PropertySensor::KX_PROPSENSOR_CHANGED); KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_EXPRESSION, SCA_PropertySensor::KX_PROPSENSOR_EXPRESSION); + KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_LESSTHAN, SCA_PropertySensor::KX_PROPSENSOR_LESSTHAN); + KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_GREATERTHAN, SCA_PropertySensor::KX_PROPSENSOR_GREATERTHAN); /* 3. Constraint actuator */ KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX); |