Skip to content

Commit

Permalink
Make larger batches of contact adding
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Apr 9, 2024
1 parent 20d1905 commit 34dd37f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions FlexibleContactsSort/LagFreeContactsLoading.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FrooxEngine;
using Elements.Core;
using FrooxEngine;
using HarmonyLib;
using MonkeyLoader.Patching;
using MonkeyLoader.Resonite;
Expand All @@ -17,6 +18,8 @@ namespace FlexibleContactsSort
[HarmonyPatch(typeof(ContactsDialog), nameof(ContactsDialog.OnAttach))]
internal sealed class LagFreeContactsLoading : ResoniteMonkey<LagFreeContactsLoading>
{
private const int ContactsPerUpdate = 8;

internal static bool AllowSorting { get; private set; } = true;

protected override IEnumerable<IFeaturePatch> GetFeaturePatches() => Enumerable.Empty<IFeaturePatch>();
Expand All @@ -37,12 +40,18 @@ private static void AddContactItems(ContactsDialog contactsDialog)

await default(ToWorld);

foreach (var (contactData, _) in contactsSortInfo)
var segments = contactsSortInfo.Length / ContactsPerUpdate;
for (var segment = 0; segment < segments; ++segment)
{
contactsDialog.UpdateContactItem(contactData);
for (var i = 0; i <= ContactsPerUpdate; ++i)
contactsDialog.UpdateContactItem(contactsSortInfo[ContactsPerUpdate * segment + i].contactData);

await default(NextUpdate);
}

for (var i = segments * ContactsPerUpdate; i < contactsSortInfo.Length; ++i)
contactsDialog.UpdateContactItem(contactsSortInfo[i].contactData);

AllowSorting = true;
});

Expand Down

0 comments on commit 34dd37f

Please sign in to comment.