From e7a49323070fc721c87a99eb854032be3657b7d5 Mon Sep 17 00:00:00 2001 From: lahm86 <33758420+lahm86@users.noreply.github.com> Date: Tue, 7 May 2024 16:56:07 +0100 Subject: [PATCH] Reorganise folder structures (#669) Part of #653. --- .../Entities/EMEntityPropertyCondition.cs | 4 +- .../Transport/TR1/TR1DataImporter.cs | 2 +- .../Transport/TR2/TR2DataImporter.cs | 2 +- .../Transport/TR3/TR3DataImporter.cs | 2 +- .../Transport/TR4/TR4DataImporter.cs | 2 +- .../Transport/TR5/TR5DataImporter.cs | 2 +- TRDataControl/Transport/TRDataImporter.cs | 6 +-- .../AbstractTRLevelTextureDeduplicator.cs | 47 ------------------- .../TR2LevelTextureDeduplicator.cs | 18 ------- .../TRModelExtensions.cs | 0 .../ITexturePositionMonitor.cs | 0 .../PositionedTexture.cs | 0 .../RemapTypes/TR1TextureRemapGroup.cs | 2 +- .../RemapTypes/TR2TextureRemapGroup.cs | 2 +- .../RemapTypes/TR3TextureRemapGroup.cs | 2 +- .../RemapTypes/TR4TextureRemapGroup.cs | 2 +- .../RemapTypes/TR5TextureRemapGroup.cs | 2 +- .../TRImageDeduplicator.cs | 0 .../TRTextureRemapGroup.cs} | 2 +- .../TextureDependency.cs | 0 .../{Textures => Remapping}/TextureRemap.cs | 0 .../Processors/TR2/TR2TextureDeduplicator.cs | 41 ++++++++++++---- 22 files changed, 48 insertions(+), 90 deletions(-) delete mode 100644 TRDataControl/Utilities/AbstractTRLevelTextureDeduplicator.cs delete mode 100644 TRDataControl/Utilities/Deduplication/TR2LevelTextureDeduplicator.cs rename TRDataControl/{Helpers => Utilities}/TRModelExtensions.cs (100%) rename TRImageControl/Packing/{Textures => Remapping}/ITexturePositionMonitor.cs (100%) rename TRImageControl/Packing/{Textures => Remapping}/PositionedTexture.cs (100%) rename TRImageControl/Packing/{Textures => Remapping}/RemapTypes/TR1TextureRemapGroup.cs (85%) rename TRImageControl/Packing/{Textures => Remapping}/RemapTypes/TR2TextureRemapGroup.cs (85%) rename TRImageControl/Packing/{Textures => Remapping}/RemapTypes/TR3TextureRemapGroup.cs (85%) rename TRImageControl/Packing/{Textures => Remapping}/RemapTypes/TR4TextureRemapGroup.cs (86%) rename TRImageControl/Packing/{Textures => Remapping}/RemapTypes/TR5TextureRemapGroup.cs (86%) rename TRImageControl/Packing/{Textures => Remapping}/TRImageDeduplicator.cs (100%) rename TRImageControl/Packing/{Textures/AbstractTextureRemapGroup.cs => Remapping/TRTextureRemapGroup.cs} (98%) rename TRImageControl/Packing/{Textures => Remapping}/TextureDependency.cs (100%) rename TRImageControl/Packing/{Textures => Remapping}/TextureRemap.cs (100%) diff --git a/TRDataControl/Environment/Model/Conditions/Entities/EMEntityPropertyCondition.cs b/TRDataControl/Environment/Model/Conditions/Entities/EMEntityPropertyCondition.cs index cb9e75b8f..def6fa3e9 100644 --- a/TRDataControl/Environment/Model/Conditions/Entities/EMEntityPropertyCondition.cs +++ b/TRDataControl/Environment/Model/Conditions/Entities/EMEntityPropertyCondition.cs @@ -80,11 +80,11 @@ private bool GetResult(TREntity entity) bool result = true; if (EntityType.HasValue) { - result &= EqualityComparer.Default.Equals(entity.TypeID, (T)(object)(int)EntityType.Value); + result &= EqualityComparer.Default.Equals(entity.TypeID, (T)(object)(uint)EntityType.Value); } if (EntityTypes != null) { - result &= EntityTypes.Any(e => EqualityComparer.Default.Equals(entity.TypeID, (T)(object)(int)e)); + result &= EntityTypes.Any(e => EqualityComparer.Default.Equals(entity.TypeID, (T)(object)(uint)e)); } if (Invisible.HasValue) { diff --git a/TRDataControl/Transport/TR1/TR1DataImporter.cs b/TRDataControl/Transport/TR1/TR1DataImporter.cs index 5b6c8744a..48baf5073 100644 --- a/TRDataControl/Transport/TR1/TR1DataImporter.cs +++ b/TRDataControl/Transport/TR1/TR1DataImporter.cs @@ -32,7 +32,7 @@ protected override List GetExistingTypes() protected override TRTextureRemapper CreateRemapper(TR1Level level) => new TR1TextureRemapper(level); - protected override AbstractTextureRemapGroup GetRemapGroup() + protected override TRTextureRemapGroup GetRemapGroup() => JsonConvert.DeserializeObject(File.ReadAllText(TextureRemapPath)); protected override bool IsMasterType(TR1Type type) diff --git a/TRDataControl/Transport/TR2/TR2DataImporter.cs b/TRDataControl/Transport/TR2/TR2DataImporter.cs index 7a952d57b..28a2c08b3 100644 --- a/TRDataControl/Transport/TR2/TR2DataImporter.cs +++ b/TRDataControl/Transport/TR2/TR2DataImporter.cs @@ -25,7 +25,7 @@ protected override List GetExistingTypes() protected override TRTextureRemapper CreateRemapper(TR2Level level) => new TR2TextureRemapper(level); - protected override AbstractTextureRemapGroup GetRemapGroup() + protected override TRTextureRemapGroup GetRemapGroup() => JsonConvert.DeserializeObject(File.ReadAllText(TextureRemapPath)); protected override bool IsMasterType(TR2Type type) diff --git a/TRDataControl/Transport/TR3/TR3DataImporter.cs b/TRDataControl/Transport/TR3/TR3DataImporter.cs index 6a0be31db..96309eb85 100644 --- a/TRDataControl/Transport/TR3/TR3DataImporter.cs +++ b/TRDataControl/Transport/TR3/TR3DataImporter.cs @@ -25,7 +25,7 @@ protected override List GetExistingTypes() protected override TRTextureRemapper CreateRemapper(TR3Level level) => new TR3TextureRemapper(level); - protected override AbstractTextureRemapGroup GetRemapGroup() + protected override TRTextureRemapGroup GetRemapGroup() => JsonConvert.DeserializeObject(File.ReadAllText(TextureRemapPath)); protected override bool IsMasterType(TR3Type type) diff --git a/TRDataControl/Transport/TR4/TR4DataImporter.cs b/TRDataControl/Transport/TR4/TR4DataImporter.cs index e239f58fb..965a85c7b 100644 --- a/TRDataControl/Transport/TR4/TR4DataImporter.cs +++ b/TRDataControl/Transport/TR4/TR4DataImporter.cs @@ -17,7 +17,7 @@ protected override List GetExistingTypes() protected override TRTextureRemapper CreateRemapper(TR4Level level) => new TR4TextureRemapper(level); - protected override AbstractTextureRemapGroup GetRemapGroup() + protected override TRTextureRemapGroup GetRemapGroup() => JsonConvert.DeserializeObject(File.ReadAllText(TextureRemapPath)); protected override bool IsMasterType(TR4Type type) diff --git a/TRDataControl/Transport/TR5/TR5DataImporter.cs b/TRDataControl/Transport/TR5/TR5DataImporter.cs index f60ab3e3e..68d9aa54e 100644 --- a/TRDataControl/Transport/TR5/TR5DataImporter.cs +++ b/TRDataControl/Transport/TR5/TR5DataImporter.cs @@ -17,7 +17,7 @@ protected override List GetExistingTypes() protected override TRTextureRemapper CreateRemapper(TR5Level level) => new TR5TextureRemapper(level); - protected override AbstractTextureRemapGroup GetRemapGroup() + protected override TRTextureRemapGroup GetRemapGroup() => JsonConvert.DeserializeObject(File.ReadAllText(TextureRemapPath)); protected override bool IsMasterType(TR5Type type) diff --git a/TRDataControl/Transport/TRDataImporter.cs b/TRDataControl/Transport/TRDataImporter.cs index e5746e416..c73dbfc6c 100644 --- a/TRDataControl/Transport/TRDataImporter.cs +++ b/TRDataControl/Transport/TRDataImporter.cs @@ -297,7 +297,7 @@ protected void RemoveData() staleTextures = new(staleTextures.Distinct()); if (staleTextures.Count > 0) { - AbstractTextureRemapGroup remapGroup = TextureRemapPath == null ? null : GetRemapGroup(); + TRTextureRemapGroup remapGroup = TextureRemapPath == null ? null : GetRemapGroup(); CreateRemapper(Level)?.RemoveUnusedTextures(staleTextures, (tile, bounds) => remapGroup?.CanRemoveRectangle(tile, bounds, TypesToRemove) ?? true); } @@ -349,7 +349,7 @@ protected void ImportTextures(List blobs) if (Level.ObjectTextures.Count >= Data.TextureObjectLimit) { - throw new TransportException($"Limit of {Data.TextureObjectLimit} textures reached."); + throw new PackingException($"Limit of {Data.TextureObjectLimit} textures reached."); } globalRemap[region.ID][segment.Index] = Level.ObjectTextures.Count; @@ -513,5 +513,5 @@ protected virtual void BlobImported(B blob) { } protected abstract void ImportSound(B blob); protected abstract List GetExistingTypes(); - protected abstract AbstractTextureRemapGroup GetRemapGroup(); + protected abstract TRTextureRemapGroup GetRemapGroup(); } diff --git a/TRDataControl/Utilities/AbstractTRLevelTextureDeduplicator.cs b/TRDataControl/Utilities/AbstractTRLevelTextureDeduplicator.cs deleted file mode 100644 index bba8fecda..000000000 --- a/TRDataControl/Utilities/AbstractTRLevelTextureDeduplicator.cs +++ /dev/null @@ -1,47 +0,0 @@ -using TRDataControl; -using TRImageControl.Packing; -using TRLevelControl.Model; - -namespace TRModelTransporter.Utilities; - -public abstract class AbstractTRLevelTextureDeduplicator - where T : Enum - where L : TRLevelBase -{ - public L Level { get; set; } - - private readonly TRTextureDeduplicator _deduplicator; - - public AbstractTRLevelTextureDeduplicator() - { - _deduplicator = new() - { - UpdateGraphics = true - }; - } - - public void Deduplicate(string remappingPath) - { - TRTexturePacker levelPacker = CreatePacker(Level); - Dictionary> allTextures = new(); - foreach (TRTextile tile in levelPacker.Tiles) - { - allTextures[tile] = new List(tile.Rectangles); - } - - AbstractTextureRemapGroup remapGroup = GetRemapGroup(remappingPath); - - _deduplicator.SegmentMap = allTextures; - _deduplicator.PrecompiledRemapping = remapGroup.Remapping; - _deduplicator.Deduplicate(); - - levelPacker.AllowEmptyPacking = true; - levelPacker.Pack(true); - - CreateRemapper(Level).Remap(); - } - - protected abstract TRTexturePacker CreatePacker(L level); - protected abstract TRTextureRemapper CreateRemapper(L level); - protected abstract AbstractTextureRemapGroup GetRemapGroup(string path); -} diff --git a/TRDataControl/Utilities/Deduplication/TR2LevelTextureDeduplicator.cs b/TRDataControl/Utilities/Deduplication/TR2LevelTextureDeduplicator.cs deleted file mode 100644 index db92bc41f..000000000 --- a/TRDataControl/Utilities/Deduplication/TR2LevelTextureDeduplicator.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Newtonsoft.Json; -using TRDataControl; -using TRImageControl.Packing; -using TRLevelControl.Model; - -namespace TRModelTransporter.Utilities; - -public class TR2LevelTextureDeduplicator : AbstractTRLevelTextureDeduplicator -{ - protected override TRTexturePacker CreatePacker(TR2Level level) - => new TR2TexturePacker(level); - - protected override TRTextureRemapper CreateRemapper(TR2Level level) - => new TR2TextureRemapper(level); - - protected override AbstractTextureRemapGroup GetRemapGroup(string path) - => JsonConvert.DeserializeObject(File.ReadAllText(path)); -} diff --git a/TRDataControl/Helpers/TRModelExtensions.cs b/TRDataControl/Utilities/TRModelExtensions.cs similarity index 100% rename from TRDataControl/Helpers/TRModelExtensions.cs rename to TRDataControl/Utilities/TRModelExtensions.cs diff --git a/TRImageControl/Packing/Textures/ITexturePositionMonitor.cs b/TRImageControl/Packing/Remapping/ITexturePositionMonitor.cs similarity index 100% rename from TRImageControl/Packing/Textures/ITexturePositionMonitor.cs rename to TRImageControl/Packing/Remapping/ITexturePositionMonitor.cs diff --git a/TRImageControl/Packing/Textures/PositionedTexture.cs b/TRImageControl/Packing/Remapping/PositionedTexture.cs similarity index 100% rename from TRImageControl/Packing/Textures/PositionedTexture.cs rename to TRImageControl/Packing/Remapping/PositionedTexture.cs diff --git a/TRImageControl/Packing/Textures/RemapTypes/TR1TextureRemapGroup.cs b/TRImageControl/Packing/Remapping/RemapTypes/TR1TextureRemapGroup.cs similarity index 85% rename from TRImageControl/Packing/Textures/RemapTypes/TR1TextureRemapGroup.cs rename to TRImageControl/Packing/Remapping/RemapTypes/TR1TextureRemapGroup.cs index 298aa790b..81f278ed6 100644 --- a/TRImageControl/Packing/Textures/RemapTypes/TR1TextureRemapGroup.cs +++ b/TRImageControl/Packing/Remapping/RemapTypes/TR1TextureRemapGroup.cs @@ -2,7 +2,7 @@ namespace TRImageControl.Packing; -public class TR1TextureRemapGroup : AbstractTextureRemapGroup +public class TR1TextureRemapGroup : TRTextureRemapGroup { protected override TRTexturePacker CreatePacker(TR1Level level) => new TR1TexturePacker(level); diff --git a/TRImageControl/Packing/Textures/RemapTypes/TR2TextureRemapGroup.cs b/TRImageControl/Packing/Remapping/RemapTypes/TR2TextureRemapGroup.cs similarity index 85% rename from TRImageControl/Packing/Textures/RemapTypes/TR2TextureRemapGroup.cs rename to TRImageControl/Packing/Remapping/RemapTypes/TR2TextureRemapGroup.cs index 4b408a245..859e52885 100644 --- a/TRImageControl/Packing/Textures/RemapTypes/TR2TextureRemapGroup.cs +++ b/TRImageControl/Packing/Remapping/RemapTypes/TR2TextureRemapGroup.cs @@ -2,7 +2,7 @@ namespace TRImageControl.Packing; -public class TR2TextureRemapGroup : AbstractTextureRemapGroup +public class TR2TextureRemapGroup : TRTextureRemapGroup { protected override TRTexturePacker CreatePacker(TR2Level level) => new TR2TexturePacker(level); diff --git a/TRImageControl/Packing/Textures/RemapTypes/TR3TextureRemapGroup.cs b/TRImageControl/Packing/Remapping/RemapTypes/TR3TextureRemapGroup.cs similarity index 85% rename from TRImageControl/Packing/Textures/RemapTypes/TR3TextureRemapGroup.cs rename to TRImageControl/Packing/Remapping/RemapTypes/TR3TextureRemapGroup.cs index 6d17d0605..f628e3a64 100644 --- a/TRImageControl/Packing/Textures/RemapTypes/TR3TextureRemapGroup.cs +++ b/TRImageControl/Packing/Remapping/RemapTypes/TR3TextureRemapGroup.cs @@ -2,7 +2,7 @@ namespace TRImageControl.Packing; -public class TR3TextureRemapGroup : AbstractTextureRemapGroup +public class TR3TextureRemapGroup : TRTextureRemapGroup { protected override TRTexturePacker CreatePacker(TR3Level level) => new TR3TexturePacker(level); diff --git a/TRImageControl/Packing/Textures/RemapTypes/TR4TextureRemapGroup.cs b/TRImageControl/Packing/Remapping/RemapTypes/TR4TextureRemapGroup.cs similarity index 86% rename from TRImageControl/Packing/Textures/RemapTypes/TR4TextureRemapGroup.cs rename to TRImageControl/Packing/Remapping/RemapTypes/TR4TextureRemapGroup.cs index 97aa60d9e..c4da1f677 100644 --- a/TRImageControl/Packing/Textures/RemapTypes/TR4TextureRemapGroup.cs +++ b/TRImageControl/Packing/Remapping/RemapTypes/TR4TextureRemapGroup.cs @@ -2,7 +2,7 @@ namespace TRImageControl.Packing; -public class TR4TextureRemapGroup : AbstractTextureRemapGroup +public class TR4TextureRemapGroup : TRTextureRemapGroup { protected override TRTexturePacker CreatePacker(TR4Level level) => new TR4TexturePacker(level, TRGroupPackingMode.All); diff --git a/TRImageControl/Packing/Textures/RemapTypes/TR5TextureRemapGroup.cs b/TRImageControl/Packing/Remapping/RemapTypes/TR5TextureRemapGroup.cs similarity index 86% rename from TRImageControl/Packing/Textures/RemapTypes/TR5TextureRemapGroup.cs rename to TRImageControl/Packing/Remapping/RemapTypes/TR5TextureRemapGroup.cs index 08e08b5d7..b77c47ece 100644 --- a/TRImageControl/Packing/Textures/RemapTypes/TR5TextureRemapGroup.cs +++ b/TRImageControl/Packing/Remapping/RemapTypes/TR5TextureRemapGroup.cs @@ -2,7 +2,7 @@ namespace TRImageControl.Packing; -public class TR5TextureRemapGroup : AbstractTextureRemapGroup +public class TR5TextureRemapGroup : TRTextureRemapGroup { protected override TRTexturePacker CreatePacker(TR5Level level) => new TR5TexturePacker(level, TRGroupPackingMode.All); diff --git a/TRImageControl/Packing/Textures/TRImageDeduplicator.cs b/TRImageControl/Packing/Remapping/TRImageDeduplicator.cs similarity index 100% rename from TRImageControl/Packing/Textures/TRImageDeduplicator.cs rename to TRImageControl/Packing/Remapping/TRImageDeduplicator.cs diff --git a/TRImageControl/Packing/Textures/AbstractTextureRemapGroup.cs b/TRImageControl/Packing/Remapping/TRTextureRemapGroup.cs similarity index 98% rename from TRImageControl/Packing/Textures/AbstractTextureRemapGroup.cs rename to TRImageControl/Packing/Remapping/TRTextureRemapGroup.cs index dddb1c706..798561460 100644 --- a/TRImageControl/Packing/Textures/AbstractTextureRemapGroup.cs +++ b/TRImageControl/Packing/Remapping/TRTextureRemapGroup.cs @@ -3,7 +3,7 @@ namespace TRImageControl.Packing; -public abstract class AbstractTextureRemapGroup +public abstract class TRTextureRemapGroup where T : Enum where L : TRLevelBase { diff --git a/TRImageControl/Packing/Textures/TextureDependency.cs b/TRImageControl/Packing/Remapping/TextureDependency.cs similarity index 100% rename from TRImageControl/Packing/Textures/TextureDependency.cs rename to TRImageControl/Packing/Remapping/TextureDependency.cs diff --git a/TRImageControl/Packing/Textures/TextureRemap.cs b/TRImageControl/Packing/Remapping/TextureRemap.cs similarity index 100% rename from TRImageControl/Packing/Textures/TextureRemap.cs rename to TRImageControl/Packing/Remapping/TextureRemap.cs diff --git a/TRRandomizerCore/Processors/TR2/TR2TextureDeduplicator.cs b/TRRandomizerCore/Processors/TR2/TR2TextureDeduplicator.cs index 3aa06d96c..a150f338f 100644 --- a/TRRandomizerCore/Processors/TR2/TR2TextureDeduplicator.cs +++ b/TRRandomizerCore/Processors/TR2/TR2TextureDeduplicator.cs @@ -1,6 +1,10 @@ -using TRRandomizerCore.Levels; +using Newtonsoft.Json; +using TRDataControl; using TRGE.Core; +using TRImageControl.Packing; +using TRLevelControl.Model; using TRModelTransporter.Utilities; +using TRRandomizerCore.Levels; namespace TRRandomizerCore.Processors; @@ -8,7 +12,7 @@ internal class TR2TextureDeduplicator : TR2LevelProcessor { public void Deduplicate() { - List processors = new() { new DeduplicationProcessor(this) }; + List processors = new() { new(this) }; int levelSplit = (int)(Levels.Count / _maxThreads); bool beginProcessing = true; @@ -18,7 +22,7 @@ public void Deduplicate() { // Kick start the last one processors[^1].Start(); - processors.Add(new DeduplicationProcessor(this)); + processors.Add(new(this)); } processors[^1].AddLevel(LoadCombinedLevel(lvl)); @@ -49,15 +53,13 @@ public void Deduplicate() internal class DeduplicationProcessor : AbstractProcessorThread { private readonly List _levels; - private readonly TR2LevelTextureDeduplicator _deduplicator; internal override int LevelCount => _levels.Count; internal DeduplicationProcessor(TR2TextureDeduplicator outer) :base(outer) { - _levels = new List(); - _deduplicator = new TR2LevelTextureDeduplicator(); + _levels = new(); } internal void AddLevel(TR2CombinedLevel level) @@ -69,11 +71,32 @@ protected override void ProcessImpl() { foreach (TR2CombinedLevel level in _levels) { - string dedupPath = _outer.GetResourcePath(@"TR2\Textures\Deduplication\" + level.JsonID + "-TextureRemap.json"); + string dedupPath = _outer.GetResourcePath($@"TR2\Textures\Deduplication\{level.JsonID}-TextureRemap.json"); if (File.Exists(dedupPath)) { - _deduplicator.Level = level.Data; - _deduplicator.Deduplicate(dedupPath); + TR2TexturePacker levelPacker = new(level.Data); + Dictionary> allTextures = new(); + foreach (TRTextile tile in levelPacker.Tiles) + { + allTextures[tile] = new List(tile.Rectangles); + } + + TR2TextureRemapGroup remapGroup = JsonConvert.DeserializeObject(File.ReadAllText(dedupPath)); + TRTextureDeduplicator deduplicator = new() + { + UpdateGraphics = true, + SegmentMap = allTextures, + PrecompiledRemapping = remapGroup.Remapping, + }; + + deduplicator.Deduplicate(); + + levelPacker.AllowEmptyPacking = true; + levelPacker.Pack(true); + + TR2TextureRemapper remapper = new(level.Data); + remapper.ResetUnusedTextures(); + remapper.Remap(); _outer.SaveLevel(level); }