How can you distribute game with incremental garbage collection -Xincgc
Hi,
I have a game that runs much more smoothly when i use the -Xincgc option on the command line when I run it. It works like any option, eg
"C:\Program Files\Java\jdk1.5.0\bin\java.exe" -Xincgc -classpath "C:\TheGame"
How can I distribute the game with this option whenever a user runs my program by double clicking the jar file?
I tried calling System.gc() in the game loop every couple of iterations but it doesn't work the same, it slows the game down badly.
Thank you,
Keith
> Hi,
> I have a game that runs much more smoothly when i use
> the -Xincgc option on the command line when I run it.
> It works like any option, eg
right on
> How can I distribute the game with this option
> whenever a user runs my program by double clicking
> the jar file?
you can't, you need to provide a batch script/file
> I tried calling System.gc() in the game loop every
> couple of iterations but it doesn't work the same, it
> slows the game down badly.
yeah, don't do that :-)
Thanks for your help SoulTech.By the way, can you make these batch/script files distributable in a platform independent way? How would you do that?Also, can you set the -Xincgc option on an applet?
Why not recursively start the Java application in a new VM with the appropriate switches ...? Use a special application command-line switch to terminate the recursion.
E.g.:
User starts the game by double-clicking the "TheGame.jar". Since no "--playgame" option is specified by default, the code goes into the else clause below to start.
class TheGame
{
public static void main( String args[] )
{
if( ContainsParam( "--playgame", args) )
{
// --playgame was specified, this means we are in the
// second ("child") process that has been started with
// good jvm options.
// Play the game.
TheGame gameObject = new TheGame();
// Exits when player is done gaming.
gameObject.Play();
}
else
{
// --playgame not specified. This must be the first ("top-level") process.
// Start the game in (hopefully) another VM with options that we want.
Runtime.exec(
"java",
new String[] = { " - -Xincgc", " -jar", "TheGame.jar", " --playgame"} );
// Assuming the above newly-started process won't
// exit when we exit, exit this process and leave the player
// playing the other one.
return;
}
return;
}
// Game code ....
private void Play()
{
...
}
}
Would that work?
Derek
Thanks for your idea Derek, that's a great way to do it - use Runtime.exec().
I can use the System.getProperty() to find the JRE home directory too so I can run the 'java' command by fully specifying the path to that exe file.
I can just return in the main method of the 1st JRE once the 2nd JRE (with correct options) is working, which is good. Its a pity this has to be done however since now the game will have to take the time to load two JREs every time you start it.
Thanks,
Keith