void State::Manager::Run(State& entranceState) { SDL_setenv("UBUNTU_PLATFORM_API_BACKEND", "touch_mirclient", 1); accel = ua_sensors_accelerometer_new(); ua_sensors_accelerometer_set_reading_cb(accel, tilt_cb, 0); ua_sensors_accelerometer_enable(accel); current = &entranceState; current->Enter(); //clock_t ticks = clock(); while (!quit) { PollEvent(); Tilt(); if (next) EnterNextState(); CallLoopFunction(); if (param.framerate != 0) { /**clock_t nticks = clock(); int32_t sleeptime = (CLOCKS_PER_SEC/param.framerate - (nticks-ticks)) / 1000; if (sleeptime > 0) SDL_Delay(sleeptime);*/ SDL_Delay(1); //ticks = nticks; } } current->Exit(); previous = current; current = NULL; }
static int ESD_Init(SDL_AudioDriverImpl * impl) { if (LoadESDLibrary() < 0) { return 0; } else { int connection = 0; /* Don't start ESD if it's not running */ SDL_setenv("ESD_NO_SPAWN", "1", 0); connection = SDL_NAME(esd_open_sound) (NULL); if (connection < 0) { UnloadESDLibrary(); SDL_SetError("ESD: esd_open_sound failed (no audio server?)"); return 0; } SDL_NAME(esd_close) (connection); } /* Set the function pointers */ impl->OpenDevice = ESD_OpenDevice; impl->PlayDevice = ESD_PlayDevice; impl->WaitDevice = ESD_WaitDevice; impl->GetDeviceBuf = ESD_GetDeviceBuf; impl->CloseDevice = ESD_CloseDevice; impl->Deinitialize = ESD_Deinitialize; impl->OnlyHasDefaultOutputDevice = 1; return 1; /* this audio target is available. */ }
/** * @brief Handles the options. */ static void parse_options( int argc, char *argv[] ) { int i; for (i = 1; i < argc; ++i) { const char *arg = argv[i]; if (SDL_strcmp(arg, "-m") == 0 || SDL_strcmp(arg, "--manual") == 0) { run_manual = 1; continue; } if (SDL_strcmp(arg, "-v") == 0 || SDL_strcmp(arg, "--verbose") == 0) { int level; SDL_ATgeti( SDL_AT_VERBOSE, &level ); SDL_ATseti( SDL_AT_VERBOSE, level+1 ); continue; } if (SDL_strcmp(arg, "-q") == 0 || SDL_strcmp(arg, "--quiet") == 0) { SDL_ATseti( SDL_AT_QUIET, 1 ); SDL_setenv("SDL_ASSERT", "abort", 0); continue; } if (SDL_strcmp(arg, "--noplatform") == 0) { run_platform = 0; continue; } if (SDL_strcmp(arg, "--norwops") == 0) { run_rwops = 0; continue; } if (SDL_strcmp(arg, "--norect") == 0) { run_rect = 0; continue; } if (SDL_strcmp(arg, "--nosurface") == 0) { run_surface = 0; continue; } if (SDL_strcmp(arg, "--norender") == 0) { run_render = 0; continue; } if (SDL_strcmp(arg, "--noaudio") == 0) { run_audio = 0; continue; } /* Print help and exit! */ print_usage( argv[0] ); exit(EXIT_FAILURE); } }
/** Process commandline-arguments */ static int process_command_args(const commandline_options& cmdline_opts) { // Options that don't change behavior based on any others should be checked alphabetically below. if(cmdline_opts.userconfig_dir) { filesystem::set_user_config_dir(*cmdline_opts.userconfig_dir); } if(cmdline_opts.userconfig_path) { std::cout << filesystem::get_user_config_dir() << '\n'; return 0; } if(cmdline_opts.userdata_dir) { filesystem::set_user_data_dir(*cmdline_opts.userdata_dir); } if(cmdline_opts.userdata_path) { std::cout << filesystem::get_user_data_dir() << '\n'; return 0; } if(cmdline_opts.data_dir) { const std::string datadir = *cmdline_opts.data_dir; std::cerr << "Overriding data directory with " << datadir << std::endl; #ifdef _WIN32 // use c_str to ensure that index 1 points to valid element since c_str() returns null-terminated string if(datadir.c_str()[1] == ':') { #else if(datadir[0] == '/') { #endif game_config::path = datadir; } else { game_config::path = filesystem::get_cwd() + '/' + datadir; } if(!filesystem::is_directory(game_config::path)) { std::cerr << "Could not find directory '" << game_config::path << "'\n"; throw config::error("directory not found"); } // don't update font as we already updating it in game ctor //font_manager_.update_font_path(); } if(cmdline_opts.data_path) { std::cout << game_config::path << '\n'; return 0; } if(cmdline_opts.debug_lua) { game_config::debug_lua = true; } if(cmdline_opts.gunzip) { const std::string input_file(*cmdline_opts.gunzip); if(!filesystem::is_gzip_file(input_file)) { std::cerr << "file '" << input_file << "'isn't a .gz file\n"; return 2; } const std::string output_file( input_file, 0, input_file.length() - 3); gzip_decode(input_file, output_file); } if(cmdline_opts.bunzip2) { const std::string input_file(*cmdline_opts.bunzip2); if(!filesystem::is_bzip2_file(input_file)) { std::cerr << "file '" << input_file << "'isn't a .bz2 file\n"; return 2; } const std::string output_file( input_file, 0, input_file.length() - 4); bzip2_decode(input_file, output_file); } if(cmdline_opts.gzip) { const std::string input_file(*cmdline_opts.gzip); const std::string output_file(*cmdline_opts.gzip + ".gz"); gzip_encode(input_file, output_file); } if(cmdline_opts.bzip2) { const std::string input_file(*cmdline_opts.bzip2); const std::string output_file(*cmdline_opts.bzip2 + ".bz2"); bzip2_encode(input_file, output_file); } if(cmdline_opts.help) { std::cout << cmdline_opts; return 0; } if(cmdline_opts.log) { for(std::vector<boost::tuple<int, std::string> >::const_iterator it=cmdline_opts.log->begin(); it!=cmdline_opts.log->end(); ++it) { const std::string log_domain = it->get<1>(); const int severity = it->get<0>(); if (!lg::set_log_domain_severity(log_domain, severity)) { std::cerr << "unknown log domain: " << log_domain << '\n'; return 2; } } } if(cmdline_opts.logdomains) { std::cout << lg::list_logdomains(*cmdline_opts.logdomains); return 0; } if(cmdline_opts.path) { std::cout << game_config::path << "\n"; return 0; } if(cmdline_opts.log_precise_timestamps) { lg::precise_timestamps(true); } if(cmdline_opts.rng_seed) { srand(*cmdline_opts.rng_seed); } if(cmdline_opts.screenshot || cmdline_opts.render_image) { SDL_setenv("SDL_VIDEODRIVER", "dummy", 1); } if(cmdline_opts.strict_validation) { strict_validation_enabled = true; } if(cmdline_opts.version) { std::cout << "Battle for Wesnoth" << " " << game_config::version << "\n\n"; std::cout << "Library versions:\n" << game_config::library_versions_report() << '\n'; std::cout << "Optional features:\n" << game_config::optional_features_report(); return 0; } // Options changing their behavior dependent on some others should be checked below. if ( cmdline_opts.preprocess ) { handle_preprocess_command(cmdline_opts); return 0; } // Not the most intuitive solution, but I wanted to leave current semantics for now return -1; } /** * I would prefer to setup locale first so that early error * messages can get localized, but we need the game_launcher * initialized to have filesystem::get_intl_dir() to work. Note: setlocale() * does not take GUI language setting into account. */ static void init_locale() { #if defined _WIN32 || defined __APPLE__ setlocale(LC_ALL, "English"); #else std::setlocale(LC_ALL, "C"); translation::init(); #endif const std::string& intl_dir = filesystem::get_intl_dir(); translation::bind_textdomain(PACKAGE, intl_dir.c_str(), "UTF-8"); translation::bind_textdomain(PACKAGE "-lib", intl_dir.c_str(), "UTF-8"); translation::set_default_textdomain(PACKAGE); }
void XBoxStartup() { const char *logdir = NULL; myargc = -1; myargv = NULL; #else #ifdef FORCESDLMAIN FUNCNORETURN int SDL_main(int argc, char **argv) #else FUNCNORETURN int main(int argc, char **argv) #endif { const char *logdir = NULL; myargc = argc; myargv = argv; /// \todo pull out path to exe from this string #endif #ifdef HAVE_TTF #ifdef _PS3 // apparently there is a bug in SDL_PSL1GHT which needs this to be set to work around SDL_setenv("SDL_VIDEODRIVER", "psl1ght", 1); I_StartupTTF(FONTPOINTSIZE, SDL_INIT_VIDEO, SDL_SWSURFACE|SDL_DOUBLEBUF); #elif defined(_WIN32) I_StartupTTF(FONTPOINTSIZE, SDL_INIT_VIDEO|SDL_INIT_AUDIO, SDL_SWSURFACE); #else I_StartupTTF(FONTPOINTSIZE, SDL_INIT_VIDEO, SDL_SWSURFACE); #endif #endif #ifdef _PS3 // initialise controllers. //ioPadInit(7); #endif // init Wii-specific stuff #ifdef _WII // Start network if_config(localip, netmask, gateway, TRUE); #ifdef REMOTE_DEBUGGING #if REMOTE_DEBUGGING == 0 DEBUG_Init(GDBSTUB_DEVICE_TCP, GDBSTUB_DEF_TCPPORT); // Port 2828 #elif REMOTE_DEBUGGING > 2 DEBUG_Init(GDBSTUB_DEVICE_TCP, REMOTE_DEBUGGING); // Custom Port #elif REMOTE_DEBUGGING < 0 DEBUG_Init(GDBSTUB_DEVICE_USB, GDBSTUB_DEF_CHANNEL); // Slot 1 #else DEBUG_Init(GDBSTUB_DEVICE_USB, REMOTE_DEBUGGING-1); // Custom Slot #endif #endif // Start FAT filesystem fatInitDefault(); if (getcwd(wiicwd, PATH_MAX)) I_PutEnv(va("HOME=%ssrb2wii", wiicwd)); #endif logdir = D_Home(); #ifdef LOGMESSAGES #if defined(_WIN32_WCE) || defined(GP2X) logstream = fopen(va("%s.log",argv[0]), "wt"); #elif defined (_WII) logstream = fopen(va("%s/log.txt",logdir), "wt"); #elif defined (DEFAULTDIR) if (logdir) logstream = fopen(va("%s/"DEFAULTDIR"/log.txt",logdir), "wt"); else #endif logstream = fopen("./log.txt", "wt"); #endif //I_OutputMsg("I_StartupSystem() ...\n"); I_StartupSystem(); #if defined (_WIN32) && !defined (_XBOX) #ifndef _WIN32_WCE { p_IsDebuggerPresent pfnIsDebuggerPresent = (p_IsDebuggerPresent)GetProcAddress(GetModuleHandleA("kernel32.dll"), "IsDebuggerPresent"); if ((!pfnIsDebuggerPresent || !pfnIsDebuggerPresent()) #ifdef BUGTRAP && !InitBugTrap() #endif ) { LoadLibraryA("exchndl.dll"); } } #endif prevExceptionFilter = SetUnhandledExceptionFilter(RecordExceptionInfo); #ifndef _WIN32_WCE MakeCodeWritable(); #endif #endif // startup SRB2 CONS_Printf("Setting up SRB2...\n"); D_SRB2Main(); CONS_Printf("Entering main game loop...\n"); // never return D_SRB2Loop(); #ifdef BUGTRAP // This is safe even if BT didn't start. ShutdownBugTrap(); #endif // return to OS #ifndef __GNUC__ return 0; #endif }
void InitVideo(int argc, char *argv[]) { int width = 640, height = 480; int flags = SDL_HWSURFACE; const char *fontname = DEFAULT_FONT; int fullscreen = 0; for (argc--, argv++; argc > 0; argc--, argv++) { if (strcmp(argv[0], "--help") == 0) usage(); else if (strcmp(argv[0], "--fullscreen") == 0) fullscreen = 1; else if (strcmp(argv[0], "--font") == 0) { argc--; argv++; if (argc > 0) fontname = argv[0]; else usage(); } } SDL_setenv("SDL_VIDEO_WINDOW_POS", "center", 1); if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(-1); } #ifdef HAVE_SDL_TTF /* Initialize fonts */ TTF_Init(); font = TTF_OpenFont(fontname, DEFAULT_PTSIZE); if (! font) { fprintf(stderr, "Failed to find font: %s\n", TTF_GetError()); exit(-1); } #endif printf("Using font: %s\n", fontname); atexit(SDL_Quit); if (fullscreen) { SDL_DisplayMode mode; SDL_GetDesktopDisplayMode(&mode); width = mode.w; height = mode.h; fprintf(stderr, "%dx%d\n", width, height); flags |= SDL_FULLSCREEN; } /* Create window */ screen = SDL_SetVideoMode(width, height, 32, flags); if (screen == NULL) { fprintf(stderr, "Unable to set %dx%d video: %s\n", width, height, SDL_GetError()); exit(-1); } }
int main(int argc, char *argv[]) { char *value; printf("Checking for non-existent variable... "); fflush(stdout); if (!SDL_getenv("EXISTS")) { printf("okay\n"); } else { printf("failed\n"); } printf("Setting FIRST=VALUE1 in the environment... "); fflush(stdout); if (SDL_setenv("FIRST", "VALUE1", 0) == 0) { printf("okay\n"); } else { printf("failed\n"); } printf("Getting FIRST from the environment... "); fflush(stdout); value = SDL_getenv("FIRST"); if (value && (SDL_strcmp(value, "VALUE1") == 0)) { printf("okay\n"); } else { printf("failed\n"); } printf("Setting SECOND=VALUE2 in the environment... "); fflush(stdout); if (SDL_setenv("SECOND", "VALUE2", 0) == 0) { printf("okay\n"); } else { printf("failed\n"); } printf("Getting SECOND from the environment... "); fflush(stdout); value = SDL_getenv("SECOND"); if (value && (SDL_strcmp(value, "VALUE2") == 0)) { printf("okay\n"); } else { printf("failed\n"); } printf("Setting FIRST=NOVALUE in the environment... "); fflush(stdout); if (SDL_setenv("FIRST", "NOVALUE", 1) == 0) { printf("okay\n"); } else { printf("failed\n"); } printf("Getting FIRST from the environment... "); fflush(stdout); value = SDL_getenv("FIRST"); if (value && (SDL_strcmp(value, "NOVALUE") == 0)) { printf("okay\n"); } else { printf("failed\n"); } printf("Checking for non-existent variable... "); fflush(stdout); if (!SDL_getenv("EXISTS")) { printf("okay\n"); } else { printf("failed\n"); } return (0); }
/** * @brief Call to SDL_getenv and SDL_setenv */ int stdlib_getsetenv(void *arg) { const int nameLen = 16; char name[17]; int counter; int result; char * value1; char * value2; char * expected; int overwrite; char * text; /* Create a random name. This tests SDL_getenv, since we need to */ /* make sure the variable is not set yet (it shouldn't). */ do { for(counter = 0; counter < nameLen; counter++) { name[counter] = (char)SDLTest_RandomIntegerInRange(65, 90); } name[nameLen] = '\0'; text = SDL_getenv(name); SDLTest_AssertPass("Call to SDL_getenv('%s')", name); if (text != NULL) { SDLTest_Log("Expected: NULL, Got: '%s' (%i)", text, (int) SDL_strlen(text)); } } while (text != NULL); /* Create random values to set */ value1 = SDLTest_RandomAsciiStringOfSize(10); value2 = SDLTest_RandomAsciiStringOfSize(10); /* Set value 1 without overwrite */ overwrite = 0; expected = value1; result = SDL_setenv(name, value1, overwrite); SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite); SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result); /* Check value */ text = SDL_getenv(name); SDLTest_AssertPass("Call to SDL_getenv('%s')", name); SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL"); if (text != NULL) { SDLTest_AssertCheck( SDL_strcmp(text, expected) == 0, "Verify returned text, expected: %s, got: %s", expected, text); } /* Set value 2 with overwrite */ overwrite = 1; expected = value2; result = SDL_setenv(name, value2, overwrite); SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value2, overwrite); SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result); /* Check value */ text = SDL_getenv(name); SDLTest_AssertPass("Call to SDL_getenv('%s')", name); SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL"); if (text != NULL) { SDLTest_AssertCheck( SDL_strcmp(text, expected) == 0, "Verify returned text, expected: %s, got: %s", expected, text); } /* Set value 1 without overwrite */ overwrite = 0; expected = value2; result = SDL_setenv(name, value1, overwrite); SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite); SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result); /* Check value */ text = SDL_getenv(name); SDLTest_AssertPass("Call to SDL_getenv('%s')", name); SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL"); if (text != NULL) { SDLTest_AssertCheck( SDL_strcmp(text, expected) == 0, "Verify returned text, expected: %s, got: %s", expected, text); } /* Set value 1 without overwrite */ overwrite = 1; expected = value1; result = SDL_setenv(name, value1, overwrite); SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite); SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result); /* Check value */ text = SDL_getenv(name); SDLTest_AssertPass("Call to SDL_getenv('%s')", name); SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL"); if (text != NULL) { SDLTest_AssertCheck( SDL_strcmp(text, expected) == 0, "Verify returned text, expected: %s, got: %s", expected, text); } /* Negative cases */ for (overwrite=0; overwrite <= 1; overwrite++) { result = SDL_setenv(NULL, value1, overwrite); SDLTest_AssertPass("Call to SDL_setenv(NULL,'%s', %i)", value1, overwrite); SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result); result = SDL_setenv("", value1, overwrite); SDLTest_AssertPass("Call to SDL_setenv('','%s', %i)", value1, overwrite); SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result); result = SDL_setenv("=", value1, overwrite); SDLTest_AssertPass("Call to SDL_setenv('=','%s', %i)", value1, overwrite); SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result); result = SDL_setenv(name, NULL, overwrite); SDLTest_AssertPass("Call to SDL_setenv('%s', NULL, %i)", name, overwrite); SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result); } /* Clean up */ SDL_free(value1); SDL_free(value2); return TEST_COMPLETED; }