forked from aly/qstbak
122 lines
3.6 KiB
C#
122 lines
3.6 KiB
C#
using System;
|
|
using System.Numerics;
|
|
using Auspex.Vfx.Internal;
|
|
using Dalamud.Game.ClientState.Objects.Types;
|
|
|
|
namespace Auspex;
|
|
|
|
public sealed class VfxRenderer : IDisposable
|
|
{
|
|
private static readonly Vector4 White = Vector4.One;
|
|
|
|
private FrameLifetimeTracker<VfxInstance> trackedVfx;
|
|
|
|
private FrameLifetimeTracker<ActorBoundVfx> trackedGOVfx;
|
|
|
|
public static string OmenPath(string name)
|
|
{
|
|
return "vfx/omen/eff/" + name + ".avfx";
|
|
}
|
|
|
|
public static string LockonPath(string name)
|
|
{
|
|
return "vfx/lockon/eff/" + name + ".avfx";
|
|
}
|
|
|
|
public static string ChannelingPath(string name)
|
|
{
|
|
return "vfx/channeling/eff/" + name + ".avfx";
|
|
}
|
|
|
|
public static string CommonPath(string name)
|
|
{
|
|
return "vfx/common/eff/" + name + ".avfx";
|
|
}
|
|
|
|
public VfxRenderer()
|
|
{
|
|
trackedVfx = new FrameLifetimeTracker<VfxInstance>();
|
|
trackedGOVfx = new FrameLifetimeTracker<ActorBoundVfx>();
|
|
}
|
|
|
|
public void AddOmen(string id, string name, Vector3 origin, Vector3? scale = null, float rotation = 0f, Vector4? color = null)
|
|
{
|
|
ArgumentNullException.ThrowIfNull((object)id, "id");
|
|
ArgumentNullException.ThrowIfNull((object)name, "name");
|
|
CreateOrUpdateVfx(id, OmenPath(name), origin, scale ?? Vector3.One, rotation, color ?? White);
|
|
}
|
|
|
|
public void AddLockon(string id, string name, IGameObject target, Vector3? scale = null, Vector4? color = null)
|
|
{
|
|
ArgumentNullException.ThrowIfNull((object)id, "id");
|
|
ArgumentNullException.ThrowIfNull((object)name, "name");
|
|
CreateOrUpdateVfx(id, LockonPath(name), target, target, scale ?? Vector3.One, color ?? White);
|
|
}
|
|
|
|
public void AddChanneling(string id, string name, IGameObject target, IGameObject source, Vector3? scale = null, Vector4? color = null)
|
|
{
|
|
ArgumentNullException.ThrowIfNull((object)id, "id");
|
|
ArgumentNullException.ThrowIfNull((object)name, "name");
|
|
CreateOrUpdateVfx(id, ChannelingPath(name), target, source, scale ?? Vector3.One, color ?? White);
|
|
}
|
|
|
|
public void AddCommon(string id, string name, IGameObject target, Vector3? scale = null, Vector4? color = null)
|
|
{
|
|
ArgumentNullException.ThrowIfNull((object)id, "id");
|
|
ArgumentNullException.ThrowIfNull((object)name, "name");
|
|
CreateOrUpdateVfx(id, CommonPath(name), target, target, scale ?? Vector3.One, color ?? White);
|
|
}
|
|
|
|
public void AddCustom(string id, string path, Vector3 origin, Vector3? scale = null, float rotation = 0f, Vector4? color = null)
|
|
{
|
|
ArgumentNullException.ThrowIfNull((object)id, "id");
|
|
ArgumentNullException.ThrowIfNull((object)path, "path");
|
|
CreateOrUpdateVfx(id, path, origin, scale ?? Vector3.One, rotation, color ?? White);
|
|
}
|
|
|
|
private void CreateOrUpdateVfx(string id, string path, Vector3 position, Vector3 scale, float rotation, Vector4 color)
|
|
{
|
|
(string, string) key = (id, path);
|
|
if (!trackedVfx.IsTouched(key))
|
|
{
|
|
if (trackedVfx.TryTouchExisting(key, out VfxInstance o))
|
|
{
|
|
o.UpdateTransform(position, scale, rotation);
|
|
o.UpdateColor(color);
|
|
}
|
|
else
|
|
{
|
|
trackedVfx.TouchNew(key, VfxInstance.Create(path, position, scale, rotation, color));
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CreateOrUpdateVfx(string id, string path, IGameObject target, IGameObject source, Vector3 scale, Vector4 color)
|
|
{
|
|
(string, string) key = (id, path);
|
|
if (!trackedGOVfx.IsTouched(key))
|
|
{
|
|
if (trackedGOVfx.TryTouchExisting(key, out ActorBoundVfx o))
|
|
{
|
|
o.UpdateColor(color);
|
|
}
|
|
else
|
|
{
|
|
trackedGOVfx.TouchNew(key, ActorBoundVfx.Create(path, target, source, scale, color));
|
|
}
|
|
}
|
|
}
|
|
|
|
internal void Update()
|
|
{
|
|
trackedVfx.Update();
|
|
trackedGOVfx.Update();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
trackedVfx.Dispose();
|
|
trackedGOVfx.Dispose();
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|