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:
authorJorge Bernal <jbernalmartinez@gmail.com>2014-06-04 00:20:59 +0400
committerMitchell Stokes <mogurijin@gmail.com>2014-06-17 01:56:36 +0400
commit8c16f4c7d0b334b70ec3b01ac1d81d280e9759b1 (patch)
tree018f4298470e095746eb24f9365a98d35c51ce5a /source/gameengine
parent3144ae2c341e06307e4ecab83e9c7bed7a061d37 (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')
-rw-r--r--source/gameengine/Converter/KX_ConvertSensors.cpp6
-rw-r--r--source/gameengine/Expressions/BoolValue.cpp7
-rw-r--r--source/gameengine/Expressions/BoolValue.h1
-rw-r--r--source/gameengine/Expressions/EmptyValue.cpp7
-rw-r--r--source/gameengine/Expressions/EmptyValue.h1
-rw-r--r--source/gameengine/Expressions/ErrorValue.cpp7
-rw-r--r--source/gameengine/Expressions/ErrorValue.h1
-rw-r--r--source/gameengine/Expressions/FloatValue.cpp7
-rw-r--r--source/gameengine/Expressions/FloatValue.h1
-rw-r--r--source/gameengine/Expressions/IntValue.cpp7
-rw-r--r--source/gameengine/Expressions/IntValue.h1
-rw-r--r--source/gameengine/Expressions/ListValue.cpp7
-rw-r--r--source/gameengine/Expressions/ListValue.h1
-rw-r--r--source/gameengine/Expressions/StringValue.cpp7
-rw-r--r--source/gameengine/Expressions/StringValue.h1
-rw-r--r--source/gameengine/Expressions/Value.cpp9
-rw-r--r--source/gameengine/Expressions/Value.h8
-rw-r--r--source/gameengine/Expressions/VectorValue.cpp8
-rw-r--r--source/gameengine/Expressions/VectorValue.h1
-rw-r--r--source/gameengine/Expressions/VoidValue.h1
-rw-r--r--source/gameengine/GameLogic/SCA_PropertySensor.cpp39
-rw-r--r--source/gameengine/GameLogic/SCA_PropertySensor.h2
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp2
23 files changed, 123 insertions, 9 deletions
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);