PDA

View Full Version : Advice on Java gaming (for multiplatform support)


Techdojo
10-23-2007, 01:16 AM
Originially this was a private message to Cas but he generously offered to share his advice in public, so this reposted here for any and all Java developers to contribute to (and anyone who's interested to learn from!)

Jon...



Hi there,

I know (from seeing your website) and reading some of your posts on this forum that you develop your games in Java.

I've been a professional games developer in C for a long time and I'm considering switching to Java (mostly to make multi-platform apps easier to develop, but also because I'm hoping to switch to a linux based machine to dev on) and I was wondering if you'd be prepared to share some advice either directly, via a thread on the forums or as an entry in your blog.

I'm currently looking at using the LWJGL libs possibly with Eclipise as an IDE (I'm assuming that OpenGL gives all the accelerated hardware support you need), but I'm interested in how you package the final apps into their various native formats for use on Windows, Mac's and Linux (and also if the latest version of Vista has caused any serious headaches).

Any help or advice you can provide will be much appreciaited...

Jon...

FiNiPa
10-23-2007, 01:44 AM
... so is his advice to better keep away from Java :D or is his statement missing ... ? ;)

Techdojo
10-23-2007, 02:05 AM
Actually he said "ask away" and was happy to make all comments public so I thought I'd repost here so any and all could contribute something "productive" and learn something...


Eclipse - excellent choice. LWJGL - even more excellent



As I said, my main interest is in how the final app is packaged and delivered on a the different systems. Hopefully once the hardwork is done on the actual game itself (and please - I don't want this to turn into a my language is better than yours pissing contenst) then leveraging the resources to make three fully saleable products *should* be relatively painless...

Jon...

princec
10-23-2007, 03:53 AM
Right, here's what we do:

For Linux - we don't bother doing anything, we just provide a Webstartable game.

First we use a very crappy Ant script like this one here that we use for Treasure Tomb (http://www.puppygames.net/downloads/shared/test/TreasureTomb.jnlp):
597

Mostly a test build just requires me to hit "Webstart Builds" and that creates a single fat jar, TreasureTomb.jar.

A full Win32 build plonks the TreasureTomb.jar into a directory structure containing a JRE (in our case a 1.4.2 VM with most of the crap hacked out of it to make it tiny). We have a simple stub launcher exe in there that invokes said JRE via JNI with a few arguments. Here's the Titan Attacks launcher:
598

We then molebox (http://www.molebox.com) the directory with the JRE lib, bin, .exe and .jars, and put the final Moleboxed .exe in a directory containing:
OpenAL32.dll
lwjgl.dll
jinput-dx8.dll
jinput-raw.dl
and some readmes etc.

Then that lot gets NSISed up into a self extracting installer using this rather primitive NSIS script. Someone please give me a better one!
599

That's Win32 sorted.

Cas :)

princec
10-23-2007, 03:54 AM
For Mac OS X, we use the same Ant script above, but we've got a native little launcher thingy (which might be out of date now so I won't post it here) which comes with Mac OS X development tools, that has a bunch of parameters that are meddled with in the Ant script. It's all a bit smoke and mirrors to me but it works. The final result is a .zip of a Mac OS .app directory structure.

Cas :)

Techdojo
10-23-2007, 05:07 AM
That's a great help thanks, plus the molebox link is just what I'm looking for (for a different project)

Jon...

elias4444
10-23-2007, 07:36 AM
I do something similar (which actually stems from the same advice Cas gave above... thanks Cas!)...

I develop on Mac OSX, but am able to package for all the platforms with a single ANT script now. I use the native Mac OSX javaapplicationstub to create the famous .app files on the Mac (Macs are SO easy to create applications for). I use launch4j to package the primary jar into an exe for windows (and then use NSIS to package it up for installation along with the natives and other libraries). And, this I learned from the Tribal Trouble guys, I use makeself in order to package the files and linux natives into a self-extracting-and-installing .sh file.

The ANT build file is just a nice way to automate everything so I can hit "build" once and it spits out all of my distributions into a single directory structure, ready to be uploaded. I'd post it here, but it may be too long.

Word of caution though: I've been seriously thinking about going back to using the Java Webstart system for Linux. It's REALLY hard to get a game to install the same way on all the different distributions out there. Using Java Webstart can save me a big hassle by making sure that the user has installed Java in whatever way it needed to be installed for their platform. And I really don't like that 80% of my effort in building installers has to be focused on the platform (Linux) that gives the fewest amount of sales.

