Lab: Level Loading
A game "level" is typically not only the level geometry, but also data describing where enemies or other dynamic entities appear, connections to other levels, etc.
Usually one of two approaches is used:
- A static level data structure is loaded as the "current level", and there can only be one current level. The player or other objects that outlive individual levels are basically destroyed and recreated (or moved) from the old level to the new level.
- The world is a bunch of stuff, and when we load a level we add a bunch of stuff (geometry, enemies, etc); when we unload a level we remove the stuff associated with it (or remove other old stuff as needed). This makes it possible to load a level in multiple chunks (and unload old pieces), but can lead to weird behaviors and bugs as the world is rarely fully reinitialized.
In either case, we have one or more active dynamic "worlds" referring to the static data, with collections of entities that change over time. Sometimes inactive levels are loaded but inert, and other times the player (and camera and renderer) move from level to level.
For this lab, define several levels as text, TOML, or JSON files using any approach you like and load them using the serde
crate. Then, have a button (or in-game interaction) that swaps from one level to another. It's up to you whether you unload resources you aren't using anymore, but levels that aren't active probably shouldn't get simulated or rendered.