Seamless level loading in Single Thread VS Multi Thread

Implementing a thread method selector for level loading: single thread, multi-thread, and ‘lazy’ multi-thread.

(The game in question is Zombies & Bullets).

  • Single Thread: In a single frame, the scene is loaded from disk, instantiated in memory, and added to the scene tree. This causes the game to freeze until the process is complete.

  • Multi-Thread: The scene is loaded from disk in one thread, instantiated in memory in another thread, and then added to the scene tree. Since this last operation can’t be done in a thread, there might still be a small stutter when adding the scene to the tree, depending on the number of nodes. Still, it’s a big improvement over single-thread loading.

  • Lazy Multi-Thread: The scene is loaded from disk in a thread, all its definitions are read with SceneState (which nodes it has, their properties, etc.), each node is instantiated manually in separate threads, and then they are gradually added to the scene at a fixed rate per frame until the whole scene is built. This method uses the most memory but avoids any freezing (and it’s pretty fun to watch things spawn when set to a slow spawn rate). I’m still working on making the best possible implementation of this method.

The current work in progress code is available here.

8 Likes