Thursday, June 12, 2008

Java is *almost* as good as Python.

So I didnt finish the client for xmlrpc-cardgame. When I do finish it, it might be in Java. (If you want to help out, as always, feel free to email me.)

As promised, I was going to pick up Sylva again when summer struck. I'd taken a break from programming to sorta clear my mind for a month or so and have now decided that summer's already here. Hence, Sylva's back on my plate. After much consideration, I decided to put the C++ engine Matt assisted me with on the back burner. The time it would have taken me to develop Sylva in C++ outweighed the point, which firstly was to let me learn a new language and evolve my programming ability a bit, and secondly to develop something semi-playable, over the course of the summer. If it took me 3 years to finish, it'd be pointless.

As such, I decided to try again but in a different language. I checked the TIOBE index and weighed the pros and cons of each of the top-10.
From the bottom up, my opinions:
Ruby (2.640%): "This will do me no good. It's a slightly different Python."
JavaScript (2.927%): "This thing will not be web-based. It'd need a java applet to be playable."
C# (4.058%): "No Java+Mono kthx."
Python (4.899% ): "I already know Python."
Perl (5.548%): "Yes, it's more than capable, but it's source is unreadable to me."
(Visual) Basic (9.787% ): "No BASIC+Mono kthx."
PHP (10.206%): "Not web based. Dont want to make a PHP desktop app."
C++ (10.806%): "Too much work for too little. Plus I wanted a different language."
C (15.513%): "WAY too much work for too little. Plus I wanted a different language. I'd also like a little object orientation please."
Java (20.890%): "It's kinda slow, but then again so is Python. And I get thousands of frames per second in a very basic C++ scene, so if Java is 10 times slower, I'd still get hundreds of frames per second."

In the end, I decided to go with Java. Just cant argue with that percentage (though admittedly, it's not particularly accurate). After I discovered Java Monkey Engine, I was sold.

After a little while fighting with version 2 (which I could tell was a real upgrade over version 1 from the little time I spent with it) and the examples provided on their wiki, I finally switched over to "latest stable" version 1 jars. Got it all set up in netbeans, and it's been a breeze since. My only hangup was adding physics. Turns out I had to add it to my classpath as well as adding it to the "Libraries" section in the netbeans project. (I did mention I was a Java/Netbeans newbie, right?) It's been a little over a day, and I already have:
Lighting
Camera
(Acceptable) Controls
Skybox
Terrain
Static Model Loading (animation to follow shortly)
(Bounding-Box based) physics (I want trimesh-based physics in the future)

Most of those are just 10 lines or so "flipping the switch" to enable them in my application.

It's rather neat, instead of giving you one "Game" class to derive yours from, there's several different derivatives, for example, I started out using a class called SimpleGame. It basically sets up a very simple game for you, the only thing it does is set up the camera and controls, the rest are up to you. Though most methods are on the order of 10 to 20 lines for each "feature". (The secret is that it handles all the threads such as rendering and updating the scene for you. You have to override these if you derive from BaseGame.) For example, when I decided I wanted physics for no real reason, I had to change from SimpleGame to SimplePhysicsGame. Since it derived from SimpleGame, pain was zero if I recall correctly.

The project's page is up at https://launchpad.net/sylva and you can grab the source by using `bzr branch lp:sylva`.

No comments: