Exemple #1
0
 /// compare two dynamic states to detect any changes
 private bool HasChanged(DynamicState old, DynamicState now)
 {
     return((Mathf.Abs(old.position.x - now.position.x) > EPSILON) ||
            (Mathf.Abs(old.position.y - now.position.y) > EPSILON) ||
            (Mathf.Abs(old.velocity.x - now.velocity.x) > EPSILON) ||
            (Mathf.Abs(old.velocity.y - now.velocity.y) > EPSILON));
 }
Exemple #2
0
        /// update the state change info, should be called
        /// once per frame
        public void CheckForChanges()
        {
            // always report changes first time

            if (theFirstTime)
            {
                theFirstTime = false;
                hasChanged   = true;
                state        = GetState();
                return;
            }

            // in all other cases,

            // has the state actually changed?

            hasChanged = HasChanged(state, GetState());

            // if so, update change info for next time

            if (hasChanged)
            {
                state = GetState();
            }
        }
        /// formulate array of changed dynamic recorder object states
        /// for storage with delta compression
        private DynamicDeltaState[] RecordDynamicStates(
            DynamicRecorder[] dynamics)
        {
            // how many states have changed?

            int numChanged = 0;

            for (int i = 0; i < dynamics.Length; i++)
            {
                dynamics[i].CheckForChanges();

                if (dynamics[i].StateHasChanged())
                {
                    numChanged++;
                }
            }

            // record those changes

            DynamicDeltaState[] deltas = new DynamicDeltaState[numChanged];

            for (int i = 0, j = 0; i < dynamics.Length; i++)
            {
                if (dynamics[i].StateHasChanged())
                {
                    DynamicState state = dynamics[i].LastState();
                    deltas[j++] =
                        new DynamicDeltaState(i, state.position, state.velocity);
                }
            }

            return(deltas);
        }
 /// set the state from a recording
 public abstract void SetState(DynamicState state);
 /// set the object's state to match this state
 public override void SetState(DynamicState state)
 {
     remote.AddState(state.position, state.velocity);
 }