public TerrainChannel Copy()
        {
            TerrainChannel copy = new TerrainChannel();

            copy.m_terrainData = m_terrainData.Clone();
            return(copy);
        }
Exemple #2
0
        public ITerrainChannel MakeCopy()
        {
            TerrainChannel copy = new TerrainChannel(false, m_scene);

            copy.m_map = (short[])m_map.Clone();
            copy.taint = (bool[, ])taint.Clone();
            return(copy);
        }
        public TerrainChannel Copy()
        {
            TerrainChannel copy = new TerrainChannel(false);

            copy.map = (double[, ])map.Clone();

            return(copy);
        }
Exemple #4
0
        public ITerrainChannel LoadStream(Stream s)
        {
            TerrainChannel retval = new TerrainChannel();

            BinaryReader bs = new BinaryReader(s);

            bool eof = false;
            if (Encoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN ")
            {
                int w = 256;
                int h = 256;

                // Terragen file
                while (eof == false)
                {
                    string tmp = Encoding.ASCII.GetString(bs.ReadBytes(4));
                    switch (tmp)
                    {
                        case "SIZE":
                            int sztmp = bs.ReadInt16() + 1;
                            w = sztmp;
                            h = sztmp;
                            bs.ReadInt16();
                            break;
                        case "XPTS":
                            w = bs.ReadInt16();
                            bs.ReadInt16();
                            break;
                        case "YPTS":
                            h = bs.ReadInt16();
                            bs.ReadInt16();
                            break;
                        case "ALTW":
                            eof = true;
                            Int16 heightScale = bs.ReadInt16();
                            Int16 baseHeight = bs.ReadInt16();
                            retval = new TerrainChannel(w, h);
                            int x;
                            for (x = 0; x < w; x++)
                            {
                                int y;
                                for (y = 0; y < h; y++)
                                {
                                    retval[x, y] = baseHeight + bs.ReadInt16() * (double) heightScale / 65536.0;
                                }
                            }
                            break;
                        default:
                            bs.ReadInt32();
                            break;
                    }
                }
            }

            bs.Close();

            return retval;
        }
Exemple #5
0
        public void BrushTest()
        {
            int midRegion = (int)Constants.RegionSize / 2;

            // Create a mask that covers only the left half of the region
            bool[,] allowMask = new bool[(int)Constants.RegionSize, 256];
            int x;
            int y;
            for (x = 0; x < midRegion; x++)
            {
                for (y = 0; y < (int)Constants.RegionSize; y++)
                {
                    allowMask[x,y] = true;
                }
            }

            //
            // Test RaiseSphere
            //
            TerrainChannel map = new TerrainChannel((int)Constants.RegionSize, (int)Constants.RegionSize);
            ITerrainPaintableEffect effect = new RaiseSphere();

            effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0,
                0, midRegion - 1,0, (int)Constants.RegionSize -1);
            Assert.That(map[127, midRegion] > 0.0, "Raise brush should raising value at this point (127,128).");
            Assert.That(map[125, midRegion] > 0.0, "Raise brush should raising value at this point (124,128).");
            Assert.That(map[120, midRegion] == 0.0, "Raise brush should not change value at this point (120,128).");
            Assert.That(map[128, midRegion] == 0.0, "Raise brush should not change value at this point (128,128).");
//            Assert.That(map[0, midRegion] == 0.0, "Raise brush should not change value at this point (0,128).");
            //
            // Test LowerSphere
            //
            map = new TerrainChannel((int)Constants.RegionSize, (int)Constants.RegionSize);
            for (x=0; x<map.Width; x++)
            {
                for (y=0; y<map.Height; y++)
                {
                    map[x,y] = 1.0;
                }
            }
            effect = new LowerSphere();

            effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0,
                0, (int)Constants.RegionSize -1,0, (int)Constants.RegionSize -1);
            Assert.That(map[127, midRegion] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128).");
            Assert.That(map[127, midRegion] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128).");
            Assert.That(map[125, midRegion] < 1.0, "Lower brush should lowering value at this point (124,128).");
            Assert.That(map[120, midRegion] == 1.0, "Lower brush should not change value at this point (120,128).");
            Assert.That(map[128, midRegion] == 1.0, "Lower brush should not change value at this point (128,128).");
