void asyncOperationsProcess()
{
	for(int i = 0; i < length; i++)
	{
		auto item = asyncBuffer[i];
		auto res  = item.handler(item.payload);
		switch(res)
		{
			case ASYNC_OPERATION_COMPLETE:
				asyncBuffer[i--] = asyncBuffer[--length];
				item.dtor(item.payload);

				RLOGI("Async operation %s completed", item.operationID);
				break;
			case ASYNC_OPERATION_RUNNING:
				//Do nothing
				break;
			case ASYNC_OPERATION_FAILURE:
				RLOGE("Async operation %s failed", item.operationID);
				asyncBuffer[i--] = asyncBuffer[--length];
				item.dtor(item.payload);
				break;
			default:
				RLOGE("Async operation %s returned invalid result %d", item.operationID, res);
				asyncBuffer[i--] = asyncBuffer[--length];
				item.dtor(item.payload);
				break;
		}
	}
}
double RobotMove::fixAngle(double angle){
	while(angle > dtor(180)){
		angle -= dtor(360);
	}
	while(angle < dtor(-180)){
		angle += dtor(360);
	}
	return angle;
}
Exemplo n.º 3
0
 /* Function: destroy
  *  Destroys the pointer <MatrixCSR::a>, <MatrixCSR::ia>, and <MatrixCSR::ja> using a custom deallocator if <MatrixCSR::free> is true. */
 void destroy(void (*dtor)(void*)) {
     if(_free) {
         dtor(_a);
         dtor(_ia);
         dtor(_ja);
         _a = nullptr;
         _ia = _ja = nullptr;
     }
 }
Exemplo n.º 4
0
//car update handlers------------------
void car::onUpdate(float timeElapsed) {
    if (speed != 0) {
        if (speed > 0) {
            facingRot -= turnRate * timeElapsed;
            wheelRot--;
        } else {
            facingRot += turnRate * timeElapsed;
            wheelRot++;
        }
        centerX += sin(dtor(facingRot)) * speed * timeElapsed;
        centerY += cos(dtor(facingRot)) * speed * timeElapsed;
    }
}
Exemplo n.º 5
0
/*
 * potm --
 *	return phase of the moon
 */
static double
potm(double days)
{
	double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime;
	double A4, lprime, V, ldprime, D, Nm;

	N = 360 * days / 365.2422;				/* sec 42 #3 */
	adj360(&N);
	Msol = N + EPSILONg - RHOg;				/* sec 42 #4 */
	adj360(&Msol);
	Ec = 360 / PI * ECCEN * sin(dtor(Msol));		/* sec 42 #5 */
	LambdaSol = N + Ec + EPSILONg;				/* sec 42 #6 */
	adj360(&LambdaSol);
	l = 13.1763966 * days + lzero;				/* sec 61 #4 */
	adj360(&l);
	Mm = l - (0.1114041 * days) - Pzero;			/* sec 61 #5 */
	adj360(&Mm);
	Nm = Nzero - (0.0529539 * days);			/* sec 61 #6 */
	adj360(&Nm);
	Ev = 1.2739 * sin(dtor(2*(l - LambdaSol) - Mm));	/* sec 61 #7 */
	Ac = 0.1858 * sin(dtor(Msol));				/* sec 61 #8 */
	A3 = 0.37 * sin(dtor(Msol));
	Mmprime = Mm + Ev - Ac - A3;				/* sec 61 #9 */
	Ec = 6.2886 * sin(dtor(Mmprime));			/* sec 61 #10 */
	A4 = 0.214 * sin(dtor(2 * Mmprime));			/* sec 61 #11 */
	lprime = l + Ev + Ec - Ac + A4;				/* sec 61 #12 */
	V = 0.6583 * sin(dtor(2 * (lprime - LambdaSol)));	/* sec 61 #13 */
	ldprime = lprime + V;					/* sec 61 #14 */
	D = ldprime - LambdaSol;				/* sec 63 #2 */
	return(50 * (1 - cos(dtor(D))));			/* sec 63 #3 */
}
Exemplo n.º 6
0
void chgOrient(PlayerClient *robotc, LaserProxy &lp, Position2dProxy &pp, robot_pos *point, robot_pos *robot){
	unsigned char orientn, directn;
	double newspeed, newturnrate;
	int iters=0;
	
	if ((robot->yaw >= 0) && (robot->yaw <= dtor(90)))				orientn=1;
	else if ((robot->yaw > dtor(90)) && (robot->yaw <= dtor(180)))	orientn=2;
	else if ((robot->yaw < 0) && (robot->yaw >= -dtor(90)))			orientn=3;
	else															orientn=4;
	
	if ((robot->x >= point->x) && (robot->y >= point->y))			directn=1;
	else if ((robot->x <= point->x) && (robot->y >= point->y))		directn=2;
	else if ((robot->x >= point->x) && (robot->y <= point->y))		directn=3;
	else															directn=4;
	
	newspeed = 0;	
	iters = MOVE_ITER;
		
	if((directn==1) && (orientn==1))		newturnrate = dtor((180)/TURNFACTOR);		
	else if ((directn==2) && (orientn==2))	newturnrate = dtor((180)/TURNFACTOR);
	else if ((directn==3) && (orientn==3))	newturnrate = dtor((180)/TURNFACTOR);
	else if ((directn==4) && (orientn==4))	newturnrate = dtor((180)/TURNFACTOR);
	else iters = 0;
	
	for(int i=0; i<iters; i++){
		robotc->Read();
		moveRobot(lp, pp, &newspeed, &newturnrate);
	}
}
void RobotMove::DriveToVector(Vector &whereToGo, Position2dProxy * position){ 

	startingAngle = whereToGo.getAngle();
	
	startingAngle = fixAngle(dtor(startingAngle));
	
	distanceToGo = whereToGo.getDistance();
	speed = whereToGo.getDistance();
	angularDistence = fixAngle(startingAngle - (*position).GetYaw());
	speed = abs(speed - abs(angularDistence / dtor(90)));
	if(speed > maxSpeed) speed = maxSpeed;
	(*position).SetSpeed(speed, angularDistence / angleDampener); 
		
	
	}
