v2 - oops, the fix was flawed - try this one, sorry

--------

Hopefully, this patch will fix Marco's routing problem in Rome. The bug
is ancient (almost as old as Rome) but it hasn't shown itself much
before now because it only causes a problem when one of the routing
tables gets to a certain size which only occurs when there are quite
a few turn restrictions within a small area.

The patch also contains a mod to allow another of the routing tables to
grow larger than it does now.

Please could as many people as possible test this patch to
check that routing doesn't bomb when using mapsource or a Nuvi in
city areas with lots of roads and turn restrictions.

Mark
diff --git a/src/uk/me/parabola/imgfmt/app/net/NOD1Part.java b/src/uk/me/parabola/imgfmt/app/net/NOD1Part.java
index 4566dbc..ac7c83c 100644
--- a/src/uk/me/parabola/imgfmt/app/net/NOD1Part.java
+++ b/src/uk/me/parabola/imgfmt/app/net/NOD1Part.java
@@ -73,8 +73,8 @@ public class NOD1Part {
 //	private static final int MAX_TABA = MAX_TABA_UNSAFE / 2;
 	private static final int MAX_TABA = MAX_TABA_UNSAFE - 0x8;
 
-	// Table B has at most 0x40 entries
-	private static final int MAX_TABB_UNSAFE = 0x40;
+	// Table B has at most 0x100 entries
+	private static final int MAX_TABB_UNSAFE = 0x100;
 //	private static final int MAX_TABB = MAX_TABB_UNSAFE / 2;
 	private static final int MAX_TABB = MAX_TABB_UNSAFE - 0x2;
 
diff --git a/src/uk/me/parabola/imgfmt/app/net/RouteArc.java b/src/uk/me/parabola/imgfmt/app/net/RouteArc.java
index 26d3a64..7b2782b 100644
--- a/src/uk/me/parabola/imgfmt/app/net/RouteArc.java
+++ b/src/uk/me/parabola/imgfmt/app/net/RouteArc.java
@@ -212,7 +212,12 @@ public class RouteArc {
 			writer.put(flagB);
 			writer.put((byte) 0);
 		} else {
-			writer.put((byte) (flagB | indexB));
+			if(indexB >= 0x3f) {
+				writer.put((byte) (flagB | 0x3f));
+				writer.put(indexB);
+			}
+			else
+				writer.put((byte) (flagB | indexB));
 		}
 
 		writer.put(indexA);
diff --git a/src/uk/me/parabola/imgfmt/app/net/TableB.java b/src/uk/me/parabola/imgfmt/app/net/TableB.java
index bdc09ac..23f63c6 100644
--- a/src/uk/me/parabola/imgfmt/app/net/TableB.java
+++ b/src/uk/me/parabola/imgfmt/app/net/TableB.java
@@ -35,7 +35,7 @@ public class TableB {
         /**
          * Retrieve the size of the Table as an int.
          *
-         * While Table B is limited in size (0x40 entries),
+         * While Table B is limited in size (0x100 entries),
          * we temporarily build larger tables while subdividing
          * the network.
          */
@@ -52,7 +52,7 @@ public class TableB {
          * it isn't too large.
          */
 	public byte getNumberOfItems() {
-		assert nodes.size() < 0x40 : "Table B too large.";
+		assert nodes.size() < 0x100 : "Table B too large.";
 		return (byte) nodes.size();
 	}
 
@@ -76,7 +76,7 @@ public class TableB {
 	public byte getIndex(RouteNode node) {
 		int i = nodes.indexOf(node);
 		assert i >= 0 : "Trying to read Table B index for non-registered node.";
-		assert i < 0x40 : "Table B index too large.";
+		assert i < 0x100 : "Table B index too large.";
 		return (byte) i;
 	}
 
diff --git a/src/uk/me/parabola/imgfmt/app/net/TableC.java b/src/uk/me/parabola/imgfmt/app/net/TableC.java
index 62f96d9..c36257c 100644
--- a/src/uk/me/parabola/imgfmt/app/net/TableC.java
+++ b/src/uk/me/parabola/imgfmt/app/net/TableC.java
@@ -49,9 +49,7 @@ public class TableC {
 			writer.put((byte) 0);
 		}
 		else {
-			byte b = getSizeBytes();
-			assert size < (1 << 8*b);
-			if (b == 1)
+			if (size < 0x100)
 				writer.put((byte) size);
 			else
 				writer.putChar((char) size);
@@ -79,13 +77,10 @@ public class TableC {
 	}
 
 	/**
-	 * The size in bytes of the size field. Also the size of
-	 * restriction indices in the nodes area.
+	 * The size of restriction indices in the nodes area.
 	 */
-	public byte getSizeBytes() {
-		if (size == 0)
-			return 0;
-		else if (size < 0x80)
+	private byte getOffsetSize() {
+		if (size < 0x80)
 			return 1; // allows 7 bit index (8th bit is flag)
 		else if (size < 0x8000)
 			return 2; // allows 15 bit index (16th bit is flag)
@@ -95,17 +90,27 @@ public class TableC {
 	}
 
 	public void propagateSizeBytes() {
-		byte b = getSizeBytes();
+		byte b = getOffsetSize();
 		for (RouteRestriction restr : restrictions)
 			restr.setOffsetSize(b);
 	}
 
 	public byte getFormat() {
-		byte format = getSizeBytes();
+		// Table C format bitmask
+		// 0x01 = 1-255 bytes of restrictions
+		// 0x02 = 256-65535 bytes of restrictions
+		// 0x08 = unpaved roads count present
+		// 0x10 = ferry count present
+		int format = 0;
+		if(size > 0) {
+			++format;
+			if(size > 0xff)
+				++format;
+		}
 		if(tabA.numUnpavedArcs() > 0)
 			format |= 0x08;
 		if(tabA.numFerryArcs() > 0)
 			format |= 0x10;
-		return format;
+		return (byte)format;
 	}
 }
_______________________________________________
mkgmap-dev mailing list
mkgmap-dev@lists.mkgmap.org.uk
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to