Ejemplo n.º 1
0
    /// <summary>
    /// Internally used for building and dispatching entity updates, build a full serialization of auto tokens and ID's
    /// Due to inconsistent handling/calling contexts, ID's are added safely
    /// </summary>
    /// <returns>0 if nothing is sent, 1 if there is content to send, 2 if content should be sent reliably</returns>
    public int SerializeAuto(Hashtable h)
    {
        var tH = tokenHandler;

        var time = Time.realtimeSinceStartup;

        bool reliableFlag = false;
        bool isSending    = false;

        foreach (var c in tH.autoTokens)
        {
            if (this[c] < time)
            {
                this[c]   = time + tH.updateTimes[c];
                isSending = true;

                h.Add(c, tH.get(c, this));

                if (!reliableFlag)
                {
                    reliableFlag = tH.reliableTokens.Contains(c);
                }
            }
        }

        if (isSending)
        {
            SerializeAlwaysTokensSafely(h);
            //toUpdate.AddRange(tH.alwaysSendTokens);
        }

        // If none of the tokens actually updated, return 0
        // Otherwise, return 1 for a normal update, 2 for a reliable update
        if (!isSending)
        {
            return(0);
        }

        h.AddOrSet(PConst.eidChar, EntityID);
        h.AddOrSet(PConst.athChar, authorityID);

        //SerializeToken(toUpdate.Distinct().ToArray());

        return(reliableFlag ? 2 : 1);
    }