From af29f4083fc8aa88d671e2385c7711e81aac7868 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Fri, 28 Jan 2011 13:59:04 -0800 Subject: [PATCH] move logging to central module. Fix orientation bug. Fix message echo bug. --- .../PhysEngineToSceneConnector.cs | 95 ++----------------- .../PhysEngineToSceneConnectorModule.cs | 5 +- .../SceneToPhysEngineConnector.cs | 8 +- .../SceneToPhysEngineSyncServer.cs | 84 ++++++++++++++++ OpenSim/Region/Physics/PEPlugin/PEScene.cs | 4 +- 5 files changed, 103 insertions(+), 93 deletions(-) diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnector.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnector.cs index 8b88ecb1de..62bdcf6efc 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnector.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnector.cs @@ -108,8 +108,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //m_statsTimer.Elapsed += new System.Timers.ElapsedEventHandler(StatsTimerElapsed); m_sysConfig = sysConfig; - logEnabled = m_sysConfig.GetBoolean("LogEnabled", false); - logDir = m_sysConfig.GetString("LogDir", "."); + SceneToPhysEngineSyncServer.logEnabled = m_sysConfig.GetBoolean("LogEnabled", false); + SceneToPhysEngineSyncServer.logDir = m_sysConfig.GetString("LogDir", "."); //assume we are connecting to the whole scene as one big quark m_subscribedQuarks = new QuarkSubsriptionInfo(0, 0, (int)Constants.RegionSize, (int)Constants.RegionSize); @@ -258,7 +258,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_client.Client.Close(); m_client.Close(); } - LogMessageClose(); + SceneToPhysEngineSyncServer.PhysLogMessageClose(); } // Listen for messages from a RegionSyncServer @@ -301,14 +301,12 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule // Send a message to a single connected RegionSyncServer private void Send(string msg) { - LogMessage(logOutput, msg); byte[] bmsg = System.Text.Encoding.ASCII.GetBytes(msg + System.Environment.NewLine); Send(bmsg); } private void Send(RegionSyncMessage msg) { - LogMessage(logOutput, msg); Send(msg.ToBytes()); //m_log.WarnFormat("{0} Sent {1}", LogHeader, msg.ToString()); } @@ -347,7 +345,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule { //TO FINISH: - LogMessage(logInput, msg); + SceneToPhysEngineSyncServer.PhysLogMessage(false, msg); switch (msg.Type) { case RegionSyncMessage.MsgType.RegionName: @@ -386,14 +384,13 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule if (pa != null) { // pa.Size = data["size"].AsVector3(); - pa.ChangingActorID = actorID; pa.Position = data["position"].AsVector3(); pa.Force = data["force"].AsVector3(); pa.Velocity = data["velocity"].AsVector3(); pa.RotationalVelocity = data["rotationalVelocity"].AsVector3(); pa.Acceleration = data["acceleration"].AsVector3(); pa.Torque = data["torque"].AsVector3(); - pa.Orientation = data["orientantion"].AsQuaternion(); + pa.Orientation = data["orientation"].AsQuaternion(); pa.IsPhysical = data["isPhysical"].AsBoolean(); // receive?? pa.Flying = data["flying"].AsBoolean(); // receive?? pa.Kinematic = data["kinematic"].AsBoolean(); // receive?? @@ -403,6 +400,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule { pa.Shape = sop.Shape; } + pa.ChangingActorID = actorID; m_validLocalScene.PhysicsScene.AddPhysicsActorTaint(pa); } else @@ -438,7 +436,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule public void SendPhysUpdateAttributes(PhysicsActor pa) { // m_log.DebugFormat("{0}: SendPhysUpdateAttributes for {1}", LogHeader, pa.UUID); - OSDMap data = new OSDMap(9); + OSDMap data = new OSDMap(17); + data["time"] = OSD.FromString(DateTime.Now.ToString("yyyyMMddHHmmssfff")); data["localID"] = OSD.FromUInteger(pa.LocalID); data["uuid"] = OSD.FromUUID(pa.UUID); data["actorID"] = OSD.FromString(RegionSyncServerModule.ActorID); @@ -526,84 +525,6 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule } #endregion Handlers for events/updates from Scene - #region Message Logging - private bool logInput = false; - private bool logOutput = true; - private bool logEnabled = true; - private class MsgLogger - { - public DateTime startTime; - public string path = null; - public System.IO.TextWriter Log = null; - } - private MsgLogger logWriter = null; - private TimeSpan logMaxFileTime = new TimeSpan(0, 5, 0); // (h,m,s) => 5 minutes - private string logDir = "/stats/stats"; - private object logLocker = new Object(); - - private void LogMessage(bool direction, RegionSyncMessage rsm) - { - if (!logEnabled) return; // save to work of the ToStringFull if not enabled - LogMessage(direction, rsm.ToStringFull()); - } - - private void LogMessage(bool direction, string msg) - { - if (!logEnabled) return; - - lock (logLocker) - { - try - { - DateTime now = DateTime.Now; - if (logWriter == null || (now > logWriter.startTime + logMaxFileTime)) - { - if (logWriter != null && logWriter.Log != null) - { - logWriter.Log.Close(); - logWriter.Log.Dispose(); - logWriter.Log = null; - } - - // First log file or time has expired, start writing to a new log file - logWriter = new MsgLogger(); - logWriter.startTime = now; - logWriter.path = (logDir.Length > 0 ? logDir + System.IO.Path.DirectorySeparatorChar.ToString() : "") - + String.Format("physics-{0}.log", now.ToString("yyyyMMddHHmmss")); - logWriter.Log = new StreamWriter(File.Open(logWriter.path, FileMode.Append, FileAccess.Write)); - } - if (logWriter != null && logWriter.Log != null) - { - StringBuilder buff = new StringBuilder(); - buff.Append(now.ToString("yyyyMMddHHmmss")); - buff.Append(" "); - buff.Append(direction ? "A->S:" : "S->A:"); - buff.Append(msg); - buff.Append("\r\n"); - logWriter.Log.Write(buff.ToString()); - } - } - catch (Exception e) - { - m_log.ErrorFormat("{0}: FAILURE WRITING TO LOGFILE: {1}", LogHeader, e); - logEnabled = false; - } - } - return; - } - - private void LogMessageClose() - { - if (logWriter != null && logWriter.Log != null) - { - logWriter.Log.Close(); - logWriter.Log.Dispose(); - logWriter.Log = null; - logWriter = null; - } - logEnabled = false; - } - #endregion Message Logging } } diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnectorModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnectorModule.cs index d14adfae33..0b77ea898b 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnectorModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnectorModule.cs @@ -301,7 +301,10 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule public void SendUpdate(PhysicsActor pa) { - this.m_physEngineToSceneConnector.SendPhysUpdateAttributes(pa); + if (this.m_physEngineToSceneConnector != null) + { + this.m_physEngineToSceneConnector.SendPhysUpdateAttributes(pa); + } } #region Console Command Interface diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineConnector.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineConnector.cs index 075232d623..ea3601d98d 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineConnector.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineConnector.cs @@ -230,6 +230,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule // We could handle messages from an incoming Queue private void HandleMessage(RegionSyncMessage msg) { + SceneToPhysEngineSyncServer.PhysLogMessage(true, msg); msgCount++; //string handlerMessage = ""; switch (msg.Type) @@ -345,7 +346,6 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule PhysicsActor pa = FindPhysicsActor(uuid); if (pa != null) { - pa.ChangingActorID = actorID; pa.Size = data["size"].AsVector3(); pa.Position = data["position"].AsVector3(); pa.Force = data["force"].AsVector3(); @@ -353,13 +353,14 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule pa.RotationalVelocity = data["rotationalVelocity"].AsVector3(); pa.Acceleration = data["acceleration"].AsVector3(); pa.Torque = data["torque"].AsVector3(); - pa.Orientation = data["orientantion"].AsQuaternion(); + pa.Orientation = data["orientation"].AsQuaternion(); pa.IsPhysical = data["isPhysical"].AsBoolean(); // receive?? pa.Flying = data["flying"].AsBoolean(); // receive?? pa.Kinematic = data["kinematic"].AsBoolean(); // receive?? pa.Buoyancy = (float)(data["buoyancy"].AsReal()); pa.CollidingGround = data["isCollidingGround"].AsBoolean(); pa.IsColliding = data["isCollidingGround"].AsBoolean(); + pa.ChangingActorID = actorID; pa.RequestPhysicsterseUpdate(); // tell the system the values have changed } @@ -396,7 +397,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule public void SendPhysUpdateAttributes(PhysicsActor pa) { // m_log.DebugFormat("{0}: sending PhysUpdateAttributes for {1}", LogHeader, pa.UUID); - OSDMap data = new OSDMap(9); + OSDMap data = new OSDMap(15); + data["time"] = OSD.FromString(DateTime.Now.ToString("yyyyMMddHHmmssfff")); data["localID"] = OSD.FromUInteger(pa.LocalID); data["uuid"] = OSD.FromUUID(pa.UUID); data["actorID"] = OSD.FromString(RegionSyncServerModule.ActorID); diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineSyncServer.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineSyncServer.cs index 14b10033f4..a4cbb96c81 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineSyncServer.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineSyncServer.cs @@ -677,5 +677,89 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule } #endregion Load balancing functions + + #region Message Logging + public static bool logInput = false; + public static bool logOutput = true; + public static bool logEnabled = true; + private class PhysMsgLogger + { + public DateTime startTime; + public string path = null; + public System.IO.TextWriter Log = null; + } + private static PhysMsgLogger logWriter = null; + private static TimeSpan logMaxFileTime = new TimeSpan(0, 5, 0); // (h,m,s) => 5 minutes + public static string logDir = "/stats/stats"; + private static object logLocker = new Object(); + + public static void PhysLogMessage(bool direction, RegionSyncMessage rsm) + { + if (!logEnabled) return; // save to work of the ToStringFull if not enabled + PhysLogMessage(direction, rsm.ToStringFull()); + } + + /// + /// Log a physics bucket message + /// + /// True of message originated from the agent + /// the message to log + public static void PhysLogMessage(bool direction, string msg) + { + if (!logEnabled) return; + + lock (logLocker) + { + try + { + DateTime now = DateTime.Now; + if (logWriter == null || (now > logWriter.startTime + logMaxFileTime)) + { + if (logWriter != null && logWriter.Log != null) + { + logWriter.Log.Close(); + logWriter.Log.Dispose(); + logWriter.Log = null; + } + + // First log file or time has expired, start writing to a new log file + logWriter = new PhysMsgLogger(); + logWriter.startTime = now; + logWriter.path = (logDir.Length > 0 ? logDir + System.IO.Path.DirectorySeparatorChar.ToString() : "") + + String.Format("physics-{0}.log", now.ToString("yyyyMMddHHmmss")); + logWriter.Log = new StreamWriter(File.Open(logWriter.path, FileMode.Append, FileAccess.Write)); + } + if (logWriter != null && logWriter.Log != null) + { + StringBuilder buff = new StringBuilder(); + buff.Append(now.ToString("yyyyMMddHHmmssfff")); + buff.Append(" "); + buff.Append(direction ? "A->S:" : "S->A:"); + buff.Append(msg); + buff.Append("\r\n"); + logWriter.Log.Write(buff.ToString()); + } + } + catch (Exception e) + { + // m_log.ErrorFormat("{0}: FAILURE WRITING TO LOGFILE: {1}", LogHeader, e); + logEnabled = false; + } + } + return; + } + + public static void PhysLogMessageClose() + { + if (logWriter != null && logWriter.Log != null) + { + logWriter.Log.Close(); + logWriter.Log.Dispose(); + logWriter.Log = null; + logWriter = null; + } + logEnabled = false; + } + #endregion Message Logging } } diff --git a/OpenSim/Region/Physics/PEPlugin/PEScene.cs b/OpenSim/Region/Physics/PEPlugin/PEScene.cs index dade4f3b8c..c7660adcc8 100755 --- a/OpenSim/Region/Physics/PEPlugin/PEScene.cs +++ b/OpenSim/Region/Physics/PEPlugin/PEScene.cs @@ -111,7 +111,7 @@ public class PEScene : PhysicsScene foreach (PEPrim prim in m_prims) { // if the values have changed and it was I who changed them, send an update - if (prim.lastValues.Changed(prim) && prim.ChangingActorID == RegionSyncServerModule.ActorID) + if (prim.ChangingActorID == RegionSyncServerModule.ActorID && prim.lastValues.Changed(prim)) { SceneToPhysEngineSyncServer.RouteUpdate(prim); } @@ -123,7 +123,7 @@ public class PEScene : PhysicsScene { // m_log.DebugFormat("[RPE]: Simulate. p={0}, a={1}", m_prims.Count, m_avatars.Count); // if the values have changed and it was I who changed them, send an update - if (actor.lastValues.Changed(actor) && actor.ChangingActorID == RegionSyncServerModule.ActorID) + if (actor.ChangingActorID == RegionSyncServerModule.ActorID && actor.lastValues.Changed(actor)) { SceneToPhysEngineSyncServer.RouteUpdate(actor); }