lwjgl Exiting my launcher and starting my game

I’ve set out on a journey to make the greatest (and my first) game in history, and like all great games I thought I’d have a launcher with options and such and a play button.

When finished adjusting one’s settings, which are stored in a .properties file, the idea is that one clicksplay to play, whereupon the launcher quits (and releases it’s resources) and the game starts.

The way I’ve done this is as follows:



public class Main {

	public static void main(String[] args) {
		if (new Engine().start()){
			System.out.println("gamestarting");

		}
	}

}


The engine class is the engine for my launcher. It returns true if play is pressed and false if exit is pressed.

Now, when the engine exits it does Display.destroy() and AL.destroy(), and since I don’t create a reference to my engine in the main method, I’m hoping the JVM throws away all resources associated with it, so that it doesn’t compromise the actual game when I run it.

However, if I do this:



public class Main {

	public static void main(String[] args) {
		if (new Engine().start()){
			new Engine().start();
		}
	}

}



I get exceptions. The first I get is this:

Exception in thread “main” java.lang.UnsatisfiedLinkError: org.lwjgl.openal.AL10.nalGenBuffers(IJ)V
at org.lwjgl.openal.AL10.nalGenBuffers(Native Method)
at org.lwjgl.openal.AL10.alGenBuffers(AL10.java:1019)
at org.newdawn.slick.openal.SoundStore.getWAV(SoundStore.java:714)
at org.newdawn.slick.openal.SoundStore.getWAV(SoundStore.java:683)
at org.newdawn.slick.openal.AudioLoader.getAudio(AudioLoader.java:54)
at components.audio.Sound.(Sound.java:15)
at launcher.Resources.(Resources.java:23)
at launcher.Engine.(Engine.java:47)
at main.main.Main.main(Main.java:10)

But I suspect there will be more.

My question is how I can solve this problem. Isn’t display.destroy() and AL.destroy() enough so that I can start from a clean slate?
What I’d really like to do is close down the entire JVM and start up the game, but I don’t know if that’s possible. Perhaps I can start my launcher as a thread and join it once it’s done. Would that clean the slate?

First of all, don’t set off to make the greatest game ever. That’s putting your hopes too high.

Also, try to actually make the game before working on aesthetics like menus and stuff. However if you really want to do this, I’d take the OOP approach and create a hierarchy of GUI elements, eg, Element -> Button implements Clickable and so on. Creating a GUI library can be a complex and confusing process. I’d just focus on the game.

Also, is there really a need for a ‘launcher’? Games like Minecraft and Planetside have these things, but honestly your game most likely just needs a main menu which leads into the actual game. No need to close down and restart. Just use the same context, there’s nothing inherently wrong with doing so.

Thanks. I probably won’t need a launcher, or maybe I will, who knows… Regardless of the case it will have been great fun making one and I want to learn how I can solve the problems it poses.

[quote] whereupon the launcher quits (and releases it’s resources)
[/quote]

  1. It’s a launcher, it is not using significant resources.

  2. The garbage collector will clean up after you.

Conclusion: there is no problem to solve. Just put up a swing dialog, and when the user clicks OK, start your game.

  1. It’s a launcher, it is not using significant resources.

  2. The garbage collector will clean up after you.

Conclusion: there is no problem to solve. Just put up a swing dialog, and when the user clicks OK, start your game.
[/quote]
This is my problem:

Exception in thread “main” java.lang.UnsatisfiedLinkError: org.lwjgl.openal.AL10.nalGenBuffers(IJ)V
at org.lwjgl.openal.AL10.nalGenBuffers(Native Method)
at org.lwjgl.openal.AL10.alGenBuffers(AL10.java:1019)
at org.newdawn.slick.openal.SoundStore.getWAV(SoundStore.java:714)
at org.newdawn.slick.openal.SoundStore.getWAV(SoundStore.java:683)
at org.newdawn.slick.openal.AudioLoader.getAudio(AudioLoader.java:54)
at components.audio.Sound.(Sound.java:15)
at launcher.Resources.(Resources.java:23)
at launcher.Engine.(Engine.java:47)
at main.main.Main.main(Main.java:10)

You’re missing some natives on your classpath. You’re overthinking this. You already have your game starting without a launcher I suppose? Go to the main method of that, and add a JDialog or whatever before you do any other business. Then you have a launcher.

Oops an accidental medal…

I solved it like this:

I initiated GL an AL in the main method.



void static main (String[] args){
initGl();

if (args[0] == "Launcher"{
    if (new Launcher().start())
        new Game().start();
} else
new Game().start();

destroyGl();

}


At a later stage I’ll make two different executives that runs this method, one passing the string Launcher and the other nothing. I can also add other arguments in the future…