Physics/PhysObject: Fixed Copy/Move operator

Former-commit-id: 58377ee8d41ef39ade38fcbf03355af5e7d7db58
This commit is contained in:
Lynix 2015-04-20 01:28:18 +02:00
parent 61c6baeabe
commit 1c7c1de3e7
2 changed files with 7 additions and 5 deletions

View File

@ -56,7 +56,7 @@ class NAZARA_API NzPhysObject : NzNonCopyable
void SetPosition(const NzVector3f& position); void SetPosition(const NzVector3f& position);
void SetRotation(const NzQuaternionf& rotation); void SetRotation(const NzQuaternionf& rotation);
NzPhysObject& operator=(NzPhysObject object); NzPhysObject& operator=(const NzPhysObject& object);
NzPhysObject& operator=(NzPhysObject&& object); NzPhysObject& operator=(NzPhysObject&& object);
private: private:

View File

@ -269,11 +269,8 @@ void NzPhysObject::SetRotation(const NzQuaternionf& rotation)
UpdateBody(); UpdateBody();
} }
NzPhysObject& NzPhysObject::operator=(NzPhysObject object) NzPhysObject& NzPhysObject::operator=(const NzPhysObject& object)
{ {
std::swap(*this, object);
return *this;
} }
void NzPhysObject::UpdateBody() void NzPhysObject::UpdateBody()
@ -282,10 +279,15 @@ void NzPhysObject::UpdateBody()
/*for (std::set<PhysObjectListener*>::iterator it = m_listeners.begin(); it != m_listeners.end(); ++it) /*for (std::set<PhysObjectListener*>::iterator it = m_listeners.begin(); it != m_listeners.end(); ++it)
(*it)->PhysObjectOnUpdate(this);*/ (*it)->PhysObjectOnUpdate(this);*/
NzPhysObject physObj(object);
return operator=(std::move(physObj));
} }
NzPhysObject& NzPhysObject::operator=(NzPhysObject&& object) NzPhysObject& NzPhysObject::operator=(NzPhysObject&& object)
{ {
if (m_body)
NewtonDestroyBody(m_world->GetHandle(), m_body);
m_body = object.m_body; m_body = object.m_body;
m_forceAccumulator = std::move(object.m_forceAccumulator); m_forceAccumulator = std::move(object.m_forceAccumulator);
m_geom = std::move(object.m_geom); m_geom = std::move(object.m_geom);