public EntityManager() { Systems = new List <BaseSystem>(); Data = new EntityStorage(); Data.Initialize(); CollisionBvh = new CompactBvh(); AddedEntities = new List <int>(); }
public void UpdateCollisionBvh() { List <RyneAABB> bounds = new List <RyneAABB>(); List <int> entityIds = new List <int>(); foreach (var entity in Entities.Where(x => x.HasComponent <CollisionComponent>())) { if (!entity.Initialized) { continue; } var entityBounds = entity.Collision.EncapsulatingAABB(entity.Transform); bounds.Add(new RyneAABB(entityBounds.Min, entityBounds.Max)); entityIds.Add(entity.EntityId); } //Parallel.For(0, Global.EntityManager.Entities.Length, i => //{ // AABB aabb = new AABB(new Float4(0.0f), new Float4(1.0f)); // bounds[i] = aabb.Transform(Global.EntityManager.TransformComponents[i]); //}); if (entityIds.Count < 1) { return; } RyneBoundingVolumeHierarchy bvh = new RyneBoundingVolumeHierarchy(); bvh.Create(bounds, entityIds); CollisionBvh = new CompactBvh { CompactedNodes = bvh.Nodes.ToArray() }; }
public void ClearAccelerationStructures() { CollisionBvh = CompactBvh.Empty; }