Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (496)
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  
  Clarifying the Javadocs for EventQueue's getNextEvent()  (Read 3523 times)
0 Members and 1 Guest are viewing this topic.
Offline fishtoprecords

Senior Newbie





« Posted 2011-02-04 20:56:53 »

The standard javadocs for EventQueue show that the full API for getNextEvent() is

Quote
getNextEvent
public final boolean getNextEvent(Event event)

With nothing about what it actually does, what the argument is, when it returns true, etc.

I take it from the sample code that turns true when there is the queue is not empty, and when it is going to return true, it modifies the argument "event" to contain the event at the top of the queue.

If this is a correct guess, I'm more than willing to change the source to improve the javadoc.

Is this guess correct?

And if so, how to I submit a patch? or to who?

thanks
Pat

BTW, I'm not a fan of the API's design, which is more of a C-idiom than a standard Java one. Usually in Java, you return the entry in the queue, and if its non-blocking, you would return a null.
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #1 - Posted 2011-02-05 11:32:30 »

Hi

The API was designed by a group of engineers from companies like sun and sony, it's something we could change these days if we really wanted, but that would cause issues to people upgrading. That doesn't mean it can't happen, just that we ought to have a good reason to do so.

The getNextEvent method returns true if the queue *had* an event on it, and it managed to populate the event object you passed in with the details. False if there was nothing in the queue to copy in to your event object.
Populating an object you pass in is an efficiency saving designed to reduce the number of objects created, and thus the amount of GC needed.

Best place to submit patches is here. I'll give it a review and commit. After a few acceptable patches I'd be happy to add people to the commiters list.

HTH

Endolf

Offline fishtoprecords

Senior Newbie





« Reply #2 - Posted 2011-02-05 15:01:29 »

Cool. What's the proper access for read-only? I assume its all in CVS/SVN/GIT or something similar.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #3 - Posted 2011-02-05 15:10:03 »

It's all on jinput.java.net, you can get read access and request other roles there.

HTH

Endolf

Offline fishtoprecords

Senior Newbie





« Reply #4 - Posted 2011-02-05 16:07:52 »

Best place to submit patches is here.
new thread created for this.
Offline fishtoprecords

Senior Newbie





« Reply #5 - Posted 2011-02-05 16:29:06 »

Populating an object you pass in is an efficiency saving designed to reduce the number of objects created, and thus the amount of GC needed

Actually, this is not a correct optimization. Some lower level code (probably the poll() function) creates the Event objects and places them in the queue. There is nothing to be gained by passing in an object to populate. The standard Queue functions in the JDK just return the reference to the object created elsewhere, and "add()" to the queue.

What this class needs, IMHO, is functions aligned with the JDK's Interface Queue<E>, specifically the peek() and poll() functions. They are the standard way of dealing with queues.

Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #6 - Posted 2011-02-05 16:59:52 »

Actually, this is not a correct optimization. Some lower level code (probably the poll() function) creates the Event objects and places them in the queue.

Erm, have you written or looked at that code?, the event queue creates x events (where x is the max queue size) and holds on to them and reuses them. This way, no objects are created at run time (after the initial setup).

Endolf

Offline fishtoprecords

Senior Newbie





« Reply #7 - Posted 2011-02-05 23:25:24 »

Yes, and the add() code replaces the Event object at the tail.

Seriously, take a breath. Its OK for old code to have creaky edges.

To make a full assessment, I'd have to dive into the code that populates the queue when you do a poll(), which is more effort than this tiny routine merits. But in the AbstractController class, the poll() function calls add() on the queue, replacing the Event that was there with the static one in the class. The Event is loaded using getNextDeviceEvent(Event event), which is abstract. Other implementations may do other things.

Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #8 - Posted 2011-02-05 23:33:58 »

If you mean line 232 of AbstractController, and then look at what the add method is doing, it takes the values from the supplied event, and sets them on the event at the tail of the queue. It wouldn't work if we did it with the static as every single event in the queue would end up being set to the static one.

And I'm sure there are some creaky bits in there, but you've yet to find those Smiley

Endolf

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 (14 views)
2014-09-19 03:14:18

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

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

TehJavaDev (80 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 (46 views)
2014-09-07 01:13:42

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

Longarmx (37 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!