Lily - LÖVE Async Loading Library

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
AuahDark
Party member
Posts: 107
Joined: Mon Oct 23, 2017 2:34 pm
Location: Indonesia
Contact:

Lily - LÖVE Async Loading Library

Post 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
Profile. Do you encounter crashes in LÖVE Android and wanna send me logcats? Please hit me up in LÖVE Discord and send the full logcat file!
KayleMaster
Party member
Posts: 234
Joined: Mon Aug 29, 2016 8:51 am

Re: Lily - LÖVE Async Loading Library

Post 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.
kuinashi101
Prole
Posts: 7
Joined: Tue Feb 21, 2023 9:47 am

Re: Lily - LÖVE Async Loading Library

Post 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!
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Lily - LÖVE Async Loading Library

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
kuinashi101
Prole
Posts: 7
Joined: Tue Feb 21, 2023 9:47 am

Re: Lily - LÖVE Async Loading Library

Post 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 :)
Post Reply

Who is online

Users browsing this forum: No registered users and 51 guests