Skip to content

Commit

Permalink
Reorganise folder structures (LostArtefacts#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm86 authored May 7, 2024
1 parent 201294b commit e7a4932
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ private bool GetResult<T>(TREntity<T> entity)
bool result = true;
if (EntityType.HasValue)
{
result &= EqualityComparer<T>.Default.Equals(entity.TypeID, (T)(object)(int)EntityType.Value);
result &= EqualityComparer<T>.Default.Equals(entity.TypeID, (T)(object)(uint)EntityType.Value);
}
if (EntityTypes != null)
{
result &= EntityTypes.Any(e => EqualityComparer<T>.Default.Equals(entity.TypeID, (T)(object)(int)e));
result &= EntityTypes.Any(e => EqualityComparer<T>.Default.Equals(entity.TypeID, (T)(object)(uint)e));
}
if (Invisible.HasValue)
{
Expand Down
2 changes: 1 addition & 1 deletion TRDataControl/Transport/TR1/TR1DataImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected override List<TR1Type> GetExistingTypes()
protected override TRTextureRemapper<TR1Level> CreateRemapper(TR1Level level)
=> new TR1TextureRemapper(level);

protected override AbstractTextureRemapGroup<TR1Type, TR1Level> GetRemapGroup()
protected override TRTextureRemapGroup<TR1Type, TR1Level> GetRemapGroup()
=> JsonConvert.DeserializeObject<TR1TextureRemapGroup>(File.ReadAllText(TextureRemapPath));

protected override bool IsMasterType(TR1Type type)
Expand Down
2 changes: 1 addition & 1 deletion TRDataControl/Transport/TR2/TR2DataImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override List<TR2Type> GetExistingTypes()
protected override TRTextureRemapper<TR2Level> CreateRemapper(TR2Level level)
=> new TR2TextureRemapper(level);

protected override AbstractTextureRemapGroup<TR2Type, TR2Level> GetRemapGroup()
protected override TRTextureRemapGroup<TR2Type, TR2Level> GetRemapGroup()
=> JsonConvert.DeserializeObject<TR2TextureRemapGroup>(File.ReadAllText(TextureRemapPath));

protected override bool IsMasterType(TR2Type type)
Expand Down
2 changes: 1 addition & 1 deletion TRDataControl/Transport/TR3/TR3DataImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override List<TR3Type> GetExistingTypes()
protected override TRTextureRemapper<TR3Level> CreateRemapper(TR3Level level)
=> new TR3TextureRemapper(level);

protected override AbstractTextureRemapGroup<TR3Type, TR3Level> GetRemapGroup()
protected override TRTextureRemapGroup<TR3Type, TR3Level> GetRemapGroup()
=> JsonConvert.DeserializeObject<TR3TextureRemapGroup>(File.ReadAllText(TextureRemapPath));

protected override bool IsMasterType(TR3Type type)
Expand Down
2 changes: 1 addition & 1 deletion TRDataControl/Transport/TR4/TR4DataImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected override List<TR4Type> GetExistingTypes()
protected override TRTextureRemapper<TR4Level> CreateRemapper(TR4Level level)
=> new TR4TextureRemapper(level);

protected override AbstractTextureRemapGroup<TR4Type, TR4Level> GetRemapGroup()
protected override TRTextureRemapGroup<TR4Type, TR4Level> GetRemapGroup()
=> JsonConvert.DeserializeObject<TR4TextureRemapGroup>(File.ReadAllText(TextureRemapPath));

protected override bool IsMasterType(TR4Type type)
Expand Down
2 changes: 1 addition & 1 deletion TRDataControl/Transport/TR5/TR5DataImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected override List<TR5Type> GetExistingTypes()
protected override TRTextureRemapper<TR5Level> CreateRemapper(TR5Level level)
=> new TR5TextureRemapper(level);

protected override AbstractTextureRemapGroup<TR5Type, TR5Level> GetRemapGroup()
protected override TRTextureRemapGroup<TR5Type, TR5Level> GetRemapGroup()
=> JsonConvert.DeserializeObject<TR5TextureRemapGroup>(File.ReadAllText(TextureRemapPath));

protected override bool IsMasterType(TR5Type type)
Expand Down
6 changes: 3 additions & 3 deletions TRDataControl/Transport/TRDataImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ protected void RemoveData()
staleTextures = new(staleTextures.Distinct());
if (staleTextures.Count > 0)
{
AbstractTextureRemapGroup<T, L> remapGroup = TextureRemapPath == null ? null : GetRemapGroup();
TRTextureRemapGroup<T, L> remapGroup = TextureRemapPath == null ? null : GetRemapGroup();
CreateRemapper(Level)?.RemoveUnusedTextures(staleTextures,
(tile, bounds) => remapGroup?.CanRemoveRectangle(tile, bounds, TypesToRemove) ?? true);
}
Expand Down Expand Up @@ -349,7 +349,7 @@ protected void ImportTextures(List<B> 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;
Expand Down Expand Up @@ -513,5 +513,5 @@ protected virtual void BlobImported(B blob) { }
protected abstract void ImportSound(B blob);

protected abstract List<T> GetExistingTypes();
protected abstract AbstractTextureRemapGroup<T, L> GetRemapGroup();
protected abstract TRTextureRemapGroup<T, L> GetRemapGroup();
}
47 changes: 0 additions & 47 deletions TRDataControl/Utilities/AbstractTRLevelTextureDeduplicator.cs

This file was deleted.

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TRImageControl.Packing;

public class TR1TextureRemapGroup : AbstractTextureRemapGroup<TR1Type, TR1Level>
public class TR1TextureRemapGroup : TRTextureRemapGroup<TR1Type, TR1Level>
{
protected override TRTexturePacker CreatePacker(TR1Level level)
=> new TR1TexturePacker(level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TRImageControl.Packing;

public class TR2TextureRemapGroup : AbstractTextureRemapGroup<TR2Type, TR2Level>
public class TR2TextureRemapGroup : TRTextureRemapGroup<TR2Type, TR2Level>
{
protected override TRTexturePacker CreatePacker(TR2Level level)
=> new TR2TexturePacker(level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TRImageControl.Packing;

public class TR3TextureRemapGroup : AbstractTextureRemapGroup<TR3Type, TR3Level>
public class TR3TextureRemapGroup : TRTextureRemapGroup<TR3Type, TR3Level>
{
protected override TRTexturePacker CreatePacker(TR3Level level)
=> new TR3TexturePacker(level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TRImageControl.Packing;

public class TR4TextureRemapGroup : AbstractTextureRemapGroup<TR4Type, TR4Level>
public class TR4TextureRemapGroup : TRTextureRemapGroup<TR4Type, TR4Level>
{
protected override TRTexturePacker CreatePacker(TR4Level level)
=> new TR4TexturePacker(level, TRGroupPackingMode.All);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TRImageControl.Packing;

public class TR5TextureRemapGroup : AbstractTextureRemapGroup<TR5Type, TR5Level>
public class TR5TextureRemapGroup : TRTextureRemapGroup<TR5Type, TR5Level>
{
protected override TRTexturePacker CreatePacker(TR5Level level)
=> new TR5TexturePacker(level, TRGroupPackingMode.All);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace TRImageControl.Packing;

public abstract class AbstractTextureRemapGroup<T, L>
public abstract class TRTextureRemapGroup<T, L>
where T : Enum
where L : TRLevelBase
{
Expand Down
41 changes: 32 additions & 9 deletions TRRandomizerCore/Processors/TR2/TR2TextureDeduplicator.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
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;

internal class TR2TextureDeduplicator : TR2LevelProcessor
{
public void Deduplicate()
{
List<DeduplicationProcessor> processors = new() { new DeduplicationProcessor(this) };
List<DeduplicationProcessor> processors = new() { new(this) };
int levelSplit = (int)(Levels.Count / _maxThreads);

bool beginProcessing = true;
Expand All @@ -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));
Expand Down Expand Up @@ -49,15 +53,13 @@ public void Deduplicate()
internal class DeduplicationProcessor : AbstractProcessorThread<TR2TextureDeduplicator>
{
private readonly List<TR2CombinedLevel> _levels;
private readonly TR2LevelTextureDeduplicator _deduplicator;

internal override int LevelCount => _levels.Count;

internal DeduplicationProcessor(TR2TextureDeduplicator outer)
:base(outer)
{
_levels = new List<TR2CombinedLevel>();
_deduplicator = new TR2LevelTextureDeduplicator();
_levels = new();
}

internal void AddLevel(TR2CombinedLevel level)
Expand All @@ -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<TRTextile, List<TRTextileRegion>> allTextures = new();
foreach (TRTextile tile in levelPacker.Tiles)
{
allTextures[tile] = new List<TRTextileRegion>(tile.Rectangles);
}

TR2TextureRemapGroup remapGroup = JsonConvert.DeserializeObject<TR2TextureRemapGroup>(File.ReadAllText(dedupPath));
TRTextureDeduplicator<TR2Type> 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);
}
Expand Down

0 comments on commit e7a4932

Please sign in to comment.