internal unsafe void CopyFrom(CollisionData *data) { _impulse = data->Impulse; _velocityA = data->VelocityA; _velocityB = data->VelocityB; _colliderA = Object.Find <Collider>(ref data->ColliderA); _colliderB = Object.Find <Collider>(ref data->ColliderB); Assert.AreEqual(data->ContactsCount, _contacts.Length); ContactPointData *ptr = &data->Contacts0; for (int i = 0; i < data->ContactsCount; i++) { _contacts[i] = new ContactPoint(ref ptr[i], ref data->ColliderA, ref data->ColliderB); } }
internal static unsafe Collision[] Internal_ExtractCollisions(byte[] data) { // Return used collisions to pool if (_data != null) { _pool.AddRange(_data); _data = null; } //CollisionData collisionData = new CollisionData(); fixed(byte *dataPtr = data) { using (var memoryStream = new MemoryStream(data, false)) using (var stream = new BinaryReader(memoryStream)) { int version = stream.ReadInt32(); if (version != 1) { return(null); } int collisionsCount = stream.ReadInt32(); int index = 0; _data = new Collision[collisionsCount * 2]; for (int i = 0; i < collisionsCount; i++) { var ptr = dataPtr + memoryStream.Position; CollisionData *collisionData = (CollisionData *)ptr; var c1 = GetCollision(collisionData->ContactsCount); var c2 = GetCollision(collisionData->ContactsCount); c1.CopyFrom(collisionData); c2.CopyFrom(c1); c2.SwapObjects(); _data[index++] = c1; _data[index++] = c2; } } } return(_data); }
internal static unsafe Collision[] Internal_ExtractCollisions(byte[] data) { fixed(byte *dataPtr = data) { using (var memoryStream = new MemoryStream(data, false)) using (var stream = new BinaryReader(memoryStream)) { int version = stream.ReadInt32(); if (version != 1) { return(null); } int collisionsCount = stream.ReadInt32(); if (_data == null || _data.Length < collisionsCount * 2) { _data = new Collision[(int)(collisionsCount * 2 * 1.5f)]; } _dataUsed = collisionsCount * 2; int index = 0; for (int i = 0; i < collisionsCount; i++) { var ptr = dataPtr + memoryStream.Position; CollisionData *collisionData = ((CollisionData *)ptr) + i; var c1 = GetCollision(collisionData->ContactsCount); var c2 = GetCollision(collisionData->ContactsCount); c1.CopyFrom(collisionData); c2.CopyFrom(c1); c2.SwapObjects(); _data[index++] = c1; _data[index++] = c2; } } } return(_data); }