Esempio n. 1
0
        static void BaseMove(usercmd_t cmd)
        {
            AdjustAngles();
            cmd.Clear();
            Math3D.VectorCopy(Globals.cl.viewangles, cmd.angles);
            if ((in_strafe.state & 1) != 0)
            {
                cmd.sidemove += (short)(Globals.cl_sidespeed.value * KeyState(in_right));
                cmd.sidemove -= (short)(Globals.cl_sidespeed.value * KeyState(in_left));
            }

            cmd.sidemove += (short)(Globals.cl_sidespeed.value * KeyState(in_moveright));
            cmd.sidemove -= (short)(Globals.cl_sidespeed.value * KeyState(in_moveleft));
            cmd.upmove   += (short)(Globals.cl_upspeed.value * KeyState(in_up));
            cmd.upmove   -= (short)(Globals.cl_upspeed.value * KeyState(in_down));
            if ((in_klook.state & 1) == 0)
            {
                cmd.forwardmove += (short)(Globals.cl_forwardspeed.value * KeyState(in_forward));
                cmd.forwardmove -= (short)(Globals.cl_forwardspeed.value * KeyState(in_back));
            }

            if (((in_speed.state & 1) ^ (int)(Globals.cl_run.value)) != 0)
            {
                cmd.forwardmove *= 2;
                cmd.sidemove    *= 2;
                cmd.upmove      *= 2;
            }
        }
Esempio n. 2
0
        static void FinishMove(usercmd_t cmd)
        {
            int ms;
            int i;

            if ((in_attack.state & 3) != 0)
            {
                cmd.buttons |= Defines.BUTTON_ATTACK;
            }
            in_attack.state &= ~2;
            if ((in_use.state & 3) != 0)
            {
                cmd.buttons |= Defines.BUTTON_USE;
            }
            in_use.state &= ~2;
            if (Key.anykeydown != 0 && Globals.cls.key_dest == Defines.key_game)
            {
                cmd.buttons |= Defines.BUTTON_ANY;
            }
            ms = (int)(Globals.cls.frametime * 1000);
            if (ms > 250)
            {
                ms = 100;
            }
            cmd.msec = (byte)ms;
            ClampPitch();
            for (i = 0; i < 3; i++)
            {
                cmd.angles[i] = (short)Math3D.ANGLE2SHORT(Globals.cl.viewangles[i]);
            }
            cmd.impulse    = (byte)in_impulse;
            in_impulse     = 0;
            cmd.lightlevel = (byte)Globals.cl_lightlevel.value;
        }
Esempio n. 3
0
    public static void SV_ReadClientMove(ref usercmd_t move)
    {
        client_t client = host_client;

        // read ping time
        client.ping_times[client.num_pings % q_shared.NUM_PING_TIMES] = (float)(sv.time - Reader.MSG_ReadFloat());
        client.num_pings++;

        // read current angles
        Vector3 angles = Reader.ReadAngles();

        Mathlib.Copy(ref angles, out client.edict.v.v_angle);

        // read movement
        move.forwardmove = Reader.MSG_ReadShort();
        move.sidemove    = Reader.MSG_ReadShort();
        move.upmove      = Reader.MSG_ReadShort();

        // read buttons
        int bits = Reader.MSG_ReadByte();

        client.edict.v.button0 = bits & 1;
        client.edict.v.button2 = (bits & 2) >> 1;

        int i = Reader.MSG_ReadByte();

        if (i != 0)
        {
            client.edict.v.impulse = i;
        }
    }
Esempio n. 4
0
        /// <summary>
        /// SV_ReadClientMove
        /// </summary>
        private void ReadClientMove(ref usercmd_t move)
        {
            var client = this.Host.HostClient;

            // read ping time
            client.ping_times[client.num_pings % ServerDef.NUM_PING_TIMES] = ( float )(this.sv.time - this.Host.Network.Reader.ReadFloat());
            client.num_pings++;

            // read current angles
            var angles = this.Host.Network.Reader.ReadAngles();

            MathLib.Copy(ref angles, out client.edict.v.v_angle);

            // read movement
            move.forwardmove = this.Host.Network.Reader.ReadShort();
            move.sidemove    = this.Host.Network.Reader.ReadShort();
            move.upmove      = this.Host.Network.Reader.ReadShort();

            // read buttons
            var bits = this.Host.Network.Reader.ReadByte();

            client.edict.v.button0 = bits & 1;
            client.edict.v.button2 = (bits & 2) >> 1;

            var i = this.Host.Network.Reader.ReadByte();

            if (i != 0)
            {
                client.edict.v.impulse = i;
            }
        }
Esempio n. 5
0
        public static void ReadDeltaUsercmd(sizebuf_t msg_read, usercmd_t from, usercmd_t move)
        {
            int bits;

            //memcpy(move, from, sizeof(* move));
            // IMPORTANT!! copy without new
            move.set(from);
            bits = MSG.ReadByte(msg_read);

            // read current angles
            if ((bits & Defines.CM_ANGLE1) != 0)
            {
                move.angles[0] = MSG.ReadShort(msg_read);
            }

            if ((bits & Defines.CM_ANGLE2) != 0)
            {
                move.angles[1] = MSG.ReadShort(msg_read);
            }

            if ((bits & Defines.CM_ANGLE3) != 0)
            {
                move.angles[2] = MSG.ReadShort(msg_read);
            }

            // read movement
            if ((bits & Defines.CM_FORWARD) != 0)
            {
                move.forwardmove = MSG.ReadShort(msg_read);
            }

            if ((bits & Defines.CM_SIDE) != 0)
            {
                move.sidemove = MSG.ReadShort(msg_read);
            }

            if ((bits & Defines.CM_UP) != 0)
            {
                move.upmove = MSG.ReadShort(msg_read);
            }

            // read buttons
            if ((bits & Defines.CM_BUTTONS) != 0)
            {
                move.buttons = (byte)MSG.ReadByte(msg_read);
            }

            if ((bits & Defines.CM_IMPULSE) != 0)
            {
                move.impulse = (byte)MSG.ReadByte(msg_read);
            }

            // read time to run command
            move.msec = (byte)MSG.ReadByte(msg_read);

            // read the light level
            move.lightlevel = (byte)MSG.ReadByte(msg_read);
        }
