Exemplo n.º 1
0
int JukeBox::Play(const std::string& category, const std::string& sample,
                  const int loop)
{
  if (!Config::GetInstance()->GetSoundEffects() || !m_init) return -1;

  uint nb_sounds= m_soundsamples.count(category+ "/" +sample);
  if (nb_sounds) {
    std::pair<sample_iterator, sample_iterator> p =
      m_soundsamples.equal_range(category+ "/" +sample);
    sample_iterator it = p.first;

    // Choose a random sound sample
    if (nb_sounds > 1) {
      uint selection = RandomLocal().GetUint(0, nb_sounds);
      if (selection == nb_sounds) --selection ;

      it = p.first ;

      for (uint i=0; i<selection && it!=p.second; ++i) it++ ;
    }

    // Play the sound
    Mix_Chunk * sampleChunk = m_cache.LoadSound(it->second.filename.c_str());
    MSG_DEBUG("jukebox.play", "Playing sample %s/%s",
              category.c_str(), sample.c_str());

    return PlaySample(sampleChunk, it->second.level, loop);
  } else if (category != "default") {
    return Play("default", sample, loop) ; // try with default profile
  }

  std::cerr << "Sound error: No sound found for sample" << category.c_str()
            << "/" << sample.c_str() << std::endl;
  return -1;
}
Exemplo n.º 2
0
AppWarmux::AppWarmux():
  video(new Video()),
  menu(NULL)
{
  RandomLocal().InitRandom();
  std::cout << "[ " << _("Run game") << " ]" << std::endl;
}
Exemplo n.º 3
0
bool JukeBox::PlayMusic(const std::string& type)
{
  if (m_init == false || !Config::GetInstance()->GetSoundMusic())
    return false;

  PlayListMap::iterator it = playlist.find(type);

  if (it == playlist.end()) {
    std::cerr << "[Music] Unable to find " << type << " profile" << std::endl;
    if (type == "ingame") {
      return false;
    } else {
      return PlayMusic("ingame");
    }
  }


  MSG_DEBUG("jukebox", "Loading playlist %s", type.c_str());

  StopMusic();

  if (it->second.empty() || !Config::GetInstance()->GetSoundMusic())
    return false;

  playing_pl = it;

  int i, j = 0;
  do {
    i = RandomLocal().GetInt(0,it->second.size()-1);
    j++;
  } while(!PlayMusicSample(it->second.begin()+i) && j < 10); // After 10 times, we think there is a problem.

  if (j >= 10)
    playing_pl = playlist.end();

  return (j < 10);
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
void ParseArgs(int argc, char * argv[])
{
  int c;
  int option_index = 0;
  struct option long_options[] = {
    {"unrandom",   no_argument,       NULL, 'u'},
    {"force-refresh", no_argument,    NULL, 'f'},
    {"help",       no_argument,       NULL, 'h'},
    {"version",    no_argument,       NULL, 'v'},
    {"play",       no_argument,       NULL, 'p'},
    {"quick-quit", no_argument,       NULL, 'q'},
    {"client",     optional_argument, NULL, 'c'},
    {"server",     no_argument,       NULL, 's'},
    {"index-server", optional_argument, NULL, 'i'},
    {"game-mode",  required_argument, NULL, 'g'},
    {"debug",      required_argument, NULL, 'd'},
    {"reset-config", no_argument,     NULL, 'r'},
    {"size",       required_argument, NULL, 'S'},
    {"replay",     required_argument, NULL, 'R'},
    {NULL,         no_argument,       NULL,  0 }
  };

  while ((c = getopt_long(argc, argv, "ufhvpqc::si::g:d:rS:R:",
                          long_options, &option_index)) != -1) {
    switch (c) {
    case 'u':
      RandomSync().UnRandom();
      RandomLocal().UnRandom();
      break;
    case 'f':
      // This option is useful to run with valgrind
      extern bool force_refresh;
      force_refresh = true;
      break;
    case 'h':
      PrintUsage(argv[0]);
      exit(EXIT_SUCCESS);
      break;
    case 'v':
      DisplayWelcomeMessage();
      exit(EXIT_SUCCESS);
      break;
    case 'p':
      choice = MainMenu::PLAY;
      skip_menu = true;
      break;
    case 'c':
      choice = MainMenu::NETWORK;
      net_action = NetworkConnectionMenu::NET_CONNECT;
      if (optarg)
        {
          Config::GetInstance()->SetNetworkClientHost(optarg);
        }
      skip_menu = true;
      break;
    case 'd':
#ifdef WMX_LOG
      printf("Debug: %s\n", optarg);
      AddDebugMode(optarg);
#else
      fprintf(stderr, "Option -d is not available. Warmux has not been compiled with debug/logging option.\n");
#endif
      break;
    case 'R':
      replay = optarg;
      break;
    case 's':
      choice = MainMenu::NETWORK;
      net_action = NetworkConnectionMenu::NET_HOST;
      skip_menu = true;
      break;
    case 'i':
      {
        std::string index_server_address;
        if (optarg) index_server_address = optarg;
        else index_server_address = "127.0.0.1";
        printf("Using %s as address for index server. This option must be used only for debugging.\n",
               index_server_address.c_str());
        IndexServer::GetInstance()->SetAddress(index_server_address.c_str());
      }
      break;
    case 'g':
      printf("Game-mode: %s\n", optarg);
      Config::GetInstance()->SetGameMode(optarg);
      break;
    case 'q':
      quit_game = true; // immediately exit the game after first run
      break;
    case 'r':
      {
        bool r;
        r = Config::GetInstance()->RemovePersonalConfigFile();
        if (!r)
          exit(EXIT_FAILURE);
        exit(EXIT_SUCCESS);
      }
      break;
    case 'S':
      {
	      uint width, height;
	      int ret = sscanf(optarg, "%ux%u", &width, &height);
	      if (ret == 2) {
	        Config::GetInstance()->SetVideoWidth(width);
	        Config::GetInstance()->SetVideoHeight(height);
	      } else {
	        fprintf(stderr, "Error: %s is not a valid resolution\n", optarg);
	      }
      }
      break;
    case '?': /* returns by getopt if option was invalid */
      PrintUsage(argv[0]);
      exit(EXIT_FAILURE);
      break;

    default:
      fprintf(stderr, "Sorry, it seems that option '-%c' is not implemented!\n", c);
      ASSERT(false);
      exit(EXIT_FAILURE);
      break;
    }
  }
}