diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-13 00:16:53 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-13 00:16:53 +0300 |
commit | bdfe7d89e2f1292644577972c716931b4ce3c6c3 (patch) | |
tree | d00eb50b749cb001e2b08272c91791e66740b05d /source/gameengine/Ketsji/KX_TouchSensor.cpp | |
parent | 78a1c27c4a6abe0ed31ca93ad21910f3df04da56 (diff) | |
parent | 7e4db234cee71ead34ee81a12e27da4bd548eb4b (diff) |
Merge of trunk into blender 2.5:
svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r12987:17416
Issues:
* GHOST/X11 had conflicting changes. Some code was added in 2.5, which was
later added in trunk also, but reverted partially, specifically revision
16683. I have left out this reversion in the 2.5 branch since I think it is
needed there.
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16683
* Scons had various conflicting changes, I decided to go with trunk version
for everything except priorities and some library renaming.
* In creator.c, there were various fixes and fixes for fixes related to the -w
-W and -p options. In 2.5 -w and -W is not coded yet, and -p is done
differently. Since this is changed so much, and I don't think those fixes
would be needed in 2.5, I've left them out.
* Also in creator.c: there was code for a python bugfix where the screen was not
initialized when running with -P. The code that initializes the screen there
I had to disable, that can't work in 2.5 anymore but left it commented as a
reminder.
Further I had to disable some new function calls. using src/ and python/, as
was done already in this branch, disabled function calls:
* bpath.c: error reporting
* BME_conversions.c: editmesh conversion functions.
* SHD_dynamic: disabled almost completely, there is no python/.
* KX_PythonInit.cpp and Ketsji/ build files: Mathutils is not there, disabled.
* text.c: clipboard copy call.
* object.c: OB_SUPPORT_MATERIAL.
* DerivedMesh.c and subsurf_ccg, stipple_quarttone.
Still to be done:
* Go over files and functions that were moved to a different location but could
still use changes that were done in trunk.
Diffstat (limited to 'source/gameengine/Ketsji/KX_TouchSensor.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_TouchSensor.cpp | 85 |
1 files changed, 50 insertions, 35 deletions
diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 62e400a7049..1935a0bde39 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -48,30 +48,30 @@ void KX_TouchSensor::SynchronizeTransform() { - - if (m_physCtrl) - { - - KX_GameObject* parent = ((KX_GameObject*)GetParent()); - MT_Vector3 pos = parent->NodeGetWorldPosition(); - MT_Quaternion orn = parent->NodeGetWorldOrientation().getRotation(); - m_physCtrl->setPosition(pos.x(),pos.y(),pos.z()); - m_physCtrl->setOrientation(orn.x(),orn.y(),orn.z(),orn.w()); - m_physCtrl->calcXform(); - } - + // the touch sensor does not require any synchronization: it uses + // the same physical object which is already synchronized by Blender } void KX_TouchSensor::EndFrame() { m_colliders->ReleaseAndRemoveAll(); + m_hitObject = NULL; m_bTriggered = false; } +void KX_TouchSensor::UnregisterToManager() +{ + // before unregistering the sensor, make sure we release all references + EndFrame(); + m_eventmgr->RemoveSensor(this); +} + 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; @@ -79,7 +79,9 @@ bool KX_TouchSensor::Evaluate(CValue* event) m_hitObject = NULL; result = true; } - + if (reset) + // force an event + result = true; return result; } @@ -87,18 +89,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(); @@ -108,8 +106,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() { @@ -121,10 +128,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; @@ -157,6 +161,14 @@ void KX_TouchSensor::RegisterSumo(KX_TouchEventManager *touchman) } } +void KX_TouchSensor::UnregisterSumo(KX_TouchEventManager* touchman) +{ + if (m_physCtrl) + { + touchman->GetPhysicsEnvironment()->removeCollisionCallback(m_physCtrl); + } +} + bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_CollData* colldata) { // KX_TouchEventManager* toucheventmgr = (KX_TouchEventManager*)m_eventmgr; @@ -172,7 +184,10 @@ bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll client_info->m_gameobject : NULL); - if (gameobj && (gameobj != parent) && client_info->isActor()) + // add the same check as in SCA_ISensor::Activate(), + // we don't want to record collision when the sensor is not active. + if (m_links && !m_suspended && + gameobj && (gameobj != parent) && client_info->isActor()) { if (!m_colliders->SearchValue(gameobj)) m_colliders->Add(gameobj->AddRef()); @@ -236,13 +251,13 @@ PyParentObject KX_TouchSensor::Parents[] = { PyMethodDef KX_TouchSensor::Methods[] = { {"setProperty", - (PyCFunction) KX_TouchSensor::sPySetProperty, METH_VARARGS, SetProperty_doc}, + (PyCFunction) KX_TouchSensor::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc}, {"getProperty", - (PyCFunction) KX_TouchSensor::sPyGetProperty, METH_VARARGS, GetProperty_doc}, + (PyCFunction) KX_TouchSensor::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc}, {"getHitObject", - (PyCFunction) KX_TouchSensor::sPyGetHitObject, METH_VARARGS, GetHitObject_doc}, + (PyCFunction) KX_TouchSensor::sPyGetHitObject, METH_VARARGS, (PY_METHODCHAR)GetHitObject_doc}, {"getHitObjectList", - (PyCFunction) KX_TouchSensor::sPyGetHitObjectList, METH_VARARGS, GetHitObjectList_doc}, + (PyCFunction) KX_TouchSensor::sPyGetHitObjectList, METH_VARARGS, (PY_METHODCHAR)GetHitObjectList_doc}, {NULL,NULL} //Sentinel }; @@ -253,7 +268,7 @@ PyObject* KX_TouchSensor::_getattr(const STR_String& attr) { /* Python API */ /* 1. setProperty */ -char KX_TouchSensor::SetProperty_doc[] = +const char KX_TouchSensor::SetProperty_doc[] = "setProperty(name)\n" "\t- name: string\n" "\tSet the property or material to collide with. Use\n" @@ -271,15 +286,15 @@ PyObject* KX_TouchSensor::PySetProperty(PyObject* self, if (!prop->IsError()) { m_touchedpropname = nameArg; - prop->Release(); } else { ; /* not found ... */ } + prop->Release(); Py_Return; } /* 2. getProperty */ -char KX_TouchSensor::GetProperty_doc[] = +const char KX_TouchSensor::GetProperty_doc[] = "getProperty(name)\n" "\tReturns the property or material to collide with. Use\n" "\tgetTouchMaterial() to find out whether this sensor\n" @@ -290,7 +305,7 @@ PyObject* KX_TouchSensor::PyGetProperty(PyObject* self, return PyString_FromString(m_touchedpropname); } -char KX_TouchSensor::GetHitObject_doc[] = +const char KX_TouchSensor::GetHitObject_doc[] = "getHitObject()\n" ; PyObject* KX_TouchSensor::PyGetHitObject(PyObject* self, @@ -306,7 +321,7 @@ PyObject* KX_TouchSensor::PyGetHitObject(PyObject* self, Py_Return; } -char KX_TouchSensor::GetHitObjectList_doc[] = +const char KX_TouchSensor::GetHitObjectList_doc[] = "getHitObjectList()\n" "\tReturn a list of the objects this object collided with,\n" "\tbut only those matching the property/material condition.\n"; @@ -348,8 +363,8 @@ PyObject* KX_TouchSensor::PyGetHitObjectList(PyObject* self, CValue* val = m_colliders->GetValue(i)->FindIdentifier(m_touchedpropname); if (!val->IsError()) { newList->Add(m_colliders->GetValue(i)->AddRef()); - val->Release(); } + val->Release(); } i++; @@ -360,7 +375,7 @@ PyObject* KX_TouchSensor::PyGetHitObjectList(PyObject* self, } /* 5. getTouchMaterial */ -char KX_TouchSensor::GetTouchMaterial_doc[] = +const char KX_TouchSensor::GetTouchMaterial_doc[] = "getTouchMaterial()\n" "\tReturns KX_TRUE if this sensor looks for a specific material,\n" "\tKX_FALSE if it looks for a specific property.\n" ; @@ -372,7 +387,7 @@ PyObject* KX_TouchSensor::PyGetTouchMaterial(PyObject* self, } /* 6. setTouchMaterial */ -char KX_TouchSensor::SetTouchMaterial_doc[] = +const char KX_TouchSensor::SetTouchMaterial_doc[] = "setTouchMaterial(flag)\n" "\t- flag: KX_TRUE or KX_FALSE.\n" "\tSet flag to KX_TRUE to switch on positive pulse mode,\n" |