O'Reilly logo

Intel Threading Building Blocks by James Reinders

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Physics Interaction and Update Code

The source code for the physics interaction (Example 11-54 and Example 11-55) and update (Example 11-56) are presented here for you to study. You can download the complete source code from http://www.threadingbuildingblocks.org/book. Look for errata and notes at this web site as well.

For more in-depth reading on this topic, Intel engineers wrote several articles covering the topic of threading games, which you can download at the web site as well.

Example 11-54. Physics interaction code: InteractTask

class InteractTask : public tbb::task { SceneNode* m_node; size_t m_i; D3DBlackHole* m_bh; float m_universeRadius; size_t m_DummyCount; public: // Interact all stars in task InteractTask(SceneNode* node, size_t i, D3DBlackHole* bh, float universeRadius, size_t DummyCount) : m_node(node), m_i(i), m_bh(bh), m_universeRadius(universeRadius), m_DummyCount(DummyCount) {} tbb::task* execute() { if (m_node->getChildCount()) { // High in scene graph, Create parallel domain tasks for the children size_t i; tbb::task_list list; tbb::task& c = *new(allocate_continuation()) tbb::empty_task(); for (i = 0; i < m_node->getChildCount(); ++i) { list.push_back(*new(c.allocate_child()) InteractTask(m_node->getChild(i), i, m_bh, m_universeRadius, m_DummyCount)); } c.set_ref_count((int)i); c.spawn(list); } if (m_node->getUserID() > 0) { // Low-level object tasks, interact each star serially D3DStar* pStar = (D3DStar*)m_node; float elapsedTime = g_elapsedTime - pStar->getTimeStamp(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required