Merged 15170:15635 from trunk (no conflicts or even merges)
[blender.git] / source / gameengine / Ketsji / KX_TouchSensor.cpp
index 3f185359de00491c81804132d54431b4d6fc357e..ce3aa1de2ef63db400926eb2b2b0713707cbfa34 100644 (file)
@@ -61,7 +61,9 @@ void KX_TouchSensor::EndFrame() {
 bool KX_TouchSensor::Evaluate(CValue* event)
 {
        bool result = false;
+       bool reset = m_reset && m_level;
 
+       m_reset = false;
        if (m_bTriggered != m_bLastTriggered)
        {
                m_bLastTriggered = m_bTriggered;
@@ -69,7 +71,9 @@ bool KX_TouchSensor::Evaluate(CValue* event)
                        m_hitObject = NULL;
                result = true;
        }
-       
+       if (reset)
+               // force an event
+               result = true;
        return result;
 }
 
@@ -77,18 +81,14 @@ KX_TouchSensor::KX_TouchSensor(SCA_EventManager* eventmgr,KX_GameObject* gameobj
 :SCA_ISensor(gameobj,eventmgr,T),
 m_touchedpropname(touchedpropname),
 m_bFindMaterial(bFindMaterial),
-m_eventmgr(eventmgr),
+m_eventmgr(eventmgr)
 /*m_sumoObj(sumoObj),*/
-m_bCollision(false),
-m_bTriggered(false),
-m_bLastTriggered(false)
 {
 //     KX_TouchEventManager* touchmgr = (KX_TouchEventManager*) eventmgr;
 //     m_resptable = touchmgr->GetResponseTable();
        
 //     m_solidHandle = m_sumoObj->getObjectHandle();
 
-       m_hitObject =  NULL;
        m_colliders = new CListValue();
        
        KX_ClientObjectInfo *client_info = gameobj->getClientInfo();
@@ -98,8 +98,17 @@ m_bLastTriggered(false)
        
        m_physCtrl = dynamic_cast<PHY_IPhysicsController*>(gameobj->GetPhysicsController());
        MT_assert( !gameobj->GetPhysicsController() || m_physCtrl );
+       Init();
 }
 
+void KX_TouchSensor::Init()
+{
+       m_bCollision = false;
+       m_bTriggered = false;
+       m_bLastTriggered = (m_invert)?true:false;
+       m_hitObject =  NULL;
+       m_reset = true;
+}
 
 KX_TouchSensor::~KX_TouchSensor()
 {
@@ -111,10 +120,7 @@ CValue* KX_TouchSensor::GetReplica()
 {
        KX_TouchSensor* replica = new KX_TouchSensor(*this);
        replica->m_colliders = new CListValue();
-       replica->m_bCollision = false;
-       replica->m_bTriggered= false;
-       replica->m_hitObject = NULL;
-       replica->m_bLastTriggered = false;
+       replica->Init();
        // this will copy properties and so on...
        CValue::AddDataToReplica(replica);
        return replica;