1- using System ;
2- using System . Collections . Generic ;
3- using System . Reflection ;
4- using UnityEngine ;
5- using KSP ;
1+ using KSP . Localization ;
2+ using ROUtils ;
63using SolverEngines ;
7- using KSP . Localization ;
4+ using System ;
5+ using UnityEngine ;
86
97namespace RealFuels
108{
@@ -16,7 +14,7 @@ public class SolverRF : EngineSolver
1614 double VarianceDuring = 0.2d ;
1715
1816 // engine params
19- private FloatCurve atmosphereCurve = null , atmCurve = null , velCurve = null , atmCurveIsp = null , velCurveIsp = null , throttleIspCurve = null , throttleIspCurveAtmStrength = null ;
17+ private HermiteCurve atmosphereCurve = null , atmCurve = null , velCurve = null , atmCurveIsp = null , velCurveIsp = null , throttleIspCurve = null , throttleIspCurveAtmStrength = null ;
2018 private double minFlow , maxFlow , maxFlowRecip , thrustRatio = 1d , throttleResponseRate , machLimit , machMult ;
2119 private double flowMultMin , flowMultCap , flowMultCapSharpness ;
2220 private bool combusting = true ;
@@ -80,13 +78,13 @@ public void InitializeOverallEngineData(
8078 minFlow = nMinFlow * 1000d ; // to kg
8179 maxFlow = nMaxFlow * 1000d ;
8280 maxFlowRecip = 1d / maxFlow ;
83- atmosphereCurve = nAtmosphereCurve ;
84- atmCurve = nAtmCurve ;
85- velCurve = nVelCurve ;
86- atmCurveIsp = nAtmCurveIsp ;
87- velCurveIsp = nVelCurveIsp ;
88- throttleIspCurve = nthrottleIspCurve ;
89- throttleIspCurveAtmStrength = nthrottleIspCurveAtmStrength ;
81+ atmosphereCurve = nAtmosphereCurve == null ? null : new HermiteCurve ( nAtmosphereCurve ) ;
82+ atmCurve = nAtmCurve == null ? null : new HermiteCurve ( nAtmCurve ) ;
83+ velCurve = nVelCurve == null ? null : new HermiteCurve ( nVelCurve ) ;
84+ atmCurveIsp = nAtmCurveIsp == null ? null : new HermiteCurve ( nAtmCurveIsp ) ;
85+ velCurveIsp = nVelCurveIsp == null ? null : new HermiteCurve ( nVelCurveIsp ) ;
86+ throttleIspCurve = nthrottleIspCurve == null ? null : new HermiteCurve ( nthrottleIspCurve ) ;
87+ throttleIspCurveAtmStrength = nthrottleIspCurveAtmStrength == null ? null : new HermiteCurve ( nthrottleIspCurveAtmStrength ) ;
9088 disableUnderwater = nDisableUnderwater ;
9189 throttleResponseRate = nThrottleResponseRate ;
9290 chamberTemp = 288d ;
@@ -110,32 +108,31 @@ public void InitializeOverallEngineData(
110108 }
111109
112110 seededRandom = new System . Random ( nSeed ) ;
113- double vFlow , vIsp , vMR ;
114- GetVariances ( true , out vFlow , out vMR , out vIsp ) ;
111+ GetVariances ( true , out double vFlow , out double vMR , out double vIsp ) ;
115112 baseVaryFlow = VarianceBase * varyFlow * vFlow ;
116113 baseVaryIsp = VarianceBase * varyIsp * vIsp ;
117114 baseVaryMR = VarianceBase * varyMR * vMR ;
118115
119116
120117 // falloff at > sea level pressure.
121- if ( atmosphereCurve . Curve . keys . Length == 2 && atmosphereCurve . Curve . keys [ 0 ] . value != atmosphereCurve . Curve . keys [ 1 ] . value )
118+ if ( atmosphereCurve . KeyCount == 2 && atmosphereCurve [ 0 ] . value != atmosphereCurve [ 1 ] . value )
122119 {
123- Keyframe k0 = atmosphereCurve . Curve . keys [ 0 ] ;
124- Keyframe k1 = atmosphereCurve . Curve . keys [ 1 ] ;
120+ HermiteCurve . Key k0 = atmosphereCurve [ 0 ] ;
121+ HermiteCurve . Key k1 = atmosphereCurve [ 1 ] ;
125122 if ( k0 . time > k1 . time )
126123 {
127- Keyframe t = k0 ;
124+ HermiteCurve . Key t = k0 ;
128125 k0 = k1 ;
129126 k1 = t ;
130127 }
131- float minIsp = 0.0001f ;
132- float invSlope = ( k1 . time - k0 . time ) / ( k0 . value - k1 . value ) ;
133- float maxP = k1 . time + ( k1 . value - minIsp ) * invSlope ;
134-
135- atmosphereCurve = new FloatCurve ( ) ;
136- atmosphereCurve . Add ( k0 . time , k0 . value , k0 . inTangent , k0 . outTangent ) ;
137- atmosphereCurve . Add ( k1 . time , k1 . value , k1 . inTangent , k1 . outTangent ) ;
138- atmosphereCurve . Add ( maxP , minIsp ) ;
128+ double minIsp = 0.0001f ;
129+ double invSlope = ( k1 . time - k0 . time ) / ( k0 . value - k1 . value ) ;
130+ double maxP = k1 . time + ( k1 . value - minIsp ) * invSlope ;
131+
132+ atmosphereCurve = new HermiteCurve ( ) ;
133+ atmosphereCurve . AddKey ( k0 . time , k0 . value , k0 . inTangent , k0 . outTangent ) ;
134+ atmosphereCurve . AddKey ( k1 . time , k1 . value , k1 . inTangent , k1 . outTangent ) ;
135+ atmosphereCurve . AddKey ( maxP , minIsp ) ;
139136 }
140137 }
141138
@@ -168,7 +165,7 @@ public override void CalculatePerformance(double airRatio, double commandedThrot
168165 M0 = mach ;
169166
170167 // Calculate Isp (before the shutdown check, so it displays even then)
171- float pressureAtm = ( float ) ( p0 * 0.001d * PhysicsGlobals . KpaToAtmospheres ) ;
168+ double pressureAtm = p0 * 0.001d * PhysicsGlobals . KpaToAtmospheres ;
172169 Isp = atmosphereCurve . Evaluate ( pressureAtm ) * ispMult ;
173170
174171 // if we're not combusting, don't combust and start cooling off
@@ -265,11 +262,11 @@ public override void CalculatePerformance(double airRatio, double commandedThrot
265262
266263 double ispOtherMult = 1d ;
267264 if ( atmCurveIsp != null )
268- ispOtherMult *= atmCurveIsp . Evaluate ( ( float ) ( rho * ( 1d / 1.225d ) ) ) ;
265+ ispOtherMult *= atmCurveIsp . Evaluate ( rho * ( 1d / 1.225d ) ) ;
269266 if ( velCurveIsp != null )
270- ispOtherMult *= velCurveIsp . Evaluate ( ( float ) mach ) ;
267+ ispOtherMult *= velCurveIsp . Evaluate ( mach ) ;
271268 if ( throttleIspCurve != null )
272- ispOtherMult *= Mathf . Lerp ( 1f , throttleIspCurve . Evaluate ( ( float ) commandedThrottle ) ,
269+ ispOtherMult *= UtilMath . Lerp ( 1f , throttleIspCurve . Evaluate ( commandedThrottle ) ,
273270 throttleIspCurveAtmStrength . Evaluate ( pressureAtm ) ) ;
274271
275272 if ( HighLogic . LoadedSceneIsFlight && varyIsp > 0d && fuelFlow > 0d )
@@ -322,10 +319,10 @@ protected double FlowMult()
322319 {
323320 double flowMult = 1d ;
324321 if ( atmCurve != null )
325- flowMult *= atmCurve . Evaluate ( ( float ) ( rho * ( 1d / 1.225d ) ) ) ;
322+ flowMult *= atmCurve . Evaluate ( ( rho * ( 1d / 1.225d ) ) ) ;
326323
327324 if ( velCurve != null )
328- flowMult *= velCurve . Evaluate ( ( float ) mach ) ;
325+ flowMult *= velCurve . Evaluate ( mach ) ;
329326
330327 if ( flowMult > flowMultCap )
331328 {
0 commit comments