Exemplo n.º 8
0
//Calculate bearing from lat1/lon1 to lat2/lon2
//Note lat1/lon1/lat2/lon2 must be in radians
//Returns bearing in degrees
int CalcBearing(double lat1, double lon1, double lat2, double lon2)
{
  lat1 = dtor(lat1);
  lon1 = dtor(lon1);
  lat2 = dtor(lat2);
  lon2 = dtor(lon2);
  
  //determine angle
  double bearing = atan2(sin(lon2-lon1)*cos(lat2), (cos(lat1)*sin(lat2))-(sin(lat1)*cos(lat2)*cos(lon2-lon1)));
  //convert to degrees
  bearing = rtod(bearing);
  //use mod to turn -90 = 270
  //bearing = fmod((bearing + 360.0), 360);
  //return (int) bearing + 0.5;
  return ((int) bearing + 360) % 360;
}
Exemplo n.º 9
0
static void call_tls_dtors()
{
again:
	bool had_valid_tls = false;

	// for each registered dtor: (call order unspecified by SUSv3)
	for(size_t i = 0; i < MAX_DTORS; i++)
	{
		// is slot #i in use?
		void (*dtor)(void*) = dtors[i].dtor;
		if(!dtor)
			continue;

		// clear slot and call dtor with its previous value.
		const pthread_key_t key = dtors[i].key;
		void* tls = pthread_getspecific(key);
		if(tls)
		{
			WARN_IF_ERR(pthread_setspecific(key, 0));

			dtor(tls);
			had_valid_tls = true;
		}
	}

	// rationale: SUSv3 says we're allowed to loop infinitely. we do so to
	// expose any dtor bugs - this shouldn't normally happen.
	if(had_valid_tls)
		goto again;
}
Exemplo n.º 10
0
Script :: Script(const std::string& fn):
    IConfigurable(fn)
{
    nullify();
    scoped_dtor<Script> dtor(this);
    
    // attempt to get script filename from ini file
    if(Filesystem::hasExtension(fn,"ini"))
    {
        properties().getStringValue("default", "script", m_Filename);
        if(!m_Filename.empty())
        {
            Log::get().error("Could not locate script property in file \"" + fn + "\"");
            throw Failure();
        }
    }
    else
        m_Filename = fn; // use passed in filename as script filename

    //m_Script.open(script_fn);
    //if(m_Script.bad())
    //{
    //    Log::get().error((std::string)"Unable to open script \"" + script_fn + "\"");
    //    throw Failure();
    //}

    setupBindings();
    m_TickFrames  = 60;
    //m_TickTime.speed(1000.0f);

    dtor.resolve();
}
Exemplo n.º 11
0
void		BulletCommand::createSimpleBullet(double direction, double speed)
{
	HitBox		*box = 0;
	double		vx, vy;
	double		dir = dtor(direction);
	Bullet		*bullet;

	if (_shape == BulletCommand::Circle)
		box = new CircleHitBox(this->getX(), this->getY(),
			static_cast<double>(_width));
	else if (_shape == BulletCommand::Rectangle)
		box = new RectHitBox(this->getX(), this->getY(),
			static_cast<double>(_width),
			static_cast<double>(_height));
	vx = speed * cos(dir);
	vy = speed * sin(dir);
	if (box)
	{
		bullet = new Bullet(_state, this->_simpleSprite, *box, vx, vy, this->_simpleXHitbox, this->_simpleYHitbox);
		bullet->setScrollY(this->_scrollY);
		bullet->setLife(this->_simpleLife);
		bullet->setDamage(this->_simpleDamage);
		this->_state.addGameObject(bullet, this->_simpleGroup, false);
		//this->insertChild(*bullet);
	}
}
Exemplo n.º 12
0
/*
 * Trim down the number of pages in the quicklist
 */
