Skip to content

Commit

Permalink
Updated submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
RisaDev committed Mar 25, 2024
1 parent abb92e7 commit ec0914a
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 67 deletions.
98 changes: 38 additions & 60 deletions CustomizePlus.GameData/Services/ObjectManager.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
using CustomizePlus.GameData.Data;
using Dalamud.Game.ClientState.Objects;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game.Control;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using OtterGui.Log;
using Penumbra.GameData.Actors;
using Penumbra.GameData.Enums;
using Penumbra.GameData.Interop;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CustomizePlus.GameData.Services;

public class ObjectManager(IFramework framework, IClientState clientState, global::Penumbra.GameData.Interop.ObjectManager objects, ActorManager actorManager, ITargetManager targetManager)
: IReadOnlyDictionary<ActorIdentifier, ActorData>
public class ObjectManager(
IFramework framework,
IClientState clientState,
IObjectTable objects,
DalamudPluginInterface pi,
Logger log,
ActorManager actors,
ITargetManager targets)
: global::Penumbra.GameData.Interop.ObjectManager(pi, log, framework, objects)
{
public global::Penumbra.GameData.Interop.ObjectManager Objects
=> objects;

public DateTime LastUpdate { get; private set; }
public DateTime LastUpdate
=> LastFrame;

private DateTime _identifierUpdate;
public bool IsInGPose { get; private set; }
public ushort World { get; private set; }

Expand All @@ -33,41 +34,27 @@ public class ObjectManager(IFramework framework, IClientState clientState, globa
public IReadOnlyDictionary<ActorIdentifier, ActorData> Identifiers
=> _identifiers;

public void Update()
public override bool Update()
{
var lastUpdate = framework.LastUpdate;
if (lastUpdate <= LastUpdate)
return;
if (!base.Update() && _identifierUpdate >= LastUpdate)
return false;

LastUpdate = lastUpdate;
World = (ushort)(clientState.LocalPlayer?.CurrentWorld.Id ?? 0u);
_identifierUpdate = LastUpdate;
World = (ushort)(this[0].Valid ? this[0].HomeWorld : 0);
_identifiers.Clear();
_allWorldIdentifiers.Clear();
_nonOwnedIdentifiers.Clear();

for (var i = 0; i < (int)ScreenActor.CutsceneStart; ++i)
{
Actor character = objects[i];
if (character.Identifier(actorManager, out var identifier))
HandleIdentifier(identifier, character);
}

for (var i = (int)ScreenActor.CutsceneStart; i < (int)ScreenActor.CutsceneEnd; ++i)
foreach (var actor in BattleNpcs.Concat(CutsceneCharacters))
{
Actor character = objects[i];
// Technically the game does not create holes in cutscenes or GPose.
// But for Brio compatibility, we allow holes in GPose.
// Since GPose always has the event actor in the first cutscene slot, we can still optimize in this case.
if (!character.Valid && i == (int)ScreenActor.CutsceneStart)
break;

HandleIdentifier(character.GetIdentifier(actorManager), character);
if (actor.Identifier(actors, out var identifier))
HandleIdentifier(identifier, actor);
}

void AddSpecial(ScreenActor idx, string label)
{
Actor actor = objects[(int)idx];
if (actor.Identifier(actorManager, out var ident))
var actor = this[(int)idx];
if (actor.Identifier(actors, out var ident))
{
var data = new ActorData(actor, label);
_identifiers.Add(ident, data);
Expand All @@ -83,15 +70,15 @@ void AddSpecial(ScreenActor idx, string label)
AddSpecial(ScreenActor.Card7, "Card Actor 7");
AddSpecial(ScreenActor.Card8, "Card Actor 8");

for (var i = (int)ScreenActor.ScreenEnd; i < objects.Count; ++i)
foreach (var actor in EventNpcs)
{
Actor character = objects[i];
if (character.Identifier(actorManager, out var identifier))
HandleIdentifier(identifier, character);
if (actor.Identifier(actors, out var identifier))
HandleIdentifier(identifier, actor);
}

var gPose = GPosePlayer;
IsInGPose = gPose.Utf8Name.Length > 0;
return true;
}

private void HandleIdentifier(ActorIdentifier identifier, Actor character)
Expand All @@ -111,8 +98,8 @@ private void HandleIdentifier(ActorIdentifier identifier, Actor character)

if (identifier.Type is IdentifierType.Player or IdentifierType.Owned)
{
var allWorld = actorManager.CreateIndividualUnchecked(identifier.Type, identifier.PlayerName, ushort.MaxValue,
identifier.Kind,
var allWorld = actors.CreateIndividualUnchecked(identifier.Type, identifier.PlayerName, ushort.MaxValue,
identifier.Kind,
identifier.DataId);

if (!_allWorldIdentifiers.TryGetValue(allWorld, out var allWorldData))
Expand All @@ -128,7 +115,7 @@ private void HandleIdentifier(ActorIdentifier identifier, Actor character)

if (identifier.Type is IdentifierType.Owned)
{
var nonOwned = actorManager.CreateNpc(identifier.Kind, identifier.DataId);
var nonOwned = actors.CreateNpc(identifier.Kind, identifier.DataId);
if (!_nonOwnedIdentifiers.TryGetValue(nonOwned, out var nonOwnedData))
{
nonOwnedData = new ActorData(character, nonOwned.ToString());
Expand All @@ -142,26 +129,26 @@ private void HandleIdentifier(ActorIdentifier identifier, Actor character)
}

public Actor GPosePlayer
=> objects[(int)ScreenActor.GPosePlayer];
=> this[(int)ScreenActor.GPosePlayer];

public Actor Player
=> objects[0];
=> this[0];

public unsafe Actor Target
=> clientState.IsGPosing ? TargetSystem.Instance()->GPoseTarget : TargetSystem.Instance()->Target;

public Actor Focus
=> targetManager.FocusTarget?.Address ?? nint.Zero;
=> targets.FocusTarget?.Address ?? nint.Zero;

public Actor MouseOver
=> targetManager.MouseOverTarget?.Address ?? nint.Zero;
=> targets.MouseOverTarget?.Address ?? nint.Zero;

public (ActorIdentifier Identifier, ActorData Data) PlayerData
{
get
{
Update();
return Player.Identifier(actorManager, out var ident) && _identifiers.TryGetValue(ident, out var data)
return Player.Identifier(actors, out var ident) && _identifiers.TryGetValue(ident, out var data)
? (ident, data)
: (ident, ActorData.Invalid);
}
Expand All @@ -172,27 +159,18 @@ public Actor MouseOver
get
{
Update();
return Target.Identifier(actorManager, out var ident) && _identifiers.TryGetValue(ident, out var data)
return Target.Identifier(actors, out var ident) && _identifiers.TryGetValue(ident, out var data)
? (ident, data)
: (ident, ActorData.Invalid);
}
}

public IEnumerator<KeyValuePair<ActorIdentifier, ActorData>> GetEnumerator()
=> Identifiers.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator()
=> GetEnumerator();

public int Count
=> Identifiers.Count;

/// <summary> Also handles All Worlds players and non-owned NPCs. </summary>
public bool ContainsKey(ActorIdentifier key)
=> Identifiers.ContainsKey(key) || _allWorldIdentifiers.ContainsKey(key) || _nonOwnedIdentifiers.ContainsKey(key);

public bool TryGetValue(ActorIdentifier key, out ActorData value)
=> Identifiers.TryGetValue(key, out value);
=> Identifiers.TryGetValue(key, out value);

public bool TryGetValueAllWorld(ActorIdentifier key, out ActorData value)
=> _allWorldIdentifiers.TryGetValue(key, out value);
Expand Down
2 changes: 1 addition & 1 deletion CustomizePlus/Armatures/Services/ArmatureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void RefreshArmatures()
return null;
}

foreach (var obj in _objectManager)
foreach (var obj in _objectManager.Identifiers)
{
var actorIdentifier = obj.Key.CreatePermanent();
if (!Armatures.ContainsKey(actorIdentifier))
Expand Down
2 changes: 1 addition & 1 deletion CustomizePlus/Game/Services/GameObjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public bool IsActorHasScalableRoot(Actor actor)
/// <returns></returns>
public IEnumerable<(ActorIdentifier, Actor)> FindActorsByName(string name)
{
foreach (var kvPair in _objectManager)
foreach (var kvPair in _objectManager.Identifiers)
{
var identifier = kvPair.Key;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void DrawArmatures()

private void DrawObjectManager()
{
foreach (var kvPair in _objectManager)
foreach (var kvPair in _objectManager.Identifiers)
{
var show = ImGui.CollapsingHeader($"{kvPair.Key} ({kvPair.Value.Objects.Count} objects)###object-{kvPair.Key}");

Expand Down
2 changes: 1 addition & 1 deletion submodules/OtterGui
Submodule OtterGui updated 1 files
+1 −2 OtterGui.csproj
2 changes: 1 addition & 1 deletion submodules/Penumbra.Api
2 changes: 1 addition & 1 deletion submodules/Penumbra.GameData

0 comments on commit ec0914a

Please sign in to comment.