Skip to content

Commit

Permalink
Merge pull request #57 from RAGECOOP/dev-nightly
Browse files Browse the repository at this point in the history
Dev nightly
  • Loading branch information
oldnapalm authored Nov 20, 2023
2 parents 39b780e + 8bd6ea1 commit 564d146
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 77 deletions.
17 changes: 16 additions & 1 deletion RageCoop.Client/Menus/Sub/SettingsMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal static class SettingsMenu
private static readonly NativeItem _menuKey = new NativeItem("Menu Key", "The key to open menu", Main.Settings.MenuKey.ToString());
private static readonly NativeItem _passengerKey = new NativeItem("Passenger Key", "The key to enter a vehicle as passenger", Main.Settings.PassengerKey.ToString());
private static readonly NativeItem _vehicleSoftLimit = new NativeItem("Vehicle limit (soft)", "The game won't spawn more NPC traffic if the limit is exceeded. \n-1 for unlimited (not recommended).", Main.Settings.WorldVehicleSoftLimit.ToString());
private static readonly NativeItem _pedSoftLimit = new NativeItem("Ped limit (soft)", "The game won't spawn more NPCs if the limit is exceeded. \n-1 for unlimited (not recommended).", Main.Settings.WorldPedSoftLimit.ToString());

static SettingsMenu()
{
Expand All @@ -37,6 +38,7 @@ static SettingsMenu()
_menuKey.Activated += ChaneMenuKey;
_passengerKey.Activated += ChangePassengerKey;
_vehicleSoftLimit.Activated += VehicleSoftLimitActivated;
_pedSoftLimit.Activated += PedSoftLimitActivated;
_showBlip.Activated += (s, e) =>
{
Main.Settings.ShowPlayerBlip = _showBlip.Checked;
Expand All @@ -55,6 +57,7 @@ static SettingsMenu()
Menu.Add(_menuKey);
Menu.Add(_passengerKey);
Menu.Add(_vehicleSoftLimit);
Menu.Add(_pedSoftLimit);
Menu.Add(_showBlip);
Menu.Add(_showNametag);
}
Expand Down Expand Up @@ -89,7 +92,19 @@ private static void VehicleSoftLimitActivated(object sender, EventArgs e)
Main.Settings.WorldVehicleSoftLimit = int.Parse(
Game.GetUserInput(WindowTitle.EnterMessage20,
Main.Settings.WorldVehicleSoftLimit.ToString(), 20));
_menuKey.AltTitle = Main.Settings.WorldVehicleSoftLimit.ToString();
_vehicleSoftLimit.AltTitle = Main.Settings.WorldVehicleSoftLimit.ToString();
Util.SaveSettings();
}
catch { }
}
private static void PedSoftLimitActivated(object sender, EventArgs e)
{
try
{
Main.Settings.WorldPedSoftLimit = int.Parse(
Game.GetUserInput(WindowTitle.EnterMessage20,
Main.Settings.WorldPedSoftLimit.ToString(), 20));
_pedSoftLimit.AltTitle = Main.Settings.WorldPedSoftLimit.ToString();
Util.SaveSettings();
}
catch { }
Expand Down
20 changes: 12 additions & 8 deletions RageCoop.Client/Networking/Receive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using RageCoop.Client.Menus;
using RageCoop.Core;
using System;
using System.Linq;
using System.Threading;

namespace RageCoop.Client
Expand Down Expand Up @@ -305,12 +306,14 @@ private static void PedSync(Packets.PedSync packet)
SyncedPed c = EntityPool.GetPedByID(packet.ID);
if (c == null)
{
// Main.Logger.Debug($"Creating character for incoming sync:{packet.ID}");
if (EntityPool.allPeds.Length < Main.Settings.GlobalPedSoftLimit || PlayerList.Players.ContainsKey(packet.ID))
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}");
EntityPool.ThreadSafe.Add(c = new SyncedPed(packet.ID));
}
else return;
}
PedDataFlags flags = packet.Flags;
c.ID = packet.ID;
c.OwnerID = packet.OwnerID;
c.Health = packet.Health;
Expand Down Expand Up @@ -356,8 +359,12 @@ private static void VehicleSync(Packets.VehicleSync packet)
SyncedVehicle v = EntityPool.GetVehicleByID(packet.ID);
if (v == null)
{
if (EntityPool.allVehicles.Length < Main.Settings.GlobalVehicleSoftLimit)
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));
}
else return;
}
if (v.IsLocal) { return; }
Expand Down Expand Up @@ -392,15 +399,12 @@ private static void VehicleSync(Packets.VehicleSync packet)
}
private static void ProjectileSync(Packets.ProjectileSync packet)
{

var p = EntityPool.GetProjectileByID(packet.ID);
if (p == null)
{
if (packet.Flags.HasProjDataFlag(ProjectileDataFlags.Exploded)) { return; }
// Main.Logger.Debug($"Creating new projectile: {(WeaponHash)packet.WeaponHash}");
if (EntityPool.allProjectiles.Length < Main.Settings.GlobalProjectileSoftLimit)
EntityPool.ThreadSafe.Add(p = new SyncedProjectile(packet.ID));
else return;
EntityPool.ThreadSafe.Add(p = new SyncedProjectile(packet.ID));
}
p.Flags = packet.Flags;
p.Position = packet.Position;
Expand Down
4 changes: 2 additions & 2 deletions RageCoop.Client/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


// Version information
[assembly: AssemblyVersion("1.5.4.6")]
[assembly: AssemblyFileVersion("1.5.4.6")]
[assembly: AssemblyVersion("1.5.4.7")]
[assembly: AssemblyFileVersion("1.5.4.7")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]

15 changes: 0 additions & 15 deletions RageCoop.Client/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,6 @@ public class Settings
/// </summary>
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>
/// The directory where log and resources downloaded from server will be placed.
/// </summary>
Expand Down
10 changes: 8 additions & 2 deletions RageCoop.Client/Sync/Entities/Ped/SyncedPed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ internal override void Update()
}
}

