优化联网游戏体验(统计数据结算、远程玩家死亡结算时机)

This commit is contained in:
MrZ_26
2022-10-28 16:33:19 +08:00
parent 6b16fcd5f5
commit e291a070f3
4 changed files with 21 additions and 5 deletions

View File

@@ -684,6 +684,7 @@ end
function NET.wsCallBack.player_finish(body) function NET.wsCallBack.player_finish(body)
for _,P in next,PLY_ALIVE do for _,P in next,PLY_ALIVE do
if P.uid==body.data.playerId then if P.uid==body.data.playerId then
P.loseTimer=26
P:lose(true) P:lose(true)
break break
end end
@@ -712,6 +713,9 @@ function NET.wsCallBack.player_setReadyMode(body)
NET.freshRoomAllReady() NET.freshRoomAllReady()
end end
function NET.wsCallBack.match_finish() function NET.wsCallBack.match_finish()
for _,P in next,PLAYERS do
NETPLY.setStat(P.uid,P.stat)
end
TASK.new(function() TASK.new(function()
TEST.yieldT(2.6) TEST.yieldT(2.6)
TASK.unlock('netPlaying') TASK.unlock('netPlaying')

View File

@@ -411,6 +411,7 @@ function PLY.newRemotePlayer(id,mini,p)
P.sid=NET.uid_sid[p.uid] or p.uid P.sid=NET.uid_sid[p.uid] or p.uid
P.group=p.group P.group=p.group
P.netAtk=0-- Sum of lines sent in stream, will be compared with P.stat.send for checking stream legal or not P.netAtk=0-- Sum of lines sent in stream, will be compared with P.stat.send for checking stream legal or not
P.loseTimer=false-- Will be set to 26 when receive player_finish signal
if not (P.group%1==0 and P.group>=1 and P.group<=6) then P.group=0 end if not (P.group%1==0 and P.group>=1 and P.group<=6) then P.group=0 end
_loadRemoteEnv(P,p.config) _loadRemoteEnv(P,p.config)

View File

@@ -2608,7 +2608,7 @@ local function update_streaming(P)
P.netAtk=P.netAtk+amount P.netAtk=P.netAtk+amount
if P.netAtk~=P.stat.send then-- He cheated or just desynchronized to death if P.netAtk~=P.stat.send then-- He cheated or just desynchronized to death
MES.new('warn',"#"..P.uid.." desynchronized") MES.new('warn',"#"..P.uid.." desynchronized")
NET.player_finish({foo=""}) NET.player_finish({reason='desync'})
P:lose(true) P:lose(true)
return return
end end
@@ -2691,8 +2691,15 @@ function Player:update(dt)
end end
while self.trigFrame>=1 do while self.trigFrame>=1 do
if self.streamProgress then if self.streamProgress then
local frameDelta local frameDelta-- Time between now and end of stream
if self.type=='remote' then if self.type=='remote' then
if self.loseTimer then
self.loseTimer=self.loseTimer-1
if self.loseTimer==0 then
self.loseTimer=false
self:lose(true)
end
end
frameDelta=(self.stream[#self.stream-1] or 0)-self.frameRun frameDelta=(self.stream[#self.stream-1] or 0)-self.frameRun
if frameDelta==0 then frameDelta=nil end if frameDelta==0 then frameDelta=nil end
else else
@@ -2700,6 +2707,7 @@ function Player:update(dt)
end end
if frameDelta then if frameDelta then
for _=1, for _=1,
self.loseTimer and 6 or
frameDelta<26 and 1 or frameDelta<26 and 1 or
frameDelta<50 and 2 or frameDelta<50 and 2 or
frameDelta<80 and 3 or frameDelta<80 and 3 or
@@ -2797,8 +2805,10 @@ function Player:lose(force)
self:revive() self:revive()
return return
elseif self.type=='remote' then elseif self.type=='remote' then
self.waiting=1e99 if not self.loseTimer then
return self.waiting=1e99
return
end
end end
end end
self:_die() self:_die()
@@ -2852,7 +2862,7 @@ function Player:lose(force)
gameOver() gameOver()
self:newTask(#PLAYERS>1 and task_lose or task_finish) self:newTask(#PLAYERS>1 and task_lose or task_finish)
if GAME.net and not NET.spectate then if GAME.net and not NET.spectate then
NET.player_finish({foo=""}) NET.player_finish({reason="lose"})
else else
TASK.new(task_autoPause) TASK.new(task_autoPause)
end end

View File

@@ -214,6 +214,7 @@ function scene.update(dt)
for i=1,#NETPLY.list do for i=1,#NETPLY.list do
NETPLY.list[i].readyMode='Standby' NETPLY.list[i].readyMode='Standby'
end end
NETPLY.freshPos()
NET.freshRoomAllReady() NET.freshRoomAllReady()
return return
else else