Don't use dictionary to store vehicle mods
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using GTA;
|
using GTA;
|
||||||
using GTA.Math;
|
using GTA.Math;
|
||||||
@ -23,7 +24,7 @@ namespace RageCoop.Client
|
|||||||
internal VehicleRoofState RoofState { get; set; }
|
internal VehicleRoofState RoofState { get; set; }
|
||||||
internal VehicleDamageModel DamageModel { get; set; }
|
internal VehicleDamageModel DamageModel { get; set; }
|
||||||
internal (byte, byte) Colors { get; set; }
|
internal (byte, byte) Colors { get; set; }
|
||||||
internal Dictionary<int, int> Mods { get; set; }
|
internal (int, int)[] Mods { get; set; }
|
||||||
internal float EngineHealth { get; set; }
|
internal float EngineHealth { get; set; }
|
||||||
internal VehicleLockStatus LockStatus { get; set; }
|
internal VehicleLockStatus LockStatus { get; set; }
|
||||||
internal byte RadioStation = 255;
|
internal byte RadioStation = 255;
|
||||||
@ -66,7 +67,7 @@ namespace RageCoop.Client
|
|||||||
#region PRIVATE
|
#region PRIVATE
|
||||||
|
|
||||||
private (byte, byte) _lastVehicleColors;
|
private (byte, byte) _lastVehicleColors;
|
||||||
private Dictionary<int, int> _lastVehicleMods = new();
|
private (int, int)[] _lastVehicleMods = Array.Empty<(int, int)>();
|
||||||
private bool _lastHornActive;
|
private bool _lastHornActive;
|
||||||
private bool _lastTransformed;
|
private bool _lastTransformed;
|
||||||
internal int _lastLivery = -1;
|
internal int _lastLivery = -1;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using GTA;
|
using GTA;
|
||||||
using GTA.Math;
|
using GTA.Math;
|
||||||
using GTA.Native;
|
using GTA.Native;
|
||||||
@ -131,11 +132,11 @@ namespace RageCoop.Client
|
|||||||
}
|
}
|
||||||
|
|
||||||
MainVehicle.EngineHealth = EngineHealth;
|
MainVehicle.EngineHealth = EngineHealth;
|
||||||
if (Mods != null && !Mods.Compare(_lastVehicleMods))
|
if (Mods != null && !Mods.SequenceEqual(_lastVehicleMods))
|
||||||
{
|
{
|
||||||
Call(SET_VEHICLE_MOD_KIT, MainVehicle, 0);
|
Call(SET_VEHICLE_MOD_KIT, MainVehicle, 0);
|
||||||
|
|
||||||
foreach (var mod in Mods) MainVehicle.Mods[(VehicleModType)mod.Key].Index = mod.Value;
|
foreach (var mod in Mods) MainVehicle.Mods[(VehicleModType)mod.Item1].Index = mod.Item2;
|
||||||
|
|
||||||
_lastVehicleMods = Mods;
|
_lastVehicleMods = Mods;
|
||||||
}
|
}
|
||||||
|
@ -47,10 +47,14 @@ namespace RageCoop.Client
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<int, int> GetVehicleMods(this VehicleModCollection mods)
|
public static (int, int)[] GetVehicleMods(this VehicleModCollection mods)
|
||||||
{
|
{
|
||||||
var result = new Dictionary<int, int>();
|
var modsArr = mods.ToArray();
|
||||||
foreach (var mod in mods.ToArray()) result.Add((int)mod.Type, mod.Index);
|
var result = new (int, int)[modsArr.Length];
|
||||||
|
for (int i = 0; i < modsArr.Length; i++)
|
||||||
|
{
|
||||||
|
result[i] = ((int)modsArr[i].Type, modsArr[i].Index);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,13 +62,13 @@ namespace RageCoop.Core
|
|||||||
|
|
||||||
// Write vehicle mods
|
// Write vehicle mods
|
||||||
// Write the count of mods
|
// Write the count of mods
|
||||||
m.Write((short)Mods.Count);
|
m.Write((short)Mods.Length);
|
||||||
// Loop the dictionary and add the values
|
// Loop the dictionary and add the values
|
||||||
foreach (var mod in Mods)
|
foreach (var mod in Mods)
|
||||||
{
|
{
|
||||||
// Write the mod value
|
// Write the mod value
|
||||||
m.Write(mod.Key);
|
m.Write(mod.Item1);
|
||||||
m.Write(mod.Value);
|
m.Write(mod.Item2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DamageModel.Equals(default(VehicleDamageModel)))
|
if (!DamageModel.Equals(default(VehicleDamageModel)))
|
||||||
@ -140,13 +140,13 @@ namespace RageCoop.Core
|
|||||||
|
|
||||||
// Read vehicle mods
|
// Read vehicle mods
|
||||||
// Create new Dictionary
|
// Create new Dictionary
|
||||||
Mods = new Dictionary<int, int>();
|
|
||||||
// Read count of mods
|
// Read count of mods
|
||||||
var vehModCount = m.ReadInt16();
|
var vehModCount = m.ReadInt16();
|
||||||
|
Mods = new (int, int)[vehModCount];
|
||||||
// Loop
|
// Loop
|
||||||
for (var i = 0; i < vehModCount; i++)
|
for (var i = 0; i < vehModCount; i++)
|
||||||
// Read the mod value
|
// Read the mod value
|
||||||
Mods.Add(m.ReadInt32(), m.ReadInt32());
|
Mods[i] = (m.ReadInt32(), m.ReadInt32());
|
||||||
|
|
||||||
if (m.ReadBoolean())
|
if (m.ReadBoolean())
|
||||||
// Read vehicle damage model
|
// Read vehicle damage model
|
||||||
@ -183,7 +183,7 @@ namespace RageCoop.Core
|
|||||||
|
|
||||||
public (byte, byte) Colors { get; set; }
|
public (byte, byte) Colors { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, int> Mods { get; set; }
|
public (int, int)[] Mods { get; set; }
|
||||||
|
|
||||||
public VehicleDamageModel DamageModel { get; set; }
|
public VehicleDamageModel DamageModel { get; set; }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user