Beispiel #1
0
 public void StoreRegionSettings(RegionSettings rs)
 {
     RegionSettings oldRegionSettings = (RegionSettings)manager.Get(typeof(RegionSettings), rs.RegionUUID);
     if (oldRegionSettings != null)
     {
         manager.Update(rs);
     }
     else
     {
         manager.Insert(rs);
     }
 }
Beispiel #2
0
        public OSDMap PackRegionInfoData(bool secure)
        {
            OSDMap args = new OSDMap();

            args["region_id"] = OSD.FromUUID(RegionID);
            if ((RegionName != null) && !RegionName.Equals(""))
            {
                args["region_name"] = OSD.FromString(RegionName);
            }
            args["external_host_name"]  = OSD.FromString(ExternalHostName);
            args["http_port"]           = OSD.FromString(HttpPort.ToString());
            args["server_uri"]          = OSD.FromString(ServerURI);
            args["region_xloc"]         = OSD.FromString(RegionLocX.ToString());
            args["region_yloc"]         = OSD.FromString(RegionLocY.ToString());
            args["internal_ep_address"] = OSD.FromString(InternalEndPoint.Address.ToString());
            args["internal_ep_port"]    = OSD.FromString(InternalEndPoint.Port.ToString());
            args["allow_alt_ports"]     = OSD.FromBoolean(m_allow_alternate_ports);
            if (RegionType != String.Empty)
            {
                args["region_type"] = OSD.FromString(RegionType);
            }
            args["password"]      = OSD.FromUUID(Password);
            args["region_size_x"] = OSD.FromInteger(RegionSizeX);
            args["region_size_y"] = OSD.FromInteger(RegionSizeY);
            args["region_size_z"] = OSD.FromInteger(RegionSizeZ);
            if (secure)
            {
                args["disabled"]        = OSD.FromBoolean(Disabled);
                args["scope_id"]        = OSD.FromUUID(ScopeID);
                args["object_capacity"] = OSD.FromInteger(m_objectCapacity);
                args["region_type"]     = OSD.FromString(RegionType);
                args["see_into_this_sim_from_neighbor"]  = OSD.FromBoolean(SeeIntoThisSimFromNeighbor);
                args["trust_binaries_from_foreign_sims"] = OSD.FromBoolean(TrustBinariesFromForeignSims);
                args["allow_script_crossing"]            = OSD.FromBoolean(AllowScriptCrossing);
                args["allow_physical_prims"]             = OSD.FromBoolean(AllowPhysicalPrims);
                args["number_startup"] = OSD.FromInteger(NumberStartup);
                args["startupType"]    = OSD.FromInteger((int)Startup);
                args["FindExternalIP"] = OSD.FromBoolean(FindExternalAutomatically);
                args["RegionSettings"] = RegionSettings.ToOSD();
            }
            return(args);
        }
        /// <summary>
        /// Builds the region settings from a datarecod.
        /// </summary>
        /// <param name="row">datarecord with regionsettings.</param>
        /// <returns></returns>
        private static RegionSettings BuildRegionSettings(IDataRecord row)
        {
            //TODO change this is some more generic code so we doesnt have to change it every time a new field is added?
            RegionSettings newSettings = new RegionSettings();

            newSettings.RegionUUID = new UUID((Guid)row["regionUUID"]);
            newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
            newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
            newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
            newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
            newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
            newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
            newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
            newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
            newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
            newSettings.Maturity = Convert.ToInt32(row["maturity"]);
            newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
            newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
            newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
            newSettings.TerrainTexture1 = new UUID((Guid)row["terrain_texture_1"]);
            newSettings.TerrainTexture2 = new UUID((Guid)row["terrain_texture_2"]);
            newSettings.TerrainTexture3 = new UUID((Guid)row["terrain_texture_3"]);
            newSettings.TerrainTexture4 = new UUID((Guid)row["terrain_texture_4"]);
            newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
            newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
            newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
            newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
            newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
            newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
            newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
            newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
            newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
            newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
            newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
            newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
            newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
            newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
            newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
            newSettings.SunVector = new Vector3(
                                                 Convert.ToSingle(row["sunvectorx"]),
                                                 Convert.ToSingle(row["sunvectory"]),
                                                 Convert.ToSingle(row["sunvectorz"])
                                                 );
            newSettings.Covenant = new UUID((Guid)row["covenant"]);
            newSettings.CovenantLastUpdated = Convert.ToInt32(row["covenantlastupdated"]);
            newSettings.MinimumAge = Convert.ToInt32(row["minimum_age"]);

            newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);

            if (row["loaded_creation_id"] is DBNull)
                newSettings.LoadedCreationID = "";
            else
                newSettings.LoadedCreationID = (String)row["loaded_creation_id"];

            OSD o = OSDParser.DeserializeJson((String)row["generic"]);
            if (o.Type == OSDType.Map)
                newSettings.Generic = (OSDMap)o;
            return newSettings;
        }
 /// <summary>
 /// Deserialize settings
 /// </summary>
 /// <param name="serializedSettings"></param>
 /// <returns></returns>
 /// <exception cref="System.Xml.XmlException"></exception>
 public static RegionSettings Deserialize(string serializedSettings)
 {
     RegionSettings settings = new RegionSettings();
     
     StringReader sr = new StringReader(serializedSettings);
     XmlTextReader xtr = new XmlTextReader(sr);
     
     xtr.ReadStartElement("RegionSettings");
  
     xtr.ReadStartElement("General");
    
     while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement)
     {
         switch (xtr.Name)
         {
             case "AllowDamage":
                 settings.AllowDamage = bool.Parse(xtr.ReadElementContentAsString());
                 break;
             case "AllowLandResell":
                 settings.AllowLandResell = bool.Parse(xtr.ReadElementContentAsString());
                 break;
             case "AllowLandJoinDivide":
                 settings.AllowLandJoinDivide = bool.Parse(xtr.ReadElementContentAsString());
                 break;
             case "BlockFly":
                 settings.BlockFly = bool.Parse(xtr.ReadElementContentAsString());
                 break;
             case "BlockLandShowInSearch":
                 settings.BlockShowInSearch = bool.Parse(xtr.ReadElementContentAsString());
                 break;
             case "BlockTerraform":
                 settings.BlockTerraform = bool.Parse(xtr.ReadElementContentAsString());
                 break;
             case "DisableCollisions":
                 settings.DisableCollisions = bool.Parse(xtr.ReadElementContentAsString());
                 break;
             case "DisablePhysics":
                 settings.DisablePhysics = bool.Parse(xtr.ReadElementContentAsString());
                 break;
             case "DisableScripts":
                 settings.DisableScripts = bool.Parse(xtr.ReadElementContentAsString());
                 break;
             case "MaturityRating":
                 settings.Maturity = int.Parse(xtr.ReadElementContentAsString());
                 break;
             case "RestrictPushing":
                 settings.RestrictPushing = bool.Parse(xtr.ReadElementContentAsString());
                 break;
             case "AgentLimit":
                 settings.AgentLimit = int.Parse(xtr.ReadElementContentAsString());
                 break;
             case "ObjectBonus":
                 settings.ObjectBonus = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
                 break;
         }
     }
     
     xtr.ReadEndElement();
     xtr.ReadStartElement("GroundTextures");
     
     while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement)
     {
         switch (xtr.Name)
         {
             case "Texture1":
                 settings.TerrainTexture1 = UUID.Parse(xtr.ReadElementContentAsString());
                 break;
             case "Texture2":
                 settings.TerrainTexture2 = UUID.Parse(xtr.ReadElementContentAsString());
                 break;
             case "Texture3":
                 settings.TerrainTexture3 = UUID.Parse(xtr.ReadElementContentAsString());
                 break;
             case "Texture4":
                 settings.TerrainTexture4 = UUID.Parse(xtr.ReadElementContentAsString());
                 break;
             case "ElevationLowSW":
                 settings.Elevation1SW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
                 break;
             case "ElevationLowNW":
                 settings.Elevation1NW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
                 break;
             case "ElevationLowSE":
                 settings.Elevation1SE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
                 break;
             case "ElevationLowNE":
                 settings.Elevation1NE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
                 break;
             case "ElevationHighSW":
                 settings.Elevation2SW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
                 break;
             case "ElevationHighNW":
                 settings.Elevation2NW = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
                 break;
             case "ElevationHighSE":
                 settings.Elevation2SE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
                 break;
             case "ElevationHighNE":
                 settings.Elevation2NE = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
                 break;
         }
     }
    
     xtr.ReadEndElement();
     xtr.ReadStartElement("Terrain");
     
     while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement)
     {
         switch (xtr.Name)
         {
             case "WaterHeight":
                 settings.WaterHeight = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
                 break;
             case "TerrainRaiseLimit":
                 settings.TerrainRaiseLimit = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
                 break;
             case "TerrainLowerLimit":
                 settings.TerrainLowerLimit = double.Parse(xtr.ReadElementContentAsString(), Culture.NumberFormatInfo);
                 break;
             case "UseEstateSun":
                 settings.UseEstateSun = bool.Parse(xtr.ReadElementContentAsString());
                 break;
             case "FixedSun":
                 settings.FixedSun = bool.Parse(xtr.ReadElementContentAsString());
                 break;
         }
     }
     
     xtr.Close();
     sr.Close();
     
     return settings;
 }
        public RegionSettings LoadRegionSettings(UUID regionUUID)
        {
            lock (ds)
            {
                DataTable regionsettings = ds.Tables["regionsettings"];

                string searchExp = "regionUUID = '" + regionUUID.ToString() + "'";
                DataRow[] rawsettings = regionsettings.Select(searchExp);
                if (rawsettings.Length == 0)
                {
                    RegionSettings rs = new RegionSettings();
                    rs.RegionUUID = regionUUID;
                    rs.OnSave += StoreRegionSettings;

                    StoreRegionSettings(rs);

                    return rs;
                }
                DataRow row = rawsettings[0];

                RegionSettings newSettings = buildRegionSettings(row);
                newSettings.OnSave += StoreRegionSettings;

                return newSettings;
            }
        }
 private void fillRegionSettingsRow(DataRow row, RegionSettings settings)
 {
     row["regionUUID"] = settings.RegionUUID.ToString();
     row["block_terraform"] = settings.BlockTerraform;
     row["block_fly"] = settings.BlockFly;
     row["allow_damage"] = settings.AllowDamage;
     row["restrict_pushing"] = settings.RestrictPushing;
     row["allow_land_resell"] = settings.AllowLandResell;
     row["allow_land_join_divide"] = settings.AllowLandJoinDivide;
     row["block_show_in_search"] = settings.BlockShowInSearch;
     row["agent_limit"] = settings.AgentLimit;
     row["object_bonus"] = settings.ObjectBonus;
     row["maturity"] = settings.Maturity;
     row["disable_scripts"] = settings.DisableScripts;
     row["disable_collisions"] = settings.DisableCollisions;
     row["disable_physics"] = settings.DisablePhysics;
     row["terrain_texture_1"] = settings.TerrainTexture1.ToString();
     row["terrain_texture_2"] = settings.TerrainTexture2.ToString();
     row["terrain_texture_3"] = settings.TerrainTexture3.ToString();
     row["terrain_texture_4"] = settings.TerrainTexture4.ToString();
     row["elevation_1_nw"] = settings.Elevation1NW;
     row["elevation_2_nw"] = settings.Elevation2NW;
     row["elevation_1_ne"] = settings.Elevation1NE;
     row["elevation_2_ne"] = settings.Elevation2NE;
     row["elevation_1_se"] = settings.Elevation1SE;
     row["elevation_2_se"] = settings.Elevation2SE;
     row["elevation_1_sw"] = settings.Elevation1SW;
     row["elevation_2_sw"] = settings.Elevation2SW;
     row["water_height"] = settings.WaterHeight;
     row["terrain_raise_limit"] = settings.TerrainRaiseLimit;
     row["terrain_lower_limit"] = settings.TerrainLowerLimit;
     row["use_estate_sun"] = settings.UseEstateSun;
     row["Sandbox"] = settings.Sandbox; // database uses upper case S for sandbox
     row["sunvectorx"] = settings.SunVector.X;
     row["sunvectory"] = settings.SunVector.Y;
     row["sunvectorz"] = settings.SunVector.Z;
     row["fixed_sun"] = settings.FixedSun;
     row["sun_position"] = settings.SunPosition;
     row["covenant"] = settings.Covenant.ToString();
     row["covenantlastupdated"] = settings.CovenantLastUpdated.ToString();
     row["map_tile_ID"] = settings.TerrainImageID.ToString();
     row["terrain_tile_ID"] = settings.TerrainMapImageID.ToString();
     row["loaded_creation_datetime"] = settings.LoadedCreationDateTime.ToString();
     row["loaded_creation_id"] = settings.LoadedCreationID.ToString();
     row["minimum_age"] = settings.MinimumAge;
     row["generic"] = OSDParser.SerializeJsonString(settings.Generic);
 }
        /// <summary>
        /// Store region settings, need to check if the check is really necesary. If we can make something for creating new region.
        /// </summary>
        /// <param name="regionSettings">region settings.</param>
        public void StoreRegionSettings(RegionSettings regionSettings)
        {
            //Little check if regionUUID already exist in DB
            string regionUUID;
            string sql = "SELECT regionUUID FROM regionsettings WHERE regionUUID = @regionUUID";
            using (SqlConnection conn = new SqlConnection(m_connectionString))
            using (SqlCommand cmd = new SqlCommand(sql, conn))
            {
                cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionSettings.RegionUUID));
                conn.Open();
                regionUUID = cmd.ExecuteScalar().ToString();
            }

            if (string.IsNullOrEmpty(regionUUID))
            {
                StoreNewRegionSettings(regionSettings);
            }
            else
            {
                //This method only updates region settings!!! First call LoadRegionSettings to create new region settings in DB
                sql =
                   @"UPDATE [regionsettings] SET [block_terraform] = @block_terraform ,[block_fly] = @block_fly ,[allow_damage] = @allow_damage 
,[restrict_pushing] = @restrict_pushing ,[allow_land_resell] = @allow_land_resell ,[allow_land_join_divide] = @allow_land_join_divide 
,[block_show_in_search] = @block_show_in_search ,[agent_limit] = @agent_limit ,[object_bonus] = @object_bonus ,[maturity] = @maturity 
,[disable_scripts] = @disable_scripts ,[disable_collisions] = @disable_collisions ,[disable_physics] = @disable_physics 
,[terrain_texture_1] = @terrain_texture_1 ,[terrain_texture_2] = @terrain_texture_2 ,[terrain_texture_3] = @terrain_texture_3 
,[terrain_texture_4] = @terrain_texture_4 ,[elevation_1_nw] = @elevation_1_nw ,[elevation_2_nw] = @elevation_2_nw 
,[elevation_1_ne] = @elevation_1_ne ,[elevation_2_ne] = @elevation_2_ne ,[elevation_1_se] = @elevation_1_se ,[elevation_2_se] = @elevation_2_se 
,[elevation_1_sw] = @elevation_1_sw ,[elevation_2_sw] = @elevation_2_sw ,[water_height] = @water_height ,[terrain_raise_limit] = @terrain_raise_limit 
,[terrain_lower_limit] = @terrain_lower_limit ,[use_estate_sun] = @use_estate_sun ,[fixed_sun] = @fixed_sun ,[sun_position] = @sun_position 
,[covenant] = @covenant , [sunvectorx] = @sunvectorx, [sunvectory] = @sunvectory, [sunvectorz] = @sunvectorz,  [Sandbox] = @Sandbox, [loaded_creation_datetime] = @loaded_creation_datetime, [loaded_creation_id] = @loaded_creation_id
 WHERE [regionUUID] = @regionUUID";

                using (SqlConnection conn = new SqlConnection(m_connectionString))
                using (SqlCommand cmd = new SqlCommand(sql, conn))
                {
                    cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
            }
        }
 public void StoreRegionSettings(RegionSettings rs)
 {
     m_database.StoreRegionSettings(rs);
 }
