Merged 15170:15635 from trunk (no conflicts or even merges)
[blender.git] / source / gameengine / GameLogic / SCA_PropertySensor.cpp
index f1fcb18d32e89de47f0c2abb40aa8e011763ebb5..c50c011cc63f353583f0b8654dd9b3df7c48413e 100644 (file)
@@ -54,10 +54,8 @@ SCA_PropertySensor::SCA_PropertySensor(SCA_EventManager* eventmgr,
          m_checkpropval(propval),
          m_checkpropmaxval(propmaxval),
          m_checkpropname(propname),
-         m_lastresult(false),
          m_range_expr(NULL)
 {
-       m_recentresult=false;
        //CParser pars;
        //pars.SetContext(this->AddRef());
        //CValue* resultval = m_rightexpr->Calculate();
@@ -73,7 +71,14 @@ SCA_PropertySensor::SCA_PropertySensor(SCA_EventManager* eventmgr,
        {
                PrecalculateRangeExpression();
        }
+       Init();
+}
 
+void SCA_PropertySensor::Init()
+{
+       m_recentresult = false;
+       m_lastresult = m_invert?true:false;
+       m_reset = true;
 }
 
 void SCA_PropertySensor::PrecalculateRangeExpression()
@@ -107,6 +112,7 @@ CValue* SCA_PropertySensor::GetReplica()
        SCA_PropertySensor* replica = new SCA_PropertySensor(*this);
        // m_range_expr must be recalculated on replica!
        CValue::AddDataToReplica(replica);
+       replica->Init();
 
        replica->m_range_expr = NULL;
        if (replica->m_checktype==KX_PROPSENSOR_INTERVAL)
@@ -149,14 +155,15 @@ SCA_PropertySensor::~SCA_PropertySensor()
 bool SCA_PropertySensor::Evaluate(CValue* event)
 {
        bool result = CheckPropertyCondition();
+       bool reset = m_reset && m_level;
        
+       m_reset = false;
        if (m_lastresult!=result)
        {
                m_lastresult = result;
                return true;
        }
-
-       return false;
+       return (reset) ? true : false;
 }