实现开始游戏信号与切换进游戏状态创建玩家
This commit is contained in:
@@ -18,11 +18,11 @@ return{
|
|||||||
GAME.modeEnv.allowMod=false
|
GAME.modeEnv.allowMod=false
|
||||||
GAME.modeEnv.task=marginTask
|
GAME.modeEnv.task=marginTask
|
||||||
|
|
||||||
local L=TABLE.copy(NETPLY.list)
|
local L=TABLE.shift(NETPLY.list,0)
|
||||||
local N=1
|
local N=1
|
||||||
for i,p in next,L do
|
for i,p in next,L do
|
||||||
if p.uid==USER.uid then
|
if p.uid==USER.uid then
|
||||||
if p.connected then
|
if p.playMode=='Gamer' then
|
||||||
PLY.newPlayer(1)
|
PLY.newPlayer(1)
|
||||||
N=2
|
N=2
|
||||||
end
|
end
|
||||||
@@ -31,7 +31,7 @@ return{
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
for _,p in next,L do
|
for _,p in next,L do
|
||||||
if p.connected then
|
if p.playMode=='Gamer' then
|
||||||
PLY.newRemotePlayer(N,false,p)
|
PLY.newRemotePlayer(N,false,p)
|
||||||
N=N+1
|
N=N+1
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -393,7 +393,7 @@ local actMap={
|
|||||||
|
|
||||||
local function wsSend(act,data)
|
local function wsSend(act,data)
|
||||||
-- print(("Send: $1 -->"):repD(act))
|
-- 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{
|
WS.send('game',JSON.encode{
|
||||||
action=assert(act),
|
action=assert(act),
|
||||||
data=data,
|
data=data,
|
||||||
@@ -512,7 +512,7 @@ function NET.player_setHost(pid)
|
|||||||
role='Admin',
|
role='Admin',
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
function NET.player_setState(state)-- what state?
|
function NET.player_setState(state)-- not used
|
||||||
wsSend(actMap.player_setState,state)
|
wsSend(actMap.player_setState,state)
|
||||||
end
|
end
|
||||||
function NET.player_stream(stream)
|
function NET.player_stream(stream)
|
||||||
@@ -522,9 +522,7 @@ function NET.player_setPlayMode(mode)
|
|||||||
wsSend(actMap.player_setPlayMode,mode)
|
wsSend(actMap.player_setPlayMode,mode)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Match
|
|
||||||
function NET.match_techminohaowan(arg)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- WS
|
-- WS
|
||||||
NET.wsCallBack={}
|
NET.wsCallBack={}
|
||||||
@@ -611,7 +609,7 @@ function NET.wsCallBack.player_joinGroup(body)-- TODO
|
|||||||
end
|
end
|
||||||
function NET.wsCallBack.player_setHost(body)-- TODO
|
function NET.wsCallBack.player_setHost(body)-- TODO
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_setState(body)-- TODO
|
function NET.wsCallBack.player_setState(body)-- TODO (not used)
|
||||||
end
|
end
|
||||||
function NET.wsCallBack.player_stream(body)-- TODO
|
function NET.wsCallBack.player_stream(body)-- TODO
|
||||||
end
|
end
|
||||||
@@ -621,6 +619,14 @@ end
|
|||||||
function NET.wsCallBack.player_setReadyMode(body)
|
function NET.wsCallBack.player_setReadyMode(body)
|
||||||
NETPLY.setReadyMode(body.data.playerId,body.data.type)
|
NETPLY.setReadyMode(body.data.playerId,body.data.type)
|
||||||
end
|
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()
|
function NET.ws_connect()
|
||||||
if WS.status('game')=='dead' then
|
if WS.status('game')=='dead' then
|
||||||
@@ -688,7 +694,7 @@ function NET.ws_update()
|
|||||||
elseif msg then
|
elseif msg then
|
||||||
msg=JSON.decode(msg)
|
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(("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
|
if msg.errno~=0 then
|
||||||
parseError(msg.message~=nil and msg.message or msg)
|
parseError(msg.message~=nil and msg.message or msg)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ function scene.sceneInit()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function scene.sceneBack()
|
function scene.sceneBack()
|
||||||
GAME.playing=false
|
TASK.unlock('netPlaying')
|
||||||
end
|
end
|
||||||
|
|
||||||
scene.mouseDown=NULL
|
scene.mouseDown=NULL
|
||||||
@@ -193,70 +193,57 @@ function scene.gamepadUp(key)
|
|||||||
end
|
end
|
||||||
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)
|
function scene.update(dt)
|
||||||
if WS.status('game')~='running' then
|
if WS.status('game')~='running' then
|
||||||
|
TASK.unlock('netPlaying')
|
||||||
NET.ws_close()
|
NET.ws_close()
|
||||||
SCN.back()
|
SCN.back()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if playing then
|
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
|
touchMoveLastFrame=false
|
||||||
VK.update(dt)
|
VK.update(dt)
|
||||||
|
|
||||||
-- Update players
|
-- Update players
|
||||||
for p=1,#PLAYERS do PLAYERS[p]:update(dt) end
|
for p=1,#PLAYERS do PLAYERS[p]:update(dt) end
|
||||||
|
|
||||||
-- Warning check
|
-- Warning check
|
||||||
checkWarning(dt)
|
checkWarning(dt)
|
||||||
|
|
||||||
-- Upload stream
|
-- Upload stream
|
||||||
if not NET.spectate and P1.frameRun-lastUpstreamTime>8 then
|
if not NET.spectate and P1.frameRun-lastUpstreamTime>8 then
|
||||||
local stream
|
local stream
|
||||||
if not GAME.rep[upstreamProgress] then
|
if not GAME.rep[upstreamProgress] then
|
||||||
ins(GAME.rep,P1.frameRun)
|
ins(GAME.rep,P1.frameRun)
|
||||||
ins(GAME.rep,0)
|
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
|
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
|
end
|
||||||
else
|
else
|
||||||
NETPLY.update(dt)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user