Skip to content

Commit

Permalink
fix: fixing IsValidDirection method
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Mar 31, 2023
1 parent b72e9fa commit e437a10
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions Assets/Mirage/Runtime/SyncSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public bool ShouldSyncFrom(NetworkIdentity identity)
{
// only write if either owner or ObserversOnly
// otherwise we can just skip the component
return (To & SyncTo.Observers) != 0;
return (To & (SyncTo.Owner | SyncTo.ObserversOnly)) != 0;
}

if ((From & SyncFrom.Owner) != 0 && identity.HasAuthority)
Expand All @@ -76,6 +76,17 @@ public bool CopyToObservers()

public static bool IsValidDirection(SyncFrom from, SyncTo to)
{
var fromNone = from == SyncFrom.None;
var toNone = to == SyncTo.None;

// both true, allowed
if (fromNone && toNone)
return true;
// both false, allowed, but 1 false not allowed
if (fromNone != toNone)
return false;


if ((from & SyncFrom.Owner) != 0)
{
// if from owner,
Expand All @@ -89,8 +100,27 @@ public static bool IsValidDirection(SyncFrom from, SyncTo to)
{
// if from server,
// must be to Owner or Observers
// Observers is optional
if ((to & SyncTo.Owner) == 0)
// either is fine
if ((to & (SyncTo.Owner | SyncTo.ObserversOnly)) == 0)
return false;
}


if ((to & SyncTo.Owner) != 0)
{
// if to owner, from server must be true
// this check if different than above,
// it is making sure From.Owner and To.Owner aren't both true without From.Server also being true
if ((from & SyncFrom.Server) == 0)
return false;
}

if ((to & SyncTo.Server) != 0)
{
// if to owner, from server must be true
// this check if different than above,
// it is making sure From.Owner and To.Owner aren't both true without From.Server also being true
if ((from & SyncFrom.Owner) == 0)
return false;
}

Expand All @@ -116,9 +146,6 @@ public enum SyncTo : byte
Owner = 1,
ObserversOnly = 2,
Server = 4,

Observers = Owner | ObserversOnly,
ServerAndObservers = Server | ObserversOnly
}

public enum SyncTiming : byte
Expand Down

0 comments on commit e437a10

Please sign in to comment.