zoukankan      html  css  js  c++  java
  • cocos2d-x源码分析-----主循环(android)

    在前面的engine_draw_frame的函数中,可以看到每一帧都调用了cocos2d::Director::getInstance()->mainLoop()方法,接下来,去看些循环中具体做了什么

    void DisplayLinkDirector::mainLoop()
    {
        if (_purgeDirectorInNextLoop)
        {
            _purgeDirectorInNextLoop = false;
            purgeDirector();
        }
        else if (! _invalid)
        {
            drawScene();
         
            // release the objects
            PoolManager::sharedPoolManager()->pop();        
        }
    }

    当中,还做了一些矩阵的计算和变换。

    _purgeDirectorInNextLoop 注释已经写明了。// this flag will be set to true in end()  在结束时,会设为true,接下来是释放资源用的。

    重点在drawScene() 这个函数.

    // Draw the Scene
    void Director::drawScene()
    {
        //计算了每帧的时间差。
        calculateDeltaTime();
    
        if (_openGLView)
        {
            _openGLView->pollInputEvents();
        }
    
        //没有暂停的情况下,引用定时器
        if (! _paused)
        {
            _scheduler->update(_deltaTime);
            _eventDispatcher->dispatchEvent(_eventAfterUpdate);
        }
    
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        /* to avoid flickr, nextScene MUST be here: after tick and before draw.
         XXX: Which bug is this one. It seems that it can't be reproduced with v0.9 */
        if (_nextScene)
        {
            setNextScene();
        }
    
        kmGLPushMatrix();
        
        //construct the frustum
        {
            kmMat4 view;
            kmMat4 projection;
            kmGLGetMatrix(KM_GL_PROJECTION, &projection);
            kmGLGetMatrix(KM_GL_MODELVIEW, &view);
            
            _cullingFrustum->setupFromMatrix(view, projection);
        }
        
        // 绘制当前的场景
        if (_runningScene)
        {
            _runningScene->visit();
            _eventDispatcher->dispatchEvent(_eventAfterVisit);
        }
    
        // draw the notifications node
        if (_notificationNode)
        {
            _notificationNode->visit();
        }
        
    //是否显示帧数等一些信息
    if (_displayStats) { showStats(); } _renderer->render(); _eventDispatcher->dispatchEvent(_eventAfterDraw); kmGLPopMatrix(); _totalFrames++; // swap buffers if (_openGLView) { _openGLView->swapBuffers(); } if (_displayStats) { calculateMPF(); } }

    以上代码中,对_openGLView具体的作用不太了解,猜测是渲染使用的,接下来,要好好注意这个问题了。

  • 相关阅读:
    Delphi 与 VC 共享接口和对象
    Delphi线程类 DIY(把类指针作为参数传进去,就可以执行类里面的方法啦)
    delphi 在多线程中使用 CreateOleObject 导致失败(一定要使用CoInitialize和CoUninitialize,举例查询WMI)
    delphi调用LUA函数来处理一些逻辑
    后台管理系统
    .NET平台机器学习
    kafka
    一些技术视频资源
    异步
    CQRS(命令查询职责分离)和 EDA(事件驱动架构)
  • 原文地址:https://www.cnblogs.com/lihaibo19891007/p/3564331.html
Copyright © 2011-2022 走看看