Jump to content

[KSP 1.4.5] [x] Science! - KSP Science report and checklist (V5.17)


Recommended Posts

I've found, that this mod is one of the most unfriendly to memory usage. It causes very often tho fire garbage collector. I've got a lot of data on this subject, I also have a temporary solution. Anybody concerned about it?

Link to comment
Share on other sites

8 hours ago, iprdn said:

I've found, that this mod is one of the most unfriendly to memory usage. It causes very often tho fire garbage collector. I've got a lot of data on this subject, I also have a temporary solution. Anybody concerned about it?

Read through this thread...

Link to comment
Share on other sites

On 27/9/2017 at 12:46 PM, John007qwe said:

https://www.dropbox.com/s/fhvpbmngu3t7kkm/KSP-X-Science modified.zip?dl=0

I added a couple lines in ScienceContext.cs

line 385, 386 and 390

@Z-Key Aerospace I have been looking for causes for bad performance on my KSP install, and came across the above old posting from @John007qwe seemingly having found a simple change to do to x-science to increase performance.

I don't know if you have seen it?

I looked through the code in the source, just to see if this was already implemented, but it does not seem to be. If you did see it, did you consider this small change? It seems to make sense to me, not looping through all experiments for all planet on every refresh.

private void RefreshExperimentCache( )
{
	//... some code
	var _vessel = FlightGlobals.ActiveVessel;	//NEW
	var _planet = FlightGlobals.currentMainBody;	//NEW
	// Check this experiment in all biomes on all bodies
	for ( int body_index = 0; body_index < bodies.Count; body_index++ )
	{
		// Only load current celestial body
		if(_vessel != null && _planet != null) if (bodies[body_index].CelestialBody != FlightGlobals.currentMainBody) continue; 	//NEW
		//... some code
	}
	//... some code
}

Also if the code runs often (like Update() or FixedUpdate()), please consider having reference variables created outside the method, as to create less garbage.

Link to comment
Share on other sites

11 hours ago, tocken said:

Submit a pull request on GitHub.

Probably not a good idea, as the change I did disables some of the functionality to reduce lag.

 

The problem is that x science loads every type of science from all possible planets, situations, types of instruments, etc. and that in return results in, if i can remember correctly, over 800 different objects to keep track of (increased even more by mods = possibly more lag). From what I could understand from the source code, it loads all of them and creates objects to store in an array, which is to avoid having to run the code every frame, but instead every time your situation changes. My change makes the code skip everything that is not currently the planet you're on, reducing the amount of objects needed to be created to much less. I don't know why it even recreates them every time, as I'd imagine just updating the ones that actually changed would remove lag completely. But that's up to @Z-Key Aerospace to figure out. There could be a reason why he made it this way.

Edited by John007qwe
Link to comment
Share on other sites

24 minutes ago, leatherneck6017 said:

I'm genuinely curious, why use this versus ScienceAlert? Sure it's been abandoned by @DennyTX, but @jefftimlin forked it (here) and fixed the scene change lag and the problem of not being able to save config files from the GUI. I don't see any reason to use this one, anymore.

You could read the description to begin with. It'S not just alerting you, it also let's you browse a list and search with parameters to plan ahead, check, compare etc.

Link to comment
Share on other sites

28 minutes ago, maculator said:

You could read the description to begin with. It'S not just alerting you, it also let's you browse a list and search with parameters to plan ahead, check, compare etc.

Oh so you think I'm one of those players that makes uneducated/un-researched comments? I asked a genuine question (ref: "I'm genuinely curious") knowing full well what this mod does. I used this exclusively before finding ScienceAlert. And you give me this snarky response? Mmk.

Link to comment
Share on other sites

If you know full well what this mod does and you're not uneducated and you also researched for your comment you could've come to the conclusion that this mod offers a list with filters to the various szenes. In case you totally missed it I shortend the OP for you to show what the list does:

  • list and a textbox filter
  • Available from anywhere
  • It reports on all science
  • It reports on all vehicles
  • Report on anywhere
  • Automatically updates
  • Filter
  • Keyword search
  • View amount of science any experiment has lefton
Link to comment
Share on other sites

1 hour ago, maculator said:

If you know full well what this mod does and you're not uneducated and you also researched for your comment you could've come to the conclusion that this mod offers a list with filters to the various szenes. In case you totally missed it I shortend the OP for you to show what the list does:

