Dev Hobby

Saturday, December 5, 2009

Holiday coding

With the exams over, I finally have a bit of time to put into Thousand Parsec, at least until January :) After a conversation with mithro, I've decided to set the following goals:
  • The wxwidgets client now has a single-player mode built in, which can be ported into the 3d client.
  • The client uses version 3 of the thousand parsec protocol (tp03), whereas the current servers already support a new version (tp04). Upgrading the protocol used will allow us to deprecate the old one.
  • tp04 comes with some new features, such as media server support. This means that various media such as 3d models, music, icons and such related to a specific game can be downloaded from a server, instead of being packaged with the base client.
I'd love to add "write a build process for Windows, Linux and Mac binaries" to the list, but it's proved to be a huge timesink in the past and I'd like to concentrate on getting the functionality right first.

Thursday, September 4, 2008

A quick update, just to break the silence

I've posted a new Windows build, and am currently trying to get the client to work fully with the python-ogre deb on Ubuntu. As expected, getting python-ogre to work on Mac is quite a chore, I'm almost there, got everything compiled but running the demos gives me a "wrapper" error, and I'll probably have to understand how the code generation in python-ogre works to figure it out.

Packaging issues aside, I've made a few updates to the client. The lines in the screen represent "Wormholes", which are basically routes between star systems. Currently, only the Risk ruleset uses this feature, so lines won't display anywhere else, such as on the demo1.thousandparsec.net server which usually runs Minisec.



I've also tweaked the "Information" window to show more useful information such as the planetary resources (I tested it with the "Armies" resource in Risk). In general, I'm trying to locate more crashes by testing the client with different systems and python-ogre builds. OgreAL has been a little problematic, and it's one of the things which I am trying to get working with the linux python-ogre deb file.

My main concern about the client is the performance on older hardware. Mithro informed me that even the login screen runs at a crawl on his laptop, which is probably due to the large textures used in the skybox (1024x1024). I guess a solution to this would be to offer a lower-resolution skybox thats selectable from the options menu.

I've started my industrial attachment, so I'm pretty much limited to weekends. Nevertheless, I'll be continuing to update the client, and when tp04 support has been added content management will be a lot more elegant, allowing "media" tags which mean no more hardcoded graphics. Another thing I'm looking forward to is more battlexml support in the servers. On my end, I also hope to include some shaders to give game objects a more realistic look, but there are still many things to work out before I have time for that.

P.S. If you zoom in on the pictures it kinda looks like those old VGA games.


From Dev Hobby

Sunday, August 17, 2008

Configuration options

This is the last week of GSOC, the date in which our evaluations begin is tomorrow. It's been a pretty short and exciting trip, sometimes I'm still amazed that I have the chance to work on this at all. On to the additions!

A checkbox for "saving details" was added to the login screen. When checked, the username, password, last server connected to and some other preferences are saved in the user's home directory, so that reinstalling the client will not affect the preferences. The password text is masked now, and saved to disk in hexadecimal format. Pretty primitive, but the idea is just to prevent casual lookers from getting the password.


The configuration dialog was expanded with a couple more options as well as two additional dialog boxes for graphics and sound configuration. The main dialog now has the option to tweak the zooming speed, as well as to adjust the distance scaling. This is meant to help deal with the variety of rulesets which use different units of distance for their maps. The distance unit ratio makes stars further apart the lower it goes, as all distances will be divided by this value when starting a new map.

Graphics options allows the player to change the renderer (although I recommend Direct3D for Windows), resolution and anti-aliasing options. Unfortunately, only the full-screen option works instantly, the rest take place after a restart as only full-screen had a convenient setFullScreen() method which I could use :). Also, each renderer (opengl or direct3d) takes in different values as their configuration. For instance, direct3d takes in resolution and colour depth as a single string, while opengl takes in resolution and colour as different parameters, which means that the user should change the either the renderer alone or the other options without changing the renderer.

For sound, the options are pretty basic (I know it is missing a volume control :)). Setting the driver to other values provided by openal (other than the default 'Generic Software' option) doesn't work for my system, perhaps because I am using on-board sound and not an actual sound card.


Some work was done to allow the client to adapt better to different rulesets. The map centers properly now (I had a dumb bug where I should be reading x and y values, but instead read both values from x). Zoom distance, which is like the 'step size' for zooming, takes into account the distance scale so that larger maps will not take forever to zoom in. Panning takes into account the current zoom level, so it zooms more when zoomed out. Also, a map boundary was added so that the user will not move out of bounds and get lost, although I'm wondering whether this is a good idea as it sometimes results in apparent 'locking' when the camera runs up against the invisible walls. Perhaps the camera could slide along the walls instead, so that the user can still move about smoothly.

One issue with having an adjustable distance scale is that for large distances, the background of stars (which was a particle system) would have to be expanded to encompass everything, thus resulting in a sparser starfield. Although I like the idea of generating the starfield at runtime, increasing the number of stars would have made performance even slower than it already is, so I made a skybox in blender instead. This skybox also replaced the one in the login screen, as it is from the default ogre media - something I am trying to move away from.

