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

Faster Debris management. (coding stuff)

Today I did some tests on GSB as I expect it to be played eventually by hardcore gamers. That means the biggest mission in the game, hundreds of fighters on each side, huge fleet, huge map, with all graphical options turned on and fullscreen in 1920×1200 (highest res on my monitor). To my delight, it handles it pretty well, dipping below 60FPS only a few times when viewing complete mayhem. (Geforce 8800 GTS on vista, Core 2 Duo)

That’s a release build, but with debug symbols in it, so it might get a tad faster.

In this build, under those circumstances, one of the slowdowns is the debris. Not the rendering of it, but the creation of it. I cap the debris at 4,000 items. 2,000 in each of two ‘pools’. The slowdown was some code that basically did this:

for(each debris item)
{
if(isfree)
{
return debris item
}
}

(It was cleverer than that, in that it only started its search from where it left off last time, to minimize wasted checks, but you get the idea.).

The slowdown was literally the loop hassle of going through maybe 2,000 checks of the ‘free’ flag, with theoretically it being the case that only number 1,999 is free for re-use (or none of them).  Readers with long memories may recall I had implemented a periodic debris-defragger, which makes this stuff easier. However, I can’t be doing that every frame, so I tried out a new system today. (after a few false starts). The new system is fiendishly more complex and works like this:

There are 10 debris ‘free registers’ which are basically indexes into the array of debris. These registers identify debris items that are currently free by their index. Whenever I’m processing some debris, if it becomes free (fades out size or alpha-wise) I notify the pool to stick its index in any empty ‘free register’ that it has. This means finding an empty free register, but there are only 10, so it’s super quick.

Then the new piece of code to get some free debris does this:

for (each free register)
{
    if(register is valid)
    {
        return register[x]
    }
}
for(each debris item)
{
    if(isfree)
    {
        return debris item

}
}

This checks if any of the registers have any free pieces of debris, and if they are free, I re-use them (and note that the register is now blank). If all the registers are blank, I must have allocated more than 10 debris since I last let any fade out, so I need to go through the whole list as usual to try and find some free ones. If that fails, I check for some that are offscreen (I maintain a separate register of those), and if even that fails (we have 2,000 live debris onscreen!), I just randomly kill one and use that.

This chunk of code takes half the time the old one did, despite having more code in general. Does that mean its 50% faster? or 100% faster. I can’t get my head around that. If anyone can spot anything I’m doing thats stupid, I’m not above being humiliated in the comments with a smarter algorithm :D. I picked 10 as my number of registers in an arbitrary fashion. I should fine tune it really.

Formatting code in wordpress is a nightmare. BTW, this isn’t C++, this is simplistic pseudocode with about a quarter of the detail :D

Overgrowth and The Indie Attitude

I was chatting to Jeff from Wolfire a few weeks ago about their game overgrowth, and we started experimenting with ideas for cross-promoting our games. Since then I’ve been insanely busy, but I did get as far as putting this rather cool, and (to me) amusingly rabbit shaped spaceship (complete with Overgrowth logo) into GSB:

Why a rabbit? Well I think I should let Jeff himself describe what the rabbit connection is:

“Overgrowth takes place in the savage world of Lugaru where rabbits, wolves and other animals are forced to use paws, claws and medieval weaponry to engage each other in battle. Combining 3rd person adventure platforming with intricate melee combat, Overgrowth achieves a unique feel. Overgrowth also benefits from Wolfire’s brand new Phoenix Engine which has been built from the ground up to allow the use of cutting edge graphics, animation, and physics.”

Overgrowth certainly looks like an amazing game. I remember being impressed by the original Lugaru game, and OG looks like it will be a big hit.

The thing I find really interesting though, is the way in which our companies can do stuff like this, where we promote each others games, even stick content from one game in another, with the minimum of fuss. When I suggested we stick a rabbit ship in GSB to see how it could work, I didn’t need to get my lawyer to talk to wolfires lawyer. I didn’t need a strategic planning meeting with the head of corporate strategy, or have to justify to shareholders why we should help out what they would see as our competitors…

