public void EnumerateIntersectingObjects(BoundingBox Box, HashSet <GameComponent> Into, Func <GameComponent, bool> Filter = null) { var minChunkID = GlobalVoxelCoordinate.FromVector3(Box.Min).GetGlobalChunkCoordinate(); var maxChunkID = GlobalVoxelCoordinate.FromVector3(Box.Max).GetGlobalChunkCoordinate(); for (var x = minChunkID.X; x <= maxChunkID.X; ++x) { for (var y = minChunkID.Y; y <= maxChunkID.Y; ++y) { for (var z = minChunkID.Z; z <= maxChunkID.Z; ++z) { var coord = new GlobalChunkCoordinate(x, y, z); if (ChunkManager.CheckBounds(coord)) { var chunk = ChunkManager.GetChunk(coord); lock (chunk) { foreach (var entity in chunk.Entities) { if (Box.Contains(entity.BoundingBox) != ContainmentType.Disjoint) { if (Filter == null || Filter(entity)) { Into.Add(entity); } } } } } } } } }
public void EnumerateIntersectingObjectsLoose(BoundingBox Box, HashSet <GameComponent> Into, Func <GameComponent, bool> Filter = null) { PerformanceMonitor.PushFrame("CollisionManager.EnumerateIntersectingObjects w/ Filter"); var minChunkID = GlobalVoxelCoordinate.FromVector3(Box.Min).GetGlobalChunkCoordinate(); var maxChunkID = GlobalVoxelCoordinate.FromVector3(Box.Max).GetGlobalChunkCoordinate(); for (var x = minChunkID.X; x <= maxChunkID.X; ++x) { for (var y = minChunkID.Y; y <= maxChunkID.Y; ++y) { for (var z = minChunkID.Z; z <= maxChunkID.Z; ++z) { var coord = new GlobalChunkCoordinate(x, y, z); if (ChunkManager.CheckBounds(coord)) { var chunk = ChunkManager.GetChunk(coord); lock (chunk) { foreach (var entity in chunk.Components) { if (Filter == null || Filter(entity)) { Into.Add(entity); } } } } } } } PerformanceMonitor.PopFrame(); }
public void EnumerateIntersectingRootEntitiesLoose(BoundingBox Box, HashSet <GameComponent> Into) { var minChunkID = GlobalVoxelCoordinate.FromVector3(Box.Min).GetGlobalChunkCoordinate(); var maxChunkID = GlobalVoxelCoordinate.FromVector3(Box.Max).GetGlobalChunkCoordinate(); for (var x = minChunkID.X; x <= maxChunkID.X; ++x) { for (var y = minChunkID.Y; y <= maxChunkID.Y; ++y) { for (var z = minChunkID.Z; z <= maxChunkID.Z; ++z) { var coord = new GlobalChunkCoordinate(x, y, z); if (ChunkManager.CheckBounds(coord)) { var chunk = ChunkManager.GetChunk(coord); lock (chunk) { foreach (var entity in chunk.RootEntities) { Into.Add(entity); } } } } } } }
private static void InvalidateNeighborSlice(ChunkManager Chunks, GlobalChunkCoordinate ChunkCoordinate, Point3 NeighborOffset, int LocalY) { var neighborCoordinate = new GlobalChunkCoordinate( ChunkCoordinate.X + NeighborOffset.X, ChunkCoordinate.Y + NeighborOffset.Y, ChunkCoordinate.Z + NeighborOffset.Z); if (Chunks.CheckBounds(neighborCoordinate)) { var chunk = Chunks.GetChunk(neighborCoordinate); chunk.InvalidateSlice(LocalY); } }
public void AddGameObject(GameComponent GameObject, BoundingBox LastBounds) { var minChunkID = GlobalVoxelCoordinate.FromVector3(LastBounds.Min).GetGlobalChunkCoordinate(); var maxChunkID = GlobalVoxelCoordinate.FromVector3(LastBounds.Max).GetGlobalChunkCoordinate(); for (var x = minChunkID.X; x <= maxChunkID.X; ++x) { for (var y = minChunkID.Y; y <= maxChunkID.Y; ++y) { for (var z = minChunkID.Z; z <= maxChunkID.Z; ++z) { var coord = new GlobalChunkCoordinate(x, y, z); if (ChunkManager.CheckBounds(coord)) { var chunk = ChunkManager.GetChunk(coord); lock (chunk) chunk.Entities.Add(GameObject); } } } } }
public void RemoveGameObject(GameComponent GameObject, BoundingBox LastBounds) { var minChunkID = GlobalVoxelCoordinate.FromVector3(LastBounds.Min).GetGlobalChunkCoordinate(); // Todo: Clamp to actual world size. var maxChunkID = GlobalVoxelCoordinate.FromVector3(LastBounds.Max).GetGlobalChunkCoordinate(); for (var x = minChunkID.X; x <= maxChunkID.X; ++x) { for (var y = minChunkID.Y; y <= maxChunkID.Y; ++y) { for (var z = minChunkID.Z; z <= maxChunkID.Z; ++z) { var coord = new GlobalChunkCoordinate(x, y, z); if (ChunkManager.CheckBounds(coord)) { var chunk = ChunkManager.GetChunk(coord); lock (chunk) chunk.Components.Remove(GameObject); } } } } }
public IEnumerable <VoxelChunk> EnumerateChunksInBounds(BoundingBox Box) { return(EnumerateChunkIDsInBounds(Box) .Where(id => ChunkManager.CheckBounds(id)) .Select(id => ChunkManager.GetChunk(id))); }