예제 #1
0
void
draw_multi_rooms (void)
{
  int x, y;

  mr_map_rooms ();

  if (anim_cycle == 0) {
    generate_wall_colors_for_room (0, room0_wall_color);
  }

  if (em == PALACE && vm == VGA
      && (has_mr_view_changed ()
          || em != mr.last.em
          || vm != mr.last.vm))
    generate_wall_colors ();

  if (has_mr_view_changed ()) {
    generate_stars ();
    generate_mirrors_reflex ();
  }

  if (mouse_pos.room != mr.last.mouse_pos.room
      || mouse_pos.floor != mr.last.mouse_pos.floor
      || mouse_pos.place != mr.last.mouse_pos.place) {
    if (is_valid_pos (&mouse_pos))
      update_cache_pos (&mouse_pos, em, vm);
    if (is_valid_pos (&mr.last.mouse_pos))
      update_cache_pos (&mr.last.mouse_pos, em, vm);
  }

  if (anim_cycle == 0
      || em != mr.last.em
      || vm != mr.last.vm
      || hgc != mr.last.hgc
      || hue != mr.last.hue) {
    update_room0_cache (em, vm);
  }

  if (anim_cycle == 0
      || has_mr_view_changed ()
      || em != mr.last.em
      || vm != mr.last.vm
      || hgc != mr.last.hgc
      || hue != mr.last.hue
      || level.number != mr.last.level) {
    update_cache (em, vm);
  }

  size_t i;
  for (i = 0; i < changed_pos_nmemb; i++) {
    /* printf ("%i,%i,%i\n", changed_pos[i].room, changed_pos[i].floor, changed_pos[i].place); */
    update_cache_pos (&changed_pos[i], em, vm);
  }
  destroy_array ((void **) &changed_pos, &changed_pos_nmemb);

  clear_bitmap (screen, BLACK);

  for (y = mr.h - 1; y >= 0; y--)
    for (x = 0; x < mr.w; x++) {
      if (! mr.cell[x][y].room) continue;
      mr.dx = x;
      mr.dy = y;
      draw_animated_background (mr.cell[x][y].screen, mr.cell[x][y].room);
    }

  if (! no_room_drawing) draw_bitmap (cache, screen, 0, 0, 0);

  for (y = mr.h - 1; y >= 0; y--)
    for (x = 0; x < mr.w; x++) {
      if (! mr.cell[x][y].room) continue;
      mr.dx = x;
      mr.dy = y;
      draw_animated_foreground (mr.cell[x][y].screen, mr.cell[x][y].room);
    }

  if (mr.select_cycles > 0) {
    al_hold_bitmap_drawing (false);

    int x0 = ORIGINAL_WIDTH * mr.x;
    int y0 = ROOM_HEIGHT * mr.y + 3;
    int x1 = x0 + ORIGINAL_WIDTH;
    int y1 = y0 + ROOM_HEIGHT;
    draw_rectangle (screen, x0, y0, x1, y1, RED, 1);

    mr.select_cycles--;
  }

  mr.dx = mr.dy = -1;

  mr_update_last_settings ();
}
예제 #2
0
int main( int argc, char **argv ){

    /* MPI Initialization */
    int nprocs, rank;
    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    /* CL input for total number of stars in each mock */
    if (argc != 2){
        fprintf( stderr, "Error. Usage: %s num_stars\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    /* total number of stars in temp galaxy */
    unsigned long int N_stars;
    sscanf(argv[1], "%lu", &N_stars);
    if(rank==0) fprintf(stderr, "%lu stars per temporary galaxy.\n", N_stars);

    /* have each process only make some stars */
    N_stars /= nprocs;
    if(rank==0) fprintf(stderr, "%d processes each responsible for %lu stars.\n", nprocs, N_stars);

    /* different variables used in main */
    POINTING *plist;        /* a pointing structure */
    int N_plist;            /* number of l.o.s. */
    int loop_flag;          /* set = 0 when file creation complete */
    int pointings_in_need;  /* a progress checker */
    PARAMS params;          /* parameters for mock creation */
    time_t t;               /* initialization of random seed */
    int N_mock;             /* # of stars in current mock l.o.s. */
    int N_mock_temp;
    int N_mock_proc;
    int N_data;             /* desired # of stars in current l.o.s. */
    int i;                  /* for loop index */
    int loop_counter;       /* a progress checker */

    /* have each proc separately load info for different pointings */
    int current_rank = 0;
    while ( current_rank < nprocs ){
        if (current_rank == rank) load_pointing_list(&N_plist, &plist, rank);
        MPI_Barrier(MPI_COMM_WORLD);
        current_rank++;
    }

    /* get info for mock */
    /* change this to CL input eventually */
    get_params(&params, N_stars, rank);

    /* Allocate arrays for galactic coordinates */
    STAR * thin  = malloc(params.N_thin * sizeof(STAR));
    STAR * thick = malloc(params.N_thick * sizeof(STAR));

    /* initialize random seed -- make different for each mock */
    srand((unsigned) time(&t) + (1+rank));

    /* Initialize for while loop */
    loop_flag    = 0;
    loop_counter = 0;

    /* create temp mocks until all l.o.s. are filled */
    while(loop_flag==0){

        /* re-initialize at each step */
        pointings_in_need = 0;
        loop_flag         = 1;

        /* Make thin and thick disks */
        generate_stars(thin, &params, 0);
        generate_stars(thick, &params, 1);

        /* Separate stars into appropriate l.o.s. */
        separate_sample(plist, thin, N_plist, params.N_thin, rank);
        separate_sample(plist, thick, N_plist, params.N_thick, rank);

        /* Check all l.o.s. to see if we have enough stars */
        for( i=0; i<N_plist; i++ ){

            /* set total stars for this temp gxy = 0 */
            N_mock_temp = 0;

            /* current pointings stars/proc */
            N_mock_proc = plist[i].N_mock_proc;

            /* Sum stars across all processes to get pointing's total stars for this temp gxy */
            MPI_Allreduce(&N_mock_proc, &N_mock_temp, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);

            /* Add temp galaxy's stars to total */
            plist[i].N_mock += N_mock_temp;
            N_mock = plist[i].N_mock;
            N_data = plist[i].N_data;

            if(N_mock<N_data){
                /* indicate that we need more stars */
                loop_flag         = 0;
                plist[i].flag     = 0;
                pointings_in_need += 1;
            }
            else{
                /* we don't need more stars for this l.o.s. */
                plist[i].flag = 1;
            }
        }

        /* update progress and output results to user */
        loop_counter +=1;
        if(rank==0){
            fprintf(stderr, "We've run the loop %d times.\n", loop_counter);
            if (pointings_in_need != 0){
                fprintf(stderr, "%d pointings need more stars.\n", pointings_in_need);
                fprintf(stderr, "Making more stars. \n");
            }
            else fprintf(stderr, "All pointings have an adequate number of stars. \n");
        }
    }

    /* Deallocate arrays */
    free(thin);
    free(thick);
    free(plist);
    if(rank==0) fprintf(stderr, "Files Written. Arrays deallocated.\n");

    MPI_Finalize();

    return 0;
}
예제 #3
0
void
draw_multi_rooms (void)
{
  int x, y;

  mr_set_origin (mr.room, mr.x, mr.y);

  bool mr_view_changed = has_mr_view_changed ();

  if (mr_view_changed) force_full_redraw = true;

  if (anim_cycle == 0) {
    generate_wall_colors_for_room (0, room0_wall_color);
  }

  if (em == PALACE && vm == VGA
      && (mr_view_changed
          || em != mr.last.em
          || vm != mr.last.vm))
    generate_wall_colors ();

  if (mr_view_changed)
    generate_stars ();

  if (mouse_pos.room != mr.last.mouse_pos.room
      || mouse_pos.floor != mr.last.mouse_pos.floor
      || mouse_pos.place != mr.last.mouse_pos.place) {
    if (is_valid_pos (&mouse_pos))
      update_cache_pos (&mouse_pos, CHPOS_MOUSE_SELECT, em, vm);
    if (is_valid_pos (&mr.last.mouse_pos))
      update_cache_pos (&mr.last.mouse_pos, CHPOS_MOUSE_DESELECT, em, vm);
  }

  if (anim_cycle == 0
      || em != mr.last.em
      || vm != mr.last.vm
      || hgc != mr.last.hgc
      || hue != mr.last.hue) {
    update_room0_cache (em, vm);
    force_full_redraw = true;
  }

  if (anim_cycle == 0
      || mr_view_changed
      || em != mr.last.em
      || vm != mr.last.vm
      || hgc != mr.last.hgc
      || hue != mr.last.hue
      || global_level.number != mr.last.level) {
    update_cache (em, vm);
  }

  size_t i;
  for (i = 0; i < changed_pos_nmemb; i++)
    update_cache_pos (&changed_pos[i].p, changed_pos[i].reason, em, vm);
  destroy_array ((void **) &changed_pos, &changed_pos_nmemb);

  for (i = 0; i < changed_room_nmemb; i++)
    update_cache_room (changed_room[i], em, vm);
  destroy_array ((void **) &changed_room, &changed_room_nmemb);

  for (y = mr.h - 1; y >= 0; y--)
    for (x = 0; x < mr.w; x++) {
      clear_bitmap (mr.cell[x][y].screen, (mr.flicker > 0 && mr.flicker % 2)
                    ? mr.color : BLACK);

      if (! mr.cell[x][y].room) continue;
      mr.dx = x;
      mr.dy = y;
      draw_animated_background (mr.cell[x][y].screen,
                                mr.cell[x][y].room);
    }

  if (mr.flicker > 0) mr.flicker--;

  struct mr_room_list l;
  mr_get_room_list (&l);

  int xm, ym;
  if (! no_room_drawing)
    for (i = 0; i < l.nmemb; i++) {
      mr_coord (l.room[i], -1, &xm, &ym);
      for (y = mr.h - 1; y >= 0; y--)
        for (x = 0; x < mr.w; x++)
          if (mr.cell[x][y].room == l.room[i])
            draw_bitmap (mr.cell[xm][ym].cache,
                         mr.cell[x][y].screen, 0, 0, 0);
    }

  mr_destroy_room_list (&l);

  /* if (! no_room_drawing) */
  /*   for (y = mr.h - 1; y >= 0; y--) */
  /*     for (x = 0; x < mr.w; x++) */
  /*       if (mr.cell[x][y].room) */
  /*         draw_bitmap (mr.cell[x][y].cache, mr.cell[x][y].screen, 0, 0, 0); */

  for (y = mr.h - 1; y >= 0; y--)
    for (x = 0; x < mr.w; x++) {
      if (! mr.cell[x][y].room) continue;
      mr.dx = x;
      mr.dy = y;
      draw_animated_foreground (mr.cell[x][y].screen, mr.cell[x][y].room);
    }

  /* if (mr.select_cycles > 0) { */
  /*   int t = max_int (mr.w, mr.h); */
  /*   draw_rectangle (mr.cell[mr.x][mr.y].screen, 0, 3, */
  /*                   ORIGINAL_WIDTH - t, */
  /*                   3 + ROOM_HEIGHT - t, RED, t); */
  /*   mr.select_cycles--; */
  /* } */

  mr_update_last_settings ();
}