private void HandleClient(AuthoritativeFrameType type, Vector3 currentValue, ref Vector3 previousValue)
{
byte currentFrame = NetworkingManager.Instance.CurrentFrame;
bool valueChanged = Vector3.Distance(currentValue, previousValue) > 0.01f;
bool frameFound = false;
switch (type)
{
case AuthoritativeFrameType.Position:
if (currentFrame != _previousPosFrame || valueChanged)
{
if (valueChanged)
_posTimeStamp = Time.time;
Vector3 delta = Vector3.zero;
Vector3 previous = previousValue;
_previousPosFrame = currentFrame;
if (_positionFrameHistory.Count > 0)
{
for (int i = _positionFrameHistory.Count - 1; i >= 0; --i)
{
if (_positionFrameHistory[i].Frame == currentFrame)
{
frameFound = true;
_positionFrameHistory[i].FrameActualValue = currentValue;
_positionFrameHistory[i].UpdateDelta();
break;
}
}
if (!frameFound)
{
delta = currentValue - _positionFrameHistory[_positionFrameHistory.Count - 1].FrameActualValue;
previousValue = currentValue;
}
previous = _positionFrameHistory[_positionFrameHistory.Count - 1].FrameActualValue;
}
if (!frameFound)
{
AuthoritativeFrame tempNewFrame = new AuthoritativeFrame(currentFrame, currentValue, delta, previous);
_positionFrameHistory.Add(tempNewFrame);
}
if (_positionFrameHistory.Count > byte.MaxValue)
_positionFrameHistory.RemoveRange(0, (int)(_positionFrameHistory.Count * 0.8f));
}
break;
case AuthoritativeFrameType.Rotation:
if (currentFrame != _previousRotFrame || valueChanged)
{
if (valueChanged)
_rotTimeStamp = Time.time;
Vector3 delta = Vector3.zero;
Vector3 previous = previousValue;
_previousRotFrame = currentFrame;
if (_rotationFrameHistory.Count > 0)
{
for (int i = _rotationFrameHistory.Count - 1; i >= 0; --i)
{
if (_rotationFrameHistory[i].Frame == currentFrame)
{
frameFound = true;
_rotationFrameHistory[i].FrameActualValue = currentValue;
_rotationFrameHistory[i].UpdateDelta();
break;
}
}
if (!frameFound)
{
delta = currentValue - _rotationFrameHistory[_rotationFrameHistory.Count - 1].FrameActualValue;
previousValue = currentValue;
}
previous = _rotationFrameHistory[_rotationFrameHistory.Count - 1].FrameActualValue;
}
if (!frameFound)
{
AuthoritativeFrame tempNewFrame = new AuthoritativeFrame(currentFrame, currentValue, delta, previous);
_rotationFrameHistory.Add(tempNewFrame);
}
if (_rotationFrameHistory.Count > byte.MaxValue)
_rotationFrameHistory.RemoveRange(0, (int)(_rotationFrameHistory.Count * 0.8f));
}
break;
case AuthoritativeFrameType.Scale:
if (currentFrame != _previousScaFrame || valueChanged)
{
if (valueChanged)
_scaTimeStamp = Time.time;
Vector3 delta = Vector3.zero;
Vector3 previous = previousValue;
_previousScaFrame = currentFrame;
if (_scaleFrameHistory.Count > 0)
{
for (int i = _scaleFrameHistory.Count - 1; i >= 0; --i)
{
if (_scaleFrameHistory[i].Frame == currentFrame)
{
frameFound = true;
_scaleFrameHistory[i].FrameActualValue = currentValue;
_scaleFrameHistory[i].UpdateDelta();
break;
}
}
if (!frameFound)
{
delta = currentValue - _scaleFrameHistory[_scaleFrameHistory.Count - 1].FrameActualValue;
previousValue = currentValue;
}
previous = _scaleFrameHistory[_scaleFrameHistory.Count - 1].FrameActualValue;
}
if (!frameFound)
{
AuthoritativeFrame tempNewFrame = new AuthoritativeFrame(currentFrame, currentValue, delta, previous);
_scaleFrameHistory.Add(tempNewFrame);
}
if (_scaleFrameHistory.Count > byte.MaxValue)
_scaleFrameHistory.RemoveRange(0, (int)(_scaleFrameHistory.Count * 0.8f));
}
break;
}
}