private void GetStateFromDynamicData(VehicleEntity vehicle, ShipInternState state) { var data = (ShipDynamicDataComponent)vehicle.GetDynamicData(); state.Flag = data.Flag; state.IsAccelerated = data.IsAccelerated; state.SteerInput = data.SteerInput; state.ThrottleInput = data.ThrottleInput; state.Position = data.Position.ShiftedVector3(); state.Rotation = data.Rotation; state.IsSleeping = data.IsSleeping; state.LinearVelocity = data.LinearVelocity; state.AngularVelocity = data.AngularVelocity; var indexArray = VehicleIndexHelper.GetRudderIndexArray(); for (int i = 0; i < indexArray.Length; ++i) { var index = indexArray[i]; if (ShipEntityUtility.HasRudder(vehicle, index)) { state.RudderStates[i] = GetRudderState(ShipEntityUtility.GetRudder(vehicle, index)); } } data.Clear(); }
private void SyncStateFromComponentToDWP(VehicleEntity vehicle, ShipInternState state) { if (!state.IsSet() || SharedConfig.IsOffline) { return; } var currentState = GetCurrentState(vehicle); currentState.IsFlagSync = state.IsRemoteSet(); currentState.IsAccelerated = state.IsAccelerated; currentState.RudderInput = state.SteerInput; currentState.ThrottleInput = state.ThrottleInput; currentState.Position = state.Position; currentState.Rotation = state.Rotation; currentState.IsSleeping = state.IsSleeping; currentState.BodyState.LinearVelocity = state.LinearVelocity; currentState.BodyState.AngularVelocity = state.AngularVelocity; var rudderStates = currentState.RudderStates; var rudderCount = rudderStates.Length; for (int i = 0; i < rudderCount; ++i) { var destState = rudderStates[i]; var sourceState = state.RudderStates[i]; destState.Angle = sourceState.Angle; } ApplyState(vehicle); }
private void SetRudderAnglesFromState(AdvancedShipController controller, ShipInternState state) { var rudders = controller.rudders; for (int i = 0; i < rudders.Count; ++i) { rudders[i].Angle = state.RudderStates[i].Angle; } }
private void SyncFromComponentToDWP(VehicleEntity vehicle, ShipInternState state) { if (SharedConfig.DynamicPrediction) { DynamicSyncFromComponentToDWP(vehicle, state); } else { DirectSyncFromComponentToDWP(vehicle, state); } }
private void DynamicSyncFromComponentToDWP(VehicleEntity vehicle, ShipInternState internalState) { var controller = GetController(vehicle); var state = VehicleDynamicPredictionUtility.MoveToState(controller, internalState); SetRudderAnglesFromState(controller, internalState); SetShipInput(controller, internalState); VehicleDynamicPredictionUtility.SetControllerState(controller, state.Position, state.Rotation, state.LinearVelocity, state.AngularVelocity, state.IsSleeping, state.SleepingOutSync); }
private void DirectSyncFromComponentToDWP(VehicleEntity vehicle, ShipInternState state) { SyncStateFromComponentToDWP(vehicle, state); }
private void SetShipInput(AdvancedShipController controller, ShipInternState state) { controller.ThrottleInput = state.ThrottleInput; controller.RudderInput = state.SteerInput; controller.IsAccelerated = state.IsAccelerated; }