using GameKit.Utilities; using System.Runtime.CompilerServices; namespace FishNet.Object.Prediction { /// /// Data to be used to configure smoothing for an owned predicted object. /// internal struct MoveRates { public float Position; public float Rotation; public float Scale; public MoveRates(float value) { Position = value; Rotation = value; Scale = value; } public MoveRates(float position, float rotation) { Position = position; Rotation = rotation; Scale = INSTANT_VALUE; } public MoveRates(float position, float rotation, float scale) { Position = position; Rotation = rotation; Scale = scale; } /// /// True if a positional move rate is set. /// public bool PositionSet => (Position != UNSET_VALUE); /// /// True if rotation move rate is set. /// public bool RotationSet => (Rotation != UNSET_VALUE); /// /// True if a scale move rate is set. /// public bool ScaleSet => (Scale != UNSET_VALUE); /// /// True if any move rate is set. /// public bool AnySet => (PositionSet || RotationSet || ScaleSet); /// /// True if position move rate should be instant. /// public bool InstantPosition => (Position == INSTANT_VALUE); /// /// True if rotation move rate should be instant. /// public bool InstantRotation => (Rotation == INSTANT_VALUE); /// /// True if scale move rate should be instant. /// public bool InstantScale => (Scale == INSTANT_VALUE); /// /// Sets all rates to instant. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetInstantRates() { Update(INSTANT_VALUE); } /// /// Sets all rates to the same value. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(float value) { Update(value, value, value); } /// /// Sets rates for each property. /// public void Update(float position, float rotation, float scale) { Position = position; Rotation = rotation; Scale = scale; } /// /// Value used when data is not set. /// public const float UNSET_VALUE = float.NegativeInfinity; /// /// Value used when move rate should be instant. /// public const float INSTANT_VALUE = float.PositiveInfinity; } /// /// Data to be used to configure smoothing for an owned predicted object. /// internal class MoveRatesCls : IResettable { public float Position; public float Rotation; public float Scale; public float LastMultiplier { get; private set; } = 1f; public MoveRatesCls(float value) { Position = value; Rotation = value; Scale = value; } public MoveRatesCls(float position, float rotation) { Position = position; Rotation = rotation; Scale = INSTANT_VALUE; } public MoveRatesCls(float position, float rotation, float scale) { Position = position; Rotation = rotation; Scale = scale; } /// /// True if a positional move rate is set. /// public bool PositionSet => (Position != UNSET_VALUE); /// /// True if rotation move rate is set. /// public bool RotationSet => (Rotation != UNSET_VALUE); /// /// True if a scale move rate is set. /// public bool ScaleSet => (Scale != UNSET_VALUE); /// /// True if any move rate is set. /// public bool AnySet => (PositionSet || RotationSet || ScaleSet); /// /// True if position move rate should be instant. /// public bool InstantPosition => (Position == INSTANT_VALUE); /// /// True if rotation move rate should be instant. /// public bool InstantRotation => (Rotation == INSTANT_VALUE); /// /// True if scale move rate should be instant. /// public bool InstantScale => (Scale == INSTANT_VALUE); public MoveRatesCls() { Update(UNSET_VALUE, UNSET_VALUE, UNSET_VALUE); } /// /// Multiplies all rates by value. /// public void Multiply(float value) { LastMultiplier = value; Position *= value; Rotation *= value; Scale *= value; } /// /// Sets all rates to instant. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetInstantRates() { Update(INSTANT_VALUE); } /// /// Sets all rates to the same value. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(float value) { Update(value, value, value); } /// /// Updaes values. /// public void Update(float position, float rotation, float scale) { Position = position; Rotation = rotation; Scale = scale; } /// /// Updaes values. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(MoveRatesCls mr) { Update(mr.Position, mr.Rotation, mr.Scale); } public void ResetState() { Position = UNSET_VALUE; Rotation = UNSET_VALUE; Scale = UNSET_VALUE; } public void InitializeState() { } /// /// Value used when data is not set. /// public const float UNSET_VALUE = float.NegativeInfinity; /// /// Value used when move rate should be instant. /// public const float INSTANT_VALUE = float.PositiveInfinity; } }