if (!IsPlayer && Health <= 0 && !MainPed.IsDead)
{
MainPed.Kill();
return;
}

if (Speed >= 4)
{
DisplayInVehicle();
Expand Down Expand Up @@ -205,7 +211,7 @@ private bool CreateCharacter()
MainPed = null;
}

if (PedBlip != null && PedBlip.Exists())
if (PedBlip != null)
{
PedBlip.Delete();
PedBlip = null;
Expand Down Expand Up @@ -420,7 +426,7 @@ private void DisplayOnFoot()
}
_lastIsJumping = false;

if (IsRagdoll || Health == 0)
if (IsRagdoll || (IsPlayer && Health == 0))
{
if (!MainPed.IsRagdoll)
{
Expand Down
47 changes: 11 additions & 36 deletions RageCoop.Client/Sync/Entities/Vehicle/SyncedVehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using RageCoop.Core;
using System;
using System.Collections.Generic;
using System.Linq;

namespace RageCoop.Client
{
Expand Down Expand Up @@ -307,6 +308,16 @@ private Vector3 GetCalibrationRotation()
}
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 = Util.CreateVehicle(Model, Position);
if (!Model.IsInCdImage)
Expand Down Expand Up @@ -337,41 +348,5 @@ private bool CreateVehicle()
Model.MarkAsNoLongerNeeded();
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
}
}
25 changes: 13 additions & 12 deletions RageCoop.Client/Sync/EntityPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void Cleanup(bool keepPlayer = true, bool keepMine = true)
PedsByID.Clear();
PedsByHandle.Clear();

foreach (int id in new List<int>(VehiclesByID.Keys))
foreach (int id in VehiclesByID.Keys.ToArray())
{
if (keepMine && (VehiclesByID[id].OwnerID == Main.LocalPlayerID)) { continue; }
RemoveVehicle(id);
Expand Down Expand Up @@ -359,22 +359,24 @@ public static void DoSync()
lock (PedsLock)
{
AddPlayer();
var mainCharacters = new List<PedHash> { PedHash.Michael, PedHash.Franklin, PedHash.Franklin02, PedHash.Trevor };

foreach (Ped p in allPeds)
{
SyncedPed c = GetPedByHandle(p.Handle);
List<PedHash> mainCharacters = new List<PedHash> { PedHash.Michael, PedHash.Franklin, PedHash.Franklin02, PedHash.Trevor };
if (c == null && p != Game.Player.Character && !mainCharacters.Contains((PedHash)p.Model.Hash))
if (!PedsByHandle.ContainsKey(p.Handle) && 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)
{
p.Delete();
continue;
if (p.PopulationType == EntityPopulationType.RandomAmbient && !p.IsInVehicle())
{
p.Delete();
continue;
}
if (p.PopulationType == EntityPopulationType.RandomScenario) continue;
}
// Main.Logger.Trace($"Creating SyncEntity for ped, handle:{p.Handle}");
c = new SyncedPed(p);

Add(c);
Add(new SyncedPed(p));
}
}
#if BENCHMARK
Expand Down Expand Up @@ -438,10 +440,9 @@ public static void DoSync()
{
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 (type == EntityPopulationType.RandomAmbient || type == EntityPopulationType.RandomParked)
if (veh.PopulationType == EntityPopulationType.RandomAmbient || veh.PopulationType == EntityPopulationType.RandomParked)
{
foreach (var p in veh.Occupants)
{
Expand Down
2 changes: 1 addition & 1 deletion RageCoop.Client/WorldThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private static void ChangeTraffic(bool enable)
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.Kill();
ped.Delete();
Expand Down

0 comments on commit 564d146

Please sign in to comment.