Friendly Gameloop to allow tab /focus switch (ALT+TAB)?

Started by Evil-Devil, September 08, 2012, 21:51:03

Previous topic - Next topic

Evil-Devil

Hi all,

its no problem to create a straight forward rendering, but still I haven't found a way to write a loop that does allow other activities beneath the ogl app.

while (this.running) {
	if (Display.isCloseRequested()) {
		this.running = false;				
		this.dispose();
	}			
		
	if (Display.isActive() && Display.isVisible()) {
		this.render();
		Display.update();
	}
}


My rendering loop is pretty easy, but even starting the application from within eclipse, setting the focus on eclipse and switch back to the ogl app, it does not respond anymore. I would appreciate any suggestions to avoid this as i like to have an app that does allow tab switching.

CodeBunny

Here's mine (very abstracted, but fairly straightforward):
protected void run()
{
	start(); // Initializes the game
	while (!shouldExit()) // Checks both a control boolean and Display.isCloseRequested()
	{
		controller.tick(); // Updates the time
		update(controller.delta()); // Updates the game based upon the delta time
		render(); // Renders the game, also calls Display.Update()
		controller.sleep(); // Handles sleeping the thread
	}
	end(); // Handles shutdown.
}


Display.isActive() seems to be bugged. When I added it to my game, it froze just like yours - upon losing focus, it will permanently return false, and also seems to block exit operations from proceeding. I've basically taken the option of not using it whatsoever.

Obsyd

If your Display.udpade is not being called it will seem like your app is frozen. (because Dsiplay.update calls Display.processMessages())
Display.processMessages() still needs to be called once in a while.

delt0r

I use Display.isActive and it works like a charm. I just sleep 100ms each loop so update is always getting called. I have noticed massive performance penalty with composing desktops. Turning it off works nicely.
If you want a plot read a book and leave Hollywood out of it.

CodeBunny


Evil-Devil

Quote from: Obsyd on September 09, 2012, 14:55:49
If your Display.udpade is not being called it will seem like your app is frozen. (because Dsiplay.update calls Display.processMessages())
Display.processMessages() still needs to be called once in a while.

Ah ok, I'll give it a try :)

Evil-Devil

Sry 4 double post...

It works, thanks alot =)

if (Display.isVisible() && Display.isActive()) {
	this.render();
	Display.update();				
} else {
	Display.processMessages();
}