2

What is the proper setup of a fullscreen Java game that uses active rendering?

Examples at http://docs.oracle.com/javase/tutorial/extra/fullscreen/example.html do not defer rendering to the EDT. What's the reason for this? Some people tend to say that updates to the GUI should be solely done in the EDT.

E.g.: Is it possible to perform active rendering in Java Swing without being on the EDT?

Is this only true when the GUI is also created in the EDT?

After all I would prefer using the main thread for the game loop and the rendering.

How can events be handled in this environment? Would it be wise to put them in a thread safe queue and process the events in the queue at the proper place in the game loop?

Community
  • 1
  • 1
thertweck
  • 1,120
  • 8
  • 24

1 Answers1

2

Take a look at the MultiBufferText in the tutorial you linked.

What its does is create a Frame and then totally decativate rendering from the EDT (undecorated and ignoreRepaint). Since the EDT won't be attempting to render anything for that frame, there is no intereference from the EDT when rendering from another thread.

You can still handle events normally (as in KeyListener, MouseListener etc.), but you need to be aware that your listeners will be called from the EDT. You need to provide proper synchronization when you change your (game?) state in response to a listener callback.

As for is it advisable, I can't tell for sure. Since the tutorial actually demonstrates how to bypass the EDT, I presume its valid to do rendering without the EDT under these circumstances (EDT rendering disabled on window).

The other question is, is it really necessary to use active rendering? In my (admittedly very limited) experience, you can stick to passive rendering for pretty much everything (requesting a simple repaint() from outside the EDT to trigger rendering in regular intervals). Unless you're doing very heavy stuff, java2d graphics are pretty fast (overpainting the entire screen twice with small aplha'd image tiles at 60fps on 2003 hardware no problem).

If you need beam synchronized rendering, the only supported way seems to be to enter fullscreen mode.

Durandal
  • 19,919
  • 4
  • 36
  • 70