bool BenchmarkMenu::Launch(BenchItem *b) { if (!b) return false; bool ok = false; float score = 0.0f; const char *fmt = ""; switch (b->type) { case BENCH_MENU: { Stopwatch clock; delete (new OptionMenu()); score = 1000.0f / clock.GetValue(); fmt = "%.3f"; ok = true; break; } case BENCH_GRAPHICS: { graph->UnsetResults(); // Backup and set playing teams std::vector<Team*> list_bak = GetTeamsList().GetPlayingList(); std::list<uint> sel; sel.push_back(1); sel.push_back(2); GetTeamsList().ChangeSelection(sel); // Backup and set team configuration - make it quick ;) std::vector<Team*>& list = GetTeamsList().GetPlayingList(); for (uint i=0; i<list.size(); i++) { printf("Setting %s\n", list[i]->GetName().c_str()); list[i]->SetPlayerName("CPU"); list[i]->SetNbCharacters(10); list[i]->SetAIName(STRONG_AI_NAME); list[i]->SetGroup(i); } // Backup and set game mode Config *cfg = Config::GetInstance(); std::string game_mode = cfg->GetGameMode(); cfg->SetGameMode("benchmark"); GameMode::GetInstance()->Load(); // Backup and set some config options uint wind_particles = cfg->GetWindParticlesPercentage(); cfg->SetWindParticlesPercentage(100); bool display_energy = cfg->GetDisplayEnergyCharacter(); cfg->SetDisplayEnergyCharacter(true); bool display_multisky = cfg->GetDisplayMultiLayerSky(); cfg->SetDisplayMultiLayerSky(false); // Mute all sounds JukeBox *jbox = JukeBox::GetInstance(); bool music = cfg->GetSoundMusic(); jbox->ActiveMusic(false); bool sfx = cfg->GetSoundEffects(); cfg->SetSoundEffects(false); // Backup and set default map - should I save the config? std::string map_name = cfg->GetMapName(); MapsList *maps = MapsList::GetInstance(); int map_id_bak = maps->GetActiveMapIndex(); maps->SelectMapByName("banquise"); if (!maps->lst[maps->GetActiveMapIndex()]->LoadBasicInfo()) { fmt = "Error!"; break; } // Set max FPS Video *video = AppWarmux::GetInstance()->video; int fps = video->GetMaxFps(); video->SetMaxFps(60); // Set seeds - we'll set random ones afterwards RandomLocal().SetSeed(0xABADCAFE); RandomSync().SetSeed(0xABADCAFE); // All set, run the game! float num = Game::UpdateGameRules()->Start(true); if (num) { GraphCanvas::Result res; res.list = Game::GetInstance()->GetBenchResults(); GraphCanvas::FindMax(res); float time = res.xmax - res.list[0].first; score = (num * video->window.GetWidth()*video->window.GetHeight()) / (1000.0f * time); fmt = "%.0f"; res.item = NULL; res.color = primary_red_color; graph->AddResult(res); } else { fmt = "Aborted"; } graph->NeedRedrawing(); // Restore all! video->SetMaxFps(fps); jbox->ActiveMusic(music); cfg->SetSoundEffects(sfx); maps->SelectMapByIndex(map_id_bak); cfg->SetMapName(map_name); cfg->SetDisplayMultiLayerSky(display_multisky); cfg->SetDisplayEnergyCharacter(display_energy); cfg->SetWindParticlesPercentage(wind_particles); cfg->SetGameMode(game_mode); GetTeamsList().SetPlayingList(list_bak); ok = num == 0; break; } default: break; } b->SetScore(fmt, score); return ok; }