完善玩家刷新机制 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={
--Tuning
'das','arr','dascut','dropcut','sddas','sdarr',
'ihs','irs','ims','RS','swap',
'ihs','irs','ims','RS','swap','FTLock',
--System
'skin','face',
@@ -557,7 +557,7 @@ do--function resetGameData(args)
if args:find'r'then
GAME.frameStart=0
GAME.recording=false
GAME.replaying=1
GAME.replaying=true
else
GAME.frameStart=args:find'n'and 0 or 150-SETTING.reTime*15
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.endCounter=0--Used after gameover
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
P.seqRND=love.math.newRandomGenerator(GAME.seed)
@@ -457,9 +459,7 @@ function PLY.newRemotePlayer(id,mini,ply)
P.type='remote'
P.draw=ply_draw.norm
P.stream={}
P.streamProgress=1
P:startStreaming()
netPLY.setPlayerObj(ply,P)
P.uid=ply.uid

View File

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

View File

@@ -275,23 +275,6 @@ function scene.gamepadUp(key)
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)
--Update control
touchMoveLastFrame=false
@@ -312,9 +295,6 @@ function scene.update(dt)
trigGameRate=trigGameRate+gameRate
while trigGameRate>=1 do
trigGameRate=trigGameRate-1
if GAME.replaying then
_update_replay(GAME.replaying)
end
_update_common(dt)
end
end

View File

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