diff --git a/Zframework/task.lua b/Zframework/task.lua index 3fa19084..a7a7c976 100644 --- a/Zframework/task.lua +++ b/Zframework/task.lua @@ -1,6 +1,5 @@ local rem=table.remove -local assert=assert -local resume,status=coroutine.resume,coroutine.status +local assert,resume,status=assert,coroutine.resume,coroutine.status local tasks={} local TASK={} diff --git a/parts/ai.lua b/parts/ai.lua index ae6506e0..0d4122df 100644 --- a/parts/ai.lua +++ b/parts/ai.lua @@ -1,6 +1,6 @@ local int,ceil,min,abs,rnd,modf=math.floor,math.ceil,math.min,math.abs,math.random,math.modf local ins,rem=table.insert,table.remove -local resume,yield=coroutine.resume,coroutine.yield +local yield=coroutine.yield -- controlname: -- 1~5:mL,mR,rR,rL,rF, -- 6~10:hD,sD,H,A,R, @@ -79,7 +79,7 @@ if type(_CC)=="table"then P.cur=rem(P.nextQueue,1) P.curX,P.curY=blockPos[P.cur.id],int(P.gameEnv.fieldH+1-modf(P.cur.sc[1]))+ceil(P.fieldBeneath/30) - assert(resume(P.newNext)) + P.newNext() local id=CCblockID[P.nextQueue[P.AIdata.next].id] if id then CC.addNext(P.AI_bot,id) diff --git a/parts/player/init.lua b/parts/player/init.lua index 04fcf48d..ac2f380d 100644 --- a/parts/player/init.lua +++ b/parts/player/init.lua @@ -178,7 +178,7 @@ local function newEmptyPlayer(id,mini) P.type="none" P.sound=false - -- P.newNext=false--Coroutine to get new next, loaded in applyGameEnv() + -- P.newNext=false--Warped coroutine to get new next, loaded in applyGameEnv() P.keyPressing={}for i=1,12 do P.keyPressing[i]=false end P.movDir,P.moving,P.downing=0,0,0--Last move key,DAS charging,downDAS charging @@ -312,8 +312,8 @@ local function applyGameEnv(P)--Finish gameEnv processing if ENV.nextCount==0 then ENV.nextPos=false end - P.newNext=coroutine.create(getSeqGen(P)) - assert(coroutine.resume(P.newNext,P,P.gameEnv.seqData)) + P.newNext=coroutine.wrap(getSeqGen(P)) + P.newNext(P,P.gameEnv.seqData) if P.mini then ENV.lockFX=false diff --git a/parts/player/player.lua b/parts/player/player.lua index 2a294017..d523b5e4 100644 --- a/parts/player/player.lua +++ b/parts/player/player.lua @@ -6,7 +6,7 @@ local Player={}--Player class local int,ceil,rnd=math.floor,math.ceil,math.random local max,min,modf=math.max,math.min,math.modf local ins,rem=table.insert,table.remove -local resume,yield=coroutine.resume,coroutine.yield +local resume,yield,status=coroutine.resume,coroutine.yield,coroutine.status local kickList=require"parts.kickList" @@ -121,8 +121,8 @@ function Player:RND(a,b) end function Player:newTask(code,...) local thread=coroutine.create(code) - coroutine.resume(thread,self,...) - if coroutine.status(thread)~="dead"then + resume(thread,self,...) + if status(thread)~="dead"then self.tasks[#self.tasks+1]={ thread=thread, code=code, @@ -763,7 +763,7 @@ function Player:popNext(ifhold)--Pop nextQueue to hand self.ctrlCount=0 self.cur=rem(self.nextQueue,1) - assert(resume(self.newNext)) + self.newNext() if self.cur then self.pieceCount=self.pieceCount+1 if self.AI_mode=="CC"then @@ -1512,8 +1512,8 @@ function Player:loadAI(data)--Load AI params else self:setRS("TRS") end - self.AI_thread=coroutine.create(AIFUNC[data.type]) - coroutine.resume(self.AI_thread,self,self.AI_keys) + self.AI_thread=coroutine.wrap(AIFUNC[data.type]) + self.AI_thread(self,self.AI_keys) end ---------------------------------------------------- diff --git a/parts/player/update.lua b/parts/player/update.lua index d04ef910..ecb0c39c 100644 --- a/parts/player/update.lua +++ b/parts/player/update.lua @@ -1,8 +1,7 @@ local max,min=math.max,math.min local int,abs,rnd=math.floor,math.abs,math.random local rem=table.remove -local resume=coroutine.resume -local status=coroutine.status +local assert,resume,status=assert,coroutine.resume,coroutine.status local function updateLine(P)--Attacks, line pushing, cam moving local bf=P.atkBuffer @@ -100,16 +99,13 @@ local function updateFXs(P,dt) TEXT.update(P.bonus) end end -local updateTasks do--updateTasks(P) - local assert=assert - function updateTasks(P) - local L=P.tasks - for i=#L,1,-1 do - local tr=L[i].thread - assert(resume(tr)) - if status(tr)=="dead"then - rem(L,i) - end +local function updateTasks(P) + local L=P.tasks + for i=#L,1,-1 do + local tr=L[i].thread + assert(resume(tr)) + if status(tr)=="dead"then + rem(L,i) end end end @@ -150,8 +146,8 @@ function update.alive(P,dt) local C=P.AI_keys P.AI_delay=P.AI_delay-1 if not C[1]then - if status(P.AI_thread)=="suspended"then - resume(P.AI_thread) + if P.AI_thread and not pcall(P.AI_thread)then + P.AI_thread=false end elseif P.AI_delay<=0 then P:pressKey(C[1])P:releaseKey(C[1]) diff --git a/parts/scenes/load.lua b/parts/scenes/load.lua index 45e9299b..0386a0c8 100644 --- a/parts/scenes/load.lua +++ b/parts/scenes/load.lua @@ -36,7 +36,7 @@ local function upFloor() SFX.play("click",.3) end end -local loadingThread=coroutine.create(function() +local loadingThread=coroutine.wrap(function() for i=1,SFX.getCount()do SFX.loadOne() if i%3==0 then YIELD()end @@ -175,7 +175,6 @@ local loadingThread=coroutine.create(function() logoColor2={COLOR.rainbow_light(r)} end STAT.run=STAT.run+1 - LOADED=true --Connect to server TASK.new(NET.TICK_WS_app) @@ -194,10 +193,10 @@ local loadingThread=coroutine.create(function() upFloor() end if progress==25 then - loadingThread=false SFX.play("welcome_sfx") VOC.play("welcome_voc") THEME.fresh() + LOADED=true return end YIELD() @@ -256,8 +255,8 @@ function scene.update(dt) if progress<25 then local p=progress repeat - assert(coroutine.resume(loadingThread)) - until not loadingThread or skip<=0 or progress~=p + loadingThread() + until LOADED or skip<=0 or progress~=p if skip>0 then skip=skip-1 end else openTime=openTime+dt diff --git a/parts/scenes/main.lua b/parts/scenes/main.lua index 9dcbdafb..08b66486 100644 --- a/parts/scenes/main.lua +++ b/parts/scenes/main.lua @@ -12,15 +12,13 @@ local widgetX0={ 1290,1290,1290,1290, } -local cmdEntryThread=coroutine.create(function() +local cmdEntryThread=coroutine.wrap(function() while true do - while true do - if YIELD()~="c"then break end - SFX.play("ren_6") - if YIELD()~="m"then break end - SFX.play("ren_9") - if YIELD()~="d"then break end - SFX.play("ren_11") + if + YIELD()=="c"and(SFX.play("ren_6")or 1)and + YIELD()=="m"and(SFX.play("ren_9")or 1)and + YIELD()=="d"and(SFX.play("ren_11")or 1) + then SCN.go("app_cmd") end end @@ -30,7 +28,7 @@ function scene.sceneInit() scrollX=tipLength BG.set() - coroutine.resume(cmdEntryThread) + cmdEntryThread() --Set quick-play-button text scene.widgetList[2].text=text.WidgetText.main.qplay..": "..text.modes[STAT.lastPlay][1] @@ -47,7 +45,7 @@ end function scene.mouseDown(x,y) if x>=520 and x<=760 and y>=140 and y<=620 then - coroutine.resume(cmdEntryThread, + cmdEntryThread( x<520+80 and y>620-80 and"c"or x>760-80 and y>620-80 and"m"or x<520+80 and y<140+80 and"d" @@ -121,7 +119,7 @@ function scene.keyDown(key) SCN.back() end else - coroutine.resume(cmdEntryThread,key) + cmdEntryThread(key) end end