public void LogicTick() { int nextIndex = (mCurrentIndex + 1) % MAX_CMD_LEN; if (nextIndex == mHeadIndex) { return; } ReqPlayerMove moveData = mMoveDatas[mCurrentIndex]; if (moveData == null) { Debug.LogError("同步队列出错"); mCurrentIndex = nextIndex; return; } float time = Time.realtimeSinceStartup - GameController.mClientStartTime; float span = time - mLastTimeStamp; if (span >= moveData.timespan) { mCha.MoveSpeed = moveData.speed; mCha.Direction = moveData.direction.ToVector3(); mCha.Position = moveData.position.ToVector3(); if (mCha.Type == CharacterType.Player) { Player player = mCha as Player; player.IsControl = moveData.control; } mMoveDatas[mCurrentIndex] = null; mCurrentIndex = nextIndex; mLastTimeStamp = moveData.timestamp; } }
void OnPlayerMove(byte[] data, Action5001 action) { ReqPlayerMove req = ProtoBufUtils.Deserialize <ReqPlayerMove>(data); Player player = FindPlayer(req.gid); if (player == null) { return; } NotifyPlayerMove msg = new NotifyPlayerMove(); msg.uid = req.gid; msg.moveData = req; for (int i = 0; i < player.mScene.GetPlayerCount(); ++i) { Player p = player.mScene.GetPlayerByIndex(i); if (p == player) { p.Speed = req.speed; p.Direction = req.direction.ToVector3(); p.Position = req.position.ToVector3(); p.IsControl = req.control; continue; } NetWork.NotifyMessage <NotifyPlayerMove>(p.UserID, STC.STC_PlayerMove, msg); } }
public void AddMoveData(ReqPlayerMove moveData) { if (mHeadIndex == mCurrentIndex) { Debug.LogError("超出最大可接受移动数据"); return; } mMoveDatas[mHeadIndex - 1] = moveData; mHeadIndex = (mHeadIndex) % MAX_CMD_LEN + 1; }
public void LogicTick() { UpdateDirty(); if (mDirty) { float time = Time.realtimeSinceStartup - GameController.mClientStartTime; ReqPlayerMove req = new ReqPlayerMove(); req.gid = mMainPlayer.gid; req.speed = mMainPlayer.MoveSpeed; req.direction = Vector3Packat.FromVector3(mMainPlayer.Direction); req.position = Vector3Packat.FromVector3(mMainPlayer.Position); req.control = mMainPlayer.IsControl; req.timestamp = time; req.timespan = time - mLastTimeStamp; NetWork.SendPacket <ReqPlayerMove>(CTS.CTS_PlayerMove, req, null); mLastTimeStamp = time; ClearDirty(); } }