예제 #1
0
        private void UpdateWaters()
        {
            foreach (var planet in PlanetMap.Values)
            {
                WaterData data;
                if (WaterApi.HasWater(planet.EntityId))
                {
                    if (!WaterMap.TryGetValue(planet.EntityId, out data))
                    {
                        data = new WaterData(planet);
                        WaterMap[planet.EntityId] = data;
                    }

                    var radiusInfo = WaterApi.GetRadiusData(data.WaterId);
                    data.Center    = radiusInfo.Item1;
                    data.Radius    = radiusInfo.Item2;
                    data.MinRadius = radiusInfo.Item3;
                    data.MaxRadius = radiusInfo.Item3;
                    var waveInfo = WaterApi.GetWaveData(data.WaterId);
                    data.WaveHeight = waveInfo.Item1;
                    data.WaveSpeed  = waveInfo.Item2;
                }
                else
                {
                    WaterMap.TryRemove(planet.EntityId, out data);
                }
            }
        }
예제 #2
0
    private static void Restore()
    {
        if (!HasValidTerrain())
        {
            return;
        }

        Debug.Log("Script reload detected. Attempting to restore texture data...");

        string path = Path.Combine(Application.dataPath, "splat.bytes");

        if (File.Exists(path))
        {
            TerrainMap <byte> byteMap = new TerrainMap <byte>(File.ReadAllBytes(path), 8);
            Splat = new SplatMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Splat Maps");
        }

        path = Path.Combine(Application.dataPath, "biome.bytes");
        if (File.Exists(path))
        {
            TerrainMap <byte> byteMap = new TerrainMap <byte>(File.ReadAllBytes(path), 4);
            Biome = new BiomeMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Biome Maps");
        }

        path = Path.Combine(Application.dataPath, "alpha.bytes");
        if (File.Exists(path))
        {
            TerrainMap <byte> byteMap = new TerrainMap <byte>(File.ReadAllBytes(path), 1);
            Alpha = new AlphaMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Alpha Maps");
        }

        path = Path.Combine(Application.dataPath, "topology.bytes");
        if (File.Exists(path))
        {
            TerrainMap <int> byteMap = new TerrainMap <int>(File.ReadAllBytes(path), 1);
            Topology = new TopologyMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Topology Maps");
        }

        path = Path.Combine(Application.dataPath, "water.bytes");
        if (File.Exists(path))
        {
            TerrainMap <short> byteMap = new TerrainMap <short>(File.ReadAllBytes(path), 1);
            Water = new WaterMap(byteMap);
            File.Delete(path);
            Debug.Log("Restored Water Maps");
        }
    }
예제 #3
0
 public TerrainMap(Heightmap hm, WaterMap wm)
 {
     this.xSize = hm.xSize;
     this.ySize = hm.ySize;
     this.grid  = new myTerrain[xSize, ySize];
     for (int x = 0; x < xSize; x++)
     {
         for (int y = 0; y < ySize; y++)
         {
             grid [x, y] = new myTerrain(hm.grid [x, y], wm.grid [x, y]);
         }
     }
 }
