Jump to content
  • Advertisement
  • entries
  • comments
  • views

vortxGE : Threads

Sign in to follow this  


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 );}
Sign in to follow this  

1 Comment

Recommended Comments

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.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!