Cocos3 -- 1. Engine running process

Source: Internet
Author: User

Cocos3 -- 1. Engine running process

1. program entry

    // create the application instance    AppDelegate app;    return Application::getInstance()->run();
2. Main Loop
Int Application: run ():

While (! Glview-> windowShouldClose () {QueryPerformanceCounter (& nNow); if (nNow. quadPart-nLast. quadPart> _ animationInterval. quadPart) {nLast. quadPart = nNow. quadPart; // The director's main cycle director-> mainLoop (); glview-> pollEvents ();} else {Sleep (0 );}}
MainLoop-> drawScene:

PushMatrix (MATRIX_STACK_TYPE: MATRIX_STACK_MODELVIEW); if (_ runningScene) {// clear draw stats _ renderer-> clearDrawStats (); // visit and draw scenarios (but draw only adds the rendering command) // The rendering command is in: renderer-> render (); // render the scene _ runningScene-> render (_ renderer); _ eventDispatcher-> dispatchEvent (_ eventAfterVisit);} // notification node, rendering independently of the scenario // draw the events node if (_ icationicationnode) {_ notificationNode-> visit (_ renderer, Mat4: IDENTITY, 0);} if (_ displayStats) {showStats () ;}// the following render _ icationicationnode and stats _ renderer-> render (); _ eventDispatcher-> dispatchEvent (_ eventAfterDraw); popMatrix (MATRIX_STACK_TYPE :: MATRIX_STACK_MODELVIEW); _ totalFrames ++; // swap buffers if (_ openGLView) {_ openGLView-> swapBuffers ();}

Void Scene: render (Renderer * renderer ):

        Camera::_visitingCamera = defaultCamera;        director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);        director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, Camera::_visitingCamera->getViewProjectionMatrix());                //visit the scene        visit(renderer, Mat4::IDENTITY, 0);        renderer->render();                director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);

3. node Traversal

Void Node: visit (Renderer * renderer, const Mat4 & parentTransform, uint32_t parentFlags ):

    // quick return if not visible. children won't be drawn.    if (!_visible)    {        return;    }    uint32_t flags = processParentFlags(parentTransform, parentFlags);    // IMPORTANT:    // To ease the migration to v3.0, we still support the Mat4 stack,    // but it is deprecated and your code should not rely on it    Director* director = Director::getInstance();    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);        bool visibleByCamera = isVisitableByVisitingCamera();    int i = 0;    if(!_children.empty())    {        sortAllChildren();        // draw children zOrder < 0        for( ; i < _children.size(); i++ )        {            auto node = _children.at(i);            if ( node && node->_localZOrder < 0 )                node->visit(renderer, _modelViewTransform, flags);            else                break;        }        // self draw        if (visibleByCamera)            this->draw(renderer, _modelViewTransform, flags);        for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)            (*it)->visit(renderer, _modelViewTransform, flags);    }    else if (visibleByCamera)    {        this->draw(renderer, _modelViewTransform, flags);    }    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.