Exemplo n.º 1
0
// Start up the SDL app
extern "C" void Java_org_hedgewars_hedgeroid_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobjectArray strArray)
{
    /* This interface could expand with ABI negotiation, calbacks, etc. */
    SDL_Android_Init(env, cls);

    //Get the String array from java
    int argc = env->GetArrayLength(strArray);
    char *argv[argc];
    jstring jstringArgv[argc];
    for(int i = 0; i < argc; i++){
		jstringArgv[i] = (jstring)env->GetObjectArrayElement(strArray, i);  //get the element
		argv[i] = (char*)malloc(env->GetStringUTFLength(jstringArgv[i]) + 1);
		const char *str = env->GetStringUTFChars(jstringArgv[i], NULL);
		strcpy(argv[i], str); //copy it to a mutable location
        env->ReleaseStringUTFChars(jstringArgv[i], str);           
    }
    
    /* Run the application code! */
    int status = SDL_main(argc, argv);

    //Clean up argv
    for(int i = 0; i < argc; i++){
		free(argv[i]);
    }
}
// Start up the SDL app
extern "C" void Java_uk_co_armedpineapple_cth_SDLActivity_nativeInit(
		JNIEnv* env, jclass cls, jstring jni_log_path,
		jstring jni_loadgame_path) {

	const char *log_path = env->GetStringUTFChars(jni_log_path, 0);
	const char* loadgame_path = env->GetStringUTFChars(jni_loadgame_path, 0);

	/* This interface could expand with ABI negotiation, callbacks, etc. */
	SDL_Android_Init(env, cls);

	/* Run the application code! */
	int status;
	char *argv[3];
	int argc = 1;
	argv[0] = strdup("SDL_app");
	if (strlen(loadgame_path) > 1) {
		char* loadstr = (char*) malloc((8 + strlen(loadgame_path)) * sizeof(char));
		strcpy(loadstr, "--load=");
		loadstr = strcat(loadstr, loadgame_path);
		argv[1] = loadstr;
		argc = 2;
	}



	status = SDL_main(argc, argv, jvm, log_path);

	/* We exit here for consistency with other platforms. */
	exit(status);
}
Exemplo n.º 3
0
    /* Start up the SDL app */
    int Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobject array)
    {
        int i;
        int argc;
        int status;

        /* This interface could expand with ABI negotiation, callbacks, etc. */
        SDL_Android_Init(env, cls);

        JavaVM *jvm;
        env->GetJavaVM(&jvm);

        loom_set_javavm((void *) jvm);

        SDL_SetMainReady();

        /* Prepare the arguments. */

        int len = env->GetArrayLength(static_cast<jarray>(array));
        char* argv[1 + len + 1];
        argc = 0;
        /* Use the name "app_process" so PHYSFS_platformCalcBaseDir() works.
        https://bitbucket.org/MartinFelis/love-android-sdl2/issue/23/release-build-crash-on-start
        */
        argv[argc++] = SDL_strdup("app_process");
        for (i = 0; i < len; ++i) {
            const char* utf;
            char* arg = NULL;
            jstring string = static_cast<jstring>(env->GetObjectArrayElement(static_cast<jobjectArray>(array), i));
            if (string) {
                utf = env->GetStringUTFChars(string, 0);
                if (utf) {
                    arg = SDL_strdup(utf);
                    env->ReleaseStringUTFChars(string, utf);
                }
                env->DeleteLocalRef(string);
            }
            if (!arg) {
                arg = SDL_strdup("");
            }
            argv[argc++] = arg;
        }
        argv[argc] = NULL;


        /* Run the application. */

        status = SDL_main(argc, argv);

        /* Release the arguments. */

        for (i = 0; i < argc; ++i) {
            SDL_free(argv[i]);
        }

        /* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
        /* exit(status); */

        return status;
    }
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
	pspDebugScreenInit();
	sdl_psp_setup_callbacks();

	/* Register sceKernelExitGame() to be called when we exit */
	atexit(sceKernelExitGame);

	(void)SDL_main(argc, argv);
	return 0;
}
Exemplo n.º 5
0
int main(int argc, char **argv) {

	int		r;

	__sdl_videoinit();
	if (sdlinit() != SUCCESS) {
		return(0);
	}
	r = SDL_main(argc, argv);
	sdlterm();
	return(r);
}
Exemplo n.º 6
0
//Start up the SDL app
extern "C" void Java_org_libsdl_app_SDLActivity_nativeInit( JNIEnv* env, 
                                                                jobject obj ){ 
                                                                   
	__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: Native Init");

	mEnv = env;
	bRenderingEnabled = true;

	Android_EnableFeature(FEATURE_ACCEL, true);

    SDL_main();
}
Exemplo n.º 7
0
int
nacl_main(int argc, char *argv[])
{
    int status;
    PSEvent* ps_event;
    PP_Resource event;  
    struct PP_Rect rect;
    int ready = 0;
    const PPB_View *ppb_view = PSInterfaceView();
    
    /* This is started in a worker thread by ppapi_simple! */
    
    /* Wait for the first PSE_INSTANCE_DIDCHANGEVIEW event before starting the app */
    
    PSEventSetFilter(PSE_INSTANCE_DIDCHANGEVIEW);
    while (!ready) {
        /* Process all waiting events without blocking */
        while (!ready && (ps_event = PSEventWaitAcquire()) != NULL) {
            event = ps_event->as_resource;
            switch(ps_event->type) {
                /* From DidChangeView, contains a view resource */
                case PSE_INSTANCE_DIDCHANGEVIEW:
                    ppb_view->GetRect(event, &rect);
                    NACL_SetScreenResolution(rect.size.width, rect.size.height, 0);
                    ready = 1;
                    break;
                default:
                    break;
            }
            PSEventRelease(ps_event);
        }
    }
    
    /* Do a default httpfs mount on /, 
     * apps can override this by unmounting / 
     * and remounting with the desired configuration
     */
    nacl_io_init_ppapi(PSGetInstanceId(), PSGetInterface);
    
    umount("/");
    mount(
        "",  /* source */
        "/",  /* target */
        "httpfs",  /* filesystemtype */
        0,  /* mountflags */
        "");  /* data specific to the html5fs type */
    
    /* Everything is ready, start the user main function */
    SDL_SetMainReady();
    status = SDL_main(argc, argv);

    return 0;
}
Exemplo n.º 8
0
/* Start up the SDL app */
JNIEXPORT int JNICALL Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobject array, jstring filesDir)
{
    int i;
    int argc;
    int status;

    /* This interface could expand with ABI negotiation, callbacks, etc. */
    SDL_Android_Init(env, cls, filesDir);

    SDL_SetMainReady();

    /* Prepare the arguments. */

    int len = (*env)->GetArrayLength(env, array);
    char* argv[len + 1];
    argc = 0;
    // Urho3D: avoid hard-coding the "app_process" as the first argument
    for (i = 0; i < len; ++i) {
        const char* utf;
        char* arg = NULL;
        jstring string = (*env)->GetObjectArrayElement(env, array, i);
        if (string) {
            utf = (*env)->GetStringUTFChars(env, string, 0);
            if (utf) {
                arg = SDL_strdup(utf);
                (*env)->ReleaseStringUTFChars(env, string, utf);
            }
            (*env)->DeleteLocalRef(env, string);
        }
        if (!arg) {
            arg = SDL_strdup("");
        }
        argv[argc++] = arg;
    }
    argv[argc] = NULL;


    /* Run the application. */

    status = SDL_main(argc, argv);

    /* Release the arguments. */

    for (i = 0; i < argc; ++i) {
        SDL_free(argv[i]);
    }

    /* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
    /* exit(status); */

    return status;
}
Exemplo n.º 9
0
extern "C" void Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env,
    jclass cls, jobject obj)
{
  SDL_Android_Init(env, cls);

  int status;
  char* argv[2];
  argv[0] = strdup("Lethe");
  argv[1] = NULL;
  status = SDL_main(1, argv);

  exit(status);
}
Exemplo n.º 10
0
/* This is where execution begins [console apps] */
int
console_main(int argc, char *argv[])
{
    int status;

    /* Run the application main() code */
    status = SDL_main(argc, argv);

    /* Exit cleanly, calling atexit() functions */
    exit(status);

    /* Hush little compiler, don't you cry... */
    return 0;
}
Exemplo n.º 11
0
/* This is where execution begins [console apps] */
int console_main(int argc, char *argv[])
{
	int n;
	char *bufp, *appname;

	/* Get the class name from argv[0] */
	appname = argv[0];
	if ( (bufp=strrchr(argv[0], '\\')) != NULL ) {
		appname = bufp+1;
	} else
	if ( (bufp=strrchr(argv[0], '/')) != NULL ) {
		appname = bufp+1;
	}

	if ( (bufp=strrchr(appname, '.')) == NULL )
		n = strlen(appname);
	else
		n = (bufp-appname);

	bufp = (char *)alloca(n+1);
	if ( bufp == NULL ) {
		return OutOfMemory();
	}
	strncpy(bufp, appname, n);
	bufp[n] = '\0';
	appname = bufp;

	/* Load SDL dynamic link library */
	if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) {
		ShowError("WinMain() error", SDL_GetError());
		return(FALSE);
	}
	atexit(cleanup_output);
	atexit(SDL_Quit);