Beispiel #9
0
 public void StoreRegionSettings(RegionSettings rs)
 {
     throw new NotImplementedException();
 }
Beispiel #10
0
        public RegionSettings LoadRegionSettings(UUID regionUUID)
        {
            RegionSettings regionSettings = (RegionSettings) manager.Get(typeof(RegionSettings), regionUUID);

            if (regionSettings == null)
            {
                regionSettings = new RegionSettings();
                regionSettings.RegionUUID = regionUUID;
                manager.Insert(regionSettings);
            }

            regionSettings.OnSave += StoreRegionSettings;
            
            return regionSettings;
        }
 private void SaveSpawnPoints(RegionSettings rs)
 {
     string sql = "DELETE FROM spawn_points WHERE RegionUUID = @RegionUUID";
     using (SqlConnection conn = new SqlConnection(m_connectionString))
     using (SqlCommand cmd = new SqlCommand(sql, conn))
     {
         cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", rs.RegionUUID));
         conn.Open();
         cmd.ExecuteNonQuery();
     }
     foreach (SpawnPoint p in rs.SpawnPoints())
     {
         sql = "INSERT INTO spawn_points (RegionUUID, Yaw, Pitch, Distance) VALUES (@RegionUUID, @Yaw, @Pitch, @Distance)";
         using (SqlConnection conn = new SqlConnection(m_connectionString))
         using (SqlCommand cmd = new SqlCommand(sql, conn))
         {
             cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", rs.RegionUUID));
             cmd.Parameters.Add(_Database.CreateParameter("@Yaw", p.Yaw));
             cmd.Parameters.Add(_Database.CreateParameter("@Pitch", p.Pitch));
             cmd.Parameters.Add(_Database.CreateParameter("@Distance", p.Distance));
             conn.Open();
             cmd.ExecuteNonQuery();
         }
     }
 }
