Пример #1
0
/**
 * This is the main entry point of a native application that is using
 * android_native_app_glue.  It runs in its own thread, with its own
 * event loop for receiving input events and doing other things.
 */
void android_main(struct android_app* app)
{
    // Make sure glue isn't stripped.
    app_dummy();

// 	NvEGLUtil* egl = NvEGLUtil::create();
//     if (!egl) 
//     {
//         // if we have a basic EGL failure, we need to exit immediately; nothing else we can do
//         nv_app_force_quit_no_cleanup(app);
//         return;
//     }

	void* gHandle;
	LOAD_MODULE_GLOBAL( gHandle, gkGameFramework );

	//= dlopen("/data/data/com.kkstudio.gklauncher/lib/libgkGameFrame.so", RTLD_LAZY |RTLD_GLOBAL );
	OsDisplayDebugString( "libloaded..." );
	if(gHandle)
	{ 
		STARTFUNC moduleInitialize = (STARTFUNC)(DLL_GETSYM(gHandle, "gkModuleInitialize"));
		if( moduleInitialize )
		{
			gGameFramework = moduleInitialize();
		}
		else
		{
			return;
		}
	}
	else
	{
		OsDisplayDebugString( "gkFramework not find..." );
	}

	OsDisplayDebugString( "system initialized..." );

    //Engine* engine = new Engine(*egl, app);

	//long lastTime = egl->getSystemTime();

    // loop waiting for stuff to do.

	OsDisplayDebugString( "system initialized..." );
	// Setup our android state
	//state->userData = &init;

	app->onAppCmd = handle_cmd;
	app->onInputEvent = handle_input;

	while (nv_app_status_running(app))
    {
        // Read all pending events.
        int ident;
        int events;
        struct android_poll_source* source;

        // If not rendering, we will block 250ms waiting for events.
        // If animating, we loop until all events are read, then continue
        // to draw the next frame of animation.
        while ((ident = ALooper_pollAll(((nv_app_status_focused(app)/* && engine->isGameplayMode()*/) ? 1 : 250),
        								NULL,
        								&events,
        								(void**)&source)) >= 0)
        {
            // Process this event. 
            if (source != NULL)
                source->process(app, source);

            // Check if we are exiting.  If so, dump out
            if (!nv_app_status_running(app))
				break;
        }

		if (gIntialized)
		{
			gGameFramework->Update();
		}

		if (exit_req)
		{
			break;
		}

// 		long currentTime = egl->getSystemTime();
// 
// 		// clamp time - it must not go backwards, and we don't
// 		// want it to be more than a half second to avoid huge
// 		// delays causing issues.  Note that we do not clamp to above
// 		// zero because some tools will give us zero delta
// 		long deltaTime = currentTime - lastTime;
// 		if (deltaTime < 0)
// 			deltaTime = 0;
// 		else if (deltaTime > 500)
// 			deltaTime = 500;
// 
// 		lastTime = currentTime;

		// Update the frame, which optionally updates time and animations
		// and renders
		//engine->updateFrame(nv_app_status_interactable(app), deltaTime);
    }

	//delete engine;
    //delete egl;
}
Пример #2
0
/**
 * This is the main entry point of a native application that is using
 * android_native_app_glue.  It runs in its own thread, with its own
 * event loop for receiving input events and doing other things.
 */
void android_main(struct android_app* app)
{
    // Make sure glue isn't stripped.
    app_dummy();

	NvEGLUtil* egl = NvEGLUtil::create();
    if (!egl) 
    {
        // if we have a basic EGL failure, we need to exit immediately; nothing else we can do
        nv_app_force_quit_no_cleanup(app);
        return;
    }

    Engine* engine = new Engine(*egl, app);

	long lastTime = egl->getSystemTime();

    // loop waiting for stuff to do.

	while (nv_app_status_running(app))
    {
        // Read all pending events.
        int ident;
        int events;
        struct android_poll_source* source;

        // If not rendering, we will block forever waiting for events.
        // If animating, we loop until all events are read, then continue
        // to draw the next frame of animation.
        while ((ident = ALooper_pollAll(((nv_app_status_focused(app) &&
										  engine->isGameplayMode()) ? 1 : 250),
        								NULL,
        								&events,
        								(void**)&source)) >= 0)
        {
			// If we timed out, then there are no pending messages
			if (ident == ALOOPER_POLL_TIMEOUT)
				break;

            // Process this event. 
            if (source != NULL)
                source->process(app, source);

            // Check if we are exiting.  If so, dump out
            if (!nv_app_status_running(app))
				break;

			engine->looperIteration(ident);
        }

		long currentTime = egl->getSystemTime();

		// clamp time - it must not go backwards, and we don't
		// want it to be more than a half second to avoid huge
		// delays causing issues.  Note that we do not clamp to above
		// zero because some tools will give us zero delta
		long deltaTime = currentTime - lastTime;
		if (deltaTime < 0)
			deltaTime = 0;
		else if (deltaTime > 500)
			deltaTime = 500;

		lastTime = currentTime;

		// Update the frame, which optionally updates time and animations
		// and renders
		engine->updateFrame(nv_app_status_interactable(app), deltaTime);
    }

	delete engine;
    delete egl;
}