/// <summary> /// Sets the value of this state with values from another /// /// Note: When the shift occurs, all intrinsict types (float, string, etc) /// have thier values copied over. Any reference types (arrays, objects) have /// thier references assigned. This includes 'child' properties. /// /// For the reference values... if we want them shared between the prev and current /// instances, we don't need to do anything. /// /// However, if we want reference values to be independant between the prev and current /// we need to grab the prev's reference, hold it, and then reset it. /// </summary> /// <param name="rSource">ActorState that has the data to copy</param> public static int Shift(ref ActorState[] rStates, int rCurrentIndex) { // Increment the index int lNextIndex = (rCurrentIndex + 1) % rStates.Length; // Grab the next state ActorState lCurrentState = rStates[rCurrentIndex]; ActorState lNextState = rStates[lNextIndex]; // Clear all the values so we can refill lNextState.Clear(); // Reset the values lNextState.ID = lCurrentState.ID++; lNextState.Stance = lCurrentState.Stance; lNextState.GroundLocalContactPoint = lCurrentState.GroundLocalContactPoint; lNextState.PrevGround = lCurrentState.Ground; lNextState.PrevGroundPosition = lCurrentState.GroundPosition; lNextState.PrevGroundRotation = lCurrentState.GroundRotation; // Return the new index return lNextIndex; }
/// <summary> /// Safe way to get the desired index. It will do the mod for us. /// </summary> /// <param name="rDesiredIndex">Unsafe index that we want</param> /// <returns></returns> public static ActorState State(ref ActorState[] rStates, int rDesiredIndex) { if (rDesiredIndex < 0) { rDesiredIndex = rStates.Length + rDesiredIndex; } return rStates[rDesiredIndex]; }