Skip to content

Commit

Permalink
Fix problem with mare colors not resetting, reduce redraws again, use…
Browse files Browse the repository at this point in the history
… material texture instead of GPU.
  • Loading branch information
Ottermandias committed Feb 22, 2024
1 parent d36e4f8 commit 80a6e89
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Glamourer/Api/GlamourerIpc.Apply.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private void ApplyDesign(DesignBase? design, IEnumerable<ActorIdentifier> actors
if ((hasModelId || state.ModelData.ModelId == 0) && state.CanUnlock(lockCode))
{
_stateManager.ApplyDesign(state, design,
new ApplySettings(Source: once ? StateSource.IpcManual : StateSource.IpcFixed, Key: lockCode, MergeLinks: true));
new ApplySettings(Source: once ? StateSource.IpcManual : StateSource.IpcFixed, Key: lockCode, MergeLinks: true, ResetMaterials: !once && lockCode != 0));
state.Lock(lockCode);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Glamourer/Automation/AutoDesignApplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public bool Reduce(Actor actor, ActorIdentifier identifier, [NotNullWhen(true)]

private unsafe void Reduce(Actor actor, ActorState state, AutoDesignSet set, bool respectManual, bool fromJobChange)
{
if (set.BaseState == AutoDesignSet.Base.Game)
if (set.BaseState is AutoDesignSet.Base.Game)
_state.ResetStateFixed(state, respectManual);
else if (!respectManual)
state.Sources.RemoveFixedDesignSources();
Expand All @@ -265,7 +265,7 @@ private unsafe void Reduce(Actor actor, ActorState state, AutoDesignSet set, boo
var mergedDesign = _designMerger.Merge(
set.Designs.Where(d => d.IsActive(actor)).SelectMany(d => d.Design?.AllLinks.Select(l => (l.Design, l.Flags & d.Type)) ?? [(d.Design, d.Type)]),
state.ModelData.Customize, state.BaseData, true, _config.AlwaysApplyAssociatedMods);
_state.ApplyDesign(state, mergedDesign, new ApplySettings(0, StateSource.Fixed, respectManual, fromJobChange, false));
_state.ApplyDesign(state, mergedDesign, new ApplySettings(0, StateSource.Fixed, respectManual, fromJobChange, false, false, set.BaseState is AutoDesignSet.Base.Game));
}

/// <summary> Get world-specific first and all-world afterward. </summary>
Expand Down
6 changes: 5 additions & 1 deletion Glamourer/Designs/IDesignEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public readonly record struct ApplySettings(
bool RespectManual = false,
bool FromJobChange = false,
bool UseSingleSource = false,
bool MergeLinks = false)
bool MergeLinks = false,
bool ResetMaterials = false)
{
public static readonly ApplySettings Manual = new()
{
Expand All @@ -22,6 +23,7 @@ public readonly record struct ApplySettings(
RespectManual = false,
UseSingleSource = false,
MergeLinks = false,
ResetMaterials = false,
};

public static readonly ApplySettings ManualWithLinks = new()
Expand All @@ -32,6 +34,7 @@ public readonly record struct ApplySettings(
RespectManual = false,
UseSingleSource = false,
MergeLinks = true,
ResetMaterials = false,
};

public static readonly ApplySettings Game = new()
Expand All @@ -42,6 +45,7 @@ public readonly record struct ApplySettings(
RespectManual = false,
UseSingleSource = false,
MergeLinks = false,
ResetMaterials = true,
};
}

Expand Down
1 change: 0 additions & 1 deletion Glamourer/Interop/Material/DirectXService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace Glamourer.Interop.Material;
public unsafe class DirectXService(IFramework framework) : IService
{
private readonly object _lock = new();

private readonly ConcurrentDictionary<nint, (DateTime Update, ColorTable Table)> _textures = [];

/// <summary> Generate a color table the way the game does inside the original texture, and release the original. </summary>
Expand Down
10 changes: 5 additions & 5 deletions Glamourer/Interop/Material/LiveColorTablePreviewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ public void OnHover(MaterialValueIndex index, ObjectIndex objectIndex, MtrlFile.

private static Vector3 CalculateDiffuse()
{
const int frameLength = 1;
const int steps = 64;
var frame = ImGui.GetFrameCount();
var hueByte = frame % (steps * frameLength) / frameLength;
var hue = (float)hueByte / steps;
const long frameLength = TimeSpan.TicksPerMillisecond * 5;
const long steps = 2000;
var frame = DateTimeOffset.UtcNow.UtcTicks;
var hueByte = frame % (steps * frameLength) / frameLength;
var hue = (float)hueByte / steps;
ImGui.ColorConvertHSVtoRGB(hue, 1, 1, out var r, out var g, out var b);
return new Vector3(r, g, b);
}
Expand Down
15 changes: 3 additions & 12 deletions Glamourer/State/StateApplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ public unsafe void ChangeMaterialValue(ActorData data, MaterialValueIndex index,
}
}

public ActorData ChangeMaterialValues(ActorState state, bool apply)
public ActorData ChangeMaterialValue(ActorState state, MaterialValueIndex index, bool apply)
{
var data = GetData(state);
if (apply)
ChangeMaterialValues(data, state.Materials, state.IsLocked);
ChangeMaterialValue(data, index, state.Materials.TryGetValue(index, out var v) ? v.Model : null, state.IsLocked);
return data;
}

Expand All @@ -326,7 +326,7 @@ public unsafe void ChangeMaterialValues(ActorData data, in StateMaterialManager
if (!mainKey.TryGetTexture(actor, out var texture))
continue;

if (!_directX.TryGetColorTable(*texture, out var table))
if (!PrepareColorSet.TryGetColorTable(actor, mainKey, out var table))
continue;

foreach (var (key, value) in values)
Expand All @@ -337,14 +337,6 @@ public unsafe void ChangeMaterialValues(ActorData data, in StateMaterialManager
}
}

public ActorData ChangeMaterialValue(ActorState state, MaterialValueIndex index, bool apply)
{
var data = GetData(state);
if (apply)
ChangeMaterialValue(data, index, state.Materials.TryGetValue(index, out var v) ? v.Model : null, state.IsLocked);
return data;
}

/// <summary> Apply the entire state of an actor to all relevant actors, either via immediate redraw or piecewise. </summary>
/// <param name="state"> The state to apply. </param>
/// <param name="redraw"> Whether a redraw should be forced. </param>
Expand Down Expand Up @@ -377,7 +369,6 @@ public ActorData ApplyAll(ActorState state, bool redraw, bool withLock)
ChangeMetaState(actors, MetaIndex.VisorState, state.ModelData.IsVisorToggled());
ChangeCrests(actors, state.ModelData.CrestVisibility);
ChangeParameters(actors, state.OnlyChangedParameters(), state.ModelData.Parameters, state.IsLocked);
// This should never be applied when caused through IPC, then redraw should be true.
ChangeMaterialValues(actors, state.Materials, state.IsLocked);
}
}
Expand Down
5 changes: 3 additions & 2 deletions Glamourer/State/StateEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ public void ApplyDesign(object data, MergedDesign mergedDesign, ApplySettings se
Editor.ChangeMetaState(state, meta, mergedDesign.Design.DesignData.GetMeta(meta), Source(meta), out _, settings.Key);
}

if (settings.ResetMaterials)
state.Materials.Clear();

foreach (var (key, value) in mergedDesign.Design.Materials)
{
if (!value.Enabled)
Expand All @@ -321,8 +324,6 @@ public void ApplyDesign(object data, MergedDesign mergedDesign, ApplySettings se
settings.Source, out _, settings.Key);
}
}

requiresRedraw |= mergedDesign.Design.Materials.Count > 0 && settings.Source.IsIpc();
}

