2022-07-20 17:50:01 +08:00
|
|
|
|
using GTA;
|
2022-05-23 15:27:51 +08:00
|
|
|
|
using GTA.Math;
|
2022-08-04 17:38:28 +08:00
|
|
|
|
using System.Diagnostics;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
|
|
|
|
|
namespace RageCoop.Client
|
|
|
|
|
{
|
2022-07-01 14:39:43 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2022-06-11 18:41:10 +08:00
|
|
|
|
public abstract class SyncedEntity
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-07-02 17:14:56 +08:00
|
|
|
|
|
2022-05-22 15:55:26 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates whether the current player is responsible for syncing this entity.
|
|
|
|
|
/// </summary>
|
2022-07-02 17:14:56 +08:00
|
|
|
|
public bool IsLocal
|
2022-05-22 15:55:26 +08:00
|
|
|
|
{
|
2022-08-11 14:48:19 +02:00
|
|
|
|
get => OwnerID == Main.LocalPlayerID;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
2022-07-02 17:14:56 +08:00
|
|
|
|
|
2022-07-01 14:39:43 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Network ID for this entity
|
|
|
|
|
/// </summary>
|
2022-07-20 17:50:01 +08:00
|
|
|
|
public int ID { get; internal set; }
|
2022-08-08 17:03:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int _ownerID;
|
2022-07-01 14:39:43 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2022-08-08 17:03:41 +08:00
|
|
|
|
public int OwnerID
|
|
|
|
|
{
|
2022-08-11 14:48:19 +02:00
|
|
|
|
get => _ownerID;
|
2022-08-08 17:03:41 +08:00
|
|
|
|
internal set
|
|
|
|
|
{
|
2022-08-11 19:42:30 +08:00
|
|
|
|
if (value==_ownerID && Owner!=null) { return; }
|
2022-08-08 17:03:41 +08:00
|
|
|
|
_ownerID = value;
|
|
|
|
|
Owner=PlayerList.GetPlayer(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-14 17:08:43 +08:00
|
|
|
|
internal virtual Player Owner { get; private set; }
|
2022-07-01 14:39:43 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2022-05-22 15:55:26 +08:00
|
|
|
|
public bool IsOutOfSync
|
|
|
|
|
{
|
2022-08-11 14:48:19 +02:00
|
|
|
|
get => Main.Ticked - LastSynced > 200 && ID != 0;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
2022-06-11 18:41:10 +08:00
|
|
|
|
internal bool IsReady
|
2022-05-23 16:59:49 +08:00
|
|
|
|
{
|
2022-08-11 14:48:19 +02:00
|
|
|
|
get => LastSynced > 0 || LastFullSynced == 0;
|
2022-05-23 16:59:49 +08:00
|
|
|
|
}
|
2022-07-02 17:14:56 +08:00
|
|
|
|
internal bool IsInvincible { get; set; } = false;
|
2022-06-11 18:41:10 +08:00
|
|
|
|
internal bool NeedUpdate
|
2022-05-23 16:59:49 +08:00
|
|
|
|
{
|
2022-08-11 14:48:19 +02:00
|
|
|
|
get => LastSynced >= LastUpdated;
|
2022-05-23 16:59:49 +08:00
|
|
|
|
}
|
2022-05-22 15:55:26 +08:00
|
|
|
|
#region LAST STATE
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Last time a new sync message arrived.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ulong LastSynced { get; set; } = 0;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Last time a new sync message arrived.
|
|
|
|
|
/// </summary>
|
2022-07-17 11:59:37 +08:00
|
|
|
|
public ulong LastFullSynced { get; internal set; } = 0;
|
2022-05-22 15:55:26 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Last time the local entity has been updated,
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ulong LastUpdated { get; set; } = 0;
|
2022-08-04 17:38:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal Stopwatch LastSentStopWatch { get; set; } = Stopwatch.StartNew();
|
2022-05-22 15:55:26 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
2022-07-20 17:50:01 +08:00
|
|
|
|
public bool SendNextFrame { get; set; } = false;
|
|
|
|
|
public bool SendFullNextFrame { get; set; } = false;
|
|
|
|
|
|
2022-07-02 17:14:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2022-07-20 17:50:01 +08:00
|
|
|
|
internal protected bool _lastFrozen = false;
|
2022-07-15 13:45:43 +08:00
|
|
|
|
internal Model Model { get; set; }
|
2022-06-11 18:41:10 +08:00
|
|
|
|
internal Vector3 Position { get; set; }
|
|
|
|
|
internal Vector3 Rotation { get; set; }
|
|
|
|
|
internal Quaternion Quaternion { get; set; }
|
|
|
|
|
internal Vector3 Velocity { get; set; }
|
|
|
|
|
internal abstract void Update();
|
|
|
|
|
internal void PauseUpdate(ulong frames)
|
2022-05-31 09:55:54 +08:00
|
|
|
|
{
|
|
|
|
|
LastUpdated=Main.Ticked+frames;
|
|
|
|
|
}
|
2022-05-22 15:55:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|