diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnector.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnector.cs index 11f71c699e..4680dc50e0 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnector.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnector.cs @@ -63,7 +63,6 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule // The client connection to the RegionSyncServer private TcpClient m_client = new TcpClient(); - private string m_authSceneName; //KittyL: Comment out m_statsTimer for now, will figure out whether we need it for PhysEngine later //private System.Timers.Timer m_statsTimer = new System.Timers.Timer(30000); @@ -94,7 +93,8 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule // Constructor - public PhysEngineToSceneConnector(Scene validLocalScene, string addr, int port, bool debugWithViewer, string authSceneName, IConfig sysConfig) + public PhysEngineToSceneConnector(Scene validLocalScene, string addr, int port, bool debugWithViewer, + IConfig sysConfig) { m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); m_validLocalScene = validLocalScene; @@ -102,7 +102,6 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_addrString = addr; m_port = port; m_debugWithViewer = debugWithViewer; - m_authSceneName = authSceneName; //m_statsTimer.Elapsed += new System.Timers.ElapsedEventHandler(StatsTimerElapsed); m_sysConfig = sysConfig; @@ -110,53 +109,6 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_subscribedQuarks = new QuarkSubsriptionInfo(0, 0, (int)Constants.RegionSize, (int)Constants.RegionSize); } - /// - /// Create a PhysEngineToSceneConnector based on the space it is supposed to subscribe (and operate) on. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public PhysEngineToSceneConnector(Scene validLocalScene, string addr, int port, bool debugWithViewer, string authSceneName, - string subscriptionSpace, IConfig sysConfig) - { - if (QuarkInfo.SizeX == -1 || QuarkInfo.SizeY == -1) - { - m_log.Error("QuarkInfo.SizeX or QuarkInfo.SizeY has not been configured."); - Environment.Exit(0); - } - - m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - m_validLocalScene = validLocalScene; - m_addr = IPAddress.Parse(addr); - m_addrString = addr; - m_port = port; - m_debugWithViewer = debugWithViewer; - m_authSceneName = authSceneName; - //m_statsTimer.Elapsed += new System.Timers.ElapsedEventHandler(StatsTimerElapsed); - m_sysConfig = sysConfig; - - m_subscribedQuarks = new QuarkSubsriptionInfo(subscriptionSpace); - } - - public PhysEngineToSceneConnectorModule GetPEToSceneConnectorMasterModule() - { - if (m_validLocalScene == null) - return null; - return (PhysEngineToSceneConnectorModule)m_validLocalScene.PhysEngineToSceneConnectorModule; - } - - public Scene GetValidLocalScene() - { - return m_validLocalScene; - } - - private List GetQuarkStringList() { List quarkList = new List(); @@ -167,19 +119,6 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule return quarkList; } - - - /// - /// Get the reference to the local scene that is supposed to be mapped to the remote auth. scene. - /// - /// - /// - private Scene GetLocalScene(string authSceneName) - { - PhysEngineToSceneConnectorModule connectorModule = GetPEToSceneConnectorMasterModule(); - return connectorModule.GetLocalScene(authSceneName); - } - // Start the RegionSyncPhysEngine client thread public bool Start() { @@ -474,28 +413,12 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule { case RegionSyncMessage.MsgType.RegionName: { - string authSceneName = Encoding.ASCII.GetString(msg.Data, 0, msg.Length); - if (authSceneName != m_authSceneName) - { - //This should not happen. If happens, check the configuration files (OpenSim.ini) on other sides. - m_log.Warn(": !!! Mismatch between configurations of authoritative scene. Script Engine's config: "+m_authSceneName+", Scene's config: "+authSceneName); - return; - } - RegionSyncMessage.HandleSuccess(LogHeader, msg, String.Format("Syncing to region \"{0}\"", m_authSceneName)); return; } case RegionSyncMessage.MsgType.Terrain: { //We need to handle terrain differently as we handle objects: we really will set the HeightMap //of each local scene that is the shadow copy of its auth. scene. - Scene localScene = GetLocalScene(m_authSceneName); - if (localScene == null) - { - m_log.Warn("no local Scene mapped to "+m_authSceneName); - return; - } - localScene.Heightmap.LoadFromXmlString(Encoding.ASCII.GetString(msg.Data, 0, msg.Length)); - RegionSyncMessage.HandleSuccess(LogHeader, msg, "Synchronized terrain"); return; } case RegionSyncMessage.MsgType.NewObject: @@ -556,24 +479,24 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule #endregion Utility functions - #region Handlers for Scene events - - private void HandleAddOrUpdateObjectInLocalScene(RegionSyncMessage msg) - { - // TODO: modify for physics - OSDMap data = DeserializeMessage(msg); + #region Handlers for Scene events + + private void HandleAddOrUpdateObjectInLocalScene(RegionSyncMessage msg) + { + // TODO: modify for physics + OSDMap data = DeserializeMessage(msg); /* if (data["locX"] == null || data["locY"] == null || data["sogXml"] == null) { m_log.Warn(LogHeader + ": parameters missing in NewObject/UpdatedObject message, need to have locX, locY, sogXml"); return; } - * */ - uint locX = data["locX"].AsUInteger(); - uint locY = data["locY"].AsUInteger(); - string sogxml = data["sogXml"].AsString(); - SceneObjectGroup sog = SceneObjectSerializer.FromXml2Format(sogxml); - + * */ + uint locX = data["locX"].AsUInteger(); + uint locY = data["locY"].AsUInteger(); + string sogxml = data["sogXml"].AsString(); + SceneObjectGroup sog = SceneObjectSerializer.FromXml2Format(sogxml); + } #endregion Handlers for events/updates from Scene diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnectorModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnectorModule.cs index 8ea8bd6fb6..c82614a59c 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnectorModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/PhysEngineToSceneConnectorModule.cs @@ -44,6 +44,35 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //The connector that connects the local Scene (cache) and remote authoratative Scene public class PhysEngineToSceneConnectorModule : IRegionModule, IPhysEngineToSceneConnectorModule, ICommandableModule { + #region PhysEngineToSceneConnectorModule members and functions + + private static int m_activeActors = 0; + private bool m_active = false; + private string m_serveraddr; + private int m_serverport; + private Scene m_scene; + private ILog m_log; + private Object m_client_lock = new Object(); + //private PhysEngineToSceneConnector m_scriptEngineToSceneConnector = null; + private IConfig m_syncConfig = null; + public IConfig SyncConfig { get { return m_syncConfig; } } + private bool m_debugWithViewer = false; + public bool DebugWithViewer { get { return m_debugWithViewer; } } + private string m_regionSyncMode = ""; + + //Variables relavant for multi-scene subscription. + private Dictionary m_PEToSceneConnectors = new Dictionary(); //connector for each auth. scene + private string LogHeader = "[PhysEngineToSceneConnectorModule]"; + private PhysEngineToSceneConnector m_idlePEToSceneConnector = null; + + //quark information + //private int QuarkInfo.SizeX; + //private int QuarkInfo.SizeY; + //private string m_quarkListString; + private string m_subscriptionSpaceString; + + #endregion PhysEngineToSceneConnectorModule members and functions + #region IRegionModule Members public void Initialise(Scene scene, IConfigSource config) @@ -53,75 +82,30 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //Read in configuration IConfig syncConfig = config.Configs["RegionSyncModule"]; - if (syncConfig != null && syncConfig.GetString("Enabled", "").ToLower() == "true") + if (syncConfig != null + && syncConfig.GetBoolean("Enabled", false) + && syncConfig.GetString("Mode", "").ToLower() == "client" + && syncConfig.GetBoolean("PhysEngineClient", false) + ) { scene.RegionSyncEnabled = true; } else { scene.RegionSyncEnabled = false; - } - - m_regionSyncMode = syncConfig.GetString("Mode", "").ToLower(); - if (syncConfig == null || m_regionSyncMode != "physics_engine") - { - m_log.Warn("[REGION SYNC PHYSICS ENGINE MODULE] Not in script_engine mode. Shutting down."); + m_log.Warn(LogHeader + ": Not in physics engine client mode. Shutting down."); return; } - //get the name of the valid region for script engine, i.e., that region that will holds all objects and scripts - //if not matching m_scene's name, simply return - string validLocalScene = syncConfig.GetString("ValidPhysEngineScene", ""); - if (!validLocalScene.Equals(scene.RegionInfo.RegionName)) - { - m_log.Warn("Not the valid local scene, shutting down"); - return; - } - m_active = true; - m_validLocalScene = validLocalScene; + m_active = true; + m_activeActors++; - m_log.Debug("Init PEToSceneConnectorModule, for local scene " + scene.RegionInfo.RegionName); + m_log.Debug(LogHeader + " Init PEToSceneConnectorModule, for local scene " + scene.RegionInfo.RegionName); - //get the number of regions this script engine subscribes - m_sceneNum = syncConfig.GetInt("SceneNumber", 1); - - //get the mapping of local scenes to auth. scenes - List authScenes = new List(); - for (int i = 0; i < m_sceneNum; i++) - { - string localScene = "LocalScene" + i; - string localSceneName = syncConfig.GetString(localScene, ""); - string masterScene = localScene + "Master"; - string masterSceneName = syncConfig.GetString(masterScene, ""); - - if (localSceneName.Equals("") || masterSceneName.Equals("")) - { - m_log.Warn(localScene + " or " + masterScene+ " has not been assigned a value in configuration. Shutting down."); - return; - } - - //m_localToAuthSceneMapping.Add(localSceneName, masterSceneName); - RecordLocalAuthSceneMappings(localSceneName, masterSceneName); - authScenes.Add(masterSceneName); - m_localScenesByName.Add(localSceneName, null); - } - - int defaultPort = 13000; - //get the addr:port info of the authoritative scenes - for (int i = 0; i < m_sceneNum; i++) - { - string authSceneName = authScenes[i]; - //string serverAddr = authSceneName + "_ServerIPAddress"; - //string serverPort = authSceneName + "_ServerPort"; - string serverAddr = authSceneName + "_SceneToPESyncServerIP"; - string addr = syncConfig.GetString(serverAddr, "127.0.0.1"); - string serverPort = authSceneName + "_SceneToPESyncServerPort"; - int port = syncConfig.GetInt(serverPort, defaultPort); - defaultPort++; - - AuthSceneInfo authSceneInfo = new AuthSceneInfo(authSceneName, addr, port); - m_authScenesInfoByName.Add(authSceneName, authSceneInfo); - } + string configString = scene.RegionInfo.RegionName + "_SceneToPESyncServerIP"; + m_serveraddr = syncConfig.GetString(configString, "127.0.0.1"); + configString = scene.RegionInfo.RegionName + "_SceneToPESyncServerPort"; + m_serverport = syncConfig.GetInt(configString, 13000); m_scene = scene; m_scene.RegisterModuleInterface(this); @@ -146,7 +130,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; InstallInterfaces(); - m_log.Warn("[REGION SYNC PHYSICS ENGINE MODULE] Initialised"); + m_log.Warn(LogHeader + " Initialised"); } public void PostInitialise() @@ -154,18 +138,17 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule if (!m_active) return; - //m_log.Warn("[REGION SYNC CLIENT MODULE] Post-Initialised"); - m_scene.EventManager.OnPopulateLocalSceneList += OnPopulateLocalSceneList; + //m_log.Warn(LogHeader + " Post-Initialised"); } public void Close() { if (m_active) { - m_scene.EventManager.OnPopulateLocalSceneList -= OnPopulateLocalSceneList; } m_scene = null; m_active = false; + m_activeActors--; } public string Name @@ -180,7 +163,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule #endregion #region ICommandableModule Members - private readonly Commander m_commander = new Commander("sync"); + private readonly Commander m_commander = new Commander("phys"); public ICommander CommandInterface { get { return m_commander; } @@ -206,323 +189,32 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule } } - - #endregion - - #region PhysEngineToSceneConnectorModule members and functions - - private bool m_active = false; - private string m_serveraddr; - private int m_serverport; - private Scene m_scene; - private ILog m_log; - private Object m_client_lock = new Object(); - //private PhysEngineToSceneConnector m_scriptEngineToSceneConnector = null; - private IConfig m_syncConfig = null; - private bool m_debugWithViewer = false; - private string m_regionSyncMode = ""; - - //Variables relavant for multi-scene subscription. - private int m_sceneNum = 0; - private string m_validLocalScene = ""; - private Dictionary m_localToAuthSceneMapping = new Dictionary(); //1-1 mapping from local shadow scene to authoratative scene - private Dictionary m_authToLocalSceneMapping = new Dictionary(); //1-1 mapping from authoratative scene to local shadow scene - private Dictionary m_localScenesByName = new Dictionary(); //name and references to local scenes - private Dictionary m_authScenesInfoByName = new Dictionary(); //info of each auth. scene's connector port, stored by each scene's name - private Dictionary m_PEToSceneConnectors = new Dictionary(); //connector for each auth. scene - private Dictionary m_authScenesInfoByLoc = new Dictionary(); //IP and port number of each auth. scene's connector port - private string LogHeader = "[PhysEngineToSceneConnectorModule]"; - private PhysEngineToSceneConnector m_idlePEToSceneConnector = null; - - //quark information - //private int QuarkInfo.SizeX; - //private int QuarkInfo.SizeY; - //private string m_quarkListString; - private string m_subscriptionSpaceString; - - public IConfig SyncConfig + public static bool IsPhysEngineScene { - get { return m_syncConfig; } + get { return SceneToPhysEngineSyncServer.IsPhysEngineScene; } } - - public bool DebugWithViewer + public static bool IsActivePhysEngineScene { - get { return m_debugWithViewer; } + get { return SceneToPhysEngineSyncServer.IsActivePhysEngineScene; } } - - //Record the locX and locY of one auth. scene (identified by addr:port) this PhysEngine connects to - public void RecordSceneLocation(string addr, int port, uint locX, uint locY) + public static bool IsPhysEngineActor { - string loc = SceneLocToString(locX, locY); - if (m_authScenesInfoByLoc.ContainsKey(loc)) - { - m_log.Warn(": have already registered info for Scene at " + loc); - m_authScenesInfoByLoc.Remove(loc); - } - - foreach (KeyValuePair valPair in m_authScenesInfoByName) - { - AuthSceneInfo authSceneInfo = valPair.Value; - if (authSceneInfo.Addr == addr && authSceneInfo.Port == port) - { - authSceneInfo.LocX = (int)locX; - authSceneInfo.LocY = (int)locY; - m_authScenesInfoByLoc.Add(loc, authSceneInfo); - break; - } - } - } - - /// - /// Set the property of a prim located in the given scene (identified by locX, locY) - /// - /// - /// - /// - /// - /// - public void SendSetPrimProperties(uint locX, uint locY, UUID primID, string pName, object pValue) - { - if (!Active || !Synced) - return; - - PhysEngineToSceneConnector connector = GetPEToSceneConnector(locX, locY); - connector.SendSetPrimProperties(primID, pName, pValue); - } - - public Scene GetLocalScene(string authSceneName) - { - if (!m_authToLocalSceneMapping.ContainsKey(authSceneName)) - { - m_log.Warn(LogHeader + ": no authoritative scene with name "+authSceneName+" recorded"); - return null; - } - string localSceneName = m_authToLocalSceneMapping[authSceneName]; - if (m_localScenesByName.ContainsKey(localSceneName)) - { - return m_localScenesByName[localSceneName]; - } - else - return null; - } - - private string SceneLocToString(uint locX, uint locY) - { - string loc = locX + "-" + locY; - return loc; - } - - //Get the right instance of PhysEngineToSceneConnector, given the location of the authoritative scene - private PhysEngineToSceneConnector GetPEToSceneConnector(uint locX, uint locY) - { - string loc = SceneLocToString(locX, locY); - if (!m_authScenesInfoByLoc.ContainsKey(loc)) - return null; - string authSceneName = m_authScenesInfoByLoc[loc].Name; - if (!m_PEToSceneConnectors.ContainsKey(authSceneName)) - { - return null; - } - return m_PEToSceneConnectors[authSceneName]; - } - - - private void RecordLocalAuthSceneMappings(string localSceneName, string authSceneName) - { - if (m_localToAuthSceneMapping.ContainsKey(localSceneName)) - { - m_log.Warn(LogHeader + ": already registered " + localSceneName+", authScene was recorded as "+ m_localToAuthSceneMapping[localSceneName]); - } - else - { - m_localToAuthSceneMapping.Add(localSceneName, authSceneName); - } - if (m_authToLocalSceneMapping.ContainsKey(authSceneName)) - { - m_log.Warn(LogHeader + ": already registered " + authSceneName + ", authScene was recorded as " + m_authToLocalSceneMapping[authSceneName]); - } - else - { - m_authToLocalSceneMapping.Add(authSceneName, localSceneName); - } - } - - //Get the name of the authoritative scene the given local scene maps to. Return null if not found. - private string GetAuthSceneName(string localSceneName) - { - if (m_localToAuthSceneMapping.ContainsKey(localSceneName)) - { - m_log.Warn(LogHeader + ": " + localSceneName + " not registered in m_localToAuthSceneMapping"); - return null; - } - return m_localToAuthSceneMapping[localSceneName]; - } - - //get the name of the local scene the given authoritative scene maps to. Return null if not found. - private string GetLocalSceneName(string authSceneName) - { - if (!m_authToLocalSceneMapping.ContainsKey(authSceneName)) - { - m_log.Warn(LogHeader + ": " + authSceneName + " not registered in m_authToLocalSceneMapping"); - return null; - } - return m_authToLocalSceneMapping[authSceneName]; + get { return (m_activeActors != 0); } } #endregion + #region Event Handlers - - public void OnPopulateLocalSceneList(List localScenes) - //public void OnPopulateLocalSceneList(List localScenes, string[] cmdparams) - { - if (!Active) - return; - - //populate the dictionary m_localScenes - foreach (Scene lScene in localScenes) - { - string name = lScene.RegionInfo.RegionName; - if(!m_localScenesByName.ContainsKey(name)){ - m_log.Warn(LogHeader+": has not reigstered a local scene named "+name); - continue; - } - m_localScenesByName[name] = lScene; - - //lScene.RegionSyncMode = m_regionSyncMode; - lScene.IsOutsideScenes = IsOutSideSceneSubscriptions; - } - - //test position conversion - /* - //Vector3 pos = new Vector3(290, 100, 10); - uint preLocX = Convert.ToUInt32(cmdparams[2]); - uint preLocY = Convert.ToUInt32(cmdparams[3]); - float posX = (float)Convert.ToDouble(cmdparams[4]); - float posY = (float)Convert.ToDouble(cmdparams[5]); - float posZ = (float)Convert.ToDouble(cmdparams[6]); - Vector3 pos = new Vector3(posX, posY, posZ); - uint locX, locY; - Vector3 newPos; - ConvertPosition(1000, 1000, pos, out locX, out locY, out newPos); - * */ - } - #endregion - private string GetAllSceneNames() - { - string scenes = ""; - foreach (KeyValuePair valPair in m_localScenesByName) - { - Scene lScene = valPair.Value; - string authScene = m_localToAuthSceneMapping[lScene.RegionInfo.RegionName]; - scenes += authScene + ","; - - } - return scenes; - } - - //public bool IsOutSideSceneSubscriptions(Scene currentScene, Vector3 pos) - public bool IsOutSideSceneSubscriptions(uint locX, uint locY, Vector3 pos) - { - string sceneNames = GetAllSceneNames(); - m_log.Debug(LogHeader + ": IsOutSideSceneSubscriptions called. Conceptually, we are checking inside scene-subscriptions: " + sceneNames); - - //First, convert the position to a scene s.t. the attempting position is contained withing that scene - uint curLocX, curLocY; - Vector3 curPos; - bool converted = ConvertPosition(locX, locY, pos, out curLocX, out curLocY, out curPos); - - if (!converted) - { - m_log.Warn("("+locX+","+locY+","+pos+")"+" converts to scenes with negative coordinates."); - return false; - } - //See of the quark identified by (curLocX,curLocY) is one we subscribed to - string sceneLoc = SceneLocToString(curLocX, curLocY); - if (m_authScenesInfoByLoc.ContainsKey(sceneLoc)) - { - return false; - } - else - { - return true; - } - } - - //When the offset position is outside the range of current scene, convert it to the offset position in the right quark. - //Return null if the new scene's left-bottom corner X or Y value is negative. - //Assumption: A position is uniquely identified by (locX, locY, offsetPos). - private bool ConvertPosition(uint preLocX, uint preLocY, Vector3 prePos, out uint curLocX, out uint curLocY, out Vector3 curPos) - { - Vector3 newPos; - int newLocX; - int newLocY; - //code copied from EntityTransferModule.Cross() - - newPos = prePos; - newLocX = (int)preLocX; - newLocY = (int)preLocY; - - int changeX = 1; - int changeY = 1; - - //Adjust the X values, if going east, changeX is positive, otherwise, it is negative - if (prePos.X >= 0) - { - changeX = (int)(prePos.X / (int)Constants.RegionSize); - } - else - { - changeX = (int)(prePos.X / (int)Constants.RegionSize) - 1 ; - } - newLocX = (int)preLocX + changeX; - newPos.X = prePos.X - (changeX * Constants.RegionSize); - - if (prePos.Y >= 0) - { - changeY = (int)(prePos.Y / (int)Constants.RegionSize); - } - else - { - changeY = (int)(prePos.Y / (int)Constants.RegionSize) - 1; - } - changeY = (int)(prePos.Y / (int)Constants.RegionSize); - newLocY = (int)preLocY + changeY; - newPos.Y = prePos.Y - (changeY * Constants.RegionSize); - - curLocX = (uint)newLocX; - curLocY = (uint)newLocY; - curPos = newPos; - - if (newLocX < 0 || newLocY < 0) - { - //reset the position - curLocX = preLocX; - curLocY = preLocY; - if (newLocX < 0) - { - curPos.X = 2; - } - if(newLocY<0) - { - curPos.Y = 2; - } - return false; - } - else - return true; - } - - private void DebugSceneStats() { return; /* List avatars = m_scene.GetAvatars(); List entities = m_scene.GetEntities(); - m_log.WarnFormat("There are {0} avatars and {1} entities in the scene", avatars.Count, entities.Count); + m_log.WarnFormat("{0} There are {1} avatars and {2} entities in the scene", LogHeader, avatars.Count, entities.Count); */ } @@ -548,17 +240,10 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule cmdSyncSetQuarkSize.AddArgument("quarksizeX", "The size on x axis of each quark", "Integer"); cmdSyncSetQuarkSize.AddArgument("quarksizeY", "The size on y axis of each quark", "Integer"); - Command cmdSyncRegister = new Command("register", CommandIntentions.COMMAND_HAZARDOUS, SyncRegister, "Register as an idle script engine. Sync'ing with Scene won't start until \"sync start\". "); - - //For debugging load balancing and migration process - Command cmdSyncStartLB = new Command("startLB", CommandIntentions.COMMAND_HAZARDOUS, SyncStartLB, "Register as an idle script engine. Sync'ing with Scene won't start until \"sync start\". "); - m_commander.RegisterCommand("start", cmdSyncStart); m_commander.RegisterCommand("stop", cmdSyncStop); m_commander.RegisterCommand("status", cmdSyncStatus); m_commander.RegisterCommand("quarkSpace", cmdSyncSetQuarks); - m_commander.RegisterCommand("register", cmdSyncRegister); - m_commander.RegisterCommand("startLB", cmdSyncStartLB); lock (m_scene) { @@ -574,7 +259,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule /// Commandline arguments private void EventManager_OnPluginConsole(string[] args) { - if (args[0] == "sync") + if (args[0] == "phys") { if (args.Length == 1) { @@ -595,100 +280,16 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule { lock (m_client_lock) { - //if (m_scriptEngineToSceneConnector != null) - if(m_PEToSceneConnectors.Count>0) - { - string authScenes = ""; - foreach (KeyValuePair valPair in m_PEToSceneConnectors) - { - authScenes += valPair.Key + ", "; - } - m_log.WarnFormat(LogHeader+": Already synchronized to "+authScenes); - return; - } - //m_log.Warn("[REGION SYNC CLIENT MODULE] Starting synchronization"); + //m_log.Warn(LogHeader + " Starting synchronization"); m_log.Warn(LogHeader + ": Starting RegionSyncPhysEngine"); - if (m_sceneNum > 1) - { - //If there is no arguments following "sync start", then be default we will connect to one or more scenes. - //we need to create a connector to each authoritative scene - foreach (KeyValuePair valPair in m_authScenesInfoByName) - { - string authSceneName = valPair.Key; - AuthSceneInfo authSceneInfo = valPair.Value; - - //create a new connector, the local end of each connector, however, is linked to the ValidScene only, - //since all objects will be contained in this scene only - PhysEngineToSceneConnector scriptEngineToSceneConnector = new PhysEngineToSceneConnector(m_scene, authSceneInfo.Addr, authSceneInfo.Port, m_debugWithViewer, authSceneName, m_syncConfig); - if (scriptEngineToSceneConnector.Start()) - { - m_PEToSceneConnectors.Add(authSceneName, scriptEngineToSceneConnector); - } - } - } - else - { - //Only one remote scene to connect to. Subscribe to whatever specified in the config file. - //List quarkStringList = RegionSyncUtil.QuarkStringToStringList(m_quarkListString); - //InitPhysEngineToSceneConnector(quarkStringList); - InitPhysEngineToSceneConnector(m_subscriptionSpaceString); - } + //Only one remote scene to connect to. Subscribe to whatever specified in the config file. + //List quarkStringList = RegionSyncUtil.QuarkStringToStringList(m_quarkListString); + //InitPhysEngineToSceneConnector(quarkStringList); + InitPhysEngineToSceneConnector(m_subscriptionSpaceString); } } - private void SyncRegister(Object[] args) - { - //This should not happen. No-validLocalScene should not have register handlers for the command - //if (m_scene.RegionInfo.RegionName != m_validLocalScene) - // return; - - //Registration only, no state sync'ing yet. So only start the connector for the validLocalScene. (For now, we only test this with one scene, and - //quarks are smaller than a 256x256 scene. - string authSceneName = m_localToAuthSceneMapping[m_validLocalScene]; - AuthSceneInfo authSceneInfo = m_authScenesInfoByName[authSceneName]; - m_idlePEToSceneConnector = new PhysEngineToSceneConnector(m_scene, authSceneInfo.Addr, authSceneInfo.Port, m_debugWithViewer, authSceneName, m_syncConfig); - m_idlePEToSceneConnector.RegisterIdle(); - } - - /// - /// The given PhysEngineToSceneConnector, after having connected to the Scene (called its Start()), will - /// call this function to remove it self as an idle connector, and to be recorded as one working connector. - /// - /// - public void RecordSyncStartAfterLoadMigration(PhysEngineToSceneConnector seToSceneConnector) - { - foreach (KeyValuePair valPair in m_authScenesInfoByName) - { - string authSceneName = valPair.Key; - AuthSceneInfo authSceneInfo = valPair.Value; - - string localScene = m_authToLocalSceneMapping[authSceneName]; - - if (localScene != m_scene.RegionInfo.RegionName) - continue; - - if (m_PEToSceneConnectors.ContainsKey(authSceneName)) - { - m_log.Warn(LogHeader + ": Connector to " + authSceneName + " is already considered connected"); - return; - } - - m_PEToSceneConnectors.Add(authSceneName, seToSceneConnector); - //there should only be one element in the dictionary if we reach this loop, anyway, we break from it. - break; - } - m_idlePEToSceneConnector = null; - } - - private void SyncStartLB(Object[] args) - { - string authSceneName = m_localToAuthSceneMapping[m_validLocalScene]; - PhysEngineToSceneConnector sceneConnector = m_PEToSceneConnectors[authSceneName]; - // TODO: load balancing. Next line commented out - // sceneConnector.SendLoadBalanceRequest(); - } - private void SetQuarkList(Object[] args) { m_subscriptionSpaceString = (string)args[0]; @@ -706,26 +307,11 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule private void InitPhysEngineToSceneConnector(string space) { - foreach (KeyValuePair valPair in m_authScenesInfoByName) + PhysEngineToSceneConnector scriptEngineToSceneConnector = new PhysEngineToSceneConnector(m_scene, + m_serveraddr, m_serverport, m_debugWithViewer, /* space,*/ m_syncConfig); + if (scriptEngineToSceneConnector.Start()) { - string authSceneName = valPair.Key; - AuthSceneInfo authSceneInfo = valPair.Value; - - string localScene = m_authToLocalSceneMapping[authSceneName]; - - if (localScene != m_scene.RegionInfo.RegionName) - continue; - - //create a new connector, the local end of each connector, however, is set of the ValidScene only, - //since all objects will be contained in this scene only - PhysEngineToSceneConnector scriptEngineToSceneConnector = new PhysEngineToSceneConnector(m_scene, authSceneInfo.Addr, authSceneInfo.Port, - m_debugWithViewer, authSceneName, space, m_syncConfig); - if (scriptEngineToSceneConnector.Start()) - { - m_PEToSceneConnectors.Add(authSceneName, scriptEngineToSceneConnector); - } - - break; //there should only be one element in the dictionary if we reach this loop, anyway, we break from it. + m_PEToSceneConnectors.Add(m_scene.RegionInfo.RegionName, scriptEngineToSceneConnector); } } @@ -736,7 +322,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //if (m_scriptEngineToSceneConnector == null) if(m_PEToSceneConnectors.Count==0 && m_idlePEToSceneConnector==null) { - m_log.WarnFormat("[REGION SYNC PHYSICS ENGINE MODULE] Already stopped"); + m_log.Warn(LogHeader + " Already stopped"); return; } @@ -764,8 +350,6 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_log.Warn(LogHeader+": Stopping synchronization"); } - m_authScenesInfoByLoc.Clear(); - //save script state and stop script instances // TODO: Load balancing. next line commented out to compile // m_scene.EventManager.TriggerPhysEngineSyncStop(); @@ -780,10 +364,10 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule { if (m_PEToSceneConnectors.Count == 0) { - m_log.WarnFormat("[REGION SYNC PHYSICS ENGINE MODULE] Not currently synchronized"); + m_log.Warn(LogHeader + " Not currently synchronized"); return; } - m_log.WarnFormat("[REGION SYNC PHYSICS ENGINE MODULE] Synchronized"); + m_log.Warn(LogHeader + " Synchronized"); foreach (KeyValuePair pair in m_PEToSceneConnectors) { PhysEngineToSceneConnector sceneConnector = pair.Value; diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncServerModule.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncServerModule.cs index 4f6899de58..ebed0d7bf3 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncServerModule.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/RegionSyncServerModule.cs @@ -109,6 +109,13 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_seSyncServerport = syncConfig.GetInt(seServerPort, DefaultPort); DefaultPort++; + //Get sync server info for Physics Engine actors + string peServerAddr = scene.RegionInfo.RegionName + "_SceneToPESyncServerIP"; + m_peSyncServeraddr = syncConfig.GetString(peServerAddr, "127.0.0.1"); + string peServerPort = scene.RegionInfo.RegionName + "_SceneToPESyncServerPort"; + m_peSyncServerport = syncConfig.GetInt(peServerPort, DefaultPort); + DefaultPort++; + //Get quark information QuarkInfo.SizeX = syncConfig.GetInt("QuarkSizeX", (int)Constants.RegionSize); QuarkInfo.SizeY = syncConfig.GetInt("QuarkSizeY", (int)Constants.RegionSize); @@ -154,6 +161,11 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule //Start the sync server for script engines m_sceneToSESyncServer = new SceneToScriptEngineSyncServer(m_scene, m_seSyncServeraddr, m_seSyncServerport); m_sceneToSESyncServer.Start(); + + m_log.Warn("[REGION SYNC SERVER MODULE] Starting SceneToPhysEngineSyncServer"); + //Start the sync server for physics engines + m_sceneToPESyncServer = new SceneToPhysEngineSyncServer(m_scene, m_peSyncServeraddr, m_peSyncServerport); + m_sceneToPESyncServer.Start(); //m_log.Warn("[REGION SYNC SERVER MODULE] Post-Initialised"); } @@ -489,6 +501,11 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule private string m_seSyncServeraddr; private int m_seSyncServerport; private SceneToScriptEngineSyncServer m_sceneToSESyncServer = null; + + //Sync-server for physics engine + private string m_peSyncServeraddr; + private int m_peSyncServerport; + private SceneToPhysEngineSyncServer m_sceneToPESyncServer = null; //quark related information //private int QuarkInfo.SizeX; diff --git a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineSyncServer.cs b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineSyncServer.cs index 44f64e5bef..f5390f480d 100644 --- a/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineSyncServer.cs +++ b/OpenSim/Region/CoreModules/RegionSync/RegionSyncModule/SceneToPhysEngineSyncServer.cs @@ -41,7 +41,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule } //Here is the per actor type listening server for physics Engines. - public class SceneToPhysEngineSyncServer + public class SceneToPhysEngineSyncServer : ISceneToPhysEngineServer { #region SceneToPhysEngineSyncServer members // Set the addr and port for TcpListener @@ -58,6 +58,10 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule private int peCounter; + // static counters that are used to compute global configuration state + private static int m_syncServerInitialized = 0; + private static int m_totalConnections = 0; + // The local scene. private Scene m_scene; @@ -92,6 +96,19 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule return (m_physEngineConnectors.Count > 0); } } + public static bool IsPhysEngineScene + { + get { return (m_syncServerInitialized != 0); } + } + public static bool IsActivePhysEngineScene + { + get { return (m_syncServerInitialized != 0 && m_totalConnections != 0); } + } + public static bool IsPhysEngineActor + { + get { return PhysEngineToSceneConnectorModule.IsPhysEngineActor; } + } + #endregion // Constructor @@ -130,6 +147,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule m_log.WarnFormat(LogHeader + ": Starting {0} thread", m_listenerThread.Name); m_listenerThread.Start(); //m_log.Warn("[REGION SYNC SERVER] Started"); + m_syncServerInitialized++; } @@ -137,6 +155,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule // Stop the server and disconnect all RegionSyncClients public void Shutdown() { + m_syncServerInitialized--; // Stop the listener and listening thread so no new clients are accepted m_listener.Stop(); m_listenerThread.Abort(); diff --git a/OpenSim/Region/Framework/Interfaces/IPhysEngineToSceneConnectorModule.cs b/OpenSim/Region/Framework/Interfaces/IPhysEngineToSceneConnectorModule.cs index 45573e504b..3d30a45f3e 100755 --- a/OpenSim/Region/Framework/Interfaces/IPhysEngineToSceneConnectorModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IPhysEngineToSceneConnectorModule.cs @@ -36,18 +36,9 @@ namespace OpenSim.Region.Framework.Interfaces //the interface for Scene to sync with Script Engine public interface IPhysEngineToSceneConnectorModule { - bool Active { get; } - bool Synced { get; } + // static bool IsPhysEngineScene { get; } + // static bool IsActivePhysEngineScene { get; } + // static bool IsPhysEngineActor { get; } bool DebugWithViewer { get; } - //void SendCoarseLocations(); - /// - /// Update the property of prim with primID, where the prim is located at quark (LocX, LocY). The length of each quark is configurable. - /// - /// - /// - /// - /// - /// - void SendSetPrimProperties(uint locX, uint locY, UUID primID, string pName, object pValue); } } \ No newline at end of file diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 9cd6db8160..7a0d6c52e6 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -410,37 +410,31 @@ namespace OpenSim.Region.Framework.Scenes { get { return m_physEngineToSceneConnectorModule; } set { m_physEngineToSceneConnectorModule = value; } - } - - // list of physactors for this scene so we can find them later for remote physics - public Dictionary PhysActors = new Dictionary(); - public void AddPhysActor(uint id, PhysicsActor pActor) - { - if (PhysActors.ContainsKey(id)) { - PhysActors.Remove(id); - } - PhysActors.Add(id, pActor); - return; - } - public void RemovePhysActor(uint id) - { - if (PhysActors.ContainsKey(id)) { - PhysActors.Remove(id); - } - return; - } - - public bool IsPhysEngineScene() - { - return (SceneToPhysEngineConnectorModule != null); - } - public bool IsActivePhysEngineScene() - { - return (SceneToPhysEngineConnectorModule != null && SceneToPhysEngineConnectorModule.Active); - } - public bool IsPhysEngineActor() - { - return (PhysEngineToSceneConnectorModule != null); + } + + protected ISceneToPhysEngineServer m_sceneToPhysEngineSyncServer = null; + public ISceneToPhysEngineServer SceneToPhysEngineSyncServer + { + get { return m_sceneToPhysEngineSyncServer; } + set { m_sceneToPhysEngineSyncServer = value; } + } + + // list of physactors for this scene so we can find them later for remote physics + public Dictionary PhysActors = new Dictionary(); + public void AddPhysActor(uint id, PhysicsActor pActor) + { + if (PhysActors.ContainsKey(id)) { + PhysActors.Remove(id); + } + PhysActors.Add(id, pActor); + return; + } + public void RemovePhysActor(uint id) + { + if (PhysActors.ContainsKey(id)) { + PhysActors.Remove(id); + } + return; } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -1480,6 +1474,8 @@ namespace OpenSim.Region.Framework.Scenes RegionSyncServerModule = RequestModuleInterface(); RegionSyncClientModule = RequestModuleInterface(); ScriptEngineToSceneConnectorModule = RequestModuleInterface(); + PhysEngineToSceneConnectorModule = RequestModuleInterface(); + SceneToPhysEngineSyncServer = RequestModuleInterface(); // Shoving this in here for now, because we have the needed // interfaces at this point diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 67fb6fe791..376019f549 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -1585,8 +1585,8 @@ namespace OpenSim.Region.Framework.Scenes dupe.RootPart.RotationOffset, dupe.RootPart.PhysActor.IsPhysical); - dupe.RootPart.PhysActor.LocalID = dupe.RootPart.LocalId; - // RA: Register physActor in scene + dupe.RootPart.PhysActor.LocalID = dupe.RootPart.LocalId; + // RA: Register physActor in scene dupe.RootPart.DoPhysicsPropertyUpdate(dupe.RootPart.PhysActor.IsPhysical, true); } @@ -2389,8 +2389,8 @@ namespace OpenSim.Region.Framework.Scenes linkPart.LinkNum = 0; if (linkPart.PhysActor != null) - { - m_scene.RemovePhysActor(linkPart.PhysActor.LocalID); + { + m_scene.RemovePhysActor(linkPart.PhysActor.LocalID); m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor); } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index b797ef78d0..46ac996a96 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -1491,9 +1491,9 @@ namespace OpenSim.Region.Framework.Scenes { PhysActor.SOPName = this.Name; // save object name and desc into the PhysActor so ODE internals know the joint/body info PhysActor.SOPDescription = this.Description; - PhysActor.LocalID = LocalId; - // RA: register PhysActor with the scene - ParentGroup.Scene.AddPhysActor(LocalId, PhysActor); + PhysActor.LocalID = LocalId; + // RA: register PhysActor with the scene + ParentGroup.Scene.AddPhysActor(LocalId, PhysActor); DoPhysicsPropertyUpdate(RigidBody, true); PhysActor.SetVolumeDetect(VolumeDetectActive ? 1 : 0); } @@ -4311,9 +4311,9 @@ namespace OpenSim.Region.Framework.Scenes pa = PhysActor; if (pa != null) { - pa.LocalID = LocalId; - // RA: register PhysActor with scene - ParentGroup.Scene.AddPhysActor(LocalId, PhysActor); + pa.LocalID = LocalId; + // RA: register PhysActor with scene + ParentGroup.Scene.AddPhysActor(LocalId, PhysActor); DoPhysicsPropertyUpdate(UsePhysics, true); if (m_parentGroup != null) { diff --git a/OpenSim/Region/Physics/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs index aa43e97be1..8fbc8cd9f2 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsActor.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs @@ -140,9 +140,9 @@ namespace OpenSim.Region.Physics.Manager public abstract Vector3 Size { get; set; } - public abstract PrimitiveBaseShape Shape { set; } - - // RA: used to be abstract but changed to allow 'get' without changing all the phys engines + public abstract PrimitiveBaseShape Shape { set; } + + // RA: used to be abstract but changed to allow 'get' without changing all the phys engines public virtual uint LocalID { set { return; } get { return 0; } } public abstract bool Grabbed { set; } @@ -158,8 +158,8 @@ namespace OpenSim.Region.Physics.Manager public abstract void delink(); - public abstract void LockAngularMotion(Vector3 axis); - + public abstract void LockAngularMotion(Vector3 axis); + public virtual void RequestPhysicsterseUpdate() { // Make a temporary copy of the event to avoid possibility of @@ -280,7 +280,7 @@ namespace OpenSim.Region.Physics.Manager public override uint LocalID { - set { return; } + set { return; } get { return 0; } } diff --git a/OpenSim/Region/Physics/PEPlugin/PEPrim.cs b/OpenSim/Region/Physics/PEPlugin/PEPrim.cs index 6a6c03eab2..e41f15a4e2 100755 --- a/OpenSim/Region/Physics/PEPlugin/PEPrim.cs +++ b/OpenSim/Region/Physics/PEPlugin/PEPrim.cs @@ -26,13 +26,16 @@ using System; using System.Reflection; using System.Collections.Generic; +using System.Xml; using log4net; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Region.Physics.Manager; +using OpenSim.Region.CoreModules.RegionSync.RegionSyncModule; namespace OpenSim.Region.Physics.PEPlugin { + [Serializable] public sealed class PEPrim : PhysicsActor { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -98,7 +101,7 @@ public sealed class PEPrim : PhysicsActor set { _localID = value; m_log.Debug("[RPE] PEPrim set LocalID"); Prop.Set(_localID, PropType.LocalID, _localID); - } + } get { return _localID; } } public override bool Grabbed { diff --git a/prebuild.xml b/prebuild.xml index 5716295935..2278e76ff9 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -533,6 +533,7 @@ + @@ -560,9 +561,11 @@ ../../../../bin/ + +