From cbf5ff4a9371c067dbe36ef28487c8784b9229d2 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Thu, 27 Dec 2007 05:37:48 +0000 Subject: [PATCH] * Added Sit Target persistence over sim restarts for mySQL and MonoSQLite. * SAVE YOUR PRIM DATA, THIS MAKES CHANGES TO YOUR PRIMS TABLE * The first time you run OpenSim after updating past this revision, you'll see a lot of Errors. Be calm, shutdown the simulator, and start it again and your prims table will be updated. * MSSQL added the fields to the Initial CreateTable section, however, you'll need to add the fields to your prims table if you want it to persist. --- .../Framework/Data.MySQL/MySQLDataStore.cs | 42 ++++++++++++++++ .../Environment/Scenes/SceneObjectPart.cs | 27 +++++++++++ .../OpenSim.DataStore.MSSQL/MSSQLDataStore.cs | 46 ++++++++++++++++++ .../MonoSqliteDataStore.cs | 48 +++++++++++++++++++ 4 files changed, 163 insertions(+) diff --git a/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs b/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs index 962d573c0d..61b22a0a29 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs @@ -523,6 +523,16 @@ namespace OpenSim.Framework.Data.MySQL createCol(prims, "RotationY", typeof(Double)); createCol(prims, "RotationZ", typeof(Double)); createCol(prims, "RotationW", typeof(Double)); + // sit target + createCol(prims, "SitTargetOffsetX", typeof(Double)); + createCol(prims, "SitTargetOffsetY", typeof(Double)); + createCol(prims, "SitTargetOffsetZ", typeof(Double)); + + createCol(prims, "SitTargetOrientW", typeof(Double)); + createCol(prims, "SitTargetOrientX", typeof(Double)); + createCol(prims, "SitTargetOrientY", typeof(Double)); + createCol(prims, "SitTargetOrientZ", typeof(Double)); + // Add in contraints prims.PrimaryKey = new DataColumn[] { prims.Columns["UUID"] }; @@ -688,7 +698,26 @@ namespace OpenSim.Framework.Data.MySQL Convert.ToSingle(row["RotationZ"]), Convert.ToSingle(row["RotationW"]) ); + try + { + prim.SetSitTargetLL(new LLVector3( + Convert.ToSingle(row["SitTargetOffsetX"]), + Convert.ToSingle(row["SitTargetOffsetX"]), + Convert.ToSingle(row["SitTargetOffsetZ"])), new LLQuaternion( + Convert.ToSingle(row["SitTargetOrientW"]), + Convert.ToSingle(row["SitTargetOrientX"]), + Convert.ToSingle(row["SitTargetOrientY"]), + Convert.ToSingle(row["SitTargetOrientX"]))); + } + catch (System.InvalidCastException) + { + // Database table was created before we got here and needs to be created! :P + using (MySqlCommand cmd = new MySqlCommand("ALTER TABLE `prims` ADD COLUMN `SitTargetOffsetX` float NOT NULL default 0, ADD COLUMN `SitTargetOffsetY` float NOT NULL default 0, ADD COLUMN `SitTargetOffsetZ` float NOT NULL default 0, ADD COLUMN `SitTargetOrientW` float NOT NULL default 0, ADD COLUMN `SitTargetOrientX` float NOT NULL default 0, ADD COLUMN `SitTargetOrientY` float NOT NULL default 0, ADD COLUMN `SitTargetOrientZ` float NOT NULL default 0;", m_connection)) + { + cmd.ExecuteNonQuery(); + } + } return prim; } @@ -798,6 +827,19 @@ namespace OpenSim.Framework.Data.MySQL row["RotationY"] = prim.RotationOffset.Y; row["RotationZ"] = prim.RotationOffset.Z; row["RotationW"] = prim.RotationOffset.W; + + // Sit target + LLVector3 sitTargetPos = prim.GetSitTargetPositionLL(); + row["SitTargetOffsetX"] = sitTargetPos.X; + row["SitTargetOffsetY"] = sitTargetPos.Y; + row["SitTargetOffsetZ"] = sitTargetPos.Z; + + LLQuaternion sitTargetOrient = prim.GetSitTargetOrientationLL(); + row["SitTargetOrientW"] = sitTargetOrient.W; + row["SitTargetOrientX"] = sitTargetOrient.X; + row["SitTargetOrientY"] = sitTargetOrient.Y; + row["SitTargetOrientZ"] = sitTargetOrient.Z; + } private void fillLandRow(DataRow row, LandData land, LLUUID regionUUID) diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index bcd31c2f5b..973c30ec38 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -72,6 +72,8 @@ namespace OpenSim.Region.Environment.Scenes private Quaternion m_sitTargetOrientation = new Quaternion(0, 0, 0, 1); private LLUUID m_SitTargetAvatar = LLUUID.Zero; + + // Main grid has default permissions as follows // @@ -345,6 +347,15 @@ namespace OpenSim.Region.Environment.Scenes private string m_text = ""; + public Vector3 SitTargetPosition + { + get { return m_sitTargetPosition; } + } + public Quaternion SitTargetOrientation + { + get { return m_sitTargetOrientation; } + } + public string Text { get { return m_text; } @@ -786,6 +797,22 @@ namespace OpenSim.Region.Environment.Scenes m_sitTargetPosition = offset; m_sitTargetOrientation = orientation; } + public LLVector3 GetSitTargetPositionLL() + { + return new LLVector3(m_sitTargetPosition.x, m_sitTargetPosition.y, m_sitTargetPosition.z); + } + + public LLQuaternion GetSitTargetOrientationLL() + { + return new LLQuaternion(m_sitTargetOrientation.w, m_sitTargetOrientation.x, m_sitTargetOrientation.y, m_sitTargetOrientation.z); + } + + // Utility function so the databases don't have to reference axiom.math + public void SetSitTargetLL(LLVector3 offset, LLQuaternion orientation) + { + m_sitTargetPosition = new Vector3(offset.X, offset.Y, offset.Z); + m_sitTargetOrientation = new Quaternion(orientation.W, orientation.X, orientation.Y, orientation.Z); + } public Vector3 GetSitTargetPosition() { diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.MSSQL/MSSQLDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.MSSQL/MSSQLDataStore.cs index c6210f7a48..91edf5e6bc 100644 --- a/OpenSim/Region/Storage/OpenSim.DataStore.MSSQL/MSSQLDataStore.cs +++ b/OpenSim/Region/Storage/OpenSim.DataStore.MSSQL/MSSQLDataStore.cs @@ -391,6 +391,16 @@ namespace OpenSim.DataStore.MSSQL createCol(prims, "RotationZ", typeof(System.Double)); createCol(prims, "RotationW", typeof(System.Double)); + // sit target + createCol(prims, "SitTargetOffsetX", typeof(System.Double)); + createCol(prims, "SitTargetOffsetY", typeof(System.Double)); + createCol(prims, "SitTargetOffsetZ", typeof(System.Double)); + + createCol(prims, "SitTargetOrientW", typeof(System.Double)); + createCol(prims, "SitTargetOrientX", typeof(System.Double)); + createCol(prims, "SitTargetOrientY", typeof(System.Double)); + createCol(prims, "SitTargetOrientZ", typeof(System.Double)); + // Add in contraints prims.PrimaryKey = new DataColumn[] { prims.Columns["UUID"] }; @@ -508,6 +518,22 @@ namespace OpenSim.DataStore.MSSQL Convert.ToSingle(row["RotationW"]) ); + try + { + prim.SetSitTargetLL(new LLVector3( + Convert.ToSingle(row["SitTargetOffsetX"]), + Convert.ToSingle(row["SitTargetOffsetX"]), + Convert.ToSingle(row["SitTargetOffsetZ"])), new LLQuaternion( + Convert.ToSingle(row["SitTargetOrientW"]), + Convert.ToSingle(row["SitTargetOrientX"]), + Convert.ToSingle(row["SitTargetOrientY"]), + Convert.ToSingle(row["SitTargetOrientX"]))); + } + catch (System.InvalidCastException) + { + // Database table was created before we got here and now has null values :P + } + return prim; } @@ -557,6 +583,26 @@ namespace OpenSim.DataStore.MSSQL row["RotationY"] = prim.RotationOffset.Y; row["RotationZ"] = prim.RotationOffset.Z; row["RotationW"] = prim.RotationOffset.W; + + try + { + // Sit target + LLVector3 sitTargetPos = prim.GetSitTargetPositionLL(); + row["SitTargetOffsetX"] = sitTargetPos.X; + row["SitTargetOffsetY"] = sitTargetPos.Y; + row["SitTargetOffsetZ"] = sitTargetPos.Z; + + LLQuaternion sitTargetOrient = prim.GetSitTargetOrientationLL(); + row["SitTargetOrientW"] = sitTargetOrient.W; + row["SitTargetOrientX"] = sitTargetOrient.X; + row["SitTargetOrientY"] = sitTargetOrient.Y; + row["SitTargetOrientZ"] = sitTargetOrient.Z; + } + catch (System.Exception) + { + // TODO: Add Sit Target Rows! + } + } private PrimitiveBaseShape buildShape(DataRow row) diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs index 6750e4db57..5bf4551ed7 100644 --- a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs +++ b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs @@ -56,6 +56,8 @@ namespace OpenSim.DataStore.MonoSqlite private SqliteDataAdapter landDa; private SqliteDataAdapter landAccessListDa; + private SqliteConnection m_conn; + private String m_connectionString; private bool persistPrimInventories; @@ -77,6 +79,9 @@ namespace OpenSim.DataStore.MonoSqlite MainLog.Instance.Verbose("DATASTORE", "Sqlite - connecting: " + connectionString); SqliteConnection conn = new SqliteConnection(m_connectionString); + // Arg! Hate databases.. + m_conn = conn; + SqliteCommand primSelectCmd = new SqliteCommand(primSelect, conn); primDa = new SqliteDataAdapter(primSelectCmd); // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa); @@ -564,6 +569,16 @@ namespace OpenSim.DataStore.MonoSqlite createCol(prims, "RotationZ", typeof (Double)); createCol(prims, "RotationW", typeof (Double)); + // sit target + createCol(prims, "SitTargetOffsetX", typeof(Double)); + createCol(prims, "SitTargetOffsetY", typeof(Double)); + createCol(prims, "SitTargetOffsetZ", typeof(Double)); + + createCol(prims, "SitTargetOrientW", typeof(Double)); + createCol(prims, "SitTargetOrientX", typeof(Double)); + createCol(prims, "SitTargetOrientY", typeof(Double)); + createCol(prims, "SitTargetOrientZ", typeof(Double)); + // Add in contraints prims.PrimaryKey = new DataColumn[] {prims.Columns["UUID"]}; @@ -764,6 +779,26 @@ namespace OpenSim.DataStore.MonoSqlite Convert.ToSingle(row["RotationW"]) ); + try + { + prim.SetSitTargetLL(new LLVector3( + Convert.ToSingle(row["SitTargetOffsetX"]), + Convert.ToSingle(row["SitTargetOffsetX"]), + Convert.ToSingle(row["SitTargetOffsetZ"])), new LLQuaternion( + Convert.ToSingle(row["SitTargetOrientW"]), + Convert.ToSingle(row["SitTargetOrientX"]), + Convert.ToSingle(row["SitTargetOrientY"]), + Convert.ToSingle(row["SitTargetOrientX"]))); + } + catch (System.InvalidCastException) + { + // Database table was created before we got here and now has null values :P + using (SqliteCommand cmd = new SqliteCommand("ALTER TABLE `prims` ADD COLUMN `SitTargetOffsetX` float NOT NULL default 0, ADD COLUMN `SitTargetOffsetY` float NOT NULL default 0, ADD COLUMN `SitTargetOffsetZ` float NOT NULL default 0, ADD COLUMN `SitTargetOrientW` float NOT NULL default 0, ADD COLUMN `SitTargetOrientX` float NOT NULL default 0, ADD COLUMN `SitTargetOrientY` float NOT NULL default 0, ADD COLUMN `SitTargetOrientZ` float NOT NULL default 0;", m_conn)) + { + cmd.ExecuteNonQuery(); + } + } + return prim; } @@ -889,6 +924,18 @@ namespace OpenSim.DataStore.MonoSqlite row["RotationY"] = prim.RotationOffset.Y; row["RotationZ"] = prim.RotationOffset.Z; row["RotationW"] = prim.RotationOffset.W; + + // Sit target + LLVector3 sitTargetPos = prim.GetSitTargetPositionLL(); + row["SitTargetOffsetX"] = sitTargetPos.X; + row["SitTargetOffsetY"] = sitTargetPos.Y; + row["SitTargetOffsetZ"] = sitTargetPos.Z; + + LLQuaternion sitTargetOrient = prim.GetSitTargetOrientationLL(); + row["SitTargetOrientW"] = sitTargetOrient.W; + row["SitTargetOrientX"] = sitTargetOrient.X; + row["SitTargetOrientY"] = sitTargetOrient.Y; + row["SitTargetOrientZ"] = sitTargetOrient.Z; } private void fillLandRow(DataRow row, LandData land, LLUUID regionUUID) @@ -1331,6 +1378,7 @@ namespace OpenSim.DataStore.MonoSqlite DataSet tmpDS = new DataSet(); try { + pDa.Fill(tmpDS, "prims"); sDa.Fill(tmpDS, "primshapes");