Esempio n. 6
0
        /// <summary>
        /// IN_MouseMove
        /// </summary>
        private void MouseMove(usercmd_t cmd)
        {
            if (!this._IsMouseActive)
            {
                return;
            }

            var current_pos   = Input.Host.MainWindow.GetMousePosition( ); //Cursor.Position;
            var window_center = this.WindowCenter;

            var mx = ( int )(current_pos.X - window_center.X + this._MouseAccum.X);
            var my = ( int )(current_pos.Y - window_center.Y + this._MouseAccum.Y);

            this._MouseAccum.X = 0;
            this._MouseAccum.Y = 0;

            if (Input.Host.Cvars.MouseFilter.Get <bool>( ))
            {
                this._Mouse.X = (mx + this._OldMouse.X) * 0.5f;
                this._Mouse.Y = (my + this._OldMouse.Y) * 0.5f;
            }
            else
            {
                this._Mouse.X = mx;
                this._Mouse.Y = my;
            }

            this._OldMouse.X = mx;
            this._OldMouse.Y = my;

            this._Mouse *= Input.Host.Client.Sensitivity;

            // add mouse X/Y movement to cmd
            if (client_input.StrafeBtn.IsDown || (Input.Host.Client.LookStrafe && client_input.MLookBtn.IsDown))
            {
                cmd.sidemove += Input.Host.Client.MSide * this._Mouse.X;
            }
            else
            {
                Input.Host.Client.cl.viewangles.Y -= Input.Host.Client.MYaw * this._Mouse.X;
            }

            Input.Host.View.StopPitchDrift( );

            Input.Host.Client.cl.viewangles.X += Input.Host.Client.MPitch * this._Mouse.Y;

            // modernized to always use mouse look
            Input.Host.Client.cl.viewangles.X = MathHelper.Clamp(Input.Host.Client.cl.viewangles.X, -70, 80);

            // if the mouse has moved, force it to the center, so there's room to move
            if (mx != 0 || my != 0)
            {
                //Cursor.Position = window_center;
                Input.Host.MainWindow.SetMousePosition(window_center.X, window_center.Y);
            }
        }
Esempio n. 7
0
        public static void SV_ClientThink(client_t cl, usercmd_t cmd)
        {
            cl.commandMsec -= cmd.msec & 0xFF;
            if (cl.commandMsec < 0 && SV_MAIN.sv_enforcetime.value != 0)
            {
                Com.DPrintf("commandMsec underflow from " + cl.name + "\\n");
                return;
            }

            PlayerClient.ClientThink(cl.edict, cmd);
        }
Esempio n. 8
0
    public static void SV_ClientThink()
    {
        if (sv_player.v.movetype == q_shared.MOVETYPE_NONE)
        {
            return;
        }

        onground = ((int)sv_player.v.flags & q_shared.FL_ONGROUND) != 0;

        DropPunchAngle();

        //
        // if dead, behave differently
        //
        if (sv_player.v.health <= 0)
        {
            return;
        }

        //
        // angles
        // show 1/3 the pitch angle and all the roll angle
        cmd = host_client.cmd;

        v3f v_angle;

        Mathlib.VectorAdd(ref sv_player.v.v_angle, ref sv_player.v.punchangle, out v_angle);
        Vector3 pang = ToVector(ref sv_player.v.angles);
        Vector3 pvel = ToVector(ref sv_player.v.velocity);

        sv_player.v.angles.z = game_engine.V_CalcRoll(ref pang, ref pvel) * 4;
        if (sv_player.v.fixangle == 0)
        {
            sv_player.v.angles.x = -v_angle.x / 3;
            sv_player.v.angles.y = v_angle.y;
        }

        if (((int)sv_player.v.flags & q_shared.FL_WATERJUMP) != 0)
        {
            SV_WaterJump();
            return;
        }
        //
        // walk
        //
        if ((sv_player.v.waterlevel >= 2) && (sv_player.v.movetype != q_shared.MOVETYPE_NOCLIP))
        {
            SV_WaterMove();
            return;
        }

        SV_AirMove();
    }
Esempio n. 9
0
        /// <summary>
        /// SV_ClientThink
        /// the move fields specify an intended velocity in pix/sec
        /// the angle fields specify an exact angular motion in degrees
        /// </summary>
        private void ClientThink()
        {
            if (this._Player.v.movetype == Movetypes.MOVETYPE_NONE)
            {
                return;
            }

            this._OnGround = (( int )this._Player.v.flags & EdictFlags.FL_ONGROUND) != 0;

            this.DropPunchAngle();

            //
            // if dead, behave differently
            //
            if (this._Player.v.health <= 0)
            {
                return;
            }

            //
            // angles
            // show 1/3 the pitch angle and all the roll angle
            this._Cmd = this.Host.HostClient.cmd;

            Vector3 v_angle;

            MathLib.VectorAdd(ref this._Player.v.v_angle, ref this._Player.v.punchangle, out v_angle);
            var pang = Utilities.ToVector(ref this._Player.v.angles);
            var pvel = Utilities.ToVector(ref this._Player.v.velocity);

            this._Player.v.angles.Z = this.Host.View.CalcRoll(ref pang, ref pvel) * 4;
            if (this._Player.v.fixangle == 0)
            {
                this._Player.v.angles.X = -v_angle.X / 3;
                this._Player.v.angles.Y = v_angle.Y;
            }

            if ((( int )this._Player.v.flags & EdictFlags.FL_WATERJUMP) != 0)
            {
                this.WaterJump();
                return;
            }
            //
            // walk
            //
            if (this._Player.v.waterlevel >= 2 && this._Player.v.movetype != Movetypes.MOVETYPE_NOCLIP)
            {
                this.WaterMove();
                return;
            }

            this.AirMove();
        }
