Skip to content

Commit

Permalink
feat(server): Add "Add" to poolmanager
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Sep 15, 2024
1 parent 0048f55 commit 3649627
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 82 deletions.
104 changes: 104 additions & 0 deletions api/AltV.Net/Alt.Pools.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AltV.Net.Elements.Entities;
using AltV.Net.Elements.Pools;

namespace AltV.Net;

public partial class Alt
{
public static void AddToPool(IBaseObject baseObject) => CoreImpl.PoolManager.Add(baseObject);

public static IReadOnlyCollection<IPlayer> GetAllPlayers() => CoreImpl.PoolManager.Player.GetAllEntities();

public static IReadOnlyCollection<IVehicle> GetAllVehicles() => CoreImpl.PoolManager.Vehicle.GetAllEntities();

public static IReadOnlyCollection<IPed> GetAllPeds() => CoreImpl.PoolManager.Ped.GetAllEntities();

public static IReadOnlyCollection<IBlip> GetAllBlips() => CoreImpl.PoolManager.Blip.GetAllObjects();

public static IReadOnlyCollection<IObject> GetAllNetworkObjects() => CoreImpl.PoolManager.Object.GetAllEntities();

public static IReadOnlyCollection<ICheckpoint> GetAllCheckpoints() =>
CoreImpl.PoolManager.Checkpoint.GetAllObjects();

public static IReadOnlyCollection<IVoiceChannel> GetAllVoiceChannels() =>
CoreImpl.PoolManager.VoiceChannel.GetAllObjects();

public static IReadOnlyCollection<IColShape> GetAllColShapes() => CoreImpl.PoolManager.ColShape.GetAllObjects();

public static IReadOnlyCollection<IMarker> GetAllMarkers() => CoreImpl.PoolManager.Marker.GetAllObjects();

public static IReadOnlyCollection<IConnectionInfo> GetAllConnectionInfos() =>
CoreImpl.PoolManager.ConnectionInfo.GetAllObjects();

public static IReadOnlyCollection<IVirtualEntity> GetAllVirtualEntities() =>
CoreImpl.PoolManager.VirtualEntity.GetAllObjects();

public static IReadOnlyCollection<IVirtualEntityGroup> GetAllVirtualEntityGroups() =>
CoreImpl.PoolManager.VirtualEntityGroup.GetAllObjects();

public static KeyValuePair<IntPtr, IPlayer>[] GetPlayersArray() => CoreImpl.PoolManager.Player.GetEntitiesArray();

public static KeyValuePair<IntPtr, IVehicle>[] GetVehiclesArray() =>
CoreImpl.PoolManager.Vehicle.GetEntitiesArray();

public static KeyValuePair<IntPtr, IPed>[] GetPedsArray() => CoreImpl.PoolManager.Ped.GetEntitiesArray();

public static KeyValuePair<IntPtr, IBlip>[] GetBlipsArray() => CoreImpl.PoolManager.Blip.GetObjectsArray();

public static KeyValuePair<IntPtr, ICheckpoint>[] GetCheckpointsArray() =>
CoreImpl.PoolManager.Checkpoint.GetObjectsArray();

public static KeyValuePair<IntPtr, IVoiceChannel>[] GetVoiceChannelsArray() =>
CoreImpl.PoolManager.VoiceChannel.GetObjectsArray();

public static KeyValuePair<IntPtr, IColShape>[] GetColShapesArray() =>
CoreImpl.PoolManager.ColShape.GetObjectsArray();

public static KeyValuePair<IntPtr, IConnectionInfo>[] GetConnectionInfoArray() =>
CoreImpl.PoolManager.ConnectionInfo.GetObjectsArray();

public static void ForEachPlayers(IBaseObjectCallback<IPlayer> baseObjectCallback) =>
CoreImpl.PoolManager.Player.ForEach(baseObjectCallback);

public static Task ForEachPlayers(IAsyncBaseObjectCallback<IPlayer> baseObjectCallback) =>
CoreImpl.PoolManager.Player.ForEach(baseObjectCallback);

public static void ForEachVehicles(IBaseObjectCallback<IVehicle> baseObjectCallback) =>
CoreImpl.PoolManager.Vehicle.ForEach(baseObjectCallback);

public static Task ForEachVehicles(IAsyncBaseObjectCallback<IVehicle> baseObjectCallback) =>
CoreImpl.PoolManager.Vehicle.ForEach(baseObjectCallback);

public static void ForEachPeds(IBaseObjectCallback<IPed> baseObjectCallback) =>
CoreImpl.PoolManager.Ped.ForEach(baseObjectCallback);

public static Task ForEachPeds(IAsyncBaseObjectCallback<IPed> baseObjectCallback) =>
CoreImpl.PoolManager.Ped.ForEach(baseObjectCallback);

public static void ForEachBlips(IBaseObjectCallback<IBlip> baseObjectCallback) =>
CoreImpl.PoolManager.Blip.ForEach(baseObjectCallback);

public static Task ForEachBlips(IAsyncBaseObjectCallback<IBlip> baseObjectCallback) =>
CoreImpl.PoolManager.Blip.ForEach(baseObjectCallback);

public static void ForEachCheckpoints(IBaseObjectCallback<ICheckpoint> baseObjectCallback) =>
CoreImpl.PoolManager.Checkpoint.ForEach(baseObjectCallback);

public static Task ForEachCheckpoints(IAsyncBaseObjectCallback<ICheckpoint> baseObjectCallback) =>
CoreImpl.PoolManager.Checkpoint.ForEach(baseObjectCallback);

public static void ForEachVoiceChannels(IBaseObjectCallback<IVoiceChannel> baseObjectCallback) =>
CoreImpl.PoolManager.VoiceChannel.ForEach(baseObjectCallback);

public static Task ForEachVoiceChannels(IAsyncBaseObjectCallback<IVoiceChannel> baseObjectCallback) =>
CoreImpl.PoolManager.VoiceChannel.ForEach(baseObjectCallback);

public static void ForEachColShapes(IBaseObjectCallback<IColShape> baseObjectCallback) =>
CoreImpl.PoolManager.ColShape.ForEach(baseObjectCallback);

public static Task ForEachColShapes(IAsyncBaseObjectCallback<IColShape> baseObjectCallback) =>
CoreImpl.PoolManager.ColShape.ForEach(baseObjectCallback);
}
81 changes: 0 additions & 81 deletions api/AltV.Net/Alt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,87 +43,6 @@ public static void EmitUnreliableClients(IPlayer[] clients, string eventName, pa

public static void Log(string message) => CoreImpl.LogInfo(message);

public static IReadOnlyCollection<IPlayer> GetAllPlayers() => CoreImpl.PoolManager.Player.GetAllEntities();

public static IReadOnlyCollection<IVehicle> GetAllVehicles() =>CoreImpl.PoolManager.Vehicle.GetAllEntities();

public static IReadOnlyCollection<IPed> GetAllPeds() =>CoreImpl.PoolManager.Ped.GetAllEntities();

public static IReadOnlyCollection<IBlip> GetAllBlips() =>CoreImpl.PoolManager.Blip.GetAllObjects();

public static IReadOnlyCollection<IObject> GetAllNetworkObjects() =>CoreImpl.PoolManager.Object.GetAllEntities();

public static IReadOnlyCollection<ICheckpoint> GetAllCheckpoints() =>CoreImpl.PoolManager.Checkpoint.GetAllObjects();

public static IReadOnlyCollection<IVoiceChannel> GetAllVoiceChannels() =>CoreImpl.PoolManager.VoiceChannel.GetAllObjects();

public static IReadOnlyCollection<IColShape> GetAllColShapes() =>CoreImpl.PoolManager.ColShape.GetAllObjects();

public static IReadOnlyCollection<IMarker> GetAllMarkers() =>CoreImpl.PoolManager.Marker.GetAllObjects();

public static IReadOnlyCollection<IConnectionInfo> GetAllConnectionInfos() => CoreImpl.PoolManager.ConnectionInfo.GetAllObjects();

public static IReadOnlyCollection<IVirtualEntity> GetAllVirtualEntities() => CoreImpl.PoolManager.VirtualEntity.GetAllObjects();

public static IReadOnlyCollection<IVirtualEntityGroup> GetAllVirtualEntityGroups() => CoreImpl.PoolManager.VirtualEntityGroup.GetAllObjects();

public static KeyValuePair<IntPtr, IPlayer>[] GetPlayersArray() => CoreImpl.PoolManager.Player.GetEntitiesArray();

public static KeyValuePair<IntPtr, IVehicle>[] GetVehiclesArray() => CoreImpl.PoolManager.Vehicle.GetEntitiesArray();

public static KeyValuePair<IntPtr, IPed>[] GetPedsArray() => CoreImpl.PoolManager.Ped.GetEntitiesArray();

public static KeyValuePair<IntPtr, IBlip>[] GetBlipsArray() => CoreImpl.PoolManager.Blip.GetObjectsArray();

public static KeyValuePair<IntPtr, ICheckpoint>[] GetCheckpointsArray() => CoreImpl.PoolManager.Checkpoint.GetObjectsArray();

public static KeyValuePair<IntPtr, IVoiceChannel>[] GetVoiceChannelsArray() => CoreImpl.PoolManager.VoiceChannel.GetObjectsArray();

public static KeyValuePair<IntPtr, IColShape>[] GetColShapesArray() => CoreImpl.PoolManager.ColShape.GetObjectsArray();
public static KeyValuePair<IntPtr, IConnectionInfo>[] GetConnectionInfoArray() => CoreImpl.PoolManager.ConnectionInfo.GetObjectsArray();

public static void ForEachPlayers(IBaseObjectCallback<IPlayer> baseObjectCallback) =>
CoreImpl.PoolManager.Player.ForEach(baseObjectCallback);

public static Task ForEachPlayers(IAsyncBaseObjectCallback<IPlayer> baseObjectCallback) =>
CoreImpl.PoolManager.Player.ForEach(baseObjectCallback);

public static void ForEachVehicles(IBaseObjectCallback<IVehicle> baseObjectCallback) =>
CoreImpl.PoolManager.Vehicle.ForEach(baseObjectCallback);

public static Task ForEachVehicles(IAsyncBaseObjectCallback<IVehicle> baseObjectCallback) =>
CoreImpl.PoolManager.Vehicle.ForEach(baseObjectCallback);

public static void ForEachPeds(IBaseObjectCallback<IPed> baseObjectCallback) =>
CoreImpl.PoolManager.Ped.ForEach(baseObjectCallback);

public static Task ForEachPeds(IAsyncBaseObjectCallback<IPed> baseObjectCallback) =>
CoreImpl.PoolManager.Ped.ForEach(baseObjectCallback);

public static void ForEachBlips(IBaseObjectCallback<IBlip> baseObjectCallback) =>
CoreImpl.PoolManager.Blip.ForEach(baseObjectCallback);

public static Task ForEachBlips(IAsyncBaseObjectCallback<IBlip> baseObjectCallback) =>
CoreImpl.PoolManager.Blip.ForEach(baseObjectCallback);

public static void ForEachCheckpoints(IBaseObjectCallback<ICheckpoint> baseObjectCallback) =>
CoreImpl.PoolManager.Checkpoint.ForEach(baseObjectCallback);

public static Task ForEachCheckpoints(IAsyncBaseObjectCallback<ICheckpoint> baseObjectCallback) =>
CoreImpl.PoolManager.Checkpoint.ForEach(baseObjectCallback);

public static void ForEachVoiceChannels(IBaseObjectCallback<IVoiceChannel> baseObjectCallback) =>
CoreImpl.PoolManager.VoiceChannel.ForEach(baseObjectCallback);

public static Task ForEachVoiceChannels(IAsyncBaseObjectCallback<IVoiceChannel> baseObjectCallback) =>
CoreImpl.PoolManager.VoiceChannel.ForEach(baseObjectCallback);

public static void ForEachColShapes(IBaseObjectCallback<IColShape> baseObjectCallback) =>
CoreImpl.PoolManager.ColShape.ForEach(baseObjectCallback);

public static Task ForEachColShapes(IAsyncBaseObjectCallback<IColShape> baseObjectCallback) =>
CoreImpl.PoolManager.ColShape.ForEach(baseObjectCallback);

public static VehicleModelInfo GetVehicleModelInfo(uint hash) => CoreImpl.GetVehicleModelInfo(hash);
public static VehicleModelInfo GetVehicleModelInfo(string name) => CoreImpl.GetVehicleModelInfo(Hash(name));
public static PedModelInfo? GetPedModelInfo(uint hash) => CoreImpl.GetPedModelInfo(hash);
Expand Down
69 changes: 69 additions & 0 deletions api/AltV.Net/Elements/Pools/PoolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,75 @@ public IBaseObject Get(IntPtr entityPointer, BaseObjectType baseObjectType)
};
}

