Skip to content

Commit 8ad2e03

Browse files
committed
Fixing outfit instance caching algorithm
use sprite id instead of sprite index might be the same for different frame groups.
1 parent 5d59a51 commit 8ad2e03

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

OpenTibia/Assets/Scripts/Core/Appearances/OutfitInstance.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class OutfitInstance : AppearanceInstance
2020
private Color _legsColor = Color.white;
2121
private Color _detailColor = Color.white;
2222

23-
private Dictionary<int, MaterialPropertyBlock> _channelProps = new Dictionary<int, MaterialPropertyBlock>();
23+
private Dictionary<uint, MaterialPropertyBlock> _channelProps = new Dictionary<uint, MaterialPropertyBlock>();
2424

2525
private int _phase = 0;
2626
private bool _walking = false;
@@ -97,21 +97,24 @@ public override void Draw(CommandBuffer commandBuffer, Vector2Int screenPosition
9797

9898
int spriteIndex = GetSpriteIndex(-1, patternX, patternY, patternZ);
9999

100-
OpenTibiaUnity.AppearanceStorage.GetSprite(ActiveFrameGroup.SpriteInfo.SpriteIDs[spriteIndex], out CachedSprite baseSprite);
101-
OpenTibiaUnity.AppearanceStorage.GetSprite(ActiveFrameGroup.SpriteInfo.SpriteIDs[spriteIndex + 1], out CachedSprite channelSprite);
100+
var baseSpriteId = ActiveFrameGroup.SpriteInfo.SpriteIDs[spriteIndex];
101+
var channelSpriteId = ActiveFrameGroup.SpriteInfo.SpriteIDs[++spriteIndex];
102+
103+
OpenTibiaUnity.AppearanceStorage.GetSprite(baseSpriteId, out CachedSprite baseSprite);
104+
OpenTibiaUnity.AppearanceStorage.GetSprite(channelSpriteId, out CachedSprite channelSprite);
102105

103106
// if these are not loaded yet we should still continue to
104107
// ensure that next time all layers are loaded!
105108
if (baseSprite == null || channelSprite == null)
106109
dontDraw = true;
107110

108111
if (!dontDraw) {
109-
if (!_channelProps.TryGetValue(spriteIndex, out MaterialPropertyBlock props)) {
112+
if (!_channelProps.TryGetValue(channelSpriteId, out MaterialPropertyBlock props)) {
110113
props = new MaterialPropertyBlock();
111114
baseSprite.GenerateMaterialProps(props);
112115
channelSprite.GenerateChannelsMaterialProps(props);
113116
UpdateMaterialProppertyBlock(props);
114-
_channelProps.Add(spriteIndex, props);
117+
_channelProps.Add(channelSpriteId, props);
115118
}
116119

117120
InternalDrawTo(commandBuffer, screenPosition, zoom, highlighted, highlightOpacity, baseSprite);

0 commit comments

Comments
 (0)