internal void OnNetMovement(S2C_Move ret)
        {
            // 验证时间戳
            int index = NetMovementMessages.FindLastIndex(x => (x.TimeStamp >= ret.TimeStamp));

            if (index > 0)
            {
                NetMovementMessages.RemoveRange(0, index);
            }

            // 如果在某次移动的时候已经发生了较大的误差则放弃其后的所有移动重新模拟服务器移动
            if (NetMovementMessages.Count > 0 &&
                (NetMovementMessages[0].Position - ret.Position).LengthSquared2D() > 300 * 300)
            {
                this.Transport(GameEngine.EngineInstance.GameLevel, ret.Position, true);

                Debug.WriteLine(string.Format("[Move] S2C_Move Error! Flag=[{0}] ClientPostion={1} ServerPosition={2}", ret.Flag, NetMovementMessages[0].Position, ret.Position));

                this.Acceleration = ret.Acceleration;
                Vector3 newRot = this.Rotation;
                newRot.y      = ret.Yaw;
                this.Rotation = newRot;

                this.NetMovementMessages.Clear();
            }

            //Debug.WriteLine("debug Local Player S2C_Move " + "Flag=" + ret.Flag);
        }
        internal void OnNetMovement(S2C_Move ret)
        {
            // 位置误差大于一定的阀值之后修正
            Vector3 position = this.Location;

            if ((position - ret.Position).LengthSquared2D() > 300 * 300)
            {
                this.Transport(GameEngine.EngineInstance.GameLevel, ret.Position, true);
            }

            this.Acceleration = ret.Acceleration;
            NSavedMove.FlagsToController(ret.Flag, this);
            Vector3 newRot = this.Rotation;

            newRot.y      = ret.Yaw;
            this.Rotation = newRot;

            //Debug.WriteLine("debug Remote Controller S2C_Move " + "Flag=" + ret.Flag);
        }
示例#3
0
        private void OnRecvCharacterMove(MessageReceivedEvent e)
        {
            // 移动消息
            Debug.Assert(GameFrameManager.Instance.CurrentFrameType == GameFrameType.Gaming);
            S2C_Move ret = MarshalConversion.PtrToStruct <S2C_Move>(e.MessagePtr);

            if (ret.UnitId == GameEngine.EngineInstance.LocalPlayer.CharacterID)
            {
                GameEngine.EngineInstance.LocalPlayer.OnNetMovement(ret);
            }
            else
            {
                RemoteCharacterController rcc = GameEngine.EngineInstance.FindCharacterController(ret.UnitId);
                if (rcc != null)
                {
                    rcc.OnNetMovement(ret);
                }
                else
                {
                    NLogger.Instance.WriteString(LogType.Debug,
                                                 string.Format("Can not find character controller when receive S2C_Move ID=[{0}]", ret.UnitId));
                }
            }
        }