// CL_KeyState // // Returns 0.25 if a key was pressed and released during the frame, // 0.5 if it was pressed and held // 0 if held then released, and // 1.0 if held for the entire time private static float KeyState(ref kbutton_t key) { bool impulsedown = (key.state & 2) != 0; bool impulseup = (key.state & 4) != 0; bool down = key.IsDown;// ->state & 1; float val = 0; if (impulsedown && !impulseup) { if (down) { val = 0.5f; // pressed and held this frame } else { val = 0; // I_Error (); } } if (impulseup && !impulsedown) { if (down) { val = 0; // I_Error (); } else { val = 0; // released this frame } } if (!impulsedown && !impulseup) { if (down) { val = 1.0f; // held the entire frame } else { val = 0; // up the entire frame } } if (impulsedown && impulseup) { if (down) { val = 0.75f; // released and re-pressed this frame } else { val = 0.25f; // pressed and released this frame } } key.state &= 1; // clear impulses return(val); }
private static void KeyUp(ref kbutton_t b) { int k; string c = cmd.Argv(1); if (!String.IsNullOrEmpty(c)) { k = int.Parse(c); } else { // typed manually at the console, assume for unsticking, so clear all b.down0 = b.down1 = 0; b.state = 4; // impulse up return; } if (b.down0 == k) { b.down0 = 0; } else if (b.down1 == k) { b.down1 = 0; } else { return; // key up without coresponding down (menu pass through) } if (b.down0 != 0 || b.down1 != 0) { return; // some other key is still holding it down } if ((b.state & 1) == 0) { return; // still up (this should not happen) } b.state &= ~1; // now up b.state |= 4; // impulse up }
private static void KeyUp(CommandMessage msg, ref kbutton_t b) { Int32 k; if (msg.Parameters?.Length > 0 && !String.IsNullOrEmpty(msg.Parameters[0])) { k = Int32.Parse(msg.Parameters[0]); } else { // typed manually at the console, assume for unsticking, so clear all b.down0 = b.down1 = 0; b.state = 4; // impulse up return; } if (b.down0 == k) { b.down0 = 0; } else if (b.down1 == k) { b.down1 = 0; } else { return; // key up without coresponding down (menu pass through) } if (b.down0 != 0 || b.down1 != 0) { return; // some other key is still holding it down } if ((b.state & 1) == 0) { return; // still up (this should not happen) } b.state &= ~1; // now up b.state |= 4; // impulse up }
private static void KeyDown(ref kbutton_t b) { int k; string c = cmd.Argv(1); if (!String.IsNullOrEmpty(c)) { k = int.Parse(c); } else { k = -1; // typed manually at the console for continuous down } if (k == b.down0 || k == b.down1) { return; // repeating key } if (b.down0 == 0) { b.down0 = k; } else if (b.down1 == 0) { b.down1 = k; } else { Con.Print("Three keys down for a button!\n"); return; } if ((b.state & 1) != 0) { return; // still down } b.state |= 1 + 2; // down + impulse down }
private static void KeyDown(CommandMessage msg, ref kbutton_t b) { Int32 k; if (msg.Parameters?.Length > 0 && !String.IsNullOrEmpty(msg.Parameters[0])) { k = Int32.Parse(msg.Parameters[0]); } else { k = -1; // typed manually at the console for continuous down } if (k == b.down0 || k == b.down1) { return; // repeating key } if (b.down0 == 0) { b.down0 = k; } else if (b.down1 == 0) { b.down1 = k; } else { Host.Console.Print("Three keys down for a button!\n"); return; } if ((b.state & 1) != 0) { return; // still down } b.state |= 1 + 2; // down + impulse down }
static void KeyUp(ref kbutton_t b) { int k; string c = Cmd.Argv(1); if (!String.IsNullOrEmpty(c)) k = int.Parse(c); else { // typed manually at the console, assume for unsticking, so clear all b.down0 = b.down1 = 0; b.state = 4; // impulse up return; } if (b.down0 == k) b.down0 = 0; else if (b.down1 == k) b.down1 = 0; else return; // key up without coresponding down (menu pass through) if (b.down0 != 0 || b.down1 != 0) return; // some other key is still holding it down if ((b.state & 1) == 0) return; // still up (this should not happen) b.state &= ~1; // now up b.state |= 4; // impulse up }
static void KeyDown(ref kbutton_t b) { int k; string c = Cmd.Argv(1); if (!String.IsNullOrEmpty(c)) k = int.Parse(c); else k = -1; // typed manually at the console for continuous down if (k == b.down0 || k == b.down1) return; // repeating key if (b.down0 == 0) b.down0 = k; else if (b.down1 == 0) b.down1 = k; else { Con.Print("Three keys down for a button!\n"); return; } if ((b.state & 1) != 0) return; // still down b.state |= 1 + 2; // down + impulse down }
// CL_KeyState // // Returns 0.25 if a key was pressed and released during the frame, // 0.5 if it was pressed and held // 0 if held then released, and // 1.0 if held for the entire time static float KeyState(ref kbutton_t key) { bool impulsedown = (key.state & 2) != 0; bool impulseup = (key.state & 4) != 0; bool down = key.IsDown;// ->state & 1; float val = 0; if (impulsedown && !impulseup) if (down) val = 0.5f; // pressed and held this frame else val = 0; // I_Error (); if (impulseup && !impulsedown) if (down) val = 0; // I_Error (); else val = 0; // released this frame if (!impulsedown && !impulseup) if (down) val = 1.0f; // held the entire frame else val = 0; // up the entire frame if (impulsedown && impulseup) if (down) val = 0.75f; // released and re-pressed this frame else val = 0.25f; // pressed and released this frame key.state &= 1; // clear impulses return val; }