The following shot shows a camera placed inside a sphere, with it's field of view set to 90 degrees. The starry texture was done by blender's built-in texture generators: some noise, clouds and playing with layer settings. After that, I rendered a screenshot in every direction and set it as a skybox. Easy to do, but getting good settings for the texture is hard, I haven't really figured it out yet.


The next shot shows the starmap with the skybox in use. Sadly, my computer chugs pretty slowly in this server with 34 players. I believe it's the overlay placement code that's the problem as the polygon-heavy models should have been hidden already.

To end on a high note, I received a nice package this weekend, courtesy of the lead dev mithro. Thank you very much! This made my weekend (well that and Singapore winning it's first Olympic medal in decades, woohoo!)

Sunday, August 10, 2008

Interface additions

I adjusted my priorities a little this week, due to the sudden realisation that GSOC is drawing to a close.

Firstly, I added a logo to the main menu.
The logo was taken from the Thousand Parsec website and put into a CEGUI ImageSet, which is the combination of an image file and an xml file which defines the pixel locations of all images within the set. Right now, it is rather empty:


I hope to fill it up with a lot more icons and image elements to add more spice to the interface.

Next, I added a map navigation panel to the lower right of the screen.

The functions of the buttons from top to bottom are zoom in, zoom out, deselect, focus on object and fit map to screen (although the last two buttons are indistinguishable at this size, one points inwards and the other outwards). The icons may be familiar already, as they come from the famous famfamfam silk icon set. I tried creating my own icons at first, but some creations should never see the light of day. With this, there will be a lot less reliance on keyboard shortcuts, hopefully making the client easier to use. The zoom buttons move in larger steps than the mousewheel zoom and are not animated, as I find the zooming animation a little slow on my older computer (it is framerate-dependent).

Lastly, I added a main menu option, allowing the user to return to the login screen gracefully.

I discovered that logging in and out caused a lot of problems with the management of system resources. Models, images, interface elements and such needed to be unloaded and reloaded again, something which I could not find an "easy" solution for. In the end, I traced the loading of all the resources and added a corresponding unload command upon logging out.

Regarding the linux installer, I edited the setup.py file so that the client installs in the same manner as the wxWidgets client. With that, the debian maintainers for Thousand Parsec will be able to package the client into a .deb file, although I'm considering whether to include the binary version of Python-Ogre inside as well, so that the package can run standalone.

This week's focus has mostly been on the user interface, and I think any additional features will have to be put on hold for now, so that I can tie up the loose ends. For now, I will be writing the documentation and working on the mac installer, which is a giant time sink :)

Sunday, August 3, 2008

Sounds and Battle

This week I took a look at introducing sound into the client. I found OgreAL a snap to use, it's API is modelled after the built-in Ogre managers such as material and resource manager, so not only was it familiar but also cleanly designed. Unfortunately, technical problems (crashes without any indication of the error - my favourite!) arose when I tried running the code, which I attributed to driver issues, as switching to "generic software" audio drivers - done by passing in a parameter during creation - solved the problem. This parameter is not available for Python-Ogre 1.1 which uses an older OgreAL API.

So all I had left to do were the sound effects.

As I mentioned, I found a program for generating ambient soundtracks last week. It's really a sine wave generator and I'm currently trying it out as a background track. I haven't thought much about what sort of music would be suitable for a game of Thousand Parsec, perhaps I will have the client play any .ogg files it finds in the directory, similar to how Oblivion does it. This way, the user can specify his own soundtrack, although it would be nice to have some original music of our own too.

I spent a while trying to create sounds for other parts of the client. Right now, I've put in a "engine rumble" and clicking sounds for buttons on the gui. Once again, I found a useful utility for these sounds, called sfxr. Most of the sounds produced are pretty lo-fi, but it's suitable for stuff like laser noises and the engine rumble was made from this too (plus some processing in audacity). Hm, there should be some way to embed sounds in blogs too...

I think that the background track does add a lot of atmosphere, but my taste in music is pretty much like that anyway (see Drone Zone on SomaFM) so hopefully it won't annoy others. The sound effects will require a bit of tweaking as well, as their volume varies based on the user's location (automatically handled by OpenAL) and they can sound too loud or too soft at times.

One of the primary motivations for adding sound was to supplement the Battle module, a standalone program for viewing BattleXML files.

Currently, it does not process the actual battle, but it does create and show the initial locations of the fleets. I'm still figuring out how to define weapon locations and attach them to the ships, which should be fun once it is done. Also, there seems to be some texturing issues with the models as well, hopefully I can fix them in Blender.

An additional windows installer script has been created as well, which actually just places the compiled client into your program files directory and create start menu shortcuts. The process of creating the installer actually exposed some bugs - although everything works, on shutdown the client outputs an error log, saying that some background threads had been forcefully shutdown, which made me realise that perhaps I hadn't been closing the client library threads properly, something that I have yet to look into.

Next week, I will be finishing up the battle module and tying up loose ends:
- the starmap could use a navigation bar for zooming and centering
- the title screen should have the TP logo
- using theora to display the intro movie
- a minimap for lost players
- writing up documentation
- packaging linux and mac binaries (big problem here)

Sunday, July 27, 2008

Ship designs and order queues

After chatting with mithro this week, I found that the ship designer in the pywx client was an old part of the code (untouched in a year), and that ship design was not considered a priority (since only MTSec supports it). What I did instead was a viewer for ship designs in the game:

The design list on the left is colour coded by player, and the information pane is currently showing etower333's scout design. Wasn't that guy in a previous post as well? How long has that game been going on anyway?

Order queue management has also been added.

After selecting an order from the queue, you can use the delete button to remove it or the edit button which will bring up the arguments window to edit the existing values. The new button also serves to create a new order after selecting from the available orders list on it's left. This change led me to venture back into the rather untidy order handling code, which I have cleaned up a little.

A minor change is that double-clicking on an object will focus and zoom in on it.

One thing I have been looking into is introducing sound and battle scenes into the client.

Battle scenes in thousand parsec are defined by a BattleXML file, which is a file format detailing how many sides there are in a battle and the makeup of the individual fleets together with a turn-by-turn breakdown of how the battle went. A sample pygame viewer as well as documentation on the format can be gained from the battleviewer git repository, although I have not run the viewer yet. One problem with BattleXML is that currently it is only supported by tpserver-py and not tpserver-cpp, which is the more popular server. Another issue is that it has to be implemented by the ruleset specifically and requires a media definition file to map 3d models to ingame objects as well as any weapon effects. Perhaps there could be a random battle generator so that support can be easily added for all rulesets?

Sound support is already available in Python-Ogre via OpenAL, a cross-platform api for 3d sound. So it's really a matter of finding the right sound effects. I've found a program called song04 which generates ambient soundscapes, it sounds quite alright and I'll be trying it out as a background soundtrack next week.

In somewhat related news, my old computer is probably on it's last legs as it frequently hangs upon startup (or the kernel starts to panic), and it has no internet access as the network adapter refuses to connect despite using the same settings which worked before. I guess it's rather fortunate that I got a new PC recently.

Sunday, July 20, 2008

This week in TP

This week, I finally figured out how to do proper camera rotation in 3d. The actual code turned out to be simple. At first, I wanted to use spherical coordinates to position the camera, as I had success with using polar coordinates for the radial menus. By storing the vertical and horizontal angles and treating radius as the zoom distance, I could convert them into 3d coordinates by applying some formulas. This worked only for rotations along the Z-axis (meaning that the world was "rolling", done by moving the mouse left and right). However, for rotations along the X-axis (pitch) it would refuse to rotate properly - upon reaching the horizon angle it would "bounce" back again.

In the end, I put the camera inside an OGRE scene node, and made it the child of another scene node which would act as the focus. Hopefully this tilted diagram isn't too confusing:

In the diagram, you can see the camera floating at a distance above the map, which contains several planets. The focus node is always level with the other map objects, while the camera node can zoom back and forth. As I mentioned, the camera node is a child of the focus node and by rotating the focus node directly, OGRE will apply any transformations to it's child nodes, causing the camera to rotate around the focus node.

Allowing the camera to look around freely posed a problem, mainly with the starry background as it was a flat field of stars. Here's a picture breaking the illusion:

Thankfully this was actually quite easy to fix. OGRE uses particle emitters, which spew out particles in various arrangements, and there was a Hollow Ellipsoid emitter which I could use to create a starfield surrounding the camera. The manual is not very clear on how to use the Hollow Ellipsoid, the inner_ parameters are actually numbers with a range from 0.0 to 1.0 specifying the percentage of inner volume which should be hollow.


There always seems to be a cluster of stars at roughly around the same location, I'm not sure why. Letting the camera roam also let a few more issues crop up, such as the planet rotation. Previously, they were facing the player who was looking from overhead, since otherwise all the player could see would be their polar caps so I had to rotate them back again. Another stickier problem is the panning of the camera. Since the camera can pan in any direction, it screws up the zoom if the player pans downwards or upwards.

Finally, the messages window layout has been changed to include a panel showing all the message headers. As I said in the previous post, the layout looks like it could do with some tweaking.
Next week, I will implement the ship design window, although I've not been able to create ship designs using the existing client yet, I should take a look at at least letting the player view the ship designs, or else he won't know how badass his fleets are. :)

Another thing will be the order queue management, which refers to deleting and editing existing orders.

There will be a turn update window, showing new events received upon a new turn.

Finally, I will create setup packages for Windows, Linux (with the help of fellow Thousand Parsec developers) and Mac (which I will be working with my mentor for - this may take longer due to issues with Python Ogre). Although not a real release yet, getting the build process done will be a load off my mind. No use working on a project if nobody can run it after all. :)