void quicklist_trim(int nr, void (*dtor)(void *),
	unsigned long min_pages, unsigned long max_free)
{
	long pages_to_free;
	struct quicklist *q;

	q = &get_cpu_var(quicklist)[nr];
	if (q->nr_pages > min_pages) {
		pages_to_free = min_pages_to_free(q, min_pages, max_free);

		while (pages_to_free > 0) {
			/*
			 * We pass a gfp_t of 0 to quicklist_alloc here
			 * because we will never call into the page allocator.
			 */
			void *p = quicklist_alloc(nr, 0, NULL);

			if (dtor)
				dtor(p);
			free_page((unsigned long)p);
			pages_to_free--;
		}
	}
	put_cpu_var(quicklist);
}
Exemplo n.º 13
0
Position Robot::getStagePosition(Position position) const {
	Position stagePosition(
		getStageLocation(position.getLocation()),
		dtor(position.getYaw())
	);
	return stagePosition;
}
Exemplo n.º 14
0
void RobotCenter::setup(){
	for(int i=0;i<3;i++){
		enc[i]->setup();
		enc[i]->cpr(1000);
	}
	enc[LEFT]->rev(true);
	enc[RIGHT]->rev(true);
	enc[BACK]->rev(true);
	enc[LEFT]->mlt(50.8);
	enc[RIGHT]->mlt(50.8);
	enc[BACK]->mlt(50.8);
	encMountAngle[LEFT]=dtor(150);
	encMountAngle[RIGHT]=dtor(30);
	encMountAngle[BACK]=dtor(-90);
	encRadius=100.0;
}
Exemplo n.º 15
0
void
heim_w32_service_thread_detach(void *unused)
{
    tls_keys *key_defs;
    void (*dtor)(void*);
    size_t i;

    HEIMDAL_MUTEX_lock(&tls_key_defs_lock);
    key_defs = tls_key_defs;
    HEIMDAL_MUTEX_unlock(&tls_key_defs_lock);

    if (key_defs == NULL)
        return;

    for (i = 0; i < values.values_num; i++) {
        assert(i >= key_defs->keys_start_idx);
        if (i >= key_defs->keys_start_idx + key_defs->keys_num) {
            HEIMDAL_MUTEX_lock(&tls_key_defs_lock);
            key_defs = key_defs->keys_next;
            HEIMDAL_MUTEX_unlock(&tls_key_defs_lock);

            assert(key_defs != NULL);
            assert(i >= key_defs->keys_start_idx);
            assert(i < key_defs->keys_start_idx + key_defs->keys_num);
        }
        dtor = key_defs->keys_dtors[i - key_defs->keys_start_idx];
        if (values.values[i] != NULL && dtor != NULL && dtor != DEAD_KEY)
            dtor(values.values[i]);
        values.values[i] = NULL;
    }
}
Exemplo n.º 16
0
int ListClear(linked_list* list, int (*dtor)(void*)) {
    while( list->count != 0) {
        dtor(list->head->data);
        ListPopFront(list);
    }
    return LNKL_SUCCESS;
}
Exemplo n.º 17
0
static void  getVectorFromAngle(float ori_angle[3], float ori_vec[3])
{
	float azim,elev,roll,cos_azim,sin_azim,sin_elev,cos_roll,sin_roll;
	azim = dtor(ori_angle[1]);
	elev = dtor(ori_angle[0]);
	roll = dtor(ori_angle[2]);
	cos_azim = cosf(azim);
	sin_azim = sinf(azim);
	sin_elev = sinf(elev);
	cos_roll = cosf(roll);
	sin_roll = sinf(roll);
	
	//float vec[3];
	ori_vec[0] = -cos_azim * cos_roll - sin_azim * sin_elev * sin_roll;
	ori_vec[1] = -cosf(elev) * sin_roll;
	ori_vec[2] = sin_azim * cos_roll - cos_azim * sin_elev * sin_roll;
}
Exemplo n.º 18
0
void WiFi_forward_to_xcsoar()
{
    int bearing = CalcBearing(fo.latitude, fo.longtitude, LATITUDE, LONGTITUDE);
    int alt_diff = fo.altitude - ALTITUDE;
    char *csum_ptr;
    unsigned char cs = 0; //clear any old checksum

    Udp.beginPacket(ARGUS_HOSTNAME, XCSOAR_PORT);
    snprintf(UDPpacketBuffer, sizeof(UDPpacketBuffer), "$PFLAU,0,1,1,1,%d,2,%d,%u,%X*", \
      bearing, alt_diff, (int) fo.distance, fo.addr );

    //calculate the checksum
    for (unsigned int n = 1; n < strlen(UDPpacketBuffer) - 1; n++) {
      cs ^= UDPpacketBuffer[n]; //calculates the checksum
    }

    csum_ptr = UDPpacketBuffer + strlen(UDPpacketBuffer);
    snprintf(csum_ptr, sizeof(UDPpacketBuffer) - strlen(UDPpacketBuffer), "%02X\n", cs);

#ifdef SERIAL_VERBOSE
    Serial.println(UDPpacketBuffer);
#endif

    Udp.write(UDPpacketBuffer, strlen(UDPpacketBuffer));
    Udp.endPacket();

    Udp.beginPacket(XCSOAR_HOSTNAME, XCSOAR_PORT);
    snprintf(UDPpacketBuffer, sizeof(UDPpacketBuffer), "$PFLAA,2,%d,%d,%d,2,%X,,,,,1*",   \
      (int) (fo.distance * cos(dtor(bearing))), (int) (fo.distance * sin(dtor(bearing))), \
      alt_diff, fo.addr );

    cs = 0; //clear any old checksum
    for (unsigned int n = 1; n < strlen(UDPpacketBuffer) - 1; n++) {
      cs ^= UDPpacketBuffer[n]; //calculates the checksum
    }

    csum_ptr = UDPpacketBuffer + strlen(UDPpacketBuffer);
    snprintf(csum_ptr, sizeof(UDPpacketBuffer) - strlen(UDPpacketBuffer), "%02X\n", cs);

#ifdef SERIAL_VERBOSE
    Serial.println(UDPpacketBuffer);
#endif

    Udp.write(UDPpacketBuffer, strlen(UDPpacketBuffer));
    Udp.endPacket();
}
Exemplo n.º 19
0
void asyncOperationsCancel()
{
	for (int i = 0; i < length; i++)
	{
		auto item = asyncBuffer[i];
		item.dtor(item.payload);
	}

	length = 0;
}
Exemplo n.º 20
0
void __stdcall MSVCRTEX_eh_vector_destructor_iterator(void *pMem, size_t sizeOfItem, int nItems, void (__thiscall *dtor)(void *))
{
    char *pEnd = static_cast<char *>(pMem) + nItems * sizeOfItem;
    for (char *pItem = pEnd - sizeOfItem;
         pItem >= pMem;
         pItem -= sizeOfItem)
    {
        try
        {
            dtor(pItem);
        }
        catch (...)
        {
            for (pItem -= sizeOfItem; pItem >= pMem; pItem -= sizeOfItem)
                dtor(pItem);
            throw;
        }
    }
}
Exemplo n.º 21
0
void		BulletCommand::doChangeDirection(double direction)
{
	if (!this->_isCommanded)
		return ;
	this->_direction = dtor(direction);
	this->_vx = this->_speed * cos(this->_direction);
	this->_vy = this->_speed * sin(this->_direction);
	if (this->_sprite)
		this->_sprite->setRotation(-direction + 90);
}
//!-----------------------------------------
void destroyTree(treeElem_t *root)
{
    assert(root);

    if (root->left)
        destroyTree(root->left);
    if (root->right)
        destroyTree(root->right);

    dtor(root);
}
Exemplo n.º 23
0
    void reset() {
        // If I am empty return
        if (!*this) return;

        if (!--*k) { /* --*k == 0 */
            dtor(ptr); // clean up memory
            delete k;
            k=0;
            ptr=0;
        }
        assert_invariant();
    }
