Пример #1
0
        private void GetChunksIntersecting(BoundingFrustum Frustum, HashSet <VoxelChunk> chunks)
        {
            chunks.Clear();
            var frustumBox = MathFunctions.GetBoundingBox(Frustum.GetCorners());
            var minChunk   = ChunkData.ConfineToBounds(GlobalVoxelCoordinate.FromVector3(frustumBox.Min).GetGlobalChunkCoordinate());
            var maxChunk   = ChunkData.ConfineToBounds(GlobalVoxelCoordinate.FromVector3(frustumBox.Max).GetGlobalChunkCoordinate());


            for (var x = minChunk.X; x <= maxChunk.X; ++x)
            {
                for (var y = minChunk.Y; y <= maxChunk.Y; ++y)
                {
                    for (var z = minChunk.Z; z <= maxChunk.Z; ++z)
                    {
                        var chunkCoord = new GlobalChunkCoordinate(x, y, z);
                        var min        = new GlobalVoxelCoordinate(chunkCoord, new LocalVoxelCoordinate(0, 0, 0));
                        var box        = new BoundingBox(min.ToVector3(), min.ToVector3() + new Vector3(VoxelConstants.ChunkSizeX, VoxelConstants.ChunkSizeY, VoxelConstants.ChunkSizeZ));
                        if (Frustum.Contains(box) != ContainmentType.Disjoint)
                        {
                            chunks.Add(ChunkData.GetChunk(chunkCoord));
                        }
                    }
                }
            }
        }
Пример #2
0
        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);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        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();
        }
Пример #4
0
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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);
                        }
                    }
                }
            }
        }
Пример #7
0
        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);
                        }
                    }
                }
            }
        }
Пример #8
0
 public IEnumerable <VoxelChunk> EnumerateChunksInBounds(BoundingBox Box)
 {
     return(EnumerateChunkIDsInBounds(Box)
            .Where(id => ChunkManager.CheckBounds(id))
            .Select(id => ChunkManager.GetChunk(id)));
 }