コード例 #1
0
ファイル: cloth.c プロジェクト: Wisellama/OpenGL-Cloth
void main_loop()
{
  // the time of the previous frame
  double old_time = glfwGetTime();
  // point that the mouse grabs
  Point *mouse_point = malloc(sizeof(Point)); // temporary
  int mouse_held = 0; // boolean
  // this just loops as long as the program runs
  while(1)
    {
      // calculate time elapsed
      double current_time = glfwGetTime(),
	delta_time = (current_time - old_time);
      old_time = current_time;
      // escape to quit, arrow keys to rotate view
      if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS) {
	break;
      }
      if (glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS) {
	rotate_y += delta_time*30;
      }
      if (glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS) {
	rotate_y -= delta_time*30;
      }
      //randomly push the mesh in a random direction with SPACE
      if(glfwGetKey(GLFW_KEY_SPACE) == GLFW_PRESS) {
	int random_point = rand()%(NUM_POINTS-NUM_POINTS_X-1) + NUM_POINTS_X+1;
	Point *p = point_array[random_point];
	p->x += rand()%10000 / 10000.0 - .5;
	p->y += rand()%10000 / 10000.0 - .5;
	p->z += rand()%10000 / 10000.0 - .5;
      }

      //update link constraints multiple times
      for(int q = 0; q < 3; q++) {
	for(int i = 0; i < NUM_LINKS; i++) {
	  if(!link_array[i]->broken) {
	    update_link(link_array[i]);
	  }
	}      
      }

      //update all points except top row (fixed points)
      for(int i = 0; i < NUM_POINTS; i++) {
	if(!point_array[i]->anchor) {
	  update_point(point_array[i], delta_time);
	}
      }

      // clear the buffer
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      // draw the figure
      draw(link_array);
      // mouse stuffs
      update_mouse(&mouse_point, &mouse_held);
      // swap back and front buffers
      glfwSwapBuffers();
    }
}
コード例 #2
0
ファイル: udev-node.c プロジェクト: OPSF/uClinux
void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev_old, int test)
{
	struct udev *udev = udev_device_get_udev(dev);
	struct udev_list_entry *list_entry;
	const char *devnode_old;

	/* update possible left-over symlinks */
	udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev_old)) {
		const char *name = udev_list_entry_get_name(list_entry);
		struct udev_list_entry *list_entry_current;
		int found;

		/* check if old link name is now our node name */
		if (strcmp(name, udev_device_get_devnode(dev)) == 0)
			continue;

		/* check if old link name still belongs to this device */
		found = 0;
		udev_list_entry_foreach(list_entry_current, udev_device_get_devlinks_list_entry(dev)) {
			const char *name_current = udev_list_entry_get_name(list_entry_current);

			if (strcmp(name, name_current) == 0) {
				found = 1;
				break;
			}
		}
		if (found)
			continue;

		info(udev, "update old symlink '%s' no longer belonging to '%s'\n", name, udev_device_get_devpath(dev));
		name_index(udev, udev_device_get_devpath(dev), name, 0, test);
		update_link(dev, name, test);
	}

	/*
	 * if the node name has changed, delete the node,
	 * and possibly restore a symlink of another device
	 */
	devnode_old = udev_device_get_devnode(dev_old);
	if (devnode_old != NULL) {
		const char *devnode = udev_device_get_devnode(dev);

		if (devnode != NULL && strcmp(devnode_old, devnode) != 0)
			update_link(dev, devnode_old, test);
	}
}
コード例 #3
0
ファイル: dict.c プロジェクト: hhktony/dict
pnode_t insert_to_file(char *word, char *explain, pnode_t phead)
{
	pnode_t p = phead;
	while (p != NULL)
	{

		if (strcmp(p->word, word + 1) < 0)
		{
			move_info(p->pos, word, explain);
			phead = update_link(phead);
			break;
		}
		p = p->pnext;
	}
	return phead;
}
コード例 #4
0
ファイル: main.c プロジェクト: akaehy/Project
V_NODE *insert_to_file(char *w, char *ex, V_NODE *head)
{
	V_NODE *p = head;
	while(p != NULL)
	{
		
		if(strcmp(p->word, w+1) < 0)
		{
			move_info(p->position, w, ex);
			head = update_link(head);
			break;
		}
		p = p->next;
	}
	return head;
}
コード例 #5
0
ファイル: udev-node.c プロジェクト: OPSF/uClinux
int udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid, int test)
{
	struct udev *udev = udev_device_get_udev(dev);
	int i;
	int num;
	struct udev_list_entry *list_entry;
	int err = 0;

	info(udev, "creating device node '%s', devnum=%d:%d, mode=%#o, uid=%d, gid=%d\n",
	     udev_device_get_devnode(dev),
	     major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev)),
	     mode, uid, gid);

	util_create_path(udev, udev_device_get_devnode(dev));
	if (!test)
		if (udev_node_mknod(dev, NULL, makedev(0,0), mode, uid, gid) != 0) {
			err = -1;
			goto exit;
		}

	/* create all_partitions if requested */
	num = udev_device_get_num_fake_partitions(dev);
	if (num > 0) {
		info(udev, "creating device partition nodes '%s[1-%i]'\n", udev_device_get_devnode(dev), num);
		if (!test) {
			for (i = 1; i <= num; i++) {
				char partitionname[UTIL_PATH_SIZE];
				dev_t part_devnum;

				snprintf(partitionname, sizeof(partitionname), "%s%d",
					 udev_device_get_devnode(dev), i);
				partitionname[sizeof(partitionname)-1] = '\0';
				part_devnum = makedev(major(udev_device_get_devnum(dev)),
						    minor(udev_device_get_devnum(dev)) + i);
				udev_node_mknod(dev, partitionname, part_devnum, mode, uid, gid);
			}
		}
	}

	/* add node to name index */
	name_index(udev, udev_device_get_devpath(dev), udev_device_get_devnode(dev), 1, test);

	/* create/update symlinks, add symlinks to name index */
	udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev)) {
		name_index(udev, udev_device_get_devpath(dev), udev_list_entry_get_name(list_entry), 1, test);
		update_link(dev, udev_list_entry_get_name(list_entry), test);
	}
