Use tuple to store vehicle colors

Array allocation is somewhat expensive
This commit is contained in:
Sardelka9515
2023-03-20 17:02:56 +08:00
parent e6c6e5ceff
commit 7cd0fd22af
5 changed files with 9 additions and 13 deletions

View File

@ -328,7 +328,6 @@ namespace RageCoop.Client
v.OwnerID = packet.OwnerID;
v.Flags = packet.Flags;
v.Position = packet.Position;
v.LastQuaternion = v.Quaternion;
v.Quaternion = packet.Quaternion;
v.SteeringAngle = packet.SteeringAngle;
v.ThrottlePower = packet.ThrottlePower;

View File

@ -126,7 +126,7 @@ namespace RageCoop.Client
}
packet.Flags |= VehicleDataFlags.IsFullSync;
packet.Colors = new[] { primaryColor, secondaryColor };
packet.Colors = (primaryColor, secondaryColor);
packet.DamageModel = veh.GetVehicleDamageModel();
packet.LandingGear = veh.IsAircraft ? (byte)veh.LandingGearState : (byte)0;
packet.RoofState = (byte)veh.RoofState;

View File

@ -22,7 +22,7 @@ namespace RageCoop.Client
internal byte LandingGear { get; set; }
internal VehicleRoofState RoofState { get; set; }
internal VehicleDamageModel DamageModel { get; set; }
internal byte[] Colors { get; set; }
internal (byte, byte) Colors { get; set; }
internal Dictionary<int, int> Mods { get; set; }
internal float EngineHealth { get; set; }
internal VehicleLockStatus LockStatus { get; set; }
@ -65,13 +65,12 @@ namespace RageCoop.Client
#region PRIVATE
private byte[] _lastVehicleColors = { 0, 0 };
private (byte, byte) _lastVehicleColors;
private Dictionary<int, int> _lastVehicleMods = new();
private bool _lastHornActive;
private bool _lastTransformed;
internal int _lastLivery = -1;
private Vector3 _predictedPosition;
internal Quaternion LastQuaternion;
#endregion

View File

@ -123,9 +123,9 @@ namespace RageCoop.Client
if (LastFullSynced >= LastUpdated)
{
if (Flags.HasVehFlag(VehicleDataFlags.Repaired)) MainVehicle.Repair();
if (Colors != null && Colors != _lastVehicleColors)
if (Colors != _lastVehicleColors)
{
Call(SET_VEHICLE_COLOURS, MainVehicle, Colors[0], Colors[1]);
Call(SET_VEHICLE_COLOURS, MainVehicle, Colors.Item1, Colors.Item2);
_lastVehicleColors = Colors;
}

View File

@ -57,8 +57,8 @@ namespace RageCoop.Core
if (Flags.HasVehFlag(VehicleDataFlags.HasRoof)) m.Write(RoofState);
// Write vehicle colors
m.Write(Colors[0]);
m.Write(Colors[1]);
m.Write(Colors.Item1);
m.Write(Colors.Item2);
// Write vehicle mods
// Write the count of mods
@ -136,9 +136,7 @@ namespace RageCoop.Core
if (Flags.HasVehFlag(VehicleDataFlags.HasRoof)) RoofState = m.ReadByte();
// Read vehicle colors
var vehColor1 = m.ReadByte();
var vehColor2 = m.ReadByte();
Colors = new[] { vehColor1, vehColor2 };
Colors = (m.ReadByte(), m.ReadByte());
// Read vehicle mods
// Create new Dictionary
@ -183,7 +181,7 @@ namespace RageCoop.Core
public float EngineHealth { get; set; }
public byte[] Colors { get; set; }
public (byte, byte) Colors { get; set; }
public Dictionary<int, int> Mods { get; set; }