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



"Oliver Wong" <owong@xxxxxxxxxxxxxx> wrote in message
news:soxMh.490$NM.6958@xxxxxxxxxxxxxxxxxxxxxxx
[most of the code snipped]

/*
* This while loop is the main game loop. It basically iterates through
* 3 stages forever: getting the player input, reacting to it, and
* drawing the results on screen.
*/
while (!timeToQuit) {
getPlayerInput();
processGameLogic();
EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
if (mainWindow != null) {
BufferStrategy strategy = mainWindow
.getBufferStrategy();
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
Insets insets = mainWindow.getInsets();
g.translate(insets.left, insets.top);
g.setTransform(AffineTransform
.getScaleInstance(
(double) (mainWindow.getWidth() - insets.right)
/ (double) DEFAULT_RENDERING_WIDTH,
(double) (mainWindow
.getHeight() - insets.bottom)
/ (double) DEFAULT_RENDERING_HEIGHT));
updateScreen(g);

Oops, I should probably call g.dispose() here.

strategy.show();
}
}
});
Thread.sleep(1);
}

- Oliver


.