Async Image Loading - Speed Test

Monkey Targets Forums/Android/Async Image Loading - Speed Test

Rus(Posted 2012) [#1]
Hiya guys! I've been trying to implement LoadImageAsync for the different targets. I've been getting good results with GLFW, and reasonable results with iOS. But Android doesn't seem to be loading asynchronously at all.

Here's the code that I'm using:

[monkeycode]
Strict
Import mojo

Class Game Extends App

Global streamedImage:StreamedImage

Method OnCreate:Int()
SetUpdateRate(60)
streamedImage = New StreamedImage( "large_image.jpg", 0, 0 )
Return 0
End

Method OnUpdate:Int()
UpdateAsyncEvents()
Return 0
End

Method OnRender:Int()
Cls

If streamedImage.image <> Null
DrawImage( streamedImage.image, 0, 0 )
EndIf

DrawText( "ms: " + Millisecs(), 0, 0 )
Return 0
End

End

Function Main:Int()
New Game
Return 0
End


Class StreamedImage Implements IOnLoadImageComplete

Field image:Image

Method New( path:String, x:Int, y:Int )
LoadImageAsync( path, 1, Image.DefaultFlags, Self )
End

Method OnLoadImageComplete:Void( image:Image,path:String,source:IAsyncEventSource )
Self.image = image
End

End
[/monkeycode]

The ms text is a Millisecs() print out that I use to see if the Update and Render calls are happening while the loading is going on in the background. For GLFW it's smooth all the time, for iOS it's great unless you try to load something huge! But Android stops dead to load then starts again once loading is complete.

Replace large_image.jpg with a large image file. Mine is a 2048x2048 6MB jpg.

If I could get descriptions of how the code works from anyone building for android, as well as information about your devices, that would be great. Also, if anyone would like to optimize or correct my code, please do! I'd appreciate it. There's very little discussion on this on the forums and it would be great to get more examples of how people are using this.


AdamRedwoods(Posted 2012) [#2]
I tried using custom AsyncLoaders for buffers with MonkeyV66 and found a lot of bugs.

But your problem sounds like Android is not threading the LoadSurface() call properly. I can try to test this later.


Rus(Posted 2012) [#3]
@AdamRedwoods:
Thanks for the feedback.

I'm looking at integrating Async loading with a larger framework that I use for my games. I guess it still doesn't work as expected across all platforms.

I wonder if the Android loading is a symptom of a bug in the Monkey generated code or an attribute of Android.

Any test results would be great! Cheers!