Esempio n. 10
0
 public usercmd_t(usercmd_t from)
 {
     this.msec        = from.msec;
     this.buttons     = from.buttons;
     this.angles[0]   = from.angles[0];
     this.angles[1]   = from.angles[1];
     this.angles[2]   = from.angles[2];
     this.forwardmove = from.forwardmove;
     this.sidemove    = from.sidemove;
     this.upmove      = from.upmove;
     this.impulse     = from.impulse;
     this.lightlevel  = from.lightlevel;
 }
Esempio n. 11
0
        // IN_Move
        // add additional movement on top of the keyboard move cmd
        public void Move(usercmd_t cmd)
        {
            if (!MainWindow.Instance.Focused)
            {
                return;
            }

            if (MainWindow.Instance.IsMinimised)
            {
                return;
            }

            this.MouseMove(cmd);
        }
Esempio n. 12
0
    public static void IN_Move(usercmd_t cmd)
    {
        if (!MainForm.Instance.Focused)
        {
            return;
        }

        if (MainForm.Instance.WindowState == WindowState.Minimized)
        {
            return;
        }

        IN_MouseMove(cmd);
    }
Esempio n. 13
0
 static void CreateCmd(usercmd_t cmd)
 {
     frame_msec = Globals.sys_frame_time - old_sys_frame_time;
     if (frame_msec < 1)
     {
         frame_msec = 1;
     }
     if (frame_msec > 200)
     {
         frame_msec = 200;
     }
     BaseMove(cmd);
     IN.Move(cmd);
     FinishMove(cmd);
     old_sys_frame_time = Globals.sys_frame_time;
 }
Esempio n. 14
0
        /// <summary>
        /// CL_BaseMove
        /// Send the intended movement message to the server
        /// </summary>
        private void BaseMove(ref usercmd_t cmd)
        {
            if (this.cls.signon != ClientDef.SIGNONS)
            {
                return;
            }

            this.AdjustAngles( );

            cmd.Clear( );

            if (client_input.StrafeBtn.IsDown)
            {
                cmd.sidemove += this.Host.Cvars.SideSpeed.Get <float>( ) * this.KeyState(ref client_input.RightBtn);
                cmd.sidemove -= this.Host.Cvars.SideSpeed.Get <float>( ) * this.KeyState(ref client_input.LeftBtn);
            }

            cmd.sidemove += this.Host.Cvars.SideSpeed.Get <float>( ) * this.KeyState(ref client_input.MoveRightBtn);
            cmd.sidemove -= this.Host.Cvars.SideSpeed.Get <float>( ) * this.KeyState(ref client_input.MoveLeftBtn);

            var upBtn = this.KeyState(ref client_input.UpBtn);

            if (upBtn > 0)
            {
                Console.WriteLine("asd");
            }
            cmd.upmove += this.Host.Cvars.UpSpeed.Get <float>( ) * this.KeyState(ref client_input.UpBtn);
            cmd.upmove -= this.Host.Cvars.UpSpeed.Get <float>( ) * this.KeyState(ref client_input.DownBtn);

            if (!client_input.KLookBtn.IsDown)
            {
                cmd.forwardmove += this.Host.Cvars.ForwardSpeed.Get <float>( ) * this.KeyState(ref client_input.ForwardBtn);
                cmd.forwardmove -= this.Host.Cvars.BackSpeed.Get <float>( ) * this.KeyState(ref client_input.BackBtn);
            }

            //
            // adjust for speed key
            //
            if (client_input.SpeedBtn.IsDown)
            {
                cmd.forwardmove *= this.Host.Cvars.MoveSpeedKey.Get <float>( );
                cmd.sidemove    *= this.Host.Cvars.MoveSpeedKey.Get <float>( );
                cmd.upmove      *= this.Host.Cvars.MoveSpeedKey.Get <float>( );
            }
        }
Esempio n. 15
0
        /*
         * =================
         * CL_SendCmd
         * =================
         */
        public static void CL_SendCmd()
        {
            usercmd_t cmd = new usercmd_t();

            if (cls.state != cactive_t.ca_connected)
            {
                return;
            }

            if (cls.signon == SIGNONS)
            {
                // get basic movement from keyboard
                CL_BaseMove(cmd);

                // allow mice or other external controllers to add to the move
//                IN_Move(cmd);

                // send the unreliable message
                CL_SendMove(cmd);
            }

            if (cls.demoplayback)
            {
                common.SZ_Clear(cls.message);
                return;
            }

            // send the reliable message
            if (cls.message.cursize == 0)
            {
                return;                 // no message at all
            }
            if (!net.NET_CanSendMessage(cls.netcon))
            {
                console.Con_DPrintf("CL_WriteToServer: can't send\n");
                return;
            }

            if (net.NET_SendMessage(cls.netcon, cls.message) == -1)
            {
                host.Host_Error("CL_WriteToServer: lost server connection");
            }

            common.SZ_Clear(cls.message);
        }
Esempio n. 16
0
    public static void CL_SendCmd()
    {
        if (cls.state != cactive_t.ca_connected)
        {
            return;
        }

        if (cls.signon == q_shared.SIGNONS)
        {
            usercmd_t cmd = new usercmd_t();

            // get basic movement from keyboard
            CL_BaseMove(ref cmd);

            // allow mice or other external controllers to add to the move
            IN_Move(cmd);

            // send the unreliable message
            CL_SendMove(ref cmd);
        }

        if (cls.demoplayback)
        {
            cls.message.Clear();
            return;
        }

        // send the reliable message
        if (cls.message.IsEmpty)
        {
            return;             // no message at all
        }
        if (!NET_CanSendMessage(cls.netcon))
        {
            Con_DPrintf("CL_WriteToServer: can't send\n");
            return;
        }

        if (NET_SendMessage(cls.netcon, cls.message) == -1)
        {
            Host_Error("CL_WriteToServer: lost server connection");
        }

        cls.message.Clear();
    }
