Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Sep 6, 2024
1 parent ad4c549 commit 2e207b2
Show file tree
Hide file tree
Showing 15 changed files with 290 additions and 299 deletions.
4 changes: 2 additions & 2 deletions api/AltV.Net.Async/AltAsync.Off.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ namespace AltV.Net.Async
public partial class AltAsync
{
public static void OffServer(string eventName, Function function) =>
Core.OffServer(eventName, function);
CoreImpl.OffServer(eventName, function);

public static void OffClient(string eventName, Function function) =>
Core.OffClient(eventName, function);
CoreImpl.OffClient(eventName, function);
}
}
136 changes: 68 additions & 68 deletions api/AltV.Net.Async/AltAsync.On.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions api/AltV.Net.Async/AltAsync.RegisterEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -727,11 +727,11 @@ public static void RegisterEvents(object target)
break;
case AsyncServerEventAttribute @event:
var serverEventName = @event.Name ?? eventMethod.Name;
Core.OnServer(serverEventName, Function.Create(Core, eventMethodDelegate));
CoreImpl.OnServer(serverEventName, Function.Create(CoreImpl, eventMethodDelegate));
break;
case AsyncClientEventAttribute @event:
var clientEventName = @event.Name ?? eventMethod.Name;
Core.OnClient(clientEventName, Function.Create(Core, eventMethodDelegate));
CoreImpl.OnClient(clientEventName, Function.Create(CoreImpl, eventMethodDelegate));
break;
}
});
Expand Down
236 changes: 118 additions & 118 deletions api/AltV.Net.Async/AltAsync.cs

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions api/AltV.Net.Client.Async/AltAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public static partial class AltAsync
// internal static AsyncCore Core;

internal static AltVAsync AltVAsync;
internal static ICore CoreImpl;

// public static async void Log(string message)
// {
Expand Down Expand Up @@ -58,27 +59,27 @@ internal static void Setup(AltVAsync altVAsync)
AltVAsync = altVAsync;
}

// internal static void Setup(AsyncCore core)
// {
// Core = core;
// }
internal static void Setup(Core core)
{
CoreImpl = core;
}

public static Task Do(Action action)
{
CheckIfAsyncResource();
return AltVAsync.Schedule(action);
}

public static Task Do(Task task)
{
throw new ArgumentException("AltAsync.Do should never have async code inside");
}

public static Task Do(Func<Task> task)
{
throw new ArgumentException("AltAsync.Do should never have async code inside");
}

public static void RunOnMainThreadBlocking(Action action, SemaphoreSlim semaphoreSlim)
{
CheckIfAsyncResource();
Expand Down Expand Up @@ -125,27 +126,27 @@ public class MainThreadContext : IAsyncDisposable
{
public async ValueTask DisposeAsync()
{
if (!Alt.Core.IsMainThread()) throw new Exception("ReturnToMainThread using block was exited on a non-main thread");
if (!CoreImpl.IsMainThread()) throw new Exception("ReturnToMainThread using block was exited on a non-main thread");
await Task.Run(() => {}); // jump to bg thread
}

private MainThreadContext()
{
}

internal static readonly MainThreadContext Instance = new();
}

public static async Task<MainThreadContext> ReturnToMainThread()
{
if (Alt.Core.IsMainThread()) return MainThreadContext.Instance;
if (CoreImpl.IsMainThread()) return MainThreadContext.Instance;
var source = new TaskCompletionSource();
RunOnMainThread(() => source.SetResult());
await source.Task;
return MainThreadContext.Instance;
}


public static async Task WaitFor(Func<bool> fn, uint timeout = 2000, uint interval = 0)
{
var checkUntil = DateTime.Now.AddMilliseconds(timeout);
Expand All @@ -164,7 +165,7 @@ public static async Task WaitFor(Func<bool> fn, uint timeout = 2000, uint interv
source.SetException(new TimeoutException("Failed to wait for callback"));
Alt.ClearInterval(handle);
}, interval);

await source.Task;
}
}
Expand Down
14 changes: 2 additions & 12 deletions api/AltV.Net.Client.Async/AsyncResource.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Runtime.Loader;
using AltV.Net.CApi;
using AltV.Net.Client.Elements.Interfaces;
using AltV.Net.Client.Elements.Pools;