コード例 #6
0
ファイル: udev-node.c プロジェクト: OPSF/uClinux
extern int udev_node_remove(struct udev_device *dev, int test)
{
	struct udev *udev = udev_device_get_udev(dev);
	struct udev_list_entry *list_entry;
	const char *devnode;
	char partitionname[UTIL_PATH_SIZE];
	struct stat stats;
	int err = 0;
	int num;

	/* remove node from name index */
	name_index(udev, udev_device_get_devpath(dev), udev_device_get_devnode(dev), 0, test);

	/* remove,update symlinks, remove symlinks from name index */
	udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev)) {
		name_index(udev, udev_device_get_devpath(dev), udev_list_entry_get_name(list_entry), 0, test);
		update_link(dev, udev_list_entry_get_name(list_entry), test);
	}
コード例 #7
0
ファイル: astar.c プロジェクト: MarcBrout/Dante
int		add_all_link_to_lists(t_case *root,
				      t_link *open_l,
				      t_link *closed_l,
				      t_case *cas)
{
  t_link	*link;
  int		ret;

  link = cas->link;
  while (link)
    {
      if (!is_in_list(closed_l, link))
	{
	  if ((ret = calc_dist(root->prev, cas, link->cas)) == 1)
	    update_link(open_l, link);
	  else if (!ret)
	    if (add_in_open_list(open_l, link))
	      return (1);
	}
      link = link->next;
    }
  return (0);
}
コード例 #8
0
ファイル: maildirshared.c プロジェクト: debdungeon/qint
static int update_cur(const char *cur, const char *shared, struct dbobj *obj)
{
DIR	*dirp;
struct	dirent *de;
char	*p;

	dirp=opendir(cur);
	while (dirp && (de=readdir(dirp)) != 0)
	{
	char	*cur_base;

	char	*cur_name_ptr;
	size_t	cur_name_len;

	char	*linked_name_buf;
	size_t	linked_name_len;
	int	n;

		if (de->d_name[0] == '.')	continue;

		/*
		** Strip the maildir flags, and look up the message in the
		** db.
		*/

		cur_base=malloc(strlen(de->d_name)+1);
		if (!cur_base)
		{
			perror("malloc");
			closedir(dirp);
			return (-1);
		}
		strcpy(cur_base, de->d_name);
		p=strrchr(cur_base, MDIRSEP[0]);
		if (p)	*p=0;

		cur_name_ptr=dbobj_fetch(obj, cur_base, strlen(cur_base),
			&cur_name_len, "");

		/* If it's there, delete the db entry. */

		if (cur_name_ptr)
			dbobj_delete(obj, cur_base, strlen(cur_base));

		/*
		** We'll either delete this soft link, or check its
		** contents, so we better build its complete pathname in
		** any case.
		*/

		free(cur_base);
		cur_base=malloc(strlen(de->d_name)+strlen(cur)+2);
		if (!cur_base)
		{
			perror("malloc");
			if (cur_name_ptr)	free(cur_name_ptr);
			closedir(dirp);
			return (-1);
		}
		strcat(strcat(strcpy(cur_base, cur), "/"), de->d_name);

		if (!cur_name_ptr)	/* Removed from sharable dir */
		{
			unlink(cur_base);
			free(cur_base);
			continue;
		}

		linked_name_len=strlen(shared)+strlen(de->d_name)+100;
			/* should be enough */

		if ((linked_name_buf=malloc(linked_name_len)) == 0)
		{
			perror("malloc");
			free(cur_base);
			free(cur_name_ptr);
			closedir(dirp);
			return (-1);
		}

		if ((n=readlink(cur_base, linked_name_buf, linked_name_len))< 0)
		{
			/* This is stupid, let's just unlink this nonsense */

			n=0;
		}

		if (n == 0 || n >= linked_name_len ||
			(linked_name_buf[n]=0,
			update_link(cur,
				cur_base, linked_name_buf, shared, cur_name_ptr,
				cur_name_len)))
		{
			unlink(cur_base);
			free(linked_name_buf);
			free(cur_base);
			free(cur_name_ptr);
			closedir(dirp);
			return (-1);
		}
		free(cur_base);
		free(linked_name_buf);
		free(cur_name_ptr);
	}
	if (dirp)	closedir(dirp);
	return (0);
}