Esempio n. 17
0
        // CL_SendCmd
        public void SendCmd()
        {
            if (this.cls.state != cactive_t.ca_connected)
            {
                return;
            }

            if (this.cls.signon == ClientDef.SIGNONS)
            {
                var cmd = new usercmd_t();

                // get basic movement from keyboard
                this.BaseMove(ref cmd);

                // allow mice or other external controllers to add to the move
                MainWindow.Input.Move(cmd);

                // send the unreliable message
                this.Host.Client.SendMove(ref cmd);
            }

            if (this.cls.demoplayback)
            {
                this.cls.message.Clear();//    SZ_Clear (cls.message);
                return;
            }

            // send the reliable message
            if (this.cls.message.IsEmpty)
            {
                return;         // no message at all
            }
            if (!this.Host.Network.CanSendMessage(this.cls.netcon))
            {
                this.Host.Console.DPrint("CL_WriteToServer: can't send\n");
                return;
            }

            if (this.Host.Network.SendMessage(this.cls.netcon, this.cls.message) == -1)
            {
                this.Host.Error("CL_WriteToServer: lost server connection");
            }

            this.cls.message.Clear();
        }
Esempio n. 18
0
        public client_state_t()
        {
            for (int n = 0; n < Defines.CMD_BACKUP; n++)
            {
                cmds[n] = new usercmd_t();
            }
            for (int i = 0; i < frames.Length; i++)
            {
                frames[i] = new frame_t();
            }

            for (int n = 0; n < Defines.MAX_CONFIGSTRINGS; n++)
            {
                configstrings[n] = new string("");
            }
            for (int n = 0; n < Defines.MAX_CLIENTS; n++)
            {
                clientinfo[n] = new clientinfo_t();
            }
        }
Esempio n. 19
0
        public static void ReadDeltaUsercmd(sizebuf_t msg_read, usercmd_t from, usercmd_t move)
        {
            Int32 bits;

            move.Set(from);
            bits = ReadByte(msg_read);
            if ((bits & CM_ANGLE1) != 0)
            {
                move.angles[0] = ReadShort(msg_read);
            }
            if ((bits & CM_ANGLE2) != 0)
            {
                move.angles[1] = ReadShort(msg_read);
            }
            if ((bits & CM_ANGLE3) != 0)
            {
                move.angles[2] = ReadShort(msg_read);
            }
            if ((bits & CM_FORWARD) != 0)
            {
                move.forwardmove = ReadShort(msg_read);
            }
            if ((bits & CM_SIDE) != 0)
            {
                move.sidemove = ReadShort(msg_read);
            }
            if ((bits & CM_UP) != 0)
            {
                move.upmove = ReadShort(msg_read);
            }
            if ((bits & CM_BUTTONS) != 0)
            {
                move.buttons = ( Byte )ReadByte(msg_read);
            }
            if ((bits & CM_IMPULSE) != 0)
            {
                move.impulse = ( Byte )ReadByte(msg_read);
            }
            move.msec       = ( Byte )ReadByte(msg_read);
            move.lightlevel = ( Byte )ReadByte(msg_read);
        }
Esempio n. 20
0
        public static void Move(usercmd_t cmd)
        {
            if (!IN.mouse_avail)
            {
                return;
            }

            if (Globals.m_filter.value != 0.0f)
            {
                KBD.mx = (KBD.mx + IN.old_mouse_x) / 2;
                KBD.my = (KBD.my + IN.old_mouse_y) / 2;
            }

            IN.old_mouse_x = KBD.mx;
            IN.old_mouse_y = KBD.my;

            KBD.mx = (int)(KBD.mx * Globals.sensitivity.value);
            KBD.my = (int)(KBD.my * Globals.sensitivity.value);

            // add mouse X/Y movement to cmd
            if ((CL_input.in_strafe.state & 1) != 0 || (Globals.lookstrafe.value != 0 && IN.mlooking))
            {
                cmd.sidemove += (short)(Globals.m_side.value * KBD.mx);
            }
            else
            {
                Globals.cl.viewangles[Defines.YAW] -= Globals.m_yaw.value * KBD.mx;
            }

            if ((IN.mlooking || Globals.freelook.value != 0.0f) && (CL_input.in_strafe.state & 1) == 0)
            {
                Globals.cl.viewangles[Defines.PITCH] += Globals.m_pitch.value * KBD.my;
            }
            else
            {
                cmd.forwardmove -= (short)(Globals.m_forward.value * KBD.my);
            }

            KBD.mx = KBD.my = 0;
        }
Esempio n. 21
0
    public static void CL_BaseMove(ref usercmd_t cmd)
    {
        if (cls.signon != q_shared.SIGNONS)
        {
            return;
        }

        CL_AdjustAngles();

        cmd.Clear();

        if (in_strafe.IsDown)
        {
            cmd.sidemove += cl_sidespeed.value * CL_KeyState(ref in_right);
            cmd.sidemove -= cl_sidespeed.value * CL_KeyState(ref in_left);
        }

        cmd.sidemove += cl_sidespeed.value * CL_KeyState(ref in_moveright);
        cmd.sidemove -= cl_sidespeed.value * CL_KeyState(ref in_moveleft);

        cmd.upmove += cl_upspeed.value * CL_KeyState(ref in_up);
        cmd.upmove -= cl_upspeed.value * CL_KeyState(ref in_down);

        if (!in_klook.IsDown)
        {
            cmd.forwardmove += cl_forwardspeed.value * CL_KeyState(ref in_forward);
            cmd.forwardmove -= cl_backspeed.value * CL_KeyState(ref in_back);
        }

        //
        // adjust for speed key
        //
        if (in_speed.IsDown)
        {
            cmd.forwardmove *= cl_movespeedkey.value;
            cmd.sidemove    *= cl_movespeedkey.value;
            cmd.upmove      *= cl_movespeedkey.value;
        }
    }
