Example #1
0
int main()
{
    CApplication app;

    // create application
    if( !app.Create(1024, 664, false) )
    //if( !app.Create(1366, 768, true) )
        return false;

	// main loop
	while( app.IsRunning() )
	{
        app.AdvanceFrame();
	}

    app.Destroy();

	// exit the app
	return 0;
}
Example #2
0
int SDL_MAIN_FUNC(int argc, char *argv[])
{
    CLogger logger; // single istance of logger

    // Workaround for character encoding in argv on Windows
    #if PLATFORM_WINDOWS
    int wargc;
    wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &wargc);
    if(wargv == nullptr)
    {
        logger.Error("CommandLineToArgvW failed\n");
        return 1;
    }
    argv = new char*[wargc];
    for(int i = 0; i < wargc; i++) {
        std::wstring warg = wargv[i];
        std::string arg = CSystemUtilsWindows::UTF8_Encode(warg);
        argv[i] = new char[arg.length()+1];
        strcpy(argv[i], arg.c_str());
    }
    LocalFree(wargv);
    #endif

    CResourceManager manager(argv[0]);

    // Initialize static string arrays
    InitializeRestext();
    InitializeEventTypeTexts();

    logger.Info("%s starting\n", COLOBOT_FULLNAME);
    
    int code = 0;
    while(true) {
        CSystemUtils* systemUtils = CSystemUtils::Create(); // platform-specific utils
        systemUtils->Init();
        
        CApplication* app = new CApplication(); // single instance of the application

        ParseArgsStatus status = app->ParseArguments(argc, argv);
        if (status == PARSE_ARGS_FAIL)
        {
            systemUtils->SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", "Invalid commandline arguments!\n");
            return app->GetExitCode();
        }
        else if (status == PARSE_ARGS_HELP)
        {
            return app->GetExitCode();
        }


        if (! app->Create())
        {
            app->Destroy(); // ensure a clean exit
            code = app->GetExitCode();
            if ( code != 0 && !app->GetErrorMessage().empty() )
            {
                systemUtils->SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", app->GetErrorMessage());
            }
            logger.Info("Didn't run main loop. Exiting with code %d\n", code);
            return code;
        }

        code = app->Run();
        bool restarting = app->IsRestarting();

        delete app;
        delete systemUtils;
        if(!restarting) break;
    }

    logger.Info("Exiting with code %d\n", code);

    #if PLATFORM_WINDOWS
    // See the workaround above
    delete[] argv;
    #endif

    return code;
}