public void SaveSettings() { List <ConfigNode> flightGUISettings = FARSettingsScenarioModule.FlightGUISettings; if (flightGUISettings == null) { FARLogger.Error("Could not save Aero Visualization Settings because settings config list was null"); return; } ConfigNode node = flightGUISettings.FirstOrDefault(t => t.name == "AeroVizSettings"); if (node == null) { node = new ConfigNode("AeroVizSettings"); flightGUISettings.Add(node); } node.ClearData(); node.AddValue("fullySaturatedCl", FullySaturatedCl); node.AddValue("fullySaturatedCd", FullySaturatedCd); node.AddValue("fullySaturatedClBody", FullySaturatedClBody); node.AddValue("fullySaturatedCdBody", FullySaturatedCdBody); node.AddValue("fullySaturatedStall", FullySaturatedStall); }
public void SaveSettings() { List <ConfigNode> flightGUISettings = FARSettingsScenarioModule.FlightGUISettings; if (flightGUISettings == null) { FARLogger.Error("Could not save Airspeed Settings because settings config list was null"); return; } ConfigNode node = null; for (int i = 0; i < flightGUISettings.Count; i++) { if (flightGUISettings[i].name == "AirSpeedSettings") { node = flightGUISettings[i]; break; } } if (node == null) { node = new ConfigNode("AirSpeedSettings"); flightGUISettings.Add(node); } node.ClearData(); node.AddValue("unitTypeIndex", (int)unitMode); node.AddValue("velTypeIndex", (int)velMode); }
public void SaveSettings() { List <ConfigNode> flightGUISettings = FARSettingsScenarioModule.FlightGUISettings; if (flightGUISettings == null) { FARLogger.Error("Could not save Aero Visualization Settings because settings config list was null"); return; } ConfigNode node = null; for (int i = 0; i < flightGUISettings.Count; i++) { if (flightGUISettings[i].name == "AeroVizSettings") { node = flightGUISettings[i]; break; } } if (node == null) { node = new ConfigNode("AeroVizSettings"); flightGUISettings.Add(node); } node.ClearData(); node.AddValue("fullySaturatedCl", _fullySaturatedCl); node.AddValue("fullySaturatedCd", _fullySaturatedCd); node.AddValue("fullySaturatedClBody", _fullySaturatedClBody); node.AddValue("fullySaturatedCdBody", _fullySaturatedCdBody); node.AddValue("fullySaturatedStall", _fullySaturatedStall); }
public void SaveSettings() { List <ConfigNode> flightGUISettings = FARSettingsScenarioModule.FlightGUISettings; if (flightGUISettings == null) { FARLogger.Error("Could not save Flight Data Settings because settings config list was null"); return; } ConfigNode node = null; for (int i = 0; i < flightGUISettings.Count; i++) { if (flightGUISettings[i].name == "FlightDataSettings") { node = flightGUISettings[i]; break; } } if (node == null) { node = new ConfigNode("FlightDataSettings"); flightGUISettings.Add(node); } node.ClearData(); for (int i = 0; i < activeFlightDataSections.Length; i++) { node.AddValue("section" + i + "active", activeFlightDataSections[i]); } }
public ShaderBundleLoader() { // ReSharper disable once SwitchStatementMissingSomeCases switch (Application.platform) { case RuntimePlatform.LinuxPlayer: case RuntimePlatform.WindowsPlayer when SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL", StringComparison.Ordinal): FARLogger.Info("Shaders will be loaded from Linux bundle"); //For OpenGL users on Windows we load the Linux shaders to fix OpenGL issues pathValue = FARConfig.Shaders.BundleLinux; break; case RuntimePlatform.WindowsPlayer: FARLogger.Info("Shaders will be loaded from Windows bundle"); pathValue = FARConfig.Shaders.BundleWindows; break; case RuntimePlatform.OSXPlayer: FARLogger.Info("Shaders will be loaded from MacOSX bundle"); pathValue = FARConfig.Shaders.BundleMac; break; default: // Should never reach this FARLogger.Error($"Invalid runtime platform {Application.platform}"); break; } Url = pathValue.Value; pathValue.OnValueChanged += UpdateUrl; }
public IEnumerator Load(IAssetRequest <Texture2D> assetRequest) { assetRequest.State = Progress.InProgress; if (loadedTextures.TryGetValue(assetRequest.Url, out Texture2D texture)) { FARLogger.DebugFormat("Using already loaded texture {0}", assetRequest.Url); assetRequest.State = Progress.Completed; assetRequest.OnLoad(texture); yield break; } string path = $@"file:///{PathUtil.Combine(PathUtil.ParentDir, assetRequest.Url)}"; FARLogger.DebugFormat("Loading texture from {0}", path); using UnityWebRequest request = UnityWebRequestTexture.GetTexture(path); yield return(request.SendWebRequest()); if (!string.IsNullOrEmpty(request.error)) { FARLogger.Error($"Error loading texture from {request.url}: {request.error}"); assetRequest.State = Progress.Error; assetRequest.OnError(); } else { FARLogger.DebugFormat("Texture loaded from from {0}", request.url); Texture2D content = DownloadHandlerTexture.GetContent(request); loadedTextures.Add(assetRequest.Url, content); assetRequest.State = Progress.Completed; assetRequest.OnLoad(content); } }
private void ToggleGear() { List <Part> partsList = EditorLogic.SortedShipList; foreach (Part p in partsList) { if (p.Modules.Contains <ModuleWheelDeployment>()) { ModuleWheelDeployment l = p.Modules.GetModule <ModuleWheelDeployment>(); l.ActionToggle(new KSPActionParam(KSPActionGroup.Gear, gearToggle ? KSPActionType.Activate : KSPActionType.Deactivate)); } if (p.Modules.Contains("FSwheel")) { PartModule m = p.Modules["FSwheel"]; MethodInfo method = m.GetType().GetMethod("animate", BindingFlags.Instance | BindingFlags.NonPublic); if (method == null) { FARLogger.Error("FSwheel does not have method 'animate"); } else { method.Invoke(m, gearToggle ? new object[] { "Deploy" } : new object[] { "Retract" }); } } if (p.Modules.Contains("FSBDwheel")) { PartModule m = p.Modules["FSBDwheel"]; MethodInfo method = m.GetType().GetMethod("animate", BindingFlags.Instance | BindingFlags.NonPublic); if (method == null) { FARLogger.Error("FSBDwheel does not have method 'animate"); } else { method.Invoke(m, gearToggle ? new object[] { "Deploy" } : new object[] { "Retract" }); } } // ReSharper disable once InvertIf if (p.Modules.Contains("KSPWheelAdjustableGear")) { PartModule m = p.Modules["KSPWheelAdjustableGear"]; ToggleGearDeploymentOnKSPWheelPM(m, "deployAction"); } else if (p.Modules.Contains("KSPWheelDeployment")) { PartModule m = p.Modules["KSPWheelDeployment"]; ToggleGearDeploymentOnKSPWheelPM(m, "toggleGearAction"); } } gearToggle = !gearToggle; }
public void SaveSettings() { List <ConfigNode> flightGUISettings = FARSettingsScenarioModule.FlightGUISettings; if (flightGUISettings == null) { FARLogger.Error("Could not save Stability Augmentation Settings because settings config list was null"); return; } ConfigNode node = null; for (int i = 0; i < flightGUISettings.Count; i++) { if (flightGUISettings[i].name == "StabilityAugmentationSettings") { node = flightGUISettings[i]; break; } } Vessel active_vessel = null; try { active_vessel = FlightGlobals.ActiveVessel; } catch (NullReferenceException) { FARLogger.Error("Could not save Stability Augmentation Settings because 'FlightGlobals.ActiveVessel' is null."); return; } if (this._vessel == active_vessel) { systemTemplates = systemInstances; if (node == null) { node = new ConfigNode("StabilityAugmentationSettings"); flightGUISettings.Add(node); } else { node.ClearData(); } for (int i = 0; i < systemTemplates.Length; i++) { node.AddNode(BuildSystemNode(i)); } node.AddValue("aoALowLim", aoALowLim); node.AddValue("aoAHighLim", aoAHighLim); node.AddValue("scalingDynPres", scalingDynPres); } }
public void SetupAdjuster(PartModule intake, Matrix4x4 worldToVesselMatrix) { if (intake is ModuleResourceIntake module) { SetupAdjuster(module, worldToVesselMatrix); } else { FARLogger.Error($"{intake} is not typeof ModuleResourceIntake"); } }
public void SetupAdjuster(PartModule intake, Matrix4x4 worldToVesselMatrix) { if (intake is ModuleResourceIntake) { SetupAdjuster((ModuleResourceIntake)intake, worldToVesselMatrix); } else { FARLogger.Error(string.Format("{0} is not typeof ModuleResourceIntake", intake)); } }
private void ToggleGearDeploymentOnKSPWheelPM(PartModule pm, string methodName) { MethodInfo method = pm.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public); var action = new KSPActionParam(KSPActionGroup.Gear, gearToggle ? KSPActionType.Activate : KSPActionType.Deactivate); try { if (method == null) { FARLogger.Error($"{pm.GetType().Name} does not have method '{methodName}'"); } else { method.Invoke(pm, new[] { action }); } } catch (Exception e) { //we just catch and print this ourselves to allow things to continue working, since there seems to be a bug in KSPWheels as of this writing FARLogger.Exception(e); } }
void ToggleGear() { List <Part> partsList = EditorLogic.SortedShipList; for (int i = 0; i < partsList.Count; i++) { Part p = partsList[i]; if (p.Modules.Contains <ModuleWheelDeployment>()) { ModuleWheelDeployment l = p.Modules.GetModule <ModuleWheelDeployment>(); l.ActionToggle(new KSPActionParam(KSPActionGroup.Gear, gearToggle ? KSPActionType.Activate : KSPActionType.Deactivate)); } if (p.Modules.Contains("FSwheel")) { PartModule m = p.Modules["FSwheel"]; MethodInfo method = m.GetType().GetMethod("animate", BindingFlags.Instance | BindingFlags.NonPublic); if (method == null) { FARLogger.Error("FSwheel does not have method 'animate"); } else { method.Invoke(m, gearToggle ? new object[] { "Deploy" } : new object[] { "Retract" }); } } if (p.Modules.Contains("FSBDwheel")) { PartModule m = p.Modules["FSBDwheel"]; MethodInfo method = m.GetType().GetMethod("animate", BindingFlags.Instance | BindingFlags.NonPublic); if (method == null) { FARLogger.Error("FSBDwheel does not have method 'animate"); } else { method.Invoke(m, gearToggle ? new object[] { "Deploy" } : new object[] { "Retract" }); } } if (p.Modules.Contains("KSPWheelAdjustableGear")) { PartModule m = p.Modules["KSPWheelAdjustableGear"]; MethodInfo method = m.GetType().GetMethod("deploy", BindingFlags.Instance | BindingFlags.Public); try { if (method == null) { FARLogger.Error("KSPWheelAdjustableGear does not have method 'animate'."); } else { method.Invoke(m, null); } } catch (Exception e) { FARLogger.Exception(e); //we just catch and print this ourselves to allow things to continue working, since there seems to be a bug in KSPWheels as of this writing } } } gearToggle = !gearToggle; }
public void PredictionCalculateAeroForces(float atmDensity, float machNumber, float reynoldsPerUnitLength, float pseudoKnudsenNumber, float skinFrictionDrag, Vector3 vel, ferram4.FARCenterQuery center) { if (partData.Count == 0) { return; } PartData data = partData[0]; FARAeroPartModule aeroModule = null; for (int i = 0; i < partData.Count; i++) { data = partData[i]; aeroModule = data.aeroModule; if (aeroModule.part == null || aeroModule.part.partTransform == null) { continue; } break; } if (aeroModule.part == null || aeroModule.part.transform == null) { return; } double skinFrictionForce = skinFrictionDrag * xForceSkinFriction.Evaluate(machNumber); //this will be the same for each part, so why recalc it multiple times? double xForceAoA0 = xForcePressureAoA0.Evaluate(machNumber); double xForceAoA180 = xForcePressureAoA180.Evaluate(machNumber); Vector3 xRefVector = data.xRefVectorPartSpace; Vector3 nRefVector = data.nRefVectorPartSpace; Vector3 velLocal = aeroModule.part.partTransform.worldToLocalMatrix.MultiplyVector(vel); Vector3 angVelLocal = aeroModule.partLocalAngVel; //Vector3 angVelLocal = aeroModule.partLocalAngVel; //velLocal += Vector3.Cross(angVelLocal, data.centroidPartSpace); //some transform issue here, needs investigation Vector3 velLocalNorm = velLocal.normalized; Vector3 localNormalForceVec = Vector3.ProjectOnPlane(-velLocalNorm, xRefVector).normalized; double cosAoA = Vector3.Dot(xRefVector, velLocalNorm); double cosSqrAoA = cosAoA * cosAoA; double sinSqrAoA = Math.Max(1 - cosSqrAoA, 0); double sinAoA = Math.Sqrt(sinSqrAoA); double sin2AoA = 2 * sinAoA * Math.Abs(cosAoA); double cosHalfAoA = Math.Sqrt(0.5 + 0.5 * Math.Abs(cosAoA)); double nForce = 0; nForce = potentialFlowNormalForce * Math.Sign(cosAoA) * cosHalfAoA * sin2AoA; //potential flow normal force if (nForce < 0) //potential flow is not significant over the rear face of things { nForce = 0; } //if (machNumber > 3) // nForce *= 2d - machNumber * 0.3333333333333333d; float normalForceFactor = Math.Abs(Vector3.Dot(localNormalForceVec, nRefVector)); normalForceFactor *= normalForceFactor; normalForceFactor = invFlatnessRatio * (1 - normalForceFactor) + flatnessRatio * normalForceFactor; //accounts for changes in relative flatness of shape float crossFlowMach, crossFlowReynolds; crossFlowMach = machNumber * (float)sinAoA; crossFlowReynolds = reynoldsPerUnitLength * diameter * (float)sinAoA / normalForceFactor; nForce += viscCrossflowDrag * sinSqrAoA * CalculateCrossFlowDrag(crossFlowMach, crossFlowReynolds); //viscous crossflow normal force nForce *= normalForceFactor; double xForce = -skinFrictionForce *Math.Sign(cosAoA) * cosSqrAoA; double localVelForce = xForce * pseudoKnudsenNumber; xForce -= localVelForce; localVelForce = Math.Abs(localVelForce); float moment = (float)(cosAoA * sinAoA); float dampingMoment = 4f * moment; if (cosAoA > 0) { xForce += cosSqrAoA * xForceAoA0; float momentFactor; if (machNumber > 6) { momentFactor = hypersonicMomentForward; } else if (machNumber < 0.6) { momentFactor = 0.6f * hypersonicMomentBackward; } else { float tmp = (-0.185185185f * machNumber + 1.11111111111f); momentFactor = tmp * hypersonicMomentBackward * 0.6f + (1 - tmp) * hypersonicMomentForward; } //if (machNumber < 1.5) // momentFactor += hypersonicMomentBackward * (0.5f - machNumber * 0.33333333333333333333333333333333f) * 0.2f; moment *= momentFactor; dampingMoment *= momentFactor; } else { xForce += cosSqrAoA * xForceAoA180; float momentFactor; //negative to deal with the ref vector facing the opposite direction, causing the moment vector to point in the opposite direction if (machNumber > 6) { momentFactor = hypersonicMomentBackward; } else if (machNumber < 0.6) { momentFactor = 0.6f * hypersonicMomentForward; } else { float tmp = (-0.185185185f * machNumber + 1.11111111111f); momentFactor = tmp * hypersonicMomentForward * 0.6f + (1 - tmp) * hypersonicMomentBackward; } //if (machNumber < 1.5) // momentFactor += hypersonicMomentForward * (0.5f - machNumber * 0.33333333333333333333333333333333f) * 0.2f; moment *= momentFactor; dampingMoment *= momentFactor; } moment /= normalForceFactor; dampingMoment = Math.Abs(dampingMoment) * 0.1f; //dampingMoment += (float)Math.Abs(skinFrictionForce) * 0.1f; float rollDampingMoment = (float)(skinFrictionForce * 0.5 * diameter); //skin friction force times avg moment arm for vehicle rollDampingMoment *= (0.75f + flatnessRatio * 0.25f); //this is just an approximation for now Vector3 forceVector = (float)xForce * xRefVector + (float)nForce * localNormalForceVec; forceVector -= (float)localVelForce * velLocalNorm; Vector3 torqueVector = Vector3.Cross(xRefVector, localNormalForceVec) * moment; Vector3 axialAngLocalVel = Vector3.Dot(xRefVector, angVelLocal) * xRefVector; Vector3 nonAxialAngLocalVel = angVelLocal - axialAngLocalVel; if (velLocal.sqrMagnitude > 0.001f) { torqueVector -= (dampingMoment * nonAxialAngLocalVel) + (rollDampingMoment * axialAngLocalVel * axialAngLocalVel.magnitude) / velLocal.sqrMagnitude; } else { torqueVector -= (dampingMoment * nonAxialAngLocalVel) + (rollDampingMoment * axialAngLocalVel * axialAngLocalVel.magnitude) / 0.001f; } Matrix4x4 localToWorld = aeroModule.part.partTransform.localToWorldMatrix; float dynPresAndScaling = 0.0005f * atmDensity * velLocal.sqrMagnitude; //dyn pres and N -> kN conversion forceVector *= dynPresAndScaling; torqueVector *= dynPresAndScaling; forceVector = localToWorld.MultiplyVector(forceVector); torqueVector = localToWorld.MultiplyVector(torqueVector); Vector3 centroid = Vector3.zero; if (!float.IsNaN(forceVector.x) && !float.IsNaN(torqueVector.x)) { for (int i = 0; i < partData.Count; i++) { PartData data2 = partData[i]; FARAeroPartModule module = data2.aeroModule; if ((object)module == null) { continue; } if (module.part == null || module.part.partTransform == null) { continue; } centroid = module.part.partTransform.localToWorldMatrix.MultiplyPoint3x4(data2.centroidPartSpace); center.AddForce(centroid, forceVector * data2.dragFactor); } center.AddTorque(torqueVector); } else { FARLogger.Error("NaN Prediction Section Error: Inputs: AtmDen: " + atmDensity + " Mach: " + machNumber + " Re: " + reynoldsPerUnitLength + " Kn: " + pseudoKnudsenNumber + " skin: " + skinFrictionDrag + " vel: " + vel); } }
private void LogError(string msg) { FARLogger.Error(msg); StopLogging(); }
public IEnumerator Load() { // wait for the other loading to be done if (State == Progress.InProgress) { yield return(new WaitWhile(() => State == Progress.InProgress)); yield break; } State = Progress.InProgress; // wait for config to be loaded fully while (FARConfig.IsLoading) { yield return(null); } NeedsReload = false; string path = Url; FARLogger.DebugFormat("Loading asset bundle from {0}", path); AssetBundleCreateRequest createRequest = AssetBundle.LoadFromFileAsync(path); yield return(createRequest); AssetBundle assetBundle = createRequest.assetBundle; if (assetBundle == null) { FARLogger.Error($"Could not load asset bundle from {path}"); State = Progress.Error; yield break; } AssetBundleRequest loadRequest = assetBundle.LoadAllAssetsAsync <T>(); yield return(loadRequest); LoadedAssets.Clear(); foreach (Object asset in loadRequest.allAssets) { if (!LoadedAssets.ContainsKey(asset.name)) { if (asset is T t) { LoadedAssets.Add(asset.name, t); } else { FARLogger .Warning($"Invalid asset type {asset.GetType().ToString()}, expected {typeof(T).ToString()}"); } } else { FARLogger.DebugFormat("Asset {0} is duplicated", asset); } } FARLogger.DebugFormat("Completed loading assets from {0}", path); State = Progress.Completed; }