Category Archives: gratuitous space battles

Am I the only person doing this? probably. I often am. Most people have moved on from DX9 (I know it so well there is big opportunity cost to updating) or use OpenGL, and very few people are doing 2D games where performance is an issue. I am taking early steps with Gratuitous Space Battles 2, and my aim is to have it run at 60 FPS on average hardware with 2 1920×1080 monitors. I also intend to get it running ok for bigger setups too. That’s a lot of pixels, and due to all sorts of fancyness I’m adding to GSB 2.0, it means a lot of processing. a REAL lot.

So…multithreading! it’s about time i ventured forth. To date, my only multi-threading efforts have been the asynch server communication in GSB 1.0 for challenge uploads etc, and the loading screen for GTB and Democracy 3. Actual mid-game multihthreading has scared me until now.

I hate middleware so I’m not using any libraries, just raw calls to CreateThread, TerminateThread and so on… This might make it more complex, but means I have complete control over stuff. My first experiments were not exactly encouraging. I attempted to speed up the position calculations of asteroids. Now to cut a long story short, I use D3DTLVERTEX style stuff (not hardware Transform and lighting) and for good reason i won’t bore you with. The upshot is, I have a lot of non-directx transform stuff to do for anything drawn on the screen.

An ideal case for multithreading!


So I wrote code to split up the asteroids into 8 chunks (test case of an 8 core chip), and gave each processor a list of asteroids to process. Result? SLOWER. Actually quite a bit slower. Some fiddling with AQTime (My profiler) let me analyze cache misses for each thread, and I also profiled it as 1 thread. The cache miss rate went through the roof. Basically, my transform code was relying on some global camera data, and I suspect that either:

a) Referencing he camera data was a bottleneck with each thread blocking each other from getting it or…

b) The memory locations of the asteroid transform data was laid out in such a way that all the different threads kept fighting for the same cache lines and generally getting in each others way.

I spent a lot of time reading and fiddling and decided that it wasn’t working (although did manage a decent few speedups in other ways). I then decided that if lots of threads sharing the same job wasn’t going to help, maybe lots of threads doing different (unrelated) jobs would…?

And this is more of a success. I have a function called ProcessFrame() which does a lot of non-directx stuff, such as the aforementioned asteroid transforming, updating engine glows, updating explosion plumes, particle effects and distortion waves blah blah… Until recently, it just did them one after the other. I then realized that although a lot of them accessed the same data (camera position stuff mostly), none of them altered it, and the tasks were quite discrete.  So I packaged them up and sent them to different threads, and then spun in the main thread waiting for them to finish. result? 21% faster. yay? not bad, but not 800% faster, which would have been theoretically do-able(not really but…)

Of course the missing link was that I am then left waiting for the slowest thread. Plus if I have more than 8 tasks, I run out of CPUs. So I re-coded it to have a queue of tasks, and when a thread finished a task, it checked the queue, and only reported it was done when the queue was empty. This was way more efficient, and easier to scale to available cores. Result? 41% faster!

Now obviously a 41% processing speedup is good (although this is pre-render, not render, so probably only a 20% FPS boost) but I can’t help thinking that if not 800%, a 200% speedup of that bit of code must be possible. Debugging cache-misses is hard, as even aqtime will bluescreen occasionally on windows 7 when profiling it. I’m pretty sure it’s some cache, false-sharing issue going on.

In the meantime, GSB is now faster as a result, even if i spend no more time attempting to multithread it (and i will… I’ve only just got going). Anyone else attempting this sort of thing?


…has now started. behold:


I could (and probably will) talk at length about the reasoning behind doing this, from a business POV. Suffice it to say for now, that there are always people who are skeptical of buying a game based on reviews, or a demo, and feel they need to play the whole game properly before they can commit to buying it. I guess this is the appeal of pay-what-you-want in some ways (I guess retrospectively…) and also FreeToPlay games. Never let it be said that cliffski is an old man afraid of trying new things :D

If you don’t know what I’m talking about here, Gratuitous Space Battles is my best-known game. It’s a space strategy/management game, that in some ways is like football-manager with space fleets, and in some ways it’s a puzzle games, and in some ways it’s an RTS. You can control the ships mid battle these days, by the way. The game has sold VERY well for a small indie, and won awards and stuff. You can check it out for free this weekend on steam (and there is a nice tasty discount to tempt you too).

So as to show off some of the latest shininess, here is the video for the last GSB expansion pack: The outcasts again… PLEASE TELL EVERYONE ABOUT THIS FREE WEEKEND!

Yup, you noticed I’d gone quiet about the new Gratuitous Space Battles expansion? Well it’s always like that in the days leading up to a release, while a bunch of admin stuff gets done. But lo! The latest expansion pack for my scarily popular space strategy game is now on sale. Here is the official launch trailer (also in HD, view on youtube to see in all it’s glory):

The website for the new DLC can be found here:

With this new race, I went with the idea of a cybernetic race who had been shunned and thrown out for their practice of biological/mechanical integration. I was thinking about all kinds of stuff, partly the tales from Star Trek:DS9 of ‘the founders’ being exiled and chased from worlds by ‘solids’, also partly the many different versions of the backstory of Doctor Who’s cybermen, and also the race of ‘krikkit’ in the hitchhikers guide to the galaxy, who seem like ncie people deep down, they just can’t cope with the thought of other species. My vision for the outcasts is that they are nice people at heart, they just suffer from a major persecution complex over the whole ‘cybernetic’ thing, and are determined to wipe out every non cybernetic life-form so they don’t have to feel awkward any more.

