Game Design, Programming and running a one-man games business…

Thoughts on multi-threaded 2D game development in directx9

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!

threads--friend--grey-cat--thread_3218279

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?

 

2013 a good year, start of investment, and some consolidation

So 2013 was very good for the business side of Positech Games. it’s definitely been my most profitable year yet. We spent more than ever making games, more than ever on marketing, and made more than ever back. In biz terms there were a lot of firsts…

  • First time I hired a PR agency was in 2013
  • First time I had a proper pro trailer made was 2013
  • First GDC attendance was 2013
  • First time I exhibited at trade shows was 2013.

First time I actually paid out for a site-takeover advert was 2013.

And on the non-biz, but development side…

  • First time I managed a foreign-language translation and…
  • First time I took Mac & Linux porting costs under positechs control, rather than splitting it.

These were all good decisions, everything seems to have gone pretty well. Plus, we released redshirt, the first name under the positech banner developed by someone else (Tiniest Shark).

Those were the exciting new, adventurous things. On the game design front I’ve been more cautious. I released Democracy 3 and started (very early) work on Gratuitous Space Battles 2, both sequels. I truly have become hollywood! My plans extend to a new IP by the tail end of 2014, so don’t think I’ve entirely run out of ideas (far from it!).

Because sales-wise the year went well, I’ve been doing some consolidation and investment for positech too. I’ve had a lot of popular games, but maybe I’ve been lucky. There is no magic rule that says I will earn a single penny in 2014, and given development costs, I *may* actually lose money. As a result, I’m starting to think longer term about investing in making positech a more ‘solid’ company to own. That means a bit of investing (it’s shocking what a terrible rate of return you can get right now, even if you are prepared to lock money away for a loooong time), and a bit of investing in the biz itself, stuff like equipment and improvements to infrastructure. I also see advertising as a long term investment. I know some people take 150+ days from clicking an ad to buying my games, and I suspect the real figure can be longer. A certain chunk of the democracy 3 ad budget will pay dividends in GSB 2.0 or New IP sales. I like to think long term.

2014 offers a lot to look forward to, I have some stuff coming up quite soon(ish) and of course I’m very keen to show off some proper GSB 2.0 screenshots when I finally have something to show :D

Happy new year all!

 

DEMOKRATIE 3

Ok, so after my fairly low key release on my own site, finally Democracy 3 was released in German to steam yesterday. It’s been trickier than I suspected it would be, mainly due to GUI annoyances and web page shenanigans, but it is on-sale now.

Sales to Germany have been pretty good, with 6% of revenue coming from there, in the English version 9and there are other countries that speak German, obviously). if I can boost sales to those countries by 25% then I have made money on the translation, so hopefully it will exceed that. It’s also cool to have more people play the game, and it’s interesting and exciting to have done something (funded and managed a pro translation) that I haven’t managed before. (Democracy 2 was translated, but on a revenue split basis).

As is typical, I’ve scheduled this for a stupid time (23rd December!) so I won’t get any press coverage, but just having the game come up with a German option has to boost sales in the long term. I can make German language copies available to any German gaming sites who only cover translated games, which is a bonus. I made a decision to go as far as I could in translation terms, so I translated the game text (obviously) and also the logo, got a new trailer done (twice!) translated the positech site page, and changed the steam screenshots and promo assets to have German text. I even have some German adwords ads I might experiment with a bit.

Anyway, if you have German speaking friends who have turned the game down until today, please point them at the games German website or at the steam page for the game. Danke!

Delegating and outsourcing as a study in comparative advantage

Delegating is hard. Getting someone else to do something instead of doing it yourself… there are a whole bunch of psychological, practical, economic and other issues to navigate when doing that sort of thing. There is definitely a point where you have to either accept that your company will never grow, or start delegating. I’m definitely there right now. If I wasn’t a workaholic, I’d have reached it 2 years ago.

So right now I’m in the situation where when I see something that I can possibly delegate, I jump at it. I guess when I say delegate, I mean outsource. Ideally, I’d have full time employees, but I don’t need an artist, or a web developer, or game designer or ad-manager or PR person. I need a little bit of all of them. Thats hard to find. As a result I end up employing a ton of people on short term piece-work contracts. Right now 3 people are working for me, a designer, a web developer and an artist. Oh and a trailer-producer, so that’s 4. The trouble is, it *always* involves some admin and management (I insist on a countersigned contract even if its $100 of work), and also it’s never 100% like you doing it yourself.

But I did recently come to a bit of a revelation. The fact that I could get the results I wanted quicker with me doing it, is irrelevant. It becomes a question of RELATIVE efficiency and not absolute. This is a bit of a mental trick, and it’s probably the one thing I recall from my economics degree, but check this out: (from wikipedia)

Comparative advantage

In economics, comparative advantage refers to the ability of a party to produce a particular good or service at a lower marginal and opportunity cost over another. Even if one country is more efficient in the production of all goods (absolute advantage in all goods) than the other, both countries will still gain by trading with each other, as long as they have different relative efficiencies.

On the surface it sounds like nonsense. If I can make bananas cheaper than you, and tractors cheaper than you too, why on earth would I trade bananas and tractors with you? Read the article if it isn’t obvious, it’s kinda magical.

There is a difference between reading that and really internalizing it. What it comes down to is this: If you can’t find an artist as efficient as you, or can’t find a designer as quick as you… it really doesn’t matter. It probably STILL makes sense for you to outsource. You aren’t paying someone to do a job more efficiently than you (of course that would be awesome) you are paying someone to do a job *so you can do something else*. Clearly, the solution is to make the *something else* the stuff that can never be outsourced.

I bet I’m explaining it badly, but I know what I mean! It’s a revelation to me. I suspect it also acts as a barrier to expansion for some small companies.