Skip to content

Commit 259cbdb

Browse files
committed
Lots of refactoring and performance updates
1 parent b36f826 commit 259cbdb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1278
-1653
lines changed

GameData/DynamicBatteryStorage/DynamicBatteryStorageSettings.cfg

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,37 @@ DYNAMICBATTERYSTORAGE
238238
simulated = true
239239
continuous = true
240240
}
241+
241242
PARTMODULEHANDLER
242243
{
243-
name = ModuleRadioisotopeGenerator
244-
handlerModuleName = ModuleRadioisotopeGeneratorPowerHandler
244+
// The name of the module
245+
name = ModuleRadioisotopeGeneratorPowerHandler
246+
// The type of handler - can be Power or Heat
245247
type = Power
248+
// The name of the handler to use
249+
handlerModuleName = GenericFieldDataHandler
250+
// Is this shown in the UI at all?
246251
visible = true
252+
// Do we use solar distance attenuation?
247253
solarEfficiencyEffects = false
254+
// Is this module a producer by default?
248255
producer = true
256+
// Is this module a consumer by default?
249257
consumer = false
258+
// Does this item start off as active in the UI? Should canonically be true for constant sources/draws
250259
simulated = true
260+
// Does this item count as a continuous power source for the purpose of the UI?
251261
continuous = true
262+
HANDLER_CONFIG
263+
{
264+
// Field to poll in editor
265+
editorFieldName = BasePower
266+
// Field to poll in flight
267+
flightFieldName = ActualPower
268+
// Multiply the output by these if you need to. Convention is that a consumer is negative.
269+
editorValueScalar = -1.0
270+
flightValueScalar = -1.0
271+
}
252272
}
253273
PARTMODULEHANDLER
254274
{
@@ -429,6 +449,9 @@ DYNAMICBATTERYSTORAGE
429449
simulated = false
430450
continuous = false
431451
}
452+
453+
454+
432455
PARTMODULEHANDLER
433456
{
434457
name = ModuleLight
Binary file not shown.

GameData/DynamicBatteryStorage/Versioning/DynamicBatteryStorage.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
"MAJOR":2,
88
"MINOR":3,
9-
"PATCH":3,
9+
"PATCH":4,
1010
"BUILD":0
1111
},
1212
"KSP_VERSION":

Source/DynamicBatteryStorage/Data/VABVesselDataManager.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ public class EditorVesselDataManager : MonoBehaviour
1515

1616
public static EditorVesselDataManager Instance { get; private set; }
1717
public VesselElectricalData ElectricalData { get { return electricalData; } }
18-
public VesselThermalData HeatData { get { return heatData; } }
19-
2018
public bool Ready { get { return dataReady; } }
2119

2220
#endregion
@@ -26,7 +24,6 @@ public class EditorVesselDataManager : MonoBehaviour
2624
bool dataReady = false;
2725

2826
VesselElectricalData electricalData;
29-
VesselThermalData heatData;
3027
#endregion
3128

3229
protected void Awake()
@@ -75,31 +72,19 @@ protected void InitializeEditorConstruct(ShipConstruct ship, bool forceReset)
7572
else
7673
electricalData.RefreshData(false, ship.Parts);
7774

78-
if (heatData == null || forceReset)
79-
heatData = new VesselThermalData(ship.Parts);
80-
else
81-
heatData.RefreshData(false, ship.Parts);
82-
83-
8475
Utils.Log(String.Format("Dumping electrical database: \n{0}", electricalData.ToString()), Utils.LogType.VesselData);
85-
Utils.Log(String.Format("Dumping thermal database: \n{0}", heatData.ToString()), Utils.LogType.VesselData);
86-
8776
dataReady = true;
8877
}
8978
else
9079
{
9180
Utils.Log(String.Format("Ship is null"), Utils.LogType.VesselData);
9281
electricalData = new VesselElectricalData(new List<Part>());
93-
heatData = new VesselThermalData(new List<Part>());
9482
}
9583
}
9684

9785
protected void RemovePart(Part p)
9886
{
99-
10087
electricalData.RemoveHandlersForPart(p);
101-
heatData.RemoveHandlersForPart(p);
102-
10388
}
10489
#endregion
10590

