I am curious as to what technique(s) are used to load files in while a game is running. For example, Minecraft will load chunks as you get within a certain range of them. How is this achieved without producing lag? Is multithreading involved?
1 Answer
Yes, this can be solved with multithreading. Either explicitly by creating a new thread which reads and interprets a file, or implicitly by using an asynchronous file access API which calls a callback function when a file finished loading.
The biggest problem with loading assets on demand is what to do when an asset is needed immediately, but it hasn't loaded yet. You can either pause the game until the asset is loaded (which is annoying), or replace it with a temporary placeholder (which can break immersion).