Cocos3--1. Engine Run Flow

Source: Internet
Author: User

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;            Director of the main circulation            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 scene (but draw just add render command)//Render command is in: Renderer->render ();        Render the scene        _runningscene->render (_renderer);                _eventdispatcher->dispatchevent (_eventaftervisit);    } Notification node, rendered independently of the scene    //Draw the Notifications node    if (_notificationnode)    {        _notificationnode-> Visit (_renderer, mat4::identity, 0);    }    if (_displaystats)    {        showstats ();    } Below are the rendered _notificationnode 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,//It's deprecated and your co    De 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);







Cocos3--1. Engine Run Flow

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.