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

Scenario Editor

I’m a big fan of modding and game editors. people love to tweak a game they way they want it, and I support that 100%. So with this in mind, here is a work-in-progress screenshot of the custom scenario editor.

The idea is that there is a new way to launch a challenge (maybe from the challenges window), rather than selecting an existing singelplayer mission. That new button takes you to this screen which lets you tweak everything. Once done, you can then click deploy, and arrange your fleet like any other mission, then issue that as a challenge to anyone else. You can only use backgrounds that already exist in the game, but everything else is tweakable.  The only big chunk not done yet is changing the deployment zones. I may end up adding that later and using defaults for now. My UI coding is sadly slow and inefficient :(

Together with in-game messaging, this is the second big feature that will be in the next patch (alongside many bug fixes) which will be 1.28

Fixing a single GSB bug

Step 1:
Where is the game crashing? it crashes here:
void GUI_TitleBar::SetTitle(std::string str)
on an assert
GASSERT(Width > 0);
Width is clearly not set right when we set the title. Cue lots of hunting through every window that uses that code to check that they never set their title when they are yet to set their width. No luck.

Step 2:
Sudden realisation that the window width is a red herring, it’s the titlebar width itself that isn’t set. Sudden discovery that a function in the dialog class is virtual, but the function it supposedly implements is not. Possible confusion? certainly sloppy and needs fixing, but I can’t fix it *now* because I need to know *exactly* what causes this, rather than changing stuff and hoping I found it.

Step 3:
Realisation that the negative width may be an infinite high width wrapping round, which implies width has never been set. Maybe this is why I never see the crash in debug? A check shows that window widths are always set to zero, but that would still trigger it…

Step 4:
Reading up on related bugs suggests something to do with the race changing, combined with the ship editor. Decide to test in release mode deploying, then changing race then going to design mode. W00T! It crashes, although release mode debugging is far from trivial. It looks like a null pointer though, meaning it should reproduce in debug

Step 5:
Reproduced it in debug, which normally means home and dry. A module type pointer is set to 0xcdcdcdcd. This means uninitialised, and this seems to be the case. I’m assuming it is null without setting it to NULL. If it had been set to NULL, then a module would have been selected.

Step 6:
Temptation to fix an obivous unintialised pointer error here, but that would be BAD. The task is to really understand the bug before fixing it. For example, why does this not *always* crash when launching ship design? Lets test… It seems to always crash for me in ship design. That cannot be right…Aha, it’s handily crashing in some code inside the STL library, but only in debug build. A quick check of the shipped release build shows I can’t now replicate the bug there. Even stranger. Could I possibly have shipped a debug executable in a patch, this explaining why not everyone has the issue? No, the file size difference is 3MB.

Step 7:
Tests shows that the same exe does not crash taking the same steps if outside the IDE. The IDE is clearly setting those debug values and trapping an error. Is this actually related to the titlebar error crash and change race crash everyone has? If the module pointer is invalid, all hell could theoretically break loose. Getting tempted now to just fix the obvious errors, at least to see what happens next.

Step 8:
There is just no way that this pointer is correctly set to null. Unless it’s null by happy co-incidence, the game should crash whenever the ship builder is viewed. (if null, the game assigns it a valid value). Adding an assert for this, which still triggers in my release builds. It doesn’t trigger. How the hell is that pointer being set to NULL?

Step 9:
I suspect I am being lucky in release build with this. The pointer is uninitialised and being set to NULL most of the time as a side effect of something else, but this is not guaranteed, hence the randomness of the crash. It’s clear this pointer should be initialised, so I’ll just do that, and move onto new stuff.

Online integration fun

You know what’s missing in GSB?

Yes, yes I know you want a big 4x style campaign game built around it. ONE DAY maybe, but certainly not by the end of the week. One thing that is not quite so huge and unwieldy for a short term project is the area of online community.

Player A reads a forum post by player B, and decides to issue them with a challenge that proves their point that tribe frigates kick ass. Player B is oblivious, unless they happen to be browsing the challenges and spot they have a new one, from that player. Wouldn’t it be much cooler if every time someone issued a challenge to you, beat your challenge, or played (and presumably lost) your challenge, the game knew about it, and collected those messages for you to review at your leisure?

So rather than having to go to challenges, filter by personal and check if anything looks new, you could have a little spangly message popup saying “you have new messages“, on the main menu, and clicking there would tell you what’s new in your world of GSB.

This sort of stuff isn’t *that* evil to code, even though it involves server-side stuff. I already have it all up and running, UI and all, and the server is currently processing messages as I speak (although nobody has  a game version that lets them see them yet. But I can tell that a bit earlier, superneals sent a new challenge to knightsofni, for example.)

This will go into version 1.28. At the moment it’s system generated messages, so you just get pre-defined text messages notifying you of events. If people liek it, I think it would be awesome to be able to win a challenge, then type a message for the person you just beat saying “Ha!, i beat that fleet without even using plasma. I’ve responded with my winning fleet.” of course, you need to be able to block abusive / spam messages, but I’m working on that now. Besides, anyone spamming or being abusive will get the ban hammer :D

Challenges and Mods and Expansions

One of the arguments against expansion packs for games is that they ‘split the community’ It’s a real fear, and it’s one that Company Of Heroes solved cunningly by patching the content for everyone, but only letting purchasers play with those units. That might work for GSB, allowing people to fight against enemy fleets from another race, but not be that race themselves, but that is a bit of a major project for another day maybe :D

When preparing the way for the games expansion pack, I’ve put a lot of time into making it as flexible as possible, in the hope that players will be able to add content and mini expansions of their own. Everyone has their own ideas on what spaceships look best etc, and I’d love to make modding GSB really easy. To that end, the expansion has been a great ‘test case’ in that it forces me to make add-on content easy and modular.

One of the things involved was support for multiple distinct directory structures for add-ons, which is already done. The second big issue was challenges. People with the new fleet will be able to upload challenges, but obviously people without it can’t play them. A method was needed to tag challenges with the names of the installed expansions (or mods) and let the client check them against what is installed locally. This has all been in for ages, its just been dormant. Now, there is finally a UI for it on the challenge screen (in the next patch). Here it is:


Basically the game lists a checkbox for each installed mod or expansion pack, and defaults to them all being on. Any challenge you submit is tagged with them all, unless you untag them on submission. This way, unfortunately you can tag them wrong, and upload a challenge which will crash if the player doesn’t have the data, but you would have to deliberately do that. What it does allow you to do is to still issue ‘basic game’ challenges, as well as ones with new content. More importantly (and the reason its not an automated file compare thing), is the ability for anyone to create a mod, give it a user-friendly name, and upload challenges with it in, which will flag up a notice explaining what’s missing for people who attempt it.

I’ve probably explained it really badly. In any case, that screenshot is of my test case with 3 packages installed locally. Thoughts?

Dealing with mice

Take a trip far back in time when dinosaurs ruled the earth and Directx 5 was the very latest cutting edge thing. Back then, the hip cool and trendy thing to do with mouse input was to use direct input. I have a pile of programming books on how to do it, and you can enjoy the handy tutorials on capturing mouse input using directinput in the directx9 (and later) SDKs.

But…

It turns out that this is not the way to do it. In fact, there are even articles online now where Microsoft quietly admits that if all you want to do is normal mouse input, you should avoid directinput altogether. To make things worse, there are a ton of features to do with mouse acceleration, button swapping, double click speeds blah blah, that are all missing and need to be implemented from scratch (as I was doing….mostly)  if you use directinput for the mouse. How come I missed the memo on this?

Like a trusty old coder, I’ve been re-using my engine for a while, and although I have a nice shiny new graphics engine I was still using directinput for the mouse, which explains the somewhat erratic and crap mouse support in GSB. But that changed today, when I finally got sick of it, and ripped it out. The next patch will switch GSB to the standard windows cursor, even in fullscreen, and it will all work much better.

One day I’ll find time to sort out the keyboard too…