Remove global limits

world limits will be applied to all players instead
Fix explosions when remote and local vehicles exist at same position
Fix "floating corpses" issue when remote NPCs are killed
This commit is contained in:
oldnapalm
2023-11-20 11:32:18 -03:00
parent 3c7f16f7a4
commit 8bd6ea15a3
7 changed files with 43 additions and 73 deletions

View File

@ -305,13 +305,15 @@ namespace RageCoop.Client
{ {
SyncedPed c = EntityPool.GetPedByID(packet.ID); SyncedPed c = EntityPool.GetPedByID(packet.ID);
if (c == null) if (c == null)
{
if (EntityPool.PedsByID.Count(x => x.Value.OwnerID == packet.OwnerID) < Main.Settings.WorldPedSoftLimit / PlayerList.Players.Count ||
EntityPool.VehiclesByID.Any(x => x.Value.Position.DistanceTo(packet.Position) < 2) || packet.ID == packet.OwnerID)
{ {
// Main.Logger.Debug($"Creating character for incoming sync:{packet.ID}"); // Main.Logger.Debug($"Creating character for incoming sync:{packet.ID}");
if (EntityPool.allPeds.Length < Main.Settings.GlobalPedSoftLimit + PlayerList.Players.Count || PlayerList.Players.ContainsKey(packet.ID))
EntityPool.ThreadSafe.Add(c = new SyncedPed(packet.ID)); EntityPool.ThreadSafe.Add(c = new SyncedPed(packet.ID));
}
else return; else return;
} }
PedDataFlags flags = packet.Flags;
c.ID = packet.ID; c.ID = packet.ID;
c.OwnerID = packet.OwnerID; c.OwnerID = packet.OwnerID;
c.Health = packet.Health; c.Health = packet.Health;
@ -357,8 +359,12 @@ namespace RageCoop.Client
SyncedVehicle v = EntityPool.GetVehicleByID(packet.ID); SyncedVehicle v = EntityPool.GetVehicleByID(packet.ID);
if (v == null) if (v == null)
{ {
if (EntityPool.allVehicles.Length < Main.Settings.GlobalVehicleSoftLimit || EntityPool.PedsByID.Any(x => x.Value.Position.DistanceTo(packet.Position) < 2f)) if (EntityPool.VehiclesByID.Count(x => x.Value.OwnerID == packet.OwnerID) < Main.Settings.WorldVehicleSoftLimit / PlayerList.Players.Count ||
EntityPool.PedsByID.Any(x => x.Value.VehicleID == packet.ID || x.Value.Position.DistanceTo(packet.Position) < 2))
{
// Main.Logger.Debug($"Creating vehicle for incoming sync:{packet.ID}");
EntityPool.ThreadSafe.Add(v = new SyncedVehicle(packet.ID)); EntityPool.ThreadSafe.Add(v = new SyncedVehicle(packet.ID));
}
else return; else return;
} }
if (v.IsLocal) { return; } if (v.IsLocal) { return; }
@ -393,15 +399,12 @@ namespace RageCoop.Client
} }
private static void ProjectileSync(Packets.ProjectileSync packet) private static void ProjectileSync(Packets.ProjectileSync packet)
{ {
var p = EntityPool.GetProjectileByID(packet.ID); var p = EntityPool.GetProjectileByID(packet.ID);
if (p == null) if (p == null)
{ {
if (packet.Flags.HasProjDataFlag(ProjectileDataFlags.Exploded)) { return; } if (packet.Flags.HasProjDataFlag(ProjectileDataFlags.Exploded)) { return; }
// Main.Logger.Debug($"Creating new projectile: {(WeaponHash)packet.WeaponHash}"); // Main.Logger.Debug($"Creating new projectile: {(WeaponHash)packet.WeaponHash}");
if (EntityPool.allProjectiles.Length < Main.Settings.GlobalProjectileSoftLimit)
EntityPool.ThreadSafe.Add(p = new SyncedProjectile(packet.ID)); EntityPool.ThreadSafe.Add(p = new SyncedProjectile(packet.ID));
else return;
} }
p.Flags = packet.Flags; p.Flags = packet.Flags;
p.Position = packet.Position; p.Position = packet.Position;

View File

@ -16,7 +16,7 @@ using System.Resources;
// Version information // Version information
[assembly: AssemblyVersion("1.5.4.6")] [assembly: AssemblyVersion("1.5.4.7")]
[assembly: AssemblyFileVersion("1.5.4.6")] [assembly: AssemblyFileVersion("1.5.4.7")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )] [assembly: NeutralResourcesLanguageAttribute( "en-US" )]

View File

@ -68,21 +68,6 @@ namespace RageCoop.Client
/// </summary> /// </summary>
public int WorldPedSoftLimit { get; set; } = 30; public int WorldPedSoftLimit { get; set; } = 30;
/// <summary>
/// The mod won't sync more vehicles if the limit is exceeded.
/// </summary>
public int GlobalVehicleSoftLimit { get; set; } = 100;
/// <summary>
/// The mod won't sync more peds if the limit is exceeded.
/// </summary>
public int GlobalPedSoftLimit { get; set; } = 100;
/// <summary>
/// The mod won't sync more projectiles if the limit is exceeded.
/// </summary>
public int GlobalProjectileSoftLimit { get; set; } = 100;
/// <summary> /// <summary>
/// The directory where log and resources downloaded from server will be placed. /// The directory where log and resources downloaded from server will be placed.
/// </summary> /// </summary>

View File

@ -141,6 +141,12 @@ namespace RageCoop.Client
} }
} }
if (!IsPlayer && Health <= 0 && !MainPed.IsDead)
{
MainPed.Kill();
return;
}
if (Speed >= 4) if (Speed >= 4)
{ {
DisplayInVehicle(); DisplayInVehicle();
@ -420,7 +426,7 @@ namespace RageCoop.Client
} }
_lastIsJumping = false; _lastIsJumping = false;
if (IsRagdoll || Health == 0) if (IsRagdoll || (IsPlayer && Health == 0))
{ {
if (!MainPed.IsRagdoll) if (!MainPed.IsRagdoll)
{ {

View File

@ -4,6 +4,7 @@ using GTA.Native;
using RageCoop.Core; using RageCoop.Core;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace RageCoop.Client namespace RageCoop.Client
{ {
@ -307,6 +308,16 @@ namespace RageCoop.Client
} }
private bool CreateVehicle() private bool CreateVehicle()
{ {
var existing = World.GetNearbyVehicles(Position, 2).ToList().FirstOrDefault();
if (existing != null && existing != MainVehicle)
{
if (EntityPool.VehiclesByHandle.ContainsKey(existing.Handle))
{
EntityPool.RemoveVehicle(ID);
return false;
}
existing.Delete();
}
MainVehicle?.Delete(); MainVehicle?.Delete();
MainVehicle = Util.CreateVehicle(Model, Position); MainVehicle = Util.CreateVehicle(Model, Position);
if (!Model.IsInCdImage) if (!Model.IsInCdImage)
@ -337,41 +348,5 @@ namespace RageCoop.Client
Model.MarkAsNoLongerNeeded(); Model.MarkAsNoLongerNeeded();
return true; return true;
} }
#region -- PEDALING --
/*
* Thanks to @oldnapalm.
*/
private string PedalingAnimDict()
{
switch ((VehicleHash)Model)
{
case VehicleHash.Bmx:
return "veh@bicycle@bmx@front@base";
case VehicleHash.Cruiser:
return "veh@bicycle@cruiserfront@base";
case VehicleHash.Scorcher:
return "veh@bicycle@mountainfront@base";
default:
return "veh@bicycle@roadfront@base";
}
}
private string PedalingAnimName(bool fast)
{
return fast ? "fast_pedal_char" : "cruise_pedal_char";
}
private void StartPedalingAnim(bool fast)
{
MainVehicle.Driver?.Task.PlayAnimation(PedalingAnimDict(), PedalingAnimName(fast), 8.0f, -8.0f, -1, AnimationFlags.Loop | AnimationFlags.Secondary, 1.0f);
}
private void StopPedalingAnim(bool fast)
{
MainVehicle.Driver.Task.ClearAnimation(PedalingAnimDict(), PedalingAnimName(fast));
}
#endregion
} }
} }

