sigma update

This commit is contained in:
2026-01-16 11:00:58 +09:00
parent 59ed03a825
commit 96123d00a2
51 changed files with 6640 additions and 1382 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
using LightlessSync.FileCache;
using LightlessSync.LightlessConfiguration;
using LightlessSync.Utils;
using Microsoft.Extensions.Logging;
using System.Collections.Concurrent;
using System.Globalization;
@@ -19,7 +20,7 @@ public sealed class ModelDecimationService
private readonly XivDataStorageService _xivDataStorageService;
private readonly SemaphoreSlim _decimationSemaphore = new(MaxConcurrentJobs);
private readonly ConcurrentDictionary<string, Task> _activeJobs = new(StringComparer.OrdinalIgnoreCase);
private readonly TaskRegistry<string> _decimationDeduplicator = new();
private readonly ConcurrentDictionary<string, string> _decimatedPaths = new(StringComparer.OrdinalIgnoreCase);
private readonly ConcurrentDictionary<string, byte> _failedHashes = new(StringComparer.OrdinalIgnoreCase);
@@ -44,14 +45,14 @@ public sealed class ModelDecimationService
return;
}
if (_decimatedPaths.ContainsKey(hash) || _failedHashes.ContainsKey(hash) || _activeJobs.ContainsKey(hash))
if (_decimatedPaths.ContainsKey(hash) || _failedHashes.ContainsKey(hash) || _decimationDeduplicator.TryGetExisting(hash, out _))
{
return;
}
_logger.LogInformation("Queued model decimation for {Hash}", hash);
_activeJobs[hash] = Task.Run(async () =>
_decimationDeduplicator.GetOrStart(hash, async () =>
{
await _decimationSemaphore.WaitAsync().ConfigureAwait(false);
try
@@ -66,9 +67,8 @@ public sealed class ModelDecimationService
finally
{
_decimationSemaphore.Release();
_activeJobs.TryRemove(hash, out _);
}
}, CancellationToken.None);
});
}
public bool ShouldScheduleDecimation(string hash, string filePath, string? gamePath = null)
@@ -116,7 +116,7 @@ public sealed class ModelDecimationService
continue;
}
if (_activeJobs.TryGetValue(hash, out var job))
if (_decimationDeduplicator.TryGetExisting(hash, out var job))
{
pending.Add(job);
}
@@ -139,13 +139,18 @@ public sealed class ModelDecimationService
return Task.CompletedTask;
}
if (!TryGetDecimationSettings(out var triangleThreshold, out var targetRatio))
if (!TryGetDecimationSettings(out var triangleThreshold, out var targetRatio, out var normalizeTangents))
{
_logger.LogInformation("Model decimation disabled or invalid settings for {Hash}", hash);
return Task.CompletedTask;
}
_logger.LogInformation("Starting model decimation for {Hash} (threshold {Threshold}, ratio {Ratio:0.##})", hash, triangleThreshold, targetRatio);
_logger.LogInformation(
"Starting model decimation for {Hash} (threshold {Threshold}, ratio {Ratio:0.##}, normalize tangents {NormalizeTangents})",
hash,
triangleThreshold,
targetRatio,
normalizeTangents);
var destination = Path.Combine(GetDecimatedDirectory(), $"{hash}.mdl");
if (File.Exists(destination))
@@ -154,7 +159,7 @@ public sealed class ModelDecimationService
return Task.CompletedTask;
}
if (!MdlDecimator.TryDecimate(sourcePath, destination, triangleThreshold, targetRatio, _logger))
if (!MdlDecimator.TryDecimate(sourcePath, destination, triangleThreshold, targetRatio, normalizeTangents, _logger))
{
_failedHashes[hash] = 1;
_logger.LogInformation("Model decimation skipped for {Hash}", hash);
@@ -313,10 +318,11 @@ public sealed class ModelDecimationService
private static string NormalizeGamePath(string path)
=> path.Replace('\\', '/').ToLowerInvariant();
private bool TryGetDecimationSettings(out int triangleThreshold, out double targetRatio)
private bool TryGetDecimationSettings(out int triangleThreshold, out double targetRatio, out bool normalizeTangents)
{
triangleThreshold = 15_000;
targetRatio = 0.8;
normalizeTangents = true;
var config = _performanceConfigService.Current;
if (!config.EnableModelDecimation)
@@ -326,6 +332,7 @@ public sealed class ModelDecimationService
triangleThreshold = Math.Max(0, config.ModelDecimationTriangleThreshold);
targetRatio = config.ModelDecimationTargetRatio;
normalizeTangents = config.ModelDecimationNormalizeTangents;
if (double.IsNaN(targetRatio) || double.IsInfinity(targetRatio))
{
return false;