Skip to content

Commit

Permalink
Merge pull request #549 from FabianTerhorst/dev
Browse files Browse the repository at this point in the history
RC
  • Loading branch information
FabianTerhorst committed May 9, 2022
2 parents ac87eb0 + 4627b2f commit 886e00a
Show file tree
Hide file tree
Showing 47 changed files with 617 additions and 127 deletions.
8 changes: 8 additions & 0 deletions api/AltV.Net.Async.CodeGen/AsyncEntityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,20 @@ public partial class {@class.Name}{classBaseDeclaration} {{
return new Async(this, asyncContext);
}}
public {@interface} ToAsync() {{
return new Async(this, null);
}}
private class Async : {asyncEntityType}<{@interface}>, {@interface} {{
public Async({@interface} player, AltV.Net.Async.IAsyncContext asyncContext) : base(player, asyncContext) {{ }}
public {@interface} ToAsync(AltV.Net.Async.IAsyncContext asyncContext) {{
return asyncContext == AsyncContext ? this : new Async(BaseObject, asyncContext);
}}
public {@interface} ToAsync() {{
return this;
}}
{Indent("\n" + string.Join("\n", members), 2)}
}}
}}";
Expand Down
5 changes: 5 additions & 0 deletions api/AltV.Net.Async/AltAsync.BaseObject.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks;
using AltV.Net.Elements.Args;
using AltV.Net.Elements.Entities;
Expand All @@ -7,19 +8,23 @@ namespace AltV.Net.Async
//TODO: allocate position, rotation, rgba structs in task thread an pass them to the main thread instead of creating them in the main thread
public partial class AltAsync
{
[Obsolete("Use async entities instead")]
public static Task<bool> ExistsAsync(this IBaseObject baseObject) =>
AltVAsync.Schedule(() => baseObject.Exists);

[Obsolete("Use async entities instead")]
public static Task<BaseObjectType> GetTypeAsync(this IBaseObject baseObject) =>
AltVAsync.Schedule(() => baseObject.Type);

[Obsolete("Use async entities instead")]
public static async Task SetMetaDataAsync(this IBaseObject baseObject, string key, object value)
{
Alt.Core.CreateMValue(out var mValue, value);
await AltVAsync.Schedule(() => baseObject.SetMetaData(key, in mValue));
mValue.Dispose();
}

[Obsolete("Use async entities instead")]
public static Task<T> GetMetaDataAsync<T>(this IBaseObject baseObject, string key) =>
AltVAsync.Schedule(() =>
{
Expand Down
10 changes: 10 additions & 0 deletions api/AltV.Net.Async/AltAsync.Blip.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks;
using AltV.Net.Data;
using AltV.Net.Elements.Entities;
Expand Down Expand Up @@ -30,30 +31,39 @@ public static partial class AltAsync
public static Task<IBlip> CreateBlip(BlipType type, IEntity entityAttach) =>
AltVAsync.Schedule(() => Alt.CreateBlip(type, entityAttach));

[Obsolete("Use async entities instead")]
public static Task<bool> IsGlobalAsync(this IBlip blip) =>
AltVAsync.Schedule(() => blip.IsGlobal);

[Obsolete("Use async entities instead")]
public static Task<bool> IsAttachedAsync(this IBlip blip) =>
AltVAsync.Schedule(() => blip.IsAttached);

[Obsolete("Use async entities instead")]
public static Task<IEntity> AttachedToAsync(this IBlip blip) =>
AltVAsync.Schedule(() => blip.AttachedTo);

[Obsolete("Use async entities instead")]
public static Task<BlipType> GetBlipTypeAsync(this IBlip blip) =>
AltVAsync.Schedule(() => (BlipType) blip.BlipType);

[Obsolete("Use async entities instead")]
public static Task SetSpriteAsync(this IBlip blip, ushort sprite) =>
AltVAsync.Schedule(() => blip.Sprite = sprite);

[Obsolete("Use async entities instead")]
public static Task SetColorAsync(this IBlip blip, byte color) =>
AltVAsync.Schedule(() => blip.Color = color);

[Obsolete("Use async entities instead")]
public static Task SetRouteAsync(this IBlip blip, bool route) =>
AltVAsync.Schedule(() => blip.Route = route);

[Obsolete("Use async entities instead")]
public static Task SetRouteColorAsync(this IBlip blip, Rgba color) =>
AltVAsync.Schedule(() => blip.RouteColor = color);

[Obsolete("Use async entities instead")]
public static Task RemoveAsync(this IBlip blip) =>
AltVAsync.Schedule(blip.RemoveAsync);
}
Expand Down
10 changes: 8 additions & 2 deletions api/AltV.Net.Async/AltAsync.Checkpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,36 @@ public static partial class AltAsync
Rgba color) =>
AltVAsync.Schedule(() => Alt.CreateCheckpoint(type, pos, radius, height, color));

[Obsolete("Use async entities instead")]
public static Task<CheckpointType> GetCheckpointTypeAsync(this ICheckpoint checkpoint) =>
AltVAsync.Schedule(() => (CheckpointType) checkpoint.CheckpointType);

[Obsolete("Use async entities instead")]
public static Task<float> GetHeightAsync(this ICheckpoint checkpoint) =>
AltVAsync.Schedule(() => checkpoint.Height);

[Obsolete("Use async entities instead")]
public static Task<float> GetRadiusAsync(this ICheckpoint checkpoint) =>
AltVAsync.Schedule(() => checkpoint.Radius);

[Obsolete("Use async entities instead")]
public static Task<Rgba> GetColorAsync(this ICheckpoint checkpoint) =>
AltVAsync.Schedule(() => checkpoint.Color);


[Obsolete("Use Checkpoint.IsEntityInAsync instead")]
[Obsolete("Use Checkpoint.IsEntityIn on async entity instead")]
public static Task<bool> IsPlayerInAsync(this ICheckpoint checkpoint, IPlayer player) =>
AltVAsync.Schedule(() => checkpoint.IsPlayerIn(player));

[Obsolete("Use Checkpoint.IsEntityInAsync instead")]
[Obsolete("Use Checkpoint.IsEntityIn on async entity instead")]
public static Task<bool> IsVehicleInAsync(this ICheckpoint checkpoint, IVehicle vehicle) =>
AltVAsync.Schedule(() => checkpoint.IsVehicleIn(vehicle));

[Obsolete("Use async entities instead")]
public static Task<bool> IsEntityInAsync(this ICheckpoint checkpoint, IEntity entity) =>
AltVAsync.Schedule(() => checkpoint.IsEntityIn(entity));

[Obsolete("Use async entities instead")]
public static Task RemoveAsync(this ICheckpoint checkpoint) =>
AltVAsync.Schedule(checkpoint.Remove);
}
Expand Down
10 changes: 10 additions & 0 deletions api/AltV.Net.Async/AltAsync.Entity.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks;
using AltV.Net.Data;
using AltV.Net.Elements.Args;
Expand All @@ -8,46 +9,55 @@ namespace AltV.Net.Async
//TODO: allocate position, rotation, rgba structs in task thread an pass them to the main thread instead of creating them in the main thread
public partial class AltAsync
{
[Obsolete("Use async entities instead")]
public static Task<uint> GetModelAsync(this IEntity entity) =>
AltVAsync.Schedule(() => entity.Model);

[Obsolete("Use async entities instead")]
public static Task SetRotationAsync(this IEntity entity, Rotation rotation) =>
AltVAsync.Schedule(() => entity.Rotation = rotation);

[Obsolete("Use async entities instead")]
public static Task<Rotation> GetRotationAsync(this IEntity entity) =>
AltVAsync.Schedule(() => entity.Rotation);

[Obsolete("Use async entities instead")]
public static async Task SetSyncedMetaDataAsync(this IEntity entity, string key, object value)
{
Alt.Core.CreateMValue(out var mValue, value);
await AltVAsync.Schedule(() => entity.SetSyncedMetaData(key, mValue));
mValue.Dispose();
}

[Obsolete("Use async entities instead")]
public static Task<T> GetSyncedMetaDataAsync<T>(this IEntity entity, string key) =>
AltVAsync.Schedule(() =>
{
entity.GetSyncedMetaData<T>(key, out var value);
return value;
});

[Obsolete("Use async entities instead")]
public static async Task SetStreamSyncedMetaDataAsync(this IEntity entity, string key, object value)
{
Alt.Core.CreateMValue(out var mValue, value);
await AltVAsync.Schedule(() => entity.SetStreamSyncedMetaData(key, mValue));
mValue.Dispose();
}

[Obsolete("Use async entities instead")]
public static Task<T> GetStreamSyncedMetaDataAsync<T>(this IEntity entity, string key) =>
AltVAsync.Schedule(() =>
{
entity.GetStreamSyncedMetaData<T>(key, out var value);
return value;
});

[Obsolete("Use async entities instead")]
public static Task DeleteSyncedMetaDataAsync(this IEntity entity, string key) =>
AltVAsync.Schedule(() => entity.DeleteSyncedMetaData(key));

[Obsolete("Use async entities instead")]
public static Task DeleteStreamSyncedMetaDataAsync(this IEntity entity, string key) =>
AltVAsync.Schedule(() => entity.DeleteStreamSyncedMetaData(key));
}
Expand Down

0 comments on commit 886e00a

Please sign in to comment.