Пример #1
0
void game_destroy(Game *game) {
    field_destroy(game->field);

    free(game->player);
    free(game->ball);

    free(game);
}
Пример #2
0
extern int plot(opt_t *opt)
{
  int err = ERROR_BUG;

#ifndef HAVE_GETRUSAGE

  /* simple timer */

  clock_t c0, c1;
  c0 = clock();

#endif

#ifdef HAVE_GETTIMEOFDAY

  /* high resolution elapsed time */

  struct timeval tv0;

  gettimeofday(&tv0, NULL);

#endif

#ifdef HAVE_PTHREAD_H

  if (opt->v.verbose)
    {
      printf("using %i thread%s\n", opt->v.threads,
	     (opt->v.threads == 1 ? "" : "s"));
    }

#endif

  if (opt->test != test_none)
    {
      /* test field */

      switch (opt->test)
	{
	case test_circular:
	  TFMSG("circular");
	  err = plot_circular(opt);
	  break;
	case test_electro2:
	  TFMSG("two-point electrostatic");
	  err = plot_electro2(opt);
	  break;
	case test_electro3:
	  TFMSG("three-point electrostatic");
	  err = plot_electro3(opt);
	  break;
	case test_cylinder:
	  TFMSG("cylindrical flow");
	  err = plot_cylinder(opt);
	  break;
	default:
	  err = ERROR_BUG;
	}
    }
  else
    {
      /* data field */

      if (opt->v.verbose)
	{
	  int i;

	  printf("reading field from\n");

	  for (i=0 ; i<opt->input.n ; i++)
	    {
	      printf("  %s\n", opt->input.file[i]);
	    }
	}

      field_t *field = field_read(opt->input.format,
				  opt->input.n,
				  opt->input.file);

      if (!field)
	{
	  fprintf(stderr, "failed to read field\n");
	  return ERROR_READ_OPEN;
	}

      /* this needs to be in libvfplot */

      field_scale(field, opt->v.arrow.scale);

      domain_t* dom;

      if (opt->domain.file)
	dom = domain_read(opt->domain.file);
      else
	dom = field_domain(field);

      if (!dom)
	{
	  fprintf(stderr, "no domain\n");
	  return ERROR_BUG;
	}

      err = plot_generic(dom, (vfun_t)fv_field, (cfun_t)fc_field, (void*)field, opt);

      field_destroy(field);
      domain_destroy(dom);
    }

#ifdef HAVE_STAT

  /* if success then stat the output file */

  if (err == ERROR_OK)
    {
      struct stat sb;

      if ((opt->v.file.output.path != NULL) &&
	  (stat(opt->v.file.output.path, &sb) != 0))
	{
	  fprintf(stderr,
		  "problem with %s : %s\n",
		  opt->v.file.output.path,
		  strerror(errno));
	}
      else
	{
	  if (opt->v.verbose)
	    printf("wrote %li bytes to %s\n",
		   (long)sb.st_size,
		   opt->v.file.output.path);
	}
    }

#endif

  if (opt->v.verbose)
    {

#ifdef HAVE_GETRUSAGE

      /* datailed stats on POSIX systems */

      struct rusage usage;

      if (getrusage(RUSAGE_SELF, &usage) == 0)
	{
	  double
	    user = usage.ru_utime.tv_sec + (double)usage.ru_utime.tv_usec/1e6,
	    sys  = usage.ru_stime.tv_sec + (double)usage.ru_stime.tv_usec/1e6;

	  printf("CPU time %.3f s (user) %.3f s (system)\n", user, sys);
	}
      else
	{
	  fprintf(stderr, "no usage stats (not fatal) ; error %s\n", strerror(errno));
	}

#else

      /* simple stats on C89 systems */
      c1 = clock();

      double wall = ((double)(c1 - c0))/(double)CLOCKS_PER_SEC;

      printf("CPU time %.3f s\n", wall);

#endif

#ifdef HAVE_GETTIMEOFDAY

      struct timeval tv1, dtv;

      gettimeofday(&tv1, NULL);
      timeval_subtract(&dtv, &tv1, &tv0);

      printf("elapsed time %ld.%03ld s\n", dtv.tv_sec, dtv.tv_usec/1000);

#endif
    }


  return err;
}