Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Date to Time and Weather sync #46

Open
wants to merge 6 commits into
base: 1.6-pre-alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 12 additions & 28 deletions Client/Scripts/Networking/Receive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,37 +321,21 @@ private static void PedSync(Packets.PedSync packet)

private static void VehicleSync(Packets.VehicleSync packet)
{
var v = EntityPool.GetVehicleByID(packet.ID);
if (v == null) EntityPool.ThreadSafe.Add(v = new SyncedVehicle(packet.ID));
var v = EntityPool.GetVehicleByID(packet.ED.ID);
if (v == null) EntityPool.ThreadSafe.Add(v = new SyncedVehicle(packet.ED.ID));
if (v.IsLocal) return;
v.ID = packet.ID;
v.OwnerID = packet.OwnerID;
v.Flags = packet.Flags;
v.Position = packet.Position;
v.Quaternion = packet.Quaternion;
v.SteeringAngle = packet.SteeringAngle;
v.ThrottlePower = packet.ThrottlePower;
v.BrakePower = packet.BrakePower;
v.Velocity = packet.Velocity;
v.RotationVelocity = packet.RotationVelocity;
v.DeluxoWingRatio = packet.DeluxoWingRatio;
bool full = packet.Flags.HasVehFlag(VehicleDataFlags.IsFullSync);
v.ID = packet.ED.ID;
v.OwnerID = packet.ED.OwnerID;
v.Position = packet.ED.Position;
v.Quaternion = packet.ED.Quaternion;
v.Velocity = packet.ED.Velocity;
v.Model = packet.ED.ModelHash;
v.VD = packet.VD;
bool full = packet.VD.Flags.HasVehFlag(VehicleDataFlags.IsFullSync);
if (full)
{
v.DamageModel = packet.DamageModel;
v.EngineHealth = packet.EngineHealth;
v.Mods = packet.Mods;
v.ToggleModsMask = packet.ToggleModsMask;
v.Model = packet.ModelHash;
v.Colors = packet.Colors;
v.LandingGear = packet.LandingGear;
v.RoofState = (VehicleRoofState)packet.RoofState;
v.LockStatus = packet.LockStatus;
v.RadioStation = packet.RadioStation;
v.LicensePlate = packet.LicensePlate;
v.Livery = packet.Livery;
v.HeadlightColor = packet.HeadlightColor;
v.ExtrasMask = packet.ExtrasMask;
v.VDF = packet.VDF;
v.VDV = packet.VDV;
}
v.SetLastSynced(full);
}
Expand Down
57 changes: 29 additions & 28 deletions Client/Scripts/Networking/Send.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,22 @@ public static void SendVehicle(SyncedVehicle v, bool full)
if (v.LastSentStopWatch.ElapsedMilliseconds < SyncInterval) return;
var veh = v.MainVehicle;
var packet = SendPackets.VehicelPacket;
packet.ID = v.ID;
packet.OwnerID = v.OwnerID;
packet.Flags = v.GetVehicleFlags();
packet.SteeringAngle = veh.SteeringAngle;
packet.Position = veh.ReadPosition();
packet.Velocity = veh.Velocity;
packet.Quaternion = veh.ReadQuaternion();
packet.RotationVelocity = veh.WorldRotationVelocity;
packet.ThrottlePower = veh.ThrottlePower;
packet.BrakePower = veh.BrakePower;
packet.ED.ID = v.ID;
packet.ED.OwnerID = v.OwnerID;
packet.ED.Position = veh.ReadPosition();
packet.ED.Velocity = veh.Velocity;
packet.ED.Quaternion = veh.ReadQuaternion();
packet.ED.ModelHash = veh.Model.Hash;
packet.VD.Flags = v.GetVehicleFlags();
packet.VD.SteeringAngle = veh.SteeringAngle;
packet.VD.ThrottlePower = veh.ThrottlePower;
packet.VD.BrakePower = veh.BrakePower;
packet.VD.Flags |= VehicleDataFlags.IsFullSync;
packet.VD.LockStatus = veh.LockStatus;

