예제 #1
0
/*!***************************************************************************
@function		main
@input			argc	count of args from OS
@input			argv	array of args from OS
@returns		result code to OS
@description	Main function of the program
*****************************************************************************/
int main(int argc, char **argv)
{
	PVRShellInit init;

	// Initialise the demo, process the command line, create the OS initialiser.
	if(!init.Init())
		return EXIT_ERR_CODE;

	init.CommandLine((argc-1),&argv[1]);

	// Initialise/run/shutdown
	while(init.Run());

	return EXIT_NOERR_CODE;
}
예제 #2
0
/*!***************************************************************************
@function		main
@input			argc	count of args from OS
@input			argv	array of args from OS
@returns		result code to OS
@description	Main function of the program
*****************************************************************************/
int main(int argc, char **argv)
{
	PVRShellInit init;

	/*
		Create the demo, process the command line, create the OS initialiser.
	*/
	PVRShell *pDemo = NewDemo();
	if(!pDemo)
		return EXIT_ERR_CODE;

	init.Init(*pDemo);
	init.CommandLine((argc-1),&argv[1]);

	/*
		Initialise/run/shutdown
	*/
	while(init.Run());

	delete pDemo;
	return EXIT_NOERR_CODE;
}
예제 #3
0
/*!***************************************************************************
@function		android_main
@input			state	the android app state
@description	Main function of the program
*****************************************************************************/
void android_main(struct android_app* state)
{
    // Make sure glue isn't stripped.
    app_dummy();

    // Initialise the demo, process the command line, create the OS initialiser.
    PVRShellInit init;

	{ // Handle command-line
		/*
		How to launch an app from an adb shell with command-line options, e.g. 
	
			am start -a android.intent.action.MAIN -n com.powervr.OGLESIntroducingPOD/.OGLESIntroducingPOD --es args "-info"
		*/
		ANativeActivity* activity = state->activity;
		
		JNIEnv *env;
		activity->vm->AttachCurrentThread(&env, 0);

		jobject me = activity->clazz;

		jclass acl = env->GetObjectClass(me); //class pointer of NativeActivity
		jmethodID giid = env->GetMethodID(acl, "getIntent", "()Landroid/content/Intent;");
		
		jobject intent = env->CallObjectMethod(me, giid); //Got our intent
		jclass icl = env->GetObjectClass(intent); //class pointer of Intent
		jmethodID gseid = env->GetMethodID(icl, "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
			
		jstring jsArgs = (jstring)env->CallObjectMethod(intent, gseid, env->NewStringUTF("args"));
		
		if (jsArgs != NULL)
        {
            const char * args = env->GetStringUTFChars(jsArgs, 0);
           
            init.CommandLine(args);

            // Tidy up the args string
            env->ReleaseStringUTFChars(jsArgs, args);
        }
		
		activity->vm->DetachCurrentThread();
	}
	
	// Setup our android state
	state->userData = &init;
	state->onAppCmd = handle_cmd;
	state->onInputEvent = handle_input;

	init.m_pAndroidState = state;
	g_AssetManager = state->activity->assetManager;

	if(!init.Init())
	{
		__android_log_print(ANDROID_LOG_INFO, "PVRShell", "Error: Failed to initialise");
		ANativeActivity_finish(state->activity);
		return;
	}

	// Call init app
	init.m_eState = ePVRShellInitApp;
	init.m_bError = !(init.Run() && init.m_eState == ePVRShellInitInstance);

	// Handle our events until we have a valid window or destroy has been requested
	int ident;
	int events;
    struct android_poll_source* source;

	//	Initialise our window/run/shutdown
	for(;;)
	{
		while ((ident = ALooper_pollAll((init.m_eState == ePVRShellRender && init.m_bRendering) ? 0 : -1, NULL, &events, (void**)&source)) >= 0)
		{
			if(init.m_bError)
			{
				ANativeActivity_finish(state->activity);
				
				// An error has occurred during setup. Execute the run loop till everything has been tidied up.
				while(init.Run()) { }

				init.m_bError = false;
			}

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

			// Check if we are exiting.
			if (state->destroyRequested != 0)
			{
				return;
			}
		}
		
		// Render our scene
		do
		{
			if(!init.Run())
			{
				ANativeActivity_finish(state->activity);
				break;
			}
		}
		while( init.m_eState != ePVRShellRender );
	}
}