示例#1
0
    protected override void SendMoveInfo(MoveInfo moveInfo)
    {
        bool isNeedSync = false;

        if (isEnableStateCheck)
        {
            if (!lastMoveInfo.dir.Equals(moveInfo.dir) || lastMoveInfo.speed != moveInfo.speed)
            {
                isNeedSync = true;
            }
        }

        // Dead Reckoning
        // state check have a higher priority
        if (!isNeedSync && isEnableDeadReckoning)
        {
            Vector2 predictedPos = lastSyncedMoveInfo.position;
            predictedPos += (lastSyncedMoveInfo.dir * lastSyncedMoveInfo.speed * (Time.time - lastSyncedMoveInfo.sendTime));
            float offset = Vector2.Distance(predictedPos, moveInfo.position);
            //Debug.Log("offset between real and predicted = " + offset.ToString());
            if (offset > drThreshold)
            {
                isNeedSync = true;
            }
        }

        moveInfo.sendTime = Time.time;
        lastMoveInfo      = moveInfo.Clone() as MoveInfo;
        if (isNeedSync)
        {
            lastSyncedMoveInfo = moveInfo.Clone() as MoveInfo;
            netSimulator.Send(moveInfo.Clone() as MoveInfo);
            AddNetflowCounter();
        }
    }
示例#2
0
 protected override void SendMoveInfo(MoveInfo moveInfo)
 {
     lastMoveInfo       = moveInfo.Clone() as MoveInfo;
     lastSyncedMoveInfo = moveInfo.Clone() as MoveInfo;
     netSimulator.Send(moveInfo.Clone() as MoveInfo);
     AddNetflowCounter();
 }
        internal async Task SendMoveToServer(MoveInfo currentMoveInfo)
        {
            if (!currentMoveInfo.Finished && currentMoveInfo.MeepleId >= 0)
            {
                throw new Exception("If a meeple is set a move should be finished!");
            }
            try
            {
                var callInfo = _urlHelper.GetMoveUrl(_baseUrl);
                if (callInfo.CallBySignalR)
                {
                    await _hubConnection.SendAsync("move", currentMoveInfo);
                }
                else
                {
                    var content    = new StringContent(JsonConvert.SerializeObject(currentMoveInfo), Encoding.UTF8, "application/json");
                    var resultJoin = await _client.PostAsync(callInfo.Url, content);

                    resultJoin.EnsureSuccessStatusCode();
                }
                _ownMoves.Add(currentMoveInfo.Clone());
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to perform move on server: " + ex.Message, ex);
            }
        }
示例#4
0
    protected override void SendMoveInfo(MoveInfo moveInfo)
    {
        bool isNeedSync = false;

        if (!lastMoveInfo.dir.Equals(moveInfo.dir) || lastMoveInfo.speed != moveInfo.speed)
        {
            isNeedSync = true;
        }

        if (isNeedSync)
        {
            lastMoveInfo = moveInfo.Clone() as MoveInfo;
            netSimulator.Send(moveInfo.Clone() as MoveInfo);
            AddNetflowCounter();
        }
    }
示例#5
0
    protected override void SendMoveInfo(MoveInfo moveInfo)
    {
        if (sendCurFrame <= svrKeyframe + syncInterval)
        {
            if (isStopClient)
            {
                sendInfoList.Add(null);
            }
            else
            {
                bool isNeedSync = false;
                if (!lastMoveInfo.dir.Equals(moveInfo.dir) || lastMoveInfo.speed != moveInfo.speed)
                {
                    isNeedSync = true;
                }

                if (isNeedSync)
                {
                    lastMoveInfo = moveInfo.Clone( ) as MoveInfo;
                    sendInfoList.Add(lastMoveInfo);
                }
                else
                {
                    sendInfoList.Add(null);
                }
            }


            // 在关键帧进行同步
            if (sendCurFrame == svrKeyframe + syncInterval)
            {
                List <MoveInfo> tmpInfoList = new List <MoveInfo>(sendInfoList.ToArray());
                SyncData        syncData    = new SyncData();
                syncData.keyframe = svrKeyframe + syncInterval;
                syncData.infoList = tmpInfoList;
                netSimulatorEx.Send(syncData);
                AddNetflowCounter(syncData);
                sendInfoList.Clear( );
            }

            sendCurFrame += 1;
        }
        else
        {
            // block game wait for other players
        }
    }
示例#6
0
    void UpdateCurMoveInfo()
    {
        curMoveInfo.Reset();
        if (isAutoMove)
        {
            if (!isStopClient)
            {
                autoChangeTimer += Time.deltaTime;
                if (autoChangeTimer > autoChangeDirInterval)
                {
                    autoChangeTimer -= autoChangeDirInterval;
                    int x = 0;
                    int y = 0;
                    if (isFirstAutoMove)
                    {
                        isFirstAutoMove = false;
                        x = 1;
                        y = 1;
                    }
                    else
                    {
                        x = autoDirRandom.Next(-1, 2);
                        y = autoDirRandom.Next(-1, 2);
                    }
                    curMoveInfo.dir.x = x;
                    curMoveInfo.dir.y = y;
                    curMoveInfo.speed = moveSpeed;
                    //Debug.Log("- dir = "+curMoveInfo.dir.ToString());
                }
                else
                {
                    curMoveInfo = lastMoveInfo.Clone() as MoveInfo;
                }
            }
            else
            {
                curMoveInfo       = lastMoveInfo.Clone() as MoveInfo;
                curMoveInfo.speed = 0;
            }
        }
        else
        {
            if (Input.GetKey(KeyCode.A))
            {
                curMoveInfo.dir.x = -1;
            }
            if (Input.GetKey(KeyCode.D))
            {
                curMoveInfo.dir.x = 1;
            }
            if (Input.GetKey(KeyCode.W))
            {
                curMoveInfo.dir.y = 1;
            }
            if (Input.GetKey(KeyCode.S))
            {
                curMoveInfo.dir.y = -1;
            }

            if (curMoveInfo.dir != Vector2.zero)
            {
                curMoveInfo.speed = moveSpeed;
            }
        }

        if (curMoveInfo.dir != Vector2.zero)
        {
            curMoveInfo.dir.Normalize();
        }
        else
        {
            curMoveInfo.dir = lastMoveInfo.dir;
        }
    }