static void q_requeue_before(struct queue *q, struct entry *dest, struct entry *e, unsigned extra_levels)
{
	struct entry *de;
	unsigned new_level;

	q_del(q, e);

	if (extra_levels && (e->level < q->nr_levels - 1u)) {
		new_level = min(q->nr_levels - 1u, e->level + extra_levels);
		for (de = l_head(q->es, q->qs + new_level); de; de = l_next(q->es, de)) {
			if (de->sentinel)
				continue;

			q_del(q, de);
			de->level = e->level;

			if (dest)
				q_push_before(q, dest, de);
			else
				q_push(q, de);
			break;
		}

		e->level = new_level;
	}

	q_push(q, e);
}
/*
 * This function assumes there is a non-sentinel entry to pop.  It's only
 * used by redistribute, so we know this is true.  It also doesn't adjust
 * the q->nr_elts count.
 */
static struct entry *__redist_pop_from(struct queue *q, unsigned level)
{
	struct entry *e;

	for (; level < q->nr_levels; level++)
		for (e = l_head(q->es, q->qs + level); e; e = l_next(q->es, e))
			if (!e->sentinel) {
				l_del(q->es, q->qs + e->level, e);
				return e;
			}

	return NULL;
}
Beispiel #3
0
List l_cloneList(List l){
  List newList = malloc(sizeof(struct list));
  assert(newList);
  newList->size = 0;
  newList->first = NULL;
  newList->current = NULL;
  newList->last = NULL;
  l_head(l);
  while(!l_isOutOfList(l)){
    l_addInFront(newList, l_getVal(l));
    l_next(l);
  }
  return newList;
}
static void l_del(struct entry_space *es, struct ilist *l, struct entry *e)
{
	struct entry *prev = l_prev(es, e);
	struct entry *next = l_next(es, e);

	if (prev)
		prev->next = e->next;
	else
		l->head = e->next;

	if (next)
		next->prev = e->prev;
	else
		l->tail = e->prev;

	if (!e->sentinel)
		l->nr_elts--;
}
Beispiel #5
0
intensity_t lighting(scene_t *scene, entity_t *ent, hitinfo_t *hit) {

    assert(ent->magic == ENTITY_T);
    
    intensity_t returnIntensity = {0,0,0};
    intensity_t tmpIntensity;
    iterator_t *lightitr = newIterator(scene->lightList);
    entity_t *light;

    while((light = l_next(lightitr)) != NULL) {
        tmpIntensity = processPointLight(scene, ent, light, hit);
        returnIntensity.x = tmpIntensity.x + returnIntensity.x; 
        returnIntensity.y = tmpIntensity.y + returnIntensity.y;
        returnIntensity.z = tmpIntensity.z + returnIntensity.z;
    }
    free(lightitr);
    return(returnIntensity);
}
static int smq_save_hints(struct smq_policy *mq, struct queue *q,
			  policy_walk_fn fn, void *context)
{
	int r;
	unsigned level;
	struct entry *e;

	for (level = 0; level < q->nr_levels; level++)
		for (e = l_head(q->es, q->qs + level); e; e = l_next(q->es, e)) {
			if (!e->sentinel) {
				r = fn(context, infer_cblock(mq, e),
				       e->oblock, e->level);
				if (r)
					return r;
			}
		}

	return 0;
}
Beispiel #7
0
entity_t *closest(scene_t *scene, point_t base, vector_t unitDir, 
                  entity_t *self, hitinfo_t *hit) {
  /* Flags
   *  1 - has been set
   *  0 - has not been set
   */
  int flag_closest = 0;

  entity_t   * ent;            //Shortcut to entity in list
  sobj_t     * sobj;           //Shortcut to ent->entDerived
  entity_t   * closest = NULL; //Will be returned at end of function
  hitinfo_t    hit_closest;
  iterator_t * iter = newIterator(scene->sobjList);

  l_begin(iter);
  while((ent = l_next(iter)) != NULL) {
    /** Run Hit Checks and store closest Entity **/
    if (ent != self) {
      sobj = ent->entDerived;
      if (sobj->hit(ent, base, unitDir, &hit_closest) == 1) {
        if (flag_closest == 1) {
          if (hit->distance > hit_closest.distance) {
            hit->distance = hit_closest.distance;
            hit->normal   = hit_closest.normal;
            hit->hitpoint = hit_closest.hitpoint;
            closest = ent;
          }
        }
        else { //first time there has been a "hit"
          hit->distance = hit_closest.distance;
          hit->normal   = hit_closest.normal;
          hit->hitpoint = hit_closest.hitpoint;

          flag_closest = 1;
          closest = ent;
        }
      } // end of if(hitFuncPtr())
    } //end of if(ent != self)
  } // end of while()
  free(iter);
  return closest;
} /* End closest */
/*
 * Return the oldest entry of the lowest populated level.
 */
