106 lines
2.7 KiB
C#
Raw Normal View History

2022-07-20 17:50:01 +08:00
using GTA;
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>
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
{
get
{
return 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
{
get
{
return _ownerID;
}
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);
}
}
internal 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
{
get
{
2022-07-02 17:14:56 +08:00
return Main.Ticked-LastSynced>200 && ID!=0;
2022-05-22 15:55:26 +08:00
}
}
internal bool IsReady
{
2022-07-20 17:50:01 +08:00
get { return (LastSynced>0||LastFullSynced==0); }
}
2022-07-02 17:14:56 +08:00
internal bool IsInvincible { get; set; } = false;
internal bool NeedUpdate
{
get { return LastSynced>=LastUpdated; }
}
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>
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;
internal Model Model { get; set; }
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
}
}