예제 #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>
        /// In this method we get the new vessel data and set it to the dictionary of all the player vessels.
        /// We set it as UNLOADED as perhaps vessel data has changed.
        /// </summary>
        public void HandleVesselProtoData(byte[] vesselData, Guid vesselId)
        {
            TaskFactory.StartNew(() =>
            {
                UniverseSyncCache.QueueToCache(vesselData);
                var vesselNode = ConfigNodeSerializer.Deserialize(vesselData);
                if (vesselNode != null && vesselId == Common.ConvertConfigStringToGuid(vesselNode.GetValue("pid")))
                {
                    var vesselProtoUpdate = new VesselProtoUpdate(vesselNode, vesselId);
                    if (vesselProtoUpdate.ProtoVessel == null)
                    {
                        return;
                    }

                    if (!AllPlayerVessels.TryGetValue(vesselId, out var existingProtoData))
                    {
                        AllPlayerVessels.TryAdd(vesselId, vesselProtoUpdate);
                    }
                    else if (VesselCommon.ProtoVesselHasChanges(existingProtoData.ProtoVessel, vesselProtoUpdate.ProtoVessel))
                    {
                        //Vessel exists and contain changes so replace it
                        AllPlayerVessels.TryUpdate(vesselId, vesselProtoUpdate, existingProtoData);
                    }
                }
            });
        }
 /// <summary>
 /// Removes a vessel from the loading system. If we receive a protovessel msg after this method is called it will be reloaded
 /// </summary>
 /// <param name="vesselId"></param>
 public void RemoveVesselFromLoadingSystem(Guid vesselId)
 {
     if (AllPlayerVessels.ContainsKey(vesselId))
     {
         AllPlayerVessels.TryRemove(vesselId, out var _);
     }
 }
예제 #4
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}");
            }
        }
예제 #5
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}");
            }
        }
예제 #6
0
 /// <summary>
 /// Sets a vessel as unloaded so it can be recreated later.
 /// For example if you leave a subspace the vessel must still be in the system but it should be unloaded
 /// </summary>
 public void UnloadVesselFromLoadingSystem(Guid vesselId)
 {
     if (AllPlayerVessels.TryGetValue(vesselId, out var existingProtoUpdate))
     {
         AllPlayerVessels.TryUpdate(vesselId, new VesselProtoUpdate(existingProtoUpdate), existingProtoUpdate);
     }
 }
예제 #7
0
 /// <summary>
 /// Updates the vesselProto from the dictionary in a thread safe manner
 /// </summary>
 private void UpdateVesselProtoInDictionary(VesselProtoUpdate vesselProto)
 {
     AllPlayerVessels.TryGetValue(vesselProto.VesselId, out var existingVesselProto);
     if (existingVesselProto != null)
     {
         AllPlayerVessels.TryUpdate(vesselProto.VesselId, vesselProto, existingVesselProto);
     }
 }
        /// <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}");
            }
        }
예제 #9
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);
            }
        }
예제 #10
0
 public override void OnDisabled()
 {
     base.OnDisabled();
     AllPlayerVessels.Clear();
     BannedPartsStr = string.Empty;
 }
예제 #11
0
 /// <summary>
 /// Removes a vessel from the loading system. If we receive a protovessel msg after this method is called it will be reloaded
 /// </summary>
 public void RemoveVesselFromLoadingSystem(Guid vesselId)
 {
     AllPlayerVessels.TryRemove(vesselId, out var _);
 }