예제 #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
static void handle_cmd(struct android_app* app, int32_t cmd)
{
    PVRShellInit* init = (PVRShellInit*) app->userData;

    switch (cmd)
    {
		case APP_CMD_START:
			init->m_bRendering = true;
			break;
		case APP_CMD_RESUME:
			init->m_bRendering = true;
			break;
		case APP_CMD_PAUSE:
			init->m_bRendering = false;
			break;
        case APP_CMD_SAVE_STATE:
			// PVRShell doesn't support saving our state
			init->m_bRendering = false;
            break;
        case APP_CMD_INIT_WINDOW:
			// Call init view
			init->m_eState = ePVRShellInitInstance;
				
			init->m_bRendering = init->Run() && init->m_eState == ePVRShellRender;
			init->m_bError = !init->m_bRendering;
            break;

		case APP_CMD_WINDOW_RESIZED:
			// Unsupported by the shell
			break;
        case APP_CMD_TERM_WINDOW: // The window is being hidden or closed.
           	// Call release view
           	if(init->m_eState <= ePVRShellReleaseView)
           	{
				init->m_eState = ePVRShellReleaseView;
				init->Run();
			}

			init->m_bRendering = false;
            break;
        case APP_CMD_STOP:
        	init->m_bRendering = false;
            break;
        case APP_CMD_DESTROY:
        	init->Deinit();
        	break;
    }
}
예제 #3
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;
}
예제 #4
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 );
	}
}
예제 #5
0
/*****************************************************************************
 Global code
*****************************************************************************/
static int32_t handle_input(struct android_app* app, AInputEvent* event)
{
	PVRShellInit* init = (PVRShellInit*) app->userData;

	if(init)
	{
		switch(AInputEvent_getType(event))
		{
			case AINPUT_EVENT_TYPE_KEY: // Handle keyboard events
			{
				switch(AKeyEvent_getAction(event))
				{
					case AKEY_EVENT_ACTION_DOWN:
					{
						switch(AKeyEvent_getKeyCode(event))
						{
							case AKEYCODE_Q:			init->KeyPressed(PVRShellKeyNameQUIT);		break;
							case AKEYCODE_BACK:			init->KeyPressed(PVRShellKeyNameQUIT);		break;
							case AKEYCODE_DPAD_CENTER:	init->KeyPressed(PVRShellKeyNameSELECT);	break;
							case AKEYCODE_SPACE: 		init->KeyPressed(PVRShellKeyNameACTION1); 	break;
							case AKEYCODE_SHIFT_LEFT: 	init->KeyPressed(PVRShellKeyNameACTION2); 	break;
							case AKEYCODE_DPAD_UP: 		init->KeyPressed(init->m_eKeyMapUP); 		break;
							case AKEYCODE_DPAD_DOWN: 	init->KeyPressed(init->m_eKeyMapDOWN); 		break;
							case AKEYCODE_DPAD_LEFT: 	init->KeyPressed(init->m_eKeyMapLEFT);  	break;
							case AKEYCODE_DPAD_RIGHT: 	init->KeyPressed(init->m_eKeyMapRIGHT); 	break;
							case AKEYCODE_S: 			init->KeyPressed(PVRShellKeyNameScreenshot);break;
							default:
								break;
						}
					}
					return 1;

					default:
						break;
				}
				return 1;
			}
			case AINPUT_EVENT_TYPE_MOTION: // Handle touch events
			{
				switch(AMotionEvent_getAction(event))
				{
					case AMOTION_EVENT_ACTION_DOWN:
					{
						PVRShell *pShell = init->m_pShell;
						if(pShell)
						{
							float vec2TouchPosition[2] = { AMotionEvent_getX(event, 0) / pShell->PVRShellGet(prefWidth), AMotionEvent_getY(event, 0) / pShell->PVRShellGet(prefHeight) };
							init->TouchBegan(vec2TouchPosition);
						}
						break;
					}
					case AMOTION_EVENT_ACTION_MOVE:
					{
						PVRShell *pShell = init->m_pShell;

						if(pShell)
						{
							float vec2TouchPosition[2] = { AMotionEvent_getX(event, 0) / pShell->PVRShellGet(prefWidth), AMotionEvent_getY(event, 0) / pShell->PVRShellGet(prefHeight) };
							init->TouchMoved(vec2TouchPosition);
						}
						break;
					}
					case AMOTION_EVENT_ACTION_UP:
					{
						PVRShell *pShell = init->m_pShell;
						if(pShell)
						{
							float vec2TouchPosition[2] = { AMotionEvent_getX(event, 0) / pShell->PVRShellGet(prefWidth), AMotionEvent_getY(event, 0) / pShell->PVRShellGet(prefHeight) };
							init->TouchEnded(vec2TouchPosition);
						}
						break;
					}
				}
				return 1;
			}
		}
	}

    return 1;
}