Video memory management with large maps

Summary

Video memory usage grows unconditionally when the player explores any given map because map chunks that are no longer required are not offloaded. The more the player explores the map, the more memory is consumed regardless of parts of the map not being visited anymore. In general, this is not a big problem because many maps are small enough to not exhaust available video memory, however in quests with large maps or in devices with small video memory (e.g. Raspberry Pi) this can become an issue. On discord, it was discussed (and proposed by @stdgregwar) that implementing a simple LRU eviction policy for these chunks can help greatly in managing video memory for map textures.

How to Reproduce

A very useful quest to showcase the problem quickly and test a possible solution is the PathFinder quest from @llamazing. On startup, this quest generates a large map that later is used for the player to explore. Instructions to use this quest are in the quest itself and requires a mouse device.

To show how video memory is being consumed without being released, simply move the Hero to a distant part of the map and use a video memory monitoring application (e.g. sudo vcdbg reloc in a Raspberry Pi device) to observe video memory usage. The farther the player moves in the map, the more memory will be consumed without being released until eventually exhausting it and the game becoming glitchy. Ideally, these parts of the map that become far away from the Hero should be released from video memory as it is not necessary to keep the entire map textures loaded all the time.