完善玩家刷新机制 close #335

This commit is contained in:
MrZ626
2021-09-28 01:55:57 +08:00
parent 438fef9f26
commit 4bf7ef0e25
5 changed files with 91 additions and 97 deletions

View File

@@ -525,7 +525,7 @@ do--function resetGameData(args)
local gameSetting={ local gameSetting={
--Tuning --Tuning
'das','arr','dascut','dropcut','sddas','sdarr', 'das','arr','dascut','dropcut','sddas','sdarr',
'ihs','irs','ims','RS','swap', 'ihs','irs','ims','RS','swap','FTLock',
--System --System
'skin','face', 'skin','face',
@@ -557,7 +557,7 @@ do--function resetGameData(args)
if args:find'r'then if args:find'r'then
GAME.frameStart=0 GAME.frameStart=0
GAME.recording=false GAME.recording=false
GAME.replaying=1 GAME.replaying=true
else else
GAME.frameStart=args:find'n'and 0 or 150-SETTING.reTime*15 GAME.frameStart=args:find'n'and 0 or 150-SETTING.reTime*15
GAME.seed=seed or math.random(1046101471,2662622626) GAME.seed=seed or math.random(1046101471,2662622626)

View File

@@ -146,6 +146,8 @@ local function _newEmptyPlayer(id,mini)
P.frameRun=GAME.frameStart--Frame run, mainly for replay P.frameRun=GAME.frameStart--Frame run, mainly for replay
P.endCounter=0--Used after gameover P.endCounter=0--Used after gameover
P.dropTime={}for i=1,10 do P.dropTime[i]=-1e99 end P.dropSpeed=0 P.dropTime={}for i=1,10 do P.dropTime[i]=-1e99 end P.dropSpeed=0
P.stream={}
P.streamProgress=false--1 to start play recording
--Randomizers --Randomizers
P.seqRND=love.math.newRandomGenerator(GAME.seed) P.seqRND=love.math.newRandomGenerator(GAME.seed)
@@ -457,9 +459,7 @@ function PLY.newRemotePlayer(id,mini,ply)
P.type='remote' P.type='remote'
P.draw=ply_draw.norm P.draw=ply_draw.norm
P:startStreaming()
P.stream={}
P.streamProgress=1
netPLY.setPlayerObj(ply,P) netPLY.setPlayerObj(ply,P)
P.uid=ply.uid P.uid=ply.uid

View File

@@ -193,6 +193,11 @@ function Player:newTask(code,...)
end end
end end
function Player:startStreaming(streamData)
self.stream=streamData
self.streamProgress=1
end
function Player:setPosition(x,y,size) function Player:setPosition(x,y,size)
size=size or 1 size=size or 1
self.x,self.y,self.size=x,y,size self.x,self.y,self.size=x,y,size
@@ -1903,6 +1908,8 @@ local function update_alive(P)
return true return true
end end
if P.timing then P.stat.frame=P.stat.frame+1 end
--Calculate key speed --Calculate key speed
do do
local v=0 local v=0
@@ -2102,62 +2109,54 @@ local function update_alive(P)
end end
_updateMisc(P) _updateMisc(P)
-- P:setPosition(640-150-(30*(P.curX+P.cur.sc[2])-15),30*(P.curY+P.cur.sc[1])+15-300+(ENV.smooth and P.ghoY~=P.curY and(P.dropDelay/ENV.drop-1)*30 or 0)) --[[
P:setPosition(
640-150-(30*(P.curX+P.cur.sc[2])-15),
30*(P.curY+P.cur.sc[1])+15-300+(
ENV.smooth and P.ghoY~=P.curY and
(P.dropDelay/ENV.drop-1)*30
or 0
)
)
]]
end end
local function update_remote_alive(P) local function update_streaming(P)
local frameRate=(P.stream[#P.stream-1]or 0)-P.frameRun local eventTime=P.stream[P.streamProgress]
frameRate= while eventTime and P.frameRun==eventTime do
frameRate<26 and 1 or local event=P.stream[P.streamProgress+1]
frameRate<50 and 2 or if event==0 then--Just wait
frameRate<80 and 3 or elseif event<=32 then--Press key
frameRate<120 and 5 or P:pressKey(event)
frameRate<160 and 7 or elseif event<=64 then--Release key
frameRate<200 and 10 or P:releaseKey(event-32)
20 elseif event>0x2000000000000 then--Sending lines
for _=1,frameRate do local sid=event%0x100
local eventTime=P.stream[P.streamProgress] local amount=int(event/0x100)%0x100
if eventTime then--Normal state, event forward local time=int(event/0x10000)%0x10000
if P.frameRun==eventTime then--Event time, execute action, read next so don't update immediately local line=int(event/0x100000000)%0x10000
local event=P.stream[P.streamProgress+1] for _,p in next,PLY_ALIVE do
if event==0 then--Just wait if p.sid==sid then
elseif event<=32 then--Press key P:attack(p,amount,time,line,true)
P:pressKey(event) P:createBeam(p,amount)
elseif event<=64 then--Release key break
P:releaseKey(event-32) end
elseif event>0x2000000000000 then--Sending lines end
local sid=event%0x100 elseif event>0x1000000000000 then--Receiving lines
local amount=int(event/0x100)%0x100 local sid=event%0x100
local time=int(event/0x10000)%0x10000 for _,p in next,PLY_ALIVE do
local line=int(event/0x100000000)%0x10000 if p.sid==sid then
for _,p in next,PLY_ALIVE do P:receive(
if p.sid==sid then p,
P:attack(p,amount,time,line,true) int(event/0x100)%0x100,--amount
P:createBeam(p,amount) int(event/0x10000)%0x10000,--time
break int(event/0x100000000)%0x10000--line
end )
end break
elseif event>0x1000000000000 then--Receiving lines
local sid=event%0x100
for _,p in next,PLY_ALIVE do
if p.sid==sid then
P:receive(
p,
int(event/0x100)%0x100,--amount
int(event/0x10000)%0x10000,--time
int(event/0x100000000)%0x10000--line
)
break
end
end
end end
P.streamProgress=P.streamProgress+2
else--No event now, run one frame
update_alive(P,1/60)
P.stat.time=P.frameRun/60
end end
else--Pause state, no actions, quit loop
break
end end
P.streamProgress=P.streamProgress+2
eventTime=P.stream[P.streamProgress]
end end
end end
local function update_dead(P) local function update_dead(P)
@@ -2210,28 +2209,42 @@ function Player:_die()
end end
end end
function Player:update(dt) function Player:update(dt)
if self.type=='remote'and self.alive then self.trigFrame=self.trigFrame+(self.gameEnv.FTLock and dt*60 or 1)
update_remote_alive(self,dt) if self.alive then
else local S=self.stat
self.trigFrame=self.trigFrame+(self.gameEnv.FTLock and dt*60 or 1) if self.timing then S.time=S.time+dt end
if self.alive then if self.type=='computer'then
if self.timing then self.bot:update(dt)
local S=self.stat end
S.frame=S.frame+1 while self.trigFrame>=1 do
S.time=S.time+dt if self.alive then
end if self.streamProgress then
while self.trigFrame>=1 do S.time=self.frameRun/60
update_alive(self) local frameDelta=self.type=='remote'and (self.stream[#self.stream-1]or 0)-self.frameRun or 0
self.trigFrame=self.trigFrame-1 for _=1,
end frameDelta<26 and 1 or
if self.type=='computer'then frameDelta<50 and 2 or
self.bot:update(dt) frameDelta<80 and 3 or
end frameDelta<120 and 5 or
else frameDelta<160 and 7 or
while self.trigFrame>=1 do frameDelta<200 and 10 or
20
do
update_streaming(self)
update_alive(self)
end
else
update_alive(self)
end
else
update_dead(self) update_dead(self)
self.trigFrame=self.trigFrame-1
end end
self.trigFrame=self.trigFrame-1
end
else
while self.trigFrame>=1 do
update_dead(self)
self.trigFrame=self.trigFrame-1
end end
end end
_updateFX(self,dt) _updateFX(self,dt)

View File

@@ -275,23 +275,6 @@ function scene.gamepadUp(key)
end end
end end
local function _update_replay(repPtr)
local P1=PLAYERS[1]
local L=GAME.rep
while P1.frameRun==L[repPtr]do
local key=L[repPtr+1]
if key==0 then--Just wait
elseif key<=32 then--Press key
P1:pressKey(key)
VK.press(key)
elseif key<=64 then--Release key
P1:releaseKey(key-32)
VK.release(key-32)
end
repPtr=repPtr+2
end
GAME.replaying=repPtr
end
local function _update_common(dt) local function _update_common(dt)
--Update control --Update control
touchMoveLastFrame=false touchMoveLastFrame=false
@@ -312,9 +295,6 @@ function scene.update(dt)
trigGameRate=trigGameRate+gameRate trigGameRate=trigGameRate+gameRate
while trigGameRate>=1 do while trigGameRate>=1 do
trigGameRate=trigGameRate-1 trigGameRate=trigGameRate-1
if GAME.replaying then
_update_replay(GAME.replaying)
end
_update_common(dt) _update_common(dt)
end end
end end

View File

@@ -60,6 +60,7 @@ local function _playRep(fileName)
loadGame(rep.mode,true) loadGame(rep.mode,true)
resetGameData('r') resetGameData('r')
PLAYERS[1].username=rep.player PLAYERS[1].username=rep.player
PLAYERS[1]:startStreaming(GAME.rep)
GAME.init=false GAME.init=false
GAME.saved=true GAME.saved=true
GAME.fromRepMenu=true GAME.fromRepMenu=true