//            Assert.That(map[0, midRegion] == 1.0, "Lower brush should not change value at this point (0,128).");
        }
        public virtual ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int w, int h)
        {
            Bitmap bitmap = new Bitmap(filename);
            ITerrainChannel retval = new TerrainChannel(true);

            for (int x = 0; x < retval.Width; x++)
            {
                for (int y = 0; y < retval.Height; y++)
                {
                    retval[x, y] = bitmap.GetPixel(offsetX * retval.Width + x, (bitmap.Height - (retval.Height * (offsetY + 1))) + retval.Height - y - 1).GetBrightness() * 128;
                }
            }

            return retval;
        }
        protected virtual ITerrainChannel LoadBitmap(Bitmap bitmap)
        {
            ITerrainChannel retval = new TerrainChannel(bitmap.Width, bitmap.Height);

            int x;
            for (x = 0; x < bitmap.Width; x++)
            {
                int y;
                for (y = 0; y < bitmap.Height; y++)
                {
                    retval[x, y] = bitmap.GetPixel(x, bitmap.Height - y - 1).GetBrightness() * 128;
                }
            }

            return retval;
        }
        public void BrushTest()
        {
            bool[,] allowMask = new bool[(int)Constants.RegionSize, 256];
            int x;
            int y;
            for (x = 0; x < (int)((int)Constants.RegionSize * 0.5f); x++)
            {
                for (y = 0; y < (int)Constants.RegionSize; y++)
                {
                    allowMask[x,y] = true;
                }
            }

            //
            // Test RaiseSphere
            //
            TerrainChannel map = new TerrainChannel((int)Constants.RegionSize, (int)Constants.RegionSize);
            ITerrainPaintableEffect effect = new RaiseSphere();

            effect.PaintEffect(map, allowMask, (int)Constants.RegionSize * 0.5f, (int)Constants.RegionSize * 0.5f, -1.0, 2, 0.1);
            Assert.That(map[127, (int)((int)Constants.RegionSize * 0.5f)] > 0.0, "Raise brush should raising value at this point (127,128).");
            Assert.That(map[124, (int)((int)Constants.RegionSize * 0.5f)] > 0.0, "Raise brush should raising value at this point (124,128).");
            Assert.That(map[123, (int)((int)Constants.RegionSize * 0.5f)] == 0.0, "Raise brush should not change value at this point (123,128).");
            Assert.That(map[128, (int)((int)Constants.RegionSize * 0.5f)] == 0.0, "Raise brush should not change value at this point (128,128).");
            Assert.That(map[0, (int)((int)Constants.RegionSize * 0.5f)] == 0.0, "Raise brush should not change value at this point (0,128).");

            //
            // Test LowerSphere
            //
            map = new TerrainChannel((int)Constants.RegionSize, (int)Constants.RegionSize);
            for (x=0; x<map.Width; x++)
            {
                for (y=0; y<map.Height; y++)
                {
                    map[x,y] = 1.0;
                }
            }
            effect = new LowerSphere();

            effect.PaintEffect(map, allowMask, ((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), -1.0, 2, 6.0);
            Assert.That(map[127, (int)((int)Constants.RegionSize * 0.5f)] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128).");
            Assert.That(map[127, (int)((int)Constants.RegionSize * 0.5f)] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128).");
            Assert.That(map[124, (int)((int)Constants.RegionSize * 0.5f)] < 1.0, "Lower brush should lowering value at this point (124,128).");
            Assert.That(map[123, (int)((int)Constants.RegionSize * 0.5f)] == 1.0, "Lower brush should not change value at this point (123,128).");
            Assert.That(map[128, (int)((int)Constants.RegionSize * 0.5f)] == 1.0, "Lower brush should not change value at this point (128,128).");
            Assert.That(map[0, (int)((int)Constants.RegionSize * 0.5f)] == 1.0, "Lower brush should not change value at this point (0,128).");
        }
Exemple #9
0
        public void BrushTest()
        {
            bool[,] allowMask = new bool[256, 256];
            int x;
            int y;
            for (x=0; x<128; x++)
            {
                for (y=0; y<256; y++)
                {
                    allowMask[x,y] = true;
                }
            }

            //
            // Test RaiseSphere
            //
            TerrainChannel map = new TerrainChannel(256, 256);
            ITerrainPaintableEffect effect = new RaiseSphere();

            effect.PaintEffect(map, allowMask, 128.0, 128.0, -1.0, 2, 0.1);
            Assert.That(map[127, 128] > 0.0, "Raise brush should raising value at this point (127,128).");
            Assert.That(map[124, 128] > 0.0, "Raise brush should raising value at this point (124,128).");
            Assert.That(map[123, 128] == 0.0, "Raise brush should not change value at this point (123,128).");
            Assert.That(map[128, 128] == 0.0, "Raise brush should not change value at this point (128,128).");
            Assert.That(map[0, 128] == 0.0, "Raise brush should not change value at this point (0,128).");

            //
            // Test LowerSphere
            //
            map = new TerrainChannel(256, 256);
            for (x=0; x<map.Width; x++)
            {
                for (y=0; y<map.Height; y++)
                {
                    map[x,y] = 1.0;
                }
            }
            effect = new LowerSphere();

            effect.PaintEffect(map, allowMask, 128.0, 128.0, -1.0, 2, 6.0);
            Assert.That(map[127, 128] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128).");
            Assert.That(map[127, 128] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128).");
            Assert.That(map[124, 128] < 1.0, "Lower brush should lowering value at this point (124,128).");
            Assert.That(map[123, 128] == 1.0, "Lower brush should not change value at this point (123,128).");
            Assert.That(map[128, 128] == 1.0, "Lower brush should not change value at this point (128,128).");
            Assert.That(map[0, 128] == 1.0, "Lower brush should not change value at this point (0,128).");
        }
Exemple #10
0
 public ITerrainChannel MakeCopy()
 {
     TerrainChannel copy = new TerrainChannel(false, m_scene);
     copy.m_map = (short[])m_map.Clone();
     copy.taint = (bool[,])taint.Clone();
     return copy;
 }
Exemple #11
0
        /// <summary>
        /// Loads the World heightmap
        /// </summary>
        public override void LoadWorldMap()
        {
            try
            {
                double[,] map = m_storageManager.DataStore.LoadTerrain(RegionInfo.RegionID);
                if (map == null)
                {
                    m_log.Info("[TERRAIN]: No default terrain. Generating a new terrain.");
                    Heightmap = new TerrainChannel();

                    m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
                }
                else
                {
                    Heightmap = new TerrainChannel(map);
                }
            }
            catch (Exception e)
            {
                m_log.Warn("[TERRAIN]: Scene.cs: LoadWorldMap() - Failed with exception " + e.ToString());
            }
        }
Exemple #12
0
 /// <summary>
 /// Reset the terrain of this region to the default
 /// </summary>
 public void ResetWater()
 {
     TerrainChannel channel = new TerrainChannel(m_scene);
     m_waterChannel = channel;
     SaveRevertWater(m_waterChannel);
     CheckForTerrainUpdates(false, true, true);
 }
Exemple #13
0
 /// <summary>
 ///   Reset the terrain of this region to the default
 /// </summary>
 public void ResetTerrain()
 {
     if (!m_noTerrain)
     {
         TerrainChannel channel = new TerrainChannel(m_scene);
         m_channel = channel;
         m_scene.SimulationDataService.Tainted();
         m_scene.RegisterModuleInterface(m_channel);
         CheckForTerrainUpdates(false, true, false);
     }
 }
Exemple #14
0
        public ITerrainChannel MakeCopy()
        {
            TerrainChannel copy = new TerrainChannel(false);
            copy.map = (double[,]) map.Clone();

            return copy;
        }
Exemple #15
0
        public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight)
        {
            TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight);

            FileInfo file = new FileInfo(filename);
            FileStream s = file.Open(FileMode.Open, FileAccess.Read);
            BinaryReader bs = new BinaryReader(s);

            int currFileYOffset = 0;

            // if our region isn't on the first Y section of the areas to be landscaped, then
            // advance to our section of the file
            while (currFileYOffset < offsetY)
            {
                // read a whole strip of regions
                int heightsToRead = sectionHeight * (fileWidth * sectionWidth);
                bs.ReadBytes(heightsToRead * 4); // because the floats are 4 bytes in the file
                currFileYOffset++;
            }

            // got to the Y start offset within the file of our region
            // so read the file bits associated with our region
            int y;
            // for each Y within our Y offset
            for (y = 0; y < sectionHeight; y++)
            {
                int currFileXOffset = 0;

                // if our region isn't the first X section of the areas to be landscaped, then
                // advance the stream to the X start pos of our section in the file
                // i.e. eat X upto where we start
                while (currFileXOffset < offsetX)
                {
                    bs.ReadBytes(sectionWidth * 4); // 4 bytes = single
                    currFileXOffset++;
                }

                // got to our X offset, so write our regions X line
                int x;
                for (x = 0; x < sectionWidth; x++)
                {
                    // Read a strip and continue
                    retval[x, y] = bs.ReadSingle();
                }
                // record that we wrote it
                currFileXOffset++;

                // if our region isn't the last X section of the areas to be landscaped, then
                // advance the stream to the end of this Y column
                while (currFileXOffset < fileWidth)
                {
                    // eat the next regions x line
                    bs.ReadBytes(sectionWidth * 4); // 4 bytes = single
                    currFileXOffset++;
                }
            }

            bs.Close();
            s.Close();

            return retval;
        }
        /// <summary>
        /// This method will produce a random city with the central region of the city being
        /// specified as a parameter. More parameters need to be made available for this method
        /// to produce a better quality city, note for now the minimum area for a city is a
        /// 3x3 grid of regions. This code is based on the original C++ version called pixel city.
        /// </summary>
        /// <param name="seed_value">Random integer seed value.</param>
        /// <returns>true / false indicator of success or failure.</returns>
        private bool doGenerate(int seed_value)
        {
            int rx, ry;
            //  Based on the initial seed value populate the regions that this shared module
            // is connected to, this means first get a list of the region, determine which
            // region is in the center of all the regions and set this as the hotzone, or
            // central part of the city (this is where the tallest/largest buildings will
            // be created) and will extend out to cover virtually all of the connected
            // regions if desired. No support for aging of the buildings or the city exists
            // yet it is a possible course for the future of this module.

            //  First quick check to see if the module is enabled or not.
            if (!m_fEnabled)
            {
                m_log.Info("[CITY BUILDER]: Disabled, aborting auto generation.");
                return (false);
            }

            m_log.Info("[CITY BUILDER]: Auto generating the city.");

            //  Now we need to ask some basic values for the city generation, we already have
            // the base seed value as this is part of the 'city generate' command, now what
            // about a name, position, size, densities etc. Some of this can be generated
            // based on the seed value, but then, it would need to be confirmed by the user
            // or allow them to change it. TODO move all requested data into the configuration file.
            if (m_UserAccountService == null)
            {
                m_UserAccountService = simulationBase.ApplicationRegistry.RequestModuleInterface<IUserAccountService>();
            }

            //  Decide where the city is to be placed within the server instance.
            int r = this.randomValue(10);

            string regionCount = MainConsole.Instance.CmdPrompt("Region Count ", r.ToString());
            r = Convert.ToInt32(regionCount);
            m_log.InfoFormat("[CITY BUILDER]: City area {0} x {1} regions ", r, r);

            cityName = MainConsole.Instance.CmdPrompt("City Name ", cityName);
            cityOwner = MainConsole.Instance.CmdPrompt("City Owner ", cityOwner);
            m_DefaultUserName = cityOwner;

            //  Make sure that the user and estate information specified in the configuration file
            // have been loaded and the information has either been found or has been created.
            m_DefaultUserAccount = m_UserAccountService.GetUserAccount(UUID.Zero, cityOwner);
            if (m_DefaultUserAccount == null)
            {
                m_log.InfoFormat("[CITY BUILDER]: Creating default account {0}", m_DefaultUserName);
                m_UserAccountService.CreateUser(m_DefaultUserName, Util.Md5Hash(m_DefaultUserPword), m_DefaultUserEmail);
                m_DefaultUserAccount = m_UserAccountService.GetUserAccount(UUID.Zero, m_DefaultUserName);
                cityOwner = m_DefaultUserName;
            }
            else
                m_log.InfoFormat("[CITY BUILDER]: Account found for {0}", m_DefaultUserName);

            // Obtain the scene manager that the server instance is using.
            sceneManager = simulationBase.ApplicationRegistry.RequestModuleInterface<SceneManager>();

            //  Construct the data instance for a city map to hold the total regions in the simulation.
            cityMap = new CityMap();
            citySeed = seed_value;
            cityMap.cityRegions = new Scene[r, r];
            cityMap.cityPlots = new List<BuildingPlot>();
            cityMap.cityBuildings = new List<CityBuilding>();

            //  Construct land and estate data and update to reflect the found user or the newly created one.
            cityLandData = new LandData();
            RegionInfo regionInfo = new RegionInfo();

            regionInfo.RegionID = UUID.Random();

            //Create an estate
            m_DefaultEstate = new EstateSettings();

            m_log.InfoFormat("[CITY BUILDER]: No estates found for user {0}, constructing default estate.", m_DefaultUserAccount.Name);

            m_DefaultEstate.EstateOwner = m_DefaultUserAccount.PrincipalID;
            m_DefaultEstate.EstateName = m_DefaultEstateName;
            m_DefaultEstate.EstatePass = Util.Md5Hash(Util.Md5Hash(m_DefaultEstatePassword));
            m_DefaultEstate.EstateID = (uint)this.randomValue(1000);

            regionInfo.EstateSettings = m_DefaultEstate; //Just set the estate, this module took care of the loading and the rest will leave it alone

            cityLandData.OwnerID = m_DefaultUserAccount.PrincipalID;
            cityLandData.Name = m_DefaultEstateName;
            cityLandData.GlobalID = UUID.Random();
            cityLandData.GroupID = UUID.Zero;

            int regionPort = startPort;

            //  Construct the region.
            regionInfo.RegionSizeX = cityConfig.GetInt("DefaultRegionSize", 256);
            regionInfo.RegionSizeY = regionInfo.RegionSizeX;
            regionInfo.RegionType = "Mainland";
            regionInfo.ObjectCapacity = 100000;
            regionInfo.Startup = StartupType.Normal;
            regionInfo.ScopeID = UUID.Zero;

            IParcelServiceConnector parcelService = Aurora.DataManager.DataManager.RequestPlugin<IParcelServiceConnector>();
            if (r == 1)
            {
                m_log.Info("[CITY BUILDER]: Single region city.");
                IPAddress address = IPAddress.Parse("0.0.0.0");
                regionInfo.ExternalHostName = Aurora.Framework.Utilities.GetExternalIp();
                regionInfo.FindExternalAutomatically = true;
                regionInfo.InternalEndPoint = new IPEndPoint(address, regionPort++);
                cityLandData.RegionID = regionInfo.RegionID;
                if(parcelService != null)
                    parcelService.StoreLandObject(cityLandData.LandData);
                regionInfo.RegionName = "Region00";
                regionInfo.RegionLocX = (int)m_DefaultStartLocation.X;
                regionInfo.RegionLocY = (int)m_DefaultStartLocation.Y;
                if (!createRegion(0, 0, regionInfo))
                {
                    m_log.Info("[CITY BUILDER]: Failed to construct region.");
                    return (false);
                }
            }
            else if (r > 1)
            {
                m_log.Info("[CITY BUILDER]: Multi-region city.");
                IPAddress address = IPAddress.Parse("0.0.0.0");
                regionInfo.ExternalHostName = Aurora.Framework.Utilities.GetExternalIp();
                regionInfo.FindExternalAutomatically = true;
                //  Construct the regions for the city.
                regionPort = startPort;
                for (rx = 0; rx < r; rx++)
                {
                    for (ry = 0; ry < r; ry++)
                    {
                        regionInfo.InternalEndPoint = new IPEndPoint(address, regionPort++);
                        cityLandData.RegionID = regionInfo.RegionID;
                        if(parcelService != null)
                            parcelService.StoreLandObject(cityLandData.LandData);
                        regionInfo.RegionName = "Region" + rx + ry;
                        regionInfo.RegionLocX = (int)(m_DefaultStartLocation.X + rx);
                        regionInfo.RegionLocY = (int)(m_DefaultStartLocation.Y + ry);
                        m_log.InfoFormat("[CITY BUILDER]: '{0}' @ {1},{2}, http://{3}/", regionInfo.RegionName,
                            regionInfo.RegionLocX, regionInfo.RegionLocY, regionInfo.InternalEndPoint);
                        //We already set the estate before, we don't need to deal with linking it or anything
                        //EstateConnector.LinkRegion(regionInfo.RegionID, (int)m_DefaultEstate.EstateID, m_DefaultEstate.EstatePass);
                        if (!createRegion(rx, ry, regionInfo))
                        {
                            m_log.InfoFormat("[CITY BUILDER]: Failed to construct region at {0},{1}", rx, ry);
                            return (false);
                        }
                    }
                }
            }

            //  Either generate the terrain or loading from an existing file, DEM for example.
            m_log.Info("[CITY BUILDER]: [TERRAIN]");

            //  For each region, just fill the terrain to be 21. This is just above the default
            // water level for Aurora.
            float[,] tHeight = new float[256, 256];
            for (rx = 0; rx < 256; rx++)
            {
                for (ry = 0; ry < 256; ry++)
                {
                    tHeight[rx, ry] = 21.0f;
                }
            }
            //  Construct the new terrain for each region and pass the height map to it.
            for (rx = 0; rx < r; rx++)
            {
                for (ry = 0; ry < r; ry++)
                {
                    Scene region = cityMap.cityRegions[rx, ry];
                    ITerrainChannel tChannel = new TerrainChannel(true, region);
                    ITerrain terrain = null;
                    try
                    {
                        region.TryRequestModuleInterface<ITerrain>(out terrain);
                        terrain.SetHeights2D(tHeight);
                    }
                    catch
                    {
                    }
                }
            }

            //  Rivers and other waterways.

            //  From the total number of regions pick a number of regions that will be 'centers'
            // for the entire city, record these in the centralRegions list.
            m_log.Info("[CITY BUILDER]: [CENTERS]");
            //  ( region count * region count ) / 3
            int aNum = this.randomValue((cityMap.cityRegions.GetUpperBound(0) * cityMap.cityRegions.GetUpperBound(1))/3);
            if (aNum == 0)
            {
                aNum = 1;
            }
            m_log.InfoFormat("[CITY BUILDER]: Total regions {0}, selecting {1} regions for centers.", (r*r), aNum );
            int prevRegionX = 0;
            int prevRegionY = 0;
            while ( aNum > 0 )
            {
                int currRegionX = randomValue( cityMap.cityRegions.GetUpperBound(0) ) / 2;
                int currRegionY = randomValue( cityMap.cityRegions.GetUpperBound(1) ) / 2;

                // If the location selected is the same as the previous location try again.
                if (currRegionX == prevRegionX && currRegionY == prevRegionY)
                {
                    aNum--;
                    continue;
                }

                m_log.InfoFormat("[CITY BUILDER]: Region {0}, located {1},{2}", aNum, prevRegionX, prevRegionY);

                try
                {
                    Scene region = cityMap.centralRegions[(prevRegionX * cityMap.cityRegions.GetUpperBound(0)) + prevRegionY];
                    if (region!=null)
                    {
                        cityMap.centralRegions.Add(region);
                    }
                }
                catch
                {
                }
                aNum--;
                prevRegionX = currRegionX;
                prevRegionY = currRegionY;
            }

            m_log.Info("[CITY BUILDER]: [DENSITY]");
            float avgDensity = 0.0f;

            avgDensity += cityDensities[0];
            avgDensity += cityDensities[1];
            avgDensity += cityDensities[2];
            avgDensity += cityDensities[3];
            avgDensity /= 4;

            //  Before ANYTHING else is created construct the transport systems, priority is given
            // to the road network before the rail network, perhaps a configuration option to allow
            // for the prioritisation value of the transport system is possible.
            m_log.Info("[CITY BUILDER]: [FREEWAYS]");
            m_log.Info("[CITY BUILDER]: [HIGHWAYS]");
            m_log.Info("[CITY BUILDER]: [STREETS]");
            m_log.Info("[CITY BUILDER]: [RAILWAYS]");

            m_log.InfoFormat("[CITY BUILDER]: [RESIDENTIAL DENSITY] {0}%", cityDensities[0] * 100);
            m_log.InfoFormat("[CITY BUILDER]: [COMMERCIAL DENSITY] {0}%", cityDensities[1] * 100);
            m_log.InfoFormat("[CITY BUILDER]: [CORPORATE DENSITY] {0}%", cityDensities[2] * 100);
            m_log.InfoFormat("[CITY BUILDER]: [INDUSTRIAL DENISTY] {0}%", cityDensities[3] * 100);
            m_log.InfoFormat("[CITY BUILDER]: [AVERAGE DENSITY] {0}%", avgDensity);

            m_log.Info("[CITY BUILDER]: [BLOCKS]");
            m_log.Info("[CITY BUILDER]: [ALLOTMENT PLOTS]");
            m_log.Info("[CITY BUILDER]: [BUILDINGS]");

            return (true);
        }
 public virtual short[] LoadWater (IScene scene, bool RevertMap, int RegionSizeX, int RegionSizeY)
 {
     ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule> ();
     if (RevertMap)
     {
         if (m_revertWater == null)
             return null;
         ITerrainChannel channel = new TerrainChannel (false, scene);
         MemoryStream ms = new MemoryStream (m_revertWater);
         if (terrainModule != null)
             terrainModule.LoadWaterRevertMapFromStream (".r32", ms, 0, 0);
         m_revertWater = null;
         return null;
     }
     else
     {
         if (m_water == null)
             return null;
         ITerrainChannel channel = new TerrainChannel (false, scene);
         MemoryStream ms = new MemoryStream (m_water);
         if (terrainModule != null)
             terrainModule.LoadWaterFromStream (".r32", ms, 0, 0);
         m_water = null;
         return null;
     }
 }
 public virtual short[] LoadTerrain (IScene scene, bool RevertMap, int RegionSizeX, int RegionSizeY)
 {
     if (!m_loaded)
     {
         m_loaded = true;
         ReadConfig (scene, scene.Config.Configs["FileBasedSimulationData"]);
         ReadBackup (scene);
     }
     ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule> ();
     if (RevertMap)
     {
         ITerrainChannel channel = new TerrainChannel (false, scene);
         if (m_revertTerrain == null)
         {
             if (m_shortrevertTerrain != null)
                 terrainModule.TerrainRevertMap = new TerrainChannel (m_shortterrain, scene);
             return null;
         }
         MemoryStream ms = new MemoryStream (m_revertTerrain);
         if (terrainModule != null)
             terrainModule.LoadRevertMapFromStream (".r32", ms, 0, 0);
         m_revertTerrain = null;
         return null;
     }
     else
     {
         if (m_terrain == null)
         {
             if (m_shortterrain != null)
                 terrainModule.TerrainMap = new TerrainChannel (m_shortterrain, scene);
             return null;
         }
         ITerrainChannel channel = new TerrainChannel (false, scene);
         MemoryStream ms = new MemoryStream (m_terrain);
         if (terrainModule != null)
             terrainModule.LoadFromStream (".r32", ms, 0, 0);
         m_terrain = null;
         return null;
     }
 }
