gecko0307 / dagon

3D game engine for D
https://gecko0307.github.io/dagon
Other
332 stars 30 forks source link

World streaming #90

Open gecko0307 opened 1 year ago

gecko0307 commented 1 year ago

A system that allows the game to load and unload fixed-sized parts of the map as the player travels through the game world.

The system assumes that the player travels predominantly on a planar surface, such as a land. The world is divided into a 2D grid with a predefined cell size (for example, 100x100 meters). Each cell is loaded as an independent asset. By default, the game only loads the home cell (where the player is at the start of the game) and its 8 neighboring cells. The player can see one adjacent cell at each direction. If the player moves to an adjacent cell, the game loads new "visible" neighboring cells and unloads "unvisible" ones. Loading is done at the background using thread-safe functions.

Core concepts

How this system should be integrated into existing API

In its current state Dagon renders Scene objects that store entities using World class. The level streaming system can seamlessly fit its workflow to Dagon's renderer by using a drop-in World replacement, StreamedWorld. This class will provide a different entity list based on the currently visible cells.

It should also store an array of global entities that are permanently present in the scene, as usual. For example, a character object and a camera are both persistent entities. The character's position will be used to update the Traveller state. When Traveller enters a new cell, it must broadcast a wrap event, which will be used in the scene to update the character's position. This way, the game logic will be continuous throughout the streamed world.