January 2013

Going multi-platform, part 3 : First throwback

Last weekend I worked on getting the lazarus / free pascal build of “Phase 2” to look and play exactly the same as the delphi build. I had to change some small things here and there, but after a few hours you can now no longer distinguish between the two builds, maybe except for performance. It looks that some stuff that’s pretty fast with delphi is kinda slow with fpc, for example accessing stringlists and stuff. But that’s nothing that can’t be easily optimized, so the first goal of getting the different compiler builds on par is done. This also means that the game is fully playable under linux.

But during my playtestings on linux (I ditched my ubuntu installation with it’s horrible ubuntu one interface btw., and now use mint) I noticed that all descriptions of nations, units, technologies, etc. were missng, as well as the whole credits text. And after hours of debugging, checking encodings, creating test applications, etc. I found out that NativeXml is not able to load text contained within XML nodes on linux. So a node like this :

[xml]<unit name="test">
<description>This is a test description</description>

Will return an empty node value on Linux. No matter what I tried, accessing it directly, via the first childnode, etc. it was always empty. At first I thought I’d be doing it wrong (though it worked fine on windows), but then I did a very simple test that failed : I loaded up the XML with NativeXml and directly saved it to disk afterwards. And guess what? All texts within the xml nodes were removed by the library!

So it seems that I can’t use NativeXml for linux due to this severe bug. Their forums seem dead (registered there the weekend, but haven’t even been unlocked there so I couldn’t post the problem), and finding people that use it for linux is almost impossible. So all the thousands of lines of code I replaced to get the xml stuff to work on windows were just a waste of time, and I’ll have to remove this library again. I took a look at other xml libraries, but most either only supported delphi or were too bloated (dozens of units, huge source files, different dependencies, etc.). But well, that’s part of the learning process that makes programming so much fun (and sometimes so frustrating), and for the next external library I’m going to use (I prefer to write most of the stuff myself anyway) I’ll first check and see if it works on all my intented platforms.

And what now? Is the linux port in danger? No, rest assured, it’s not! Instead of relying on an external library for loading and saving xml I have written my own xmlwrapper that abstracts free pascal’s and delphi’s different xml interfaces into a single structure that I can use in my game (and coming projects). So now I load up an xml document via my own wrapper and compiler directives control wether delphi’s xml interface or free pascal’s DOM is used to fill this dynamic xml structure from the given file. The syntax is leaned towards the style of delphi’s xml implementation and parts of the game have already been changed to use my new xmlwrapper. So in my code it looks like this to get values from the xmlwrapper :

[delphi]VFS.LoadXML(‘data\xml\nationinfo.xml’, TmpXML);
for i := 0 to High(Nation) do
Nation[i].History := TmpXML.Root.NodesByIndex[i].Nodes[‘history’].NodeValue;
for j := 0 to LocalizationDB.LangID.Count-1 do
Nation[i].Name[j] := TmpXML.Root.NodesByIndex[i].Attributes[‘name_’+LowerCase(LocalizationDB.LangID[j])].AsString;
Nation[i].Stronghold := TmpXML.Root.NodesByIndex[i].Attributes[‘stronghold’].AsInteger;
with TmpXML.Root.NodesByIndex[i].Nodes[‘basefactor’] do
Nation[i].BaseFactor.Growth := Attributes[‘growth’].AsSingle;
Nation[i].BaseFactor.Loyality := Attributes[‘loyality’].AsSingle;
Nation[i].BaseFactor.Ressources := Attributes[‘ressources’].AsSingle;


So much for an open source xml library that was supposed to work with linux. So I guess this weekend will pretty much look like the second last one with me replacing lots of lines of xml-related code πŸ™

Going multi-platform, part 2 : First compile and run

I’ve been working to get the current code of “Phase 2” to compile and work under linux for the whole last weekend (and my eyes kinda hurt, again sitting in front of a monitor ;)). And things went much faster than I expected, so I was able to compile and run the game under linux for the very first time ever!

