📄 cl_input.pas
字号:
{----------------------------------------------------------------------------}
{ }
{ File(s): cl_input.c }
{ Content: Quake2\Client - builds an intended movement command to send to the server }
{ }
{ Initial conversion by : Mani - mani246@yahoo.com }
{ Initial conversion on : 23-Mar-2002 }
{ }
{ This File contains part of convertion of Quake2 source to ObjectPascal. }
{ More information about this project can be found at: }
{ http://www.sulaco.co.za/quake2/ }
{ }
{ Copyright (C) 1997-2001 Id Software, Inc. }
{ }
{ This program is free software; you can redistribute it and/or }
{ modify it under the terms of the GNU General Public License }
{ as published by the Free Software Foundation; either version 2 }
{ of the License, or (at your option) any later version. }
{ }
{ This program is distributed in the hope that it will be useful, }
{ but WITHOUT ANY WARRANTY; without even the implied warranty of }
{ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. }
{ }
{ See the GNU General Public License for more details. }
{ }
{----------------------------------------------------------------------------}
{ * Updated: 03-jun-2002 Juha Hartikainen (juha@linearteam.org) }
{ - Changed this to real unit}
{ - Around 100 little fixes to make this compile }
{}
{ * Updated: 06-jun-2002 Juha Hartikainen (juha@linearteam.org) }
{ - Unit compiles now }
{ }
{----------------------------------------------------------------------------}
// cl.input.pas -- builds an intended movement command to send to the server
unit cl_input;
interface
uses
q_shared,
client;
procedure IN_CenterView; cdecl;
procedure CL_SendCmd;
procedure CL_InitInput;
var
cl_nodelta: cvar_p;
frame_msec,
old_sys_frame_time: Cardinal;
var
cl_upspeed,
cl_forwardspeed,
cl_sidespeed,
cl_yawspeed,
cl_pitchspeed,
cl_run,
cl_anglespeedkey: cvar_p;
{*
===============================================================================
KEY BUTTONS
Continuous button event tracking is complicated by the fact that two different
input sources (say, mouse button 1 and the control key) can both press the
same button, but the button should only be released when both of the
pressing key have been released.
When a key event issues a button command (+forward, +attack, etc), it appends
its key number as a parameter to the command so it can be matched up with
the release.
state bit 0 is the current state of the key
state bit 1 is edge triggered on the up to down transition
state bit 2 is edge triggered on the down to up transition
Key_Event (int key, qboolean down, unsigned time);
+mlook src time
===============================================================================
*}
implementation
uses Common, net_chan, CVar, SysUtils, Cmd, sys_win, Keys,
cl_main, in_win, cl_cin;
var
in_klook,
in_left, in_right, in_forward, in_back,
in_lookup, in_lookdown, in_moveleft, in_moveright,
in_strafe, in_speed, in_use, in_attack,
in_up, in_down : kbutton_t;
in_impulse_: integer;
procedure KeyDown (b: pkbutton_t);
var
k: integer;
c: PChar;
begin
c := Cmd_Argv(1);
if (c^ <> #0) then
k := StrToInt(c)
else
k := -1; // typed manually at the console for continuous down
if (k = b^.down[0]) or (k = b^.down[1]) then Exit; // repeating key
if ( b^.down[0] = 0) then
b^.down[0] := k
else if (b^.down[1] = 0) then
b^.down[1] := k
else
begin
Com_Printf ('Three keys down for a button!'#10, []);
Exit;
end;
if (b^.state and 1 <> 0) then Exit; // still down
// save timestamp
c := Cmd_Argv(2);
b^.downtime := StrToInt(c);
if (b^.downtime = 0) then
b^.downtime := sys_frame_time - 100;
b^.state := b^.state or (1 + 2); // down + impulse down
end;
procedure KeyUp (b: pkbutton_t);
var
k: integer;
c: PChar;
uptime: word;
begin
c := Cmd_Argv(1);
if (c <> '') then
k := StrToInt(c)
else
begin // typed manually at the console, assume for unsticking, so clear all
b^.down[0] := 0;
b^.down[1] := 0;
b^.state := 4; // impulse up
exit;
end;
if (b^.down[0] = k) then
b^.down[0] := 0
else if (b^.down[1] = k) then
b^.down[1] := 0
else
exit; // key up without coresponding down (menu pass through)
if (b^.down[0] <> 0) or (b^.down[1] <> 0) then Exit; // some other key is still holding it down
if ((b^.state and 1) = 0) then Exit; // still up (this should not happen)
// save timestamp
c := Cmd_Argv(2);
uptime := StrToInt(c);
if (uptime <> 0) then
b^.msec := b^.msec + uptime - b^.downtime
else
b^.msec := b^.msec + 10;
b^.state := b^.state and (not 1); // now up
b^.state := b^.state or 4; // impulse up
end;
procedure IN_KLookDown; cdecl;
begin
KeyDown(@in_klook);
end;
procedure IN_KLookUp; cdecl;
begin
KeyUp(@in_klook);
end;
procedure IN_UpDown; cdecl;
begin
KeyDown(@in_up);
end;
procedure IN_UpUp; cdecl;
begin
KeyUp(@in_up);
end;
procedure IN_DownDown; cdecl;
begin
KeyDown(@in_down);
end;
procedure IN_DownUp; cdecl;
begin
KeyUp(@in_down);
end;
procedure IN_LeftDown; cdecl;
begin
KeyDown(@in_left);
end;
procedure IN_LeftUp; cdecl;
begin
KeyUp(@in_left);
end;
procedure IN_RightDown; cdecl;
begin
KeyDown(@in_right);
end;
procedure IN_RightUp; cdecl;
begin
KeyUp(@in_right);
end;
procedure IN_ForwardDown; cdecl;
begin
KeyDown(@in_forward);
end;
procedure IN_ForwardUp; cdecl;
begin
KeyUp(@in_forward);
end;
procedure IN_BackDown; cdecl;
begin
KeyDown(@in_back);
end;
procedure IN_BackUp; cdecl;
begin
KeyUp(@in_back);
end;
procedure IN_LookupDown; cdecl;
begin
KeyDown(@in_lookup);
end;
procedure IN_LookupUp; cdecl;
begin
KeyUp(@in_lookup);
end;
procedure IN_LookdownDown; cdecl;
begin
KeyDown(@in_lookdown);
end;
procedure IN_LookdownUp; cdecl;
begin
KeyUp(@in_lookdown);
end;
procedure IN_MoveleftDown; cdecl;
begin
KeyDown(@in_moveleft);
end;
procedure IN_MoveleftUp; cdecl;
begin
KeyUp(@in_moveleft);
end;
procedure IN_MoverightDown; cdecl;
begin
KeyDown(@in_moveright);
end;
procedure IN_MoverightUp; cdecl;
begin
KeyUp(@in_moveright);
end;
procedure IN_SpeedDown; cdecl;
begin
KeyDown(@in_speed);
end;
procedure IN_SpeedUp; cdecl;
begin
KeyUp(@in_speed);
end;
procedure IN_StrafeDown; cdecl;
begin
KeyDown(@in_strafe);
end;
procedure IN_StrafeUp; cdecl;
begin
KeyUp(@in_strafe);
end;
procedure IN_AttackDown; cdecl;
begin
KeyDown(@in_attack);
end;
procedure IN_AttackUp; cdecl;
begin
KeyUp(@in_attack);
end;
procedure IN_UseDown; cdecl;
begin
KeyDown(@in_use);
end;
procedure IN_UseUp; cdecl;
begin
KeyUp(@in_use);
end;
procedure IN_Impulse; cdecl;
begin
in_impulse_ := StrToInt(Cmd_Argv(1));
end;
{*
===============
CL_KeyState
Returns the fraction of the frame that the key was down
===============
*}
function CL_KeyState (key: pkbutton_t): single;
var
val: single;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -