Ejemplo n.º 1
0
void SDLH_Play(void)
{
    musicMutex = !songs.empty();
    while (musicMutex)
    {
        HIDUSER_GetSoundVolume(&currentVolume);
        if (!Mix_PlayingMusic() || (currentVolume == 0 && songs.size() > 1))
        {
            if (song)
            {
                Mix_FreeMusic(song);
                song = nullptr;
            }
            if (Configuration::getInstance().randomMusic())
            {
                currentSong = randomNumbers() % songs.size();
            }
            else
            {
                currentSong = (currentSong + 1) % songs.size();
            }
            song = Mix_LoadMUS(songs[currentSong].c_str());
            Mix_PlayMusic(song, 1);
        }
        if (currentVolume == 0)
        {
            Mix_PauseMusic();
        }
        while (currentVolume == 0 && musicMutex)
        {
            HIDUSER_GetSoundVolume(&currentVolume);
            svcSleepThread(250000000);
        }
        if (Mix_PausedMusic() && musicMutex)
        {
            Mix_ResumeMusic();
        }
        svcSleepThread(250000000);
    }
    donePlaying = true;
}
Ejemplo n.º 2
0
Int_t mtbb101_fillNtuples()
{
   ROOT::EnableThreadSafety();
   // No nuisance for batch execution
   gROOT->SetBatch();

   // Perform the operation sequentially ---------------------------------------

   // Create a random generator and and Ntuple to hold the numbers
   TRandom3 rndm(1);
   TFile ofile("mp101_singleCore.root", "RECREATE");
   TNtuple randomNumbers("singleCore", "Random Numbers", "r");
   fillRandom(randomNumbers, rndm, nNumbers);
   randomNumbers.Write();
   ofile.Close();

   // We now go MP! ------------------------------------------------------------

   // We define our work item
   auto workItem = [](UInt_t workerID) {
      // One generator, file and ntuple per worker
      TRandom3 workerRndm(workerID); // Change the seed
      TFile ofile(Form("mp101_multiCore_%u.root", workerID), "RECREATE");
      TNtuple workerRandomNumbers("multiCore", "Random Numbers", "r");
      fillRandom(workerRandomNumbers, workerRndm, workSize);
      workerRandomNumbers.Write();
      return 0;
   };

   // Create the pool of workers
   ThreadPool pool(nThreads);

   // Fill the pool with work
   pool.Map(workItem, ROOT::TSeqI(nThreads));

   return 0;

}
Ejemplo n.º 3
0
Int_t mt101_fillNtuples(UInt_t nWorkers = 4)
{

   // No nuisance for batch execution
   gROOT->SetBatch();

   // Total amount of numbers
   const UInt_t nNumbers = 20000000U;

   // A simple function to fill ntuples randomly

   auto fillRandom = [](TNtuple & ntuple, TRandom3 & rndm, UInt_t n) {
      for (UInt_t i = 0; i < n; ++i) ntuple.Fill(rndm.Gaus());
   };

   // Perform the operation sequentially ---------------------------------------

   // Create a random generator and and Ntuple to hold the numbers
   TRandom3 rndm(1);
   TFile ofile("mt101_singleCore.root", "RECREATE");
   TNtuple randomNumbers("singleCore", "Random Numbers", "r");

   // Now let's measure how much time we need to fill it up
   {
      TimerRAII t("Sequential execution");
      fillRandom(randomNumbers, rndm, nNumbers);
      randomNumbers.Write();
   }


   // We now go MT! ------------------------------------------------------------

   // The first, fundamental operation to be performed in order to make ROOT
   // thread-aware.
   ROOT::EnableThreadSafety();

   // We define our work item
   auto workItem = [&fillRandom](UInt_t workerID, UInt_t workSize) {
      // One generator, file and ntuple per worker
      TRandom3 workerRndm(workerID); // Change the seed
      TFile ofile(Form("mt101_multiCore_%u.root", workerID), "RECREATE");
      TNtuple workerRandomNumbers("multiCore", "Random Numbers", "r");
      fillRandom(workerRandomNumbers, workerRndm, workSize);
      workerRandomNumbers.Write();
   };

   // Create the collection which will hold the threads, our "pool"
   std::vector<std::thread> workers;

   // We measure time here as well
   {
      TimerRAII t("Parallel execution");

      // We split the work in equal parts
      const auto workSize = nNumbers / nWorkers;

      // Fill the "pool" with workers
      for (UInt_t workerID = 0; workerID < nWorkers; ++workerID) {
         workers.emplace_back(workItem, workerID, workSize);
      }

      // Now join them
      for (auto && worker : workers) worker.join();
   }

   return 0;

}
Ejemplo n.º 4
0
void Sav6::trade(std::shared_ptr<PKX> pk)
{
    PK6 *pk6 = (PK6*)pk.get();
    if (pk6->egg())
    {
        if (otName() != pk6->otName() || TID() != pk6->TID() || SID() != pk6->SID() || gender() != pk6->otGender())
        {
            pk6->metDay(Configuration::getInstance().day());
            pk6->metMonth(Configuration::getInstance().month());
            pk6->metYear(Configuration::getInstance().year() - 2000);
            pk6->metLocation(30002);
        }
        return;
    }
    else if (otName() == pk6->otName() && TID() == pk6->TID() && SID() == pk6->SID() && gender() == pk6->otGender())
    {
        pk6->currentHandler(0);

        if (!pk6->untraded() && (country() != pk6->geoCountry(0) || subRegion() != pk6->geoRegion(0)))
        {
            for (int i = 4; i > 0; i--)
            {
                pk6->geoCountry(pk6->geoCountry(i - 1), i);
                pk6->geoRegion(pk6->geoRegion(i - 1), i);
            }
            pk6->geoCountry(country());
            pk6->geoRegion(subRegion());
        }
    }
    else
    {
        if (otName() != pk6->htName() || gender() != pk6->htGender() || (pk6->geoCountry(0) == 0 && pk6->geoRegion(0) == 0 && !pk6->untradedEvent()))
        {
            for (int i = 4; i > 0; i--)
            {
                pk6->geoCountry(pk6->geoCountry(i - 1), i);
                pk6->geoRegion(pk6->geoRegion(i - 1), i);
            }
            pk6->geoCountry(country());
            pk6->geoRegion(subRegion());
        }

        if (pk6->htName() != otName())
        {
            pk6->htFriendship(pk6->baseFriendship());
            pk6->htAffection(0);
            pk6->htName(otName());
        }
        pk6->currentHandler(1);
        pk6->htGender(gender());

        if (pk6->htMemory() == 0)
        {
            pk6->htMemory(4);
            pk6->htTextVar(9);
            pk6->htIntensity(1);

            /*static constexpr u32 memoryBits[70] = { 
                0x000000, 0x04CBFD, 0x004BFD, 0x04CBFD, 0x04CBFD, 0xFFFBFB, 0x84FFF9, 0x47FFFF, 0xBF7FFA, 0x7660B0,
                0x80BDF9, 0x88FB7A, 0x083F79, 0x0001FE, 0xCFEFFF, 0x84EBAF, 0xB368B0, 0x091F7E, 0x0320A0, 0x080DDD,
                0x081A7B, 0x404030, 0x0FFFFF, 0x9A08BC, 0x089A7B, 0x0032AA, 0x80FF7A, 0x0FFFFF, 0x0805FD, 0x098278,
                0x0B3FFF, 0x8BBFFA, 0x8BBFFE, 0x81A97C, 0x8BB97C, 0x8BBF7F, 0x8BBF7F, 0x8BBF7F, 0x8BBF7F, 0xAC3ABE,
                0xBFFFFF, 0x8B837C, 0x848AFA, 0x88FFFE, 0x8B0B7C, 0xB76AB2, 0x8B1FFF, 0xBE7AB8, 0xB77EB8, 0x8C9FFD,
                0xBF9BFF, 0xF408B0, 0xBCFE7A, 0x8F3F72, 0x90DB7A, 0xBCEBFF, 0xBC5838, 0x9C3FFE, 0x9CFFFF, 0x96D83A,
                0xB770B0, 0x881F7A, 0x839F7A, 0x839F7A, 0x839F7A, 0x53897F, 0x41BB6F, 0x0C35FF, 0x8BBF7F, 0x8BBF7F 
            };*/

            u32 bits = 0x04CBFD; //memoryBits[pk6->htMemory()];
            while (true)
            {
                u32 feel = randomNumbers() % 20;
                if ((bits & (1 << feel)) != 0)
                {
                    pk6->htFeeling(feel);
                    break;
                }
            }
        }
    }
}