Skip to content

Latest commit

 

History

History
54 lines (40 loc) · 2.72 KB

atlas_tile_design.md

File metadata and controls

54 lines (40 loc) · 2.72 KB

Atlas Tile Renderer Design

  • Matt Young.

Introduction

This is the main part of the Atlas renderer. Its job is to render OpenStreetMap tiles as a 3D plane in LibGDX.

Starting the tile server

The tile server is a Docker image, as detailed in docs/atlas_map_pipeline.md. Once it's been installed, Atlas will attempt to automatically start the tile server. It will then verify the tile server is connected successfully.

If the tile server crashes, Atlas should throw an error dialogue and probably quit the game.

Constructing the grid

OUTDATED

  • Imagine the ground is an infinite plane
  • We can determine the area of this plane that is visible on screen
  • Using the camera frustum, we can cast rays through the four corners and see where they intersect the ground plane
  • This will define the visible view rectangle on the ground
  • At certain low view angles, this would create extremely long regions of the map to be rendered, but we can fix this by still doing distance thresholding
    • Either truncate the rectangle or cap ray length

Fetching and caching tiles

PARTIALLY OUTDATED

Once the grid is constructed, Atlas will fetch tiles from the tile server using HTTP. To avoid blocking the main thread, the HTTP fetch is done async using Gdx.net.

The tile PNG will be downloaded from the server either using Pixmap.downloadFromUrl which uses Gdx.net and so is async. Once the tile has been fetched, the Pixmap will be converted into a Texture (which implies it is also uploaded to the GPU - more on that in a sec). This will then be stored in a class Tile with Vector3 position and Texture tex.

Once the Tile has been created, it will be stored in a TileCache, which is basically a LRU cache of Tiles. When we download a texture, we want to cache it - but if we keep downloading tiles forever, this implies unlimited VRAM usage (or at least, however large as Brisbane is). To fix this, we will store a configurable number of Tiles in the ring buffer. When the LRU cache is full, we evict the oldest Tile and call dispose() on it to free the texture VRAM.

When we're trying to render a Tile, we locate it in the LRU cache. If it's in there, great, we use that texture. Otherwise, we will re-download it from the tile server.

The cache will either use Guava's CacheBuilder or Caffeine: https://github.com/ben-manes/caffeine (probably Caffeine due to its support of async loading, which makes sense for HTTP)

Scene optimisation

Tiles whose centroid is a configurable distance away from the camera will not be added to the render list.

Tiles where at least one of the four corners is not contained inside the camera's view frustum are also not added to the render list (frustum culling).

Once these checks have been performed, the