void 
resize_geometry (int new_width, int new_height)
{
    if (display.winW == new_width && display.winH == new_height) {
	/* Not a resize event. */
	return;
    }

    /* Update display info */
    display.winW = new_width;
    display.winH = new_height;

    /* Expand pixmap if necessary */
    new_width = new_width - 2*borderx;
    new_height = new_height - 2*bordery;
    resize_pixmap (new_width, new_height);

    /* Adjust items that need adjusting */
    initialize_geometry (&scr);
    scr.select_message.y = SELECT_BUTTON_MESSAGE_Y + (new_height - 480);
    scr.date.y = DATE_Y + (new_height - 480);
    scr.time_for_year.y = TIME_FOR_YEAR_Y + (new_height - 480);
    resize_main_win (new_width, new_height);

    scr.pbar_area.x = 56 + scr.main_win.w + 16 + 2;
    scr.pbar_pop.x = scr.pbar_area.x + 4;
    scr.pbar_tech.x = scr.pbar_area.x + 4;
    scr.pbar_food.x = scr.pbar_area.x + 4;
    scr.pbar_jobs.x = scr.pbar_area.x + 4;
    scr.pbar_money.x = scr.pbar_area.x + 4;
    scr.pbar_coal.x = scr.pbar_area.x + 4;
    scr.pbar_goods.x = scr.pbar_area.x + 4;
    scr.pbar_ore.x = scr.pbar_area.x + 4;
    scr.pbar_steel.x = scr.pbar_area.x + 4;

    scr.monthgraph.x = scr.pbar_area.x + 4;
    scr.mappoint_stats.x = scr.pbar_area.x + 4;
    scr.market_cb.x = scr.pbar_area.x;

    scr.mini_map_aux.x = scr.pbar_area.x + 4;
    scr.mini_map_area.x = scr.pbar_area.x + 4;
    scr.mini_map.x = scr.mini_map_aux.x 
	    + ((scr.mini_map_aux.w - scr.mini_map.w) / 2);

    /* Complete refresh of the screen required here */
    screen_full_refresh ();
}
示例#2
0
int main (int argc, char ** argv)
{
  int i;
    
  /*
   *  this is set to either euler or runge_kutta_4
   */
  enum solver_t solver;

  /*
   *  bc (boundary condition) can be either periodic or no_slip
   */
  enum bc_t bc;

  /*
   * these specify the geometry of the area to be simulated 
   * tdim ist the total number of points, i.e. tdim = xdim *ydim 
   */
  int xdim, ydim, tdim;
  double dx, dy;

  /*
   * this holds the neighbors 
   */
  int **neighbors;

  /*
   * this holds latitude and longitude values of each point
   */
  unsigned int *lat, *lon;

  /*
   * this holds order of the data to be printed out
   */
  unsigned int *print_out_order;

  /*
   * these control temporal aspects of the simulation 
   */
  long int ncycle;
  double dt = 5.1;
  long int n_iter = 25800;
  int write_out_interval = 5000;

  /*
   * these hold the physical parameters 
   *
   * f0:              coriolis parameter (1/1sec)
   * beta:            linear beta for coriolis force (1/(meter sec))
   * forcingTerm:     Wind stress amplitude "tau_0"(N/meter^2)
   * dissipationTerm: "A" viscosity coefficient (meters^2/sec)
   * RayleighFriction: Rayleigh friction parameter (1/sec)
   */
  double f0 = 5.0e-5;
  double beta =2e-11;
  double forcingTerm = 0.0005;
  double dissipationTerm = 0.00005;
  double RayleighFriction = 5e-8;

  /*
   * upper layer equilibrium depth (meters)
   */
  double EquilibriumDepth = 50000.0;
  double A;

  /*
   * this holds the physical parameters and the forcing
   */
  double *parameters;
  double *x_forcing, *y_forcing, *z_forcing;

  /*
   * "fields" holds the values of the u, v and P fields
   */
  double *fields;
  double *u, *v, *P;     

  /*
   * "fields_prev" holds the u, v and P values of the previous time step
   */
  //double *fields_prev;
  //double *u_prev, *v_prev, *P_prev;     

  /*
   * these are temporary storage locations 
   * for the Runge-Kutta scheme
   */
  double *temp_dots_rk;
  double *temp_fields_rk;

  /*
   * read parameters from command line
   */
  if(argc == 2){

    get_parameters(argv[1], &xdim, &ydim, &dx, &dy, &n_iter, &dt, &write_out_interval, &bc, &solver, &f0, &beta, &forcingTerm, &dissipationTerm, &RayleighFriction, &EquilibriumDepth, &A);

  }
  else{

    fprintf(stderr, "ERROR: You need to give a file containing the parameters as an argument!\n");
    exit(1);

  }

  print_parameters(xdim, ydim, dx, dy, n_iter, dt, write_out_interval, bc, solver, f0, beta, forcingTerm, dissipationTerm, RayleighFriction, EquilibriumDepth, A);

  tdim = xdim*ydim;

  /*
   *  allocate arrays containing geometrical information and fill these
   */
  lat = calloc(tdim, sizeof(unsigned int)); 
  lon = calloc(tdim, sizeof(unsigned int)); 
  print_out_order = calloc(tdim, sizeof(unsigned int)); 
  neighbors = calloc(tdim, sizeof(int*)); 
  for(i=0; i< tdim; i++){
    neighbors[i] = calloc(4, sizeof(int));
  }

  initialize_geometry(xdim, ydim, neighbors, lat, lon, print_out_order);

  /*
   * allocate memory for physical parameters and forcing
   */
  parameters = calloc(5+3*tdim, sizeof(double));

  parameters[0] = f0;
  parameters[1] = beta;
  parameters[2] = forcingTerm;
  parameters[3] = dissipationTerm;
  parameters[4] = RayleighFriction;

  x_forcing = parameters + 5;
  y_forcing = parameters + 5 + tdim;
  z_forcing = parameters + 5 + 2*tdim;

  /*
   * allocate "fields" and set addresses for u, v, and P
   */
  fields = calloc(3*tdim, sizeof(double));
  u = fields;
  v = fields + tdim;
  P = fields + 2 * tdim;

  /*
   * allocate "fields_prev" and set addresses for u_prev, v_prev, and P_prev
   */
  //fields_prev = calloc(3*tdim, sizeof(double));
  //u_prev = fields_prev;
  //v_prev = fields_prev + tdim;
  //P_prev = fields_prev + 2 * tdim;

  double *fields_dot;
  fields_dot = calloc(3*tdim, sizeof(double));

  /*
   * allocate memory for temporary Runge-Kutta storage locations 
   */
  temp_dots_rk = calloc(3*tdim, sizeof(double));
  temp_fields_rk = calloc(3*tdim, sizeof(double));

  /*
   * initialize fields
   */
  initialize_fields (u, v, P, x_forcing, y_forcing, z_forcing, xdim, ydim, dx, dy, EquilibriumDepth, A, neighbors, lat, lon, bc);

  /*
   *  loop through time steps to do the actual simulation
   */
  for (ncycle=0; ncycle<n_iter; ncycle++) {
    //printf("step #%li\n", ncycle);

    /*
     * print result
     */
    if(ncycle % write_out_interval == 0){
      print_field(u, "u", ncycle, xdim, ydim, print_out_order);
      print_field(v, "v", ncycle, xdim, ydim, print_out_order);
      print_field(P, "P", ncycle, xdim, ydim, print_out_order);
      printf("%li ", ncycle);
      fflush(stdout);
    }
    Fcalc(fields_dot, fields, parameters, xdim, ydim, dx, dy, neighbors, lat, bc, print_out_order, ncycle);
 

    //for (i=0;i<3*tdim;i++) {
    //  fields_prev[i] = fields[i];
    //}

    if(solver == runge_kutta_4){

      /*
       *  Runge-Kutta 4th order
       *
       *                 dt
       *    y_1 = y_0 + ---- (y'_0 + 2 * y'_A + 2 * y'_B +y'_C)
       *                  6
       */

      /*                          dt
       * first step: y_A = y_0 + ---- y'_0
       *                          2
       */
      for (i=0; i < 3*tdim;  i++) {
        temp_fields_rk[i] = fields[i]+0.5*dt*fields_dot[i];
      }
      Fcalc(temp_dots_rk, temp_fields_rk, parameters, xdim, ydim, dx, dy, neighbors, lat, bc, print_out_order, ncycle);
      for (i=0; i < 3*tdim;  i++) {
        fields_dot[i] += 2*temp_dots_rk[i];
      }

      /*                           dt
       * second step: y_B = y_0 + ---- y'_A
       *                            2
       */
      for (i=0; i < 3*tdim;  i++) {
        temp_fields_rk[i] = fields[i]+0.5*dt*temp_dots_rk[i];
      }
      Fcalc(temp_dots_rk, temp_fields_rk, parameters, xdim, ydim, dx, dy, neighbors, lat, bc, print_out_order, ncycle);
      for (i=0; i < 3*tdim;  i++) {
        fields_dot[i] += 2*temp_dots_rk[i];
      }

      /*
       * third step: y_C = y_0 + dt * y'_B
       */
      for (i=0; i < 3*tdim;  i++){
        temp_fields_rk[i] = fields[i]+dt*temp_dots_rk[i];
      }
      Fcalc(temp_dots_rk, temp_fields_rk, parameters, xdim, ydim, dx, dy, neighbors, lat, bc, print_out_order, ncycle);
      for (i=0; i < 3*tdim;  i++) {
        fields_dot[i] += temp_dots_rk[i];
      }

      /*                          dt
       * final step: y_1 = y_0 + ---- (y'_0 + 2 * y'_A + 2 * y'_B +y'_C)
       *                           6
       */
      for (i=0; i < 3*tdim;  i++) {
        fields_dot[i] /= 6.0;
        fields[i] += dt*fields_dot[i];
      }
    }
    else{

      if(solver == euler){

        /*
         *  the Euler scheme
         */
        for (i=0; i < 3*tdim;  i++) {
          fields[i] += dt*fields_dot[i];
        }
      }
      else{
        fprintf(stderr, "ERROR: No valid solver was found\n");
        exit(2);
      }
    }
  }
  printf("\n");

  return(0);
}
示例#3
0
int
lincity_main (int argc, char *argv[])
{
#if defined (LC_X11)
    char *geometry = NULL;
#endif

#if defined (SVGALIB)
    int q;
    vga_init ();
#endif

#if !defined (WIN32)
    signal (SIGPIPE, SIG_IGN);    /* broken pipes are ignored. */
#endif

    /* Initialize some global variables */
    make_dir_ok_flag = 1;
    main_screen_originx = 1;
    main_screen_originy = 1;
    given_scene[0] = 0;
    quit_flag = network_flag = load_flag = save_flag 
	    = prefs_flag = cheat_flag = monument_bul_flag
	    = river_bul_flag = shanty_bul_flag;
    prefs_drawn_flag = 0;
    kmouse_val = 8;

#ifdef LC_X11
    borderx = 0;
    bordery = 0;
    parse_xargs (argc, argv, &geometry);
#endif

    /* I18n */
    lincity_set_locale ();

    /* Set up the paths to certain files and directories */
    init_path_strings ();

    /* Make sure that things are installed where they should be */
    verify_package ();

    /* Make sure the save directory exists */
    check_savedir ();

    /* Load preferences */
    load_lincityrc ();

#ifndef CS_PROFILE
#ifdef SEED_RAND
    srand (time (0));
#endif
#endif

#ifdef LC_X11
#if defined (commentout)
    borderx = 0;
    bordery = 0;
    parse_xargs (argc, argv, &geometry);
#endif
    Create_Window (geometry);
    pirate_cursor = XCreateFontCursor (display.dpy, XC_pirate);
#elif defined (WIN32)
    /* Deal with all outstanding messages */
    ProcessPendingEvents ();
#else
    parse_args (argc, argv);
    q = vga_setmode (G640x480x256);
    gl_setcontextvga (G640x480x256);
#endif

#if defined (WIN32) || defined (LC_X11)
    initialize_pixmap ();
#endif

    init_fonts ();

#if defined (SKIP_OPENING_SCENE)
    skip_splash_screen = 1;
#endif
    if (!skip_splash_screen) {
	load_start_image ();
    }

#ifdef LC_X11
    unlock_window_size ();
#endif

    Fgl_setfont (8, 8, main_font);
    Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);

    initialize_geometry (&scr);

