@@ -1417,7 +1417,7 @@ internal void Mark()
14171417 public abstract class CabViewControlRenderer : RenderPrimitive
14181418 {
14191419 protected readonly Viewer Viewer ;
1420- public readonly MSTSLocomotive Locomotive ;
1420+ protected readonly MSTSLocomotive Locomotive ;
14211421 public readonly CabViewControl Control ;
14221422 protected readonly CabShader Shader ;
14231423 protected readonly SpriteBatchMaterial ControlView ;
@@ -1429,6 +1429,25 @@ public abstract class CabViewControlRenderer : RenderPrimitive
14291429
14301430 Matrix Matrix = Matrix . Identity ;
14311431
1432+ /// <summary>
1433+ /// Determines whether or not the control has power given the state of the cab power supply.
1434+ /// </summary>
1435+ /// <remarks>
1436+ /// For controls that do not depend on the power supply, this will always return true.
1437+ /// </remarks>
1438+ public bool IsPowered
1439+ {
1440+ get
1441+ {
1442+ if ( Control . DisabledIfLowVoltagePowerSupplyOff )
1443+ return Locomotive . LocomotivePowerSupply . LowVoltagePowerSupplyOn ;
1444+ else if ( Control . DisabledIfCabPowerSupplyOff )
1445+ return Locomotive . LocomotivePowerSupply . CabPowerSupplyOn ;
1446+ else
1447+ return true ;
1448+ }
1449+ }
1450+
14321451 public CabViewControlRenderer ( Viewer viewer , MSTSLocomotive locomotive , CabViewControl control , CabShader shader )
14331452 {
14341453 Viewer = viewer ;
@@ -1471,11 +1490,12 @@ public CABViewControlStyles GetStyle()
14711490 [ CallOnThread ( "Updater" ) ]
14721491 public virtual void PrepareFrame ( RenderFrame frame , ElapsedTime elapsedTime )
14731492 {
1474- if ( ( ! Control . DisabledIfLowVoltagePowerSupplyOff || Locomotive . LocomotivePowerSupply . LowVoltagePowerSupplyOn ) &&
1475- ( ! Control . DisabledIfCabPowerSupplyOff || Locomotive . LocomotivePowerSupply . CabPowerSupplyOn ) )
1476- {
1477- frame . AddPrimitive ( ControlView , this , RenderPrimitiveGroup . Cab , ref Matrix ) ;
1478- }
1493+ var noPower = ( Control . DisabledIfLowVoltagePowerSupplyOff && ! Locomotive . LocomotivePowerSupply . LowVoltagePowerSupplyOn )
1494+ || ( Control . DisabledIfCabPowerSupplyOff && ! Locomotive . LocomotivePowerSupply . CabPowerSupplyOn ) ;
1495+ if ( noPower )
1496+ return ;
1497+
1498+ frame . AddPrimitive ( ControlView , this , RenderPrimitiveGroup . Cab , ref Matrix ) ;
14791499 }
14801500
14811501 internal void Mark ( )
@@ -3109,18 +3129,17 @@ static float GetTextureCoordY(char c)
31093129
31103130 public void PrepareFrame ( RenderFrame frame , ElapsedTime elapsedTime )
31113131 {
3112- if ( ( ! CVFR . Control . DisabledIfLowVoltagePowerSupplyOff || CVFR . Locomotive . LocomotivePowerSupply . LowVoltagePowerSupplyOn )
3113- && ( ! CVFR . Control . DisabledIfCabPowerSupplyOff || CVFR . Locomotive . LocomotivePowerSupply . CabPowerSupplyOn ) )
3114- {
3115- UpdateDigit ( ) ;
3116- Matrix mx = TrainCarShape . Location . XNAMatrix ;
3117- mx . M41 += ( TrainCarShape . Location . TileX - Viewer . Camera . TileX ) * 2048 ;
3118- mx . M43 += ( - TrainCarShape . Location . TileZ + Viewer . Camera . TileZ ) * 2048 ;
3119- Matrix m = XNAMatrix * mx ;
3132+ if ( ! CVFR . IsPowered )
3133+ return ;
31203134
3121- // TODO: Make this use AddAutoPrimitive instead.
3122- frame . AddPrimitive ( this . shapePrimitive . Material , this . shapePrimitive , RenderPrimitiveGroup . Interior , ref m , ShapeFlags . None ) ;
3123- }
3135+ UpdateDigit ( ) ;
3136+ Matrix mx = TrainCarShape . Location . XNAMatrix ;
3137+ mx . M41 += ( TrainCarShape . Location . TileX - Viewer . Camera . TileX ) * 2048 ;
3138+ mx . M43 += ( - TrainCarShape . Location . TileZ + Viewer . Camera . TileZ ) * 2048 ;
3139+ Matrix m = XNAMatrix * mx ;
3140+
3141+ // TODO: Make this use AddAutoPrimitive instead.
3142+ frame . AddPrimitive ( this . shapePrimitive . Material , this . shapePrimitive , RenderPrimitiveGroup . Interior , ref m , ShapeFlags . None ) ;
31243143 }
31253144
31263145 internal void Mark ( )
@@ -3324,18 +3343,17 @@ private void UpdateShapePrimitive()
33243343
33253344 public void PrepareFrame ( RenderFrame frame , ElapsedTime elapsedTime )
33263345 {
3327- if ( ( ! CVFR . Control . DisabledIfLowVoltagePowerSupplyOff || CVFR . Locomotive . LocomotivePowerSupply . LowVoltagePowerSupplyOn )
3328- && ( ! CVFR . Control . DisabledIfCabPowerSupplyOff || CVFR . Locomotive . LocomotivePowerSupply . CabPowerSupplyOn ) )
3329- {
3330- UpdateDigit ( ) ;
3331- Matrix mx = TrainCarShape . Location . XNAMatrix ;
3332- mx . M41 += ( TrainCarShape . Location . TileX - Viewer . Camera . TileX ) * 2048 ;
3333- mx . M43 += ( - TrainCarShape . Location . TileZ + Viewer . Camera . TileZ ) * 2048 ;
3334- Matrix m = XNAMatrix * mx ;
3346+ if ( ! CVFR . IsPowered )
3347+ return ;
33353348
3336- // TODO: Make this use AddAutoPrimitive instead.
3337- frame . AddPrimitive ( this . shapePrimitive . Material , this . shapePrimitive , RenderPrimitiveGroup . Interior , ref m , ShapeFlags . None ) ;
3338- }
3349+ UpdateDigit ( ) ;
3350+ Matrix mx = TrainCarShape . Location . XNAMatrix ;
3351+ mx . M41 += ( TrainCarShape . Location . TileX - Viewer . Camera . TileX ) * 2048 ;
3352+ mx . M43 += ( - TrainCarShape . Location . TileZ + Viewer . Camera . TileZ ) * 2048 ;
3353+ Matrix m = XNAMatrix * mx ;
3354+
3355+ // TODO: Make this use AddAutoPrimitive instead.
3356+ frame . AddPrimitive ( this . shapePrimitive . Material , this . shapePrimitive , RenderPrimitiveGroup . Interior , ref m , ShapeFlags . None ) ;
33393357 }
33403358
33413359 internal void Mark ( )
@@ -3371,12 +3389,7 @@ public void Update(MSTSLocomotiveViewer locoViewer, ElapsedTime elapsedTime)
33713389 {
33723390 if ( ! locoViewer . _has3DCabRenderer ) return ;
33733391
3374- float scale = 0f ;
3375- if ( ( ! CVFR . Control . DisabledIfLowVoltagePowerSupplyOff || CVFR . Locomotive . LocomotivePowerSupply . LowVoltagePowerSupplyOn )
3376- && ( ! CVFR . Control . DisabledIfCabPowerSupplyOff || CVFR . Locomotive . LocomotivePowerSupply . CabPowerSupplyOn ) )
3377- {
3378- scale = CVFR . GetRangeFraction ( ) ;
3379- }
3392+ var scale = CVFR . IsPowered ? CVFR . GetRangeFraction ( ) : 0f ;
33803393
33813394 if ( CVFR . GetStyle ( ) == CABViewControlStyles . POINTER )
33823395 {
0 commit comments