This is what I like about the Indie attitude.  Indie devs often share tips on game coding, getting decent contract work done, promoting websites and running forums, even the financial side of the best payment providers and who knows a decent accountant etc.

Can you imagine the head of EA giving the head of Activision tips on how to save on their bandwidth bill?

This is the indie attitude, and the indie advantage. We tend to take it for granted, because at the end of the day, me and jeff are two guys who love games and love making games. Somewhere along the line, the mainstream industry forgot that.

Level-of-detail in particles and debris

It took me a while to get support for this in. I still need some decent tools to get my particle effects placement faster and easier.

Anyway…. there is now some basic LOD support for particle emitters and the debris particles. That means I can have buckets of both and only render what I need (although tragically you still need to update a lot of it for consistency sake). here’s a screenshot showing debris increasing as you zoom in. It doesn’t look like I’m zooming in the way I cropped the screens, but I am :D

It’s faked a bit with a sudden detonation, so the screen looks a bit sparse, but it looks very cool in the game :D. It’s nice that it fades into view rather than having any popup.

I’ve been adding in hulk textures for all the frigates today, doing texture-atlases for the fighter hulks, and re-rendering some of them to prevent black jaggies around them at low zoom, designing some more AI fleets and generally fixing and tweaking.

Working through the levels

Almost all of today has been spent going through each mission in the game and constructing AI fleets (in three levels of difficulty) for you to fight against. Obviously each fleet will need tweaking and re-visiting many times before release, but this week I’m at least hoping to get every fleet in and working so the game is playable throughout all it’s missions.

There are a finite number of ship hulls for each race, and it’s pretty clear that I can’t get away with just the 12 or so ship designs for each opponent. In other words, the AI ships will have different variants of each design, so you won’t be able to just see a silhouette of the enemy ship on the mission screen and go ‘ah yes, it’s the one with lots of pulse lasers’. Which is cool.

Screenshot for today:

Playing through the game, and occasionally using the speed controls, I’m happy that there is enough going on, and enough you need to keep an eye on, to ensure that the battles are worth watching for more than just visual appeal. It really does help to observe exactly why your fighter squadron got destroyed without inflicting a single point of damage. There is a stats screen post-battle, but it’s more helpful to watch it happen to see who did it :D.

My current plans are for a few more weeks of play testing, and bug fixing and tweaking, and then to start thinking about my beta plans. I’ll probably get a few fellow game devs and friends to try it out to catch anything really obvious, then I’ll consider how to handle pre-orders and beta testing. My gut instinct is to go with a closed beta that’s only open to people who pre-order, because I think you get some decent feedback then. Feedback from people who have put money down on a game is always more accurate than feedback from random surfers who probably wouldn’t buy it anyway :D

I haven’t really thought about prices and publishers yet, although several are interested. People who own big web portals, feel free to get in touch :D

Fighter Hulks and some aborted stuff

I spent most of Saturday wasting my time on code that I reverted. Long long hours were spent working on bloom effects and shadows for ships passing over each other.  Eventually both were rejected. The bloom code simply didn’t look that good, and the shadow stuff proved to be hideously involved and likely very slow. I know people might assume you can do it simply by just rendering the ships to a separate render target complete with shadows, then slotting in the background later, but you can’t, due to laser and particle effects lying ‘between’ ships and also needing to be blended with the map background at render time.

Anyway… who cares :D

What I *have* got working is hulks for fighters. Previously a destroyed fighter was just obliterated by a fairly low res particle effect. The effect still needs improving, but now destroyed fighters linger as debris. Crucially, the fighter hulk maintains its momentum for a while, so they look like their engines just got shot out, and they also drift faster than the big lumbering cruiser hulks. This all looks a bit nicer than before where they just vanished. I also went through and got 4 variants of hulk done for each fighter.

Now I’m rendering out a few more loading screens, and later I’ll work on some improvements to particle stuff. Monday onwards will be ai-fleet design and general game balancing.