Beispiel #12
0
        // Add a terrain to the renderer.
        // Note that we create a 'low resolution' 256x256 vertex terrain rather than trying for
        //    full resolution. This saves a lot of memory especially for very large regions.
        private void CreateTerrain(WarpRenderer renderer, bool textureTerrain)
        {
            ITerrainChannel terrain = m_scene.Heightmap;

            // 'diff' is the difference in scale between the real region size and the size of terrain we're buiding
            float diff = (float)m_scene.RegionInfo.RegionSizeX / 256f;

            warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2);

            // Create all the vertices for the terrain
            for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff)
            {
                for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff)
                {
                    warp_Vector pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]);
                    obj.addVertex(new warp_Vertex(pos,
                                                  x / (float)m_scene.RegionInfo.RegionSizeX,
                                                  (((float)m_scene.RegionInfo.RegionSizeY) - y) / m_scene.RegionInfo.RegionSizeY));
                }
            }

            // Now that we have all the vertices, make another pass and create
            //     the normals for each of the surface triangles and
            //     create the list of triangle indices.
            for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff)
            {
                for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff)
                {
                    float newX = x / diff;
                    float newY = y / diff;
                    if (newX < 255 && newY < 255)
                    {
                        int v = (int)newY * 256 + (int)newX;

                        // Normal for a triangle made up of three adjacent vertices
                        Vector3     v1   = new Vector3(newX, newY, (float)terrain[(int)x, (int)y]);
                        Vector3     v2   = new Vector3(newX + 1, newY, (float)terrain[(int)(x + 1), (int)y]);
                        Vector3     v3   = new Vector3(newX, newY + 1, (float)terrain[(int)x, ((int)(y + 1))]);
                        warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3));
                        norm            = norm.reverse();
                        obj.vertex(v).n = norm;

                        // Make two triangles for each of the squares in the grid of vertices
                        obj.addTriangle(
                            v,
                            v + 1,
                            v + 256);

                        obj.addTriangle(
                            v + 256 + 1,
                            v + 256,
                            v + 1);
                    }
                }
            }

            renderer.Scene.addObject("Terrain", obj);

            UUID[]  textureIDs   = new UUID[4];
            float[] startHeights = new float[4];
            float[] heightRanges = new float[4];

            OpenSim.Framework.RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings;

            textureIDs[0] = regionInfo.TerrainTexture1;
            textureIDs[1] = regionInfo.TerrainTexture2;
            textureIDs[2] = regionInfo.TerrainTexture3;
            textureIDs[3] = regionInfo.TerrainTexture4;

            startHeights[0] = (float)regionInfo.Elevation1SW;
            startHeights[1] = (float)regionInfo.Elevation1NW;
            startHeights[2] = (float)regionInfo.Elevation1SE;
            startHeights[3] = (float)regionInfo.Elevation1NE;

            heightRanges[0] = (float)regionInfo.Elevation2SW;
            heightRanges[1] = (float)regionInfo.Elevation2NW;
            heightRanges[2] = (float)regionInfo.Elevation2SE;
            heightRanges[3] = (float)regionInfo.Elevation2NE;

            uint globalX, globalY;

            Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out globalX, out globalY);

            warp_Texture texture;

            using (
                Bitmap image
                    = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges,
                                         new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain))
            {
                texture = new warp_Texture(image);
            }

            warp_Material material = new warp_Material(texture);

            material.setReflectivity(50);
            renderer.Scene.addMaterial("TerrainColor", material);
            renderer.Scene.material("TerrainColor").setReflectivity(0);             // reduces tile seams a bit thanks lkalif
            renderer.SetObjectMaterial("Terrain", "TerrainColor");
        }
Beispiel #13
0
        public void TestLoadOarRegionSettings()
        {
            TestHelpers.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            MemoryStream     archiveWriteStream = new MemoryStream();
            TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream);

            tar.WriteDir(ArchiveConstants.TERRAINS_PATH);
            tar.WriteFile(
                ArchiveConstants.CONTROL_FILE_PATH,
                new ArchiveWriteRequest(m_scene, (Stream)null, Guid.Empty).CreateControlFile(new ArchiveScenesGroup()));

            RegionSettings rs = new RegionSettings();

            rs.AgentLimit          = 17;
            rs.AllowDamage         = true;
            rs.AllowLandJoinDivide = true;
            rs.AllowLandResell     = true;
            rs.BlockFly            = true;
            rs.BlockShowInSearch   = true;
            rs.BlockTerraform      = true;
            rs.DisableCollisions   = true;
            rs.DisablePhysics      = true;
            rs.DisableScripts      = true;
            rs.Elevation1NW        = 15.9;
            rs.Elevation1NE        = 45.3;
            rs.Elevation1SE        = 49;
            rs.Elevation1SW        = 1.9;
            rs.Elevation2NW        = 4.5;
            rs.Elevation2NE        = 19.2;
            rs.Elevation2SE        = 9.2;
            rs.Elevation2SW        = 2.1;
            rs.FixedSun            = true;
            rs.SunPosition         = 12.0;
            rs.ObjectBonus         = 1.4;
            rs.RestrictPushing     = true;
            rs.TerrainLowerLimit   = 0.4;
            rs.TerrainRaiseLimit   = 17.9;
            rs.TerrainTexture1     = UUID.Parse("00000000-0000-0000-0000-000000000020");
            rs.TerrainTexture2     = UUID.Parse("00000000-0000-0000-0000-000000000040");
            rs.TerrainTexture3     = UUID.Parse("00000000-0000-0000-0000-000000000060");
            rs.TerrainTexture4     = UUID.Parse("00000000-0000-0000-0000-000000000080");
            rs.UseEstateSun        = true;
            rs.WaterHeight         = 23;
            rs.TelehubObject       = UUID.Parse("00000000-0000-0000-0000-111111111111");
            rs.AddSpawnPoint(SpawnPoint.Parse("1,-2,0.33"));

            tar.WriteFile(ArchiveConstants.SETTINGS_PATH + "region1.xml", RegionSettingsSerializer.Serialize(rs, null));

            tar.Close();

            MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());

            m_scene.EventManager.OnOarFileLoaded += LoadCompleted;
            m_oarEvent.Reset();
            m_archiverModule.DearchiveRegion(archiveReadStream);

            m_oarEvent.WaitOne(60000);

            Assert.That(m_lastErrorMessage, Is.Null);
            RegionSettings loadedRs = m_scene.RegionInfo.RegionSettings;

            Assert.That(loadedRs.AgentLimit, Is.EqualTo(17));
            Assert.That(loadedRs.AllowDamage, Is.True);
            Assert.That(loadedRs.AllowLandJoinDivide, Is.True);
            Assert.That(loadedRs.AllowLandResell, Is.True);
            Assert.That(loadedRs.BlockFly, Is.True);
            Assert.That(loadedRs.BlockShowInSearch, Is.True);
            Assert.That(loadedRs.BlockTerraform, Is.True);
            Assert.That(loadedRs.DisableCollisions, Is.True);
            Assert.That(loadedRs.DisablePhysics, Is.True);
            Assert.That(loadedRs.DisableScripts, Is.True);
            Assert.That(loadedRs.Elevation1NW, Is.EqualTo(15.9));
            Assert.That(loadedRs.Elevation1NE, Is.EqualTo(45.3));
            Assert.That(loadedRs.Elevation1SE, Is.EqualTo(49));
            Assert.That(loadedRs.Elevation1SW, Is.EqualTo(1.9));
            Assert.That(loadedRs.Elevation2NW, Is.EqualTo(4.5));
            Assert.That(loadedRs.Elevation2NE, Is.EqualTo(19.2));
            Assert.That(loadedRs.Elevation2SE, Is.EqualTo(9.2));
            Assert.That(loadedRs.Elevation2SW, Is.EqualTo(2.1));
            Assert.That(loadedRs.ObjectBonus, Is.EqualTo(1.4));
            Assert.That(loadedRs.RestrictPushing, Is.True);
            Assert.That(loadedRs.TerrainLowerLimit, Is.EqualTo(0.4));
            Assert.That(loadedRs.TerrainRaiseLimit, Is.EqualTo(17.9));
            Assert.That(loadedRs.TerrainTexture1, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000020")));
            Assert.That(loadedRs.TerrainTexture2, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000040")));
            Assert.That(loadedRs.TerrainTexture3, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000060")));
            Assert.That(loadedRs.TerrainTexture4, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000080")));
            Assert.That(loadedRs.WaterHeight, Is.EqualTo(23));
            Assert.AreEqual(UUID.Zero, loadedRs.TelehubObject); // because no object was found with the original UUID
            Assert.AreEqual(0, loadedRs.SpawnPoints().Count);
        }
Beispiel #14
0
        // Add a terrain to the renderer.
        // Note that we create a 'low resolution' 256x256 vertex terrain rather than trying for
        //    full resolution. This saves a lot of memory especially for very large regions.
        private void CreateTerrain(WarpRenderer renderer, bool textureTerrain)
        {
            ITerrainChannel terrain = m_scene.Heightmap;

            float regionsx = m_scene.RegionInfo.RegionSizeX;
            float regionsy = m_scene.RegionInfo.RegionSizeY;

            // 'diff' is the difference in scale between the real region size and the size of terrain we're buiding
            float diff = regionsx / 256f;

            int npointsx = (int)(regionsx / diff);
            int npointsy = (int)(regionsy / diff);

            float invsx = 1.0f / regionsx;
            float invsy = 1.0f / (float)m_scene.RegionInfo.RegionSizeY;

            // Create all the vertices for the terrain
            warp_Object obj = new warp_Object();

            for (float y = 0; y < regionsy; y += diff)
            {
                for (float x = 0; x < regionsx; x += diff)
                {
                    warp_Vector pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]);
                    obj.addVertex(new warp_Vertex(pos, x * invsx, 1.0f - y * invsy));
                }
            }

            // Now that we have all the vertices, make another pass and
            // create the list of triangle indices.
            float invdiff = 1.0f / diff;
            int   limx    = npointsx - 1;
            int   limy    = npointsy - 1;

            for (float y = 0; y < regionsy; y += diff)
            {
                for (float x = 0; x < regionsx; x += diff)
                {
                    float newX = x * invdiff;
                    float newY = y * invdiff;
                    if (newX < limx && newY < limy)
                    {
                        int v = (int)newY * npointsx + (int)newX;

                        // Make two triangles for each of the squares in the grid of vertices
                        obj.addTriangle(
                            v,
                            v + 1,
                            v + npointsx);

                        obj.addTriangle(
                            v + npointsx + 1,
                            v + npointsx,
                            v + 1);
                    }
                }
            }

            renderer.Scene.addObject("Terrain", obj);

            UUID[]  textureIDs   = new UUID[4];
            float[] startHeights = new float[4];
            float[] heightRanges = new float[4];

            OpenSim.Framework.RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings;

            textureIDs[0] = regionInfo.TerrainTexture1;
            textureIDs[1] = regionInfo.TerrainTexture2;
            textureIDs[2] = regionInfo.TerrainTexture3;
            textureIDs[3] = regionInfo.TerrainTexture4;

            startHeights[0] = (float)regionInfo.Elevation1SW;
            startHeights[1] = (float)regionInfo.Elevation1NW;
            startHeights[2] = (float)regionInfo.Elevation1SE;
            startHeights[3] = (float)regionInfo.Elevation1NE;

            heightRanges[0] = (float)regionInfo.Elevation2SW;
            heightRanges[1] = (float)regionInfo.Elevation2NW;
            heightRanges[2] = (float)regionInfo.Elevation2SE;
            heightRanges[3] = (float)regionInfo.Elevation2NE;

            uint globalX, globalY;

            Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out globalX, out globalY);

            warp_Texture texture;

            using (Bitmap image = TerrainSplat.Splat(
                       terrain, textureIDs, startHeights, heightRanges,
                       new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain))
                texture = new warp_Texture(image);

            warp_Material material = new warp_Material(texture);

            material.setReflectivity(50);
            renderer.Scene.addMaterial("TerrainColor", material);
            renderer.Scene.material("TerrainColor").setReflectivity(0); // reduces tile seams a bit thanks lkalif
            renderer.SetObjectMaterial("Terrain", "TerrainColor");
        }
