示例#1
0
        public void Update(MyTimeSpan clientTimestamp, MySnapshotSyncSetup setup)
        {
            // skip entities with parent
            if (m_entity.Parent != null)
            {
                return;
            }
            if (m_entity.Physics == null) //trees
            {
                return;
            }
            if (m_entity.Physics.RigidBody != null && !m_entity.Physics.RigidBody.IsActive)
            {
                return;
            }

            VRage.Profiler.ProfilerShort.Begin("Sync Predicted" + m_entity.DisplayName);
            UpdatePrediction(clientTimestamp, setup);
            VRage.Profiler.ProfilerShort.End();
        }
        void IMySnapshotSync.Update(MyTimeSpan clientTimestamp, MySnapshotSyncSetup setup)
        {
            VRage.Profiler.NetProfiler.Begin("PhHistory:Update: " + m_entity.DisplayName);
            VRage.Profiler.ProfilerShort.Begin("MyPhysicsHistory.Update");
            // synchronization of timestamps from server and on client is missing (history won't work correctly now)
            var item = m_history.Get(clientTimestamp, MySnapshotHistory.DELAY);

            m_history.PruneTooOld(clientTimestamp);
            VRage.Profiler.ProfilerShort.End();

            if (item.Valid)
            {
                var targetSnapshot = item.Snapshot;

                float difpos = (float)Vector3D.Distance(m_entity.PositionComp.GetPosition(), targetSnapshot.Position);
                VRage.Profiler.NetProfiler.Begin("Diff position", 0);
                VRage.Profiler.NetProfiler.End(difpos, 0, "m", "{0} m");

                targetSnapshot.Apply(m_entity, setup.ApplyRotation, setup.ApplyPhysics);
            }

            VRage.Profiler.NetProfiler.End();
        }
示例#3
0
        public void UpdatePrediction(MyTimeSpan clientTimestamp, MySnapshotSyncSetup setup)
        {
            var currentSnapshot = new MySnapshot(m_entity);
            var tmpSnapshot     = currentSnapshot;

            m_clientHistory.Add(currentSnapshot, clientTimestamp);

            var  serverTmpSnapshot = m_receivedQueue.GetItem(clientTimestamp);
            var  timeDelta         = (float)(m_lastServerTimestamp - serverTmpSnapshot.Timestamp).Seconds;
            var  predictedSetup    = setup as MyPredictedSnapshotSyncSetup;
            var  serverDeltaItem   = UpdateFromServerQueue(clientTimestamp, predictedSetup);
            bool animated          = m_animDeltaPositionIterations > 0 || m_animDeltaLinearVelocityIterations > 0 || m_animDeltaRotationIterations > 0 ||
                                     m_animDeltaAngularVelocityIterations > 0;
            bool applySnapshot = false;

            if (serverDeltaItem.Valid)
            {
                currentSnapshot.Add(serverDeltaItem.Snapshot);
                m_clientHistory.ApplyDelta(serverDeltaItem.Timestamp, serverDeltaItem.Snapshot);
                applySnapshot = true;
            }

            if (animated)
            {
                if (m_animDeltaPositionIterations > 0)
                {
                    m_clientHistory.ApplyDeltaPosition(m_animDeltaPositionTimestamp, m_animDeltaPosition);
                    currentSnapshot.Position += m_animDeltaPosition;
                    m_animDeltaPositionIterations--;
                }
                if (m_animDeltaLinearVelocityIterations > 0)
                {
                    m_clientHistory.ApplyDeltaLinearVelocity(m_animDeltaLinearVelocityTimestamp, m_animDeltaLinearVelocity);
                    currentSnapshot.LinearVelocity += m_animDeltaLinearVelocity;
                    m_animDeltaLinearVelocityIterations--;
                }
                if (m_animDeltaAngularVelocityIterations > 0)
                {
                    m_clientHistory.ApplyDeltaAngularVelocity(m_animDeltaAngularVelocityTimestamp, m_animDeltaAngularVelocity);
                    currentSnapshot.AngularVelocity += m_animDeltaAngularVelocity;
                    m_animDeltaAngularVelocityIterations--;
                }
                if (m_animDeltaRotationIterations > 0)
                {
                    m_clientHistory.ApplyDeltaRotation(m_animDeltaRotationTimestamp, m_animDeltaRotation);
                    currentSnapshot.Rotation = currentSnapshot.Rotation * Quaternion.Inverse(m_animDeltaRotation);
                    currentSnapshot.Rotation.Normalize();
                    m_animDeltaRotationIterations--;
                }

                applySnapshot = true;
            }
            if (applySnapshot)
            {
                currentSnapshot.Apply(m_entity, setup.ApplyRotation, setup.ApplyPhysics, serverDeltaItem.Type == MySnapshotHistory.SnapshotType.Reset);
            }

            //if (MyCompilationSymbols.EnableNetworkClientUpdateTracking)
            {
                if (m_entity.DisplayName.Contains("dicykal") && (serverDeltaItem.Valid || animated))
                {
                    var velocity = (serverTmpSnapshot.Snapshot.Position - m_lastServerSnapshot.Position) / timeDelta;
                    m_lastServerSnapshot = serverTmpSnapshot.Snapshot;

                    var clientTimeDelta = (float)(m_lastClientTimestamp - clientTimestamp).Seconds;
                    var clientVelocity  = (currentSnapshot.Position - m_lastClientSnapshot.Position) / clientTimeDelta;
                    m_lastClientSnapshot  = currentSnapshot;
                    m_lastClientTimestamp = clientTimestamp;

                    VRage.Trace.MyTrace.Send(VRage.Trace.TraceWindow.MPositions3, m_entity.DisplayName + ": " +
                                             tmpSnapshot + " / " + currentSnapshot + " / " + serverTmpSnapshot.Snapshot + "; cvel " + velocity + " / " + clientVelocity + "; " +
                                             serverDeltaItem.Valid + ", " + animated + "; " + m_animDeltaPosition * 60);

                    /*var delta = tmpSnapshot.Diff(currentSnapshot);
                     * var posLen = delta.Position.Length();
                     * var lenLV = delta.LinearVelocity.Length();
                     * var sdPosLen = serverDeltaItem.Snapshot.Position.Length();
                     * var aPosLen = m_animDeltaPosition.Length();
                     *
                     * VRage.Trace.MyTrace.Send(VRage.Trace.TraceWindow.MPositions3, m_entity.DisplayName +
                     *  ": pos " + delta.Position + " / " + posLen + " lv " + tmpSnapshot.LinearVelocity + " / " + lenLV +
                     *  "; sdelta " + serverDeltaItem.Valid + " pos " + serverDeltaItem.Snapshot.Position + " / " + sdPosLen +
                     *  " anim " + m_animDeltaPositionIterations + " pos " + m_animDeltaPosition + " / " + aPosLen);*/
                }
            }
        }