Example #1
0
/** model_init **/
int model_init(FILE *in, model_t *model) {
/****variables****/
   obj_t *obj = NULL;
   char  buf[256];
   char  objclass[128];
   int ctr;
   int flag;
/*****************/
   
/* Load the objects in the scene */
   while (fscanf(in, "%128s", objclass) == 1)
   {
      /* The word just inputted must be either a class name or the
         beginning of a comment 
      */
      flag = 0;
      if (objclass[0] == '#') {
         /* It's a comment -- skip the rest of the line */
         fgets(buf, sizeof(buf), in); /* consume rest of line */
      }
      else {
         
         for(ctr = 0; ctr < (sizeof(helper)/sizeof(*helper)); ctr++) {
            // Use helper struct to call correct init
            if(strcmp(objclass, (helper[ctr]).objecttype) == 0) {
               obj = helper[ctr].init(in, objclass);
               flag = 1;
               break;
            }
         }
         
         // Catches objects not in the helper struct
         if (flag == 0) {
            fprintf(stderr, "Unrecognized object type\n");
            exit(1);
         }
         
         // Catches failed initiation procedure otherwise adds
         if (obj == NULL) {
            fprintf(stderr, "Failed to load type %s \n", objclass);
            model_dump(model);
            exit(2);
         }
         else
         {
            /* Add object to scene object linked list */
            if(obj->objcat == 0)
               l_add(model->scene, obj);
            else
               l_add(model->lights, obj);
         }
      } /* End else "not a comment" */
   }
   return(0);
}
Example #2
0
Timer *
tmr_create(struct timeval *nowP, TimerProc *timer_proc, ClientData client_data, long msecs, int periodic)
{
  Timer *t;

  if (free_timers != (Timer *)0) {
    t           = free_timers;
    free_timers = t->next;
  } else {
    t = (Timer *)malloc(sizeof(Timer));
    if (t == (Timer *)0)
      return (Timer *)0;
  }

  mstimeout_cache = -1;
  t->timer_proc   = timer_proc;
  t->client_data  = client_data;
  t->msecs        = msecs;
  t->periodic     = periodic;
  if (nowP != (struct timeval *)0)
    t->time = *nowP;
  else
    (void)gettimeofday(&t->time, (struct timezone *)0);
  t->time.tv_sec += msecs / 1000L;
  t->time.tv_usec += (msecs % 1000L) * 1000L;
  if (t->time.tv_usec >= 1000000L) {
    t->time.tv_sec += t->time.tv_usec / 1000000L;
    t->time.tv_usec %= 1000000L;
  }
  t->hash = hash(t);
  /* Add the new timer to the proper active list. */
  l_add(t);

  return t;
}
Example #3
0
static void l_resort(Timer * t)
{
	/* Remove the timer from its old list. */
	l_remove(t);
	/* Recompute the hash. */
	t->hash = hash(t);
	/* And add it back in to its new list, sorted correctly. */
	l_add(t);
}
Example #4
0
atom *l_add(lcons *args,nspace *n) {
	if (!args)
		return l_newint(0);
	lint *car = l_cint(eval(args->car,n));
	lint *cdr = l_cint(l_add(l_ccons(args->cdr),n));
	if (car && cdr)
		return l_newint(car->i + cdr->i);
	else {
		printf("Error: \"+\" bad int \n");
		return NULL;
	}
}
Example #5
0
Timer *tmr_create(struct timeval *nowP, TimerProc *timer_proc, arg_t arg, long msecs, int periodic)
{
	Timer *t;

	if (free_timers) {
		t           = free_timers;
		free_timers = t->next;
		--free_count;
	} else {
		t = (Timer *)malloc(sizeof(Timer));
		if (!t)
			return NULL;

		++alloc_count;
	}

	t->timer_proc  = timer_proc;
	t->arg = arg;
	t->msecs       = msecs;
	t->periodic    = periodic;
	if (nowP)
		t->time = *nowP;
	else
		tmr_prepare_timeval(&t->time);

	t->time.tv_sec  +=  msecs / 1000L;
	t->time.tv_usec += (msecs % 1000L) * 1000L;
	if (t->time.tv_usec >= 1000000L) {
		t->time.tv_sec += t->time.tv_usec / 1000000L;
		t->time.tv_usec %= 1000000L;
	}

	t->hash = hash(t);

	/* Add the new timer to the proper active list. */
	l_add(t);
	++active_count;

	return t;
}
Example #6
0
void completePointLight(scene_t *scene, entity_t *ent) {
    l_add(scene->lightList, ent);
}
Example #7
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;
}
Example #8
0
int LegacyWrapper::add(int a, int b)
{
    qDebug("wrapper add");
    return l_add(a, b);
}