Esempio n. 22
0
        /*
         * ================
         * CL_BaseMove
         *
         * Send the intended movement message to the server
         * ================
         */
        static void CL_BaseMove(usercmd_t cmd)
        {
            if (cls.signon != SIGNONS)
            {
                return;
            }

            CL_AdjustAngles();

            //Q_memset (cmd, 0, sizeof(*cmd));

            if ((in_strafe.state & 1) != 0)
            {
                cmd.sidemove += cl_sidespeed.value * CL_KeyState(in_right);
                cmd.sidemove -= cl_sidespeed.value * CL_KeyState(in_left);
            }

            cmd.sidemove += cl_sidespeed.value * CL_KeyState(in_moveright);
            cmd.sidemove -= 350 /*cl_sidespeed.value*/ * CL_KeyState(in_moveleft);

            cmd.upmove += cl_upspeed.value * CL_KeyState(in_up);
            cmd.upmove -= cl_upspeed.value * CL_KeyState(in_down);

            if ((in_klook.state & 1) == 0)
            {
                cmd.forwardmove += cl_forwardspeed.value * CL_KeyState(in_forward);
                cmd.forwardmove -= cl_backspeed.value * CL_KeyState(in_back);
            }

            //
            // adjust for speed key
            //
            if ((in_speed.state & 1) != 0)
            {
                cmd.forwardmove *= cl_movespeedkey.value;
                cmd.sidemove    *= cl_movespeedkey.value;
                cmd.upmove      *= cl_movespeedkey.value;
            }
        }
Esempio n. 23
0
        public static void Move(usercmd_t cmd)
        {
            if (!IN.mouse_avail)
            {
                return;
            }
            if (Globals.m_filter.value != 0F)
            {
                KBD.mx = (KBD.mx + IN.old_mouse_x) / 2;
                KBD.my = (KBD.my + IN.old_mouse_y) / 2;
            }

            IN.old_mouse_x = KBD.mx;
            IN.old_mouse_y = KBD.my;
            KBD.mx         = ( Int32 )(KBD.mx * Globals.sensitivity.value);
            KBD.my         = ( Int32 )(KBD.my * Globals.sensitivity.value);
            if ((CL_input.in_strafe.state & 1) != 0 || ((Globals.lookstrafe.value != 0) && IN.mlooking))
            {
                cmd.sidemove += ( Int16 )(Globals.m_side.value * KBD.mx);                    // TODO - Is this truncating
            }
            else
            {
                Globals.cl.viewangles[YAW] -= Globals.m_yaw.value * KBD.mx;
            }

            if ((IN.mlooking || Globals.freelook.value != 0F) && (CL_input.in_strafe.state & 1) == 0)
            {
                Globals.cl.viewangles[PITCH] += Globals.m_pitch.value * KBD.my;
            }
            else
            {
                cmd.forwardmove -= ( Int16 )(Globals.m_forward.value * KBD.my);                    // TODO - Is this truncating
            }

            KBD.mx = KBD.my = 0;
        }
Esempio n. 24
0
        /*
        ================
        CL_BaseMove

        Send the intended movement message to the server
        ================
        */
        static void CL_BaseMove(usercmd_t cmd)
        {
            if (cls.signon != SIGNONS)
                return;

            CL_AdjustAngles ();

            //Q_memset (cmd, 0, sizeof(*cmd));

            if ((in_strafe.state & 1) != 0)
            {
                cmd.sidemove += cl_sidespeed.value * CL_KeyState (in_right);
                cmd.sidemove -= cl_sidespeed.value * CL_KeyState (in_left);
            }

            cmd.sidemove += cl_sidespeed.value * CL_KeyState (in_moveright);
            cmd.sidemove -= 350/*cl_sidespeed.value*/ * CL_KeyState (in_moveleft);

            cmd.upmove += cl_upspeed.value * CL_KeyState (in_up);
            cmd.upmove -= cl_upspeed.value * CL_KeyState (in_down);

            if ( (in_klook.state & 1) == 0 )
            {
                cmd.forwardmove += cl_forwardspeed.value * CL_KeyState (in_forward);
                cmd.forwardmove -= cl_backspeed.value * CL_KeyState (in_back);
            }

            //
            // adjust for speed key
            //
            if ((in_speed.state & 1) != 0)
            {
                cmd.forwardmove *= cl_movespeedkey.value;
                cmd.sidemove *= cl_movespeedkey.value;
                cmd.upmove *= cl_movespeedkey.value;
            }
        }
Esempio n. 25
0
        /*
        =================
        CL_SendCmd
        =================
        */
        public static void CL_SendCmd()
        {
            usercmd_t cmd = new usercmd_t();

            if (cls.state != cactive_t.ca_connected)
                return;

            if (cls.signon == SIGNONS)
            {
                // get basic movement from keyboard
                CL_BaseMove(cmd);

                // allow mice or other external controllers to add to the move
            //                IN_Move(cmd);

                // send the unreliable message
                CL_SendMove(cmd);
            }

            if (cls.demoplayback)
            {
                common.SZ_Clear (cls.message);
                return;
            }

            // send the reliable message
            if (cls.message.cursize == 0)
                return;		// no message at all

            if (!net.NET_CanSendMessage (cls.netcon))
            {
                console.Con_DPrintf ("CL_WriteToServer: can't send\n");
                return;
            }

            if (net.NET_SendMessage (cls.netcon, cls.message) == -1)
                host.Host_Error ("CL_WriteToServer: lost server connection");

            common.SZ_Clear (cls.message);
        }
