Skip to content

Commit

Permalink
update runtime submodule. apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDutchDev committed Dec 26, 2024
1 parent 67969a6 commit a84334e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 71 deletions.
32 changes: 12 additions & 20 deletions api/AltV.Net.Async/Elements/Entities/AsyncPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,18 @@ public long DiscordId
}
}
}

public List<StreamedEntityDistance> StreamedEntityDistances => GetStreamedEntities();

public List<StreamedEntityDistance> StreamedEntities
{
get
{
lock (Player)
{
if (!AsyncContext.CheckIfExistsOrCachedNullable(Player)) return default;
return Player.StreamedEntities;
}
}
}

public ushort Health
{
Expand Down Expand Up @@ -956,24 +966,6 @@ public WeaponData[] GetWeapons()
}
}

public uint GetStreamedEntitiesCount()
{
lock (Player)
{
if (!AsyncContext.CheckIfExistsNullable(Player)) return default;
return Player.GetStreamedEntitiesCount();
}
}

public List<StreamedEntityDistance> GetStreamedEntities()
{
lock (Player)
{
if (!AsyncContext.CheckIfExistsNullable(Player)) return default;
return Player.GetStreamedEntities();
}
}

public void ClearBloodDamage()
{
lock (Player)
Expand Down
14 changes: 1 addition & 13 deletions api/AltV.Net/Elements/Entities/IPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public interface IPlayer : ISharedPlayer, IEntity

long DiscordId { get; }

List<StreamedEntityDistance> StreamedEntityDistances { get; }
List<StreamedEntityDistance> StreamedEntities { get; }

/// <summary>
/// Gets and Sets the players health
Expand Down Expand Up @@ -256,18 +256,6 @@ void SetDateTime(int day, int month, int year, int hour,
/// <returns></returns>
WeaponData[] GetWeapons();

/// <summary>
/// Returns the amount of streamed entities
/// </summary>
/// <returns></returns>
uint GetStreamedEntitiesCount();

/// <summary>
/// Returns a list of streamed entities
/// </summary>
/// <returns></returns>
List<StreamedEntityDistance> GetStreamedEntities();

/// <summary>
/// Clears the blood damage of the player
/// </summary>
Expand Down
68 changes: 30 additions & 38 deletions api/AltV.Net/Elements/Entities/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,36 @@ public long DiscordId
}
}

public List<StreamedEntityDistance> StreamedEntityDistances => GetStreamedEntities();
public List<StreamedEntityDistance> StreamedEntities
{
get
{
unsafe
{
CheckIfEntityExistsOrCached();

var entitiesCount = Core.Library.Server.Player_GetStreamedEntitiesCount(PlayerNativePointer);

var pointers = IntPtr.Zero;
var distances = new ushort[entitiesCount];
var types = new byte[entitiesCount];
Core.Library.Server.Player_GetStreamedEntities(PlayerNativePointer, &pointers, types, distances, entitiesCount);

var entityPtrArray = new IntPtr[entitiesCount];
Marshal.Copy(pointers, entityPtrArray, 0, (int) entitiesCount);
Core.Library.Shared.FreeVoidPointerArray(pointers);

var streamedEntities = new List<StreamedEntityDistance>((int) entitiesCount);
for (ulong i = 0; i < entitiesCount; i++)
{
var entity = (IEntity) Core.PoolManager.GetOrCreate(Core, entityPtrArray[i], (BaseObjectType) types[i]);
streamedEntities.Add(new StreamedEntityDistance(entity, distances[i]));
}

return streamedEntities;
}
}
}

public ushort Health
{
Expand Down Expand Up @@ -1259,43 +1288,6 @@ public WeaponData[] GetWeapons()
}
}

public uint GetStreamedEntitiesCount()
{
unsafe
{
CheckIfEntityExists();
return Core.Library.Server.Player_GetStreamedEntitiesCount(PlayerNativePointer);
}
}

public List<StreamedEntityDistance> GetStreamedEntities()
{
unsafe
{
CheckIfEntityExists();

var entitiesCount = Core.Library.Server.Player_GetStreamedEntitiesCount(PlayerNativePointer);

var pointers = IntPtr.Zero;
var distances = new ushort[entitiesCount];
var types = new byte[entitiesCount];
Core.Library.Server.Player_GetStreamedEntities(PlayerNativePointer, &pointers, distances, types, entitiesCount);

var entityPtrArray = new IntPtr[entitiesCount];
Marshal.Copy(pointers, entityPtrArray, 0, (int) entitiesCount);
Core.Library.Shared.FreeVoidPointerArray(pointers);

var streamedEntities = new List<StreamedEntityDistance>((int) entitiesCount);
for (ulong i = 0; i < entitiesCount; i++)
{
var entity = (IEntity) Core.PoolManager.GetOrCreate(Core, entityPtrArray[i], (BaseObjectType) types[i]);
streamedEntities.Add(new StreamedEntityDistance(entity, distances[i]));
}

return streamedEntities;
}
}

public void Kick(string reason)
{
unsafe
Expand Down

0 comments on commit a84334e

Please sign in to comment.