/// <summary> /// SV_ReadClientMove /// </summary> private void ReadClientMove(ref usercmd_t move) { var client = Host.HostClient; // read ping time client.ping_times[client.num_pings % ServerDef.NUM_PING_TIMES] = ( Single )(sv.time - Host.Network.Reader.ReadFloat()); client.num_pings++; // read current angles var angles = Host.Network.Reader.ReadAngles(); MathLib.Copy(ref angles, out client.edict.v.v_angle); // read movement move.forwardmove = Host.Network.Reader.ReadShort(); move.sidemove = Host.Network.Reader.ReadShort(); move.upmove = Host.Network.Reader.ReadShort(); // read buttons var bits = Host.Network.Reader.ReadByte(); client.edict.v.button0 = bits & 1; client.edict.v.button2 = (bits & 2) >> 1; var i = Host.Network.Reader.ReadByte(); if (i != 0) { client.edict.v.impulse = i; } }
/// <summary> /// SV_ReadClientMove /// </summary> static void ReadClientMove(ref usercmd_t move) { client_t client = Host.HostClient; // read ping time client.ping_times[client.num_pings % NUM_PING_TIMES] = (float)(sv.time - Net.Reader.ReadFloat()); client.num_pings++; // read current angles Vector3 angles = Net.Reader.ReadAngles(); Mathlib.Copy(ref angles, out client.edict.v.v_angle); // read movement move.forwardmove = Net.Reader.ReadShort(); move.sidemove = Net.Reader.ReadShort(); move.upmove = Net.Reader.ReadShort(); // read buttons int bits = Net.Reader.ReadByte(); client.edict.v.button0 = bits & 1; client.edict.v.button2 = (bits & 2) >> 1; int i = Net.Reader.ReadByte(); if (i != 0) { client.edict.v.impulse = i; } }
// CL_SendMove public static void SendMove(ref usercmd_t cmd) { cl.cmd = cmd; // cl.cmd = *cmd - struct copying!!! MsgWriter msg = new MsgWriter(128); // // send the movement message // msg.WriteByte(Protocol.clc_move); msg.WriteFloat((float)cl.mtime[0]); // so server can get ping times msg.WriteAngle(cl.viewangles.X); msg.WriteAngle(cl.viewangles.Y); msg.WriteAngle(cl.viewangles.Z); msg.WriteShort((short)cmd.forwardmove); msg.WriteShort((short)cmd.sidemove); msg.WriteShort((short)cmd.upmove); // // send button bits // int bits = 0; if ((ClientInput.AttackBtn.state & 3) != 0) bits |= 1; ClientInput.AttackBtn.state &= ~2; if ((ClientInput.JumpBtn.state & 3) != 0) bits |= 2; ClientInput.JumpBtn.state &= ~2; msg.WriteByte(bits); msg.WriteByte(ClientInput.Impulse); ClientInput.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.Print("CL_SendMove: lost server connection\n"); Disconnect(); } }
/// <summary> /// IN_MouseMove /// </summary> private void MouseMove(usercmd_t cmd) { if (!_IsMouseActive) { return; } var current_pos = Host.MainWindow.GetMousePosition( ); //Cursor.Position; var window_center = WindowCenter; var mx = ( Int32 )(current_pos.X - window_center.X + _MouseAccum.X); var my = ( Int32 )(current_pos.Y - window_center.Y + _MouseAccum.Y); _MouseAccum.X = 0; _MouseAccum.Y = 0; if (Host.Cvars.MouseFilter.Get <Boolean>( )) { _Mouse.X = (mx + _OldMouse.X) * 0.5f; _Mouse.Y = (my + _OldMouse.Y) * 0.5f; } else { _Mouse.X = mx; _Mouse.Y = my; } _OldMouse.X = mx; _OldMouse.Y = my; _Mouse *= Host.Client.Sensitivity; // add mouse X/Y movement to cmd if (client_input.StrafeBtn.IsDown || (Host.Client.LookStrafe && client_input.MLookBtn.IsDown)) { cmd.sidemove += Host.Client.MSide * _Mouse.X; } else { Host.Client.cl.viewangles.Y -= Host.Client.MYaw * _Mouse.X; } Host.View.StopPitchDrift( ); Host.Client.cl.viewangles.X += Host.Client.MPitch * _Mouse.Y; // modernized to always use mouse look Host.Client.cl.viewangles.X = MathHelper.Clamp(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; Host.MainWindow.SetMousePosition(window_center.X, window_center.Y); } }
/// <summary> /// IN_MouseMove /// </summary> private static void MouseMove(usercmd_t cmd) { if (!_IsMouseActive) { return; } Point current_pos = new Point(Mouse.GetCursorState().X, Mouse.GetCursorState().Y); //Cursor.Position; Point window_center = input.WindowCenter; int mx = (int)(current_pos.X - window_center.X + _MouseAccum.X); int my = (int)(current_pos.Y - window_center.Y + _MouseAccum.Y); _MouseAccum.X = 0; _MouseAccum.Y = 0; if (_MouseFilter.Value != 0) { _Mouse.X = (mx + _OldMouse.X) * 0.5f; _Mouse.Y = (my + _OldMouse.Y) * 0.5f; } else { _Mouse.X = mx; _Mouse.Y = my; } _OldMouse.X = mx; _OldMouse.Y = my; _Mouse *= client.Sensitivity; // add mouse X/Y movement to cmd if (client_input.StrafeBtn.IsDown || (client.LookStrafe && client_input.MLookBtn.IsDown)) { cmd.sidemove += client.MSide * _Mouse.X; } else { client.cl.viewangles.Y -= client.MYaw * _Mouse.X; } view.StopPitchDrift(); client.cl.viewangles.X += client.MPitch * _Mouse.Y; // modernized to always use mouse look client.cl.viewangles.X = MathHelper.Clamp(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; Mouse.SetPosition(window_center.X, window_center.Y); } }
/// <summary> /// SV_ClientThink /// the move fields specify an intended velocity in pix/sec /// the angle fields specify an exact angular motion in degrees /// </summary> static void ClientThink() { if (_Player.v.movetype == Movetypes.MOVETYPE_NONE) { return; } _OnGround = ((int)_Player.v.flags & EdictFlags.FL_ONGROUND) != 0; DropPunchAngle(); // // if dead, behave differently // if (_Player.v.health <= 0) { return; } // // angles // show 1/3 the pitch angle and all the roll angle _Cmd = Host.HostClient.cmd; v3f v_angle; Mathlib.VectorAdd(ref _Player.v.v_angle, ref _Player.v.punchangle, out v_angle); Vector3 pang = Common.ToVector(ref _Player.v.angles); Vector3 pvel = Common.ToVector(ref _Player.v.velocity); _Player.v.angles.z = View.CalcRoll(ref pang, ref pvel) * 4; if (_Player.v.fixangle == 0) { _Player.v.angles.x = -v_angle.x / 3; _Player.v.angles.y = v_angle.y; } if (((int)_Player.v.flags & EdictFlags.FL_WATERJUMP) != 0) { WaterJump(); return; } // // walk // if ((_Player.v.waterlevel >= 2) && (_Player.v.movetype != Movetypes.MOVETYPE_NOCLIP)) { WaterMove(); return; } AirMove(); }
// 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; } MouseMove(cmd); }
// IN_Move // add additional movement on top of the keyboard move cmd public static void Move(usercmd_t cmd) { if (!mainwindow.Instance.Focused) { return; } if (mainwindow.Instance.WindowState == WindowState.Minimized) { return; } MouseMove(cmd); }
// CL_SendCmd public void SendCmd() { if (cls.state != cactive_t.ca_connected) { return; } if (cls.signon == ClientDef.SIGNONS) { var cmd = new usercmd_t(); // get basic movement from keyboard BaseMove(ref cmd); // allow mice or other external controllers to add to the move MainWindow.Input.Move(cmd); // send the unreliable message Host.Client.SendMove(ref cmd); } if (cls.demoplayback) { cls.message.Clear();// SZ_Clear (cls.message); return; } // send the reliable message if (cls.message.IsEmpty) { return; // no message at all } if (!Host.Network.CanSendMessage(cls.netcon)) { Host.Console.DPrint("CL_WriteToServer: can't send\n"); return; } if (Host.Network.SendMessage(cls.netcon, cls.message) == -1) { Host.Error("CL_WriteToServer: lost server connection"); } cls.message.Clear(); }
/// <summary> /// CL_BaseMove /// Send the intended movement message to the server /// </summary> private void BaseMove(ref usercmd_t cmd) { if (cls.signon != ClientDef.SIGNONS) { return; } AdjustAngles( ); cmd.Clear( ); if (client_input.StrafeBtn.IsDown) { cmd.sidemove += Host.Cvars.SideSpeed.Get <Single>( ) * KeyState(ref client_input.RightBtn); cmd.sidemove -= Host.Cvars.SideSpeed.Get <Single>( ) * KeyState(ref client_input.LeftBtn); } cmd.sidemove += Host.Cvars.SideSpeed.Get <Single>( ) * KeyState(ref client_input.MoveRightBtn); cmd.sidemove -= Host.Cvars.SideSpeed.Get <Single>( ) * KeyState(ref client_input.MoveLeftBtn); var upBtn = KeyState(ref client_input.UpBtn); if (upBtn > 0) { Console.WriteLine("asd"); } cmd.upmove += Host.Cvars.UpSpeed.Get <Single>( ) * KeyState(ref client_input.UpBtn); cmd.upmove -= Host.Cvars.UpSpeed.Get <Single>( ) * KeyState(ref client_input.DownBtn); if (!client_input.KLookBtn.IsDown) { cmd.forwardmove += Host.Cvars.ForwardSpeed.Get <Single>( ) * KeyState(ref client_input.ForwardBtn); cmd.forwardmove -= Host.Cvars.BackSpeed.Get <Single>( ) * KeyState(ref client_input.BackBtn); } // // adjust for speed key // if (client_input.SpeedBtn.IsDown) { cmd.forwardmove *= Host.Cvars.MoveSpeedKey.Get <Single>( ); cmd.sidemove *= Host.Cvars.MoveSpeedKey.Get <Single>( ); cmd.upmove *= Host.Cvars.MoveSpeedKey.Get <Single>( ); } }
/// <summary> /// CL_BaseMove /// Send the intended movement message to the server /// </summary> private static void BaseMove(ref usercmd_t cmd) { if (cls.signon != SIGNONS) { return; } AdjustAngles(); cmd.Clear(); if (client_input.StrafeBtn.IsDown) { cmd.sidemove += _SideSpeed.Value * KeyState(ref client_input.RightBtn); cmd.sidemove -= _SideSpeed.Value * KeyState(ref client_input.LeftBtn); } cmd.sidemove += _SideSpeed.Value * KeyState(ref client_input.MoveRightBtn); cmd.sidemove -= _SideSpeed.Value * KeyState(ref client_input.MoveLeftBtn); cmd.upmove += _UpSpeed.Value * KeyState(ref client_input.UpBtn); cmd.upmove -= _UpSpeed.Value * KeyState(ref client_input.DownBtn); if (!client_input.KLookBtn.IsDown) { cmd.forwardmove += _ForwardSpeed.Value * KeyState(ref client_input.ForwardBtn); cmd.forwardmove -= _BackSpeed.Value * KeyState(ref client_input.BackBtn); } // // adjust for speed key // if (client_input.SpeedBtn.IsDown) { cmd.forwardmove *= _MoveSpeedKey.Value; cmd.sidemove *= _MoveSpeedKey.Value; cmd.upmove *= _MoveSpeedKey.Value; } }
/// <summary> /// IN_MouseMove /// </summary> static void MouseMove(usercmd_t cmd) { if (!_IsMouseActive) { return; } Rectangle bounds = MainForm.Instance.Bounds; Point current_pos = Cursor.Position; Point window_center = Input.WindowCenter; int mx = (int)(current_pos.X - window_center.X + _MouseAccum.X); int my = (int)(current_pos.Y - window_center.Y + _MouseAccum.Y); _MouseAccum.X = 0; _MouseAccum.Y = 0; if (_MouseFilter.Value != 0) { _Mouse.X = (mx + _OldMouse.X) * 0.5f; _Mouse.Y = (my + _OldMouse.Y) * 0.5f; } else { _Mouse.X = mx; _Mouse.Y = my; } _OldMouse.X = mx; _OldMouse.Y = my; _Mouse *= Client.Sensitivity; // add mouse X/Y movement to cmd if (ClientInput.StrafeBtn.IsDown || (Client.LookStrafe && ClientInput.MLookBtn.IsDown)) { cmd.sidemove += Client.MSide * _Mouse.X; } else { Client.cl.viewangles.Y -= Client.MYaw * _Mouse.X; } if (ClientInput.MLookBtn.IsDown) { View.StopPitchDrift(); } if (ClientInput.MLookBtn.IsDown && !ClientInput.StrafeBtn.IsDown) { Client.cl.viewangles.X += Client.MPitch * _Mouse.Y; if (Client.cl.viewangles.X > 80) { Client.cl.viewangles.X = 80; } if (Client.cl.viewangles.X < -70) { Client.cl.viewangles.X = -70; } } else { if (ClientInput.StrafeBtn.IsDown && Host.NoClipAngleHack) { cmd.upmove -= Client.MForward * _Mouse.Y; } else { cmd.forwardmove -= Client.MForward * _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; } }
// CL_SendMove public static void SendMove(ref usercmd_t cmd) { cl.cmd = cmd; // cl.cmd = *cmd - struct copying!!! MsgWriter msg = new MsgWriter(128); // // send the movement message // msg.WriteByte(protocol.clc_move); msg.WriteFloat((float)cl.mtime[0]); // so server can get ping times msg.WriteAngle(cl.viewangles.X); msg.WriteAngle(cl.viewangles.Y); msg.WriteAngle(cl.viewangles.Z); msg.WriteShort((short)cmd.forwardmove); msg.WriteShort((short)cmd.sidemove); msg.WriteShort((short)cmd.upmove); // // send button bits // int 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 (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.Print("CL_SendMove: lost server connection\n"); Disconnect(); } }
/// <summary> /// SV_ClientThink /// the move fields specify an intended velocity in pix/sec /// the angle fields specify an exact angular motion in degrees /// </summary> static void ClientThink() { if (_Player.v.movetype == Movetypes.MOVETYPE_NONE) return; _OnGround = ((int)_Player.v.flags & EdictFlags.FL_ONGROUND) != 0; DropPunchAngle(); // // if dead, behave differently // if (_Player.v.health <= 0) return; // // angles // show 1/3 the pitch angle and all the roll angle _Cmd = Host.HostClient.cmd; v3f v_angle; Mathlib.VectorAdd(ref _Player.v.v_angle, ref _Player.v.punchangle, out v_angle); Vector3 pang = Common.ToVector(ref _Player.v.angles); Vector3 pvel = Common.ToVector(ref _Player.v.velocity); _Player.v.angles.z = View.CalcRoll(ref pang, ref pvel) * 4; if (_Player.v.fixangle == 0) { _Player.v.angles.x = -v_angle.x / 3; _Player.v.angles.y = v_angle.y; } if (((int)_Player.v.flags & EdictFlags.FL_WATERJUMP) != 0) { WaterJump(); return; } // // walk // if ((_Player.v.waterlevel >= 2) && (_Player.v.movetype != Movetypes.MOVETYPE_NOCLIP)) { WaterMove(); return; } AirMove(); }
/// <summary> /// IN_MouseMove /// </summary> static void MouseMove(usercmd_t cmd) { if (!_IsMouseActive) return; Rectangle bounds = MainForm.Instance.Bounds; Point current_pos = Cursor.Position; Point window_center = Input.WindowCenter; int mx = (int)(current_pos.X - window_center.X + _MouseAccum.X); int my = (int)(current_pos.Y - window_center.Y + _MouseAccum.Y); _MouseAccum.X = 0; _MouseAccum.Y = 0; if (_MouseFilter.Value != 0) { _Mouse.X = (mx + _OldMouse.X) * 0.5f; _Mouse.Y = (my + _OldMouse.Y) * 0.5f; } else { _Mouse.X = mx; _Mouse.Y = my; } _OldMouse.X = mx; _OldMouse.Y = my; _Mouse *= Client.Sensitivity; // add mouse X/Y movement to cmd if (ClientInput.StrafeBtn.IsDown || (Client.LookStrafe && ClientInput.MLookBtn.IsDown)) cmd.sidemove += Client.MSide * _Mouse.X; else Client.cl.viewangles.Y -= Client.MYaw * _Mouse.X; if (ClientInput.MLookBtn.IsDown) View.StopPitchDrift(); if (ClientInput.MLookBtn.IsDown && !ClientInput.StrafeBtn.IsDown) { Client.cl.viewangles.X += Client.MPitch * _Mouse.Y; if (Client.cl.viewangles.X > 80) Client.cl.viewangles.X = 80; if (Client.cl.viewangles.X < -70) Client.cl.viewangles.X = -70; } else { if (ClientInput.StrafeBtn.IsDown && Host.NoClipAngleHack) cmd.upmove -= Client.MForward * _Mouse.Y; else cmd.forwardmove -= Client.MForward * _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; } }
/// <summary> /// SV_ReadClientMove /// </summary> static void ReadClientMove(ref usercmd_t move) { client_t client = Host.HostClient; // read ping time client.ping_times[client.num_pings % NUM_PING_TIMES] = (float)(sv.time - Net.Reader.ReadFloat()); client.num_pings++; // read current angles Vector3 angles = Net.Reader.ReadAngles(); Mathlib.Copy(ref angles, out client.edict.v.v_angle); // read movement move.forwardmove = Net.Reader.ReadShort(); move.sidemove = Net.Reader.ReadShort(); move.upmove = Net.Reader.ReadShort(); // read buttons int bits = Net.Reader.ReadByte(); client.edict.v.button0 = bits & 1; client.edict.v.button2 = (bits & 2) >> 1; int i = Net.Reader.ReadByte(); if (i != 0) client.edict.v.impulse = i; }
// CL_SendCmd public static void SendCmd() { if (cls.state != cactive_t.ca_connected) return; if (cls.signon == SIGNONS) { usercmd_t cmd = new usercmd_t(); // get basic movement from keyboard BaseMove(ref cmd); // allow mice or other external controllers to add to the move Input.Move(cmd); // send the unreliable message Client.SendMove(ref cmd); } if (cls.demoplayback) { cls.message.Clear();// SZ_Clear (cls.message); return; } // send the reliable message if (cls.message.IsEmpty) return; // no message at all if (!Net.CanSendMessage(cls.netcon)) { Con.DPrint("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(); }
// IN_Move // add additional movement on top of the keyboard move cmd public static void Move(usercmd_t cmd) { if (!MainForm.Instance.Focused) return; if (MainForm.Instance.WindowState == WindowState.Minimized) return; MouseMove(cmd); }
/// <summary> /// CL_BaseMove /// Send the intended movement message to the server /// </summary> static void BaseMove(ref usercmd_t cmd) { if (cls.signon != SIGNONS) return; AdjustAngles(); cmd.Clear(); if (ClientInput.StrafeBtn.IsDown) { cmd.sidemove += _SideSpeed.Value * KeyState(ref ClientInput.RightBtn); cmd.sidemove -= _SideSpeed.Value * KeyState(ref ClientInput.LeftBtn); } cmd.sidemove += _SideSpeed.Value * KeyState(ref ClientInput.MoveRightBtn); cmd.sidemove -= _SideSpeed.Value * KeyState(ref ClientInput.MoveLeftBtn); cmd.upmove += _UpSpeed.Value * KeyState(ref ClientInput.UpBtn); cmd.upmove -= _UpSpeed.Value * KeyState(ref ClientInput.DownBtn); if (!ClientInput.KLookBtn.IsDown) { cmd.forwardmove += _ForwardSpeed.Value * KeyState(ref ClientInput.ForwardBtn); cmd.forwardmove -= _BackSpeed.Value * KeyState(ref ClientInput.BackBtn); } // // adjust for speed key // if (ClientInput.SpeedBtn.IsDown) { cmd.forwardmove *= _MoveSpeedKey.Value; cmd.sidemove *= _MoveSpeedKey.Value; cmd.upmove *= _MoveSpeedKey.Value; } }