Daniel and I sat down this afternoon to try and kill that AI performance bug I mentioned in our last post - and I'm glad to report we fixed it. The game should run smoothly on a variety of hardware now.

You see, we have pretty powerful AI that was taxing on the performance of the game - it was dropping our frames down by like a factor of ten on MY computer (which is unacceptable!) so we had to sit down and work on it. We set up a control variable of 500 Artificial Intelligence's in one room, and ran the game.

Update 783 : 8.012ms
Physics step : 0.247ms
Update entities : 6.802ms
Update model attachments : 0.405ms
Update entity attachments : 0.531ms
Update hud : 0.021ms

Here is the initial data. As you can see, it takes almost 7 milliseconds to update the entities (which are all of the living creatures in the game), which is pretty bad considering our "budget" is around 2 milliseconds. The total update time was 8 milliseconds.

So after some tweaking and optimizing, we arrived at this data:

Update 1202 : 3.067ms
Physics step : 0.145ms
Update entities : 1.896ms
Update model attachments : 0.57ms
Update entity attachments : 0.427ms
Update hud : 0.023ms

We dropped it by more than half with some quick work - and now it's pretty acceptable. We did this by decreasing the amount of raycasting the AI was doing, and also optimizing their sensory systems and the physics engine to accommodate their large sensory radii (how far they can see and hear)

However, this still was no acceptable. We were still going over our 2 millisecond budget. So we decided to set precedence over certain thought processes of the AI's brain. For instancing, they should only consider sensory stimuli every tenth of a second, instead of 512 times per second.

So finally, we added this, and this was the final data:

Update 3296 : 2.441ms
Physics step : 0.172ms
Update entities : 1.26ms
Update model attachments : 0.511ms
Update entity attachments : 0.477ms
Update hud : 0.017ms

We dropped it by another 600 microseconds, and we're now in our budget range (atleast, pretty darn close!). Which is really cool. We dropped it by a factor of 3 times!

Sorry to ramble, but I had to share! Demo 5 Wednesday!