vortxGE : Threads

Published March 11, 2013
Advertisement
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 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

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!
Profile
Author
Advertisement

Latest Entries

vortxGE : Threads

2338 views

C++11 Threads

3038 views

My Business

2193 views

Still Alive

2021 views

vortxEDIT : video

2135 views

vortxGE : Update

5985 views

vortxEDIT : Save

1894 views
Advertisement