February 13, 2018 at 5:28 am #13623
In Monkey-X we had the “OnLoading” App method, which you could use to detect whether images had finished loading or not, while the app was already rendering.
Is there anything similar on Monkey2? I don’t really grasp Fibers and Futures yet… I guess now is a good chance to learn it? (°.°)
Cheers.February 14, 2018 at 3:12 am #13625
Async image/sound loading is not currently supported, and fibers wont really help here as they are cooperative.February 14, 2018 at 3:32 am #13626
Ok. I’ll try something like:
- Start game, but don’t load anything yet
- On first frame, render a loading screen
- On second frame, load all assets while the loading screen stays there
- After it’s all loaded, the next frame will be rendered normally and the game will start
Cheers!February 14, 2018 at 4:19 am #13627
That’s probably the way to go for now.
It should be possible to at least RequestRender/Yield between loads, I’ll have a look into that.February 14, 2018 at 4:38 am #13628
Here’s one possible approach – build it in the simplelight banana dir or use your own image.
Note that it only syncs with OnRender every .1 seconds (shouold probably be slower?) – if you sync *every* load you substantially slow down loading time of course as waiting for OnRender can take up to 16ms.
Writing truly async loaders should be substantially simpler now as most of the async framework stuff is already in there. The only tricky bits will be the loaders written in pure monkey2 as they will need to be rewritten in c++ to be threadable. The only one I can think of here is the WAV loader.Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..#Import "Slate Tiles II_D.png"Class MyWindow Extends WindowField image:ImageField progress:FloatField future:Future<Bool>Field time:DoubleMethod New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )New Fiber( LoadStuff )time=Now()EndMethod WaitRender()Local elapsed:=Now()-timeIf elapsed<.1 Returntime+=elapsedfuture=New Future<Bool>future.Get()future=NullEndMethod SignalRender()If future future.Set( True )EndMethod LoadStuff()For Local i:=0 Until 256progress=i/256.0image=Image.Load( "asset::Slate Tiles II_D.png" )WaitRender()NextPrint "Finished!"EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()If image canvas.DrawImage( image,0,0 )canvas.DrawText( "Progress="+int(progress*100)+"%",Width/2,Height/2,.5,.5 )SignalRender()EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndFebruary 14, 2018 at 12:59 pm #13632
I would argue that we would need a feature that’s more like Threads in the near future. Game development of a higher scale would benefit from this. Although it’s not needed for most simple games, but I’m sure a new learning curve would emerge implementing it like data-races and such. And thoughts?February 14, 2018 at 5:33 pm #13633
Aw, I didn’t see the post with the code and ended up making the asset loading screen in my own caveman style. Will take a look at this approach tonight and see if I can borrow some ideas.
At a glance, I’m still confused by “who-calls-what-in-which-order”, but I guess it’ll click at some point.
Thanks!February 14, 2018 at 10:45 pm #13638
I would argue that we would need a feature that’s more like Threads in the near future
I agree with this, I think proper threading is the real fix for this instead of hacking in a bunch of async load functions.
Aw, I didn’t see the post with the code and ended up making the asset loading screen in my own caveman style.
Actually, after sleeping on it for a bit I think caveman style is probably the right approach for now!February 15, 2018 at 5:19 am #13652
Ok, caveman grade asset management & loading screen is up!
Now on to some more texturing.
Cheers.February 15, 2018 at 4:16 pm #13655
You must be logged in to reply to this topic.