📄 cl_input.java
字号:
/* * java * Copyright (C) 2004 * * $Id: CL_input.java,v 1.7 2005/06/26 09:17:33 hzi Exp $ *//* 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */package jake2.client;import jake2.Defines;import jake2.Globals;import jake2.game.Cmd;import jake2.game.cvar_t;import jake2.game.usercmd_t;import jake2.qcommon.*;import jake2.sys.IN;import jake2.util.Lib;import jake2.util.Math3D;/** * CL_input */public class CL_input { static long frame_msec; static long old_sys_frame_time; static cvar_t cl_nodelta; /* * =============================================================================== * * 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 * * =============================================================================== */ static kbutton_t in_klook = new kbutton_t(); static kbutton_t in_left = new kbutton_t(); static kbutton_t in_right = new kbutton_t(); static kbutton_t in_forward = new kbutton_t(); static kbutton_t in_back = new kbutton_t(); static kbutton_t in_lookup = new kbutton_t(); static kbutton_t in_lookdown = new kbutton_t(); static kbutton_t in_moveleft = new kbutton_t(); static kbutton_t in_moveright = new kbutton_t(); public static kbutton_t in_strafe = new kbutton_t(); static kbutton_t in_speed = new kbutton_t(); static kbutton_t in_use = new kbutton_t(); static kbutton_t in_attack = new kbutton_t(); static kbutton_t in_up = new kbutton_t(); static kbutton_t in_down = new kbutton_t(); static int in_impulse; static void KeyDown(kbutton_t b) { int k; String c; c = Cmd.Argv(1); if (c.length() > 0) k = Lib.atoi(c); else k = -1; // typed manually at the console for continuous down if (k == b.down[0] || k == b.down[1]) return; // repeating key if (b.down[0] == 0) b.down[0] = k; else if (b.down[1] == 0) b.down[1] = k; else { Com.Printf("Three keys down for a button!\n"); return; } if ((b.state & 1) != 0) return; // still down // save timestamp c = Cmd.Argv(2); b.downtime = Lib.atoi(c); if (b.downtime == 0) b.downtime = Globals.sys_frame_time - 100; b.state |= 3; // down + impulse down } static void KeyUp(kbutton_t b) { int k; String c; int uptime; c = Cmd.Argv(1); if (c.length() > 0) k = Lib.atoi(c); else { // typed manually at the console, assume for unsticking, so clear // all b.down[0] = b.down[1] = 0; b.state = 4; // impulse up return; } if (b.down[0] == k) b.down[0] = 0; else if (b.down[1] == k) b.down[1] = 0; else return; // key up without coresponding down (menu pass through) if (b.down[0] != 0 || b.down[1] != 0) return; // some other key is still holding it down if ((b.state & 1) == 0) return; // still up (this should not happen) // save timestamp c = Cmd.Argv(2); uptime = Lib.atoi(c); if (uptime != 0) b.msec += uptime - b.downtime; else b.msec += 10; b.state &= ~1; // now up b.state |= 4; // impulse up } static void IN_KLookDown() { KeyDown(in_klook); } static void IN_KLookUp() { KeyUp(in_klook); } static void IN_UpDown() { KeyDown(in_up); } static void IN_UpUp() { KeyUp(in_up); } static void IN_DownDown() { KeyDown(in_down); } static void IN_DownUp() { KeyUp(in_down); } static void IN_LeftDown() { KeyDown(in_left); } static void IN_LeftUp() { KeyUp(in_left); } static void IN_RightDown() { KeyDown(in_right); } static void IN_RightUp() { KeyUp(in_right); } static void IN_ForwardDown() { KeyDown(in_forward); } static void IN_ForwardUp() { KeyUp(in_forward); } static void IN_BackDown() { KeyDown(in_back); } static void IN_BackUp() { KeyUp(in_back); } static void IN_LookupDown() { KeyDown(in_lookup); } static void IN_LookupUp() { KeyUp(in_lookup); } static void IN_LookdownDown() { KeyDown(in_lookdown); } static void IN_LookdownUp() { KeyUp(in_lookdown); } static void IN_MoveleftDown() { KeyDown(in_moveleft); } static void IN_MoveleftUp() { KeyUp(in_moveleft); } static void IN_MoverightDown() { KeyDown(in_moveright); } static void IN_MoverightUp() { KeyUp(in_moveright); } static void IN_SpeedDown() { KeyDown(in_speed); } static void IN_SpeedUp() { KeyUp(in_speed); } static void IN_StrafeDown() { KeyDown(in_strafe); } static void IN_StrafeUp() { KeyUp(in_strafe); } static void IN_AttackDown() { KeyDown(in_attack); } static void IN_AttackUp() { KeyUp(in_attack); } static void IN_UseDown() { KeyDown(in_use); } static void IN_UseUp() { KeyUp(in_use); } static void IN_Impulse() { in_impulse = Lib.atoi(Cmd.Argv(1)); } /* * =============== CL_KeyState * * Returns the fraction of the frame that the key was down =============== */ static float KeyState(kbutton_t key) { float val; long msec; key.state &= 1; // clear impulses msec = key.msec; key.msec = 0; if (key.state != 0) { // still down msec += Globals.sys_frame_time - key.downtime; key.downtime = Globals.sys_frame_time; } val = (float) msec / frame_msec; if (val < 0) val = 0; if (val > 1) val = 1; return val; } // ========================================================================== /* * ================ CL_AdjustAngles * * Moves the local angle positions ================ */ static void AdjustAngles() { float speed; float up, down; if ((in_speed.state & 1) != 0) speed = Globals.cls.frametime * Globals.cl_anglespeedkey.value; else speed = Globals.cls.frametime; if ((in_strafe.state & 1) == 0) { Globals.cl.viewangles[Defines.YAW] -= speed * Globals.cl_yawspeed.value * KeyState(in_right); Globals.cl.viewangles[Defines.YAW] += speed * Globals.cl_yawspeed.value * KeyState(in_left); } if ((in_klook.state & 1) != 0) { Globals.cl.viewangles[Defines.PITCH] -= speed * Globals.cl_pitchspeed.value * KeyState(in_forward); Globals.cl.viewangles[Defines.PITCH] += speed * Globals.cl_pitchspeed.value * KeyState(in_back); } up = KeyState(in_lookup); down = KeyState(in_lookdown); Globals.cl.viewangles[Defines.PITCH] -= speed * Globals.cl_pitchspeed.value * up; Globals.cl.viewangles[Defines.PITCH] += speed * Globals.cl_pitchspeed.value * down; } /* * ================ CL_BaseMove * * Send the intended movement message to the server ================ */ static void BaseMove(usercmd_t cmd) { AdjustAngles(); //memset (cmd, 0, sizeof(*cmd)); cmd.clear(); Math3D.VectorCopy(Globals.cl.viewangles, cmd.angles);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -