public static void Save(string name, LargeMap map)
        {
            string directoryPath = Application.dataPath + "/../PlanetData/largeMaps";

            Directory.CreateDirectory(directoryPath);
            string saveFilePath = directoryPath + "/" + name + ".png";

            Debug.Log("Save " + saveFilePath);
            FileStream   saveFile   = new FileStream(saveFilePath, FileMode.Create, FileAccess.Write);
            BinaryWriter dataStream = new BinaryWriter(saveFile);

            Color[] colors = new Color[map.size * map.size];
            for (int i = 0; i < map.size; i++)
            {
                for (int j = 0; j < map.size; j++)
                {
                    colors [i * map.size + j] = new Color(map.heightMap [i] [j], map.heightMap [i] [j], map.heightMap [i] [j]);
                }
            }
            Texture2D imgMap = new Texture2D(map.size, map.size);

            imgMap.SetPixels(colors);

            dataStream.Write(imgMap.EncodeToPNG());

            dataStream.Close();
            saveFile.Close();
        }
        public static LargeMap Load(string name, int size)
        {
            string path = Application.dataPath + "/../PlanetData/largeMaps/" + name + ".png";

            if (File.Exists(path))
            {
                Debug.Log("Load " + path);
                byte[]    data   = File.ReadAllBytes(path);
                Texture2D imgMap = new Texture2D(2, 2);
                imgMap.LoadImage(data);
                LargeMap map = new LargeMap(size);
                for (int i = 0; i < map.size; i++)
                {
                    for (int j = 0; j < map.size; j++)
                    {
                        map.heightMap [i] [j] = imgMap.GetPixel(i, j).r;
                    }
                }
                return(map);
            }
            else
            {
                return(null);
            }
        }
示例#3
0
        public void LargeMap()
        {
            Key    key     = new Key(args.ns, args.set, "setkey");
            string binName = args.GetBinName("setbin");

            // Delete record if it already exists.
            client.Delete(null, key);

            // Initialize Large Map operator.
            LargeMap lmap = client.GetLargeMap(null, key, binName, null);

            // Write values.
            lmap.Put(Value.Get("lmapName1"), Value.Get("lmapValue1"));
            lmap.Put(Value.Get("lmapName2"), Value.Get("lmapValue2"));
            lmap.Put(Value.Get("lmapName3"), Value.Get("lmapValue3"));

            // Remove last value.
            lmap.Remove(Value.Get("lmapName3"));
            Assert.AreEqual(2, lmap.Size());

            IDictionary mapReceived    = lmap.Get(Value.Get("lmapName2"));
            string      stringReceived = (string)mapReceived["lmapName2"];

            Assert.AreEqual("lmapValue2", stringReceived);
        }
示例#4
0
 public static void ResetPointer()
 {
     Minimap.Reload();
     LargeMap.Reload();
     Inventory.Reload();
     Stash.Reload();
     Kadala.Reload();
     SkillsBar.Reload();
     InventoryTabs.Tabs.ForEach(x => x.Reload());
 }
示例#5
0
        public static void RevealLargeMap()
        {
            LargeMap Minimap = SearchControl <LargeMap>();

            if (Minimap == null)
            {
                return;
            }

            // Minimap.MapItems.RevealLargemap.Enabled = Value;
        }
