private void LogClientInfo(NetworkSnapshotAckComponent ack)
 {
     Debug.Log("");
     Debug.Log("============== LogClientInfo =================");
     Debug.Log($"Local:{ack.LastReceivedSnapshotByLocal}");
     Log(ack.ReceivedSnapshotByLocalMask);
     Debug.Log("===============================================");
 }
 private void LogServerInfo(NetworkSnapshotAckComponent ack)
 {
     Debug.Log("");
     Debug.Log("============== LogServerInfo =================");
     Debug.Log($"Remote:{ack.LastReceivedSnapshotByRemote}");
     Debug.Log($"Mask3 - {ToString(ack.ReceivedSnapshotByRemoteMask3)}");
     Debug.Log($"Mask2 - {ToString(ack.ReceivedSnapshotByRemoteMask2)}");
     Debug.Log($"Mask1 - {ToString(ack.ReceivedSnapshotByRemoteMask1)}");
     Debug.Log($"Mask0 - {ToString(ack.ReceivedSnapshotByRemoteMask0)}");
     Debug.Log("===============================================");
 }
        public void TestSnapshotMask1()
        {
            NetworkSnapshotAckComponent clientAck = new NetworkSnapshotAckComponent();
            NetworkSnapshotAckComponent serverAck = new NetworkSnapshotAckComponent();

            for (uint i = 1; i <= 130; i++)
            {
                if (i % 2 == 0)
                {
                    // 1.客户端收到服务端快照 tick = 2
                    // 由于第一次收到,mask = mask | 1;
                    clientAck.UpdateLocalValues(i);

                    // 2.回给服务端
                    serverAck.UpdateReceiveByRemote(clientAck.LastReceivedSnapshotByLocal,
                                                    clientAck.ReceivedSnapshotByLocalMask);
                }
            }

            LogClientInfo(clientAck);
            LogServerInfo(serverAck);
        }
        public void TestSnapshotMask()
        {
            NetworkSnapshotAckComponent clientAck = new NetworkSnapshotAckComponent();
            NetworkSnapshotAckComponent serverAck = new NetworkSnapshotAckComponent();

            // 1.客户端收到服务端快照 tick = 2
            // 由于第一次收到,mask = mask | 1;
            clientAck.UpdateLocalValues(2U);
            LogClientInfo(clientAck);
            Assert.AreEqual(clientAck.LastReceivedSnapshotByLocal, 2);

            // 2.回给服务端
            serverAck.UpdateReceiveByRemote(clientAck.LastReceivedSnapshotByLocal,
                                            clientAck.ReceivedSnapshotByLocalMask);
            LogServerInfo(serverAck);
            Assert.AreEqual(serverAck.LastReceivedSnapshotByRemote, 2);
            Assert.AreEqual(serverAck.ReceivedSnapshotByRemoteMask0, 1);

            // 3.客户端第二次收到快照 tick = 4
            clientAck.UpdateLocalValues(4U);
            LogClientInfo(clientAck);
            Assert.AreEqual(clientAck.LastReceivedSnapshotByLocal, 4);
        }
Example #5
0
        protected override void OnUpdate()
        {
            NetworkSnapshotAckComponent ack = GetSingleton <NetworkSnapshotAckComponent>();

            if (World.GetExistingSystem <GhostPredictionSystemGroup>().LastAppliedSnapshotTick <
                ack.LastReceivedSnapshotByLocal)
            {
                Entities.With(_ownerPredicationQuery).ForEach(
                    (Entity ent, ref Translation pos, ref Rotation rot, ref NetworkRigidbody r) =>
                {
                    if (!_storeSystem.TryGetValue(ent, out var go))
                    {
                        return;
                    }

                    Rigidbody rigid       = go.GetComponent <Rigidbody>();
                    rigid.position        = pos.Value;
                    rigid.rotation        = rot.Value;
                    rigid.velocity        = r.velocity;
                    rigid.angularVelocity = r.angularVelocity;
                    // Debug.Log($"回滚前的设置值.");
                });
            }
        }
Example #6
0
        protected override void OnUpdate()
        {
            NetworkSnapshotAckComponent ack = GetSingleton <NetworkSnapshotAckComponent>();

            if (World.GetExistingSystem <GhostPredictionSystemGroup>().LastAppliedSnapshotTick >=
                ack.LastReceivedSnapshotByLocal)
            {
                return;
            }

            Entities.With(_ownerPredicationQuery).ForEach(
                (Entity ent, ref NetworkCharacterComponent state) =>
            {
                if (!_storeSystem.TryGetValue(ent, out var trans))
                {
                    return;
                }

                var movement = trans.GetComponent <MovementController>();
                movement.ApplyState(ref state);
            });

            Entities.With(_grenadeQuery).ForEach(
                (Entity ent, ref Translation pos, ref Rotation rot, ref NetworkRigidbody rig) =>
            {
                if (!_storeSystem.TryGetValue(ent, out var trans))
                {
                    return;
                }

                var r             = trans.GetComponent <Rigidbody>();
                r.position        = pos.Value;
                r.rotation        = rot.Value;
                r.velocity        = rig.velocity;
                r.angularVelocity = rig.angularVelocity;

                // Debug.Log($"[C] {ack.LastReceivedSnapshotByLocal} Restore: {pos.Value} {rig.velocity}");
            });

            Entities.With(_ballQuery).ForEach(
                (Entity ent, ref Translation pos, ref Rotation rot, ref NetworkRigidbody rig) =>
            {
                if (!_storeSystem.TryGetValue(ent, out var trans))
                {
                    return;
                }

                var r             = trans.GetComponent <Rigidbody>();
                r.position        = pos.Value;
                r.rotation        = rot.Value;
                r.velocity        = rig.velocity;
                r.angularVelocity = rig.angularVelocity;
            });

            Entities.With(_d1Query).ForEach(
                (Entity ent, ref Translation pos, ref Rotation rot) =>
            {
                if (!_storeSystem.TryGetValue(ent, out var trans))
                {
                    return;
                }

                var r      = trans.GetComponent <Transform>();
                r.position = pos.Value;
                r.rotation = rot.Value;
            });
        }