cocos3——1.引擎运行流程

cocos3——1.引擎运行流程,第1张

概述1.程序入口 // create the application instance AppDelegate app; return Application::getInstance()->run();2.主循环   int Application::run(): while(!glview->windowShouldClose()) { QueryP

1.程序入口

    // create the application instance    AppDelegate app;    return Application::getInstance()->run();
2.主循环
int Application::run():
while(!glvIEw->windowshouldClose())    {        queryPerformanceCounter(&nNow);        if (nNow.QuadPart - nLast.QuadPart > _animationInterval.QuadPart)        {            nLast.QuadPart = nNow.QuadPart;            			// 导演的主循环            director->mainLoop();            glvIEw->pollEvents();        }        else        {            Sleep(0);        }    }
mainLoop->drawScene:
    pushmatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);        if (_runningScene)    {        //clear draw stats        _renderer->clearDrawStats();        		// visit和draw场景(但draw只是添加渲染命令)		// 进行渲染命令是在:renderer->render();        //render the scene        _runningScene->render(_renderer);                _eventdispatcher->dispatchEvent(_eventAfterVisit);    }	// 通知节点,独立于场景之后渲染    // draw the notifications node    if (_notificationNode)    {        _notificationNode->visit(_renderer,Mat4::IDENTITY,0);    }    if (_displayStats)    {        showStats();    }	// 下面是渲染_notificationNode和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,0);        renderer->render();                director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);

3.节点遍历

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,flags);        for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)            (*it)->visit(renderer,flags);    }    else if (visibleByCamera)    {        this->draw(renderer,flags);    }    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
总结

以上是内存溢出为你收集整理的cocos3——1.引擎运行流程全部内容,希望文章能够帮你解决cocos3——1.引擎运行流程所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1017925.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存