Multi-Thread Game Engine Proof of Concept
A very long title for both the most intresting and most boring (depending on your point of view) project I’ve done in a while.
This all infact started after a discusion in the gamedev.net forums about making a multi-threaded game engine. Someone on there called Superpig put forward some ideas he had been playing with and I decided to have a go at reproducing them with my own code and twists on it, and as such the screen shot above was born.
I threw the term ‘multi-thread’ at your just now, so I’ll try to explain that quickly. Basically, when the computer is doing something it can do that and only that, multi-threading is a way of making it appear todo more than one thing at once. This is a pretty new disappline when it comes to game programming (its been used before, but not in such a way) and in my opinion one of the hardest areas of computing as so many things can go wrong when you are running effectively two things at once.
Although I said ‘appear’ back there on newer systems the computer can infact do two things at once as many new systems are coming with what are called ‘multi-core CPUs’ which area effectively two CPUs on one chip. This makes this that much harder because two things really are happening at once!
The idea behind this project was pretty simple;
- One thread was used to update the world, doing so every 20ms
- One thread was used to update the screen as fast as possible
In the screen shot above you can see its doing 48update per second and rendering at 1429frames per second. The position between each update is calculated by the rendering thread, which was the most brain breaking bit as you need to store 3 states;
- where it was
- where it is
- where its going to be
You render by working out the correct position between snapshot 1 and 2 based on the current rendering time.
The biggest challenge with this project was making the swapping of the various states as fast as possible. The method used was infact very simple in the end and involves just swapping what each update pointed to, data wise, very quick and very stable.
Project Status
Work in progress.
This one has legs I think, plus I’ve got a slight 64bit OpenGL problem to solve.
Downloads
None right now.
One Response to “Multi-Thread Game Engine Proof of Concept”
By Kairehn on Jun 14, 2008 | Reply
Ahoy! Still working on this? Would love to play around with it sometime.