Beispiel #1
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 */
Beispiel #2
0
void
ExodusFormatter::format()
{
  std::string s;
  _input_file_record.clear();

  while (std::getline(_ss, s))
  {
    // MAX_LINE_LENGTH is from ExodusII
    if ( s.length() > MAX_LINE_LENGTH )
    {
      const std::string continuation("...");
      const size_t cont_len(continuation.length());
      size_t num_lines = s.length() / (MAX_LINE_LENGTH - cont_len) + 1;
      std::string split_line;
      for (size_t j(0), l_begin(0); j < num_lines; ++j, l_begin+=MAX_LINE_LENGTH-cont_len)
      {
        size_t l_len = MAX_LINE_LENGTH-cont_len;
        if (s.length() < l_begin + l_len )
        {
          l_len = s.length() - l_begin;
        }
        split_line = s.substr( l_begin, l_len );
        if ( l_begin + l_len != s.length())
        {
          split_line += continuation;
        }
        _input_file_record.push_back(split_line);
      }
    }
    else
    {
      _input_file_record.push_back(s);
    }
  }
}
Beispiel #3
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;
}