Skip to content

Commit

Permalink
fix: prevent counting unchanged refs after encodeAll
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Aug 19, 2020
1 parent b87ba50 commit ec3b136
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
7 changes: 5 additions & 2 deletions Assets/Plugins/Colyseus/Serializer/Schema/ReferenceTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ReferenceTracker

public ReferenceTracker() {}

public void Add(int refId, IRef _ref)
public void Add(int refId, IRef _ref, bool incrementCount = true)
{
int previousCount;

Expand All @@ -26,7 +26,10 @@ public void Add(int refId, IRef _ref)
previousCount = refCounts[refId];
}

refCounts[refId] = previousCount + 1;
if (incrementCount)
{
refCounts[refId] = previousCount + 1;
}
}

public IRef Get(int refId)
Expand Down
10 changes: 2 additions & 8 deletions Assets/Plugins/Colyseus/Serializer/Schema/Schema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,7 @@ public void Decode(byte[] bytes, Iterator it = null, ReferenceTracker refs = nul
}
}

if (value != previousValue)
{
refs.Add(refId, (IRef)value);
}
refs.Add(refId, (IRef)value, (value != previousValue));
}
}
else if (childType == null)
Expand Down Expand Up @@ -420,10 +417,7 @@ public void Decode(byte[] bytes, Iterator it = null, ReferenceTracker refs = nul
}
}

if (valueRef != previousValue)
{
refs.Add(refId, (IRef)value);
}
refs.Add(refId, (IRef)value, (valueRef != previousValue));
}

bool hasChange = (previousValue != value);
Expand Down

0 comments on commit ec3b136

Please sign in to comment.