Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Do I need to Keyboard.poll()?  (Read 2762 times)
0 Members and 1 Guest are viewing this topic.
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Posted 2005-05-31 11:31:18 »

I am using Keyboard.isKeyDown(KEY_xxxx) to detect keypresses & have not included a call to Keyboard.poll() in the main loop.

This works, but am I creating a steadily growing list of unprocessed key events?

If so, would a periodic call to Keyboard.poll() clear them?

On a similar vein, do I need to call Mouse.poll() regularly to avoid a build up of mouse events?

Alan

/Edit - The description of Display.update() says it polls input devices.  I *do* have that in my code. Hopefully that means there is no need to poll separately.

Time flies like a bird. Fruit flies like a banana.
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #1 - Posted 2005-05-31 12:16:04 »

you need to read the buffered events, or simply discard them:
1  
while (Keyboard.next()) { /* loop through events*/}

Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #2 - Posted 2005-06-03 16:50:20 »

Matzon,

Thanks for the reply, which has confirmed my suspicions.  Should I empty the mouse queue too?

1  
2  
while (Keyboard.next()) { };
while (Mouse.next()) { };


(I am assuming it is Mouse.next() but can't check right now as the javadoc's on my other computer)

Alan

Time flies like a bird. Fruit flies like a banana.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline LastBoyScout

Senior Newbie




Java games rock!


« Reply #3 - Posted 2005-06-03 18:21:35 »

If I remember correctly the event queues (at least the keyboard event queue) only queue up to some 10 (or so) events...
I'd say there is no need to "pseudo" process them just to make them go away !?

LastBoyScout
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #4 - Posted 2005-06-03 18:30:18 »

If I remember correctly the event queues (at least the keyboard event queue) only queue up to some 10 (or so) events...
I'd say there is no need to "pseudo" process them just to make them go away !?

LastBoyScout


Interesting.

I checked memory usage & it didn't seem to grow significantly during game play without emptying the event queues.

Looking at the source we have (for keyboard)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
   public static void poll() {
      if (!created)
         throw new IllegalStateException("Keyboard must be created before you can poll the device");
      Display.getImplementation().pollKeyboard(keyDownBuffer);
      read();
   }

   private static void read() {
      readBuffer.compact();
      int numEvents = Display.getImplementation().readKeyboard(readBuffer, readBuffer.position());
      readBuffer.position(readBuffer.position() + numEvents*EVENT_SIZE);
      readBuffer.flip();
   }


I guess I need to check what happens if you try to write past the end of a NIO buffer Wink

Alan  Smiley

/Edit  BufferOverflowException it seems - so why didn't this happen?

Time flies like a bird. Fruit flies like a banana.
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #5 - Posted 2005-06-03 20:04:12 »

coz the native code only adds up to a certain point
then it starts warning if debug is turned on I think Smiley -Dorg.lwjgl.util.Debug=true

Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #6 - Posted 2005-06-03 20:08:16 »

Thanks.

All clear now.

Alan Smiley

Time flies like a bird. Fruit flies like a banana.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (13 views)
2014-09-19 03:14:18

Dwinin (31 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (79 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (62 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (30 views)
2014-09-07 01:12:14

Longarmx (36 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!