Exemplo n.º 1
0
    public float CalculateRelevance(P2PPeer peer, out Relevance.ERelevanceCalculationResult result)
    {
        if (peer.m_Representation == null)
        {
            result = Relevance.ERelevanceCalculationResult.Inactive;
            return(0f);
        }
        if (!base.GetReplicationComponent().enabled&& !peer.IsLocalPeer())
        {
            result = Relevance.ERelevanceCalculationResult.Inactive;
            return(0f);
        }
        float b    = peer.m_Representation.GetWorldPosition().Distance(this.GetRelevanceReferencePosition());
        float num  = this.m_Relevance.ContainsKey(peer) ? this.m_Relevance[peer] : 0f;
        float num2 = -1f;

        for (int i = 0; i < this.m_CustomCalculators.Length; i++)
        {
            float num3 = this.m_CustomCalculators[i].CalculateRelevance(peer.m_Representation, peer == base.ReplGetOwner());
            if (num3 != -1f)
            {
                num2 = System.Math.Max(num3, num2);
            }
        }
        if (num2 == -1f)
        {
            num2 = CJTools.Math.GetProportionalClamp(1f, 0f, b, this.GetMaxRelevanceRange(), this.GetMinRelevanceRange());
        }
        if (num2 <= 0.1f)
        {
            if (num > 0.1f)
            {
                result = Relevance.ERelevanceCalculationResult.ToDeactivate;
            }
            else
            {
                result = Relevance.ERelevanceCalculationResult.Inactive;
            }
        }
        else if (num2 >= 0.2f)
        {
            if (num < 0.2f)
            {
                result = Relevance.ERelevanceCalculationResult.ToActivate;
            }
            else
            {
                result = Relevance.ERelevanceCalculationResult.Active;
            }
        }
        else
        {
            result = Relevance.ERelevanceCalculationResult.NoChange;
        }
        this.m_Relevance[peer] = num2;
        return(num2);
    }
Exemplo n.º 2
0
 public void OnReplicatorUpdate(bool force_update = false)
 {
     if (!base.enabled || !base.gameObject.activeSelf)
     {
         return;
     }
     if (!this.ReplIsOwner() && (this.ReplGetOwner().IsValid() || !ReplTools.AmIMaster()))
     {
         return;
     }
     if (force_update || this.m_LastReplicationTimeReal < Time.realtimeSinceStartup - this.GetReplicationIntervalMin())
     {
         this.m_LastReplicationTime     = Time.time;
         this.m_LastReplicationTimeReal = Time.realtimeSinceStartup;
         if (this.GetRelevanceComponent)
         {
             ReplicationComponent.s_SendToPeers.Reset();
             foreach (KeyValuePair <P2PPeer, float> keyValuePair in this.GetRelevanceComponent.m_Relevance)
             {
                 P2PPeer key = keyValuePair.Key;
                 if (!key.IsLocalPeer() && keyValuePair.Value > 0.1f)
                 {
                     float num = 0f;
                     this.m_LastPeerReplicationTime.TryGetValue(key, out num);
                     if (num + this.CalculateReplicationInterval(keyValuePair.Key) < Time.time)
                     {
                         this.m_LastPeerReplicationTime[key] = Time.time;
                         ReplicationComponent.s_SendToPeers.Add(key);
                     }
                 }
             }
             if (ReplicationComponent.s_SendToPeers.count > 0)
             {
                 this.ReplicationSend(false, ReplicationComponent.s_SendToPeers);
                 return;
             }
         }
         else
         {
             this.ReplicationSend(false, null);
         }
     }
 }