View File

@ -363,18 +363,20 @@ namespace RageCoop.Client
foreach (Ped p in allPeds) foreach (Ped p in allPeds)
{ {
SyncedPed c = GetPedByHandle(p.Handle); if (!PedsByHandle.ContainsKey(p.Handle) && p != Game.Player.Character && !mainCharacters.Contains((PedHash)p.Model.Hash))
if (c == null && p != Game.Player.Character && !mainCharacters.Contains((PedHash)p.Model.Hash))
{ {
if (allPeds.Length > Main.Settings.WorldPedSoftLimit && p.PopulationType == EntityPopulationType.RandomAmbient && !p.IsInVehicle()) if (PedsByID.Count(x => x.Value.IsLocal) > Main.Settings.WorldPedSoftLimit)
{
if (p.PopulationType == EntityPopulationType.RandomAmbient && !p.IsInVehicle())
{ {
p.Delete(); p.Delete();
continue; continue;
} }
if (p.PopulationType == EntityPopulationType.RandomScenario) continue;
}
// Main.Logger.Trace($"Creating SyncEntity for ped, handle:{p.Handle}"); // Main.Logger.Trace($"Creating SyncEntity for ped, handle:{p.Handle}");
c = new SyncedPed(p);
Add(c); Add(new SyncedPed(p));
} }
} }
#if BENCHMARK #if BENCHMARK
@ -438,10 +440,9 @@ namespace RageCoop.Client
{ {
if (!VehiclesByHandle.ContainsKey(veh.Handle)) if (!VehiclesByHandle.ContainsKey(veh.Handle))
{ {
if (allVehicles.Length > Main.Settings.WorldVehicleSoftLimit) if (VehiclesByID.Count(x => x.Value.IsLocal) > Main.Settings.WorldVehicleSoftLimit)
{ {
var type = veh.PopulationType; if (veh.PopulationType == EntityPopulationType.RandomAmbient || veh.PopulationType == EntityPopulationType.RandomParked)
if (type == EntityPopulationType.RandomAmbient || type == EntityPopulationType.RandomParked)
{ {
foreach (var p in veh.Occupants) foreach (var p in veh.Occupants)
{ {

View File

@ -120,7 +120,7 @@ namespace RageCoop.Client
if ((c == null) || (c.IsLocal && (ped.Handle != Game.Player.Character.Handle) && ped.PopulationType != EntityPopulationType.Mission)) if ((c == null) || (c.IsLocal && (ped.Handle != Game.Player.Character.Handle) && ped.PopulationType != EntityPopulationType.Mission))
{ {
Main.Logger.Trace($"Removing ped {ped.Handle}. Reason:RemoveTraffic"); // Main.Logger.Trace($"Removing ped {ped.Handle}. Reason:RemoveTraffic");
ped.CurrentVehicle?.Delete(); ped.CurrentVehicle?.Delete();
ped.Kill(); ped.Kill();
ped.Delete(); ped.Delete();