コード例 #1
0
ファイル: UserCommand.cs プロジェクト: demiurghg/ShooterDemo
        /// <summary>
        /// Gets user command from bytes
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        public static UserCommand FromBytes(byte[] array)
        {
            var userCmd = new UserCommand();

            int size = Marshal.SizeOf(userCmd);
            IntPtr ptr = Marshal.AllocHGlobal(size);

            Marshal.Copy(array, 0, ptr, size);

            userCmd = (UserCommand)Marshal.PtrToStructure(ptr, userCmd.GetType());
            Marshal.FreeHGlobal(ptr);

            return userCmd;
        }
コード例 #2
0
        /// <summary>
        /// 
        /// </summary>
        void UpdateInput( ref UserCommand userCommand )
        {
            var flags = UserCtrlFlags.None;

            if (Game.Keyboard.IsKeyDown( MoveForward	)) flags |= UserCtrlFlags.Forward;
            if (Game.Keyboard.IsKeyDown( MoveBackward	)) flags |= UserCtrlFlags.Backward;
            if (Game.Keyboard.IsKeyDown( StrafeLeft		)) flags |= UserCtrlFlags.StrafeLeft;
            if (Game.Keyboard.IsKeyDown( StrafeRight	)) flags |= UserCtrlFlags.StrafeRight;
            if (Game.Keyboard.IsKeyDown( Jump			)) flags |= UserCtrlFlags.Jump;
            if (Game.Keyboard.IsKeyDown( Crouch			)) flags |= UserCtrlFlags.Crouch;
            if (Game.Keyboard.IsKeyDown( Zoom			)) flags |= UserCtrlFlags.Zoom;
            if (Game.Keyboard.IsKeyDown( Attack			)) flags |= UserCtrlFlags.Attack;

            //	http://eliteownage.com/mousesensitivity.html
            //	Q3A: 16200 dot per 360 turn:
            var vp		=	Game.RenderSystem.DisplayBounds;
            var ui		=	Game.UserInterface as ShooterInterface;
            var cam		=	World.GetView<CameraView>();

            if (!Game.Console.IsShown) {
                UserCommand.CtrlFlags	=	flags | weaponControl;
                UserCommand.Yaw			-=	2 * MathUtil.Pi * cam.Sensitivity * Game.Mouse.PositionDelta.X / 16200.0f;
                UserCommand.Pitch		-=	2 * MathUtil.Pi * cam.Sensitivity * Game.Mouse.PositionDelta.Y / 16200.0f * ( InvertMouse ? -1 : 1 );
                UserCommand.Roll		=	0;
            }
        }
コード例 #3
0
ファイル: UserCommand.cs プロジェクト: demiurghg/ShooterDemo
        /// <summary>
        /// Gets user command's bytes.
        /// </summary>
        /// <param name="userCmd"></param>
        /// <returns></returns>
        public static byte[] GetBytes(UserCommand userCmd)
        {
            int size = Marshal.SizeOf(userCmd);
            byte[] array = new byte[size];

            IntPtr ptr = Marshal.AllocHGlobal(size);
            Marshal.StructureToPtr(userCmd, ptr, true);
            Marshal.Copy(ptr, array, 0, size);
            Marshal.FreeHGlobal(ptr);
            return array;
        }
コード例 #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cmdData"></param>
 public void FeedCommand( byte[] cmdData )
 {
     UserCmd	=	UserCommand.FromBytes( cmdData );
 }