@@ -496,7 +496,15 @@ public class SoundSource : SoundSourceBase
496
496
/// Squared cutoff distance. No sound is audible above that, except for the actual player train,
497
497
/// where cutoff occurs at a distance wich is higher than the train length
498
498
/// </summary>
499
- private const int CUTOFFDISTANCE = 4000000 ;
499
+ private int CutOffDistanceM2
500
+ {
501
+ get
502
+ {
503
+ const int staticDistanceM2 = 4000000 ;
504
+ var isPlayer = Car ? . Train ? . IsActualPlayerTrain ?? false ;
505
+ return ( int ) Math . Max ( staticDistanceM2 , isPlayer ? Car . Train . Length * Car . Train . Length : 0 ) ;
506
+ }
507
+ }
500
508
/// <summary>
501
509
/// Max distance for OpenAL inverse distance model. Equals to Math.Sqrt(CUTOFFDISTANCE)
502
510
/// </summary>
@@ -660,9 +668,9 @@ public override void Uninitialize()
660
668
public bool MstsMonoTreatment ;
661
669
662
670
/// <summary>
663
- /// Current distance to camera, squared meter. Is used for comparision to <see cref="CUTOFFDISTANCE "/>, to determine if is out-of-scope
671
+ /// Current distance to camera, squared meter. Is used for comparision to <see cref="CutOffDistanceM2 "/>, to determine if is out-of-scope
664
672
/// </summary>
665
- public float DistanceSquared = CUTOFFDISTANCE + 1 ;
673
+ public float DistanceSquared = float . MaxValue ;
666
674
/// <summary>
667
675
/// Out-of-scope state in previous <see cref="Update"/> loop
668
676
/// </summary>
@@ -995,7 +1003,7 @@ public override bool Update()
995
1003
} // Update
996
1004
997
1005
/// <summary>
998
- /// Calculate current distance to camera, and compare it to <see cref="CUTOFFDISTANCE "/>
1006
+ /// Calculate current distance to camera, and compare it to <see cref="CutOffDistanceM2 "/>
999
1007
/// </summary>
1000
1008
/// <returns>True, if is now out-of-scope</returns>
1001
1009
public bool isOutOfDistance ( )
@@ -1010,15 +1018,13 @@ public bool isOutOfDistance()
1010
1018
float . IsNaN ( WorldLocation . Location . Y ) ||
1011
1019
float . IsNaN ( WorldLocation . Location . Z ) )
1012
1020
{
1013
- DistanceSquared = ( Car != null && Car . Train != null && Car . Train . IsActualPlayerTrain ?
1014
- Math . Max ( CUTOFFDISTANCE , Car . Train . Length * Car . Train . Length ) : CUTOFFDISTANCE ) + 1 ;
1021
+ DistanceSquared = float . MaxValue ;
1015
1022
return true ;
1016
1023
}
1017
1024
1018
1025
DistanceSquared = WorldLocation . GetDistanceSquared ( WorldLocation , Viewer . Camera . CameraWorldLocation ) ;
1019
1026
1020
- return DistanceSquared > ( Car != null && Car . Train != null && Car . Train . IsActualPlayerTrain ?
1021
- Math . Max ( CUTOFFDISTANCE , Car . Train . Length * Car . Train . Length ) + 2500f : CUTOFFDISTANCE ) ;
1027
+ return DistanceSquared > CutOffDistanceM2 ;
1022
1028
}
1023
1029
1024
1030
/// <summary>
@@ -1037,8 +1043,7 @@ public bool Activate()
1037
1043
{
1038
1044
// (ActivationConditions.Distance == 0) means distance checking disabled
1039
1045
if ( ( ActivationConditions . Distance == 0 || DistanceSquared < ActivationConditions . Distance * ActivationConditions . Distance ) &&
1040
- DistanceSquared < ( Car != null && Car . Train != null && Car . Train . IsActualPlayerTrain ?
1041
- Math . Max ( CUTOFFDISTANCE , Car . Train . Length * Car . Train . Length ) + 2500f : CUTOFFDISTANCE ) )
1046
+ DistanceSquared < CutOffDistanceM2 )
1042
1047
return true ;
1043
1048
}
1044
1049
else
@@ -1063,8 +1068,7 @@ public bool DeActivate()
1063
1068
if ( WorldLocation != WorldLocation . None )
1064
1069
{
1065
1070
if ( DeactivationConditions . Distance != 0 && DistanceSquared > DeactivationConditions . Distance * DeactivationConditions . Distance ||
1066
- DistanceSquared > ( Car != null && Car . Train != null && Car . Train . IsActualPlayerTrain ?
1067
- Math . Max ( CUTOFFDISTANCE , Car . Train . Length * Car . Train . Length ) + 2500f : CUTOFFDISTANCE ) )
1071
+ DistanceSquared > CutOffDistanceM2 )
1068
1072
return true ;
1069
1073
}
1070
1074
0 commit comments