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

Minimizing Texture Swaps

Heres the other ‘big thing’ that sometimes causes 2D games like mine to slow down. Not drawing too many pixels, but changing what image is being drawn from too often. Video cards are great at drawing tons and tons of triangles using the same image to copy the pixels from. changing which image is ‘active’ will cause a major stall in the video cards rendering operation and waste time. Bizzarely, AFAIK you can only have ONE texture as the active texture for any specific moment (without doing multiple textures in different ‘stages’). So regardless how many pipelines your card has, you can’t be drawing from two different textures to two different polys at once. (is that right?)

Worst case scenario:
You render 200 sprites on screen. half have texture “ogre.bmp” half have “elf.bmp”. They have to be drawn from back to front, so that nearer ones obscure further ones. They are positioned (in distance from you)

Elf / Ogre / Elf / Ogre / Elf….

Etc. This is hell. because it means changing the texture 100 times. Ideally what you would do is get the video card to sort this stuff out. You would use Z values (distance from the viewer), and send all your sprites to the card with the right Z values and let the card sort it out.

Thats easy if you have a nice modular engine where every single rendering call goes through some nice sorted system where everything drawn on the screen is esentially some offshoot of the same base object. if you only ever draw sprites, then just send a huge bunch of Z-positioned sprites to the card and click go.

Unfortunately few engines work that simply, because there is no ‘one size fits all’ drawing object. Text is often composed of thousands of 2-poly characters, best sent as a vertex buffer. Some lines and primitives are drawn using direct 3dDevice rendering calls. And some are sprites with different render states. This is where it gets horribly messy. I’m slowly, with each game getting closer to a system where I am not blindly just rendering over the top of myself and hoping for the best. I can at least now bunch up a load of sprites called from different places, and have them drawn with a single call. What I don’t have is a perfect system that auto Z-sorts my sprites by position and texture, and makes the most efficient calls. maybe some 2D games have such a system, but I’m assuming most of them just don’t do enough fancy drawing for it to be an issue (or they ignore backwards compatibility with slower cards).

