#if !FISHNET_STABLE_REPLICATESTATES using System; using FishNet.Utility; using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo(UtilityConstants.CODEGEN_ASSEMBLY_NAME)] namespace FishNet.Object.Prediction { [System.Flags] public enum ReplicateState : byte { /// /// The default value of this state. /// This value should never occur when a replicate runs. /// Invalid = 0, /// /// Server and clients use this flag. /// Flag will be set if data tick has run outside a reconcile, such as from user code within OnTick. /// Ticked = (1 << 0), //1 /// /// Only client will use this flag. /// Flag is set if data is being run during a reconcile. /// Replayed = (1 << 1), //2 /// /// Server and client use this flag. /// Data has been created by the server or client. /// This indicates that data is known and was intentionally sent. /// Created = (1 << 2), //4 } public static class ReplicateStateExtensions { /// /// Returns if value is valid. /// This should never be false. /// public static bool IsValid(this ReplicateState value) => (value != ReplicateState.Invalid); /// /// Returns if value contains ReplicateState.Ticked. /// public static bool ContainsTicked(this ReplicateState value) => value.FastContains(ReplicateState.Ticked); /// /// Returns if value contains ReplicateState.Created. /// public static bool ContainsCreated(this ReplicateState value) => value.FastContains(ReplicateState.Created); /// /// Returns if value contains ReplicateState.Replayed. /// public static bool ContainsReplayed(this ReplicateState value) => value.FastContains(ReplicateState.Replayed); [Obsolete("Use ContainsReplayed.")] public static bool IsReplayed(this ReplicateState value) => value.ContainsReplayed(); /// /// Returns if value is (ReplicateState.Ticked | ReplicateState.Created). /// public static bool IsTickedCreated(this ReplicateState value) => (value == (ReplicateState.Ticked | ReplicateState.Created)); /// /// Returns if value equals ReplicateState.Ticked. /// public static bool IsTickedNonCreated(this ReplicateState value) => (value == ReplicateState.Ticked); /// /// Returns if value is (ReplicateState.Replayed | ReplicateState.Ticked | ReplicateState.Created). /// public static bool IsReplayedCreated(this ReplicateState value) => (value == (ReplicateState.Replayed | ReplicateState.Created)); /// /// Returns if value is ReplicateState.Replayed without ReplicateState.Ticked nor ReplicateState.Created. /// public static bool IsFuture(this ReplicateState value) => (value == ReplicateState.Replayed); [Obsolete("Use ContainsCreated.")] public static bool IsCreated(this ReplicateState value) => value.ContainsCreated(); /// /// True if part is containined within whole. /// public static bool FastContains(this ReplicateState whole, ReplicateState part) => (whole & part) == part; } } #else using FishNet.Utility; using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo(UtilityConstants.CODEGEN_ASSEMBLY_NAME)] namespace FishNet.Object { public enum ReplicateState : byte { /// /// The default value of this state. /// This value should never occur when a replicate runs. /// Invalid = 0, /// /// Value is seen on server and clients. /// Client or server has data on the object for the tick. /// Clients will only see this value on spectated objects when PredictionManager is using Appended state order. /// CurrentCreated = 1, /// /// Value is only seen on server when they do not own the object. /// Server does not have data on this non-owned object for the tick but expected to, such as a state should have arrived but did not. /// [System.Obsolete("This is currently not used but may be in a later release. Please read summary for value.")] CurrentPredicted = 2, /// /// Value is only seen on clients when they do not own the object. /// Client does not have data for the tick but expected to, such as a state should have arrived but did not. /// Client is currently reconciling. /// [System.Obsolete("This is currently not used but may be in a later release. Please read summary for value.")] ReplayedPredicted = 3, /// /// Value is only seen on clients. /// Client has data on the object for the tick. /// Client is currently reconciling. /// ReplayedCreated = 4, /// /// Value is only seen on clients when they do not own the object. /// Tick is in the future and data cannot yet be known. /// This can be used to exit replicate early to not process actions, or create actions based on previous datas. /// CurrentFuture = 5, /// /// Value is only seen on clients when they do not own the object. /// Tick is in the future and data cannot yet be known. /// Client is currently reconciling. /// This can be used to exit replicate early to not process actions, or create actions based on previous datas. /// ReplayedFuture = 6, } public static class ReplicateStateExtensions { /// /// Returns if value is valid. /// This should never be false. /// public static bool IsValid(this ReplicateState value) => (value != ReplicateState.Invalid); /// /// Returns if value is replayed. /// #pragma warning disable CS0618 // Type or member is obsolete public static bool IsReplayed(this ReplicateState value) => (value == ReplicateState.ReplayedPredicted || value == ReplicateState.ReplayedCreated || value == ReplicateState.ReplayedFuture); #pragma warning restore CS0618 // Type or member is obsolete /// /// Returns if value is user created. /// public static bool IsCreated(this ReplicateState value) => (value == ReplicateState.CurrentCreated || value == ReplicateState.ReplayedCreated); /// /// Returns if value is predicted. /// #pragma warning disable CS0618 // Type or member is obsolete public static bool IsPredicted(this ReplicateState value) => (value == ReplicateState.ReplayedPredicted); #pragma warning restore CS0618 // Type or member is obsolete /// /// Returns if value is in the future. /// public static bool IsFuture(this ReplicateState value) => (value == ReplicateState.CurrentFuture || value == ReplicateState.ReplayedFuture); } } #endif