简化接收网络消息的task函数,不再永久停留于任务队列中

This commit is contained in:
MrZ626
2021-06-07 12:45:40 +08:00
parent c78e2c0fbf
commit a49d71f097
2 changed files with 298 additions and 311 deletions

View File

@@ -126,6 +126,8 @@ end
--Connect
function NET.wsconn_app()
WS.connect('app','/app')
TASK.new(NET.updateWS_app)
TASK.new(NET.freshPlayerCount)
end
function NET.wsconn_user_pswd(email,password)
if WS.status('wsc_user')=='dead'then NET.unlock('wsc_user')end
@@ -134,6 +136,7 @@ function NET.wsconn_user_pswd(email,password)
email=email,
password=password,
},6)
TASK.new(NET.updateWS_user)
end
end
function NET.wsconn_user_token(uid,authToken)
@@ -143,6 +146,7 @@ function NET.wsconn_user_token(uid,authToken)
uid=uid,
authToken=authToken,
},6)
TASK.new(NET.updateWS_user)
end
end
function NET.wsconn_play()
@@ -152,6 +156,7 @@ function NET.wsconn_play()
uid=USER.uid,
accessToken=NET.accessToken,
},6)
TASK.new(NET.updateWS_play)
end
end
function NET.wsconn_stream(srid)
@@ -228,14 +233,6 @@ function NET.getUserInfo(uid)
},
})
end
function NET.freshPlayerCount()
while true do
for _=1,260 do yield()end
if WS.status('app')=='running'then
WS.send('app',JSON.encode{action=3})
end
end
end
--Save
function NET.uploadSave()
@@ -383,10 +380,15 @@ function NET.quitChat()
end
--WS tick funcs
function NET.freshPlayerCount()
while WS.status('app')~='dead'do
for _=1,260 do yield()end
WS.send('app',JSON.encode{action=3})
end
end
function NET.updateWS_app()
while true do
while WS.status('app')~='dead'do
yield()
if WS.status('app')=='running'then
local message,op=WS.read('app')
if message then
if op=='ping'then
@@ -439,11 +441,9 @@ function NET.updateWS_app()
end
end
end
end
function NET.updateWS_user()
while true do
while WS.status('user')~='dead'do
yield()
if WS.status('user')=='running'then
local message,op=WS.read('user')
if message then
if op=='ping'then
@@ -488,11 +488,9 @@ function NET.updateWS_user()
end
end
end
end
function NET.updateWS_play()
while true do
while WS.status('play')~='dead'do
yield()
if WS.status('play')=='running'then
local message,op=WS.read('play')
if message then
if op=='ping'then
@@ -614,11 +612,9 @@ function NET.updateWS_play()
end
end
end
end
function NET.updateWS_stream()
while true do
while WS.status('stream')~='dead'do
yield()
if WS.status('stream')=='running'then
local message,op=WS.read('stream')
if message then
if op=='ping'then
@@ -687,11 +683,9 @@ function NET.updateWS_stream()
end
end
end
end
function NET.updateWS_chat()
while true do
while WS.status('chat')~='dead'do
yield()
if WS.status('chat')=='running'then
local message,op=WS.read('chat')
if message then
if op=='ping'then
@@ -711,11 +705,9 @@ function NET.updateWS_chat()
end
end
end
end
function NET.updateWS_manage()
while true do
while WS.status('manage')~='dead'do
yield()
if WS.status('manage')=='running'then
local message,op=WS.read('manage')
if message then
if op=='ping'then
@@ -747,6 +739,5 @@ function NET.updateWS_manage()
end
end
end
end
return NET

View File

@@ -184,11 +184,7 @@ local loadingThread=coroutine.wrap(function()
STAT.run=STAT.run+1
--Connect to server
TASK.new(NET.updateWS_app)
TASK.new(NET.updateWS_user)
TASK.new(NET.updateWS_play)
NET.wsconn_app()
TASK.new(NET.freshPlayerCount)
YIELD()
while true do