Example #1
0
        /// <summary>
        /// Take the new state update from the server (i.e. its correction) and store it, so
        /// that we can apply it on our next frame.
        /// </summary>
        public override void AuthoritativeChangePosition(StateUpdateData data, double time)
        {
            base.AuthoritativeChangePosition(data, time);
            Animation  = data.Animation;
            FacingLeft = data.FacingLeft;

            ServerPosition = data.Position;
            Corrections.Add(new CorrectionInfo(time, data.Position, data.Velocity, PreviousLastAck));
            Corrected = true;

            // Remove corrections that are too old
            double limit = Client.Instance.GetTime().TotalSeconds - CORRECTIONS_TIME_KEPT.TotalSeconds;
            int    i     = 0;

            for (; i < Corrections.Count &&
                 Corrections[i].Time < limit; ++i)
            {
            }
            Corrections.RemoveRange(0, i);

            // Remove actions that are most certainly acknowledged
            if (Corrections.Count > 0)
            {
                for (i = 0; i < RecentActions.Count &&
                     RecentActions[i].ID <= Corrections[0].LastAcknowledgedActionId; ++i)
                {
                }
                RecentActions.RemoveRange(0, i);
            }
        }
Example #2
0
        /// <summary>
        /// Get the correction info received from the server that is *right before* our first
        /// unacknowledged action. This simplifies our calculations a lot, since we just apply
        /// this correction, reapply all the unacknowledged actions and our correction is done.
        /// If we would always simply take the latest correction, we'd have to deal with applying
        /// corrections while simulating unacknowledged actions right before our correction, effectively
        /// undoing our actions.
        /// </summary>
        /// <returns>null if there are no unacknowledged actions or not enough corrections (must then ignore the correction for the frame).</returns>
        CorrectionInfo GetCorrectionBeforeUnackAction()
        {
            if (Corrections.Count == 0)               // no corrections? no need to apply a server correction then.
            {
                return(null);
            }

            if (RecentActions.Count == 0)             // no ations to redo? we just take our most recent correction and apply it
            {
                return(Corrections[Corrections.Count - 1]);
            }

            CorrectionInfo corr = null;

            int i;

            for (i = Corrections.Count - 1; i >= 0 && corr == null; --i)
            {
                // first unacknowledged action of that correction
                int firstAction = RecentActions.FindIndex(a => a.ID > Corrections[i].LastAcknowledgedActionId);
                if (firstAction < 0 ||                                     // if we have a correction with *no* unacknowledged action, we want to use it! (most recent correction)
                    RecentActions[firstAction].Time > Corrections[i].Time) // we don't have unacknowledged actions before our correction, so this is our first before our first unack-ed action
                {
                    corr = Corrections[i];
                }
            }

            if (corr == null)
            {
                corr = Corrections[Corrections.Count - 1];
            }

            return(corr);
        }
Example #3
0
        private void UpdateRecentAction(RecentActions recentAction)
        {
            switch (recentAction)
            {
                case RecentActions.ClearHistory:
                    lblRecentAction.Text = "Clear History";
                    break;

                case RecentActions.OpenCalculator:
                    lblRecentAction.Text = "Open Calculator";
                    break;

                case RecentActions.OpenFile:
                    lblRecentAction.Text = "Open file";
                    break;

                case RecentActions.OpenNotepad:
                    lblRecentAction.Text = "Open Notepad";
                    break;

                case RecentActions.OpenPaint:
                    lblRecentAction.Text = "Open Paint";
                    break;
            }
        }
Example #4
0
        public void PackageAction(PlayerAction action)
        {
            PackagedActions.Enqueue(action);

            RecentActions.Add(action);

            IEntity temp = (IEntity)this.Clone();

            this.Clone(NoCorrections);
            ExecuteAction(action.Type);
            NoCorrections = (IEntity)Match.CurrentState.GetEntity(ID).Clone();
            this.Clone(temp);
            ExecuteAction(action.Type);
        }