Exemple #19
0
 /// <summary>
 /// Loads the World Revert heightmap
 /// </summary>
 public ITerrainChannel LoadRevertMap()
 {
     try
     {
         double[,] map = SimulationDataService.LoadTerrain(RegionInfo.RegionID, true);
         if (map == null)
         {
             map = Heightmap.GetDoubles();
             TerrainChannel channel = new TerrainChannel(map);
             SaveRevertTerrain(channel);
             return channel;
         }
         return new TerrainChannel(map);
     }
     catch (Exception e)
     {
         m_log.Warn("[TERRAIN]: Scene.cs: LoadRevertMap() - Failed with exception " + e.ToString());
     }
     return Heightmap;
 }
Exemple #20
0
        public TerrainChannel Copy()
        {
            TerrainChannel copy = new TerrainChannel(false, m_scene);
            copy.map = (double[,]) map.Clone();

            return copy;
        }
Exemple #21
0
        public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight)
        {
            TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight);

            FileInfo file = new FileInfo(filename);
            FileStream s = file.Open(FileMode.Open, FileAccess.Read);
            BinaryReader bs = new BinaryReader(s);

            bool eof = false;

            int fileXPoints = 0;
//            int fileYPoints = 0;

            // Terragen file
            while (eof == false)
            {
                string tmp = Encoding.ASCII.GetString(bs.ReadBytes(4));
                switch (tmp)
                {
                    case "SIZE":
                        fileXPoints = bs.ReadInt16() + 1;
//                        fileYPoints = fileXPoints;
                        bs.ReadInt16();
                        break;
                    case "XPTS":
                        fileXPoints = bs.ReadInt16();
                        bs.ReadInt16();
                        break;
                    case "YPTS":
//                        fileYPoints = bs.ReadInt16();
                        bs.ReadInt16();
                        bs.ReadInt16();
                        break;
                    case "ALTW":
                        eof = true;
                        Int16 heightScale = bs.ReadInt16();
                        Int16 baseHeight = bs.ReadInt16();

                        int currFileYOffset = 0;

                        // if our region isn't on the first X section of the areas to be landscaped, then
                        // advance to our section of the file
                        while (currFileYOffset < offsetY)
                        {
                            // read a whole strip of regions
                            int heightsToRead = sectionHeight * fileXPoints;
                            bs.ReadBytes(heightsToRead * 2); // because the shorts are 2 bytes in the file
                            currFileYOffset++;
                        }

                        for (int y = 0; y < sectionHeight; y++)
                        {
                            int currFileXOffset = 0;

                            // if our region isn't the first X section of the areas to be landscaped, then
                            // advance the stream to the X start pos of our section in the file
                            // i.e. eat X upto where we start
                            while (currFileXOffset < offsetX)
                            {
                                bs.ReadBytes(sectionWidth * 2); // 2 bytes = short
                                currFileXOffset++;
                            }

                            // got to our X offset, so write our regions X line
                            for (int x = 0; x < sectionWidth; x++)
                            {
                                // Read a strip and continue
                                retval[x, y] = baseHeight + bs.ReadInt16() * (double)heightScale / 65536.0;
                            }
                            // record that we wrote it
                            currFileXOffset++;

                            // if our region isn't the last X section of the areas to be landscaped, then
                            // advance the stream to the end of this Y column
                            while (currFileXOffset < fileWidth)
                            {
                                // eat the next regions x line
                                bs.ReadBytes(sectionWidth * 2); // 2 bytes = short
                                currFileXOffset++;
                            }
                            //eat the last additional point
                            bs.ReadInt16();
                        }


                        break;
                    default:
                        bs.ReadInt32();
                        break;
                }
            }

            bs.Close();
            s.Close();

            return retval;
        }
        public virtual short[] LoadTerrain(IScene scene, bool RevertMap, int RegionSizeX, int RegionSizeY)
        {
            if (!m_loaded)
            {
                m_loaded = true;
                ReadConfig(scene, scene.Config.Configs["FileBasedSimulationData"]);
                ReadBackup(scene);
            }
            ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule>();
            if (RevertMap)
            {
                ITerrainChannel channel = new TerrainChannel(false, scene);
                if (m_revertTerrain == null)
                {
                    if (m_shortrevertTerrain != null) //OpenSim style
                        terrainModule.TerrainRevertMap = new TerrainChannel(m_shortrevertTerrain, scene);
                    else if (m_oldstylerevertTerrain != null)
                    {
                        MemoryStream ms = new MemoryStream(m_oldstylerevertTerrain);
                        if (terrainModule != null)
                            terrainModule.LoadRevertMapFromStream(".r32", ms, 0, 0);
                    }
                }
                else
                    //New style
                    terrainModule.TerrainRevertMap = ReadFromData(m_revertTerrain, scene);
                //Make sure the size is right!
                if (terrainModule.TerrainRevertMap != null &&
                    terrainModule.TerrainRevertMap.Height != scene.RegionInfo.RegionSizeX)
                    terrainModule.TerrainRevertMap = null;
                m_revertTerrain = null;
                m_oldstylerevertTerrain = null;
                m_shortrevertTerrain = null;
                return null;
            }
            else
            {
                if (m_terrain == null)
                {
                    if (m_shortterrain != null) //OpenSim style
                        terrainModule.TerrainMap = new TerrainChannel(m_shortterrain, scene);
                    else if (m_oldstyleterrain != null)
                    {
//Old style
                        ITerrainChannel channel = new TerrainChannel(false, scene);
                        MemoryStream ms = new MemoryStream(m_oldstyleterrain);
                        if (terrainModule != null)
                            terrainModule.LoadFromStream(".r32", ms, 0, 0);
                    }
                }
                else
                    //New style
                    terrainModule.TerrainMap = ReadFromData(m_terrain, scene);
                //Make sure the size is right!
                if (terrainModule.TerrainMap != null &&
                    terrainModule.TerrainMap.Height != scene.RegionInfo.RegionSizeX)
                    terrainModule.TerrainMap = null;
                m_terrain = null;
                m_oldstyleterrain = null;
                m_shortterrain = null;
                return null;
            }
        }
 public TerrainChannel Copy()
 {
     TerrainChannel copy = new TerrainChannel();
     copy.m_terrainData = m_terrainData.Clone();
     return copy;
 }