FiNiPa
10-23-2007, 09:23 AM
That's really a great help! I read somewhere that you still use 1.4x? is that true? I wonder because I never liked webstart before, but your beta and some other apps I used recently are also webstart and they all work perfectly for me. I have 1.6x.

@Techdojo: My comment was meant as a little dot of humor, I hope you don't feel attacked in any way, if you do, then sorry, will try to work at my humor, but no promise :o

elias4444
10-23-2007, 10:26 AM
Are you talking about the demo for Tommy Twisters? Or are you directing the question at one of Cas' demos (he has a lot more than I do ;) )?

If it's at me: The demo you probably downloaded was an older one, and would have been written in Java 1.4x (backwards compatibility issues kinda disappeared when Microsoft stopped messing with everything). I've really appreciated how well webstart has worked on the Linux side. The only catch is, the user has to get Java installed on their own first (but chances are, most Linux users have done something much more difficult than that already). Oh, and the fact that you get a little Java popup screen the first time the jnlp file is downloaded. Still, it's been easier and has better cross-distribution compatibility than anything else I've tried... it even auto-updates the game when I release an update for it. Can't complain about that! :D

princec
10-23-2007, 10:34 AM
We're stuck at 1.4.2 until 95% of the OSX users out there are running 1.5.

Cas :)

wazoo
10-23-2007, 11:21 AM
Awesome thread, as I've always wondered how to go about the same process!

Thanks Cas (and Jon for sharing) for posting this info!

Also didn't realize that so much of the OSX client userbase out there were still running 1.4...I thought the bulk of them had already migrated into 1.5 territory..

FiNiPa
10-23-2007, 11:24 AM
well I was actually referring to Cas, but I will gladly take your experience too!
A friend of mine, a java disliker, has 1.4.2 installed but has problems with Webstart.
I am actually developing with the newest 1.6.3 on windows and using processing as api with eclipse which helps me allot. Unfortunately I will only be able to test on Windows and Linux. But as I am doing a thorough prototyping first, it's no problem for now. Later on, when I actually want to publish it, I will need some help sooner or later anyhow.

BTW I will be looking for some compagnons, any Java Guru thinking of the possibility of joining in someday or are you all more or less a one man team by choice? If you want to know more or are possibly interested you can send me a pm, I will try to explain the big picture without getting into details.

elias4444
10-23-2007, 02:19 PM
well I was actually referring to Cas
Yeah, I should have figured as much. Don't mind me... I'm just trying to get my # of posts up a bit. ;)

FiNiPa
10-23-2007, 03:31 PM
Yeah, I should have figured as much. Don't mind me... I'm just trying to get my # of posts up a bit. ;)

nahh, now really, this is a very interesting field and every experience is really valuable. It's a pity that the newest Java isn't always included in ms updates :D

princec
10-23-2007, 03:47 PM
Probably best that it isn't, or we'd be in the same situation as Mac OS, stuck at 1.4.2 for years.

The new 1.6 update N stuff is awesome - a legit JVM in 1.9MB.

Cas :)

FiNiPa
10-23-2007, 03:55 PM
You're probably wright about the ms update, but maybe an outdated version would be better than none?
Is the new version with the small JVM out? must have a look....

Another small question I have, do you use scripting, like groovy, jython or lua?
I tried groovy, but it didn't fit because of the slowness, terribly slow for what I could need it.

princec
10-23-2007, 04:44 PM
Nah, never used scripting, never done anything remotely complex enough to warrant it.

Cas :)

Aldacron
10-23-2007, 05:42 PM
Is the new version with the small JVM out? must have a look.....

