Inside3D!
     

Detecting a double-tap..

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Engine Programming
View previous topic :: View next topic  
Author Message
Downsider



Joined: 16 Sep 2008
Posts: 478

PostPosted: Sat Mar 06, 2010 7:43 pm    Post subject: Detecting a double-tap.. Reply with quote

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:
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.
Back to top
View user's profile Send private message
Downsider



Joined: 16 Sep 2008
Posts: 478

PostPosted: Sun Mar 07, 2010 7:14 pm    Post subject: Reply with quote

Got it working Smile

If anybody wants it for one of their PSP projects, swing by me..
Back to top
View user's profile Send private message
Baker



Joined: 14 Mar 2006
Posts: 1538

PostPosted: Mon Mar 08, 2010 1:17 am    Post subject: Reply with quote

I'd like to see the code.

How well does it work if you just single tap?
_________________
Tomorrow Never Dies. I feel this Tomorrow knocking on the door ...
Back to top
View user's profile Send private message
avirox



Joined: 16 Aug 2006
Posts: 109

PostPosted: Mon Mar 08, 2010 2:31 am    Post subject: Reply with quote

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..
Back to top
View user's profile Send private message
Downsider



Joined: 16 Sep 2008
Posts: 478

PostPosted: Mon Mar 08, 2010 3:03 am    Post subject: Reply with quote

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:

bind "TRIANGLE" "+forward"
binddt "TRIANGLE" "+forward; qcf A_Sprint;"


Works perfectly fine. When you single tap, it just does the normal walk forward.
Back to top
View user's profile Send private message
Baker



Joined: 14 Mar 2006
Posts: 1538

PostPosted: Mon Mar 08, 2010 8:37 pm    Post subject: Reply with quote

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.
_________________
Tomorrow Never Dies. I feel this Tomorrow knocking on the door ...
Back to top
View user's profile Send private message
Downsider



Joined: 16 Sep 2008
Posts: 478

PostPosted: Mon Mar 08, 2010 10:13 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
avirox



Joined: 16 Aug 2006
Posts: 109

PostPosted: Tue Mar 09, 2010 2:37 pm    Post subject: Reply with quote

.. 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..
Back to top
View user's profile Send private message
Irritant



Joined: 19 May 2008
Posts: 115
Location: Maryland

PostPosted: Tue Mar 09, 2010 3:18 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Engine Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group