A question about loading stuff from OnUpdate()

Monkey Forums/Monkey Beginners/A question about loading stuff from OnUpdate()

GfK(Posted 2014) [#1]
Hello.

I'm pretty sure that Monkey (as I understand it) is more or less "fire-and-forget" when it comes to game timing as it's all managed by SetUpdateRate(), right?

But what if I have a function call in OnUpdate() which loads stuff and takes, say, 2 seconds to complete? Will there be a massive knock-on effect to OnRender() resulting in a lengthy screen-freeze? If so, how do I avoid that?


Gerry Quinn(Posted 2014) [#2]
Yes, that's an issue. What should usually happen with images and sounds is that you will return quickly from OnUpdate(), but OnLoading() will be called instead of OnRender() while they are loading. You can put a 'please wait' message here to start with. OnLoading() should also be called when loading images and sounds in OnCreate().

However, there are undoubtedly things that will not load asynchronously this way, and in that case, since Monkey is single-threaded, you'll stay in OnUpdate() until it's done. The same would apply to any super-long function calls. In that case you'll have to find a way to do cooperative or full multi-tasking (the latter would involve going outside Monkey) if you want to maintain responsiveness.