public void Add(IBaseObject baseObject)
{
switch (baseObject.Type)
{
case BaseObjectType.Player:
{
Player.Add((IPlayer)baseObject);
break;
}
case BaseObjectType.Vehicle:
{
Vehicle.Add((IVehicle)baseObject);
break;
}
case BaseObjectType.Ped:
{
Ped.Add((IPed)baseObject);
break;
}
case BaseObjectType.Object:
{
Object.Add((IObject)baseObject);
break;
}
case BaseObjectType.Blip:
{
Blip.Add((IBlip)baseObject);
break;
}
case BaseObjectType.Checkpoint:
{
Checkpoint.Add((ICheckpoint)baseObject);
break;
}
case BaseObjectType.VoiceChannel:
{
VoiceChannel.Add((IVoiceChannel)baseObject);
break;
}
case BaseObjectType.ColShape:
{
ColShape.Add((IColShape)baseObject);
break;
}
case BaseObjectType.VirtualEntity:
{
VirtualEntity.Add((IVirtualEntity)baseObject);
break;
}
case BaseObjectType.VirtualEntityGroup:
{
VirtualEntityGroup.Add((IVirtualEntityGroup)baseObject);
break;
}
case BaseObjectType.Marker:
{
Marker.Add((IMarker)baseObject);
break;
}
case BaseObjectType.ConnectionInfo:
{
ConnectionInfo.Add((IConnectionInfo)baseObject);
break;
}
}


}

public void Dispose()
{
Player.Dispose();
Expand Down
1 change: 1 addition & 0 deletions api/AltV.Net/IPoolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public interface IPoolManager : ISharedPoolManager
IBaseObject GetOrCreate(ICore core, IntPtr entityPointer, BaseObjectType baseObjectType, uint entityId);
IBaseObject GetOrCreate(ICore core, IntPtr entityPointer, BaseObjectType baseObjectType);
IBaseObject Get(IntPtr entityPointer, BaseObjectType baseObjectType);
void Add(IBaseObject baseObject);
bool Remove(IBaseObject baseObject);
bool Remove(IntPtr entityPointer, BaseObjectType baseObjectType);
}
Expand Down
2 changes: 1 addition & 1 deletion runtime

0 comments on commit 3649627

Please sign in to comment.