Esempio n. 1
0
int main(int argc, char *argv[]) {
	SDL_SetMainReady();
	SDL_Init(0);
	oldstate = ClientComponent::state;
	g_Client()->Start();
	while (g_Client()->isRunning()) {
		ClientComponent::TickComponents();
	}
	ClientComponent::ClearComponents();
	SDL_Quit();
	return 0;
}
Esempio n. 2
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;
}
Esempio n. 3
0
int PERSDLJoyInit(void) {
	int i, j;

	// does not need init if already done
	if ( SDL_PERCORE_INITIALIZED )
	{
		return 0;
	}

#if defined (_MSC_VER) && SDL_VERSION_ATLEAST(2,0,0)
   SDL_SetMainReady();
#endif

	// init joysticks
	if ( SDL_InitSubSystem( SDL_INIT_JOYSTICK ) == -1 )
	{
		return -1;
	}
	
	// ignore joysticks event in sdl event loop
	SDL_JoystickEventState( SDL_IGNORE );
	
	// open joysticks
	SDL_PERCORE_JOYSTICKS_INITIALIZED = SDL_NumJoysticks();
	SDL_PERCORE_JOYSTICKS = malloc(sizeof(PERSDLJoystick) * SDL_PERCORE_JOYSTICKS_INITIALIZED);
	for ( i = 0; i < SDL_PERCORE_JOYSTICKS_INITIALIZED; i++ )
	{
		SDL_Joystick* joy = SDL_JoystickOpen( i );
		
		SDL_JoystickUpdate();
		
		SDL_PERCORE_JOYSTICKS[ i ].mJoystick = joy;
		SDL_PERCORE_JOYSTICKS[ i ].mScanStatus = joy ? malloc(sizeof(s16) * SDL_JoystickNumAxes( joy )) : 0;
		SDL_PERCORE_JOYSTICKS[ i ].mHatStatus = joy ? malloc(sizeof(Uint8) * SDL_JoystickNumHats( joy )) : 0;
		
		if ( joy )
		{
			for ( j = 0; j < SDL_JoystickNumAxes( joy ); j++ )
			{
				SDL_PERCORE_JOYSTICKS[ i ].mScanStatus[ j ] = SDL_JoystickGetAxis( joy, j );
			}
			for ( j = 0; j < SDL_JoystickNumHats( joy ); j++ )
			{
				SDL_PERCORE_JOYSTICKS[ i ].mHatStatus[ j ] = SDL_JoystickGetHat( joy, j );
			}
		}
	}
	
	// success
	SDL_PERCORE_INITIALIZED = 1;
	return 0;
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");
    SDL_SetMainReady();
    if (SDL_Init(SDL_INIT_VIDEO) != 0)
    {
        qDebug() << "SDL_Init failed: " << QString::fromStdString(SDL_GetError());
        return 0;
    }

    QApplication app(argc, argv);

    // Now we make sure the current dir is set to application path
    QDir dir(QCoreApplication::applicationDirPath());

    #ifdef Q_OS_MAC
    if (dir.dirName() == "MacOS") {
        dir.cdUp();
        dir.cdUp();
        dir.cdUp();
    }

    // force Qt to load only LOCAL plugins, don't touch system Qt installation
    QDir pluginsPath(QCoreApplication::applicationDirPath());
    pluginsPath.cdUp();
    pluginsPath.cd("Plugins");

    QStringList libraryPaths;
    libraryPaths << pluginsPath.path() << QCoreApplication::applicationDirPath();
    app.setLibraryPaths(libraryPaths);
    #endif

    QDir::setCurrent(dir.absolutePath());

    // Support non-latin characters
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));

    Launcher::MainDialog mainWin;

    if (!mainWin.showFirstRunDialog())
        return 0;

