Skip to content

Various cleanups to ModuleSystemHeat#161

Merged
JonnyOThan merged 8 commits intoKSPModStewards:masterfrom
Phantomical:cleanup-module-system-heat
May 7, 2026
Merged

Various cleanups to ModuleSystemHeat#161
JonnyOThan merged 8 commits intoKSPModStewards:masterfrom
Phantomical:cleanup-module-system-heat

Conversation

@Phantomical
Copy link
Copy Markdown
Contributor

I'm gonna tackle #150 but decided to do a cleanup pass throughModuleSystemHeat first.

Here's what's included:

  • A bunch of minor formatting things: fix indentation, weird spaces, etc
  • Simplify some stuff that could use null coalescing
  • Avoid calling string.Format if the log message is not enabled
  • Initialize fluxes and temperatures in the constructor, then mark them readonly
  • Delete ChangeAllLoops because it is dead code
  • Change whole-method if statements to guard clauses

I have tested this and everything seems to work correctly, but there should also be no behaviour changes from this.

* Initialize fluxes, temperatures, and loopIDs in the ctor
* Switch to using guard clauses
* A bunch of minor formatting fixes
* Avoid calling string.Format if the relevant LogType is not enabled
* Delete ChangeAllLoops since it is dead code
Comment thread Source/Modules/ModuleSystemHeat.cs Outdated
public void AddFlux(string id, float sourceTemperature, float flux, bool useForNominal)
{
x_AddFluxMarker.Begin();
using var scope = x_AddFluxMarker.Auto();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC "auto" markers like this do not properly get removed when profiling is not enabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In most cases I actually consider this a benefit, though this method is probably called too often for that to be true. Let me whip up a helper that fixes this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, the code that was there before was perfectly fine...

Copy link
Copy Markdown
Contributor Author

@Phantomical Phantomical May 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would break if an early return ever gets added or an exception is thrown. That's my main objection, especially if I'm going to be adding more of these throughout.

@JonnyOThan JonnyOThan added this to the 0.9 milestone May 7, 2026
@JonnyOThan JonnyOThan merged commit 1a50e5e into KSPModStewards:master May 7, 2026
1 check passed
@Phantomical Phantomical deleted the cleanup-module-system-heat branch May 7, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants