Skip to content

Commit c6cdeec

Browse files
committed
Reduce load on schedule calls in many entity classes
1 parent e263c37 commit c6cdeec

File tree

6 files changed

+170
-50
lines changed

6 files changed

+170
-50
lines changed

src/AlternateLife.RageMP.Net/Elements/Entities/Blip.cs

+38-12
Original file line numberDiff line numberDiff line change
@@ -19,70 +19,90 @@ public async Task SetDrawDistanceAsync(float value)
1919
{
2020
CheckExistence();
2121

22-
await _plugin.Schedule(() => Rage.Blip.Blip_SetDrawDistance(NativePointer, value)).ConfigureAwait(false);
22+
await _plugin
23+
.Schedule(() => Rage.Blip.Blip_SetDrawDistance(NativePointer, value))
24+
.ConfigureAwait(false);
2325
}
2426

2527
public async Task<float> GetDrawDistanceAsync()
2628
{
2729
CheckExistence();
2830

29-
return await _plugin.Schedule(() => Rage.Blip.Blip_GetDrawDistance(NativePointer)).ConfigureAwait(false);
31+
return await _plugin
32+
.Schedule(() => Rage.Blip.Blip_GetDrawDistance(NativePointer))
33+
.ConfigureAwait(false);
3034
}
3135

3236
public async Task SetRotationAsync(int value)
3337
{
3438
CheckExistence();
3539

36-
await _plugin.Schedule(() => Rage.Blip.Blip_SetRotation(NativePointer, value)).ConfigureAwait(false);
40+
await _plugin
41+
.Schedule(() => Rage.Blip.Blip_SetRotation(NativePointer, value))
42+
.ConfigureAwait(false);
3743
}
3844

3945
public new async Task<int> GetRotationAsync()
4046
{
4147
CheckExistence();
4248

43-
return await _plugin.Schedule(() => Rage.Blip.Blip_GetRotation(NativePointer)).ConfigureAwait(false);
49+
return await _plugin
50+
.Schedule(() => Rage.Blip.Blip_GetRotation(NativePointer))
51+
.ConfigureAwait(false);
4452
}
4553

4654
public async Task SetShortRangeAsync(bool value)
4755
{
4856
CheckExistence();
4957

50-
await _plugin.Schedule(() => Rage.Blip.Blip_SetShortRange(NativePointer, value)).ConfigureAwait(false);
58+
await _plugin
59+
.Schedule(() => Rage.Blip.Blip_SetShortRange(NativePointer, value))
60+
.ConfigureAwait(false);
5161
}
5262

5363
public async Task<bool> GetShortRangeAsync()
5464
{
5565
CheckExistence();
5666

57-
return await _plugin.Schedule(() => Rage.Blip.Blip_IsShortRange(NativePointer)).ConfigureAwait(false);
67+
return await _plugin
68+
.Schedule(() => Rage.Blip.Blip_IsShortRange(NativePointer))
69+
.ConfigureAwait(false);
5870
}
5971

6072
public async Task SetColorAsync(uint value)
6173
{
6274
CheckExistence();
6375

64-
await _plugin.Schedule(() => Rage.Blip.Blip_SetColor(NativePointer, value)).ConfigureAwait(false);
76+
await _plugin
77+
.Schedule(() => Rage.Blip.Blip_SetColor(NativePointer, value))
78+
.ConfigureAwait(false);
6579
}
6680

6781
public async Task<uint> GetColorAsync()
6882
{
6983
CheckExistence();
7084

71-
return await _plugin.Schedule(() => Rage.Blip.Blip_GetColor(NativePointer)).ConfigureAwait(false);
85+
return await _plugin
86+
.Schedule(() => Rage.Blip.Blip_GetColor(NativePointer))
87+
.ConfigureAwait(false);
7288
}
7389