Beispiel #15
0
        public void UnpackRegionInfoData(OSDMap args)
        {
            if (args.ContainsKey("region_id"))
            {
                RegionID = args["region_id"].AsUUID();
            }
            if (args.ContainsKey("region_name"))
            {
                RegionName = args["region_name"].AsString();
            }
            if (args.ContainsKey("external_host_name"))
            {
                ExternalHostName = args["external_host_name"].AsString();
            }
            if (args.ContainsKey("http_port"))
            {
                UInt32.TryParse(args["http_port"].AsString(), out m_httpPort);
            }
            if (args.ContainsKey("region_xloc"))
            {
                int locx;
                Int32.TryParse(args["region_xloc"].AsString(), out locx);
                RegionLocX = locx;
            }
            if (args.ContainsKey("region_yloc"))
            {
                int locy;
                Int32.TryParse(args["region_yloc"].AsString(), out locy);
                RegionLocY = locy;
            }
            IPAddress ip_addr = null;

            if (args.ContainsKey("internal_ep_address"))
            {
                IPAddress.TryParse(args["internal_ep_address"].AsString(), out ip_addr);
            }
            int port = 0;

            if (args.ContainsKey("internal_ep_port"))
            {
                Int32.TryParse(args["internal_ep_port"].AsString(), out port);
            }
            InternalEndPoint = new IPEndPoint(ip_addr, port);
            if (args.ContainsKey("allow_alt_ports"))
            {
                m_allow_alternate_ports = args["allow_alt_ports"].AsBoolean();
            }
            if (args.ContainsKey("region_type"))
            {
                m_regionType = args["region_type"].AsString();
            }
            if (args.ContainsKey("password"))
            {
                Password = args["password"].AsUUID();
            }

            if (args.ContainsKey("disabled"))
            {
                Disabled = args["disabled"].AsBoolean();
            }
            if (args.ContainsKey("scope_id"))
            {
                ScopeID = args["scope_id"].AsUUID();
            }

            if (args.ContainsKey("region_size_x"))
            {
                RegionSizeX = args["region_size_x"].AsInteger();
            }
            if (args.ContainsKey("region_size_y"))
            {
                RegionSizeY = args["region_size_y"].AsInteger();
            }
            if (args.ContainsKey("region_size_z"))
            {
                RegionSizeZ = args["region_size_z"].AsInteger();
            }

            if (args.ContainsKey("object_capacity"))
            {
                m_objectCapacity = args["object_capacity"].AsInteger();
            }
            if (args.ContainsKey("region_type"))
            {
                RegionType = args["region_type"].AsString();
            }
            if (args.ContainsKey("see_into_this_sim_from_neighbor"))
            {
                SeeIntoThisSimFromNeighbor = args["see_into_this_sim_from_neighbor"].AsBoolean();
            }
            if (args.ContainsKey("trust_binaries_from_foreign_sims"))
            {
                TrustBinariesFromForeignSims = args["trust_binaries_from_foreign_sims"].AsBoolean();
            }
            if (args.ContainsKey("allow_script_crossing"))
            {
                AllowScriptCrossing = args["allow_script_crossing"].AsBoolean();
            }
            if (args.ContainsKey("allow_physical_prims"))
            {
                AllowPhysicalPrims = args["allow_physical_prims"].AsBoolean();
            }
            if (args.ContainsKey("number_startup"))
            {
                NumberStartup = args["number_startup"].AsInteger();
            }
            if (args.ContainsKey("startupType"))
            {
                Startup = (StartupType)args["startupType"].AsInteger();
            }
            if (args.ContainsKey("FindExternalIP"))
            {
                FindExternalAutomatically = args["FindExternalIP"].AsBoolean();
            }
            if (args.ContainsKey("RegionSettings"))
            {
                RegionSettings = new RegionSettings();
                RegionSettings.FromOSD((OSDMap)args["RegionSettings"]);
            }
        }
Beispiel #16
0
 public RegionSettings LoadRegionSettings(UUID regionUUID)
 {
     RegionSettings rs = new RegionSettings();
     rs.RegionUUID = regionUUID;
     return rs;
 }
        /// <summary>
        /// Stores new regionsettings.
        /// </summary>
        /// <param name="regionSettings">The region settings.</param>
        private void StoreNewRegionSettings(RegionSettings regionSettings)
        {
            string sql = @"INSERT INTO [regionsettings]
                                ([regionUUID],[block_terraform],[block_fly],[allow_damage],[restrict_pushing],[allow_land_resell],[allow_land_join_divide],
                                [block_show_in_search],[agent_limit],[object_bonus],[maturity],[disable_scripts],[disable_collisions],[disable_physics],
                                [terrain_texture_1],[terrain_texture_2],[terrain_texture_3],[terrain_texture_4],[elevation_1_nw],[elevation_2_nw],[elevation_1_ne],
                                [elevation_2_ne],[elevation_1_se],[elevation_2_se],[elevation_1_sw],[elevation_2_sw],[water_height],[terrain_raise_limit],
                                [terrain_lower_limit],[use_estate_sun],[fixed_sun],[sun_position],[covenant],[sunvectorx], [sunvectory], [sunvectorz],[Sandbox], [loaded_creation_datetime], [loaded_creation_id]
 ) 
                            VALUES
                                (@regionUUID,@block_terraform,@block_fly,@allow_damage,@restrict_pushing,@allow_land_resell,@allow_land_join_divide,
                                @block_show_in_search,@agent_limit,@object_bonus,@maturity,@disable_scripts,@disable_collisions,@disable_physics,
                                @terrain_texture_1,@terrain_texture_2,@terrain_texture_3,@terrain_texture_4,@elevation_1_nw,@elevation_2_nw,@elevation_1_ne,
                                @elevation_2_ne,@elevation_1_se,@elevation_2_se,@elevation_1_sw,@elevation_2_sw,@water_height,@terrain_raise_limit,
                                @terrain_lower_limit,@use_estate_sun,@fixed_sun,@sun_position,@covenant,@sunvectorx,@sunvectory, @sunvectorz, @Sandbox, @loaded_creation_datetime, @loaded_creation_id)";

            using (SqlConnection conn = new SqlConnection(m_connectionString))
            using (SqlCommand cmd = new SqlCommand(sql, conn))
            {
                cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
                conn.Open();
                cmd.ExecuteNonQuery();
            }
        }
