Jump to content

[1.3.0] Kerbal Engineer Redux 1.1.3.0 (2017-05-28)


cybutek

Recommended Posts

Any chance of Sun and working Jool stats being added to the editor readouts?

Knowing TWR would be useful for a lower atmosphere return craft to Jool, and my own use case is a low Sun orbit vehicle with a requirement to pull away at its thermal limit, but maybe that's a bit too niche to bother implementing.

Link to comment
Share on other sites

On 28/1/2017 at 2:05 AM, EstebanLB said:

Hey, I was looking for a changelog and couldn't found one that indicates when both the flight computer and the chip parts, that this mod adds, were not necesary anymore to have KER working on a vessel. I'm testing in Career mode

You can change it in the in-game settings in the VAB/SBH

Link to comment
Share on other sites

On 28/01/2017 at 1:05 AM, EstebanLB said:

Hey, I was looking for a changelog and couldn't found one that indicates when both the flight computer and the chip parts, that this mod adds, were not necesary anymore to have KER working on a vessel. I'm testing in Career mode

For the KER information window in the VAB/SPH, you're right, the mod changed quite a while ago so that the parts were not needed.

For the KER in-flight information windows in career mode, I think you need one of:

  • A KER part on the vessel, or
  • An Engineer kerbal, or
  • The tracking station upgraded to level three.

 

Link to comment
Share on other sites

On 31/01/2017 at 4:02 PM, EstebanLB said:

Ok, thanks!

@CSE Do you know if the kerbal engineer needs a minimum XP level and if the signal strengh or net connection is relevant if using the KSC Tracking Station?

Any level of engineer is enough. I don't know whether you now need a connection to take advantage of the level three tracking station; by the time I get to the upgrade in a career, I've typically got almost complete coverage from all the contract satellites I've launched.

Link to comment
Share on other sites

Bug: while in flight, KER considers engines that have been activated through staging and then shut down manually as active for the purposes of dV and thrust calculations. This is mildly annoying on spaceplanes if you use an action group to shut your airbreathing engines down manually rather than letting them flame out on their own, because when you shut them down, KER will continue showing airbreathing dV until you reach the point where the engine's thrust curve reaches zero, and after that it will show your dV as NaN regardless of what your rocket engines are doing, so there's probably a negative root or a division by zero somewhere. The vessel mass is shown as 0 / <total> once you shut down the air breathing engines, so that seems rather suspicious in context. MechJeb does it right and does not consider shutdown engines.

I haven't debugged it, but taking a quick look at the code I noticed that when looking up which engines are active, there's a check which after a couple of layers of abstraction ends up being the equivalent of

ModuleEngines.isOperational && !ModuleEngines.flameout

that may be intended to prevent this behavior. I'm not sure what isOperational actually means but are you sure you shouldn't be checking isEnabled instead?

Link to comment
Share on other sites

9 hours ago, renhanxue said:

Bug: while in flight

Thanks for the report, is there any chance you can post a few screenshots and/or the craft file you're using?  The same area of code is also implicated in a similar issue with RealFuels (shows 0 dV in flight scene once engines are ignited) but I've not had any spare time in the last few weeks for modding due to other commitments.  I'll try to take a look at it soon...

Link to comment
Share on other sites

8 hours ago, Padishar said:

Thanks for the report, is there any chance you can post a few screenshots and/or the craft file you're using?  The same area of code is also implicated in a similar issue with RealFuels (shows 0 dV in flight scene once engines are ignited) but I've not had any spare time in the last few weeks for modding due to other commitments.  I'll try to take a look at it soon...

This also seems indirectly related to my request way back in the thread. I know time is a rare resource for many of us, but when the issue is being addressed it would be great to take the relevant bits and pieces into account. :)

 

Link to comment
Share on other sites

I've been working on adding  GetModuleCost() to some of my modules, however whenever I do, the thing start spamming my debugging logs. As far as I've been able to gather, it is not supposed to do that.

