[Freeciv-Dev] Re: (PR#8998) Small map meets large screen, they have prob
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8998 >
Here is a patch that restricts the maximum size of the mapview. I don't
think I can explain it any better than is done in the patch...which
isn't very well. To large degree these limits were determined by
trial-and-error, and I'm still not sure about the non-aligned case
(except I am sure the player doesn't want to play non-aligned).
I didn't test under hex but this should be just like the iso case.
Also attached is a patch that removes all sanity limits on the minimum
size of the map. Use this patch to debug the first one. Don't try
using a size of less than 200 (tiles) or mapgen may fail. Anyone who
wants to figure out why and fix it is welcome to it ;-).
jason
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.148
diff -u -r1.148 mapview_common.c
--- client/mapview_common.c 20 Sep 2004 16:27:12 -0000 1.148
+++ client/mapview_common.c 22 Sep 2004 00:43:38 -0000
@@ -2470,11 +2470,63 @@
int old_tile_width = mapview_canvas.tile_width;
int old_tile_height = mapview_canvas.tile_height;
int old_width = mapview_canvas.width, old_height = mapview_canvas.height;
- int tile_width = (width + NORMAL_TILE_WIDTH - 1) / NORMAL_TILE_WIDTH;
- int tile_height = (height + NORMAL_TILE_HEIGHT - 1) / NORMAL_TILE_HEIGHT;
- int full_width = tile_width * NORMAL_TILE_WIDTH;
- int full_height = tile_height * NORMAL_TILE_HEIGHT;
+ int tile_width, tile_height, full_width, full_height;
bool tile_size_changed, size_changed, redrawn = FALSE;
+ int max_width, max_height;
+ const int W = NORMAL_TILE_WIDTH, H = NORMAL_TILE_HEIGHT;
+
+ /* Impose a maximum limit on the size of the mapview.
+ *
+ * The logic for this is complicated, and in part determined by
+ * trial-and-error. */
+ if (XOR(topo_has_flag(TF_ISO) || topo_has_flag(TF_HEX), is_isometric)) {
+ /* Non-matching. In this case the mapview does not line up with the
+ * map's axis of wrapping. This will give very bad results for the
+ * player! */
+ if (topo_has_flag(TF_WRAPX) || topo_has_flag(TF_WRAPY)) {
+ /* We can never show more than half of the map.
+ *
+ * We divide by 4 below because we have to divide by 2 twice. The
+ * first division by 2 is because the square must be half the size
+ * of the (width+height). The second division by two is because for
+ * an iso-map, NATURAL_XXX has a scale of 2, whereas for iso-view
+ * NORMAL_TILE_XXX has a scale of 2. */
+ max_width = (NATURAL_WIDTH + NATURAL_HEIGHT) * W / 4;
+ max_height = (NATURAL_WIDTH + NATURAL_HEIGHT) * H / 4;
+ } else {
+ /* An unwrapping map: no limitation. */
+ max_width = FC_INFINITY;
+ max_height = FC_INFINITY;
+ }
+ } else {
+ /* Matching. */
+ const int isofactor = (is_isometric ? 2 : 1);
+ const int isodiff = (is_isometric ? 6 : 2);
+
+ if (topo_has_flag(TF_WRAPX)) {
+ /* We have to leave some extra tiles undrawn on each side. */
+ max_width = (NATURAL_WIDTH - isodiff) * W / isofactor;
+ } else {
+ /* No wrapping in this direction: no limitation. */
+ max_width = FC_INFINITY;
+ }
+ if (topo_has_flag(TF_WRAPY)) {
+ /* We have to leave some extra tiles undrawn on each side. */
+ max_height = (NATURAL_HEIGHT - isodiff) * H / isofactor;
+ } else {
+ /* No wrapping in this direction: no limitation. */
+ max_height = FC_INFINITY;
+ }
+ }
+
+ width = MIN(width, max_width);
+ height = MIN(height, max_height);
+
+ tile_width = (width + NORMAL_TILE_WIDTH - 1) / NORMAL_TILE_WIDTH;
+ tile_height = (height + NORMAL_TILE_HEIGHT - 1) / NORMAL_TILE_HEIGHT;
+
+ full_width = tile_width * NORMAL_TILE_WIDTH;
+ full_height = tile_height * NORMAL_TILE_HEIGHT;
/* Resized */
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.197
diff -u -r1.197 map.c
--- common/map.c 20 Sep 2004 16:42:30 -0000 1.197
+++ common/map.c 22 Sep 2004 00:33:10 -0000
@@ -185,7 +185,7 @@
void map_init(void)
{
map.topology_id = MAP_DEFAULT_TOPO;
- map.size = MAP_DEFAULT_SIZE;
+ map.tilesize = MAP_DEFAULT_SIZE;
/* The [xy]size values are set in map_init_topology. It is initialized
* to a non-zero value because some places erronously use these values
@@ -322,7 +322,7 @@
if (!set_sizes) {
/* Set map.size based on map.xsize and map.ysize. */
- map.size = (float)(map.xsize * map.ysize) / 1000.0 + 0.5;
+ map.tilesize = map.xsize * map.ysize;
}
/* sanity check for iso topologies*/
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.217
diff -u -r1.217 map.h
--- common/map.h 20 Sep 2004 16:42:30 -0000 1.217
+++ common/map.h 22 Sep 2004 00:33:10 -0000
@@ -157,7 +157,7 @@
int num_valid_dirs, num_cardinal_dirs;
struct iter_index *iterate_outwards_indices;
int num_iterate_outwards_indices;
- int size; /* used to calculate [xy]size */
+ int tilesize; /* used to calculate [xy]size */
int xsize, ysize; /* native dimensions */
int seed;
int riches;
@@ -607,15 +607,15 @@
#define MAP_MAX_HUTS 500
/* Size of the map in thousands of tiles */
-#define MAP_DEFAULT_SIZE 4
+#define MAP_DEFAULT_SIZE 4000
#define MAP_MIN_SIZE 1
-#define MAP_MAX_SIZE 29
+#define MAP_MAX_SIZE 29000
/* This defines the maximum linear size in _map_ coordinates.
* This must be smaller than 255 because of the way coordinates are sent
* across the network. */
#define MAP_MAX_LINEAR_SIZE 254
-#define MAP_MIN_LINEAR_SIZE 8
+#define MAP_MIN_LINEAR_SIZE 3
#define MAP_MAX_WIDTH MAP_MAX_LINEAR_SIZE
#define MAP_MAX_HEIGHT MAP_MAX_LINEAR_SIZE
Index: server/settings.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settings.c,v
retrieving revision 1.5
diff -u -r1.5 settings.c
--- server/settings.c 20 Sep 2004 16:42:31 -0000 1.5
+++ server/settings.c 22 Sep 2004 00:33:11 -0000
@@ -221,12 +221,12 @@
/* These should be grouped by sclass */
/* Map size parameters: adjustable if we don't yet have a map */
- GEN_INT("size", map.size, SSET_MAP_SIZE,
+ GEN_INT("size", map.tilesize, SSET_MAP_SIZE,
SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
- N_("Map size in 1,000 tiles units"),
+ N_("Map size (in tiles)"),
N_("This value is used to determine xsize and ysize\n"
- " size = 4 is a normal map of 4,000 tiles (default)\n"
- " size = 20 is a huge map of 20,000 tiles"), NULL,
+ " size = 4,000 is a normal map (default)\n"
+ " size = 20,000 is a huge map"), NULL,
MAP_MIN_SIZE, MAP_MAX_SIZE, MAP_DEFAULT_SIZE)
GEN_INT("topology", map.topology_id, SSET_MAP_SIZE,
SSET_GEOLOGY, SSET_VITAL, SSET_TO_CLIENT,
Index: server/generator/mapgen_topology.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/generator/mapgen_topology.c,v
retrieving revision 1.3
diff -u -r1.3 mapgen_topology.c
--- server/generator/mapgen_topology.c 17 Sep 2004 09:14:01 -0000 1.3
+++ server/generator/mapgen_topology.c 22 Sep 2004 00:33:11 -0000
@@ -170,7 +170,7 @@
Set the map xsize and ysize based on a base size and ratio (in natural
coordinates).
****************************************************************************/
-static void set_sizes(double size, int Xratio, int Yratio)
+static void set_sizes(double tilesize, int Xratio, int Yratio)
{
/* Some code in generator assumes even dimension, so this is set to 2.
* Future topologies may also require even dimensions. */
@@ -182,7 +182,7 @@
/* We have:
*
- * 1000 * size = xsize * ysize
+ * tilesize = xsize * ysize
*
* And to satisfy the ratios and other constraints we set
*
@@ -191,14 +191,14 @@
*
* For any value of "i_size". So with some substitution
*
- * 1000 * size = i_size * i_size * xratio * yratio * even * even * iso
- * i_size = sqrt(1000 * size / (xratio * yratio * even * even * iso))
+ * tilesize = i_size * i_size * xratio * yratio * even * even * iso
+ * i_size = sqrt(tilesize / (xratio * yratio * even * even * iso))
*
* Make sure to round off i_size to preserve exact wanted ratios,
* that may be importante for some topologies.
*/
const int i_size
- = sqrt((float)(1000 * size)
+ = sqrt(tilesize
/ (float)(Xratio * Yratio * iso * even * even)) + 0.49;
/* Now build xsize and ysize value as described above. */
@@ -208,22 +208,22 @@
/* Now make sure the size isn't too large for this ratio. If it is
* then decrease the size and try again. */
if (MAX(MAP_WIDTH, MAP_HEIGHT) > MAP_MAX_LINEAR_SIZE ) {
- assert(size > 0.1);
- set_sizes(size - 0.1, Xratio, Yratio);
+ assert(tilesize >= 1.0);
+ set_sizes(tilesize - 100, Xratio, Yratio);
return;
}
/* If the ratio is too big for some topology the simplest way to avoid
* this error is to set the maximum size smaller for all topologies! */
- if (map.size > size + 0.9) {
+ if (map.tilesize > tilesize + 900.0) {
/* Warning when size is set uselessly big */
freelog(LOG_ERROR,
"Requested size of %d is too big for this topology.",
- map.size);
+ map.tilesize);
}
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);
+ map.xsize, map.ysize, map.xsize * map.ysize, map.tilesize);
}
/*
@@ -255,7 +255,7 @@
assert(TF_WRAPX == 0x1 && TF_WRAPY == 0x2);
/* Set map.xsize and map.ysize based on map.size. */
- set_sizes(map.size, default_ratios[id][0], default_ratios[id][1]);
+ set_sizes(map.tilesize, default_ratios[id][0], default_ratios[id][1]);
}
/* initialize the ICE_BASE_LEVEL */
- [Freeciv-Dev] Re: (PR#8998) Small map meets large screen, they have problems together.,
Jason Short <=
|
|