Saturday, February 14, 2009

OpenSolaris, Qt and Game Development

Overview

A group of 3 other people and myself were charged with making a game for a class this trimester, which is essentially a Final Fantasy clone with a few quirks localized to our university. In thinking of a toolkit, I thought to myself "what event-driven toolkit provides a graphics system and paint system complete and robust enough to make this happen?" Naturally Qt came to mind. The professor suggested some Java toolkits, including SWT, but my experiences with SWT have not been at all good, so I decided to give Qt a shot. Another perk of Qt over SWT is how easy it is to learn and use, since my 3 team members are not familiar with it.

After a few days of playing with Qt tutorials on the Graphics framework and studying KDE games code, I had a small but working prototype of one of the modes of our game, where the character explores the scene of a level.




Things to notice that were easy to do:

- Creating a graphics item from a graphic file
- Moving it around
- Having it change form
- Collision detection with walls
- Dragging of the view to see different parts of the scene

Deployment

Before proceeding I had to make sure that the program would run on the target platform of the school servers: SunOS 5.10 (Solaris). Now Qt is a cross-platform toolkit, and binary builds of it are provided for Linux, OS X, and Windows, but not for Solaris (that I could find here).

Having recently installed VirtualBox after hearing lots of good things about it, I decided to give Solaris a spin as a virtual machine. There was a bit of confusion for me at the beginning with so many possible distros to choose from, but luckily since only 2 of them are supported by the KDE Solaris team, that narrowed it down. They prefer using SXCE, so I gave that a shot, but unfortunately some bug where X would show up but then freeze on the live dvd stopped me short (I figured it was an issue of running in a VM or something). Then I tried OpenSolaris 2008.11, which installed fine

Then the problem became that the instructions on the wiki for compiling using OpenSolaris were a bit lacking, a problem I have since mended with some updates based on my experience. After much strife with getting the environment set up just right, compiling was not a big deal, thanks to the awesome efforts of the KDE OpenSolaris team. I ran into some issue with a Qt example not compiling, and hacked it up to fix it, since it didn't much matter, and voila, Qt was on the system, and my previous example in the youtube video worked.

From here, I had a few options (as I saw it):
- build Qt as static, deploy a static binary
- build Qt as shared library, ask school admins to install Qt on servers
- build QtJambi, port to Java, deploy as jar

Since building Qt as static was not supported by the KDE Solaris team, I decided to give QtJambi a shot, and ported my example to Java. Unfortunately the QtJambi build specfile provided didn't work too well, and went into an infinite recursive make loop.

When at last I had almost given up, I discovered that the shared library approach doesn't actually require the system to have Qt installed on it, just that the necessary .so shared object files be deployed with the program itself, and to use a script to launch the program (a script which simply adds current directory to linker path).

A simple ldd resulted in this:


libc.so.1 => /usr/lib/libc.so.1
libQtGui.so.4 => /opt/foss/qt4/lib/libQtGui.so.4
libQtCore.so.4 => /opt/foss/qt4/lib/libQtCore.so.4
libCrun.so.1 => /usr/lib/libCrun.so.1
libm.so.2 => /usr/lib/libm.so.2
libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0
libpng12.so.0 => /usr/lib/libpng12.so.0
libSM.so.6 => /usr/lib/libSM.so.6
libICE.so.6 => /usr/lib/libICE.so.6
libz.so.1 => /usr/lib/libz.so.1
libXrender.so.1 => /usr/lib/libXrender.so.1
libXrandr.so.2 => /usr/lib/libXrandr.so.2
libXfixes.so.1 => /usr/lib/libXfixes.so.1
libXcursor.so.1 => /usr/lib/libXcursor.so.1
libXinerama.so.1 => /usr/lib/libXinerama.so.1
libfreetype.so.6 => /usr/lib/libfreetype.so.6
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1
libXext.so.0 => /usr/lib/libXext.so.0
libX11.so.4 => /usr/lib/libX11.so.4
libgthread-2.0.so.0 => /usr/lib/libgthread-2.0.so.0
libnsl.so.1 => /lib/libnsl.so.1
libsocket.so.1 => /lib/libsocket.so.1
libexpat.so.1 => /usr/lib/libexpat.so.1
libXau.so.6 => /usr/X11/lib/libXau.so.6
libpthread.so.1 => /lib/libpthread.so.1
libmp.so.2 => /lib/libmp.so.2
libmd.so.1 => /lib/libmd.so.1
libscf.so.1 => /lib/libscf.so.1
libuutil.so.1 => /lib/libuutil.so.1
libgen.so.1 => /lib/libgen.so.1
libXevie.so.1 => /usr/X11/lib/libXevie.so.1
libXss.so.1 => /usr/X11/lib/libXss.so.1



Wow, that's a lot of shared objects! According to the Qt deployment guide though, all of the X libraries could and should be avoided to be packaged. I did end up adding other ones though, one by one, as I saw necessary until the program finally ran without a linker error. The bad news is this blew the total package up to 30 MB or so. Oh well, so be it, it ran!

And now...?

And now the real development can begin. There's only a few weeks to work on it, but that should be plenty. It won't be a terribly fantastic game as a result, but it was an interesting adventure, and more importantly proves the point that Qt is an awesome toolkit, and that there are quite a few options open for deployment.

Thanks to the KDE Solaris team for helping me with getting things building, I'd be nowhere without your help (in particular: szt, [ade], steleman, and trochej thanks a lot guys).

6 comments:

workman161 said...

Flash only video? Where's the ogg?

Anonymous said...

Heh, it would probably have benefitted the whole Solaris community if you managed to package a relatively recent (>=4.3 or so) version of Qt and offered it for download. I've personally spent the weekend trying to get Qt compiled, and I'm sure there are many less-ambitious out there. ;)

awainzin said...

workman161: I don't have hosting for an .ogg file, but I'll try to look for some for next time.

mattlewellyn: I thought a package was already provided for it, since the spec file is for Qt 4.3.x but let me know how I can upload the package and I will.

Kevin Kofler said...

@awainzin: blip.tv allows you to upload .ogg/.ogv videos (they're the same, but using the .ogv extension is recommended to make it clear it's a video) and it allows the user to download them in the original format. (They also automatically transcode it to Flash and offer a Flash version which you can use instead of the YouTube version. But Flash is evil and proprietary.)

Thomas said...

Well, is it possible to get the sourcecode of this? ^^

awainzin said...

The final game was done in a rush so isn't too pretty. The source of this movement example was altered to work with a PNG graphic that moved but didn't animate, and I'd have to sift a bit back in svn commits to find where the old version was.

In the meantime, a much better way of implementing this stuff came out. It's called QtAnimation and QtState frameworks, which are available now as Qt solutions, you should check them out.