Fix disable traffic not always work
This commit is contained in:
@ -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;
|
||||
|
@ -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" )]
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 --
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
/// </summary>
|
||||
public class WorldThread : Script
|
||||
{
|
||||
private static bool _lastDisableTraffic = false;
|
||||
|
||||
/// <summary>
|
||||
/// 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,6 +97,8 @@ namespace RageCoop.Client
|
||||
Function.Call(Hash.SET_DISTANT_CARS_ENABLED, false);
|
||||
Function.Call(Hash.DISABLE_VEHICLE_DISTANTLIGHTS, true);
|
||||
|
||||
if (Networking.IsOnServer)
|
||||
{
|
||||
|
||||
foreach (Ped ped in World.GetAllPeds())
|
||||
{
|
||||
@ -110,6 +131,32 @@ namespace RageCoop.Client
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Ped ped in World.GetAllPeds())
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
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("")]
|
||||
|
||||
// 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" )]
|
||||
|
||||
|
Reference in New Issue
Block a user