Beispiel #18
0
        public void TestLoadOarV0_2RegionSettings()
        {
            TestHelper.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            MemoryStream     archiveWriteStream = new MemoryStream();
            TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream);

            tar.WriteDir(ArchiveConstants.TERRAINS_PATH);
            tar.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, ArchiveWriteRequestExecution.Create0p2ControlFile());

            RegionSettings rs = new RegionSettings();

            rs.AgentLimit          = 17;
            rs.AllowDamage         = true;
            rs.AllowLandJoinDivide = true;
            rs.AllowLandResell     = true;
            rs.BlockFly            = true;
            rs.BlockShowInSearch   = true;
            rs.BlockTerraform      = true;
            rs.DisableCollisions   = true;
            rs.DisablePhysics      = true;
            rs.DisableScripts      = true;
            rs.Elevation1NW        = 15.9;
            rs.Elevation1NE        = 45.3;
            rs.Elevation1SE        = 49;
            rs.Elevation1SW        = 1.9;
            rs.Elevation2NW        = 4.5;
            rs.Elevation2NE        = 19.2;
            rs.Elevation2SE        = 9.2;
            rs.Elevation2SW        = 2.1;
            rs.FixedSun            = true;
            rs.ObjectBonus         = 1.4;
            rs.RestrictPushing     = true;
            rs.TerrainLowerLimit   = 0.4;
            rs.TerrainRaiseLimit   = 17.9;
            rs.TerrainTexture1     = UUID.Parse("00000000-0000-0000-0000-000000000020");
            rs.TerrainTexture2     = UUID.Parse("00000000-0000-0000-0000-000000000040");
            rs.TerrainTexture3     = UUID.Parse("00000000-0000-0000-0000-000000000060");
            rs.TerrainTexture4     = UUID.Parse("00000000-0000-0000-0000-000000000080");
            rs.UseEstateSun        = true;
            rs.WaterHeight         = 23;

            tar.WriteFile(ArchiveConstants.SETTINGS_PATH + "region1.xml", RegionSettingsSerializer.Serialize(rs));

            tar.Close();

            MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());

            lock (this)
            {
                m_scene.EventManager.OnOarFileLoaded += LoadCompleted;
                m_archiverModule.DearchiveRegion(archiveReadStream);
            }

            Assert.That(m_lastErrorMessage, Is.Null);
            RegionSettings loadedRs = m_scene.RegionInfo.RegionSettings;

            Assert.That(loadedRs.AgentLimit, Is.EqualTo(17));
            Assert.That(loadedRs.AllowDamage, Is.True);
            Assert.That(loadedRs.AllowLandJoinDivide, Is.True);
            Assert.That(loadedRs.AllowLandResell, Is.True);
            Assert.That(loadedRs.BlockFly, Is.True);
            Assert.That(loadedRs.BlockShowInSearch, Is.True);
            Assert.That(loadedRs.BlockTerraform, Is.True);
            Assert.That(loadedRs.DisableCollisions, Is.True);
            Assert.That(loadedRs.DisablePhysics, Is.True);
            Assert.That(loadedRs.DisableScripts, Is.True);
            Assert.That(loadedRs.Elevation1NW, Is.EqualTo(15.9));
            Assert.That(loadedRs.Elevation1NE, Is.EqualTo(45.3));
            Assert.That(loadedRs.Elevation1SE, Is.EqualTo(49));
            Assert.That(loadedRs.Elevation1SW, Is.EqualTo(1.9));
            Assert.That(loadedRs.Elevation2NW, Is.EqualTo(4.5));
            Assert.That(loadedRs.Elevation2NE, Is.EqualTo(19.2));
            Assert.That(loadedRs.Elevation2SE, Is.EqualTo(9.2));
            Assert.That(loadedRs.Elevation2SW, Is.EqualTo(2.1));
            Assert.That(loadedRs.FixedSun, Is.True);
            Assert.That(loadedRs.ObjectBonus, Is.EqualTo(1.4));
            Assert.That(loadedRs.RestrictPushing, Is.True);
            Assert.That(loadedRs.TerrainLowerLimit, Is.EqualTo(0.4));
            Assert.That(loadedRs.TerrainRaiseLimit, Is.EqualTo(17.9));
            Assert.That(loadedRs.TerrainTexture1, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000020")));
            Assert.That(loadedRs.TerrainTexture2, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000040")));
            Assert.That(loadedRs.TerrainTexture3, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000060")));
            Assert.That(loadedRs.TerrainTexture4, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000080")));
            Assert.That(loadedRs.UseEstateSun, Is.True);
            Assert.That(loadedRs.WaterHeight, Is.EqualTo(23));
        }
        public void StoreRegionSettings(RegionSettings rs)
        {
            lock (ds)
            {
                DataTable regionsettings = ds.Tables["regionsettings"];

                DataRow settingsRow = regionsettings.Rows.Find(rs.RegionUUID.ToString());
                if (settingsRow == null)
                {
                    settingsRow = regionsettings.NewRow();
                    fillRegionSettingsRow(settingsRow, rs);
                    regionsettings.Rows.Add(settingsRow);
                }
                else
                {
                    fillRegionSettingsRow(settingsRow, rs);
                }

                Commit();
            }
        }
 public void StoreRegionSettings(RegionSettings rs)
 {
 }
        public static string Serialize(RegionSettings settings)
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.Indented;
            xtw.WriteStartDocument();
            
            xtw.WriteStartElement("RegionSettings");
            
            xtw.WriteStartElement("General");
            xtw.WriteElementString("AllowDamage", settings.AllowDamage.ToString());
            xtw.WriteElementString("AllowLandResell", settings.AllowLandResell.ToString());
            xtw.WriteElementString("AllowLandJoinDivide", settings.AllowLandJoinDivide.ToString());
            xtw.WriteElementString("BlockFly", settings.BlockFly.ToString());
            xtw.WriteElementString("BlockLandShowInSearch", settings.BlockShowInSearch.ToString());
            xtw.WriteElementString("BlockTerraform", settings.BlockTerraform.ToString());
            xtw.WriteElementString("DisableCollisions", settings.DisableCollisions.ToString());
            xtw.WriteElementString("DisablePhysics", settings.DisablePhysics.ToString());
            xtw.WriteElementString("DisableScripts", settings.DisableScripts.ToString());
            xtw.WriteElementString("MaturityRating", settings.Maturity.ToString());
            xtw.WriteElementString("RestrictPushing", settings.RestrictPushing.ToString());
            xtw.WriteElementString("AgentLimit", settings.AgentLimit.ToString());
            xtw.WriteElementString("ObjectBonus", settings.ObjectBonus.ToString());
            xtw.WriteEndElement();

            xtw.WriteStartElement("GroundTextures");
            xtw.WriteElementString("Texture1", settings.TerrainTexture1.ToString());
            xtw.WriteElementString("Texture2", settings.TerrainTexture2.ToString());
            xtw.WriteElementString("Texture3", settings.TerrainTexture3.ToString());
            xtw.WriteElementString("Texture4", settings.TerrainTexture4.ToString());
            xtw.WriteElementString("ElevationLowSW", settings.Elevation1SW.ToString());
            xtw.WriteElementString("ElevationLowNW", settings.Elevation1NW.ToString());
            xtw.WriteElementString("ElevationLowSE", settings.Elevation1SE.ToString());
            xtw.WriteElementString("ElevationLowNE", settings.Elevation1NE.ToString());
            xtw.WriteElementString("ElevationHighSW", settings.Elevation2SW.ToString());
            xtw.WriteElementString("ElevationHighNW", settings.Elevation2NW.ToString());
            xtw.WriteElementString("ElevationHighSE", settings.Elevation2SE.ToString());
            xtw.WriteElementString("ElevationHighNE", settings.Elevation2NE.ToString());
            xtw.WriteEndElement();
            
            xtw.WriteStartElement("Terrain");
            xtw.WriteElementString("WaterHeight", settings.WaterHeight.ToString());
            xtw.WriteElementString("TerrainRaiseLimit", settings.TerrainRaiseLimit.ToString());
            xtw.WriteElementString("TerrainLowerLimit", settings.TerrainLowerLimit.ToString());
            xtw.WriteElementString("UseEstateSun", settings.UseEstateSun.ToString());
            xtw.WriteElementString("FixedSun", settings.FixedSun.ToString());
            // XXX: Need to expose interface to get sun phase information from sun module
            // xtw.WriteStartElement("SunPhase", 
            xtw.WriteEndElement(); 
            
            xtw.WriteEndElement();
            
            xtw.Close();
            sw.Close();
            
            return sw.ToString();
        }
        /// <summary>
        /// Store region settings, need to check if the check is really necesary. If we can make something for creating new region.
        /// </summary>
        /// <param name="regionSettings">region settings.</param>
        public void StoreRegionSettings(RegionSettings regionSettings)
        {
            //Little check if regionUUID already exist in DB
            string regionUUID;
            string sql = @"SELECT ""regionUUID"" FROM regionsettings WHERE ""regionUUID"" = :regionUUID";
            using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
            using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
            {
                cmd.Parameters.Add(_Database.CreateParameter("regionUUID", regionSettings.RegionUUID));
                conn.Open();
                regionUUID = cmd.ExecuteScalar().ToString();
            }

            if (string.IsNullOrEmpty(regionUUID))
            {
                StoreNewRegionSettings(regionSettings);
            }
            else
            {
                //This method only updates region settings!!! First call LoadRegionSettings to create new region settings in DB
                sql =
                   @"UPDATE regionsettings SET block_terraform = :block_terraform ,block_fly = :block_fly ,allow_damage = :allow_damage 
,restrict_pushing = :restrict_pushing ,allow_land_resell = :allow_land_resell ,allow_land_join_divide = :allow_land_join_divide 
,block_show_in_search = :block_show_in_search ,agent_limit = :agent_limit ,object_bonus = :object_bonus ,maturity = :maturity 
,disable_scripts = :disable_scripts ,disable_collisions = :disable_collisions ,disable_physics = :disable_physics 
,terrain_texture_1 = :terrain_texture_1 ,terrain_texture_2 = :terrain_texture_2 ,terrain_texture_3 = :terrain_texture_3 
,terrain_texture_4 = :terrain_texture_4 ,elevation_1_nw = :elevation_1_nw ,elevation_2_nw = :elevation_2_nw 
,elevation_1_ne = :elevation_1_ne ,elevation_2_ne = :elevation_2_ne ,elevation_1_se = :elevation_1_se ,elevation_2_se = :elevation_2_se 
,elevation_1_sw = :elevation_1_sw ,elevation_2_sw = :elevation_2_sw ,water_height = :water_height ,terrain_raise_limit = :terrain_raise_limit 
,terrain_lower_limit = :terrain_lower_limit ,use_estate_sun = :use_estate_sun ,fixed_sun = :fixed_sun ,sun_position = :sun_position 
,covenant = :covenant ,covenant_datetime = :covenant_datetime, sunvectorx = :sunvectorx, sunvectory = :sunvectory, sunvectorz = :sunvectorz,  
""Sandbox"" = :Sandbox, loaded_creation_datetime = :loaded_creation_datetime, loaded_creation_id = :loaded_creation_id, ""map_tile_ID"" = :TerrainImageID, ""block_search"" = :block_search, ""casino"" = :casino, 
""TelehubObject"" = :telehubobject, ""parcel_tile_ID"" = :ParcelImageID
 WHERE ""regionUUID"" = :regionUUID";

                using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
                using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
                {
                    cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
            }
            SaveSpawnPoints(regionSettings);
        }
        public void TestLoadOarRegionSettings()
        {
            TestHelpers.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            MemoryStream archiveWriteStream = new MemoryStream();
            TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream);
            
            tar.WriteDir(ArchiveConstants.TERRAINS_PATH);
            tar.WriteFile(
                ArchiveConstants.CONTROL_FILE_PATH,
                new ArchiveWriteRequest(m_scene, (Stream)null, Guid.Empty).CreateControlFile(new ArchiveScenesGroup()));

            RegionSettings rs = new RegionSettings();
            rs.AgentLimit = 17;
            rs.AllowDamage = true;
            rs.AllowLandJoinDivide = true;
            rs.AllowLandResell = true;
            rs.BlockFly = true;
            rs.BlockShowInSearch = true;
            rs.BlockTerraform = true;
            rs.DisableCollisions = true;
            rs.DisablePhysics = true;
            rs.DisableScripts = true;
            rs.Elevation1NW = 15.9;
            rs.Elevation1NE = 45.3;
            rs.Elevation1SE = 49;
            rs.Elevation1SW = 1.9;
            rs.Elevation2NW = 4.5;
            rs.Elevation2NE = 19.2;
            rs.Elevation2SE = 9.2;
            rs.Elevation2SW = 2.1;
            rs.FixedSun = true;
            rs.SunPosition = 12.0;
            rs.ObjectBonus = 1.4;
            rs.RestrictPushing = true;
            rs.TerrainLowerLimit = 0.4;
            rs.TerrainRaiseLimit = 17.9;
            rs.TerrainTexture1 = UUID.Parse("00000000-0000-0000-0000-000000000020");
            rs.TerrainTexture2 = UUID.Parse("00000000-0000-0000-0000-000000000040");
            rs.TerrainTexture3 = UUID.Parse("00000000-0000-0000-0000-000000000060");
            rs.TerrainTexture4 = UUID.Parse("00000000-0000-0000-0000-000000000080");
            rs.UseEstateSun = true;
            rs.WaterHeight = 23;
            rs.TelehubObject = UUID.Parse("00000000-0000-0000-0000-111111111111");
            rs.AddSpawnPoint(SpawnPoint.Parse("1,-2,0.33"));

            tar.WriteFile(ArchiveConstants.SETTINGS_PATH + "region1.xml", RegionSettingsSerializer.Serialize(rs));
            
            tar.Close();

            MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());

            lock (this)
            {
                m_scene.EventManager.OnOarFileLoaded += LoadCompleted;
                m_archiverModule.DearchiveRegion(archiveReadStream);
            }
            
            Assert.That(m_lastErrorMessage, Is.Null);
            RegionSettings loadedRs = m_scene.RegionInfo.RegionSettings;

            Assert.That(loadedRs.AgentLimit, Is.EqualTo(17));
            Assert.That(loadedRs.AllowDamage, Is.True);
            Assert.That(loadedRs.AllowLandJoinDivide, Is.True);
            Assert.That(loadedRs.AllowLandResell, Is.True);
            Assert.That(loadedRs.BlockFly, Is.True);
            Assert.That(loadedRs.BlockShowInSearch, Is.True);
            Assert.That(loadedRs.BlockTerraform, Is.True);
            Assert.That(loadedRs.DisableCollisions, Is.True);
            Assert.That(loadedRs.DisablePhysics, Is.True);
            Assert.That(loadedRs.DisableScripts, Is.True);
            Assert.That(loadedRs.Elevation1NW, Is.EqualTo(15.9));
            Assert.That(loadedRs.Elevation1NE, Is.EqualTo(45.3));
            Assert.That(loadedRs.Elevation1SE, Is.EqualTo(49));
            Assert.That(loadedRs.Elevation1SW, Is.EqualTo(1.9));
            Assert.That(loadedRs.Elevation2NW, Is.EqualTo(4.5));
            Assert.That(loadedRs.Elevation2NE, Is.EqualTo(19.2));
            Assert.That(loadedRs.Elevation2SE, Is.EqualTo(9.2));
            Assert.That(loadedRs.Elevation2SW, Is.EqualTo(2.1));
            Assert.That(loadedRs.FixedSun, Is.True);
            Assert.AreEqual(12.0, loadedRs.SunPosition);
            Assert.That(loadedRs.ObjectBonus, Is.EqualTo(1.4));
            Assert.That(loadedRs.RestrictPushing, Is.True);
            Assert.That(loadedRs.TerrainLowerLimit, Is.EqualTo(0.4));
            Assert.That(loadedRs.TerrainRaiseLimit, Is.EqualTo(17.9));
            Assert.That(loadedRs.TerrainTexture1, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000020")));
            Assert.That(loadedRs.TerrainTexture2, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000040")));
            Assert.That(loadedRs.TerrainTexture3, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000060")));
            Assert.That(loadedRs.TerrainTexture4, Is.EqualTo(UUID.Parse("00000000-0000-0000-0000-000000000080")));
            Assert.That(loadedRs.UseEstateSun, Is.True);
            Assert.That(loadedRs.WaterHeight, Is.EqualTo(23));
            Assert.AreEqual(UUID.Zero, loadedRs.TelehubObject); // because no object was found with the original UUID
            Assert.AreEqual(0, loadedRs.SpawnPoints().Count);
        }
        /// <summary>
        /// Stores new regionsettings.
        /// </summary>
        /// <param name="regionSettings">The region settings.</param>
        private void StoreNewRegionSettings(RegionSettings regionSettings)
        {
            string sql = @"INSERT INTO regionsettings
                                (""regionUUID"",block_terraform,block_fly,allow_damage,restrict_pushing,allow_land_resell,allow_land_join_divide,
                                block_show_in_search,agent_limit,object_bonus,maturity,disable_scripts,disable_collisions,disable_physics,
                                terrain_texture_1,terrain_texture_2,terrain_texture_3,terrain_texture_4,elevation_1_nw,elevation_2_nw,elevation_1_ne,
                                elevation_2_ne,elevation_1_se,elevation_2_se,elevation_1_sw,elevation_2_sw,water_height,terrain_raise_limit,
                                terrain_lower_limit,use_estate_sun,fixed_sun,sun_position,covenant,covenant_datetime,sunvectorx, sunvectory, sunvectorz,
                                ""Sandbox"", loaded_creation_datetime, loaded_creation_id,block_search,casino
                                ) 
                            VALUES
                                (:regionUUID,:block_terraform,:block_fly,:allow_damage,:restrict_pushing,:allow_land_resell,:allow_land_join_divide,
                                :block_show_in_search,:agent_limit,:object_bonus,:maturity,:disable_scripts,:disable_collisions,:disable_physics,
                                :terrain_texture_1,:terrain_texture_2,:terrain_texture_3,:terrain_texture_4,:elevation_1_nw,:elevation_2_nw,:elevation_1_ne,
                                :elevation_2_ne,:elevation_1_se,:elevation_2_se,:elevation_1_sw,:elevation_2_sw,:water_height,:terrain_raise_limit,
                                :terrain_lower_limit,:use_estate_sun,:fixed_sun,:sun_position,:covenant, :covenant_datetime, :sunvectorx,:sunvectory, 
                                :sunvectorz, :Sandbox, :loaded_creation_datetime, :loaded_creation_id, :block_search, :casino )";

            using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
            using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
            {
                cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
                conn.Open();
                cmd.ExecuteNonQuery();
            }
        }
        public void UnpackRegionInfoData(OSDMap args)
        {
            if (args.ContainsKey("region_id"))
                RegionID = args["region_id"].AsUUID();
            if (args.ContainsKey("region_name"))
                RegionName = args["region_name"].AsString();
            if (args.ContainsKey("external_host_name"))
                ExternalHostName = args["external_host_name"].AsString();
            if (args.ContainsKey("http_port"))
                UInt32.TryParse(args["http_port"].AsString(), out m_httpPort);
            if (args.ContainsKey("region_xloc"))
            {
                int locx;
                Int32.TryParse(args["region_xloc"].AsString(), out locx);
                RegionLocX = locx;
            }
            if (args.ContainsKey("region_yloc"))
            {
                int locy;
                Int32.TryParse(args["region_yloc"].AsString(), out locy);
                RegionLocY = locy;
            }
            IPAddress ip_addr = null;
            if (args.ContainsKey("internal_ep_address"))
            {
                IPAddress.TryParse(args["internal_ep_address"].AsString(), out ip_addr);
            }
            int port = 0;
            if (args.ContainsKey("internal_ep_port"))
            {
                Int32.TryParse(args["internal_ep_port"].AsString(), out port);
            }
            InternalEndPoint = new IPEndPoint(ip_addr, port);
            if (args.ContainsKey("allow_alt_ports"))
                m_allow_alternate_ports = args["allow_alt_ports"].AsBoolean();
            if (args.ContainsKey("region_type"))
                m_regionType = args["region_type"].AsString();
            if (args.ContainsKey("password"))
                Password = args["password"].AsUUID();

            if (args.ContainsKey("disabled"))
                Disabled = args["disabled"].AsBoolean();
            if (args.ContainsKey("scope_id"))
                ScopeID = args["scope_id"].AsUUID();

            if (args.ContainsKey("region_size_x"))
                RegionSizeX = args["region_size_x"].AsInteger();
            if (args.ContainsKey("region_size_y"))
                RegionSizeY = args["region_size_y"].AsInteger();
            if (args.ContainsKey("region_size_z"))
                RegionSizeZ = args["region_size_z"].AsInteger();

            if (args.ContainsKey("object_capacity"))
                m_objectCapacity = args["object_capacity"].AsInteger();
            if (args.ContainsKey("region_type"))
                RegionType = args["region_type"].AsString();
            if (args.ContainsKey("see_into_this_sim_from_neighbor"))
                SeeIntoThisSimFromNeighbor = args["see_into_this_sim_from_neighbor"].AsBoolean();
            if (args.ContainsKey("trust_binaries_from_foreign_sims"))
                TrustBinariesFromForeignSims = args["trust_binaries_from_foreign_sims"].AsBoolean();
            if (args.ContainsKey("allow_script_crossing"))
                AllowScriptCrossing = args["allow_script_crossing"].AsBoolean();
            if (args.ContainsKey("allow_physical_prims"))
                AllowPhysicalPrims = args["allow_physical_prims"].AsBoolean();
            if(args.ContainsKey("number_startup"))
                NumberStartup = args["number_startup"].AsInteger();
            if (args.ContainsKey ("startupType"))
                Startup = (StartupType)args["startupType"].AsInteger();
            FindExternalAutomatically = args["FindExternalIP"].AsBoolean();
            if (args.ContainsKey("RegionSettings"))
            {
                RegionSettings = new RegionSettings();
                RegionSettings.FromOSD((OSDMap)args["RegionSettings"]);
            }
        }
        private void LoadSpawnPoints(RegionSettings rs)
        {
            rs.ClearSpawnPoints();

            string sql = @"SELECT ""Yaw"", ""Pitch"", ""Distance"" FROM spawn_points WHERE ""RegionUUID"" = :RegionUUID";

            using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
            using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
            {
                cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID));
                conn.Open();
                using (NpgsqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        SpawnPoint sp = new SpawnPoint();

                        sp.Yaw = (float)reader["Yaw"];
                        sp.Pitch = (float)reader["Pitch"];
                        sp.Distance = (float)reader["Distance"];

                        rs.AddSpawnPoint(sp);
                    }
                }
            }
        }
 private void SaveSpawnPoints(RegionSettings rs)
 {
     string sql = @"DELETE FROM spawn_points WHERE ""RegionUUID"" = :RegionUUID";
     using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
     using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
     {
         cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID));
         conn.Open();
         cmd.ExecuteNonQuery();
     }
     foreach (SpawnPoint p in rs.SpawnPoints())
     {
         sql = @"INSERT INTO spawn_points (""RegionUUID"", ""Yaw"", ""Pitch"", ""Distance"") VALUES (:RegionUUID, :Yaw, :Pitch, :Distance)";
         using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
         using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
         {
             cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID));
             cmd.Parameters.Add(_Database.CreateParameter("Yaw", p.Yaw));
             cmd.Parameters.Add(_Database.CreateParameter("Pitch", p.Pitch));
             cmd.Parameters.Add(_Database.CreateParameter("Distance", p.Distance));
             conn.Open();
             cmd.ExecuteNonQuery();
         }
     }
 }
