• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
himynameisnick

moving in a 3d space: movement delay when pressing keys

3 posts in this topic

Hi, sorry if this has been answered somewhere, I checked google and searched the forums here and found nothing. If it has already been answered I would appreciate any links!

This is a project for a computer graphics class I'm in, we are to make an animation or game or do a research paper, and I chose to make a game (duh). Anyway, I created a 3d world that you can fly around in using opengl on a linux machine.

The problem is that when I push a key to move, there's a slight delay before you actually start moving, maybe half a second at the most. It's especially annoying when I'm moving forward and then push one of the keys to turn, it works but as soon as I hit the second key it stops moving for half a second and then starts moving again.

Does anyone know what's causing the delay?


ps. I think the NeHe tutorial 10 is about moving in a 3d space but I'm having trouble getting it to run on my computer. It runs on the machines at my school but I'm not going back there until monday :P
0

Share this post


Link to post
Share on other sites
Sounds like it might have something to do with how you're capturing key events. I get the feeling your half second delay is the time between when you hold down a key and when the OS starts sending character repeats (like when you hold down 'a' in a text editor, it sends it once, than after a 1/2 to 1 second it starts spamming 'aaaaaaaaa' until you release.

I'm not that familiar with linux input events, but that sounds like a culprit to me. Are you capturing keyup/keydown messages and setting a state off of that, or are you just moving anytime you get a keydown message?
0

Share this post


Link to post
Share on other sites
[quote name='karwosts' timestamp='1301176955' post='4790793']
Sounds like it might have something to do with how you're capturing key events. I get the feeling your half second delay is the time between when you hold down a key and when the OS starts sending character repeats (like when you hold down 'a' in a text editor, it sends it once, than after a 1/2 to 1 second it starts spamming 'aaaaaaaaa' until you release.

I'm not that familiar with linux input events, but that sounds like a culprit to me. Are you capturing keyup/keydown messages and setting a state off of that, or are you just moving anytime you get a keydown message?
[/quote]


I'm capturing keyup/keydown messages. I think you might be right, I noticed when I hit the key it actually moves just a little bit, pauses half a second, and then starts moving again.
0

Share this post


Link to post
Share on other sites
Linux input events basically go "KEYDOWN... {pause}, KEYREPEAT, KEYREPEAT, KEYREPEAT, KEYREPEAT, KEYREPEAT, KEYREPEAT, KEYREPEAT,KEYUP"

What you need to do is remember the state of the keys between events and query that state store instead of examining the events themselves.

If you set up a mapping between X keynames ( the ones in the events ) and your interpretation (up, down, left, right etc which you can enumerate as small integers), then you can have a small array to store the keystates.

The event interpretation then just puts a 1 or 0 in the appropriate array slot for up and down. Ignore the keyrepeats.

There are TWO important gotchas here. One is obvious and one isn't.

The first is that X11 doesn't actually conveniently send you a keyrepeat code for you to ignore. Why it doesn't I don't know but hacky bodging seems likely.

So what you get is a "keyup/keydown" pair of events.

Your options here are just use them as they are or to find the repeat and deliberately ignore it.

If you process ALL pending events between frames, chances are you'll always process both parts and your state array will still hold a "1" for key down, and then everything "just works"

If you timelimit or countlimit your event handling, you may not process both halves, so you need to check if an UP is really an up or part of a repeat. The way to test that (and hence whether to discard) is to take the event, and if it's a keyup peek at the next one. If that's a keydown for the same key AND has the same timestamp as your keyup then you've got a repeat and you can bin them both.

{Technically you're supposed to go on a crawl of the event stack because there technically might be an event in between, but a) that's a pain to do because it needs predicate routines and void casts and nasty stuff like that and b) it's usually never the case on local servers.}


Your second gotcha is the focus. If you lose keyboard focus, you will not get key up events. Hence -- press the button, hold it, click mouse outside the window, release key.... and you'll never see the up event because it went to another window and in this new world of processing state and not events, that's a perpetual turn.

There are two fixes -- the easy way and the technically correct way. The latter is to use a keyboard grab. I wouldn't bother if I were you. Do the easy thing; catch the "lost focus" event (which you WILL get as you click) and clear down your state array at that point ending the movement. It'll be good enough while you're developing and it's less likely to lead to tears than keyboard grabs.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0