It doesn't actually have a small JVM, it just allows you to install only the bits of the JVM you need on the end user's system. From a page on new features in Update N (https://jdk6.dev.java.net/6uNea.html):


The Kernel installation mode (not available yet in this build) lets first time Java users run applets and Web Start applications without waiting for the whole JRE download. While the default Kernel installation will work with existing Java applets, application developers have the ability to select libraries that should be installed with the kernel, before the rest of the JRE is installed on the end user's system.


You can download the latest snapshot release (not yet an official release) here (http://download.java.net/jdk6/). Kernel mode isn't available yet, but there are other goodies to play with.


I tried groovy, but it didn't fit because of the slowness, terribly slow for what I could need it.


You might try pnuts (https://pnuts.dev.java.net/). I've not benchmarked it myself, but I've heard its one of the better performing scripting languages for Java. If the learning curve seems too steep, Rhino (http://www.mozilla.org/rhino/) is also rather performant and may be more familiar, being that it's JavaScript. Java6 ships with a Rhino implementation for the scripting framework, but it doesn't support script compilation (it's purely interpreted). To get compilation, you'll need to download from the Rhino site.

As an alternative, you might want to check into dynamic compilation of Java source and the hot loading of classes. It takes a little bit more effort to get set up, but it's not too painful. Sort of makes scripting languages superfluous from a development perspective. Unless, of course, you're adding scripting primarily for non-developers. In which case, Rhino would probably be the best of all options.

oNyx
10-23-2007, 05:47 PM
Try Janino (http://janino.net/). It's an ultra fast on-the-fly compiler. It takes less than a second to compile a dozen files on a 500mhz machine.

Since it's a compiler you can even script inner loops or prototype hefty algorithms. It's pretty mature and the author is very responsive. All bugs I filed were fixed in no time.

elias4444
10-23-2007, 07:32 PM
Well Cas, I set my eclipse dev environment to compile to 1.4.2 specs so I can be MORE mac compatible. I can't believe I've become so reliant on Generics already. :( I'll probably have to do some serious updating (downgrading, actually) of my code to get it back to 1.4.2 standards.

Do you have any actual stats on the percentage of your sales to users of Mac OS X 10.3 or earlier? I need some help in deciding if this "downgrade" is worth it.

Techdojo
10-24-2007, 01:48 AM
@Techdojo: My comment was meant as a little dot of humor, I hope you don't feel attacked in any way, if you do, then sorry, will try to work at my humor, but no promise :o

No worries (no offence taken), I was just a little worried that the thread might get hijacked by some Java naysayers and turn into a bash-fest, looks like that hasn't happend :)

Thanks again to all those who freely shared their info - this is what makes these forums such a great resource...

Jon...

FiNiPa
10-24-2007, 03:59 AM
It doesn't actually have a small JVM

Oh yes, I know, sorry I actually meant the small initial download :o

Pnuts seems really fast, Rhino is nice because of its Javascript Syntax. I don't really grasp the idea behind Janino. The real benefit for me would be to be able to edit my algorithms on the fly without restarting the main app , but it must be fast. I'll check them all and see what fits best or if its better to shut down the app, add the changes and restart.
Dynamic compilation and hot loading of classes is something I never heard of, but sounds very very interesting, must check too.

Techdojo: Java naysayer?!?!! NEVER :eek: I'm so glad I finally found a way into Java, thanks to processing (http://www.processing.org)though. It's all I need and the future is bright for Java IMHO.

princec
10-24-2007, 04:12 AM
Well Cas, I set my eclipse dev environment to compile to 1.4.2 specs so I can be MORE mac compatible. I can't believe I've become so reliant on Generics already. :( I'll probably have to do some serious updating (downgrading, actually) of my code to get it back to 1.4.2 standards.

Do you have any actual stats on the percentage of your sales to users of Mac OS X 10.3 or earlier? I need some help in deciding if this "downgrade" is worth it.

Use Retroweaver.

Can get some stats... might dig em up later.

Cas :)

FiNiPa
10-24-2007, 04:19 AM
Try Janino (http://janino.net/). It's an ultra fast on-the-fly compiler. It takes less than a second to compile a dozen files on a 500mhz machine.

Since it's a compiler you can even script inner loops or prototype hefty algorithms. It's pretty mature and the author is very responsive. All bugs I filed were fixed in no time.

Janino as a Source Code ClassLoader!! Now this sounds very interesting, do you know if it uses some sort of cache or does it compile every time? Man this looks really great!

elias4444
10-24-2007, 09:01 AM
Use Retroweaver.
ALL HAIL CAS! KING OF JAVA! Wow... where do you find this stuff?!?! Thanks again! :D

For Onyx, Janino looks interesting too, but I'm not sure I want to get into dynamic class loading for my current project. Maybe the next one. ;)

princec
10-24-2007, 09:09 AM
Just been around a looooong time ;) I like to become an expert in a few things rather than hopping from one buzzword to the next.

Cas :)

FiNiPa
10-24-2007, 10:36 AM
Holy....! hope they update to 1.6x soon :p

oNyx
10-24-2007, 12:47 PM
[...]I don't really grasp the idea behind Janino. The real benefit for me would be to be able to edit my algorithms on the fly without restarting the main app , but it must be fast. I'll check them all and see what fits best or if its better to shut down the app, add the changes and restart.
Dynamic compilation and hot loading of classes is something I never heard of, but sounds very very interesting, must check too.
[...]

Ye, usually you want to add some hook to reload a specific class.

My framework for example is pretty simple. It takes care of screen setup, frame capping, input handling, media caching etc. And the thing I'm reloading is the bare game logic (init, tick, render, destroy...). Basically there is some main loop, which calls those tick and render methods on some Game object. If I press F5 that object gets overwritten with a fresh one (destroy, overwrite, init) and if I press ctrl+F5 the same happens and the media cache gets cleared.

Thanks to full speed execution I can script everything. And I don't need to shut down the app, restart it or reload any media. It's about as direct as writing html/css/js - even on really dated hardware.

FiNiPa
10-24-2007, 02:13 PM
so the main difference between hot stuff and janino ist that in janino you have a very small 1.4 compiler you can e.g. put on a server or even distribute and with dynamic compilation I get all the benefits of my installed jdk without great adaptation, but can better be used while development. I guess janino could be more flexible for when it's finished but slower that hot plugging. I am correct or am I missing an essential point?

oNyx
10-24-2007, 02:32 PM
Well, it's more fun during developing and if you're scripting complete classes, you can compile em as usual at the end. That means there is no need to ship Janino or any source and there also won't be any (byte code) compilation on the user's side.

For that to work you need some kind of pluggable loader system. Eg mine supports Java, Janino, Beanshell and Jython. And I can easily write new loaders if necessary.

FiNiPa
10-24-2007, 03:27 PM
This is really some very interesting stuff. I think this is the way to go for my project, but I will have to dive deep into this, before I can use it. Many thanks for pointing me in this direction!

jankoM
10-24-2007, 07:24 PM
I have done one big project in java but I know java only on the surface anyway. Can I ask how much aprox would moleboxing JRE add to download size these days. I would use the latest JRE.

I noticed in the old 2004 thread when cas invented this Mike Boeh said that molebox isn't compatible with portal wrappers. Does anyone know, did this change?

ok... possibly stupid question .. if you pack JRE with game on windows ... can't you somehow pack it for mac too and loose the need for 1.4 version?

thanks..

oNyx
10-24-2007, 08:11 PM
I have done one big project in java but I know java only on the surface anyway. Can I ask how much aprox would moleboxing JRE add to download size these days. I would use the latest JRE.
[...]

1.5-2.5mb depending on how much you pull in from the std lib. Classes can be compressed very well (http://kaioa.com/svg/compression_ratio.svgz), and media can be sorted out by using appropriate formats. Creating a game with less than 5mb in size is pretty easy.

[...]ok... possibly stupid question .. if you pack JRE with game on windows ... can't you somehow pack it for mac too and loose the need for 1.4 version?[...]

In theory... sure. But staying 1.4 compatible isn't really a big issue. I actually prefer not using the new language features.

jankoM
10-24-2007, 08:41 PM
1.5 - 2.5 MB ... then that is really not a problem.. great, I thought it is 6MB or more..

I believe you don't... but I am very new at java and when I first downloaded it a year back, SDK was allready 1.6 so I think (maybe wrongly) that I would feel really bad reverting to past and leaving the cool language I found for something ancient :) ... well maybe features I used were all in 1.4 I don't know..

from library side I looked and piccolo (2d scenegraph I used and is used in javaFx now) needs 1.4, but Syntetica L&F needs 1.5. But aren't all the cool things on java client side happening in latest versions?

elias4444
10-25-2007, 07:59 AM
I actually prefer not using the new language features.
Yeah, I felt that way until I forced myself to use them. :p

Really, a lot of the additions are there to enforce good programming technique (generics, etc.), and won't make much (if any) impact on your games performance. I've just gotten hooked on being able to scroll up to my variable declaration and seeing exactly what classes I'm using it for. It help me keep things "clean."