Who knows how many intergalactic wars could be solved just by some therapy eh?

Anyway, the new race comes with a few new goodies for people to play with, I suspect people will really enjoy the multi-point tractor beam and the decoy projection module, and no doubt GSB’s extensive modding community will pull the expansion to pieces, see how it ticks and start producing weird hybrid alien ships and new modules over the next few weeks. I hope so anyway. I’m also very pleased with the visual design of the ships for this race.

here are the obligatory buy links.

buy buy

Please help if you can by tweeting or facebook posting, or forum-commenting on the new race. It’s all much appreciated. For those of the social-inclined there is a Gratuitous Space Battles facebook page here.

…for direct bought copies, and will be updating on steam soon (as soon as I find the right instructions for it…doh!). Copies auto-update over the next 24 hours.

What are the changes? well…

version 1.61
1) Bug Fix: Drag selecting now launches ship inspector for the first selected ship, not the first ship in the fleet…ooops.
2) New feature: Support for the cruiser decoy projector module.
3) Bug Fix: AI now works differently, and less stupidly when assessing which target to move towards.
4) New feature: pulse-glow effect now supports two new variables ‘min alpha’ and ‘max alpha’
5) Support for new two-stage missiles.
6) Bug fix: Ensuring that regardless of framerate or missile speed, missiles that would hit, will actually hit.
7) Support for new multi-point tractor beams.
8) Improved design of load-ship dialog in the design screen so it scales to fill the available space and shows (and can sort by) hull name too.
9) Support for modding plasma torpedoes to use style CUSTOM and plasma_texture = “” for custom effects
10) Support for weapons firing from cloaked ships using the “fire_while_cloaked=1″ setting
11) Reverted the Area-of-effect code so it only happens on hits, not misses, as requested.
12) Added support for modded music.
13) Fixed obscure timing issue where when at 4x speed and a low FPS, theoretically some very-rapid fire weapons may have been ‘dropping’ shots. Game now supports multiple shots per frame.
14) Removed now redundant ‘internet news’ dialog.
15) Stats summary screen now closes properly when exiting the stats screen without closing it.
16) restricted race field for modules now supports comma-separated list for multiple races (for modders)
17) races can now be locked out of all vanilla tech (for modders)
18) hulls can now be hidden from the player (for modders)

So there is a lot of mod support stuff and preparatory stuff for the upcoming ‘outcasts’ race expansion. Plus the big things are the better design loader dialog, and the changes to AI, area-of-effect weapons and a bit of a rapid-fire timing bug problem.

I suspect all of today will be GSB/Outcasts related, probably the weekend too…

For those not following closely I am working on a new expansion pack for Gratuitous Space Battles. I was working on something else…but then i got seduced by the idea of more spaceships. I’ll return to the ‘other thing’ soon, I promise!

The new race is called the outcasts, and they are cybernetic types with a chip on their shoulder about biology. Think ‘the founders’ from DS9 but with a hatred of biologicals rather than solids.  In terms of visual design, they like their ships to be saucer shaped, with some exposed pipework and no shortage of engines or big glowy regions:

In terms of race design, I’m giving them a slight tendency towards faster ships (speed bonuses a plenty!) and concentrating on making better frigates for them. Currently my special ‘race-specific’ modules are as follows:

  1. Cruiser Decoy projector (see video here): This is a way that cruisers can project a fake cruiser hologram in front of them to lure enemy weapons away from the real fleet. bwahahahaha.
  2. Frigate 2-stage missiles (see video here): These start off slow, then accelerate (like a javelin missile) to make them hard to shoot down.
  3. Frigate multi-point tractor beam: These puppies can grab up to three different targets (probably fighters) at once. Oh yes.
  4. Frigate Pulse Gun: A new fast-firing laser-salvo gun that acts like a souped up ion cannon.
  5. Frigate Sniper Laser: Super-long-range frigate beam laser that allows them to snipe at the enemy from the safety of the main battle line for the first time.
  6. Solar Power Collector: A special frigate power generator module that beats all the others. Possibly frees up an extra slot for crew./shields/armor.

I may add other stuff, or make a few more radical changes during testing. I’ve also commissioned some awesome new music for the expansion from sean vella. This will make the outcasts the first new race to get their own special music recorded. Plus there are some stunning new nebula backdrops I got an artist to render for the new missions. For some reason, I’m really getting into this expansion pack :D There is no release date yet. I need to test and test and then release a patch to the main game to support them before I even consider releasing them. I can’t tell yet if it will be pre or post-christmas. Join in the discussion on the forums.

In other news, I just spent another fortune (well…£200) on insulation*. It’s COOOOOLLLLDDDDD here, and I’m determined to finish insulating that attic one day. I’ve shivered enough. Actually it’s not a problem if you are a normal person without an obsession with not using the oil-fired radiators like me. I’m a log-fire kind of guy.

*we have to use ‘breathable’ insulation in this old house, which makes the stuff much more expensive than normal.