void dgWorld::SerializeScene(void* const userData, OnBodySerialize bodyCallback, dgSerialize serializeCallback, void* const serializeHandle) const { dgBody** const array = new dgBody*[GetBodiesCount()]; dgInt32 count = 0; const dgBodyMasterList& me = *this; for (dgBodyMasterList::dgListNode* node = me.GetFirst()->GetNext(); node; node = node->GetNext()) { const dgBodyMasterListRow& graphNode = node->GetInfo(); array[count] = graphNode.GetBody(); array[count]->m_serializedEnum = count; count++; dgAssert(count <= GetBodiesCount()); } dgSortIndirect(array, count, SerializeToFileSort); SerializeBodyArray(userData, bodyCallback ? bodyCallback : OnBodySerializeToFile, array, count, serializeCallback, serializeHandle); SerializeJointArray(count, OnSerializeToFile, serializeHandle); for (dgBodyMasterList::dgListNode* node = me.GetFirst()->GetNext(); node; node = node->GetNext()) { const dgBodyMasterListRow& graphNode = node->GetInfo(); graphNode.GetBody()->m_serializedEnum = -1; } delete[] array; }
void dgWorld::SerializeToFile (const char* const fileName) const { FILE* const file = fopen (fileName, "wb"); if (file) { dgBody** const array = new dgBody*[GetBodiesCount()]; dgInt32 count = 0; const dgBodyMasterList& me = *this; for (dgBodyMasterList::dgListNode* node = me.GetFirst()->GetNext(); node; node = node->GetNext()) { const dgBodyMasterListRow& graphNode = node->GetInfo(); array[count] = graphNode.GetBody(); count ++; dgAssert (count <= GetBodiesCount()); } SerializeBodyArray (array, count, OnBodySerializeToFile, OnSerializeToFile, file); delete[] array; fclose (file); } }