Loading progress.

I’m thinking of giving users an update bar on loading, but before I go and write hundreds of lines I thought I’d check a couple of things.

If I ignore the Loading routine and set a flag in the Update code to load a graphic item each time the update is called until everything is loaded, and make something spin in the draw routine, will this be synchronous?

At the moment the game is taking about 6 seconds for everything to setup and I’m using a huge PC, I’m about to add a load more graphics and setup code so this is going to get worse.

What crevasses am I going to fall into, or should this be pretty simple?

Many thanks.

So I’m new to MonoGame but an experienced .net engineer.

The answer to your first question is yes, setting a flag and loading content would be synchronous. Performing loading IO logic in the main thread will cause the thread to the blocked until the loading is finished. So if you wanted a spinning loader, the spinning animation would “freeze” until the loading is finished.

I’d suggest checking out co routines and asynchronous programming. Using these two concepts combined can give you what you want. I don’t think that it would be hundreds of lines either.

Yes, this will work.

You have to set FixedTimeStep & VSync = false during content loading,
otherwise each asset will take 16.6msec. After that you can set it back to true during gameplay, if you like so.

That’s the simplest approach to load one asset per update. Or you can use a StopWatch and load as many assets withing 16msec and then return from update, then draw the spin, etc, until you reach the end of the asset queue.

I am a senior software engineer in the .NET development environments as well.

ItsGood posited some very good thoughts regarding the use of asynchronous co-routines. A casual review of co-routine information does show definite promise in this recommendation.

However, when faced with such a situation I have simply used multiple threads to handle the main process as well as one that would update the main process as a result of its own task responsibilities. From what I have read, co-routines are an alternative to primary threading that may fit your requirements. However, if they don’t for whatever reason than simply use standard threading, which should definitely work in your situation.

Here are tw links to help you get going with co-routines…

StackOverflow Post
NuGet Concurrency Helper Library

As to the spinning image, another alternative would be to simply use a GIF file that is already designed to animate in the manner you would like. This way it can run on the main thread without you having to worry about any updates to it.

1 Like

That all sounds about as I expected.

I’m hoping to start a new thread and set it off loading all the graphics, I’ll use a flag so the update/draw routines know what’s going on, or how far it’s got.

Hopefully that way I can keep the update routines ticking away nicely. If it doesn’t work that well I haven’t lost anything.

Thanks for the VSync tip nkast, I will test and see how results differ.

Tomorrow could be a fun day!

1 Like

HDD or SSD though? big can be old too…