zoukankan      html  css  js  c++  java
  • cocos2d-x源码分析-----入口分析(android)

    版本:cocos2d-x 3.0 Beta

    分析的是android部分的源码

    在cocos2d-x自动生成的android部分,下jni目录,main.cpp是java调用的部分,代码如下 

    void cocos_android_app_init (struct android_app* app) {
    LOGD("cocos_android_app_init");
    AppDelegate *pAppDelegate = new AppDelegate();
    }

    在这个版本中,android部分使用了nativeActivity

    在cocos2dplatformandroid目录下,有nativeactivity.cpp文件,进行了初使化

    static void cocos_init(cocos_dimensions d, struct android_app* app) {
        LOGI("cocos_init(...)");
        pthread_t thisthread = pthread_self();
        LOGI("pthread_self() = %X", thisthread);
    
        cocos2d::FileUtilsAndroid::setassetmanager(app->activity->assetManager);
    
        if (!cocos2d::Director::getInstance()->getOpenGLView())
        {
            cocos2d::EGLView *view = cocos2d::EGLView::getInstance();
            view->setFrameSize(d.w, d.h);
    
            cocos_android_app_init(app);
    
            cocos2d::Application::getInstance()->run();
        }
        else
        {
            cocos2d::GL::invalidateStateCache();
            cocos2d::ShaderCache::getInstance()->reloadDefaultShaders();
            cocos2d::DrawPrimitives::init();
            cocos2d::VolatileTextureMgr::reloadAllTextures();
            cocos2d::EventCustom foregroundEvent(EVENT_COME_TO_FOREGROUND);
            cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&foregroundEvent);
            cocos2d::Director::getInstance()->setGLDefaultValues(); 
        }
    }
    cocos2d::Application::getInstance()->run();
    就调用了开发者的代码,游戏就运行起来了,在
    engine_draw_frame中,调用了cocos2d::Director::getInstance()->mainLoop();
    static void engine_draw_frame(struct engine* engine) {
        LOG_RENDER_DEBUG("engine_draw_frame(...)");
        pthread_t thisthread = pthread_self();
        LOG_RENDER_DEBUG("pthread_self() = %X", thisthread);
    
        if (engine->display == NULL) {
            // No display.
            LOGW("engine_draw_frame : No display.");
            return;
        }
    
        dispatch_pending_runnables();
        cocos2d::Director::getInstance()->mainLoop();
        LOG_RENDER_DEBUG("engine_draw_frame : just called cocos' mainLoop()");
    
        /* // Just fill the screen with a color. */
        /* glClearColor(((float)engine->state.x)/engine->width, engine->state.angle, */
        /*         ((float)engine->state.y)/engine->height, 1); */
        /* glClear(GL_COLOR_BUFFER_BIT); */    
        
        if (s_pfEditTextCallback && editboxText)
        {
            s_pfEditTextCallback(editboxText, s_ctx);
            free(editboxText);
            editboxText = NULL;
        }    
    
        eglSwapBuffers(engine->display, engine->surface);
    }
    
    
  • 相关阅读:
    eclipse安装pydev
    pymongo常见的高级用法
    android sdk下载SDK Platform失败记录
    centos7 yum安装redis(转)
    centos7 将服务添加到systemctl
    python Parent.__init()和super(Child, self)的区别
    流畅的python第二十章属性描述符学习记录
    流畅的python第十九章元编程学习记录
    python 协程的学习记录
    [转]Shell脚本之无限循环的两种方法
  • 原文地址:https://www.cnblogs.com/lihaibo19891007/p/3558771.html
Copyright © 2011-2022 走看看