bool projectM::writeConfig(const std::string & configFile, const Settings & settings) { ConfigFile config ( configFile ); config.add("Mesh X", settings.meshX); config.add("Mesh Y", settings.meshY); config.add("Texture Size", settings.textureSize); config.add("FPS", settings.fps); config.add("Window Width", settings.windowWidth); config.add("Window Height", settings.windowHeight); config.add("Smooth Preset Duration", settings.smoothPresetDuration); config.add("Preset Duration", settings.presetDuration); config.add("Preset Path", settings.presetURL); config.add("Title Font", settings.titleFontURL); config.add("Menu Font", settings.menuFontURL); config.add("Hard Cut Sensitivity", settings.beatSensitivity); config.add("Aspect Correction", settings.aspectCorrection); config.add("Easter Egg Parameter", settings.easterEgg); config.add("Shuffle Enabled", settings.shuffleEnabled); config.add("Soft Cut Ratings Enabled", settings.softCutRatingsEnabled); std::fstream file(configFile.c_str()); if (file) { file << config; return true; } else return false; }
void Initialize(int argc, char *argv[]) { // Process command line arguments for (int i = 0; i < argc - 1; ++i) { if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--map-width")) gameWidth = atof(argv[++i]); else if (!strcmp(argv[i], "-y") || !strcmp(argv[i], "--map-height")) gameHeight = atof(argv[++i]); else if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "--path")) path = argv[++i]; else if (!strcmp(argv[i], "-w") || !strcmp(argv[i], "--screen-width")) windowWidth = atoi(argv[++i]); else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--screen-height")) windowHeight = atoi(argv[++i]); } // Process config file if (!file_exists(CONFIG_FILE)) { ConfigFile newconfig; newconfig.add("playername", "Unnamed"); newconfig.add("team", 'a'); newconfig.save(CONFIG_FILE); } try { config = new ConfigFile(CONFIG_FILE); } catch (ConfigFile::file_not_found e) { delete config; config = NULL; puts("Unable to create config file: " CONFIG_FILE "!"); exit(EXIT_FAILURE); } fullscreen = (config->read("fullscreen", '0')) == '1'? true : false; /* deprecated: for (int i = 0; i < argc; ++i) { if (!strcmp(argv[i], "--fullscreen")) fullscreen = true; }*/ // Global subsystem initializations srand(time(NULL)); // Create window and set up viewports game.window = new Video::Window(windowWidth, windowHeight, GAME_NAME, fullscreen); Video::Viewport *view = new Video::Viewport(1,1); game.window->viewports.push_back(view); // Show loading screen // Problem: we can't use the hud prior to asset loading // Load game assets Assets::Initialize(argc, argv); config->readInto(NetCode::MessageOfTheDay, "motd", string("No message of the day ;(")); // Set up game world game.root = World(gameWidth, gameHeight); game.world = TO(World,game.root); game.topId = 1; game.teams.insert(make_pair('a', Team('a'))); game.teams.insert(make_pair('b', Team('b'))); string name; unsigned char team; config->readInto(name, "playername", string("Unnamed")); team = config->read("team", 'a'); Player::Id pid = game.topId++; ObjectHandle player = Player(pid, team, name); game.player = TO(Player,player); game.player->weapon = weapLaser; game.player->origin = getSpawn(team); game.root->children.insert(player); game.players[pid] = player; game.world->terrain->placeStructure(GridPoint(2,2), Mine()); game.world->terrain->placeStructure(GridPoint(2,48), Mine()); game.world->terrain->placeStructure(GridPoint(48,2), Mine()); game.world->terrain->placeStructure(GridPoint(48,48), Mine()); game.world->terrain->placeStructure(GridPoint(25,25), RichMine()); game.world->terrain->placeStructure(GridPoint(15,25), Mine()); game.world->terrain->placeStructure(GridPoint(35,25), Mine()); game.world->terrain->placeStructure(GridPoint(25,5), RichMine()); game.world->terrain->placeStructure(GridPoint(25,45), RichMine()); game.world->terrain->placeStructure(GridPoint(6,9), Mine()); game.world->terrain->placeStructure(GridPoint(6,41), Mine()); game.world->terrain->placeStructure(GridPoint(44,9), Mine()); game.world->terrain->placeStructure(GridPoint(44,41), Mine()); game.world->terrain->placeStructure(GridPoint(10,17), Mine()); game.world->terrain->placeStructure(GridPoint(10,33), Mine()); game.world->terrain->placeStructure(GridPoint(40,17), Mine()); game.world->terrain->placeStructure(GridPoint(40,33), Mine()); ObjectHandle RedBot = player; ObjectHandle BlueBot = player; if (team == 'b') { RedBot = Player(INT_MAX - 'a', 'a', "RedBot", Pd(-1000,-1000,-1000)); //game.world->children.insert(RedBot); game.players[TO(Player, RedBot)->id] = RedBot; } else if (team == 'a') { BlueBot = Player(INT_MAX - 'b', 'b', "BlueBot", Pd(-1000,-1000,-1000)); //game.world->children.insert(BlueBot); game.players[TO(Player, BlueBot)->id] = BlueBot; } game.world->terrain->placeStructure(GridPoint(3,25), HeadQuarters(TO(Player, BlueBot)->id)); game.world->terrain->placeStructure(GridPoint(48,26), HeadQuarters(TO(Player, RedBot)->id)); game.world->terrain->placeStructure(GridPoint(4,26), DefenseTower(TO(Player, BlueBot)->id)); game.world->terrain->placeStructure(GridPoint(4,23), DefenseTower(TO(Player, BlueBot)->id)); game.world->terrain->placeStructure(GridPoint(46,27), DefenseTower(TO(Player, RedBot)->id)); game.world->terrain->placeStructure(GridPoint(46,24), DefenseTower(TO(Player, RedBot)->id)); for(int i = 0; i <= 50; i++) { game.world->terrain->placeStructure(GridPoint(0,i), Wall()); game.world->terrain->placeStructure(GridPoint(50,i), Wall()); game.world->terrain->placeStructure(GridPoint(i,0), Wall()); game.world->terrain->placeStructure(GridPoint(i,50), Wall()); } for(int i = 8; i <= 42; i++) { if (i < 23 || i > 27) { game.world->terrain->placeStructure(GridPoint(25,i), Wall()); game.world->terrain->placeStructure(GridPoint(i,5), Wall()); game.world->terrain->placeStructure(GridPoint(i,45), Wall()); } if (i < 22 || i > 28) { game.world->terrain->placeStructure(GridPoint(i,15), Wall()); game.world->terrain->placeStructure(GridPoint(i,35), Wall()); } if (i < 13 || i > 37) { game.world->terrain->placeStructure(GridPoint(i,25), Wall()); } } for (int i = 5; i <=11; i++) { game.world->terrain->placeStructure(GridPoint(4,i), Wall()); game.world->terrain->placeStructure(GridPoint(46,i), Wall()); game.world->terrain->placeStructure(GridPoint(i,11), Wall()); game.world->terrain->placeStructure(GridPoint(i,39), Wall()); } for (int i = 39; i <=45; i++) { game.world->terrain->placeStructure(GridPoint(4,i), Wall()); game.world->terrain->placeStructure(GridPoint(46,i), Wall()); game.world->terrain->placeStructure(GridPoint(i,11), Wall()); game.world->terrain->placeStructure(GridPoint(i,39), Wall()); } for (int i = 15; i <= 35; i++) { game.world->terrain->placeStructure(GridPoint(8,i), Wall()); game.world->terrain->placeStructure(GridPoint(42,i), Wall()); } for (int i = 3; i <= 47; i++) { if (i < 12 || i > 38 || (i > 19 && i < 31)) { game.world->terrain->placeStructure(GridPoint(18,i), Wall()); game.world->terrain->placeStructure(GridPoint(32,i), Wall()); } } for (int i = 13; i <= 37; i++) { if (i < 18 || i > 32) { game.world->terrain->placeStructure(GridPoint(i,20), Wall()); game.world->terrain->placeStructure(GridPoint(i,30), Wall()); } } game.world->terrain->placeStructure(GridPoint(11,1), Wall()); game.world->terrain->placeStructure(GridPoint(11,2), Wall()); game.world->terrain->placeStructure(GridPoint(11,49), Wall()); game.world->terrain->placeStructure(GridPoint(11,48), Wall()); game.world->terrain->placeStructure(GridPoint(39,1), Wall()); game.world->terrain->placeStructure(GridPoint(39,2), Wall()); game.world->terrain->placeStructure(GridPoint(39,49), Wall()); game.world->terrain->placeStructure(GridPoint(39,48), Wall()); // Set up user interface view->world = game.root; game.controller = new Controller(view->camera, player); game.input = new Input(*game.window); game.input->onKeyUp = KeyUp; game.input->onKeyDown = KeyDown; //input->onMouseMove = MouseMove; Echo("Everything loaded!"); Echo("Welcome to the game"); Echo(NetCode::MessageOfTheDay); }
void Configuration::write() { ConfigFile cFile; cFile.add("aimColorB", AimColorB); cFile.add("aimColorA", AimColorA); cFile.add("soundVolume", SoundVolume); cFile.add("musicVolume", MusicVolume); cFile.add("autoReload", AutoReload); cFile.add("showFps", ShowFps); cFile.add("frameDelay", FrameDelay); cFile.add("fullScreen", Screen.Full); cFile.add("screenColor", Screen.Color); cFile.add("screenHeight", Screen.Height); cFile.add("screenWidth", Screen.Width); cFile.add("autoWeaponPickup", AutoWeaponPickup); cFile.add("friendlyFire", FriendlyFire); cFile.add("controlStyle", Control); for (int i = 0; i < InputHandler::GameInputEventsCount; i++) { WritePlayerBinding(&cFile, &PlayerInputBinding[i], InputHandler::getEventIdentifier(i)); } boost::filesystem::ofstream ofile( m_fileUtility->getFullPath(FileUtility::user, "config")); if (ofile) { ofile << cFile; ofile.close(); } }