Re: Requesting tips, comments for an EDT thread-safe game architecture



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/
.



Relevant Pages

  • Re: Syncronization message
    ... In Windows Explorer, click Synchronize on the Tools menu, and then click ... synchronize from the current network connection. ... Since there are normally no errors, I would like to not have that window ...
    (microsoft.public.windowsxp.general)
  • Re: Swing/Thread ShortCut - Bad Style or Good Idea?
    ... realize that Swing uses threads to synchronize shared objects. ... If a method is not noted as being thread safe, ... There's also invokeLater(), but invokeAndWait is likely to be a bit easier to understand because it's synchronous. ...
    (comp.lang.java.programmer)
  • mNotes / Calendar Synchronization Problem
    ... in order to synchronize the Notes Calendar with my ... The synchronization from my office PC --> PPC works well. ... But, when I synchronize my home PC with my PPC, I have some unsolved ... a window entitled "Checking names" is displayed. ...
    (microsoft.public.pocketpc)
  • Re: TThread.Synchronize() without the wait
    ... Look into how Synchronize is done - it also ... post a message to the same window handle. ... what - ThreadWindow variable is not public;-))). ... > for receiving (e.g. if you are using a datamodule) I would use a TForm ...
    (borland.public.delphi.nativeapi)
  • synchronize contacts in personal folder with contacts folder
    ... Is there a way to synchronize my contacts in "Contacts in Personal Folder" ... able to pull up the contact through the "Select Names" window under the ... but am not able to synchronize with my Palm device. ...
    (microsoft.public.outlook.contacts)