Exemplo n.º 24
0
static void pt_sb_free_decoder(struct pt_sb_decoder *decoder)
{
	void (*dtor)(void *);

	if (!decoder)
		return;

	dtor = decoder->dtor;
	if (dtor)
		dtor(decoder->priv);

	free(decoder);
}
LinearAllocator::~LinearAllocator(void) {
    while (mDtorList) {
        auto node = mDtorList;
        mDtorList = node->next;
        node->dtor(node->addr);
    }
    Page* p = mPages;
    while (p) {
        Page* next = p->next();
        p->~Page();
        free(p);
        RM_ALLOCATION();
        p = next;
    }
}
Exemplo n.º 26
0
		ClassMetatable()
		{
			FunctorType dtor(&class_userdata::destructor<ObjectWrapperBase>);
			function_map_["__gc"].push_back(dtor);

			KAGUYA_STATIC_ASSERT(is_registerable<class_type>::value || !traits::is_std_vector<class_type>::value, "std::vector is binding to lua-table by default.If you wants register for std::vector yourself,"
				"please define KAGUYA_NO_STD_VECTOR_TO_TABLE");

			KAGUYA_STATIC_ASSERT(is_registerable<class_type>::value || !traits::is_std_map<class_type>::value, "std::map is binding to lua-table by default.If you wants register for std::map yourself,"
				"please define KAGUYA_NO_STD_MAP_TO_TABLE");

			//can not register push specialized class
			KAGUYA_STATIC_ASSERT(is_registerable<class_type>::value,
				"Can not register specialized of type conversion class. e.g. std::tuple");
		}