Esempio n. 26
0
        public static void WriteDeltaUsercmd(sizebuf_t buf, usercmd_t from, usercmd_t cmd)
        {
            Int32 bits;

            bits = 0;
            if (cmd.angles[0] != from.angles[0])
            {
                bits |= CM_ANGLE1;
            }
            if (cmd.angles[1] != from.angles[1])
            {
                bits |= CM_ANGLE2;
            }
            if (cmd.angles[2] != from.angles[2])
            {
                bits |= CM_ANGLE3;
            }
            if (cmd.forwardmove != from.forwardmove)
            {
                bits |= CM_FORWARD;
            }
            if (cmd.sidemove != from.sidemove)
            {
                bits |= CM_SIDE;
            }
            if (cmd.upmove != from.upmove)
            {
                bits |= CM_UP;
            }
            if (cmd.buttons != from.buttons)
            {
                bits |= CM_BUTTONS;
            }
            if (cmd.impulse != from.impulse)
            {
                bits |= CM_IMPULSE;
            }
            WriteByte(buf, bits);
            if ((bits & CM_ANGLE1) != 0)
            {
                WriteShort(buf, cmd.angles[0]);
            }
            if ((bits & CM_ANGLE2) != 0)
            {
                WriteShort(buf, cmd.angles[1]);
            }
            if ((bits & CM_ANGLE3) != 0)
            {
                WriteShort(buf, cmd.angles[2]);
            }
            if ((bits & CM_FORWARD) != 0)
            {
                WriteShort(buf, cmd.forwardmove);
            }
            if ((bits & CM_SIDE) != 0)
            {
                WriteShort(buf, cmd.sidemove);
            }
            if ((bits & CM_UP) != 0)
            {
                WriteShort(buf, cmd.upmove);
            }
            if ((bits & CM_BUTTONS) != 0)
            {
                WriteByte(buf, cmd.buttons);
            }
            if ((bits & CM_IMPULSE) != 0)
            {
                WriteByte(buf, cmd.impulse);
            }
            WriteByte(buf, cmd.msec);
            WriteByte(buf, cmd.lightlevel);
        }
Esempio n. 27
0
    static void IN_MouseMove(usercmd_t cmd)
    {
        if (!mouseactive)
        {
            return;
        }

        Rectangle bounds        = MainForm.Instance.Bounds;
        Point     current_pos   = Cursor.Position;
        Point     window_center = WindowCenter;

        int mx = (int)(current_pos.X - window_center.X + mx_accum);
        int my = (int)(current_pos.Y - window_center.Y + my_accum);

        mx_accum = 0;
        my_accum = 0;


        if (m_filter.value != 0)
        {
            mouse_x = (mx + old_mouse_x) * 0.5f;
            mouse_y = (my + old_mouse_y) * 0.5f;
        }
        else
        {
            mouse_x = mx;
            mouse_y = my;
        }

        old_mouse_x = mx;
        old_mouse_y = my;

        mouse_x *= sensitivity.value;
        mouse_y *= sensitivity.value;

        // add mouse X/Y movement to cmd
        // HACK: remove the look stafe and mouse look button
        if (in_strafe.IsDown || ((lookstrafe.value != 0) && in_mlook.IsDown))
        {
            cmd.sidemove += m_side.value * mouse_x;
        }
        else
        {
            cl.viewangles.Y -= m_yaw.value * mouse_x;
        }

        if (in_mlook.IsDown)
        {
            V_StopPitchDrift();
        }

        if (in_mlook.IsDown && !in_strafe.IsDown)
        {
            cl.viewangles.X += m_pitch.value * mouse_y;
            if (cl.viewangles.X > 80)
            {
                cl.viewangles.X = 80;
            }
            if (cl.viewangles.X < -70)
            {
                cl.viewangles.X = -70;
            }
        }
        else
        {
            if (in_strafe.IsDown && noclip_anglehack)
            {
                cmd.upmove -= m_forward.value * mouse_y;
            }
            else
            {
                cmd.forwardmove -= m_forward.value * mouse_y;
            }
        }

        // if the mouse has moved, force it to the center, so there's room to move
        if (mx != 0 || my != 0)
        {
            Cursor.Position = window_center;
        }
    }
Esempio n. 28
0
        /*
         * ==============
         * CL_SendMove
         * ==============
         */
        static void CL_SendMove(usercmd_t cmd)
        {
            int i;
            int bits;

            common.sizebuf_t buf = new common.sizebuf_t();
            byte[]  data         = new byte[128];

            buf.maxsize = 128;
            buf.cursize = 0;
            buf.data    = data;

            cl.cmd = cmd;

            //
            // send the movement message
            //
            common.MSG_WriteByte(buf, net.clc_move);

            common.MSG_WriteFloat(buf, cl.mtime[0]);    // so server can get ping times

            for (i = 0; i < 3; i++)
            {
                common.MSG_WriteAngle(buf, cl.viewangles[i]);
            }

            common.MSG_WriteShort(buf, (int)cmd.forwardmove);
            common.MSG_WriteShort(buf, (int)cmd.sidemove);
            common.MSG_WriteShort(buf, (int)cmd.upmove);

            //
            // send button bits
            //
            bits = 0;

            if ((in_attack.state & 3) != 0)
            {
                bits |= 1;
            }
            in_attack.state &= ~2;

            if ((in_jump.state & 3) != 0)
            {
                bits |= 2;
            }
            in_jump.state &= ~2;

            common.MSG_WriteByte(buf, bits);

            common.MSG_WriteByte(buf, in_impulse);
            in_impulse = 0;

            //
            // deliver the message
            //
            if (cls.demoplayback)
            {
                return;
            }

            //
            // allways dump the first two message, because it may contain leftover inputs
            // from the last level
            //
            if (++cl.movemessages <= 2)
            {
                return;
            }

            if (net.NET_SendUnreliableMessage(cls.netcon, buf) == -1)
            {
                console.Con_Printf("CL_SendMove: lost server connection\n");
                CL_Disconnect();
            }
        }
