Sponsored By

Sponsored Feature: Two Brains Are Better Than One -- How to Thread Game AI 2

This Intel-sponsored feature, part of <a href="http://www.gamasutra.com/visualcomputing">Gamasutra's Visual Computing section</a>, presents a practical look at <a href="http://www.gamasutra.com/view/feature/4073/sponsored_feature_two_brains_are_.php">how

July 10, 2009

2 Min Read

Author: by Staff

In this Intel-sponsored feature, part of Gamasutra's Visual Computing section, game programming veteran Orion Granatir presents a practical look at how to use multi-core CPUs to thread game elements, in this case artificial intelligence (AI) for your game. Whether discussing complex pathfinding systems or simple scripting engines, AI drives gameplay -- and to maximize AI's potential, it needs threading in order to utilize the entire CPU. As Granatir explains in the technical article's introduction: "The concepts described in this article were used in the creation of the multithreaded AI of Intel's Smoke demo. This demo showcases functional and data decomposition with multiple game technologies, including physics, audio, and AI. The source code is free to download at Whatif.intel.com." Granatir offers illustrated examples of a sample AI, and then defines challenges of threading its code: "For our simple AI, we need the collision and the move system to be thread safe. We could put locks around any access to these systems, but we'll see lower performance because threads will have to block and wait for each other. The solution for collision and pathfinding are similar, so let's focus on collision. For the collision system we will have multiple requests in parallel. For multiple readers, the collision data is just fine. This is no different from the serial case because the data is not changing. When someone starts writing data, then we have work to do. Data access to be protected (with locks) or the data has to be double buffered. If the data is double buffered, the readers can just access the data from the last frame and not worry about the writes until the next frame. We can run collision independent of AI three ways: issue early and use late, deferred requests, and task stealing. Each is worth a bit of investigation." The full Gamasutra sponsored feature goes into greater depth on the multithreaded AI concepts used in Intel's Smoke demo.

Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like