cocos2dx ios入口类_cocos2dx 运行流程

1、入口函数main.cpp。

AppDelegate app; //初始化app,继承自Application的单例,不同test有不同的app。

return Application::getInstance()->run();

2、application。

int Application::run()

{

PVRFrameEnableControlWindow(false);

///

/// changing timer resolution

///

UINT TARGET_RESOLUTION = 1; // 1 millisecond target resolution

TIMECAPS tc;

UINT wTimerRes = 0;

if (TIMERR_NOERROR == timeGetDevCaps(&tc, sizeof(TIMECAPS)))

{

wTimerRes = std::min(std::max(tc.wPeriodMin, TARGET_RESOLUTION), tc.wPeriodMax);

timeBeginPeriod(wTimerRes);

}

// Main message loop:

LARGE_INTEGER nLast;

LARGE_INTEGER nNow;

QueryPerformanceCounter(&nLast); //windows获取精准时间。

initGLContextAttrs(); //初始化openGL的上下文环境

// Initialize instance and cocos2d.

if (!applicationDidFinishLaunching()) //重要的初始化。

{

return 1;

}

auto director = Director::getInstance();

auto glview = director->getOpenGLView();

// Retain glview to avoid glview being released in the while loop

glview->retain();

LONGLONG interval = 0LL;

LONG waitMS = 0L;

LARGE_INTEGER freq;

QueryPerformanceFrequency(&freq); //windows精准计时频率。

while(!glview->windowShouldClose()) //循环

{

QueryPerformanceCounter(&nNow);

interval = nNow.QuadPart - nLast.QuadPart; //每次循环的间隔

if (interval >= _animationInterval.QuadPart) //这次循环间隔大于等于设置的时间间隔

{

nLast.QuadPart = nNow.QuadPart;

director->mainLoop(); // 导演类的主循环

glview->pollEvents();

}

else //否则刷空或者等待一会

{

// The precision of timer on Windows is set to highest (1ms) by 'timeBeginPeriod' from above code,

// but it's still not precise enough. For example, if the precision of timer is 1ms,

// Sleep(3) may make a sleep of 2ms or 4ms. Therefore, we subtract 1ms here to make Sleep time shorter.

// If 'waitMS' is equal or less than 1ms, don't sleep and run into next loop to

// boost CPU to next frame accurately.

waitMS = (_animationInterval.QuadPart - interval) * 1000LL / freq.QuadPart - 1L;

// 比预设的刷的快多了<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值