Re: Requesting tips, comments for an EDT thread-safe game architecture
- From: Knute Johnson <nospam@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 Mar 2007 18:14:23 -0700
Oliver Wong wrote:
I recently saw a thread about the Swing EDT in the CLJP, and it made me wonder whether my general game architecture was thread safe or not. EDT, and threading in general, are one of my weaker points in Java. Is this general design okay? Are there things which I've put into the EDT which I shouldn't have? Are there things which are outside of the EDT that should be in it?
@Override
public void windowClosing(WindowEvent e) {
timeToQuit = true;
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
synchronized (mainWindow) {
mainWindow.setVisible(false);
mainWindow.dispose();
}
}
});
}
Oliver:
Window events are already processed on the EDT you don't need to specifically call them with EventQueue.invokeLater().
I'm not sure why you have the calls to set then main window visible and dispose it synchronized. They are already being called on the EDT and if you don't make any Swing method calls except on the EDT they will already be synchronized by default.
Having played a lot with one form of animation, I would use a completely different tack. Use a Window or JWindow and do active rendering. This avoids the EDT altogether for any drawing. You still may have to synchronize some parts of your code but the more you can avoid that the better. Synchronizing can have a rather significant performance hit.
--
Knute Johnson
email s/nospam/knute/
.
- Follow-Ups:
- Re: Requesting tips, comments for an EDT thread-safe game architecture
- From: Daniel Pitts
- Re: Requesting tips, comments for an EDT thread-safe game architecture
- References:
- Requesting tips, comments for an EDT thread-safe game architecture
- From: Oliver Wong
- Requesting tips, comments for an EDT thread-safe game architecture
- Prev by Date: Re: Automatically resize font when component size changes?
- Next by Date: Re: Requesting tips, comments for an EDT thread-safe game architecture
- Previous by thread: Requesting tips, comments for an EDT thread-safe game architecture
- Next by thread: Re: Requesting tips, comments for an EDT thread-safe game architecture
- Index(es):
Relevant Pages
|
|