Jump to content

  • Log In with Google      Sign In   
  • Create Account






vortxGE : Threads

Posted by Lee A. Stripp, 11 March 2013 · 451 views

Threads C++11 vortxGE
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 );
}






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.

July 2014 »

S M T W T F S
  12345
6789101112
13 14 1516171819
20212223242526
2728293031  

Recent Comments

PARTNERS