Beispiel #1
0
    /// <summary>Creates the "custom content" Hashtable that is sent as position update.</summary>
    /// <remarks>
    /// As with event codes, the content of this event is arbitrary and "made up" for this demo.
    /// Your game (e.g.) could use floats as positions or you send a height and actions or state info.
    /// It makes sense to use numbers (best: bytes) as Hashtable key type, cause they are use less space.
    /// But this is not a requirement as you see in WriteEvColor.
    ///
    /// The position can only go up to 128 in this demo, so a byte[] technically is the best (leanest)
    /// choice here.
    /// </remarks>
    /// <returns>Hashtable for event "move" to update others</returns>
    public Hashtable WriteEvInput()
    {
        Hashtable evContent       = new Hashtable();
        int       currentFrameNum = RollbackManager.Instance.GetIndexFrameNumFromStart();
        int       numFramesToSend = CustomConstants.NetworkBufferSize;

        if (numFramesToSend >= currentFrameNum)
        {
            numFramesToSend = currentFrameNum - 1;
        }

        evContent[0] = numFramesToSend; // Last x frames to pass through the
        evContent[1] = currentFrameNum; // Current frame number
        RollbackElementRollbackInputBaseActions playerInputHistory = RollbackManager.rbInputManager.GetPlayerInputHistory(ActorNumber - 1);

        for (int i = 0; i < numFramesToSend; i++)
        {
            RollbackInputBaseActions rollbackInputBaseActions = playerInputHistory.GetValue(currentFrameNum - i);
            evContent[2 + i] = rollbackInputBaseActions.PackBits();
        }
        return(evContent);
    }