BGE: New Property sensor evaluation types
authorJorge Bernal <jbernalmartinez@gmail.com>
Tue, 3 Jun 2014 20:20:59 +0000 (13:20 -0700)
committerMitchell Stokes <mogurijin@gmail.com>
Mon, 16 Jun 2014 21:56:36 +0000 (14:56 -0700)
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:
doc/python_api/rst/bge.logic.rst
source/blender/editors/space_logic/logic_window.c
source/blender/makesdna/DNA_sensor_types.h
source/blender/makesrna/intern/rna_sensor.c
source/gameengine/Converter/KX_ConvertSensors.cpp
source/gameengine/Expressions/BoolValue.cpp
source/gameengine/Expressions/BoolValue.h
source/gameengine/Expressions/EmptyValue.cpp
source/gameengine/Expressions/EmptyValue.h
source/gameengine/Expressions/ErrorValue.cpp
source/gameengine/Expressions/ErrorValue.h
source/gameengine/Expressions/FloatValue.cpp
source/gameengine/Expressions/FloatValue.h
source/gameengine/Expressions/IntValue.cpp
source/gameengine/Expressions/IntValue.h
source/gameengine/Expressions/ListValue.cpp
source/gameengine/Expressions/ListValue.h
source/gameengine/Expressions/StringValue.cpp
source/gameengine/Expressions/StringValue.h
source/gameengine/Expressions/Value.cpp
source/gameengine/Expressions/Value.h
source/gameengine/Expressions/VectorValue.cpp
source/gameengine/Expressions/VectorValue.h
source/gameengine/Expressions/VoidValue.h
source/gameengine/GameLogic/SCA_PropertySensor.cpp
source/gameengine/GameLogic/SCA_PropertySensor.h
source/gameengine/Ketsji/KX_PythonInit.cpp

index 0ddae476e086b6941409b049c28626a61fd5e35f..b37806437a92629f6d8a5dc768fc6dc6bfa8febc 100644 (file)
@@ -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
 ------------
index 4b533292a952f2fcc7063759bc2eb9c478e91e02..7f0fadc07ef782f526a9f0c5dc2d074cbb168cd2 100644 (file)
@@ -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:
index fcdbbe3154154587f030021e238f74b645986dcb..cd1977c0ce3b2b5d5ae19cb9bd34e65ad5bcfcec 100644 (file)
@@ -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!!! */
index f5e59119baab97325eaca2d3b31f13e71cb1ab6f..aeef04f4ac76546604ed879f9c02d46676a73ce9 100644 (file)
@@ -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);
index b3c6f6ddd24a7a8d2028942edb39fef7bd9c0a0a..93a5ee11366ae20be17b3c3998d846d582ee944b 100644 (file)
@@ -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 */
                                        }
index ee913877c9661133320409cd69a42729353f9d6e..9ff53395056e3b2a6629a140d067d90672e2bcfb 100644 (file)
@@ -186,6 +186,13 @@ double CBoolValue::GetNumber()
 
 
 