Exemple #24
0
        /// <summary>
        /// Loads the World heightmap
        /// </summary>
        public override void LoadWorldMap()
        {
            try
            {
                double[,] map = SimulationDataService.LoadTerrain(RegionInfo.RegionID);
                if (map == null)
                {
                    m_log.Info("[TERRAIN]: No default terrain. Generating a new terrain.");
                    Heightmap = new TerrainChannel();

                    SimulationDataService.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
                }
                else
                {
                    Heightmap = new TerrainChannel(map);
                }
            }
            catch (IOException e)
            {
                m_log.WarnFormat(
                    "[TERRAIN]: Scene.cs: LoadWorldMap() - Regenerating as failed with exception {0}{1}",
                    e.Message, e.StackTrace);

                // Non standard region size.    If there's an old terrain in the database, it might read past the buffer
#pragma warning disable 0162
                if ((int)Constants.RegionSize != 256)
                {
                    Heightmap = new TerrainChannel();

                    SimulationDataService.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
                }
            }
            catch (Exception e)
            {
                m_log.WarnFormat(
                    "[TERRAIN]: Scene.cs: LoadWorldMap() - Failed with exception {0}{1}", e.Message, e.StackTrace);
            }
        }
        public void TerrainChannelTest()
        {
            TerrainChannel x = new TerrainChannel((int)Constants.RegionSize, (int)Constants.RegionSize);
            Assert.That(x[0, 0] == 0.0, "Terrain not initialising correctly.");

            x[0, 0] = 1.0;
            Assert.That(x[0, 0] == 1.0, "Terrain not setting values correctly.");

            x[0, 0] = 0;
            x[0, 0] += 5.0;
            x[0, 0] -= 1.0;
            Assert.That(x[0, 0] == 4.0, "Terrain addition/subtraction error.");

            x[0, 0] = Math.PI;
            double[,] doublesExport = x.GetDoubles();
            Assert.That(doublesExport[0, 0] == Math.PI, "Export to double[,] array not working correctly.");

            x[0, 0] = 1.0;
            float[] floatsExport = x.GetFloatsSerialised();
            Assert.That(floatsExport[0] == 1.0f, "Export to float[] not working correctly.");

            x[0, 0] = 1.0;
            Assert.That(x.Tainted(0, 0), "Terrain channel tainting not working correctly.");
            Assert.That(!x.Tainted(0, 0), "Terrain channel tainting not working correctly.");

            TerrainChannel y = x.Copy();
            Assert.That(!ReferenceEquals(x, y), "Terrain copy not duplicating correctly.");
            Assert.That(!ReferenceEquals(x.GetDoubles(), y.GetDoubles()), "Terrain array not duplicating correctly.");
        }