var actors = settings.Source.RequiresChange()
Expand Down
3 changes: 1 addition & 2 deletions Glamourer/State/StateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ public void ResetState(ActorState state, StateSource source, uint key = 0)
|| !state.ModelData.IsHuman
|| CustomizeArray.Compare(state.ModelData.Customize, state.BaseData.Customize).RequiresRedraw();

redraw |= state.Materials.Values.Count > 0 && source.IsIpc();
state.ModelData = state.BaseData;
state.ModelData.SetIsWet(false);
foreach (var index in Enum.GetValues<CustomizeIndex>())
Expand Down Expand Up @@ -346,7 +345,7 @@ public void ReapplyState(Actor actor, StateSource source)
public void ReapplyState(Actor actor, ActorState state, StateSource source)
{
var data = Applier.ApplyAll(state,
!actor.Model.IsHuman || CustomizeArray.Compare(actor.Model.GetCustomize(), state.ModelData.Customize).RequiresRedraw() || state.Materials.Values.Count > 0 && source.IsIpc(), false);
!actor.Model.IsHuman || CustomizeArray.Compare(actor.Model.GetCustomize(), state.ModelData.Customize).RequiresRedraw(), false);
StateChanged.Invoke(StateChanged.Type.Reapply, source, state, data, null);
}

Expand Down

0 comments on commit 80a6e89

Please sign in to comment.