/// 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); }
/// Apply this frame's information to these replayer objects /// so that they match the frame public void Apply( DynamicReplayer[] dynamics, StaticReplayer[] statics) { // apply dynamic states from this frame for (int i = 0; i < this.dynamics.Length; i++) { DynamicDeltaState state = this.dynamics[i]; dynamics[state.index].SetState(new DynamicState( new Vector2(state.positionX, state.positionY), new Vector2(state.velocityX, state.velocityY) )); } // apply static states from this frame for (int i = 0; i < this.statics.Length; i++) { BooleanDeltaState state = this.statics[i]; statics[state.index].SetState(state.state); } }