<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: GTA6 GPS</title>
    <description>The latest articles on DEV Community by GTA6 GPS (@gta6gps).</description>
    <link>https://dev.to/gta6gps</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4280976%2F4edc4abf-1e87-449b-b021-5aef6272df99.png</url>
      <title>DEV Community: GTA6 GPS</title>
      <link>https://dev.to/gta6gps</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gta6gps"/>
    <language>en</language>
    <item>
      <title>Building a 16ms Drive/Walk/Boat Routing Engine from Raster Game Map Tiles (No Vector Data)</title>
      <dc:creator>GTA6 GPS</dc:creator>
      <pubDate>Sat, 05 Dec 2026 01:58:56 +0000</pubDate>
      <link>https://dev.to/gta6gps/building-a-16ms-drivewalkboat-routing-engine-from-raster-game-map-tiles-no-vector-data-3ap0</link>
      <guid>https://dev.to/gta6gps/building-a-16ms-drivewalkboat-routing-engine-from-raster-game-map-tiles-no-vector-data-3ap0</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: AI coding assistants were used to help draft code, iterate on image-processing scripts, and edit this write-up. All architecture decisions, graph metrics, overpass audits, and production benchmarks are from my own live deployment.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When building an interactive game map for a brand-new open world (&lt;strong&gt;GTA6 GPS&lt;/strong&gt;, an interactive map of Leonida I maintain at &lt;a href="https://gta6gps.com/" rel="noopener noreferrer"&gt;gta6gps.com&lt;/a&gt;), players quickly ask for route planning between collectibles. Straight-line dashed segments are easy—real road and water routing is much harder when you &lt;strong&gt;don't have OpenStreetMap or a licensed vector street dataset&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;All we had was a CC BY 4.0 raster base map (zoom-5 and zoom-6 tiles). Here is how we turned flat PNG/WebP map tiles into a fast server-side &lt;strong&gt;Drive / Walk / Boat&lt;/strong&gt; routing engine in ~16 ms per request.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Extracting a road graph from raster colors
&lt;/h2&gt;

&lt;p&gt;Game base maps are cleaner than satellite imagery: highways, city streets, park paths, and water each use consistent color palettes.&lt;/p&gt;

&lt;p&gt;Our offline Python pipeline takes zoom-6 raster tiles (plus a zoom-5 street mask for thin pale roads and lavender park paths) and runs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Color-mask segmentation&lt;/strong&gt; per road class (highway, street, park path).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Morphological closing&lt;/strong&gt; to bridge lane dividers and minor tile artifacts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Skeletonization&lt;/strong&gt; to collapse multi-pixel road bands into 1-pixel centerlines.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Graph extraction &amp;amp; simplification&lt;/strong&gt; into nodes and weighted polyline edges.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first prototype (v1) produced &lt;strong&gt;7,823 nodes and 9,659 edges&lt;/strong&gt; (~738k map units of road), with 80% of total road length in one connected component.&lt;/p&gt;

&lt;p&gt;The biggest immediate failure mode was &lt;strong&gt;broken bridges and slight lane gaps&lt;/strong&gt; leaving islands disconnected. In v2, we added a dead-end bridging pass that connects collinear dead ends across short gaps (joining &lt;strong&gt;443 bridges/gaps&lt;/strong&gt;), expanding total road length to &lt;strong&gt;1,417k units&lt;/strong&gt; and lifting the largest connected component from &lt;strong&gt;80% to 94%&lt;/strong&gt;. Across 200 seeded pin pairs, the median road-to-straight-line ratio improved from &lt;strong&gt;1.45 to 1.32&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The flat-image trap: overpasses look like 4-way junctions
&lt;/h2&gt;

&lt;p&gt;Skeletonizing a 2D raster creates a classic routing bug: &lt;strong&gt;every highway overpass looks like a 4-way intersection&lt;/strong&gt;. A* happily tells players to make a 90-degree turn off an elevated freeway onto the surface street below.&lt;/p&gt;

&lt;p&gt;To fix this in v3 without hand-drawing the entire map:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We classified every edge by its base-map color: &lt;strong&gt;3,462 highway&lt;/strong&gt;, &lt;strong&gt;15,603 street&lt;/strong&gt;, and &lt;strong&gt;4,418 park-path&lt;/strong&gt; edges.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We detected candidate highway-over-street crossings, rendered zoom-6 crops around each one, audited them by eye, and split &lt;strong&gt;31 true overpasses&lt;/strong&gt; into non-intersecting two-level edges.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That single pass eliminated the most jarring impossible turns.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Adding Boat mode with a 40.5 KB water graph
&lt;/h2&gt;

&lt;p&gt;For coastal and island runs, Drive and Walk aren't enough. We applied a similar raster-extraction pipeline to water tiles to build a separate &lt;strong&gt;40.5 KB server-only water graph&lt;/strong&gt; (&lt;code&gt;water-v1.json&lt;/code&gt;) with connected-water snapping, so Boat routes stay on navigable water instead of cutting across sandbars or piers.&lt;/p&gt;

&lt;p&gt;Combined with edge-class speed weights (highways faster for Drive, park paths and shortcuts enabled for Walk), the same A* solver supports &lt;strong&gt;Drive, Walk, and Boat&lt;/strong&gt; modes with per-mode ETA and turn-by-turn directions (angle-based bear/turn/sharp left-right + U-turn + region transitions, even without street names).&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Moving routing off the client
&lt;/h2&gt;

&lt;p&gt;Shipping the v2/v3 graph to the browser meant downloading &lt;strong&gt;1.14 MB JSON (439 KB gzipped)&lt;/strong&gt; on every visit—way too heavy for mobile players who just want to look up one location.&lt;/p&gt;

&lt;p&gt;Moving A* to a lightweight server endpoint (&lt;code&gt;GET /api/route?g=7&amp;amp;stops=...&lt;/code&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A typical 3-stop route response is &lt;strong&gt;~0.5 KB&lt;/strong&gt; instead of 439 KB.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cold graph load per serverless instance takes &lt;strong&gt;~240 ms&lt;/strong&gt;; warm route queries take &lt;strong&gt;~16 ms&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Responses are edge-cached for a week keyed by quantized stops + graph version, and the client caches per-leg segments so dragging one waypoint only recomputes the affected legs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multi-stop "Nearest next" ordering uses nearest-neighbor + &lt;strong&gt;2-opt&lt;/strong&gt; refinement.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;You don't need vector tiles to ship real routing&lt;/strong&gt; for a game map—consistent raster color classes + skeletonization + targeted overpass splitting gets you 94%+ connectivity quickly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Keep the graph server-side&lt;/strong&gt; and cache per leg. Players feel the difference immediately on mobile.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Measure with seeded test pairs&lt;/strong&gt; (road/straight ratio, % of legs routed on road vs straight-line fallback) before every graph rebuild so you catch regressions automatically.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to test the Drive/Walk/Boat routing or drag-to-edit waypoints yourself, it's live on &lt;a href="https://gta6gps.com/" rel="noopener noreferrer"&gt;GTA6 GPS&lt;/a&gt;. Happy to answer questions about the skeletonization or overpass-splitting scripts in the comments.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>architecture</category>
      <category>performance</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
