Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Source/Client/Patches/VTRSyncPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ static bool Prefix(Thing thing, ref int __result)
if (Multiplayer.Client == null)
return true;

VTRSync.FlushPendingViewedMapUpdate();

// Keep the synchronized update rate until animation timing can be
// brought back in line with the vanilla value.
__result = VTRSync.GetSynchronizedUpdateRate(thing);
Expand Down Expand Up @@ -55,18 +57,48 @@ static class VTRSync
public const int InvalidMapId = -1;
public static int lastMovedToMapId = InvalidMapId;
public static int lastSentAtTick = -1;
private static int pendingPreviousMapId = InvalidMapId;
private static int pendingCurrentMapId = InvalidMapId;

// Vtr rates
public const int MaximumVtr = 15;
public const int MinimumVtr = 1;

public static int GetSynchronizedUpdateRate(Thing thing) => thing?.MapHeld?.AsyncTime()?.VTR ?? MaximumVtr;

public static void FlushPendingViewedMapUpdate()
{
if (Multiplayer.reloading)
return;

if (pendingPreviousMapId == InvalidMapId && pendingCurrentMapId == InvalidMapId)
return;

int previous = pendingPreviousMapId;
int current = pendingCurrentMapId;
pendingPreviousMapId = InvalidMapId;
pendingCurrentMapId = InvalidMapId;

SendViewedMapUpdateCore(previous, current);
}

public static void SendViewedMapUpdate(int previous, int current)
{
if (Multiplayer.reloading)
{
if (pendingPreviousMapId == InvalidMapId && pendingCurrentMapId == InvalidMapId)
pendingPreviousMapId = previous;
pendingCurrentMapId = current;
return;
}

FlushPendingViewedMapUpdate();

SendViewedMapUpdateCore(previous, current);
}

private static void SendViewedMapUpdateCore(int previous, int current)
{
string warn = string.Empty;
if (previous != lastMovedToMapId)
warn = $" mismatch between expected previous map {previous} and last moved to map {lastMovedToMapId}";
Expand All @@ -81,6 +113,8 @@ public static void Reset()
{
lastMovedToMapId = InvalidMapId;
lastSentAtTick = -1;
pendingPreviousMapId = InvalidMapId;
pendingCurrentMapId = InvalidMapId;
}
}

Expand All @@ -91,6 +125,8 @@ static void Prefix(Map value)
{
if (Multiplayer.Client == null) return;

VTRSync.FlushPendingViewedMapUpdate();

try
{
// WorldRenderModePatch will handle it
Expand Down Expand Up @@ -133,6 +169,8 @@ static void Postfix(WorldRenderMode __result)
{
if (Multiplayer.Client == null) return;

VTRSync.FlushPendingViewedMapUpdate();

try
{
// Detect transition to world map (Planet mode)
Expand Down
Loading