static struct entry *q_peek(struct queue *q, unsigned max_level, bool can_cross_sentinel)
{
	unsigned level;
	struct entry *e;

	max_level = min(max_level, q->nr_levels);

	for (level = 0; level < max_level; level++)
		for (e = l_head(q->es, q->qs + level); e; e = l_next(q->es, e)) {
			if (e->sentinel) {
				if (can_cross_sentinel)
					continue;
				else
					break;
			}

			return e;
		}

	return NULL;
}
Beispiel #9
0
myvector lighting(scene_t *scene, entity_t *ent, hitinfo_t &hit) 
{
	myvector total_illumination;
  	iterator_t *light_iter = newIterator(scene->lightList);

	/* gather light from all sources */
	while(l_hasnext(light_iter)) {
	      	/* set pointer to current light 
		   and advance the light_iterator*/
	        pointlight_t *light_ptr = static_cast<pointlight_t*>
		  (l_next(light_iter));
		
		/* process light */
		myvector new_light = light_ptr->processLight(scene, ent, hit);

		/* add to current illumination */
		total_illumination = total_illumination + new_light;
	}

    return total_illumination;
}
Beispiel #10
0
int main() {
   int data[] = {5, 10, 15, 20, 25};
 
   char *fruit[] = {"apple", "orange", "peach", "banana"};

   veh_t vehicles[] = { {23456, "Ford", "Mustang", 2009},
                        {32168, "Honda", "Accord", 2010},
                        {32565, "Toyota", "Camry", 2010},
                        {15677, "Jeep", "Cherokee", 2004},
                        {34257, "Chevrolet", "Impala", 2007},
                        {54387, "Nissan", "Altima", 2006},
                        {34577, "Dodge", "Caravan", 2003}};

   int index;
   int size;

   int   *ptr1;
   char  *ptr2;
   veh_t *ptr3;

   list_t *list1;
   list_t *list2;
   list_t *list3;

   iterator_t *iter1;
   iterator_t *iter2;
   iterator_t *iter3;
                        
   /** Create the lists **/
   list1 = newList();
   list2 = newList();
   list3 = newList();

   /*  Populate the lists  */
   size = sizeof(data)/sizeof(int);
   for(index = 0; index < size; index++) {
      l_add(list1, &data[index]);
   }

   size = sizeof(fruit)/sizeof(char *);
   for(index = 0; index < size; index++) {
      l_add(list2, fruit[index]);
   }
   
   size = sizeof(vehicles)/sizeof(veh_t);
   for(index = 0; index < size; index++) {
      l_add(list3, &vehicles[index]);
   }

   /** Retrieve data from lists **/

   /* Print list 1 */
   fprintf(stdout, "List 1: ");
   iter1 = newIterator(list1);
   while(l_hasnext(iter1)) {
      ptr1 = l_next(iter1);
      fprintf(stdout, "%d, ", *ptr1);
   }
   fprintf(stdout, "\n");
   fprintf(stdout, "\nTest l_begin() function: ");

   /* Test of l_begin() function */
   l_begin(iter1);
   ptr1 = l_next(iter1);
   fprintf(stdout, "First value=%d\n", *ptr1);

   /* Print list 2 */
   fprintf(stdout, "\nList 2: ");
   // Create a new iterator based on list2
   iter2 = newIterator(list2);
   // While we haven't fallen off the end of the list
   while(l_hasnext(iter2)){
      // Move to the next element in the list
      ptr2 = l_next(iter2);
      // and print out it's contents
      fprintf(stdout, "%s,", ptr2);
   } 
   fprintf(stdout,"\n");
   

   /* Print list 3 */
   fprintf(stdout, "\nList 3: ");
   // Create a new iterator based off list3
   iter3 = newIterator(list3);
   // While we haven't fallen off the end of the list
   while(l_hasnext(iter3)){
      // move to the next element on the list.
      ptr3 = l_next(iter3);
      // Print out the contents of the element by accessing the individual
      // fields in the structure.
      fprintf(stdout,"[%d %s %s %d],",ptr3->vin,ptr3->make,ptr3->model,ptr3->year);
   }

   fprintf(stdout, "\n\n");
   return 0;
}