]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix decal megadiffs (#30732)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Fri, 9 Aug 2024 05:47:23 +0000 (15:47 +1000)
committerGitHub <noreply@github.com>
Fri, 9 Aug 2024 05:47:23 +0000 (15:47 +1000)
Just preserves the uids and doesn't care about trying to re-map the decals lower. We have a uint to work with anyway.

Content.Shared/Decals/DecalGridChunkCollectionTypeSerializer.cs

index ba89c8a695935ea5583f1d186ff8a69e27b724f2..85364fe5f40cda23698e48be87d253dc2fcd5a48 100644 (file)
@@ -62,41 +62,18 @@ namespace Content.Shared.Decals
                 dictionary = serializationManager.Read<Dictionary<Vector2i, DecalChunk>>(node, hookCtx, context, notNullableOverride: true);
             }
 
-            var uids = new SortedSet<uint>();
-            var uidChunkMap = new Dictionary<uint, Vector2i>();
-            var allIndices = dictionary.Keys.ToList();
-            allIndices.Sort((x, y) => x.X == y.X ? x.Y.CompareTo(y.Y) : x.X.CompareTo(y.X));
+            uint nextIndex = 0;
 
-            foreach (var indices in allIndices)
+            foreach (var decals in dictionary.Values)
             {
-                var decals = dictionary[indices];
-                var decalUids = decals.Decals.Keys.ToList();
-                decalUids.Sort();
-
-                foreach (var uid in decalUids)
+                foreach (var uid in decals.Decals.Keys)
                 {
-                    uids.Add(uid);
-                    uidChunkMap[uid] = indices;
+                    nextIndex = Math.Max(uid, nextIndex);
                 }
             }
 
-            var uidMap = new Dictionary<uint, uint>();
-            uint nextIndex = 0;
-            foreach (var uid in uids)
-            {
-                uidMap[uid] = nextIndex++;
-            }
-
-            var newDict = new Dictionary<Vector2i, DecalChunk>();
-            foreach (var (oldUid, newUid) in uidMap)
-            {
-                var indices = uidChunkMap[oldUid];
-                if(!newDict.ContainsKey(indices))
-                    newDict[indices] = new();
-                newDict[indices].Decals[newUid] = dictionary[indices].Decals[oldUid];
-            }
-
-            return new DecalGridChunkCollection(newDict) { NextDecalId = nextIndex };
+            nextIndex++;
+            return new DecalGridChunkCollection(dictionary) { NextDecalId = nextIndex };
         }
 
         public DataNode Write(ISerializationManager serializationManager,
@@ -109,8 +86,6 @@ namespace Content.Shared.Decals
 
             var allData = new MappingDataNode();
             // Want consistent chunk + decal ordering so diffs aren't mangled
-            var chunks = new List<Vector2i>(value.ChunkCollection.Keys);
-            chunks.Sort((x, y) => x.X == y.X ? x.Y.CompareTo(y.Y) : x.X.CompareTo(y.X));
             var nodes = new SequenceDataNode();
 
             // Assuming decal indices stay consistent:
@@ -122,9 +97,6 @@ namespace Content.Shared.Decals
             // Build all of the decal lookups first.
             foreach (var chunk in value.ChunkCollection.Values)
             {
-                var sortedDecals = new List<uint>(chunk.Decals.Keys);
-                sortedDecals.Sort();
-
                 foreach (var (uid, decal) in chunk.Decals)
                 {
                     var data = new DecalData(decal);