Skip to content

Commit 102ec3a

Browse files
committed
Add sprite texture position mapping
On data import, object texture positions are mapped so texture monitoring can reference the positions, but sprite textures were missed in this logic. This meant that such sprites couldn't be targeted for texture randomization in levels such as Venice where they don't already exist. Resolves LostArtefacts#844.
1 parent 0ef5b47 commit 102ec3a

2 files changed

Lines changed: 67 additions & 38 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- fixed uncontrolled SFX in TR2 and TR3 causing an error message during randomization (#827)
2424
- fixed cloned enemies in TR1X being left behind if a room is flooded and the original enemy is moved on land (#842)
2525
- fixed Lara potentially starting beyond initial enemy triggers in The Great Wall if the first area is flooded
26+
- fixed flame sprites in some TR2 levels not being targeted for texture randomization (#844)
2627

2728
## [V1.10.2](https://github.com/LostArtefacts/TR-Rando/compare/V1.10.1...V1.10.2) - 2024-12-06
2829
- added support for TR1X 4.6 (#796)

TRDataControl/Transport/TRDataImporter.cs

Lines changed: 66 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -408,62 +408,90 @@ protected void ImportTextures(List<B> blobs)
408408
}
409409
}
410410

411-
Dictionary<T, List<PositionedTexture>> texturePositions = new();
412-
411+
var texturePositions = new Dictionary<T, List<PositionedTexture>>();
413412
foreach (B blob in blobs)
414413
{
415414
if (blob.IsDependencyOnly)
416-
continue;
417-
418-
Dictionary<int, int> remap = new();
419-
foreach (TRTextileRegion region in blob.Textures)
420415
{
421-
foreach (int oldIndex in globalRemap[region.ID].Keys)
422-
{
423-
remap[oldIndex] = globalRemap[region.ID][oldIndex];
424-
}
416+
continue;
425417
}
426418

427-
List<TRMesh> meshes = new();
428-
if (blob.Model != null)
419+
if (blob.Type == TRBlobType.Sprite)
429420
{
430-
meshes.AddRange(blob.Model.Meshes);
421+
MapSpriteTextures(blob, texturePositions);
431422
}
432-
if (blob.StaticMesh != null)
423+
else
433424
{
434-
meshes.Add(blob.StaticMesh.Mesh);
425+
MapObjectTextures(blob, globalRemap, texturePositions);
435426
}
427+
}
436428

437-
IEnumerable<TRMeshFace> faces = meshes
438-
.Where(m => m != null)
439-
.SelectMany(m => m.TexturedFaces);
440-
foreach (TRMeshFace face in faces)
441-
{
442-
face.Texture = (ushort)remap[face.Texture];
443-
}
429+
TextureMonitor?.OnTexturesPositioned(texturePositions);
430+
}
444431

445-
faces = meshes
446-
.Where(m => m != null)
447-
.SelectMany(m => m.ColouredFaces);
448-
foreach (TRMeshFace face in faces)
432+
private static void MapSpriteTextures(B blob, Dictionary<T, List<PositionedTexture>> texturePositions)
433+
{
434+
texturePositions[blob.Alias] = [];
435+
foreach (var segment in blob.Textures.SelectMany(t => t.Segments))
436+
{
437+
texturePositions[blob.Alias].Add(new()
449438
{
450-
face.Texture = ImportColour(blob, face.Texture);
451-
}
439+
OriginalIndex = segment.Index,
440+
TileIndex = segment.Atlas,
441+
Position = segment.Position,
442+
});
443+
}
444+
}
452445

453-
texturePositions[blob.Alias] = new();
454-
foreach (var (oldIndex, newIndex) in remap)
446+
private void MapObjectTextures(B blob,Dictionary<string, Dictionary<int, int>> globalRemap,
447+
Dictionary<T, List<PositionedTexture>> texturePositions)
448+
{
449+
var remap = new Dictionary<int, int>();
450+
foreach (var region in blob.Textures)
451+
{
452+
foreach (int oldIndex in globalRemap[region.ID].Keys)
455453
{
456-
TRObjectTexture texture = Level.ObjectTextures[newIndex];
457-
texturePositions[blob.Alias].Add(new()
458-
{
459-
OriginalIndex = oldIndex,
460-
TileIndex = texture.Atlas,
461-
Position = texture.Position
462-
});
454+
remap[oldIndex] = globalRemap[region.ID][oldIndex];
463455
}
464456
}
465457

466-
TextureMonitor?.OnTexturesPositioned(texturePositions);
458+
var meshes = new List<TRMesh>();
459+
if (blob.Model != null)
460+
{
461+
meshes.AddRange(blob.Model.Meshes);
462+
}
463+
if (blob.StaticMesh != null)
464+
{
465+
meshes.Add(blob.StaticMesh.Mesh);
466+
}
467+
468+
var faces = meshes
469+
.Where(m => m != null)
470+
.SelectMany(m => m.TexturedFaces);
471+
foreach (var face in faces)
472+
{
473+
face.Texture = (ushort)remap[face.Texture];
474+
}
475+
476+
faces = meshes
477+
.Where(m => m != null)
478+
.SelectMany(m => m.ColouredFaces);
479+
foreach (var face in faces)
480+
{
481+
face.Texture = ImportColour(blob, face.Texture);
482+
}
483+
484+
texturePositions[blob.Alias] = [];
485+
foreach (var (oldIndex, newIndex) in remap)
486+
{
487+
var texture = Level.ObjectTextures[newIndex];
488+
texturePositions[blob.Alias].Add(new()
489+
{
490+
OriginalIndex = oldIndex,
491+
TileIndex = texture.Atlas,
492+
Position = texture.Position,
493+
});
494+
}
467495
}
468496

469497
protected void ImportData(List<B> blobs, TRMesh oldDummyMesh)

0 commit comments

Comments
 (0)