Smartness overload – addendum

July 4, 2010 – 9:33 pm

In my previous note I mentioned that IDs are my favourite form of weak references. By pure coincidence, just recently Noel made one of his Inner Product articles public and it deals with very related subject. As a matter of fact Noel’s implementation of HandleManager has been a starting point for the one I use for my home projects. I use it not only for dealing with resources, but as a general ID->pointer resolver. It can be made a little bit easier if you don’t need to handle heterogenous objects. My modifications include:

  • getting rid of a type field (instead, I have multiple pools/managers),
  • optimizing Get() method a little bit. I do not test if entry is active, I only compare counters. To make sure it works as intended, I modify counter when releasing resource/object, not when acquiring it. This let me to get rid of one comparison, not a big deal, but every little bit helps.

Noel made his implementation public, I encourage everyone to download it and take a look, it’s very simple, yet helpful piece of code.

Read the rest of this entry »

Smartness overload

June 28, 2010 – 12:10 am

Over the years, I’ve seen plenty of different code bases – open source projects, internal game engines, my own experiments. Some of them were just bad and buggy, but in many situations I found something that could only be described as ‘smartness overload’. An obviously skilled & experienced programmer just tried too hard. There’s a great quote attributed to Brian Kernighan: “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it”. I find it very true, it’s even more dangerous when working in team, you cannot assume that everyone is as smart/experienced as you.

Read the rest of this entry »

Optimization 101: ordering conditions

May 15, 2010 – 9:22 pm

One of the most basic truths about optimizing existing code is: there are no low hanging fruits. Your coworkers are not stupid, it’s not like you can just add some switch or line and code will magically run two times faster (at least not often). “Easiest” way nowadays is probably some form of parallalization, but it’s not always possible. Usually, it’s more a series of mundane tweaks, day after day, shaving few cycles here, few there. I’ve been in situations where I was genuinely happy after gaining as little as 1.5ms (out of ~9ms, it was main object update loop, that’s been already after few optimization sessions in the course of 4-5 years, there really wasn’t much to get). Read also Pierre’s Novodex story for better idea of how it works.
Condition order is one of those not-so-glamour aspects of optmization. It won’t give you much, but it can give you something, at least.

Read the rest of this entry »

Be nice to your cache

April 25, 2010 – 2:25 am

Short list of tips & guidelines that every game developer should keep in mind. No rocket science, common sense, really, but it’s still relatively rare to find codebases that apply to them. It’s especially aimed at gameplay programmers, who operate a little bit further up from the metal. With todays hardware, cache can be your biggest friend or enemy, CPUs got the the point where a few extra calculations hurt much less than a single cache miss (so LUT is not always the best option, for example). I’m not going to write too much about cache architecture itself, it’s a topic on its own. If you’re interested see Gustavo’s article or this paper by Ulrich Drepper. In a nutshell – cache is a very fast memory organized in lines of 32-128 bytes. When memory is referenced, cache is tested first, if data is there – access is very quick, if not – whole line is loaded. In the latter case, this means cache miss and costs hundreds of cycles. Read the rest of this entry »

Venice

April 4, 2010 – 3:29 am

Venice is truly one-of-a-kind city. I’ve “been” there almost 8 years ago when returning from Italy by train (long story involving lost plane connection), but it was continental part then (Mestre) and only for 2 hours. For some reason I thought that the rest of the city looks the same, just with some canals here and there. Couldn’t be more wrong. Basically, it’s more of a museum than a city. There are no roads, no cars, no buildings younger than XVIII century. All municipal services use boats (police, hospitals, post, transport). There are other cities that are sometimes named Venice of the North/East/West. I don’t think they’re even close. Some random photos:

St Mark square, balcony view

Masks are everywhere, not always as beautiful as those, though Random canal photo #65263 Sculptures on Santa Maria della Salute church Yet another canal Family house of Marco Polo Cemetary island (Cimitero) That's convenient, parking just in front of the door... View from Giudecca island (night photo) Lido beach This guy surely knows all work and & no play makes Jack a dull boy St Mark square

More photos from Venice here, Verona here.

Back!

March 28, 2010 – 10:56 pm

OK, I’m back. Just for a few days, though. I’m crashing at my sister’s place, as our flat is rented. There’s rather crappy internet connection here, so no Venice photos yet. I’ve updated (very roughly) my GDC note. In the meantime – GDC vault has been updated, so you can find most of the papers there. I will try to upload some photos when I get to the hotel in Canada.

GDC update

March 20, 2010 – 12:31 am

As I mentioned – I’m flying for a quick vacations tomorrow, so I will not be able to update the GDC links. This post is mainly to trigger RSS readers, as I’ve added some new stuff during last week. Feel free to add new links in the comments, I will move them to the post when I get back. In the meantime people can just dig them out from the comments section.

Ten Months in Sweden

March 17, 2010 – 7:20 pm

About two weeks ago I had my last company beer/good-bye party at Starbreeze. I need to deal with lots of formal stuff in Poland now, then I’ll have a short vacation (flying to Venice next week) and then I will move to Canada to work for Digital Extremes. It really wasn’t easy decision as I had great time in Sweden and Starbreeze, but the offer was just too good to pass, one needs to take risks sometimes.

I will miss Sweden and SBZ guys, last 10 months were really cool and I’d like to summarize it in few photos (image heavy post incoming).

Read the rest of this entry »

GDC 2010 proceedings

March 9, 2010 – 11:49 am

I’ll keep updating this post with links as I find them.GDC logo

Data breakpoints

February 27, 2010 – 2:15 pm

Data breakpoints are one of the most helpful debugger features when trying to hunt for memory overwrites/ninja variable modifications. In majority of cases it’s enough to set them up from debugger, however, there are situations when it’s not possible. Sometimes breaking into debugger changes program behavior (I had this problem just yesterday), sometimes we don’t want to catch every variable access, just some of them (as others are legal). In situations like that we need to set data breakpoints from code. Read the rest of this entry »