Ejemplo n.º 1
0
        // 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 float KeyState(ref kbutton_t key)
        {
            var   impulsedown = (key.state & 2) != 0;
            var   impulseup   = (key.state & 4) != 0;
            var   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);
        }
Ejemplo n.º 2
0
        private static void KeyUp(CommandMessage msg, ref kbutton_t b)
        {
            int k;

            if (msg.Parameters?.Length > 0 && !string.IsNullOrEmpty(msg.Parameters[0]))
            {
                k = int.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
        }
Ejemplo n.º 3
0
        private static void KeyDown(CommandMessage msg, ref kbutton_t b)
        {
            int k;

            if (msg.Parameters?.Length > 0 && !string.IsNullOrEmpty(msg.Parameters[0]))
            {
                k = int.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
            {
                client_input.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
        }