//    if (!mainWin.setup()) {
//        return 0;
//    }

    mainWin.show();

    int returnValue = app.exec();
    SDL_Quit();
    return returnValue;
}
/* 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;
}
Esempio n. 6
0
int main(int argc, char *argv[])
{
    pspDebugScreenInit();
    sdl_psp_setup_callbacks();

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

    SDL_SetMainReady();

    (void)SDL_main(argc, argv);
    return 0;
}
Esempio n. 7
0
int main(int argc, char *argv[])
{
    try
    {
        SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");
        SDL_SetMainReady();
        if (SDL_Init(SDL_INIT_VIDEO) != 0)
        {
            qDebug() << "SDL_Init failed: " << QString::fromUtf8(SDL_GetError());
            return 0;
        }
        signal(SIGINT, SIG_DFL); // We don't want to use the SDL event loop in the launcher,
                                 // so reset SIGINT which SDL wants to redirect to an SDL_Quit event.

        QApplication app(argc, argv);

        // Now we make sure the current dir is set to application path
        QDir dir(QCoreApplication::applicationDirPath());

        #ifdef Q_OS_MAC
        if (dir.dirName() == "MacOS") {
            dir.cdUp();
            dir.cdUp();
            dir.cdUp();
        }
        #endif

        QDir::setCurrent(dir.absolutePath());

        Launcher::MainDialog mainWin;

        Launcher::FirstRunDialogResult result = mainWin.showFirstRunDialog();
        if (result == Launcher::FirstRunDialogResultFailure)
            return 0;

        if (result == Launcher::FirstRunDialogResultContinue)
            mainWin.show();

        int returnValue = app.exec();
        SDL_Quit();
        return returnValue;
    }
    catch (std::exception& e)
    {
        std::cerr << "ERROR: " << e.what() << std::endl;
        return 0;
    }
}
Esempio n. 8
0
/* This is where execution begins [console apps] */
int
console_main(int argc, char *argv[])
{
    int status;

    SDL_SetMainReady();

    /* 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;
}
Esempio n. 9
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);
}
Esempio n. 10
0
static int SNDSDLInit(void)
{
   //samples should be a power of 2 according to SDL-doc
   //so normalize it to the nearest power of 2 here
   u32 normSamples = 512;

#if defined (_MSC_VER) && SDL_VERSION_ATLEAST(2,0,0)
   SDL_SetMainReady();
#endif
   SDL_InitSubSystem(SDL_INIT_AUDIO);
//   if (SDL_InitSubSystem(SDL_INIT_AUDIO) != 0);
//      return -1;

   audiofmt.freq = 44100;
   audiofmt.format = AUDIO_S16SYS;
   audiofmt.channels = 2;
   audiofmt.samples = (audiofmt.freq / 60) * 2;
   audiofmt.callback = MixAudio;
   audiofmt.userdata = NULL;

   while (normSamples < audiofmt.samples) 
      normSamples <<= 1;

   audiofmt.samples = normSamples;
   
   soundlen = audiofmt.freq / 60; // 60 for NTSC or 50 for PAL. Initially assume it's going to be NTSC.
   soundbufsize = soundlen * NUMSOUNDBLOCKS * 2 * 2;
   
   soundvolume = SDL_MIX_MAXVOLUME;

   if (SDL_OpenAudio(&audiofmt, NULL) != 0)
   {
      YabSetError(YAB_ERR_SDL, (void *)SDL_GetError());
      return -1;
   }

   if ((stereodata16 = (u16 *)malloc(soundbufsize)) == NULL)
      return -1;

   memset(stereodata16, 0, soundbufsize);

   soundpos = 0;

   SDL_PauseAudio(0);

   return 0;
}
Esempio n. 11
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);
}
Esempio n. 12
0
/* Start up the SDL app */
void Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls, jint initialWidth, jint initialHeight)
{
	/* 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;
	android_entrypoint(initialWidth, initialHeight);

	/* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
	/* exit(status); */
}
Esempio n. 13
0
int Java_org_libsdl_app_SDLActivity_nativeInit(JNIEnv* env, jclass cls,
		jobject obj) {

	SDL_Android_Init(env, cls);

	SDL_SetMainReady();

	/* Run the application code! */

	int status;

	status = main(argcData+1, argvData);
	releaseArgv();
	/* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
	/* exit(status); */

	return status;
}
Esempio n. 14
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;
}
Esempio n. 15
0
OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
  : mOgre (0)
  , mFpsLevel(0)
  , mVerboseScripts (false)
  , mSkipMenu (false)
  , mUseSound (true)
  , mCompileAll (false)
  , mCompileAllDialogue (false)
  , mWarningsMode (1)
  , mScriptContext (0)
  , mFSStrict (false)
  , mScriptConsoleMode (false)
  , mCfgMgr(configurationManager)
  , mEncoding(ToUTF8::WINDOWS_1252)
  , mEncoder(NULL)
  , mActivationDistanceOverride(-1)
  , mGrab(true)
  , mScriptBlacklistUse (true)
  , mExportFonts(false)
  , mNewGame (false)
{
    std::srand ( std::time(NULL) );
    MWClass::registerClasses();

    Uint32 flags = SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE;
    if(SDL_WasInit(flags) == 0)
    {
        //kindly ask SDL not to trash our OGL context
        //might this be related to http://bugzilla.libsdl.org/show_bug.cgi?id=748 ?
        SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software");
        SDL_SetMainReady();
        if(SDL_Init(flags) != 0)
        {
            throw std::runtime_error("Could not initialize SDL! " + std::string(SDL_GetError()));
        }
    }
}
Esempio n. 16
0
int initEverything( void )
{
#ifndef _DEBUG
	logFile = SDL_RWFromFile( "log.txt", "w" );
	if( logFile != NULL ) {
		SDL_LogSetOutputFunction( LogOutput, NULL );
	}
#endif

	// memory first, won't be used everywhere at first so lets keep the initial allocation low, 64 MB
	mem_Init( 64 * 1024 * 1024 );

	/* then SDL */
	SDL_SetMainReady( );
	if( SDL_Init( SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS ) != 0 ) {
		SDL_LogError( SDL_LOG_CATEGORY_APPLICATION, SDL_GetError( ) );
		return -1;
	}
	SDL_LogInfo( SDL_LOG_CATEGORY_APPLICATION, "SDL successfully initialized" );
	atexit( cleanUp );

	// set up opengl
	// try opening and parsing the config file
	int majorVersion;
	int minorVersion;
	int redSize;
	int greenSize;
	int blueSize;
	int depthSize;

	void* oglCFGFile = cfg_OpenFile( "opengl.cfg" );
	cfg_GetInt( oglCFGFile, "MAJOR", 3, &majorVersion );
	cfg_GetInt( oglCFGFile, "MINOR", 3, &minorVersion );
	cfg_GetInt( oglCFGFile, "RED_SIZE", 8, &redSize );
	cfg_GetInt( oglCFGFile, "GREEN_SIZE", 8, &greenSize );
	cfg_GetInt( oglCFGFile, "BLUE_SIZE", 8, &blueSize );
	cfg_GetInt( oglCFGFile, "DEPTH_SIZE", 16, &depthSize );
	cfg_CloseFile( oglCFGFile );

	majorVersion = 2;
	minorVersion = 1;
	// want the core functionality
	SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
	SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, majorVersion );
	SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, minorVersion );
	// want 8 bits minimum per color
	SDL_GL_SetAttribute( SDL_GL_RED_SIZE, redSize );
    SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, greenSize );
    SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, blueSize );
	// want 16 bit depth buffer
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, depthSize );
	// want it to be double buffered
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

	window = SDL_CreateWindow( windowName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
		WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL );
	if( window == NULL ) {
		SDL_LogError( SDL_LOG_CATEGORY_VIDEO, SDL_GetError( ) );
		return -1;
	}
	SDL_LogInfo( SDL_LOG_CATEGORY_APPLICATION, "SDL OpenGL window successfully created" );

	/* Load and create images */
	if( gfx_Init( window ) < 0 ) {
		return -1;
	}
	SDL_LogInfo( SDL_LOG_CATEGORY_APPLICATION, "Rendering successfully initialized" );

	/* Load and create sounds and music */
	if( initMixer( ) < 0 ) {
		return -1;
	}
	SDL_LogInfo( SDL_LOG_CATEGORY_APPLICATION, "Mixer successfully initialized" );

	cam_Init( );
	cam_SetProjectionMatrices( window );
	SDL_LogInfo( SDL_LOG_CATEGORY_APPLICATION, "Cameras successfully initialized" );

	loadAllResources( );

	return 0;
}
Esempio n. 17
0
/**
 * \brief  This is the function where CG beings
 *
 * \param	argc   	number of arguments
 * \param	argv   	pointer to  char arrays where
 * 					where the passed arguments are stored
 * 					in the process
 * \return	        This always returns 0. If
 * 					some errors appear, take a look
 * 					at the Logfile.
 *
 */
