Fix disable traffic not always work
This commit is contained in:
@ -335,6 +335,7 @@ namespace RageCoop.Client
|
|||||||
c.Flags=packet.Flags;
|
c.Flags=packet.Flags;
|
||||||
c.Heading=packet.Heading;
|
c.Heading=packet.Heading;
|
||||||
c.Position = packet.Position;
|
c.Position = packet.Position;
|
||||||
|
c.LastSyncedStopWatch.Restart();
|
||||||
if (c.IsRagdoll)
|
if (c.IsRagdoll)
|
||||||
{
|
{
|
||||||
c.HeadPosition=packet.HeadPosition;
|
c.HeadPosition=packet.HeadPosition;
|
||||||
|
@ -16,7 +16,7 @@ using System.Resources;
|
|||||||
|
|
||||||
|
|
||||||
// Version informationr(
|
// Version informationr(
|
||||||
[assembly: AssemblyVersion("1.5.2.104")]
|
[assembly: AssemblyVersion("1.5.2.111")]
|
||||||
[assembly: AssemblyFileVersion("1.5.2.104")]
|
[assembly: AssemblyFileVersion("1.5.2.111")]
|
||||||
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
|
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
|
||||||
|
|
||||||
|
@ -684,10 +684,11 @@ namespace RageCoop.Client
|
|||||||
private void SmoothTransition()
|
private void SmoothTransition()
|
||||||
{
|
{
|
||||||
var localRagdoll = MainPed.IsRagdoll;
|
var localRagdoll = MainPed.IsRagdoll;
|
||||||
var dist = Position.DistanceTo(MainPed.ReadPosition());
|
var predicted = Predict(Position);
|
||||||
if (dist>3)
|
var dist = predicted.DistanceTo(MainPed.ReadPosition());
|
||||||
|
if (IsOff(dist))
|
||||||
{
|
{
|
||||||
MainPed.PositionNoOffset=Position;
|
MainPed.PositionNoOffset= predicted;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(localRagdoll || MainPed.IsDead))
|
if (!(localRagdoll || MainPed.IsDead))
|
||||||
@ -696,12 +697,12 @@ namespace RageCoop.Client
|
|||||||
{
|
{
|
||||||
var cur=MainPed.Heading;
|
var cur=MainPed.Heading;
|
||||||
var diff=Heading-cur;
|
var diff=Heading-cur;
|
||||||
if (diff > 180) { diff = diff - 360; }
|
if (diff > 180) { diff -= 360; }
|
||||||
else if (diff < -180) { diff = 360 + diff; }
|
else if (diff < -180) { diff += 360; }
|
||||||
|
|
||||||
MainPed.Heading=cur+diff/2;
|
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)
|
else if (Main.Ticked-_lastRagdollTime<10)
|
||||||
{
|
{
|
||||||
@ -718,25 +719,25 @@ namespace RageCoop.Client
|
|||||||
|
|
||||||
helper.EqualizeAmount = 1;
|
helper.EqualizeAmount = 1;
|
||||||
helper.PartIndex=20;
|
helper.PartIndex=20;
|
||||||
helper.Impulse=20*(HeadPosition-head.Position);
|
helper.Impulse=20*(Predict(HeadPosition) -head.Position);
|
||||||
helper.Start();
|
helper.Start();
|
||||||
helper.Stop();
|
helper.Stop();
|
||||||
|
|
||||||
helper.EqualizeAmount = 1;
|
helper.EqualizeAmount = 1;
|
||||||
helper.PartIndex=6;
|
helper.PartIndex=6;
|
||||||
helper.Impulse=20*(RightFootPosition-rightFoot.Position);
|
helper.Impulse=20*(Predict(RightFootPosition) -rightFoot.Position);
|
||||||
helper.Start();
|
helper.Start();
|
||||||
helper.Stop();
|
helper.Stop();
|
||||||
|
|
||||||
helper.EqualizeAmount = 1;
|
helper.EqualizeAmount = 1;
|
||||||
helper.PartIndex=3;
|
helper.PartIndex=3;
|
||||||
helper.Impulse=20*(LeftFootPosition-leftFoot.Position);
|
helper.Impulse=20*(Predict(LeftFootPosition) -leftFoot.Position);
|
||||||
helper.Start();
|
helper.Start();
|
||||||
helper.Stop();
|
helper.Stop();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MainPed.Velocity=Velocity+5*dist*(Position-MainPed.ReadPosition());
|
MainPed.Velocity=Velocity+5*dist*(predicted-MainPed.ReadPosition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,10 +89,27 @@ namespace RageCoop.Client
|
|||||||
internal Vector3 Rotation { get; set; }
|
internal Vector3 Rotation { get; set; }
|
||||||
internal Quaternion Quaternion { get; set; }
|
internal Quaternion Quaternion { get; set; }
|
||||||
internal Vector3 Velocity { get; set; }
|
internal Vector3 Velocity { get; set; }
|
||||||
|
public Stopwatch LastSyncedStopWatch = new Stopwatch();
|
||||||
internal abstract void Update();
|
internal abstract void Update();
|
||||||
internal void PauseUpdate(ulong frames)
|
internal void PauseUpdate(ulong frames)
|
||||||
{
|
{
|
||||||
LastUpdated=Main.Ticked+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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ using GTA.Native;
|
|||||||
namespace RageCoop.Client{
|
namespace RageCoop.Client{
|
||||||
public partial class SyncedVehicle{
|
public partial class SyncedVehicle{
|
||||||
public Vehicle MainVehicle { get; internal set; }
|
public Vehicle MainVehicle { get; internal set; }
|
||||||
public Stopwatch LastSyncedStopWatch = new Stopwatch();
|
|
||||||
|
|
||||||
|
|
||||||
#region -- SYNC DATA --
|
#region -- SYNC DATA --
|
||||||
|
@ -260,8 +260,7 @@ namespace RageCoop.Client
|
|||||||
}
|
}
|
||||||
void DisplayVehicle()
|
void DisplayVehicle()
|
||||||
{
|
{
|
||||||
_elapsed = Owner.PacketTravelTime + 0.001f * LastSyncedStopWatch.ElapsedMilliseconds;
|
_predictedPosition = Predict(Position);
|
||||||
_predictedPosition = Position + _elapsed * Velocity;
|
|
||||||
var current = MainVehicle.ReadPosition();
|
var current = MainVehicle.ReadPosition();
|
||||||
var dist = current.DistanceTo(_predictedPosition);
|
var dist = current.DistanceTo(_predictedPosition);
|
||||||
var cali = dist * (_predictedPosition - current);
|
var cali = dist * (_predictedPosition - current);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using GTA;
|
using GTA;
|
||||||
using GTA.Native;
|
using GTA.Native;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace RageCoop.Client
|
namespace RageCoop.Client
|
||||||
{
|
{
|
||||||
@ -9,7 +11,6 @@ namespace RageCoop.Client
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class WorldThread : Script
|
public class WorldThread : Script
|
||||||
{
|
{
|
||||||
private static bool _lastDisableTraffic = false;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Don't use it!
|
/// Don't use it!
|
||||||
@ -19,15 +20,30 @@ namespace RageCoop.Client
|
|||||||
Tick += OnTick;
|
Tick += OnTick;
|
||||||
Aborted += (sender, e) =>
|
Aborted += (sender, e) =>
|
||||||
{
|
{
|
||||||
if (_lastDisableTraffic)
|
ChangeTraffic(true);
|
||||||
{
|
|
||||||
Traffic(true);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Thread.Sleep(5000);
|
||||||
|
Main.QueueAction(() => { ChangeTraffic(_trafficEnabled); });
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
static bool _trafficEnabled;
|
||||||
private void OnTick(object sender, EventArgs e)
|
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)
|
if (Game.IsLoading || !Networking.IsOnServer)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -39,13 +55,16 @@ namespace RageCoop.Client
|
|||||||
{
|
{
|
||||||
Game.DisableControlThisFrame(Control.FrontendPauseAlternate);
|
Game.DisableControlThisFrame(Control.FrontendPauseAlternate);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets a value that determines how aggressive the ocean waves will be.
|
// 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.
|
// 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
|
Function.Call(Hash.SET_DEEP_OCEAN_SCALER, 0.0f); // Works only ~200 meters around the player
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Traffic(bool enable)
|
public static void Traffic(bool enable)
|
||||||
|
{
|
||||||
|
ChangeTraffic(enable);
|
||||||
|
_trafficEnabled = enable;
|
||||||
|
}
|
||||||
|
private static void ChangeTraffic(bool enable)
|
||||||
{
|
{
|
||||||
if (enable)
|
if (enable)
|
||||||
{
|
{
|
||||||
@ -78,35 +97,63 @@ namespace RageCoop.Client
|
|||||||
Function.Call(Hash.SET_DISTANT_CARS_ENABLED, false);
|
Function.Call(Hash.SET_DISTANT_CARS_ENABLED, false);
|
||||||
Function.Call(Hash.DISABLE_VEHICLE_DISTANTLIGHTS, true);
|
Function.Call(Hash.DISABLE_VEHICLE_DISTANTLIGHTS, true);
|
||||||
|
|
||||||
|
if (Networking.IsOnServer)
|
||||||
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");
|
foreach (Ped ped in World.GetAllPeds())
|
||||||
ped.CurrentVehicle?.Delete();
|
{
|
||||||
ped.Kill();
|
SyncedPed c = EntityPool.GetPedByHandle(ped.Handle);
|
||||||
ped.Delete();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
foreach (Vehicle veh in World.GetAllVehicles())
|
|
||||||
{
|
{
|
||||||
SyncedVehicle v = veh.GetSyncEntity();
|
foreach (Ped ped in World.GetAllPeds())
|
||||||
if (v.MainVehicle==Game.Player.LastVehicle)
|
|
||||||
{
|
{
|
||||||
// Don't delete player's vehicle
|
if ((ped != Game.Player.Character) && (ped.PopulationType != EntityPopulationType.Mission))
|
||||||
continue;
|
{
|
||||||
}
|
// Main.Logger.Trace($"Removing ped {ped.Handle}. Reason:RemoveTraffic");
|
||||||
if ((v== null) || (v.IsLocal&&veh.PopulationType!=EntityPopulationType.Mission))
|
ped.CurrentVehicle?.Delete();
|
||||||
{
|
ped.Kill();
|
||||||
// Main.Logger.Debug($"Removing Vehicle {veh.Handle}. Reason:ClearTraffic");
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ using System.Resources;
|
|||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
// Version information
|
// Version information
|
||||||
[assembly: AssemblyVersion("1.5.2.83")]
|
[assembly: AssemblyVersion("1.5.2.84")]
|
||||||
[assembly: AssemblyFileVersion("1.5.2.83")]
|
[assembly: AssemblyFileVersion("1.5.2.84")]
|
||||||
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
|
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user