Category Archives: Programming

Moving House

So, it turns out moving house takes up a lot of time and mental energy. I’m about to make a large move across the country to a new city (London) and lose most of my remaining savings at the same time. It’s pretty daunting  but I’m hopeful that things will work out for the best.

I’ve been squeezing in a little bit of work on game projects when I’ve had the time or energy. Over the summer I started work on a little top down 2D project inspired by a TIG Source competition but, as such things tend to, it grew larger in my imagination and it began to take away time I should have been spending on the Free Company project. I learned a bunch of useful things through working on it, principally about texture atlasing and how difficult it is to make a flexible action scripting system for a level editor. Hopefully I’ll pick that project back up at some point in the future and polish it into something playable. Recently, I’ve been back on Free Company trying to make some headway on the automated level generation (very tricky), cleaning up the front end and a lot of refactoring of the code I’d already written to make it more useable across the multiple projects I’d been running.

The  indie game stuff is going to have to take a backseat from now on though, I’m out of money and taking on a big mortgage at the same time so I’m back searching for some full-time work. I’ll still try to do a little bit of work on the game now and again but realistically it’s pretty unlikely I’ll get anything big finished anytime soon.

Hopefully, once I’m settled in London things will calm down a bit and I’ll be able to get back to this blog occasionally with information on whatever it is I end up doing next.

Thanks for following.


Post release code cleansing

I’ve spent the last couple of days tidying up my code base, it has become functional rather than readable during the heady final days of preparing it for last weekends release. I’ve gone back to basics and am attacking it with a series of tests and refactoring approaches to get it into a more happy shape.

Firstly, I attacked performance again. I probably spend too much time on performance because it bothers me when I’m certain that something I’ve just crafted could run a lot faster with an approach that its lurking on the periphery of my thinking regions. This time I was convinced that I could reduce the work of the visibility system because it had a couple of meaty looking for loops sitting in it. I had an early disappointment when I found out that I had got to one of them already with my intended refactor, but was able to recover by completely removing the last of my big three loops at the cost of making dynamic point lights a problem to be solved again later.

Of course these planned efforts were somewhat undermined when I inadvertently made a large improvement by slightly contracting the radius of my vision cone’s clip planes. Hours of work for a few half milliseconds a frame and a one line change that saves a couple all by itself.

Somewhat stubbornly I think there is still more to do on performance. I have a to do list item to make my hexagon grid fully visible to help players figure out what’s going on under the hood at the minute and to allow for better tactical decisions later on. The problem is that I’m currently insisting on make each hex of the grid be its own visibility node and renderable instance and there are about four times as many of them as the rest of the scene combined. The reason I want to keep them as separate objects is because it makes it a lot easier to do fancy things with them, particularly highlighting a certain arbitrary selection of them whenever I choose, but perhaps more. If I didn’t want this flexibility I could make the grid a single quad with a tiling hexagon image.

I have a, somewhat primitive, ‘shader instancing’ system for bundling up all the visible instances of a type into a smaller number of bigger buffers. This helps a lot with the draw calls per frame but incurs a cost in building the larger buffers each frame and still maintains the cost of checking the visibility of each hexagon instance. To improve this further I need to somehow stop refreshing the entirity of what is visible and what is in each instanced buffer every frame. I suspect there is a way to do this but I’ve put it to one side for now.

The past few days I’ve been looking into cleaning up my memory usage. I’m generally fairly diligent about putting my ‘news’ and deletes in the right place but everyone misses things every now and again and the mistakes can pile up if you’ve been mostly ignoring not fatal memory leaks for a while. Early on in the development of my engine I took the precaution of performing all allocations through a #define’d version of new that allowed me to easily swap between alternate versions of my allocators without editing everything or affecting any libraries I was using. This approach is pretty handy for tracking down persistent memory leaks as I can swap out my standard allocator for one that keeps track of an ID for every allocation in a giant hash map. Then when the application shuts down I can see a printed report of any objects that weren’t deallocated along with their IDs. It works pretty well so far.

There are some leaks that escape this method because they are allocations that don’t make use of my macros so to make sure I don’t miss them I also make use of Microsoft’s memory leak detection methodology at the same time. I recommend you read through the whole section on memory leak detection here if you’ve ever had problems with leaks. One quirk they don’t mention is that to get the really useful line numbers of when an allocation with new takes place you also need to add in a line that looks a little like this:

