Page 1 of 1

Lily - LÖVE Async Loading Library

Posted: Fri Jan 05, 2018 12:00 pm
by AuahDark
TL;DR: love-loader but uses events and multiple CPUs

Single loading example

Code: Select all

local lily = require("lily")
local myimage
local mysound

function love.load()
	lily.newImage("image.png"):onComplete(function(userdata, image)
		-- In v2.0, there's "userdata" before the return value
		myimage = image
	end)
	lily.newSource("song.wav"):onComplete(function(userdata, sound)
		-- In v2.0, there's "userdata" before the return value
		mysound = sound
		sound:play()
	end)
end

function love.draw()
	if myimage then love.graphics.draw(myimage, 0, 24, 0, 0.25, 0.25)
	else love.graphics.print("Loading image") end
	if not(mysound) then love.graphics.print("Loading song", 0, 12) end
end
Multi loading example

Code: Select all

local lily = require("lily")

function love.load()
	multilily = lily.loadMulti({
		{"newImage", "image1-0.png"},	-- You can use string
		{lily.newImage, love.filesystem.newFile("image1-1.png")},	-- or the function object
	})
	local a = love.timer.getTime()
	multilily:onComplete(function(_, lilies)
		image1 = lilies[1][1]
		image2 = lilies[2][1]
	end)
end

function love.update() end
function love.draw()
	if multilily:isComplete() then
		love.graphics.draw(image1, -1024, -1024)
		love.graphics.draw(image2)
	end
end
GitHub Repository

Re: Lily - LÖVE Async Loading Library

Posted: Fri Jan 05, 2018 3:44 pm
by KayleMaster
I've been using this library before it was posted here, can assure you - it's great.
Your game won't freeze up on start if you're loading a lot of files (or big ones) and thus won't come up as not responding.
I'm using this with gamestate from hump and I've got myself a nice loading screen that isn't a still picture.

Re: Lily - LÖVE Async Loading Library

Posted: Fri Mar 03, 2023 2:02 am
by kuinashi101
How could I get the return value of loaded sound as table instead of userdata? I need to set the pitch before hand and play them multiple times in short period using SLAM. Thanks!

Re: Lily - LÖVE Async Loading Library

Posted: Fri Mar 03, 2023 8:54 am
by zorg
kuinashi101 wrote: Fri Mar 03, 2023 2:02 am How could I get the return value of loaded sound as table instead of userdata? I need to set the pitch before hand and play them multiple times in short period using SLAM. Thanks!
You don't. Even with regular love.audio.newSource, you'll get a Source object, not a table. SLAM does its own thing, and probably is not really compatible with this library. Besides, SLAM also calls Source:setPitch internally so that has nothing to do with tables either.

Re: Lily - LÖVE Async Loading Library

Posted: Fri Mar 03, 2023 2:05 pm
by kuinashi101
zorg wrote: Fri Mar 03, 2023 8:54 am You don't. Even with regular love.audio.newSource, you'll get a Source object, not a table. SLAM does its own thing, and probably is not really compatible with this library. Besides, SLAM also calls Source:setPitch internally so that has nothing to do with tables either.
By test the code below:


lily.newSource("test.mp3","static"):onComplete(function(userdata, sound)
print( sound ) -- Source: 0x7feea5805240
print( "sound: "..inspect(sound) ) -- sound: <userdata 1>
end)

local _table = love.audio.newSource( "test.mp3","static" )
print("_table: ".._table) -- error (a table value)
print( "_table: "..inspect(_table) ) -- SEE BELOW:

_table: {
_paused = false,
how = "static",
instances = {},
looping = false,
pitch = 1,
target = <userdata 1>,
volume = 1,
<metatable> = <1>{
__index = <table 1>,
__newindex = <function 1>,
addTags = <function 2>,
getLooping = <function 3>,
getPitch = <function 4>,
getVolume = <function 5>,
isLooping = <function 3>,
isStatic = <function 6>,
pause = <function 7>,
play = <function 8>,
removeTags = <function 9>,
resume = <function 10>,
setLooping = <function 11>,
setPitch = <function 12>,
setVolume = <function 13>,
stop = <function 14>
}
}

I've noticed that by require("slam"), the return value become a table with userdata1 wrapped inside when you call love.audio.newSource.
that's why I got table instead of userdata. there is nothing wrong with lily, might have to get my hands dirty to tweak slam or make another wrapper. :?

I won't be noticed that without you point it out, thanks for that :)