void RandomGenerator::init()
{
    typedef std::chrono::high_resolution_clock Clock;

    Clock::duration distance = Clock::now().time_since_epoch();
    __initGenerator = Generator(distance.count());
    __initDistrib = Distribution(0, distance.count());
}
Exemplo n.º 2
0
/*!
  */
double SimpleRenderer::getCurrentFps(const uint32 cycle,
                                     const Clock::duration& time) const noexcept
{
  static_assert(std::milli::den <= Clock::period::den, 
                "The tick period should be smaller or equal than milli.");

  using zisc::cast;

  constexpr uint64 k = cast<uint64>(Clock::period::den);
  const auto time_count = time.count();
  const double fps = cast<double>(k * cycle) /
                     cast<double>((time_count == 0) ? 1 : time_count);

  return fps;
}
Exemplo n.º 3
0
/*!
  */
void SimpleRenderer::notifyOfRenderingProgress(
    const uint32 cycle,
    const Clock::duration& time,
    const std::string_view& status) const noexcept
{
  if (progress_callback_) {
    const double cycle_progress = (0 < cycleToFinish())
        ? zisc::cast<double>(cycle) / zisc::cast<double>(cycleToFinish())
        : 0.0;
    const auto time_to_finish = timeToFinish().count();
    const double time_progress = (0 < time_to_finish)
        ? zisc::cast<double>(time.count()) / zisc::cast<double>(time_to_finish)
        : 0.0;
    double progress = zisc::max(cycle_progress, time_progress);
    progress = zisc::clamp(progress, 0.0, 1.0);
    progress_callback_(progress, status);
  }
}
Exemplo n.º 4
0
void NetworkTopology::advance_time(Clock::duration t)
{
    const Clock::duration max_step = std::chrono::milliseconds(500);
    do {
        const auto step = std::min(t, max_step);
        now += step;
        t -= step;
        // update timestamp for every router
        for (auto& host : hosts) {
            Runtime& runtime = host.second->runtime;
            runtime.trigger(now);
            Router& router = host.second->router;
            LongPositionVector lpv = router.get_local_position_vector();
            lpv.timestamp = now;
            router.update(lpv);
        }
        dispatch();
    } while (t.count() > 0);
}
Exemplo n.º 5
0
void SpellHistory::ModifyCooldown(uint32 spellId, Clock::duration offset)
{
    auto itr = _spellCooldowns.find(spellId);
    if (!offset.count() || itr == _spellCooldowns.end())
        return;

    Clock::time_point now = Clock::now();

    if (itr->second.CooldownEnd + offset > now)
        itr->second.CooldownEnd += offset;
    else
        EraseCooldown(itr);

    if (Player* playerOwner = GetPlayerOwner())
    {
        WorldPackets::Spells::ModifyCooldown modifyCooldown;
        modifyCooldown.IsPet = _owner != playerOwner;
        modifyCooldown.SpellID = spellId;
        modifyCooldown.DeltaTime = std::chrono::duration_cast<std::chrono::milliseconds>(offset).count();
        playerOwner->SendDirectMessage(modifyCooldown.Write());
    }
}
Exemplo n.º 6
0
 /**
 @brief  turn the duration into seconds unit
  the duration is using std::chrono::system_clock, 
  which the unit is in "microseconds..."
 
 @param d
 
 @return duration in second units...
 */
 static double duration_to_second(Clock::duration d){
     return d.count() / 1'000'000.0;
 }