Unlike you, I don't make ASSumptions about people and their intentions. My inquiry was based on the lag/stutter frustrations that have been voiced here, and experienced by myself. And also to offer up an alternative.

Link to comment
Share on other sites

On 2/4/2018 at 2:26 PM, John007qwe said:

Probably not a good idea, as the change I did disables some of the functionality to reduce lag.

 

The problem is that x science loads every type of science from all possible planets, situations, types of instruments, etc. and that in return results in, if i can remember correctly, over 800 different objects to keep track of (increased even more by mods = possibly more lag). From what I could understand from the source code, it loads all of them and creates objects to store in an array, which is to avoid having to run the code every frame, but instead every time your situation changes. My change makes the code skip everything that is not currently the planet you're on, reducing the amount of objects needed to be created to much less. I don't know why it even recreates them every time, as I'd imagine just updating the ones that actually changed would remove lag completely. But that's up to @Z-Key Aerospace to figure out. There could be a reason why he made it this way.

I think I might have found a way to reduce the lag. I'm playing with it right now, and in the current build I have not identified anything broken yet.

Stutter from changing biomes does seem to be significantly reduced.

If anyone want's to help test, then here is a link. (according to the license rules if this mod, I believe this is allowed). It is only the .dll, and you will have to overwrite the original manually.

https://drive.google.com/open?id=1tKivW4S7YTOeMRHRTU7tm0oB1FNSKHnN

I do think there is more that can be done to the here and now, since I also get a stutter when applying experiments. But I have not figured anything out for that part yet.

@Z-Key Aerospace I hope you can use the work done. There is probably something to optimize in my work as well, this is just what I could come up with.