#ifndef DISABLE_VIDEO
	SDL_SetModuleHandle(GetModuleHandle(NULL));
#endif /* !DISABLE_VIDEO */

	/* Run the application main() code */
	SDL_main(argc, argv);

	/* Exit cleanly, calling atexit() functions */
	exit(0);

	/* Hush little compiler, don't you cry... */
	return(0);
}
Exemplo n.º 12
0
/* Start up the SDL app */
void Java_fr_bmartel_plotsdl_PlotSDLActivity_nativeInit(JNIEnv* env, jclass cls)
{

	/* This interface could expand with ABI negotiation, calbacks, etc. */
	SDL_Android_Init(env, cls);

	SDL_SetMainReady();

	/* Run the application code! */
	int status;
	char *argv[2];
	argv[0] = SDL_strdup("SDL_app");
	argv[1] = NULL;

	status = SDL_main(1, argv);
}
Exemplo n.º 13
0
int __sdlx_init(void *arg)
{
	awargs[1] = (char *)arg;
	GUI_LockExtMsg();		// 锁住消息锁
	esKRNL_TimeDly(1);		// 进行调度
	GUI_UnLockExtMsg();		// 解开消息锁
//	GUI_Init();			// ucGUI初始化
	atexit(SDL_Quit);		// 勾住Quit

	awargs[0] = __sdlx_getenvr();	/* 得到工作目录 */

	SDL_main(2, awargs);		// 进入主循环
	_exitcs();			// atexit结束
	esKRNL_TimeDly(1);		// 进行调度
	return EPDK_OK;
}
Exemplo n.º 14
0
// Initialize ScoreLoop C SDK
void JNI(SDLActivity_nativeInit)(JNIEnv* env, jclass cls, jobject obj)
{
    /* This interface could expand with ABI negotiation, calbacks, etc. */
    SDL_Android_Init(env, cls);

    SDL_SetMainReady();

    /* Run the application code! */
    int status;
    char *argv[2];
    argv[0] = SDL_strdup("SDL_app");
    argv[1] = NULL;
    status = SDL_main(1, argv);

    /* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
    //exit(status);
}
Exemplo n.º 15
0
extern C_LINKAGE void
JAVA_EXPORT_NAME(DemoRenderer_nativeInit) (JNIEnv * env, jobject obj, jobject assetManager)
{
	__assetManager = (AAssetManager *)AAssetManager_fromJava(env, assetManager);
	
	if (__assetManager == NULL)
	{
		__android_log_print(ANDROID_LOG_ERROR, "libSDL", "Error Assigning AAssetManager");
	}
	else
	{
		__android_log_print(ANDROID_LOG_INFO, "libSDL", "Assigned AAssetManager");
	}

	__android_log_print(ANDROID_LOG_INFO, "libSDL", "Calling SDL_main");

	SDL_main(argc, argv);
}
Exemplo n.º 16
0
int main(int argc, char *argv[])
{
#ifdef PS2SDL_ENABLE_MTAP
	smod_mod_info_t info;
	if(smod_get_mod_by_name("sio2man",&info)!=0)
	{
		printf("PS2SDL: sio2man detected, resetting iop\n");
		cdInit(CDVD_INIT_EXIT);
		SifExitIopHeap();
		SifLoadFileExit();
		SifExitRpc();

		SifIopReset("rom0:UDNL rom0:EELOADCNF", 0);
		while (SifIopSync()) ;
	}
#endif
	SifInitRpc(0); 
	return(SDL_main(argc, argv));
}
Exemplo n.º 17
0
extern C_LINKAGE void
JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv*  env, jobject thiz, jstring currentDirectoryPath_j, jobjectArray arg )
{
	int argc = 1 + (*env)->GetArrayLength(env, arg);
	char **argv = malloc(sizeof(char*)*argc);
	argv[0] = "sdl";
	int i;
	for (i=0 ; i<argc-1 ; i++){
		jstring str = (jstring)(*env)->GetObjectArrayElement(env, arg, i);
		argv[i+1] = (char*)(*env)->GetStringUTFChars(env, str, 0);
	}

	// Set current directory
	const char *currentDirectoryPath = (*env)->GetStringUTFChars(env, currentDirectoryPath_j, 0);
	chdir(currentDirectoryPath);
	(*env)->ReleaseStringUTFChars(env, currentDirectoryPath_j, currentDirectoryPath);

	SDL_main( argc, argv );
};
Exemplo n.º 18
0
/* Start up the SDL app */
int Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobject obj)
{
    /* This interface could expand with ABI negotiation, calbacks, etc. */
    SDL_Android_Init(env, cls);

    SDL_SetMainReady();

    /* Run the application code! */
    /* Use the name "app_process" so PHYSFS_platformCalcBaseDir() works.
       https://bitbucket.org/MartinFelis/love-android-sdl2/issue/23/release-build-crash-on-start
     */
    int status;
    char *argv[2];
    argv[0] = SDL_strdup("app_process");
    argv[1] = NULL;
    status = SDL_main(1, argv);

    /* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
    /* exit(status); */

    return status;
}
Exemplo n.º 19
0
int 
main(int argc, char *argv[])
{
#if defined(GP2X_MODE) || defined(WIZ_MODE)
  cpu_init();
#endif

#ifndef NO_STDIO_REDIRECT
  /* Redirect standard output and standard error. */
  /* TODO: Error checking. */
  freopen(STDOUT_FILE, "w", stdout);
  freopen(STDERR_FILE, "w", stderr);
  setvbuf(stdout, NULL, _IOLBF, BUFSIZ);  /* Line buffered */
  setbuf(stderr, NULL);          /* No buffering */
#endif /* NO_STDIO_REDIRECT */

  atexit(cleanup_output);

  SDL_main(argc,argv);

  return 0;
}
// Start up the SDL app
extern "C" void Java_com_scheffsblend_smw_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jobject obj)
{
    /* This interface could expand with ABI negotiation, calbacks, etc. */
    SDL_Android_Init(env, cls);
    mEnv = env;
	jNativeCls = env->FindClass("com/scheffsblend/smw/SDLActivity");

	// Load OnStopMusic()
	jStopMusicMethod = env->GetStaticMethodID( jNativeCls,
			"OnStopMusic", "()V");

	// Load OnStartMusic(String name)
	jStartMusicMethod = env->GetStaticMethodID(jNativeCls,
			"OnStartMusic", "(ZLjava/lang/String;)V");

	// Load OnPauseMusic(boolean pause)
	jPauseMusicMethod = env->GetStaticMethodID( jNativeCls,
			"OnPauseMusic", "(Z)V" );

	// Load OnSetVolume(int level)
	jSetVolumeMethod = env->GetStaticMethodID( jNativeCls,
			"OnSetVolume", "(I)V" );

    if( !jStopMusicMethod || !jStartMusicMethod ||
    		!jPauseMusicMethod || !jSetVolumeMethod ) {
        __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL: Couldn't locate Java callbacks, check that they're named and typed correctly");
    }
    /* Run the application code! */
    int status;
    char *argv[2];
    argv[0] = strdup("SDL_app");
    argv[1] = NULL;
    status = SDL_main(1, argv);

    /* We exit here for consistency with other platforms. */
    exit(status);
}
Exemplo n.º 21
0
int main(int argc, char **argv)
{
    SDL_main(argc,argv);
}
Exemplo n.º 22
0
int
main(int ac, char** av){
    return SDL_main(ac, av);
}
Exemplo n.º 23
0
int main(int argc, char *argv[])
{
	return(SDL_main(argc, argv));
}
/* Start up the SDL app */
extern "C" void Java_com_nlbhub_instead_SDLActivity_nativeInit(
    JNIEnv* env,
    jclass cls,
    jstring jnativelog,
    jstring jpath,
    jstring jappdata,
    jstring jgamespath,
    jstring jres,
    jstring jgame,
    jstring jidf,
    jstring jmusic,
    jstring jowntheme,
    jstring jtheme
) {

    if (jnativelog != NULL) {
        const char *nativelog = env->GetStringUTFChars(jnativelog, 0);
        logFile = fopen(nativelog, "w");
        start_logger("INSTEAD-Native");
        env->ReleaseStringUTFChars(jnativelog, nativelog);
    }
    
    /* This interface could expand with ABI negotiation, calbacks, etc. */
    SDL_Android_Init(env, cls);

    /* Run the application code! */
    int status;
    char *argv[15];
    int n = 1;
    if (jpath != NULL) {
        const char *path = env->GetStringUTFChars(jpath, 0);
        printf("path = %s\n", path);
        chdir(SDL_strdup(path));
        env->ReleaseStringUTFChars(jpath, path);
    }

    argv[0] = SDL_strdup("sdl-instead");

    argv[n++] = SDL_strdup("-nostdgames");
    
    if (jres != NULL) {
        const char *res = env->GetStringUTFChars(jres, 0);
        printf("res = %s\n", res);
        argv[n++] = SDL_strdup("-mode");
        argv[n++] = SDL_strdup(res);
        env->ReleaseStringUTFChars(jres, res);
    }
    if (jappdata != NULL) {
        const char *appdata = env->GetStringUTFChars(jappdata, 0);
        printf("appdata = %s\n", appdata);
        argv[n++] = SDL_strdup("-appdata");
        argv[n++] = SDL_strdup(appdata);
        env->ReleaseStringUTFChars(jappdata, appdata);
    }
    if (jgamespath != NULL) {
        const char *gamespath = env->GetStringUTFChars(jgamespath, 0);
        printf("gamespath = %s\n", gamespath);
        argv[n++] = SDL_strdup("-gamespath");
        argv[n++] = SDL_strdup(gamespath);
        env->ReleaseStringUTFChars(jgamespath, gamespath);
    }
    if (jidf != NULL) {
        const char *idf = env->GetStringUTFChars(jidf, 0);
        printf("idf = %s\n", idf);
        argv[n++] = SDL_strdup(idf);
        env->ReleaseStringUTFChars(jidf, idf);
    } else if (jgame != NULL) {
        const char *game = env->GetStringUTFChars(jgame, 0);
        printf("game = %s\n", game);
        argv[n++] = SDL_strdup("-game");
        argv[n++] = SDL_strdup(game);
        env->ReleaseStringUTFChars(jgame, game);
    }
    if (jmusic == NULL) {
        printf("Without music = YES\n");
        argv[n++] = SDL_strdup("-nosound");
    }
    if (jowntheme != NULL) {
        printf("Force own theme = YES\n");
        argv[n++] = SDL_strdup("-owntheme");
    }
    if (jtheme != NULL) {
        const char *theme = env->GetStringUTFChars(jtheme, 0);
        printf("theme = %s\n", theme);
        argv[n++] = SDL_strdup("-theme");
        argv[n++] = SDL_strdup(theme);
        env->ReleaseStringUTFChars(jtheme, theme);
    }
    argv[n] = NULL;

    printf("Before instead_main()\n");
    status = SDL_main(n, argv);
    printf("After instead_main()\n");
    fflush(NULL);
    // Stopping the logger thread, if needed. Closing the log file, if it was opened...
    if (jnativelog != NULL) {
        // Wait for potentially not logged data
        usleep(1000000);
        setStopIssued(1);
        void* thr_res;
        pthread_join(thr, &thr_res);
        // Write to the log anything that can be missed by the thread
        write_buffer_to_log();
    }
    if (logFile != NULL) {
        fclose(logFile);
    }

    /*
    No freeing in initial SDL_android_main.c
    int i;
    for (i = 0; i < n; ++i) {
        free(argv[i]);
    }
    */

    /* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
    /* exit(status); */
}
Exemplo n.º 25
0
/* This is where execution begins [console apps] */
int console_main(int argc, char *argv[])
{
	int n;
	char *bufp, *appname;

	/* Get the class name from argv[0] */
	appname = argv[0];
	if ( (bufp=strrchr(argv[0], '\\')) != NULL ) {
		appname = bufp+1;
	} else
	if ( (bufp=strrchr(argv[0], '/')) != NULL ) {
		appname = bufp+1;
	}

	if ( (bufp=strrchr(appname, '.')) == NULL )
		n = strlen(appname);
	else
		n = (bufp-appname);

	bufp = (char *)alloca(n+1);
	if ( bufp == NULL ) {
		return OutOfMemory();
	}
	strncpy(bufp, appname, n);
	bufp[n] = '\0';
	appname = bufp;

	/* Load SDL dynamic link library */
	if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) {
		ShowError("WinMain() error", SDL_GetError());
		return(FALSE);
	}
	atexit(cleanup_output);
	atexit(SDL_Quit);

