public static void Simulate() { CollisionIterationRemain = (CollisionPairCount) / CollisionIterationSpread + 1; if (CollisionIterationCount == CollisionIterationSpread) { CollisionIterationCount = 0; CollisionIterationMark = 0; } else { CollisionIterationMark += CollisionIterationRemain; } CurCount = 0; for (i = 0; i < FastCollisionPairs.Count; i++) { pair = FastCollisionPairs[i]; CurCount++; if (CollisionIterationRemain == 0 || CurCount < CollisionIterationMark) { pair.DistributeCollision(); } else { pair.CheckAndDistributeCollision(); CollisionIterationRemain--; } } if (CollisionIterationCount == 0) { for (i = 0; i < PeakCount; i++) { if (SimObjectExists [i]) { LSBody b1 = SimObjects [i]; b1.EarlySimulate(); if (b1.PositionChanged) { Partition.Body = b1; Partition.PartitionObject(); } b1.Simulate(); } } Partition.EstablishPartitions(); } else { for (i = 0; i < PeakCount; i++) { if (SimObjectExists [i]) { LSBody b1 = SimObjects [i]; b1.EarlySimulate(); b1.Simulate(); } } } CollisionIterationCount++; }