v.LastSentStopWatch.Restart();
if (packet.Flags.HasVehFlag(VehicleDataFlags.IsDeluxoHovering))
packet.DeluxoWingRatio = v.MainVehicle.GetDeluxoWingRatio();
if (packet.VD.Flags.HasVehFlag(VehicleDataFlags.IsDeluxoHovering))
packet.VD.DeluxoWingRatio = v.MainVehicle.GetDeluxoWingRatio();
if (full)
{
byte primaryColor = 0;
Expand All @@ -125,23 +128,21 @@ public static void SendVehicle(SyncedVehicle v, bool full)
Call<byte>(GET_VEHICLE_COLOURS, veh, &primaryColor, &secondaryColor);
}

packet.Flags |= VehicleDataFlags.IsFullSync;
packet.Colors = (primaryColor, secondaryColor);
packet.DamageModel = veh.GetVehicleDamageModel();
packet.LandingGear = veh.IsAircraft ? (byte)veh.LandingGearState : (byte)0;
packet.RoofState = (byte)veh.RoofState;
packet.Mods = v.GetVehicleMods(out packet.ToggleModsMask);
packet.ModelHash = veh.Model.Hash;
packet.EngineHealth = veh.EngineHealth;
packet.LockStatus = veh.LockStatus;
packet.LicensePlate = Call<string>(GET_VEHICLE_NUMBER_PLATE_TEXT, veh);
packet.Livery = Call<int>(GET_VEHICLE_LIVERY, veh);
packet.HeadlightColor = (byte)Call<int>(GET_VEHICLE_XENON_LIGHT_COLOR_INDEX, veh);
packet.ExtrasMask = v.GetVehicleExtras();
packet.RadioStation = v.MainVehicle == LastV
packet.VDF.LandingGear = veh.IsAircraft ? (byte)veh.LandingGearState : (byte)0;
packet.VDF.RoofState = (byte)veh.RoofState;
packet.VDF.Colors = (primaryColor, secondaryColor);
packet.VDF.DamageModel = veh.GetVehicleDamageModel();
packet.VDF.EngineHealth = veh.EngineHealth;
packet.VDF.Livery = Call<int>(GET_VEHICLE_LIVERY, veh);
packet.VDF.HeadlightColor = (byte)Call<int>(GET_VEHICLE_XENON_LIGHT_COLOR_INDEX, veh);
packet.VDF.ExtrasMask = v.GetVehicleExtras();
packet.VDF.RadioStation = v.MainVehicle == LastV
? Util.GetPlayerRadioIndex() : byte.MaxValue;
if (packet.EngineHealth > v.LastEngineHealth) packet.Flags |= VehicleDataFlags.Repaired;
v.LastEngineHealth = packet.EngineHealth;
if (packet.VDF.EngineHealth > v.LastEngineHealth) packet.VD.Flags |= VehicleDataFlags.Repaired;

packet.VDV.Mods = v.GetVehicleMods(out packet.VDF.ToggleModsMask);
packet.VDV.LicensePlate = Call<string>(GET_VEHICLE_NUMBER_PLATE_TEXT, veh);
v.LastEngineHealth = packet.VDF.EngineHealth;
}

SendSync(packet, ConnectionChannel.VehicleSync);
Expand Down
10 changes: 5 additions & 5 deletions Client/Scripts/Scripting/BaseScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public static void OnStart()
{
unsafe
{
var time = World.CurrentTimeOfDay;
var date = World.CurrentDate;
var weather1 = default(int);
var weather2 = default(int);
var percent2 = default(float);
Call(GET_CURR_WEATHER_STATE, &weather1, &weather2, &percent2);
API.SendCustomEvent(CustomEvents.WeatherTimeSync, time.Hours, time.Minutes,
time.Seconds, weather1, weather2, percent2);
API.SendCustomEvent(CustomEvents.WeatherTimeSync, date.Year, date.Month, date.Day, date.Hour, date.Minute,
date.Second, weather1, weather2, percent2);
}
});

Expand All @@ -61,8 +61,8 @@ public static void OnStart()

private static void WeatherTimeSync(CustomEventReceivedArgs e)
{
World.CurrentTimeOfDay = new TimeSpan((int)e.Args[0], (int)e.Args[1], (int)e.Args[2]);
Call(SET_CURR_WEATHER_STATE, (int)e.Args[3], (int)e.Args[4], (float)e.Args[5]);
World.CurrentDate = new DateTime((int)e.Args[0], (int)e.Args[1], (int)e.Args[2], (int)e.Args[3], (int)e.Args[4], (int)e.Args[5]);
Call(SET_CURR_WEATHER_STATE, (int)e.Args[6], (int)e.Args[7], (float)e.Args[8]);
}

