Load services asynchronously whenever possible (#893)

This commit is contained in:
kizer 2022-06-25 05:12:51 +09:00 committed by GitHub
parent fba8c7163c
commit 8e7f370ddd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 959 additions and 899 deletions

View file

@ -14,18 +14,18 @@ namespace Dalamud.Game.ClientState.Aetherytes
/// </summary>
[PluginInterface]
[InterfaceVersion("1.0")]
[ServiceManager.BlockingEarlyLoadedService]
public sealed partial class AetheryteList
{
[ServiceManager.ServiceDependency]
private readonly ClientState clientState = Service<ClientState>.Get();
private readonly ClientStateAddressResolver address;
private readonly UpdateAetheryteListDelegate updateAetheryteListFunc;
/// <summary>
/// Initializes a new instance of the <see cref="AetheryteList"/> class.
/// </summary>
/// <param name="addressResolver">Client state address resolver.</param>
internal AetheryteList(ClientStateAddressResolver addressResolver)
[ServiceManager.ServiceConstructor]
private AetheryteList()
{
this.address = addressResolver;
this.address = this.clientState.AddressResolver;
this.updateAetheryteListFunc = Marshal.GetDelegateForFunctionPointer<UpdateAetheryteListDelegate>(this.address.UpdateAetheryteList);
Log.Verbose($"Teleport address 0x{this.address.Telepo.ToInt64():X}");
@ -40,9 +40,7 @@ namespace Dalamud.Game.ClientState.Aetherytes
{
get
{
var clientState = Service<ClientState>.Get();
if (clientState.LocalPlayer == null)
if (this.clientState.LocalPlayer == null)
return 0;
this.Update();
@ -70,9 +68,7 @@ namespace Dalamud.Game.ClientState.Aetherytes
return null;
}
var clientState = Service<ClientState>.Get();
if (clientState.LocalPlayer == null)
if (this.clientState.LocalPlayer == null)
return null;
return new AetheryteEntry(TelepoStruct->TeleportList.Get((ulong)index));
@ -81,10 +77,8 @@ namespace Dalamud.Game.ClientState.Aetherytes
private void Update()
{
var clientState = Service<ClientState>.Get();
// this is very very important as otherwise it crashes
if (clientState.LocalPlayer == null)
if (this.clientState.LocalPlayer == null)
return;
this.updateAetheryteListFunc(this.address.Telepo, 0);