@@ -135,7 +120,7 @@ public void onEditorVesselPartRemoved(GameEvents.HostTargetAction<Part, Part> p)
135120
Utils.Log("[VAB VesselDataManager][Editor]: Vessel PART REMOVE", Utils.LogType.VesselData);
136121
if (!HighLogic.LoadedSceneIsEditor) { return; }
137122

138-
if (electricalData == null || heatData == null)
123+
if (electricalData == null)
139124
InitializeEditorConstruct(EditorLogic.fetch.ship, false);
140125
else
141126
RemovePart(p.target);

Source/DynamicBatteryStorage/Data/VesselDataManager.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ public class VesselDataManager : VesselModule
1010
#region Accessors
1111

1212
public VesselElectricalData ElectricalData { get { return electricalData; } }
13-
public VesselThermalData HeatData { get { return heatData; } }
14-
1513
public bool Ready { get { return dataReady; } }
1614

1715
#endregion
@@ -22,7 +20,6 @@ public class VesselDataManager : VesselModule
2220
bool vesselLoaded = false;
2321

2422
VesselElectricalData electricalData;
25-
VesselThermalData heatData;
2623
#endregion
2724

2825
protected override void OnStart()
@@ -89,13 +86,8 @@ protected void RefreshVesselData()
8986
return;
9087

9188
electricalData = new VesselElectricalData(vessel.Parts);
92-
heatData = new VesselThermalData(vessel.Parts);
93-
9489
dataReady = true;
95-
9690
Utils.Log(String.Format("Dumping electrical database: \n{0}", electricalData.ToString()), Utils.LogType.VesselData);
97-
Utils.Log(String.Format("Dumping thermal database: \n{0}", heatData.ToString()), Utils.LogType.VesselData);
98-
9991
}
10092
}
10193
}

Source/DynamicBatteryStorage/Data/VesselThermalData.cs

Lines changed: 0 additions & 63 deletions
This file was deleted.

Source/DynamicBatteryStorage/DynamicBatteryStorage.csproj

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,34 @@
7979
<Compile Include="Data\VesselData.cs" />
8080
<Compile Include="Data\VesselDataManager.cs" />
8181
<Compile Include="Data\VesselElectricalData.cs" />
82-
<Compile Include="Data\VesselThermalData.cs" />
8382
<Compile Include="DynamicBatteryStorage.cs" />
8483
<Compile Include="FormatUtils.cs" />
8584
<Compile Include="HandlerConfiguration.cs" />
8685
<Compile Include="HandlerModuleData.cs" />
8786
<Compile Include="Handlers\GenericFieldDataHandler.cs" />
88-
<Compile Include="Handlers\Heat\NFTHeatHandlers.cs" />
89-
<Compile Include="Handlers\Heat\StockHeatHandlers.cs" />
9087
<Compile Include="Handlers\ModuleDataHandler.cs" />
91-
<Compile Include="Handlers\Power\KopernicusPowerHandlers.cs" />
92-
<Compile Include="Handlers\Power\NFTPowerHandlers.cs" />
93-
<Compile Include="Handlers\Power\RealBatteryPowerHandlers.cs" />
94-
<Compile Include="Handlers\Power\RemoteTechPowerHandler.cs" />
95-
<Compile Include="Handlers\Power\ScanSatPowerHandler.cs" />
96-
<Compile Include="Handlers\Power\StockPowerHandlers.cs" />
88+
<Compile Include="Handlers\KopernicusPowerHandlers.cs" />
89+
<Compile Include="Handlers\PostKerbin\DischargeCapacitorPowerHandler.cs" />
90+
<Compile Include="Handlers\PostKerbin\FissionGeneratorPowerHandler.cs" />
91+
<Compile Include="Handlers\PostKerbin\ModuleChargeableEnginePowerHandler.cs" />
92+
<Compile Include="Handlers\PostKerbin\ModuleCryoTankPowerHandler.cs" />
93+
<Compile Include="Handlers\PostKerbin\ModuleCurvedSolarPanelPowerHandler.cs" />
94+
<Compile Include="Handlers\PostKerbin\ModuleDeployableCentrifugePowerHandler.cs" />
95+
<Compile Include="Handlers\RealBatteryPowerHandlers.cs" />
96+
<Compile Include="Handlers\RemoteTechPowerHandler.cs" />
97+
<Compile Include="Handlers\ScanSatPowerHandler.cs" />
98+
<Compile Include="Handlers\Stock\ModuleActiveRadiatorPowerHandler.cs" />
99+
<Compile Include="Handlers\Stock\ModuleAlternatorPowerHandler.cs" />
100+
<Compile Include="Handlers\Stock\ModuleCommandPowerHandler.cs" />
101+
<Compile Include="Handlers\Stock\ModuleDataTransmitterPowerHandler.cs" />
102+
<Compile Include="Handlers\Stock\ModuleDeployableSolarPanelPowerHandler.cs" />
103+
<Compile Include="Handlers\Stock\ModuleEnginesPowerHandler.cs" />
104+
<Compile Include="Handlers\Stock\ModuleGeneratorPowerHandler.cs" />
105+
<Compile Include="Handlers\Stock\ModuleLightPowerHandler.cs" />
106+
<Compile Include="Handlers\Stock\ModuleResourceConverterPowerHandler.cs" />
107+
<Compile Include="Handlers\Stock\ModuleResourceHarvesterPowerHandler.cs" />
108+
<Compile Include="Handlers\Stock\ModuleScienceConverterPowerHandler.cs" />
109+
<Compile Include="Handlers\Stock\ModuleScienceLabPowerHandler.cs" />
97110
<Compile Include="Properties\AssemblyInfo.cs" />
98111
<Compile Include="Settings.cs" />
99112
<Compile Include="UI\SystemsMonitorUI.cs" />
@@ -108,7 +121,7 @@
108121
<Compile Include="UI\ToolbarSituation.cs" />
109122
<Compile Include="UI\Tooltips.cs" />
110123
<Compile Include="Utils.cs" />
111-
<Compile Include="Handlers\Power\WDSPPowerHandlers.cs" />
124+
<Compile Include="Handlers\WDSPPowerHandlers.cs" />
112125
</ItemGroup>
113126
<ItemGroup />
114127
<ItemGroup>

