And we're back again
So it's been an extended leave of absence from the game, with other projects taking priority, such as building a site for my wedding, getting married, honeymoon, and another side project. I didn't realise it'd been a year until I checked here.
Anyway, I've taking the time to take the development back a couple of steps (mainly due to that damned profiler) and focused a bit more on improving the speed of the AI and adding some useful tools like testing.
To start back then, let's look at the AI speed again. There was a post from a year ago with some graphs in it showing the speed improvements back then.
The top two graphs are from before. The first being the first attempt at the AI (with 66ms spikes!) and the second is after the first major refactor. It's significantly better in that it's removed the massive slowdowns and kept everything ticking along, but it has some issues. This test is with a single AI. The 5ms spikes you can see in the second graph are the AI's "heartbeat". That's when it's thinking about the world around it.
These heartbeats need to be quite regular to keep the AI being responsive to the world. With 100 AIs in the world, there will be quite a few of these spikes overlapping. That's not even taking into account that I want these AIs to be quite intelligent, and this is the speed at the AI's most dumb.
The bottom graph shows the new AI speed. The 10ms spikes are the processing from the mouse event (there's one hidden behind the grey indicator line). The 4ms spikes are it pathfinding, and the rest is it moving around the world. For comparison, here's an image with the 3 graphs compared next to each other.
Notice that in the final 3rd of the graph, the spikes are all but invisible. compared to the other 2 graphs.
This is achieved by breaking ever command an AI can receive down into segments and then limiting how many of these can run each frame. For instance, if pathfinding from A to B and that distance is 10 tiles apart, we can now decide to process 4 tiles at a time. This means that we process the first 4 tiles and then pause. If there's still more time left this frame, we'll process the next 4. If there's no more time this frame, we'll wait until the next one. Next frame, we process the final 2 tiles to get our valid path and then pass that onto whatever process requested it. The aim being to make sure we're using as little time on AI processing, as efficiently as possible.
Next post will cover the automated testing I've been playing with using Unity's testing tools.