Skip to content

Commit 0126887

Browse files
Improve async module
1 parent 23653d6 commit 0126887

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

api/AltV.Net.Async/AsyncModule.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Runtime.Loader;
34
using System.Threading.Tasks;
45
using AltV.Net.Async.Events;
56
using AltV.Net.Elements.Entities;
@@ -67,13 +68,13 @@ private readonly Dictionary<string, HashSet<ServerEventAsyncDelegate>> serverEve
6768
=
6869
new Dictionary<string, HashSet<ServerEventAsyncDelegate>>();
6970

70-
public AsyncModule(IServer server, CSharpNativeResource cSharpNativeResource,
71+
public AsyncModule(IServer server, AssemblyLoadContext assemblyLoadContext, CSharpNativeResource cSharpNativeResource,
7172
IBaseBaseObjectPool baseBaseObjectPool, IBaseEntityPool baseEntityPool, IEntityPool<IPlayer> playerPool,
7273
IEntityPool<IVehicle> vehiclePool,
7374
IBaseObjectPool<IBlip> blipPool,
7475
IBaseObjectPool<ICheckpoint> checkpointPool,
7576
IBaseObjectPool<IVoiceChannel> voiceChannelPool,
76-
IBaseObjectPool<IColShape> colShapePool) : base(server, cSharpNativeResource, baseBaseObjectPool,
77+
IBaseObjectPool<IColShape> colShapePool) : base(server, assemblyLoadContext, cSharpNativeResource, baseBaseObjectPool,
7778
baseEntityPool, playerPool, vehiclePool, blipPool,
7879
checkpointPool, voiceChannelPool, colShapePool)
7980
{
@@ -174,7 +175,9 @@ public override void OnVehicleRemoveEvent(IVehicle vehicle)
174175
@delegate(vehicle)));
175176
}
176177

177-
//TODO: we could write mvalues to own onion struct in cpp to better share it but we would need to execute at least getorcreate entity when it contains a entity type in main thread
178+
//TODO: we could write mvalue's to own onion struct in cpp to better share it but we would need to execute at least getorcreate entity when it contains a entity type in main thread
179+
//TODO: or lock entities dictionary so entity can't get removed until thread got it from dictionary
180+
//TODO: lock dictionary for async maybe as well for use cases like this
178181
public override void OnClientEventEvent(IPlayer player, string name, ref MValueArray args, MValue[] mValues,
179182
object[] objects)
180183
{

api/AltV.Net.Async/AsyncResource.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Runtime.Loader;
12
using AltV.Net.Async.Elements.Pools;
23
using AltV.Net.Elements.Entities;
34

@@ -42,22 +43,25 @@ public override IBaseObjectPool<IBlip> GetBlipPool(IBaseObjectFactory<IBlip> bli
4243
return new AsyncBlipPool(blipFactory);
4344
}
4445

45-
public override IBaseObjectPool<ICheckpoint> GetCheckpointPool(IBaseObjectFactory<ICheckpoint> checkpointFactory)
46+
public override IBaseObjectPool<ICheckpoint> GetCheckpointPool(
47+
IBaseObjectFactory<ICheckpoint> checkpointFactory)
4648
{
4749
return new AsyncCheckpointPool(checkpointFactory);
4850
}
4951

50-
public override IBaseObjectPool<IVoiceChannel> GetVoiceChannelPool(IBaseObjectFactory<IVoiceChannel> voiceChannelFactory)
52+
public override IBaseObjectPool<IVoiceChannel> GetVoiceChannelPool(
53+
IBaseObjectFactory<IVoiceChannel> voiceChannelFactory)
5154
{
5255
return new AsyncVoiceChannelPool(voiceChannelFactory);
5356
}
54-
57+
5558
public override IBaseObjectPool<IColShape> GetColShapePool(IBaseObjectFactory<IColShape> colShapeFactory)
5659
{
5760
return new AsyncColShapePool(colShapeFactory);
5861
}
5962

60-
public override Module GetModule(IServer server, CSharpNativeResource cSharpNativeResource,
63+
public override Module GetModule(IServer server, AssemblyLoadContext assemblyLoadContext,
64+
CSharpNativeResource cSharpNativeResource,
6165
IBaseBaseObjectPool baseBaseObjectPool,
6266
IBaseEntityPool baseEntityPool,
6367
IEntityPool<IPlayer> playerPool,
@@ -67,7 +71,8 @@ public override Module GetModule(IServer server, CSharpNativeResource cSharpNati
6771
IBaseObjectPool<IVoiceChannel> voiceChannelPool,
6872
IBaseObjectPool<IColShape> colShapePool)
6973
{
70-
return new AsyncModule(server, cSharpNativeResource, baseBaseObjectPool, baseEntityPool, playerPool,
74+
return new AsyncModule(server, assemblyLoadContext, cSharpNativeResource, baseBaseObjectPool,
75+
baseEntityPool, playerPool,
7176
vehiclePool, blipPool, checkpointPool, voiceChannelPool, colShapePool);
7277
}
7378
}

0 commit comments

Comments
 (0)