Forum

Detecting a double-tap..

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

Detecting a double-tap..

Postby Downsider » Sat Mar 06, 2010 7:43 pm

Trying to make an interface to detect double-taps for any key, as the PSP has a limited control scheme.

Any ideas as far as it could be done?

I was thinking about modifying this struct:

Code: Select all
typedef struct
{
   int      down[2];      // key nums holding it down
   int      state;         // low bit is down state
} kbutton_t;


to have a time value as well, that would be set to like time + .1 when the initial keypress is detected, then if it hasn't expired by the time the second keypress is detected, perform an alternate binding?

Is there a better way? I'm sure you people that have been modding Quake for years could think of a better way.

EDIT: I also have no clue if this is used for button presses or an on-screen-keyboard.
User avatar
Downsider
 
Posts: 621
Joined: Tue Sep 16, 2008 1:35 am

Postby Downsider » Sun Mar 07, 2010 7:14 pm

Got it working :)

If anybody wants it for one of their PSP projects, swing by me..
User avatar
Downsider
 
Posts: 621
Joined: Tue Sep 16, 2008 1:35 am

Postby Baker » Mon Mar 08, 2010 1:17 am

I'd like to see the code.

How well does it work if you just single tap?
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby avirox » Mon Mar 08, 2010 2:31 am

i can think of an easy way to do this in CSQC, but i am also interested in seeing how you did it in ssqc..
avirox
 
Posts: 137
Joined: Wed Aug 16, 2006 3:25 pm

Postby Downsider » Mon Mar 08, 2010 3:03 am

It's in the engine programming subforum for a reason, Avirox =O

I added the commands binddt and unbinddt and essentially copied over a bunch of the code in key.c with minor alterations to suit the double-tap array of commands assigned to keys. Then I simply had a global variable for the last pressed key and the time it was pressed, compared, and if it was within .3 "time" ago (I have no clue at the scale which Quake does time so I'll refer to it as "time" instead of seconds), I Cbuf_Addtext'd the command that the key was bound to.

For instance, in my game, I want the character to sprint when he double tapped triangle, this is what the config reads as:

Code: Select all
bind "TRIANGLE" "+forward"
binddt "TRIANGLE" "+forward; qcf A_Sprint;"


Works perfectly fine. When you single tap, it just does the normal walk forward.
User avatar
Downsider
 
Posts: 621
Joined: Tue Sep 16, 2008 1:35 am

Postby Baker » Mon Mar 08, 2010 8:37 pm

Possibly another useful related idea, the idea of holding the button down for more than a second or two has an alternate function.

One possible example, alter jump so the jump occurs on key release but if the button is held more than a couple of seconds it is a forward lunge attack that knocks enemies out of the way.

Nice idea downsider on thinking how to reuse existing controls.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby Downsider » Mon Mar 08, 2010 10:13 pm

Yeah but that's quite a bit harder to implement.. Now you'd need a function calling every single frame to compare how long since the keydown event.
User avatar
Downsider
 
Posts: 621
Joined: Tue Sep 16, 2008 1:35 am

Postby avirox » Tue Mar 09, 2010 2:37 pm

.. which is why i asked how you were doing it in ssqc, thinking that you may have implemented some extension to read client key inputs. That's how I would do it, sans CSQC, anyways..
avirox
 
Posts: 137
Joined: Wed Aug 16, 2006 3:25 pm

Postby Irritant » Tue Mar 09, 2010 3:18 pm

I know it's a different engine, but you could see how this is done in Alien Arena - http://svn.icculus.org/alienarena/

Bulk of it is in p_client.c in Clientthink().
http://red.planetarena.org - Alien Arena and the CRX engine
Irritant
 
Posts: 250
Joined: Mon May 19, 2008 2:54 pm
Location: Maryland

Postby Jukki » Fri Oct 15, 2010 12:30 pm

hello, and sory forreviving this, But how did you do it in code. I need this thing in my engine and my c skills are like how good i speak russian. :?
Jukki
 
Posts: 214
Joined: Wed Apr 07, 2010 4:59 am

Postby Jukki » Mon Mar 21, 2011 4:01 pm

and sory for revivng this againg. Well double tap would help alot atm. Want to share or tell me how to do this. me stupid, veeery stupid
Jukki
 
Posts: 214
Joined: Wed Apr 07, 2010 4:59 am


Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest