diff --git a/RageCoop.Client/Networking/Receive.cs b/RageCoop.Client/Networking/Receive.cs index 4f00e14..5bd0af4 100644 --- a/RageCoop.Client/Networking/Receive.cs +++ b/RageCoop.Client/Networking/Receive.cs @@ -335,6 +335,7 @@ namespace RageCoop.Client c.Flags=packet.Flags; c.Heading=packet.Heading; c.Position = packet.Position; + c.LastSyncedStopWatch.Restart(); if (c.IsRagdoll) { c.HeadPosition=packet.HeadPosition; diff --git a/RageCoop.Client/Properties/AssemblyInfo.cs b/RageCoop.Client/Properties/AssemblyInfo.cs index 2cf9c27..d02c3aa 100644 --- a/RageCoop.Client/Properties/AssemblyInfo.cs +++ b/RageCoop.Client/Properties/AssemblyInfo.cs @@ -16,7 +16,7 @@ using System.Resources; // Version informationr( -[assembly: AssemblyVersion("1.5.2.104")] -[assembly: AssemblyFileVersion("1.5.2.104")] +[assembly: AssemblyVersion("1.5.2.111")] +[assembly: AssemblyFileVersion("1.5.2.111")] [assembly: NeutralResourcesLanguageAttribute( "en-US" )] diff --git a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs index 641ddbf..d996cbb 100644 --- a/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs +++ b/RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs @@ -684,10 +684,11 @@ namespace RageCoop.Client private void SmoothTransition() { var localRagdoll = MainPed.IsRagdoll; - var dist = Position.DistanceTo(MainPed.ReadPosition()); - if (dist>3) + var predicted = Predict(Position); + var dist = predicted.DistanceTo(MainPed.ReadPosition()); + if (IsOff(dist)) { - MainPed.PositionNoOffset=Position; + MainPed.PositionNoOffset= predicted; return; } if (!(localRagdoll || MainPed.IsDead)) @@ -696,12 +697,12 @@ namespace RageCoop.Client { var cur=MainPed.Heading; var diff=Heading-cur; - if (diff > 180) { diff = diff - 360; } - else if (diff < -180) { diff = 360 + diff; } + if (diff > 180) { diff -= 360; } + else if (diff < -180) { diff += 360; } MainPed.Heading=cur+diff/2; } - MainPed.Velocity=Velocity+5*dist*(Position-MainPed.ReadPosition()); + MainPed.Velocity = Velocity + 5 * dist * (predicted - MainPed.ReadPosition()); } else if (Main.Ticked-_lastRagdollTime<10) { @@ -718,25 +719,25 @@ namespace RageCoop.Client helper.EqualizeAmount = 1; helper.PartIndex=20; - helper.Impulse=20*(HeadPosition-head.Position); + helper.Impulse=20*(Predict(HeadPosition) -head.Position); helper.Start(); helper.Stop(); helper.EqualizeAmount = 1; helper.PartIndex=6; - helper.Impulse=20*(RightFootPosition-rightFoot.Position); + helper.Impulse=20*(Predict(RightFootPosition) -rightFoot.Position); helper.Start(); helper.Stop(); helper.EqualizeAmount = 1; helper.PartIndex=3; - helper.Impulse=20*(LeftFootPosition-leftFoot.Position); + helper.Impulse=20*(Predict(LeftFootPosition) -leftFoot.Position); helper.Start(); helper.Stop(); } else { - MainPed.Velocity=Velocity+5*dist*(Position-MainPed.ReadPosition()); + MainPed.Velocity=Velocity+5*dist*(predicted-MainPed.ReadPosition()); } } diff --git a/RageCoop.Client/Sync/Entities/SyncedEntity.cs b/RageCoop.Client/Sync/Entities/SyncedEntity.cs index 1433fd3..faec6b6 100644 --- a/RageCoop.Client/Sync/Entities/SyncedEntity.cs +++ b/RageCoop.Client/Sync/Entities/SyncedEntity.cs @@ -89,10 +89,27 @@ namespace RageCoop.Client internal Vector3 Rotation { get; set; } internal Quaternion Quaternion { get; set; } internal Vector3 Velocity { get; set; } + public Stopwatch LastSyncedStopWatch = new Stopwatch(); internal abstract void Update(); internal void PauseUpdate(ulong frames) { LastUpdated=Main.Ticked+frames; } + protected Vector3 Predict(Vector3 input) + { + return (Owner.PacketTravelTime + 0.001f * LastSyncedStopWatch.ElapsedMilliseconds) * Velocity + input; + } + private float _accumulatedOff=0; + protected bool IsOff(float thisOff, float tolerance=3 , float limit = 30) + { + _accumulatedOff += thisOff - tolerance; + if (_accumulatedOff < 0) { _accumulatedOff=0;} + else if (_accumulatedOff>=limit) + { + _accumulatedOff = 0; + return true; + } + return false; + } } } diff --git a/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.Members.cs b/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.Members.cs index 79b71ea..5f39871 100644 --- a/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.Members.cs +++ b/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.Members.cs @@ -9,7 +9,6 @@ using GTA.Native; namespace RageCoop.Client{ public partial class SyncedVehicle{ public Vehicle MainVehicle { get; internal set; } - public Stopwatch LastSyncedStopWatch = new Stopwatch(); #region -- SYNC DATA -- diff --git a/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs b/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs index 31269a1..c72a2be 100644 --- a/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs +++ b/RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs @@ -260,8 +260,7 @@ namespace RageCoop.Client } void DisplayVehicle() { - _elapsed = Owner.PacketTravelTime + 0.001f * LastSyncedStopWatch.ElapsedMilliseconds; - _predictedPosition = Position + _elapsed * Velocity; + _predictedPosition = Predict(Position); var current = MainVehicle.ReadPosition(); var dist = current.DistanceTo(_predictedPosition); var cali = dist * (_predictedPosition - current); diff --git a/RageCoop.Client/WorldThread.cs b/RageCoop.Client/WorldThread.cs index 43ada70..903e209 100644 --- a/RageCoop.Client/WorldThread.cs +++ b/RageCoop.Client/WorldThread.cs @@ -1,6 +1,8 @@ using GTA; using GTA.Native; using System; +using System.Threading.Tasks; +using System.Threading; namespace RageCoop.Client { @@ -9,7 +11,6 @@ namespace RageCoop.Client /// public class WorldThread : Script { - private static bool _lastDisableTraffic = false; /// /// Don't use it! @@ -19,15 +20,30 @@ namespace RageCoop.Client Tick += OnTick; Aborted += (sender, e) => { - if (_lastDisableTraffic) - { - Traffic(true); - } + ChangeTraffic(true); }; + Task.Run(() => + { + while (true) + { + Thread.Sleep(5000); + Main.QueueAction(() => { ChangeTraffic(_trafficEnabled); }); + } + }); } - + static bool _trafficEnabled; private void OnTick(object sender, EventArgs e) { + if (!_trafficEnabled) + { + Function.Call(Hash.SET_VEHICLE_POPULATION_BUDGET, 0); + Function.Call(Hash.SET_PED_POPULATION_BUDGET, 0); + Function.Call(Hash.SET_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0f); + Function.Call(Hash.SET_RANDOM_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0f); + Function.Call(Hash.SET_PARKED_VEHICLE_DENSITY_MULTIPLIER_THIS_FRAME, 0f); + Function.Call(Hash.SUPPRESS_SHOCKING_EVENTS_NEXT_FRAME); + Function.Call(Hash.SUPPRESS_AGITATION_EVENTS_NEXT_FRAME); + } if (Game.IsLoading || !Networking.IsOnServer) { return; @@ -39,13 +55,16 @@ namespace RageCoop.Client { Game.DisableControlThisFrame(Control.FrontendPauseAlternate); } - // Sets a value that determines how aggressive the ocean waves will be. // Values of 2.0 or more make for very aggressive waves like you see during a thunderstorm. Function.Call(Hash.SET_DEEP_OCEAN_SCALER, 0.0f); // Works only ~200 meters around the player } - public static void Traffic(bool enable) + { + ChangeTraffic(enable); + _trafficEnabled = enable; + } + private static void ChangeTraffic(bool enable) { if (enable) { @@ -78,35 +97,63 @@ namespace RageCoop.Client Function.Call(Hash.SET_DISTANT_CARS_ENABLED, false); Function.Call(Hash.DISABLE_VEHICLE_DISTANTLIGHTS, true); - - foreach (Ped ped in World.GetAllPeds()) + if (Networking.IsOnServer) { - SyncedPed c = EntityPool.GetPedByHandle(ped.Handle); - if ((c==null) || (c.IsLocal && (ped.Handle!=Game.Player.Character.Handle)&&ped.PopulationType!=EntityPopulationType.Mission)) - { - if (ped.Handle==Game.Player.Character.Handle) { continue; } - // Main.Logger.Trace($"Removing ped {ped.Handle}. Reason:RemoveTraffic"); - ped.CurrentVehicle?.Delete(); - ped.Kill(); - ped.Delete(); + foreach (Ped ped in World.GetAllPeds()) + { + SyncedPed c = EntityPool.GetPedByHandle(ped.Handle); + if ((c == null) || (c.IsLocal && (ped.Handle != Game.Player.Character.Handle) && ped.PopulationType != EntityPopulationType.Mission)) + { + if (ped.Handle == Game.Player.Character.Handle) { continue; } + + // Main.Logger.Trace($"Removing ped {ped.Handle}. Reason:RemoveTraffic"); + ped.CurrentVehicle?.Delete(); + ped.Kill(); + ped.Delete(); + } + } + foreach (Vehicle veh in World.GetAllVehicles()) + { + SyncedVehicle v = veh.GetSyncEntity(); + if (v.MainVehicle == Game.Player.LastVehicle) + { + // Don't delete player's vehicle + continue; + } + if ((v == null) || (v.IsLocal && veh.PopulationType != EntityPopulationType.Mission)) + { + // Main.Logger.Debug($"Removing Vehicle {veh.Handle}. Reason:ClearTraffic"); + + veh.Delete(); + } + } } - - foreach (Vehicle veh in World.GetAllVehicles()) + else { - SyncedVehicle v = veh.GetSyncEntity(); - if (v.MainVehicle==Game.Player.LastVehicle) + foreach (Ped ped in World.GetAllPeds()) { - // Don't delete player's vehicle - continue; - } - if ((v== null) || (v.IsLocal&&veh.PopulationType!=EntityPopulationType.Mission)) - { - // Main.Logger.Debug($"Removing Vehicle {veh.Handle}. Reason:ClearTraffic"); + if ((ped != Game.Player.Character) && (ped.PopulationType != EntityPopulationType.Mission)) + { + // Main.Logger.Trace($"Removing ped {ped.Handle}. Reason:RemoveTraffic"); + ped.CurrentVehicle?.Delete(); + ped.Kill(); + ped.Delete(); + } - veh.Delete(); + } + var last = Game.Player.Character.LastVehicle; + var current = Game.Player.Character.CurrentVehicle; + foreach (Vehicle veh in World.GetAllVehicles()) + { + if (veh.PopulationType != EntityPopulationType.Mission && veh != last && veh!=current) + { + // Main.Logger.Debug($"Removing Vehicle {veh.Handle}. Reason:ClearTraffic"); + + veh.Delete(); + } } } } diff --git a/RageCoop.Server/Properties/AssemblyInfo.cs b/RageCoop.Server/Properties/AssemblyInfo.cs index 5d62843..a8c0184 100644 --- a/RageCoop.Server/Properties/AssemblyInfo.cs +++ b/RageCoop.Server/Properties/AssemblyInfo.cs @@ -15,7 +15,7 @@ using System.Resources; [assembly: AssemblyCulture("")] // Version information -[assembly: AssemblyVersion("1.5.2.83")] -[assembly: AssemblyFileVersion("1.5.2.83")] +[assembly: AssemblyVersion("1.5.2.84")] +[assembly: AssemblyFileVersion("1.5.2.84")] [assembly: NeutralResourcesLanguageAttribute( "en-US" )]