It looks like you're new here. If you want to get involved, click one of these buttons!
Assets={} Assets.count=1000000 Assets.base="sky_world.png" --Set up a progress bar ProgressBar=Pixel.new(0x000000,1,application:getContentWidth(),50) local innerBar=Pixel.new(0xFF0000,1,application:getContentWidth()-10,40) innerBar:setScale(0,1) innerBar:setPosition(5,5) ProgressBar:addChild(innerBar) ProgressBar.setProgress=function (self,ratio) self:getChildAt(1):setScale(ratio,1) end stage:addChild(ProgressBar) function loadAssets() local ts=os.timer() print ("Start loading assets") for i=1,Assets.count do Assets[i]=Texture.new(Assets.base) ProgressBar:setProgress(i/Assets.count) end print ("Finished loading assets in",os.timer()-ts) -- Start our game logic here end Core.asyncCall(loadAssets) --loadAssets() |
Likes: simwhi, Apollo14, snooks, john26, n1cke, NatWobble, totebo, mertocan, hgvyas123, antix, SinisterSoft, pie, vitalitymobile, MoKaLux
Comments
By the way, @hgy29 could you please take a look at ios Object C/ Swift - LUA bridge and bring to Gideros as a plugin?
https://github.com/alibaba/wax
With that plugin, Our Gideros will be more robust and strong!
Thank for your hard work
http://giderosmobile.com/forum/discussion/1719/using-wax-for-easy-access-to-objective-c-under-ios-gideros/p1
Maybe better try to contact him for that.
It will help making even better user interfaces, Gideros used to look jaggy/slow because of synchronous loading. I am convinced this feature will help attracting more people to Gideros.
Likes: SinisterSoft
The co routines start once the main thread has finished - so the sooner you get them started and run out of code on the main thread, the better.
There is a cost to CPU btw, but it is cycles that would otherwise have been wasted.
Likes: totebo
https://deluxepixel.com
Likes: totebo
https://deluxepixel.com
BTW,will it cause any side effects if update the UI in the background task?
Likes: SinisterSoft, totebo
https://deluxepixel.com
i'm trying to change my file loading function to work in an async way but simply putting the loading function into Core.async() did not work, still the app freezes while a file is loaded.
my file loading function first calls another raw file loading function that has a zlib.decode part, then a json.decode part. then my main file loading function processes the table we got this way from the raw function.
the freeze of the app happens in both the raw loading part and in the processing part.
is it that zlib/json cannot work in an async way or am i doing something wrong? thanks
edit: of course i start with a call of
local file = io.open( path, "r" )
file:read( "*a" )
i don't know if this part freezes, but if only this would hang up my app, that would be still way better than it is now, as the other parts take up most of the loading time.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
https://deluxepixel.com
i think my problem is that zlib.decode and json.decode is one line of code so there is no chance to async it in lua and probably parts of zlib.decode cannot run in an async mode even if it is within an async called function.
it would be good if some native functions that can be expected to run for a long time (like zlib,json) would handle async-ing.
btw my use case is that in my anim app e.g. there are 2 layers of looping animations running and with a press of a button on one layer a new animation should be loaded (from a zipped json file). and what i want is that during this loading the animation on the other layer should run smoothly all the time (it is updated at each enterframe event).
Fragmenter - animated loop machine and IKONOMIKON - the memory game
You are totally right, async code can only be preempted at lua granularity, so if your decompression or json parsing takes longer than the spare time in the rendering loop, then it will lag.
Modifying C-code of those native functions to allow them to be paused and restarted later looks not easy, it would have been a job for independent threads.
An option would be to fragment your files so that you would load several small chunks of zipped json, yielding between each chunk.
splitting the files is not really an option, as these can be exported/imported by the user.
on the other hand i could try to split inside a file into smaller chunks (e.g. each frame is jsonned and zlibbed separately).
Fragmenter - animated loop machine and IKONOMIKON - the memory game
I attached the example project. My system shows incorrect times and i wanna remove compressed files after unpacking. What's my wrong?
How can i benchmark and confirm async loading assets for both untar and gunzip example? Beside the gunzip method is too slow for large asset packs, Is there more efficient way? or should we just use for little files ?
Thanks in advance
Have a look at this example of how to do coroutines. It shows how to get two coroutines to run together "move" and "pulse". In this case I had to use yield commands but this is only needed if you want to run equal timesteps as would be needed for animation. In your case the yield statements are automatically generated (but it might be an idea to try putting them in manually)
http://giderosmobile.com/forum/discussion/comment/48666#Comment_48666
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
I want to unpack over ~7.000 assets in a single file with reasonable size and speed.
But I noticed to misunderstood asyncCall coroutine aspect for different sprite jobs. You are right, no need asyncCall for the same unpack jobs. So I will just use untar method. Gunzip method is so heavy for low-end devices. Thanks for your explanation
does asynccall work properly with onenterframe events (Actually i need it to work with timer events)? or they are not part of the 'main thread', so if i want to async load a function, then all eventlisteners should be also rewritten to async called functions?
edit: sorry, maybe i was wrong and it maybe works. still, it's no harm to ask these, the answers would be informative.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Event listeners are always called on the main thread. Actually the main thread first runs all lua files, then continuously process events of each frame.
Async functions on the other hand run on the spare time of each frame, each call within its own coroutine so that they can be interrupted and resumed at will.
as i made a mistake in my code, for a while i thought that 'main thread' might mean only the lua code that is not called by some event listener but run directly while running the program. i'm happy that i was wrong.
Fragmenter - animated loop machine and IKONOMIKON - the memory game