Now blowfish was really helpful in advising me in how to track the behaviour back. Based on using " System.Environment.StackTrace" the log showed that Kerbal Engineer was seemingly was implicated.

I have no idea if this is a known behaviour of KER, or a bug which might have creeped in when functionality in KSP evolved. But now I've tried to make sure it is known about.

I hope this is something that can (and will be changed/fixed). I am considering not using GetModuleCost() / IPartCostModifier until this is not an issue anymore as I am very focused on having my mods being light weight.

 

Highlights of the log

Spoiler

[LOG 22:20:39.107] UpdateCost() in LoadedSceneIsEditor

[LOG 22:20:39.285] System.Environment.StackTrace
   at System.Environment.get_StackTrace()
   at GTI.GTI_MultiModeEngineFX.GetModuleCost(Single defaultCost, ModifierStagingSituation sit)
   at Part.GetModuleCosts(Single defaultCost, ModifierStagingSituation sit)
   at KerbalEngineer.Extensions.PartExtensions.GetCostDry(.Part part)
   at KerbalEngineer.VesselSimulator.PartSim.New(.Part p, Int32 id, Double atmosphere, KerbalEngineer.LogMsg log)
   at KerbalEngineer.VesselSimulator.Simulation.PrepareSimulation(KerbalEngineer.LogMsg _log, System.Collections.Generic.List`1 parts, Double theGravity, Double theAtmosphere, Double theMach, Boolean dumpTree, Boolean vectoredThrust, Boolean fullThrust)
   at KerbalEngineer.VesselSimulator.SimManager.StartSimulation()
   at KerbalEngineer.VesselSimulator.SimManager.TryStartSimulation()
   at KerbalEngineer.Editor.BuildAdvanced.Update()

[LOG 22:20:39.287] UnityEngine.StackTraceUtility.ExtractStackTrace()
GTI.GTI_MultiModeEngineFX:GetModuleCost(Single, ModifierStagingSituation)
Part:GetModuleCosts(Single, ModifierStagingSituation)
KerbalEngineer.Extensions.PartExtensions:GetCostDry(Part)
KerbalEngineer.VesselSimulator.PartSim:New(Part, Int32, Double, LogMsg)
KerbalEngineer.VesselSimulator.Simulation:PrepareSimulation(LogMsg, List`1, Double, Double, Double, Boolean, Boolean, Boolean)
KerbalEngineer.VesselSimulator.SimManager:StartSimulation()
KerbalEngineer.VesselSimulator.SimManager:TryStartSimulation()
KerbalEngineer.Editor.BuildAdvanced:Update(

Full log file

 

Link to comment
Share on other sites

Yes, KER calls GetModuleCosts once on every part every time it constructs the parts tree, which it does every time the fuel flow simulation runs, which, in flight, is "all the time" (like, literally, it hooks Update() and starts a new simulation as soon as the previous one is complete). In flight it wouldn't need to do this since I don't think you can actually show the cost in a GUI readout, but unless you're doing some heavy calculations in your GetModuleCost implementation this shouldn't be an issue in practice. Try benchmarking it and see if you can even get a meaningful run time measurement out of it. As Donald Knuth (peace be upon him) said: premature optimization is the root of all evil.

The relevant code is at PartSim.cs line 130 and PartExtensions.cs line 81.

Edited by renhanxue
Link to comment
Share on other sites

Hi @Padishar, I'm using your version of KER (1.1.2.8p) and there is an error, when celestial body is selected as a target and rendezvous window is visible. I'm using floating windows in HUD mode. If the rendezvous windows isn't in the floating mode, then it just dissapears. When other target type is selected, then all readouts are visible and the error isn't generated. Replicated in a clean install of KSP.

KSP.log:
[EXC 10:09:42.330] NullReferenceException: Object reference not set to an instance of an object
	KerbalEngineer.Flight.Readouts.Surface.TargetLatitude.Draw (KerbalEngineer.Flight.Sections.SectionModule section)
	KerbalEngineer.Flight.Sections.SectionModule.DrawReadoutModules ()
	KerbalEngineer.Flight.Sections.SectionModule.Draw ()
	KerbalEngineer.Flight.Sections.SectionWindow.Window (Int32 windowId)
	UnityEngine.GUILayout+LayoutedWindow.DoWindow (Int32 windowID)
	UnityEngine.GUI.CallWindowDelegate (UnityEngine.WindowFunction func, Int32 id, UnityEngine.GUISkin _skin, Int32 forceRect, Single width, Single height, UnityEngine.GUIStyle style)

Error.log:
NullReferenceException: Object reference not set to an instance of an object
  at KerbalEngineer.Flight.Readouts.Surface.TargetLatitude.Draw (KerbalEngineer.Flight.Sections.SectionModule section) [0x00000] in <filename unknown>:0 
  at KerbalEngineer.Flight.Sections.SectionModule.DrawReadoutModules () [0x00000] in <filename unknown>:0 
  at KerbalEngineer.Flight.Sections.SectionModule.Draw () [0x00000] in <filename unknown>:0 
  at KerbalEngineer.Flight.Sections.SectionWindow.Window (Int32 windowId) [0x00000] in <filename unknown>:0 
  at UnityEngine.GUILayout+LayoutedWindow.DoWindow (Int32 windowID) [0x00000] in <filename unknown>:0 
  at UnityEngine.GUI.CallWindowDelegate (UnityEngine.WindowFunction func, Int32 id, UnityEngine.GUISkin _skin, Int32 forceRect, Single width, Single height, UnityEngine.GUIStyle style) [0x00000] in <filename unknown>:0 
 
(Filename:  Line: -1)

 

Link to comment
Share on other sites

14 hours ago, renhanxue said:

Yes, KER calls GetModuleCosts once on every part every time it constructs the parts tree, which it does every time the fuel flow simulation runs, which, in flight, is "all the time" (like, literally, it hooks Update() and starts a new simulation as soon as the previous one is complete). In flight it wouldn't need to do this since I don't think you can actually show the cost in a GUI readout, but unless you're doing some heavy calculations in your GetModuleCost implementation this shouldn't be an issue in practice. Try benchmarking it and see if you can even get a meaningful run time measurement out of it. As Donald Knuth (peace be upon him) said: premature optimization is the root of all evil.

The relevant code is at PartSim.cs line 130 and PartExtensions.cs line 81.

How can it be premature optimization, when I just want to avoid having irrelevant code running each frame. But yes, I'm looking at reducing the code running to just be lookup of a value, and then changing the value at the right time.

Link to comment
Share on other sites

2 hours ago, Warezcrawler said:

How can it be premature optimization, when I just want to avoid having irrelevant code running each frame. But yes, I'm looking at reducing the code running to just be lookup of a value, and then changing the value at the right time.

You're trying to eliminate code that you don't know if it has a meaningful performance impact or not. It's a good instinct in general to try to avoid calling code that doesn't need to run, but it's the definition of premature optimization to do so before having benchmarked it and finding that it has a meaningful performance impact that you want to avoid. Have you profiled it?

Link to comment
Share on other sites

22 minutes ago, renhanxue said:

You're trying to eliminate code that you don't know if it has a meaningful performance impact or not. It's a good instinct in general to try to avoid calling code that doesn't need to run, but it's the definition of premature optimization to do so before having benchmarked it and finding that it has a meaningful performance impact that you want to avoid. Have you profiled it?

I haven't profiled it as such, and your point of specific impact of my code was also pointed out by blowfish.

And I do not see it to be a problem if it was my mod only. But we are all piling on, so I just aim at not creating a mod that have unnecessary performance impact. When running with 100+ mods, this is snowballing. Every modder can approach this as they want, but I want KSP to run as smoothly as possible - and I do love that the core game have been optimized a lot since 1.0!

And my point here was to ask if KER intentionally wanted the behaviour of running code in mod's using GetModuleCost() all the time. If it is intentional and with good meaning, then that is just that. If it is not, the dev might look into changing that at some point. All good intentions only. And in the meantime I will do on my end what I can to keep my mods as light weight as possible.

Link to comment
Share on other sites

1 hour ago, Warezcrawler said:

I haven't profiled it as such, and your point of specific impact of my code was also pointed out by blowfish.

And I do not see it to be a problem if it was my mod only. But we are all piling on, so I just aim at not creating a mod that have unnecessary performance impact. When running with 100+ mods, this is snowballing. Every modder can approach this as they want, but I want KSP to run as smoothly as possible - and I do love that the core game have been optimized a lot since 1.0!

And my point here was to ask if KER intentionally wanted the behaviour of running code in mod's using GetModuleCost() all the time. If it is intentional and with good meaning, then that is just that. If it is not, the dev might look into changing that at some point. All good intentions only. And in the meantime I will do on my end what I can to keep my mods as light weight as possible.

This is getting off topic for this thread, but... I think there's a point I'm not getting across here, so I'll try one final time.

Your intent is good, and I apologize if I'm coming across as antagonistic or hostile, but I am still of the opinion that you're approaching the problem in a fundamentally flawed way. Optimization is very much an empirical science, and without profiling you are like the ancient Greeks trying to theorize on the workings of the universe without ever really observing it. It is not at all uncommon (in fact, it is probably the ordinary state of affairs) that when you profile software to see a few very small "hot spots" that are responsible for the majority of the total run time and every other function in the program contributing somewhere between a few percent each and approximately nothing. The difference between a "fast" function and a "slow" one can be (and usually is) several orders of magnitude. Once you realize this, it is easy to see that trying to optimize a function that is taking 0.5% of the total run time will in practice have no meaningful performance impact whatsoever even if you manage to eliminate it completely. That's why I'm trying to tell you that optimizing code without profiling is a fool's errand - you can improve performance by 25% but you can also do absolutely nothing, and then why did you go to that effort?

To a certain extent it is possible to reason about the performance of software on an abstract level based solely on the code as written, but modern systems (especially managed ones like Mono) are so complex and far away from the hardware that the results when running in the real world can be completely different from what you expect. You simply must profile to have any idea about what you're doing.

As a rule of thumb though, basic arithmetic operations on a modern CPU are so cheap as to be basically free. I'm not kidding - if you try to do a few dozen arithmetic operations on a number, put a lot of numbers in RAM and then see how many of them you can process per unit of time, you'll actually bottleneck on RAM bandwidth long before you are anywhere near saturating the CPU's ability to crunch numbers. As long as you only do simple arithmetic and don't try to do I/O or allocate/deallocate memory in a function, you can regard that function call as (essentially) free until profiling proves otherwise. If you start doing many thousands of calls per frame, then maybe you'll notice it, but otherwise, nope. KER assumes (rather reasonably, I'd say) that calculating the cost of a part isn't a very complex operation (for fuel tanks it's a few multiplications and additions, for everything else it's a constant), and so does not hesitate to call that function often.

All of that being said, having looked into the simulation code with the intent of getting into KSP modding and possibly fixing that bug I posted about above, I think the simulation code could probably use a once-over... but that's a lot of work.

Edited by renhanxue
Link to comment
Share on other sites

I'm sorry if this is a stupid question, but, how do I get Engineer to show up in Blizzy's toolbar instead of stock toolbar? I saw nothing on the in-game settings, and I checked each file in Engineer folder in the GameData folder, but there is nothing related to toolbar. How do I do it?

Link to comment
Share on other sites

Hey @Padishar, just wondering, any chance yet to look at the issue I posted around Jan 7?  Need any more info?  (I did confirm changing the root parts to match doesn't help).  I've noticed some edge cases where KER doesn't present correct results but am finding it a challenge to reproduce them consistently.  Hoping that test case I provided helps narrow it down.

Link to comment
Share on other sites

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...