7490
public async Task SetScaleAsync(float value)
7591
{
7692
CheckExistence();
7793

78-
await _plugin.Schedule(() => Rage.Blip.Blip_SetScale(NativePointer, value)).ConfigureAwait(false);
94+
await _plugin
95+
.Schedule(() => Rage.Blip.Blip_SetScale(NativePointer, value))
96+
.ConfigureAwait(false);
7997
}
8098

8199
public async Task<float> GetScaleAsync()
82100
{
83101
CheckExistence();
84102

85-
return await _plugin.Schedule(() => Rage.Blip.Blip_GetScale(NativePointer)).ConfigureAwait(false);
103+
return await _plugin
104+
.Schedule(() => Rage.Blip.Blip_GetScale(NativePointer))
105+
.ConfigureAwait(false);
86106
}
87107

88108
public async Task SetNameAsync(string value)
@@ -94,15 +114,21 @@ public async Task SetNameAsync(string value)
94114
{
95115
var name = converter.StringToPointer(value);
96116

97-
await _plugin.Schedule(() => Rage.Blip.Blip_SetName(NativePointer, name)).ConfigureAwait(false);
117+
await _plugin
118+
.Schedule(() => Rage.Blip.Blip_SetName(NativePointer, name))
119+
.ConfigureAwait(false);
98120
}
99121
}
100122

101123
public async Task<string> GetNameAsync()
102124
{
103125
CheckExistence();
104126

105-
return await _plugin.Schedule(() => StringConverter.PointerToString(Rage.Blip.Blip_GetName(NativePointer))).ConfigureAwait(false);
127+
var namePointer = await _plugin
128+
.Schedule(() => Rage.Blip.Blip_GetName(NativePointer))
129+
.ConfigureAwait(false);
130+
131+
return StringConverter.PointerToString(namePointer);
106132
}
107133

108134
public async Task ShowRouteAsync(IEnumerable<IPlayer> forPlayers, uint color, float scale)

src/AlternateLife.RageMP.Net/Elements/Entities/Checkpoint.cs

+28-8
Original file line numberDiff line numberDiff line change
@@ -23,56 +23,76 @@ public async Task SetColorAsync(Color value)
2323
{
2424
CheckExistence();
2525

26-
await _plugin.Schedule(() => Rage.Checkpoint.Checkpoint_SetColor(NativePointer, value.R, value.G, value.B, value.A)).ConfigureAwait(false);
26+
await _plugin
27+
.Schedule(() => Rage.Checkpoint.Checkpoint_SetColor(NativePointer, value.R, value.G, value.B, value.A))
28+
.ConfigureAwait(false);
2729
}
2830

2931
public async Task<Color> GetColorAsync()
3032
{
3133
CheckExistence();
3234

33-
return await _plugin.Schedule(() => StructConverter.PointerToStruct<ColorRgba>(Rage.Checkpoint.Checkpoint_GetColor(NativePointer)).FromModColor()).ConfigureAwait(false);
35+
var colorPointer = await _plugin
36+
.Schedule(() => Rage.Checkpoint.Checkpoint_GetColor(NativePointer))
37+
.ConfigureAwait(false);
38+
39+
return StructConverter.PointerToStruct<ColorRgba>(colorPointer).FromModColor();
3440
}
3541

3642
public async Task SetDirectionAsync(Vector3 value)
3743
{
3844
CheckExistence();
3945

40-
await _plugin.Schedule(() => Rage.Checkpoint.Checkpoint_SetDirection(NativePointer, value)).ConfigureAwait(false);
46+
await _plugin
47+
.Schedule(() => Rage.Checkpoint.Checkpoint_SetDirection(NativePointer, value))
48+
.ConfigureAwait(false);
4149
}
4250

4351
public async Task<Vector3> GetDirectionAsync()
4452
{
4553
CheckExistence();
4654

47-
return await _plugin.Schedule(() => StructConverter.PointerToStruct<Vector3>(Rage.Checkpoint.Checkpoint_GetDirection(NativePointer))).ConfigureAwait(false);
55+
var directionPointer = await _plugin
56+
.Schedule(() => Rage.Checkpoint.Checkpoint_GetDirection(NativePointer))
57+
.ConfigureAwait(false);
58+
59+
return StructConverter.PointerToStruct<Vector3>(directionPointer);
4860
}
4961