Exemple #26
0
        public ITerrainChannel LoadStream(Stream s)
        {
            // The raw format doesn't contain any dimension information.
            // Guess the square dimensions by using the length of the raw file.
            double dimension = Math.Sqrt((double)(s.Length / 4));
            // Regions are always multiples of 256.
            int trimmedDimension = (int)dimension - ((int)dimension % (int)Constants.RegionSize);
            if (trimmedDimension < Constants.RegionSize)
                trimmedDimension = (int)Constants.RegionSize;

            TerrainChannel retval = new TerrainChannel(trimmedDimension, trimmedDimension);

            BinaryReader bs = new BinaryReader(s);
            int y;
            for (y = 0; y < retval.Height; y++)
            {
                int x;
                for (x = 0; x < retval.Width; x++)
                {
                    retval[x, y] = bs.ReadSingle();
                }
            }

            bs.Close();

            return retval;
        }
Exemple #27
0
 /// <summary>
 ///   Reset the terrain of this region to the default
 /// </summary>
 public void ResetWater()
 {
     if (!m_noTerrain)
     {
         TerrainChannel channel = new TerrainChannel(m_scene);
         m_waterChannel = channel;
         m_scene.SimulationDataService.Tainted();
         CheckForTerrainUpdates(false, true, true);
     }
 }