Exemplo n.º 27
0
static void spl_ptr_llist_destroy(spl_ptr_llist *llist) /* {{{ */
{
	spl_ptr_llist_element   *current = llist->head, *next;
	spl_ptr_llist_dtor_func  dtor    = llist->dtor;

	while (current) {
		next = current->next;
		if (dtor) {
			dtor(current);
		}
		SPL_LLIST_DELREF(current);
		current = next;
	}

	efree(llist);
}
//!-----------------------------------
void removeList(header_t *Head)
{
    assert_ok(Head != NULL);
    listElem_t * work = Head->theFirst;

    for (int i = 2; i < Head->ListLen; i++)
    {
        assert(2 <= i && i <= Head->ListLen);
        dtor(work->prev, Head);
        work = work->next;
    }
    work = NULL;

    free(Head);
    dumpList(Head);
}
void LinearAllocator::runDestructorFor(void* addr) {
    auto node = mDtorList;
    DestructorNode* previous = nullptr;
    while (node) {
        if (node->addr == addr) {
            if (previous) {
                previous->next = node->next;
            } else {
                mDtorList = node->next;
            }
            node->dtor(node->addr);
            rewindIfLastAlloc(node, sizeof(DestructorNode));
            break;
        }
        previous = node;
        node = node->next;
    }
}
/* Function: al_emit_user_event
 */
bool al_emit_user_event(ALLEGRO_EVENT_SOURCE *src,
   ALLEGRO_EVENT *event, void (*dtor)(ALLEGRO_USER_EVENT *))
{
   size_t num_queues;
   bool rc;

   ASSERT(src);
   ASSERT(event);
   ASSERT(ALLEGRO_EVENT_TYPE_IS_USER(event->any.type));

   if (dtor) {
      ALLEGRO_USER_EVENT_DESCRIPTOR *descr = al_malloc(sizeof(*descr));
      descr->refcount = 0;
      descr->dtor = dtor;
      event->user.__internal__descr = descr;
   }
   else {
      event->user.__internal__descr = NULL;
   }

   _al_event_source_lock(src);
   {
      ALLEGRO_EVENT_SOURCE_REAL *rsrc = (ALLEGRO_EVENT_SOURCE_REAL *)src;

      num_queues = _al_vector_size(&rsrc->queues);
      if (num_queues > 0) {
         event->user.timestamp = al_get_time();
         _al_event_source_emit_event(src, event);
         rc = true;
      }
      else {
         rc = false;
      }
   }
   _al_event_source_unlock(src);

   if (dtor && !rc) {
      dtor(&event->user);
      al_free(event->user.__internal__descr);
   }

   return rc;
}