adjust terse avatar update filtering to send updates when distance traveled does not match expected distance, rather than at a fixed time period. this should smooth avatar motion somewhat when moving in a straight line and velocity is constant.

bulletsim
dahlia 2011-05-03 19:47:50 -07:00
parent f7d3720126
commit 13ab00e45a
1 changed files with 17 additions and 3 deletions

View File

@ -2395,6 +2395,7 @@ namespace OpenSim.Region.Framework.Scenes
// vars to support reduced update frequency when velocity is unchanged
private Vector3 lastVelocitySentToAllClients = Vector3.Zero;
private Vector3 lastPositionSentToAllClients = Vector3.Zero;
private int lastTerseUpdateToAllClientsTick = Util.EnvironmentTickCount();
/// <summary>
@ -2404,14 +2405,27 @@ namespace OpenSim.Region.Framework.Scenes
{
int currentTick = Util.EnvironmentTickCount();
// decrease update frequency when avatar is moving but velocity is not changing
// Decrease update frequency when avatar is moving but velocity is
// not changing.
// If there is a mismatch between distance travelled and expected
// distance based on last velocity sent and velocity hasnt changed,
// then send a new terse update
float timeSinceLastUpdate = (currentTick - lastTerseUpdateToAllClientsTick) * 0.001f;
Vector3 expectedPosition = lastPositionSentToAllClients + lastVelocitySentToAllClients * timeSinceLastUpdate;
float absoluteDistanceError = (float)Math.Abs(Vector3.Distance(m_pos, expectedPosition));
if (m_velocity.Length() < 0.01f
|| Vector3.Distance(lastVelocitySentToAllClients, m_velocity) > 0.01f
|| currentTick - lastTerseUpdateToAllClientsTick > 1500)
|| absoluteDistanceError > 0.25f // arbitrary distance error threshold
|| Vector3.Distance(lastVelocitySentToAllClients, m_velocity) > 0.01f)
{
m_perfMonMS = currentTick;
lastVelocitySentToAllClients = m_velocity;
lastTerseUpdateToAllClientsTick = currentTick;
lastPositionSentToAllClients = m_pos;
m_scene.ForEachClient(SendTerseUpdateToClient);