Beispiel #28
0
        /// <summary>
        /// Loads the settings of a region.
        /// </summary>
        /// <param name="regionUUID">The region UUID.</param>
        /// <returns></returns>
        public RegionSettings LoadRegionSettings(UUID regionUUID)
        {
            string sql = "select * from regionsettings where regionUUID = @regionUUID";
            RegionSettings regionSettings;
            using (AutoClosingSqlCommand cmd = _Database.Query(sql))
            {
                cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        regionSettings = BuildRegionSettings(reader);
                        regionSettings.OnSave += StoreRegionSettings;

                        return regionSettings;
                    }
                }
            }

            //If comes here then there is now region setting for that region
            regionSettings = new RegionSettings();
            regionSettings.RegionUUID = regionUUID;
            regionSettings.OnSave += StoreRegionSettings;

            //Store new values
            StoreNewRegionSettings(regionSettings);

            return regionSettings;
        }
        /// <summary>
        /// Creates the region setting parameters.
        /// </summary>
        /// <param name="settings">regionsettings.</param>
        /// <returns></returns>
        private SqlParameter[] CreateRegionSettingParameters(RegionSettings settings)
        {
            List<SqlParameter> parameters = new List<SqlParameter>();

            parameters.Add(_Database.CreateParameter("regionUUID", settings.RegionUUID));
            parameters.Add(_Database.CreateParameter("block_terraform", settings.BlockTerraform));
            parameters.Add(_Database.CreateParameter("block_fly", settings.BlockFly));
            parameters.Add(_Database.CreateParameter("allow_damage", settings.AllowDamage));
            parameters.Add(_Database.CreateParameter("restrict_pushing", settings.RestrictPushing));
            parameters.Add(_Database.CreateParameter("allow_land_resell", settings.AllowLandResell));
            parameters.Add(_Database.CreateParameter("allow_land_join_divide", settings.AllowLandJoinDivide));
            parameters.Add(_Database.CreateParameter("block_show_in_search", settings.BlockShowInSearch));
            parameters.Add(_Database.CreateParameter("agent_limit", settings.AgentLimit));
            parameters.Add(_Database.CreateParameter("object_bonus", settings.ObjectBonus));
            parameters.Add(_Database.CreateParameter("maturity", settings.Maturity));
            parameters.Add(_Database.CreateParameter("disable_scripts", settings.DisableScripts));
            parameters.Add(_Database.CreateParameter("disable_collisions", settings.DisableCollisions));
            parameters.Add(_Database.CreateParameter("disable_physics", settings.DisablePhysics));
            parameters.Add(_Database.CreateParameter("terrain_texture_1", settings.TerrainTexture1));
            parameters.Add(_Database.CreateParameter("terrain_texture_2", settings.TerrainTexture2));
            parameters.Add(_Database.CreateParameter("terrain_texture_3", settings.TerrainTexture3));
            parameters.Add(_Database.CreateParameter("terrain_texture_4", settings.TerrainTexture4));
            parameters.Add(_Database.CreateParameter("elevation_1_nw", settings.Elevation1NW));
            parameters.Add(_Database.CreateParameter("elevation_2_nw", settings.Elevation2NW));
            parameters.Add(_Database.CreateParameter("elevation_1_ne", settings.Elevation1NE));
            parameters.Add(_Database.CreateParameter("elevation_2_ne", settings.Elevation2NE));
            parameters.Add(_Database.CreateParameter("elevation_1_se", settings.Elevation1SE));
            parameters.Add(_Database.CreateParameter("elevation_2_se", settings.Elevation2SE));
            parameters.Add(_Database.CreateParameter("elevation_1_sw", settings.Elevation1SW));
            parameters.Add(_Database.CreateParameter("elevation_2_sw", settings.Elevation2SW));
            parameters.Add(_Database.CreateParameter("water_height", settings.WaterHeight));
            parameters.Add(_Database.CreateParameter("terrain_raise_limit", settings.TerrainRaiseLimit));
            parameters.Add(_Database.CreateParameter("terrain_lower_limit", settings.TerrainLowerLimit));
            parameters.Add(_Database.CreateParameter("use_estate_sun", settings.UseEstateSun));
            parameters.Add(_Database.CreateParameter("sandbox", settings.Sandbox));
            parameters.Add(_Database.CreateParameter("fixed_sun", settings.FixedSun));
            parameters.Add(_Database.CreateParameter("sun_position", settings.SunPosition));
            parameters.Add(_Database.CreateParameter("sunvectorx", settings.SunVector.X));
            parameters.Add(_Database.CreateParameter("sunvectory", settings.SunVector.Y));
            parameters.Add(_Database.CreateParameter("sunvectorz", settings.SunVector.Z));
            parameters.Add(_Database.CreateParameter("covenant", settings.Covenant));
            parameters.Add(_Database.CreateParameter("Loaded_Creation_DateTime", settings.LoadedCreationDateTime));
            parameters.Add(_Database.CreateParameter("Loaded_Creation_ID", settings.LoadedCreationID));

            return parameters.ToArray();
        }
