vortxGE : Threads

Published March 11, 2013
After reading lots of tech papers/blogs on C++11 threads I redesigned the way the engine handles threading.

Developers can now change threads manually per Scene, each pipeline : Move, Optimise are now batch threaded for better performance. after lots of testing this approch seems to work better under heavy load and being scalable its my new method of choice.

Here is some code from the engine that creates threads based on nodes.void lsNode::MoveThread( lsScene* scn, lsOpenGL* opengl, double delta ){#ifdef VORTX_DEBUG_NODES cout << "lsNode::MoveThred() ********************************" << endl;#endif vector<thread> th; lsNode *ptr; int threads = 1; int tc = 0; // Threads if( scn ) { threads = scn->getThreads(); } else { threads = thread::hardware_concurrency() * 2; } // cycle through child and its next nodes ptr = getNode_list(); while( ptr ) { // Add thread th.push_back( thread( &lsNode::Move, ptr, scn, opengl, delta ) ); tc++; // check our thread count if(( tc >= threads )||( ptr->getNext_node() == NULL )) {#ifdef VORTX_DEBUG_NODETHREADS // debug cout << "lsNode::MoveThread - Thread count : " << tc << endl;#endif // Join and wait for( auto &t : th ) { t.join(); } // clean up th.clear(); tc = 0; } ptr = ptr->getNext_node(); } // pass it on if( getNode_list() ) getNode_list()->MoveThread( scn, opengl, delta ); if( getNext_node() ) getNext_node()->MoveThread( scn, opengl, delta );}
Previous Entry C++11 Threads
0 likes 1 comments

Comments

Comments are shown oldest first so the discussion reads top to bottom.
mixmaster

I should also add I have my event system working with the new threads. All core events are on a scene by scene basis, e.g. if a scene node wants to delete itself because its life is over, it must add an event to do so. Game events will work on a Level basis.

March 12, 2013 12:19 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!

Latest Entries

vortxGE : Threads

2985 views

C++11 Threads

3669 views

My Business

2769 views

Still Alive

2600 views

vortxEDIT : video

2729 views

vortxGE : Update

6556 views

vortxEDIT : Save

2446 views