feat: continue work on spawning actor

This commit is contained in:
Anna 2024-07-22 02:07:05 -04:00
parent 288ac50a6b
commit 460261d830
Signed by: anna
GPG Key ID: D0943384CD9F87D1
3 changed files with 22 additions and 9 deletions

View File

@ -59,8 +59,8 @@ public class Plugin : IDalamudPlugin {
this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration();
this.Vfx = new Vfx(this);
this.Messages = new Messages(this);
this.ActorManager = new ActorManager(this);
this.Ui = new PluginUi(this);
this.ActorManager = new ActorManager(this);
this.VfxReplacer = new VfxReplacer(this);
this.Commands = new Commands(this);
this.Pinger = new Pinger(this);
@ -74,8 +74,8 @@ public class Plugin : IDalamudPlugin {
this.Pinger.Dispose();
this.Commands.Dispose();
this.VfxReplacer.Dispose();
this.Ui.Dispose();
this.ActorManager.Dispose();
this.Ui.Dispose();
this.Messages.Dispose();
this.Vfx.Dispose();
}

View File

@ -13,7 +13,7 @@ internal class Viewer {
internal bool Visible;
internal delegate void MessageViewDelegate(Message? message);
internal event MessageViewDelegate View;
internal event MessageViewDelegate? View;
private Guid _lastViewed = Guid.Empty;
@ -26,7 +26,7 @@ internal class Viewer {
internal void Draw() {
if (!this.Visible) {
if (this._lastViewed != Guid.Empty) {
this.View(null);
this.View?.Invoke(null);
}
this._lastViewed = Guid.Empty;
@ -97,7 +97,7 @@ internal class Viewer {
var message = nearby[this._idx];
if (this._lastViewed != message.Id) {
try {
this.View(message);
this.View?.Invoke(message);
} catch (Exception ex) {
Plugin.Log.Error(ex, "Error in View event");
}

View File

@ -10,7 +10,6 @@ internal class ActorManager : IDisposable {
private readonly Queue<Mode> _tasks = [];
private enum Mode {
None,
Enable,
Disable,
Delete,
@ -47,20 +46,24 @@ internal class ActorManager : IDisposable {
switch (mode) {
case Mode.Disable: {
Plugin.Log.Debug("disabling actor");
obj->DisableDraw();
success = true;
break;
}
case Mode.Enable: {
if (!obj->IsReadyToDraw()) {
Plugin.Log.Debug("not ready to draw");
break;
}
Plugin.Log.Debug("drawing actor");
obj->EnableDraw();
success = true;
break;
}
case Mode.Delete: {
Plugin.Log.Debug("deleting actor");
objMan->DeleteObjectByIndex((ushort) idx, 0);
this._idx = null;
success = true;
@ -69,11 +72,14 @@ internal class ActorManager : IDisposable {
}
if (success) {
this._tasks.Dequeue();
var res = this._tasks.Dequeue();
Plugin.Log.Debug($"deq {Enum.GetName(res)}");
}
}
private void OnView(Message? message) {
var msg = message == null ? "null" : "not null";
Plugin.Log.Debug($"OnView message is {msg}");
this.Despawn();
if (message != null) {
@ -87,9 +93,12 @@ internal class ActorManager : IDisposable {
return;
}
Plugin.Log.Debug("spawning actor");
var objMan = ClientObjectManager.Instance();
var idx = objMan->CreateBattleCharacter();
if (idx == 0xFFFFFFFF) {
Plugin.Log.Debug("actor could not be spawned");
return;
}
@ -97,6 +106,7 @@ internal class ActorManager : IDisposable {
var chara = (BattleChara*) objMan->GetObjectByIndex((ushort) idx);
chara->ObjectKind = ObjectKind.BattleNpc;
chara->Position = message.Position;
chara->Rotation = message.Yaw;
var drawData = &chara->DrawData;
@ -109,8 +119,11 @@ internal class ActorManager : IDisposable {
this._tasks.Enqueue(Mode.Enable);
}
internal unsafe void Despawn() {
Plugin.Log.Debug("despawning actor");
internal void Despawn() {
if (this._idx == null) {
return;
}
this._tasks.Enqueue(Mode.Disable);
this._tasks.Enqueue(Mode.Delete);
}