First step was to add code for all things that are specific to an operating system. So in addition to all the IFDEFs that differntiate between free pascal and Delphi, there are now also IFDEFs that differntiate beween windows and linux. Luckily MacOS and linux are pretty much the same when it comes to OS specific functions, so most of the IFDEFs for linux should also work there. This includes creation and management of the render context (WGL, GLX), getting the user’s home directory (to store logs, saves, screenshots, etc.) and much more. Currently there are still several functions missing from the linux version, e.g. getting a list of available screen resolutions and the possibility to change them via the settings like on windows. I also had to install an additional package for MESA (the software OpenGL implementation running in the VM) so it supports S3TC texture compression. That’s a must for the game cause almost all textures are stored as DDS and with compression.

Second step was debugging and stepping through the code. For some reasons it seems that there are small differences between FPC (2.6.) on windows and linux. For example I’m using a THashedStringList for getting texture indices by name from my texture manager. On Delphi this worked fine, whereas on linux I only got blank white quads. In the first place I thought that the OpenGL implementation in my VM wasn’t able to load the textures, but after some (unstable, gdb often lost trace) debugging I finally found out that the THashedStringList was case-sensitive by default, and setting this parameter to false oddly had no effect at all. So I just changed my texturemanager, it now inserts and compares with uppercase texture names all the time. Same goes for the localization database, which was suffering from the same problem.

In the third step I had to remove the sound system (for now). The game uses a rather old version of FMOD for it’s soundsystem, and though FMOD works with Delphi and FPC and also win, linux, macOS, they dropped Delphi/FPC-Support some time ago. And since I don’t have the last linux package version of FMOD that I used for the windows releae, I just couldn’t get it to work. I haven’t yet found that version anywhere (not even in FMODs archives), so I guess I’ll have to go for a different path on linux. I actually once wrote a soundsystem based on OpenAL, so I may take a look at it and use that one for linux.

After these steps I was finally able to compile, link and run the game under linux, for the very first time in the long development history of the game! Yeah, that’s kind of a historic milestone for me and was worth spending a whole weekend in front of the IDE.

As for a public release it’s still a way to go. First I need to get sound in again, some OS specific stuff is still missing and I also need to setup a real linux somewhere, as the VM is nice to test but I wanna see the release running on a real linux before I’ll spread it to the public.

But yes, linux support is finally coming, and with it maybe also a MacOS release somewhere in the future!

Going multi-platform, part 1 : The setup

As mentioned in my agenda for 2013 (and in several older posts), I’ve been wanting to release “Phase 2” of Projekt W on more platforms than just windows. Especially in the developer community linux has a big fan base, and the bigger the audience for the game, the better.

So shortly after the last post I updated my lazarus installation to the latest one (along with a current FPC compiler) and started to make the code compile with it. I already hinted at the fact that this required changing thousands of lines of code to make the game compileable with free pascal (which is the first step to getting it onto multiple platforms, Delphi isn’t a choice for that). And that’s exactly what I did. So for the complete last week (and weekend) I’ve put all my spare time in getting the code ready for lazarus, and considering that I’m coding 8h a day for living it was a bit tiresome, but I’m the kind of guy that likes to get things done once started.

The biggest part was to replace the all of Delphi’s xml functionality cause it’s based on windows xml librariesΒ  and it also has a different syntax than the xml implementation of free pascal. But since I want my code to compile with Delphi and FPC (I’d like to keep all options open, e.g. Embarcadero’s announced mobile studio with android support) I opted for NativeXML instead, an open source library that’s self-contained, works with Delphi and FPC and works on different operating sytems. And it’s a lot faster than the implementation of Delphi, so the next release of the game should load a bit faster. Other than that there wasn’t much to do. Some IFDEFs here and there for slight syntax differences between FPC and Delphi (e.g. in the generics implementation) and different units to be included.

And so I was finally able to compile the game with free pascal and with a few small fixes it’s now completely playable and performance is on par with the Delphi version . There are still some visual glitches and some of the text labels aren’t filled with language specific texts, but that’s nothing that can’t be fixed within a day or two.

After I got it to compile and run with free pascal under windows the first big step towards multi-platform support was completed. And just before writing this post I’ve set up a linux and got lazarus to work there. I must admit though that it was a real pain compared to getting Lazarus set up for windows. The user interface of Ubuntu 12 is just horrible (I’m actually shocked at it’s bad usability) and getting Lazarus to work there had me install a total of 10 packages, and none of the required vesions could be installed by the package manager. So compared to the 3~4 minutes you need under windows, it took me almost an hour to get it up and running. But the virtual machine is saved, so no need to do this again.

