RPG #4 - World Streaming

Huge worlds to explore has been a staple for RPGs as early as 1981 in Ultima.

Unfortunately it’s not always possible to load such massive worlds into memory, even on todays computers where game worlds become more and more complex.

Even though I haven’t ran into performance issues yet I decided to already build a world streamer so that I can potentially build infinite worlds.


For my first implementation I took the simplest approach I could come up with and implemented the following algorithm (pseudo code):

func _on_player_moved():
  var chunk_x = int(floor(world_x / 100))
  var chunk_y = int(floor(world_y / 100))

  for direction in directions:

func load_chunk(direction):
  if !has_node(direction):
    var chunk = load_chunk().instance()

The animation below demonstrate how it loads 9 chunks of the world wherever the player is in the world. As if now the world is 100 by 100 tiles, but I might be able to load larger tiles after I have done some testing.

Animation how new chunks are loaded as the player moves from chunk to chunk

In order to get rid of the flickering I would have to make some improvements like loading tiles in the background, caching tiles and preloading tiles.