예제 #1
0
        /// <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);
            }
        }
예제 #2
0
        /// <summary>
        /// Check vessels that must be reloaded
        /// </summary>
        private void CheckVesselsToReload()
        {
            try
            {
                if (ProtoSystemBasicReady && !VesselCommon.ActiveVesselIsInSafetyBubble())
                {
                    //Reload vessels that exist
                    var vesselsToReLoad = AllPlayerVessels
                                          .Where(pv => !pv.Value.Loaded && pv.Value.VesselExist)
                                          .ToArray();

                    foreach (var vesselProto in vesselsToReLoad)
                    {
                        if (SystemsContainer.Get <VesselRemoveSystem>().VesselWillBeKilled(vesselProto.Key))
                        {
                            continue;
                        }

                        LunaLog.Log($"[LMP]: Reloading vessel {vesselProto.Key}");
                        if (VesselLoader.ReloadVessel(vesselProto.Value.ProtoVessel))
                        {
                            vesselProto.Value.Loaded = true;
                            LunaLog.Log($"[LMP]: Vessel {vesselProto.Key} reloaded");
                            UpdateVesselProtoInDictionary(vesselProto.Value);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LunaLog.LogError($"[LMP]: Error in CheckVesselsToReload {e}");
            }
        }
예제 #3
0
        /// <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}");
            }
        }
        /// <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}");
            }
        }
예제 #5
0
        /// <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);
            }
        }