int main(int argc, char *argv[])
{

#if SDL_VERSION_ATLEAST(2, 0, 0)
    #ifdef ANDROID
        SDL_SetMainReady( );
    #endif
#endif

	// Check if CG should look into a given directory
	std::string binary_dir;
	if(argc >= 1)
	{		
		binary_dir = argv[0];
		size_t slashpos = findLastPathSep(binary_dir);
		
		if(slashpos != std::string::npos)
		{
			binary_dir.erase(slashpos);
            binary_dir = SystemNativeToUtf8(binary_dir);
		}
		else
		{
			binary_dir = ".";
		}
	}
	else
	{
		warnings << "Binary-argument not given, assuming current dir" << endl;
		binary_dir = ".";
	}

	SetBinaryDir( GetAbsolutePath(binary_dir) );

	InitThreadPool();
    InitSearchPaths(g_pSettings->getConfigFileName());

    gLogging.CreateLogfile("CGLog.html", APP_NAME, CGVERSION);

    // Check if there are settings on the PC, otherwise use defaults.
    if(!g_pSettings->loadDrvCfg())
    {
        //m_firsttime = true;
        gLogging.textOut(RED,"First time message: CG didn't find the driver config file. ");
        gLogging.textOut(RED,"However, it generated some default values and will save them now.\n");
        g_pSettings->saveDrvCfg();
    }

    gLogging.textOut(GREEN,"Loading game options...\n");
    if(!g_pSettings->loadGameOptions())
    {
        gLogging.textOut(RED,"Cannot do loading defaults...\n");
        g_pSettings->loadDefaultGameCfg();
    }

    // Init the Game sound
    g_pSound->init();

    ////////////////////////////////////////////////////
    // Initialize CG and run the main cycle if worthy //
    ////////////////////////////////////////////////////
    if( gApp.init( argc, argv ) )
	{
        ////////////////////////////////
        // Set GameLauncher as Engine //
        ////////////////////////////////
        gApp.setEngine(new CGameLauncher(false));

        //////////////////////////////
        // Run the Commander Genius //
        //////////////////////////////
        gApp.runMainCycle();
	}

    g_pSettings->saveDispCfg();

	UnInitThreadPool();
	return 0;
}