* Adds PhysicsCombiner Module

* May rename this later
remotes/origin/0.6.7-post-fixes
Teravus Ovares (Dan Olivares) 2009-08-20 23:25:40 -04:00
parent 181b992b4a
commit c9b52cd0b6
1 changed files with 355 additions and 0 deletions

View File

@ -0,0 +1,355 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using log4net;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.CoreModules.World.Land
{
public class PhysicsCombiner : ISharedRegionModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public string Name { get { return "PhysicsCombiner";} }
public Type ReplaceableInterface
{
get { return null; }
}
public Type ReplacableInterface { get { return null; } }
private Dictionary<UUID, RegionConnections> m_regions = new Dictionary<UUID, RegionConnections>();
public void Initialise(IConfigSource source)
{
}
public void Close()
{
}
public void AddRegion(Scene scene)
{
/*
RegionData regionData = new RegionData();
regionData.Offset = Vector3.Zero;
regionData.RegionId = scene.RegionInfo.originRegionID;
regionData.RegionScene = scene;
*/
RegionConnections regionConnections = new RegionConnections();
regionConnections.ConnectedRegions = new List<RegionData>();
regionConnections.RegionScene = scene;
regionConnections.RegionId = scene.RegionInfo.originRegionID;
regionConnections.X = scene.RegionInfo.RegionLocX;
regionConnections.Y = scene.RegionInfo.RegionLocY;
regionConnections.XEnd = (int)Constants.RegionSize;
regionConnections.YEnd = (int)Constants.RegionSize;
lock (m_regions)
{
bool connectedYN = false;
foreach (RegionConnections conn in m_regions.Values)
{
/*
// If we're one region over +x +y
//xxx
//xxx
//xxy
if ((((int)conn.X * (int)Constants.RegionSize) + conn.XEnd
== (regionConnections.X * (int)Constants.RegionSize))
&& (((int)conn.Y * (int)Constants.RegionSize) - conn.YEnd
== (regionConnections.Y * (int)Constants.RegionSize)))
{
Vector3 offset = Vector3.Zero;
offset.X = (((regionConnections.X * (int) Constants.RegionSize)) -
((conn.X * (int) Constants.RegionSize)));
offset.Y = (((regionConnections.Y * (int) Constants.RegionSize)) -
((conn.Y * (int) Constants.RegionSize)));
Vector3 extents = Vector3.Zero;
extents.Y = regionConnections.YEnd + conn.YEnd;
extents.X = conn.XEnd + conn.XEnd;
m_log.DebugFormat("Scene: {0} to the northwest of Scene{1}. Offset: {2}. Extents:{3}",
conn.RegionScene.RegionInfo.RegionName,
regionConnections.RegionScene.RegionInfo.RegionName,
offset, extents);
scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
connectedYN = true;
break;
}
*/
/*
//If we're one region over x +y
//xxx
//xxx
//xyx
if ((((int)conn.X * (int)Constants.RegionSize)
== (regionConnections.X * (int)Constants.RegionSize))
&& (((int)conn.Y * (int)Constants.RegionSize) - conn.YEnd
== (regionConnections.Y * (int)Constants.RegionSize)))
{
Vector3 offset = Vector3.Zero;
offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
((conn.X * (int)Constants.RegionSize)));
offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
((conn.Y * (int)Constants.RegionSize)));
Vector3 extents = Vector3.Zero;
extents.Y = regionConnections.YEnd + conn.YEnd;
extents.X = conn.XEnd;
m_log.DebugFormat("Scene: {0} to the north of Scene{1}. Offset: {2}. Extents:{3}",
conn.RegionScene.RegionInfo.RegionName,
regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
connectedYN = true;
break;
}
*/
/*
// If we're one region over -x +y
//xxx
//xxx
//yxx
if ((((int)conn.X * (int)Constants.RegionSize) - conn.XEnd
== (regionConnections.X * (int)Constants.RegionSize))
&& (((int)conn.Y * (int)Constants.RegionSize) - conn.YEnd
== (regionConnections.Y * (int)Constants.RegionSize)))
{
Vector3 offset = Vector3.Zero;
offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
((conn.X * (int)Constants.RegionSize)));
offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
((conn.Y * (int)Constants.RegionSize)));
Vector3 extents = Vector3.Zero;
extents.Y = regionConnections.YEnd + conn.YEnd;
extents.X = conn.XEnd + conn.XEnd;
m_log.DebugFormat("Scene: {0} to the northeast of Scene. Offset: {2}. Extents:{3}",
conn.RegionScene.RegionInfo.RegionName,
regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
connectedYN = true;
break;
}
*/
/*
// If we're one region over -x y
//xxx
//yxx
//xxx
if ((((int)conn.X * (int)Constants.RegionSize) - conn.XEnd
== (regionConnections.X * (int)Constants.RegionSize))
&& (((int)conn.Y * (int)Constants.RegionSize)
== (regionConnections.Y * (int)Constants.RegionSize)))
{
Vector3 offset = Vector3.Zero;
offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
((conn.X * (int)Constants.RegionSize)));
offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
((conn.Y * (int)Constants.RegionSize)));
Vector3 extents = Vector3.Zero;
extents.Y = regionConnections.YEnd;
extents.X = conn.XEnd + conn.XEnd;
m_log.DebugFormat("Scene: {0} to the east of Scene{1} Offset: {2}. Extents:{3}",
conn.RegionScene.RegionInfo.RegionName,
regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
connectedYN = true;
break;
}
*/
// If we're one region over +x y
//xxx
//xxy
//xxx
if ((((int)conn.X * (int)Constants.RegionSize) + conn.XEnd
== (regionConnections.X * (int)Constants.RegionSize))
&& (((int)conn.Y * (int)Constants.RegionSize)
== (regionConnections.Y * (int)Constants.RegionSize)))
{
Vector3 offset = Vector3.Zero;
offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
((conn.X * (int)Constants.RegionSize)));
offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
((conn.Y * (int)Constants.RegionSize)));
Vector3 extents = Vector3.Zero;
extents.Y = regionConnections.YEnd;
extents.X = conn.XEnd + conn.XEnd;
m_log.DebugFormat("Scene: {0} to the west of Scene{1} Offset: {2}. Extents:{3}",
conn.RegionScene.RegionInfo.RegionName,
regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
connectedYN = true;
break;
}
// If we're one region over -x -y
//yxx
//xxx
//xxx
if ((((int)conn.X * (int)Constants.RegionSize) - conn.XEnd
== (regionConnections.X * (int)Constants.RegionSize))
&& (((int)conn.Y * (int)Constants.RegionSize) + conn.YEnd
== (regionConnections.Y * (int)Constants.RegionSize)))
{
Vector3 offset = Vector3.Zero;
offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
((conn.X * (int)Constants.RegionSize)));
offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
((conn.Y * (int)Constants.RegionSize)));
Vector3 extents = Vector3.Zero;
extents.Y = regionConnections.YEnd + conn.YEnd;
extents.X = conn.XEnd + conn.XEnd;
m_log.DebugFormat("Scene: {0} to the northeast of Scene{1} Offset: {2}. Extents:{3}",
conn.RegionScene.RegionInfo.RegionName,
regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, extents);
connectedYN = true;
break;
}
// If we're one region over x -y
//xyx
//xxx
//xxx
if ((((int)conn.X * (int)Constants.RegionSize)
== (regionConnections.X * (int)Constants.RegionSize))
&& (((int)conn.Y * (int)Constants.RegionSize) + conn.YEnd
== (regionConnections.Y * (int)Constants.RegionSize)))
{
Vector3 offset = Vector3.Zero;
offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
((conn.X * (int)Constants.RegionSize)));
offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
((conn.Y * (int)Constants.RegionSize)));
Vector3 extents = Vector3.Zero;
extents.Y = regionConnections.YEnd + conn.YEnd;
extents.X = conn.XEnd;
m_log.DebugFormat("Scene: {0} to the northeast of Scene{1} Offset: {2}. Extents:{3}",
conn.RegionScene.RegionInfo.RegionName,
regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
conn.RegionScene.PhysicsScene.Combine(scene.PhysicsScene,Vector3.Zero,extents);
scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset, Vector3.Zero);
conn.RegionScene.NorthBorders[0].BorderLine.Z += (int)Constants.RegionSize;
conn.RegionScene.EastBorders[0].BorderLine.Y += (int)Constants.RegionSize;
conn.RegionScene.WestBorders[0].BorderLine.Y += (int)Constants.RegionSize;
scene.SouthBorders[0].BorderLine.Z += (int)Constants.RegionSize; //auto teleport south
// Reset Terrain.. since terrain normally loads first.
conn.RegionScene.PhysicsScene.SetTerrain(conn.RegionScene.Heightmap.GetFloatsSerialised());
scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
connectedYN = true;
break;
}
// If we're one region over +x -y
//xxy
//xxx
//xxx
if ((((int)conn.X * (int)Constants.RegionSize) + conn.YEnd
== (regionConnections.X * (int)Constants.RegionSize))
&& (((int)conn.Y * (int)Constants.RegionSize) + conn.YEnd
== (regionConnections.Y * (int)Constants.RegionSize)))
{
Vector3 offset = Vector3.Zero;
offset.X = (((regionConnections.X * (int)Constants.RegionSize)) -
((conn.X * (int)Constants.RegionSize)));
offset.Y = (((regionConnections.Y * (int)Constants.RegionSize)) -
((conn.Y * (int)Constants.RegionSize)));
Vector3 extents = Vector3.Zero;
extents.Y = regionConnections.YEnd + conn.YEnd;
extents.X = conn.XEnd + conn.XEnd;
m_log.DebugFormat("Scene: {0} to the south of Scene{1} Offset: {2}. Extents:{3}",
conn.RegionScene.RegionInfo.RegionName,
regionConnections.RegionScene.RegionInfo.RegionName, offset, extents);
scene.PhysicsScene.Combine(conn.RegionScene.PhysicsScene, offset,extents);
break;
}
}
if (!connectedYN)
m_regions.Add(scene.RegionInfo.originRegionID,regionConnections);
}
}
public void RemoveRegion(Scene scene)
{
}
public void RegionLoaded(Scene scene)
{
}
public void PostInitialise()
{
}
public void OnFrame()
{
}
}
public struct RegionConnections
{
public UUID RegionId;
public Scene RegionScene;
public uint X;
public uint Y;
public int XEnd;
public int YEnd;
public List<RegionData> ConnectedRegions;
}
public struct RegionData
{
public UUID RegionId;
public Scene RegionScene;
public Vector3 Offset;
}
}