+int CBoolValue::GetValueType()
+{
+       return VALUE_BOOL_TYPE;
+}
+
+
+
 const STR_String& CBoolValue::GetText()
 {
        return m_bool ? sTrueString : sFalseString;
index b88c839a58e50125aeddf1f6d0650613c2f4b45f..161d6112f684cdc94ce2325919b9f31c33aac8e9 100644 (file)
@@ -41,6 +41,7 @@ public:
 
        virtual const STR_String& GetText();
        virtual double          GetNumber();
+       virtual int                     GetValueType();
        bool                            GetBool();
        virtual void            SetValue(CValue* newval);
        
index 7f3af9f649d62e46085d3dbbd7529cac278cd811..f8e72181ed723a87ee104854311204c85fac5794 100644 (file)
@@ -82,6 +82,13 @@ double CEmptyValue::GetNumber()
 
 
 
+int CEmptyValue::GetValueType()
+{
+       return VALUE_EMPTY_TYPE;
+}
+
+
+
 CListValue* CEmptyValue::GetPolySoup()
 {
        CListValue* soup = new CListValue();
index 8eccb97e0f5a85b17d07349bbe10ecdc2b4a2c36..88ef206f0f0b007a5135ee37e4e804fca2905d67 100644 (file)
@@ -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);
index ba9c52be6c7d6790a37b73aea57bd825ff724beb..46e09b9073f2b04e44d91d3b589fb9d0c6c8a6bd 100644 (file)
@@ -107,6 +107,13 @@ double CErrorValue::GetNumber()
 
 
 
+int CErrorValue::GetValueType()
+{
+       return VALUE_ERROR_TYPE;
+}
+
+
+
 const STR_String & CErrorValue::GetText()
 {
        return m_strErrorText;
index 0095528254e3fd2e3cad1100eca19b417821399c..61c72151f40fef50b595100a253baa917223dfa7 100644 (file)
@@ -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();
index 0f468e328edc4d5a191465943b16e71993444fa1..4d6f3f467eb382f33665b52776bf2f6b256d0496 100644 (file)
@@ -285,6 +285,13 @@ double CFloatValue::GetNumber()
 
 
 
+int CFloatValue::GetValueType()
+{
+       return VALUE_FLOAT_TYPE;
+}
+
+
+
 void CFloatValue::SetValue(CValue* newval)
 {      
        m_float = (float)newval->GetNumber(); 
index bc6a2d052d43c7eee1a0316cf46b0f93feda7790..379c3e951bc14c0b07c63b5090176a6c822034bd 100644 (file)
@@ -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);
index fa4c9ad8ac991e759639ab616707052ef9db1b88..5cb8a1ca296b654c8ee9a37120dfa215422f8fc9 100644 (file)
@@ -298,6 +298,13 @@ double CIntValue::GetNumber()
 
 
 
+int CIntValue::GetValueType()
+{
+       return VALUE_INT_TYPE;
+}
+
+
+
 const STR_String & CIntValue::GetText()
 {
        if (!m_pstrRep)
index 8411b09693c10bf9e7098a0ba4f33e2097a5d95f..6da975f4f7faccca8ab68485696322f821ac4e6e 100644 (file)
@@ -31,6 +31,7 @@ class CIntValue : public CPropValue
 public:
        virtual const STR_String& GetText();
        virtual double                  GetNumber();
+       virtual int                             GetValueType();
        
        cInt GetInt();
        CIntValue();
index 1f12a9b78e1e607fae6f5a556edaa9432bb8ac66..75e3b4905051d8eff415b5a7cfba691fabebd17f 100644 (file)
@@ -250,6 +250,13 @@ double CListValue::GetNumber()
 
 
 
+int CListValue::GetValueType()
+{
+       return VALUE_LIST_TYPE;
+}
+
+
+
 void CListValue::SetModified(bool bModified)
 {
        CValue::SetModified(bModified);
index 5240c54ae4ef8c9ef1459c378570b5c2c056102e..bb188179836d62de07aa412179c1f7daa1dee298 100644 (file)
@@ -40,6 +40,7 @@ public:
                                                          VALUE_OPERATOR op,
                                                          CValue* val);
        virtual double GetNumber();
+       virtual int GetValueType();
        virtual CValue* GetReplica();
 
 public:
index 166125bc906342d0171470408e46ef323f89db59..098949c9d7b8a05c115d297f4aa8cb34103f7f55 100644 (file)
@@ -120,6 +120,13 @@ double CStringValue::GetNumber()
 
 
 
+int CStringValue::GetValueType()
+{
+       return VALUE_STRING_TYPE;
+}
+
+
+
 const STR_String & CStringValue::GetText()
 {
        return m_strString;
index 22d433455ecad2fa7bc00b03290ca83fb6dacb38..cb60600ad88cb1d34c921f9ecac4324cb705c60c 100644 (file)
@@ -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);
index e5c4001de4c6777b92522a3661208961b4b67f39..1ced71e66a4a24e4f398752b9c86acbd44ffb164 100644 (file)
@@ -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)
 {
 
index db7d69a638f12e68830b9514b3cba43ece0b0678..7f6ce9aa7034ad27316cb05ecc4c14bb3fd06321 100644 (file)
@@ -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
index a0e1b616d5eaae37c6629d22eff512b9cd6892bc..6931ba2aa76497322da68e04a948c03b429c264f 100644 (file)
@@ -162,6 +162,14 @@ double CVectorValue::GetNumber()
 }
 
 
+
+int CVectorValue::GetValueType()
+{
+       return VALUE_VECTOR_TYPE;
+}
+
+
+
 double* CVectorValue::GetVector3(bool bGetTransformedVec)
 {
        if (bGetTransformedVec)
index 69f2d4b54ae10c07a41ae8eeab7156734b758d78..717fa68f6dc92dab43f8f61452e1dae5d0085c9d 100644 (file)
@@ -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);
index 832f75c9c9fc55f5883254f30cc066058fca93ca..4f74910dd8a88eef50d675be1f7433d6d03d3874 100644 (file)
@@ -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);
index ad57e529297adb4aa7caeda5e4ac9badac1411ce..6f34f8710c17e19e1f9080f4ea481a117ba19f9d 100644 (file)
@@ -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);
@@ -226,6 +227,36 @@ bool       SCA_PropertySensor::CheckPropertyCondition()
                        orgprop->Release();
 
                        //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:
index fee03dcf4c0be1ac121482666e8cb8acaeffe42a..f9cfb5fb1d29b95f36baeec7f9486dfe36931956 100644 (file)
@@ -57,6 +57,8 @@ public:
                KX_PROPSENSOR_INTERVAL,
                KX_PROPSENSOR_CHANGED,
                KX_PROPSENSOR_EXPRESSION,
+               KX_PROPSENSOR_LESSTHAN,
+               KX_PROPSENSOR_GREATERTHAN,
                KX_PROPSENSOR_MAX
        };
 
index 234d03ab618e95175f330a4572f7b9543be006d7..913851bcc3fa2ec854b9b2fc677eaa5ef047e685 100644 (file)
@@ -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);