private static void BalanceBrakePipe(Brakeset brakeset, float dt) { var states = brakeset.cars.Select(ExtraBrakeState.Instance).ToArray(); var fullCycles = Mathf.Floor(Main.settings.pipeBalanceSpeed); var partialCycle = Main.settings.pipeBalanceSpeed - fullCycles; for (int i = 0; i < fullCycles; i++) { for (int carIndex = 0; carIndex < states.Length - 1; carIndex++) { var stateA = states[carIndex]; var pressureA = stateA.brakePipePressureUnsmoothed; var stateB = states[carIndex + 1]; var pressureB = stateB.brakePipePressureUnsmoothed; var mean = (pressureA + pressureB) / 2f; stateA.brakePipePressureUnsmoothed = stateB.brakePipePressureUnsmoothed = mean; } } if (partialCycle >= 0.01f) { for (int carIndex = 0; carIndex < states.Length - 1; carIndex++) { var stateA = states[carIndex]; var pressureA = stateA.brakePipePressureUnsmoothed; var stateB = states[carIndex + 1]; var pressureB = stateB.brakePipePressureUnsmoothed; var mean = (pressureA + pressureB) / 2f; stateA.brakePipePressureUnsmoothed = Mathf.Lerp(pressureA, mean, partialCycle); stateB.brakePipePressureUnsmoothed = Mathf.Lerp(pressureB, mean, partialCycle); } } }
public static void Update(Brakeset brakeset, float dt) { Update(brakeset.firstCar, dt); if (brakeset.firstCar != brakeset.lastCar) { Update(brakeset.lastCar, dt); } foreach (BrakeSystem car in brakeset.cars) { car.Front.UpdatePressurized(); car.Rear.UpdatePressurized(); } }