cocos2D-X源码分析之从cocos2D-X学习OpenGL----cocos2D-X渲染结构


void DisplayLinkDirector::mainLoop()
{
// 这个标志在调用end()方法会设置为true
    if (_purgeDirectorInNextLoop)
    {
<span style="font-family:Consolas, Courier New, Courier, mono, serif;"><span style="line-height: 18px;">//只有一种情况会调用到这里来,就是导演类调用end函数</span></span>
        _purgeDirectorInNextLoop = false;
        purgeDirector();
    }
//<span style="font-family: Arial, Helvetica, sans-serif;">startAnimation 设置为false, </span><span style="font-family: Arial, Helvetica, sans-serif;">stopAnimation 设置为 true</span><span style="font-family: Arial, Helvetica, sans-serif;">
</span>    else if (! _invalid)
    {
        drawScene();
     
        // release the objects
        PoolManager::getInstance()->getCurrentPool()->clear();
    }
}//


void DisplayLinkDirector::stopAnimation()
{
    _invalid = true;
}

// should we implement 4 types of director ??
// I think DisplayLinkDirector is enough
// so we now only support DisplayLinkDirector
void DisplayLinkDirector::startAnimation()
{
    if (gettimeofday(_lastUpdate, nullptr) != 0)
    {
        CCLOG("cocos2d: DisplayLinkDirector: Error on gettimeofday");
    }

    _invalid = false;

    Application::getInstance()->setAnimationInterval(_animationInterval);
    
    // fix issue #3509, skip one fps to avoid incorrect time calculation.
    setNextDeltaTimeZero(true);
}



// Draw the Scene
void Director::drawScene()
{
    // calculate "global" dt
    calculateDeltaTime();
    
    // skip one flame when _deltaTime equal to zero.
    if(_deltaTime < FLT_EPSILON)
    {
        return;
    }

    if (_openGLView)
    {
        _openGLView->pollInputEvents();
    }

    //tick before glClear: issue #533
    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();
    }

    pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);

    // draw the scene
    if (_runningScene)
    {
        _runningScene->visit(_renderer, Mat4::IDENTITY, false);
        _eventDispatcher->dispatchEvent(_eventAfterVisit);
    }

    // draw the notifications node
    if (_notificationNode)
    {
        _notificationNode->visit(_renderer, Mat4::IDENTITY, false);
    }

    if (_displayStats)
    {
        showStats();
    }

    _renderer->render();
    _eventDispatcher->dispatchEvent(_eventAfterDraw);

    popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);

    _totalFrames++;

    // swap buffers
    if (_openGLView)
    {
        _openGLView->swapBuffers();
    }

    if (_displayStats)
    {
        calculateMPF();
    }
}


void Director::calculateDeltaTime()
{
//大概是表示时间struct
    struct timeval now;
//使用C语言编写程序需要获得当前精确时间(1970年1月1日到现在的时间)
//<span style="font-family: Arial, Helvetica, sans-serif;">其参数</span><span style="font-family: Arial, Helvetica, sans-serif;">now</span><span style="font-family: Arial, Helvetica, sans-serif;">是保存获取时间结果的结构体,第二个参数用于保存时区结果:可以传null</span><span style="font-family: Arial, Helvetica, sans-serif;">
</span>    if (gettimeofday(&now, nullptr) != 0)
    {
        CCLOG("error in gettimeofday");
//记录 自mainloop上次tick过去了多少时间
        _deltaTime = 0;
        return;
    }

    // new delta time. Re-fixed issue #1277
//是否下一个增量时间(<span style="font-family: Arial, Helvetica, sans-serif;">_deltaTime</span><span style="font-family: Arial, Helvetica, sans-serif;">)将是零</span>
    if (_nextDeltaTimeZero)
    {
        _deltaTime = 0;
        _nextDeltaTimeZero = false;
    }
    else
    {
//计算过去了的时间,后面的微秒 <span style="font-family: Arial, Helvetica, sans-serif;">/ 1000000.0f</span>
        _deltaTime = (now.tv_sec - _lastUpdate->tv_sec) + (now.tv_usec - _lastUpdate->tv_usec) / 1000000.0f;
        _deltaTime = MAX(0, _deltaTime);
    }

#if COCOS2D_DEBUG
    // If we are debugging our code, prevent big delta time
    if (_deltaTime > 0.2f)
    {
        _deltaTime = 1 / 60.0f;
    }
#endif
//最后一次更新的时间
    *_lastUpdate = now;
}



摘自于百度 http://baike.baidu.com/view/2982901.htm?fr=aladdin

#include <sys/time.h>
int gettimeofday(struct timeval*tv, struct timezone *tz);
其参数tv是保存获取时间结果的结构体,参数tz用于保存时区结果:
struct timezone{
   int tz_minuteswest;/*格林威治时间往西方的时差*/
   int tz_dsttime;/*DST 时间的修正方式*/
}
timezone 参数若不使用则传入NULL即可。
而结构体timeval的定义为:
struct timeval{
  long int tv_sec; // 秒数
  long int tv_usec; // 微秒数
}
它获得的时间精确到微秒(1e-6 s)量级。在一段代码前后分别使用gettimeofday可以计算代码执行时间:
struct timeval tv_begin, tv_end;
  gettimeofday(&tv_begin, NULL);
foo();
  gettimeofday(&tv_end, NULL);










  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的体育馆管理系统,源码+数据库+毕业论文+视频演示 现代经济快节奏发展以及不断完善升级的信息化技术,让传统数据信息的管理升级为软件存储,归纳,集中处理数据信息的管理方式。本体育馆管理系统就是在这样的大环境下诞生,其可以帮助管理者在短时间内处理完毕庞大的数据信息,使用这种软件工具可以帮助管理人员提高事务处理效率,达到事半功倍的效果。此体育馆管理系统利用当下成熟完善的SpringBoot框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的Mysql数据库进行程序开发。实现了用户在线选择试题并完成答题,在线查看考核分数。管理员管理收货地址管理、购物车管理、场地管理、场地订单管理、字典管理、赛事管理、赛事收藏管理、赛事评价管理、赛事订单管理、商品管理、商品收藏管理、商品评价管理、商品订单管理、用户管理、管理员管理等功能。体育馆管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 关键词:体育馆管理系统;SpringBoot框架;Mysql;自动化
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值