コード例 #1
0
ファイル: exe_list_test.c プロジェクト: colmsjo/batches
int
main(int argc, char *argv[])
{
    exe_list_t *list = NULL;
    exe_t *e = NULL;
    cl_t l1, l2, l3, l4, l5, l6, l7;

    l1.cl_shell = "line 1";
    l2.cl_shell = "line 2";
    l3.cl_shell = "line 3";
    l4.cl_shell = "line 4";
    l5.cl_shell = "line 5";
    l6.cl_shell = "line 6";
    l7.cl_shell = "line 7";

    list = exe_list_init();

    /* trigger a resize of the list during an iteration */
    printf("Adding l1...\n");
    exe_list_add_line(list, &l1);
    printf("Adding l2...\n");
    exe_list_add_line(list, &l2);
    printf("Adding l3...\n");
    exe_list_add_line(list, &l3);
    e = exe_list_first(list);
    print_cur(e);
    e = exe_list_next(list);
    print_cur(e);
    printf("Adding l4...\n");
    exe_list_add_line(list, &l4);
    printf("Adding l5...\n");
    exe_list_add_line(list, &l5);
    printf("Adding l6...\n");
    exe_list_add_line(list, &l6);
    printf("Adding l7...\n");
    exe_list_add_line(list, &l7);

    e = exe_list_next(list);
    print_cur(e);
    e = exe_list_next(list);
    print_cur(e);
    e = exe_list_next(list);
    print_cur(e);
    e = exe_list_next(list);
    print_cur(e);
    e = exe_list_next(list);
    print_cur(e);
    e = exe_list_next(list);
    print_cur(e);

    /* "standard" iteration: */
    print_list(list);

    /* remove item at the beginning and middle of the list + add an item which is already in there */
    printf("removing l1, l3, adding l2\n");
    e = exe_list_first(list);
    print_cur(e);
    printf("Removing l1...\n");
    exe_list_remove_cur(list);
    e = exe_list_next(list);
    print_cur(e);               /* this one will be the item replacing l1 */
    e = exe_list_next(list);
    print_cur(e);
    e = exe_list_next(list);
    print_cur(e);
    printf("Removing l3...\n");
    exe_list_remove_cur(list);
    exe_list_end_iteration(list);
    printf("Adding l2...\n");
    exe_list_add_line(list, &l2);       /* we suppose the list array won't be reallocated() */

    print_list(list);

    /* remove an item at the end of the list: */
    printf("removing l5, l2\n");
    e = exe_list_first(list);
    print_cur(e);
    e = exe_list_next(list);
    print_cur(e);
    e = exe_list_next(list);
    print_cur(e);
    e = exe_list_next(list);
    print_cur(e);
    e = exe_list_next(list);
    print_cur(e);
    printf("Removing l5...\n");
    exe_list_remove_cur(list);
    exe_list_end_iteration(list);
    e = exe_list_first(list);
    print_cur(e);
    e = exe_list_next(list);
    print_cur(e);
    printf("Removing l2...\n");
    exe_list_remove_cur(list);
    exe_list_end_iteration(list);

    print_list(list);

    printf("Adding l1...\n");
    exe_list_add_line(list, &l1);

    print_list(list);

    printf("empty the list\n");
    e = exe_list_first(list);
    print_cur(e);
    exe_list_remove_cur(list);
    e = exe_list_next(list);
    print_cur(e);
    exe_list_remove_cur(list);
    e = exe_list_next(list);
    print_cur(e);
    exe_list_remove_cur(list);
    e = exe_list_next(list);
    print_cur(e);
    exe_list_remove_cur(list);
    e = exe_list_next(list);
    print_cur(e);
    exe_list_remove_cur(list);
    e = exe_list_next(list);
    print_cur(e);

    print_list(list);

    printf("Destroying the list...\n");
    list = exe_list_destroy(list);

    return 0;

}
コード例 #2
0
ファイル: fireworks-30.c プロジェクト: Choino/school
void my_keyboard( unsigned char key, int x, int y ) 
{ 
  switch( key ) {


  case 'q': 
  case 'Q': {
    exit(0) ;
    break ; 
  }
  
  
  case 'w':
  case 'W': {
  		//sparkler out of 1
  		make_fuse(&fuses[cur_fuse = (cur_fuse + 1) % MAX_FIREWORKS], 30, colors[RED], 0, .04, 0, .01, (&nozzles[0])->x, -1);
  }break;
  
  case 'e':
  case 'E': {
  		//sparkler out of 2
  		make_fuse(&fuses[cur_fuse = (cur_fuse + 1) % MAX_FIREWORKS], 30, colors[RED], 0, .04, 0, .01, (&nozzles[1])->x, -1);
  }break;
  
  case 'r':
  case 'R': {
  		//sparkler out of 3
  		make_fuse(&fuses[cur_fuse = (cur_fuse + 1) % MAX_FIREWORKS], 30, colors[RED], 0, .04, 0, .01, (&nozzles[2])->x, -1);
  }break;
  
  case 't':
  case 'T': {
  		make_fuse(&fuses[cur_fuse = (cur_fuse + 1) % MAX_FIREWORKS], 30, colors[RED], 0, .04, 0, .01, (&nozzles[3])->x, -1);
  		//sparkler out of 4
  
  }break;
  
  case 'y':
  case 'Y': {
  		make_fuse(&fuses[cur_fuse = (cur_fuse + 1) % MAX_FIREWORKS], 30, colors[RED], 0, .04, 0, .01, (&nozzles[4])->x, -1);
  		//sparkler out of 5
  
  }break;
  
  case 'u':
  case 'U': {
  		make_fuse(&fuses[cur_fuse = (cur_fuse + 1) % MAX_FIREWORKS], 30, colors[RED], 0, .04, 0, .01, (&nozzles[5])->x, -1);
  		//sparkler out of 6
  
  }break;
  
  case 'i':
  case 'I': {
  		make_fuse(&fuses[cur_fuse = (cur_fuse + 1) % MAX_FIREWORKS], 30, colors[RED], 0, .04, 0, .01, (&nozzles[6])->x, -1);
  		//sparkler out of 7
  
  }break;

  case '+':
  case '=': {
    if (cur_variable == RADIUS) {
      cur_radius += 2;
    }
    if (cur_variable == DENSITY) {
      cur_density += 1;
    }
    if (cur_variable == QUANTITY) {
      cur_quantity += 5;
    }
    if (cur_variable == CUBE_SIZE) {
      cur_cube_size += .001;
    }
    if (cur_variable == AFTER_COUNTER) {
      cur_after_counter += 10;
    }
    print_cur();
  } break;

  case 'j': {
    light_screen = 1;
  } break;

  case '-':
  case '_': {
    if (cur_variable == RADIUS) {
      cur_radius -= 2;
    }
    if (cur_variable == DENSITY) {
      cur_density -= 1;
    }
    if (cur_variable == QUANTITY) {
      cur_quantity -= 5;
    }
    if (cur_variable == CUBE_SIZE) {
      cur_cube_size -= .001;
    }
    if (cur_variable == AFTER_COUNTER) {
      cur_after_counter -= 10;
    }
    print_cur();
  } break;


  case 'z': {
    music_playing = (music_playing + 1) % 2;
    if (music_playing) {
      BASS_ChannelPlay(sounds[8], FALSE);
    }
    else {
      BASS_ChannelPause(sounds[8]);
    }
  } break;



  case 'a':
  case 'A': {
    cur_variable = RADIUS;
    print_cur();
  } break;
  case 's':
  case 'S': {
    cur_variable = DENSITY;
    print_cur();
  } break;
  case 'd':
  case 'D': {
    cur_variable = QUANTITY;
    print_cur();
  } break;
  case 'f':
  case 'F': {
    cur_variable = CUBE_SIZE;
    print_cur();
  } break;
  case 'g':
  case 'G': {
    cur_variable = AFTER_COUNTER;
    print_cur();
  } break;

  case '1': {

    make_fuse(&fuses[cur_fuse = (cur_fuse + 1) % MAX_FIREWORKS], 30, colors[RED], 0, .04, 0, .01, (&nozzles[0])->x, (&nozzles[0])->y);
    BASS_ChannelPlay(sounds[9], TRUE);
    break;
  }
  case '2': {
    make_fuse(&fuses[cur_fuse = (cur_fuse + 1) % MAX_FIREWORKS], 30, colors[RED], 0, .04, 0, .01, (&nozzles[1])->x, (&nozzles[1])->y);
    BASS_ChannelPlay(sounds[10], TRUE);

    break;
  }
  case '3': {
    make_fuse(&fuses[cur_fuse = (cur_fuse + 1) % MAX_FIREWORKS], 30, colors[RED], 0, .04, 0, .01, (&nozzles[2])->x, (&nozzles[2])->y);
    BASS_ChannelPlay(sounds[11], TRUE);

    break;
  }
  case '4': {
    make_fuse(&fuses[cur_fuse = (cur_fuse + 1) % MAX_FIREWORKS], 30, colors[RED], 0, .04, 0, .01, (&nozzles[3])->x, (&nozzles[3])->y);
    BASS_ChannelPlay(sounds[12], TRUE);

    break;
  }
  case '5': {
    make_fuse(&fuses[cur_fuse = (cur_fuse + 1) % MAX_FIREWORKS], 30, colors[RED], 0, .04, 0, .01, (&nozzles[4])->x, (&nozzles[4])->y);
    BASS_ChannelPlay(sounds[13], TRUE);

    break;
  }
  case '6': {
    make_fuse(&fuses[cur_fuse = (cur_fuse + 1) % MAX_FIREWORKS], 30, colors[RED], 0, .04, 0, .01, (&nozzles[5])->x, (&nozzles[5])->y);
    BASS_ChannelPlay(sounds[14], TRUE);
  
    break;
  }
  case '7': {
    make_fuse(&fuses[cur_fuse = (cur_fuse + 1) % MAX_FIREWORKS], 30, colors[RED], 0, .04, 0, .01, (&nozzles[6])->x, (&nozzles[6])->y);
    BASS_ChannelPlay(sounds[15], TRUE);
   
    break;
  }

  default: break;
  }


  glutPostRedisplay();
}
コード例 #3
0
ファイル: fireworks-24.c プロジェクト: Zaxcoding/fireworks
void my_keyboard( unsigned char key, int x, int y ) 
{

  GLfloat used_radius;
  GLfloat used_density;
  int used_quantity;
  GLfloat used_cube_size;
  int used_after_counter;
  int num = rand() % (NUM_SOUNDS - 2);
  
   
  int cur_shape = rand() % (NUM_SHAPES+1);			//right now 2 0-regular 1-burst
  
  if(cur_shape){
  		used_radius = reg_radius;
  		used_density = reg_density;
  		used_quantity = reg_quantity;
  		used_after_counter = reg_after_counter;
  
  }
  else{
  		used_radius = bur_radius;
  		used_density = bur_density;
  		used_quantity = bur_quantity;
  		used_after_counter = bur_after_counter;
  		BASS_ChannelSetAttribute(sounds[num], BASS_ATTRIB_VOL, 90);
  	
  
  }

  GLfloat new_radius = (float)((rand()%41 -20)/100.)*used_radius +used_radius;
  GLfloat new_density = (float)((rand()%41 -20)/100.)*used_density +used_density;
  int new_quantity = (int)((float)(rand()%41 -20)/100.)*used_quantity +used_quantity;
  GLfloat new_after_counter= (float)((rand()%41 -20)/100.)*used_after_counter +used_after_counter;
  //GLfloat cur_cube_size = .007;

    
  

  switch( key ) {

  case 'q': 
  case 'Q': {
    exit(0) ;
    break ; 
  }

  case '+':
  case '=': {
    if (cur_variable == RADIUS) {
      cur_radius += 2;
    }
    if (cur_variable == DENSITY) {
      cur_density += 1;
    }
    if (cur_variable == QUANTITY) {
      cur_quantity += 5;
    }
    if (cur_variable == CUBE_SIZE) {
      cur_cube_size += .001;
    }
    if (cur_variable == AFTER_COUNTER) {
      cur_after_counter += 10;
    }
    print_cur();
  } break;

  case 'j': {
    light_screen = 1;
  } break;

  case '-':
  case '_': {
    if (cur_variable == RADIUS) {
      cur_radius -= 2;
    }
    if (cur_variable == DENSITY) {
      cur_density -= 1;
    }
    if (cur_variable == QUANTITY) {
      cur_quantity -= 5;
    }
    if (cur_variable == CUBE_SIZE) {
      cur_cube_size -= .001;
    }
    if (cur_variable == AFTER_COUNTER) {
      cur_after_counter -= 10;
    }
    print_cur();
  } break;


  case 'z': {
    music_playing = (music_playing + 1) % 2;
    if (music_playing) {
      BASS_ChannelPlay(sounds[8], FALSE);
    }
    else {
      BASS_ChannelPause(sounds[8]);
    }
  } break;



  case 'a':
  case 'A': {
    cur_variable = RADIUS;
    print_cur();
  } break;
  case 's':
  case 'S': {
    cur_variable = DENSITY;
    print_cur();
  } break;
  case 'd':
  case 'D': {
    cur_variable = QUANTITY;
    print_cur();
  } break;
  case 'f':
  case 'F': {
    cur_variable = CUBE_SIZE;
    print_cur();
  } break;
  case 'g':
  case 'G': {
    cur_variable = AFTER_COUNTER;
    print_cur();
  } break;

  case '1': {

  	make_explosion(&explosions[num_fireworks = (num_fireworks + 1 )% MAX_FIREWORKS], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[0])->x, (&nozzles[0])->y + 1.2);
    //make_explosion(&explosions[0], 60, 1, 5000, .02, 48, 1, test_sound, (&nozzles[0])->x, (&nozzles[0])->y + 1);
    BASS_ChannelPlay(sounds[cur_shape], TRUE);

    break;
  }
  case '2': {
  	 make_explosion(&explosions[num_fireworks = (num_fireworks + 1 )% MAX_FIREWORKS], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[1])->x, (&nozzles[1])->y + 1.2);
    //make_explosion(&explosions[1], 500, 1, 100, .01, 1100, 1, test_sound, (&nozzles[1])->x, (&nozzles[1])->y + 1);
        BASS_ChannelPlay(sounds[cur_shape], TRUE);

    break;
  }
  case '3': {
  	 make_explosion(&explosions[num_fireworks = (num_fireworks + 1 )% MAX_FIREWORKS], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[2])->x, (&nozzles[2])->y + 1.2);
    //make_explosion(&explosions[2], 6MAX_FIREWORKS, 1, 100, .05, 800, 1, test_sound, (&nozzles[2])->x, (&nozzles[2])->y + 1);
        BASS_ChannelPlay(sounds[cur_shape], TRUE);

    break;
  }
  case '4': {
     if(cur_shape){
     	if(cur_shape ==1){
     		new_radius *=1.5;
     		new_quantity *=1.2;
     	}
     
     }
  	 make_explosion(&explosions[num_fireworks = (num_fireworks + 1 )% MAX_FIREWORKS], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[3])->x, (&nozzles[3])->y + 1.2);
    //make_explosion(&explosions[3], 1000, 1, 100, .05, 900, 1, test_sound, (&nozzles[3])->x, (&nozzles[3])->y + 1);
        BASS_ChannelPlay(sounds[cur_shape], TRUE);

    break;
  }
  case '5': {
  	 make_explosion(&explosions[num_fireworks = (num_fireworks + 1 )% MAX_FIREWORKS], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[4])->x, (&nozzles[4])->y + 1.2);
    //make_explosion(&explosions[4], 1MAX_FIREWORKS0, 1, 100, .1, 1000, 1, test_sound, (&nozzles[4])->x, (&nozzles[4])->y + 1);
        BASS_ChannelPlay(sounds[cur_shape], TRUE);

    break;
  }
  case '6': {
  	 make_explosion(&explosions[num_fireworks = (num_fireworks + 1 )% MAX_FIREWORKS], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[5])->x, (&nozzles[5])->y + 1.2);
    //make_explosion(&explosions[5], 600, 1, 100, .09, 1100, 1, test_sound, (&nozzles[5])->x, (&nozzles[5])->y + 1);
        BASS_ChannelPlay(sounds[cur_shape], TRUE);

    break;
  }
  case '7': {
  	 make_explosion(&explosions[num_fireworks = (num_fireworks + 1 )% MAX_FIREWORKS], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[6])->x, (&nozzles[6])->y + 1.2);
    //make_explosion(&explosions[6], 2MAX_FIREWORKS0, 1, 100, .3, 1200, 1, test_sound, (&nozzles[6])->x, (&nozzles[6])->y + 1);
        BASS_ChannelPlay(sounds[cur_shape], TRUE);

    break;
  }
  case '0': {
  	
    make_explosion(&explosions[num_fireworks = (num_fireworks + 1 )% MAX_FIREWORKS], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[3])->x, (&nozzles[3])->y + 1);
  } break;

  default: break;
  }


  glutPostRedisplay();
}
コード例 #4
0
ファイル: fireworks-21.c プロジェクト: Choino/school
void my_keyboard( unsigned char key, int x, int y ) 
{
  int num = rand() % (NUM_SOUNDS - 2);
  GLfloat new_radius = (float)((rand()%41 -20)/100.)*cur_radius +cur_radius;
  GLfloat new_density = (float)((rand()%41 -20)/100.)*cur_density +cur_density;
  int new_quantity = (int)((float)(rand()%41 -20)/100.)*cur_quantity +cur_quantity;
  GLfloat new_after_counter= (float)((rand()%41 -20)/100.)*cur_after_counter +cur_after_counter;
  //GLfloat cur_cube_size = .007;

  int cur_shape = 1;
  
  printf("num is %d", num);
  
  

  switch( key ) {

  case 'q': 
  case 'Q': {
    exit(0) ;
    break ; 
  }

  case '+':
  case '=': {
    if (cur_variable == RADIUS) {
      cur_radius += 2;
    }
    if (cur_variable == DENSITY) {
      cur_density += 1;
    }
    if (cur_variable == QUANTITY) {
      cur_quantity += 5;
    }
    if (cur_variable == CUBE_SIZE) {
      cur_cube_size += .001;
    }
    if (cur_variable == AFTER_COUNTER) {
      cur_after_counter += 10;
    }
    print_cur();
  } break;

  case '-':
  case '_': {
    if (cur_variable == RADIUS) {
      cur_radius -= 2;
    }
    if (cur_variable == DENSITY) {
      cur_density -= 1;
    }
    if (cur_variable == QUANTITY) {
      cur_quantity -= 5;
    }
    if (cur_variable == CUBE_SIZE) {
      cur_cube_size -= .001;
    }
    if (cur_variable == AFTER_COUNTER) {
      cur_after_counter -= 10;
    }
    print_cur();
  } break;


  case 'z': {
    music_playing = (music_playing + 1) % 2;
    if (music_playing) {
      BASS_ChannelPlay(sounds[8], FALSE);
    }
    else {
      BASS_ChannelPause(sounds[8]);
    }
  } break;



  case 'a':
  case 'A': {
    cur_variable = RADIUS;
    print_cur();
  } break;
  case 's':
  case 'S': {
    cur_variable = DENSITY;
    print_cur();
  } break;
  case 'd':
  case 'D': {
    cur_variable = QUANTITY;
    print_cur();
  } break;
  case 'f':
  case 'F': {
    cur_variable = CUBE_SIZE;
    print_cur();
  } break;
  case 'g':
  case 'G': {
    cur_variable = AFTER_COUNTER;
    print_cur();
  } break;

  case '1': {
  	 make_explosion(&explosions[0], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[0])->x, (&nozzles[0])->y + 1.2);
    //make_explosion(&explosions[0], 60, 1, 5000, .02, 48, 1, test_sound, (&nozzles[0])->x, (&nozzles[0])->y + 1);
    BASS_ChannelPlay(sounds[num], TRUE);

    break;
  }
  case '2': {
  	 make_explosion(&explosions[1], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[1])->x, (&nozzles[1])->y + 1.2);
    //make_explosion(&explosions[1], 500, 1, 100, .01, 1100, 1, test_sound, (&nozzles[1])->x, (&nozzles[1])->y + 1);
        BASS_ChannelPlay(sounds[num], TRUE);

    break;
  }
  case '3': {
  	 make_explosion(&explosions[2], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[2])->x, (&nozzles[2])->y + 1.2);
    //make_explosion(&explosions[2], 650, 1, 100, .05, 800, 1, test_sound, (&nozzles[2])->x, (&nozzles[2])->y + 1);
        BASS_ChannelPlay(sounds[num], TRUE);

    break;
  }
  case '4': {
  	 make_explosion(&explosions[3], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[3])->x, (&nozzles[3])->y + 1.2);
    //make_explosion(&explosions[3], 1000, 1, 100, .05, 900, 1, test_sound, (&nozzles[3])->x, (&nozzles[3])->y + 1);
        BASS_ChannelPlay(sounds[num], TRUE);

    break;
  }
  case '5': {
  	 make_explosion(&explosions[4], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[4])->x, (&nozzles[4])->y + 1.2);
    //make_explosion(&explosions[4], 1500, 1, 100, .1, 1000, 1, test_sound, (&nozzles[4])->x, (&nozzles[4])->y + 1);
        BASS_ChannelPlay(sounds[num], TRUE);

    break;
  }
  case '6': {
  	 make_explosion(&explosions[5], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[5])->x, (&nozzles[5])->y + 1.2);
    //make_explosion(&explosions[5], 600, 1, 100, .09, 1100, 1, test_sound, (&nozzles[5])->x, (&nozzles[5])->y + 1);
        BASS_ChannelPlay(sounds[num], TRUE);

    break;
  }
  case '7': {
  	 make_explosion(&explosions[6], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[6])->x, (&nozzles[6])->y + 1.2);
    //make_explosion(&explosions[6], 2500, 1, 100, .3, 1200, 1, test_sound, (&nozzles[6])->x, (&nozzles[6])->y + 1);
        BASS_ChannelPlay(sounds[num], TRUE);

    break;
  }
  case '0': {
  	
    make_explosion(&explosions[3], new_radius, new_density, new_quantity, cur_cube_size, new_after_counter, cur_shape, test_sound, (&nozzles[3])->x, (&nozzles[3])->y + 1);
  } break;

  default: break;
  }

  glutPostRedisplay();
}