Beispiel #30
0
        // Add a terrain to the renderer.
        // Note that we create a 'low resolution' 257x257 vertex terrain rather than trying for
        //    full resolution. This saves a lot of memory especially for very large regions.
        private void CreateTerrain(WarpRenderer renderer)
        {
            ITerrainChannel terrain = m_scene.Heightmap;

            float regionsx = m_scene.RegionInfo.RegionSizeX;
            float regionsy = m_scene.RegionInfo.RegionSizeY;

            // 'diff' is the difference in scale between the real region size and the size of terrain we're buiding

            int bitWidth;
            int bitHeight;

            const double log2inv = 1.4426950408889634073599246810019;

            bitWidth  = (int)Math.Ceiling((Math.Log(terrain.Width) * log2inv));
            bitHeight = (int)Math.Ceiling((Math.Log(terrain.Height) * log2inv));

            if (bitWidth > 8) // more than 256 is very heavy :(
            {
                bitWidth = 8;
            }
            if (bitHeight > 8)
            {
                bitHeight = 8;
            }

            int twidth  = (int)Math.Pow(2, bitWidth);
            int theight = (int)Math.Pow(2, bitHeight);

            float diff = regionsx / twidth;

            int npointsx = (int)(regionsx / diff);
            int npointsy = (int)(regionsy / diff);

            float invsx = 1.0f / (npointsx * diff);
            float invsy = 1.0f / (npointsy * diff);

            npointsx++;
            npointsy++;

            // Create all the vertices for the terrain
            warp_Object obj = new warp_Object();
            warp_Vector pos;
            float       x, y;
            float       tv;

            for (y = 0; y < regionsy; y += diff)
            {
                tv = y * invsy;
                for (x = 0; x < regionsx; x += diff)
                {
                    pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]);
                    obj.addVertex(new warp_Vertex(pos, x * invsx, tv));
                }
                pos = ConvertVector(x, y, (float)terrain[(int)(x - diff), (int)y]);
                obj.addVertex(new warp_Vertex(pos, 1.0f, tv));
            }

            int lastY = (int)(y - diff);

            for (x = 0; x < regionsx; x += diff)
            {
                pos = ConvertVector(x, y, (float)terrain[(int)x, lastY]);
                obj.addVertex(new warp_Vertex(pos, x * invsx, 1.0f));
            }
            pos = ConvertVector(x, y, (float)terrain[(int)(x - diff), lastY]);
            obj.addVertex(new warp_Vertex(pos, 1.0f, 1.0f));

            // create triangles.
            int limx = npointsx - 1;
            int limy = npointsy - 1;

            for (int j = 0; j < limy; j++)
            {
                for (int i = 0; i < limx; i++)
                {
                    int v = j * npointsx + i;

                    // Make two triangles for each of the squares in the grid of vertices
                    obj.addTriangle(
                        v,
                        v + 1,
                        v + npointsx);

                    obj.addTriangle(
                        v + npointsx + 1,
                        v + npointsx,
                        v + 1);
                }
            }

            renderer.Scene.addObject("Terrain", obj);

            UUID[]  textureIDs   = new UUID[4];
            float[] startHeights = new float[4];
            float[] heightRanges = new float[4];

            OpenSim.Framework.RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings;

            textureIDs[0] = regionInfo.TerrainTexture1;
            textureIDs[1] = regionInfo.TerrainTexture2;
            textureIDs[2] = regionInfo.TerrainTexture3;
            textureIDs[3] = regionInfo.TerrainTexture4;

            startHeights[0] = (float)regionInfo.Elevation1SW;
            startHeights[1] = (float)regionInfo.Elevation1NW;
            startHeights[2] = (float)regionInfo.Elevation1SE;
            startHeights[3] = (float)regionInfo.Elevation1NE;

            heightRanges[0] = (float)regionInfo.Elevation2SW;
            heightRanges[1] = (float)regionInfo.Elevation2NW;
            heightRanges[2] = (float)regionInfo.Elevation2SE;
            heightRanges[3] = (float)regionInfo.Elevation2NE;

            warp_Texture texture;

            using (Bitmap image = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges,
                                                     m_scene.RegionInfo.WorldLocX, m_scene.RegionInfo.WorldLocY,
                                                     m_scene.AssetService, m_imgDecoder, m_textureTerrain, m_textureAverageTerrain,
                                                     twidth, twidth))
                texture = new warp_Texture(image);

            warp_Material material = new warp_Material(texture);

            renderer.Scene.addMaterial("TerrainMat", material);
            renderer.SetObjectMaterial("Terrain", "TerrainMat");
        }
        /// <summary>
        /// Loads the settings of a region.
        /// </summary>
        /// <param name="regionUUID">The region UUID.</param>
        /// <returns></returns>
        public RegionSettings LoadRegionSettings(UUID regionUUID)
        {
            string sql = "select * from regionsettings where regionUUID = @regionUUID";
            RegionSettings regionSettings;
            using (SqlConnection conn = new SqlConnection(m_connectionString))
            using (SqlCommand cmd = new SqlCommand(sql, conn))
            {
                cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
                conn.Open();
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        regionSettings = BuildRegionSettings(reader);
                        regionSettings.OnSave += StoreRegionSettings;

                        return regionSettings;
                    }
                }
            }

            //If we reach this point then there are new region settings for that region
            regionSettings = new RegionSettings();
            regionSettings.RegionUUID = regionUUID;
            regionSettings.OnSave += StoreRegionSettings;

            //Store new values
            StoreNewRegionSettings(regionSettings);

            return regionSettings;
        }