示例#1
0
static int Apply(TreeMap *tree,int (*Applyfn)(const void *data,void *arg),void *arg)
{
    Iterator *it = newIterator(tree);
    void *obj;

    for (obj = it->GetFirst(it);
    	 obj != NULL;
    	 obj = it->GetNext(it)) {
    	Applyfn(obj,arg);
    }
    return 1;
}
示例#2
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);
}
示例#3
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 */
示例#4
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;
}
示例#5
0
static int Clear(TreeMap *tree)
{
	if (tree->DestructorFn) {
		Iterator *it = newIterator(tree);
		void *obj;
	
		for (obj = it->GetFirst(it);
			 obj != NULL;
			 obj = it->GetNext(it)) {
			tree->DestructorFn(obj);
		}
	}
    iHeap.Finalize(tree->Heap);
    tree->Heap = iHeap.Create(tree->ElementSize+sizeof(struct Node),CurrentMemoryManager);
    tree->count = 0;
    tree->root=0;
    tree->max_size=0;            /* Max size since last complete rebalance. */
    tree->Flags=0;
    tree->timestamp=0;
    return 1;
}
示例#6
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;
}