/// <summary> Working with a given connection, a List of all views, SliceSize and Position, /// the connection has its scope updated for the given position/slice of the provided list /// of views. If views.Count == 512, Position == 64, and slice size == 32, connection will /// have scope updated for views occupying index 64 through 96 of the views List only. </summary> internal void UpdateScopeRange(NetConnection connection, List <NetView> views) { if (Position >= views.Count) { Position = 0; } int count = SliceSize; NetScope scope = connection.Scope; for (int i = Position; i < views.Count; i++) { var view = views[i]; if (view != connection.View && view.Server == Socket.Self && connection.InGroup(view.Group) && view.CanInstantiateFor(connection) && UpdateScope(scope, view)) { if (scope.In(view.Id)) { view.SendInstantiateData(connection); } else { ViewManager.SendOutOfScope(view.Id, connection); } } count--; if (count == 0) { break; } } }
/// <summary> The provided scope is updated if the provided view has gone in or out of scope. /// False is returned if there is no change. </summary> internal bool UpdateScope(NetScope source, NetView view) { bool scopeChanged = false; float distance = Vector3.Distance(source.Position, view.Scope.Position); // If the source scope is configured to override, use its scope distances instead: var rulesScope = source.TakePrecedence ? source : view.Scope; if (view.Scope.CalcDisabled || distance > rulesScope.OutScopeDist) { if (!source.In(view.Id)) { return(false); } scopeChanged = true; source.SetOut(view.Id); } else if (distance < rulesScope.InScopeDist) { if (!source.In(view.Id)) { scopeChanged = true; } if (distance < rulesScope.LevelOne) { source.SetIn(view.Id, 1); } else if (distance < rulesScope.LevelTwo) { source.SetIn(view.Id, 2); } else { source.SetIn(view.Id, 3); } } return(scopeChanged); }
/// <summary> The provided scope is updated if the provided view has gone in or out of scope. /// False is returned if there is no change. </summary> internal bool UpdateScope(NetScope source, NetView view) { bool scopeChanged = false; float distance = Vector3.Distance(source.Position, view.Scope.Position); // If the source scope is configured to override, use its scope distances instead: var rulesScope = source.TakePrecedence ? source : view.Scope; if (view.Scope.CalcDisabled || distance > rulesScope.OutScopeDist) { if (!source.In(view.Id)) return false; scopeChanged = true; source.SetOut(view.Id); } else if (distance < rulesScope.InScopeDist) { if (!source.In(view.Id)) scopeChanged = true; if (distance < rulesScope.LevelOne) source.SetIn(view.Id, 1); else if (distance < rulesScope.LevelTwo) source.SetIn(view.Id, 2); else source.SetIn(view.Id, 3); } return scopeChanged; }