コード例 #1
0
ファイル: Particle.cpp プロジェクト: ddamiani/cosmic-sim
void Particle::Propagate() {
  m_decay = TerminalDecay();

  if(m_decay != UNDECAYED) {
    double final_position = m_term_dist + m_position;
    if(final_position < END_POSITION) {
      CheckPositionResult(final_position);
      m_position = final_position;
      m_energy = END_ENERGY;
    } else {
      m_position = END_POSITION;
      m_decay = END;
    }

    return ;
  }

  double new_position = RandomMT::MeanFree(m_rad_length) + m_position;
  
  if(new_position < END_POSITION) {
    CheckPositionResult(new_position);

    // Decay the particle and create the children
    m_position = new_position;
    m_decay = Decay();
    m_energy = END_ENERGY;
    // Propogate the first child
    m_child_1->Propagate();
    delete m_child_1;
    m_child_1 = NULL;
    // Propogate the second child
    m_child_2->Propagate();
    delete m_child_2;
    m_child_2 = NULL;
  } else {
    m_position = END_POSITION;
    m_decay = END;
  }
}
コード例 #2
0
ファイル: leaves.cpp プロジェクト: Almamu/mineserver
void BlockLeaves::onNeighbourBroken(User* user, int16_t oldblock, int32_t x, int16_t y, int32_t z, int map, int8_t direction)
{
  if ( (oldblock != BLOCK_WOOD && oldblock != BLOCK_LEAVES)   ||
       std::find_if(decaying.begin(), decaying.end(), DecayFinder(x,y,z,map)) != decaying.end() )
  {
    return;
  }

  for (int xi = -2; xi <= 2; ++xi)
    for (int yi = -2; yi <= 2; ++yi)
      for (int zi = -2; zi <= 2; ++zi)
        if (std::abs(xi) + std::abs(yi) + std::abs(zi) <= 3)
        {
          uint8_t block, meta;

          ServerInstance->map(map)->getBlock(x + xi, y + yi, z + zi, &block, &meta);

          if (block == BLOCK_WOOD) return;
        }

  decaying.insert(Decay(time(0), x, y, z, map));
}
コード例 #3
0
	void CacheBasedLanguageModel::Insert(std::vector<std::string> ngrams)
	{
		Decay();
		Update(ngrams,1);
		IFVERBOSE(2) Print();
	}
コード例 #4
0
ファイル: WaveComputer.cpp プロジェクト: Advi42/XCSoar
void
WaveComputer::Compute(const NMEAInfo &basic,
                      const FlyingState &flight,
                      WaveResult &result,
                      const WaveSettings &settings)
{
  const bool new_enabled = settings.enabled;
  if (new_enabled != last_enabled) {
    last_enabled = new_enabled;

    if (new_enabled) {
      /* the WaveComputer has just been enabled - initialise internal
         state */
      Initialise();
    } else
      /* the WaveComputer has just been disabled - clear the result */
      result.Clear();
  }

  if (!new_enabled) {
    /* we're disabled: bail out */
    assert(result.waves.empty());
    return;
  }

  if (!flight.IsGliding()) {
    /* no wave calculations while not in gliding free-flight */
    ResetCurrent();
    return;
  }

  const auto netto_vario_available = GetNettoVarioAvailable(basic);
  if (!basic.location_available.Modified(last_location_available) ||
      !netto_vario_available.Modified(last_netto_vario_available))
    /* no new data since the last call; need both a new GPS location
       and a vario value */
    return;

  const auto dt = delta_time.Update(basic.time, 0.5, 20);
  if (dt < 0)
    /* time warp */
    Reset();

  if (dt <= 0)
    /* throttle */
    return;

  const auto vario = basic.netto_vario;

  constexpr double threshold(0.5);
  if (vario > threshold) {
    /* positive vario value - feed it to the #LeastSquares instance */

    if (ls.IsEmpty())
      /* initialise the projection each time we inspect a new wave
         "candidate" */
      projection.SetCenter(basic.location);

    auto flat = projection.ProjectFloat(basic.location);
    ls.Update(flat.x, flat.y, vario - threshold / 2);
  }

  if (vario < 0)
    sinking_clock.Add(dt);
  else
    sinking_clock.Subtract(dt);

  const bool sinking = sinking_clock >= dt + 1;
  if (sinking) {
    /* we've been sinking; stop calculating the current wave; prepare
       to flush the #LeastSquares instance */
    if (ls.GetCount() > 30) {
      /* we've been lifting in the wave for some time; see if we
         really spotted a wave */
      const WaveInfo wave = GetWaveInfo(ls, projection,
                                        basic.time_available ? basic.time : 0);
      if (wave.IsDefined())
        /* yes, spotted a wave: copy it from the #LeastSquares
           instance to the list of waves */
        FoundWave(wave);
    }

    ls.Reset();
  }

  if (basic.time_available)
    /* forget all waves which are older than 8 hours */
    Decay(basic.time - 8 * 3600);

  /* fill the #WaveResult */

  result.Clear();

  /* first copy the wave that is currently being calculated (partial
     data) */
  WaveInfo wave = GetWaveInfo(ls, projection,
                              basic.time_available ? basic.time : 0);
  if (wave.IsDefined())
    result.waves.push_back(wave);

  /* now copy the rest */
  for (auto i = waves.begin(), end = waves.end();
       i != end && !result.waves.full(); ++i)
    result.waves.push_back(*i);

  /* remember some data for the next iteration */
  last_location_available = basic.location_available;
  last_netto_vario_available = netto_vario_available;
}