ugly culling

LSLKeyTest
UbitUmarov 2016-07-13 14:00:33 +01:00
parent 14296bc792
commit 7131703244
1 changed files with 122 additions and 71 deletions

View File

@ -1722,17 +1722,43 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_entityUpdates.Remove(localIDs); m_entityUpdates.Remove(localIDs);
KillObjectPacket kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject); KillObjectPacket kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject);
// TODO: don't create new blocks if recycling an old packet
kill.ObjectData = new KillObjectPacket.ObjectDataBlock[localIDs.Count]; int perpacket = localIDs.Count;
if(perpacket > 200)
perpacket = 200;
int nsent = 0;
kill.ObjectData = new KillObjectPacket.ObjectDataBlock[perpacket];
for (int i = 0 ; i < localIDs.Count ; i++ ) for (int i = 0 ; i < localIDs.Count ; i++ )
{ {
kill.ObjectData[i] = new KillObjectPacket.ObjectDataBlock(); kill.ObjectData[nsent] = new KillObjectPacket.ObjectDataBlock();
kill.ObjectData[i].ID = localIDs[i]; kill.ObjectData[nsent].ID = localIDs[i];
}
if(++nsent >= 200)
{
kill.Header.Reliable = true; kill.Header.Reliable = true;
kill.Header.Zerocoded = true; kill.Header.Zerocoded = true;
OutPacket(kill, ThrottleOutPacketType.Task); OutPacket(kill, ThrottleOutPacketType.Task);
perpacket = localIDs.Count - i - 1;
if(perpacket == 0)
break;
if(perpacket > 200)
perpacket = 200;
kill = (KillObjectPacket)PacketPool.Instance.GetPacket(PacketType.KillObject);
kill.ObjectData = new KillObjectPacket.ObjectDataBlock[perpacket];
nsent = 0;
}
}
if(nsent != 0)
{
kill.Header.Reliable = true;
kill.Header.Zerocoded = true;
OutPacket(kill, ThrottleOutPacketType.Task);
}
} }
/// <summary> /// <summary>
@ -4292,8 +4318,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_killRecord.Clear(); m_killRecord.Clear();
} }
lock(GroupsNeedFullUpdate)
{
if(GroupsNeedFullUpdate.Count > 0) if(GroupsNeedFullUpdate.Count > 0)
{ {
foreach(SceneObjectGroup grp in GroupsNeedFullUpdate) foreach(SceneObjectGroup grp in GroupsNeedFullUpdate)
@ -4302,8 +4326,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
lock(GroupsInView) lock(GroupsInView)
GroupsInView.Add(grp); GroupsInView.Add(grp);
} }
GroupsNeedFullUpdate.Clear();
}
} }
#endregion #endregion
@ -4339,16 +4361,30 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public void ReprioritizeUpdates() public void ReprioritizeUpdates()
{ {
CheckGroupsInView();
lock (m_entityUpdates.SyncRoot) lock (m_entityUpdates.SyncRoot)
m_entityUpdates.Reprioritize(UpdatePriorityHandler); m_entityUpdates.Reprioritize(UpdatePriorityHandler);
CheckGroupsInView();
} }
private bool CheckGroupsInViewBusy = false;
private bool CheckGroupsInViewOverRun = false;
public void CheckGroupsInView() public void CheckGroupsInView()
{ {
bool doCulling = m_scene.ObjectsCullingByDistance; bool doCulling = m_scene.ObjectsCullingByDistance;
if(!doCulling) if(!doCulling)
return; return;
if(CheckGroupsInViewBusy)
{
CheckGroupsInViewOverRun = true;
return;
}
CheckGroupsInViewBusy = true;
do
{
CheckGroupsInViewOverRun = false;
float cullingrange = 64.0f; float cullingrange = 64.0f;
Vector3 mycamera = Vector3.Zero; Vector3 mycamera = Vector3.Zero;
Vector3 mypos = Vector3.Zero; Vector3 mypos = Vector3.Zero;
@ -4360,34 +4396,47 @@ namespace OpenSim.Region.ClientStack.LindenUDP
mypos = mysp.AbsolutePosition; mypos = mysp.AbsolutePosition;
} }
else else
{
CheckGroupsInViewBusy= false;
return; return;
}
HashSet<SceneObjectGroup> NewGroupsInView = new HashSet<SceneObjectGroup>(); HashSet<SceneObjectGroup> NewGroupsInView = new HashSet<SceneObjectGroup>();
HashSet<SceneObjectGroup> GroupsNeedFullUpdate = new HashSet<SceneObjectGroup>(); HashSet<SceneObjectGroup> GroupsNeedFullUpdate = new HashSet<SceneObjectGroup>();
List<uint> kills = new List<uint>(); List<uint> kills = new List<uint>();
// will this take for ever ?
EntityBase[] entities = m_scene.Entities.GetEntities(); EntityBase[] entities = m_scene.Entities.GetEntities();
foreach (EntityBase e in entities) foreach (EntityBase e in entities)
{ {
if(!IsActive)
return;
if (e != null && e is SceneObjectGroup && !((SceneObjectGroup)e).IsAttachment) if (e != null && e is SceneObjectGroup && !((SceneObjectGroup)e).IsAttachment)
{ {
SceneObjectGroup grp = (SceneObjectGroup)e; SceneObjectGroup grp = (SceneObjectGroup)e;
Vector3 grppos = grp.AbsolutePosition; Vector3 grppos = grp.AbsolutePosition;
float dcam = (grppos - mycamera).LengthSquared(); float dcam = (grppos - mycamera).LengthSquared();
float dpos = (grppos - mypos).LengthSquared(); float dpos = (grppos - mypos).LengthSquared();
if(dcam < dpos) if(dcam < dpos)
dpos = dcam; dpos = dcam;
dpos = (float)Math.Sqrt(dpos) - grp.GetBoundsRadius(); dpos = (float)Math.Sqrt(dpos) - grp.GetBoundsRadius();
bool inview; bool inview;
lock(GroupsInView) lock(GroupsInView)
inview = GroupsInView.Contains(grp); inview = GroupsInView.Contains(grp);
if(dpos > cullingrange) if(dpos > cullingrange)
{ {
if(inview) if(inview)
{ {
// GroupsInView.Remove(grp);
if (!kills.Contains(grp.LocalId))
kills.Add(grp.LocalId); kills.Add(grp.LocalId);
if (kills.Count > 100)
{
SendKillObject(kills);
kills.Clear();
Thread.Sleep(50);
}
} }
} }
else else
@ -4413,7 +4462,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
foreach(SceneObjectGroup grp in GroupsNeedFullUpdate) foreach(SceneObjectGroup grp in GroupsNeedFullUpdate)
grp.ScheduleGroupForFullUpdate(); grp.ScheduleGroupForFullUpdate();
} }
GroupsNeedFullUpdate.Clear(); } while(CheckGroupsInViewOverRun);
CheckGroupsInViewBusy = false;
} }
private bool UpdatePriorityHandler(ref uint priority, ISceneEntity entity) private bool UpdatePriorityHandler(ref uint priority, ISceneEntity entity)