5062
public async Task SetRadiusAsync(float value)
5163
{
5264
CheckExistence();
5365

54-
await _plugin.Schedule(() => Rage.Checkpoint.Checkpoint_SetRadius(NativePointer, value)).ConfigureAwait(false);
66+
await _plugin
67+
.Schedule(() => Rage.Checkpoint.Checkpoint_SetRadius(NativePointer, value))
68+
.ConfigureAwait(false);
5569
}
5670

5771
public async Task<float> GetRadiusAsync()
5872
{
5973
CheckExistence();
6074

61-
return await _plugin.Schedule(() => Rage.Checkpoint.Checkpoint_GetRadius(NativePointer)).ConfigureAwait(false);
75+
return await _plugin
76+
.Schedule(() => Rage.Checkpoint.Checkpoint_GetRadius(NativePointer))
77+
.ConfigureAwait(false);
6278
}
6379

6480
public async Task SetVisibleAsync(bool value)
6581
{
6682
CheckExistence();
6783

68-
await _plugin.Schedule(() => Rage.Checkpoint.Checkpoint_SetVisible(NativePointer, value)).ConfigureAwait(false);
84+
await _plugin
85+
.Schedule(() => Rage.Checkpoint.Checkpoint_SetVisible(NativePointer, value))
86+
.ConfigureAwait(false);
6987
}
7088

7189
public async Task<bool> IsVisibleAsync()
7290
{
7391
CheckExistence();
7492

75-
return await _plugin.Schedule(() => Rage.Checkpoint.Checkpoint_IsVisible(NativePointer)).ConfigureAwait(false);
93+
return await _plugin
94+
.Schedule(() => Rage.Checkpoint.Checkpoint_IsVisible(NativePointer))
95+
.ConfigureAwait(false);
7696
}
7797

7898
public async Task ShowForAsync(IEnumerable<IPlayer> players)

src/AlternateLife.RageMP.Net/Elements/Entities/Colshape.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ public async Task<ColshapeType> GetShapeTypeAsync()
1717
{
1818
CheckExistence();
1919

20-
return (ColshapeType) await _plugin.Schedule(() => Rage.Colshape.Colshape_GetShapeType(NativePointer)).ConfigureAwait(false);
20+
return (ColshapeType) await _plugin
21+
.Schedule(() => Rage.Colshape.Colshape_GetShapeType(NativePointer))
22+
.ConfigureAwait(false);
2123
}
2224

2325
public async Task<bool> IsPointWhithinAsync(Vector3 position)

src/AlternateLife.RageMP.Net/Elements/Entities/Entity.cs

+39-11
Original file line numberDiff line numberDiff line change
@@ -38,77 +38,105 @@ public async Task SetModelAsync(uint value)
3838
{
3939
CheckExistence();
4040

41-
await _plugin.Schedule(() => Rage.Entity.Entity_SetModel(NativePointer, value)).ConfigureAwait(false);
41+
await _plugin
42+
.Schedule(() => Rage.Entity.Entity_SetModel(NativePointer, value))
43+
.ConfigureAwait(false);
4244
}
4345

4446
public async Task<uint> GetModelAsync()
4547
{
4648
CheckExistence();
4749

48-
return await _plugin.Schedule(() => Rage.Entity.Entity_GetModel(NativePointer)).ConfigureAwait(false);
50+
return await _plugin
51+
.Schedule(() => Rage.Entity.Entity_GetModel(NativePointer))
52+
.ConfigureAwait(false);
4953
}
5054

5155
public async Task SetAlphaAsync(uint value)
5256
{
5357
CheckExistence();
5458

55-
await _plugin.Schedule(() => Rage.Entity.Entity_SetAlpha(NativePointer, value)).ConfigureAwait(false);
59+
await _plugin
60+
.Schedule(() => Rage.Entity.Entity_SetAlpha(NativePointer, value))
61+
.ConfigureAwait(false);
5662
}
5763

