//------------------------------------------------------------------
int do_phase_field_crystal(doubleArray* valArray_p,
                            doubleArray* dArray_p,
                            doubleArray* cubeArray_p,
                            doubleArray* lapOneArray_p,
                            doubleArray* lapTwoArray_p,
                            doubleArray* sumArray_p,
                            double epsilon,
                            double TMAX,
                            double dt,
                            double dx)
{
    double tTotal = 0;
    while(tTotal < TMAX)
    {
        laplace(valArray_p, lapOneArray_p, dx);
        laplace(lapOneArray_p, lapTwoArray_p, dx);
        cube(valArray_p, cubeArray_p);

        multiply_scalar((1 - epsilon), valArray_p);
        multiply_scalar(2, lapOneArray_p);

        sum_array(valArray_p, sumArray_p);
        sum_array(lapOneArray_p, sumArray_p);
        sum_array(lapTwoArray_p, sumArray_p);
        sum_array(cubeArray_p, sumArray_p);

        laplace(sumArray_p, dArray_p, dx);

        do_time_step(valArray_p, dArray_p, dt);
        tTotal += dt;
    }
    return 1;
}
//------------------------------------------------------------------
int do_cahn_hilliard(doubleArray* valArray_p,
                    doubleArray* dArray_p,
                    doubleArray* cubeArray_p,
                    doubleArray* lptermArray_p,
                    doubleArray* sumArray_p,
                    double TMAX,
                    double dt,
                    double dx)
{
    double tTotal = 0;
    while(tTotal < TMAX)
    {
        laplace(valArray_p, lptermArray_p, dx);
        cube(valArray_p, cubeArray_p);
        multiply_scalar(-1, cubeArray_p);

        sum_array(valArray_p, sumArray_p);
        sum_array(lptermArray_p, sumArray_p);
        sum_array(cubeArray_p, sumArray_p);

        laplace(sumArray_p, dArray_p, dx);
        multiply_scalar(-1, dArray_p);

        do_time_step(valArray_p, dArray_p, dt);
        tTotal += dt;
    }
    return 1;
}
void execute_timestep ()
{
  static Uint32 oldTime = SDL_GetTicks();
  Uint32 now=SDL_GetTicks();
  Uint32 mStepTime=( lincitySpeed *1000/NUMOF_DAYS_IN_YEAR); 

  if( lincitySpeed == 0 || blockingDialogIsOpen
        || ( (now - oldTime < (mStepTime-10)) && (lincitySpeed != FAST_TIME_FOR_YEAR)) ) {
      SDL_Delay(10); //don't burn cpu in active loop
      return;
  }
  if ( (now - oldTime < mStepTime) && lincitySpeed != FAST_TIME_FOR_YEAR  )
    return; // skip frame
  oldTime = now;

  //  TRACE;
  do_time_step();

  //draw the updated city
  //in FAST-Mode, update at the last day in Month, so print_stats will work.
  if( ( lincitySpeed != FAST_TIME_FOR_YEAR ) || 
          ( total_time % ( NUMOF_DAYS_IN_MONTH * getConfig()->skipMonthsFast ) == (NUMOF_DAYS_IN_MONTH - 1) ) ){
    //update_main_screen (0); //does nothing in NG
    print_stats ();
    updateDate();
    print_total_money();
    getGameView()->requestRedraw();
  }
}
//------------------------------------------------------------------
int do_diffusion(doubleArray* valArray_p,
                doubleArray* dArray_p,
                double TMAX,
                double dt,
                double dx)
{
    double tTotal = 0;
    while(tTotal < TMAX)
    {
        laplace(valArray_p, dArray_p, dx);
        do_time_step(valArray_p, dArray_p, dt);
        tTotal += dt;
    }
    return 1;
}
Esempio n. 5
0
/* The "guts" of main loop is here. */
int 
execute_timestep (void)
{
    static int next_time_step = 0;
    int engine_updated = 0;
    int real_quit_flag = 0;

    if (market_cb_flag == 0 && help_flag == 0 
	&& port_cb_flag == 0 && prefs_flag == 0)
    {

	if ((real_time < next_time_step || pause_flag || mt_flag)
	    && save_flag == 0 && load_flag == 0)
	{
	    if ((let_one_through == 0) || mt_flag)
	    {
		lc_usleep (1);
		return 0;
	    }
	    else
		let_one_through = 0;
	}

	if (slow_flag)
	    next_time_step = real_time + (SLOW_TIME_FOR_YEAR
					  * 1000 / NUMOF_DAYS_IN_YEAR);
	else if (fast_flag)
	    next_time_step = real_time + (FAST_TIME_FOR_YEAR
					  * 1000 / NUMOF_DAYS_IN_YEAR);
	else if (med_flag)
	    next_time_step = real_time + (MED_TIME_FOR_YEAR
					  * 1000 / NUMOF_DAYS_IN_YEAR);

	do_time_step ();

#ifdef CS_PROFILE
	if (--prof_countdown <= 0)
	    real_quit_flag = 1;
#endif

	update_main_screen (0);

	/* XXX: Shouldn't the rest be handled in update_main_screen()? */
	/* GCS: No, I don't think so.  These remaining items are 
		outside of the main screen */

	print_stats ();

	if (market_cb_flag)
	    draw_market_cb ();
	else if (port_cb_flag)	/* else- can't have both */
	    draw_port_cb ();
    }
    else /* if game is "stalled" */
    {
	if (market_cb_flag != 0 && market_cb_drawn_flag == 0)
	    draw_market_cb ();
	if (port_cb_flag != 0 && port_cb_drawn_flag == 0)
	    draw_port_cb ();
#if defined (SVGALIB)
	mouse_update ();
#endif
    }

#if defined (NETWORK_ENABLE)
    if (network_flag != 0) {
	do_network_screen ();
	network_flag = 0;
	let_one_through = 1;	/* if we are paused we need */
    }			        /* this to redraw the screen */
#endif

    if (prefs_flag != 0 && prefs_drawn_flag == 0) {
	do_prefs_screen ();
	let_one_through = 1;	/* if we are paused we need */
    }			        /* this to redraw the screen */

    if (load_flag != 0) {
#if defined (WIN32)
	DisableWindowsMenuItems ();
#endif
	if (help_flag == 0)	/* block loading when in help */
	    do_load_city ();
	load_flag = 0;
	let_one_through = 1;	/* if we are paused we need */
    }			        /* this to redraw the screen */

    else if (save_flag != 0) {
#if defined (WIN32)
	DisableWindowsMenuItems ();
#endif
	if (help_flag == 0)
	    do_save_city ();
	save_flag = 0;
	let_one_through = 1;
    }

    else if (quit_flag != 0) {
#if defined (WIN32)
	DisableWindowsMenuItems ();
#endif
	if (yn_dial_box (_("Quit The Game?")
			 ,_("Do you really want to quit?")
			 ,_("If you want to save the game select NO.")
			 ,""     /* GCS: This can't be translated!. */
			 ) != 0)
	    real_quit_flag = 1;
	else
	    quit_flag = 0;
    }

    if (help_flag != 0)
	lc_usleep (1);

    if (make_dir_ok_flag)
	make_savedir ();	/* sorry a bit crude :( */
    return real_quit_flag;
}