void SendStatePacket()
    {
        NetOutgoingMessage inputPacket = GetClient().CreateMessage();

        inputPacket.Write((UInt32)core.PacketType.kState, PacketTypeLengthBits);
        mDeliveryNotificationManager.WriteState(inputPacket);


        var characterState = new core.CharacterState();

        if (LocalCharacter != null)
        {
            characterState.location = LocalCharacter.GetPosition();
            characterState.velocity = LocalCharacter.GetVelocity();
        }
        characterState.timeStamp = core.Timing.sInstance.GetFrameStartTime();

        characterState.Write(inputPacket);

#if UNITY_EDITOR && USE_CLIENT_STATE_RECORD
        if (ACScrambleBattle.GetState().State == EACBattleState.PLAY)
        {
            System.IO.FileStream   fs = new System.IO.FileStream($"client_record", System.IO.FileMode.Append, System.IO.FileAccess.Write);
            System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
            bw.Write((int)core.PacketType.kState);
            characterState.Write(bw);
            bw.Close();
            fs.Close();
        }
#endif

        inputPacket.Write((UInt32)AIStates.Count, (int)core.AIPlayer.MaxAIPlayerBit);
        foreach (var state in AIStates.Values)
        {
            state.Write(inputPacket);
        }

        //Debug.Log($"send location{characterState.location}, velocity{characterState.velocity}");


        SendMessage(inputPacket, NetDeliveryMethod.Unreliable);
    }
Exemplo n.º 2
0
    void SendInputPacket()
    {
        //only send if there's any input to sent!
        var moveList = InputManager.sInstance.GetMoveList();

        if (moveList.HasMoves())
        {
            NetOutgoingMessage inputPacket = GetClient().CreateMessage();

            inputPacket.Write((UInt32)core.PacketType.kInputCC);

            mDeliveryNotificationManager.WriteState(inputPacket);

            //eventually write the 3 latest moves so they have three chances to get through...
            int moveCount      = moveList.GetMoveCount();
            int firstMoveIndex = moveCount - 3;
            if (firstMoveIndex < 0)
            {
                firstMoveIndex = 0;
            }
            //auto move = moveList.begin() + firstMoveIndex;

            //only need two bits to write the move count, because it's 0, 1, 2 or 3
            inputPacket.Write((uint32_t)(moveCount - firstMoveIndex), 2);

            ++debug_index;
            for (; firstMoveIndex < moveCount; ++firstMoveIndex)
            {
                //Debug.Log("send move info " + debug_index + ", moveCount : " +  moveCount + ", firstMoveIndex :" + firstMoveIndex + ", timestamp:" + moveList.mMoves[firstMoveIndex].GetTimestamp() + ", delta:" + moveList.mMoves[firstMoveIndex].GetDeltaTime());
                ///would be nice to optimize the time stamp...
                moveList.mMoves[firstMoveIndex].Write(inputPacket);
            }

            GetClient().SendMessage(inputPacket, NetDeliveryMethod.Unreliable);
        }
    }