Exemple #28
0
        /// <summary>
        /// Loads the World heightmap
        /// </summary>
        public override void LoadWorldMap()
        {
            try
            {
                double[,] map = SimulationDataService.LoadTerrain(RegionInfo.RegionID);
                if (map == null)
                {
                    // This should be in the Terrain module, but it isn't because
                    // the heightmap is needed _way_ before the modules are initialized...
                    IConfig terrainConfig = m_config.Configs["Terrain"];
                    String m_InitialTerrain = "pinhead-island";
                    if (terrainConfig != null)
                        m_InitialTerrain = terrainConfig.GetString("InitialTerrain", m_InitialTerrain);

                    m_log.InfoFormat("[TERRAIN]: No default terrain. Generating a new terrain {0}.", m_InitialTerrain);
                    Heightmap = new TerrainChannel(m_InitialTerrain);

                    SimulationDataService.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
                }
                else
                {
                    Heightmap = new TerrainChannel(map);
                }
            }
            catch (IOException e)
            {
                m_log.WarnFormat(
                    "[TERRAIN]: Scene.cs: LoadWorldMap() - Regenerating as failed with exception {0}{1}",
                    e.Message, e.StackTrace);
                
                // Non standard region size.    If there's an old terrain in the database, it might read past the buffer
                #pragma warning disable 0162
                if ((int)Constants.RegionSize != 256)
                {
                    Heightmap = new TerrainChannel();

                    SimulationDataService.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
                }
            }
            catch (Exception e)
            {
                m_log.WarnFormat(
                    "[TERRAIN]: Scene.cs: LoadWorldMap() - Failed with exception {0}{1}", e.Message, e.StackTrace);
            }
        }
