From ddbe1d9c975ceb4344d3bf362d41eb723f6d978e Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Thu, 10 Dec 2020 14:53:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=A0=E4=B8=AA=E5=A4=9A=E5=AA=92=E4=BD=93?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=94=AF=E6=8C=81=E9=87=8D=E8=BD=BD=E8=B5=84?= =?UTF-8?q?=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/bgm.lua | 11 +++---- Zframework/image.lua | 12 ++------ Zframework/sfx.lua | 12 ++++---- Zframework/voice.lua | 71 +++++++++++++++++++++----------------------- 4 files changed, 46 insertions(+), 60 deletions(-) diff --git a/Zframework/bgm.lua b/Zframework/bgm.lua index d73316ff..6288d7a5 100644 --- a/Zframework/bgm.lua +++ b/Zframework/bgm.lua @@ -4,10 +4,10 @@ local BGM={ play=NULL, freshVolume=NULL, stop=NULL, + reload=NULL, --nowPlay=[str:playing ID] --playing=[src:playing SRC] } - function BGM.init(list) BGM.init=nil local min=math.min @@ -39,9 +39,7 @@ function BGM.init(list) local function removeCurFadeOut(task,code,src) return task.code==code and task.args[1]==src end - - BGM.loadOne=coroutine.wrap(function(skip) - BGM.loadAll=nil + local function load(skip) for i=1,count do local file="media/BGM/"..list[i]..".ogg" if love.filesystem.getInfo(file)then @@ -90,9 +88,8 @@ function BGM.init(list) if BGM.nowPlay then TASK.new(fadeOut,BGM.playing)end BGM.nowPlay,BGM.playing=nil end - end) - function BGM.loadAll() - BGM.loadOne(true) end + BGM.loadOne=coroutine.wrap(load) + function BGM.loadAll()load(true)end end return BGM \ No newline at end of file diff --git a/Zframework/image.lua b/Zframework/image.lua index 2ff300c9..c2f0c22f 100644 --- a/Zframework/image.lua +++ b/Zframework/image.lua @@ -7,9 +7,7 @@ function IMG.init(list) IMG[k]=v end function IMG.getCount()return count end - - IMG.loadOne=coroutine.wrap(function(skip) - IMG.loadAll=nil + local function load(skip) for k,v in next,list do IMG[k]=love.graphics.newImage("media/image/"..v) if not skip and i~=count then @@ -17,12 +15,8 @@ function IMG.init(list) end end IMG.loadOne=nil - end) - - function IMG.loadAll() - for i=1,count do - IMG.loadOne(i) - end end + IMG.loadOne=coroutine.wrap(load) + function IMG.loadAll()load(true)end end return IMG \ No newline at end of file diff --git a/Zframework/sfx.lua b/Zframework/sfx.lua index 1b9327ec..7895c63c 100644 --- a/Zframework/sfx.lua +++ b/Zframework/sfx.lua @@ -4,6 +4,7 @@ local SFX={ play=NULL, fplay=NULL, reset=NULL, + reload=NULL, } function SFX.init(list) SFX.init=nil @@ -11,10 +12,7 @@ function SFX.init(list) local Sources={} local count=#list function SFX.getCount()return count end - - SFX.loadOne=coroutine.wrap(function(skip) - SFX.loadAll=nil - + local function load(skip) for i=1,count do local N="media/SFX/"..list[i]..".ogg" if love.filesystem.getInfo(N)then @@ -91,9 +89,9 @@ function SFX.init(list) end end end - end) - function SFX.loadAll() - SFX.loadOne(true) end + + SFX.loadOne=coroutine.wrap(load) + function SFX.loadAll()load(true)end end return SFX \ No newline at end of file diff --git a/Zframework/voice.lua b/Zframework/voice.lua index 718649be..6adaf9a5 100644 --- a/Zframework/voice.lua +++ b/Zframework/voice.lua @@ -4,8 +4,8 @@ local VOC={ getFreeChannel=NULL, play=NULL, update=NULL, + reload=NULL, } - function VOC.init(list) VOC.init=nil local rnd=math.random @@ -37,9 +37,7 @@ function VOC.init(list) return L[n] --Load voice with string end - - VOC.loadOne=coroutine.wrap(function(skip) - VOC.loadAll=nil + local function load(skip) for i=1,count do Source[list[i]]={} @@ -85,44 +83,43 @@ function VOC.init(list) end end end - end) - function VOC.loadAll() - VOC.loadOne(true) - end - - function VOC.update() - for i=#voiceQueue,1,-1 do - local Q=voiceQueue[i] - if Q.s==0 then--Free channel, auto delete when >3 - if i>3 then - rem(voiceQueue,i) - end - elseif Q.s==1 then--Waiting load source - Q[1]=getVoice(Q[1]) - Q[1]:setVolume(SETTING.voc) - Q[1]:play() - Q.s=Q[2]and 2 or 4 - elseif Q.s==2 then--Playing 1,ready 2 - if Q[1]:getDuration()-Q[1]:tell()<.08 then - Q[2]=getVoice(Q[2]) - Q[2]:setVolume(SETTING.voc) - Q[2]:play() - Q.s=3 - end - elseif Q.s==3 then--Playing 12 same time - if not Q[1]:isPlaying()then - for j=1,#Q do - Q[j]=Q[j+1] + function VOC.update() + for i=#voiceQueue,1,-1 do + local Q=voiceQueue[i] + if Q.s==0 then--Free channel, auto delete when >3 + if i>3 then + rem(voiceQueue,i) end + elseif Q.s==1 then--Waiting load source + Q[1]=getVoice(Q[1]) + Q[1]:setVolume(SETTING.voc) + Q[1]:play() Q.s=Q[2]and 2 or 4 - end - elseif Q.s==4 then--Playing last - if not Q[1].isPlaying(Q[1])then - Q[1]=nil - Q.s=0 + elseif Q.s==2 then--Playing 1,ready 2 + if Q[1]:getDuration()-Q[1]:tell()<.08 then + Q[2]=getVoice(Q[2]) + Q[2]:setVolume(SETTING.voc) + Q[2]:play() + Q.s=3 + end + elseif Q.s==3 then--Playing 12 same time + if not Q[1]:isPlaying()then + for j=1,#Q do + Q[j]=Q[j+1] + end + Q.s=Q[2]and 2 or 4 + end + elseif Q.s==4 then--Playing last + if not Q[1].isPlaying(Q[1])then + Q[1]=nil + Q.s=0 + end end end end end + + VOC.loadOne=coroutine.wrap(load) + function VOC.loadAll()load(true)end end return VOC \ No newline at end of file