Esempio n. 29
0
        // CL_SendMove
        public void SendMove(ref usercmd_t cmd)
        {
            this.cl.cmd = cmd; // cl.cmd = *cmd - struct copying!!!

            var msg = new MessageWriter(128);

            //
            // send the movement message
            //
            msg.WriteByte(ProtocolDef.clc_move);

            msg.WriteFloat(( float )this.cl.mtime[0]);          // so server can get ping times

            msg.WriteAngle(this.cl.viewangles.X);
            msg.WriteAngle(this.cl.viewangles.Y);
            msg.WriteAngle(this.cl.viewangles.Z);

            msg.WriteShort(( short )cmd.forwardmove);
            msg.WriteShort(( short )cmd.sidemove);
            msg.WriteShort(( short )cmd.upmove);

            //
            // send button bits
            //
            var bits = 0;

            if ((client_input.AttackBtn.state & 3) != 0)
            {
                bits |= 1;
            }
            client_input.AttackBtn.state &= ~2;

            if ((client_input.JumpBtn.state & 3) != 0)
            {
                bits |= 2;
            }
            client_input.JumpBtn.state &= ~2;

            msg.WriteByte(bits);

            msg.WriteByte(client_input.Impulse);
            client_input.Impulse = 0;

            //
            // deliver the message
            //
            if (this.cls.demoplayback)
            {
                return;
            }

            //
            // allways dump the first two message, because it may contain leftover inputs
            // from the last level
            //
            if (++this.cl.movemessages <= 2)
            {
                return;
            }

            if (this.Host.Network.SendUnreliableMessage(this.cls.netcon, msg) == -1)
            {
                this.Host.Console.Print("CL_SendMove: lost server connection\n");
                this.Disconnect( );
            }
        }
Esempio n. 30
0
    public static void CL_SendMove(ref usercmd_t cmd)
    {
        cl.cmd = cmd; // cl.cmd = *cmd - struct copying!!!

        MsgWriter msg = new MsgWriter(128);

        //
        // send the movement message
        //
        msg.MSG_WriteByte(q_shared.clc_move);

        msg.MSG_WriteFloat((float)cl.mtime[0]); // so server can get ping times

        msg.MSG_WriteAngle(cl.viewangles.X);
        msg.MSG_WriteAngle(cl.viewangles.Y);
        msg.MSG_WriteAngle(cl.viewangles.Z);

        msg.MSG_WriteShort((short)cmd.forwardmove);
        msg.MSG_WriteShort((short)cmd.sidemove);
        msg.MSG_WriteShort((short)cmd.upmove);

        //
        // send button bits
        //
        int bits = 0;

        if ((in_attack.state & 3) != 0)
        {
            bits |= 1;
        }
        in_attack.state &= ~2;

        if ((in_jump.state & 3) != 0)
        {
            bits |= 2;
        }
        in_jump.state &= ~2;

        msg.MSG_WriteByte(bits);

        msg.MSG_WriteByte(in_impulse);
        in_impulse = 0;

        //
        // deliver the message
        //
        if (cls.demoplayback)
        {
            return;
        }

        //
        // allways dump the first two message, because it may contain leftover inputs
        // from the last level
        //
        if (++cl.movemessages <= 2)
        {
            return;
        }

        if (NET_SendUnreliableMessage(cls.netcon, msg) == -1)
        {
            Con_Printf("CL_SendMove: lost server connection\n");
            CL_Disconnect();
        }
    }
Esempio n. 31
0
        /*
        ==============
        CL_SendMove
        ==============
        */
        static void CL_SendMove(usercmd_t cmd)
        {
            int		i;
            int		bits;
            common.sizebuf_t	buf = new common.sizebuf_t();
            byte[]	data = new byte[128];

            buf.maxsize = 128;
            buf.cursize = 0;
            buf.data = data;

            cl.cmd = cmd;

            //
            // send the movement message
            //
            common.MSG_WriteByte (buf, net.clc_move);

            common.MSG_WriteFloat(buf, cl.mtime[0]);	// so server can get ping times

            for (i=0 ; i<3 ; i++)
                common.MSG_WriteAngle(buf, cl.viewangles[i]);

            common.MSG_WriteShort(buf, (int)cmd.forwardmove);
            common.MSG_WriteShort(buf, (int)cmd.sidemove);
            common.MSG_WriteShort(buf, (int)cmd.upmove);

            //
            // send button bits
            //
            bits = 0;

            if (( in_attack.state & 3 ) != 0)
                bits |= 1;
            in_attack.state &= ~2;

            if ((in_jump.state & 3) != 0)
                bits |= 2;
            in_jump.state &= ~2;

            common.MSG_WriteByte(buf, bits);

            common.MSG_WriteByte(buf, in_impulse);
            in_impulse = 0;

            //
            // deliver the message
            //
            if (cls.demoplayback)
                return;

            //
            // allways dump the first two message, because it may contain leftover inputs
            // from the last level
            //
            if (++cl.movemessages <= 2)
                return;

            if (net.NET_SendUnreliableMessage (cls.netcon, buf) == -1)
            {
                console.Con_Printf ("CL_SendMove: lost server connection\n");
                CL_Disconnect ();
            }
        }