5864
public async Task<uint> GetAlphaAsync()
5965
{
6066
CheckExistence();
6167

62-
return await _plugin.Schedule(() => Rage.Entity.Entity_GetAlpha(NativePointer)).ConfigureAwait(false);
68+
return await _plugin
69+
.Schedule(() => Rage.Entity.Entity_GetAlpha(NativePointer))
70+
.ConfigureAwait(false);
6371
}
6472

6573
public async Task SetDimensionAsync(uint value)
6674
{
6775
CheckExistence();
6876

69-
await _plugin.Schedule(() => Rage.Entity.Entity_SetDimension(NativePointer, value)).ConfigureAwait(false);
77+
await _plugin
78+
.Schedule(() => Rage.Entity.Entity_SetDimension(NativePointer, value))
79+
.ConfigureAwait(false);
7080
}
7181

7282
public async Task<uint> GetDimensionAsync()
7383
{
7484
CheckExistence();
7585

76-
return await _plugin.Schedule(() => Rage.Entity.Entity_GetDimension(NativePointer)).ConfigureAwait(false);
86+
return await _plugin
87+
.Schedule(() => Rage.Entity.Entity_GetDimension(NativePointer))
88+
.ConfigureAwait(false);
7789
}
7890

7991
public async Task SetPositionAsync(Vector3 value)
8092
{
8193
CheckExistence();
8294

83-
await _plugin.Schedule(() => Rage.Entity.Entity_SetPosition(NativePointer, value)).ConfigureAwait(false);
95+
await _plugin
96+
.Schedule(() => Rage.Entity.Entity_SetPosition(NativePointer, value))
97+
.ConfigureAwait(false);
8498
}
8599

86100
public async Task<Vector3> GetPositionAsync()
87101
{
88102
CheckExistence();
89103

90-
return await _plugin.Schedule(() => StructConverter.PointerToStruct<Vector3>(Rage.Entity.Entity_GetPosition(NativePointer))).ConfigureAwait(false);
104+
var positionPointer = await _plugin
105+
.Schedule(() => Rage.Entity.Entity_GetPosition(NativePointer))
106+
.ConfigureAwait(false);
107+
108+
return StructConverter.PointerToStruct<Vector3>(positionPointer);
91109
}
92110

93111
public virtual async Task SetRotationAsync(Vector3 value)
94112
{
95113
CheckExistence();
96114

97-
await _plugin.Schedule(() => Rage.Entity.Entity_SetRotation(NativePointer, value)).ConfigureAwait(false);
115+
await _plugin
116+
.Schedule(() => Rage.Entity.Entity_SetRotation(NativePointer, value))
117+
.ConfigureAwait(false);
98118
}
99119

100120
public virtual async Task<Vector3> GetRotationAsync()
101121
{
102122
CheckExistence();
103123

104-
return await _plugin.Schedule(() => StructConverter.PointerToStruct<Vector3>(Rage.Entity.Entity_GetRotation(NativePointer))).ConfigureAwait(false);
124+
var rotationPointer = await _plugin
125+
.Schedule(() => Rage.Entity.Entity_GetRotation(NativePointer))
126+
.ConfigureAwait(false);
127+
128+
return StructConverter.PointerToStruct<Vector3>(rotationPointer);
105129
}
106130

107131
public async Task<Vector3> GetVelocityAsync()
108132
{
109133
CheckExistence();
110134

111-
return await _plugin.Schedule(() => StructConverter.PointerToStruct<Vector3>(Rage.Entity.Entity_GetVelocity(NativePointer))).ConfigureAwait(false);
135+
var velocityPointer = await _plugin
136+
.Schedule(() => Rage.Entity.Entity_GetVelocity(NativePointer))
137+
.ConfigureAwait(false);
138+
139+
return StructConverter.PointerToStruct<Vector3>(velocityPointer);
112140
}
113141

114142
public Task DestroyAsync()

0 commit comments

Comments
 (0)