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(); ...

Get Intel Threading Building Blocks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.