private static void SetDisplayNameTag(CustomEventReceivedArgs e)
Expand Down
57 changes: 18 additions & 39 deletions Client/Scripts/Sync/Entities/Vehicle/SyncedVehicle.Variables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,23 @@ public partial class SyncedVehicle


#region -- SYNC DATA --

internal Vector3 RotationVelocity { get; set; }
internal float SteeringAngle { get; set; }
internal float ThrottlePower { get; set; }
internal float BrakePower { get; set; }
internal float DeluxoWingRatio { get; set; } = -1;


internal byte LandingGear { get; set; }
internal VehicleRoofState RoofState { get; set; }
internal VehicleDamageModel DamageModel { get; set; }
internal (byte, byte) Colors { get; set; }
internal (int, int)[] Mods { get; set; }
internal float EngineHealth { get; set; }
internal VehicleLockStatus LockStatus { get; set; }
internal byte RadioStation = 255;
internal string LicensePlate { get; set; }
internal int Livery { get; set; } = -1;
internal byte HeadlightColor { get; set; } = 255;
internal VehicleDataFlags Flags { get; set; }
internal ushort ExtrasMask;
internal byte ToggleModsMask;
internal VehicleData VD;
internal VehicleDataFull VDF;
internal VehicleDataVar VDV;

#endregion

#region FLAGS

internal bool EngineRunning => Flags.HasVehFlag(VehicleDataFlags.IsEngineRunning);
internal bool Transformed => Flags.HasVehFlag(VehicleDataFlags.IsTransformed);
internal bool HornActive => Flags.HasVehFlag(VehicleDataFlags.IsHornActive);
internal bool LightsOn => Flags.HasVehFlag(VehicleDataFlags.AreLightsOn);
internal bool BrakeLightsOn => Flags.HasVehFlag(VehicleDataFlags.AreBrakeLightsOn);
internal bool HighBeamsOn => Flags.HasVehFlag(VehicleDataFlags.AreHighBeamsOn);
internal bool SireneActive => Flags.HasVehFlag(VehicleDataFlags.IsSirenActive);
internal bool IsDead => Flags.HasVehFlag(VehicleDataFlags.IsDead);
internal bool IsDeluxoHovering => Flags.HasVehFlag(VehicleDataFlags.IsDeluxoHovering);
internal bool EngineRunning => VD.Flags.HasVehFlag(VehicleDataFlags.IsEngineRunning);
internal bool Transformed => VD.Flags.HasVehFlag(VehicleDataFlags.IsTransformed);
internal bool HornActive => VD.Flags.HasVehFlag(VehicleDataFlags.IsHornActive);
internal bool LightsOn => VD.Flags.HasVehFlag(VehicleDataFlags.AreLightsOn);
internal bool BrakeLightsOn => VD.Flags.HasVehFlag(VehicleDataFlags.AreBrakeLightsOn);
internal bool HighBeamsOn => VD.Flags.HasVehFlag(VehicleDataFlags.AreHighBeamsOn);
internal bool SireneActive => VD.Flags.HasVehFlag(VehicleDataFlags.IsSirenActive);
internal bool IsDead => VD.Flags.HasVehFlag(VehicleDataFlags.IsDead);
internal bool IsDeluxoHovering => VD.Flags.HasVehFlag(VehicleDataFlags.IsDeluxoHovering);

#endregion

Expand All @@ -69,15 +50,13 @@ public partial class SyncedVehicle
#endregion

#region PRIVATE
private byte _lastToggleMods;
private (byte, byte) _lastVehicleColors;
private ushort _lastExtras;
private (int, int)[] _lastVehicleMods = Array.Empty<(int, int)>();
private bool _lastHornActive;
private bool _lastTransformed;
private int _lastLivery = -1;
private byte _lastHeadlightColor = 255;
private VehicleData _lastVD;
private VehicleDataFull _lastVDF;
private VehicleDataVar _lastVDV;
private Vector3 _predictedPosition;
internal bool _lastTransformed => _lastVD.Flags.HasVehFlag(VehicleDataFlags.IsTransformed);
internal bool _lastHornActive => _lastVD.Flags.HasVehFlag(VehicleDataFlags.IsHornActive);

#endregion

#region OUTGOING
Expand Down
Loading