Exemple #29
0
 /// <summary>
 /// Reset the terrain of this region to the default
 /// </summary>
 public void ResetTerrain()
 {
     TerrainChannel channel = new TerrainChannel(m_scene);
     m_channel = channel;
     SaveRevertTerrain(channel);
     m_scene.RegisterModuleInterface<ITerrainChannel>(m_channel);
     CheckForTerrainUpdates(false, true, false);
 }
Exemple #30
0
        /// <summary>
        /// Loads the World heightmap
        /// </summary>
        public override void LoadWorldMap()
        {
            try
            {
                double[,] map = m_storageManager.DataStore.LoadTerrain(RegionInfo.RegionID);
                if (map == null)
                {
                    m_log.Info("[TERRAIN]: No default terrain. Generating a new terrain.");
                    Heightmap = new TerrainChannel();

                    m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
                }
                else
                {
                    Heightmap = new TerrainChannel(map);
                }
            }
            catch (IOException e)
            {
                m_log.Warn("[TERRAIN]: Scene.cs: LoadWorldMap() - Failed with exception " + e.ToString() + " Regenerating");
                
                // Non standard region size.    If there's an old terrain in the database, it might read past the buffer
                #pragma warning disable 0162
                if ((int)Constants.RegionSize != 256)
                {
                    Heightmap = new TerrainChannel();

                    m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
                }
            }
            catch (Exception e)
            {
                m_log.Warn("[TERRAIN]: Scene.cs: LoadWorldMap() - Failed with exception " + e.ToString());
            }
        }
