Jump to content

Asset loading suggestion


Recommended Posts

Kerbal uses a co routine to load every asset during the initial loading screen and only loads one asset per frame.

Now that might not sound bad but if you take into account that after each asset Kerbal renders the whole frame again for no good reason. Yes the loading screen only consist of a loading bar and a image for the background but even that adds to the loading time. I have noticed that on my GTX 770 the clock goes all the way up and stays at around 90% load during this time which makes me ask the question how slower GPU's handle this. I would guess this adds to the loading time quite a bit.

Lets assume Kerbal does the following:

    private IEnumerator LoadAssets()
    {
      //no idea how kerbal handles the loading screen internally so lets assume loops trough a list of items called assets
      foreach(var asset in assets)
      {
        //loads asset here

        //and gives controll back to unity/whatever else is loading during the loading screen
        yield return null;
      }
    }

As you can see with this code i would load one asset at a time which brings up the problems i highlighted before.

Now my suggestion would be to modify that code to something along these lines:

    private IEnumerator LoadAssets()
    {
      //start a timer
      Stopwatch timer = new Stopwatch();
      timer.Start();
      //no idea how kerbal handles the loading screen internally so lets assume loops trough a list of items called assets
      foreach (var asset in assets)
      {
        //loads asset here

        //a frame at 60fps takes ~0.016 seconds so we take that as the target
        if (timer.Elapsed.TotalMilliseconds >= 0.016)
        {//if it took longer than a frame we give controll back to unity/whatever else is loading during the loading screen
          yield return null;
          //reset and start the timer
          timer.Reset();
          timer.Start();
        }
      }
    }

In this example small files would load back to back without any downtime, maxing out either CPU or HDD/SSD, big files would behave exactly the same as before as they took more time to load anyways.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...