Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] Re: (PR#9496) PATCH: Clean up on set-ratio
Home

[Freeciv-Dev] Re: (PR#9496) PATCH: Clean up on set-ratio

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: mburda@xxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#9496) PATCH: Clean up on set-ratio
From: "rwetmore@xxxxxxxxxxxx" <rwetmore@xxxxxxxxxxxx>
Date: Sun, 25 Jul 2004 02:19:44 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9496 >


Ratio is *not* a fundamental or worthwhile concept and just leads to
an endless set of these sort of problems. As has been stated from its
initial proposal, it should not be included in any Freeciv code. At
most there may be some dialog that is totally different from the
rest of the game concepts that wants to use it. Certainly low-level
code like map.c is not an appropriate place for anything but the
fundamental definitions of the low level window {xsize,ysize} with
appropriate topology restrictions like even and odd row limits from
wrapping constraints.

Please see these are removed from the patch code and replaced with
something closer to the original layering of core and GUI/user needs,
i.e. the ratio concept *never* appears as pollution at this level and
is cleanly separated into something fundamental and UI oriented with
the code placed accordingly.

Cheers,
RossW
=====

Marcelo Burda wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=9496 >
> 
> HI,
> A am trying to integrate the improvements to set_ratio(#9328) patch of
> Jason and my comment(#9409) to make a clean-up.
> i obtains i best accuracy in size changing the default ratio from 8:5 to
> 3:2 
> Be free to comment it. ( my english still very bad, sorry)
> Marcelo
> 
> 
> ------------------------------------------------------------------------
> 
> diff -ruN -Xfreeciv/diff_ignore freeciv/common/map.c freeciv__/common/map.c
> --- freeciv/common/map.c      2004-07-25 07:51:41.327673656 +0200
> +++ freeciv__/common/map.c    2004-07-25 08:46:48.608890488 +0200
> @@ -310,73 +310,78 @@
>  /****************************************************************************
>    Set the map xsize and ysize based on a base size and ratio (in natural
>    coordinates).
> -
> -  xsize and ysize are even numbers.  For iso-maps ysize%4 == 0.  This avoids
> -  problems in current and future topologies.
>  ****************************************************************************/
> -static void set_ratio(double base_size, int Xratio, int Yratio)
> +static void set_ratio(double size, int Xratio, int Yratio)
>  {
> +  /* Future topologies may require even dimensions. */
> +  /* Some code assume even dimension,(set this to 2) */  
> +  const int even = 2;
> +
>    /* In TF_ISO we need to double the map.ysize factor, since xsize is
>     * in native coordinates which are compressed 2x in the X direction. */ 
>    const int iso = topo_has_flag(TF_ISO) ? 2 : 1;
>  
>    /* We have:
>     *
> -   *   size = xsize * ysize
> +   *   1000 * size = xsize * ysize
>     *
>     * And to satisfy the ratios and other constraints we set
>     *
> -   *   xsize = 2 * isize * xratio
> -   *   ysize = 2 * isize * yratio * iso
> -   *
> -   * For any value of "isize".  The factor of 2 is to ensure even dimensions
> -   * (which are important for some topologies).  So with some substitution
> +   *   xsize = i_size * xratio * even
> +   *   ysize = i_size * yratio * even * iso
>     *
> -   *   size = 4 * isize * xratio * isize * yratio * iso
> -   *   isize = sqrt(size / (4 * xratio * yratio * iso))
> +   * For any value of "i_size".  So with some substitution
>     *
> -   * Remember that size = base_size * 1000.  So this gives us
> -   *
> -   *   isize = sqrt(base_size * 250 / (xratio * yratio * iso))
> +   *   1000 * size = i_size * i_size * xratio * yratio * even * even * iso
> +   *   i_size = sqrt(1000 * size / (xratio * yratio * even * even * iso))
> +   * 
> +   * Make sure to round off i_size to preserve exact wanted ratios,
> +   * that may be importante for some topologies.
>     */
> -  int i_size = sqrt(250.0 * base_size / (Xratio * Yratio * iso)) + 0.49;
> -
> -  /* Make sure the linear size is large enough. */
> -  while (MIN(Xratio, iso * Yratio) * 2 * i_size < MAP_MIN_LINEAR_SIZE) {
> -    i_size++;
> -  }
> -
> -  /* Now build xsize and ysize value as described above.  This gives and
> -   * even xsize and ysize.  For iso maps ysize % 4 == 0. */
> -  map.xsize =       2 * Xratio * i_size;
> -  map.ysize = iso * 2 * Yratio * i_size;
> -
> -  /* Now make sure the linear size isn't too large.  If it is, the best thing
> -   * we can do is decrease the base_size and try again. */
> -  if (MAX(MAP_WIDTH, MAP_HEIGHT) - 1 > MAP_MAX_LINEAR_SIZE ) {
> -      /* make a more litle map if possible */
> -    assert(base_size > 0.1);
> -    set_ratio(base_size - 0.1, Xratio, Yratio);
> +  const int i_size
> +    = sqrt((float)(1000 * size)
> +        / (float)(Xratio * Yratio * iso * even * even)) + 0.49;
> +
> +  /* Now build xsize and ysize value as described above. */
> +  map.xsize = Xratio * i_size * even;
> +  map.ysize = Yratio * i_size * even * iso;
> +
> +  /* The size and ratio must satisfy the minimum and maximum *linear*
> +   * restrictions on width */
> +
> +  assert(MAP_WIDTH >= MAP_MIN_LINEAR_SIZE);
> +  assert(MAP_HEIGHT >= MAP_MIN_LINEAR_SIZE);
> + 
> + /* Now make sure the if size isn't too large for this ratio.
> +  * is not then decrease the size and try again. */
> +  if (MAX(MAP_WIDTH, MAP_HEIGHT) > MAP_MAX_LINEAR_SIZE ) {
> +    assert(size > 0.1);
> +    set_ratio(size - 0.1, Xratio, Yratio);
>      return;
>    }
>  
> -  if (map.size > base_size + 0.9) {
> +  /* if ratio is big for some topology the simplest way to avoid
> +     next message is set maximum size smaller for all topo! */
> +  if (map.size > size + 0.9) {
>      /* Warning when size is set uselessly big */ 
>      freelog(LOG_NORMAL,
>           _("Requested size of %d is too big for this topology."),
>           map.size);
>    }
> -  freelog(LOG_VERBOSE, "Creating a map of size of %2.1fk tiles.", base_size);
> -  freelog(LOG_VERBOSE, "xsize and ysize are set to %d and %d.",
> -       map.xsize, map.ysize);
> +  freelog(LOG_VERBOSE,
> +       "Creating a map of size %d x %d = %d tiles (%d requested).",
> +       map.xsize, map.ysize, map.xsize * map.ysize, map.size * 1000);
>  }
>  
>  /*
>   * The auto ratios for known topologies
> + *
> + * the facto Xratio * Yratio determine accuracy of size, 
> + * best if small, specially for small sizes
>   */
>  #define AUTO_RATIO_FLAT           {1, 1}
> -#define AUTO_RATIO_CLASSIC        {8, 5} 
> -#define AUTO_RATIO_URANUS         {5, 8} 
> +#define AUTO_RATIO_CLASSIC        {3, 2} 
> +#define AUTO_RATIO_URANUS         {2, 3} 
>  #define AUTO_RATIO_TORUS          {1, 1}
>  
>  /****************************************************************************




[Prev in Thread] Current Thread [Next in Thread]