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

@@ -52,18 +52,19 @@ Navigate to where you put ``tromi_mobile.love`` in the File manager (the one you
* Update ``binser`` library, this fixes some weird bugs related to saving
* Add ``simple-button`` module, made by me (SweetSea)
* Replaced old Cambridge's ``config`` module with the new one inspired by "the sequel of Techmino"s ``SETTINGS`` module".
* Using `lily` to improve the loading speed of animated backgrounds and sounds.
# TODO
- [x] Add a way to export replay data for Android > 11
- [x] Add a way to export replay data for Android 11+
- [x] Revert ``bitser`` with ``binser`` (if and only if I can make it works)
- [x] Design a new on-screen buttons skin (the current one is come from [C₂₉H₂₅N₃O₅](https://github.com/C29H25N3O5), I am aware that it's not fit to Tromi's design language)
- [x] Updating on-screen control configuration screen
- [x] (Low priority) Design a new menu screen
- [x] Add shortcut to open replay converter at https://sweetsea-butimnotsweet.github.io/tromi_replay_converter
- [x] Redesign the replay selector screen
- [ ] Add user data management
- [ ] Redesign "the Control method selection" screen
- [ ] Redesign the replay screen
- [ ] Add shortcut to open replay converter at https://sweetsea-butimnotsweet.github.io/tromi_replay_converter
# License (GNU GPLv3)
Please read ``COPYING.txt`` for more information.<br>

1009
libs/lily.lua Normal file

File diff suppressed because it is too large Load Diff

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

View File

@@ -17,21 +17,7 @@ BACKGROUND_COLOR = {32/255, 120/255, 88/255}
CURRENT_OS = love.system.getOS()
MOBILE = CURRENT_OS == "Android" or CURRENT_OS == "iOS"
LOADING_IMAGE_FILE = love.graphics.newImage('res/loading.png')
--- Show the loading text while we are loading resources<br>
--- **WARNING**: should only be used while loading the game!
function ShowLoadingText(thing)
love.resize(love.graphics.getDimensions())
love.graphics.replaceTransform(GLOBAL_TRANSFORM)
love.graphics.setFont(love.graphics.newFont(20))
love.graphics.clear()
love.graphics.draw(LOADING_IMAGE_FILE,0,0,0,0.5)
drawText("Loading ".. thing .. "...", 15, 455, 1e99, "left")
love.graphics.flushBatch()
love.graphics.present()
end
LILY = require "libs.lily"
function love.load()
require 'funcs'
@@ -53,17 +39,6 @@ function love.load()
require "game.vctrl" -- VCTRL
SCENE = LoadingScene()
-- VCTRL.new{ -- up down left right --- right left down up
-- -- {type='button',x= 100,y=320,key= 'up',r=35,iconSize=60,alpha=0.75},
-- -- {type='button',x= 100,y=440,key= 'down',r=35,iconSize=60,alpha=0.75},
-- -- {type='button',x= 40,y=380,key= 'left',r=35,iconSize=60,alpha=0.75},
-- -- {type='button',x= 160,y=380,key= 'right',r=35,iconSize=60,alpha=0.75},
-- -- {type='button',x=640- 40,y=380,key= 'rotate_left',r=35,iconSize=60,alpha=0.75},
-- -- {type='button',x=640-160,y=380,key= 'rotate_left2',r=35,iconSize=60,alpha=0.75},
-- -- {type='button',x=640-100,y=440,key= 'rotate_right',r=35,iconSize=60,alpha=0.75},
-- -- {type='button',x=640-100,y=320,key='rotate_right2',r=35,iconSize=60,alpha=0.75},
-- }
VCTRL.new(SETTINGS.input.virtual)
end
@@ -148,7 +123,7 @@ function love.keypressed(key, scancode)
love.resize(love.graphics.getDimensions())
elseif scancode == "f2" and SCENE.title ~= "Input Config" and SCENE.title ~= "Game" then
SCENE = InputConfigScene()
elseif scancode == "f3" then SCENE = DataManagementScene()
elseif scancode == "f3" then SCENE = UserManagementScene()
elseif scancode == "f12" then LLDEBUGGER.requestBreak()
-- elseif scancode == "f11" then SETTINGS.firstTime = true
-- function keys are reserved
@@ -305,6 +280,10 @@ end
function love.focus(f) end
function love.quit()
LILY.quit()
end
local TARGET_FPS = 60
function love.run()

View File

@@ -1,10 +1,21 @@
local LoadingScene = SCENE:extend()
local LoadingImageFile = love.graphics.newImage('res/loading.png')
function LoadingScene.update()
if LOADED_BACKGROUND and LOADED_MUSIC then
SCENE = SETTINGS.firstTime and InputConfigScene(true) or TitleScene()
LILY.quit()
end
end
function LoadingScene.render()
love.graphics.draw(LOADING_IMAGE_FILE,0,0,0,0.5)
love.graphics.draw(LoadingImageFile,0,0,0,0.5)
drawText(
("Background: %s\nMusic & SFX: %s"):format(
LOADED_BACKGROUND and "loaded" or "...",
LOADED_MUSIC and "loaded" or "..."
),
15, 440, 1e99, "left"
)
end
return LoadingScene