From 9a4e8ab4ece98928022689404fa917a56dc3a486 Mon Sep 17 00:00:00 2001 From: MrZ_26 <1046101471@qq.com> Date: Fri, 21 Oct 2022 00:16:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=BC=80=E5=A7=8B=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=E4=BF=A1=E5=8F=B7=E4=B8=8E=E5=88=87=E6=8D=A2=E8=BF=9B?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E7=8A=B6=E6=80=81=E5=88=9B=E5=BB=BA=E7=8E=A9?= =?UTF-8?q?=E5=AE=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/modes/netBattle.lua | 6 +-- parts/net.lua | 20 +++++---- parts/scenes/net_game.lua | 87 +++++++++++++++++---------------------- 3 files changed, 53 insertions(+), 60 deletions(-) diff --git a/parts/modes/netBattle.lua b/parts/modes/netBattle.lua index f0d263a8..a29d445f 100644 --- a/parts/modes/netBattle.lua +++ b/parts/modes/netBattle.lua @@ -18,11 +18,11 @@ return{ GAME.modeEnv.allowMod=false GAME.modeEnv.task=marginTask - local L=TABLE.copy(NETPLY.list) + local L=TABLE.shift(NETPLY.list,0) local N=1 for i,p in next,L do if p.uid==USER.uid then - if p.connected then + if p.playMode=='Gamer' then PLY.newPlayer(1) N=2 end @@ -31,7 +31,7 @@ return{ end end for _,p in next,L do - if p.connected then + if p.playMode=='Gamer' then PLY.newRemotePlayer(N,false,p) N=N+1 end diff --git a/parts/net.lua b/parts/net.lua index 8b75fa7e..475bf3d0 100644 --- a/parts/net.lua +++ b/parts/net.lua @@ -393,7 +393,7 @@ local actMap={ local function wsSend(act,data) -- print(("Send: $1 -->"):repD(act)) - print(("Send: $1 -->"):repD(act)) print(type(data)=='table' and TABLE.dump(data) or tostring(data),"\n") + -- print(("Send: $1 -->"):repD(act)) print(type(data)=='table' and TABLE.dump(data) or tostring(data),"\n") WS.send('game',JSON.encode{ action=assert(act), data=data, @@ -512,7 +512,7 @@ function NET.player_setHost(pid) role='Admin', }) end -function NET.player_setState(state)-- what state? +function NET.player_setState(state)-- not used wsSend(actMap.player_setState,state) end function NET.player_stream(stream) @@ -522,9 +522,7 @@ function NET.player_setPlayMode(mode) wsSend(actMap.player_setPlayMode,mode) end --- Match -function NET.match_techminohaowan(arg) -end + -- WS NET.wsCallBack={} @@ -611,7 +609,7 @@ function NET.wsCallBack.player_joinGroup(body)-- TODO end function NET.wsCallBack.player_setHost(body)-- TODO end -function NET.wsCallBack.player_setState(body)-- TODO +function NET.wsCallBack.player_setState(body)-- TODO (not used) end function NET.wsCallBack.player_stream(body)-- TODO end @@ -621,6 +619,14 @@ end function NET.wsCallBack.player_setReadyMode(body) NETPLY.setReadyMode(body.data.playerId,body.data.type) end +function NET.wsCallBack.match_finish() + TASK.unlock('netPlaying') +end +function NET.wsCallBack.match_ready()-- TODO +end +function NET.wsCallBack.match_start() + TASK.lock('netPlaying') +end function NET.ws_connect() if WS.status('game')=='dead' then @@ -688,7 +694,7 @@ function NET.ws_update() elseif msg then msg=JSON.decode(msg) -- print(("Recv: <-- $1 err:$2"):repD(msg.action,msg.errno)) - print(("Recv: <-- $1 err:$2"):repD(msg.action,msg.errno)) print(TABLE.dump(msg),"\n") + -- print(("Recv: <-- $1 err:$2"):repD(msg.action,msg.errno)) print(TABLE.dump(msg),"\n") if msg.errno~=0 then parseError(msg.message~=nil and msg.message or msg) else diff --git a/parts/scenes/net_game.lua b/parts/scenes/net_game.lua index a602c300..9c56ee6b 100644 --- a/parts/scenes/net_game.lua +++ b/parts/scenes/net_game.lua @@ -80,7 +80,7 @@ function scene.sceneInit() end end function scene.sceneBack() - GAME.playing=false + TASK.unlock('netPlaying') end scene.mouseDown=NULL @@ -193,70 +193,57 @@ function scene.gamepadUp(key) end end -function scene._(cmd,d) - if cmd=='join' then - textBox:push{ - COLOR.lR,d.username, - COLOR.dY,"#"..d.uid.." ", - COLOR.Y,text.joinRoom, - } - SFX.play('warn_1') - elseif cmd=='leave' then - textBox:push{ - COLOR.lR,d.username, - COLOR.dY,"#"..d.uid.." ", - COLOR.Y,text.leaveRoom, - } - elseif cmd=='go' then - if not playing then - playing=true - lastUpstreamTime=0 - upstreamProgress=1 - resetGameData('n',NET.seed) - NETPLY.mouseMove(0,0) - end - elseif cmd=='finish' then - playing=false - BG.set() - end -end - function scene.update(dt) if WS.status('game')~='running' then + TASK.unlock('netPlaying') NET.ws_close() SCN.back() return end if playing then - local P1=PLAYERS[1] + if not TASK.getLock('netPlaying') then + playing=false + BG.set() + return + else + local P1=PLAYERS[1] - touchMoveLastFrame=false - VK.update(dt) + touchMoveLastFrame=false + VK.update(dt) - -- Update players - for p=1,#PLAYERS do PLAYERS[p]:update(dt) end + -- Update players + for p=1,#PLAYERS do PLAYERS[p]:update(dt) end - -- Warning check - checkWarning(dt) + -- Warning check + checkWarning(dt) - -- Upload stream - if not NET.spectate and P1.frameRun-lastUpstreamTime>8 then - local stream - if not GAME.rep[upstreamProgress] then - ins(GAME.rep,P1.frameRun) - ins(GAME.rep,0) + -- Upload stream + if not NET.spectate and P1.frameRun-lastUpstreamTime>8 then + local stream + if not GAME.rep[upstreamProgress] then + ins(GAME.rep,P1.frameRun) + ins(GAME.rep,0) + end + stream,upstreamProgress=DATA.dumpRecording(GAME.rep,upstreamProgress) + if #stream%3==1 then + stream=stream.."\0\0" + elseif #stream%3==2 then + stream=stream.."\0\0\0\0" + end + NET.player_stream(stream) + lastUpstreamTime=PLAYERS[1].alive and P1.frameRun or 1e99 end - stream,upstreamProgress=DATA.dumpRecording(GAME.rep,upstreamProgress) - if #stream%3==1 then - stream=stream.."\0\0" - elseif #stream%3==2 then - stream=stream.."\0\0\0\0" - end - NET.player_stream(stream) - lastUpstreamTime=PLAYERS[1].alive and P1.frameRun or 1e99 end else NETPLY.update(dt) + if TASK.getLock('netPlaying') and not playing then + playing=true + TASK.lock('netPlaying') + lastUpstreamTime=0 + upstreamProgress=1 + resetGameData('n',NET.seed) + NETPLY.mouseMove(0,0) + end end end