Пример #1
0
        public VoxelChunk ToChunk(ChunkManager Manager)
        {
            VoxelChunk c = new VoxelChunk(Manager, Origin, ID);

            for (var i = 0; i < VoxelConstants.ChunkVoxelCount; ++i)
            {
                c.Data.Types[i] = Types[i];

                if (Types[i] > 0)
                {
                    c.Data.Health[i] = (byte)VoxelLibrary.GetVoxelType(Types[i]).StartingHealth;

                    // Rebuild the VoxelsPresentInSlice counters
                    c.Data.VoxelsPresentInSlice[(i >> VoxelConstants.ZDivShift) >> VoxelConstants.XDivShift] += 1;
                }
            }

            Explored.CopyTo(c.Data.IsExplored, 0);
            // Separate loop for cache effeciency
            for (var i = 0; i < VoxelConstants.ChunkVoxelCount; ++i)
            {
                c.Data.Water[i].WaterLevel = Liquid[i];
                c.Data.Water[i].Type       = (LiquidType)LiquidTypes[i];

                // Rebuild the LiquidPresent counters
                if ((LiquidType)LiquidTypes[i] != LiquidType.None)
                {
                    c.Data.LiquidPresent[(i >> VoxelConstants.ZDivShift) >> VoxelConstants.XDivShift] += 1;
                }
            }
            c.CalculateInitialSunlight();
            return(c);
        }
Пример #2
0
        public VoxelChunk ToChunk(ChunkManager Manager)
        {
            VoxelChunk c = new VoxelChunk(Manager, Origin, ID);

            for (var i = 0; i < VoxelConstants.ChunkVoxelCount; ++i)
            {
                c.Data.Types[i] = Types[i];

                if (Types[i] > 0)
                {
                    // Rebuild the VoxelsPresentInSlice counters
                    c.Data.VoxelsPresentInSlice[(i >> VoxelConstants.ZDivShift) >> VoxelConstants.XDivShift] += 1;
                }
            }

            if (Liquid != null)
            {
                Liquid.CopyTo(c.Data._Water, 0);
                for (int y = 0; y < VoxelConstants.ChunkSizeY; y++)
                {
                    for (int x = 0; x < VoxelConstants.ChunkSizeX; x++)
                    {
                        for (int z = 0; z < VoxelConstants.ChunkSizeZ; z++)
                        {
                            VoxelHandle handle = new VoxelHandle(c, new LocalVoxelCoordinate(x, y, z));
                            c.Data.LiquidPresent[y] += handle.LiquidLevel;
                        }
                    }
                }
            }
            if (RampsSunlightExplored != null)
            {
                RampsSunlightExplored.CopyTo(c.Data.RampsSunlightExploredPlayerBuilt, 0);
            }
            if (GrassType != null)
            {
                GrassType.CopyTo(c.Data.Grass, 0);
            }
            if (Decals != null)
            {
                Decals.CopyTo(c.Data.Decals, 0);
            }

            c.CalculateInitialSunlight();
            return(c);
        }