Exemplo n.º 1
0
        /// <summary>
        /// Run the reveal algorithm without invoking the invalidation mechanism.
        /// </summary>
        /// <param name="Data"></param>
        /// <param name="voxel"></param>
        public static void InitialReveal(
            ChunkManager Manager,
            ChunkData Data,
            VoxelHandle voxel)
        {
            // Fog of war must be on for the initial reveal to avoid artifacts.
            bool fogOfWar = GameSettings.Default.FogofWar;

            GameSettings.Default.FogofWar = true;

            var queue = new Queue <VoxelHandle>(128);

            queue.Enqueue(voxel);

            while (queue.Count > 0)
            {
                var v = queue.Dequeue();
                if (!v.IsValid)
                {
                    continue;
                }

                foreach (var neighborCoordinate in VoxelHelpers.EnumerateManhattanNeighbors(v.Coordinate))
                {
                    var neighbor = new VoxelHandle(Data, neighborCoordinate);
                    if (!neighbor.IsValid)
                    {
                        continue;
                    }
                    if (neighbor.IsExplored)
                    {
                        continue;
                    }

                    // We are skipping the invalidation mechanism but still need to trigger events.
                    Manager.NotifyChangedVoxel(new VoxelChangeEvent
                    {
                        Type  = VoxelChangeEventType.Explored,
                        Voxel = neighbor
                    });
                    neighbor.RawSetIsExplored();

                    if (neighbor.IsEmpty)
                    {
                        queue.Enqueue(neighbor);
                    }
                }

                v.RawSetIsExplored();
            }

            GameSettings.Default.FogofWar = fogOfWar;
        }