Skip to content

Commit

Permalink
robust
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth committed Sep 3, 2024
1 parent 6b7a8b2 commit 83c2f78
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions Robust.Shared/Prototypes/PrototypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,11 @@ public void ReloadPrototypes(Dictionary<Type, HashSet<string>> modified,
var prototypeTypeOrder = modified.Keys.ToList();
prototypeTypeOrder.Sort(SortPrototypesByPriority);

// Keep track of what has been pushed so we don't double-work common parents.
var pushed = new Dictionary<Type, HashSet<string>>();
// Track what prototypes actually get modified as a result of the reload.
// This is for big files to ensure we don't flag 100 prototypes as modified when only 1 may be.
var changedPrototypes = new Dictionary<Type, HashSet<string>>();
var modifiedKinds = new HashSet<KindData>();

foreach (var kind in prototypeTypeOrder)
Expand Down Expand Up @@ -427,6 +431,7 @@ public void ReloadPrototypes(Dictionary<Type, HashSet<string>> modified,
kindData.UnfrozenInstances ??= kindData.Instances.ToDictionary();
kindData.UnfrozenInstances[id] = prototype;
modifiedKinds.Add(kindData);
changedPrototypes.GetOrNew(kind).Add(id);
}
}

Expand All @@ -437,11 +442,28 @@ public void ReloadPrototypes(Dictionary<Type, HashSet<string>> modified,
Freeze(modifiedKinds);
if (modifiedKinds.Any(x => x.Type == typeof(EntityPrototype) || x.Type == typeof(EntityCategoryPrototype)))
UpdateCategories();
#endif

var byType = new Dictionary<Type, PrototypesReloadedEventArgs.PrototypeChangeSet>();

foreach (var (type, pushedSet) in pushed)
foreach (var (type, pushedSet) in changedPrototypes)
{
var kindData = _kinds[type];
var set = new Dictionary<string, IPrototype>(pushedSet.Count);

foreach (var pId in pushedSet)
{
if (!kindData.Instances.TryGetValue(pId, out var prototype))
continue;

set[pId] = prototype;
}

byType[type] = new PrototypesReloadedEventArgs.PrototypeChangeSet(set);
}
#else
var byType = new Dictionary<Type, PrototypesReloadedEventArgs.PrototypeChangeSet>();

foreach (var (type, pushedSet) in modified)
{
var kindData = _kinds[type];
var set = new Dictionary<string, IPrototype>(pushedSet.Count);
Expand All @@ -456,6 +478,7 @@ public void ReloadPrototypes(Dictionary<Type, HashSet<string>> modified,

byType[type] = new PrototypesReloadedEventArgs.PrototypeChangeSet(set);
}
#endif

// Don't raise the event if types match.
var types = new ValueList<Type>(byType.Keys);
Expand Down

0 comments on commit 83c2f78

Please sign in to comment.