If I was a bigger company with a dedicated graphics programmer who just worked on the engine, I’d have a better system, but I’m still a one-man show doing everything, and there just isn’t time :(

Think Big

Just inspired by ‘enemy at the gates’ on TV tonight to find a picture of this statue:

Check out the people at the bottom. Yes it’s THAT big. It’s a monument to the battle of stalingrad apparently.

Holy cow.

Why use Directx7 (and dead links)

My games use directx 7. Not 8, 9 or 10. SEVEN. That is OLD. If you have windows XP and never installed anything, you already have Directx7 (or later, which is fine).

Why do I do this?

Several reasons. Firstly, DX7 is the version I learned when I first wrote a reusable graphics engine for use in multiple games. Re-writing an entire engine can be a slow process. Don’t get me wrong, getting it to WORK, is not a big deal, but getting it stable, bug free and (essential for an engine) FAST is very slow work. I know DX7 very well, I have optimized it to death, and know my way around the API really well.

Secondly, DX7 is all I need. I don’t even do 3D games, let alone ones using bump mapping and pixel and vertex shaders. I don’t stream geometry or use mip maps, or do multithreaded vertex processing or anything clever like that. DX8 and 9 *do* achieve some simplification of code, but don’t add anything I need.

Thirdly, DX7 means everyone who buys the game will have drivers that support the game. I don’t need to package the game with the directx installer or worry about such things. Some people playing indie games on laptops have very low spec cards, and you are best off sticking with DX7 if you can. A LOT of casual games use DX7.

The thing is, Microsoft REALLY don’t like this. Obviously they try and push you to use the newer versions, that’s natural, but it’s almost like they are insulted and annoyed if you want to stick with DX7. It is *impossible* to find a download of the directx7 SDK. Microsoft removed it from their website, including all earlier versions. They want to FORCE you to use the new stuff, even if its just pure hassle with no gain. After all, why would anyone make a game without bump mapping right?¬† I am rewriting part of my engine in an attempt to speed it up yet again, and I was forced to dig out the CD that came with an old book to find some source code, written by Microsoft that they refuse to let you have any more. It’s mad. I have released a lot better games that ‘Asteroid Miner’, but if you follow a link from a website not updated since 1997 to my homepage (which has moved servers 4 times since then), to an outdated zip file containing the game in the root of my site (before I knew not to do this) that zip file is STILL there. I just think it’s rude to move files people have linked to, for no good reason. Every time I follow a link to a companies website that’s dead, I just think they are LAZY. Web links last a very long time, why encourage inward pointing links to die?

Email day

I made some silly config mistakes today and sent an email to some people who I wasn’t intending to email. There is no ‘harm’ done, but some people who bought Democracy and Democracy 2 got an email from me on the basis of them *not* having bought the sequel.

I screwed up.

Nobody has really complained, which is great, because the minute I realized what had happened, I worried I had committed email sin by effectively spamming. I guess I just have to put it down to experience.

Like a lot of developers, I don’t handle the sending of emails myself. You might wonder why not, and ironically the answer is spam. If you try and send more than 100 or so emails, many ISP’s will block your ability to send emails for a few hours or more. This is a GOOD idea, because it prevents you unknowingly being part of a spammers botnet. It’s also good, because there is no chance of any paranoid, badly configured ISP’s anywhere assuming you are a spammer and blacklisting you (nightmare!).

I use this company:


To send my emails. It’s not free, but it’s a worthy investment. I don’t mind paying to send an email to a bunch of people, because it makes you think about the content. I read some wise words from a respected marketing guru, saying that you should only email someone from your business if you would still have sent the email if it had cost you $0.42 (per recipient). Despite my balls up today, this still holds. The number of companies that send me pie-in-the-sky bullshit every week on the sad misunderstanding that I am interested in their megabucks 3D engines, are recruiting Animators, want a job in IT support etc etc, is sad proof that *most* businesses who send email (not spam, but ‘targeted’ emails) wouldn’t send most of it even if it cost $0.01.

Have a gift

I started redoing the code for gifts in Kudos 2 today. The original game had a simple¬† single ‘gift’ which you could only buy if you had a ‘romantic partner‘, and went straight to them. There was some pretty cool code regarding ‘gift cynicism’ in there, but to be honest it was put into a post-release patch and not properly thought through. I’ve set aside tommorow to code a better, slightly deeper system for Kudos 2. A day doesn’t sound long, but remember I do everything, and there are a lot of areas to polish and get finished.

My first thought is whether gifts should still be just romantic. Shouldn’t I be able to buy a gift for a friend? Maybe… but perhaps code is needed to handle how this is a different matter to romance. Would it be fair to suggest that friends feel more uncomfortable getting gifts, than romantic partners would? If You are my “significant other “and I buy you a box of chocs, thats cool, but if you are my pal and I buy you an ipod, would you not think it a bit weird? maybe feel like I’m showing off, or that I must want something. I think there is a lot of complex contextual stuff needed to handle how friends react to being given gifts. Some of this is already in Kudos (friends track how in debt they are to you in terms of offers to pay for entertainment), but it would still require a lot of extra complexity. Gifts also bring up the possibility of tracking friends and partners birthdays, and thus birthday social invites etc etc.

At the very least, the new system will have multiple gifts, at different price points, and let you buy them in advance and hand them to people later, maybe just after you turned down their invite to a romantic candlelit dinner so you could spend the night reading a book on software engineering. This sounds like it’s autobiographical now doesn’t it?

In unrelated news, I’m reading a book on ‘supercrunching‘ and andrew marrs ‘history of britain’. both are good reads. My knowledge of the Korean war, or the Attlee government was minimal. I didn’t even realize Churchill was voted out, then in again. I guess I was good at maths and crap at history as a kid…