-/**
- * Options that should be evaluated after config is read go here
- */
-bool
-Main::parse_commandline(int argc, char** argv)
-{
- for(int i = 1; i < argc; ++i) {
- std::string arg = argv[i];
-
- if(arg == "--fullscreen" || arg == "-f") {
- g_config->use_fullscreen = true;
- } else if(arg == "--default" || arg == "-d") {
- g_config->use_fullscreen = false;
-
- g_config->window_size = Size(800, 600);
- g_config->fullscreen_size = Size(800, 600);
- g_config->aspect_size = Size(0, 0); // auto detect
-
- } else if(arg == "--window" || arg == "-w") {
- g_config->use_fullscreen = false;
- } else if(arg == "--geometry" || arg == "-g") {
- i += 1;
- if(i >= argc)
- {
- print_usage(argv[0]);
- throw std::runtime_error("Need to specify a size (WIDTHxHEIGHT) for geometry argument");
- }
- else
- {
- int width, height;
- if (sscanf(argv[i], "%dx%d", &width, &height) != 2)
- {
- print_usage(argv[0]);
- throw std::runtime_error("Invalid geometry spec, should be WIDTHxHEIGHT");
- }
- else
- {
- g_config->window_size = Size(width, height);
- g_config->fullscreen_size = Size(width, height);
- }
- }
- } else if(arg == "--aspect" || arg == "-a") {
- i += 1;
- if(i >= argc)
- {
- print_usage(argv[0]);
- throw std::runtime_error("Need to specify a ratio (WIDTH:HEIGHT) for aspect ratio");
- }
- else
- {
- int aspect_width = 0;
- int aspect_height = 0;
- if (strcmp(argv[i], "auto") == 0)
- {
- aspect_width = 0;
- aspect_height = 0;
- }
- else if (sscanf(argv[i], "%d:%d", &aspect_width, &aspect_height) != 2)
- {
- print_usage(argv[0]);
- throw std::runtime_error("Invalid aspect spec, should be WIDTH:HEIGHT or auto");
- }
- else
- {
- float aspect_ratio = static_cast<float>(aspect_width) / static_cast<float>(aspect_height);
-
- // use aspect ratio to calculate logical resolution
- if (aspect_ratio > 1) {
- g_config->aspect_size = Size(static_cast<int>(600 * aspect_ratio + 0.5),
- 600);
- } else {
- g_config->aspect_size = Size(600,
- static_cast<int>(600 * 1/aspect_ratio + 0.5));
- }
- }
- }
- } else if(arg == "--renderer") {
- i += 1;
- if(i >= argc)
- {
- print_usage(argv[0]);
- throw std::runtime_error("Need to specify a renderer for renderer argument");
- }
- else
- {
- g_config->video = VideoSystem::get_video_system(argv[i]);
- }
- } else if(arg == "--show-fps") {
- g_config->show_fps = true;
- } else if(arg == "--no-show-fps") {
- g_config->show_fps = false;
- } else if(arg == "--console") {
- g_config->console_enabled = true;
- } else if(arg == "--noconsole") {
- g_config->console_enabled = false;
- } else if(arg == "--disable-sfx") {
- g_config->sound_enabled = false;
- } else if(arg == "--disable-music") {
- g_config->music_enabled = false;
- } else if(arg == "--play-demo") {
- if(i+1 >= argc) {
- print_usage(argv[0]);
- throw std::runtime_error("Need to specify a demo filename");
- }
- g_config->start_demo = argv[++i];
- } else if(arg == "--record-demo") {
- if(i+1 >= argc) {
- print_usage(argv[0]);
- throw std::runtime_error("Need to specify a demo filename");
- }
- g_config->record_demo = argv[++i];
- } else if(arg == "--debug-scripts" || arg == "-s") {
- g_config->enable_script_debugger = true;
- } else if(arg[0] != '-') {
- g_config->start_level = arg;
- } else {
- log_warning << "Unknown option '" << arg << "'. Use --help to see a list of options" << std::endl;
- return true;