// TODO: Minimize allocations somehow. protected override void OnUpdate() { _bhTree = new BarnesHutTree(new float3(-32, -32, -32), new float3(32, 32, 32)); // tree is rebuilt every update. Entities.ForEach((in Entity entity, in PhysicsMass mass, in Translation translation) => { _bhTree.AddEntityToTree(entity, 1f / mass.InverseMass, translation.Value); }).WithoutBurst().Run();
private void CPUGravityCalculations() { var BHTree = BarnesHutTree.CreateTree(Objects, this.transform.position, 200); foreach (var body in Objects) { BHTree.CalculateForces(body, 1f); } }