Changes to RefreshExperimentCache() in ScienceContext class

        //WarezCrawler 2018-04-03
        BodySituationFilter BodyFilter = new BodySituationFilter();	//Reduce garbage collection. I think this class maybe could be changed to static?
        internal bool ExperimentCacheLoaded = false;				//Make sure all experiments are only updated very seldom

        /// <summary>
        /// Refreshes the experiment cache. THIS IS VERY EXPENSIVE.
        /// CB: Actually doesn't seem much worse than UpdateExperiments()
        /// </summary>
        private void RefreshExperimentCache()
        {
            Debug.Log("[XS-GTI] RefreshExperimentCache()");
            if (_allScienceInstances != null)
                Debug.Log("[XS-GTI] " + _allScienceInstances.Count);
            // Init
            var StartTime = DateTime.Now;
            //BodySituationFilter BodyFilter = new BodySituationFilter( );
            _unlockedInstruments.Clear();
            //WarezCrawler 2018-04-03
            if (!ExperimentCacheLoaded || !HighLogic.LoadedSceneIsFlight)	//Make sure all experiments are only updated very seldom
            {
                Debug.Log("[XS-GTI] Clearing experiments");
                _allScienceInstances.Clear();
                ExperimentCacheLoaded = false;
            }


            //_logger.Info( "RefreshExperimentCache" );


            // Quick check for things we depend on
            if (ResearchAndDevelopment.Instance == null || PartLoader.Instance == null)
            {
                _logger.Debug("ResearchAndDevelopment and PartLoader must be instantiated.");
                return;
            }


            if (!ExperimentCacheLoaded)	//Make sure all experiments are only updated very seldom
            {
                Debug.Log("[XS-GTI] Updating _allScienceInstances");
                if (_allScienceInstances != null)
                    Debug.Log("[XS-GTI]" + _allScienceInstances.Count);
                // Check this experiment in all biomes on all bodies

                // Loop around all experiments
                foreach (var X in _experiments)
                {
                    var experiment = X.Key;


                    //_logger.Trace( experiment.experimentTitle );
                    // Where the experiment is possible
                    uint sitMask = experiment.situationMask;
                    uint biomeMask = experiment.biomeMask;



                    /* Need to look at
                        public bool BiomeIsRelevantWhile( ExperimentSituations situation );
                        public bool IsAvailableWhile( ExperimentSituations situation, CelestialBody body );
                    On ScienceExperiment
                    */



                    // OrbitalScience support - where the experiment is possible
                    if (sitMask == 0 && _experiments[experiment] != null)
                    {
                        var sitMaskField = _experiments[experiment].GetType().GetField("sitMask");
                        if (sitMaskField != null)
                        {
                            sitMask = (uint)(int)sitMaskField.GetValue(_experiments[experiment]);
                            //_logger.Trace( "Setting sitMask to " + sitMask + " for " + experiment.experimentTitle );
                        }

                        if (biomeMask == 0)
                        {
                            var biomeMaskField = _experiments[experiment].GetType().GetField("bioMask");
                            if (biomeMaskField != null)
                            {
                                biomeMask = (uint)(int)biomeMaskField.GetValue(_experiments[experiment]);
                                //_logger.Trace( "Setting biomeMask to " + biomeMask + " for " + experiment.experimentTitle );
                            }
                        }
                    }



                    List<ExperimentSituations> SituationList = Enum.GetValues(typeof(ExperimentSituations)).Cast<ExperimentSituations>().ToList<ExperimentSituations>();
                    List<Body> bodies = new List<Body>(_bodyList.Values.ToList());



                    // Check for CelestialBodyFilter
                    if (_experiments[experiment] != null)
                    {
                        //_logger.Trace( Experiments[ experiment ].experimentID );
                        if (CelestialBodyFilters.Filters.HasValue(_experiments[experiment].experimentID))
                        {
                            string FilterText = CelestialBodyFilters.Filters.GetValue(_experiments[experiment].experimentID);
                            BodyFilter.Filter(bodies, SituationList, FilterText);
                        }
                    }

                    for (int body_index = 0; body_index < bodies.Count; body_index++)
                    {
                        //WarezCrawler 2018-04-03
                        //if (HighLogic.LoadedSceneIsFlight && (FlightGlobals.ActiveVessel != null && FlightGlobals.currentMainBody != null))
                        //    if (bodies[body_index].CelestialBody != FlightGlobals.currentMainBody)
                        //        continue;

                        if (experiment.requireAtmosphere && !bodies[body_index].HasAtmosphere)
                            continue; // If the whole planet doesn't have an atmosphere, then there's not much point continuing.
                        for (int situation_index = 0; situation_index < SituationList.Count; situation_index++)
                        {
                            if (SituationList[situation_index] == ExperimentSituations.SrfSplashed && !bodies[body_index].HasOcean)
                                continue; // Some planets don't have an ocean for us to be splashed down in.

                            if (SituationList[situation_index] == ExperimentSituations.SrfLanded && !bodies[body_index].HasSurface)
                                continue; // Jool and the Sun don't have a surface.

                            if ((SituationList[situation_index] == ExperimentSituations.FlyingHigh || SituationList[situation_index] == ExperimentSituations.FlyingLow) && !bodies[body_index].HasAtmosphere)
                                continue; // Some planets don't have an atmosphere for us to fly in.

                            if ((sitMask & (uint)SituationList[situation_index]) == 0)
                                continue; // This experiment isn't valid for our current situation.

                            if (bodies[body_index].Biomes.Any() && (biomeMask & (uint)SituationList[situation_index]) != 0)
                            {
                                for (int biome_index = 0; biome_index < bodies[body_index].Biomes.Count(); biome_index++)
                                {
                                    ScienceInstance S = new ScienceInstance(experiment, new Situation(bodies[body_index], SituationList[situation_index], bodies[body_index].Biomes[biome_index]), this);
                                    if (BodyFilter.TextFilter(S))
                                        if (!_parent.Config.FilterDifficultScience || BodyFilter.DifficultScienceFilter(S))
                                            _allScienceInstances.Add(S);
                                }
                            }
                            else
                            {
                                ScienceInstance S = new ScienceInstance(experiment, new Situation(bodies[body_index], SituationList[situation_index]), this);
                                if (BodyFilter.TextFilter(S))
                                    if (!_parent.Config.FilterDifficultScience || BodyFilter.DifficultScienceFilter(S))
                                        _allScienceInstances.Add(S);
                            }
                        }
                    }

                    if (((sitMask & (uint)ExperimentSituations.SrfLanded) != 0) && ((biomeMask & (uint)ExperimentSituations.SrfLanded) != 0))
                    {
                        if (_homeWorld != null && _kscBiomes.Count > 0)
                        {
                            if (bodies.Contains(_bodyList[_homeWorld])) // If we haven't filtered it out
                            {
                                if (SituationList.Contains(ExperimentSituations.SrfLanded))
                                {
                                    //_logger.Trace( "BabyBiomes " + experiment.experimentTitle + ": " + sitMask );
                                    for (int x = 0; x < _kscBiomes.Count; x++)
                                    {
                                        ScienceInstance S = new ScienceInstance(experiment, new Situation(_bodyList[_homeWorld], ExperimentSituations.SrfLanded, _kscBiome, _kscBiomes[x]), this);
                                        if (BodyFilter.TextFilter(S))
                                            if (!_parent.Config.FilterDifficultScience || BodyFilter.DifficultScienceFilter(S))
                                                _allScienceInstances.Add(S);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //WarezCrawler 2018-04-03
            if (_allScienceInstances != null)
                ExperimentCacheLoaded = true;

            if (_allScienceInstances != null)
                Debug.Log("[XS-GTI] _allScienceInstances.Count " + _allScienceInstances.Count);



            //			var Elapsed = DateTime.Now - StartTime;
            //			_logger.Trace( "RefreshExperimentCache Done - " + Elapsed.ToString( ) + "ms" );
        }

Changes to onGameSceneSwitchRequested() in ScienceChecklistAddon class

// Runs when scene switch is requested
private void onGameSceneSwitchRequested( GameEvents.FromToAction<GameScenes, GameScenes> action )
  {
  Science.ExperimentCacheLoaded = false;	//<-- make sure to reload experiments on change of scene (don't know if it is abolutely needed, but does not cost much)
  // The game likes to play music when we switch scenes, so we have to tell it to shut up once more
  HammerMusicMute( );
  }

 

Link to comment
Share on other sites

XScience was running lag free, now i installed it via CKAN and the LAG is back. Also the helpfull DLL is gone. Are thee any easy solutions now`Thank you

Edited by Nowater
Link to comment
Share on other sites

@Warezcrawler generally your .dll makes the mod run better, but when this "+x (Science Transmission)" messages float over the screen it still lags.

@N70 Actually I'm not sure if these "floating messages" are a feature of Kerbalism - but if yes, that doesn't mean Kerbalism is the issue, because it just shows an information about a transmission occured and science points rewarded.
This could still be an issue of [x] Science! because it also recognizes this information.

Perhaps the floating of the messages itself is the issue.

Edited by Gordon Dry
Link to comment
Share on other sites

1 minute ago, Gordon Dry said:

but when this "+x (Science Transmission)" messages float over the screen it still lags.

What are you referring to? I'm not sure I follow. Is it Kerbalism related? I've never tried Kerbalism, so might not have experienced what you are referring to.

Any screen shots?

Link to comment
Share on other sites

23 minutes ago, Gordon Dry said:

Because I started a new career last night the intervals of science transmission are low actually ... tbd next session I guess ... :confused:

Erm.. you can just create a new career, use the console to unlock the techtree, warp a craft with all the science parts in orbit of eeloo and transmitt everyting. Should give you enough oportunities to record a video or screenshot of the problem...

Link to comment
Share on other sites

@Warezcrawler @N70 @maculator

You can see a lag when doing the EVA report at the beginning, but let's go to nearly the end where the transmission of the EVA report is finished:
Shortly before the transmission is done there is a GC allocation, ignore that
Directly after the end of the transmission there is a much longer lag, that is the issue I'm talking about

Edited by Gordon Dry
Link to comment
Share on other sites

41 minutes ago, Gordon Dry said:

You can see a lag when doing the EVA report at the beginning, but let's go to nearly the end where the transmission of the EVA report is finished:
Shortly before the transmission is done there is a GC allocation, ignore that
Directly after the end of the transmission there is a much longer lag, that is the issue I'm talking about

I have noticed that X-Science does a lot of recalculations when you hit those buttons. The does give lag. My latest build of X-Science does reduce that, in my experience. Try it out here.

https://drive.google.com/open?id=1tKivW4S7YTOeMRHRTU7tm0oB1FNSKHnN

Based on your video (nice demo by the way), I'm guessing the the "floating of the messages" are the message regarding the science having been sent and received, stating how much science you got. If that is the case, I'm 99% sure that has nothing to do with X-Science. That is stock. However, X-Science might be doing a reset at that point (I think it does).... If that is the case, the above build might reduce the lag. Please try it out.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...