示例#6
0
        private async void UpdateWeather()
        {
            main.Visibility = Visibility.Collapsed;
            var forecast = await weatherService.GetForecastAsync();

            Temp.Text              = forecast.Current.Temperature.ToString();
            FeelsLike.Text         = forecast.Current.FeelsLike.ToString();
            Humidity.Text          = forecast.Current.Humidity.ToString();
            Wind.Text              = $"{(int)forecast.Current.WindSpeed}{forecast.Current.WindDirection}";
            CurrentConditions.Text = forecast.Current.WeatherDescription;
            var when  = DateTime.Now;
            var tides = await TideData.GetNextTides(when, TideData.Location.BowleysBar);

            HighTide.Text = tides.HighTide;
            LowTide.Text  = tides.LowTide;
            LargeMap.Navigate(new Uri(largeMapUrl));
            SmallMap.Navigate(new Uri(smallMapUrl));
            main.Visibility = Visibility.Visible;
        }
        private Byte[][][] GetByteFor(
            int iPos,
            int jPos,
            int kPos,
            Planet.Side side,
            LargeMap map, LargeMap
            holes0Map,
            LargeMap holes0DepthMap,
            LargeMap holes1Map,
            LargeMap holes1DepthMap,
            LargeMap holes2Map,
            LargeMap holes2DepthMap
            )
        {
            Byte[][][] chunckData = new Byte[PlanetUtility.ChunckSize][][];
            int        size       = PlanetUtility.DegreeToSize(PlanetUtility.KPosToDegree(kPos));
            int        mapSize    = map.heightMap.Length;
            int        sizeRatio  = mapSize / size;

            float t2 = Time.realtimeSinceStartup;

            for (int i = 0; i < PlanetUtility.ChunckSize; i++)
            {
                chunckData[i] = new Byte[PlanetUtility.ChunckSize][];
                for (int j = 0; j < PlanetUtility.ChunckSize; j++)
                {
                    chunckData[i][j] = new Byte[PlanetUtility.ChunckSize];
                    for (int k = 0; k < PlanetUtility.ChunckSize; k++)
                    {
                        int iGlobal         = iPos * PlanetUtility.ChunckSize + i;
                        int jGlobal         = jPos * PlanetUtility.ChunckSize + j;
                        int kGlobal         = kPos * PlanetUtility.ChunckSize + k;
                        int heightThreshold = Mathf.FloorToInt(map.heightMap[iGlobal * sizeRatio][jGlobal * sizeRatio] * lowToHighPoint + lowestPoint);
                        int h0Alt           = Mathf.FloorToInt(holes0Map.heightMap[iGlobal * sizeRatio][jGlobal * sizeRatio] * lowToHighPoint + lowestPoint - lowToHighPoint / 2);
                        int h0Depth         = Mathf.FloorToInt(holes0DepthMap.heightMap[iGlobal * sizeRatio][jGlobal * sizeRatio] * lowToHighPoint / 2);
                        //h0Depth = 0;
                        int h1Alt   = Mathf.FloorToInt(holes1Map.heightMap[iGlobal * sizeRatio][jGlobal * sizeRatio] * lowToHighPoint + lowestPoint - lowToHighPoint);
                        int h1Depth = Mathf.FloorToInt(holes1DepthMap.heightMap[iGlobal * sizeRatio][jGlobal * sizeRatio] * lowToHighPoint / 2);
                        //h1Depth = 0;
                        int h2Alt   = Mathf.FloorToInt(holes2Map.heightMap[iGlobal * sizeRatio][jGlobal * sizeRatio] * lowToHighPoint + lowestPoint - 3 * lowToHighPoint / 2);
                        int h2Depth = Mathf.FloorToInt(holes2DepthMap.heightMap[iGlobal * sizeRatio][jGlobal * sizeRatio] * lowToHighPoint / 2);

                        BlockData data = BlockData.Empty;

                        // if k is under main heightMap threshold
                        if (kGlobal <= heightThreshold)
                        {
                            // if k is not in generated hole0
                            if ((kGlobal <= h0Alt) || (kGlobal >= h0Alt + h0Depth))
                            {
                                // if k is not in generated hole1
                                if ((kGlobal <= h1Alt) || (kGlobal >= h1Alt + h1Depth))
                                {
                                    // if k is not in generated hole2
                                    if ((kGlobal <= h2Alt) || (kGlobal >= h2Alt + h2Depth))
                                    {
                                        // then data is not empty, set rock as default
                                        data = BlockData.Rock;
                                        // compute depth of soil block (blocks that are not rocks)
                                        int soilDepth = Mathf.FloorToInt(Mathf.Abs(Mathf.Cos(i * 53 + j * 41 + k * 29) * 5) + 1);
                                        // if k is close to the surface of the map or of any hole
                                        if (
                                            ((kGlobal <= heightThreshold) && (heightThreshold - kGlobal < soilDepth)) ||
                                            ((kGlobal <= h0Alt) && (h0Alt - kGlobal < soilDepth)) ||
                                            ((kGlobal <= h1Alt) && (h1Alt - kGlobal < soilDepth)) ||
                                            ((kGlobal <= h2Alt) && (h2Alt - kGlobal < soilDepth)))
                                        {
                                            // then data is soil block
                                            data = GetSoilBlock(map.latMap [iGlobal * sizeRatio] [jGlobal * sizeRatio], iGlobal, jGlobal, kGlobal);
                                            // if data is Dirt
                                            if (data == BlockData.Dirt)
                                            {
                                                // and if data is strictly at surface of any hole
                                                if (
                                                    (kGlobal == heightThreshold) ||
                                                    (kGlobal == h0Alt))
                                                {
                                                    data = BlockData.Grass;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        /*
                         * if (kGlobal <= heightThreshold) {
                         *      // then data is not empty, set rock as default
                         *      data = BlockData.Rock;
                         *      // compute depth of soil block (blocks that are not rocks)
                         *      int soilDepth = Mathf.FloorToInt (Mathf.Abs (Mathf.Cos (i * 53 + j * 41 + k * 29) * 5) + 1);
                         *      if (heightThreshold - kGlobal < soilDepth) {
                         *              // then data is soil block
                         *              data = GetSoilBlock (map.latMap [iGlobal * sizeRatio] [jGlobal * sizeRatio], iGlobal, jGlobal, kGlobal);
                         *              // if data is Dirt
                         *              if (data == BlockData.Dirt) {
                         *                      // and if data is strictly at surface of any hole
                         *                      if (kGlobal == heightThreshold) {
                         *                              data = BlockData.Grass;
                         *                      }
                         *              }
                         *      }
                         * }
                         */
                        chunckData [i] [j] [k] = (byte)data;
                    }
                }
            }
            float t3 = Time.realtimeSinceStartup;

            tSetBytes += t3 - t2;

            return(chunckData);
        }
        private LargeMap GetLargeMapFor(RandomSeed seed, Planet.Side side, bool withLatMap = false)
        {
            float t0 = Time.realtimeSinceStartup;

            int      x, y, z;
            int      size     = PlanetUtility.DegreeToSize(PlanetUtility.KPosToDegree(this.kPosMax));
            string   mapName  = side + "-" + degreeAtKPosMax + "-" + seed.seed;
            bool     evaluate = false;
            LargeMap map      = Load(mapName, size);

            if (map == null)
            {
                map      = new LargeMap(size);
                evaluate = true;
            }

            if (side == Planet.Side.Top)
            {
                y = size;
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        x = size - j;
                        z = i;
                        if (evaluate)
                        {
                            map.heightMap[i][j] = EvaluateTriCubic(x, y, z, seed);
                        }
                        if (withLatMap)
                        {
                            map.latMap[i][j] = Mathf.Abs(Vector3.Angle(PlanetUtility.EvaluateVertex(size, x, y, z), Vector3.up) - 90f);
                        }
                    }
                }
            }
            else if (side == Planet.Side.Bottom)
            {
                y = 0;
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        x = j;
                        z = i;
                        if (evaluate)
                        {
                            map.heightMap[i][j] = EvaluateTriCubic(x, y, z, seed);
                        }
                        if (withLatMap)
                        {
                            map.latMap[i][j] = Mathf.Abs(Vector3.Angle(PlanetUtility.EvaluateVertex(size, x, y, z), Vector3.up) - 90f);
                        }
                    }
                }
            }
            else if (side == Planet.Side.Right)
            {
                x = size;
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        y = j;
                        z = i;
                        if (evaluate)
                        {
                            map.heightMap[i][j] = EvaluateTriCubic(x, y, z, seed);
                        }
                        if (withLatMap)
                        {
                            map.latMap[i][j] = Mathf.Abs(Vector3.Angle(PlanetUtility.EvaluateVertex(size, x, y, z), Vector3.up) - 90f);
                        }
                    }
                }
            }
            else if (side == Planet.Side.Left)
            {
                x = 0;
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        y = j;
                        z = size - i;
                        if (evaluate)
                        {
                            map.heightMap[i][j] = EvaluateTriCubic(x, y, z, seed);
                        }
                        if (withLatMap)
                        {
                            map.latMap[i][j] = Mathf.Abs(Vector3.Angle(PlanetUtility.EvaluateVertex(size, x, y, z), Vector3.up) - 90f);
                        }
                    }
                }
            }
            else if (side == Planet.Side.Front)
            {
                z = size;
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        y = j;
                        x = size - i;
                        if (evaluate)
                        {
                            map.heightMap[i][j] = EvaluateTriCubic(x, y, z, seed);
                        }
                        if (withLatMap)
                        {
                            map.latMap[i][j] = Mathf.Abs(Vector3.Angle(PlanetUtility.EvaluateVertex(size, x, y, z), Vector3.up) - 90f);
                        }
                    }
                }
            }
            else if (side == Planet.Side.Back)
            {
                z = 0;
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        y = j;
                        x = i;
                        if (evaluate)
                        {
                            map.heightMap[i][j] = EvaluateTriCubic(x, y, z, seed);
                        }
                        if (withLatMap)
                        {
                            map.latMap[i][j] = Mathf.Abs(Vector3.Angle(PlanetUtility.EvaluateVertex(size, x, y, z), Vector3.up) - 90f);
                        }
                    }
                }
            }
            Save(mapName, map);
            float t1 = Time.realtimeSinceStartup;

            tBuildHeightMap += t1 - t0;

            return(map);
        }
        private void Generate()
        {
            float t0    = Time.realtimeSinceStartup;
            float tSave = 0f;
            float tGet  = 0f;

            tBuildHeightMap = 0f;
            tSetBytes       = 0f;
            RandomSeed mapSeed             = new RandomSeed(this.planetName);
            RandomSeed holes0MapSeed       = new RandomSeed(this.planetName + "holes0Map");
            RandomSeed holes0HeightMapSeed = new RandomSeed(this.planetName + "holes0HeightMap");
            RandomSeed holes1MapSeed       = new RandomSeed(this.planetName + "holes1Map");
            RandomSeed holes1HeightMapSeed = new RandomSeed(this.planetName + "holes1HeightMap");
            RandomSeed holes2MapSeed       = new RandomSeed(this.planetName + "holes2Map");
            RandomSeed holes2HeightMapSeed = new RandomSeed(this.planetName + "holes2HeightMap");
            int        chunckSaved         = 0;
            int        chunckTotal         = 4242;

            this.degreeAtKPosMax = PlanetUtility.KPosToDegree(this.kPosMax);
            this.maxHeight       = PlanetUtility.ChunckSize * (this.kPosMax + 1);
            this.lowestPoint     = Mathf.FloorToInt(this.lowestPointPercent / 100f * this.maxHeight);
            this.highestPoint    = Mathf.FloorToInt(this.highestPointPercent / 100f * this.maxHeight);
            this.lowToHighPoint  = highestPoint - lowestPoint;

            foreach (Planet.Side side in Enum.GetValues(typeof(Planet.Side)))
            {
                LargeMap map             = GetLargeMapFor(mapSeed, side, true);
                LargeMap holes0Map       = GetLargeMapFor(holes0MapSeed, side);
                LargeMap holes0HeightMap = GetLargeMapFor(holes0HeightMapSeed, side);
                LargeMap holes1Map       = GetLargeMapFor(holes1MapSeed, side);
                LargeMap holes1HeightMap = GetLargeMapFor(holes1HeightMapSeed, side);
                LargeMap holes2Map       = GetLargeMapFor(holes2MapSeed, side);
                LargeMap holes2HeightMap = GetLargeMapFor(holes2HeightMapSeed, side);

                for (int kPos = 0; kPos <= this.kPosMax; kPos++)
                {
                    int chuncksCount = PlanetUtility.DegreeToChuncksCount(PlanetUtility.KPosToDegree(kPos));
                    for (int iPos = 0; iPos < chuncksCount; iPos++)
                    {
                        for (int jPos = 0; jPos < chuncksCount; jPos++)
                        {
                            float      t2         = Time.realtimeSinceStartup;
                            Byte[][][] chunckData = GetByteFor(iPos, jPos, kPos, side, map, holes0Map, holes0HeightMap, holes1Map, holes1HeightMap, holes2Map, holes2HeightMap);
                            float      t3         = Time.realtimeSinceStartup;
                            tGet += (t3 - t2);

                            float t4 = Time.realtimeSinceStartup;
                            if (this.babylonJSVersion)
                            {
                                PlanetUtility.SaveForBabylonJSVersion(this.planetName, chunckData, iPos, jPos, kPos, side);
                            }
                            else
                            {
                                PlanetUtility.Save(this.planetName, chunckData, iPos, jPos, kPos, side);
                            }
                            float t5 = Time.realtimeSinceStartup;
                            tSave += (t5 - t4);

                            chunckSaved++;
                            EditorUtility.DisplayProgressBar("Planet Data Generator", "Saving chunck datas for side " + side + " (" + ((int)side + 1) + "/6)...", (float)chunckSaved / (float)chunckTotal);
                        }
                    }
                }
            }
            float t1 = Time.realtimeSinceStartup;

            this.SavePlanetInfoFile();
            EditorUtility.ClearProgressBar();
            this.output += "Total time to create files : " + (t1 - t0) + "s.\n";
            this.output += "  Including time to compute block byte : " + tGet + "s.\n";
            this.output += "    Including time to build heightMap : " + tBuildHeightMap + "s.\n";
            this.output += "    Including time to set bytes : " + tSetBytes + "s.\n";
            this.output += "  Including time to save files : " + tSave + "s.\n";
            this.output += "MinValue : " + this.minValue + ".\n";
            this.output += "MaxValue : " + this.maxValue + ".\n";
            this.output += "MedianValue : " + (this.valuesSum / this.valuesCount) + ".\n";
            this.output += "KPosMax : " + this.kPosMax + ".\n";
            this.output += "MaxHeight : " + this.maxHeight + ".\n";
            this.output += "LowestPoint : " + this.lowestPoint + ".\n";
            this.output += "LowToHighPoint : " + this.lowToHighPoint + ".\n";
            this.output += "HighestPoint : " + this.highestPoint + ".\n";
        }