Source/DynamicBatteryStorage/Handlers/GenericFieldDataHandler.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
namespace DynamicBatteryStorage
24
{
35
/// <summary>
@@ -6,11 +8,14 @@ namespace DynamicBatteryStorage
68
/// </summary>
79
public class GenericFieldDataHandler : ModuleDataHandler
810
{
9-
private string editorFieldName;
10-
private string flightFieldName;
11+
private readonly string editorFieldName;
12+
private readonly string flightFieldName;
13+
14+
private readonly double editorValueScalar = 1.0d;
15+
private readonly double flightValueScalar = 1.0d;
1116

12-
private double editorValueScalar = 1.0d;
13-
private double flightValueScalar = 1.0d;
17+
private BaseField editorField;
18+
private BaseField flightField;
1419

1520
public GenericFieldDataHandler(HandlerModuleData moduleData) : base(moduleData)
1621
{
@@ -23,16 +28,34 @@ public GenericFieldDataHandler(HandlerModuleData moduleData) : base(moduleData)
2328
public override bool Initialize(PartModule pm)
2429
{
2530
base.Initialize(pm);
31+
try
32+
{
33+
editorField = pm.Fields[editorFieldName];
34+
}
35+
catch (Exception)
36+
{
37+
Utils.Warn($"[GenericFieldDataHandler] Issue locating editor field name {editorFieldName} on {pm.moduleName}");
38+
return false;
39+
}
40+
try
41+
{
42+
flightField = pm.Fields[flightFieldName];
43+
}
44+
catch (Exception)
45+
{
46+
Utils.Warn($"[GenericFieldDataHandler] Issue locating flight field name {flightFieldName} on {pm.moduleName}");
47+
return false;
48+
}
2649
return true;
2750
}
2851
protected override double GetValueEditor()
2952
{
30-
double.TryParse(pm.Fields.GetValue(editorFieldName).ToString(), out double results);
53+
double.TryParse(editorField.GetValue(pm).ToString(), out double results);
3154
return results * editorValueScalar;
3255
}
3356
protected override double GetValueFlight()
3457
{
35-
double.TryParse(pm.Fields.GetValue(flightFieldName).ToString(), out double results);
58+
double.TryParse(flightField.GetValue(pm).ToString(), out double results);
3659
return results * flightValueScalar;
3760
}
3861
}

0 commit comments

Comments
 (0)