feat: continue work on spawning actor
This commit is contained in:
parent
288ac50a6b
commit
460261d830
@ -59,8 +59,8 @@ public class Plugin : IDalamudPlugin {
|
|||||||
this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration();
|
this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration();
|
||||||
this.Vfx = new Vfx(this);
|
this.Vfx = new Vfx(this);
|
||||||
this.Messages = new Messages(this);
|
this.Messages = new Messages(this);
|
||||||
this.ActorManager = new ActorManager(this);
|
|
||||||
this.Ui = new PluginUi(this);
|
this.Ui = new PluginUi(this);
|
||||||
|
this.ActorManager = new ActorManager(this);
|
||||||
this.VfxReplacer = new VfxReplacer(this);
|
this.VfxReplacer = new VfxReplacer(this);
|
||||||
this.Commands = new Commands(this);
|
this.Commands = new Commands(this);
|
||||||
this.Pinger = new Pinger(this);
|
this.Pinger = new Pinger(this);
|
||||||
@ -74,8 +74,8 @@ public class Plugin : IDalamudPlugin {
|
|||||||
this.Pinger.Dispose();
|
this.Pinger.Dispose();
|
||||||
this.Commands.Dispose();
|
this.Commands.Dispose();
|
||||||
this.VfxReplacer.Dispose();
|
this.VfxReplacer.Dispose();
|
||||||
this.Ui.Dispose();
|
|
||||||
this.ActorManager.Dispose();
|
this.ActorManager.Dispose();
|
||||||
|
this.Ui.Dispose();
|
||||||
this.Messages.Dispose();
|
this.Messages.Dispose();
|
||||||
this.Vfx.Dispose();
|
this.Vfx.Dispose();
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ internal class Viewer {
|
|||||||
internal bool Visible;
|
internal bool Visible;
|
||||||
|
|
||||||
internal delegate void MessageViewDelegate(Message? message);
|
internal delegate void MessageViewDelegate(Message? message);
|
||||||
internal event MessageViewDelegate View;
|
internal event MessageViewDelegate? View;
|
||||||
|
|
||||||
private Guid _lastViewed = Guid.Empty;
|
private Guid _lastViewed = Guid.Empty;
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ internal class Viewer {
|
|||||||
internal void Draw() {
|
internal void Draw() {
|
||||||
if (!this.Visible) {
|
if (!this.Visible) {
|
||||||
if (this._lastViewed != Guid.Empty) {
|
if (this._lastViewed != Guid.Empty) {
|
||||||
this.View(null);
|
this.View?.Invoke(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._lastViewed = Guid.Empty;
|
this._lastViewed = Guid.Empty;
|
||||||
@ -97,7 +97,7 @@ internal class Viewer {
|
|||||||
var message = nearby[this._idx];
|
var message = nearby[this._idx];
|
||||||
if (this._lastViewed != message.Id) {
|
if (this._lastViewed != message.Id) {
|
||||||
try {
|
try {
|
||||||
this.View(message);
|
this.View?.Invoke(message);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Plugin.Log.Error(ex, "Error in View event");
|
Plugin.Log.Error(ex, "Error in View event");
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ internal class ActorManager : IDisposable {
|
|||||||
private readonly Queue<Mode> _tasks = [];
|
private readonly Queue<Mode> _tasks = [];
|
||||||
|
|
||||||
private enum Mode {
|
private enum Mode {
|
||||||
None,
|
|
||||||
Enable,
|
Enable,
|
||||||
Disable,
|
Disable,
|
||||||
Delete,
|
Delete,
|
||||||
@ -47,20 +46,24 @@ internal class ActorManager : IDisposable {
|
|||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case Mode.Disable: {
|
case Mode.Disable: {
|
||||||
|
Plugin.Log.Debug("disabling actor");
|
||||||
obj->DisableDraw();
|
obj->DisableDraw();
|
||||||
success = true;
|
success = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Mode.Enable: {
|
case Mode.Enable: {
|
||||||
if (!obj->IsReadyToDraw()) {
|
if (!obj->IsReadyToDraw()) {
|
||||||
|
Plugin.Log.Debug("not ready to draw");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Plugin.Log.Debug("drawing actor");
|
||||||
obj->EnableDraw();
|
obj->EnableDraw();
|
||||||
success = true;
|
success = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Mode.Delete: {
|
case Mode.Delete: {
|
||||||
|
Plugin.Log.Debug("deleting actor");
|
||||||
objMan->DeleteObjectByIndex((ushort) idx, 0);
|
objMan->DeleteObjectByIndex((ushort) idx, 0);
|
||||||
this._idx = null;
|
this._idx = null;
|
||||||
success = true;
|
success = true;
|
||||||
@ -69,11 +72,14 @@ internal class ActorManager : IDisposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
this._tasks.Dequeue();
|
var res = this._tasks.Dequeue();
|
||||||
|
Plugin.Log.Debug($"deq {Enum.GetName(res)}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnView(Message? message) {
|
private void OnView(Message? message) {
|
||||||
|
var msg = message == null ? "null" : "not null";
|
||||||
|
Plugin.Log.Debug($"OnView message is {msg}");
|
||||||
this.Despawn();
|
this.Despawn();
|
||||||
|
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
@ -87,9 +93,12 @@ internal class ActorManager : IDisposable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Plugin.Log.Debug("spawning actor");
|
||||||
|
|
||||||
var objMan = ClientObjectManager.Instance();
|
var objMan = ClientObjectManager.Instance();
|
||||||
var idx = objMan->CreateBattleCharacter();
|
var idx = objMan->CreateBattleCharacter();
|
||||||
if (idx == 0xFFFFFFFF) {
|
if (idx == 0xFFFFFFFF) {
|
||||||
|
Plugin.Log.Debug("actor could not be spawned");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +106,7 @@ internal class ActorManager : IDisposable {
|
|||||||
|
|
||||||
var chara = (BattleChara*) objMan->GetObjectByIndex((ushort) idx);
|
var chara = (BattleChara*) objMan->GetObjectByIndex((ushort) idx);
|
||||||
|
|
||||||
|
chara->ObjectKind = ObjectKind.BattleNpc;
|
||||||
chara->Position = message.Position;
|
chara->Position = message.Position;
|
||||||
chara->Rotation = message.Yaw;
|
chara->Rotation = message.Yaw;
|
||||||
var drawData = &chara->DrawData;
|
var drawData = &chara->DrawData;
|
||||||
@ -109,8 +119,11 @@ internal class ActorManager : IDisposable {
|
|||||||
this._tasks.Enqueue(Mode.Enable);
|
this._tasks.Enqueue(Mode.Enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal unsafe void Despawn() {
|
internal void Despawn() {
|
||||||
Plugin.Log.Debug("despawning actor");
|
if (this._idx == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._tasks.Enqueue(Mode.Disable);
|
this._tasks.Enqueue(Mode.Disable);
|
||||||
this._tasks.Enqueue(Mode.Delete);
|
this._tasks.Enqueue(Mode.Delete);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user