Exemple #31
0
        /// <summary>
        ///   Loads a terrain file from a stream and installs it in the scene.
        /// </summary>
        /// <param name = "filename">Filename to terrain file. Type is determined by extension.</param>
        /// <param name = "stream"></param>
        public ITerrainChannel InternalLoadFromStream(string filename, Stream stream, int offsetX, int offsetY,
                                                      ITerrainChannel update)
        {
            ITerrainChannel channel = null;
#if (!ISWIN)
            foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
            {
                if (filename.EndsWith(loader.Key))
                {
                    lock (m_scene)
                    {
                        try
                        {
                            channel = loader.Value.LoadStream(stream, m_scene);
                            if (channel != null)
                            {
                                channel.Scene = m_scene;
                                if (update == null || (update.Height == channel.Height && update.Width == channel.Width))
                                {
                                    if (m_scene.RegionInfo.RegionSizeX != channel.Width || m_scene.RegionInfo.RegionSizeY != channel.Height)
                                    {
                                        if ((channel.Width) > m_scene.RegionInfo.RegionSizeX || (channel.Height) > m_scene.RegionInfo.RegionSizeY)
                                        {
                                            TerrainChannel c = new TerrainChannel(true, m_scene);
                                            for (int x = 0; x < m_scene.RegionInfo.RegionSizeX; x++)
                                            {
                                                for (int y = 0; y < m_scene.RegionInfo.RegionSizeY; y++)
                                                {
                                                    c[x, y] = channel[x, y];
                                                }
                                            }
                                            return c;
                                        }
                                        return null;
                                    }
                                }
                                else
                                {
                                    //Make sure it is in bounds
                                    if ((offsetX + channel.Width) > update.Width || (offsetY + channel.Height) > update.Height)
                                    {
                                        MainConsole.Instance.Error("[TERRAIN]: Unable to load heightmap, the terrain you have given is larger than the current region.");
                                        return null;
                                    }
                                    else
                                    {
                                        //Merge the terrains together at the specified offset
                                        for (int x = offsetX; x < offsetX + channel.Width; x++)
                                        {
                                            for (int y = offsetY; y < offsetY + channel.Height; y++)
                                            {
                                                update[x, y] = channel[x - offsetX, y - offsetY];
                                            }
                                        }
                                        return update;
                                    }
                                }
                            }
                        }
                        catch (NotImplementedException)
                        {
                            MainConsole.Instance.Error("[TERRAIN]: Unable to load heightmap, the " + loader.Value + " parser does not support file loading. (May be save only)");
                            throw new TerrainException(String.Format("unable to load heightmap: parser {0} does not support loading", loader.Value));
                        }
                    }

                    MainConsole.Instance.Info("[TERRAIN]: File (" + filename + ") loaded successfully");
                    return channel;
                }
            }
#else
            foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders.Where(loader => filename.EndsWith(loader.Key)))
            {
                lock (m_scene)
                {
                    try
                    {
                        channel = loader.Value.LoadStream(stream, m_scene);
                        if (channel != null)
                        {
                            channel.Scene = m_scene;
                            if (update == null || (update.Height == channel.Height &&
                                                   update.Width == channel.Width))
                            {
                                if (m_scene.RegionInfo.RegionSizeX != channel.Width ||
                                    m_scene.RegionInfo.RegionSizeY != channel.Height)
                                {
                                    if ((channel.Width) > m_scene.RegionInfo.RegionSizeX ||
                                        (channel.Height) > m_scene.RegionInfo.RegionSizeY)
                                    {
                                        TerrainChannel c = new TerrainChannel(true, m_scene);
                                        for (int x = 0; x < m_scene.RegionInfo.RegionSizeX; x++)
                                        {
                                            for (int y = 0; y < m_scene.RegionInfo.RegionSizeY; y++)
                                            {
                                                c[x, y] = channel[x, y];
                                            }
                                        }
                                        return c;
                                    }
                                    return null;
                                }
                            }
                            else
                            {
                                //Make sure it is in bounds
                                if ((offsetX + channel.Width) > update.Width ||
                                    (offsetY + channel.Height) > update.Height)
                                {
                                    MainConsole.Instance.Error(
                                        "[TERRAIN]: Unable to load heightmap, the terrain you have given is larger than the current region.");
                                    return null;
                                }
                                else
                                {
                                    //Merge the terrains together at the specified offset
                                    for (int x = offsetX; x < offsetX + channel.Width; x++)
                                    {
                                        for (int y = offsetY; y < offsetY + channel.Height; y++)
                                        {
                                            update[x, y] = channel[x - offsetX, y - offsetY];
                                        }
                                    }
                                    return update;
                                }
                            }
                        }
                    }
                    catch (NotImplementedException)
                    {
                        MainConsole.Instance.Error("[TERRAIN]: Unable to load heightmap, the " + loader.Value +
                                    " parser does not support file loading. (May be save only)");
                        throw new TerrainException(
                            String.Format("unable to load heightmap: parser {0} does not support loading",
                                          loader.Value));
                    }
                }

                MainConsole.Instance.Info("[TERRAIN]: File (" + filename + ") loaded successfully");
                return channel;
            }
#endif
            MainConsole.Instance.Error("[TERRAIN]: Unable to load heightmap, no file loader available for that format.");
            throw new TerrainException(
                String.Format("unable to load heightmap from file {0}: no loader available for that format", filename));
        }
Exemple #32
0
        public ITerrainChannel LoadStream (Stream s, IScene scene)
        {
            BinaryReader bs = new BinaryReader(s);
            int size = (int)System.Math.Sqrt(s.Length);
            size /= sizeof(short);
            TerrainChannel retval = new TerrainChannel(size, size, scene);
            for (int y = 0; y < retval.Height; y++)
            {
                for (int x = 0; x < retval.Width; x++)
                {
                    retval[x, y] = bs.ReadSingle();
                }
            }

            bs.Close();

            return retval;
        }
Exemple #33
0
        public ITerrainChannel LoadStream(Stream s)
        {
            TerrainChannel retval = new TerrainChannel();

            BinaryReader bs = new BinaryReader(s);
            int y;
            for (y = 0; y < retval.Height; y++)
            {
                int x;
                for (x = 0; x < retval.Width; x++)
                {
                    retval[x, y] = bs.ReadSingle();
                }
            }

            bs.Close();

            return retval;
        }