void
World::action(double frame_ratio)
{
  tux.action(frame_ratio);
  tux.check_bounds(level->back_scrolling, (bool)level->hor_autoscroll_speed);
  scrolling(frame_ratio);

  /* Handle bouncy distros: */
  for (unsigned int i = 0; i < bouncy_distros.size(); i++)
    bouncy_distros[i]->action(frame_ratio);

  /* Handle broken bricks: */
  for (unsigned int i = 0; i < broken_bricks.size(); i++)
    broken_bricks[i]->action(frame_ratio);

  // Handle all kinds of game objects
  for (unsigned int i = 0; i < bouncy_bricks.size(); i++)
    bouncy_bricks[i]->action(frame_ratio);
  
  for (unsigned int i = 0; i < floating_scores.size(); i++)
    floating_scores[i]->action(frame_ratio);

  for (unsigned int i = 0; i < bullets.size(); ++i)
    bullets[i].action(frame_ratio);
  
  for (unsigned int i = 0; i < upgrades.size(); i++)
    upgrades[i].action(frame_ratio);

  for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
    (*i)->action(frame_ratio);

  /* update particle systems */
  std::vector<ParticleSystem*>::iterator p;
  for(p = particle_systems.begin(); p != particle_systems.end(); ++p)
    {
      (*p)->simulate(frame_ratio);
    }

  /* Handle all possible collisions. */
  collision_handler();
  
  // Cleanup marked badguys
  for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end();
      /* ++i handled at end of the loop */) {
    if ((*i)->is_removable()) {
      delete *i;
      i =  bad_guys.erase(i);
    } else {
      ++i;
    }
  }
}
unsigned int HashTableCounter::hashfunc(const unsigned int k_item[]) const {
	unsigned int hashcode = m_hash_func(k_item, m_dimension, m_table_size);
	if (NULL == m_hash_table[hashcode])
		return hashcode;
	else {
		bool equal = true;
		for (unsigned int i = 0; i < m_dimension; i++) {
			if (m_hash_table[hashcode][i] != k_item[i]) {
				equal = false;
				break;
			}
		}
		if (equal)
			return hashcode;
		else
			return collision_handler(k_item, hashcode);
	}
}
Exemple #3
0
void rigid_sys::update(number_t t0,number_t tn)
{

	int i;
	int N=dynamics.size();
	number_t h=step_max;
	number_t err=0;
	
	vector<dynamic_info> y=dynamics,z=dynamics,y_temp=dynamics,z_temp=dynamics,y_back;
	RK temp;
	//adaptive
	while(t0<=tn)
	{
		while(1)
		{
			err=0;
			temp=delta(y,t0,h);
			for(i=0;i<N;i++)
			{
				y_temp[i]=y[i]+temp.RK4[i];
				z_temp[i]=z[i]+temp.RK5[i];
				
				dynamic_info diff=y_temp[i]-z_temp[i];
				err+=diff.L.len2()+diff.P.len2()+diff.q.len2()+diff.x.len2();
			}
			err=sqrt(err);
			//y_temp.at(N)=y.at(N);
			if(err<=err_max && err>=err_min)
			{
				y_back=y;
				y=y_temp;
				z=z_temp;
				break;
			}

			if(err>=err_max)
			{
				if(h==step_min)
				{
					cout<<"not accurate at t="<<t0+h<<endl;
					y_back=y;
					y=y_temp;
					z=z_temp;
					break;
				}
				h=max(step_min,h/2.0);
				continue;
			}

			if(err<err_min)
			{
				h=min(step_max,h*2);
				y_back=y;
				y=y_temp;
				z=z_temp;
				break;
			}
		}
		if(collision_dectect(y))
		{
			//bisection to find the time
			//int itr=2;
			number_t dtl=0,dtr=h;
			vector<dynamic_info> rk4;
			for(int i=0;i<iteration_conllision_rollback;i++)
			{
				//y_back=delta(y_back,t0,(dtl+dtr)/2).RK4;
				rk4=delta(y_back,t0,(dtl+dtr)/2).RK4;
				for(int j=0;j<rk4.size();j++)
					rk4[j]=rk4[j]+y_back[j];

				if(collision_dectect(rk4))
					dtr=(dtl+dtr)/2;
				else
					dtl=(dtl+dtr)/2;

			}
			rk4=delta(y_back,t0,dtr).RK4;
			for(int j=0;j<rk4.size();j++)
			{
				y[j]=rk4[j]+y_back[j];
			}
			t0+=dtr;
			
			collision_handler(y);
			
			//start over
			z=y;
			y_temp=y;
			z_temp=y;
		}
		else
		{
			t0+=h;
		}
		for(i=0;i<y.size();i++)
		{
			if(y[i].L.len()<precision)
				y[i].L=vec(0,0,0);
			if(y[i].P.len()<precision)
				y[i].P=vec(0,0,0);
		}
	}
	dynamics=y;
		

}
Exemple #4
0
/**
 * @brief     1-wire search ROM callback.
 * @note      Must be called from PWM's ISR.
 *
 * @param[in] pwmp      pointer to the @p PWMDriver object
 * @param[in] owp       pointer to the @p onewireDriver object
 *
 * @notapi
 */
static void ow_search_rom_cb(PWMDriver *pwmp, onewireDriver *owp) {

  onewire_search_rom_t *sr = &owp->search_rom;

  if (0 == sr->reg.bit_step) {                    /* read direct bit */
    sr->reg.bit_buf |= ow_read_bit(owp);
    sr->reg.bit_step++;
  }
  else if (1 == sr->reg.bit_step) {               /* read complement bit */
    sr->reg.bit_buf |= ow_read_bit(owp) << 1;
    sr->reg.bit_step++;
    switch(sr->reg.bit_buf){
    case 0b11:
      /* no one device on bus or any other fail happened */
      sr->reg.result = ONEWIRE_SEARCH_ROM_ERROR;
      goto THE_END;
      break;
    case 0b01:
      /* all slaves have 1 in this position */
      store_bit(sr, 1);
      ow_write_bit_I(owp, 1);
      break;
    case 0b10:
      /* all slaves have 0 in this position */
      store_bit(sr, 0);
      ow_write_bit_I(owp, 0);
      break;
    case 0b00:
      /* collision */
      sr->reg.single_device = false;
      ow_write_bit_I(owp, collision_handler(sr));
      break;
    }
  }
  else {                                      /* start next step */
    #if !ONEWIRE_SYNTH_SEARCH_TEST
    ow_write_bit_I(owp, 1);
    #endif
    sr->reg.bit_step = 0;
    sr->reg.bit_buf = 0;
  }

  /* one ROM successfully discovered */
  if (64 == sr->reg.rombit) {
    sr->reg.devices_found++;
    sr->reg.search_iter = ONEWIRE_SEARCH_ROM_NEXT;
    if (true == sr->reg.single_device)
      sr->reg.result = ONEWIRE_SEARCH_ROM_LAST;
    goto THE_END;
  }
  return; /* next search bit iteration */

THE_END:
#if ONEWIRE_SYNTH_SEARCH_TEST
  (void)pwmp;
  return;
#else
  osalSysLockFromISR();
  pwmDisableChannelI(pwmp, owp->config->master_channel);
  pwmDisableChannelI(pwmp, owp->config->sample_channel);
  osalThreadResumeI(&(owp)->thread, MSG_OK);
  osalSysUnlockFromISR();
#endif
}