Esempio n. 32
0
        public static void SV_ExecuteClientMessage(client_t cl)
        {
            Int32     c;
            String    s;
            usercmd_t nullcmd = new usercmd_t();
            usercmd_t oldest = new usercmd_t(), oldcmd = new usercmd_t(), newcmd = new usercmd_t();
            Int32     net_drop;
            Int32     stringCmdCount;
            Int32     checksum, calculatedChecksum;
            Int32     checksumIndex;
            Boolean   move_issued;
            Int32     lastframe;

            SV_MAIN.sv_client = cl;
            SV_USER.sv_player = SV_MAIN.sv_client.edict;
            move_issued       = false;
            stringCmdCount    = 0;
            while (true)
            {
                if (Globals.net_message.readcount > Globals.net_message.cursize)
                {
                    Com.Printf("SV_ReadClientMessage: bad read:\\n");
                    Com.Printf(Lib.HexDump(Globals.net_message.data, 32, false));
                    SV_MAIN.SV_DropClient(cl);
                    return;
                }

                c = MSG.ReadByte(Globals.net_message);
                if (c == -1)
                {
                    break;
                }
                switch (c)

                {
                default:
                    Com.Printf("SV_ReadClientMessage: unknown command char\\n");
                    SV_MAIN.SV_DropClient(cl);
                    return;

                case Defines.clc_nop:
                    break;

                case Defines.clc_userinfo:
                    cl.userinfo = MSG.ReadString(Globals.net_message);
                    SV_MAIN.SV_UserinfoChanged(cl);
                    break;

                case Defines.clc_move:
                    if (move_issued)
                    {
                        return;
                    }
                    move_issued   = true;
                    checksumIndex = Globals.net_message.readcount;
                    checksum      = MSG.ReadByte(Globals.net_message);
                    lastframe     = MSG.ReadLong(Globals.net_message);
                    if (lastframe != cl.lastframe)
                    {
                        cl.lastframe = lastframe;
                        if (cl.lastframe > 0)
                        {
                            cl.frame_latency[cl.lastframe & (Defines.LATENCY_COUNTS - 1)] = SV_INIT.svs.realtime - cl.frames[cl.lastframe & Defines.UPDATE_MASK].senttime;
                        }
                    }

                    nullcmd = new usercmd_t();
                    MSG.ReadDeltaUsercmd(Globals.net_message, nullcmd, oldest);
                    MSG.ReadDeltaUsercmd(Globals.net_message, oldest, oldcmd);
                    MSG.ReadDeltaUsercmd(Globals.net_message, oldcmd, newcmd);
                    if (cl.state != Defines.cs_spawned)
                    {
                        cl.lastframe = -1;
                        break;
                    }

                    calculatedChecksum = Com.BlockSequenceCRCByte(Globals.net_message.data, checksumIndex + 1, Globals.net_message.readcount - checksumIndex - 1, cl.netchan.incoming_sequence);
                    if ((calculatedChecksum & 0xff) != checksum)
                    {
                        Com.DPrintf("Failed command checksum for " + cl.name + " (" + calculatedChecksum + " != " + checksum + ")/" + cl.netchan.incoming_sequence + "\\n");
                        return;
                    }

                    if (0 == SV_MAIN.sv_paused.value)
                    {
                        net_drop = cl.netchan.dropped;
                        if (net_drop < 20)
                        {
                            while (net_drop > 2)
                            {
                                SV_ClientThink(cl, cl.lastcmd);
                                net_drop--;
                            }

                            if (net_drop > 1)
                            {
                                SV_ClientThink(cl, oldest);
                            }
                            if (net_drop > 0)
                            {
                                SV_ClientThink(cl, oldcmd);
                            }
                        }

                        SV_ClientThink(cl, newcmd);
                    }

                    cl.lastcmd.Set(newcmd);
                    break;

                case Defines.clc_stringcmd:
                    s = MSG.ReadString(Globals.net_message);
                    if (++stringCmdCount < SV_USER.MAX_STRINGCMDS)
                    {
                        SV_ExecuteUserCommand(s);
                    }
                    if (cl.state == Defines.cs_zombie)
                    {
                        return;
                    }
                    break;
                }
            }
        }
Esempio n. 33
0
        public static void WriteDeltaUsercmd(sizebuf_t buf, usercmd_t from, usercmd_t cmd)
        {
            int bits;

            //
            // send the movement message
            //
            bits = 0;

            if (cmd.angles[0] != from.angles[0])
            {
                bits |= Defines.CM_ANGLE1;
            }

            if (cmd.angles[1] != from.angles[1])
            {
                bits |= Defines.CM_ANGLE2;
            }

            if (cmd.angles[2] != from.angles[2])
            {
                bits |= Defines.CM_ANGLE3;
            }

            if (cmd.forwardmove != from.forwardmove)
            {
                bits |= Defines.CM_FORWARD;
            }

            if (cmd.sidemove != from.sidemove)
            {
                bits |= Defines.CM_SIDE;
            }

            if (cmd.upmove != from.upmove)
            {
                bits |= Defines.CM_UP;
            }

            if (cmd.buttons != from.buttons)
            {
                bits |= Defines.CM_BUTTONS;
            }

            if (cmd.impulse != from.impulse)
            {
                bits |= Defines.CM_IMPULSE;
            }

            MSG.WriteByte(buf, bits);

            if ((bits & Defines.CM_ANGLE1) != 0)
            {
                MSG.WriteShort(buf, cmd.angles[0]);
            }

            if ((bits & Defines.CM_ANGLE2) != 0)
            {
                MSG.WriteShort(buf, cmd.angles[1]);
            }

            if ((bits & Defines.CM_ANGLE3) != 0)
            {
                MSG.WriteShort(buf, cmd.angles[2]);
            }

            if ((bits & Defines.CM_FORWARD) != 0)
            {
                MSG.WriteShort(buf, cmd.forwardmove);
            }

            if ((bits & Defines.CM_SIDE) != 0)
            {
                MSG.WriteShort(buf, cmd.sidemove);
            }

            if ((bits & Defines.CM_UP) != 0)
            {
                MSG.WriteShort(buf, cmd.upmove);
            }

            if ((bits & Defines.CM_BUTTONS) != 0)
            {
                MSG.WriteByte(buf, cmd.buttons);
            }

            if ((bits & Defines.CM_IMPULSE) != 0)
            {
                MSG.WriteByte(buf, cmd.impulse);
            }

            MSG.WriteByte(buf, cmd.msec);
            MSG.WriteByte(buf, cmd.lightlevel);
        }