From 5073fe536357a5dc962c53db6ee2095263ffda60 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Tue, 9 Feb 2021 17:59:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7task=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=92=8C=E4=BD=BF=E7=94=A8=E6=A8=A1=E5=9D=97=E7=9A=84=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E7=9B=B8=E5=85=B3=E5=87=BD=E6=95=B0=EF=BC=8Cws?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E4=BB=BB=E5=8A=A1=E4=B8=8D=E5=86=8D=E4=B8=8E?= =?UTF-8?q?=E6=9C=AA=E5=AE=8C=E6=88=90=E7=9A=84http=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/task.lua | 20 +++++++++++++++++++- Zframework/toolfunc.lua | 4 ++-- parts/scenes/net_rooms.lua | 3 +-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Zframework/task.lua b/Zframework/task.lua index 0ba89f1d..eb900da7 100644 --- a/Zframework/task.lua +++ b/Zframework/task.lua @@ -5,6 +5,7 @@ local tasks={} local TASK={ netTaskCount=0, + wsConnecting=false, } function TASK.getCount() return #tasks @@ -17,7 +18,10 @@ function TASK.update() if T.net then TASK.netTaskCount=TASK.netTaskCount-1 end - rem(tasks,i) + if T.ws then + TASK.wsConnecting=false + end + rem(tasks,i) end end end @@ -44,6 +48,20 @@ function TASK.newNet(code,...) } end end +function TASK.newWS(code,...) + TASK.wsConnecting=true + local thread=ct.create(code) + ct.resume(thread,...) + if ct.status(thread)~="dead"then + tasks[#tasks+1]={ + thread=thread, + code=code, + args={...}, + net=true, + ws=true, + } + end +end function TASK.removeTask_code(code) for i=#tasks,1,-1 do if tasks[i].code==code then diff --git a/Zframework/toolfunc.lua b/Zframework/toolfunc.lua index b41a25c3..84a08ff3 100644 --- a/Zframework/toolfunc.lua +++ b/Zframework/toolfunc.lua @@ -559,7 +559,7 @@ do--httpRequest & wsConnect end function wsConnect(tick,path,header) - if TASK.netTaskCount>0 then + if TASK.wsConnecting then LOG.print(text.waitNetTask,"message") return end @@ -569,7 +569,7 @@ do--httpRequest & wsConnect header=header, } if task then - TASK.newNet(tick,task) + TASK.newWS(tick,task) else LOG.print("NETlib error: "..err,"warn") end diff --git a/parts/scenes/net_rooms.lua b/parts/scenes/net_rooms.lua index 74e0e81f..e1a1eb32 100644 --- a/parts/scenes/net_rooms.lua +++ b/parts/scenes/net_rooms.lua @@ -28,7 +28,6 @@ local function task_enterRoom(task) end end local function enterRoom(roomID) - coroutine.yield() wsConnect( task_enterRoom, PATH.socket..PATH.onlinePlay.. @@ -72,7 +71,7 @@ local function task_createRoom(task) local res=json.decode(response.body) if response.code==200 and res.message=="OK"then LOG.print(text.createRoomSuccessed) - TASK.newNet(enterRoom,res.room.id) + enterRoom(res.room.id) else LOG.print(text.httpCode..response.code..": "..res.message,"warn") end