#define new new(1, __FILE__, __LINE__)

Otherwise it will only work for malloc.

Some leaks appear to elude even both of these detection methodologies so for my final set of leaks I resorted to the old programmer standby of the trial and error commenting out of code and recompiling. For this method to work with any degree of success your code has to be robust and independent enough to still run when you comment it out piece by piece. I spent a bit of time ensuring this were initialized to zero to make this possible but eventually I narrowed the problem down to the root cause, fixed it and I was back down to leak free code.

No leak

If I was doing this better of course I would probably be making much greater use of template based reference counting pointers for all my heap memory usage. They’re not yet part of the STL but I’m pretty certain they are due to be added in the next round of standardisation, there are also many implementations available through boost and vendor implementations of the TR1. Changing everything over to use shared_ptr rather than new and delete would be a fairly large refactoring right now with only minimal short term benefits (as I’m able to track leaks that occur fairly reliably) so I probably won’t do it for this project but I fully intend to start the next project with reference counted pointers as a key technical inclusion.

Next up will be some more general usability refactoring and code tidying. The key goals here are to make the purpose of classes clearer, adding new ones where they are needed and making all classes more data driven and flexible for reuse.

Coding an indie game is a lot like building a multi story shanty house. Before you build the next story you need to make sure the previous one is going to take the weight without collapsing into a pile of corrugated iron and salvaged wood.

multistory shanty

Coming later will be a look at some of the less technical aspects of the game’s development so far. If you have any think to add onto any of my warbling above then feel free to do so in the comments.


Come inside the Robotic Shed

I’ve decided now that I’m not going to think up a better name for my fledgling game making production house than ‘Robotic Shed’. I mean what could be better than a regular garden shed with robotic arms, legs and a fervent desire to see you all dead, for making you think ‘Games! Yes! I need some of those, and from that guy!’.

Nothing could be better, thats what.

Work on the game itself continues apace. I’m in that sort of sticky middle patch where I spend a long time taking care of boring sometimes awkward stuff that makes the game no more fun but a lot less ‘where the hell is the…’. For example, I’ve fixed up my pause and options menus a lot so that you can now turn off some of the graphical wizardry to better suit a lower end machine. I also spent an unreasonable amount of time puzzling out line of sight on a hexagon grid by hand before realising that the enitre internet had got there first. I had several pages of A3 covered in scribbled diagrams before I went back to google and adjusted my search terms a little.

I’m also now pretty certain that I’m going to be calling the game ‘Free Company’ after the mercenaries of medieval italy. This is a massive improvement on my previous title of ‘Dan’s hexagon fighty game’ which in market testing lacked a certain resonance with my intended target demographic.

I’m still intending to churn out something playable at the end of January and to that end I’ve been trying to pare down the design to the barest of essentials to hit that date with a decent chance of it all working and being a little bit fun. I’m not cutting stuff forever, just removing things from the ‘tech test’ demo schedule that don’t absolutely need to be there.

My current plan is to get the barest bones of a tactical battle engine up and running with a simple test battle between the player and a few AI controlled minions. Once thats in place the months after that will be entirely focused on adding to and iterating that basic battle engine until its super fun on its own merits. The goal with this phase of the project is to eventually produce an alpha version that features a neverending sequence of randomly generated battle levels that are all balanced and mega fun while the player takes a persistent group of mercenaries through them until all of his mercenaries are dead. Ultimate battling without context if you will; the sort of entertainment offered by something like Gratuitous Space Battles or Zangband.

The third and final phase of ‘Free Company’ will be then to add the Total War/Civilization/X-Com style campaign map to give the battles the political context of a gradually developing mercenary group in a randomly generated dark fantasy setting. This all depends, of course on me still having any money or sanity left after hammering down phase two. I’m debating opening the project up where interested pioneers can get the latest pre-release versions for a heavy discount once phase two is complete. This would be both so I get a little income going, and so I get some valuable feedback on the design. That sort of thing seemed to work out alright for the developers of Mount & Blade so maybe I’ll have a chance with it as well.

Anyway, carry on.