namespace AltV.Net.Client.Async
{
Expand Down Expand Up @@ -60,17 +62,5 @@ public override void OnTick()
// return new AsyncColShapePool(colShapeFactory);
// }
//
// public override Core GetCore(IntPtr nativePointer, IntPtr resourcePointer, AssemblyLoadContext assemblyLoadContext, ILibrary library, IBaseBaseObjectPool baseBaseObjectPool,
// IBaseEntityPool baseEntityPool,
// IEntityPool<IPlayer> playerPool,
// IEntityPool<IVehicle> vehiclePool,
// IBaseObjectPool<IBlip> blipPool,
// IBaseObjectPool<ICheckpoint> checkpointPool,
// IBaseObjectPool<IVoiceChannel> voiceChannelPool,
// IBaseObjectPool<IColShape> colShapePool,
// INativeResourcePool nativeResourcePool)
// {
// return new AsyncCore(nativePointer, resourcePointer, assemblyLoadContext, library, baseBaseObjectPool, baseEntityPool, playerPool, vehiclePool, blipPool, checkpointPool, voiceChannelPool, colShapePool, nativeResourcePool);
// }
}
}
2 changes: 1 addition & 1 deletion api/AltV.Net.Client/ModuleWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static void MainWithAssembly(Assembly resourceAssembly, IntPtr resourcePo

_core = client;
Alt.CoreImpl = client;
AltShared.Core = client;
AltShared.CoreImpl = client;
Alt.Log("Core initialized");

_core.GetAllPlayers();
Expand Down
6 changes: 3 additions & 3 deletions api/AltV.Net.Shared/AltShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace AltV.Net.Shared
{
public static class AltShared
{
public static ISharedCore Core { get; set; }
public static uint Hash(string key) => Core.Hash(key);
internal static ISharedCore CoreImpl { get; set; }
public static uint Hash(string key) => CoreImpl.Hash(key);
public static bool CacheEntities = true;
public static void EmitLocal(string eventName, params object[] args) => Core.TriggerLocalEvent(eventName, args);
public static void EmitLocal(string eventName, params object[] args) => CoreImpl.TriggerLocalEvent(eventName, args);
}
}
4 changes: 2 additions & 2 deletions api/AltV.Net.Shared/Elements/Args/MValueBuffer2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public struct MValueBuffer2
public int size;

[Obsolete("Use Alt.CreateMValueBuffer or overload with ISharedCore argument instead")]
public MValueBuffer2(MValueConst[] values) : this(AltShared.Core, values) {
AltShared.Core.LogWarning("new MValueBuffer2(MValueConst[]) is deprecated, use Alt.CreateMValueBuffer or overload with ISharedCore argument instead");
public MValueBuffer2(MValueConst[] values) : this(AltShared.CoreImpl, values) {
AltShared.CoreImpl.LogWarning("new MValueBuffer2(MValueConst[]) is deprecated, use Alt.CreateMValueBuffer or overload with ISharedCore argument instead");
}

public MValueBuffer2(ISharedCore core, MValueConst[] values)
Expand Down
8 changes: 4 additions & 4 deletions api/AltV.Net.Shared/Elements/Args/MValueWriter2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class MValueWriter2 : IMValueWriter
private readonly ISharedCore core;

[Obsolete("Use Alt.CreateMValueWriter or overload with ISharedCore argument instead")]
public MValueWriter2() : this(AltShared.Core)
public MValueWriter2() : this(AltShared.CoreImpl)
{
AltShared.Core.LogWarning("new MValueWriter2() is deprecated, use Alt.CreateMValueWriter or overload with ISharedCore argument instead");
AltShared.CoreImpl.LogWarning("new MValueWriter2() is deprecated, use Alt.CreateMValueWriter or overload with ISharedCore argument instead");
}

public MValueWriter2(ISharedCore core)
Expand All @@ -43,7 +43,7 @@ public struct MValueObject : IWritableMValue
public List<object> Values { get; }

[Obsolete("Use overload with core as first parameter instead")]
public MValueObject(List<string> names, List<object> values) : this(AltShared.Core, names, values)
public MValueObject(List<string> names, List<object> values) : this(AltShared.CoreImpl, names, values)
{
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public struct MValueArray : IWritableMValue


[Obsolete("Use overload with core as first parameter instead")]
public MValueArray(List<object> values) : this(AltShared.Core, values)
public MValueArray(List<object> values) : this(AltShared.CoreImpl, values)
{
}
public MValueArray(ISharedCore core, List<object> values)
Expand Down
2 changes: 1 addition & 1 deletion api/AltV.Net.Shared/Events/HashSetEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace AltV.Net.Shared.Events
{
internal class HashSetEventHandler<TEvent> : IEventHandler<TEvent>
{
private ISharedCore core => AltShared.Core; // todo pass core to constructor
private ISharedCore core => AltShared.CoreImpl; // todo pass core to constructor
private readonly EventType? type;
private readonly HashSet<TEvent> events = new();

Expand Down
Loading

0 comments on commit 2e207b2

Please sign in to comment.