void dgBody::Serialize (const dgTree<dgInt32, const dgCollision*>& collisionRemapId, dgSerialize serializeCallback, void* const userData) { serializeCallback (userData, &m_rotation, sizeof (m_rotation)); serializeCallback (userData, &m_matrix.m_posit, sizeof (m_matrix.m_posit)); serializeCallback (userData, &m_veloc, sizeof (m_veloc)); serializeCallback (userData, &m_omega, sizeof (m_omega)); serializeCallback (userData, &m_localCentreOfMass, sizeof (m_localCentreOfMass)); serializeCallback (userData, &m_aparentMass, sizeof (m_aparentMass)); serializeCallback (userData, &m_flags, sizeof (m_flags)); serializeCallback (userData, &m_maxAngulaRotationPerSet2, sizeof (m_maxAngulaRotationPerSet2)); dgTree<dgInt32, const dgCollision*>::dgTreeNode* const node = collisionRemapId.Find(m_collision->GetChildShape()); dgAssert (node); dgInt32 id = node->GetInfo(); serializeCallback (userData, &id, sizeof (id)); m_collision->Serialize(serializeCallback, userData, false); }
void dgWorld::DeserializeJointArray (const dgTree<dgBody*, dgInt32>&bodyMap, dgDeserialize serializeCallback, void* const userData) { dgInt32 count = 0; dgDeserializeMarker (serializeCallback, userData); serializeCallback(userData, &count, sizeof (count)); for (dgInt32 i = 0; i < count; i ++) { if (m_deserializedJointCallback) { dgInt32 bodyIndex0; dgInt32 bodyIndex1; serializeCallback(userData, &bodyIndex0, sizeof (bodyIndex0)); serializeCallback(userData, &bodyIndex1, sizeof (bodyIndex1)); dgBody* const body0 = (bodyIndex0 != -1) ? bodyMap.Find (bodyIndex0)->GetInfo() : NULL; dgBody* const body1 = (bodyIndex1 != -1) ? bodyMap.Find (bodyIndex1)->GetInfo() : NULL; m_deserializedJointCallback (body0, body1, serializeCallback, userData); } dgDeserializeMarker(serializeCallback, userData); } dgDeserializeMarker(serializeCallback, userData); }
void dgWorld::DeserializeBodyArray (void* const userData, OnBodyDeserialize bodyCallback, dgTree<dgBody*, dgInt32>&bodyMap, dgDeserialize deserializeCallback, void* const serializeHandle) { dgInt32 revision = dgDeserializeMarker(deserializeCallback, serializeHandle); dgTree<const dgCollision*, dgInt32> shapeMap(GetAllocator()); dgInt32 uniqueShapes; deserializeCallback(serializeHandle, &uniqueShapes, sizeof (uniqueShapes)); for (dgInt32 i = 0; i < uniqueShapes; i++) { dgInt32 id; deserializeCallback(serializeHandle, &id, sizeof (id)); dgCollisionInstance instance(this, deserializeCallback, serializeHandle, revision); dgDeserializeMarker(deserializeCallback, serializeHandle); const dgCollision* const shape = instance.GetChildShape(); shapeMap.Insert(shape, id); shape->AddRef(); } dgInt32 bodyCount; deserializeCallback(serializeHandle, &bodyCount, sizeof (bodyCount)); for (dgInt32 i = 0; i < bodyCount; i++) { dgInt32 bodyType; deserializeCallback(serializeHandle, &bodyType, sizeof (bodyType)); dgBody* body = NULL; switch (bodyType) { case dgBody::m_dynamicBody: { body = new (m_allocator)dgDynamicBody(this, &shapeMap, deserializeCallback, serializeHandle, revision); break; } case dgBody::m_kinematicBody: { body = new (m_allocator)dgKinematicBody(this, &shapeMap, deserializeCallback, serializeHandle, revision); break; } case dgBody::m_dynamicBodyAsymatric: { body = new (m_allocator)dgDynamicBodyAsymetric(this, &shapeMap, deserializeCallback, serializeHandle, revision); break; } } dgAssert(body); m_bodiesUniqueID++; body->m_freeze = false; body->m_sleeping = false; body->m_equilibrium = false; body->m_spawnnedFromCallback = false; body->m_uniqueID = dgInt32(m_bodiesUniqueID); dgBodyMasterList::AddBody(body); body->SetMatrix(body->GetMatrix()); m_broadPhase->Add(body); if (body->IsRTTIType(dgBody::m_dynamicBodyRTTI)) { dgDynamicBody* const dynBody = (dgDynamicBody*)body; dynBody->SetMassMatrix(dynBody->m_mass.m_w, dynBody->CalculateLocalInertiaMatrix()); } // load user related data bodyCallback(*body, userData, deserializeCallback, serializeHandle); bodyMap.Insert(body, body->m_serializedEnum); // sync to next body dgDeserializeMarker(deserializeCallback, serializeHandle); } dgTree<const dgCollision*, dgInt32>::Iterator iter(shapeMap); for (iter.Begin(); iter; iter++) { const dgCollision* const collision = iter.GetNode()->GetInfo(); collision->Release(); } }