So in summary, is it fair to say that Java is bad choice for game development if you do not include native libs?
I think the answer to the question is fairly obvious really. I don’t mind using native libraries from within Java, but using them increases the likelihod that my game will fail to start up on another machine. For example, neither LWJGL nor JOGL will work on this Windows Vista laptop that I’m using despite the fact that it is a reasonably well specc’d machine. LWJGL complains about an unsupported pixel format (video card trouble) and JOGL regularly crashes the JRE, though software emulation works just fine but is far too slow for games work. I can’t play Puppy Games’ games because they won’t start up on my machine. The failure to start problem is just eating away at your profits Cas. A DirectX version in C++ would have run just fine. A shame really 'cos I really like playing shoot-em up games --they help me to concentrate.
As for writing games in pure Java, I’ve given up! There are timing problems and screen update problems that I just don’t get if I use C and a really simple hardware layer interface library like SDL. Additionally, there is something deeply suspicious about the inner-workings of System.nanotime() and the lag and stutter in the main game loop is causing me so many headaches. Again, as Kev suggested, it is probably a hardware problem but I no longer care about Java’s hardware interface problems. My lack of care in this respect is prompted in part by the suspiciously low coupling of Java to hardware.
Anyway, back to the point. If I can’t do something really, really basic like time the appearance of game objects and move them smoothly around on screen (even at low frame rates on really bad hardware) then I don’t really want to know what else Java can do. Hell, even Blitz Basic and Dark Basic will give me a smooth, consistent main loop on a crappy 500Mhz Pentium, why won’t Java? Christ, even Flash will give me a steady frame rate and Flash is the suckiest of the suckiest arse-over-tit, extra-ecma-anal game programming environments. On this machine, I only get a stable frame rate for my test code in Java if I drop the frame rate to ten frames per seconds, which is unusable except for the simplest of puzzle games.
It is not enough to say, well there’s something wrong with the way you’re doing your screen updates in the test code (as Dzzd said) and you need code to stabalize the frame rate. That’s just a load of bollocks Dzzd. There’s nothing wrong with the code: time the game objects update & drawing operations and then sleep for a period of time to sync the loop at sixty frames per second, or whatever frame rate you can get away with. It doesn’t get much simpler than that. Coding a game loop is trivial, yet Java just doesn’t seem to be able to handle the timing and synchronisation requirements and produces inexplicable stutters and lags in the main loop. Let’s face it, stutter and lag are just anathema to a games writer. Its the kind of thing that furrows your brow when you’re falling off to sleep and it is annoying because the problem subtracts thinking time from designing and implementing the game play and game mechanic. Incidentally, when I ported the test code across to C and SDL, I got a rock steady frame rate. As expected, with none of the stupid bollocky timing artifacts that Java seems to throw in to the mix.
The other thing that is bothering me, which cas has touched upon, is that there is no console support in Java. If I write a game for the PC and it does reasonably well then the obvious thing to do would be to use the profits generated from the PC version to purchase a console development kit and port the game across. If I’ve already written the game in C then porting becomes trivial, if it is written in Java with native lib dependencies then porting is not so easy and straight-forward. In fact, it is probably near enough a complete rewrite.
IMO Java fails as a choice for game writing at the most basic level: the game’s update/render loop. This is unpardonable for a runtime that wants to make it in the game writing arena. If the timing in your game is off then the players will notice and stop playing the game and they certainly won’t buy a game that stutters and lags. I’m a little annoyed not to mention peeved at the amount of time (wasted in my opinion) I have spent writing and debugging code on a platform that just doesn’t perform well enough and no amount of tinkering will coax the JRE, or the graphics libraries or the timer or whatever the Hell the problem is with Java’s jerky screen updates into giving me a stable main loop on top of which I can build a playable game.
I’ll continue to hang around the forum to see if things improve, but TBH I think that Java’s games writing problems are fundamental and located within the JRE and the native interface code. Aargh, all those bloody layers just to get at the hardware! I’m sorry, but I think you are completely wrong to spend your time writing games in Java. C/C++ is a much better choice. Using Java for games writing just brings to mind a modern curse: may your games stutter and lag for all eternity.
I’ll stick around the forum to view the games showcase releases (I do like seeing those) and just generally monitor the Java performance related posts but as for using Java to write a commercial game, I think I’d rather eat a pooh sandwhich and wash it down with an extra large cup of vommit. ;D Heh, not that I’m in the habit of consuming such eye wateringly disgusting repasts. My experiences with Java game programming have given me a bloody twitch. Right, where the Hell’s my C compiler? Sanity extends an elegant, manicured finger and beckons with a sultry call “this way young Jedi, this way…”.
Jesus, you know what? I’m actually beginning to believe that I’ll need a theraputic course in advanced cognitive neronal repair after my experiences with that JRE and class library. I feel that my experience of writing games in Java has just caused the window of opportunity to slam down on my fingernails, throwing me breathless to the floor. And there I lied, helpless, as I watched the Sun Necrosystems vultures descend from the sky to pick at my loathsome bones…
–Mario