예제 #4
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            /*physical = mapObject.GetComponent<PhysicalMap>();
             * physical.init(xSize, ySize);
             * HeightMapGenerator hgen = new HeightMapGenerator();
             * Heightmap heightmap = hgen.generateMap(xSize, ySize);
             * WaterMap watermap = new WaterMap(heightmap);
             * terrainmap = new TerrainMap(heightmap, watermap);
             * temperaturemap = new TemperatureMap(terrainmap, Random.Range(0, 11));
             * tr = new TemperatureRenderer(new LandmassMap(terrainmap), temperaturemap);
             * physical.draw(tr);*/
            physical = mapObject.GetComponent <PhysicalMap>();
            physical.init(xSize, ySize);
            MapSerializable mser      = MapSerializable.loadFromFile("testHM");
            Heightmap       heightmap = new Heightmap(xSize, ySize, 0.5f, mser.grid);
            WaterMap        watermap  = new WaterMap(heightmap);
            terrainmap     = new TerrainMap(heightmap, watermap);
            mser           = MapSerializable.loadFromFile("testTM");
            temperaturemap = new TemperatureMap(xSize, ySize, mser.grid, terrainmap);
            tr             = new TemperatureRenderer(new LandmassMap(terrainmap), temperaturemap);
            physical.draw(tr);
        }
        if (Input.GetMouseButtonDown(1))
        {
            if (state == 0)
            {
                RecursiveWindGenerator wgen = new RecursiveWindGenerator(temperaturemap);
                wm = new WindMap(xSize, ySize, terrainmap, temperaturemap, 3);

                WindSpeedRenderer     wsr = new WindSpeedRenderer(wm, new LandmassMap(terrainmap));
                WindDirectionRenderer wdr = new WindDirectionRenderer(wm, new LandmassMap(terrainmap));

                physical.draw(wsr);
                state++;
            }
            else if (state >= 1)
            {
                RecursiveWindGenerator wgen = new RecursiveWindGenerator(temperaturemap);
                wm = new WindMap(xSize, ySize, terrainmap, temperaturemap, state);

                WindSpeedRenderer     wsr = new WindSpeedRenderer(wm, new LandmassMap(terrainmap));
                WindDirectionRenderer wdr = new WindDirectionRenderer(wm, new LandmassMap(terrainmap));

                physical.draw(wdr);
                state++;
            }
        }
    }
예제 #5
0
 private void WApiReceiveData()
 {
     if (WApi.Registered)
     {
         WaterMap.Clear();
         MaxWaterHeightSqr.Clear();
         for (int i = 0; i < WApi.Waters.Count; i++)
         {
             var water = WApi.Waters[i];
             if (water.planet != null)
             {
                 WaterMap[water.planet] = water;
                 var maxWaterHeight    = water.radius;
                 var maxWaterHeightSqr = maxWaterHeight * maxWaterHeight;
                 MaxWaterHeightSqr[water.planet] = maxWaterHeightSqr;
             }
         }
     }
 }
        private bool PourWater()
        {
            rainCounter++;
            if (rainCounter >= Configs.RainInterval && Configs.RainIntensity != 0)
            {
                rainCounter = 0;

                // Loop geral do mapa
                for (int x = 0; x < WaterMap.GetLength(0); x++)
                {
                    for (int y = 0; y < WaterMap.GetLength(1); y++)
                    {
                        WaterMap[x, y] += Configs.RainIntensity * SurfacePourModifiers[SurfaceMap[x, y]];
                    }
                }

                return(true);
            }

            return(false);
        }
예제 #7
0
    public IEnumerator Load(World.Data world)
    {
        ActionProgressBar.UpdateProgress("Loading Terrain", 0f);
        yield return(null);

        yield return(null);

        Splat    = new SplatMap(world.splatMap);
        Alpha    = new AlphaMap(world.alphaMap);
        Biome    = new BiomeMap(world.biomeMap);
        Topology = new TopologyMap(world.topologyMap);
        Water    = new WaterMap(world.waterMap);

        TerrainData terrainData = new TerrainData();

        terrainData.alphamapResolution  = Mathf.Clamp(Mathf.NextPowerOfTwo((int)(world.size.x * 0.50f)), 16, 2048);
        terrainData.baseMapResolution   = Mathf.NextPowerOfTwo((int)((float)(world.size.x) * 0.01f));
        terrainData.heightmapResolution = Mathf.NextPowerOfTwo((int)((float)(world.size.x) * 0.5f)) + 1;

        terrainData.size = world.size;

        terrainData.SetHeights(0, 0, world.landHeightMap);

        Terrain = Terrain.CreateTerrainGameObject(terrainData).GetComponent <Terrain>();

        Terrain.name = Terrain.tag = "Terrain";

        Terrain.gameObject.layer = 8;

        Terrain.transform.position = -0.5f * terrainData.size;

        Terrain.gameObject.AddComponent <PositionLock>();

        SetSplatMaps(PaintType.Splat);

        CreateWaterPlane(world.size.x);
    }