/// <summary> /// Get the vessels that are in a past subspace and kill them /// </summary> private IEnumerator RemoveVesselsInPastSubspace() { var seconds = new WaitForSeconds((float)TimeSpan.FromMilliseconds(SettingsSystem.ServerSettings.VesselKillCheckMsInterval).TotalSeconds); while (true) { try { if (!Enabled) { break; } if (MainSystem.Singleton.GameRunning) { var vesselsToUnload = VesselProtoSystem.Singleton.AllPlayerVessels .Where(v => v.Loaded && VesselCommon.VesselIsControlledAndInPastSubspace(v.VesselId)) .Select(v => FlightGlobals.FindVessel(v.VesselId)) .ToArray(); if (vesselsToUnload.Any()) { Debug.Log($"[LMP]: Unloading {vesselsToUnload.Length} vessels that are in a past subspace"); UnloadVessels(vesselsToUnload); } } } catch (Exception e) { Debug.LogError($"[LMP]: Coroutine error in CheckVesselsToKill {e}"); } yield return(seconds); } }
/// <summary> /// Get the vessels that are in a past subspace and kill them /// </summary> private void KillPastSubspaceVessels() { if (SettingsSystem.ServerSettings.ShowVesselsInThePast) { return; } if (Enabled) { var vesselsToUnloadIds = VesselsProtoStore.AllPlayerVessels .Where(v => v.Value.VesselExist && VesselCommon.VesselIsControlledAndInPastSubspace(v.Key)); foreach (var vesselId in vesselsToUnloadIds) { AddToKillList(vesselId.Key); } } }
/// <summary> /// Get the vessels that are in a past subspace and kill them /// </summary> private void KillPastSubspaceVessels() { if (SettingsSystem.ServerSettings.ShowVesselsInThePast) { return; } if (Enabled && SystemsContainer.Get <MainSystem>().GameRunning) { var vesselsToUnload = SystemsContainer.Get <VesselProtoSystem>().AllPlayerVessels .Where(v => v.Value.Loaded && VesselCommon.VesselIsControlledAndInPastSubspace(v.Key)) .Select(v => FlightGlobals.FindVessel(v.Key)) .ToArray(); if (vesselsToUnload.Any()) { LunaLog.Log($"[LMP]: Unloading {vesselsToUnload.Length} vessels that are in a past subspace"); UnloadVessels(vesselsToUnload); } } }
/// <summary> /// Check vessels that must be loaded /// </summary> private IEnumerator CheckVesselsToLoad() { var seconds = new WaitForSeconds(CheckVesselsToLoadSInterval); while (true) { try { if (!Enabled) { break; } if (ProtoSystemBasicReady) { //Load vessels when we have at least 1 update for them and are in our subspace var vesselsToLoad = AllPlayerVessels .Where(v => !v.Loaded && (SettingsSystem.ServerSettings.ShowVesselsInThePast || !VesselCommon.VesselIsControlledAndInPastSubspace(v.VesselId))) .ToArray(); foreach (var vesselProto in vesselsToLoad) { Client.Singleton.StartCoroutine(VesselLoader.LoadVessel(vesselProto)); } } } catch (Exception e) { Debug.LogError($"[LMP]: Coroutine error in CheckVesselsToLoad {e}"); } yield return(seconds); } }
/// <summary> /// Check vessels that must be loaded /// </summary> private void CheckVesselsToLoad() { try { if (ProtoSystemBasicReady) { //Try to remove proto messages to own vessel if (!VesselCommon.IsSpectating && FlightGlobals.ActiveVessel != null) { AllPlayerVessels.TryRemove(FlightGlobals.ActiveVessel.id, out _); } //Reload vessels that exist var vesselsToReLoad = AllPlayerVessels .Where(v => !v.Value.Loaded && FlightGlobals.Vessels.Any(vl => vl.id == v.Value.VesselId)) .ToArray(); foreach (var vesselProto in vesselsToReLoad) { bool vesselLoaded = VesselLoader.ReloadVesselIfChanged(vesselProto.Value); if (vesselLoaded && !SettingsSystem.CurrentSettings.UseAlternativePositionSystem) { //TODO: This call will not put the vessel in the right position if a long time has elapsed between when the update was generated and when it's being applied, if in atmo. //TODO: This is because positions are set via ballistic orbits, which don't extrapolate properly in atmo. SystemsContainer.Get <VesselPositionSystem>().UpdateVesselPositionOnNextFixedUpdate(vesselProto.Value.VesselId); } } //Load vessels that don't exist and are in our subspace var vesselsToLoad = AllPlayerVessels .Where(v => !v.Value.Loaded && FlightGlobals.Vessels.All(vl => vl.id != v.Value.VesselId) && (SettingsSystem.ServerSettings.ShowVesselsInThePast || !VesselCommon.VesselIsControlledAndInPastSubspace(v.Value.VesselId))) .ToArray(); foreach (var vesselProto in vesselsToLoad) { VesselLoader.LoadVessel(vesselProto.Value); if (!SettingsSystem.CurrentSettings.UseAlternativePositionSystem) { //TODO: This call will not put the vessel in the right position if a long time has elapsed between when the update was generated and when it's being applied, if in atmo. //TODO: This is because positions are set via ballistic orbits, which don't extrapolate properly in atmo. SystemsContainer.Get <VesselPositionSystem>().UpdateVesselPositionOnNextFixedUpdate(vesselProto.Value.VesselId); } } } } catch (Exception e) { LunaLog.LogError($"[LMP]: Error in CheckVesselsToLoad {e}"); } }
/// <summary> /// Check vessels that must be loaded /// </summary> private IEnumerator CheckVesselsToLoad() { var seconds = new WaitForSeconds(CheckVesselsToLoadSInterval); while (true) { try { if (!Enabled) { break; } if (ProtoSystemBasicReady) { //Reload vessels that exist var vesselsToReLoad = AllPlayerVessels .Where(v => !v.Loaded && FlightGlobals.Vessels.Any(vl => vl.id == v.VesselId)) .ToArray(); foreach (var vesselProto in vesselsToReLoad) { VesselLoader.ReloadVessel(vesselProto); } //Load vessels that don't exist and are in our subspace var vesselsToLoad = AllPlayerVessels .Where(v => !v.Loaded && FlightGlobals.Vessels.All(vl => vl.id != v.VesselId) && (SettingsSystem.ServerSettings.ShowVesselsInThePast || !VesselCommon.VesselIsControlledAndInPastSubspace(v.VesselId))) .ToArray(); foreach (var vesselProto in vesselsToLoad) { VesselLoader.LoadVessel(vesselProto); } } } catch (Exception e) { Debug.LogError($"[LMP]: Coroutine error in CheckVesselsToLoad {e}"); } yield return(seconds); } }
/// <summary> /// Check vessels that must be loaded /// </summary> private void CheckVesselsToLoad() { try { if (ProtoSystemBasicReady && !VesselCommon.ActiveVesselIsInSafetyBubble()) { //Load vessels that don't exist and are in our subspace var vesselsToLoad = AllPlayerVessels .Where(v => !v.Value.Loaded && !v.Value.VesselExist && (SettingsSystem.ServerSettings.ShowVesselsInThePast || !VesselCommon.VesselIsControlledAndInPastSubspace(v.Value.VesselId))) .ToArray(); foreach (var vesselProto in vesselsToLoad) { if (SystemsContainer.Get <VesselRemoveSystem>().VesselWillBeKilled(vesselProto.Key)) { continue; } LunaLog.Log($"[LMP]: Loading vessel {vesselProto.Key}"); if (VesselLoader.LoadVessel(vesselProto.Value.ProtoVessel)) { vesselProto.Value.Loaded = true; LunaLog.Log($"[LMP]: Vessel {vesselProto.Key} loaded"); UpdateVesselProtoInDictionary(vesselProto.Value); } } } } catch (Exception e) { LunaLog.LogError($"[LMP]: Error in CheckVesselsToLoad {e}"); } }