Exemple #1
0
        public void CalculateHeightsAndCreateSunlightData()
        {
            var worldPosition = _position << WorldPositionShift;

            for (var x = 0; x < RegionLength; x++)
            {
                for (var z = 0; z < RegionLength; z++)
                {
                    var local = new Vector2i(x, z);
                    _heights[x, z]      = _biomes[x, z].GetColumnHeight(worldPosition + local);
                    _sunlightData[x, z] = new SunlightData(this, new Vector2i(x, z));
                }
            }
        }
Exemple #2
0
        public bool Load()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var regionsFolder = _world.Folder + Path.DirectorySeparatorChar + World2dRegionFolder;

            FolderUtils.CreateRegionFolderIfNotExist(regionsFolder);
            var file = regionsFolder + Path.DirectorySeparatorChar + _position.X + "-" + _position.Y + ".reg";

            if (!File.Exists(file))
            {
                return(false);
            }

            var stream    = new DeflateStream(File.Open(file, FileMode.Open, FileAccess.Read), CompressionMode.Decompress);
            var formatter = new BinaryFormatter();
            var version   = (uint)formatter.Deserialize(stream);

            var grid = _world.WorldGenerator.BiomeGrid;

            for (var x = 0; x < RegionLength; x++)
            {
                for (var z = 0; z < RegionLength; z++)
                {
                    _biomes[x, z]                  = grid.GetBiomeOrDefault((string)formatter.Deserialize(stream));
                    _heights[x, z]                 = (int)formatter.Deserialize(stream);
                    _interpolatedHeights[x, z]     = (int)formatter.Deserialize(stream);
                    _interpolatedGrassColors[x, z] = new Rgba32I(
                        (byte)formatter.Deserialize(stream),
                        (byte)formatter.Deserialize(stream),
                        (byte)formatter.Deserialize(stream),
                        (byte)formatter.Deserialize(stream));

                    var light = new SunlightData(this, new Vector2i(x, z));
                    light.Load(stream, formatter);
                    _sunlightData[x, z] = light;
                }
            }

            stream.Close();

            stopwatch.Stop();
            _world.DelayViewer.AddRegion2dLoad(stopwatch.ElapsedTicks);

            return(true);
        }