Using Lily to speed up assets loading

This commit is contained in:
Nguyễn Quốc Hưng
2024-08-09 19:47:04 +07:00
parent 0a5bc1476d
commit 1a99de7435
5 changed files with 1072 additions and 60 deletions

View File

@@ -60,22 +60,25 @@ BUTTON.setDefaultOption{
}
-- Graphics
ShowLoadingText('backgrounds')
local gc_newImage, gc_newVideo = love.graphics.newImage, love.graphics.newVideo
BACKGROUNDS = {
[0] = gc_newVideo("res/backgrounds/green_waterfall.ogv", {audio=false}),
gc_newVideo("res/backgrounds/water.ogv", {audio=false}),
gc_newVideo("res/backgrounds/green_streams.ogv", {audio=false}),
gc_newVideo("res/backgrounds/streams.ogv", {audio=false}),
gc_newVideo("res/backgrounds/red_forest_waterfall.ogv", {audio=false}),
gc_newVideo("res/backgrounds/flowers_rain.ogv", {audio=false}),
gc_newVideo("res/backgrounds/moonlight_tree.ogv", {audio=false}),
gc_newVideo("res/backgrounds/lisa_frank.ogv", {audio=false}),
gc_newVideo("res/backgrounds/snowy_trees.ogv", {audio=false}),
gc_newVideo("res/backgrounds/snowy_cabin.ogv", {audio=false}),
}
BACKGROUNDS = {}
LILY.loadMulti{
{'newVideo', "res/backgrounds/green_waterfall.ogv", {audio=false}},
{'newVideo', "res/backgrounds/water.ogv", {audio=false}},
{'newVideo', "res/backgrounds/green_streams.ogv", {audio=false}},
{'newVideo', "res/backgrounds/streams.ogv", {audio=false}},
{'newVideo', "res/backgrounds/red_forest_waterfall.ogv", {audio=false}},
{'newVideo', "res/backgrounds/flowers_rain.ogv", {audio=false}},
{'newVideo', "res/backgrounds/moonlight_tree.ogv", {audio=false}},
{'newVideo', "res/backgrounds/lisa_frank.ogv", {audio=false}},
{'newVideo', "res/backgrounds/snowy_trees.ogv", {audio=false}},
{'newVideo', "res/backgrounds/snowy_cabin.ogv", {audio=false}},
}:onComplete(
function(_, lilies)
for i = 0, 9 do BACKGROUNDS[i] = lilies[i + 1][1] end
LOADED_BACKGROUND = true;
end)
ShowLoadingText('blocks')
BLOCKS = {
["2tie"] = {
R = gc_newImage("res/img/r.png"),
@@ -112,21 +115,30 @@ COLOUR_SCHEMES = {
}
-- BGMs and SFXs
ShowLoadingText('BGMs & SFXs')
local audio_newSource = love.audio.newSource
SOUNDS = {
bottom = audio_newSource("res/se/bottom.wav", "static"),
lock = audio_newSource("res/se/lock.wav", "static"),
erase = audio_newSource("res/se/erase.wav", "static"),
fall = audio_newSource("res/se/fall.wav", "static"),
ready = audio_newSource("res/se/ready.wav", "static"),
promote = audio_newSource("res/se/promote.wav", "static"),
demote = audio_newSource("res/se/demote.wav", "static"),
autopromote = audio_newSource("res/se/autopromote.wav", "static"),
bgm_firsthalf = audio_newSource("res/bgm/firsthalf.flac", "static"),
bgm_secondhalf = audio_newSource("res/bgm/secondhalf.flac", "static"),
bgm_title = audio_newSource("res/bgm/title.flac", "static")
}
SOUNDS = {}
LILY.loadMulti{
{"newSource", "res/se/bottom.wav", "static"},
{"newSource", "res/se/lock.wav", "static"},
{"newSource", "res/se/erase.wav", "static"},
{"newSource", "res/se/fall.wav", "static"},
{"newSource", "res/se/ready.wav", "static"},
{"newSource", "res/se/promote.wav", "static"},
{"newSource", "res/se/demote.wav", "static"},
{"newSource", "res/se/autopromote.wav", "static"},
{"newSource", "res/bgm/firsthalf.flac", "static"},
{"newSource", "res/bgm/secondhalf.flac", "static"},
{"newSource", "res/bgm/title.flac", "static"},
}:onComplete(
function(_, lilies)
SOUNDS.bottom, SOUNDS.lock, SOUNDS.erase, SOUNDS.fall = unpack(lilies, 1, 4)
SOUNDS.ready, SOUNDS.promote, SOUNDS.demote, SOUNDS.autopromote = unpack(lilies, 5, 8)
SOUNDS.bgm_firsthalf, SOUNDS.bgm_secondhalf, SOUNDS.bgm_title = unpack(lilies, 9)
for k, v in pairs(SOUNDS) do SOUNDS[k] = v[1] end -- Again, to avoid userdata
LOADED_MUSIC = true;
end
)
function PlaySE(sound, subsound)
if sound ~= nil then