#ifndef DISABLE_VIDEO
#if 0
	/* Create and register our class *
	   DJM: If we do this here, the user nevers gets a chance to
	   putenv(SDL_WINDOWID).  This is already called later by
	   the (DIB|DX5)_CreateWindow function, so it should be
	   safe to comment it out here.
	if ( SDL_RegisterApp(appname, CS_BYTEALIGNCLIENT, 
	                     GetModuleHandle(NULL)) < 0 ) {
		ShowError("WinMain() error", SDL_GetError());
		exit(1);
	}*/
#else
	/* Sam:
	   We still need to pass in the application handle so that
	   DirectInput will initialize properly when SDL_RegisterApp()
	   is called later in the video initialization.
	 */
	SDL_SetModuleHandle(GetModuleHandle(NULL));
#endif /* 0 */
#endif /* !DISABLE_VIDEO */

	/* Run the application main() code */
	SDL_main(argc, argv);

	/* Exit cleanly, calling atexit() functions */
	exit(0);

	/* Hush little compiler, don't you cry... */
	return(0);
}
Exemplo n.º 26
0
static int threadedMain(void * unused)
{
	SDL_main( argc, argv );
	__android_log_print(ANDROID_LOG_INFO, "libSDL", "Application closed, calling exit(0)");
	exit(0);
}
Exemplo n.º 27
0
extern C_LINKAGE void
JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv*  env, jobject thiz, jstring jcurdir, jstring cmdline, jint multiThreadedVideo )
{
	int i = 0;
	char curdir[PATH_MAX] = "";
	const jbyte *jstr;
	const char * str = "sdl";

	jstr = (*env)->GetStringUTFChars(env, jcurdir, NULL);
	if (jstr != NULL && strlen(jstr) > 0)
		strcpy(curdir, jstr);
	(*env)->ReleaseStringUTFChars(env, jcurdir, jstr);

	chdir(curdir);
	setenv("HOME", curdir, 1);
	__android_log_print(ANDROID_LOG_INFO, "libSDL", "Changing curdir to \"%s\"", curdir);

	jstr = (*env)->GetStringUTFChars(env, cmdline, NULL);

	if (jstr != NULL && strlen(jstr) > 0)
		str = jstr;

	{
		char * str1, * str2;
		str1 = strdup(str);
		str2 = str1;
		while(str2)
		{
			argc++;
			str2 = strchr(str2, ' ');
			if(!str2)
				break;
			str2++;
		}

		argv = (char **)malloc(argc*sizeof(char *));
		str2 = str1;
		while(str2)
		{
			argv[i] = str2;
			i++;
			str2 = strchr(str2, ' ');
			if(str2)
				*str2 = 0;
			else
				break;
			str2++;
		}
	}

	__android_log_print(ANDROID_LOG_INFO, "libSDL", "Calling SDL_main(\"%s\")", str);

	(*env)->ReleaseStringUTFChars(env, cmdline, jstr);

	for( i = 0; i < argc; i++ )
		__android_log_print(ANDROID_LOG_INFO, "libSDL", "param %d = \"%s\"", i, argv[i]);

#if SDL_VERSION_ATLEAST(1,3,0)
	SDL_main( argc, argv );
#else
	if( ! multiThreadedVideo )
		SDL_main( argc, argv );
	else
	{
		SDL_ANDROID_MultiThreadedVideoLoopInit();
		SDL_CreateThread(threadedMain, NULL);
		SDL_ANDROID_MultiThreadedVideoLoop();
	}
#endif
};
Exemplo n.º 28
0
// Start up the SDL app
extern "C" void Java_paulscode_android_mupen64plusae_NativeMethods_init(JNIEnv* env, jclass cls, jobject obj)
{
    /* This interface could expand with ABI negotiation, calbacks, etc. */
    SDL_Android_Init(env, cls);

    /* Run the application code! */
    int status;

    /* Simple usage: (i.e. to play Mario 64..)
        char *argv[3];
        argv[0] = strdup("mupen64plus");
        argv[1] = strdup( "roms/mario.n64" );
        argv[2] = NULL;
        status = SDL_main( 2, argv );
    */
    // Retrieve the (space-separated) extra args string from Java:
    char *extraArgs = Android_JNI_GetExtraArgs();
    
    char **argv;              // Map to hold the indices
    int argc = 1;             // First arg is reserved for program name
    char *index = extraArgs;  // Start at the beginning of the string
    
    // Loop through the args string to count them:
    while( index != NULL )
    {
        argc++;                        // Count the arg
        index = strchr( index + 1, ' ' );  // Advance to next space
    }
    argc += 2;  // Last two args are the ROM path and NULL
    
    // Allocate enough char pointers to index all the args:
    argv = (char **) malloc( sizeof( char *) * argc );
    
    argv[0] = strdup( "mupen64plus" );  // Store the first arg
    
    char *argSpace;     // Index for pointing to the next space
    argc = 1;           // Reuse argc rather than making a new counter
    index = extraArgs;  // Rewind back to the beginning of the string
    
    // Loop through the args string again, this time to index them:
    while( index != NULL )
    {
        argSpace = strchr( index + 1, ' ' );  // Find the end of the arg
        // Make sure this isn't the last arg:
        if( argSpace != NULL )
           argSpace[0] = '\0'; // Change space to end-of-string
        argv[argc] = strdup( index );  // Have to strdup, or args not recognized
        if( argSpace == NULL )
            index = NULL;  // Last arg, end the loop
        else
            index = argSpace + 1; // Advance to the next arg
        argc++;  // Count the arg
    }
    argv[argc] = strdup( Android_JNI_GetROMPath() );
    argc++;  // Count the ROM path arg
    argv[argc] = NULL;  // End of args
    
    status = SDL_main( argc, argv );  // Launch the emulator

    /* We exit here for consistency with other platforms. */
    exit( status );  // <---- TODO: This is the ASDP bug culprit
}
Exemplo n.º 29
0
/* This is where execution begins */
int STDCALL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
{
    char *appname;
    char *ptr;
    int i;
    FILE *fp;
    char **argv;
    int argc;

    /*
	 * Direct Draw has a nasty bug where a file that is opened before
	 * Direct Draw is invoked, *stays* open until the system is rebooted.
	 * So we need to get Direct Draw loaded before we open any files.
	 */

    {
        HANDLE h;

        h = LoadLibrary("DDRAW.DLL");
        if(h)
            FreeLibrary(LoadLibrary("DDRAW.DLL"));
    }

    /* FIXME:
	 * fprintf needs to be remapped to a windows function, otherwise when 
	 * executor dies the user has no idea why it just vanished.
	 */
    fp = freopen("stdout.txt", "w", stdout);
#if !defined(stdout)
    if(!fp)
        stdout = fopen("stdout.txt", "w");
#else
    if(!fp)
        *stdout = *fopen("stdout.txt", "w");
#endif
    setbuf(stdout, 0);
    fp = freopen("stderr.txt", "w", stderr);
#if !defined(stderr)
    if(!fp)
        stderr = fopen("stderr.txt", "w");
#else
    if(!fp)
        *stderr = *fopen("stderr.txt", "w");
#endif
    setbuf(stderr, 0);

    paramline_to_argcv(GetCommandLine(), &argc, &argv);

    /* Get the class name from argv[0] */
    /* Basename... */
    if((ptr = strrchr(argv[0], '\\')) == NULL)
        appname = argv[0];
    else
        appname = ptr + 1;
    /* minus extension... */
    if((ptr = strrchr(appname, '.')) == NULL)
        i = strlen(appname);
    else
        i = (ptr - appname);
    /* equals appname! */
    ptr = (char *)alloca(i + 1);
    strncpy(ptr, appname, i);
    ptr[i] = '\0';
    appname = ptr;

    /* Load SDL dynamic link library */
    if(SDL_Init(0) < 0)
    {
        fprintf(stderr, "WinMain() error: %s\n", SDL_GetError());
        return (false);
    }
    atexit(SDL_Quit);

    /* Create and register our class, then run main code */
    if(SDL_RegisterApp(appname, CS_BYTEALIGNCLIENT, hInst) < 0)
    {
        fprintf(stderr, "WinMain() error: %s\n", SDL_GetError());
        return (false);
    }
    SDL_main(argc, argv);

    exit(0);
}