From 98629be450e2bb5afd5e87a1d1139b0c9cde6044 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Fri, 4 Dec 2020 16:09:17 +0800 Subject: [PATCH] =?UTF-8?q?Task=E6=A8=A1=E5=9D=97=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E6=94=B9=E7=94=A8=E5=8D=8F=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/task.lua | 36 +- Zframework/toolfunc.lua | 7 +- parts/gametoolfunc.lua | 2 +- parts/modes/GM.lua | 11 +- parts/modes/attacker_hard.lua | 48 +-- parts/modes/attacker_ultimate.lua | 64 ++-- parts/modes/defender_lunatic.lua | 54 +-- parts/modes/defender_normal.lua | 56 ++-- parts/modes/dig_hard.lua | 21 +- parts/modes/dig_ultimate.lua | 21 +- parts/modes/pctrain_lunatic.lua | 19 +- parts/modes/pctrain_normal.lua | 19 +- parts/modes/survivor_easy.lua | 23 +- parts/modes/survivor_hard.lua | 35 +- parts/modes/survivor_lunatic.lua | 25 +- parts/modes/survivor_normal.lua | 33 +- parts/modes/survivor_ultimate.lua | 33 +- parts/modes/ultra.lua | 21 +- parts/player/player.lua | 16 +- parts/player/update.lua | 7 +- parts/tick.lua | 530 +++++++++++++++++------------- 21 files changed, 607 insertions(+), 474 deletions(-) diff --git a/Zframework/task.lua b/Zframework/task.lua index 3f4bee7d..5d06a259 100644 --- a/Zframework/task.lua +++ b/Zframework/task.lua @@ -1,4 +1,6 @@ local rem=table.remove +local ct=coroutine +local assert=assert local tasks={} local TASK={ @@ -10,24 +12,40 @@ end function TASK.update() for i=#tasks,1,-1 do local T=tasks[i] - if T.code(T.data)then - if T.data.net then + assert(ct.resume(T.thread)) + if ct.status(T.thread)=="dead"then + if T.net then TASK.netTaskCount=TASK.netTaskCount-1 end rem(tasks,i) end end end -function TASK.new(code,data) - tasks[#tasks+1]={ - code=code, - data=data, - } +function TASK.new(code,...) + local thread=ct.create(code) + if ...~=nil then ct.resume(thread,...)end + if ct.status(thread)~="dead"then + tasks[#tasks+1]={ + thread=thread, + code=code, + } + end +end +function TASK.newNet(code,...) + local thread=ct.create(code) + if ...~=nil then ct.resume(thread,...)end + if ct.status(thread)~="dead"then + tasks[#tasks+1]={ + thread=thread, + code=code, + net=true, + } + end end function TASK.changeCode(c1,c2) for i=#tasks,1,-1 do - if tasks[i].code==c1 then - tasks[i].code=c2 + if tasks[i].thread==c1 then + tasks[i].thread=c2 end end end diff --git a/Zframework/toolfunc.lua b/Zframework/toolfunc.lua index d7202346..cca298d5 100644 --- a/Zframework/toolfunc.lua +++ b/Zframework/toolfunc.lua @@ -548,13 +548,12 @@ do--httpRequest & wsConnect client and function(tick,path,method,header,body) local task,err=client.httpraw{ url="http://krakens.tpddns.cn:10026"..path, - -- url="http://127.0.0.1:10026"..path, method=method or"GET", header=header, body=body, } if task then - TASK.new(tick,{task=task,time=0,net=true}) + TASK.newNet(tick,task) else LOG.print("NETlib error: "..err,"warn") end @@ -569,12 +568,10 @@ do--httpRequest & wsConnect local task,err=client.wsraw{ url="ws://krakens.tpddns.cn:10026"..path, origin="krakens.tpddns.cn", - -- url="ws://127.0.0.1:10026"..path, - -- origin="127.0.0.1", header=header, } if task then - TASK.new(tick,{wsconntask=task,time=0,net=true}) + TASK.newNet(tick,task) else LOG.print("NETlib error: "..err,"warn") end diff --git a/parts/gametoolfunc.lua b/parts/gametoolfunc.lua index ec167833..ef5bb12b 100644 --- a/parts/gametoolfunc.lua +++ b/parts/gametoolfunc.lua @@ -487,7 +487,7 @@ function resetGameData(replaying) STAT.game=STAT.game+1 FREEROW.reset(30*#PLAYERS) TASK.removeTask_code(TICK.showMods) - TASK.new(TICK.showMods,{0}) + TASK.new(TICK.showMods) SFX.play("ready") collectgarbage() end diff --git a/parts/modes/GM.lua b/parts/modes/GM.lua index 17799fd2..3d68e047 100644 --- a/parts/modes/GM.lua +++ b/parts/modes/GM.lua @@ -23,11 +23,14 @@ return{ freshLimit=15, dropPiece=score, task=function(P) + while true do + coroutine.yield() if P.stat.frame>=53.5*60 then - P.modeData.point=min(P.modeData.point+16,80) - P.modeData.event=sectionName[int(P.modeData.point*.1)+1] - P:win("finish") - return true + P.modeData.point=min(P.modeData.point+16,80) + P.modeData.event=sectionName[int(P.modeData.point*.1)+1] + P:win("finish") + return + end end end, bg="tunnel",bgm="far", diff --git a/parts/modes/attacker_hard.lua b/parts/modes/attacker_hard.lua index bab6d7cb..fbe6c949 100644 --- a/parts/modes/attacker_hard.lua +++ b/parts/modes/attacker_hard.lua @@ -6,29 +6,31 @@ return{ freshLimit=15, pushSpeed=2, task=function(P) - if not(P.control and SCN.cur=="play")then return end - if P.atkBuffer.sum==0 then - local p=#P.atkBuffer+1 - local B,D=P.atkBuffer,P.modeData - local t - if D.event<20 then - t=1500-30*D.event--1500~900 - B[p]= {pos=P:RND(4,7),amount=12,countdown=t,cd0=t,time=0,sent=false,lv=3} - B[p+1]= {pos=P:RND(3,8),amount=10,countdown=t,cd0=t,time=0,sent=false,lv=4} - else - t=900-10*(D.event-20)--900~600 - B[p]= {pos=P:RND(10),amount=14,countdown=t,cd0=t,time=0,sent=false,lv=4} - B[p+1]= {pos=P:RND(4,7),amount=8,countdown=t,cd0=t,time=0,sent=false,lv=5} - end - B.sum=B.sum+22 - P.stat.recv=P.stat.recv+22 - D.event=D.event+1 - if D.event%10==0 then - if D.event==20 then - P:showTextF(text.great,0,-140,100,"appear",.6) - P.gameEnv.pushSpeed=3 - elseif D.event==50 then - P:showTextF(text.maxspeed,0,-140,100,"appear",.6) + while true do + coroutine.yield() + if P.control and SCN.cur=="play"and P.atkBuffer.sum==0 then + local p=#P.atkBuffer+1 + local B,D=P.atkBuffer,P.modeData + local t + if D.event<20 then + t=1500-30*D.event--1500~900 + B[p]= {pos=P:RND(4,7),amount=12,countdown=t,cd0=t,time=0,sent=false,lv=3} + B[p+1]= {pos=P:RND(3,8),amount=10,countdown=t,cd0=t,time=0,sent=false,lv=4} + else + t=900-10*(D.event-20)--900~600 + B[p]= {pos=P:RND(10),amount=14,countdown=t,cd0=t,time=0,sent=false,lv=4} + B[p+1]= {pos=P:RND(4,7),amount=8,countdown=t,cd0=t,time=0,sent=false,lv=5} + end + B.sum=B.sum+22 + P.stat.recv=P.stat.recv+22 + D.event=D.event+1 + if D.event%10==0 then + if D.event==20 then + P:showTextF(text.great,0,-140,100,"appear",.6) + P.gameEnv.pushSpeed=3 + elseif D.event==50 then + P:showTextF(text.maxspeed,0,-140,100,"appear",.6) + end end end end diff --git a/parts/modes/attacker_ultimate.lua b/parts/modes/attacker_ultimate.lua index 874d24bd..14e5154a 100644 --- a/parts/modes/attacker_ultimate.lua +++ b/parts/modes/attacker_ultimate.lua @@ -5,37 +5,39 @@ return{ fall=8, freshLimit=15, task=function(P) - if not(P.control and SCN.cur=="play")then return end - if P.atkBuffer.sum<4 then - local p=#P.atkBuffer+1 - local B,D=P.atkBuffer,P.modeData - local s - local t=800-10*D.event--800~700~600~500 - if D.event<10 then - B[p]= {pos=P:RND(5,6),amount=9,countdown=t,cd0=t,time=0,sent=false,lv=3} - B[p+1]= {pos=P:RND(4,7),amount=11,countdown=t,cd0=t+62,time=0,sent=false,lv=4} - s=20 - elseif D.event<20 then - B[p]= {pos=P:RND(3,8),amount=11,countdown=t,cd0=t,time=0,sent=false,lv=4} - B[p+1]= {pos=P:RND(4,7),amount=13,countdown=t,cd0=t+62,time=0,sent=false,lv=5} - s=24 - else - B[p]= {pos=P:RND(2)*9-8,amount=14,countdown=t,cd0=t,time=0,sent=false,lv=5} - B[p+1]= {pos=P:RND(3,8),amount=14,countdown=t+62,cd0=t,time=0,sent=false,lv=5} - s=28 - end - B.sum=B.sum+s - P.stat.recv=P.stat.recv+s - D.event=D.event+1 - if D.event%10==0 then - if D.event==10 then - P:showTextF(text.great,0,-140,100,"appear",.6) - P.gameEnv.pushSpeed=4 - elseif D.event==20 then - P:showTextF(text.awesome,0,-140,100,"appear",.6) - P.gameEnv.pushSpeed=5 - elseif D.event==30 then - P:showTextF(text.maxspeed,0,-140,100,"appear",.6) + while true do + coroutine.yield() + if P.control and SCN.cur=="play"and P.atkBuffer.sum<4 then + local p=#P.atkBuffer+1 + local B,D=P.atkBuffer,P.modeData + local s + local t=800-10*D.event--800~700~600~500 + if D.event<10 then + B[p]= {pos=P:RND(5,6),amount=9,countdown=t,cd0=t,time=0,sent=false,lv=3} + B[p+1]= {pos=P:RND(4,7),amount=11,countdown=t,cd0=t+62,time=0,sent=false,lv=4} + s=20 + elseif D.event<20 then + B[p]= {pos=P:RND(3,8),amount=11,countdown=t,cd0=t,time=0,sent=false,lv=4} + B[p+1]= {pos=P:RND(4,7),amount=13,countdown=t,cd0=t+62,time=0,sent=false,lv=5} + s=24 + else + B[p]= {pos=P:RND(2)*9-8,amount=14,countdown=t,cd0=t,time=0,sent=false,lv=5} + B[p+1]= {pos=P:RND(3,8),amount=14,countdown=t+62,cd0=t,time=0,sent=false,lv=5} + s=28 + end + B.sum=B.sum+s + P.stat.recv=P.stat.recv+s + D.event=D.event+1 + if D.event%10==0 then + if D.event==10 then + P:showTextF(text.great,0,-140,100,"appear",.6) + P.gameEnv.pushSpeed=4 + elseif D.event==20 then + P:showTextF(text.awesome,0,-140,100,"appear",.6) + P.gameEnv.pushSpeed=5 + elseif D.event==30 then + P:showTextF(text.maxspeed,0,-140,100,"appear",.6) + end end end end diff --git a/parts/modes/defender_lunatic.lua b/parts/modes/defender_lunatic.lua index b952aa62..b8a014fd 100644 --- a/parts/modes/defender_lunatic.lua +++ b/parts/modes/defender_lunatic.lua @@ -8,31 +8,35 @@ return{ freshLimit=15, pushSpeed=2, task=function(P) - if not(P.control and SCN.cur=="play")then return end - P.modeData.counter=P.modeData.counter+1 - local t=240-2*P.modeData.event - if P.modeData.counter>=t then - P.modeData.counter=0 - for _=1,4 do - P.atkBuffer[#P.atkBuffer+1]={pos=P:RND(10),amount=1,countdown=5*t,cd0=5*t,time=0,sent=false,lv=2} - end - P.atkBuffer.sum=P.atkBuffer.sum+4 - P.stat.recv=P.stat.recv+4 - local D=P.modeData - if D.event<75 then - D.event=D.event+1 - D.point=int(144e3/(240-2*D.event))*.1 - if D.event==25 then - P:showTextF(text.great,0,-140,100,"appear",.6) - P.gameEnv.pushSpeed=3 - P.dropDelay,P.gameEnv.drop=4,4 - elseif D.event==50 then - P:showTextF(text.awesome,0,-140,100,"appear",.6) - P.gameEnv.pushSpeed=4 - P.dropDelay,P.gameEnv.drop=3,3 - elseif D.event==75 then - P:showTextF(text.maxspeed,0,-140,100,"appear",.6) - P.dropDelay,P.gameEnv.drop=2,2 + while true do + coroutine.yield() + if P.control and SCN.cur=="play"then + P.modeData.counter=P.modeData.counter+1 + local t=240-2*P.modeData.event + if P.modeData.counter>=t then + P.modeData.counter=0 + for _=1,4 do + P.atkBuffer[#P.atkBuffer+1]={pos=P:RND(10),amount=1,countdown=5*t,cd0=5*t,time=0,sent=false,lv=2} + end + P.atkBuffer.sum=P.atkBuffer.sum+4 + P.stat.recv=P.stat.recv+4 + local D=P.modeData + if D.event<75 then + D.event=D.event+1 + D.point=int(144e3/(240-2*D.event))*.1 + if D.event==25 then + P:showTextF(text.great,0,-140,100,"appear",.6) + P.gameEnv.pushSpeed=3 + P.dropDelay,P.gameEnv.drop=4,4 + elseif D.event==50 then + P:showTextF(text.awesome,0,-140,100,"appear",.6) + P.gameEnv.pushSpeed=4 + P.dropDelay,P.gameEnv.drop=3,3 + elseif D.event==75 then + P:showTextF(text.maxspeed,0,-140,100,"appear",.6) + P.dropDelay,P.gameEnv.drop=2,2 + end + end end end end diff --git a/parts/modes/defender_normal.lua b/parts/modes/defender_normal.lua index e3170bc0..2cf6d210 100644 --- a/parts/modes/defender_normal.lua +++ b/parts/modes/defender_normal.lua @@ -8,33 +8,37 @@ return{ freshLimit=15, pushSpeed=1, task=function(P) - if not(P.control and SCN.cur=="play")then return end - P.modeData.counter=P.modeData.counter+1 - local t=360-P.modeData.event*2 - if P.modeData.counter>=t then - P.modeData.counter=0 - for _=1,3 do - P.atkBuffer[#P.atkBuffer+1]={pos=P:RND(2,9),amount=1,countdown=2*t,cd0=2*t,time=0,sent=false,lv=1} - end - P.atkBuffer.sum=P.atkBuffer.sum+3 - P.stat.recv=P.stat.recv+3 - local D=P.modeData - if D.event<90 then - D.event=D.event+1 - D.point=int(108e3/(360-D.event*2))*.1 - if D.event==25 then - P:showTextF(text.great,0,-140,100,"appear",.6) - P.gameEnv.pushSpeed=2 - P.dropDelay,P.gameEnv.drop=20,20 - elseif D.event==50 then - P:showTextF(text.awesome,0,-140,100,"appear",.6) - P.gameEnv.pushSpeed=3 - P.dropDelay,P.gameEnv.drop=10,10 - elseif D.event==90 then - P.dropDelay,P.gameEnv.drop=5,5 - P:showTextF(text.maxspeed,0,-140,100,"appear",.6) + while true do + coroutine.yield() + if P.control and SCN.cur=="play"then + P.modeData.counter=P.modeData.counter+1 + local t=360-P.modeData.event*2 + if P.modeData.counter>=t then + P.modeData.counter=0 + for _=1,3 do + P.atkBuffer[#P.atkBuffer+1]={pos=P:RND(2,9),amount=1,countdown=2*t,cd0=2*t,time=0,sent=false,lv=1} + end + P.atkBuffer.sum=P.atkBuffer.sum+3 + P.stat.recv=P.stat.recv+3 + local D=P.modeData + if D.event<90 then + D.event=D.event+1 + D.point=int(108e3/(360-D.event*2))*.1 + if D.event==25 then + P:showTextF(text.great,0,-140,100,"appear",.6) + P.gameEnv.pushSpeed=2 + P.dropDelay,P.gameEnv.drop=20,20 + elseif D.event==50 then + P:showTextF(text.awesome,0,-140,100,"appear",.6) + P.gameEnv.pushSpeed=3 + P.dropDelay,P.gameEnv.drop=10,10 + elseif D.event==90 then + P.dropDelay,P.gameEnv.drop=5,5 + P:showTextF(text.maxspeed,0,-140,100,"appear",.6) + end + end end - end + end end end, bg="rainbow2",bgm="storm", diff --git a/parts/modes/dig_hard.lua b/parts/modes/dig_hard.lua index b2b36104..1cdece89 100644 --- a/parts/modes/dig_hard.lua +++ b/parts/modes/dig_hard.lua @@ -1,4 +1,3 @@ -local max=math.max return{ color=COLOR.magenta, env={ @@ -6,14 +5,18 @@ return{ fall=20, freshLimit=15, task=function(P) - if not(P.control and SCN.cur=="play")then return end - local D=P.modeData - D.counter=D.counter+1 - if D.counter>=max(90,180-D.event)then - P:garbageRise(21,1,P:getHolePos()) - P.stat.recv=P.stat.recv+1 - D.counter=0 - D.event=D.event+1 + while true do + coroutine.yield() + if P.control and SCN.cur=="play"then + local D=P.modeData + D.counter=D.counter+1 + if D.counter>=math.max(90,180-D.event)then + P:garbageRise(21,1,P:getHolePos()) + P.stat.recv=P.stat.recv+1 + D.counter=0 + D.event=D.event+1 + end + end end end, bg="bg2",bgm="down", diff --git a/parts/modes/dig_ultimate.lua b/parts/modes/dig_ultimate.lua index 06a0b6ae..96b58833 100644 --- a/parts/modes/dig_ultimate.lua +++ b/parts/modes/dig_ultimate.lua @@ -1,18 +1,21 @@ -local max=math.max return{ color=COLOR.lYellow, env={ drop=10,lock=30, freshLimit=15, task=function(P) - if not(P.control and SCN.cur=="play")then return end - local D=P.modeData - D.counter=D.counter+1 - if D.counter>=max(30,80-.3*D.event)then - P:garbageRise(20+D.event%5,1,P:getHolePos()) - P.stat.recv=P.stat.recv+1 - D.counter=0 - D.event=D.event+1 + while true do + coroutine.yield() + if P.control and SCN.cur=="play"then + local D=P.modeData + D.counter=D.counter+1 + if D.counter>=math.max(30,80-.3*D.event)then + P:garbageRise(20+D.event%5,1,P:getHolePos()) + P.stat.recv=P.stat.recv+1 + D.counter=0 + D.event=D.event+1 + end + end end end, bg="bg2",bgm="down", diff --git a/parts/modes/pctrain_lunatic.lua b/parts/modes/pctrain_lunatic.lua index bf92fc4b..525bfdfc 100644 --- a/parts/modes/pctrain_lunatic.lua +++ b/parts/modes/pctrain_lunatic.lua @@ -7,14 +7,17 @@ local PClist=require"parts/modes/PClist" local PCtype={[0]=1,2,3,2,3} local function task_PC(P) - P.modeData.counter=P.modeData.counter+1 - if P.modeData.counter==26 then - local base=PCbase[P.modeData.type] - P:pushLineList(base[P:RND(#base)],P.modeData.symmetry) - return true + local D=P.modeData + while true do + coroutine.yield() + D.counter=D.counter+1 + if D.counter==26 then + local base=PCbase[D.type] + P:pushLineList(base[P:RND(#base)],D.symmetry) + end end end -local function newPC(P) +local function check(P) local r=P.field if r[1]then r=r[#r] @@ -55,7 +58,7 @@ return{ fall=20, sequence="none", freshLimit=15, - dropPiece=newPC, + dropPiece=check, RS="SRS", ospin=false, bg="rgb",bgm="oxygen", @@ -63,7 +66,7 @@ return{ pauseLimit=true, load=function() PLY.newPlayer(1,340,15) - newPC(PLAYERS[1]) + check(PLAYERS[1]) end, mesDisp=function(P) setFont(75) diff --git a/parts/modes/pctrain_normal.lua b/parts/modes/pctrain_normal.lua index 3d111acd..f8e580ac 100644 --- a/parts/modes/pctrain_normal.lua +++ b/parts/modes/pctrain_normal.lua @@ -13,14 +13,17 @@ local PCtype={ 3, } local function task_PC(P) - P.modeData.counter=P.modeData.counter+1 - if P.modeData.counter==26 then - local base=PCbase[P.modeData.type] - P:pushLineList(base[P:RND(#base)],P.modeData.symmetry) - return true + local D=P.modeData + while true do + D.counter=D.counter+1 + if D.counter==26 then + local base=PCbase[D.type] + P:pushLineList(base[P:RND(#base)],D.symmetry) + end + coroutine.yield() end end -local function newPC(P) +local function check(P) local r=P.field if r[1]then r=r[#r] @@ -47,7 +50,7 @@ return{ drop=120,lock=180, fall=20, sequence="none", - dropPiece=newPC, + dropPiece=check, RS="SRS", ospin=false, bg="rgb",bgm="oxygen", @@ -55,7 +58,7 @@ return{ pauseLimit=true, load=function() PLY.newPlayer(1,340,15) - newPC(PLAYERS[1]) + check(PLAYERS[1]) end, mesDisp=function(P) setFont(75) diff --git a/parts/modes/survivor_easy.lua b/parts/modes/survivor_easy.lua index c529939e..0e7b8036 100644 --- a/parts/modes/survivor_easy.lua +++ b/parts/modes/survivor_easy.lua @@ -1,19 +1,22 @@ -local max=math.max return{ color=COLOR.cyan, env={ drop=30,lock=45, freshLimit=10, task=function(P) - if not(P.control and SCN.cur=="play")then return end - P.modeData.counter=P.modeData.counter+1 - if P.modeData.counter>=max(60,150-2*P.modeData.event)and P.atkBuffer.sum<4 then - P.atkBuffer[#P.atkBuffer+1]={pos=P:RND(10),amount=1,countdown=30,cd0=30,time=0,sent=false,lv=1} - P.atkBuffer.sum=P.atkBuffer.sum+1 - P.stat.recv=P.stat.recv+1 - if P.modeData.event==45 then P:showTextF(text.maxspeed,0,-140,100,"appear",.6)end - P.modeData.counter=0 - P.modeData.event=P.modeData.event+1 + while true do + coroutine.yield() + if P.control and SCN.cur=="play"then + P.modeData.counter=P.modeData.counter+1 + if P.modeData.counter>=math.max(60,150-2*P.modeData.event)and P.atkBuffer.sum<4 then + P.atkBuffer[#P.atkBuffer+1]={pos=P:RND(10),amount=1,countdown=30,cd0=30,time=0,sent=false,lv=1} + P.atkBuffer.sum=P.atkBuffer.sum+1 + P.stat.recv=P.stat.recv+1 + if P.modeData.event==45 then P:showTextF(text.maxspeed,0,-140,100,"appear",.6)end + P.modeData.counter=0 + P.modeData.event=P.modeData.event+1 + end + end end end, bg="glow",bgm="new era", diff --git a/parts/modes/survivor_hard.lua b/parts/modes/survivor_hard.lua index d2877b87..c1556a30 100644 --- a/parts/modes/survivor_hard.lua +++ b/parts/modes/survivor_hard.lua @@ -1,25 +1,28 @@ -local max=math.max return{ color=COLOR.magenta, env={ drop=30,lock=45, freshLimit=10, task=function(P) - if not(P.control and SCN.cur=="play")then return end - P.modeData.counter=P.modeData.counter+1 - local B=P.atkBuffer - if P.modeData.counter>=max(60,180-2*P.modeData.event)and B.sum<15 then - B[#B+1]= - P.modeData.event%3<2 and - {pos=P:RND(10),amount=1,countdown=0,cd0=0,time=0,sent=false,lv=1} - or - {pos=P:RND(10),amount=3,countdown=60,cd0=60,time=0,sent=false,lv=2} - local R=(P.modeData.event%3<2 and 1 or 3) - B.sum=B.sum+R - P.stat.recv=P.stat.recv+R - if P.modeData.event==60 then P:showTextF(text.maxspeed,0,-140,100,"appear",.6)end - P.modeData.counter=0 - P.modeData.event=P.modeData.event+1 + while true do + coroutine.yield() + if P.control and SCN.cur=="play"then + P.modeData.counter=P.modeData.counter+1 + local B=P.atkBuffer + if P.modeData.counter>=math.max(60,180-2*P.modeData.event)and B.sum<15 then + B[#B+1]= + P.modeData.event%3<2 and + {pos=P:RND(10),amount=1,countdown=0,cd0=0,time=0,sent=false,lv=1} + or + {pos=P:RND(10),amount=3,countdown=60,cd0=60,time=0,sent=false,lv=2} + local R=(P.modeData.event%3<2 and 1 or 3) + B.sum=B.sum+R + P.stat.recv=P.stat.recv+R + if P.modeData.event==60 then P:showTextF(text.maxspeed,0,-140,100,"appear",.6)end + P.modeData.counter=0 + P.modeData.event=P.modeData.event+1 + end + end end end, bg="glow",bgm="secret7th", diff --git a/parts/modes/survivor_lunatic.lua b/parts/modes/survivor_lunatic.lua index f3fc14ac..1a8622dd 100644 --- a/parts/modes/survivor_lunatic.lua +++ b/parts/modes/survivor_lunatic.lua @@ -1,20 +1,23 @@ -local max=math.max return{ color=COLOR.red, env={ drop=30,lock=45, freshLimit=10, task=function(P) - if not(P.control and SCN.cur=="play")then return end - P.modeData.counter=P.modeData.counter+1 - if P.modeData.counter>=max(60,150-P.modeData.event)and P.atkBuffer.sum<20 then - local t=max(60,90-P.modeData.event) - P.atkBuffer[#P.atkBuffer+1]={pos=P:RND(10),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=3} - P.atkBuffer.sum=P.atkBuffer.sum+4 - P.stat.recv=P.stat.recv+4 - if P.modeData.event==60 then P:showTextF(text.maxspeed,0,-140,100,"appear",.6)end - P.modeData.counter=0 - P.modeData.event=P.modeData.event+1 + while true do + coroutine.yield() + if P.control and SCN.cur=="play"then + P.modeData.counter=P.modeData.counter+1 + if P.modeData.counter>=math.max(60,150-P.modeData.event)and P.atkBuffer.sum<20 then + local t=math.max(60,90-P.modeData.event) + P.atkBuffer[#P.atkBuffer+1]={pos=P:RND(10),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=3} + P.atkBuffer.sum=P.atkBuffer.sum+4 + P.stat.recv=P.stat.recv+4 + if P.modeData.event==60 then P:showTextF(text.maxspeed,0,-140,100,"appear",.6)end + P.modeData.counter=0 + P.modeData.event=P.modeData.event+1 + end + end end end, bg="glow",bgm="storm", diff --git a/parts/modes/survivor_normal.lua b/parts/modes/survivor_normal.lua index 71386427..c3f9226e 100644 --- a/parts/modes/survivor_normal.lua +++ b/parts/modes/survivor_normal.lua @@ -1,24 +1,27 @@ -local max=math.max return{ color=COLOR.green, env={ drop=30,lock=45, freshLimit=10, task=function(P) - if not(P.control and SCN.cur=="play")then return end - P.modeData.counter=P.modeData.counter+1 - if P.modeData.counter>=max(90,180-2*P.modeData.event)and P.atkBuffer.sum<8 then - local d=P.modeData.event+1 - P.atkBuffer[#P.atkBuffer+1]= - d%4==0 and{pos=P:RND(10),amount=1,countdown=60,cd0=60,time=0,sent=false,lv=1}or - d%4==1 and{pos=P:RND(10),amount=2,countdown=70,cd0=70,time=0,sent=false,lv=1}or - d%4==2 and{pos=P:RND(10),amount=3,countdown=80,cd0=80,time=0,sent=false,lv=2}or - d%4==3 and{pos=P:RND(10),amount=4,countdown=90,cd0=90,time=0,sent=false,lv=3} - P.atkBuffer.sum=P.atkBuffer.sum+d%4+1 - P.stat.recv=P.stat.recv+d%4+1 - if P.modeData.event==45 then P:showTextF(text.maxspeed,0,-140,100,"appear",.6)end - P.modeData.counter=0 - P.modeData.event=d + while true do + coroutine.yield() + if P.control and SCN.cur=="play"then + P.modeData.counter=P.modeData.counter+1 + if P.modeData.counter>=math.max(90,180-2*P.modeData.event)and P.atkBuffer.sum<8 then + local d=P.modeData.event+1 + P.atkBuffer[#P.atkBuffer+1]= + d%4==0 and{pos=P:RND(10),amount=1,countdown=60,cd0=60,time=0,sent=false,lv=1}or + d%4==1 and{pos=P:RND(10),amount=2,countdown=70,cd0=70,time=0,sent=false,lv=1}or + d%4==2 and{pos=P:RND(10),amount=3,countdown=80,cd0=80,time=0,sent=false,lv=2}or + d%4==3 and{pos=P:RND(10),amount=4,countdown=90,cd0=90,time=0,sent=false,lv=3} + P.atkBuffer.sum=P.atkBuffer.sum+d%4+1 + P.stat.recv=P.stat.recv+d%4+1 + if P.modeData.event==45 then P:showTextF(text.maxspeed,0,-140,100,"appear",.6)end + P.modeData.counter=0 + P.modeData.event=d + end + end end end, bg="glow",bgm="secret8th", diff --git a/parts/modes/survivor_ultimate.lua b/parts/modes/survivor_ultimate.lua index 6754c883..0afb058c 100644 --- a/parts/modes/survivor_ultimate.lua +++ b/parts/modes/survivor_ultimate.lua @@ -1,4 +1,3 @@ -local max=math.max return{ color=COLOR.lYellow, env={ @@ -7,20 +6,24 @@ return{ freshLimit=15, pushSpeed=2, task=function(P) - if not(P.control and SCN.cur=="play")then return end - P.modeData.counter=P.modeData.counter+1 - if P.modeData.counter>=max(300,600-10*P.modeData.event)and P.atkBuffer.sum<20 then - local t=max(300,480-12*P.modeData.event) - local p=#P.atkBuffer+1 - P.atkBuffer[p] ={pos=P:RND(10),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=2} - P.atkBuffer[p+1]={pos=P:RND(10),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=3} - P.atkBuffer[p+2]={pos=P:RND(10),amount=6,countdown=1.2*t,cd0=1.2*t,time=0,sent=false,lv=4} - P.atkBuffer[p+3]={pos=P:RND(10),amount=6,countdown=1.5*t,cd0=1.5*t,time=0,sent=false,lv=5} - P.atkBuffer.sum=P.atkBuffer.sum+20 - P.stat.recv=P.stat.recv+20 - if P.modeData.event==31 then P:showTextF(text.maxspeed,0,-140,100,"appear",.6)end - P.modeData.counter=0 - P.modeData.event=P.modeData.event+1 + while true do + coroutine.yield() + if P.control and SCN.cur=="play"then + P.modeData.counter=P.modeData.counter+1 + if P.modeData.counter>=math.max(300,600-10*P.modeData.event)and P.atkBuffer.sum<20 then + local t=math.max(300,480-12*P.modeData.event) + local p=#P.atkBuffer+1 + P.atkBuffer[p] ={pos=P:RND(10),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=2} + P.atkBuffer[p+1]={pos=P:RND(10),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=3} + P.atkBuffer[p+2]={pos=P:RND(10),amount=6,countdown=1.2*t,cd0=1.2*t,time=0,sent=false,lv=4} + P.atkBuffer[p+3]={pos=P:RND(10),amount=6,countdown=1.5*t,cd0=1.5*t,time=0,sent=false,lv=5} + P.atkBuffer.sum=P.atkBuffer.sum+20 + P.stat.recv=P.stat.recv+20 + if P.modeData.event==31 then P:showTextF(text.maxspeed,0,-140,100,"appear",.6)end + P.modeData.counter=0 + P.modeData.event=P.modeData.event+1 + end + end end end, bg="welcome",bgm="storm", diff --git a/parts/modes/ultra.lua b/parts/modes/ultra.lua index 47000dfb..92101963 100644 --- a/parts/modes/ultra.lua +++ b/parts/modes/ultra.lua @@ -8,15 +8,18 @@ return{ drop=60,lock=60, fall=20, task=function(P) - local _=P.modeData.counter+1 - if P.stat.frame>=warnTime[_]*60 then - if _<9 then - P.modeData.counter=_ - SFX.play("ready",.7+_*.03) - else - SFX.play("start") - P:win("finish") - return true + while true do + coroutine.yield() + local _=P.modeData.counter+1 + if P.stat.frame>=warnTime[_]*60 then + if _<9 then + P.modeData.counter=_ + SFX.play("ready",.7+_*.03) + else + SFX.play("start") + P:win("finish") + return + end end end end, diff --git a/parts/player/player.lua b/parts/player/player.lua index 1c10e7b7..c935610c 100644 --- a/parts/player/player.lua +++ b/parts/player/player.lua @@ -7,6 +7,7 @@ local Player={}--Player class local int,ceil,rnd=math.floor,math.ceil,math.random local max,min=math.max,math.min local ins,rem=table.insert,table.remove +local ct=coroutine local kickList=require"parts/kickList" local scs=spinCenters @@ -124,12 +125,11 @@ function Player.RND(P,a,b) local R=P.randGen return R:random(a,b) end -function Player.newTask(P,code,data) +function Player.newTask(P,code) local L=P.tasks - ins(L,{ - code=code, - data=data, - }) + local thread=ct.create(code) + ct.resume(thread,P) + L[#L+1]=thread end function Player.set20G(P,if20g,init)--Only set init=true when initialize CC, do not use it @@ -1453,7 +1453,7 @@ function Player.win(P,result) end if P.human then gameOver() - TASK.new(TICK.autoPause,{0}) + TASK.new(TICK.autoPause) if MARKING then P:showTextF(text.marking,0,-226,25,"appear",.4,.0626) end @@ -1532,7 +1532,7 @@ function Player.lose(P,force) end P.lastRecv=A if P.id==1 or A.id==1 then - TASK.new(TICK.throwBadge,{A.ai,P,max(3,P.badge)*4}) + TASK.new(TICK.throwBadge,A.ai,P,max(3,P.badge)*4) end end else @@ -1561,7 +1561,7 @@ function Player.lose(P,force) end gameOver() P:newTask(#PLAYERS>1 and TICK.lose or TICK.finish) - TASK.new(TICK.autoPause,{0}) + TASK.new(TICK.autoPause) if MARKING then P:showTextF(text.marking,0,-226,25,"appear",.4,.0626) end diff --git a/parts/player/update.lua b/parts/player/update.lua index 1c504884..c308df5f 100644 --- a/parts/player/update.lua +++ b/parts/player/update.lua @@ -1,5 +1,7 @@ local int,max,min,abs=math.floor,math.max,math.min,math.abs local rem=table.remove +local ct=coroutine +local assert=assert local function updateLine(P)--Attacks, line pushing, cam moving local bf=P.atkBuffer @@ -95,7 +97,10 @@ end local function updateTasks(P) local L=P.tasks for i=#L,1,-1 do - if L[i].code(P,L[i].data)then rem(L,i)end + assert(ct.resume(L[i])) + if ct.status(L[i])=="dead"then + rem(L,i) + end end end diff --git a/parts/tick.lua b/parts/tick.lua index dca874ce..ff017f47 100644 --- a/parts/tick.lua +++ b/parts/tick.lua @@ -1,151 +1,248 @@ -local function checkTimeout(data,time) - data.time=data.time+1 - if data.time==time then - LOG.print(text.httpTimeout,"message") - return true - end -end +local yield=coroutine.yield + local Tick={} -function Tick.showMods(data) - local d=data[1]+1 - if d%20==0 then - local M=GAME.mod[d/20] - if M then - TEXT.show(M.id,700+(d-20)%120*4,36,45,"spin",.5) - else - return true +function Tick.showMods() + local time=0 + while true do + yield() + time=time+1 + if time%20==0 then + local M=GAME.mod[time/20] + if M then + TEXT.show(M.id,700+(time-20)%120*4,36,45,"spin",.5) + else + return + end end end - data[1]=d end function Tick.finish(P) - P.endCounter=P.endCounter+1 - if P.endCounter<40 then - --Make field visible - for j=1,#P.field do for i=1,10 do - if P.visTime[j][i]<20 then P.visTime[j][i]=P.visTime[j][i]+.5 end - end end - elseif P.endCounter==60 then - return true + while true do + yield() + P.endCounter=P.endCounter+1 + if P.endCounter<40 then + --Make field visible + for j=1,#P.field do for i=1,10 do + if P.visTime[j][i]<20 then P.visTime[j][i]=P.visTime[j][i]+.5 end + end end + elseif P.endCounter==60 then + return + end end end function Tick.lose(P) - P.endCounter=P.endCounter+1 - if P.endCounter<40 then - --Make field visible - for j=1,#P.field do for i=1,10 do - if P.visTime[j][i]<20 then P.visTime[j][i]=P.visTime[j][i]+.5 end - end end - elseif P.endCounter>80 then - for i=1,#P.field do - for j=1,10 do - if P.visTime[i][j]>0 then - P.visTime[i][j]=P.visTime[i][j]-1 + while true do + yield() + P.endCounter=P.endCounter+1 + if P.endCounter<40 then + --Make field visible + for j=1,#P.field do for i=1,10 do + if P.visTime[j][i]<20 then P.visTime[j][i]=P.visTime[j][i]+.5 end + end end + elseif P.endCounter>80 then + for i=1,#P.field do + for j=1,10 do + if P.visTime[i][j]>0 then + P.visTime[i][j]=P.visTime[i][j]-1 + end end end - end - if P.endCounter==120 then - for _=#P.field,1,-1 do - FREEROW.discard(P.field[_]) - FREEROW.discard(P.visTime[_]) - P.field[_],P.visTime[_]=nil + if P.endCounter==120 then + for _=#P.field,1,-1 do + FREEROW.discard(P.field[_]) + FREEROW.discard(P.visTime[_]) + P.field[_],P.visTime[_]=nil + end + return end - return true end - end - if not GAME.modeEnv.royaleMode and #PLAYERS>1 then - P.y=P.y+P.endCounter*.26 - P.absFieldY=P.absFieldY+P.endCounter*.26 + if not GAME.modeEnv.royaleMode and #PLAYERS>1 then + P.y=P.y+P.endCounter*.26 + P.absFieldY=P.absFieldY+P.endCounter*.26 + end end end -function Tick.throwBadge(data)--{ifAI,Sender,timer} - data[3]=data[3]-1 - if data[3]%4==0 then - local S,R=data[2],data[2].lastRecv - local x1,y1,x2,y2 - if S.small then - x1,y1=S.centerX,S.centerY - else - x1,y1=S.x+308*S.size,S.y+450*S.size - end - if R.small then - x2,y2=R.centerX,R.centerY - else - x2,y2=R.x+66*R.size,R.y+344*R.size - end +function Tick.throwBadge(ifAI,sender,time) + while true do + yield() + time=time-1 + if time%4==0 then + local S,R=sender,sender.lastRecv + local x1,y1,x2,y2 + if S.small then + x1,y1=S.centerX,S.centerY + else + x1,y1=S.x+308*S.size,S.y+450*S.size + end + if R.small then + x2,y2=R.centerX,R.centerY + else + x2,y2=R.x+66*R.size,R.y+344*R.size + end - --Generate badge object - SYSFX.newBadge(x1,y1,x2,y2) + --Generate badge object + SYSFX.newBadge(x1,y1,x2,y2) - if not data[1]and data[3]%8==0 then - SFX.play("collect") + if not ifAI and time%8==0 then + SFX.play("collect") + end end + if time<=0 then return end end - if data[3]<=0 then return true end end -function Tick.autoPause(data) - data[1]=data[1]+1 - if SCN.cur~="play"then return true end - if data[1]==120 then - if SCN.cur=="play"then +function Tick.autoPause() + local time=0 + while true do + yield() + time=time+1 + if SCN.cur~="play"then + return + elseif time==120 then pauseGame() + return end - return true end end -function Tick.httpREQ_launch(data) - local response,request_error=client.poll(data.task) - if response then - local res=json.decode(response.body) - if res then - if response.code==200 then - LOG.print(res.notice,360,COLOR.sky) - if VERSION_CODE>=res.version_code then - LOG.print(text.versionIsNew,360,COLOR.sky) +function Tick.httpREQ_launch(task) + local time=0 + while true do + yield() + local response,request_error=client.poll(task) + if response then + local res=json.decode(response.body) + if res then + if response.code==200 then + LOG.print(res.notice,360,COLOR.sky) + if VERSION_CODE>=res.version_code then + LOG.print(text.versionIsNew,360,COLOR.sky) + else + LOG.print(string.gsub(text.versionIsOld,"$1",res.version_name),"warn") + end else - LOG.print(string.gsub(text.versionIsOld,"$1",res.version_name),"warn") + LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") + end + end + return + elseif request_error then + LOG.print(text.getNoticeFail..": "..request_error,"warn") + return + end + time=time+1 + if time>360 then + LOG.print(text.httpTimeout,"message") + return + end + end +end +function Tick.httpREQ_register(task) + local time=0 + while true do + yield() + local response,request_error=client.poll(task) + if response then + local res=json.decode(response.body) + if res then + if response.code==200 then + LOG.print(text.registerSuccessed..": "..res.message) + else + LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") + end + end + return + elseif request_error then + LOG.print(text.loginFailed..": "..request_error,"warn") + return + end + time=time+1 + if time>360 then + LOG.print(text.httpTimeout,"message") + return + end + end +end +function Tick.httpREQ_newLogin(task) + local time=0 + while true do + yield() + local response,request_error=client.poll(task) + if response then + local res=json.decode(response.body) + LOGIN=response.code==200 + if res then + if LOGIN then + LOG.print(text.loginSuccessed) + ACCOUNT.email=res.email + ACCOUNT.auth_token=res.auth_token + FILE.save(ACCOUNT,"account","") + + httpRequest( + TICK.httpREQ_getAccessToken, + PATH.api..PATH.access, + "POST", + {["Content-Type"]="application/json"}, + json.encode{ + email=ACCOUNT.email, + auth_token=ACCOUNT.auth_token, + } + ) + else + LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") + end + end + return + elseif request_error then + LOG.print(text.loginFailed..": "..request_error,"warn") + return + end + time=time+1 + if time>360 then + LOG.print(text.httpTimeout,"message") + return + end + end +end +function Tick.httpREQ_autoLogin(task) + local time=0 + while true do + yield() + local response,request_error=client.poll(task) + if response then + if response.code==200 then + LOGIN=true + local res=json.decode(response.body) + if res then + LOG.print(text.loginSuccessed) end else - LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") + LOGIN=false + local err=json.decode(response.body) + if err then + LOG.print(text.loginFailed..": "..text.netErrorCode..response.code.."-"..err.message,"warn") + end end + return + elseif request_error then + LOG.print(text.loginFailed..": "..request_error,"warn") + return + end + time=time+1 + if time>360 then + LOG.print(text.httpTimeout,"message") + return end - return true - elseif request_error then - LOG.print(text.getNoticeFail..": "..request_error,"warn") - return true end - return checkTimeout(data,260) end -function Tick.httpREQ_register(data) - local response,request_error=client.poll(data.task) - if response then - local res=json.decode(response.body) - if res then +function Tick.httpREQ_checkAccessToken(task) + local time=0 + while true do + yield() + local response,request_error=client.poll(task) + if response then if response.code==200 then - LOG.print(text.registerSuccessed..": "..res.message) - else - LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") - end - end - return true - elseif request_error then - LOG.print(text.loginFailed..": "..request_error,"warn") - return true - end - return checkTimeout(data,360) -end -function Tick.httpREQ_newLogin(data) - local response,request_error=client.poll(data.task) - if response then - local res=json.decode(response.body) - LOGIN=response.code==200 - if res then - if LOGIN then - LOG.print(text.loginSuccessed) - ACCOUNT.email=res.email - ACCOUNT.auth_token=res.auth_token - FILE.save(ACCOUNT,"account","") - + LOG.print(text.accessSuccessed) + SCN.pop() + SCN.go("netgame") + elseif response.code==403 or response.code==401 then httpRequest( TICK.httpREQ_getAccessToken, PATH.api..PATH.access, @@ -157,144 +254,115 @@ function Tick.httpREQ_newLogin(data) } ) else - LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") + local err=json.decode(response.body) + if err then + LOG.print(text.netErrorCode..response.code..": "..err.message,"warn") + end end + return + elseif request_error then + LOG.print(text.loginFailed..": "..request_error,"warn") + return end - return true - elseif request_error then - LOG.print(text.loginFailed..": "..request_error,"warn") - return true - end - return checkTimeout(data,360) -end -function Tick.httpREQ_autoLogin(data) - local response,request_error=client.poll(data.task) - if response then - if response.code==200 then - LOGIN=true - local res=json.decode(response.body) - if res then - LOG.print(text.loginSuccessed) - end - else - LOGIN=false - local err=json.decode(response.body) - if err then - LOG.print(text.loginFailed..": "..text.netErrorCode..response.code.."-"..err.message,"warn") - end + time=time+1 + if time>360 then + LOG.print(text.httpTimeout,"message") + return end - return true - elseif request_error then - LOG.print(text.loginFailed..": "..request_error,"warn") - return true end - return checkTimeout(data,360) end -function Tick.httpREQ_checkAccessToken(data) - local response,request_error=client.poll(data.task) - if response then - if response.code==200 then - LOG.print(text.accessSuccessed) - SCN.pop() - SCN.go("netgame") - elseif response.code==403 or response.code==401 then - httpRequest( - TICK.httpREQ_getAccessToken, - PATH.api..PATH.access, - "POST", - {["Content-Type"]="application/json"}, - json.encode{ - email=ACCOUNT.email, - auth_token=ACCOUNT.auth_token, - } - ) - else - local err=json.decode(response.body) - if err then - LOG.print(text.netErrorCode..response.code..": "..err.message,"warn") - end - end - return true - elseif request_error then - LOG.print(text.loginFailed..": "..request_error,"warn") - return true - end - return checkTimeout(data,360) -end -function Tick.httpREQ_getAccessToken(data) - local response,request_error=client.poll(data.task) - if response then - if response.code==200 then - local res=json.decode(response.body) - if res then - LOG.print(text.accessSuccessed) - ACCOUNT.access_token=res.access_token - FILE.save(ACCOUNT,"account","") - SCN.pop() - SCN.go("netgame") +function Tick.httpREQ_getAccessToken(task) + local time=0 + while true do + yield() + local response,request_error=client.poll(task) + if response then + if response.code==200 then + local res=json.decode(response.body) + if res then + LOG.print(text.accessSuccessed) + ACCOUNT.access_token=res.access_token + FILE.save(ACCOUNT,"account","") + SCN.pop() + SCN.go("netgame") + else + LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") + SCN.pop() + SCN.go("main") + end else - LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") + LOGIN=false + ACCOUNT.access_token=nil + ACCOUNT.auth_token=nil + local err=json.decode(response.body) + if err then + LOG.print(text.loginFailed..": "..text.netErrorCode..response.code.."-"..err.message,"warn") + else + LOG.print(text.loginFailed..": "..text.netErrorCode,"warn") + end SCN.pop() SCN.go("main") end - else - LOGIN=false - ACCOUNT.access_token=nil - ACCOUNT.auth_token=nil - local err=json.decode(response.body) - if err then - LOG.print(text.loginFailed..": "..text.netErrorCode..response.code.."-"..err.message,"warn") - else - LOG.print(text.loginFailed..": "..text.netErrorCode,"warn") - end - SCN.pop() - SCN.go("main") + return + elseif request_error then + LOG.print(text.loginFailed..": "..request_error,"warn") + return + end + time=time+1 + if time>360 then + LOG.print(text.httpTimeout,"message") + return end - return true - elseif request_error then - LOG.print(text.loginFailed..": "..request_error,"warn") - return true end - return checkTimeout(data,360) end -function Tick.wsCONN_connect(data) - if data.wsconntask then - local wsconn,connErr=client.poll(data.wsconntask) +function Tick.wsCONN_connect(task) + local time=0 + while true do + yield() + local wsconn,connErr=client.poll(task) if wsconn then - WSCONN = wsconn + WSCONN=wsconn TASK.new(Tick.wsCONN_read) - return true + return elseif connErr then LOG.print(text.wsFailed..": "..connErr,"warn") - return true + return + end + time=time+1 + if time>360 then + LOG.print(text.httpTimeout,"message") + return end end - return checkTimeout(data,360) end function Tick.wsCONN_read() - local messages,readErr=client.read(WSCONN) - if messages then - if messages[1] then - LOG.print(messages[1]) + while true do + yield() + local messages,readErr=client.read(WSCONN) + if messages then + if messages[1]then + LOG.print(messages[1]) + end + elseif readErr then + print("Read error: "..readErr) + if readErr=="EOF"then + LOG.print("Socket closed!","warn") + end + WSCONN=nil + return end - elseif readErr then - print("Read error: "..readErr) - if readErr == "EOF" then - LOG.print("Socket closed!","warn") - end - WSCONN = nil - return true end end --- function Tick.wsCONN_write(data) --- if not data.net then --- return true +-- function Tick.wsCONN_write() +-- while true do +-- local message=yield() +-- if message then +-- local writeErr=client.write(WSCONN,message) +-- if writeErr then +-- print(writeErr,"warn") +-- end +-- end -- end --- local writeErr=client.write(WSCONN,data.message) --- if writeErr then --- print(writeErr, "warn") --- end --- return true -- end return Tick \ No newline at end of file