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

[523 byte] By [CommanderKeitha] at [2007-10-1 21:00:55]
# 1

> 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 :-)

SoulTech2012a at 2007-7-13 2:57:40 > top of Java-index,Other Topics,Java Game Development...
# 2
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?
CommanderKeitha at 2007-7-13 2:57:40 > top of Java-index,Other Topics,Java Game Development...
# 3

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

Arborfielda at 2007-7-13 2:57:40 > top of Java-index,Other Topics,Java Game Development...
# 4

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

CommanderKeitha at 2007-7-13 2:57:40 > top of Java-index,Other Topics,Java Game Development...
# 5
Or use one of the exe wrappers out there. One commercial one is exe4j... I've also seen several free ones out there.
JN_a at 2007-7-13 2:57:40 > top of Java-index,Other Topics,Java Game Development...
# 6
The OP was asking for a platform independent way to do this. Exe wrappers are not.
Herko_ter_Horsta at 2007-7-13 2:57:40 > top of Java-index,Other Topics,Java Game Development...