So now everything is set up to start porting the game to Linux (with other platforms to follow), so hopefully I’ll be able to release a current snapshot of the game for two platforms, with more platforms (Mac OSX will be next) following sometime in the future.

Agenda for 2013

And so 2013 is here and it’s a good idea to update you on my agenda for this new year. My primary target for 2013 will be the release of a final “Phase 2” version of Projekt “W”. And with a public beta available that’s pretty close to the final product I’m pretty confident that this will finally happen this year.

People seem to be mostly positive about the current public beta release (or at least I haven’t heard any negative comments) and all comments up until now have been pretty nice, something I’ve been missing before the release of a public beta. Releasing something people can play around with gets you much more feedback than just uploading screenshots and videos to look at. But that’s just one of the advantages of the release early, release often philosophy, together with the fact that you can easily integrate player’s feedback right during your development instead of having to patch your game later on. The onyl disadvantage of this philisophy is that releasing builds on a regular basis takes time. You’ll have to make sure that the current build is working fine (and not worse than the one before), so during coding it’s necessary to check if changes did break something, then you need to package your release, upload it and spread the word. But in my opionion it’s totally worth the additional time, and I want to stay on release early, release often for all my future projects.

But back to my plans for “Phase 2” in 2013.
There isn’t that much left to do yet (compared to what I did over the last few years), but some of these open points need to be closed before I can call it a final release :

  • Sound design
    The game is severely lacking in this area. I noticed this will playing a small indie strategy game where the sounds perfectly fit the scenario and added to the overall atmosphere. That’s pretty much missing from “Phase 2” currently, and this is one of the bigger issues I’ll take care of.
  • Politics feature
    I mentioned this in several posts and the button is already there in the current beta build, but the feature is still in design stage. My plan is to add more personality to the game so the player feels more like the leader of a nation rather than “just” building stuff and moving divisions.
  • Ingame tutorial and documentation
    “Phase 1” had an ingame tutorial that lead the player through the most important aspects of the gameplay. This is currently missing from “Phase 2”, but something like this is a necessity for such a complex game. The html manual include is already a step in the right direction but not sufficient in my eyes.
  • Add more content
    Although already stuffed with a lot of content (currrently the development directory inlcudes almost 800 MBytes of drafts, artworks, models, textures, designs, etc.) there are still areas where content is lacking. Battlefields for example still lack variety in 3D models and I also want to add some more buildings, technologies and global projects.
  • Remove backwards compatibility for shaderless GPUs
    When the original game launched there were lots of GPUs that didn’t support shaders, so there is still code in the renderer for these cards. But nowadays even the cheapest GPU is capable of shaders (inlcuded integrated GPUs), so I want to remove this legacy stuff and then also use shaders to opimize rendering in certain areas.
  • Multi-platform support (*)
    Something I’ve been wanting to do all the time. Since Delphi doesn’t offer this the main obstacle here is to get it compiling with Lazarus/FPC. But since this includes a lot fo changes to the code (e.g. thousands of lines of code that use Delphi’s XML-implementation) I don’t know if it will ever happen, though this is a point that I’d really like to implement.

This is my (more-or-less) immediate agende for “Phase 2” in 2013. And yes, I also plan to add some more stuff depending on time and motivation (e.g. a complete network mode, PBEM, modding, etc.) but also want to take on other proects after “Phase 2” somewhere in the near future.

On a sidenote I added “Phase 2” to the indie games db. This is a first step in broadening the audience for the game. For the first release I only really promoted it inside my developer communities, and with this step I hope to get more people to play my game. So give it a spin.

And you also may have noticed that the look of the page has changed a bit. That’s because I finally got around upgrading my server to the latest PHP/MySQL versions so I could upgade to the newest wordpress version. So I also switched to a different theme that offers more functionality (dropdown menus, widgets, etc.) so that you now have easier access to the areas on my page. Please note that I’m still working on the migration, so some pages may look add, but that’ll be fixed.

Oh, and a good and healthy 2013 to all of you btw πŸ˜‰