Exemplo n.º 1
0
static void *techtonics_start(void *args)
{
    SDL_Surface *back = args; 

    vec2 *velocity = alloca(sizeof(vec2) * N_PLATES);

    int i,j;
    for(i = 0; i < N_PLATES; i++)
    {
        vec2_rand(velocity[i]);
    }

    for(j = 0; j < HEIGHT; j++)
    {
        for(i = 0; i < WIDTH; i++)
        {
            int val = unpackid(getpixel(s, i, j));
            int dstx = iwrap(i + velocity[val][X] * 5, WIDTH - 1);
            int dsty = iwrap(j + velocity[val][Y] * 5, HEIGHT - 1);
            setpixel(back, dstx, dsty, val); 
        }
    }
}
Exemplo n.º 2
0
int main (int argc, char *argv[])
   {
      stat   *a,*b;
      hit     h;
      int     p[FIELDS];
      char    str[256], str_last[256];
      char   *s;

      int     i, j, w, c, len = 0;
      idtype     id, threshold, sizelog = SIZELOG;
      

      a = (stat *) malloc ( sizeof (stat) * 1 << sizelog );
      b = (stat *) malloc ( sizeof (stat) * 1 << sizelog );

      threshold = atol ( argv[1] );

      while ( gets (str) )
	 {
	    s = rindex (str, ' ') + 1;
	    
	    str [ s - str - 1 ] = '\0';

	    readhit (str, &h);
	    c = atol (s);

	    if ( c < threshold ) lcheck (&h);

	    id = getid ( &h );

	    if ( !len ) 
	       { 
		  a[0].n = id; 
		  a[0].c = c; 

		  len++; 
	       }
	    else 
	       {
		  w = bfind (a, id, len);

		  if ( w == len )
		    {
		      a[w].n = id;
		      a[w].c = c;

		      len++;
		    }
		  else if ( a[w].n == id ) a[w].c+=c;
		  else 
		    {
		      memcpy ((char *)b, (char *)a + w * sizeof(stat), (len - w) * sizeof(stat));
		      a[w].n = id;
		      a[w].c = c;

		      memcpy ((char *)a + (w + 1) * sizeof(stat), (char *)b, (len - w) * sizeof(stat)); 

		      len++;
		      /*fprintf (stderr, "%d\n", len);*/
/*
		      if ( len == 2 << sizelog )
			{
			  sizelog++;
			  a = (stat *) realloc ( a, sizeof (stat) * 1 << sizelog );
			  b = (stat *) realloc ( b, sizeof (stat) * 1 << sizelog );
			}
 */
		    }
		}
	  }


      for ( i = 0; i < len; i++ )
	 {
	    unpackid (a[i].n, &h);

	    printf ("%d", h.i[0]);

	    for ( j = 1; j < FIELDS; j++ )
	       printf ("_%d", h.i[j]);

	    printf (" %d\n", a[i].c);
	 }

      return 0;

   }