forked from bartvdbraak/blender
BGE: some more cleanup, implement proper GetReplica/ProcessReplica workflow for touch/near/radar sensor. Remove duplicated code.
This commit is contained in:
parent
b22819f686
commit
48f483d14f
@ -109,51 +109,35 @@ void KX_NearSensor::UnregisterSumo(KX_TouchEventManager* touchman)
|
||||
CValue* KX_NearSensor::GetReplica()
|
||||
{
|
||||
KX_NearSensor* replica = new KX_NearSensor(*this);
|
||||
replica->m_colliders = new CListValue();
|
||||
replica->Init();
|
||||
replica->ProcessReplica();
|
||||
|
||||
replica->m_client_info = new KX_ClientObjectInfo(m_client_info->m_gameobject, KX_ClientObjectInfo::NEAR);
|
||||
|
||||
if (replica->m_physCtrl)
|
||||
{
|
||||
replica->m_physCtrl = replica->m_physCtrl->GetReplica();
|
||||
if (replica->m_physCtrl)
|
||||
{
|
||||
//static_cast<KX_TouchEventManager*>(m_eventmgr)->GetPhysicsEnvironment()->addSensor(replica->m_physCtrl);
|
||||
replica->m_physCtrl->SetMargin(m_Margin);
|
||||
replica->m_physCtrl->setNewClientInfo(replica->m_client_info);
|
||||
}
|
||||
|
||||
}
|
||||
//Wrong: the parent object could be a child, this code works only if it is a root parent.
|
||||
//Anyway, at this stage, the parent object is already synchronized, nothing to do.
|
||||
//bool parentUpdated = false;
|
||||
//((KX_GameObject*)replica->GetParent())->GetSGNode()->ComputeWorldTransforms(NULL, parentUpdated);
|
||||
replica->SynchronizeTransform();
|
||||
|
||||
return replica;
|
||||
}
|
||||
|
||||
void KX_NearSensor::ProcessReplica()
|
||||
{
|
||||
KX_TouchSensor::ProcessReplica();
|
||||
|
||||
m_client_info = new KX_ClientObjectInfo(m_client_info->m_gameobject, KX_ClientObjectInfo::NEAR);
|
||||
|
||||
if (m_physCtrl)
|
||||
{
|
||||
m_physCtrl = m_physCtrl->GetReplica();
|
||||
if (m_physCtrl)
|
||||
{
|
||||
//static_cast<KX_TouchEventManager*>(m_eventmgr)->GetPhysicsEnvironment()->addSensor(replica->m_physCtrl);
|
||||
m_physCtrl->SetMargin(m_Margin);
|
||||
m_physCtrl->setNewClientInfo(m_client_info);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void KX_NearSensor::ReParent(SCA_IObject* parent)
|
||||
{
|
||||
m_client_info->m_gameobject = static_cast<KX_GameObject*>(parent);
|
||||
m_client_info->m_sensors.push_back(this);
|
||||
|
||||
|
||||
/* KX_ClientObjectInfo *client_info = gameobj->getClientInfo();
|
||||
client_info->m_gameobject = gameobj;
|
||||
client_info->m_auxilary_info = NULL;
|
||||
|
||||
client_info->m_sensors.push_back(this);
|
||||
SCA_ISensor::ReParent(parent);
|
||||
*/
|
||||
//Not needed, was done in GetReplica() already
|
||||
//bool parentUpdated = false;
|
||||
//((KX_GameObject*)GetParent())->GetSGNode()->ComputeWorldTransforms(NULL,parentUpdated);
|
||||
//SynchronizeTransform();
|
||||
//Synchronize here with the actual parent.
|
||||
SynchronizeTransform();
|
||||
SCA_ISensor::ReParent(parent);
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,7 @@ public:
|
||||
virtual ~KX_NearSensor();
|
||||
virtual void SynchronizeTransform();
|
||||
virtual CValue* GetReplica();
|
||||
virtual void ProcessReplica();
|
||||
virtual bool Evaluate(CValue* event);
|
||||
|
||||
virtual void ReParent(SCA_IObject* parent);
|
||||
|
@ -80,33 +80,15 @@ KX_RadarSensor::~KX_RadarSensor()
|
||||
CValue* KX_RadarSensor::GetReplica()
|
||||
{
|
||||
KX_RadarSensor* replica = new KX_RadarSensor(*this);
|
||||
replica->m_colliders = new CListValue();
|
||||
replica->Init();
|
||||
replica->ProcessReplica();
|
||||
|
||||
replica->m_client_info = new KX_ClientObjectInfo(m_client_info->m_gameobject, KX_ClientObjectInfo::RADAR);
|
||||
|
||||
if (replica->m_physCtrl)
|
||||
{
|
||||
replica->m_physCtrl = replica->m_physCtrl->GetReplica();
|
||||
if (replica->m_physCtrl)
|
||||
{
|
||||
replica->m_physCtrl->setNewClientInfo(replica->m_client_info);
|
||||
}
|
||||
}
|
||||
|
||||
//todo: make sure replication works fine!
|
||||
//>m_sumoObj = new SM_Object(DT_NewCone(m_coneradius, m_coneheight),NULL,NULL,NULL);
|
||||
//replica->m_sumoObj->setMargin(m_Margin);
|
||||
//replica->m_sumoObj->setClientObject(replica->m_client_info);
|
||||
//Wrong: see KX_TouchSensor
|
||||
//bool parentUpdated = false;
|
||||
//((KX_GameObject*)replica->GetParent())->GetSGNode()->ComputeWorldTransforms(NULL,parentUpdated);
|
||||
replica->SynchronizeTransform();
|
||||
|
||||
return replica;
|
||||
}
|
||||
|
||||
void KX_RadarSensor::ProcessReplica()
|
||||
{
|
||||
KX_NearSensor::ProcessReplica();
|
||||
m_client_info->m_type = KX_ClientObjectInfo::RADAR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the collision object. A cone is not correctly centered
|
||||
|
@ -76,6 +76,7 @@ public:
|
||||
virtual ~KX_RadarSensor();
|
||||
virtual void SynchronizeTransform();
|
||||
virtual CValue* GetReplica();
|
||||
virtual void ProcessReplica();
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* Python interface ---------------------------------------------------- */
|
||||
|
@ -142,12 +142,17 @@ KX_TouchSensor::~KX_TouchSensor()
|
||||
CValue* KX_TouchSensor::GetReplica()
|
||||
{
|
||||
KX_TouchSensor* replica = new KX_TouchSensor(*this);
|
||||
replica->m_colliders = new CListValue();
|
||||
replica->Init();
|
||||
replica->ProcessReplica();
|
||||
return replica;
|
||||
}
|
||||
|
||||
void KX_TouchSensor::ProcessReplica()
|
||||
{
|
||||
SCA_ISensor::ProcessReplica();
|
||||
m_colliders = new CListValue();
|
||||
Init();
|
||||
}
|
||||
|
||||
void KX_TouchSensor::ReParent(SCA_IObject* parent)
|
||||
{
|
||||
KX_GameObject *gameobj = static_cast<KX_GameObject *>(parent);
|
||||
|
@ -84,6 +84,7 @@ public:
|
||||
virtual ~KX_TouchSensor();
|
||||
|
||||
virtual CValue* GetReplica();
|
||||
virtual void ProcessReplica();
|
||||
virtual void SynchronizeTransform();
|
||||
virtual bool Evaluate(CValue* event);
|
||||
virtual void Init();
|
||||
|
Loading…
Reference in New Issue
Block a user