#if defined (SVGALIB)
    set_vga_mode ();
#endif

    initialize_monthgraph ();
    init_mouse_registry ();
    init_mini_map_mouse ();

#ifdef LC_X11
    x_key_value = 0;
#elif defined (WIN32)
    RefreshScreen ();
#endif
    setcustompalette ();
    draw_background ();
    prog_box (_("Loading the game"), 1);
    init_types ();
    init_modules();
    init_mappoint_array ();
    initialize_tax_rates ();
    prog_box ("", 95);
    mouse_hide_count = 0;
    suppress_ok_buttons = 0;
    prog_box ("", 100);
#ifdef USE_PIXMAPS
    prog_box (_("Creating pixmaps"), 1);
    init_pixmaps ();
    prog_box ("", 100);
#endif
    //draw_normal_mouse (1, 1);
#if defined (LC_X11)
    init_x_mouse ();
#endif
    init_timer_buttons();
    mouse_initialized = 1;
    //set_selected_module (CST_TRACK_LR);
    screen_setup ();

    /* Main loop! */
    client_main_loop ();

#if defined (SVGALIB)
    mouse_close ();
    vga_setmode (TEXT);
#endif

    print_results ();

#if defined (WIN32) || defined (LC_X11)
    free_pixmap ();
#endif

#if defined (WIN32)
    return 0;
#else
    exit (0);
#endif
}