实现开始游戏信号与切换进游戏状态创建玩家
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user