Your browser (Internet Explorer 6) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.

Archive for October, 2012



Well, more like lost memory. Or chewing through memory. I’ve spent a while now investigating where I’m being foolish with it and I’ve been bleeding foolish everywhere. Looking into how memory is used and abused is really interesting and not something I’ve ever really delved into deeply as my previous work hasn’t required it. Now I have an entire city to look out for, I’m having to do things differently.

My main foe is modern memory management and the garbage collector. If I’m creating loads of things that only last fleetingly, then management will come in at some point and clean up all the unwanted stuff. They’re sluggish about it too, they have to look at absolutely everything and how it’s connected to destroy only the abandoned stuff. Basic game development advice always talked about object pools for things like bullets. But what about local variables? What about objects that are being rebuilt many times? Usually it’s a nonexistent issue and the new keyword will be fine to use locally. When you have so much going on though and so many local variables – it adds up. Sooner or later you’ll get the garbage collector coming in to pause your game for 1000 milliseconds. Very painful.

//Instead of
Vector3 newVector = new Vector3(someValue,0,someOtherValue);
//I’m using
Vector3 newVector = Vector.right*someValue+Vector.forward*someOtherValue;
EDIT: TenebrousP on Reddit pointed out this is rubbish and a quick test shows it’s just a stupid slow way of doing things. Serves me right for trusting a forum post without testing it myself… plain old new is more than twice as fast as the other method. TIL and thanks.

Dynamic meshes have been an interesting challenge; I don’t control the data in the mesh directly. I can set vertices fine, but can only retrieve a copy of them. Setting them more than once means the array is lost to the garbage collector and the game will freeze at some point. In order to solve this, I’ve had to wrap the mesh class with my own so that I have one array for vertices/uvs/triangles that is modified and never lost or destroyed. The array needs to be big enough for any kind of mesh it so everything is allocated at the start. It’s a waste of memory but the only way to ensure there’s less garbage collection.

public class DynamicMesh {

	public string name = "";
	public Mesh mesh = new Mesh();
	public Vector3[] vertices;
	public Vector2[] uv;
	public int[] triangles;
	private int _size = 0;
	private int triSize = 0;
	private bool _built = false;

	public DynamicMesh(int _size)
			Debug.LogError("Error: Size is not even");
		vertices = new Vector3[_size];
		uv = new Vector2[_size];
		triangles = new int[triSize];

	public void Build()

It’d be a tall task to completely eliminate garbage collection and I don’t plan on being able to. Ideally my game can run for long enough for it to not be called until I want it to be. Any pause in the gameplay like menu screens will be a good time to call it and release the memory. The user will be oblivious and everyone will be happy…ish


A Bit Quiet Lately…

So it’s become a little quiet lately on Redacted. At least when you look at this website it looks that way. However a lot of the work in the past month isn’t the visual kind, and I’m going through a large shift in the city generation code architecture so i can have bigger and more stable cities.
I’ve also had house guests, a 30th birthday and a trip to Japan eat into development time. But I’m getting on with it!

One thing I wanted to touch on was motivation, especially with projects you’re doing yourself and when you’re working from home. How can you deal with all those distractions? How can you keep going? I’ve noticed my productivity correlates to how clear my goals are. I’ve seen this even in my normal jobs. If I don’t really know what i should be doing, I won’t do anything.
As a lone developer, it’s sometimes been hard to keep yourself going. The trick I’ve been using has been to keep my goals small. Very small. Couple of hours small. I feel like I’m achieving stuff and I’ve always got more goals to achieve. I also need to get this game done, I’m super excited!

I just want it done! To finish off – here’s an amazing video on motivation I keep watching…